v0.14.0
Public Member Functions | Public Attributes | Private Attributes | List of all members
AtomTest::OpError Struct Reference

Operator to evaluate errors. More...

Collaboration diagram for AtomTest::OpError:
[legend]

Public Member Functions

 OpError (boost::shared_ptr< MatrixDouble > data_ptr)
 
MoFEMErrorCode doWork (int side, EntityType type, EntData &data)
 
 OpError (boost::shared_ptr< CommonData > &common_data_ptr)
 
MoFEMErrorCode doWork (int side, EntityType type, EntData &data)
 

Public Attributes

boost::shared_ptr< CommonDatacommonDataPtr
 

Private Attributes

boost::shared_ptr< MatrixDouble > dataPtr
 

Detailed Description

Operator to evaluate errors.

Examples
child_and_parent.cpp, dg_projection.cpp, hanging_node_approx.cpp, and higher_derivatives.cpp.

Definition at line 82 of file child_and_parent.cpp.

Constructor & Destructor Documentation

◆ OpError() [1/2]

AtomTest::OpError::OpError ( boost::shared_ptr< MatrixDouble >  data_ptr)
inline

Definition at line 95 of file dg_projection.cpp.

96  : DomainEleOp(NOSPACE, OPSPACE), dataPtr(data_ptr) {}

◆ OpError() [2/2]

AtomTest::OpError::OpError ( boost::shared_ptr< CommonData > &  common_data_ptr)
inline

Definition at line 117 of file higher_derivatives.cpp.

118  : DomainEleOp(FIELD_NAME, OPROW), commonDataPtr(common_data_ptr) {
119  std::fill(doEntities.begin(), doEntities.end(), false);
120  doEntities[MBVERTEX] = true;
121  }

Member Function Documentation

◆ doWork() [1/2]

MoFEMErrorCode AtomTest::OpError::doWork ( int  side,
EntityType  type,
EntData data 
)
inline

Definition at line 98 of file dg_projection.cpp.

98  {
100 
101  const int nb_integration_pts = getGaussPts().size2();
102  auto t_val = getFTensor1FromMat<1>(
103  *(dataPtr)); // get function approximation at gauss pts
104  auto t_coords = getFTensor1CoordsAtGaussPts(); // get coordinates of
105  // integration points
106 
107  for (int gg = 0; gg != nb_integration_pts; ++gg) {
108 
109  // Calculate errors
110 
111  double diff = t_val(0) - fun(t_coords(0), t_coords(1), t_coords(2));
112  constexpr double eps = 1e-8;
113  if (std::abs(diff) > eps) {
114  MOFEM_LOG("SELF", Sev::error) << "Wrong function value " << diff;
115  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
116  "Wrong function value");
117  }
118 
119  // move data to next integration point
120  ++t_val;
121  ++t_coords;
122  }
123 
124  MOFEM_LOG("SELF", Sev::noisy) << "All is OK";
125 
127  }

◆ doWork() [2/2]

MoFEMErrorCode AtomTest::OpError::doWork ( int  side,
EntityType  type,
EntData data 
)
inline

Definition at line 122 of file higher_derivatives.cpp.

122  {
124 
125  const int nb_integration_pts = getGaussPts().size2();
126  auto t_w = getFTensor0IntegrationWeight(); // ger integration weights
127  auto t_val = getFTensor0FromVec(*(
128  commonDataPtr->approxVals)); // get function approximation at gauss pts
129  auto t_grad_val = getFTensor1FromMat<SPACE_DIM>(
130  *(commonDataPtr
131  ->approxGradVals)); // get gradient of approximation at gauss pts
132  auto t_hessian_val = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(
133  *(commonDataPtr)->approxHessianVals); // get hessian of approximation
134  // at integration pts
135 
136  auto t_inv_jac = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(
137  *(commonDataPtr->invJacPtr)); // get inverse of element jacobian
138  auto t_coords = getFTensor1CoordsAtGaussPts(); // get coordinates of
139  // integration points
140 
141  // Indices used for tensor operations
146 
147  const double volume = getMeasure(); // get finite element area
148 
149 
150  std::array<double, 3> error = {0, 0,
151  0}; // array for storing operator errors
152 
153  for (int gg = 0; gg != nb_integration_pts; ++gg) {
154 
155  const double alpha = t_w * volume;
156 
157  // Calculate errors
158 
159  double diff = t_val - fun(t_coords(0), t_coords(1), t_coords(2));
160  error[0] += alpha * pow(diff, 2);
161  auto t_diff_grad = diff_fun(t_coords(0), t_coords(1), t_coords(2));
162  t_diff_grad(i) -= t_grad_val(i);
163 
164  error[1] += alpha * t_diff_grad(i) *
165  t_diff_grad(i); // note push forward derivatives
166 
168  MOFEM_LOG("SELF", Sev::noisy) << "t_hessian_val " << t_hessian_push;
169 
170  // hessian expected to have symmetry
171  if (std::abs(t_hessian_val(0, 1) - t_hessian_val(1, 0)) >
172  std::numeric_limits<float>::epsilon()) {
173  MOFEM_LOG("SELF", Sev::error) << "t_hessian_val " << t_hessian_val;
174  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
175  "Hessian should be symmetric");
176  }
177 
178  auto t_diff_hessian = diff2_fun(t_coords(0), t_coords(1), t_coords(2));
179  t_diff_hessian(i, j) -= t_hessian_val(i, j);
180  error[2] = t_diff_hessian(i, j) * t_diff_hessian(i, j);
181 
182  // move data to next integration point
183  ++t_w;
184  ++t_val;
185  ++t_grad_val;
186  ++t_hessian_val;
187  ++t_inv_jac;
188  ++t_coords;
189  }
190 
191  // assemble error vector
192  std::array<int, 3> index = {0, 1, 2};
193  CHKERR VecSetValues(commonDataPtr->L2Vec, 3, index.data(), error.data(),
194  ADD_VALUES);
195 
197  }

Member Data Documentation

◆ commonDataPtr

boost::shared_ptr< CommonData > AtomTest::OpError::commonDataPtr

Definition at line 94 of file dg_projection.cpp.

◆ dataPtr

boost::shared_ptr<MatrixDouble> AtomTest::OpError::dataPtr
private

Definition at line 130 of file dg_projection.cpp.


The documentation for this struct was generated from the following files:
NOSPACE
@ NOSPACE
Definition: definitions.h:83
MoFEM::VecSetValues
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.
Definition: EntitiesFieldData.hpp:1576
FTensor::Tensor2
Definition: Tensor2_value.hpp:16
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
diff2_fun
auto diff2_fun
Function second derivative.
Definition: higher_derivatives.cpp:55
DomainEleOp
DomainEle::UserDataOperator DomainEleOp
Finire element operator type.
Definition: dg_projection.cpp:29
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FIELD_NAME
constexpr char FIELD_NAME[]
Definition: higher_derivatives.cpp:16
FTensor::Index< 'i', 2 >
diff_fun
auto diff_fun
Function derivative.
Definition: higher_derivatives.cpp:45
fun
auto fun
Function to approximate.
Definition: higher_derivatives.cpp:37
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
AtomTest::OpError::dataPtr
boost::shared_ptr< MatrixDouble > dataPtr
Definition: dg_projection.cpp:130
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
AtomTest::OpError::commonDataPtr
boost::shared_ptr< CommonData > commonDataPtr
Definition: dg_projection.cpp:94
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
DomainEleOp
DomainEle::UserDataOperator DomainEleOp
Finire element operator type.
Definition: higher_derivatives.cpp:30
fun
auto fun
Function to approximate.
Definition: dg_projection.cpp:36
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
l
FTensor::Index< 'l', 3 > l
Definition: matrix_function.cpp:21