v0.13.0
Public Member Functions | Private Attributes | List of all members
PoissonExample::AuxFunctions Struct Reference

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

Public Member Functions

 AuxFunctions (const MoFEM::Interface &m_field)
 
MoFEMErrorCode createGhostVec (Vec *ghost_vec) const
 
MoFEMErrorCode assembleGhostVector (Vec ghost_vec) const
 Assemble error vector. More...
 
MoFEMErrorCode printError (Vec ghost_vec)
 Print error. More...
 
MoFEMErrorCode testError (Vec ghost_vec)
 Test error. More...
 

Private Attributes

MPI_Comm cOmm
 
const int rAnk
 

Detailed Description

Examples
analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, and analytical_poisson_field_split.cpp.

Definition at line 26 of file AuxPoissonFunctions.hpp.

Constructor & Destructor Documentation

◆ AuxFunctions()

PoissonExample::AuxFunctions::AuxFunctions ( const MoFEM::Interface m_field)
Examples
AuxPoissonFunctions.hpp.

Definition at line 28 of file AuxPoissonFunctions.hpp.

29  : cOmm(m_field.get_comm()), rAnk(m_field.get_comm_rank()) {}
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0

Member Function Documentation

◆ assembleGhostVector()

MoFEMErrorCode PoissonExample::AuxFunctions::assembleGhostVector ( Vec  ghost_vec) const

Assemble error vector.

Examples
AuxPoissonFunctions.hpp, analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, and analytical_poisson_field_split.cpp.

Definition at line 55 of file AuxPoissonFunctions.hpp.

55  {
56 
58  CHKERR VecAssemblyBegin(ghost_vec);
59  CHKERR VecAssemblyEnd(ghost_vec);
60  // accumulate errors from processors
61  CHKERR VecGhostUpdateBegin(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
62  CHKERR VecGhostUpdateEnd(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
63  // scatter errors to all processors
64  CHKERR VecGhostUpdateBegin(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
65  CHKERR VecGhostUpdateEnd(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
67  }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548

◆ createGhostVec()

MoFEMErrorCode PoissonExample::AuxFunctions::createGhostVec ( Vec *  ghost_vec) const

Create ghost vector to assemble errors from all element on distributed mesh. Ghost vector has size 1, where one element is owned by processor 0, other processor have one ghost element of zero element at processor 0.

[createGhostVec description]

Parameters
ghost_vecpointer to created ghost vector
Returns
error code
Examples
AuxPoissonFunctions.hpp, analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, and analytical_poisson_field_split.cpp.

Definition at line 42 of file AuxPoissonFunctions.hpp.

42  {
43 
45  int ghosts[] = {0};
46  int nb_locals = rAnk == 0 ? 1 : 0;
47  int nb_ghosts = rAnk > 0 ? 1 : 0;
48  CHKERR VecCreateGhost(cOmm, nb_locals, 1, nb_ghosts, ghosts, ghost_vec);
50  }

◆ printError()

MoFEMErrorCode PoissonExample::AuxFunctions::printError ( Vec  ghost_vec)

Print error.

Examples
AuxPoissonFunctions.hpp, analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, and analytical_poisson_field_split.cpp.

Definition at line 72 of file AuxPoissonFunctions.hpp.

72  {
73 
75  double *e;
76  CHKERR VecGetArray(ghost_vec, &e);
77  CHKERR PetscPrintf(cOmm, "Approximation error %4.3e\n", sqrt(e[0]));
78  CHKERR VecRestoreArray(ghost_vec, &e);
80  }

◆ testError()

MoFEMErrorCode PoissonExample::AuxFunctions::testError ( Vec  ghost_vec)

Test error.

Examples
AuxPoissonFunctions.hpp, analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, and analytical_poisson_field_split.cpp.

Definition at line 85 of file AuxPoissonFunctions.hpp.

85  {
86 
88  double *e;
89  CHKERR VecGetArray(ghost_vec, &e);
90  // Check if error is zero, otherwise throw error
91  const double eps = 1e-8;
92  if ((sqrt(e[0]) > eps) || (!boost::math::isnormal(e[0]))) {
93  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
94  "Test failed, error too big");
95  }
96  CHKERR VecRestoreArray(ghost_vec, &e);
98  }
static const double eps
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:53

Member Data Documentation

◆ cOmm

MPI_Comm PoissonExample::AuxFunctions::cOmm
private
Examples
AuxPoissonFunctions.hpp.

Definition at line 101 of file AuxPoissonFunctions.hpp.

◆ rAnk

const int PoissonExample::AuxFunctions::rAnk
private
Examples
AuxPoissonFunctions.hpp.

Definition at line 102 of file AuxPoissonFunctions.hpp.


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