Chi-Tech
FromFileMeshGenerator.cc
Go to the documentation of this file.
2
4
5#include "ChiObjectFactory.h"
6
7#include "chi_runtime.h"
8#include "chi_log.h"
9
10#include <filesystem>
11
12namespace chi_mesh
13{
14
16
18{
20
21 params.SetGeneralDescription("Generator for loading an unpartitioned mesh"
22 " from a file.");
23 params.SetDocGroup("doc_MeshGenerators");
24
25 params.AddRequiredParameter<std::string>("filename", "Path to the file.");
27 "material_id_fieldname",
28 "BlockID",
29 "The name of the field storing cell block/material ids. Only really used "
30 "for .vtu, .pvtu and .e files.");
32 "boundary_id_fieldname", "", "The name of the field storing boundary-ids");
33
34 return params;
35}
36
38 : MeshGenerator(params),
39 filename_(params.GetParamValue<std::string>("filename")),
40 material_id_fieldname_(
41 params.GetParamValue<std::string>("material_id_fieldname")),
42 boundary_id_fieldname_(
43 params.GetParamValue<std::string>("boundary_id_fieldname"))
44{
45 const std::filesystem::path filepath(filename_);
46 const std::string extension = filepath.extension();
47}
48
49std::unique_ptr<UnpartitionedMesh>
51 std::unique_ptr<UnpartitionedMesh> input_umesh)
52{
54 input_umesh != nullptr,
55 "FromFileMeshGenerator can not be preceded by another"
56 " mesh generator because it cannot process an input mesh");
57
59 options.file_name = filename_;
60 options.scale = scale_;
63
64 const std::filesystem::path filepath(filename_);
65 const std::string extension = filepath.extension();
66
67 auto umesh = std::make_unique<UnpartitionedMesh>();
68
69 Chi::log.Log() << "FromFileMeshGenerator: Generating UnpartitionedMesh";
70
71 if (extension == ".obj") umesh->ReadFromWavefrontOBJ(options);
72 else if (extension == ".msh")
73 umesh->ReadFromMsh(options);
74 else if (extension == ".e")
75 umesh->ReadFromExodus(options);
76 else if (extension == ".vtu")
77 umesh->ReadFromVTU(options);
78 else if (extension == ".pvtu")
79 umesh->ReadFromPVTU(options);
80 else if (extension == ".case")
81 umesh->ReadFromEnsightGold(options);
82 else
83 ChiInvalidArgument("Unsupported file type \"" + extension +
84 "\". Supported types limited to"
85 ".obj, .msh, .e, .vtu, .pvtu, .case.");
86
87 Chi::log.Log() << "FromFileMeshGenerator: Done generating UnpartitionedMesh";
88 return umesh;
89}
90
91} // namespace chi_mesh
#define ChiInvalidArgumentIf(condition, message)
#define ChiInvalidArgument(message)
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
void SetDocGroup(const std::string &doc_group)
void AddRequiredParameter(const std::string &name, const std::string &doc_string)
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
void SetGeneralDescription(const std::string &description)
std::unique_ptr< UnpartitionedMesh > GenerateUnpartitionedMesh(std::unique_ptr< UnpartitionedMesh > input_umesh) override
static chi::InputParameters GetInputParameters()
FromFileMeshGenerator(const chi::InputParameters &params)
static chi::InputParameters GetInputParameters()
RegisterChiObject(chi_mesh, BooleanLogicalVolume)