Commit a7cd5a68 authored by Nicolas CHEVAUGEON's avatar Nicolas CHEVAUGEON

[xFEM/test] added 2 atomic test for 3d search structure

First, I added a test directory inside xFEM for xFEM Atomic test that was missing. (As usual Atomic test means that the test do not need other library that the current tested library dependencies)
A new Build option is added, corresponding to the xFEM Atomic test  : BUILD_XFEM_TEST. It must be set to ON in your parent CMakeFiles.txt for this test to be builded, thanks to the Xfiles/CMakeLists.txt that will add the subdirectory xFEM/test to the build if BUILD_XFEM_TEST is set to ON

In xFEM/test I added two tests cases :
testxOctreeGrid and testxRegularGrid, along with there references.

Some other tests from in Xtest/xfem-seq-test for example could also be moved here.
parent 6bb4eac4
......@@ -150,6 +150,10 @@ if(BUILD_ATOMIC_TEST)
add_subdirectory(xMeshTool/xDistMesh/test "${CMAKE_BINARY_DIR}/Atomic/xDistMesh")
endif()
if(BUILD_XFEM_TEST)
add_subdirectory(xFEM/test "${CMAKE_BINARY_DIR}/Atomic/xFEM")
endif()
if(BUILD_XOCTREE_TEST)
if(NOT PARALLEL AND NOT PARSEQ AND NOT PARDIST AND NOT PARFUTURE)
add_subdirectory(xOctree/test "${CMAKE_BINARY_DIR}/Atomic/xOctree")
......
cmake_minimum_required(VERSION 2.6)
set(text "----------------------")
message_verbose(text)
message(STATUS "atomic test: xFEM --")
set(text "----------------------")
message_verbose(text)
find_and_set(xFEM xFEM EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xTensor xTensor EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xTool xTool EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(Trellis Trellis EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xMapping xMapping EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xQuadrature xQuadrature EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xSolverBase xSolverBase EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xInterfaceAOMDGeneral xInterfaceAOMDGeneral EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(xInterfaceLapack xInterfaceLapack EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(LAPACK2 LAPACK EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
find_and_set(BLAS2 BLAS EXTERNAL_INCLUDES EXTERNAL_LIBRARIES REQUIRED )
list(APPEND EXTERNAL_INCLUDES
${MPI_CXX_INCLUDE_PATH}
)
list(APPEND EXTERNAL_LIBRARIES
${MPI_CXX_LIBRARIES}
)
set(LIST
${CMAKE_CURRENT_SOURCE_DIR}/testxOctreeGrid
${CMAKE_CURRENT_SOURCE_DIR}/testxRegularGrid
)
create_tests_from_list(${LIST})
enable_testing()
add_test(
NAME testxOctreeGrid
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${INSTALL_PATH}/${TARGET_NAME} ${MPIEXEC_POSTFLAGS}
WORKING_DIRECTORY ${INSTALL_PATH}
)
add_test(ndiff_testxOctreeGrid ${TESTNDIFF} )
set_tests_properties(ndiff_testxOctreeGrid PROPERTIES DEPENDS testxOctreeGrid)
m=0.5; // mesh size
h=2;
Point(newp) = {0, 0, 0, m};
Point(newp) = {10, 0, 0, m};
Point(newp) = {10, 10, 0, m};
Point(newp) = {0, 10, 0, m};
Point(newp) = {2, 2, 0, m};
Point(newp) = {8, 2, 0, m};
Point(newp) = {8, 8, 0, m};
Point(newp) = {2, 8, 0, m};
Point(newp) = {2, 0, 0, m};
Point(newp) = {8, 0, 0, m};
Point(newp) = {2, 10, 0, m};
Point(newp) = {8, 10, 0, m};
Point(newp) = {0, 0, h, m};
Point(newp) = {10, 0, h, m};
Point(newp) = {10, 10, h, m};
Point(newp) = {0, 10, h, m};
Point(newp) = {2, 2, h, m};
Point(newp) = {8, 2, h, m};
Point(newp) = {8, 8, h, m};
Point(newp) = {2, 8, h, m};
Point(newp) = {2, 0, h, m};
Point(newp) = {8, 0, h, m};
Point(newp) = {2, 10, h, m};
Point(newp) = {8, 10, h, m};
Line(1) = {16, 23};
Line(2) = {23, 11};
Line(3) = {11, 4};
Line(4) = {4, 16};
Line(5) = {24, 12};
Line(6) = {12, 3};
Line(7) = {3, 15};
Line(8) = {15, 24};
Line(9) = {10, 2};
Line(10) = {2, 14};
Line(11) = {14, 22};
Line(12) = {22, 10};
Line(13) = {21, 9};
Line(14) = {9, 1};
Line(15) = {1, 13};
Line(16) = {13, 21};
Curve Loop(17) = {3, 4, 1, 2};
Surface(18) = {17};
Curve Loop(19) = {6, 7, 8, 5};
Surface(20) = {19};
Curve Loop(21) = {9, 10, 11, 12};
Surface(22) = {21};
Curve Loop(23) = {14, 15, 16, 13};
Surface(24) = {23};
Line(25) = {16, 13};
Line(26) = {1, 4};
Line(27) = {11, 12};
Line(28) = {24, 23};
Line(29) = {21, 22};
Line(30) = {10, 9};
Line(31) = {2, 3};
Line(32) = {15, 14};
Line(33) = {20, 19};
Line(34) = {19, 18};
Line(35) = {18, 17};
Line(36) = {17, 20};
Line(37) = {8, 7};
Line(38) = {7, 6};
Line(39) = {6, 18};
Line(40) = {5, 6};
Line(41) = {5, 8};
Line(42) = {20, 8};
Line(43) = {17, 5};
Line(44) = {19, 7};
Curve Loop(45) = {27, -5, 28, 2};
Surface(46) = {45};
Curve Loop(47) = {25, -15, 26, 4};
Surface(48) = {47};
Curve Loop(49) = {29, 12, 30, -13};
Surface(50) = {49};
Curve Loop(51) = {32, -10, 31, 7};
Surface(52) = {51};
Curve Loop(53) = {41, -42, -36, 43};
Surface(54) = {53};
Curve Loop(55) = {35, 43, 40, 39};
Surface(56) = {55};
Curve Loop(57) = {34, -39, -38, -44};
Surface(58) = {57};
Curve Loop(59) = {33, 44, -37, -42};
Surface(60) = {59};
Curve Loop(61) = {27, 6, -31, -9, 30, 14, 26, -3};
Curve Loop(62) = {37, 38, -40, 41};
Plane Surface(63) = {61, 62};
Curve Loop(64) = {25, 16, 29, -11, -32, 8, 28, -1};
Curve Loop(65) = {34, 35, 36, 33};
Plane Surface(66) = {64, 65};
Surface Loop(67) = {46, 63, 20, 52, 66, 48, 24, 50, 22, 18, 60, 58, 56, 54};
Volume(68) = {67};
This diff is collapsed.
#include <fstream>
#include "xMPIEnv.h"
#include "xMappingBuilderHolder.h"
#include "xMesh.h"
#include "xOctreeGrid.h"
using namespace xfem;
using namespace xtensor;
using namespace xtool;
using myOctantBucket = octantBucket<2, 8, 2>;
using elem_data = myOctantBucket::elem_data;
void exportGMSH(const xPoint &p, std::ostream &out) { out << p[0] << ", " << p[1] << ", " << p[2]; }
void exportAsCubeGMSH(const xBoundingBox &bb, std::ostream &out)
{
const auto &min = bb.min;
const auto &max = bb.max;
auto dir = max - min;
std::array<xPoint, 8> cubevert;
for (int k = 0; k < 2; ++k)
{
cubevert[k * 4] = xPoint{min[0], min[1], min[2] + dir[2] * k};
cubevert[k * 4 + 1] = xPoint{min[0] + dir[0], min[1], min[2] + dir[2] * k};
cubevert[k * 4 + 2] = xPoint{min[0] + dir[0], min[1] + dir[1], min[2] + dir[2] * k};
cubevert[k * 4 + 3] = xPoint{min[0], min[1] + dir[1], min[2] + dir[2] * k};
}
out << "SH(";
for (int i = 0; i < 7; ++i)
{
exportGMSH(cubevert[i], out);
out << ", ";
}
exportGMSH(cubevert[7], out);
out << ") {0,0,0,0,0,0,0,0};\n";
}
template <class OCTANT>
void exportGMSH(const OCTANT &buck, std::ostream &out)
{
out << "View \" octree_grid \" { \n";
buck.visitLeaves([&out](const OCTANT &b) { exportAsCubeGMSH(b.getBoundingBox(), out); });
out << "};";
}
int main(int argc, char *argv[])
{
xMPIEnv::init(argc, argv);
{ // a hand made case, with 6 "elem", with all there centroid at the same position, to force the octree to go to high level !!
myOctantBucket buck(xBoundingBox{xPoint{-1., -1., -1.}, xPoint{1., 1., 1.}});
int elem1, elem2, elem3, elem4, elem5, elem6;
elem_data data_elem1{&elem1, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
elem_data data_elem2{&elem2, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
elem_data data_elem3{&elem3, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
elem_data data_elem4{&elem4, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
elem_data data_elem5{&elem5, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
elem_data data_elem6{&elem6, xPoint{0.1, 0.1, 0.}, xBoundingBox{xPoint{-0.5, -0.5, -0.5}, xPoint{0.5, 0.5, 0.5}}};
buck.addElement(data_elem1);
buck.addElement(data_elem2);
buck.addElement(data_elem3);
buck.addElement(data_elem4);
buck.addElement(data_elem5);
buck.addElement(data_elem6);
std::ofstream out("octree_simple.pos");
exportGMSH(buck, out);
}
{
// A case build out of an xmesh, but the octree is build directly in the code.
std::cout << "Testing xOctreeGrid construction and exploration" << std::endl;
xMesh mesh("data/CubeWithCubeHole.msh");
std::cout << "Mesh read : " << mesh.size(0) << " vertices " << mesh.size(3) << " solids " << std::endl;
myOctantBucket buck(xBoundingBox{xPoint{-0.03, -0.03, -0.03}, xPoint{10.3, 10.3, 10.3}});
for (auto preg : mesh.range(3))
{
std::unique_ptr<xmapping::xMapping> pmapping(xMappingBuilderHolderSingleton::instance().buildMapping(*preg));
elem_data edata{preg, pmapping->eval(pmapping->COG()), pmapping->boundingBox()};
buck.addElement(edata);
}
std::ofstream out("octree_3d_from_xmesh.pos");
exportGMSH(buck, out);
size_t max_nelement = 0;
buck.visitLeaves([&max_nelement](const myOctantBucket &b) {
size_t nb = std::distance(b.getDatas().begin(), b.getDatas().end());
max_nelement = std::max(max_nelement, nb);
});
std::cout << "max element in a octree Leaf " << max_nelement << std::endl;
std::array<xPoint, 2> targets{xPoint{0.05, 0.05, 0.05}, xPoint{0., 0., 0.}};
for (auto target : targets)
{
const myOctantBucket *pbuck = buck.findBucket(target);
std::list<std::pair<AOMD::mEntity *, xPoint>> pent_to_loccoord;
if (pbuck)
{
std::cout << " found !" << std::distance(pbuck->getDatas().begin(), pbuck->getDatas().end()) << std::endl;
for (const auto &edata : pbuck->getDatas())
{
if (edata.bb.contains(target))
{
AOMD::mEntity *pe = static_cast<AOMD::mEntity *>(edata.elem);
std::unique_ptr<xmapping::xMapping> pmapping(xMappingBuilderHolderSingleton::instance().buildMapping(*pe));
xPoint uvw;
if (pmapping->interiorCheck(target, uvw))
{
pent_to_loccoord.push_back(std::make_pair(pe, uvw));
}
}
}
}
std::cout << "Point " << target << " Found in " << pent_to_loccoord.size() << " Elements " << std::endl;
for (const auto &pe_pt : pent_to_loccoord)
{
const AOMD::mEntity *pe = pe_pt.first;
xPoint uvw = pe_pt.second;
std::unique_ptr<xmapping::xMapping> pmapping(xMappingBuilderHolderSingleton::instance().buildMapping(*pe));
xPoint xyz = pmapping->eval(uvw);
std::cout << "Entity " << pe_pt.first << " local Coordinate " << pe_pt.second << " Global Coordinate " << xyz
<< std::endl;
}
}
}
{ // A case on a 3d mesh, using the xMesh internal createOctree and locateOctree
xMesh mesh("data/CubeWithCubeHole.msh");
std::cout << "Mesh read : " << mesh.size(0) << " vertices " << mesh.size(3) << " solids " << std::endl;
std::array<xPoint, 2> targets{xPoint{0.05, 0.05, 0.05}, xPoint{0., 0., 0.}};
std::cout << "Testing mesh.locateElementOctree" << std::endl;
for (auto target : targets)
{
auto entityfounds = mesh.locateElementOctree(target);
std::cout << "Point " << target << " Found in " << entityfounds.size() << " Elements " << std::endl;
for (const auto pe_uvw : entityfounds)
{
std::unique_ptr<xmapping::xMapping> pmapping(xMappingBuilderHolderSingleton::instance().buildMapping(*pe_uvw.first));
std::cout << "Entity " << pe_uvw.first << " local Coordinate " << pe_uvw.second << " Global Coordinate "
<< pmapping->eval(pe_uvw.second) << std::endl;
}
}
std::ofstream out("octree_3d_from_xmesh_getOctreeGrid.pos");
exportGMSH(mesh.getOctreeGrid(), out);
}
return xMPIEnv::finalize();
}
This diff is collapsed.
This diff is collapsed.
enable_testing()
add_test(
NAME testxRegularGrid
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${INSTALL_PATH}/${TARGET_NAME} ${MPIEXEC_POSTFLAGS}
WORKING_DIRECTORY ${INSTALL_PATH}
)
add_test(ndiff_testxRegularGrid ${TESTNDIFF} )
set_tests_properties(ndiff_testxRegularGrid PROPERTIES DEPENDS testxRegularGrid)
m=0.5; // mesh size
h=2;
Point(newp) = {0, 0, 0, m};
Point(newp) = {10, 0, 0, m};
Point(newp) = {10, 10, 0, m};
Point(newp) = {0, 10, 0, m};
Point(newp) = {2, 2, 0, m};
Point(newp) = {8, 2, 0, m};
Point(newp) = {8, 8, 0, m};
Point(newp) = {2, 8, 0, m};
Point(newp) = {2, 0, 0, m};
Point(newp) = {8, 0, 0, m};
Point(newp) = {2, 10, 0, m};
Point(newp) = {8, 10, 0, m};
Point(newp) = {0, 0, h, m};
Point(newp) = {10, 0, h, m};
Point(newp) = {10, 10, h, m};
Point(newp) = {0, 10, h, m};
Point(newp) = {2, 2, h, m};
Point(newp) = {8, 2, h, m};
Point(newp) = {8, 8, h, m};
Point(newp) = {2, 8, h, m};
Point(newp) = {2, 0, h, m};
Point(newp) = {8, 0, h, m};
Point(newp) = {2, 10, h, m};
Point(newp) = {8, 10, h, m};
Line(1) = {16, 23};
Line(2) = {23, 11};
Line(3) = {11, 4};
Line(4) = {4, 16};
Line(5) = {24, 12};
Line(6) = {12, 3};
Line(7) = {3, 15};
Line(8) = {15, 24};
Line(9) = {10, 2};
Line(10) = {2, 14};
Line(11) = {14, 22};
Line(12) = {22, 10};
Line(13) = {21, 9};
Line(14) = {9, 1};
Line(15) = {1, 13};
Line(16) = {13, 21};
Curve Loop(17) = {3, 4, 1, 2};
Surface(18) = {17};
Curve Loop(19) = {6, 7, 8, 5};
Surface(20) = {19};
Curve Loop(21) = {9, 10, 11, 12};
Surface(22) = {21};
Curve Loop(23) = {14, 15, 16, 13};
Surface(24) = {23};
Line(25) = {16, 13};
Line(26) = {1, 4};
Line(27) = {11, 12};
Line(28) = {24, 23};
Line(29) = {21, 22};
Line(30) = {10, 9};
Line(31) = {2, 3};
Line(32) = {15, 14};
Line(33) = {20, 19};
Line(34) = {19, 18};
Line(35) = {18, 17};
Line(36) = {17, 20};
Line(37) = {8, 7};
Line(38) = {7, 6};
Line(39) = {6, 18};
Line(40) = {5, 6};
Line(41) = {5, 8};
Line(42) = {20, 8};
Line(43) = {17, 5};
Line(44) = {19, 7};
Curve Loop(45) = {27, -5, 28, 2};
Surface(46) = {45};
Curve Loop(47) = {25, -15, 26, 4};
Surface(48) = {47};
Curve Loop(49) = {29, 12, 30, -13};
Surface(50) = {49};
Curve Loop(51) = {32, -10, 31, 7};
Surface(52) = {51};
Curve Loop(53) = {41, -42, -36, 43};
Surface(54) = {53};
Curve Loop(55) = {35, 43, 40, 39};
Surface(56) = {55};
Curve Loop(57) = {34, -39, -38, -44};
Surface(58) = {57};
Curve Loop(59) = {33, 44, -37, -42};
Surface(60) = {59};
Curve Loop(61) = {27, 6, -31, -9, 30, 14, 26, -3};
Curve Loop(62) = {37, 38, -40, 41};
Plane Surface(63) = {61, 62};
Curve Loop(64) = {25, 16, 29, -11, -32, 8, 28, -1};
Curve Loop(65) = {34, 35, 36, 33};
Plane Surface(66) = {64, 65};
Surface Loop(67) = {46, 63, 20, 52, 66, 48, 24, 50, 22, 18, 60, 58, 56, 54};
Volume(68) = {67};
This diff is collapsed.
#include <fstream>
#include "xMPIEnv.h"
#include "xMappingBuilderHolder.h"
#include "xMesh.h"
#include "xOctreeGrid.h"
using namespace xfem;
using namespace xtensor;
using namespace xtool;
int main(int argc, char* argv[])
{
xMPIEnv::init(argc, argv);
{ // A case on a 3d mesh, using the xMesh internal createOctree and locateOctree
xMesh mesh("data/CubeWithCubeHole.msh");
std::cout << "Mesh read : " << mesh.size(0) << " vertices " << mesh.size(3) << " solids " << std::endl;
std::array<xPoint, 2> targets{xPoint{0.05, 0.05, 0.05}, xPoint{0., 0., 0.}};
std::cout << "Testing mesh.locateElement" << std::endl;
for (auto target : targets)
{
auto entityfounds = mesh.locateElement(target);
std::cout << "Point " << target << " Found in " << std::distance(entityfounds.begin(), entityfounds.end())
<< " Elements " << std::endl;
for (const auto pe_uvw : entityfounds)
{
std::unique_ptr<xmapping::xMapping> pmapping(xMappingBuilderHolderSingleton::instance().buildMapping(*pe_uvw.first));
std::cout << "Entity " << pe_uvw.first << " local Coordinate " << pe_uvw.second << " Global Coordinate "
<< pmapping->eval(pe_uvw.second) << std::endl;
}
}
std::ofstream out("regular_grid_from_xmesh_getRegularGrid.txt");
mesh.getRegularGrid().print(out);
}
return xMPIEnv::finalize();
}
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