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

Evaluate error. More...

#include <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 494 of file PoissonOperators.hpp.

Member Typedef Documentation

◆ GVal

typedef boost::function<FTensor::Tensor1<double, 3> const double, const double, const double)> PoissonExample::OpError::GVal

Definition at line 501 of file PoissonOperators.hpp.

◆ UVal

typedef boost::function<double(const double, const double, const double)> PoissonExample::OpError::UVal

Definition at line 498 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 
)
inline

Definition at line 503 of file PoissonOperators.hpp.

506  : OpBaseRhs<VolumeElementForcesAndSourcesCore::UserDataOperator>("ERROR"),
507  globalError(global_error), uValue(u_value), gValue(g_value),
508  fieldVals(field_vals), gradVals(grad_vals) {}

Member Function Documentation

◆ aSsemble()

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

Assemble error.

Definition at line 578 of file PoissonOperators.hpp.

578  {
580  // set error on mesh
581  data.getFieldDofs()[0]->getFieldData() = sqrt(data.getFieldData()[0]);
582  // assemble vector to global error
583  CHKERR VecSetValue(globalError, 0, data.getFieldData()[0], ADD_VALUES);
585  }

◆ doWork()

MoFEMErrorCode PoissonExample::OpError::doWork ( int  row_side,
EntityType  row_type,
EntitiesFieldData::EntData row_data 
)
inline

Definition at line 510 of file PoissonOperators.hpp.

511  {
513  nbRows = row_data.getFieldData().size();
514  if (!nbRows)
516  nbIntegrationPts = getGaussPts().size2();
517  CHKERR iNtegrate(row_data);
518  CHKERR aSsemble(row_data);
520  }

◆ iNtegrate()

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

Integrate error.

Definition at line 538 of file PoissonOperators.hpp.

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

Member Data Documentation

◆ fieldVals

boost::shared_ptr<VectorDouble> PoissonExample::OpError::fieldVals
private

Definition at line 532 of file PoissonOperators.hpp.

◆ globalError

Vec PoissonExample::OpError::globalError
private

ghost vector with global (integrated over volume) error

Definition at line 523 of file PoissonOperators.hpp.

◆ gradVals

boost::shared_ptr<MatrixDouble> PoissonExample::OpError::gradVals
private

Definition at line 533 of file PoissonOperators.hpp.

◆ gValue

GVal PoissonExample::OpError::gValue
private

function with exact solution for gradient

Definition at line 530 of file PoissonOperators.hpp.

◆ i

FTensor::Index<'i', 3> PoissonExample::OpError::i
private

Definition at line 528 of file PoissonOperators.hpp.

◆ NX

FTensor::Number<0> PoissonExample::OpError::NX
private

Definition at line 525 of file PoissonOperators.hpp.

◆ NY

FTensor::Number<1> PoissonExample::OpError::NY
private

Definition at line 526 of file PoissonOperators.hpp.

◆ NZ

FTensor::Number<2> PoissonExample::OpError::NZ
private

Definition at line 527 of file PoissonOperators.hpp.

◆ uValue

UVal PoissonExample::OpError::uValue
private

function with exact solution

Definition at line 529 of file PoissonOperators.hpp.


The documentation for this struct was generated from the following file:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
PoissonExample::OpError::globalError
Vec globalError
ghost vector with global (integrated over volume) error
Definition: PoissonOperators.hpp:523
PoissonExample::OpError::fieldVals
boost::shared_ptr< VectorDouble > fieldVals
Definition: PoissonOperators.hpp:532
FTensor::Tensor1< double, 3 >
MoFEM::EntitiesFieldData::EntData::getFieldData
const VectorDouble & getFieldData() const
get dofs values
Definition: EntitiesFieldData.hpp:1254
PoissonExample::OpError::gValue
GVal gValue
function with exact solution for gradient
Definition: PoissonOperators.hpp:530
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
PoissonExample::OpError::NX
FTensor::Number< 0 > NX
Definition: PoissonOperators.hpp:525
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
PoissonExample::OpError::NZ
FTensor::Number< 2 > NZ
Definition: PoissonOperators.hpp:527
MoFEM::EntitiesFieldData::EntData::getFieldDofs
const VectorDofs & getFieldDofs() const
get dofs data stature FEDofEntity
Definition: EntitiesFieldData.hpp:1269
PoissonExample::OpError::NY
FTensor::Number< 1 > NY
Definition: PoissonOperators.hpp:526
PoissonExample::OpError::i
FTensor::Index< 'i', 3 > i
Definition: PoissonOperators.hpp:528
PoissonExample::OpError::uValue
UVal uValue
function with exact solution
Definition: PoissonOperators.hpp:529
PoissonExample::OpError::gradVals
boost::shared_ptr< MatrixDouble > gradVals
Definition: PoissonOperators.hpp:533
PoissonExample::OpError::iNtegrate
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &data)
Integrate error.
Definition: PoissonOperators.hpp:538
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
PoissonExample::OpError::aSsemble
MoFEMErrorCode aSsemble(EntitiesFieldData::EntData &data)
Assemble error.
Definition: PoissonOperators.hpp:578
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >::nbRows
int nbRows
< error code
Definition: PoissonOperators.hpp:207
PoissonExample::OpBaseRhs< VolumeElementForcesAndSourcesCore::UserDataOperator >::nbIntegrationPts
int nbIntegrationPts
number of integration points
Definition: PoissonOperators.hpp:208