v0.16.3
Loading...
Searching...
No Matches
Functions
sdf_python.cpp File Reference

Python namespace, array-layout, optional-derivative and error checks. More...

#include <MoFEM.hpp>

Go to the source code of this file.

Functions

MoFEMErrorCode run (MoFEM::Interface &m_field)
 
int main (int argc, char *argv[])
 

Detailed Description

Python namespace, array-layout, optional-derivative and error checks.

Definition in file sdf_python.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 45 of file sdf_python.cpp.

45 {
46 MoFEM::Core::Initialize(&argc, &argv, nullptr, "Python SDF checks\n");
47 try {
49 {
50 moab::Core mb;
51 MoFEM::Core core(mb);
52 CHKERR run(core);
53 }
55 }
58 return 0;
59}
moab::Interface & mb
#define CATCH_ERRORS
Catch errors.
#define CHKERR
Inline error check.
MoFEMErrorCode run(MoFEM::Interface &m_field)
Definition sdf_python.cpp:7
Core (interface) class.
Definition Core.hpp:83
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
static MoFEMErrorCode initialise()
Definition SDFPython.cpp:84
static MoFEMErrorCode finalise()

◆ run()

MoFEMErrorCode run ( MoFEM::Interface &  m_field)
Examples
mofem/atom_tests/field_values_from_tags.cpp.

Definition at line 7 of file sdf_python.cpp.

7 {
10 char file[PETSC_MAX_PATH_LEN], other[PETSC_MAX_PATH_LEN];
11 CHKERR PetscOptionsGetString(nullptr, nullptr, "-sdf_file", file,
12 sizeof(file), nullptr);
13 CHKERR PetscOptionsGetString(nullptr, nullptr, "-other_sdf", other,
14 sizeof(other), nullptr);
15 SDFPython first, second;
16 CHKERR first.sdfInit(file);
18 CHKERR second.sdfInit(other);
19 MatrixDouble x(2, 3), normals(2, 3), grad, hess;
20 x.clear();
21 normals.clear();
22 x(1, 0) = 2;
24 CHKERR first.evalSdf(.5, 1., x, normals, 0, values);
25 CHKERR first.evalGradSdf(0, 0, x, normals, 0, grad);
26 CHKERR first.evalHessSdf(0, 0, x, normals, 0, hess);
27 if (values.size() != 2 || values[0] != 8.5 || values[1] != 10.5 ||
28 grad(1, 0) != 1 || grad(1, 1) != 2 || grad(1, 2) != 3 ||
29 hess(1, 5) != 10 || second.value({2, 0, 0}) != 102 ||
30 first.value({2, 0, 0}) != 9)
31 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
32 "SDF values, array strides or script namespaces are incorrect");
33 CHKERR PetscPushErrorHandler(PetscReturnErrorHandler, nullptr);
34 const auto missing_derivatives = second.requireDerivatives();
35 const auto shape = first.evalSdf(0, 0, x, normals, 1, values);
36 const auto exception = first.evalSdf(0, 0, x, normals, 2, values);
37 const auto nan = first.evalSdf(0, 0, x, normals, 3, values);
38 CHKERR PetscPopErrorHandler();
39 if (!missing_derivatives || !shape || !exception || !nan)
40 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
41 "Invalid SDF input/result was accepted");
43}
SmartPetscObj< Vec > values
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEMErrorCode requireDerivatives() const
MoFEMErrorCode evalHessSdf(double dt, double t, const MatrixDouble &coordinates, const MatrixDouble &normals, int block, MatrixDouble &values) const
MoFEMErrorCode sdfInit(const std::string &file)
double value(const std::array< double, 3 > &point, double dt=0, double t=0, int block=0) const
MoFEMErrorCode evalSdf(double dt, double t, const MatrixDouble &coordinates, const MatrixDouble &normals, int block, VectorDouble &values) const
MoFEMErrorCode evalGradSdf(double dt, double t, const MatrixDouble &coordinates, const MatrixDouble &normals, int block, MatrixDouble &values) const
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.