Commit d297f965 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1403 Add new test for consistency between Medit and Ensight format.

parent de7a2369
include(${CMAKE_CURRENT_LIST_DIR}/EnsightMeditMesh/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/Coloring/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/CoordsInParallel/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/DomainListInCoords/CMakeLists.txt)
......
add_executable(MoReFEMTestEnsightMeditMesh
${CMAKE_CURRENT_LIST_DIR}/main.cpp
)
target_link_libraries(MoReFEMTestEnsightMeditMesh
${ALL_LOAD_BEGIN_FLAG}
${MOREFEM_GEOMETRY}
${ALL_LOAD_END_FLAG}
MoReFEM_test_tools
)
add_test(EnsightMeditMesh
MoReFEMTestEnsightMeditMesh
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR}/Geometry/EnsightMeditMesh)
Check the equivalence between an Ensight and Medit mesh (of course when possible: some geometric elements are supported by only one of them).
These tests create one from the other and check the content is the same.
/*!
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 26 Apr 2013 12:18:22 +0200
// Copyright (c) Inria. All rights reserved.
//
*/
#include <cstdlib>
#include <algorithm>
#define BOOST_TEST_MODULE ensight_medit_mesh
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Utilities/String/String.hpp"
#include "Geometry/Mesh/Mesh.hpp"
#include "Geometry/Mesh/Internal/MeshManager.hpp"
#include "Test/Tools/Fixture/Environment.hpp"
using namespace MoReFEM;
PRAGMA_DIAGNOSTIC(push)
PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
BOOST_FIXTURE_TEST_CASE(medit_to_ensight, TestNS::FixtureNS::Environment)
{
decltype(auto) mesh_manager = Internal::MeshNS::MeshManager::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
constexpr auto medit_unique_id = 1u;
constexpr auto dimension = 3u;
constexpr auto space_unit = 1.;
mesh_manager.Create(medit_unique_id,
environment.SubstituteValues("${MOREFEM_ROOT}/Data/Mesh/Bar.mesh"),
dimension,
MeshNS::Format::Medit,
space_unit);
decltype(auto) medit_mesh = mesh_manager.GetMesh<medit_unique_id>();
std::string directory = environment.SubstituteValues("${MOREFEM_TEST_OUTPUT_DIR}/EnsightMeditMesh");
if (!FilesystemNS::Folder::DoExist(directory))
FilesystemNS::Folder::Create(directory, __FILE__, __LINE__);
std::string ensight_mesh_file = directory + "/Bar.geo";
medit_mesh.Write<MeshNS::Format::Ensight>(ensight_mesh_file);
constexpr auto ensight_unique_id = 2u;
mesh_manager.Create(ensight_unique_id,
ensight_mesh_file,
dimension,
MeshNS::Format::Ensight,
space_unit);
decltype(auto) ensight_mesh = mesh_manager.GetMesh<ensight_unique_id>();
decltype(auto) medit_mesh_label_list = medit_mesh.GetLabelList();
decltype(auto) ensight_mesh_label_list = ensight_mesh.GetLabelList();
// It is possible that some labels are there only for Coords; in this case they are not reported in Ensight
// (maybe #1378 will change that!)
BOOST_TEST(medit_mesh_label_list.size() >= ensight_mesh_label_list.size());
std::vector<unsigned int> medit_mesh_label_index_list(medit_mesh_label_list.size());
std::transform(medit_mesh_label_list.cbegin(),
medit_mesh_label_list.cend(),
medit_mesh_label_index_list.begin(),
[](const auto& ptr)
{
assert(!(!ptr));
return ptr->GetIndex();
});
// For Ensight things are more complicated: the format imposes labels runs from 1 to NLABEL.
// Here we would rather get the same than for Medit, to be able to compare.
// So I will extract the identifier from the description: when an Ensight file is generated by MoReFEM,
// its description is MeshLabel I where I is the original mesh label.
// Key: Ensight mesh label, from 1 to NLABEL.
// Value: The original Medit label.
std::map<unsigned int, unsigned int> ensight_mesh_label_mapping;
for (const auto& ensight_mesh_label_ptr : ensight_mesh_label_list)
{
assert(!(!ensight_mesh_label_ptr));
auto desc = ensight_mesh_label_ptr->GetDescription();
Utilities::String::Replace("MeshLabel", "", desc);
auto equivalent_medit_mesh_label_id = stoi(desc);
const auto check =
ensight_mesh_label_mapping.insert({ ensight_mesh_label_ptr->GetIndex(), equivalent_medit_mesh_label_id });
assert(check.second);
BOOST_CHECK(std::find(medit_mesh_label_index_list.cbegin(),
medit_mesh_label_index_list.cend(),
equivalent_medit_mesh_label_id)
!= medit_mesh_label_index_list.cend());
}
auto ensight_bag = ensight_mesh.BagOfEltType();
auto medit_bag = medit_mesh.BagOfEltType();
BOOST_REQUIRE(ensight_bag.size() == medit_bag.size());
std::sort(ensight_bag.begin(), ensight_bag.end(),
[](const auto& lhs, const auto& rhs)
{
assert(!(!lhs));
assert(!(!rhs));
return lhs->GetIdentifier() < rhs->GetIdentifier();
});
std::sort(medit_bag.begin(), medit_bag.end(),
[](const auto& lhs, const auto& rhs)
{
assert(!(!lhs));
assert(!(!rhs));
return lhs->GetIdentifier() < rhs->GetIdentifier();
});
BOOST_REQUIRE(ensight_bag == medit_bag);
for (const auto& mapping : ensight_mesh_label_mapping)
{
const auto ensight_mesh_label = mapping.first;
const auto medit_mesh_label = mapping.second;
for (const auto& ref_geom_elt_ptr : ensight_bag)
{
assert(!(!ref_geom_elt_ptr));
const auto& ref_geom_elt = *ref_geom_elt_ptr;
auto medit_range = medit_mesh.GetSubsetGeometricEltList(ref_geom_elt,
medit_mesh_label);
auto ensight_range = ensight_mesh.GetSubsetGeometricEltList(ref_geom_elt,
ensight_mesh_label);
BOOST_TEST_INFO("RefGeomElt = " << ref_geom_elt.GetName());
BOOST_TEST_INFO("(Medit) Mesh label = " << medit_mesh_label);
BOOST_TEST_INFO("(Ensight) Mesh label = part " << ensight_mesh_label);
BOOST_TEST((medit_range.second - medit_range.first) ==
(ensight_range.second - ensight_range.first));
}
}
decltype(auto) medit_geom_elt_list = medit_mesh.GetGeometricEltList();
decltype(auto) ensight_geom_elt_list = ensight_mesh.GetGeometricEltList();
BOOST_REQUIRE(medit_geom_elt_list.size() == ensight_geom_elt_list.size());
}
PRAGMA_DIAGNOSTIC(pop)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment