5#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
6#include <CGAL/squared_distance_3.h>
11double determinant(
const std::array<double, 3> &
a,
12 const std::array<double, 3> &b,
13 const std::array<double, 3> &
c) {
14 return a[0] * (b[1] *
c[2] - b[2] *
c[1]) -
15 a[1] * (b[0] *
c[2] - b[2] *
c[0]) +
16 a[2] * (b[0] *
c[1] - b[1] *
c[0]);
23 auto &
tools = bridge->getTools();
26 auto radius = [](
const auto &x) {
27 return std::sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
29 for (
bool shell : {
false,
true}) {
31 <<
"Generating " << (shell ?
"shell" :
"sphere");
36 return shell ? std::max(radius(x) - 1., .45 - radius(x))
42 std::array<double, 3>
a, b,
c;
43 for (
int d = 0;
d != 3; ++
d) {
44 a[
d] =
mesh.points[cell[1]][
d] -
mesh.points[cell[0]][
d];
45 b[
d] =
mesh.points[cell[2]][
d] -
mesh.points[cell[0]][
d];
46 c[
d] =
mesh.points[cell[3]][
d] -
mesh.points[cell[0]][
d];
48 const double v = determinant(
a, b,
c) / 6.;
51 "Nonpositive generated cell");
54 std::array<double, 3> p;
55 for (
int d = 0;
d != 3; ++
d)
56 p[
d] = -
mesh.points[cell[0]][
d];
57 const double den = 6 *
v;
58 const double u = determinant(p, b,
c) / den;
59 const double w = determinant(
a, p,
c) / den;
60 const double z = determinant(
a, b, p) / den;
61 if (u >= 0 &&
w >= 0 && z >= 0 && u +
w + z <= 1)
63 "Mesher filled the cavity");
64 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
65 const K::Point_3 origin(0, 0, 0);
66 for (
int omit = 0; omit != 4; ++omit) {
67 std::vector<K::Point_3> face;
68 for (
int d = 0;
d != 4; ++
d)
70 const auto &x =
mesh.points[cell[
d]];
71 face.emplace_back(x[0], x[1], x[2]);
73 const auto distance = CGAL::squared_distance(
74 origin, K::Triangle_3(face[0], face[1], face[2]));
78 "Generated cell penetrates the cavity beyond facet tolerance");
82 const double expected =
83 4. * std::acos(-1.) / 3. * (shell ? 1. - std::pow(.45, 3) : 1.);
86 :
"SDF sphere volume",
87 volume, expected, {0., .08});
88 if (
mesh.boundary.empty())
90 "Incorrect implicit-domain volume");
93 const double r = radius(
mesh.points[
i]);
94 const double error = shell
95 ? std::min(std::abs(r - 1), std::abs(r - .45))
99 "Boundary is off the SDF");
104 mesh.vertexIds.clear();
107 if (entities.subset_by_type(MBVERTEX).size() !=
mesh.points.size())
109 "Mesh import lost vertices");
111 CHKERR bridge->exportMesh(entities.subset_by_type(MBTET),
mesh);
119 "Reconstruction changed vertices");
123 bool rejected =
false;
127 [](
const auto &) {
return std::numeric_limits<double>::quiet_NaN(); },
129 }
catch (
const std::exception &) {
132 if (!rejected || !invalid.
cells.empty())
134 "Non-finite SDF was accepted");
139int main(
int argc,
char *argv[]) {
const Settings & settings
const std::vector< Vec > * points
std::vector< Cell > cells
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
MoFEMErrorCode TestingInterface::checkValue< TestType::SCALAR >(const std::string &check_name, PetscReal actual, PetscReal expected, Tolerance tolerance, Sev error_severity, Sev success_severity) const
MoFEMErrorCode run(MoFEM::Interface &m_field)
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
std::vector< std::array< int, 4 > > cells
Zero-based point indices.
std::vector< std::array< double, 3 > > points
std::vector< int > vertexIds
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.