v0.14.0
AuxPoissonFunctions.hpp
/**
* \file AuxPoissonFunctions.hpp
* \example AuxPoissonFunctions.hpp
*
*/
#ifndef ___AUX_FUNCTIONS_HPP__
#define ___AUX_FUNCTIONS_HPP__
namespace PoissonExample {
struct AuxFunctions {
: cOmm(m_field.get_comm()), rAnk(m_field.get_comm_rank()) {}
/**
* 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]
* @param ghost_vec pointer to created ghost vector
* @return error code
*/
MoFEMErrorCode createGhostVec(Vec *ghost_vec) const {
int ghosts[] = {0};
int nb_locals = rAnk == 0 ? 1 : 0;
int nb_ghosts = rAnk > 0 ? 1 : 0;
CHKERR VecCreateGhost(cOmm, nb_locals, 1, nb_ghosts, ghosts, ghost_vec);
}
/**
* \brief Assemble error vector
*/
CHKERR VecAssemblyBegin(ghost_vec);
CHKERR VecAssemblyEnd(ghost_vec);
// accumulate errors from processors
CHKERR VecGhostUpdateBegin(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(ghost_vec, ADD_VALUES, SCATTER_REVERSE);
// scatter errors to all processors
CHKERR VecGhostUpdateBegin(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(ghost_vec, INSERT_VALUES, SCATTER_FORWARD);
}
/**
* \brief Print error
*/
double *e;
CHKERR VecGetArray(ghost_vec, &e);
CHKERR PetscPrintf(cOmm, "Approximation error %4.3e\n", sqrt(e[0]));
CHKERR VecRestoreArray(ghost_vec, &e);
}
/**
* \brief Test error
*/
double *e;
CHKERR VecGetArray(ghost_vec, &e);
// Check if error is zero, otherwise throw error
const double eps = 1e-8;
if ((sqrt(e[0]) > eps) || (!boost::math::isnormal(e[0]))) {
SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"Test failed, error too big");
}
CHKERR VecRestoreArray(ghost_vec, &e);
}
private:
MPI_Comm cOmm;
const int rAnk;
};
} // namespace PoissonExample
#endif //___AUX_FUNCTIONS_HPP__
PoissonExample::AuxFunctions::rAnk
const int rAnk
Definition: AuxPoissonFunctions.hpp:90
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
PoissonExample
Definition: AuxPoissonFunctions.hpp:12
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
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