21 CHKERR this->setPtrFE(&fe);
22 this->getGaussPts().resize(4, points,
false);
27MoFEMErrorCode checkNear(
const double value,
const double expected) {
29 if (!std::isfinite(value) || std::abs(value - expected) > 2.e-13)
31 "Deviator field value %g differs from %g", value, expected);
42 constexpr int size = Dim == 2 ? 3 : 5;
43 const int points = data.
getN().size1();
44 if (tensor.size1() != points || tensor.size2() != 6 ||
45 coordinates.size1() != points || coordinates.size2() !=
size)
47 "Incorrect deviator output layout");
48 for (
int gg = 0; gg != points; ++gg) {
49 std::array<double, 5> d{};
51 for (
int c = 0;
c !=
size; ++
c) {
52 for (
int b = 0; b != 2; ++b)
54 CHKERR checkNear(coordinates(gg,
c), d[
c]);
56 const std::array<double, 6> expected{
57 d[0] / std::sqrt(2.) + d[1] / std::sqrt(6.),
58 d[2] / std::sqrt(2.), d[3] / std::sqrt(2.),
59 -d[0] / std::sqrt(2.) + d[1] / std::sqrt(6.),
60 d[4] / std::sqrt(2.), -2. * d[1] / std::sqrt(6.)};
61 for (
int c = 0;
c != 6; ++
c)
62 CHKERR checkNear(tensor(gg,
c), expected[
c]);
63 CHKERR checkNear(tensor(gg, 0) + tensor(gg, 3) + tensor(gg, 5), 0.);
64 const double norm = tensor(gg, 0) * tensor(gg, 0) +
65 tensor(gg, 3) * tensor(gg, 3) +
66 tensor(gg, 5) * tensor(gg, 5) +
67 2. * (tensor(gg, 1) * tensor(gg, 1) +
68 tensor(gg, 2) * tensor(gg, 2) +
69 tensor(gg, 4) * tensor(gg, 4));
70 double coordinate_norm = 0;
71 for (
const auto value : d)
72 coordinate_norm += value * value;
73 CHKERR checkNear(norm, coordinate_norm);
80 constexpr int size = Dim == 2 ? 3 : 5;
85 for (
int c = 0;
c != 2 *
size; ++
c)
88 auto tensor = boost::make_shared<MatrixDouble>();
89 auto coordinates = boost::make_shared<MatrixDouble>();
92 for (
const int points : {3, 4}) {
93 CHKERR op.attach(fe, points);
94 data.
getN().resize(points, 3,
false);
95 for (
int gg = 0; gg != points; ++gg) {
96 data.
getN()(gg, 0) = .2 * (gg + 1);
97 data.
getN()(gg, 1) = -.1 * (gg + 2);
98 data.
getN()(gg, 2) = 17.;
100 CHKERR op.doWork(0, MBVERTEX, data);
101 CHKERR checkValues<Dim>(*tensor, *coordinates, data, original, 1.);
102 CHKERR op.doWork(1, MBVERTEX, data);
103 CHKERR checkValues<Dim>(*tensor, *coordinates, data, original, 2.);
104 CHKERR op.doWork(0, MBVERTEX, data);
105 CHKERR checkValues<Dim>(*tensor, *coordinates, data, original, 1.);
109 CHKERR VecCreateSeq(PETSC_COMM_SELF, 2 *
size, &raw_vector);
112 CHKERR VecGetArray(vector, &array);
115 for (
int c = 0;
c != 2 *
size; ++
c)
116 array[
c] = -.03 * (
c + 1);
117 for (
int c = 0;
c != 2 *
size; ++
c) {
118 const int index =
c == 1 ? -1 : 2 *
size -
c - 1;
120 from_vector[
c] = index == -1 ? 0. : array[index];
122 CHKERR VecRestoreArray(vector, &array);
123 TestOp<Dim> vector_op(
"D", tensor, vector, MBVERTEX, 0, coordinates);
124 CHKERR vector_op.attach(fe, data.
getN().size1());
125 CHKERR vector_op.doWork(0, MBVERTEX, data);
126 CHKERR checkValues<Dim>(*tensor, *coordinates, data, from_vector, 1.);
127 for (
int c = 0;
c != 2 *
size; ++
c)
131 CHKERR vector_op.doWork(0, MBVERTEX, data);
132 CHKERR checkValues<Dim>(*tensor, *coordinates, data, original, 0.);
133 CHKERR PetscPrintf(PETSC_COMM_SELF,
"%dD deviator field evaluation passed\n", Dim);
139int main(
int argc,
char *argv[]) {
141 "Check symmetric deviator field interpolation\n");
145 CHKERR checkField<2>(core);
146 CHKERR checkField<3>(core);
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#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.
const double c
speed of light (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
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.
Data on single entity (This is passed as argument to DataOperator::doWork)
FieldApproximationBase & getBase()
Get approximation base.
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
Get DOF values on entity.
const VectorInt & getLocalIndices() const
Get local indices of degrees of freedom on entity.
structure to get information from mofem into EntitiesFieldData
intrusive_ptr for managing petsc objects
Volume finite element base.