Crate polymesh_rw

Source
Expand description

§polymesh_rw

polymesh_rw is a library for reading and writing meshes and simulation data in the OpenFOAM polyMesh file format. Full case files can be read to a Case struct, which contains the mesh and all time directories.

use polymesh_rw::*;
  let case_file_path = std::path::Path::new("tests/test_cases/original/cylinder");
  let mut case = Case::parse_file(case_file_path)?;

The data in a case struct is separated in a polymesh structure which stores the mesh, and a time_directories structure which stores the simulation data. For example, the boundary conditions which are located in the constant/polyMesh/boundary file will be found in case.polymesh.boundary.

  let boundary = &mut case.polymesh.boundary;

Data files are stored in FileContent structs, which contain the metadata (header) and data of the file. The structure also allows to parse and write files individually.

   let boundary_file_path = &case_file_path.join("constant/polyMesh/boundary");
   let boundary_2 = FileContent::<BoundaryData>::parse_file(&boundary_file_path)?;
   assert_eq!(*boundary, boundary_2);

All the data and metadata containers implement std::fmt::Debug, so they can be printed to the console.

   println!("{}", boundary);

The underlying data is stored in two different ways: either as HashMaps or a Vectors. The wrappers around these data types, which provide parsing and writing functionality, also implement Deref and DerefMut for easy manipulation. Inside of the FoamStructures (HashMaps) the data is stored as FoamValues, which indicate the type of the data:

  • String
  • Float
  • Integer
  • List
  • Structure
  let FoamValue::Structure(ref mut down_bc) = boundary
      .data
      .get_mut("down")
      .expect("\"down\" boundary condition not found.")
  else {
      panic!("\"down\" boundary condition is not a structure.");
  };
  println!("{}", down_bc);
  *down_bc.get_mut("type").unwrap() = FoamValue::String("fixedValue".to_string());
  println!("{}", down_bc);

Files can be written using the write_file method, which writes the data to the provided path. In the following example, the full case is written to a new directory.

   let modified_case_file_path = std::path::Path::new("tests/test_cases/copy/cylinder");
   case.write_file(modified_case_file_path)?;

We can also choose to write only the boundary file, which is a part of the full case.

   let modified_case_file_path = std::path::Path::new("tests/test_cases/copy/cylinder");
    boundary.write_file(modified_case_file_path)?;

We still provide the path to the case directory, but the file will be written to the correct location inside the case directory. If the relative location needs to be changed, it can be done by assigning the correct relative path to the boundary.meta.location field (relative to the case directory).

Structs§

BoundaryData
The BoundaryData structure holds the data of a polyMesh/boundary file.
Case
The Case structure holds the mesh and results found in a case directory.
CellZone
The CellZone structure containts the data of a single cellZone.
FaceData
The FaceData structure holds the data of a polyMesh/faces file.
FaceZone
Container for the data of a single faceZone.
FileContent
The FileContent structure holds the full content of a file. The file content is divided into two parts:
FoamFile
The FoamFile structure holds the FoamFile object that is part of the header of a file. It is effectively a HashMap with some extra I/O functionalities.
FoamStructure
A structure that holds key-value pairs. It is effectively a HashMap with some extra I/O functionalities. Correspons to structures commonly found in OpenFOAM files, such as the following part of a uniform/time file:
NeighbourData
The NeighbourData structure holds the data of a polyMesh/neighbour file.
OwnerData
The OwnerData structure holds the data of a polyMesh/owner file.
PointData
The PointData structure holds the data of a polyMesh/points file.
PointZone
The PointZone structure containts the data of a single pointZone.
PolyMesh
Data-containing structures The PolyMesh structure holds all the data of a polyMesh directory.
ResultData
The ResultData structure holds the data of a time directory file, e.g., “0/phi”.
Set
The Set structure containts the data of a single set file found in the “constant/polyMesh/sets/” directory.
Sets
The Sets structure holds the full content of the “constant/polyMesh/sets” directory.
TimeDir
The structure that holds the full content of a time directory, which is where simulation results are stored.
UniformData
The UniformData structure holds the data of a polyMesh/uniform file.
ZoneData
Container for the polyMesh Zones data, e.g. cellZones, faceZones and pointZones.

Enums§

FoamField
An enumerator that holds the different types of physical fields that can be found in OpenFOAM files.
FoamValue
An enumerator that holds the different types of values (usually paired to keys) that can be found in OpenFOAM files.

Traits§

Zone
A trait for the different types of zones, e.g. cellZones, faceZones and pointZones.