conspire/geometry/mesh/write/
mod.rs1#[cfg(test)]
2mod test;
3
4pub(super) mod abaqus;
5pub(super) mod exodus;
6pub(super) mod medit;
7pub(super) mod vtk;
8
9use crate::{
10 geometry::mesh::Mesh,
11 io::{Write, write::Compression},
12};
13use std::{io::Error as ErrorIO, path::Path};
14
15use self::abaqus::WriteAbaqus;
16use self::exodus::{ExodusFormat, WriteExodus};
17use self::medit::WriteMedit;
18use self::vtk::{Vtk, multi_block::WriteVtkMultiBlock, unstructured::WriteVtkUnstructured};
19
20pub enum Output<P>
21where
22 P: AsRef<Path>,
23{
24 Abaqus(P),
25 Exodus(ExodusFormat<P>),
26 Medit(P),
27 Vtk(Vtk<P>),
28}
29
30impl<P> AsRef<Path> for Output<P>
31where
32 P: AsRef<Path>,
33{
34 fn as_ref(&self) -> &Path {
35 match self {
36 Output::Abaqus(path) => path.as_ref(),
37 Output::Exodus(format) => format.as_ref(),
38 Output::Medit(path) => path.as_ref(),
39 Output::Vtk(vtk) => vtk.as_ref(),
40 }
41 }
42}
43
44impl<const D: usize, P> Write<Output<P>> for Mesh<D>
45where
46 P: AsRef<Path>,
47{
48 type Error = ErrorIO;
49 fn write(&self, output: Output<P>) -> Result<(), Self::Error> {
50 match output {
51 Output::Abaqus(path) => self.write_abaqus(path)?,
52 Output::Exodus(ExodusFormat::Classic(path)) => self.write_exodus(path)?,
53 Output::Exodus(ExodusFormat::Netcdf4 { path, threads }) => {
54 self.write_exodus_compressed(path, threads)?
55 }
56 Output::Medit(path) => self.write_medit(path)?,
57 Output::Vtk(Vtk::UnstructuredGrid(Compression::On(path))) => {
58 self.write_vtk_unstructured_compressed(path)?
59 }
60 Output::Vtk(Vtk::UnstructuredGrid(Compression::Off(path))) => {
61 self.write_vtk_unstructured(path)?
62 }
63 Output::Vtk(Vtk::MultiBlock(Compression::On(path))) => {
64 self.write_vtk_multi_block_compressed(path)?
65 }
66 Output::Vtk(Vtk::MultiBlock(Compression::Off(path))) => {
67 self.write_vtk_multi_block(path)?
68 }
69 }
70 Ok(())
71 }
72}