@@ -4,7 +4,7 @@ module smbjson
44 use NFDETypes
55
66 use NFDETypes_extension
7- use labels_mod
7+ use smbjson_labels_mod
88 use mesh_mod
99 use parser_tools_mod
1010 use idchildtable_mod
@@ -30,7 +30,6 @@ module smbjson
3030
3131 contains
3232 procedure :: readProblemDescription
33- procedure :: initializeJson
3433
3534 ! private
3635 procedure :: readGeneral
@@ -93,112 +92,96 @@ function parser_ctor(filename) result(res)
9392 type (parser_t) :: res
9493 character (len=* ), intent (in ) :: filename
9594 res% filename = filename
96- end function
97-
98- subroutine initializeJson (this )
99- class(parser_t) :: this
100- integer :: stat
101-
102- allocate (this% jsonfile)
103- call this% jsonfile% initialize()
104- if (this% jsonfile% failed()) then
105- call this% jsonfile% print_error_message(error_unit)
95+
96+ allocate (res% jsonfile)
97+ call res% jsonfile% initialize()
98+ if (res% jsonfile% failed()) then
99+ call res% jsonfile% print_error_message(error_unit)
106100 return
107101 end if
108102
109- call this % jsonfile% load(filename = this % filename)
110- if (this % jsonfile% failed()) then
111- call this % jsonfile% print_error_message(error_unit)
103+ call res % jsonfile% load(filename = res % filename)
104+ if (res % jsonfile% failed()) then
105+ call res % jsonfile% print_error_message(error_unit)
112106 return
113107 end if
114108
115- allocate (this % core)
116- call this % jsonfile% get_core(this % core)
117- call this % jsonfile% get(' .' , this % root)
118- end subroutine
109+ allocate (res % core)
110+ call res % jsonfile% get_core(res % core)
111+ call res % jsonfile% get(' .' , res % root)
112+ end function
119113
120114 function readProblemDescription (this ) result (res)
121115 class(parser_t) :: this
122116 type (Parseador) :: res
123117 integer :: stat
124118
125- allocate (this% jsonfile)
126- call this% jsonfile% initialize()
127- if (this% jsonfile% failed()) then
128- call this% jsonfile% print_error_message(error_unit)
129- return
130- end if
131-
132- call this% jsonfile% load(filename = this% filename)
133- if (this% jsonfile% failed()) then
134- call this% jsonfile% print_error_message(error_unit)
135- return
136- end if
137-
138- allocate (this% core)
139- call this% jsonfile% get_core(this% core)
140- call this% jsonfile% get(' .' , this% root)
141-
142119 this% mesh = this% readMesh()
143120 this% matTable = IdChildTable_t(this% core, this% root, J_MATERIALS)
144-
121+
145122 call initializeProblemDescription(res)
146-
123+
147124 ! Basics
148125 res% general = this% readGeneral()
149126 res% matriz = this% readMediaMatrix()
150127 res% despl = this% readGrid()
151128 res% front = this% readBoundary()
152-
129+
153130 ! Materials
154131 res% pecRegs = this% readPECRegions()
155132 res% pmcRegs = this% readPMCRegions()
156-
133+
157134 ! Sources
158135 res% plnSrc = this% readPlanewaves()
159136 res% nodSrc = this% readNodalSources()
160-
137+
161138 ! Probes
162139 res% oldSonda = this% readProbes()
163140 res% sonda = this% readMoreProbes()
164141 res% BloquePrb = this% readBlockProbes()
165142 res% VolPrb = this% readVolumicProbes()
166-
143+
167144 ! Thin elements
168145 res% tWires = this% readThinWires()
169146 res% mtln = this% readMTLN(res% despl)
170147
171- ! Cleanup
172- call this% core% destroy()
173- call this% jsonfile% destroy()
174- nullify(this% root)
148+ ! ! Cleanup
149+ ! call this%core%destroy()
150+ ! call this%jsonfile%destroy()
151+ ! nullify(this%root)
175152
176153 end function
177154
178155 function readMesh (this ) result(res)
179156 class(parser_t) :: this
180157 type (Mesh_t) :: res
181- type (json_value), pointer :: jcs, jc
182- integer :: id, i
183- real , dimension (:), allocatable :: pos
184- type (coordinate_t) :: c
185- integer :: stat
186- logical :: found
187-
188- call this% core% get(this% root, J_MESH// ' .' // J_COORDINATES, jcs, found= found)
189- if (found) then
190- call res% allocateCoordinates(10 * this% core% count (jcs))
191- do i = 1 , this% core% count (jcs)
192- call this% core% get_child(jcs, i, jc)
193- call this% core% get(jc, J_ID, id)
194- call this% core% get(jc, J_COORDINATE_POS, pos)
195- c% position = pos
196- call res% addCoordinate(id, c)
197- end do
198- end if
158+ call addCoordinates(res)
199159 call addElements(res)
200160
201161 contains
162+ subroutine addCoordinates (mesh )
163+ type (mesh_t), intent (inout ) :: mesh
164+ type (json_value), pointer :: jcs, jc
165+ integer :: id, i
166+ real , dimension (:), allocatable :: pos
167+ type (coordinate_t) :: c
168+ integer :: numberOfCoordinates
169+ logical :: found
170+
171+ call this% core% get(this% root, J_MESH// ' .' // J_COORDINATES, jcs, found= found)
172+ if (found) then
173+ numberOfCoordinates = this% core% count (jcs)
174+ call res% allocateCoordinates(10 * numberOfCoordinates)
175+ do i = 1 , numberOfCoordinates
176+ call this% core% get_child(jcs, i, jc)
177+ call this% core% get(jc, J_ID, id)
178+ call this% core% get(jc, J_COORDINATE_POS, pos)
179+ c% position = pos
180+ call mesh% addCoordinate(id, c)
181+ end do
182+ end if
183+ end subroutine
184+
202185 subroutine addElements (mesh )
203186 type (mesh_t), intent (inout ) :: mesh
204187 character (len= :), allocatable :: elementType
@@ -207,10 +190,15 @@ subroutine addElements(mesh)
207190 type (node_t) :: node
208191 type (polyline_t) :: polyline
209192 integer , dimension (:), allocatable :: coordIds
193+ integer :: numberOfElements
210194 logical :: found
195+
211196 call this% core% get(this% root, J_MESH// ' .' // J_ELEMENTS, jes, found= found)
197+ numberOfElements = this% core% count (jes)
198+ call res% allocateElements(10 * numberOfElements)
199+
212200 if (found) then
213- do i = 1 , this % core % count (jes)
201+ do i = 1 , numberOfElements
214202 call this% core% get_child(jes, i, je)
215203 call this% core% get(je, J_ID, id)
216204 call this% core% get(je, J_TYPE, elementType)
@@ -985,19 +973,13 @@ function readVolProbe(p) result(res)
985973 cs = cellIntervalsToCoords(cRs(1 )% intervals)
986974
987975 fieldType = this% getStrAt(p, J_FIELD, default= J_FIELD_ELECTRIC)
988- call this% core% get(p, J_PR_MOVIE_COMPONENTS, compsPtr, found= componentsFound)
976+ call this% core% get(p, J_PR_MOVIE_COMPONENT, compsPtr, found= componentsFound)
977+ allocate (res% cordinates(1 ))
989978 if (componentsFound) then
990- numberOfComponents = this% core% count (compsPtr)
991- allocate (res% cordinates(numberOfComponents))
992- do i = 1 , numberOfComponents
993- call this% core% get_child(compsPtr, i, compPtr)
994- call this% core% get(compPtr, component)
995- res% cordinates(i) = cs(1 )
996- res% cordinates(i)% Or = buildVolProbeType(fieldType, component)
997- end do
998- else
999- allocate (res% cordinates(1 ))
979+ call this% core% get(compsPtr, component)
1000980 res% cordinates(1 ) = cs(1 )
981+ res% cordinates(1 )% Or = buildVolProbeType(fieldType, component)
982+ else
1001983 component = J_DIR_M
1002984 res% cordinates(1 )% Or = buildVolProbeType(fieldType, component)
1003985 endif
0 commit comments