v0.16.3
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
MoFEM::SDFPython::Impl Struct Reference
Collaboration diagram for MoFEM::SDFPython::Impl:
[legend]

Public Member Functions

MoFEMErrorCode evaluate (const char *name, int columns, double dt, double t, const MatrixDouble &coordinates, const MatrixDouble &normals, int block, MatrixDouble &values) const
 

Public Attributes

bp::dict globals
 
std::string file
 

Detailed Description

Definition at line 18 of file SDFPython.cpp.

Member Function Documentation

◆ evaluate()

MoFEMErrorCode MoFEM::SDFPython::Impl::evaluate ( const char *  name,
int  columns,
double  dt,
double  t,
const MatrixDouble &  coordinates,
const MatrixDouble &  normals,
int  block,
MatrixDouble &  values 
) const
inline

Definition at line 22 of file SDFPython.cpp.

25 {
27 if (coordinates.size2() != 3 || normals.size2() != 3 ||
28 coordinates.size1() != normals.size1())
29 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
30 "SDF coordinates and normals must both have shape (N,3)");
31 PythonLock lock;
32 if (!globals.has_key(name) ||
33 !PyCallable_Check(bp::object(globals[name]).ptr()))
34 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
35 "Script %s has no callable %s", file.c_str(), name);
36 try {
37 const auto n = coordinates.size1();
38 std::vector<np::ndarray> args;
39 for (int d = 0; d != 6; ++d) {
40 auto a = np::empty(bp::make_tuple(n), np::dtype::get_builtin<double>());
41 auto *p = reinterpret_cast<double *>(a.get_data());
42 for (size_t i = 0; i != n; ++i)
43 p[i] = d < 3 ? coordinates(i, d) : normals(i, d - 3);
44 args.push_back(a);
45 }
46 bp::object result = globals[name](dt, t, args[0], args[1], args[2],
47 args[3], args[4], args[5], block);
48 auto a = np::from_object(result, np::dtype::get_builtin<double>());
49 if (a.get_nd() != (columns == 1 ? 1 : 2) ||
50 a.shape(0) != static_cast<Py_intptr_t>(n) ||
51 (columns != 1 && a.shape(1) != columns))
52 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
53 "Wrong result shape from %s in %s", name, file.c_str());
54 values.resize(n, columns, false);
55 for (size_t i = 0; i != n; ++i)
56 for (int d = 0; d != columns; ++d) {
57 double v;
58 std::memcpy(&v,
59 a.get_data() + i * a.strides(0) +
60 (columns == 1 ? 0 : d * a.strides(1)),
61 sizeof(v));
62 if (!std::isfinite(v))
63 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
64 "Non-finite result from %s in %s", name, file.c_str());
65 values(i, d) = v;
66 }
67 } catch (const bp::error_already_set &) {
68 PyErr_Print();
69 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
70 "Python %s failed in %s", name, file.c_str());
71 }
73 }
TetMeshData result
Vec t
Removal: the ring edge.
std::vector< std::array< double, 3 > > coordinates
SmartPetscObj< Vec > values
std::string name
constexpr double a
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
FTensor::Index< 'i', SPACE_DIM > i
double dt
const double v
phase velocity of light in medium (cm/ns)

Member Data Documentation

◆ file

std::string MoFEM::SDFPython::Impl::file

Definition at line 20 of file SDFPython.cpp.

◆ globals

bp::dict MoFEM::SDFPython::Impl::globals

Definition at line 19 of file SDFPython.cpp.


The documentation for this struct was generated from the following file: