Commit c50730e3 authored by Kirill Terekhov's avatar Kirill Terekhov
Browse files

Remake Examples/GridTools/slice_func.cpp into service (done)

parent 318635ab
......@@ -7,7 +7,7 @@ add_executable(UniteFaces unite_faces.cpp)
add_executable(Dual dual.cpp)
add_executable(Tetra tetra.cpp)
add_executable(Slice slice.cpp)
add_executable(SliceFunc slice_func.cpp)
add_executable(SliceFunc slice_func_test.cpp)
add_executable(SplitNonplanar split_nonplanar.cpp)
add_executable(CollapseDegenerate collapse_degenerate.cpp)
add_executable(Bnd2Stl bnd2stl.cpp)
......@@ -36,6 +36,7 @@ add_executable(check_collapse check_collapse.cpp)
add_executable(test_fracture test_fracture.cpp)
add_executable(segment_data segment_data.cpp)
add_library(FractureLib fracture.cpp fracture.h)
add_library(SliceFuncLib slice_func.cpp slice_func.h)
target_link_libraries(test_fracture inmost)
target_link_libraries(test_fracture FractureLib)
......@@ -160,6 +161,7 @@ install(TARGETS Slice EXPORT inmost-targets RUNTIME DESTINATION bin/GridTools)
target_link_libraries(SliceFunc inmost)
target_link_libraries(SliceFunc SliceFuncLib)
if(USE_MPI)
message("linking SliceFunc with MPI")
target_link_libraries(SliceFunc ${MPI_LIBRARIES})
......@@ -418,8 +420,9 @@ install(TARGETS segment_data EXPORT inmost-targets RUNTIME DESTINATION bin/GridT
set_property(TARGET FractureLib PROPERTY PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/fracture.h")
set_property(TARGET SliceFuncLib PROPERTY PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/slice_func.h")
install(TARGETS FractureLib EXPORT inmost-targets
install(TARGETS FractureLib SliceFuncLib EXPORT inmost-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include)
......
This diff is collapsed.
......@@ -7,17 +7,17 @@ using namespace INMOST;
class Slice
{
double epsf, epsl;
int maxits;
int maxits, maxits_zero;
Mesh * m;
double Search(double r0, double r1, double c0[3], double c1[3], double p[3], bool binary = false) const;
double SearchZero(double r0, double r1, double c0[3], double c1[3], double p[3]) const;
public:
Slice(double epsf = 1.0e-6, double epsl = 1.0e-3, int maxits = 100) : epsf(epsf), epsl(epsl), maxits(maxits) {}
Slice(const Slice & b) : epsf(b.epsf), epsl(b.epsl), maxits(b.maxits) {}
Slice & operator =(Slice const & b) {epsf = b.epsf; epsl = b.epsl; maxits = b.maxits; return *this;}
virtual ~Slice();
Slice(double epsf = 1.0e-6, double epsl = 1.0e-3, int maxits = 100, int maxits_zero = 20) : epsf(epsf), epsl(epsl), maxits(maxits), maxits_zero(maxits_zero) {}
Slice(const Slice & b) : epsf(b.epsf), epsl(b.epsl), maxits(b.maxits), maxits_zero(b.maxits_zero) {}
Slice & operator =(Slice const & b) {epsf = b.epsf; epsl = b.epsl; maxits = b.maxits; maxits_zero = maxits_zero; return *this;}
virtual ~Slice() {}
virtual double LevelFunction(double p[3]) const = 0;
void SliceMesh(Mesh & m);
void SliceMesh(Mesh & m, bool remove_material_zero = true);
};
#endif // __SLICE__H
......
#include "inmost.h"
#include "slice_func.h"
using namespace INMOST;
class SliceTest : public Slice
{
int testn;
double func(double x, double y, double z, int n) const
{
if( n == 0 )
return sqrt(x*x+y*y)-0.25;
else if( n == 1 )
return -(sqrt((x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)+(z-0.5)*(z-0.5))-0.5);
else if( n == 2 )
{
if( x > 0.5 )
return -(sqrt((x-0.7)*(x-0.7)+(y-0.2)*(y-0.2)+(z-0.4)*(z-0.4))-0.4);
else
return sqrt((x-0.3)*(x-0.3)+(y-0.4)*(y-0.4)+(z-0.5)*(z-0.5))-0.3;
}
else if( n == 3 )
return y-(4*x*x*x*x-2*x*x+0.5)+z*z*z;
else if( n == 4 )
return y-(10*x*x*x*x-8*x*x*x-5*x*x+0.2+4*x)+z*z*z;
else if( n == 5 )
{
//double Lx = 0.2, Rx = 0.4, Ly = 0.1, Ry = 0.3;
/*
double Lx = 0., Rx = 2, Ly = 0.0, Ry = 4.5;
if (x > Rx){
if (y > Ry) return -sqrt( (x-Rx)*(x-Rx) + (y-Ry)*(y-Ry) );
else return -(x-Rx);
}
if (x < Lx){
if (y < Ly) return -sqrt( (x-Lx)*(x-Lx) + (y-Ly)*(y-Ly) );
else return (x - Lx);
}
if (y > Ry) return Ry - y;
if (y < Ly) return y - Ly;
return fmin( fmin(x-Lx,Rx-x), fmin(y-Ly, Ry-y) );
*/
double Lx = 0., Rx = 20, Ly = -2.5, Ry = 17.5;
if (x > Rx)
{
if (y > Ry) return -sqrt( (x-Rx)*(x-Rx) + (y-Ry)*(y-Ry) );
if (y < Ly) return -sqrt( (x-Rx)*(x-Rx) + (y-Ly)*(y-Ly) );
return -(x-Rx);
}
if (x < Lx)
{
if (y < Ly) return -sqrt( (x-Lx)*(x-Lx) + (y-Ly)*(y-Ly) );
if (y > Ry) return -sqrt( (x-Lx)*(x-Lx) + (y-Ry)*(y-Ry) );
else return (x - Lx);
}
if (y > Ry) return Ry - y;
if (y < Ly) return y - Ly;
return fmin( fmin(x-Lx,Rx-x), fmin(y-Ly, Ry-y) );
}
else if( n == 6 )
{
return std::min(std::min(sqrt((x-0.48)*(x-0.48) + (z-1)*(z-1))-0.25,sqrt((y-0.53)*(y-0.53) + (z-3)*(z-3))-0.24),sqrt((x-0.6)*(x-0.6) + (z-5)*(z-5))-0.3);
}
return 1;
}
public:
SliceTest(int testn) :Slice(), testn(testn) {}
SliceTest(const SliceTest &b) :Slice(b), testn(b.testn) {}
SliceTest & operator =(SliceTest const & b) { Slice::operator =(b); testn = b.testn; return *this;}
double LevelFunction(double p[3]) const {return func(p[0],p[1],p[2],testn);}
};
int main(int argc, char ** argv)
{
if( argc < 2 )
{
std::cout << "Usage: " << argv[0] << " mesh [mesh_out=grid.pmf] [type=perforated_strip]" << std::endl;
return -1;
}
std::string grid_out = "grid.pmf";
int ntype = 0;
if( argc > 2 ) grid_out = std::string(argv[2]);
if( argc > 3 ) ntype = atoi(argv[3]);
Mesh m;
m.Load(argv[1]);
//m.SetTopologyCheck(NEED_TEST_CLOSURE|PROHIBIT_MULTILINE|PROHIBIT_MULTIPOLYGON|GRID_CONFORMITY|DEGENERATE_EDGE|DEGENERATE_FACE|DEGENERATE_CELL | FACE_EDGES_ORDER | MARK_ON_ERROR | ADJACENT_DUPLICATE);
//m.RemTopologyCheck(THROW_EXCEPTION);
std::cout << "Cells: " << m.NumberOfCells() << std::endl;
std::cout << "Faces: " << m.NumberOfFaces() << std::endl;
SliceTest(ntype).SliceMesh(m);
std::cout << "Cells: " << m.NumberOfCells() << std::endl;
std::cout << "Faces: " << m.NumberOfFaces() << std::endl;
m.Save(grid_out);
return 0;
}
......@@ -1567,7 +1567,7 @@ namespace INMOST
//debug
if(report || !mat.all_visited())
if( false ) if(report || !mat.all_visited())
{
mat.print_matrix();
incident_matrix<Face> mat(m,temp.begin(),temp.end(),ninner,GridCoords(),true);
......
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