Skip to content

Commit a16bc9f

Browse files
Merge pull request #224 from OpenSEMBA/fix-for-ugrfdtd
Fix current slice
2 parents da55fba + ed4850d commit a16bc9f

File tree

8 files changed

+245
-121
lines changed

8 files changed

+245
-121
lines changed

src_main_pub/observation.F90

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

src_main_pub/semba_fdtd.F90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ subroutine semba_init(this, input_flags)
313313
call initialize_MPI_process(this%l%filefde,this%l%extension)
314314
#else
315315
#ifdef CompilePrivateVersion
316-
NFDE_FILE => cargar_NFDE_FILE (this%l%filefde)
316+
if (trim(adjustl(this%l%extension))=='.nfde') then
317+
NFDE_FILE => cargar_NFDE_FILE (this%l%filefde)
318+
else
319+
allocate (NFDE_FILE)
320+
endif
317321
#else
318322
allocate (NFDE_FILE)
319323
#endif
@@ -331,8 +335,6 @@ subroutine semba_init(this, input_flags)
331335
this%l%chain2=trim(adjustl(chaindummy))//' '//trim(adjustl(this%sgg%extraswitches))//' '//trim(adjustl(this%l%chain2(this%l%length+1:)))
332336
this%l%chaininput=trim(adjustl(this%l%chain2))
333337
!!!!
334-
335-
336338
call interpreta(this%l,status )
337339
this%sgg%nEntradaRoot=trim (adjustl(this%l%nEntradaRoot))
338340

src_main_pub/vtk.F90

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
2525
!------------------------>
2626
CHARACTER (LEN=BUFSIZE) :: filename ! File name
2727
CHARACTER (LEN=BUFSIZE) :: fichero,fichero_input,char_i_sub_time ! File name
28-
!
28+
integer (kind=4) :: k
29+
character (len=32), dimension(3) :: suffFile = (/'_current.vtk', '_efield.vtk ', '_hfield.vtk '/)
30+
character (len=3), dimension (3) :: suffTag = (/'cu', 'ef', 'hf'/)
2931
!
3032
!
3133

