v0.14.0
AuxPoissonFunctions.hpp
Go to the documentation of this file.
1 /**
2  * \file AuxPoissonFunctions.hpp
3  * \example AuxPoissonFunctions.hpp
4  *
5  */
6 
7 
8 
9 #ifndef ___AUX_FUNCTIONS_HPP__
10 #define ___AUX_FUNCTIONS_HPP__
11 
12 namespace PoissonExample {
13 
14 struct AuxFunctions {
15 
17  : cOmm(m_field.get_comm()), rAnk(m_field.get_comm_rank()) {}
18 
19  /**
20  * Create ghost vector to assemble errors from all element on distributed
21  mesh.
22  * Ghost vector has size 1, where one element is owned by processor 0, other
23  processor
24  * have one ghost element of zero element at processor 0.
25 
26  * [createGhostVec description]
27  * @param ghost_vec pointer to created ghost vector
28  * @return error code
29  */
30  MoFEMErrorCode createGhostVec(Vec *ghost_vec) const {
31 
33  int ghosts[] = {0};
34  int nb_locals = rAnk == 0 ? 1 : 0;
35  int nb_ghosts = rAnk > 0 ? 1 : 0;
36  CHKERR VecCreateGhost(cOmm, nb_locals, 1, nb_ghosts, ghosts, ghost_vec);
38  }
39 
40  /**
41  * \brief Assemble error vector
42  */
44 
46  CHKERR VecAssemblyBegin(ghost_vec);
47  CHKERR VecAssemblyEnd(ghost_vec);
48  // accumulate errors from processors
49  CHKERR VecGhostUpdateBegin(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
50  CHKERR VecGhostUpdateEnd(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
51  // scatter errors to all processors
52  CHKERR VecGhostUpdateBegin(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
53  CHKERR VecGhostUpdateEnd(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
55  }
56 
57  /**
58  * \brief Print error
59  */
61 
63  double *e;
64  CHKERR VecGetArray(ghost_vec, &e);
65  CHKERR PetscPrintf(cOmm, "Approximation error %4.3e\n", sqrt(e[0]));
66  CHKERR VecRestoreArray(ghost_vec, &e);
68  }
69 
70  /**
71  * \brief Test error
72  */
74 
76  double *e;
77  CHKERR VecGetArray(ghost_vec, &e);
78  // Check if error is zero, otherwise throw error
79  const double eps = 1e-8;
80  if ((sqrt(e[0]) > eps) || (!boost::math::isnormal(e[0]))) {
81  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
82  "Test failed, error too big");
83  }
84  CHKERR VecRestoreArray(ghost_vec, &e);
86  }
87 
88 private:
89  MPI_Comm cOmm;
90  const int rAnk;
91 };
92 
93 } // namespace PoissonExample
94 
95 #endif //___AUX_FUNCTIONS_HPP__
PoissonExample::AuxFunctions
Definition: AuxPoissonFunctions.hpp:14
PoissonExample::AuxFunctions::rAnk
const int rAnk
Definition: AuxPoissonFunctions.hpp:90
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
PoissonExample
Definition: AuxPoissonFunctions.hpp:12
PoissonExample::AuxFunctions::cOmm
MPI_Comm cOmm
Definition: AuxPoissonFunctions.hpp:89
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
PoissonExample::AuxFunctions::createGhostVec
MoFEMErrorCode createGhostVec(Vec *ghost_vec) const
Definition: AuxPoissonFunctions.hpp:30
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
PoissonExample::AuxFunctions::testError
MoFEMErrorCode testError(Vec ghost_vec)
Test error.
Definition: AuxPoissonFunctions.hpp:73
PoissonExample::AuxFunctions::printError
MoFEMErrorCode printError(Vec ghost_vec)
Print error.
Definition: AuxPoissonFunctions.hpp:60
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
PoissonExample::AuxFunctions::AuxFunctions
AuxFunctions(const MoFEM::Interface &m_field)
Definition: AuxPoissonFunctions.hpp:16
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
PoissonExample::AuxFunctions::assembleGhostVector
MoFEMErrorCode assembleGhostVector(Vec ghost_vec) const
Assemble error vector.
Definition: AuxPoissonFunctions.hpp:43