Check OperatorsTester::setDirectionFromFunctionThe direction is a smooth function of the vertex positions, defined here.
The whole mesh is loaded on every rank and the problem is partitioned afterwards, so each rank can compute reference values from all mesh vertices, independently of the DOF partition and numbering. Equal references on one and two ranks show that the direction does not depend on the partition.
static char help[] =
"Partition-independent test directions\n\n";
namespace {
constexpr double LENGTH = 0.7;
const std::array<double, 3> &xyz) {
if (type_from_handle(dof.
getEnt()) != MBVERTEX)
return 0.;
constexpr double a[3] = {0.20, -0.15, 0.10};
constexpr double b[3][2] = {{0.45, 0.25}, {0.40, 0.30}, {0.35, 0.35}};
constexpr double k[3][2][3] = {
{{1.3, -0.7, 0.9}, {-0.4, 1.1, 1.7}},
{{0.8, 1.5, -0.6}, {1.9, -0.3, 0.5}},
{{-1.2, 0.6, 1.4}, {0.7, 1.8, -0.9}}};
constexpr double phi[3][2] = {{0.3, 1.1}, {-0.8, 0.4}, {1.3, -0.2}};
for (
int m = 0;
m != 2; ++
m) {
for (
int d = 0;
d != 3; ++
d)
value += b[
c][
m] * std::sin(arg);
}
return value;
};
}
}
int main(
int argc,
char *argv[]) {
try {
moab::Core moab_core;
moab::Interface &moab = moab_core;
CHKERR DMRegister_MoFEM(
"DMMOFEM");
const auto function = smoothVertexDirection(LENGTH);
bool ghosts) {
Vec local;
CHKERR VecGhostGetLocalForm(
v, &local);
CHKERR VecGetLocalSize(local, &ghost_size);
const double *array;
CHKERR VecGetArrayRead(local, &array);
double error = 0;
int checked = 0;
for (auto &dof : *getProblemPtr(dm)->getNumeredColDofsPtr()) {
const auto idx = dof->getPetscLocalDofIdx();
if (idx < 0 || (ghosts ? (idx < size || idx >= ghost_size)
continue;
const auto ent = dof->getEnt();
double expected = 0;
const bool in_ents = !ents || ents->find(ent) != ents->end();
if (dof->getBitNumber() == u_bit && in_ents) {
std::array<double, 3> xyz{0., 0., 0.};
CHKERR moab.get_coords(&ent, 1, xyz.data());
expected = function(*dof, xyz);
}
error = std::max(error, std::abs(array[idx] - expected));
++checked;
}
CHKERR VecRestoreArrayRead(local, &array);
CHKERR VecGhostRestoreLocalForm(
v, &local);
ghosts ? "ghost values" : "owned values", error, 1., TOL);
int global_checked;
CHKERR MPI_Allreduce(&checked, &global_checked, 1, MPI_INT, MPI_SUM,
"No DOFs checked");
};
std::array<boost::shared_ptr<NumeredDofEntity>,
SPACE_DIM> coeff_dofs;
if (dof->getBitNumber() == u_bit &&
coeff_dofs[dof->getDofCoeffIdx()] = dof;
for (auto &dof : coeff_dofs)
if (!dof)
"Missing vertex DOF of U in the local problem");
auto reference_norm2 = [&](
const Range &verts) {
double sum = 0;
for (auto vertex : verts) {
std::array<double, 3> xyz;
CHK_MOAB_THROW(moab.get_coords(&vertex, 1, xyz.data()),
"Get coords");
const double value = function(*coeff_dofs[
c], xyz);
sum += value * value;
}
}
return sum;
};
const std::string &
name) {
double norm;
const double expected = reference_norm2(verts);
TOL);
<<
name <<
" squared norm " << std::setprecision(15) << norm * norm;
};
{
}
auto skin_ptr = boost::make_shared<Range>(skin_verts);
{
CHKERR moab.get_adjacencies(skin_verts, 1,
false, skin_edges,
moab::Interface::UNION);
skin_ptr->merge(skin_edges);
}
auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
CHKERR check_values(
v,
nullptr,
false);
});
auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
});
auto v = opt->setDirectionFromFunction(dm, {
"U"}, function, skin_ptr);
CHKERR check_values(
v, skin_ptr,
false);
CHKERR check_norm(
v, skin_verts,
"skin vertices");
});
auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
CHKERR check_values(
v,
nullptr,
true);
});
}
return 0;
}
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
std::vector< int > vertices
void simple(double P1[], double P2[], double P3[], double c[], const int N)
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'k', 3 > k
implementation of Data Operators for Forces and Sources
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto getProblemPtr(DM dm)
get problem pointer from DM
FTensor::Index< 'm', 3 > m
virtual int get_comm_size() const =0
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
virtual MPI_Comm & get_comm() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
keeps information about indexed dofs for the problem
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative...
std::function< double(const NumeredDofEntity &dof, const std::array< double, 3 > &xyz)> DirectionFunction
Value of a test direction for one DOF.
Simple interface for fast problem set-up.
MoFEMErrorCode getOptions()
get options
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
FieldCoefficientsNumber getDofCoeffIdx() const
EntityHandle getEnt() const