Commit 396d240d authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1272 Add in the test suite DomainListInCoords (which was previously a manually-run test).

parent 04b12fd9
......@@ -7,8 +7,23 @@ add_executable(MoReFEMTestDomainListInCoords
)
target_link_libraries(MoReFEMTestDomainListInCoords
${ALL_LOAD_BEGIN_FLAG}
${MOREFEM_MODEL}
${ALL_LOAD_END_FLAG})
${ALL_LOAD_BEGIN_FLAG}
${MOREFEM_MODEL}
${ALL_LOAD_END_FLAG}
MoReFEM_test_tools
)
add_test(DomainListInCoords
MoReFEMTestDomainListInCoords
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR})
morefem_install(MoReFEMTestDomainListInCoords)
\ No newline at end of file
add_test(DomainListInCoords-mpi
${OPEN_MPI_INCL_DIR}/../bin/mpirun
--oversubscribe
-np 4 MoReFEMTestDomainListInCoords
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR})
......@@ -49,7 +49,9 @@ namespace MoReFEM
volume = 1,
exterior_surface = 2,
interior_surface = 3,
ring = 4
ring = 4,
exterior_and_ring = 5, // through lightweight domain list
interior_and_ring = 6 // through lightweight domain list
};
......
......@@ -7,7 +7,7 @@
//
*/
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Test/Geometry/DomainListInCoords/Model.hpp"
......@@ -36,168 +36,132 @@ namespace MoReFEM
void CheckValue(std::string&& name,
unsigned int expected_value,
unsigned int computed_value);
void ParallelCheckValue(const Wrappers::Mpi& mpi,
std::string&& name,
unsigned int expected_value,
unsigned int processor_computed_value);
} // namespace anonymous
void Model::SupplInitialize()
{
decltype(auto) god_of_dof = GetGodOfDof(EnumUnderlyingType(MeshIndex::mesh));
void SupplInitialize();
const auto& god_of_dof = GetGodOfDof(EnumUnderlyingType(MeshIndex::mesh));
decltype(auto) mesh = god_of_dof.GetMesh();
const auto& mesh = god_of_dof.GetMesh();
const auto& coords_list = mesh.GetProcessorWiseCoordsList();
decltype(auto) coords_list = mesh.GetProcessorWiseCoordsList();
decltype(auto) domain_manager = DomainManager::GetInstance(__FILE__, __LINE__);
decltype(auto) domain_volume =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::volume), __FILE__, __LINE__);
const auto domain_volume_unique_id = domain_volume.GetUniqueId();
unsigned int Ncoords_in_volume = 0;
decltype(auto) domain_ring =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::ring), __FILE__, __LINE__);
const auto domain_ring_unique_id = domain_ring.GetUniqueId();
unsigned int Ncoords_in_ring = 0;
decltype(auto) domain_exterior =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::exterior_surface), __FILE__, __LINE__);
const auto domain_exterior_unique_id = domain_exterior.GetUniqueId();
unsigned int Ncoords_in_exterior = 0;
decltype(auto) domain_interior =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::interior_surface), __FILE__, __LINE__);
const auto domain_interior_unique_id = domain_interior.GetUniqueId();
unsigned int Ncoords_in_interior = 0;
// Domains through lightweight domain list
decltype(auto) domain_exterior_and_ring = domain_manager.GetDomain(5, __FILE__, __LINE__);
const auto domain_exterior_and_ring_unique_id = domain_exterior_and_ring.GetUniqueId();
unsigned int Ncoords_in_exterior_and_ring = 0;
decltype(auto) domain_interior_and_ring = domain_manager.GetDomain(6, __FILE__, __LINE__);
const auto domain_interior_and_ring_unique_id = domain_interior_and_ring.GetUniqueId();
unsigned int Ncoords_in_interior_and_ring = 0;
for (const auto& coords_ptr : coords_list)
decltype(auto) domain_exterior_and_ring =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::exterior_and_ring), __FILE__, __LINE__);
decltype(auto) domain_interior_and_ring =
domain_manager.GetDomain(EnumUnderlyingType(DomainIndex::interior_and_ring), __FILE__, __LINE__);
for (decltype(auto) coords_ptr : coords_list)
{
assert(!(!coords_ptr));
const auto& coords = *coords_ptr;
decltype(auto) coords = *coords_ptr;
if (coords.IsInDomain(domain_volume_unique_id))
++Ncoords_in_volume;
if (coords.IsInDomain(domain_volume))
++Ncoords_in_volume_;
if (coords.IsInDomain(domain_ring_unique_id))
++Ncoords_in_ring;
if (coords.IsInDomain(domain_ring))
++Ncoords_in_ring_;
if (coords.IsInDomain(domain_exterior_unique_id))
++Ncoords_in_exterior;
if (coords.IsInDomain(domain_exterior))
++Ncoords_in_exterior_;
if (coords.IsInDomain(domain_interior_unique_id))
++Ncoords_in_interior;
if (coords.IsInDomain(domain_interior))
++Ncoords_in_interior_;
if (coords.IsInDomain(domain_exterior_and_ring_unique_id))
++Ncoords_in_exterior_and_ring;
if (coords.IsInDomain(domain_exterior_and_ring))
++Ncoords_in_exterior_and_ring_;
if (coords.IsInDomain(domain_interior_and_ring_unique_id))
++Ncoords_in_interior_and_ring;
if (coords.IsInDomain(domain_interior_and_ring))
++Ncoords_in_interior_and_ring_;
}
}
void Model::CheckNormalDomain() const
{
decltype(auto) mpi = parent::GetMpi();
const auto Nprocessor = mpi.Nprocessor<int>();
const auto Ncoords_in_volume_program_wise = NcoordsInDomain<MpiScale::program_wise>(GetMpi(),
domain_exterior,
mesh);
const auto Ncoords_in_volume_processor_wise = NcoordsInDomain<MpiScale::processor_wise>(GetMpi(),
domain_exterior,
mesh);
if (Nprocessor == 1)
auto Ncoords_in_volume = Ncoords_in_volume_;
auto Ncoords_in_ring = Ncoords_in_ring_;
auto Ncoords_in_exterior = Ncoords_in_exterior_;
auto Ncoords_in_interior = Ncoords_in_interior_;
if (Nprocessor > 1)
{
CheckValue("Ncoords_in_volume", 48, Ncoords_in_volume);
CheckValue("Ncoords_in_ring", 8, Ncoords_in_ring);
CheckValue("Ncoords_in_exterior", 24, Ncoords_in_exterior);
CheckValue("Ncoords_in_interior", 24, Ncoords_in_interior);
CheckValue("Ncoords_in_exterior_and_ring", 28, Ncoords_in_exterior_and_ring);
CheckValue("Ncoords_in_interior_and_ring", 28, Ncoords_in_interior_and_ring);
CheckValue("Ncoords_in_volume_program_wise", 24, Ncoords_in_volume_program_wise);
CheckValue("Ncoords_in_volume_processor_wise", 24, Ncoords_in_volume_processor_wise);
Ncoords_in_volume = mpi.AllReduce(Ncoords_in_volume_, Wrappers::MpiNS::Op::Sum);
Ncoords_in_ring = mpi.AllReduce(Ncoords_in_ring_, Wrappers::MpiNS::Op::Sum);
Ncoords_in_exterior = mpi.AllReduce(Ncoords_in_exterior_, Wrappers::MpiNS::Op::Sum);
Ncoords_in_interior = mpi.AllReduce(Ncoords_in_interior_, Wrappers::MpiNS::Op::Sum);
}
else if (Nprocessor == 4)
CheckValue("Ncoords_in_volume", 48, Ncoords_in_volume);
CheckValue("Ncoords_in_ring", 8, Ncoords_in_ring);
CheckValue("Ncoords_in_exterior", 24, Ncoords_in_exterior);
CheckValue("Ncoords_in_interior", 24, Ncoords_in_interior);
}
void Model::CheckLightweightDomain() const
{
decltype(auto) mpi = parent::GetMpi();
const auto Nprocessor = mpi.Nprocessor<int>();
auto Ncoords_in_exterior_and_ring = Ncoords_in_exterior_and_ring_;
auto Ncoords_in_interior_and_ring = Ncoords_in_interior_and_ring_;
if (Nprocessor > 1)
{
// We can't really compare processor by processor, as parallel repartition may differ from one
// compiler to another. So we gather them all and check nothing is lost.
ParallelCheckValue(mpi, "Ncoords_in_volume", 48, Ncoords_in_volume);
ParallelCheckValue(mpi, "Ncoords_in_ring", 8, Ncoords_in_ring);
ParallelCheckValue(mpi, "Ncoords_in_exterior", 24, Ncoords_in_exterior);
ParallelCheckValue(mpi, "Ncoords_in_interior", 24, Ncoords_in_interior);
ParallelCheckValue(mpi, "Ncoords_in_exterior_and_ring", 28, Ncoords_in_exterior_and_ring);
ParallelCheckValue(mpi, "Ncoords_in_interior_and_ring", 28, Ncoords_in_interior_and_ring);
CheckValue("Ncoords_in_volume_program_wise", 24, Ncoords_in_volume_program_wise); // not a mistake!
ParallelCheckValue(mpi, "Ncoords_in_volume_processor_wise", 24, Ncoords_in_volume_processor_wise);
Ncoords_in_exterior_and_ring =
mpi.AllReduce(Ncoords_in_exterior_and_ring, Wrappers::MpiNS::Op::Sum);
Ncoords_in_interior_and_ring =
mpi.AllReduce(Ncoords_in_interior_and_ring, Wrappers::MpiNS::Op::Sum);
}
else
throw Exception("This test was written to be checked against 1 or 4 processors.",
__FILE__, __LINE__);
CheckValue("Ncoords_in_exterior_and_ring", 28, Ncoords_in_exterior_and_ring);
CheckValue("Ncoords_in_interior_and_ring", 28, Ncoords_in_interior_and_ring);
}
namespace // anonymous
{
PRAGMA_DIAGNOSTIC(push)
PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
void CheckValue(std::string&& name,
unsigned int expected_value,
unsigned int computed_value)
{
if (expected_value != computed_value)
{
std::ostringstream oconv;
oconv << "Expected value for " << name << " was " << expected_value << " but computation "
"yielded " << computed_value;
throw Exception(oconv.str(), __FILE__, __LINE__);
}
}
void ParallelCheckValue(const Wrappers::Mpi& mpi,
std::string&& name,
unsigned int expected_value,
unsigned int processor_computed_value)
{
auto sum = mpi.ReduceOnRootProcessor(processor_computed_value, Wrappers::MpiNS::Op::Sum);
if (mpi.IsRootProcessor() && expected_value != sum)
{
std::ostringstream oconv;
oconv << "Expected value for " << name << " was " << expected_value << " but computation "
"yielded " << sum;
throw Exception(oconv.str(), __FILE__, __LINE__);
}
BOOST_TEST_INFO("Expected value for " << name << " was " << expected_value << " but computation "
"through Coords iteration yielded " << computed_value);
BOOST_TEST(expected_value == computed_value);
}
PRAGMA_DIAGNOSTIC(pop)
} // namespace anonymous
......
......@@ -88,6 +88,17 @@ namespace MoReFEM
///@}
/*!
* \brief This function encompass tests about \a Domain defined as full-fledged domains in input data.
*/
void CheckNormalDomain() const;
/*!
* \brief This function encompass tests about \a Domain defined with lightweight domain facility in
* input data.
*/
void CheckLightweightDomain() const;
/// \name Crtp-required methods.
///@{
......@@ -145,6 +156,32 @@ namespace MoReFEM
//! Output directory.
const std::string output_directory_;
/*!
* \class doxygen_hide_domain_list_in_coords_attribute
*
* \brief Number of \a Coords in a given domain computed by iterating over all \a Coords.
*
*/
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_volume_ = 0;
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_ring_ = 0;
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_exterior_ = 0;
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_interior_ = 0;
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_exterior_and_ring_ = 0;
//! \copydoc doxygen_hide_domain_list_in_coords_attribute
unsigned int Ncoords_in_interior_and_ring_ = 0;
};
......
......@@ -7,60 +7,78 @@
//
*/
#include <cstdlib>
#define BOOST_TEST_MODULE domain_list_in_coords
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "Test/Geometry/DomainListInCoords/InputData.hpp"
#include "Test/Geometry/DomainListInCoords/Model.hpp"
#include "Test/Tools/Fixture/Model.hpp"
using namespace MoReFEM;
using namespace MoReFEM::TestNS;
int main(int argc, char** argv)
namespace // anonymous
{
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = DomainListInCoordsNS::InputData;
try
struct LuaFile
{
MoReFEMData<InputData> morefem_data(argc, argv);
const auto& input_data = morefem_data.GetInputData();
const auto& mpi = morefem_data.GetMpi();
try
{
DomainListInCoordsNS::Model model(morefem_data);
model.Run();
input_data.PrintUnused(std::cout);
}
catch(const std::exception& e)
{
ExceptionNS::PrintAndAbort(mpi, e.what());
}
catch(Seldon::Error& e)
{
ExceptionNS::PrintAndAbort(mpi, e.What());
}
}
catch(const std::exception& e)
static std::string GetPath();
};
using fixture_type =
TestNS::FixtureNS::Model
<
TestNS::DomainListInCoordsNS::Model,
LuaFile
>;
} // namespace anonymous
PRAGMA_DIAGNOSTIC(push)
PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
BOOST_FIXTURE_TEST_CASE(normal_domains, fixture_type)
{
GetModel().CheckNormalDomain();
}
BOOST_FIXTURE_TEST_CASE(lightweight_domains, fixture_type)
{
GetModel().CheckLightweightDomain();
}
PRAGMA_DIAGNOSTIC(pop)
namespace // anonymous
{
std::string LuaFile::GetPath()
{
std::ostringstream oconv;
oconv << "Exception caught from MoReFEMData<InputData>: " << e.what() << std::endl;
std::cout << oconv.str();
return EXIT_FAILURE;
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
return
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Geometry/DomainListInCoords/demo.lua");
}
return EXIT_SUCCESS;
}
} // namespace anonymous
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