FireDynamics / fdsreader

Python reader for FDS data
GNU General Public License v3.0
44 stars 18 forks source link

Issue and fix for reading data from meshes of same ID #63

Closed dushyant-fire closed 1 year ago

dushyant-fire commented 1 year ago

Hello, I came across the issue where fdsreader was reading only the first mesh from 9 meshes. These meshes were created by the following FDS input (a simpler FDS input shown here that recreated the error),

&MESH ID='MESH1', IJK=30,10,33,  XB=-0.3,0.3,0.0,0.1,-0.04,0.62, MULT_ID='multy'/ !2cm, 1cm, 2cm
&MULT ID='multy', DY=0.1, DZ = 0.66, J_UPPER=1, K_UPPER=3/

However, I accidentally left the ID on &MESH (as shown here) and by doing that, FDS created all meshes with the same ID. It seems that fdsreader was having trouble with reading the output data from these meshes. It was likely because of this line in slice.py

if mesh_data["mesh"].id not in self._subslices:

which only takes unique mesh_ids. I fixed this by appending a string at the end of the mesh_id if the mesh_id repeats. I updated the simulation.py, by first instantiating self.mesh_count in __init__() and added the following in _load_mesh method,

mesh_id = "".join(line.split()[1:]) # Existing line in fdsreader
mesh_ids = [mesh_data.id for mesh_data in self._meshes]   # Creating a list of mesh_ids so far read
if mesh_id in mesh_ids: # checking for repeated mesh_ids
     # print('Duplicate Mesh IDS, renaming mesh IDs')
     mesh_id = mesh_id +str(self.mesh_count) # renaming the mesh_id if ids repeats. Appends the number of the corresponding mesh where ID repeats
self.mesh_count +=1

Let me know if you want me to push the changes.

Thanks, Dushyant

JanVogelsang commented 1 year ago

Although I would personally think this is a bug in FDS and not the reader (as an identifier should always be unique), I think it is easier for us to fix the problem in the reader, which also has the advantage of enabling backwards compatibility.
I'll look into the issue and see if your solution covers all cases.

JanVogelsang commented 1 year ago

Implemented in 1.9.10