@@ -66,6 +68,7 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
6668
real (kind= RKIND), allocatable, dimension(:,:) :: Nodes
6769
integer (kind=4), allocatable, dimension(:,:) :: Elems
6870
integer (kind=4) :: coldummy
71+
integer (kind=4), dimension(5) :: volumicCurrentFlags = [iCur, iCurX, iCurY, iCurZ, mapvtk]
6972
! print *,'RKIND,CKIND,REALSIZE,COMPLEXSIZE,MPI_DOUBLE_PRECISION, MPI_DOUBLE_COMPLEX',RKIND,CKIND,REALSIZE,COMPLEXSIZE,MPI_DOUBLE_PRECISION, MPI_DOUBLE_COMPLEX
7073
yacreado=.false.
7174
numNodes=0; numEdges=0;numQuads=0;
@@ -77,35 +80,30 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
7780
!
7881
somethingdone=.false.
7982
barridoprobes: DO ii = 1, sgg%NumberRequest
80-
81-
IF (sgg%observation(ii)%Volumic) then
82-
if (sgg%observation(ii)%nP == 1) then
83-
if ((sgg%observation(ii)%P(1)%What == iCur).or.(sgg%observation(ii)%P(1)%What == iCurX).or. &
84-
(sgg%observation(ii)%P(1)%What == iCurY).or.(sgg%observation(ii)%P(1)%What == iCurZ).or. &
85-
(sgg%observation(ii)%P(1)%What == mapvtk)) THEN !solo corrientes volumicas
86-
if (sgg%Observation(ii)%done.and.(sgg%Observation(ii)%flushed)) then
83+
IF ((sgg%observation(ii)%Volumic) .and. (sgg%observation(ii)%nP == 1)) then
84+
if (any(sgg%observation(ii)%P(1)%What == volumicCurrentFlags)) then
85+
if (sgg%Observation(ii)%done) then
86+
if (sgg%Observation(ii)%flushed) then
8787
cycle barridoprobes
88-
elseif (sgg%Observation(ii)%done) then
89-
sgg%Observation(ii)%flushed=.true. !ultima que se flushea
88+
else
89+
sgg%Observation(ii)%flushed=.true.
9090
continue
91-
elseif ((.not.(sgg%Observation(ii)%done)).and.(sgg%Observation(ii)%Begun)) then
91+
endif
92+
else
93+
if (sgg%Observation(ii)%Begun) then
9294
continue
93-
elseif (.not.(sgg%Observation(ii)%begun)) then
95+
else
9496
cycle barridoprobes
95-
else !creo que tengo toda la casuistica, por si se me escapa algo continuo, y ya debajo se manejara
96-
continue
9797
endif
98+
endif
9899
else
99100
cycle barridoprobes
100101
endif
101-
endif
102102
endif
103103
!sondas Volumic traducelas a VTK
104104
IF (sgg%observation(ii)%Volumic) then
105105
if (sgg%observation(ii)%nP == 1) then
106-
if ((sgg%observation(ii)%P(1)%What == iCur).or.(sgg%observation(ii)%P(1)%What == iCurX).or. &
107-
(sgg%observation(ii)%P(1)%What == iCurY).or.(sgg%observation(ii)%P(1)%What == iCurZ).or. &
108-
(sgg%observation(ii)%P(1)%What == mapvtk)) THEN !solo corrientes volumicas
106+
if (any(sgg%observation(ii)%P(1)%What == volumicCurrentFlags)) then
109107
INQUIRE (FILE=trim(adjustl(output(ii)%item(1)%path)), EXIST=lexis)
110108
if ((lexis).and.(output(ii)%TimesWritten/=0)) then
111109
!
@@ -163,15 +161,6 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
163161
endif
164162
endif
165163
#endif
166-
167-
168-
!!! OPEN (output(ii)%item(1)%UNIT, FILE=trim(adjustl(output(ii)%item(1)%path)), &
169-
!!! FORM='unformatted')
170-
!!! DO
171-
!!! READ (output(ii)%item(1)%UNIT, end=762) finalstep
172-
!!! END DO
173-
!!!762 CONTINUE
174-
!!! CLOSE (output(ii)%item(1)%UNIT)
175164
finalstep=output(ii)%TimesWritten
176165
allocate (att(1:finalstep))
177166
!!!!!!!!!!!!!
@@ -495,15 +484,7 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
495484
READ (output(ii)%item(1)%UNIT) &
496485
Serialized%valorComplex_x(1,posicionMPI+conta), &
497486
Serialized%valorComplex_y(1,posicionMPI+conta), &
498-
Serialized%valorComplex_z(1,posicionMPI+conta) !lo meto en el unico step
499-
READ (output(ii)%item(1)%UNIT) &
500-
Serialized%valorComplex_Ex(1,posicionMPI+conta), &
501-
Serialized%valorComplex_Ey(1,posicionMPI+conta), &
502-
Serialized%valorComplex_Ez(1,posicionMPI+conta) !lo meto en el unico step
503-
READ (output(ii)%item(1)%UNIT) &
504-
Serialized%valorComplex_Hx(1,posicionMPI+conta), &
505-
Serialized%valorComplex_Hy(1,posicionMPI+conta), &
506-
Serialized%valorComplex_Hz(1,posicionMPI+conta) !lo meto en el unico step
487+
Serialized%valorComplex_z(1,posicionMPI+conta)
507488
end do
508489
endif
509490

