mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Can read unstructured mesh from statepoint now.
This commit is contained in:
parent
4f5b8e8034
commit
8cdbedf674
2 changed files with 24 additions and 5 deletions
|
|
@ -605,8 +605,12 @@ class UnstructuredMesh(MeshBase):
|
|||
Unique identifier for the mesh
|
||||
name : str
|
||||
Name of the mesh
|
||||
filename : str
|
||||
mesh_file : str
|
||||
Name of the file containing the unstructured mesh
|
||||
volumes : Iterable of float
|
||||
Volumes of the unstructured mesh elements
|
||||
total_volume : float
|
||||
Volume of the unstructured mesh in total
|
||||
"""
|
||||
|
||||
def __init__(self, mesh_id=None, name='', filename=''):
|
||||
|
|
@ -626,6 +630,19 @@ class UnstructuredMesh(MeshBase):
|
|||
else:
|
||||
self.filename = ''
|
||||
|
||||
@property
|
||||
def volumes(self):
|
||||
return self._volumes
|
||||
|
||||
@volumes.setter
|
||||
def volumes(self, volumes):
|
||||
cv.check_type("Unstructured mesh volumes", volumes, Iterable, Real)
|
||||
self._volumes = volumes
|
||||
|
||||
@property
|
||||
def total_volume(self):
|
||||
return np.sum(self.volumes)
|
||||
|
||||
def __repr__(self):
|
||||
string = super().__repr__()
|
||||
string += '{0: <16}{1}{2}\n'.format('\tFilename', '=\t', self.filename)
|
||||
|
|
@ -636,7 +653,10 @@ class UnstructuredMesh(MeshBase):
|
|||
mesh_id = int(group.name.split('/')[-1].lstrip('mesh '))
|
||||
|
||||
mesh = cls(mesh_id)
|
||||
mesh = group['filename']
|
||||
mesh.filename = group['filename'][()].decode()
|
||||
mesh.volumes = group['volumes'][()]
|
||||
|
||||
return mesh
|
||||
|
||||
def to_xml_element(self):
|
||||
"""Return XML representation of the mesh
|
||||
|
|
|
|||
|
|
@ -1864,15 +1864,14 @@ UnstructuredMesh::to_hdf5(hid_t group) const
|
|||
hid_t mesh_group = create_group(group, "mesh " + std::to_string(id_));
|
||||
|
||||
write_dataset(mesh_group, "type", "unstructured");
|
||||
write_dataset(mesh_group, "filename", filename_);
|
||||
|
||||
// write volume of each tet
|
||||
std::vector<double> tet_vols;
|
||||
for (const auto& eh : ehs_) {
|
||||
tet_vols.emplace_back(tet_volume(eh));
|
||||
}
|
||||
write_dataset(mesh_group, "volumes", tet_vols);
|
||||
// and the total volume of the mesh
|
||||
auto total_vol = std::accumulate(tet_vols.begin(), tet_vols.end(), 0.0);
|
||||
write_dataset(mesh_group, "total_volume", total_vol);
|
||||
|
||||
close_group(mesh_group);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue