OGS
postLIE.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
12#include <boost/property_tree/ptree.hpp>
13#include <boost/property_tree/xml_parser.hpp>
14#include <map>
15#include <memory>
16#include <vector>
17
18#include "BaseLib/FileTools.h"
19#include "BaseLib/MPI.h"
20#include "InfoLib/GitInfo.h"
23#include "MeshLib/Mesh.h"
27
28namespace
29{
30void postVTU(std::string const& int_vtu_filename,
31 std::string const& out_vtu_filename)
32{
33 // read VTU with simulation results
34 std::unique_ptr<MeshLib::Mesh const> mesh(
35 MeshLib::IO::readMeshFromFile(int_vtu_filename));
36 if (mesh->hasNonlinearElement())
37 {
38 mesh = MeshToolsLib::convertToLinearMesh(*mesh, mesh->getName());
39 }
40
41 // post-process
42 std::vector<MeshLib::Element*> vec_matrix_elements;
43 std::vector<int> vec_fracture_mat_IDs;
44 std::vector<std::vector<MeshLib::Element*>> vec_fracture_elements;
45 std::vector<std::vector<MeshLib::Element*>> vec_fracture_matrix_elements;
46 std::vector<std::vector<MeshLib::Node*>> vec_fracture_nodes;
47 std::vector<std::pair<std::size_t, std::vector<int>>>
48 vec_branch_nodeID_matIDs;
49 std::vector<std::pair<std::size_t, std::vector<int>>>
50 vec_junction_nodeID_matIDs;
52 *mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements,
53 vec_fracture_matrix_elements, vec_fracture_nodes,
54 vec_branch_nodeID_matIDs, vec_junction_nodeID_matIDs);
55
57 vec_fracture_mat_IDs,
58 vec_fracture_nodes,
59 vec_fracture_matrix_elements,
60 vec_branch_nodeID_matIDs,
61 vec_junction_nodeID_matIDs);
62
63 // create a new VTU file
64 INFO("create {:s}", out_vtu_filename);
65 MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_vtu_filename);
66}
67
68void postPVD(std::string const& in_pvd_filename,
69 std::string const& out_pvd_filename,
70 bool const allow_overwrite)
71{
72 auto const in_pvd_file_dir = BaseLib::extractPath(in_pvd_filename);
73 auto const out_pvd_file_dir = BaseLib::extractPath(out_pvd_filename);
74 INFO("start reading the PVD file {:s}", in_pvd_filename);
75 boost::property_tree::ptree pt;
76 read_xml(in_pvd_filename, pt,
77 boost::property_tree::xml_parser::trim_whitespace);
78
79 for (auto& dataset : pt.get_child("VTKFile.Collection"))
80 {
81 if (dataset.first != "DataSet")
82 {
83 continue;
84 }
85
86 // get VTU file name
87 auto const org_vtu_filename =
88 dataset.second.get<std::string>("<xmlattr>.file");
89 auto const org_vtu_filebasename =
90 BaseLib::extractBaseName(org_vtu_filename);
91 auto org_vtu_dir = BaseLib::extractPath(org_vtu_filename);
92 if (org_vtu_dir.empty())
93 {
94 org_vtu_dir = in_pvd_file_dir;
95 }
96 auto const org_vtu_filepath =
97 BaseLib::joinPaths(org_vtu_dir, org_vtu_filebasename);
98 INFO("processing {:s}...", org_vtu_filepath);
99
100 // post-process the VTU and save into the new file
101 auto const dest_vtu_filename = "post_" + org_vtu_filebasename;
102 auto const dest_vtu_filepath =
103 BaseLib::joinPaths(out_pvd_file_dir, dest_vtu_filename);
104 if (!allow_overwrite && BaseLib::IsFileExisting(dest_vtu_filepath))
105 {
106 INFO("The destination file already exists. Skip overwriting it.");
107 }
108 else
109 {
110 postVTU(org_vtu_filepath, dest_vtu_filepath);
111 }
112
113 // create a new VTU file and update XML
114 dataset.second.put("<xmlattr>.file", dest_vtu_filename);
115 }
116
117 // save into the new PVD file
118 INFO("save into the new PVD file {:s}", out_pvd_filename);
119 boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
120 write_xml(out_pvd_filename, pt, std::locale(), settings);
121}
122
123} // unnamed namespace
124
125int main(int argc, char* argv[])
126{
127 TCLAP::CmdLine cmd(
128 "Post-process results of the LIE approach.\n\n"
129 "OpenGeoSys-6 software, version " +
131 ".\n"
132 "Copyright (c) 2012-2024, OpenGeoSys Community "
133 "(http://www.opengeosys.org)",
135 TCLAP::ValueArg<std::string> arg_out_file(
136 "o", "output-file", "the name of the new PVD or VTU file", true, "",
137 "path");
138 cmd.add(arg_out_file);
139 TCLAP::ValueArg<std::string> arg_in_file(
140 "i", "input-file", "the original PVD or VTU file name", true, "",
141 "path");
142 cmd.add(arg_in_file);
143 TCLAP::SwitchArg nooverwrite_arg(
144 "",
145 "no-overwrite",
146 "don't overwrite existing post processed VTU files");
147 cmd.add(nooverwrite_arg);
148
149 cmd.parse(argc, argv);
150
151 BaseLib::MPI::Setup mpi_setup(argc, argv);
152
153 auto const in_file_ext = BaseLib::getFileExtension(arg_in_file.getValue());
154 if (in_file_ext == ".pvd")
155 {
156 postPVD(arg_in_file.getValue(), arg_out_file.getValue(),
157 !nooverwrite_arg.getValue());
158 }
159 else if (in_file_ext == ".vtu")
160 {
161 postVTU(arg_in_file.getValue(), arg_out_file.getValue());
162 }
163 else
164 {
165 OGS_FATAL("The given file type ({:s}) is not supported.", in_file_ext);
166 }
167
168 return EXIT_SUCCESS;
169}
#define OGS_FATAL(...)
Definition Error.h:26
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the Mesh class.
MeshLib::Mesh const & getOutputMesh() const
Definition PostUtils.h:44
std::string getFileExtension(const std::string &path)
std::string extractPath(std::string const &pathname)
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
Definition FileTools.cpp:50
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string extractBaseName(std::string const &pathname)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
std::unique_ptr< MeshLib::Mesh > convertToLinearMesh(MeshLib::Mesh const &mesh, std::string const &new_mesh_name)
void getFractureMatrixDataInMesh(MeshLib::Mesh const &mesh, std::vector< MeshLib::Element * > &vec_matrix_elements, std::vector< int > &vec_fracture_mat_IDs, std::vector< std::vector< MeshLib::Element * > > &vec_fracture_elements, std::vector< std::vector< MeshLib::Element * > > &vec_fracture_matrix_elements, std::vector< std::vector< MeshLib::Node * > > &vec_fracture_nodes, std::vector< std::pair< std::size_t, std::vector< int > > > &vec_branch_nodeID_matIDs, std::vector< std::pair< std::size_t, std::vector< int > > > &vec_junction_nodeID_matIDs)
void postVTU(std::string const &int_vtu_filename, std::string const &out_vtu_filename)
Definition postLIE.cpp:30
void postPVD(std::string const &in_pvd_filename, std::string const &out_pvd_filename, bool const allow_overwrite)
Definition postLIE.cpp:68
int main(int argc, char *argv[])
Definition postLIE.cpp:125
Definition of readMeshFromFile function.