-
Notifications
You must be signed in to change notification settings - Fork 3
/
chdommod.f90
588 lines (569 loc) · 17.4 KB
/
chdommod.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
! Copyright 2021, Christian Hafner
!
! This file is part of OpenMaXwell.
!
! OpenMaXwell is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
! OpenMaXwell is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
! You should have received a copy of the GNU General Public License
! along with OpenMaXwell. If not, see <http://www.gnu.org/licenses/>.
MODULE CHDOM
! Domains
USE CHOBJ
SAVE
CONTAINS
! Graphics
Subroutine TDrawDomain(lCheck)
Implicit none
Include 'resource.fd'
Logical(4), intent(in) :: lCheck
Logical(4) ldum
ldum=lCheck
call WaitEndThread()
iThreadAction=2
call StartDOMThread(ldum)
end Subroutine TDrawDomain
Subroutine StartDOMThread(ldi)
! start a new thread
Implicit none
Include 'resource.fd'
Integer(INT_PTR_KIND()) iThread
Integer(4), Save:: iArgument
Integer(4) iStack,iCreation,idum
Logical, intent(in) :: ldi
Logical(4) ldum
if(lThreadStarted) return
call OutTxt('t3','start domain thread'C)
call OutTxt('n3',' 'C)
call OutTxt('m3',' 'C)
lThreadStarted=.true.
iStack=0
iArgument=0
iCreation=0
iThread=0
if(ldi) iArgument=1_4
if(iThreadHandle.ne.0) then
call OutTxt('t3','close thread handle'C)
ldum=CloseHandle(iThreadHandle)
if(.not.ldum) then
idum=MessageBoxQQ('Cannot close thread handle'C,'Start domain thread'C, &
MB$OK.or.MB$ICONEXCLAMATION)
lThreadStarted=.false.
return
end if
iThreadHandle=0
endif
call OutTxt('t3','Start domain thread'C)
iThreadHandle=CreateThread(NULL,iStack,Loc(DOMThread),Loc(iArgument),iCreation,iThread)
if(iThreadHandle.eq.0) then
idum=MessageBoxQQ('Cannot create thread'C,'Start domain thread'C, &
MB$OK.or.MB$ICONEXCLAMATION)
lThreadStarted=.false.
return
end if
end Subroutine StartDOMThread
Integer(4) Function DOMThread(iWhat)
! tread calls.....
Implicit none
Integer(4) iWhat
Logical ldum
Include 'resource.fd'
lStopThread=.false.
ldum=.false.
if(iWhat.ne.0) ldum=.true.
DOMThread=0_4
if(iThreadAction.eq.2) then
call MTDrawBoundary(ldum)
call MTDrawExpansion(.true.)
end if
call endThread()
end Function DOMThread
! I/O
Subroutine SaveDomain(lCheck)
! save domain data in a file
Implicit none
Logical, intent(in) :: lCheck
Integer(4) iOk,ios,i,idum
if(.not.lCheck) then
call Open2write(-1,'Select domain data file to be written!','Domain data file ',DomFileName,'DOM',ios)
if(ios.gt.0) return
end if
open(1,file=DomFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save domains'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHDomIdent,iOK)
ich(1)=nDom
sch(1:8)=' domains'
call chwrit2(1,ich,1,rch,0,sch,8,iOK)
do i=1,nDom
ich(1)=Int4(iDom(i))
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
call WriteStr(1,Dom_Form(1,i),iOK)
call WriteStr(1,Dom_Form(2,i),iOK)
call WriteStr(1,Dom_Form(3,i),iOK)
call WriteStr(1,Dom_Form(4,i),iOK)
end do
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
end Subroutine SaveDomain
Subroutine OpenDomain(lCheck)
! read domain data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical ldum,lFileExist
Integer(4) iOK,ios,i,idum,iVers
Character(20) text
if(.not.lCheck) then
call Open2read(-1,'Select domain data file to be read!','Domain data file ',DomFileName,'DOM',ios)
if(ios.gt.0) return
end if
inquire(file=DomFileName,Exist=lFileExist)
if(.not.lFileExist) return
open(1,file=DomFileName,status='old',iostat=ios)
if(ios.ne.0) then
if(.not.lCheck) idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open domains'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHDomIdent(1:15).ne.text(1:15)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open domains'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
call StrToInt(text(16:16)//text(18:18),iVers,iOK)
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(number of domains)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nDom=ich(1)
if(nDom.gt.mDom) then
mDom=nDom
call AllocateDom(ldum)
if(.not.ldum) return
end if
do i=1,nDom
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(domain color)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
iDom(i)=Int2(ich(1))
call ReadStr(1,Dom_Form(1,i),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(domain formula 1)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Dom_Form(2,i),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(domain formula 2)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
call ReadStr(1,Dom_Form(3,i),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(domain formula 3)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
if(iVers.gt.10) then
call ReadStr(1,Dom_Form(4,i),iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(domain formula 3)'C,'Open domains'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
else
Dom_Form(4,i)='0.0'C
end if
end do
close(1)
call getEUST()
end Subroutine OpenDomain
Subroutine SaveProject(lCheck,lOpened)
! save Project data in a file
Implicit none
Logical, intent(in) :: lCheck
Logical lOpened
Integer(4) iOk,ios,idum
lOpened=.false.
if(.not.lCheck) then
call Open2write(-1,'Select Project data file to be written!','Project data file ',ProFileName,'PRO',ios)
if(ios.gt.0) return
end if
open(1,file=ProFileName,iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot save data!'C,'Save project'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call WriteStr(1,CHProIdent,iOK)
ich(1)=0
sch(1:10)=' time dep.'
if(lfcFld) then
ich(1)=1
sch(1:10)=' freq.dep.'
end if
call chwrit2(1,ich,1,rch,0,sch,10,iOK)
rch(1)=Dble(fcFld)
rch(2)=DImag(fcFld)
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
ich(1)=0
sch(1:14)=' 3D, wave type'
if(lgcFld) then
ich(1)=1
sch(1:14)=' 2D'
end if
ich(2)=Int4(iHEGlobal)
call chwrit2(1,ich,2,rch,0,sch,14,iOK)
if(lgcFld) then
if(lzPer) then
rch(1)=Dble(dcFld)
rch(2)=2.0d0*pBig
else
rch(1)=Dble(gcFld)
rch(2)=DImag(gcFld)
end if
call chwrit2(1,ich,0,rch,2,sch,0,iOK)
end if
ich(1:3)=0
sch(1:13)=' non-periodic'
if(lxPeriod) then
ich(1)=1
if(.not.lregularPeriod) ich(1)=-1
end if
if(lyPeriod) ich(2)=1
if(lzPeriod) ich(3)=1
if(lxPeriod.or.lyPeriod.or.lzPeriod) sch(1:13)=' periodic '
call chwrit2(1,ich,3,rch,0,sch,13,iOK)
if(lxPeriod.or.lyPeriod.or.lzPeriod) then
rch(1)=xPeriod
rch(2:3)=yPeriodVector(1:2)
rch(4:6)=zPeriodVector(1:3)
call chwrit2(1,ich,0,rch,6,sch,0,iOK)
rch(1)=Dble(cxPeriodDlg)
rch(2)=DImag(cxPeriodDlg)
rch(3)=Dble(cyPeriodDlg)
rch(4)=DImag(cyPeriodDlg)
rch(5)=Dble(czPeriodDlg)
rch(6)=DImag(czPeriodDlg)
call chwrit2(1,ich,0,rch,6,sch,0,iOK)
end if
ich(1)=0
sch(1:11)=' scattering'
if(lEigen) then
ich(1)=1
sch(1:11)=' eigenvalue'
end if
call chwrit2(1,ich,1,rch,0,sch,11,iOK)
if(lEigen) then
ich(1)=iEigen
ich(2)=0
if(lEigenSave) ich(2)=1
if(.not.lWriteRoughFld) ich(2)=ich(2)+2
call chwrit2(1,ich,2,rch,0,sch,0,iOK)
ich(1)=nrEigen
ich(2)=niEigen
rch(1)=Dble(c1Eigen)
rch(2)=DImag(c1Eigen)
rch(3)=Dble(c2Eigen)
rch(4)=DImag(c2Eigen)
call chwrit2(1,ich,2,rch,4,sch,0,iOK)
ich(1)=imEigen
ich(2)=itmEigen
rch(1)=aEigen
rch(2)=fEigen
call chwrit2(1,ich,2,rch,2,sch,0,iOK)
rch(1)=Dble(c1EigenC)
rch(2)=DImag(c1EigenC)
rch(3)=Dble(c2EigenC)
rch(4)=DImag(c2EigenC)
call chwrit2(1,ich,0,rch,4,sch,0,iOK)
end if
ich(1)=ixySymm
ich(2)=ixzSymm
ich(3)=iyzSymm
call chwrit2(1,ich,3,rch,0,sch,0,iOK)
ich(1)=Int4(iWriteDigits)
call chwrit2(1,ich,1,rch,0,sch,0,iOK)
sch(1:1)=' '
call chwrit2(1,ich,0,rch,0,sch,1,iOK)
EndFile(1)
close(1)
lOpened=.true.
end Subroutine SaveProject
Subroutine OpenProject(lCheck,lOpened)
! read Project data from a file
Implicit none
Logical, intent(in) :: lCheck
Logical lFileExist,lOpened
Integer(4) iOk,ios,iVers,idum
Character(20) text
lOpened=.false.
if(.not.lCheck) then
call Open2read(-1,'Select Project data file to be read!','Project data file ',ProFileName,'PRO',ios)
if(ios.gt.0) return
end if
inquire(file=ProFileName,Exist=lFileExist)
if(.not.lFileExist) return
open(1,file=ProFileName,status='old',iostat=ios)
if(ios.ne.0) then
idum=MessageBoxQQ('Error opening file!\rCannot read data!'C,'Open project'C, &
MB$OK.or.MB$IconExclamation)
close(1)
return
end if
call ReadStr(1,text,iOK)
if(CHProIdent(1:15).ne.text(1:15)) then
idum=MessageBoxQQ('Wrong file Type!\rContinue reading?'C,'Open project'C, &
MB$YesNo.or.MB$IconQuestion)
if(idum.eq.MB$IDNO) then
close(1)
return
end if
end if
call StrToInt(text(16:16)//text(18:18),iVers,iOK)
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(frequency/time dependence)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
lfcFld=.false.
if(ich(1).ne.0) lfcFld=.true.
if((iVers.gt.30).or.lfcFld) then
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(frequency)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
fcFld=DCmplx(rch(1),rch(2))
end if
call chread2(1,ich,2,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(2D/3D)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
iHEGlobal=Int2(ich(2))
lgcFld=.false.
if(ich(1).ne.0) then
lgcFld=.true.
call chread2(1,ich,0,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(gamma)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
if(rch(2).gt.pBig) then
lzPer=.true.
dcFld=DCmplx(rch(1),0.0d0)
gcFld=0.5d0/(dcFld*fcFld*kw0)
else
lzPer=.false.
gcFld=DCmplx(rch(1),rch(2))
dcFld=0.5d0/(gcFld*fcFld*kw0)
end if
end if
lxPeriod=.false.
lyPeriod=.false.
lzPeriod=.false.
lregularPeriod=.true.
if(iVers.gt.19) then
call chread2(1,ich,3,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Periodic Y/N)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
if(ich(1).ne.0) lxPeriod=.true.
if(ich(1).lt.0) lregularPeriod=.false.
if(ich(2).ne.0) lyPeriod=.true.
if(ich(3).ne.0) lzPeriod=.true.
if(lxPeriod.or.lyPeriod.or.lzPeriod) then
call chread2(1,ich,0,rch,6,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Period)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
xPeriod=rch(1)
yPeriodVector(1:2)=rch(2:3)
yPeriodVector(3)=0.0d0
zPeriodVector(1:3)=rch(4:6)
call chread2(1,ich,0,rch,6,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Period)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
cxPeriod=DCmplx(rch(1),rch(2))
cyPeriod=DCmplx(rch(3),rch(4))
czPeriod=DCmplx(rch(5),rch(6))
CxPeriodDlg=CxPeriod
CyPeriodDlg=CyPeriod
CzPeriodDlg=CzPeriod
end if
else
call chread2(1,ich,2,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Periodic Y/N)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
if(ich(1).ne.0) lxPeriod=.true.
if(ich(1).lt.0) lregularPeriod=.false.
if(ich(2).ne.0) lyPeriod=.true.
if(lxPeriod.or.lyPeriod.or.lzPeriod) then
call chread2(1,ich,0,rch,6,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Period)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
xPeriod=rch(1)
yPeriodVector(1)=0.0d0
yPeriodVector(2)=rch(2)
yPeriodVector(3)=0.0d0
zPeriodVector(1)=0.0d0
zPeriodVector(2)=0.0d0
zPeriodVector(3)=1.0d0
cxPeriod=DCmplx(rch(3),rch(4))
cyPeriod=DCmplx(rch(5),rch(6))
czPeriod=(0.0d0,0.0d0)
CxPeriodDlg=CxPeriod
CyPeriodDlg=CyPeriod
CzPeriodDlg=CzPeriod
end if
end if
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Eigenvalue Y/N)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
lEigen=.false.
if(ich(1).ne.0) then
lEigen=.true.
call chread2(1,ich,2,rch,0,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Eigenvalue type)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
iEigen=ich(1)
lEigenSave=.false.
lWriteRoughFld=.true.
if((ich(2).eq.1).or.(ich(2).gt.2)) lEigenSave=.true.
if(ich(2).gt.1) lWriteRoughFld=.false.
call chread2(1,ich,2,rch,4,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Rough search data)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
nrEigen=ich(1)
niEigen=ich(2)
c1Eigen=DCmplx(rch(1),rch(2))
c2Eigen=DCmplx(rch(3),rch(4))
c1EigenC=DCmplx(min(rch(1),rch(3)),min(rch(2),rch(4)))
c2EigenC=DCmplx(max(rch(1),rch(3)),max(rch(2),rch(4)))
call chread2(1,ich,2,rch,2,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Fine search data)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
imEigen=min(100,ich(1))
itmEigen=ich(2)
aEigen=rch(1)
fEigen=rch(2)
if(iVers.gt.20) then
call chread2(1,ich,0,rch,4,iOK)
if(iOK.ne.0) then
idum=MessageBoxQQ('Error reading input file!\r(Fine search clip)'C,'Open project'C, &
MB$OK.or.MB$ICONSTOP)
close(1)
return
end if
c1EigenC=DCmplx(min(rch(1),rch(3)),min(rch(2),rch(4)))
c2EigenC=DCmplx(max(rch(1),rch(3)),max(rch(2),rch(4)))
end if
end if
call chread2(1,ich,3,rch,0,iOK)
if(iOK.ne.0) ich(1:3)=0
ixySymm=ich(1)
ixzSymm=ich(2)
iyzSymm=ich(3)
call chread2(1,ich,1,rch,0,iOK)
if(iOK.ne.0) ich(1)=7
iWriteDigits=Int2(ich(1))
close(1)
lMMPstat=.false.
if((cdAbs(fcFld).lt.pSmall).or.(.not.lfcFld)) lMMPstat=.true.
lOpened=.true.
end Subroutine OpenProject
Complex(8) function cDrudeLorentz(x,c,e,omd,gamd,de,oml,gaml)
Implicit none
Integer(4) l,iErr2
Real(8) x,e,omd,gamd,de,oml,gaml
Character(1) c
Character(256) sch
cDrudeLorentz=(0.0d0,0.0d0)
cCForm(0)=(0.0d0,1.0d0)
pCForm(0)=(1.0d0,0.0d0)
vCForm(0)=DCmplx(1.0d0,0.0d0)
vCForm(1)=DCmplx(x,0.0d0)
vCForm(2)=DCmplx(e,0.0d0)
vCForm(3)=DCmplx(omd,0.0d0)
vCForm(4)=DCmplx(gamd,0.0d0)
vCForm(5)=DCmplx(de,0.0d0)
vCForm(6)=DCmplx(oml,0.0d0)
vCForm(7)=DCmplx(gaml,0.0d0)
sch='dlf(v1,v2,v3,v4,v5,v6,v7)'C
sch(3:3)=c(1:1)
l=25
cFormu=cFormula(sch,l,cCForm,pCForm,vCForm,0,0,7,1,1,1,iErr2)
if(iErr2.eq.0) cDrudeLorentz=cFormu(1)
end function cDrudeLorentz
END MODULE CHDOM