Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend postLIE #1555

Merged
merged 7 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Applications/Utils/MeshEdit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ install(TARGETS
AddTopLayer
appendLinesAlongPolyline
checkMesh
convertToLinearMesh
CreateBoundaryConditionsAlongPolylines
createLayeredMeshFromRasters
createQuadraticeMesh
Expand Down
8 changes: 8 additions & 0 deletions Applications/Utils/PostProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ target_link_libraries(postLIE MeshLib ProcessLib)
ADD_VTK_DEPENDENCY(postLIE)
set_target_properties(postLIE PROPERTIES FOLDER Utilities)

####################
### Installation ###
####################
install(TARGETS
postLIE
RUNTIME DESTINATION bin
COMPONENT Utilities
)
112 changes: 72 additions & 40 deletions Applications/Utils/PostProcessing/postLIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,105 @@
#include "MeshLib/IO/writeMeshToFile.h"

#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEditing/ConvertToLinearMesh.h"

#include "ProcessLib/LIE/Common/MeshUtils.h"
#include "ProcessLib/LIE/Common/PostUtils.h"


int main (int argc, char* argv[])
namespace
{
ApplicationsLib::LogogSetup logog_setup;

TCLAP::CmdLine cmd("Postp-process results of the LIE approach",
' ', "0.1");
TCLAP::ValueArg<std::string> arg_out_pvd("o", "output-file",
"the name of the new PVD file", true,
"", "path");
cmd.add(arg_out_pvd);
TCLAP::ValueArg<std::string> arg_in_pvd("i", "input-file",
"the original PVD file name", true,
"", "path");
cmd.add(arg_in_pvd);
void postVTU(std::string const& int_vtu_filename, std::string const& out_vtu_filename)
{
// read VTU with simulation results
std::unique_ptr<MeshLib::Mesh const> mesh(
MeshLib::IO::readMeshFromFile(int_vtu_filename));
if (mesh->isNonlinear())
mesh = MeshLib::convertToLinearMesh(*mesh, mesh->getName());

// post-process
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;
ProcessLib::LIE::getFractureMatrixDataInMesh(
*mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements,
vec_fracture_matrix_elements, vec_fracture_nodes);

ProcessLib::LIE::PostProcessTool post(
*mesh, vec_fracture_nodes, vec_fracture_matrix_elements);

// create a new VTU file
INFO("create %s", out_vtu_filename.c_str());
MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_vtu_filename);
}

cmd.parse(argc, argv);

auto const in_pvd_filename = arg_in_pvd.getValue();
void postPVD(std::string const& in_pvd_filename, std::string const& out_pvd_filename)
{
auto const in_pvd_file_dir = BaseLib::extractPath(in_pvd_filename);
auto const out_pvd_filename = arg_out_pvd.getValue();
auto const out_pvd_file_dir = BaseLib::extractPath(out_pvd_filename);
INFO("start reading the PVD file %s", in_pvd_filename.c_str());
boost::property_tree::ptree pt;
read_xml(arg_in_pvd.getValue(), pt, boost::property_tree::xml_parser::trim_whitespace);
read_xml(in_pvd_filename, pt, boost::property_tree::xml_parser::trim_whitespace);

for (auto& dataset : pt.get_child("VTKFile.Collection"))
{
if (dataset.first != "DataSet")
continue;

// read VTU with simulation results
// get VTU file name
auto const org_vtu_filename = dataset.second.get<std::string>("<xmlattr>.file");
INFO("processing %s...", (in_pvd_file_dir + org_vtu_filename).c_str());

std::unique_ptr<MeshLib::Mesh const> mesh(
MeshLib::IO::readMeshFromFile(in_pvd_file_dir + org_vtu_filename));

// post-process
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;
ProcessLib::LIE::getFractureMatrixDataInMesh(
*mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements,
vec_fracture_matrix_elements, vec_fracture_nodes);

ProcessLib::LIE::PostProcessTool post(
*mesh, vec_fracture_nodes, vec_fracture_matrix_elements);
auto const org_vtu_filebasename = BaseLib::extractBaseName(org_vtu_filename);
auto org_vtu_dir = BaseLib::extractPath(org_vtu_filename);
if (org_vtu_dir.empty())
org_vtu_dir = in_pvd_file_dir;
auto const org_vtu_filepath = BaseLib::joinPaths(org_vtu_dir, org_vtu_filebasename);
INFO("processing %s...", org_vtu_filepath.c_str());

// post-process the VTU and save into the new file
auto const dest_vtu_filename = "post_" + org_vtu_filebasename;
auto const dest_vtu_filepath = BaseLib::joinPaths(out_pvd_file_dir, dest_vtu_filename);
postVTU(org_vtu_filepath, dest_vtu_filepath);

// create a new VTU file and update XML
auto const dest_vtu_filename = "post_" + org_vtu_filename;
INFO("create %s", (out_pvd_file_dir + dest_vtu_filename).c_str());
MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_pvd_file_dir + dest_vtu_filename);

dataset.second.put("<xmlattr>.file", dest_vtu_filename);
}

// save into the new PVD file
INFO("save into the new PVD file %s", out_pvd_filename.c_str());
boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
write_xml(arg_out_pvd.getValue(), pt, std::locale(), settings);
write_xml(out_pvd_filename, pt, std::locale(), settings);
}

} // unnamed namespace


int main (int argc, char* argv[])
{
ApplicationsLib::LogogSetup logog_setup;

TCLAP::CmdLine cmd("Post-process results of the LIE approach",
' ', "0.1");
TCLAP::ValueArg<std::string> arg_out_file("o", "output-file",
"the name of the new PVD or VTU file", true,
"", "path");
cmd.add(arg_out_file);
TCLAP::ValueArg<std::string> arg_in_file("i", "input-file",
"the original PVD or VTU file name", true,
"", "path");
cmd.add(arg_in_file);

cmd.parse(argc, argv);

auto const in_file_ext = BaseLib::getFileExtension(arg_in_file.getValue());
if (in_file_ext == "pvd")
postPVD(arg_in_file.getValue(), arg_out_file.getValue());
else if (in_file_ext == "vtu")
postVTU(arg_in_file.getValue(), arg_out_file.getValue());
else
OGS_FATAL("The given file type (%s) is not supported.", in_file_ext.c_str());

return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion ProcessLib/LIE/Common/PostUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PostProcessTool::PostProcessTool(
}

// split elements using the new duplicated nodes
for (unsigned fracture_id=0; fracture_id<=vec_vec_fracture_matrix_elements.size(); fracture_id++)
for (unsigned fracture_id=0; fracture_id<vec_vec_fracture_matrix_elements.size(); fracture_id++)
{
auto const& vec_fracture_matrix_elements = vec_vec_fracture_matrix_elements[fracture_id];
auto const& vec_fracture_nodes = vec_vec_fracture_nodes[fracture_id];
Expand Down