Skip to content

Commit 965bbc7

Browse files
Merge pull request #248 from OpenSEMBA/248-null-direction-for-volumic-bulk-probe
248 Fix null direction for volumic bulk probe
2 parents ec5bcc8 + 2889a08 commit 965bbc7

File tree

6 files changed

+1213
-1
lines changed

6 files changed

+1213
-1
lines changed

src_json_parser/smbjson.F90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,8 @@ function readBlockProbe(bp) result(res)
14301430
type(coords), dimension(:), allocatable :: cs
14311431
type(cell_region_t), dimension(:), allocatable :: cRs
14321432

1433+
character(len=1) :: direction
1434+
14331435
cRs = this%mesh%getCellRegions(this%getIntsAt(bp, J_ELEMENTIDS))
14341436
if (size(cRs) /= 1) then
14351437
call WarnErrReport("Bulk current probe must be defined by a single cell region.", .true.)
@@ -1447,6 +1449,15 @@ function readBlockProbe(bp) result(res)
14471449
res%k1 = cs(1)%zi
14481450
res%k2 = cs(1)%ze
14491451
res%nml = abs(cs(1)%Or)
1452+
if (res%nml == 0) then !DIR_NULL
1453+
direction = this%getStrAt(bp, J_DIR)
1454+
select case(trim(adjustl(direction)))
1455+
case(J_DIR_X); res%nml = 1 !DIR_X
1456+
case(J_DIR_Y); res%nml = 2 !DIR_Y
1457+
case(J_DIR_Z); res%nml = 3 !DIR_Z
1458+
case default; call WarnErrReport('Null direction detected for bulk probe. Check definition')
1459+
end select
1460+
end if
14501461

14511462
res%outputrequest = trim(adjustl(this%getStrAt(bp, J_NAME)))
14521463
call setDomain(res, this%getDomain(bp, J_PR_DOMAIN))

src_json_parser/smbjson_labels.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module smbjson_labels_mod
88
character (len=*), parameter :: J_TYPE = "type"
99
character (len=*), parameter :: J_ELEMENTIDS = "elementIds"
1010

11+
character (len=*), parameter :: J_DIR = "direction"
1112
character (len=*), parameter :: J_DIR_X = "x"
1213
character (len=*), parameter :: J_DIR_Y = "y"
1314
character (len=*), parameter :: J_DIR_Z = "z"

test/pyWrapper/test_full_system.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,35 @@ def test_negative_offset_in_x(tmp_path):
10241024

10251025
assert np.corrcoef(probeTotal['current'].to_numpy(), I_interp)[0, 1] > 0.999
10261026
assert np.corrcoef(probeL['current'].to_numpy(), I_interp)[0, 1] > 0.999
1027-
assert np.allclose(probeR['current'].to_numpy(), 0.0, atol=3e-3)
1027+
assert np.allclose(probeR['current'].to_numpy(), 0.0, atol=3e-3)
1028+
1029+
def test_bulk_current_outputs(tmp_path):
1030+
# This test uses bulk_probe_cases_over_nodal_source.fdtd from input_examples as input.
1031+
# Verifies all kind of bulk probes are recognised and setted properly by checking outputFile format.
1032+
fn = PROBES_INPUT_EXAMPLE + 'bulk_probe_cases_over_nodal_source.fdtd.json'
1033+
solver = FDTD(fn, path_to_exe=SEMBA_EXE, run_in_folder=tmp_path)
1034+
solver.run()
1035+
1036+
bulkXPlaneFiles = solver.getSolvedProbeFilenames("BulkXPlane")
1037+
bulkYPlaneFiles = solver.getSolvedProbeFilenames("BulkYPlane")
1038+
bulkZPlaneFiles = solver.getSolvedProbeFilenames("BulkZPlane")
1039+
bulkYPointFiles = solver.getSolvedProbeFilenames("BulkYPoint")
1040+
bulkZVolumeFiles = solver.getSolvedProbeFilenames("BulkZVolume")
1041+
1042+
assert len(bulkXPlaneFiles) == 1
1043+
assert len(bulkYPlaneFiles) == 1
1044+
assert len(bulkZPlaneFiles) == 1
1045+
assert len(bulkYPointFiles) == 1
1046+
assert len(bulkZVolumeFiles) == 10
1047+
1048+
probeBulkXPlane = Probe(bulkXPlaneFiles[0])
1049+
probeBulkYPlane = Probe(bulkYPlaneFiles[0])
1050+
probeBulkZPlane = Probe(bulkZPlaneFiles[0])
1051+
probeBulkYPoint = Probe(bulkYPointFiles[0])
1052+
probeBulkZVolume = Probe(bulkZVolumeFiles[0])
1053+
1054+
assert probeBulkXPlane.direction == 'x'
1055+
assert probeBulkYPlane.direction == 'y'
1056+
assert probeBulkZPlane.direction == 'z'
1057+
assert probeBulkYPoint.direction == 'y'
1058+
assert probeBulkZVolume.direction == 'z'

test/pyWrapper/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
OUTPUTS_FOLDER = os.path.join(TEST_DATA_FOLDER, 'outputs/')
4242
SPINIT_FOLDER = os.path.join(TEST_DATA_FOLDER, 'spinit/')
4343
GEOMETRIES_FOLDER = os.path.join(TEST_DATA_FOLDER, 'geometries/')
44+
PROBES_INPUT_EXAMPLE = os.path.join(TEST_DATA_FOLDER, 'input_examples/probes/')
4445

