v0.15.0
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | List of all members
AtomTest::OpError< FIELD_DIM > Struct Template Reference

Operator to evaluate errors. More...

Inheritance diagram for AtomTest::OpError< FIELD_DIM >:
[legend]
Collaboration diagram for AtomTest::OpError< FIELD_DIM >:
[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< MatrixDoubledataPtr
 

Detailed Description

template<int FIELD_DIM>
struct AtomTest::OpError< FIELD_DIM >

Operator to evaluate errors.

Examples
hanging_node_approx.cpp, higher_derivatives.cpp, and mofem/atom_tests/child_and_parent.cpp.

Definition at line 115 of file higher_derivatives.cpp.

Constructor & Destructor Documentation

◆ OpError() [1/2]

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

Definition at line 96 of file dg_projection.cpp.

97 : DomainEleOp(NOSPACE, OPSPACE), dataPtr(data_ptr) {}
@ NOSPACE
Definition definitions.h:83
DomainEle::UserDataOperator DomainEleOp
Finire element operator type.
boost::shared_ptr< MatrixDouble > dataPtr

◆ OpError() [2/2]

template<int FIELD_DIM>
AtomTest::OpError< FIELD_DIM >::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 }
constexpr char FIELD_NAME[]
boost::shared_ptr< CommonData > commonDataPtr

Member Function Documentation

◆ doWork() [1/2]

template<int FIELD_DIM>
MoFEMErrorCode AtomTest::OpError< FIELD_DIM >::doWork ( int  side,
EntityType  type,
EntData data 
)
inline
Examples
hanging_node_approx.cpp, higher_derivatives.cpp, and mofem/atom_tests/child_and_parent.cpp.

Definition at line 99 of file dg_projection.cpp.

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

◆ doWork() [2/2]

template<int FIELD_DIM>
MoFEMErrorCode AtomTest::OpError< FIELD_DIM >::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>(
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
142 FTensor::Index<'i', 2> i;
143 FTensor::Index<'j', 2> j;
144 FTensor::Index<'k', 2> k;
145 FTensor::Index<'l', 2> l;
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 }
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
FTensor::Index< 'i', SPACE_DIM > i
auto diff2_fun
Function second derivative.
auto diff_fun
Function derivative.
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
MoFEMErrorCode VecSetValues(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Assemble PETSc vector.

Member Data Documentation

◆ commonDataPtr

template<int FIELD_DIM>
boost::shared_ptr< CommonData > AtomTest::OpError< FIELD_DIM >::commonDataPtr

◆ dataPtr

template<int FIELD_DIM>
boost::shared_ptr<MatrixDouble> AtomTest::OpError< FIELD_DIM >::dataPtr
private

Definition at line 131 of file dg_projection.cpp.


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