19int main(
int argc,
char *argv[]) {
25 moab::Core mb_instance;
26 moab::Interface &moab = mb_instance;
35 PetscBool flg = PETSC_TRUE;
37 PetscBool test_jacobian = PETSC_FALSE;
63 Range triangle_springs;
65 if (it->getName().compare(0, 9,
"SPRING_BC") == 0) {
67 triangle_springs,
true);
73 "MESH_NODE_POSITIONS");
75 m_field,
"SPATIAL_POSITION",
"MESH_NODE_POSITIONS", triangle_springs);
85 PetscRandomCreate(PETSC_COMM_WORLD, &rctx);
87 auto set_coord = [&](
VectorAdaptor &&field_data,
double *x,
double *y,
92 PetscRandomGetValue(rctx, &value);
93 field_data[0] = (*x) + (value - 0.5) *
scale;
94 PetscRandomGetValue(rctx, &value);
95 field_data[1] = (*y) + (value - 0.5) *
scale;
96 PetscRandomGetValue(rctx, &value);
97 field_data[2] = (*z) + (value - 0.5) *
scale;
104 set_coord,
"MESH_NODE_POSITIONS");
106 PetscRandomDestroy(&rctx);
108 boost::shared_ptr<NeumannForcesSurface> surfacePressure(
111 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE> fe_rhs_ptr(
112 surfacePressure, &(surfacePressure->getLoopFe()));
113 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE> fe_lhs_ptr(
114 surfacePressure, &(surfacePressure->getLoopFeLhs()));
115 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE> fe_mat_rhs_ptr(
116 surfacePressure, &(surfacePressure->getLoopFeMatRhs()));
117 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE> fe_mat_lhs_ptr(
118 surfacePressure, &(surfacePressure->getLoopFeMatLhs()));
121 "MESH_NODE_POSITIONS");
123 "MESH_NODE_POSITIONS");
125 "MESH_NODE_POSITIONS");
127 "MESH_NODE_POSITIONS");
129 boost::shared_ptr<NeumannForcesSurface> surfaceForce(
132 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE>
133 fe_rhs_surface_force_ptr(surfaceForce, &(surfaceForce->getLoopFe()));
134 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE>
135 fe_lhs_surface_force_ptr(surfaceForce, &(surfaceForce->getLoopFeLhs()));
136 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE>
137 fe_mat_rhs_surface_force_ptr(surfaceForce,
138 &(surfaceForce->getLoopFeMatRhs()));
139 boost::shared_ptr<NeumannForcesSurface::MyTriangleFE>
140 fe_mat_lhs_surface_force_ptr(surfaceForce,
141 &(surfaceForce->getLoopFeMatLhs()));
144 fe_rhs_surface_force_ptr->getOpPtrVector(), {},
145 "MESH_NODE_POSITIONS");
147 fe_lhs_surface_force_ptr->getOpPtrVector(), {},
148 "MESH_NODE_POSITIONS");
150 fe_mat_rhs_surface_force_ptr->getOpPtrVector(), {},
151 "MESH_NODE_POSITIONS");
153 fe_mat_lhs_surface_force_ptr->getOpPtrVector(), {},
154 "MESH_NODE_POSITIONS");
157 CHKERR moab.get_entities_by_type(0, MBVERTEX, nodes,
false);
162 boost::shared_ptr<NeumannForcesSurface::DataAtIntegrationPts> dataAtPts =
163 boost::make_shared<NeumannForcesSurface::DataAtIntegrationPts>();
165 dataAtPts->forcesOnlyOnEntitiesRow = nodes;
168 if (
bit->getName().compare(0, 8,
"PRESSURE") == 0) {
169 CHKERR surfacePressure->addPressure(
"SPATIAL_POSITION", PETSC_NULLPTR,
170 bit->getMeshsetId(),
true,
true);
171 CHKERR surfacePressure->addPressureAle(
172 "SPATIAL_POSITION",
"MESH_NODE_POSITIONS", dataAtPts,
178 const string block_set_force_name(
"FORCE");
182 CHKERR surfaceForce->addForce(
"SPATIAL_POSITION", PETSC_NULLPTR,
183 (
bit->getMeshsetId()),
true,
false);
184 CHKERR surfaceForce->addForceAle(
185 "SPATIAL_POSITION",
"MESH_NODE_POSITIONS", dataAtPts,
191 if (it->getName().compare(0, block_set_force_name.length(),
192 block_set_force_name) == 0) {
193 CHKERR surfaceForce->addForce(
"SPATIAL_POSITION", PETSC_NULLPTR,
194 (it->getMeshsetId()),
true,
true);
195 CHKERR surfaceForce->addForceAle(
196 "SPATIAL_POSITION",
"MESH_NODE_POSITIONS", dataAtPts,
197 si->
getDomainFEName(), PETSC_NULLPTR, PETSC_NULLPTR, it->getMeshsetId(),
204 boost::shared_ptr<FaceElementForcesAndSourcesCore> fe_spring_lhs_ptr(
206 boost::shared_ptr<FaceElementForcesAndSourcesCore> fe_spring_rhs_ptr(
209 m_field, fe_spring_lhs_ptr, fe_spring_rhs_ptr,
"SPATIAL_POSITION",
210 "MESH_NODE_POSITIONS");
212 boost::shared_ptr<FaceElementForcesAndSourcesCore> fe_spring_lhs_ale_ptr_dx(
214 boost::shared_ptr<FaceElementForcesAndSourcesCore> fe_spring_lhs_ale_ptr_dX(
217 boost::shared_ptr<FaceElementForcesAndSourcesCore> fe_spring_rhs_ale_ptr(
220 boost::shared_ptr<MetaSpringBC::DataAtIntegrationPtsSprings>
222 boost::make_shared<MetaSpringBC::DataAtIntegrationPtsSprings>(
225 Range spring_ale_nodes;
226 CHKERR moab.get_connectivity(triangle_springs, spring_ale_nodes,
true);
228 data_at_spring_gp->forcesOnlyOnEntitiesRow = spring_ale_nodes;
231 m_field, fe_spring_lhs_ale_ptr_dx, fe_spring_lhs_ale_ptr_dX,
232 fe_spring_rhs_ale_ptr, data_at_spring_gp,
"SPATIAL_POSITION",
241 PETSC_NULLPTR, PETSC_NULLPTR);
243 PETSC_NULLPTR, PETSC_NULLPTR);
245 PETSC_NULLPTR, PETSC_NULLPTR);
259 fe_lhs_surface_force_ptr,
nullptr,
nullptr);
261 fe_rhs_surface_force_ptr,
nullptr,
nullptr);
264 fe_mat_lhs_surface_force_ptr,
nullptr,
267 fe_mat_rhs_surface_force_ptr,
nullptr,
271 CHKERR DMCreateGlobalVector(dm, &x);
272 CHKERR VecDuplicate(x, &f);
273 CHKERR VecSetOption(f, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
278 CHKERR MatDuplicate(
A, MAT_DO_NOT_COPY_VALUES, &fdA);
280 if (test_jacobian == PETSC_TRUE) {
281 char testing_options[] =
282 "-snes_test_jacobian -snes_test_jacobian_display "
283 "-snes_no_convergence_test -snes_atol 0 -snes_rtol 0 -snes_max_it 1 ";
285 CHKERR PetscOptionsInsertString(NULL, testing_options);
287 char testing_options[] =
"-snes_no_convergence_test -snes_atol 0 "
291 CHKERR PetscOptionsInsertString(NULL, testing_options);
295 CHKERR SNESCreate(PETSC_COMM_WORLD, &snes);
300 CHKERR SNESSetFromOptions(snes);
302 CHKERR SNESSolve(snes, NULL, x);
304 if (test_jacobian == PETSC_FALSE) {
306 CHKERR MatNorm(
A, NORM_INFINITY, &nrm_A0);
308 char testing_options_fd[] =
"-snes_fd";
309 CHKERR PetscOptionsInsertString(NULL, testing_options_fd);
313 CHKERR SNESSetFromOptions(snes);
315 CHKERR SNESSolve(snes, NULL, x);
316 CHKERR MatAXPY(
A, -1, fdA, SUBSET_NONZERO_PATTERN);
319 CHKERR MatNorm(
A, NORM_INFINITY, &nrm_A);
320 PetscPrintf(PETSC_COMM_WORLD,
"Matrix norms %3.4e %3.4e\n", nrm_A,
324 const double tol = 1e-7;
327 "Difference between hand-calculated tangent matrix and finite "
328 "difference matrix is too big");
336 CHKERR SNESDestroy(&snes);