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

Identify subdomains tool. #2227

Merged
merged 6 commits into from
Oct 2, 2018
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
8 changes: 8 additions & 0 deletions Applications/Utils/MeshGeoTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ target_link_libraries(constructMeshesFromGeometry
ApplicationsFileIO
${OGS_VTK_REQUIRED_LIBS}
)

add_executable(identifySubdomains IdentifySubdomains.cpp )
set_target_properties(identifySubdomains PROPERTIES FOLDER Utilities)
target_link_libraries(identifySubdomains
MeshGeoToolsLib
ApplicationsFileIO
${OGS_VTK_REQUIRED_LIBS}
)
139 changes: 139 additions & 0 deletions Applications/Utils/MeshGeoTools/IdentifySubdomains.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/

#include <tclap/CmdLine.h>

#include "Applications/ApplicationsLib/LogogSetup.h"
#include "BaseLib/BuildInfo.h"
#include "MeshGeoToolsLib/IdentifySubdomainMesh.h"
#include "MeshGeoToolsLib/MeshNodeSearcher.h"
#include "MeshGeoToolsLib/SearchLength.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"

std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes(
std::vector<std::string> const& filenames)
{
std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
meshes.reserve(filenames.size());

for (auto const& filename : filenames)
{
meshes.emplace_back(MeshLib::IO::readMeshFromFile(filename));
}
if (meshes.empty())
{
OGS_FATAL("No subdomain meshes were read.");
}
return meshes;
}

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

TCLAP::CmdLine cmd(
"Checks if the subdomain meshes are part of the bulk mesh and writes "
"the 'bulk_node_ids' and the 'bulk_element_ids' in each of them.\n\n"
"OpenGeoSys-6 software, version " +
BaseLib::BuildInfo::git_describe +
".\n"
"Copyright (c) 2012-2018, OpenGeoSys Community "
"(http://www.opengeosys.org)",
' ', BaseLib::BuildInfo::git_describe);

TCLAP::ValueArg<bool> force_overwrite_arg(
"f",
"force",
"Overwrites the existing subdomain meshes. (default: do not "
"overwrite.)",
false,
false,
"true/false");
cmd.add(force_overwrite_arg);

TCLAP::ValueArg<std::string> output_prefix_arg(
"o",
"output_prefix",
"Prefix the subdomain meshes' filenames with the output prefix/path.",
false,
"",
"path");
cmd.add(output_prefix_arg);

TCLAP::ValueArg<double> search_length_arg(
"s",
"searchlength",
"search length determining radius for the node search algorithm. "
"Non-negative floating point number (default 1e-16) ",
false,
1e-16,
"float");
cmd.add(search_length_arg);

TCLAP::ValueArg<std::string> bulk_mesh_arg(
"m", "mesh", "the file name of the bulk mesh", true, "", "mesh file");
cmd.add(bulk_mesh_arg);

// All the remaining arguments are used as file names for boundary/subdomain
// meshes.
TCLAP::UnlabeledMultiArg<std::string> subdomain_meshes_filenames_arg(
"subdomain_meshes_filenames", "mesh file names.", true,
"subdomain mesh file");
cmd.add(subdomain_meshes_filenames_arg);
cmd.parse(argc, argv);

//
// The bulk mesh.
//
std::unique_ptr<MeshLib::Mesh> bulk_mesh{
MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())};

//
// Read the subdomain meshes.
//
auto const subdomain_meshes =
readMeshes(subdomain_meshes_filenames_arg.getValue());

//
// Bulk mesh node searcher.
//
auto const& mesh_node_searcher =
MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher(
*bulk_mesh,
std::make_unique<MeshGeoToolsLib::SearchLength>(
search_length_arg.getValue()));

//
// Identify the subdomains in the bulk mesh.
//
for (auto& mesh_ptr : subdomain_meshes)
{
// If force overwrite is set or the output is to different mesh than
// the input mesh.
bool const overwrite_property_vectors =
force_overwrite_arg.getValue() ||
!output_prefix_arg.getValue().empty();
identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher,
overwrite_property_vectors);
}

//
// Output after the successful subdomain mesh identification.
//
for (auto const& mesh_ptr : subdomain_meshes)
{
MeshLib::IO::writeMeshToFile(
*mesh_ptr,
output_prefix_arg.getValue() + mesh_ptr->getName() + ".vtu");
}

return EXIT_SUCCESS;
}
28 changes: 28 additions & 0 deletions Applications/Utils/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ AddTest(
expected_post_single_joint_pcs_0_ts_1_t_1.000000.vtu post_single_joint_pcs_0_ts_1_t_1.000000.vtu u u 1e-14 1e-14
)

AddTest(
NAME identifySubdomains_2D_Create
PATH MeshGeoToolsLib/IdentifySubdomains
EXECUTABLE identifySubdomains
EXECUTABLE_ARGS -m 2D_mesh.vtu -o ${Data_BINARY_DIR}/MeshGeoToolsLib/IdentifySubdomains/new_ -- 2D_mesh_top_boundary.vtu 2D_mesh_bottom_boundary.vtu
REQUIREMENTS NOT OGS_USE_MPI
TESTER vtkdiff
DIFF_DATA
2D_mesh_top.vtu new_2D_mesh_top_boundary.vtu bulk_node_ids bulk_node_ids 0 0
2D_mesh_top.vtu new_2D_mesh_top_boundary.vtu bulk_element_ids bulk_element_ids 0 0
2D_mesh_bottom.vtu new_2D_mesh_bottom_boundary.vtu bulk_node_ids bulk_node_ids 0 0
2D_mesh_bottom.vtu new_2D_mesh_bottom_boundary.vtu bulk_element_ids bulk_element_ids 0 0
)

AddTest(
NAME identifySubdomains_2D_Check
PATH MeshGeoToolsLib/IdentifySubdomains
EXECUTABLE identifySubdomains
EXECUTABLE_ARGS -m 2D_mesh.vtu -o ${Data_BINARY_DIR}/MeshGeoToolsLib/IdentifySubdomains/check_ -- 2D_mesh_top.vtu 2D_mesh_bottom.vtu
REQUIREMENTS NOT OGS_USE_MPI
TESTER vtkdiff
DIFF_DATA
2D_mesh_top.vtu check_2D_mesh_top.vtu bulk_node_ids bulk_node_ids 0 0
2D_mesh_top.vtu check_2D_mesh_top.vtu bulk_element_ids bulk_element_ids 0 0
2D_mesh_bottom.vtu check_2D_mesh_bottom.vtu bulk_node_ids bulk_node_ids 0 0
2D_mesh_bottom.vtu check_2D_mesh_bottom.vtu bulk_element_ids bulk_element_ids 0 0
)

# Mac is producing slightly different partitioning, so the results are not
# comparable.
AddTest(
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pipeline {
// .*potential recursive class relation.*
recordIssues tools: [[pattern: 'build/DoxygenWarnings.log',
tool: [$class: 'Doxygen']]],
unstableTotalAll: 23
unstableTotalAll: 24
dir('build/docs') { stash(name: 'doxygen') }
publishHTML(target: [allowMissing: false, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: 'build/docs', reportFiles: 'index.html',
Expand Down
Loading