4546
def getCase(case):
4647
return json.load(open(CASES_FOLDER + case + '.fdtd.json'))
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
{
2+
"_format": "FDTD Input file",
3+
"general": {
4+
"timeStep": 3.0813e-12,
5+
"numberOfSteps": 1298
6+
},
7+
"boundary": {
8+
"all": {
9+
"type": "mur"
10+
}
11+
},
12+
"mesh": {
13+
"grid": {
14+
"numberOfCells": [
15+
30,
16+
30,
17+
30
18+
],
19+
"steps": {
20+
"x": [
21+
0.002
22+
],
23+
"y": [
24+
0.002
25+
],
26+
"z": [
27+
0.002
28+
]
29+
}
30+
},
31+
"coordinates": [
32+
{
33+
"id": 1,
34+
"relativePosition": [
35+
0.0,
36+
10.0,
37+
10.0
38+
]
39+
},
40+
{
41+
"id": 2,
42+
"relativePosition": [
43+
10.0,
44+
10.0,
45+
10.0
46+
]
47+
},
48+
{
49+
"id": 3,
50+
"relativePosition": [
51+
10.0,
52+
0.0,
53+
10.0
54+
]
55+
}
56+
],
57+
"elements": [
58+
{
59+
"id": 1,
60+
"type": "cell",
61+
"intervals": [
62+
[
63+
[
64+
0.0,
65+
20.0,
66+
20.0
67+
],
68+
[
69+
20.0,
70+
20.0,
71+
20.0
72+
]
73+
],
74+
[
75+
[
76+
20.0,
77+
20.0,
78+
20.0
79+
],
80+
[
81+
20.0,
82+
20.0,
83+
10.0
84+
]
85+
],
86+
[
87+
[
88+
20.0,
89+
20.0,
90+
10.0
91+
],
92+
[
93+
20.0,
94+
0.0,
95+
10.0
96+
]
97+
]
98+
]
99+
},
100+
{
101+
"id": 2,
102+
"type": "cell",
103+
"intervals": [
104+
[
105+
[
106+
10,
107+
19,
108+
19
109+
],
110+
[
111+
10,
112+
21,
113+
21
114+
]
115+
]
116+
]
117+
},
118+
{
119+
"id": 3,
120+
"type": "cell",
121+
"intervals": [
122+
[
123+
[
124+
19,
125+
10,
126+
9
127+
],
128+
[
129+
21,
130+
10,
131+
11
132+
]
133+
]
134+
]
135+
},
136+
{
137+
"id": 4,
138+
"type": "cell",
139+
"intervals": [
140+
[
141+
[
142+
19,
143+
19,
144+
14
145+
],
146+
[
147+
21,
148+
21,
149+
14
150+
]
151+
]
152+
]
153+
},
154+
{
155+
"id": 5,
156+
"type": "cell",
157+
"intervals": [
158+
[
159+
[
160+
20,
161+
20,
162+
20
163+
],
164+
[
165+
20,
166+
20,
167+
20
168+
]
169+
]
170+
]
171+
},
172+
{
173+
"id": 6,
174+
"type": "cell",
175+
"intervals": [
176+
[
177+
[
178+
15,
179+
15,
180+
15
181+
],
182+
[
183+
25,
184+
25,
185+
25
186+
]
187+
]
188+
]
189+
}
190+
]
191+
},
192+
"materials": [],
193+
"materialAssociations": [],
194+
"sources": [
195+
{
196+
"name": "nodalSource",
197+
"type": "nodalSource",
198+
"magnitudeFile": "predefinedExcitation.1.exc",
199+
"elementIds": [
200+
1
201+
]
202+
}
203+
],
204+
"probes": [
205+
{
206+
"name": "BulkXPlane",
207+
"type": "bulkCurrent",
208+
"field": "electric",
209+
"elementIds": [
210+
2
211+
],
212+
"domain": {
213+
"type": "time"
214+
}
215+
},
216+
{
217+
"name": "BulkYPlane",
218+
"type": "bulkCurrent",
219+
"field": "electric",
220+
"elementIds": [
221+
3
222+
],
223+
"domain": {
224+
"type": "time"
225+
}
226+
},
227+
{
228+
"name": "BulkZPlane",
229+
"type": "bulkCurrent",
230+
"field": "electric",
231+
"elementIds": [
232+
4
233+
],
234+
"domain": {
235+
"type": "time"
236+
}
237+
},
238+
{
239+
"name": "BulkYPoint",
240+
"type": "bulkCurrent",
241+
"field": "electric",
242+
"elementIds": [
243+
5
244+
],
245+
"direction": "y",
246+
"domain": {
247+
"type": "time"
248+
}
249+
},
250+
{
251+
"name": "BulkZVolume",
252+
"type": "bulkCurrent",
253+
"field": "electric",
254+
"elementIds": [
255+
6
256+
],
257+
"direction": "z",
258+
"domain": {
259+
"type": "time"
260+
}
261+
}
262+
]
263+
}

0 commit comments

Comments
 (0)