OGS
FEFLOW2OGS.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <tclap/CmdLine.h>
5
6#include <memory>
7#include <string>
8
9#include "BaseLib/FileTools.h"
10#include "BaseLib/Logging.h"
11#include "BaseLib/MPI.h"
12#include "BaseLib/RunTime.h"
14#include "InfoLib/GitInfo.h"
15#ifndef WIN32
16#include "BaseLib/MemWatch.h"
17#endif
18
19// FileIO
24#include "MeshLib/Mesh.h"
25
26int main(int argc, char* argv[])
27{
28 TCLAP::CmdLine cmd(
29 "Converting a mesh in FEFLOW file format (ASCII, version 5.4) to a vtk "
30 "unstructured grid file (new OGS file format) or to the old OGS file "
31 "format - see options.\n\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2026, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38
39 TCLAP::ValueArg<std::string> ogs_mesh_arg(
40 "o",
41 "out",
42 "Output. Filename for output mesh (if extension is msh, old OGS file "
43 "format is "
44 "written)",
45 true,
46 "",
47 "OUTPUT_FILE");
48 cmd.add(ogs_mesh_arg);
49
50 TCLAP::ValueArg<std::string> feflow_mesh_arg(
51 "i", "in", "Input (.fem). FEFLOW input file", true, "", "INPUT_FILE");
52 cmd.add(feflow_mesh_arg);
53
54 auto log_level_arg = BaseLib::makeLogLevelArg();
55 cmd.add(log_level_arg);
56 cmd.parse(argc, argv);
57
58 BaseLib::MPI::Setup mpi_setup(argc, argv);
59 BaseLib::initOGSLogger(log_level_arg.getValue());
60
61 // *** read mesh
62 INFO("Reading {:s}.", feflow_mesh_arg.getValue());
63#ifndef WIN32
64 BaseLib::MemWatch mem_watch;
65 unsigned long mem_without_mesh(mem_watch.getVirtMemUsage());
66#endif
67 BaseLib::RunTime run_time;
68 run_time.start();
70 std::unique_ptr<MeshLib::Mesh const> mesh(
71 feflowIO.readFEFLOWFile(feflow_mesh_arg.getValue()));
72
73 if (mesh == nullptr)
74 {
75 INFO("Could not read mesh from {:s}.", feflow_mesh_arg.getValue());
76 return EXIT_FAILURE;
77 }
78#ifndef WIN32
79 unsigned long mem_with_mesh(mem_watch.getVirtMemUsage());
80 INFO("Mem for mesh: {} MiB",
81 (mem_with_mesh - mem_without_mesh) / (1024 * 1024));
82#endif
83 INFO("Time for reading: {:f} seconds.", run_time.elapsed());
84 INFO("Read {:d} nodes and {:d} elements.", mesh->getNumberOfNodes(),
85 mesh->getNumberOfElements());
86
87 std::string ogs_mesh_fname(ogs_mesh_arg.getValue());
88 INFO("Writing {:s}.", ogs_mesh_fname);
89 MeshLib::IO::writeMeshToFile(*mesh, ogs_mesh_fname);
90 INFO("\tDone.");
91 return EXIT_SUCCESS;
92}
int main(int argc, char *argv[])
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
unsigned long getVirtMemUsage()
Definition MemWatch.cpp:48
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
MeshLib::Mesh * readFEFLOWFile(const std::string &filename)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)