v0.13.1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
PoissonExample::OpError Struct Reference

Evaluate error. More...

#include <users_modules/tutorials/cor-2to5/src/PoissonOperators.hpp>

Inheritance diagram for PoissonExample::OpError:
[legend]
Collaboration diagram for PoissonExample::OpError:
[legend]

Public Types

typedef boost::function< double(const double, const double, const double)> UVal
 
typedef boost::function< FTensor::Tensor1< double, 3 >(const double, const double, const double)> GVal
 

Public Member Functions

 OpError (UVal u_value, GVal g_value, boost::shared_ptr< VectorDouble > &field_vals, boost::shared_ptr< MatrixDouble > &grad_vals, Vec global_error)
 
MoFEMErrorCode doWork (int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
 
- Public Member Functions inherited from PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >
 OpBaseRhs (const std::string field_name)
 
MoFEMErrorCode doWork (int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
 This function is called by finite element. More...
 
virtual MoFEMErrorCode iNtegrate (EntitiesFieldData::EntData &data)=0
 Class dedicated to integrate operator. More...
 
virtual MoFEMErrorCode aSsemble (EntitiesFieldData::EntData &data)=0
 Class dedicated to assemble operator to global system vector. More...
 

Private Member Functions

MoFEMErrorCode iNtegrate (EntitiesFieldData::EntData &data)
 Integrate error. More...
 
MoFEMErrorCode aSsemble (EntitiesFieldData::EntData &data)
 Assemble error. More...
 

Private Attributes

Vec globalError
 ghost vector with global (integrated over volume) error More...
 
FTensor::Number< 0 > NX
 
FTensor::Number< 1 > NY
 
FTensor::Number< 2 > NZ
 
FTensor::Index< 'i', 3 > i
 
UVal uValue
 function with exact solution More...
 
GVal gValue
 function with exact solution for gradient More...
 
boost::shared_ptr< VectorDouble > fieldVals
 
boost::shared_ptr< MatrixDouble > gradVals
 

Additional Inherited Members

- Protected Attributes inherited from PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >
int nbRows
 < error code More...
 
int nbIntegrationPts
 number of integration points More...
 

Detailed Description

Evaluate error.

Definition at line 491 of file PoissonOperators.hpp.

Member Typedef Documentation

◆ GVal

Examples
PoissonOperators.hpp.

Definition at line 498 of file PoissonOperators.hpp.

◆ UVal

Examples
PoissonOperators.hpp.

Definition at line 495 of file PoissonOperators.hpp.

Constructor & Destructor Documentation

◆ OpError()

PoissonExample::OpError::OpError ( UVal  u_value,
GVal  g_value,
boost::shared_ptr< VectorDouble > &  field_vals,
boost::shared_ptr< MatrixDouble > &  grad_vals,
Vec  global_error 
)
Examples
PoissonOperators.hpp.

Definition at line 500 of file PoissonOperators.hpp.

503 : OpBaseRhs<VolumeElementForcesAndSourcesCore::UserDataOperator>("ERROR"),
504 globalError(global_error), uValue(u_value), gValue(g_value),
505 fieldVals(field_vals), gradVals(grad_vals) {}
Vec globalError
ghost vector with global (integrated over volume) error
UVal uValue
function with exact solution
boost::shared_ptr< MatrixDouble > gradVals
GVal gValue
function with exact solution for gradient
boost::shared_ptr< VectorDouble > fieldVals

Member Function Documentation

◆ aSsemble()

MoFEMErrorCode PoissonExample::OpError::aSsemble ( EntitiesFieldData::EntData data)
privatevirtual

Assemble error.

Implements PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >.

Examples
PoissonOperators.hpp.

Definition at line 575 of file PoissonOperators.hpp.

575 {
577 // set error on mesh
578 data.getFieldDofs()[0]->getFieldData() = sqrt(data.getFieldData()[0]);
579 // assemble vector to global error
580 CHKERR VecSetValue(globalError, 0, data.getFieldData()[0], ADD_VALUES);
582 }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535

◆ doWork()

MoFEMErrorCode PoissonExample::OpError::doWork ( int  row_side,
EntityType  row_type,
EntitiesFieldData::EntData row_data 
)
Examples
PoissonOperators.hpp.

Definition at line 507 of file PoissonOperators.hpp.

508 {
510 nbRows = row_data.getFieldData().size();
511 if (!nbRows)
513 nbIntegrationPts = getGaussPts().size2();
514 CHKERR iNtegrate(row_data);
515 CHKERR aSsemble(row_data);
517 }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &data)
Integrate error.
MoFEMErrorCode aSsemble(EntitiesFieldData::EntData &data)
Assemble error.

◆ iNtegrate()

MoFEMErrorCode PoissonExample::OpError::iNtegrate ( EntitiesFieldData::EntData data)
privatevirtual

Integrate error.

Implements PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >.

Examples
PoissonOperators.hpp.

Definition at line 535 of file PoissonOperators.hpp.

535 {
537 // clear field dofs
538 data.getFieldData().clear();
539 // get volume of element
540 const double vol = getVolume();
541 // get integration weight
542 auto t_w = getFTensor0IntegrationWeight();
543 // get solution at integration point
544 auto t_u = getFTensor0FromVec(*fieldVals);
545 // get solution at integration point
546 auto t_grad = getFTensor1FromMat<3>(*gradVals);
547 // get coordinates at integration point
548 auto t_coords = getFTensor1CoordsAtGaussPts();
549 // keep exact gradient and error or gradient
550 FTensor::Tensor1<double, 3> t_exact_grad, t_error_grad;
551 // integrate over
552 for (int gg = 0; gg != nbIntegrationPts; gg++) {
553 double alpha = vol * t_w;
554 // evaluate exact value
555 double exact_u = uValue(t_coords(NX), t_coords(NY), t_coords(NZ));
556 // evaluate exact gradient
557 t_exact_grad = gValue(t_coords(NX), t_coords(NY), t_coords(NZ));
558 // calculate gradient errro
559 t_error_grad(i) = t_grad(i) - t_exact_grad(i);
560 // error
561 double error = pow(t_u - exact_u, 2) + t_error_grad(i) * t_error_grad(i);
562 // iterate over base functions
563 data.getFieldData()[0] += alpha * error;
564 ++t_w; // move to next integration point
565 ++t_u; // next value of function at integration point
566 ++t_grad; // next gradient at integration point
567 ++t_coords; // next coordinate at integration point
568 }
570 }
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
FTensor::Number< 2 > NZ
FTensor::Index< 'i', 3 > i
FTensor::Number< 1 > NY
FTensor::Number< 0 > NX

Member Data Documentation

◆ fieldVals

boost::shared_ptr<VectorDouble> PoissonExample::OpError::fieldVals
private
Examples
PoissonOperators.hpp.

Definition at line 529 of file PoissonOperators.hpp.

◆ globalError

Vec PoissonExample::OpError::globalError
private

ghost vector with global (integrated over volume) error

Examples
PoissonOperators.hpp.

Definition at line 520 of file PoissonOperators.hpp.

◆ gradVals

boost::shared_ptr<MatrixDouble> PoissonExample::OpError::gradVals
private
Examples
PoissonOperators.hpp.

Definition at line 530 of file PoissonOperators.hpp.

◆ gValue

GVal PoissonExample::OpError::gValue
private

function with exact solution for gradient

Examples
PoissonOperators.hpp.

Definition at line 527 of file PoissonOperators.hpp.

◆ i

FTensor::Index<'i', 3> PoissonExample::OpError::i
private
Examples
PoissonOperators.hpp.

Definition at line 525 of file PoissonOperators.hpp.

◆ NX

FTensor::Number<0> PoissonExample::OpError::NX
private
Examples
PoissonOperators.hpp.

Definition at line 522 of file PoissonOperators.hpp.

◆ NY

FTensor::Number<1> PoissonExample::OpError::NY
private
Examples
PoissonOperators.hpp.

Definition at line 523 of file PoissonOperators.hpp.

◆ NZ

FTensor::Number<2> PoissonExample::OpError::NZ
private
Examples
PoissonOperators.hpp.

Definition at line 524 of file PoissonOperators.hpp.

◆ uValue

UVal PoissonExample::OpError::uValue
private

function with exact solution

Examples
PoissonOperators.hpp.

Definition at line 526 of file PoissonOperators.hpp.


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