26static char help[] =
"Partition-independent test directions\n\n";
32constexpr double LENGTH = 0.7;
42 const std::array<double, 3> &xyz) {
46 constexpr double a[3] = {0.20, -0.15, 0.10};
47 constexpr double b[3][2] = {{0.45, 0.25}, {0.40, 0.30}, {0.35, 0.35}};
48 constexpr double k[3][2][3] = {
49 {{1.3, -0.7, 0.9}, {-0.4, 1.1, 1.7}},
50 {{0.8, 1.5, -0.6}, {1.9, -0.3, 0.5}},
51 {{-1.2, 0.6, 1.4}, {0.7, 1.8, -0.9}}};
52 constexpr double phi[3][2] = {{0.3, 1.1}, {-0.8, 0.4}, {1.3, -0.2}};
55 for (
int m = 0;
m != 2; ++
m) {
56 double arg =
phi[
c][
m];
57 for (
int d = 0;
d != 3; ++
d)
59 value += b[
c][
m] * std::sin(arg);
67int main(
int argc,
char *argv[]) {
74 moab::Interface &moab = moab_core;
92 const auto function = smoothVertexDirection(LENGTH);
103 int size, ghost_size;
106 CHKERR VecGhostGetLocalForm(
v, &local);
107 CHKERR VecGetLocalSize(local, &ghost_size);
109 CHKERR VecGetArrayRead(local, &array);
112 for (
auto &dof : *
getProblemPtr(dm)->getNumeredColDofsPtr()) {
113 const auto idx = dof->getPetscLocalDofIdx();
114 if (idx < 0 || (ghosts ? (idx < size || idx >= ghost_size)
117 const auto ent = dof->getEnt();
119 const bool in_ents = !ents || ents->find(ent) != ents->end();
120 if (dof->getBitNumber() == u_bit && in_ents) {
121 std::array<double, 3> xyz{0., 0., 0.};
123 CHKERR moab.get_coords(&ent, 1, xyz.data());
124 expected = function(*dof, xyz);
126 error = std::max(error, std::abs(array[idx] - expected));
129 CHKERR VecRestoreArrayRead(local, &array);
130 CHKERR VecGhostRestoreLocalForm(
v, &local);
132 ghosts ?
"ghost values" :
"owned values", error, 1., TOL);
134 CHKERR MPI_Allreduce(&checked, &global_checked, 1, MPI_INT, MPI_SUM,
137 if (!global_checked && (!ghosts || m_field.
get_comm_size() > 1))
146 std::array<boost::shared_ptr<NumeredDofEntity>,
SPACE_DIM> coeff_dofs;
148 if (dof->getBitNumber() == u_bit &&
150 coeff_dofs[dof->getDofCoeffIdx()] = dof;
151 for (
auto &dof : coeff_dofs)
154 "Missing vertex DOF of U in the local problem");
157 auto reference_norm2 = [&](
const Range &verts) {
159 for (
auto vertex : verts) {
160 std::array<double, 3> xyz;
161 CHK_MOAB_THROW(moab.get_coords(&vertex, 1, xyz.data()),
"Get coords");
163 const double value = function(*coeff_dofs[
c], xyz);
164 sum += value * value;
171 const std::string &
name) {
174 CHKERR VecNorm(
v, NORM_2, &norm);
175 const double expected = reference_norm2(verts);
179 <<
name <<
" squared norm " << std::setprecision(15) << norm * norm;
188 CHKERR moab.get_connectivity(
faces, skin_verts,
true);
190 auto skin_ptr = boost::make_shared<Range>(skin_verts);
194 CHKERR moab.get_adjacencies(skin_verts, 1,
false, skin_edges,
195 moab::Interface::UNION);
196 skin_ptr->merge(skin_edges);
201 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
202 CHKERR check_values(
v,
nullptr,
false);
207 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
211 CHKERR testing->addTestCommandLine(
"", 3,
"restricted", [&]() {
213 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function, skin_ptr);
214 CHKERR check_values(
v, skin_ptr,
false);
215 CHKERR check_norm(
v, skin_verts,
"skin vertices");
220 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
221 CHKERR check_values(
v,
nullptr,
true);
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.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
#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