v0.14.0
Loading...
Searching...
No Matches
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
12namespace PoissonExample {
13
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 */
43 MoFEMErrorCode assembleGhostVector(Vec ghost_vec) const {
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 */
60 MoFEMErrorCode printError(Vec ghost_vec) {
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 */
73 MoFEMErrorCode testError(Vec ghost_vec) {
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
88private:
89 MPI_Comm cOmm;
90 const int rAnk;
91};
92
93} // namespace PoissonExample
94
95#endif //___AUX_FUNCTIONS_HPP__
static const double eps
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
#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
Deprecated interface functions.
MoFEMErrorCode createGhostVec(Vec *ghost_vec) const
MoFEMErrorCode testError(Vec ghost_vec)
Test error.
AuxFunctions(const MoFEM::Interface &m_field)
MoFEMErrorCode assembleGhostVector(Vec ghost_vec) const
Assemble error vector.
MoFEMErrorCode printError(Vec ghost_vec)
Print error.