From 1fd9859b32e3c0b2098ffa9c9fbce70cdf41abe5 Mon Sep 17 00:00:00 2001 From: Kirill Terekhov Date: Fri, 14 Apr 2017 23:29:38 -0700 Subject: [PATCH] Refinement tools for MFD-ES Refinement into cube and sphere in AdaptiveMesh for specific tests with MFD-ES --- Examples/AdaptiveMesh/CMakeLists.txt | 18 ++++++++--- Examples/AdaptiveMesh/main_cube.cpp | 45 +++++++++++++++++++++++++++ Examples/AdaptiveMesh/main_sphere.cpp | 45 +++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 Examples/AdaptiveMesh/main_cube.cpp create mode 100644 Examples/AdaptiveMesh/main_sphere.cpp diff --git a/Examples/AdaptiveMesh/CMakeLists.txt b/Examples/AdaptiveMesh/CMakeLists.txt index 494dbbd..50d9899 100644 --- a/Examples/AdaptiveMesh/CMakeLists.txt +++ b/Examples/AdaptiveMesh/CMakeLists.txt @@ -1,18 +1,24 @@ project(AdaptiveMesh) -set(LIBSOURCE amesh.cpp amesh.h) -set(SOURCE main.cpp) -add_library(AdaptiveMeshLib ${LIBSOURCE}) -add_executable(AdaptiveMesh ${SOURCE}) +add_library(AdaptiveMeshLib amesh.cpp amesh.h) +add_executable(AdaptiveMesh main.cpp) +add_executable(AdaptiveMeshCube main_cube.cpp) +add_executable(AdaptiveMeshSphere main_sphere.cpp) target_link_libraries(AdaptiveMesh inmost AdaptiveMeshLib) +target_link_libraries(AdaptiveMeshCube inmost AdaptiveMeshLib) +target_link_libraries(AdaptiveMeshSphere inmost AdaptiveMeshLib) if(USE_MPI) message("linking AdaptiveMesh with MPI") target_link_libraries(AdaptiveMesh ${MPI_LIBRARIES}) + target_link_libraries(AdaptiveMeshCube ${MPI_LIBRARIES}) + target_link_libraries(AdaptiveMeshSphere ${MPI_LIBRARIES}) if(MPI_LINK_FLAGS) set_target_properties(AdaptiveMesh PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}") + set_target_properties(AdaptiveMeshCube PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}") + set_target_properties(AdaptiveMeshSphere PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}") endif() endif(USE_MPI) @@ -22,4 +28,6 @@ install(TARGETS AdaptiveMeshLib EXPORT inmost-targets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib PUBLIC_HEADER DESTINATION include) -install(TARGETS AdaptiveMesh EXPORT inmost-targets RUNTIME DESTINATION bin) \ No newline at end of file +install(TARGETS AdaptiveMesh EXPORT inmost-targets RUNTIME DESTINATION bin) +install(TARGETS AdaptiveMeshCube EXPORT inmost-targets RUNTIME DESTINATION bin) +install(TARGETS AdaptiveMeshSphere EXPORT inmost-targets RUNTIME DESTINATION bin) \ No newline at end of file diff --git a/Examples/AdaptiveMesh/main_cube.cpp b/Examples/AdaptiveMesh/main_cube.cpp new file mode 100644 index 0000000..a07ac7e --- /dev/null +++ b/Examples/AdaptiveMesh/main_cube.cpp @@ -0,0 +1,45 @@ +#include "amesh.h" + +using namespace INMOST; + +int main(int argc, char ** argv) +{ + Mesh::Initialize(&argc,&argv); + + if( argc > 1 ) + { + AdaptiveMesh m; + m.Load(argv[1]); + TagInteger indicator = m.CreateTag("INDICATOR",DATA_INTEGER,CELL,NONE,1); + + int max_levels = 2; + if( argc > 2 ) max_levels = atoi(argv[2]); + + int numref; + do + { + numref = 0; + for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it) + if( m.GetLevel(it->self()) < max_levels ) + { + double x[3]; + it->Centroid(x); + if( x[0] > 0.3 && x[0] < 0.7 && x[1] > 0.3 && x[1] < 0.7 && x[2] > 0.3 && x[2] < 0.7) + { + indicator[it->self()] = 1; + numref++; + } + } + if( numref ) + { + if( !m.Refine(indicator) ) break; + for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it) indicator[it->self()] = 0; + } + } + while(numref); + std::string file = "out.vtk"; + if( argc > 3 ) file = std::string(argv[3]); + m.Save(file); + } + else std::cout << "Usage: " << argv[0] << " mesh_file [max_levels=2] [mesh_out=out.vtk]" << std::endl; +} \ No newline at end of file diff --git a/Examples/AdaptiveMesh/main_sphere.cpp b/Examples/AdaptiveMesh/main_sphere.cpp new file mode 100644 index 0000000..b57ec1e --- /dev/null +++ b/Examples/AdaptiveMesh/main_sphere.cpp @@ -0,0 +1,45 @@ +#include "amesh.h" + +using namespace INMOST; + +int main(int argc, char ** argv) +{ + Mesh::Initialize(&argc,&argv); + + if( argc > 1 ) + { + AdaptiveMesh m; + m.Load(argv[1]); + TagInteger indicator = m.CreateTag("INDICATOR",DATA_INTEGER,CELL,NONE,1); + + int max_levels = 2; + if( argc > 2 ) max_levels = atoi(argv[2]); + + int numref; + do + { + numref = 0; + for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it) + if( m.GetLevel(it->self()) < max_levels ) + { + double x[3]; + it->Centroid(x); + if( sqrt((x[0]-0.5)*(x[0]-0.5)+(x[1]-0.5)*(x[1]-0.5)+(x[2]-0.5)*(x[2]-0.5)) < 0.25 ) + { + indicator[it->self()] = 1; + numref++; + } + } + if( numref ) + { + if( !m.Refine(indicator) ) break; + for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it) indicator[it->self()] = 0; + } + } + while(numref); + std::string file = "out.vtk"; + if( argc > 3 ) file = std::string(argv[3]); + m.Save(file); + } + else std::cout << "Usage: " << argv[0] << " mesh_file [max_levels=2] [mesh_out=out.vtk]" << std::endl; +} \ No newline at end of file -- 2.26.2