20 #include <tclap/CmdLine.h>
44 std::vector<MeshLib::Element*>
const& selected_elements,
45 std::string mesh_name)
54 return std::make_unique<MeshLib::Mesh>(std::move(mesh_name), nodes,
59 MeshLib::Mesh const& mesh, std::vector<std::size_t> selected_element_ids)
62 if (material_ids ==
nullptr)
65 "GMSH2OGS: Expected material ids to be present in the mesh to "
66 "extract boundary meshes.");
69 std::vector<std::unique_ptr<MeshLib::Mesh>> boundary_meshes;
73 while (!selected_element_ids.empty())
77 int const material_id = (*material_ids)[selected_element_ids.back()];
78 auto split = std::partition(
79 begin(selected_element_ids), end(selected_element_ids),
80 [&material_id, &material_ids](
int const id)
81 {
return (*material_ids)[
id] != material_id; });
84 std::vector<MeshLib::Element*> single_material_elements;
85 single_material_elements.reserve(
86 std::distance(split, end(selected_element_ids)));
87 std::transform(split, end(selected_element_ids),
88 std::back_inserter(single_material_elements),
89 [&](
int const id) {
return elements[id]; });
92 selected_element_ids.erase(split, end(selected_element_ids));
96 mesh, single_material_elements, std::to_string(material_id)));
98 return boundary_meshes;
103 std::string
const& file_name,
104 std::vector<std::unique_ptr<MeshLib::Mesh>>& boundary_meshes)
107 auto const& mesh_node_searcher =
110 std::make_unique<MeshGeoToolsLib::SearchLength>(
113 for (
auto& boundary_mesh : boundary_meshes)
119 '_' + boundary_mesh->getName() +
126 int main(
int argc,
char* argv[])
129 "Converting meshes in gmsh file format (ASCII, version 2.2) to a vtk "
130 "unstructured grid file (new OGS file format) or to the old OGS file "
131 "format - see options.\n\n"
132 "OpenGeoSys-6 software, version " +
135 "Copyright (c) 2012-2021, OpenGeoSys Community "
136 "(http://www.opengeosys.org)",
139 TCLAP::ValueArg<std::string> ogs_mesh_arg(
142 "filename for output mesh (if extension is .msh, old OGS-5 fileformat "
143 "is written, if extension is .vtu, a vtk unstructure grid file is "
144 "written (OGS-6 mesh format))",
147 "filename as string");
148 cmd.add(ogs_mesh_arg);
150 TCLAP::ValueArg<std::string> gmsh_mesh_arg(
"i",
"in",
"gmsh input file",
151 true,
"",
"filename as string");
152 cmd.add(gmsh_mesh_arg);
154 TCLAP::SwitchArg valid_arg(
"v",
"validation",
"validate the mesh");
157 TCLAP::SwitchArg create_boundary_meshes_arg(
158 "b",
"boundaries",
"if set, boundary meshes will be generated");
159 cmd.add(create_boundary_meshes_arg);
161 TCLAP::SwitchArg exclude_lines_arg(
162 "e",
"exclude-lines",
163 "if set, lines will not be written to the ogs mesh");
164 cmd.add(exclude_lines_arg);
166 cmd.parse(argc, argv);
169 INFO(
"Reading {:s}.", gmsh_mesh_arg.getValue());
180 INFO(
"Could not read mesh from {:s}.", gmsh_mesh_arg.getValue());
184 INFO(
"Mem for mesh: {} MiB",
188 INFO(
"Time for reading: {:f} seconds.", run_time.
elapsed());
193 if (exclude_lines_arg.getValue() || create_boundary_meshes_arg.getValue())
197 auto const& selected_element_ids = ex.getSearchedElementIDs();
203 std::vector<std::unique_ptr<MeshLib::Mesh>> boundary_meshes;
204 if (create_boundary_meshes_arg.getValue())
210 if (exclude_lines_arg.getValue())
213 mesh->
getName() +
"-withoutLines");
216 INFO(
"Removed {:d} lines.",
223 INFO(
"Mesh does not contain any lines.");
227 if (create_boundary_meshes_arg.getValue())
235 INFO(
"Please check your mesh carefully!");
237 "Degenerated or redundant mesh elements can cause OGS to stop or "
239 INFO(
"Use the -e option to delete redundant line elements.");
245 INFO(
"Node coordinates:");
246 INFO(
"\tx [{:g}, {:g}] (extent {:g})", minPt[0], maxPt[0],
247 maxPt[0] - minPt[0]);
248 INFO(
"\ty [{:g}, {:g}] (extent {:g})", minPt[1], maxPt[1],
249 maxPt[1] - minPt[1]);
250 INFO(
"\tz [{:g}, {:g}] (extent {:g})", minPt[2], maxPt[2],
251 maxPt[2] - minPt[2]);
261 if (valid_arg.isSet())
Definition of the AABB class.
Definition of Duplicate functions.
int main(int argc, char *argv[])
static std::vector< std::unique_ptr< MeshLib::Mesh > > extractBoundaryMeshes(MeshLib::Mesh const &mesh, std::vector< std::size_t > selected_element_ids)
static std::unique_ptr< MeshLib::Mesh > createMeshFromElements(MeshLib::Mesh const &mesh, std::vector< MeshLib::Element * > const &selected_elements, std::string mesh_name)
static void identifyAndWriteBoundaryMeshes(MeshLib::Mesh const &mesh, std::string const &file_name, std::vector< std::unique_ptr< MeshLib::Mesh >> &boundary_meshes)
void INFO(char const *fmt, Args const &... args)
Definition of the MemWatch class.
Definition of the MeshValidation class.
Definition of the Mesh class.
Definition of the RunTime class.
unsigned long getVirtMemUsage()
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMinPoint() const
Eigen::Vector3d const & getMaxPoint() const
double getMaxEdgeLength() const
Get the maximum edge length over all elements of the mesh.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
double getMinEdgeLength() const
Get the minimum edge length over all elements of the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
const std::string getName() const
Get name of the mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::size_t getNumberOfElements() const
Get the number of elements.
std::string getFileExtension(const std::string &path)
std::string dropFileExtension(std::string const &filename)
MeshLib::Mesh * readGMSHMesh(std::string const &fname)
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
std::vector< bool > markUnusedNodes(std::vector< Element * > const &elements, std::vector< Node * > const &nodes)
Marks nodes not used by any of the elements.
void removeMarkedNodes(std::vector< bool > const &nodes_to_delete, std::vector< Node * > &nodes)
Deallocates and removes nodes marked true.
std::vector< Element * > copyElementVector(std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)