@@ -848,30 +829,23 @@ SUBROUTINE createVTK (layoutnumber, size, sgg,vtkindex,somethingdone,mpidir,tagt
848829
else
849830
if (freqDomain) then
850831
total_sub_times=time_phases_param
851-
do i_sub_time=0,total_sub_times
852-
write (char_i_sub_time,'(i3)') i_sub_time
853-
fichero_input=fichero(1:iroot1-1)//'_n_'//trim(adjustl(char_i_sub_time))//'_current.vtk'
854-
CALL write_VTKfile(sgg,fichero_input,iroot2, Serialized, numberOfSerialized,Nodes,Numnodes,Elems,NumEdges,NumQuads,time, &
855-
i_sub_time,total_sub_times,freqDomain,sgg%observation(ii)%P(1)%What,sggMtag,'cu')
856-
write(dubuf,'(a,i9,a,i9)') trim(adjustl(whoamishort))//' -------> Dumped frequency phase file '//trim(adjustl(fichero_input))//', ',i_sub_time,'/',total_sub_times
857-
call print11(layoutnumber,dubuf,.true.)
858-
!electric
832+
do i_sub_time = 0, total_sub_times
833+
write(char_i_sub_time,'(i3)') i_sub_time
834+
do k = 1, 3
835+
fichero_input = fichero(1:iroot1-1)//'_n_'//trim(adjustl(char_i_sub_time))//suffFile(k)
836+
837+
CALL write_VTKfile( sgg, fichero_input, iroot2, Serialized, numberOfSerialized, &
838+
Nodes, Numnodes, Elems, NumEdges, NumQuads, time, &
839+
i_sub_time, total_sub_times, freqDomain, sgg%observation(ii)%P(1)%What, sggMtag, &
840+
suffTag(k) )
841+
842+
write(dubuf,'(a,i9,a,i9)') trim(adjustl(whoamishort))//' -------> Dumped frequency phase file '// &
843+
trim(adjustl(fichero_input))//', ', i_sub_time, '/', total_sub_times
844+
call print11(layoutnumber, dubuf, .true.)
845+
end do
859846

860-
fichero_input=fichero(1:iroot1-1)//'_n_'//trim(adjustl(char_i_sub_time))//'_efield.vtk'
861-
CALL write_VTKfile(sgg,fichero_input,iroot2, Serialized, numberOfSerialized,Nodes,Numnodes,Elems,NumEdges,NumQuads,time, &
862-
i_sub_time,total_sub_times,freqDomain,sgg%observation(ii)%P(1)%What,sggMtag,'ef')
863-
write(dubuf,'(a,i9,a,i9)') trim(adjustl(whoamishort))//' -------> Dumped frequency phase file '//trim(adjustl(fichero_input))//', ',i_sub_time,'/',total_sub_times
864-
call print11(layoutnumber,dubuf,.true.)
865-
!
866-
! magnetic
867-
868-
fichero_input=fichero(1:iroot1-1)//'_n_'//trim(adjustl(char_i_sub_time))//'_hfield.vtk'
869-
CALL write_VTKfile(sgg,fichero_input,iroot2, Serialized, numberOfSerialized,Nodes,Numnodes,Elems,NumEdges,NumQuads,time, &
870-
i_sub_time,total_sub_times,freqDomain,sgg%observation(ii)%P(1)%What,sggMtag,'hf')
871-
write(dubuf,'(a,i9,a,i9)') trim(adjustl(whoamishort))//' -------> Dumped frequency phase file '//trim(adjustl(fichero_input))//', ',i_sub_time,'/',total_sub_times
872-
call print11(layoutnumber,dubuf,.true.)
873-
!
874847
end do
848+
875849
else
876850
fichero_input=fichero(1:iroot1-1)//'_current.vtk'
877851
i_sub_time=-30 !cualquier cosa

test/pyWrapper/test_full_system.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ def test_sphere(tmp_path):
278278

279279
solver.run()
280280

281-
# semba-fdtd seems to always use the name Far for "far field" probes.
282-
far_field_probe_files = solver.getSolvedProbeFilenames("Far")
281+
far_field_probe_files = solver.getSolvedProbeFilenames("far")
283282
assert len(far_field_probe_files) == 1
284283
p = Probe(far_field_probe_files[0])
285284
assert p.type == 'farField'

test/pyWrapper/test_integration.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_sphere_case_with_far_field_probe_launches(tmp_path):
6161

6262
solver.run()
6363

64-
p = Probe(solver.getSolvedProbeFilenames("Far")[0])
64+
p = Probe(solver.getSolvedProbeFilenames("far")[0])
6565
assert p.case_name == 'sphere'
6666
assert p.type == 'farField'
6767
assert np.all(p.cell_init == np.array([2, 2, 2]))
@@ -71,6 +71,35 @@ def test_sphere_case_with_far_field_probe_launches(tmp_path):
7171
assert p.type == 'movie'
7272
assert np.all(p.cell_init == np.array([2, 2, 2]))
7373

74+
def test_movie_with_frequency_domain(tmp_path):
75+
fn = CASES_FOLDER + 'observation/movieFrequency.fdtd.json'
76+
solver = FDTD(fn, path_to_exe=SEMBA_EXE, run_in_folder=tmp_path)
77+
solver['general']['numberOfSteps'] = 100
78+
solver['general']['timeStep'] = 2.0e-9
79+
solver['probes'][0]['domain']['numberOfFrequencies'] = 100
80+
81+
solver.run()
82+
83+
p = Probe(solver.getSolvedProbeFilenames("movie_electric")[0])
84+
assert p.case_name == 'movieFrequency'
85+
assert p.type == 'movie'
86+
assert np.all(p.cell_init == np.array([1, 1, 1]))
87+
88+
def test_movie_with_time_domain(tmp_path):
89+
fn = CASES_FOLDER + 'observation/movieTime.fdtd.json'
90+
solver = FDTD(fn, path_to_exe=SEMBA_EXE, run_in_folder=tmp_path)
91+
solver['general']['numberOfSteps'] = 1
92+
solver['probes'][0]['domain']['samplingPeriod'] = 1e-9
93+
94+
solver.run()
95+
96+
p = Probe(solver.getSolvedProbeFilenames("movie_electric")[0])
97+
assert p.case_name == 'movieTime'
98+
assert p.type == 'movie'
99+
assert np.all(p.cell_init == np.array([1, 1, 1]))
100+
101+
102+
74103

75104
def test_three_surfaces(tmp_path):
76105
fn = CASES_FOLDER + 'observation/three_surfaces.fdtd.json'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"format": "FDTD Input file",
3+
"__comments": "Dummy case for movies with frequency domain",
4+
5+
"general": {
6+
"timeStep": 2.0e-9,
7+
"numberOfSteps": 100
8+
},
9+
10+
"boundary": {
11+
"all": {
12+
"type": "mur"
13+
}
14+
},
15+
16+
"mesh": {
17+
"grid": {
18+
"numberOfCells": [10, 20, 10],
19+
"steps": {"x": [0.1], "y": [0.1], "z": [0.1]}
20+
},
21+
22+
"coordinates": [
23+
],
24+
25+
"elements": [
26+
{"id": 1, "type": "cell", "name": "cube", "intervals": [ [ [2,4,2], [8, 10, 8] ] ]},
27+
{"id": 2, "type": "cell", "name": "movie-domain", "intervals": [ [[1, 1, 1], [9, 19, 9] ]]}
28+
]
29+
},
30+
31+
"materials": [
32+
{
33+
"id": 1,
34+
"name": "cube_material",
35+
"type": "pec"
36+
}
37+
],
38+
39+
"materialAssociations": [
40+
{
41+
"name": "cube_association",
42+
"elementIds": [1],
43+
"materialId": 1
44+
}
45+
],
46+
"probes": [
47+
{
48+
"name": "movie_electric",
49+
"type": "movie",
50+
"field": "electric",
51+
"component": "magnitude",
52+
"elementIds": [2],
53+
"domain": {
54+
"initialFrequency": 1e6,
55+
"finalFrequency": 2e6,
56+
"numberOfFrequencies": 3
57+
}
58+
}
59+
]
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"format": "FDTD Input file",
3+
"__comments": "Dummy case for movies with frequency domain",
4+
5+
"general": {
6+
"timeStep": 2.0e-9,
7+
"numberOfSteps": 100
8+
},
9+
10+
"boundary": {
11+
"all": {
12+
"type": "mur"
13+
}
14+
},
15+
16+
"mesh": {
17+
"grid": {
18+
"numberOfCells": [10, 20, 10],
19+
"steps": {"x": [0.1], "y": [0.1], "z": [0.1]}
20+
},
21+
22+
"coordinates": [
23+
],
24+
25+
"elements": [
26+
{"id": 1, "type": "cell", "name": "cube", "intervals": [ [ [2,4,2], [8, 10, 8] ] ]},
27+
{"id": 2, "type": "cell", "name": "movie-domain", "intervals": [ [[1, 1, 1], [9, 19, 9] ]]}
28+
]
29+
},
30+
31+
"materials": [
32+
{
33+
"id": 1,
34+
"name": "cube_material",
35+
"type": "pec"
36+
}
37+
],
38+
39+
"materialAssociations": [
40+
{
41+
"name": "cube_association",
42+
"elementIds": [1],
43+
"materialId": 1
44+
}
45+
],
46+
47+
"probes": [
48+
{
49+
"name": "movie_electric",
50+
"type": "movie",
51+
"field": "electric",
52+
"component": "magnitude",
53+
"elementIds": [2],
54+
"domain": {
55+
"type": "time",
56+
"samplingPeriod": 1e-9
57+
}
58+
}
59+
]
60+
}

testData/cases/sphere/sphere.fdtd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40928,7 +40928,7 @@
4092840928
],
4092940929
"probes": [
4093040930
{
40931-
"name": "FarField",
40931+
"name": "farfield",
4093240932
"type": "farField",
4093340933
"elementIds": [
4093440934
2

0 commit comments

Comments
 (0)