67 {
68
70
71 try {
72
73 moab::Core moab_core;
74 moab::Interface &moab = moab_core;
78
81
88
92 const auto function = smoothVertexDirection(LENGTH);
94
95
99
101 bool ghosts) {
103 int size, ghost_size;
106 CHKERR VecGhostGetLocalForm(
v, &local);
107 CHKERR VecGetLocalSize(local, &ghost_size);
108 const double *array;
109 CHKERR VecGetArrayRead(local, &array);
110 double error = 0;
111 int checked = 0;
112 for (
auto &dof : *
getProblemPtr(dm)->getNumeredColDofsPtr()) {
113 const auto idx = dof->getPetscLocalDofIdx();
114 if (idx < 0 || (ghosts ? (idx < size || idx >= ghost_size)
116 continue;
117 const auto ent = dof->getEnt();
118 double expected = 0;
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);
125 }
126 error = std::max(error, std::abs(array[idx] - expected));
127 ++checked;
128 }
129 CHKERR VecRestoreArrayRead(local, &array);
130 CHKERR VecGhostRestoreLocalForm(
v, &local);
132 ghosts ? "ghost values" : "owned values", error, 1., TOL);
133 int global_checked;
134 CHKERR MPI_Allreduce(&checked, &global_checked, 1, MPI_INT, MPI_SUM,
136
137 if (!global_checked && (!ghosts || m_field.
get_comm_size() > 1))
139 "No DOFs checked");
141 };
142
143
144
145
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)
152 if (!dof)
154 "Missing vertex DOF of U in the local problem");
155
156
157 auto reference_norm2 = [&](
const Range &verts) {
158 double sum = 0;
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;
165 }
166 }
167 return sum;
168 };
169
171 const std::string &
name) {
173 double norm;
174 CHKERR VecNorm(
v, NORM_2, &norm);
175 const double expected = reference_norm2(verts);
177 TOL);
179 <<
name <<
" squared norm " << std::setprecision(15) << norm * norm;
181 };
182
184 {
188 CHKERR moab.get_connectivity(
faces, skin_verts,
true);
189 }
190 auto skin_ptr = boost::make_shared<Range>(skin_verts);
191
192 {
194 CHKERR moab.get_adjacencies(skin_verts, 1,
false, skin_edges,
195 moab::Interface::UNION);
196 skin_ptr->merge(skin_edges);
197 }
198
201 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
202 CHKERR check_values(
v,
nullptr,
false);
204 });
207 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
210 });
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");
217 });
220 auto v = opt->setDirectionFromFunction(dm, {
"U"}, function);
221 CHKERR check_values(
v,
nullptr,
true);
223 });
225 }
227
229 return 0;
230}
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)
const FTensor::Tensor2< T, Dim, Dim > Vec
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto getProblemPtr(DM dm)
get problem pointer from DM
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.
Calculate directional derivative of the right hand side and compare it with tangent matrix derivative...
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.