128 lines
5.8 KiB
C++
128 lines
5.8 KiB
C++
// VDE-1361: VTK / CGNS / HDF5 result and mesh export.
|
|
//
|
|
// The existing deck exporters (export_abaqus / export_ansys / export_nastran)
|
|
// only carry the mesh and boundary conditions; they cannot carry result fields.
|
|
// This header adds three post-processing / interchange writers that carry both
|
|
// the mesh and nodal / element result fields:
|
|
//
|
|
// * VTU - VTK XML UnstructuredGrid (binary appended, or ASCII).
|
|
// * CGNS - CGNS SIDS container stored as an HDF5 file (readable by
|
|
// ParaView / vtkCGNSReader, h5py, ...).
|
|
// * HDF5 - a small, documented plain-HDF5 schema (not CGNS).
|
|
//
|
|
// All three writers:
|
|
// * validate that Nodal fields have vertices.size() values per component and
|
|
// Element fields have elements.size() values per component;
|
|
// * write 64-bit node / element counts and 0-based connectivity (CGNS uses
|
|
// the 1-based connectivity mandated by CGNS);
|
|
// * write to a temporary file and rename on success, so a failed export never
|
|
// leaves a partial file behind;
|
|
// * are deterministic: the same FEAMesh and fields produce byte-identical
|
|
// output. None of the formats below embeds a timestamp.
|
|
//
|
|
// Namespace: the API is implemented in vde::mesh (where FEAMesh lives) and is
|
|
// also exposed as vde::brep through using-declarations at the end of this
|
|
// header, matching the wording of VDE-1361. See docs/feedback/VDE-1361.md.
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "vde/cae/fea_mesh.h"
|
|
|
|
namespace vde::mesh {
|
|
|
|
/// Association of a result field with mesh entities.
|
|
enum class FieldAssociation {
|
|
Nodal, ///< one value per mesh vertex
|
|
Element, ///< one value per element
|
|
};
|
|
|
|
/// One result field to export.
|
|
struct ResultField {
|
|
std::string name; ///< "U", "S", "T", ...
|
|
int components = 1; ///< 1 scalar, 3 vector, 6 tensor components
|
|
FieldAssociation association = FieldAssociation::Nodal;
|
|
/// Length = (association == Nodal ? vertices.size() : elements.size())
|
|
/// * components.
|
|
std::vector<double> values;
|
|
};
|
|
|
|
/// Options shared by the three exporters.
|
|
struct ResultExportOptions {
|
|
bool binary = true; ///< binary output where the format supports it
|
|
bool write_named_sets = true;///< preserve boundary_face_tags as patches/groups
|
|
bool write_materials = true; ///< write material ids when present
|
|
int compression_level = 0; ///< reserved for HDF5 (currently ignored: the
|
|
///< minimal writer does not implement deflate;
|
|
///< values != 0 are still accepted and produce
|
|
///< an uncompressed file)
|
|
};
|
|
|
|
/// Write a VTK XML UnstructuredGrid (.vtu) with the mesh and result fields.
|
|
///
|
|
/// Format details:
|
|
/// * boundary_face_tags are exposed as a cell data array named "FaceTag"
|
|
/// (Int32, -1 for interior cells; the first tag when an element touches
|
|
/// several tagged boundary faces). VTK's unstructured grid format has no
|
|
/// first-class "patch" concept, so ParaView visualises these sets by
|
|
/// thresholding FaceTag. The exact per-patch node sets are written to
|
|
/// FieldData (PATCH_<name>_NODES, 0-based ids) and are available
|
|
/// losslessly in the CGNS and HDF5 exporters.
|
|
/// * Cell types: Tet4=10, Tet10=24, Hex8=12, Hex20=25, Wedge6=13,
|
|
/// Wedge15=26 (VTK ids; node order is the VDE-1355 / Abaqus order, which
|
|
/// is also VTK's order for these types).
|
|
bool export_vtu(const FEAMesh& mesh, const std::vector<ResultField>& fields,
|
|
const std::string& filepath,
|
|
const ResultExportOptions& opts = {},
|
|
std::string* error = nullptr);
|
|
|
|
/// Write a CGNS (HDF5-backed) file with the mesh, result fields and one
|
|
/// ZoneBC BC_t node per boundary face tag.
|
|
///
|
|
/// Node order: VDE-1355 contract (Abaqus sorted) is identical to the CGNS
|
|
/// ordering for Tet4/Tet10/Hex8/Hex20/Wedge6/Wedge15, so connectivity is
|
|
/// written unchanged except for the 1-based offset. Boundary faces are
|
|
/// written as their own Elements_t sections (TRI_3/QUAD_4/TRI_6/QUAD_8) and
|
|
/// each BC_t PointList holds the 1-based indices of those boundary elements;
|
|
/// this is what vtkCGNSReader turns into named patches / blocks.
|
|
bool export_cgns(const FEAMesh& mesh, const std::vector<ResultField>& fields,
|
|
const std::string& filepath,
|
|
const ResultExportOptions& opts = {},
|
|
std::string* error = nullptr);
|
|
|
|
/// Write a plain HDF5 file with a small documented schema:
|
|
///
|
|
/// / attrs: format="VDE-HDF5", version=1
|
|
/// /Mesh/Points F64 [n,3]
|
|
/// /Mesh/Elements I64 [ne,npe] (0-based node ids)
|
|
/// /Mesh/ElementType I32 [1] (FEAElementType enum value)
|
|
/// /Mesh/NodesPerElement I64 [1]
|
|
/// /Mesh/MaterialIds I32 [ne] (only when write_materials)
|
|
/// /Results/<name> F64 [count,components]
|
|
/// attrs: association="Nodal"|"Element",
|
|
/// components=<int32>,
|
|
/// original_name="<name>"
|
|
/// /Patches/<FACE_n> attrs: tag=<int32>
|
|
/// NodeIds I64 [k] (0-based, sorted, unique)
|
|
/// FaceIds I64 [m] (0-based indices into boundary_faces)
|
|
///
|
|
/// <FACE_n> is FACE_<tag> (-1 -> UNASSIGNED), matching the naming used by
|
|
/// make_face_selection / the deck exporters.
|
|
bool export_hdf5(const FEAMesh& mesh, const std::vector<ResultField>& fields,
|
|
const std::string& filepath,
|
|
const ResultExportOptions& opts = {},
|
|
std::string* error = nullptr);
|
|
|
|
} // namespace vde::mesh
|
|
|
|
// VDE-1361 exposes these symbols in vde::brep as well.
|
|
namespace vde::brep {
|
|
using mesh::export_cgns;
|
|
using mesh::export_hdf5;
|
|
using mesh::export_vtu;
|
|
using mesh::FieldAssociation;
|
|
using mesh::ResultExportOptions;
|
|
using mesh::ResultField;
|
|
} // namespace vde::brep
|