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

Evaluate error. More...

#include <users_modules/basic_finite_elements/poisson/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, DataForcesAndSourcesCore::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, DataForcesAndSourcesCore::EntData &row_data)
 This function is called by finite element. More...
 

Private Member Functions

MoFEMErrorCode iNtegrate (DataForcesAndSourcesCore::EntData &data)
 Integrate error. More...
 
MoFEMErrorCode aSsemble (DataForcesAndSourcesCore::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 504 of file PoissonOperators.hpp.

Member Typedef Documentation

◆ GVal

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

Definition at line 511 of file PoissonOperators.hpp.

◆ UVal

typedef boost::function<double(const double, const double, const double)> PoissonExample::OpError::UVal
Examples
PoissonOperators.hpp.

Definition at line 508 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 513 of file PoissonOperators.hpp.

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

Member Function Documentation

◆ aSsemble()

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

Assemble error.

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

Examples
PoissonOperators.hpp.

Definition at line 588 of file PoissonOperators.hpp.

588  {
590  // set error on mesh
591  data.getFieldDofs()[0]->getFieldData() = sqrt(data.getFieldData()[0]);
592  // assemble vector to global error
593  CHKERR VecSetValue(globalError, 0, data.getFieldData()[0], ADD_VALUES);
595  }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
Vec globalError
ghost vector with global (integrated over volume) error
#define CHKERR
Inline error check.
Definition: definitions.h:596
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ doWork()

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

Definition at line 520 of file PoissonOperators.hpp.

521  {
523  nbRows = row_data.getFieldData().size();
524  if (!nbRows)
526  nbIntegrationPts = getGaussPts().size2();
527  CHKERR iNtegrate(row_data);
528  CHKERR aSsemble(row_data);
530  }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
#define CHKERR
Inline error check.
Definition: definitions.h:596
MoFEMErrorCode iNtegrate(DataForcesAndSourcesCore::EntData &data)
Integrate error.
MoFEMErrorCode aSsemble(DataForcesAndSourcesCore::EntData &data)
Assemble error.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ iNtegrate()

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

Integrate error.

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

Examples
PoissonOperators.hpp.

Definition at line 548 of file PoissonOperators.hpp.

548  {
550  // clear field dofs
551  data.getFieldData().clear();
552  // get volume of element
553  const double vol = getVolume();
554  // get integration weight
555  auto t_w = getFTensor0IntegrationWeight();
556  // get solution at integration point
557  auto t_u = getFTensor0FromVec(*fieldVals);
558  // get solution at integration point
559  auto t_grad = getFTensor1FromMat<3>(*gradVals);
560  // get coordinates at integration point
561  auto t_coords = getFTensor1CoordsAtGaussPts();
562  // keep exact gradient and error or gradient
563  FTensor::Tensor1<double, 3> t_exact_grad, t_error_grad;
564  // integrate over
565  for (int gg = 0; gg != nbIntegrationPts; gg++) {
566  double alpha = vol * t_w;
567  // evaluate exact value
568  double exact_u = uValue(t_coords(NX), t_coords(NY), t_coords(NZ));
569  // evaluate exact gradient
570  t_exact_grad = gValue(t_coords(NX), t_coords(NY), t_coords(NZ));
571  // calculate gradient errro
572  t_error_grad(i) = t_grad(i) - t_exact_grad(i);
573  // error
574  double error = pow(t_u - exact_u, 2) + t_error_grad(i) * t_error_grad(i);
575  // iterate over base functions
576  data.getFieldData()[0] += alpha * error;
577  ++t_w; // move to next integration point
578  ++t_u; // next value of function at integration point
579  ++t_grad; // next gradient at integration point
580  ++t_coords; // next coordinate at integration point
581  }
583  }
boost::shared_ptr< MatrixDouble > gradVals
static FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:142
boost::shared_ptr< VectorDouble > fieldVals
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
FTensor::Index< 'i', 3 > i
UVal uValue
function with exact solution
FTensor::Number< 0 > NX
static moab::Error error
FTensor::Number< 2 > NZ
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
FTensor::Number< 1 > NY
GVal gValue
function with exact solution for gradient

Member Data Documentation

◆ fieldVals

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

Definition at line 542 of file PoissonOperators.hpp.

◆ globalError

Vec PoissonExample::OpError::globalError
private

ghost vector with global (integrated over volume) error

Examples
PoissonOperators.hpp.

Definition at line 533 of file PoissonOperators.hpp.

◆ gradVals

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

Definition at line 543 of file PoissonOperators.hpp.

◆ gValue

GVal PoissonExample::OpError::gValue
private

function with exact solution for gradient

Examples
PoissonOperators.hpp.

Definition at line 540 of file PoissonOperators.hpp.

◆ i

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

Definition at line 538 of file PoissonOperators.hpp.

◆ NX

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

Definition at line 535 of file PoissonOperators.hpp.

◆ NY

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

Definition at line 536 of file PoissonOperators.hpp.

◆ NZ

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

Definition at line 537 of file PoissonOperators.hpp.

◆ uValue

UVal PoissonExample::OpError::uValue
private

function with exact solution

Examples
PoissonOperators.hpp.

Definition at line 539 of file PoissonOperators.hpp.


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