v0.16.3
Loading...
Searching...
No Matches
dynamic_first_order_con_law.cpp
Go to the documentation of this file.
1/**
2 * \file dynamic_first_order_con_law.cpp
3 * \example mofem/tutorials/adv-4_dynamic_first_order_con_law/dynamic_first_order_con_law.cpp
4 *
5 * Explicit first order conservation laws for solid dynamics
6 *
7 */
8
9#include <MoFEM.hpp>
10#include <MatrixFunction.hpp>
11
12using namespace MoFEM;
13
14template <typename T> inline double trace(FTensor::Tensor2<T, 2, 2> &t_stress) {
15 constexpr double third = boost::math::constants::third<double>();
16 return (t_stress(0, 0) + t_stress(1, 1));
17};
18
19template <typename T> inline double trace(FTensor::Tensor2<T, 3, 3> &t_stress) {
20 return (t_stress(0, 0) + t_stress(1, 1) + t_stress(2, 2));
21};
22
23constexpr int SPACE_DIM =
24 EXECUTABLE_DIMENSION; //< Space dimension of problem, mesh
25
28using DomainEleOp = DomainEle::UserDataOperator;
32
35using BoundaryEleOp = BoundaryEle::UserDataOperator;
37
38template <int DIM> struct PostProcEleByDim;
39
45
51
55
60
63
65 GAUSS>::OpBaseTimesVector<1, SPACE_DIM, 0>;
66
71 SPACE_DIM>;
72
76
79 IntegrationType::GAUSS>::OpBaseTimesVector<1, SPACE_DIM * SPACE_DIM,
81
85
89
90/** \brief Save field DOFS on vertices/tags
91 */
92
93constexpr double omega = 1.;
94constexpr double young_modulus = 1.;
95constexpr double poisson_ratio = 0.;
96double bulk_modulus_K = young_modulus / (3. * (1. - 2. * poisson_ratio));
98double mu = young_modulus / (2. * (1. + poisson_ratio));
100 ((1. + poisson_ratio) * (1. - 2. * poisson_ratio));
101
102// Operator to Calculate F
103template <int DIM_0, int DIM_1>
105 OpCalculateFStab(boost::shared_ptr<MatrixDouble> def_grad_ptr,
106 boost::shared_ptr<MatrixDouble> def_grad_stab_ptr,
107 boost::shared_ptr<MatrixDouble> def_grad_dot_ptr,
108 double tau_F_ptr, double xi_F_ptr,
109 boost::shared_ptr<MatrixDouble> grad_x_ptr,
110 boost::shared_ptr<MatrixDouble> grad_vel_ptr)
112 defGradPtr(def_grad_ptr), defGradStabPtr(def_grad_stab_ptr),
113 defGradDotPtr(def_grad_dot_ptr), tauFPtr(tau_F_ptr), xiF(xi_F_ptr),
114 gradxPtr(grad_x_ptr), gradVelPtr(grad_vel_ptr) {}
115
116 MoFEMErrorCode doWork(int side, EntityType type,
117 DataForcesAndSourcesCore::EntData &data) {
119 // Define Indicies
122
123 // Number of Gauss points
124 const size_t nb_gauss_pts = getGaussPts().size2();
125
126 defGradStabPtr->resize(nb_gauss_pts, DIM_0 * DIM_1, false);
127 defGradStabPtr->clear();
128
129 // Extract matrix from data matrix
130 auto t_F = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradPtr);
131 auto t_Fstab = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradStabPtr);
132 auto t_F_dot = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradDotPtr);
133
134 // tau_F = alpha deltaT
135 auto tau_F = tauFPtr;
136 double xi_F = xiF;
137 auto t_gradx = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*gradxPtr);
138 auto t_gradVel = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*gradVelPtr);
139
140 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
141 // Stabilised Deformation Gradient
142 t_Fstab(i, j) = t_F(i, j) + tau_F * (t_gradVel(i, j) - t_F_dot(i, j)) +
143 xi_F * (t_gradx(i, j) - t_F(i, j));
144
145 ++t_F;
146 ++t_Fstab;
147 ++t_gradVel;
148 ++t_F_dot;
149
150 ++t_gradx;
151 }
152
154 }
155
156private:
157 double tauFPtr;
158 double xiF;
159 boost::shared_ptr<MatrixDouble> defGradPtr;
160 boost::shared_ptr<MatrixDouble> defGradStabPtr;
161 boost::shared_ptr<MatrixDouble> defGradDotPtr;
162 boost::shared_ptr<MatrixDouble> gradxPtr;
163 boost::shared_ptr<MatrixDouble> gradVelPtr;
164};
165
166// Operator to Calculate P
167template <int DIM_0, int DIM_1>
169 OpCalculatePiola(double shear_modulus, double bulk_modulus, double m_u,
170 double lambda_lamme,
171 boost::shared_ptr<MatrixDouble> first_piola_ptr,
172 boost::shared_ptr<MatrixDouble> def_grad_ptr)
174 shearModulus(shear_modulus), bulkModulus(bulk_modulus), mU(m_u),
175 lammeLambda(lambda_lamme), firstPiolaPtr(first_piola_ptr),
176 defGradPtr(def_grad_ptr) {}
177
178 MoFEMErrorCode doWork(int side, EntityType type,
179 DataForcesAndSourcesCore::EntData &data) {
181 // Define Indicies
185
186 // Define Kronecker Delta
187 constexpr auto t_kd = FTensor::Kronecker_Delta<double>();
188
189 // Number of Gauss points
190 const size_t nb_gauss_pts = getGaussPts().size2();
191
192 // Resize Piola
193 firstPiolaPtr->resize(nb_gauss_pts, DIM_0 * DIM_1, false); // ignatios check
194 firstPiolaPtr->clear();
195
196 // Extract matrix from data matrix
197 auto t_P = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*firstPiolaPtr);
198 auto t_F = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradPtr);
199 const double two_o_three = 2. / 3.;
200 const double trace_t_dk = DIM_0;
201 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
202
203 t_P(i, j) = shearModulus * (t_F(i, j) + t_F(j, i) - 2. * t_kd(i, j) -
204 two_o_three * trace(t_F) * t_kd(i, j) +
205 two_o_three * trace_t_dk * t_kd(i, j)) +
206 bulkModulus * trace(t_F) * t_kd(i, j) -
207 bulkModulus * trace_t_dk * t_kd(i, j);
208
209 ++t_F;
210 ++t_P;
211 }
212
214 }
215
216private:
219 double mU;
221 boost::shared_ptr<MatrixDouble> firstPiolaPtr;
222 boost::shared_ptr<MatrixDouble> defGradPtr;
223};
224
225template <int DIM>
227 OpCalculateDisplacement(boost::shared_ptr<MatrixDouble> spatial_pos_ptr,
228 boost::shared_ptr<MatrixDouble> reference_pos_ptr,
229 boost::shared_ptr<MatrixDouble> u_ptr)
231 xPtr(spatial_pos_ptr), XPtr(reference_pos_ptr), uPtr(u_ptr) {}
232
233 MoFEMErrorCode doWork(int side, EntityType type,
234 DataForcesAndSourcesCore::EntData &data) {
236 // Define Indicies
237 FTensor::Index<'i', DIM> i;
238
239 // Number of Gauss points
240 const size_t nb_gauss_pts = getGaussPts().size2();
241
242 uPtr->resize(DIM, nb_gauss_pts, false); // ignatios check
243 uPtr->clear();
244
245 // Extract matrix from data matrix
246 auto t_x = getFTensor1FromMat<DIM>(*xPtr);
247 auto t_X = getFTensor1FromMat<DIM>(*XPtr);
248 auto t_u = getFTensor1FromMat<DIM>(*uPtr);
249 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
250
251 t_u(i) = t_x(i) - t_X(i);
252 ++t_u;
253 ++t_x;
254 ++t_X;
255 }
256
258 }
259
260private:
261 boost::shared_ptr<MatrixDouble> xPtr;
262 boost::shared_ptr<MatrixDouble> XPtr;
263 boost::shared_ptr<MatrixDouble> uPtr;
264};
265
266template <int DIM_0, int DIM_1>
270 double shear_modulus, double bulk_modulus, double m_u,
271 double lambda_lamme, boost::shared_ptr<MatrixDouble> first_piola_ptr,
272 boost::shared_ptr<MatrixDouble> def_grad_ptr,
273 boost::shared_ptr<MatrixDouble> inv_def_grad_ptr,
274 boost::shared_ptr<VectorDouble> det)
276 shearModulus(shear_modulus), bulkModulus(bulk_modulus), mU(m_u),
277 lammeLambda(lambda_lamme), firstPiolaPtr(first_piola_ptr),
278 defGradPtr(def_grad_ptr), invDefGradPtr(inv_def_grad_ptr), dEt(det) {}
279
280 MoFEMErrorCode doWork(int side, EntityType type,
281 DataForcesAndSourcesCore::EntData &data) {
283 // Define Indicies
288
289 // Define Kronecker Delta
290 constexpr auto t_kd = FTensor::Kronecker_Delta<double>();
291
292 // Number of Gauss points
293 const size_t nb_gauss_pts = getGaussPts().size2();
294
295 // Resize Piola
296 firstPiolaPtr->resize(nb_gauss_pts, DIM_0 * DIM_1, false); // ignatios check
297 firstPiolaPtr->clear();
298
299 // Extract matrix from data matrix
300 auto t_P = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*firstPiolaPtr);
301 auto t_F = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradPtr);
302 auto t_inv_F = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*invDefGradPtr);
303 auto t_det = getFTensor0FromVec<1>(*dEt);
304 const double two_o_three = 2. / 3.;
305 const double one_o_three = 1. / 3.;
306 const double bulk_mod = bulkModulus;
307 const double shear_mod = shearModulus;
308 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
309
310 // Nearly incompressible NH
311 // volumetric part
312 t_P(i, j) = bulk_mod * (t_det - 1.) * t_det * t_inv_F(j, i);
313 // deviatoric part
314 t_P(i, j) +=
315 shear_mod * pow(t_det, two_o_three) *
316 (t_F(i, j) - one_o_three * (t_F(l, k) * t_F(l, k)) * t_inv_F(j, i));
317
318 ++t_F;
319 ++t_P;
320 ++t_inv_F;
321 ++t_det;
322 }
323
325 }
326
327private:
330 double mU;
332 boost::shared_ptr<MatrixDouble> firstPiolaPtr;
333 boost::shared_ptr<MatrixDouble> defGradPtr;
334 boost::shared_ptr<MatrixDouble> invDefGradPtr;
335 boost::shared_ptr<VectorDouble> dEt;
336};
337
338template <int DIM_0, int DIM_1>
342 boost::shared_ptr<MatrixDouble> def_grad_ptr,
343 boost::shared_ptr<MatrixDouble> grad_tensor_ptr)
345 defGradPtr(def_grad_ptr), gradTensorPtr(grad_tensor_ptr) {}
346
347 MoFEMErrorCode doWork(int side, EntityType type,
348 DataForcesAndSourcesCore::EntData &data) {
350 // Define Indicies
353
354 // Define Kronecker Delta
355 constexpr auto t_kd = FTensor::Kronecker_Delta<double>();
356
357 // Number of Gauss points
358 const size_t nb_gauss_pts = getGaussPts().size2();
359
360 // Resize Piola
361 defGradPtr->resize(nb_gauss_pts, DIM_0 * DIM_1, false);
362 defGradPtr->clear();
363
364 // Extract matrix from data matrix
365 auto t_F = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*defGradPtr);
366 auto t_H = getFTensor2FromMat<SPACE_DIM, SPACE_DIM>(*gradTensorPtr);
367 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
368
369 t_F(i, j) = t_H(i, j) + t_kd(i, j);
370
371 ++t_F;
372 ++t_H;
373 }
374
376 }
377
378private:
379 boost::shared_ptr<MatrixDouble> gradTensorPtr;
380 boost::shared_ptr<MatrixDouble> defGradPtr;
381};
382
383struct Example;
385
386 TSPrePostProc() = default;
387 virtual ~TSPrePostProc() = default;
388
389 /**
390 * @brief Used to setup TS solver
391 *
392 * @param ts
393 * @return MoFEMErrorCode
394 */
395 MoFEMErrorCode tsSetUp(TS ts);
396
397 // SmartPetscObj<VecScatter> getScatter(Vec x, Vec y, enum FR fr);
399 static MoFEMErrorCode tsPostStage(TS ts, PetscReal stagetime,
400 PetscInt stageindex, Vec *Y);
401 static MoFEMErrorCode tsPostStep(TS ts);
402 static MoFEMErrorCode tsPreStep(TS ts);
403};
404
405static boost::weak_ptr<TSPrePostProc> tsPrePostProc;
406
409 double getScale(const double time) {
410 return sin(2. * M_PI * MoFEM::TimeScale::getScale(time));
411 };
412};
413
414struct CommonData {
415 SmartPetscObj<Mat> M; ///< Mass matrix
416 SmartPetscObj<KSP> ksp; ///< Linear solver
417};
418
419struct Example {
420
421 Example(MoFEM::Interface &m_field) : mField(m_field) {}
422
424
425private:
427
435 friend struct TSPrePostProc;
436
439 double getScale(const double time) { return 0.001 * sin(0.1 * time); };
440 };
441
444 double getScale(const double time) { return 0.001; };
445 };
446};
447
448//! [Run problem]
459}
460//! [Run problem]
461
462//! [Read mesh]
471//! [Read mesh]
472
473//! [Set up problem]
477 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
478 const char *list_bases[LASBASETOPT] = {"ainsworth", "demkowicz"};
479 PetscInt choice_base_value = AINSWORTH;
480 CHKERR PetscOptionsGetEList(PETSC_NULLPTR, NULL, "-base", list_bases,
481 LASBASETOPT, &choice_base_value, PETSC_NULLPTR);
482
484 switch (choice_base_value) {
485 case AINSWORTH:
487 MOFEM_LOG("WORLD", Sev::inform)
488 << "Set AINSWORTH_LEGENDRE_BASE for displacements";
489 break;
490 case DEMKOWICZ:
492 MOFEM_LOG("WORLD", Sev::inform)
493 << "Set DEMKOWICZ_JACOBI_BASE for displacements";
494 break;
495 default:
496 base = LASTBASE;
497 break;
498 }
499 // Add field
507
508 CHKERR simple->addDataField("GEOMETRY", H1, base, SPACE_DIM);
509 int order = 2;
510 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &order, PETSC_NULLPTR);
514 CHKERR simple->setFieldOrder("F_dot", order);
517 CHKERR simple->setFieldOrder("GEOMETRY", order);
519
520 auto project_ho_geometry = [&]() {
521 Projection10NodeCoordsOnField ent_method_x(mField, "x_1");
522 CHKERR mField.loop_dofs("x_1", ent_method_x);
523 Projection10NodeCoordsOnField ent_method_x_2(mField, "x_2");
524 CHKERR mField.loop_dofs("x_2", ent_method_x_2);
525
526 Projection10NodeCoordsOnField ent_method(mField, "GEOMETRY");
527 return mField.loop_dofs("GEOMETRY", ent_method);
528 };
529 CHKERR project_ho_geometry();
530
532}
533//! [Set up problem]
534
535//! [Boundary condition]
538
540 auto bc_mng = mField.getInterface<BcManager>();
541 auto *pipeline_mng = mField.getInterface<PipelineManager>();
542 auto time_scale = boost::make_shared<TimeScale>();
543
544 PetscBool sin_time_function = PETSC_FALSE;
545 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-sin_time_function",
546 &sin_time_function, PETSC_NULLPTR);
547
548 if (sin_time_function)
549 time_scale = boost::make_shared<DynamicFirstOrderConsSinusTimeScale>();
550 else
551 time_scale = boost::make_shared<DynamicFirstOrderConsConstantTimeScale>();
552
553 pipeline_mng->getBoundaryExplicitRhsFE().reset();
555 pipeline_mng->getOpBoundaryExplicitRhsPipeline(), {NOSPACE}, "GEOMETRY");
556
558 pipeline_mng->getOpBoundaryExplicitRhsPipeline(), mField, "V",
559 {time_scale}, "FORCE", "PRESSURE", Sev::inform);
560
561 auto integration_rule = [](int, int, int approx_order) {
562 return 2 * approx_order;
563 };
564
565 CHKERR pipeline_mng->setBoundaryExplicitRhsIntegrationRule(integration_rule);
566 CHKERR pipeline_mng->setDomainExplicitRhsIntegrationRule(integration_rule);
567
568 CHKERR bc_mng->removeBlockDOFsOnEntities<DisplacementCubitBcData>(
569 simple->getProblemName(), "V");
570
571 auto get_pre_proc_hook = [&]() {
573 mField, pipeline_mng->getDomainExplicitRhsFE(), {time_scale});
574 };
575 pipeline_mng->getDomainExplicitRhsFE()->preProcessHook = get_pre_proc_hook();
576
578}
579//! [Boundary condition]
580
582 PetscInt stageindex, Vec *Y) {
584 // cerr << "tsPostStage " <<"\n";
585 if (auto ptr = tsPrePostProc.lock()) {
586 auto &m_field = ptr->fsRawPtr->mField;
587
588 auto fb = m_field.getInterface<FieldBlas>();
589 double dt;
590 CHKERR TSGetTimeStep(ts, &dt);
591 double time;
592 CHKERR TSGetTime(ts, &time);
593 PetscInt num_stages;
594 Vec *stage_solutions;
595
596 CHKERR TSGetStages(ts, &num_stages, &stage_solutions);
597 PetscPrintf(PETSC_COMM_WORLD, "Check timestep %d time %e dt %e\n",
598 num_stages, time, dt);
599
600 const double inv_num_step = (double)num_stages;
601 CHKERR fb->fieldCopy(1., "x_1", "x_2");
602 CHKERR fb->fieldAxpy(dt, "V", "x_2");
603 CHKERR fb->fieldCopy(1., "x_2", "x_1");
604
605 CHKERR fb->fieldCopy(-inv_num_step / dt, "F_0", "F_dot");
606 CHKERR fb->fieldAxpy(inv_num_step / dt, "F", "F_dot");
607 CHKERR fb->fieldCopy(1., "F", "F_0");
608 }
610}
611
614
615 if (auto ptr = tsPrePostProc.lock()) {
616 double dt;
617 CHKERR TSGetTimeStep(ts, &dt);
618 double time;
619 CHKERR TSGetTime(ts, &time);
620 }
622}
623
626
627 if (auto ptr = tsPrePostProc.lock()) {
628 double dt;
629 CHKERR TSGetTimeStep(ts, &dt);
630 double time;
631 CHKERR TSGetTime(ts, &time);
632 int step_num;
633 CHKERR TSGetStepNumber(ts, &step_num);
634 }
636}
637
638//! [Push operators to pipeline]
641 auto get_body_force = [this](const double, const double, const double) {
644 t_source(i) = 0.;
645 t_source(0) = 0.1;
646 t_source(1) = 1.;
647 return t_source;
648 };
649
650 // specific time scaling
651 auto get_time_scale = [this](const double time) {
652 return sin(time * omega * M_PI);
653 };
654
655 auto apply_rhs = [&](auto &pip) {
657
659 "GEOMETRY");
660
661 // Calculate Gradient of velocity
662 auto mat_v_grad_ptr = boost::make_shared<MatrixDouble>();
664 "V", mat_v_grad_ptr));
665
666 auto gravity_vector_ptr = boost::make_shared<MatrixDouble>();
667 gravity_vector_ptr->resize(1, SPACE_DIM);
668 auto set_body_force = [&]() {
671 auto t_force = getFTensor1FromMat<SPACE_DIM, 0>(*gravity_vector_ptr);
672 double unit_weight = 0.;
673 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-unit_weight", &unit_weight,
674 PETSC_NULLPTR);
675 t_force(i) = 0;
676 if (SPACE_DIM == 2) {
677 t_force(1) = -unit_weight;
678 } else if (SPACE_DIM == 3) {
679 t_force(2) = unit_weight;
680 }
682 };
683
684 CHKERR set_body_force();
685 pip.push_back(new OpBodyForce("V", gravity_vector_ptr,
686 [](double, double, double) { return 1.; }));
687
688 // Calculate unknown F
689 auto mat_H_tensor_ptr = boost::make_shared<MatrixDouble>();
691 "F", mat_H_tensor_ptr));
692
693 // // Calculate F
694 double tau = 0.2;
695 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-tau", &tau, PETSC_NULLPTR);
696
697 double xi = 0.;
698 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-xi", &xi, PETSC_NULLPTR);
699
700 // Calculate P stab
701 auto one = [&](const double, const double, const double) {
702 return 3. * bulk_modulus_K;
703 };
704 auto minus_one = [](const double, const double, const double) {
705 return -1.;
706 };
707
708 auto mat_dot_F_tensor_ptr = boost::make_shared<MatrixDouble>();
710 "F_dot", mat_dot_F_tensor_ptr));
711
712 // Calculate Gradient of Spatial Positions
713 auto mat_x_grad_ptr = boost::make_shared<MatrixDouble>();
715 "x_2", mat_x_grad_ptr));
716
717 auto mat_F_tensor_ptr = boost::make_shared<MatrixDouble>();
719 mat_F_tensor_ptr, mat_H_tensor_ptr));
720
721 auto mat_F_stab_ptr = boost::make_shared<MatrixDouble>();
723 mat_F_tensor_ptr, mat_F_stab_ptr, mat_dot_F_tensor_ptr, tau, xi,
724 mat_x_grad_ptr, mat_v_grad_ptr));
725
726 PetscBool is_linear_elasticity = PETSC_TRUE;
727 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-is_linear_elasticity",
728 &is_linear_elasticity, PETSC_NULLPTR);
729
730 auto mat_P_stab_ptr = boost::make_shared<MatrixDouble>();
731 if (is_linear_elasticity) {
734 mat_F_stab_ptr));
735 } else {
736 auto inv_F = boost::make_shared<MatrixDouble>();
737 auto det_ptr = boost::make_shared<VectorDouble>();
738
739 pip.push_back(
740 new OpInvertMatrix<SPACE_DIM>(mat_F_stab_ptr, det_ptr, inv_F));
741
742 // OpCalculatePiolaIncompressibleNH
745 mat_F_stab_ptr, inv_F, det_ptr));
746 }
747
748 pip.push_back(new OpGradTimesTensor2("V", mat_P_stab_ptr, minus_one));
749 pip.push_back(new OpRhsTestPiola("F", mat_v_grad_ptr, one));
750
752 };
753
754 auto *pipeline_mng = mField.getInterface<PipelineManager>();
755 CHKERR apply_rhs(pipeline_mng->getOpDomainExplicitRhsPipeline());
756
757 auto integration_rule = [](int, int, int approx_order) {
758 return 2 * approx_order;
759 };
760 CHKERR pipeline_mng->setDomainExplicitRhsIntegrationRule(integration_rule);
761
763}
764//! [Push operators to pipeline]
765
766/**
767 * @brief Monitor solution
768 *
769 * This functions is called by TS solver at the end of each step. It is used
770 * to output results to the hard drive.
771 */
772
773struct Monitor : public FEMethod {
776 boost::shared_ptr<PostProcEle> post_proc,
777 boost::shared_ptr<PostProcFaceEle> post_proc_bdry,
778 boost::shared_ptr<MatrixDouble> velocity_field_ptr,
779 boost::shared_ptr<MatrixDouble> x2_field_ptr,
780 boost::shared_ptr<MatrixDouble> geometry_field_ptr,
781 std::array<double, 3> pass_field_eval_coords,
782 boost::shared_ptr<SetPtsData> pass_field_eval_data)
783 : dM(dm), mField(m_field), postProc(post_proc),
784 postProcBdy(post_proc_bdry), velocityFieldPtr(velocity_field_ptr),
785 x2FieldPtr(x2_field_ptr), geometryFieldPtr(geometry_field_ptr),
786 fieldEvalCoords(pass_field_eval_coords),
787 fieldEvalData(pass_field_eval_data){};
790
791 auto *simple = mField.getInterface<Simple>();
792
794 ->evalFEAtThePoint<SPACE_DIM>(
795 fieldEvalCoords.data(), 1e-12, simple->getProblemName(),
796 simple->getDomainFEName(), fieldEvalData, mField.get_comm_rank(),
798
799 if (velocityFieldPtr->size1()) {
800 auto t_vel = getFTensor1FromMat<SPACE_DIM>(*velocityFieldPtr);
801 auto t_x2_field = getFTensor1FromMat<SPACE_DIM>(*x2FieldPtr);
802 auto t_geom = getFTensor1FromMat<SPACE_DIM>(*geometryFieldPtr);
803
804 double u_x = t_x2_field(0) - t_geom(0);
805 double u_y = t_x2_field(1) - t_geom(1);
806 double u_z = t_x2_field(2) - t_geom(2);
807
808 MOFEM_LOG("SYNC", Sev::inform)
809 << "Velocities x: " << t_vel(0) << " y: " << t_vel(1)
810 << " z: " << t_vel(2) << "\n";
811 MOFEM_LOG("SYNC", Sev::inform) << "Displacement x: " << u_x
812 << " y: " << u_y << " z: " << u_z << "\n";
813 }
814
815 for (auto m : mField.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
816 std::regex((boost::format("%s(.*)") % "Data_Vertex").str()))) {
817 Range ents;
818 mField.get_moab().get_entities_by_dimension(m->getMeshset(), 0, ents,
819 true);
820 auto print_vets = [](boost::shared_ptr<FieldEntity> ent_ptr) {
822 if (!(ent_ptr->getPStatus() & PSTATUS_NOT_OWNED)) {
823 MOFEM_LOG("SYNC", Sev::inform)
824 << "Velocities: " << ent_ptr->getEntFieldData()[0] << " "
825 << ent_ptr->getEntFieldData()[1] << " "
826 << ent_ptr->getEntFieldData()[2] << "\n";
827 }
829 };
830 CHKERR mField.getInterface<FieldBlas>()->fieldLambdaOnEntities(
831 print_vets, "V", &ents);
832 }
834
835 PetscBool print_volume = PETSC_FALSE;
836 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-print_volume", &print_volume,
837 PETSC_NULLPTR);
838
839 PetscBool print_skin = PETSC_FALSE;
840 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-print_skin", &print_skin,
841 PETSC_NULLPTR);
842
843 int save_every_nth_step = 1;
844 CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-save_step",
845 &save_every_nth_step, PETSC_NULLPTR);
846 if (ts_step % save_every_nth_step == 0) {
847
848 if (print_volume) {
850 CHKERR postProc->writeFile(
851 "out_step_" + boost::lexical_cast<std::string>(ts_step) + ".h5m");
852 }
853
854 if (print_skin) {
856 CHKERR postProcBdy->writeFile(
857 "out_boundary_" + boost::lexical_cast<std::string>(ts_step) +
858 ".h5m");
859 }
860 }
862 }
863
864private:
866 boost::shared_ptr<PostProcEle> postProc;
867 boost::shared_ptr<PostProcFaceEle> postProcBdy;
868 boost::shared_ptr<MatrixDouble> velocityFieldPtr;
869 boost::shared_ptr<MatrixDouble> x2FieldPtr;
870 boost::shared_ptr<MatrixDouble> geometryFieldPtr;
871 std::array<double, 3> fieldEvalCoords;
872 boost::shared_ptr<SetPtsData> fieldEvalData;
873};
874
875//! [Solve]
878 auto *simple = mField.getInterface<Simple>();
879 auto *pipeline_mng = mField.getInterface<PipelineManager>();
880
881 auto dm = simple->getDM();
882
883 auto calculate_stress_ops = [&](auto &pip) {
885
886 auto v_ptr = boost::make_shared<MatrixDouble>();
887 pip.push_back(new OpCalculateVectorFieldValues<SPACE_DIM>("V", v_ptr));
888 auto X_ptr = boost::make_shared<MatrixDouble>();
889 pip.push_back(
890 new OpCalculateVectorFieldValues<SPACE_DIM>("GEOMETRY", X_ptr));
891
892 auto x_ptr = boost::make_shared<MatrixDouble>();
893 pip.push_back(new OpCalculateVectorFieldValues<SPACE_DIM>("x_1", x_ptr));
894
895 // Calculate unknown F
896 auto mat_H_tensor_ptr = boost::make_shared<MatrixDouble>();
898 "F", mat_H_tensor_ptr));
899
900 auto u_ptr = boost::make_shared<MatrixDouble>();
901 pip.push_back(new OpCalculateDisplacement<SPACE_DIM>(x_ptr, X_ptr, u_ptr));
902 // Calculate P
903
904 auto mat_F_ptr = boost::make_shared<MatrixDouble>();
906 mat_F_ptr, mat_H_tensor_ptr));
907
908 PetscBool is_linear_elasticity = PETSC_TRUE;
909 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-is_linear_elasticity",
910 &is_linear_elasticity, PETSC_NULLPTR);
911
912 auto mat_P_ptr = boost::make_shared<MatrixDouble>();
913 if (is_linear_elasticity) {
916 mat_F_ptr));
917 } else {
918 auto inv_F = boost::make_shared<MatrixDouble>();
919 auto det_ptr = boost::make_shared<VectorDouble>();
920
921 pip.push_back(new OpInvertMatrix<SPACE_DIM>(mat_F_ptr, det_ptr, inv_F));
922
925 mat_F_ptr, inv_F, det_ptr));
926 }
927
928 auto mat_v_grad_ptr = boost::make_shared<MatrixDouble>();
930 "V", mat_v_grad_ptr));
931
932 return boost::make_tuple(v_ptr, X_ptr, x_ptr, mat_P_ptr, mat_F_ptr, u_ptr);
933 };
934
935 auto post_proc_boundary = [&]() {
936 auto boundary_post_proc_fe = boost::make_shared<PostProcFaceEle>(mField);
937
939 boundary_post_proc_fe->getOpPtrVector(), {}, "GEOMETRY");
940 auto op_loop_side =
942 // push ops to side element, through op_loop_side operator
943 auto [boundary_v_ptr, boundary_X_ptr, boundary_x_ptr, boundary_mat_P_ptr,
944 boundary_mat_F_ptr, boundary_u_ptr] =
945 calculate_stress_ops(op_loop_side->getOpPtrVector());
946 boundary_post_proc_fe->getOpPtrVector().push_back(op_loop_side);
947
949
950 boundary_post_proc_fe->getOpPtrVector().push_back(
951
952 new OpPPMap(
953
954 boundary_post_proc_fe->getPostProcMesh(),
955 boundary_post_proc_fe->getMapGaussPts(),
956
958
959 OpPPMap::DataMapMat{{"V", boundary_v_ptr},
960 {"GEOMETRY", boundary_X_ptr},
961 {"x", boundary_x_ptr},
962 {"U", boundary_u_ptr}},
963
964 OpPPMap::DataMapMat{{"FIRST_PIOLA", boundary_mat_P_ptr},
965 {"F", boundary_mat_F_ptr}},
966
968
969 )
970
971 );
972 return boundary_post_proc_fe;
973 };
974
975 // Add monitor to time solver
976
977 double rho = 1.;
978 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-density", &rho, PETSC_NULLPTR);
979 auto get_rho = [rho](const double, const double, const double) {
980 return rho;
981 };
982
983 SmartPetscObj<Mat> M; ///< Mass matrix
984 SmartPetscObj<KSP> ksp; ///< Linear solver
985
986 auto ts_pre_post_proc = boost::make_shared<TSPrePostProc>();
987 tsPrePostProc = ts_pre_post_proc;
988
990 CHKERR MatZeroEntries(M);
991
992 boost::shared_ptr<DomainEle> vol_mass_ele(new DomainEle(mField));
993
994 vol_mass_ele->B = M;
995
996 auto integration_rule = [](int, int, int approx_order) {
997 return 2 * approx_order;
998 };
999
1000 vol_mass_ele->getRuleHook = integration_rule;
1001
1002 vol_mass_ele->getOpPtrVector().push_back(new OpMassV("V", "V", get_rho));
1003 vol_mass_ele->getOpPtrVector().push_back(new OpMassF("F", "F"));
1004
1005 CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(), vol_mass_ele);
1006 CHKERR MatAssemblyBegin(M, MAT_FINAL_ASSEMBLY);
1007 CHKERR MatAssemblyEnd(M, MAT_FINAL_ASSEMBLY);
1008
1009 auto lumpVec = createDMVector(simple->getDM());
1010 CHKERR MatGetRowSum(M, lumpVec);
1011
1012 CHKERR MatZeroEntries(M);
1013 CHKERR MatDiagonalSet(M, lumpVec, INSERT_VALUES);
1014
1015 // Create and septup KSP (linear solver), we need this to calculate g(t,u) =
1016 // M^-1G(t,u)
1017 ksp = createKSP(mField.get_comm());
1018 CHKERR KSPSetOperators(ksp, M, M);
1019 CHKERR KSPSetFromOptions(ksp);
1020 CHKERR KSPSetUp(ksp);
1021
1022 auto solve_boundary_for_g = [&]() {
1024 if (*(pipeline_mng->getBoundaryExplicitRhsFE()->vecAssembleSwitch)) {
1025
1026 CHKERR VecGhostUpdateBegin(pipeline_mng->getBoundaryExplicitRhsFE()->ts_F,
1027 ADD_VALUES, SCATTER_REVERSE);
1028 CHKERR VecGhostUpdateEnd(pipeline_mng->getBoundaryExplicitRhsFE()->ts_F,
1029 ADD_VALUES, SCATTER_REVERSE);
1030 CHKERR VecAssemblyBegin(pipeline_mng->getBoundaryExplicitRhsFE()->ts_F);
1031 CHKERR VecAssemblyEnd(pipeline_mng->getBoundaryExplicitRhsFE()->ts_F);
1032 *(pipeline_mng->getBoundaryExplicitRhsFE()->vecAssembleSwitch) = false;
1033
1034 auto D =
1035 vectorDuplicate(pipeline_mng->getBoundaryExplicitRhsFE()->ts_F);
1036 CHKERR KSPSolve(ksp, pipeline_mng->getBoundaryExplicitRhsFE()->ts_F, D);
1037 CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
1038 CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
1039 CHKERR VecCopy(D, pipeline_mng->getBoundaryExplicitRhsFE()->ts_F);
1040 }
1041
1043 };
1044
1045 pipeline_mng->getBoundaryExplicitRhsFE()->postProcessHook =
1046 solve_boundary_for_g;
1047
1049 ts = pipeline_mng->createTSEX(dm);
1050
1051 // Field eval
1052 PetscBool field_eval_flag = PETSC_TRUE;
1053 boost::shared_ptr<MatrixDouble> velocity_field_ptr;
1054 boost::shared_ptr<MatrixDouble> geometry_field_ptr;
1055 boost::shared_ptr<MatrixDouble> spatial_position_field_ptr;
1056 boost::shared_ptr<SetPtsData> field_eval_data;
1057
1058 std::array<double, 3> field_eval_coords = {0.5, 0.5, 5.};
1059 int dim = 3;
1060 CHKERR PetscOptionsGetRealArray(NULL, NULL, "-field_eval_coords",
1061 field_eval_coords.data(), &dim,
1062 &field_eval_flag);
1063
1064 if (field_eval_flag) {
1065 field_eval_data =
1066 mField.getInterface<FieldEvaluatorInterface>()->getData<DomainEle>();
1067 CHKERR mField.getInterface<FieldEvaluatorInterface>()->buildTree<SPACE_DIM>(
1068 field_eval_data, simple->getDomainFEName());
1069
1070 field_eval_data->setEvalPoints(field_eval_coords.data(), 1);
1071
1072 auto no_rule = [](int, int, int) { return -1; };
1073
1074 auto fe_ptr = field_eval_data->feMethodPtr;
1075 fe_ptr->getRuleHook = no_rule;
1076 velocity_field_ptr = boost::make_shared<MatrixDouble>();
1077 geometry_field_ptr = boost::make_shared<MatrixDouble>();
1078 spatial_position_field_ptr = boost::make_shared<MatrixDouble>();
1079 fe_ptr->getOpPtrVector().push_back(
1080 new OpCalculateVectorFieldValues<SPACE_DIM>("V", velocity_field_ptr));
1081 fe_ptr->getOpPtrVector().push_back(
1083 geometry_field_ptr));
1084 fe_ptr->getOpPtrVector().push_back(
1086 "x_2", spatial_position_field_ptr));
1087 }
1088
1089 auto post_proc_domain = [&]() {
1090 auto post_proc_fe_vol = boost::make_shared<PostProcEle>(mField);
1091
1093
1094 auto [boundary_v_ptr, boundary_X_ptr, boundary_x_ptr, boundary_mat_P_ptr,
1095 boundary_mat_F_ptr, boundary_u_ptr] =
1096 calculate_stress_ops(post_proc_fe_vol->getOpPtrVector());
1097
1098 post_proc_fe_vol->getOpPtrVector().push_back(
1099
1100 new OpPPMap(
1101
1102 post_proc_fe_vol->getPostProcMesh(),
1103 post_proc_fe_vol->getMapGaussPts(),
1104
1105 {},
1106
1107 {{"V", boundary_v_ptr},
1108 {"GEOMETRY", boundary_X_ptr},
1109 {"x", boundary_x_ptr},
1110 {"U", boundary_u_ptr}},
1111
1112 {{"FIRST_PIOLA", boundary_mat_P_ptr}, {"F", boundary_mat_F_ptr}},
1113
1114 {}
1115
1116 )
1117
1118 );
1119 return post_proc_fe_vol;
1120 };
1121
1122 boost::shared_ptr<FEMethod> null_fe;
1123 auto monitor_ptr = boost::make_shared<Monitor>(
1124 SmartPetscObj<DM>(dm, true), mField, post_proc_domain(),
1125 post_proc_boundary(), velocity_field_ptr, spatial_position_field_ptr,
1126 geometry_field_ptr, field_eval_coords, field_eval_data);
1127
1128 CHKERR DMMoFEMTSSetMonitor(dm, ts, simple->getDomainFEName(), null_fe,
1129 null_fe, monitor_ptr);
1130
1131 double ftime = 1;
1132 // CHKERR TSSetMaxTime(ts, ftime);
1133 CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
1134
1135 auto T = createDMVector(simple->getDM());
1136 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1137 SCATTER_FORWARD);
1138 CHKERR TSSetSolution(ts, T);
1139 CHKERR TSSetFromOptions(ts);
1140
1141 CHKERR TSSetPostStage(ts, TSPrePostProc::tsPostStage);
1142 CHKERR TSSetPostStep(ts, TSPrePostProc::tsPostStep);
1143 CHKERR TSSetPreStep(ts, TSPrePostProc::tsPreStep);
1144
1145 boost::shared_ptr<ForcesAndSourcesCore> null;
1146
1147 if (auto ptr = tsPrePostProc.lock()) {
1148 ptr->fsRawPtr = this;
1149 CHKERR TSSetUp(ts);
1150 CHKERR TSSolve(ts, NULL);
1151 CHKERR TSGetTime(ts, &ftime);
1152 }
1153
1155}
1156//! [Solve]
1157
1158//! [Postprocess results]
1161 PetscBool test_flg = PETSC_FALSE;
1162 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test", &test_flg, PETSC_NULLPTR);
1163 if (test_flg) {
1164 auto *simple = mField.getInterface<Simple>();
1165 auto T = createDMVector(simple->getDM());
1166 CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
1167 SCATTER_FORWARD);
1168 double nrm2;
1169 CHKERR VecNorm(T, NORM_2, &nrm2);
1170 MOFEM_LOG("EXAMPLE", Sev::inform) << "Regression norm " << nrm2;
1171 constexpr double regression_value = 0.0194561;
1172 if (fabs(nrm2 - regression_value) > 1e-2)
1173 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
1174 "Regression test failed; wrong norm value.");
1175 }
1177}
1178//! [Postprocess results]
1179
1180//! [Check]
1185//! [Check]
1186
1187static char help[] = "...\n\n";
1188
1189int main(int argc, char *argv[]) {
1190
1191 // Initialisation of MoFEM/PETSc and MOAB data structures
1192 const char param_file[] = "param_file.petsc";
1193 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
1194
1195 // Add logging channel for example
1196 auto core_log = logging::core::get();
1197 core_log->add_sink(
1199 LogManager::setLog("EXAMPLE");
1200 MOFEM_LOG_TAG("EXAMPLE", "example");
1201
1202 try {
1203
1204 //! [Register MoFEM discrete manager in PETSc]
1205 DMType dm_name = "DMMOFEM";
1206 CHKERR DMRegister_MoFEM(dm_name);
1207 //! [Register MoFEM discrete manager in PETSc
1208
1209 //! [Create MoAB]
1210 moab::Core mb_instance; ///< mesh database
1211 moab::Interface &moab = mb_instance; ///< mesh database interface
1212 //! [Create MoAB]
1213
1214 //! [Create MoFEM]
1215 MoFEM::Core core(moab); ///< finite element database
1216 MoFEM::Interface &m_field = core; ///< finite element database interface
1217 //! [Create MoFEM]
1218
1219 //! [Example]
1220 Example ex(m_field);
1221 CHKERR ex.runProblem();
1222 //! [Example]
1223 }
1225
1227}
std::string type
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
int main()
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Kronecker Delta class.
@ QUIET
#define CATCH_ERRORS
Catch errors.
@ MF_EXIST
FieldApproximationBase
approximation base
Definition definitions.h:58
@ LASTBASE
Definition definitions.h:69
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
@ H1
continuous field
Definition definitions.h:85
@ NOSPACE
Definition definitions.h:83
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
constexpr int order
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM > OpMassV
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM *SPACE_DIM > OpMassF
static boost::weak_ptr< TSPrePostProc > tsPrePostProc
static char help[]
[Check]
constexpr int SPACE_DIM
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpBaseTimesVector< 1, SPACE_DIM, SPACE_DIM > OpInertiaForce
constexpr double poisson_ratio
constexpr double omega
Save field DOFS on vertices/tags.
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::DomainEle DomainEle
double trace(FTensor::Tensor2< T, 2, 2 > &t_stress)
FormsIntegrators< DomainEleOp >::Assembly< AssemblyType::PETSC >::LinearForm< IntegrationType::GAUSS >::OpGradTimesTensor< 1, SPACE_DIM, SPACE_DIM > OpGradTimesPiola
double bulk_modulus_K
FormsIntegrators< DomainEleOp >::Assembly< AssemblyType::PETSC >::LinearForm< IntegrationType::GAUSS >::OpBaseTimesVector< 1, SPACE_DIM *SPACE_DIM, SPACE_DIM *SPACE_DIM > OpRhsTestPiola
FormsIntegrators< DomainEleOp >::Assembly< AssemblyType::PETSC >::LinearForm< IntegrationType::GAUSS >::OpGradTimesTensor< 1, SPACE_DIM, SPACE_DIM > OpGradTimesTensor2
double shear_modulus_G
constexpr double young_modulus
auto integration_rule
constexpr auto t_kd
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
Definition DMMoFEM.cpp:1188
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:576
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1237
@ GAUSS
Gaussian quadrature integration.
@ PETSC
Standard PETSc assembly.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
FTensor::Index< 'i', SPACE_DIM > i
double dt
double D
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto createKSP(MPI_Comm comm)
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
Definition DMMoFEM.cpp:1046
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
PetscErrorCode PetscOptionsGetRealArray(PetscOptions *, const char pre[], const char name[], PetscReal dval[], PetscInt *nmax, PetscBool *set)
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
FTensor::Index< 'M', 3 > M
FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpGradTimesTensor< 1, FIELD_DIM, SPACE_DIM > OpGradTimesTensor
int save_every_nth_step
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
static constexpr int approx_order
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, SPACE_DIM > OpMass
[Only used with Hooke equation (linear material model)]
Definition seepage.cpp:56
FTensor::Index< 'm', 3 > m
SmartPetscObj< Mat > M
Mass matrix.
SmartPetscObj< KSP > ksp
Linear solver.
double getScale(const double time)
Get scaling at given time.
double getScale(const double time)
Get scaling at given time.
[Example]
Definition plastic.cpp:216
MoFEMErrorCode boundaryCondition()
[Set up problem]
MoFEMErrorCode assembleSystem()
[Push operators to pipeline]
MoFEMErrorCode readMesh()
[Run problem]
FieldApproximationBase base
Choice of finite element basis functions.
Definition plot_base.cpp:68
Simple * simple
MoFEMErrorCode checkResults()
[Postprocess results]
MoFEMErrorCode solveSystem()
[Solve]
Example(MoFEM::Interface &m_field)
MoFEMErrorCode runProblem()
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:226
MoFEMErrorCode setupProblem()
MoFEMErrorCode outputResults()
[Solve]
double getScale(const double time)
Get scaling at given time.
Add operators pushing bases from local to physical configuration.
boost::weak_ptr< CacheTuple > getCacheWeakPtr() const
Get the cache weak pointer object.
Boundary condition manager for finite element problem setup.
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
Core (interface) class.
Definition Core.hpp:83
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
Deprecated interface functions.
Definition of the displacement bc data structure.
Definition BCData.hpp:72
Data on single entity (This is passed as argument to DataOperator::doWork)
Class (Function) to enforce essential constrains.
Definition Essential.hpp:25
Structure for user loop methods on finite elements.
Basic algebra on fields.
Definition FieldBlas.hpp:21
Field evaluator interface.
SetIntegrationPtsMethodData SetPtsData
structure to get information from mofem into EntitiesFieldData
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Interface for managing meshsets containing materials and boundary conditions.
Assembly methods.
Definition Natural.hpp:65
Get values at integration pts for tensor field rank 2, i.e. matrix field.
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Specialization for MatrixDouble vector field values calculation.
Operator for inverting matrices at integration points.
Element used to execute operators on side of the element.
Post post-proc data at points from hash maps.
std::map< std::string, ScalarDataPtr > DataMapVec
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
Template struct for dimension-specific finite element types.
PipelineManager interface.
Projection of edge entities with one mid-node on hierarchical basis.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition Simple.cpp:261
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition Simple.cpp:191
MoFEMErrorCode addBoundaryField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
Definition Simple.cpp:355
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:799
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:575
MoFEMErrorCode addDataField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add data field.
Definition Simple.cpp:393
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition Simple.cpp:735
const std::string getProblemName() const
Get the Problem Name.
Definition Simple.hpp:450
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
intrusive_ptr for managing petsc objects
PetscInt ts_step
Current time step number.
Force scale operator for reading two columns.
double getScale(const double time)
Get scaling at a given time.
TimeScale(std::string file_name="", bool error_if_file_not_given=false, ScalingFun def_scaling_fun=[](double time) { return time;})
TimeScale constructor.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
[Push operators to pipeline]
boost::shared_ptr< PostProcFaceEle > postProcBdy
std::array< double, 3 > fieldEvalCoords
MoFEM::Interface & mField
Monitor(SmartPetscObj< DM > dm, MoFEM::Interface &m_field, boost::shared_ptr< PostProcEle > post_proc, boost::shared_ptr< PostProcFaceEle > post_proc_bdry, boost::shared_ptr< MatrixDouble > velocity_field_ptr, boost::shared_ptr< MatrixDouble > x2_field_ptr, boost::shared_ptr< MatrixDouble > geometry_field_ptr, std::array< double, 3 > pass_field_eval_coords, boost::shared_ptr< SetPtsData > pass_field_eval_data)
boost::shared_ptr< MatrixDouble > geometryFieldPtr
SmartPetscObj< DM > dM
MoFEMErrorCode postProcess()
Post-processing function executed at loop completion.
boost::shared_ptr< MatrixDouble > velocityFieldPtr
boost::shared_ptr< SetPtsData > fieldEvalData
boost::shared_ptr< MatrixDouble > x2FieldPtr
boost::shared_ptr< PostProcEle > postProc
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
boost::shared_ptr< MatrixDouble > defGradPtr
boost::shared_ptr< MatrixDouble > gradTensorPtr
OpCalculateDeformationGradient(boost::shared_ptr< MatrixDouble > def_grad_ptr, boost::shared_ptr< MatrixDouble > grad_tensor_ptr)
boost::shared_ptr< MatrixDouble > XPtr
boost::shared_ptr< MatrixDouble > uPtr
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
OpCalculateDisplacement(boost::shared_ptr< MatrixDouble > spatial_pos_ptr, boost::shared_ptr< MatrixDouble > reference_pos_ptr, boost::shared_ptr< MatrixDouble > u_ptr)
boost::shared_ptr< MatrixDouble > xPtr
boost::shared_ptr< MatrixDouble > gradxPtr
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
OpCalculateFStab(boost::shared_ptr< MatrixDouble > def_grad_ptr, boost::shared_ptr< MatrixDouble > def_grad_stab_ptr, boost::shared_ptr< MatrixDouble > def_grad_dot_ptr, double tau_F_ptr, double xi_F_ptr, boost::shared_ptr< MatrixDouble > grad_x_ptr, boost::shared_ptr< MatrixDouble > grad_vel_ptr)
boost::shared_ptr< MatrixDouble > defGradStabPtr
boost::shared_ptr< MatrixDouble > gradVelPtr
boost::shared_ptr< MatrixDouble > defGradPtr
boost::shared_ptr< MatrixDouble > defGradDotPtr
OpCalculatePiolaIncompressibleNH(double shear_modulus, double bulk_modulus, double m_u, double lambda_lamme, boost::shared_ptr< MatrixDouble > first_piola_ptr, boost::shared_ptr< MatrixDouble > def_grad_ptr, boost::shared_ptr< MatrixDouble > inv_def_grad_ptr, boost::shared_ptr< VectorDouble > det)
boost::shared_ptr< VectorDouble > dEt
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
boost::shared_ptr< MatrixDouble > invDefGradPtr
boost::shared_ptr< MatrixDouble > defGradPtr
boost::shared_ptr< MatrixDouble > firstPiolaPtr
OpCalculatePiola(double shear_modulus, double bulk_modulus, double m_u, double lambda_lamme, boost::shared_ptr< MatrixDouble > first_piola_ptr, boost::shared_ptr< MatrixDouble > def_grad_ptr)
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
boost::shared_ptr< MatrixDouble > defGradPtr
boost::shared_ptr< MatrixDouble > firstPiolaPtr
PipelineManager::ElementsAndOpsByDim< 2 >::FaceSideEle SideEle
PipelineManager::ElementsAndOpsByDim< 3 >::FaceSideEle SideEle
Set of functions called by PETSc solver used to refine and update mesh.
static MoFEMErrorCode tsPostStep(TS ts)
virtual ~TSPrePostProc()=default
static MoFEMErrorCode tsPreStep(TS ts)
TSPrePostProc()=default
static MoFEMErrorCode tsPostStage(TS ts, PetscReal stagetime, PetscInt stageindex, Vec *Y)
[Boundary condition]
MoFEMErrorCode tsSetUp(TS ts)
Used to setup TS solver.
static boost::weak_ptr< TSPrePostProc > tsPrePostProc
double rho
Definition plastic.cpp:144
#define EXECUTABLE_DIMENSION
Definition plastic.cpp:13
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:61
constexpr int SPACE_DIM
DomainNaturalBC::OpFlux< NaturalMeshsetType< BLOCKSET >, 1, SPACE_DIM > OpBodyForce