v0.16.0
Loading...
Searching...
No Matches
ContactOps.hpp
Go to the documentation of this file.
1
2
3/**
4 * \file ContactOps.hpp
5 * \example mofem/tutorials/adv-1_contact/src/ContactOps.hpp
6 */
7
8#ifndef __CONTACTOPS_HPP__
9#define __CONTACTOPS_HPP__
10
11namespace ContactOps {
12
13//! [Common data]
14struct CommonData : public boost::enable_shared_from_this<CommonData> {
15 // MatrixDouble contactStress;
16 MatrixDouble contactTraction;
17 MatrixDouble contactDisp;
18 MatrixDouble contactDispGrad;
19
20 VectorDouble sdfVals; ///< size is equal to number of gauss points on element
21 MatrixDouble gradsSdf; ///< nb of rows is equals to number of gauss points on
22 ///< element, and nb of cols is equals to dimension
23 MatrixDouble hessSdf; ///< nb of rows is equals to nb of element of symmetric
24 ///< matrix, and nb of cols is equals to number of gauss
25 ///< points on element
26 VectorDouble constraintVals;
27
28 static SmartPetscObj<Vec>
29 totalTraction; // User have to release and create vector when appropiate.
30
31 static auto createTotalTraction(MoFEM::Interface &m_field) {
32 constexpr int ghosts[] = {0, 1, 2, 3, 4};
34 createGhostVector(m_field.get_comm(),
35
36 (m_field.get_comm_rank() == 0) ? 5 : 0, 5,
37
38 (m_field.get_comm_rank() == 0) ? 0 : 5, ghosts);
39 return totalTraction;
40 }
41
44 const double *t_ptr;
45 CHK_THROW_MESSAGE(VecGetArrayRead(CommonData::totalTraction, &t_ptr),
46 "get array");
47 FTensor::Tensor1<double, 5> t{t_ptr[0], t_ptr[1], t_ptr[2], t_ptr[3],
48 t_ptr[4]};
49 CHK_THROW_MESSAGE(VecRestoreArrayRead(CommonData::totalTraction, &t_ptr),
50 "restore array");
51 return t;
52 } else {
53 return FTensor::Tensor1<double, 5>{0., 0., 0., 0., 0.};
54 }
55 }
56
57 inline auto contactTractionPtr() {
58 return boost::shared_ptr<MatrixDouble>(shared_from_this(),
60 }
61
62 inline auto contactDispPtr() {
63 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &contactDisp);
64 }
65
66 inline auto contactDispGradPtr() {
67 return boost::shared_ptr<MatrixDouble>(shared_from_this(),
69 }
70
71 inline auto sdfPtr() {
72 return boost::shared_ptr<VectorDouble>(shared_from_this(), &sdfVals);
73 }
74
75 inline auto gradSdfPtr() {
76 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &gradsSdf);
77 }
78
79 inline auto hessSdfPtr() {
80 return boost::shared_ptr<MatrixDouble>(shared_from_this(), &hessSdf);
81 }
82
83 inline auto constraintPtr() {
84 return boost::shared_ptr<VectorDouble>(shared_from_this(), &constraintVals);
85 }
86};
87
88SmartPetscObj<Vec> CommonData::totalTraction;
89
90//! [Common data]
91
92//! [Surface distance function from python]
93#ifdef ENABLE_PYTHON_BINDING
94struct SDFPython {
95 SDFPython() = default;
96 virtual ~SDFPython() = default;
97
98 MoFEMErrorCode sdfInit(const std::string py_file) {
100 try {
101
102 // create main module
103 auto main_module = bp::import("__main__");
104 mainNamespace = main_module.attr("__dict__");
105 bp::exec_file(py_file.c_str(), mainNamespace, mainNamespace);
106 // create a reference to python function
107 sdfFun = mainNamespace["sdf"];
108 sdfGradFun = mainNamespace["grad_sdf"];
109 sdfHessFun = mainNamespace["hess_sdf"];
110
111 } catch (bp::error_already_set const &) {
112 // print all other errors to stderr
113 PyErr_Print();
115 }
117 };
118
119 template <typename T>
120 inline std::vector<T>
121 py_list_to_std_vector(const boost::python::object &iterable) {
122 return std::vector<T>(boost::python::stl_input_iterator<T>(iterable),
123 boost::python::stl_input_iterator<T>());
124 }
125
126 MoFEMErrorCode evalSdf(
127
128 double delta_t, double t, np::ndarray x, np::ndarray y, np::ndarray z,
129 np::ndarray tx, np::ndarray ty, np::ndarray tz, int block_id,
130 np::ndarray &sdf
131
132 ) {
134 try {
135
136 // call python function
137 sdf = bp::extract<np::ndarray>(
138 sdfFun(delta_t, t, x, y, z, tx, ty, tz, block_id));
139
140 } catch (bp::error_already_set const &) {
141 // print all other errors to stderr
142 PyErr_Print();
144 }
146 }
147
148 MoFEMErrorCode evalGradSdf(
149
150 double delta_t, double t, np::ndarray x, np::ndarray y, np::ndarray z,
151 np::ndarray tx, np::ndarray ty, np::ndarray tz, int block_id,
152 np::ndarray &grad_sdf
153
154 ) {
156 try {
157
158 // call python function
159 grad_sdf = bp::extract<np::ndarray>(
160 sdfGradFun(delta_t, t, x, y, z, tx, ty, tz, block_id));
161
162 } catch (bp::error_already_set const &) {
163 // print all other errors to stderr
164 PyErr_Print();
166 }
168 }
169
170 MoFEMErrorCode evalHessSdf(
171
172 double delta_t, double t, np::ndarray x, np::ndarray y, np::ndarray z,
173 np::ndarray tx, np::ndarray ty, np::ndarray tz, int block_id,
174 np::ndarray &hess_sdf
175
176 ) {
178 try {
179
180 // call python function
181 hess_sdf = bp::extract<np::ndarray>(
182 sdfHessFun(delta_t, t, x, y, z, tx, ty, tz, block_id));
183
184 } catch (bp::error_already_set const &) {
185 // print all other errors to stderr
186 PyErr_Print();
188 }
190 }
191
192private:
193 bp::object mainNamespace;
194 bp::object sdfFun;
195 bp::object sdfGradFun;
196 bp::object sdfHessFun;
197};
198
199static boost::weak_ptr<SDFPython> sdfPythonWeakPtr;
200
201inline np::ndarray convert_to_numpy(VectorDouble &data, int nb_gauss_pts,
202 int id) {
203 auto dtype = np::dtype::get_builtin<double>();
204 auto size = bp::make_tuple(nb_gauss_pts);
205 auto stride = bp::make_tuple(3 * sizeof(double));
206 return (np::from_data(&data[id], dtype, size, stride, bp::object()));
207};
208#endif
209//! [Surface distance function from python]
210
211using SurfaceDistanceFunction = boost::function<VectorDouble(
212 double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords,
213 MatrixDouble &normals_at_pts, int block_id)>;
214
215using GradSurfaceDistanceFunction = boost::function<MatrixDouble(
216 double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords,
217 MatrixDouble &normals_at_pts, int block_id)>;
218
219using HessSurfaceDistanceFunction = boost::function<MatrixDouble(
220 double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords,
221 MatrixDouble &normals_at_pts, int block_id)>;
222
223inline VectorDouble surface_distance_function(double delta_t, double t,
224 int nb_gauss_pts,
225 MatrixDouble &m_spatial_coords,
226 MatrixDouble &m_normals_at_pts,
227 int block_id) {
228
229#ifdef ENABLE_PYTHON_BINDING
230 if (auto sdf_ptr = sdfPythonWeakPtr.lock()) {
231
232 VectorDouble v_spatial_coords = m_spatial_coords.data();
233 VectorDouble v_normal_at_pts = m_normals_at_pts.data();
234
235 bp::list python_coords;
236 bp::list python_normals;
237
238 for (int idx = 0; idx < 3; ++idx) {
239 python_coords.append(
240 convert_to_numpy(v_spatial_coords, nb_gauss_pts, idx));
241 python_normals.append(
242 convert_to_numpy(v_normal_at_pts, nb_gauss_pts, idx));
243 }
244
245 np::ndarray np_sdf = np::empty(bp::make_tuple(nb_gauss_pts),
246 np::dtype::get_builtin<double>());
247 CHK_MOAB_THROW(sdf_ptr->evalSdf(delta_t, t,
248 bp::extract<np::ndarray>(python_coords[0]),
249 bp::extract<np::ndarray>(python_coords[1]),
250 bp::extract<np::ndarray>(python_coords[2]),
251 bp::extract<np::ndarray>(python_normals[0]),
252 bp::extract<np::ndarray>(python_normals[1]),
253 bp::extract<np::ndarray>(python_normals[2]),
254 block_id, np_sdf),
255 "Failed python call");
256
257 // check the shape of returned array
258 if (np_sdf.get_nd() != 1 || np_sdf.get_shape()[0] != nb_gauss_pts) {
261 "Wrong number of dimensions or size of SDF returned from "
262 "python, expected: dim 1, got: " +
263 std::to_string(np_sdf.get_nd()) + ", expected size: (" +
264 std::to_string(nb_gauss_pts) + ")");
265 }
266
267 double *sdf_val_ptr = reinterpret_cast<double *>(np_sdf.get_data());
268
269 VectorDouble v_sdf;
270 v_sdf.resize(nb_gauss_pts, false);
271
272 for (size_t gg = 0; gg < nb_gauss_pts; ++gg)
273 v_sdf[gg] = *(sdf_val_ptr + gg);
274
275 return v_sdf;
276 }
277#endif
278 VectorDouble v_sdf;
279 v_sdf.resize(nb_gauss_pts, false);
280 auto t_coords = getFTensor1FromPtr<3>(&m_spatial_coords(0, 0));
281
282 for (size_t gg = 0; gg < nb_gauss_pts; ++gg) {
283 v_sdf[gg] = -t_coords(2) - 0.1;
284 ++t_coords;
285 }
286
287 return v_sdf;
288}
289
290inline MatrixDouble
291grad_surface_distance_function(double delta_t, double t, int nb_gauss_pts,
292 MatrixDouble &m_spatial_coords,
293 MatrixDouble &m_normals_at_pts, int block_id) {
294#ifdef ENABLE_PYTHON_BINDING
295 if (auto sdf_ptr = sdfPythonWeakPtr.lock()) {
296
297 VectorDouble v_spatial_coords = m_spatial_coords.data();
298 VectorDouble v_normal_at_pts = m_normals_at_pts.data();
299
300 bp::list python_coords;
301 bp::list python_normals;
302
303 for (int idx = 0; idx < 3; ++idx) {
304 python_coords.append(
305 convert_to_numpy(v_spatial_coords, nb_gauss_pts, idx));
306 python_normals.append(
307 convert_to_numpy(v_normal_at_pts, nb_gauss_pts, idx));
308 }
309
310 np::ndarray np_grad_sdf = np::empty(bp::make_tuple(nb_gauss_pts, 3),
311 np::dtype::get_builtin<double>());
312 CHK_MOAB_THROW(sdf_ptr->evalGradSdf(
313 delta_t, t, bp::extract<np::ndarray>(python_coords[0]),
314 bp::extract<np::ndarray>(python_coords[1]),
315 bp::extract<np::ndarray>(python_coords[2]),
316 bp::extract<np::ndarray>(python_normals[0]),
317 bp::extract<np::ndarray>(python_normals[1]),
318 bp::extract<np::ndarray>(python_normals[2]), block_id,
319 np_grad_sdf),
320 "Failed python call");
321
322 // check the shape of returned array
323 if (np_grad_sdf.get_shape()[0] != nb_gauss_pts ||
324 np_grad_sdf.get_shape()[1] != 3) {
326 "Wrong shape of gradient of SDF returned from "
327 "python, expected: (" +
328 std::to_string(nb_gauss_pts) + ", 3), got: (" +
329 std::to_string(np_grad_sdf.get_shape()[0]) + ", " +
330 std::to_string(np_grad_sdf.get_shape()[1]) + ")");
331 }
332
333 double *grad_ptr = reinterpret_cast<double *>(np_grad_sdf.get_data());
334
335 MatrixDouble m_grad_sdf;
336 m_grad_sdf.resize(nb_gauss_pts, 3, false);
337 for (size_t gg = 0; gg < nb_gauss_pts; ++gg) {
338 for (int idx = 0; idx < 3; ++idx)
339 m_grad_sdf(gg, idx) = *(grad_ptr + (3 * gg + idx));
340 }
341 return m_grad_sdf;
342 }
343#endif
344 MatrixDouble m_grad_sdf;
345 m_grad_sdf.resize(nb_gauss_pts, 3, false);
346 FTensor::Index<'i', 3> i;
347 FTensor::Tensor1<double, 3> t_grad_sdf_set{0.0, 0.0, -1.0};
348 auto t_grad_sdf = getFTensor1FromMat<3>(m_grad_sdf);
349
350 for (size_t gg = 0; gg < nb_gauss_pts; ++gg) {
351 t_grad_sdf(i) = t_grad_sdf_set(i);
352 ++t_grad_sdf;
353 }
354
355 return m_grad_sdf;
356}
357
358inline MatrixDouble
359hess_surface_distance_function(double delta_t, double t, int nb_gauss_pts,
360 MatrixDouble &m_spatial_coords,
361 MatrixDouble &m_normals_at_pts, int block_id) {
362#ifdef ENABLE_PYTHON_BINDING
363 if (auto sdf_ptr = sdfPythonWeakPtr.lock()) {
364
365 VectorDouble v_spatial_coords = m_spatial_coords.data();
366 VectorDouble v_normal_at_pts = m_normals_at_pts.data();
367
368 bp::list python_coords;
369 bp::list python_normals;
370
371 for (int idx = 0; idx < 3; ++idx) {
372 python_coords.append(
373 convert_to_numpy(v_spatial_coords, nb_gauss_pts, idx));
374 python_normals.append(
375 convert_to_numpy(v_normal_at_pts, nb_gauss_pts, idx));
376 };
377
378 np::ndarray np_hess_sdf = np::empty(bp::make_tuple(nb_gauss_pts, 6),
379 np::dtype::get_builtin<double>());
380 CHK_MOAB_THROW(sdf_ptr->evalHessSdf(
381 delta_t, t, bp::extract<np::ndarray>(python_coords[0]),
382 bp::extract<np::ndarray>(python_coords[1]),
383 bp::extract<np::ndarray>(python_coords[2]),
384 bp::extract<np::ndarray>(python_normals[0]),
385 bp::extract<np::ndarray>(python_normals[1]),
386 bp::extract<np::ndarray>(python_normals[2]), block_id,
387 np_hess_sdf),
388 "Failed python call");
389
390 // check the shape of returned array
391 if (np_hess_sdf.get_shape()[0] != nb_gauss_pts ||
392 np_hess_sdf.get_shape()[1] != 6) {
394 "Wrong shape of Hessian of SDF returned from "
395 "python, expected: (" +
396 std::to_string(nb_gauss_pts) + ", 6), got: (" +
397 std::to_string(np_hess_sdf.get_shape()[0]) + ", " +
398 std::to_string(np_hess_sdf.get_shape()[1]) + ")");
399 }
400
401 double *hess_ptr = reinterpret_cast<double *>(np_hess_sdf.get_data());
402
403 MatrixDouble m_hess_sdf;
404 m_hess_sdf.resize(nb_gauss_pts, 6, false);
405 for (size_t gg = 0; gg < nb_gauss_pts; ++gg) {
406 for (int idx = 0; idx < 6; ++idx)
407 m_hess_sdf(gg, idx) = *(hess_ptr + (6 * gg + idx));
408 }
409 return m_hess_sdf;
410 }
411#endif
412 MatrixDouble m_hess_sdf;
413 m_hess_sdf.resize(nb_gauss_pts, 6, false);
414 FTensor::Index<'i', 3> i;
415 FTensor::Index<'j', 3> j;
416 FTensor::Tensor2_symmetric<double, 3> t_hess_sdf_set{0., 0., 0., 0., 0., 0.};
417 auto t_hess_sdf = getFTensor2SymmetricFromMat<3>(m_hess_sdf);
418
419 for (size_t gg = 0; gg < nb_gauss_pts; ++gg) {
420 t_hess_sdf(i, j) = t_hess_sdf_set(i, j);
421 ++t_hess_sdf;
422 }
423 return m_hess_sdf;
424}
425
426template <int DIM, IntegrationType I, typename BoundaryEleOp>
428
429template <int DIM, IntegrationType I, typename BoundaryEleOp>
431
432template <int DIM, IntegrationType I, typename BoundaryEleOp>
434
435template <int DIM, IntegrationType I, typename AssemblyBoundaryEleOp>
437
438template <int DIM, IntegrationType I, typename AssemblyBoundaryEleOp>
440
441template <int DIM, IntegrationType I, typename AssemblyBoundaryEleOp>
443
444template <typename T1, typename T2, int DIM1, int DIM2>
447 size_t nb_gauss_pts) {
448 MatrixDouble m_spatial_coords(nb_gauss_pts, 3);
449 m_spatial_coords.clear();
450 auto t_spatial_coords = getFTensor1FromPtr<3>(&m_spatial_coords(0, 0));
451 FTensor::Index<'i', DIM2> i;
452 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
453 t_spatial_coords(i) = t_coords(i) + t_disp(i);
454 ++t_spatial_coords;
455 ++t_coords;
456 ++t_disp;
457 }
458 return m_spatial_coords;
459}
460
461template <typename T1, int DIM1>
463 size_t nb_gauss_pts) {
464 MatrixDouble m_normals_at_pts(nb_gauss_pts, 3);
465 m_normals_at_pts.clear();
466 FTensor::Index<'i', DIM1> i;
467 auto t_set_normal = getFTensor1FromMat<3>(m_normals_at_pts);
468 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
469 t_set_normal(i) = t_normal_at_pts(i) / t_normal_at_pts.l2();
470 ++t_set_normal;
471 ++t_normal_at_pts;
472 }
473 return m_normals_at_pts;
474}
475
476template <int DIM, typename BoundaryEleOp>
478 : public BoundaryEleOp {
480 boost::shared_ptr<CommonData> common_data_ptr, double scale = 1,
481 bool is_axisymmetric = false);
482 MoFEMErrorCode doWork(int side, EntityType type, EntData &data);
483
484private:
485 boost::shared_ptr<CommonData> commonDataPtr;
486 const double scaleTraction;
488};
489
490template <int DIM, typename BoundaryEleOp>
492 : public BoundaryEleOp {
494 boost::shared_ptr<CommonData> common_data_ptr,
495 bool is_axisymmetric = false,
496 boost::shared_ptr<Range> contact_range_ptr = nullptr);
497 MoFEMErrorCode doWork(int side, EntityType type, EntData &data);
498
500 GradSurfaceDistanceFunction gradSurfaceDistanceFunction =
502
503private:
504 boost::shared_ptr<CommonData> commonDataPtr;
506 boost::shared_ptr<Range> contactRange;
507};
508
509template <int DIM, typename BoundaryEleOp>
510struct OpEvaluateSDFImpl<DIM, GAUSS, BoundaryEleOp> : public BoundaryEleOp {
511 OpEvaluateSDFImpl(boost::shared_ptr<CommonData> common_data_ptr);
512 MoFEMErrorCode doWork(int side, EntityType type, EntData &data);
513
514private:
515 boost::shared_ptr<CommonData> commonDataPtr;
516
518 GradSurfaceDistanceFunction gradSurfaceDistanceFunction =
520 HessSurfaceDistanceFunction hessSurfaceDistanceFunction =
522};
523
524template <int DIM, typename AssemblyBoundaryEleOp>
526 : public AssemblyBoundaryEleOp {
527 OpConstrainBoundaryRhsImpl(const std::string field_name,
528 boost::shared_ptr<CommonData> common_data_ptr,
529 bool is_axisymmetric = false);
530 MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &data);
531
533 GradSurfaceDistanceFunction gradSurfaceDistanceFunction =
535
536private:
537 boost::shared_ptr<CommonData> commonDataPtr;
539};
540
541template <int DIM, typename AssemblyBoundaryEleOp>
543 : public AssemblyBoundaryEleOp {
544 OpConstrainBoundaryLhs_dUImpl(const std::string row_field_name,
545 const std::string col_field_name,
546 boost::shared_ptr<CommonData> common_data_ptr,
547 bool is_axisymmetric = false);
548 MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data,
549 EntitiesFieldData::EntData &col_data);
550
552 GradSurfaceDistanceFunction gradSurfaceDistanceFunction =
554 HessSurfaceDistanceFunction hessSurfaceDistanceFunction =
556
557 boost::shared_ptr<CommonData> commonDataPtr;
559};
560
561template <int DIM, typename AssemblyBoundaryEleOp>
563 : public AssemblyBoundaryEleOp {
565 const std::string row_field_name, const std::string col_field_name,
566 boost::shared_ptr<CommonData> common_data_ptr,
567 bool is_axisymmetric = false);
568 MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data,
569 EntitiesFieldData::EntData &col_data);
570
572 GradSurfaceDistanceFunction gradSurfaceDistanceFunction =
574
575private:
576 boost::shared_ptr<CommonData> commonDataPtr;
578};
579
580template <typename BoundaryEleOp> struct ContactIntegrators {
581 template <int DIM, IntegrationType I>
584
585 template <int DIM, IntegrationType I>
588
589 template <int DIM, IntegrationType I>
591
592 template <AssemblyType A> struct Assembly {
593
595 typename FormsIntegrators<BoundaryEleOp>::template Assembly<A>::OpBase;
596
597 template <int DIM, IntegrationType I>
600
601 template <int DIM, IntegrationType I>
604
605 template <int DIM, IntegrationType I>
608 };
609};
610
611inline double sign(double x) {
612 constexpr auto eps = std::numeric_limits<float>::epsilon();
613 if (std::abs(x) < eps)
614 return 0;
615 else if (x > eps)
616 return 1;
617 else
618 return -1;
619};
620
621inline double w(const double sdf, const double tn) {
622 return sdf - cn_contact * tn;
623}
624
625/**
626 * @brief constrain function
627 *
628 * return 1 if negative sdf or positive tn
629 *
630 * @param sdf signed distance
631 * @param tn traction
632 * @return double
633 */
634inline double constrain(double sdf, double tn) {
635 const auto s = sign(w(sdf, tn));
636 return (1 - s) / 2;
637}
638
639template <int DIM, typename BoundaryEleOp>
642 boost::shared_ptr<CommonData> common_data_ptr, double scale,
643 bool is_axisymmetric)
645 commonDataPtr(common_data_ptr), scaleTraction(scale),
646 isAxisymmetric(is_axisymmetric) {}
647
648template <int DIM, typename BoundaryEleOp>
649MoFEMErrorCode
651 int side, EntityType type, EntData &data) {
653
654 FTensor::Index<'i', DIM> i;
655 FTensor::Tensor1<double, 3> t_sum_t{0., 0., 0.};
656
657 auto t_w = BoundaryEleOp::getFTensor0IntegrationWeight();
658 auto t_traction = getFTensor1FromMat<DIM>(commonDataPtr->contactTraction);
659 auto t_coords = BoundaryEleOp::getFTensor1CoordsAtGaussPts();
660
661 const auto nb_gauss_pts = BoundaryEleOp::getGaussPts().size2();
662 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
663 double jacobian = 1.;
664 if (isAxisymmetric) {
665 jacobian = 2. * M_PI * t_coords(0);
666 }
667 const double alpha = t_w * jacobian * BoundaryEleOp::getMeasure();
668 t_sum_t(i) += alpha * t_traction(i);
669 ++t_w;
670 ++t_traction;
671 ++t_coords;
672 }
673
674 t_sum_t(i) *= scaleTraction;
675
676 constexpr int ind[] = {0, 1, 2};
677 CHKERR VecSetValues(commonDataPtr->totalTraction, 3, ind, &t_sum_t(0),
678 ADD_VALUES);
679
681}
682template <int DIM, typename BoundaryEleOp>
685 boost::shared_ptr<CommonData> common_data_ptr, bool is_axisymmetric,
686 boost::shared_ptr<Range> contact_range_ptr)
688 commonDataPtr(common_data_ptr), isAxisymmetric(is_axisymmetric),
689 contactRange(contact_range_ptr) {}
690
691template <int DIM, typename BoundaryEleOp>
692MoFEMErrorCode
694 int side, EntityType type, EntData &data) {
696
697 auto fe_type = BoundaryEleOp::getFEType();
698
699 const auto fe_ent = BoundaryEleOp::getFEEntityHandle();
700
701 if (contactRange->find(fe_ent) != contactRange->end()) {
702 FTensor::Index<'i', DIM> i;
703 FTensor::Index<'j', DIM> j;
704 FTensor::Tensor1<double, 2> t_sum_a{0., 0.};
705
706 auto t_w = BoundaryEleOp::getFTensor0IntegrationWeight();
707 auto t_traction = getFTensor1FromMat<DIM>(commonDataPtr->contactTraction);
708 auto t_coords = BoundaryEleOp::getFTensor1CoordsAtGaussPts();
709
710 auto t_grad = getFTensor2FromMat<DIM, DIM>(commonDataPtr->contactDispGrad);
711 auto t_normal_at_pts = BoundaryEleOp::getFTensor1NormalsAtGaussPts();
712
713 const auto nb_gauss_pts = BoundaryEleOp::getGaussPts().size2();
714 auto m_spatial_coords = get_spatial_coords(
715 BoundaryEleOp::getFTensor1CoordsAtGaussPts(),
716 getFTensor1FromMat<DIM>(commonDataPtr->contactDisp), nb_gauss_pts);
717 auto m_normals_at_pts = get_normalize_normals(
718 BoundaryEleOp::getFTensor1NormalsAtGaussPts(), nb_gauss_pts);
719
720 auto ts_time = BoundaryEleOp::getTStime();
721 auto ts_time_step = BoundaryEleOp::getTStimeStep();
722 int block_id = 0;
723 auto v_sdf =
724 surfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
725 m_spatial_coords, m_normals_at_pts, block_id);
726 auto m_grad_sdf = gradSurfaceDistanceFunction(
727 ts_time_step, ts_time, nb_gauss_pts, m_spatial_coords, m_normals_at_pts,
728 block_id);
729 auto t_sdf = getFTensor0FromVec(v_sdf);
730 auto t_grad_sdf = getFTensor1FromMat<3>(m_grad_sdf);
731 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
732 double jacobian = 1.;
733 if (isAxisymmetric) {
734 jacobian = 2. * M_PI * t_coords(0); // Axisymmetric Jacobian
735 }
736 auto tn = -t_traction(i) * t_grad_sdf(i);
737 auto c = constrain(t_sdf, tn);
738 double alpha = t_w * jacobian;
739
742 FTensor::Tensor1<double, DIM> t_normal_current;
743
744 F(i, j) = t_grad(i, j) + kronecker_delta(i, j);
745 auto det = determinantTensor(F);
746 CHKERR invertTensor(F, det, invF);
747 t_normal_current(i) = det * (invF(j, i) * t_normal_at_pts(j));
748
749 alpha *= sqrt(t_normal_current(i) * t_normal_current(i));
750
751 if (fe_type == MBTRI) {
752 alpha /= 2;
753 }
754 if (c > 1e-12) {
755 t_sum_a(0) += alpha; // real area
756 }
757 t_sum_a(1) += alpha; // Potential area
758 ++t_w;
759 ++t_traction;
760 ++t_coords;
761 ++t_sdf;
762 ++t_grad_sdf;
763
764 ++t_grad;
765 ++t_normal_at_pts;
766 }
767 constexpr int ind[] = {3, 4};
768 CHKERR VecSetValues(commonDataPtr->totalTraction, 2, ind, &t_sum_a(0),
769 ADD_VALUES);
770 }
772}
773
774template <int DIM, typename BoundaryEleOp>
776 boost::shared_ptr<CommonData> common_data_ptr)
778 commonDataPtr(common_data_ptr) {}
779
780template <int DIM, typename BoundaryEleOp>
781MoFEMErrorCode
783 EntData &data) {
785
786 const auto nb_gauss_pts = BoundaryEleOp::getGaussPts().size2();
787 auto &sdf_vec = commonDataPtr->sdfVals;
788 auto &grad_mat = commonDataPtr->gradsSdf;
789 auto &hess_mat = commonDataPtr->hessSdf;
790 auto &constraint_vec = commonDataPtr->constraintVals;
791 auto &contactTraction_mat = commonDataPtr->contactTraction;
792
793 sdf_vec.resize(nb_gauss_pts, false);
794 grad_mat.resize(nb_gauss_pts, DIM, false);
795 hess_mat.resize(nb_gauss_pts, (DIM * (DIM + 1)) / 2, false);
796 constraint_vec.resize(nb_gauss_pts, false);
797
798 auto t_traction = getFTensor1FromMat<DIM>(contactTraction_mat);
799
800 auto t_sdf = getFTensor0FromVec(sdf_vec);
801 auto t_grad_sdf = getFTensor1FromMat<DIM>(grad_mat);
802 auto t_hess_sdf = getFTensor2SymmetricFromMat<DIM>(hess_mat);
803 auto t_constraint = getFTensor0FromVec(constraint_vec);
804
805 auto t_disp = getFTensor1FromMat<DIM>(commonDataPtr->contactDisp);
806 FTensor::Index<'i', DIM> i;
807 FTensor::Index<'j', DIM> j;
808
809 auto ts_time = BoundaryEleOp::getTStime();
810 auto ts_time_step = BoundaryEleOp::getTStimeStep();
811
812 auto m_spatial_coords = get_spatial_coords(
813 BoundaryEleOp::getFTensor1CoordsAtGaussPts(),
814 getFTensor1FromMat<DIM>(commonDataPtr->contactDisp), nb_gauss_pts);
815 auto m_normals_at_pts = get_normalize_normals(
816 BoundaryEleOp::getFTensor1NormalsAtGaussPts(), nb_gauss_pts);
817
818 // placeholder to pass boundary block id to python
819 int block_id = 0;
820
821 auto v_sdf =
822 surfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
823 m_spatial_coords, m_normals_at_pts, block_id);
824
825 auto m_grad_sdf =
826 gradSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
827 m_spatial_coords, m_normals_at_pts, block_id);
828
829 auto m_hess_sdf =
830 hessSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
831 m_spatial_coords, m_normals_at_pts, block_id);
832
833 auto t_sdf_v = getFTensor0FromVec(v_sdf);
834 auto t_grad_sdf_v = getFTensor1FromMat<3>(m_grad_sdf);
835 auto t_hess_sdf_v = getFTensor2SymmetricFromMat<3>(m_hess_sdf);
836
837 auto next = [&]() {
838 ++t_sdf;
839 ++t_sdf_v;
840 ++t_grad_sdf;
841 ++t_grad_sdf_v;
842 ++t_hess_sdf;
843 ++t_hess_sdf_v;
844 ++t_disp;
845 ++t_traction;
846 ++t_constraint;
847 };
848
849 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
850
851 auto tn = -t_traction(i) * t_grad_sdf_v(i);
852 auto c = constrain(t_sdf_v, tn);
853
854 t_sdf = t_sdf_v;
855 t_grad_sdf(i) = t_grad_sdf_v(i);
856 t_hess_sdf(i, j) = t_hess_sdf_v(i, j);
857 t_constraint = c;
858
859 next();
860 }
861
863}
864
865template <int DIM, typename AssemblyBoundaryEleOp>
868 boost::shared_ptr<CommonData> common_data_ptr,
869 bool is_axisymmetric)
871 AssemblyBoundaryEleOp::OPROW),
872 commonDataPtr(common_data_ptr), isAxisymmetric(is_axisymmetric) {}
873
874template <int DIM, typename AssemblyBoundaryEleOp>
875MoFEMErrorCode
877 EntitiesFieldData::EntData &data) {
879
880 FTensor::Index<'i', DIM> i;
881 FTensor::Index<'j', DIM> j;
882 FTensor::Index<'k', DIM> k;
883 FTensor::Index<'l', DIM> l;
884
885 const size_t nb_gauss_pts = AssemblyBoundaryEleOp::getGaussPts().size2();
886
887 auto &nf = AssemblyBoundaryEleOp::locF;
888
889 auto t_w = AssemblyBoundaryEleOp::getFTensor0IntegrationWeight();
890 auto t_disp = getFTensor1FromMat<DIM>(commonDataPtr->contactDisp);
891 auto t_traction = getFTensor1FromMat<DIM>(commonDataPtr->contactTraction);
892 auto t_coords = AssemblyBoundaryEleOp::getFTensor1CoordsAtGaussPts();
893
894 size_t nb_base_functions = data.getN().size2() / 3;
895 auto t_base = data.getFTensor1N<3>();
896
897 auto m_spatial_coords = get_spatial_coords(
898 BoundaryEleOp::getFTensor1CoordsAtGaussPts(),
899 getFTensor1FromMat<DIM>(commonDataPtr->contactDisp), nb_gauss_pts);
900 auto m_normals_at_pts = get_normalize_normals(
901 BoundaryEleOp::getFTensor1NormalsAtGaussPts(), nb_gauss_pts);
902
903 auto t_normal = getFTensor1FromMat<3>(m_normals_at_pts);
904
905 auto ts_time = AssemblyBoundaryEleOp::getTStime();
906 auto ts_time_step = AssemblyBoundaryEleOp::getTStimeStep();
907
908 // placeholder to pass boundary block id to python
909 int block_id = 0;
910
911 auto v_sdf =
912 surfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
913 m_spatial_coords, m_normals_at_pts, block_id);
914
915 auto m_grad_sdf =
916 gradSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
917 m_spatial_coords, m_normals_at_pts, block_id);
918
919 auto t_sdf = getFTensor0FromVec(v_sdf);
920 auto t_grad_sdf = getFTensor1FromMat<3>(m_grad_sdf);
921
922 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
923
924 auto t_nf = getFTensor1FromPtr<DIM>(&nf[0]);
925
926 double jacobian = 1.;
927 if (isAxisymmetric) {
928 jacobian = 2. * M_PI * t_coords(0);
929 }
930 const double alpha = t_w * jacobian * AssemblyBoundaryEleOp::getMeasure();
931
932 auto tn = -t_traction(i) * t_grad_sdf(i);
933 auto c = constrain(t_sdf, tn);
934
936 t_cP(i, j) = (c * t_grad_sdf(i)) * t_grad_sdf(j);
938 t_cQ(i, j) = kronecker_delta(i, j) - t_cP(i, j);
939
941 t_rhs(i) =
942
943 t_cQ(i, j) * (t_disp(j) - cn_contact * t_traction(j))
944
945 +
946
947 t_cP(i, j) * t_disp(j) +
948 c * (t_sdf * t_grad_sdf(i)); // add gap0 displacements
949
950 size_t bb = 0;
951 for (; bb != AssemblyBoundaryEleOp::nbRows / DIM; ++bb) {
952 const double beta = alpha * (t_base(i) * t_normal(i));
953 t_nf(i) -= beta * t_rhs(i);
954
955 ++t_nf;
956 ++t_base;
957 }
958 for (; bb < nb_base_functions; ++bb)
959 ++t_base;
960
961 ++t_disp;
962 ++t_traction;
963 ++t_coords;
964 ++t_w;
965 ++t_normal;
966 ++t_sdf;
967 ++t_grad_sdf;
968 }
969
971}
972
973template <int DIM, typename AssemblyBoundaryEleOp>
975 OpConstrainBoundaryLhs_dUImpl(const std::string row_field_name,
976 const std::string col_field_name,
977 boost::shared_ptr<CommonData> common_data_ptr,
978 bool is_axisymmetric)
979 : AssemblyBoundaryEleOp(row_field_name, col_field_name,
980 AssemblyBoundaryEleOp::OPROWCOL),
981 commonDataPtr(common_data_ptr), isAxisymmetric(is_axisymmetric) {
982 AssemblyBoundaryEleOp::sYmm = false;
983}
984
985template <int DIM, typename AssemblyBoundaryEleOp>
986MoFEMErrorCode
988 EntitiesFieldData::EntData &row_data,
989 EntitiesFieldData::EntData &col_data) {
991
992 FTensor::Index<'i', DIM> i;
993 FTensor::Index<'j', DIM> j;
994 FTensor::Index<'k', DIM> k;
995
996 const size_t nb_gauss_pts = AssemblyBoundaryEleOp::getGaussPts().size2();
997 auto &locMat = AssemblyBoundaryEleOp::locMat;
998
999 auto t_traction = getFTensor1FromMat<DIM>(commonDataPtr->contactTraction);
1000 auto t_coords = AssemblyBoundaryEleOp::getFTensor1CoordsAtGaussPts();
1001
1002 auto t_w = AssemblyBoundaryEleOp::getFTensor0IntegrationWeight();
1003 auto t_row_base = row_data.getFTensor1N<3>();
1004 size_t nb_face_functions = row_data.getN().size2() / 3;
1005
1006 auto m_spatial_coords = get_spatial_coords(
1007 BoundaryEleOp::getFTensor1CoordsAtGaussPts(),
1008 getFTensor1FromMat<DIM>(commonDataPtr->contactDisp), nb_gauss_pts);
1009 auto m_normals_at_pts = get_normalize_normals(
1010 BoundaryEleOp::getFTensor1NormalsAtGaussPts(), nb_gauss_pts);
1011
1012 auto t_normal = getFTensor1FromMat<3>(m_normals_at_pts);
1013
1014 auto ts_time = AssemblyBoundaryEleOp::getTStime();
1015 auto ts_time_step = AssemblyBoundaryEleOp::getTStimeStep();
1016
1017 // placeholder to pass boundary block id to python
1018 int block_id = 0;
1019
1020 auto v_sdf =
1021 surfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
1022 m_spatial_coords, m_normals_at_pts, block_id);
1023
1024 auto m_grad_sdf =
1025 gradSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
1026 m_spatial_coords, m_normals_at_pts, block_id);
1027
1028 auto m_hess_sdf =
1029 hessSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
1030 m_spatial_coords, m_normals_at_pts, block_id);
1031
1032 auto t_sdf = getFTensor0FromVec(v_sdf);
1033 auto t_grad_sdf = getFTensor1FromMat<3>(m_grad_sdf);
1034 auto t_hess_sdf = getFTensor2SymmetricFromMat<3>(m_hess_sdf);
1035
1036 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
1037
1038 double jacobian = 1.;
1039 if (isAxisymmetric) {
1040 jacobian = 2. * M_PI * t_coords(0);
1041 }
1042 const double alpha = t_w * jacobian * AssemblyBoundaryEleOp::getMeasure();
1043
1044 auto tn = -t_traction(i) * t_grad_sdf(i);
1045 auto c = constrain(t_sdf, tn);
1046
1048 t_cP(i, j) = (c * t_grad_sdf(i)) * t_grad_sdf(j);
1050 t_cQ(i, j) = kronecker_delta(i, j) - t_cP(i, j);
1051
1053 t_res_dU(i, j) = kronecker_delta(i, j) + t_cP(i, j);
1054
1055 if (c > 0) {
1056 t_res_dU(i, j) +=
1057 (c * cn_contact) *
1058 (t_hess_sdf(i, j) * (t_grad_sdf(k) * t_traction(k)) +
1059 t_grad_sdf(i) * t_hess_sdf(k, j) * t_traction(k)) +
1060 c * t_sdf * t_hess_sdf(i, j);
1061 }
1062
1063 size_t rr = 0;
1064 for (; rr != AssemblyBoundaryEleOp::nbRows / DIM; ++rr) {
1065
1066 auto t_mat = getFTensor2FromArray<DIM, DIM, DIM>(locMat, DIM * rr);
1067
1068 const double row_base = t_row_base(i) * t_normal(i);
1069
1070 auto t_col_base = col_data.getFTensor0N(gg, 0);
1071 for (size_t cc = 0; cc != AssemblyBoundaryEleOp::nbCols / DIM; ++cc) {
1072 const double beta = alpha * row_base * t_col_base;
1073
1074 t_mat(i, j) -= beta * t_res_dU(i, j);
1075
1076 ++t_col_base;
1077 ++t_mat;
1078 }
1079
1080 ++t_row_base;
1081 }
1082 for (; rr < nb_face_functions; ++rr)
1083 ++t_row_base;
1084
1085 ++t_traction;
1086 ++t_coords;
1087 ++t_w;
1088 ++t_normal;
1089 ++t_sdf;
1090 ++t_grad_sdf;
1091 ++t_hess_sdf;
1092 }
1093
1095}
1096
1097template <int DIM, typename AssemblyBoundaryEleOp>
1100 const std::string row_field_name, const std::string col_field_name,
1101 boost::shared_ptr<CommonData> common_data_ptr, bool is_axisymmetric)
1102 : AssemblyBoundaryEleOp(row_field_name, col_field_name,
1103 AssemblyBoundaryEleOp::OPROWCOL),
1104 commonDataPtr(common_data_ptr), isAxisymmetric(is_axisymmetric) {
1105 AssemblyBoundaryEleOp::sYmm = false;
1106}
1107
1108template <int DIM, typename AssemblyBoundaryEleOp>
1109MoFEMErrorCode
1111 iNtegrate(EntitiesFieldData::EntData &row_data,
1112 EntitiesFieldData::EntData &col_data) {
1114
1115 FTensor::Index<'i', DIM> i;
1116 FTensor::Index<'j', DIM> j;
1117 FTensor::Index<'k', DIM> k;
1118
1119 const size_t nb_gauss_pts = AssemblyBoundaryEleOp::getGaussPts().size2();
1120 auto &locMat = AssemblyBoundaryEleOp::locMat;
1121
1122 auto t_traction = getFTensor1FromMat<DIM>(commonDataPtr->contactTraction);
1123 auto t_coords = AssemblyBoundaryEleOp::getFTensor1CoordsAtGaussPts();
1124
1125 auto t_w = AssemblyBoundaryEleOp::getFTensor0IntegrationWeight();
1126 auto t_row_base = row_data.getFTensor1N<3>();
1127 size_t nb_face_functions = row_data.getN().size2() / 3;
1128
1129 auto m_spatial_coords = get_spatial_coords(
1130 BoundaryEleOp::getFTensor1CoordsAtGaussPts(),
1131 getFTensor1FromMat<DIM>(commonDataPtr->contactDisp), nb_gauss_pts);
1132 auto m_normals_at_pts = get_normalize_normals(
1133 BoundaryEleOp::getFTensor1NormalsAtGaussPts(), nb_gauss_pts);
1134
1135 auto t_normal = getFTensor1FromMat<3>(m_normals_at_pts);
1136
1137 auto ts_time = AssemblyBoundaryEleOp::getTStime();
1138 auto ts_time_step = AssemblyBoundaryEleOp::getTStimeStep();
1139
1140 // placeholder to pass boundary block id to python
1141 int block_id = 0;
1142
1143 auto v_sdf =
1144 surfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
1145 m_spatial_coords, m_normals_at_pts, block_id);
1146
1147 auto m_grad_sdf =
1148 gradSurfaceDistanceFunction(ts_time_step, ts_time, nb_gauss_pts,
1149 m_spatial_coords, m_normals_at_pts, block_id);
1150
1151 auto t_sdf = getFTensor0FromVec(v_sdf);
1152 auto t_grad_sdf = getFTensor1FromMat<3>(m_grad_sdf);
1153
1154 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
1155
1156 double jacobian = 1.;
1157 if (isAxisymmetric) {
1158 jacobian = 2. * M_PI * t_coords(0);
1159 }
1160 const double alpha = t_w * jacobian * AssemblyBoundaryEleOp::getMeasure();
1161
1162 auto tn = -t_traction(i) * t_grad_sdf(i);
1163 auto c = constrain(t_sdf, tn);
1164
1166 t_cP(i, j) = (c * t_grad_sdf(i)) * t_grad_sdf(j);
1168 t_cQ(i, j) = kronecker_delta(i, j) - t_cP(i, j);
1169
1171 t_res_dt(i, j) = -cn_contact * t_cQ(i, j);
1172
1173 size_t rr = 0;
1174 for (; rr != AssemblyBoundaryEleOp::nbRows / DIM; ++rr) {
1175
1176 auto t_mat = getFTensor2FromArray<DIM, DIM, DIM>(locMat, DIM * rr);
1177 const double row_base = t_row_base(i) * t_normal(i);
1178
1179 auto t_col_base = col_data.getFTensor1N<3>(gg, 0);
1180 for (size_t cc = 0; cc != AssemblyBoundaryEleOp::nbCols / DIM; ++cc) {
1181 const double col_base = t_col_base(i) * t_normal(i);
1182 const double beta = alpha * row_base * col_base;
1183
1184 t_mat(i, j) -= beta * t_res_dt(i, j);
1185
1186 ++t_col_base;
1187 ++t_mat;
1188 }
1189
1190 ++t_row_base;
1191 }
1192 for (; rr < nb_face_functions; ++rr)
1193 ++t_row_base;
1194
1195 ++t_traction;
1196 ++t_coords;
1197 ++t_w;
1198 ++t_normal;
1199 ++t_sdf;
1200 ++t_grad_sdf;
1201 }
1202
1204}
1205
1206template <int DIM, AssemblyType A, IntegrationType I, typename DomainEleOp>
1207MoFEMErrorCode opFactoryDomainRhs(
1208 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1209 std::string sigma, std::string u, bool is_axisymmetric = false) {
1211
1212 using B = typename FormsIntegrators<DomainEleOp>::template Assembly<
1213 A>::template LinearForm<I>;
1214 using OpMixDivURhs = typename B::template OpMixDivTimesU<3, DIM, DIM>;
1215 using OpMixDivUCylRhs =
1216 typename B::template OpMixDivTimesU<3, DIM, DIM, CYLINDRICAL>;
1217
1218 using OpMixLambdaGradURhs = typename B::template OpMixTensorTimesGradU<DIM>;
1219 using OpMixUTimesDivLambdaRhs =
1220 typename B::template OpMixVecTimesDivLambda<SPACE_DIM>;
1221 using OpMixUTimesLambdaRhs =
1222 typename B::template OpGradTimesTensor<1, DIM, DIM>;
1223
1224 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
1225 auto mat_grad_ptr = boost::make_shared<MatrixDouble>();
1226 auto div_stress_ptr = boost::make_shared<MatrixDouble>();
1227 auto contact_stress_ptr = boost::make_shared<MatrixDouble>();
1228
1229 auto jacobian = [is_axisymmetric](const double r, const double,
1230 const double) {
1231 if (is_axisymmetric)
1232 return 2. * M_PI * r;
1233 else
1234 return 1.;
1235 };
1236
1237 pip.push_back(new OpCalculateVectorFieldValues<DIM>(
1238 u, common_data_ptr->contactDispPtr()));
1239 pip.push_back(
1240 new OpCalculateHVecTensorField<DIM, DIM>(sigma, contact_stress_ptr));
1241
1242 if (!is_axisymmetric) {
1243 pip.push_back(
1244 new OpCalculateHVecTensorDivergence<DIM, DIM>(sigma, div_stress_ptr));
1245 } else {
1246 pip.push_back(new OpCalculateHVecTensorDivergence<DIM, DIM, CYLINDRICAL>(
1247 sigma, div_stress_ptr));
1248 }
1249
1250 pip.push_back(new OpCalculateVectorFieldGradient<DIM, DIM>(u, mat_grad_ptr));
1251
1252 if (!is_axisymmetric) {
1253 pip.push_back(
1254 new OpMixDivURhs(sigma, common_data_ptr->contactDispPtr(), jacobian));
1255 } else {
1256 pip.push_back(new OpMixDivUCylRhs(sigma, common_data_ptr->contactDispPtr(),
1257 jacobian));
1258 }
1259
1260 pip.push_back(new OpMixLambdaGradURhs(sigma, mat_grad_ptr, jacobian));
1261 pip.push_back(new OpMixUTimesDivLambdaRhs(u, div_stress_ptr, jacobian));
1262 pip.push_back(new OpMixUTimesLambdaRhs(u, contact_stress_ptr, jacobian));
1263
1265}
1266
1267template <typename OpMixLhs> struct OpMixLhsSide : public OpMixLhs {
1268 using OpMixLhs::OpMixLhs;
1269 MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
1270 EntityType col_type,
1271 EntitiesFieldData::EntData &row_data,
1272 EntitiesFieldData::EntData &col_data) {
1274 auto side_fe_entity = OpMixLhs::getSidePtrFE()->getFEEntityHandle();
1275 auto side_fe_data = OpMixLhs::getSideEntity(row_side, row_type);
1276 // Only assemble side which correspond to edge entity on boundary
1277 if (side_fe_entity == side_fe_data) {
1278 CHKERR OpMixLhs::doWork(row_side, col_side, row_type, col_type, row_data,
1279 col_data);
1280 }
1282 }
1283};
1284
1285template <int DIM, AssemblyType A, IntegrationType I, typename DomainEle>
1287 MoFEM::Interface &m_field,
1288 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1289 std::string fe_domain_name, std::string sigma, std::string u,
1290 std::string geom, ForcesAndSourcesCore::RuleHookFun rule,
1291 bool is_axisymmetric = false) {
1293
1294 using DomainEleOp = typename DomainEle::UserDataOperator;
1295
1296 auto op_loop_side = new OpLoopSide<DomainEle>(
1297 m_field, fe_domain_name, DIM, Sev::noisy,
1298 boost::make_shared<ForcesAndSourcesCore::UserDataOperator::AdjCache>());
1299 pip.push_back(op_loop_side);
1300
1301 CHKERR AddHOOps<DIM, DIM, DIM>::add(op_loop_side->getOpPtrVector(),
1302 {H1, HDIV}, geom);
1303
1304 using B = typename FormsIntegrators<DomainEleOp>::template Assembly<
1305 A>::template BiLinearForm<I>;
1306
1307 using OpMixDivULhs = typename B::template OpMixDivTimesVec<DIM>;
1308 using OpMixDivUCylLhs =
1309 typename B::template OpMixDivTimesVec<DIM, CYLINDRICAL>;
1310 using OpLambdaGraULhs = typename B::template OpMixTensorTimesGrad<DIM>;
1311
1312 using OpMixDivULhsSide = OpMixLhsSide<OpMixDivULhs>;
1313 using OpMixDivUCylLhsSide = OpMixLhsSide<OpMixDivUCylLhs>;
1314 using OpLambdaGraULhsSide = OpMixLhsSide<OpLambdaGraULhs>;
1315
1316 auto unity = []() { return 1; };
1317 auto jacobian = [is_axisymmetric](const double r, const double,
1318 const double) {
1319 if (is_axisymmetric)
1320 return 2. * M_PI * r;
1321 else
1322 return 1.;
1323 };
1324
1325 if (!is_axisymmetric) {
1326 op_loop_side->getOpPtrVector().push_back(
1327 new OpMixDivULhsSide(sigma, u, unity, jacobian, true));
1328 } else {
1329 op_loop_side->getOpPtrVector().push_back(
1330 new OpMixDivUCylLhsSide(sigma, u, unity, jacobian, true));
1331 }
1332 op_loop_side->getOpPtrVector().push_back(
1333 new OpLambdaGraULhsSide(sigma, u, unity, jacobian, true));
1334
1335 op_loop_side->getSideFEPtr()->getRuleHook = rule;
1337}
1338
1339template <int DIM, AssemblyType A, IntegrationType I, typename BoundaryEleOp>
1341 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1342 std::string sigma, std::string u, bool is_axisymmetric = false) {
1344
1346
1347 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
1348
1349 pip.push_back(new OpCalculateVectorFieldValues<DIM>(
1350 u, common_data_ptr->contactDispPtr()));
1351 pip.push_back(new OpCalculateHVecTensorTrace<DIM, BoundaryEleOp>(
1352 sigma, common_data_ptr->contactTractionPtr()));
1353 pip.push_back(
1354 new typename C::template Assembly<A>::template OpConstrainBoundaryLhs_dU<
1355 DIM, GAUSS>(sigma, u, common_data_ptr, is_axisymmetric));
1356 pip.push_back(new typename C::template Assembly<A>::
1357 template OpConstrainBoundaryLhs_dTraction<DIM, GAUSS>(
1358 sigma, sigma, common_data_ptr, is_axisymmetric));
1359
1361}
1362
1363template <int DIM, AssemblyType A, IntegrationType I, typename BoundaryEleOp>
1365 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1366 std::string sigma, std::string u, bool is_axisymmetric = false) {
1368
1370
1371 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
1372
1373 pip.push_back(new OpCalculateVectorFieldValues<DIM>(
1374 u, common_data_ptr->contactDispPtr()));
1375 pip.push_back(new OpCalculateHVecTensorTrace<DIM, BoundaryEleOp>(
1376 sigma, common_data_ptr->contactTractionPtr()));
1377 pip.push_back(
1378 new typename C::template Assembly<A>::template OpConstrainBoundaryRhs<
1379 DIM, GAUSS>(sigma, common_data_ptr, is_axisymmetric));
1380
1382}
1383
1384template <int DIM, IntegrationType I, typename BoundaryEleOp>
1386 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1387 std::string sigma, bool is_axisymmetric = false) {
1389
1391
1392 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
1393 pip.push_back(new OpCalculateHVecTensorTrace<DIM, BoundaryEleOp>(
1394 sigma, common_data_ptr->contactTractionPtr()));
1395 pip.push_back(new typename C::template OpAssembleTotalContactTraction<DIM, I>(
1396 common_data_ptr, 1. / scale, is_axisymmetric));
1397
1399}
1400
1401template <int DIM, IntegrationType I, typename BoundaryEleOp>
1403 boost::ptr_deque<ForcesAndSourcesCore::UserDataOperator> &pip,
1404 OpLoopSide<SideEle> *op_loop_side, std::string sigma, std::string u,
1405 bool is_axisymmetric = false,
1406 boost::shared_ptr<Range> contact_range_ptr = nullptr) {
1409
1410 auto common_data_ptr = boost::make_shared<ContactOps::CommonData>();
1411
1412 op_loop_side->getOpPtrVector().push_back(
1413 new OpCalculateVectorFieldGradient<SPACE_DIM, SPACE_DIM>(
1414 "U", common_data_ptr->contactDispGradPtr()));
1415
1416 if (contact_range_ptr) {
1417 pip.push_back(new OpCalculateVectorFieldValues<DIM>(
1418 u, common_data_ptr->contactDispPtr()));
1419 pip.push_back(new OpCalculateHVecTensorTrace<DIM, BoundaryEleOp>(
1420 sigma, common_data_ptr->contactTractionPtr()));
1421 pip.push_back(op_loop_side);
1422 pip.push_back(new typename C::template OpAssembleTotalContactArea<DIM, I>(
1423 common_data_ptr, is_axisymmetric, contact_range_ptr));
1424 }
1426}
1427
1428}; // namespace ContactOps
1429
1430#endif // __CONTACTOPS_HPP__
std::string type
static const double eps
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ NOSPACE
Definition definitions.h:83
#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_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
@ F
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
constexpr int DIM2
Definition level_set.cpp:22
constexpr int DIM1
Definition level_set.cpp:21
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
boost::function< VectorDouble(double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords, MatrixDouble &normals_at_pts, int block_id)> SurfaceDistanceFunction
[Common data]
MoFEMErrorCode opFactoryDomainRhs(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, std::string u, bool is_axisymmetric=false)
auto get_normalize_normals(FTensor::Tensor1< T1, DIM1 > &&t_normal_at_pts, size_t nb_gauss_pts)
double cn_contact
Definition contact.cpp:97
MoFEMErrorCode opFactoryCalculateArea(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, OpLoopSide< SideEle > *op_loop_side, std::string sigma, std::string u, bool is_axisymmetric=false, boost::shared_ptr< Range > contact_range_ptr=nullptr)
MatrixDouble grad_surface_distance_function(double delta_t, double t, int nb_gauss_pts, MatrixDouble &m_spatial_coords, MatrixDouble &m_normals_at_pts, int block_id)
MoFEMErrorCode opFactoryBoundaryToDomainLhs(MoFEM::Interface &m_field, boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string fe_domain_name, std::string sigma, std::string u, std::string geom, ForcesAndSourcesCore::RuleHookFun rule, bool is_axisymmetric=false)
MatrixDouble hess_surface_distance_function(double delta_t, double t, int nb_gauss_pts, MatrixDouble &m_spatial_coords, MatrixDouble &m_normals_at_pts, int block_id)
MoFEMErrorCode opFactoryBoundaryRhs(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, std::string u, bool is_axisymmetric=false)
double w(const double sdf, const double tn)
boost::function< MatrixDouble(double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords, MatrixDouble &normals_at_pts, int block_id)> GradSurfaceDistanceFunction
EntitiesFieldData::EntData EntData
boost::function< MatrixDouble(double delta_t, double t, int nb_gauss_pts, MatrixDouble &spatial_coords, MatrixDouble &normals_at_pts, int block_id)> HessSurfaceDistanceFunction
auto get_spatial_coords(FTensor::Tensor1< T1, DIM1 > &&t_coords, FTensor::Tensor1< T2, DIM2 > &&t_disp, size_t nb_gauss_pts)
double constrain(double sdf, double tn)
constrain function
VectorDouble surface_distance_function(double delta_t, double t, int nb_gauss_pts, MatrixDouble &m_spatial_coords, MatrixDouble &m_normals_at_pts, int block_id)
MoFEMErrorCode opFactoryBoundaryLhs(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, std::string u, bool is_axisymmetric=false)
MoFEMErrorCode opFactoryCalculateTraction(boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > &pip, std::string sigma, bool is_axisymmetric=false)
double sign(double x)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition sdf.py:1
hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition sdf.py:20
grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition sdf.py:16
FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpGradTimesTensor< 1, FIELD_DIM, SPACE_DIM > OpGradTimesTensor
constexpr AssemblyType A
constexpr double t
plate stiffness
Definition plate.cpp:58
constexpr auto field_name
VectorDouble sdfVals
size is equal to number of gauss points on element
VectorDouble constraintVals
MatrixDouble contactTraction
static auto getFTensor1TotalTraction()
MatrixDouble contactDisp
static SmartPetscObj< Vec > totalTraction
MatrixDouble contactDispGrad
static auto createTotalTraction(MoFEM::Interface &m_field)
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
Deprecated interface functions.
PetscBool is_axisymmetric
Definition contact.cpp:91