v0.16.3
Loading...
Searching...
No Matches
UserDataOperators.hpp
Go to the documentation of this file.
1/** \file UserDataOperators.hpp
2 * \brief User data operators for finite element computations
3 *
4 * This file contains a comprehensive collection of user data operators used in
5 * MoFEM finite element computations. These operators provide functionality for
6 * calculating, transforming, and manipulating field values at integration points.
7 *
8 * ## Main Categories of Operators:
9 *
10 * ### Field Value Calculation Operators
11 * - **Scalar Field Operators**: Calculate scalar field values at integration points
12 * - OpCalculateScalarFieldValues: General scalar field value calculation
13 * - OpCalculateScalarFieldValuesFromPetscVecImpl: PETSc vector-based scalar values
14 * - **Vector Field Operators**: Calculate vector field values at integration points
15 * - OpCalculateVectorFieldValues: General vector field value calculation
16 * - OpCalculateDivergenceVectorFieldValues: Divergence calculation for vector fields
17 * - **Tensor Field Operators**: Calculate tensor field values at integration points
18 * - OpCalculateTensor2FieldValues: Second-rank tensor field calculations
19 * - OpCalculateTensor2SymmetricFieldValues: Symmetric tensor field calculations
20 * - **Values from MOAB tags**: Entity or vertex tag data at integration points,
21 * created by the factories in UserDataOperatorsFromTags.hpp
22 * (createOpCalculateScalarFieldValuesFromTags and its vector and tensor
23 * variants)
24 *
25 * ### Field Gradient Calculation Operators
26 * - **Scalar Gradient Operators**:
27 * - OpCalculateScalarFieldGradient: Gradient of scalar fields
28 * - OpCalculateScalarFieldHessian: Hessian (second derivatives) of scalar fields
29 * - **Vector Gradient Operators**:
30 * - OpCalculateVectorFieldGradient: Gradient of vector fields
31 *
32 * ### Matrix and Tensor Operations
33 * - **Matrix Manipulation**:
34 * - OpInvertMatrix: Matrix inversion at integration points
35 * - OpScaleMatrix: Element-wise matrix scaling operations
36 * - OpCalculateTraceFromMat: Trace calculation for matrices
37 * - **Tensor Operations**:
38 * - OpSymmetrizeTensor: Tensor symmetrization operations
39 * - OpTensorTimesSymmetricTensor: Tensor multiplication operations
40 *
41 * @see ForcesAndSourcesCore::UserDataOperator for base class documentation
42 * @see EntitiesFieldData for field data management
43 * @see PipelineManager for operator pipeline management
44 */
45
46#ifndef __USER_DATA_OPERATORS_HPP__
47 #define __USER_DATA_OPERATORS_HPP__
48
49namespace MoFEM {
50
51/** \name Get values at Gauss pts */
52
53/**@{*/
54
55/** \name Scalar values */
56
57/**@{*/
58
59/** \brief Scalar field values at integration points
60 *
61 */
62
63/**
64 * @brief Operator for calculating scalar field values at integration points
65 *
66 * This template structure calculates scalar field values at integration points
67 * and stores them in a provided data container. It supports different storage
68 * types through template parameters and can optionally work with PETSc vectors.
69 *
70 * @tparam T Data type for the scalar field values (e.g., double, float)
71 * @tparam A Allocator type for the ublas vector storage
72 */
73template <class T, class A>
76
77 /**
78 * @brief Constructor with PETSc vector support
79 *
80 * @param field_name Name of the scalar field to calculate values for
81 * @param data_ptr Shared pointer to ublas vector for storing calculated values
82 * @param data_vec Smart PETSc vector object for additional data storage
83 * @param zero_type Entity type for zero-level entities (default: MBVERTEX)
84 */
87 const std::string field_name,
88 boost::shared_ptr<ublas::vector<T, A>> data_ptr,
89 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX)
91 dataPtr(data_ptr), zeroType(zero_type), dataVec(data_vec) {
92 if (!dataPtr)
93 THROW_MESSAGE("Pointer is not set");
94 }
95
96 /**
97 * @brief Constructor with PETSc vector support for a different problem
98 * layout
99 *
100 * The finite-element data local indices belong to the problem driving the
101 * current loop. When @p data_vec belongs to another DM, @p data_dm maps
102 * field DOFs by their unique IDs to that vector's local indices. @p op_type
103 * selects row or column numbering in @p data_dm.
104 */
106 SmartPetscObj<DM> data_dm,
108 const std::string field_name,
109 boost::shared_ptr<ublas::vector<T, A>> data_ptr,
110 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX)
112 dataPtr(data_ptr), zeroType(zero_type), dataVec(data_vec),
113 dataDm(data_dm) {
116 THROW_MESSAGE("Cross-DM field evaluation requires OPROW or OPCOL");
117 if (!dataPtr)
118 THROW_MESSAGE("Pointer is not set");
119 }
120
122 const std::string field_name,
123 boost::shared_ptr<ublas::vector<T, A>> data_ptr,
124 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX)
127 data_vec, zero_type) {}
128
129 /**
130 * @brief Constructor for scalar field values calculation operator
131 *
132 * @param field_name Name of the scalar field to calculate values for
133 * @param data_ptr Shared pointer to ublas vector for storing calculated values
134 * @param zero_type Entity type for zero-level entities (default: MBVERTEX)
135 */
137 const std::string field_name,
138 boost::shared_ptr<ublas::vector<T, A>> data_ptr,
139 const EntityType zero_type = MBVERTEX)
142 SmartPetscObj<Vec>(), zero_type) {}
143
144 /**
145 * \brief calculate values of scalar field at integration points
146 * @param side side entity number
147 * @param type side entity type
148 * @param data entity data
149 * @return error code
150 */
151 MoFEMErrorCode doWork(int side, EntityType type,
153
154protected:
155 boost::shared_ptr<ublas::vector<T, A>> dataPtr;
156 const EntityHandle zeroType;
160};
161
162/**
163 * \brief Specialization of member function
164 *
165 */
166template <class T, class A>
168 int side, EntityType type, EntitiesFieldData::EntData &data) {
170 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "Not implemented for T = %s",
171 typeid(T).name() // boost::core::demangle(typeid(T).name()).c_str()
172 );
174}
175
176/**
177 * @brief Specialization for double precision scalar field values calculation
178 *
179 * This structure is a specialization of OpCalculateScalarFieldValues_General
180 * for double precision scalar fields using DoubleAllocator. It provides
181 * concrete implementation for calculating scalar field values at integration
182 * points and storing them in double precision format.
183 *
184 * @ingroup mofem_forces_and_sources_user_data_operators
185 */
187 : public OpCalculateScalarFieldValues_General<double, DoubleAllocator> {
188
190 double, DoubleAllocator>::OpCalculateScalarFieldValues_General;
191
192 /**
193 * \brief calculate values of scalar field at integration points
194 * @param side side entity number
195 * @param type side entity type
196 * @param data entity data
197 * @return error code
198 */
199 MoFEMErrorCode doWork(int, EntityType type,
202 VectorDouble &vec = *dataPtr;
203 const size_t nb_gauss_pts = getGaussPts().size2();
204 if (type == zeroType || vec.size() != nb_gauss_pts) {
205 vec.resize(nb_gauss_pts, false);
206 vec.clear();
207 }
208
209 const size_t nb_dofs = data.getFieldData().size();
210
211 if (nb_dofs) {
212
213 if (dataVec.use_count()) {
214 dotVector.resize(nb_dofs, false);
215 const double *array;
216 CHKERR VecGetArrayRead(dataVec, &array);
217 if (dataDm) {
218 const Problem *problem_ptr;
219 CHKERR DMMoFEMGetProblemPtr(dataDm, &problem_ptr);
220 const NumeredDofEntityByUId *dofs_by_uid;
221 switch (getOpType()) {
223 dofs_by_uid =
224 &problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>();
225 break;
227 dofs_by_uid =
228 &problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>();
229 break;
230 default:
231 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
232 "Cross-DM field evaluation requires OPROW or OPCOL");
233 }
234 const auto &field_dofs = data.getFieldDofs();
235 for (size_t i = 0; i != field_dofs.size(); ++i) {
236 const auto dof_it =
237 dofs_by_uid->find(field_dofs[i]->getLocalUniqueId());
238 dotVector[i] =
239 (dof_it != dofs_by_uid->end())
240 ? array[(*dof_it)->getPetscLocalDofIdx()]
241 : 0;
242 }
243 } else {
244 const auto &local_indices = data.getLocalIndices();
245 for (size_t i = 0; i != local_indices.size(); ++i)
246 if (local_indices[i] != -1)
247 dotVector[i] = array[local_indices[i]];
248 else
249 dotVector[i] = 0;
250 }
251 CHKERR VecRestoreArrayRead(dataVec, &array);
252 data.getFieldData().swap(dotVector);
253 }
254
255 const size_t nb_base_functions = data.getN().size2();
256 auto base_function = data.getFTensor0N();
257 auto values_at_gauss_pts = getFTensor0FromVec(vec);
258 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
259 auto field_data = data.getFTensor0FieldData();
260 size_t bb = 0;
261 for (; bb != nb_dofs; ++bb) {
262 values_at_gauss_pts += field_data * base_function;
263 ++field_data;
264 ++base_function;
265 }
266 // It is possible to have more base functions than dofs
267 for (; bb < nb_base_functions; ++bb)
268 ++base_function;
269 ++values_at_gauss_pts;
270 }
271
272 if (dataVec.use_count()) {
273 data.getFieldData().swap(dotVector);
274 }
275 }
276
278 }
279};
280
281/**
282 * @brief Calculate scalar field values from PETSc vector at integration points
283 *
284 * This template structure extracts scalar field values from a PETSc vector
285 * and calculates them at integration points. It supports different data contexts
286 * through the template parameter and can handle various entity types.
287 *
288 * @tparam CTX PETSc data context type specifying how data is accessed
289 *
290 * @ingroup mofem_forces_and_sources_user_data_operators
291 */
292template <PetscData::DataContext CTX>
295
296 /**
297 * @brief Constructor for PETSc vector-based scalar field calculation
298 *
299 * @param field_name Name of the scalar field to extract values from
300 * @param data_ptr Shared pointer to VectorDouble for storing calculated values
301 * @param zero_at_type Entity type where values should be zeroed (default: MBVERTEX)
302 */
304 const std::string field_name, boost::shared_ptr<VectorDouble> data_ptr,
305 const EntityType zero_at_type = MBVERTEX)
308 dataPtr(data_ptr), zeroAtType(zero_at_type) {
309 if (!dataPtr)
310 THROW_MESSAGE("Pointer is not set");
311 }
312
313 MoFEMErrorCode doWork(int side, EntityType type,
316
317 const size_t nb_gauss_pts = getGaussPts().size2();
318
319 VectorDouble &vec = *dataPtr;
320 if (type == zeroAtType || vec.size() != nb_gauss_pts) {
321 vec.resize(nb_gauss_pts, false);
322 vec.clear();
323 }
324
325 auto &local_indices = data.getLocalIndices();
326 const size_t nb_dofs = local_indices.size();
327 if (nb_dofs) {
328
329 const double *array;
330
331 auto get_array = [&](const auto ctx, auto vec) {
333 #ifndef NDEBUG
334 if ((getFEMethod()->data_ctx & ctx).none()) {
335 MOFEM_LOG_CHANNEL("SELF");
336 MOFEM_LOG("SELF", Sev::error)
337 << "In this case field degrees of freedom are read from vector. "
338 "That usually happens when time solver is used, and acces to "
339 "first or second rates is needed. You probably not set ts_u, "
340 "ts_u_t, or ts_u_tt and associated data structure, i.e. "
341 "data_ctx to CTX_SET_X, CTX_SET_X_T, or CTX_SET_X_TT "
342 "respectively";
343 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set!");
344 }
345 #endif
346 CHKERR VecGetArrayRead(vec, &array);
348 };
349
350 auto restore_array = [&](auto vec) {
351 return VecRestoreArrayRead(vec, &array);
352 };
353
354 switch (CTX) {
356 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->ts_u);
357 break;
359 CHKERR get_array(PetscData::CtxSetX_T, getFEMethod()->ts_u_t);
360 break;
362 CHKERR get_array(PetscData::CtxSetX_TT, getFEMethod()->ts_u_tt);
363 break;
364 default:
365 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
366 "That case is not implemented");
367 }
368
369 std::array<double, MAX_DOFS_ON_ENTITY> dot_dofs_vector;
370 for (int i = 0; i != local_indices.size(); ++i)
371 if (local_indices[i] != -1)
372 dot_dofs_vector[i] = array[local_indices[i]];
373 else
374 dot_dofs_vector[i] = 0;
375
376 switch (CTX) {
378 CHKERR restore_array(getFEMethod()->ts_u);
379 break;
381 CHKERR restore_array(getFEMethod()->ts_u_t);
382 break;
384 CHKERR restore_array(getFEMethod()->ts_u_tt);
385 break;
386 default:
387 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
388 "That case is not implemented");
389 }
390
391 const size_t nb_base_functions = data.getN().size2();
392 auto base_function = data.getFTensor0N();
393 auto values_at_gauss_pts = getFTensor0FromVec(vec);
394
395 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
396 size_t bb = 0;
397 for (; bb != nb_dofs; ++bb) {
398 values_at_gauss_pts += dot_dofs_vector[bb] * base_function;
399 ++base_function;
400 }
401 // Number of dofs can be smaller than number of Tensor_Dim x base
402 // functions
403 for (; bb < nb_base_functions; ++bb)
404 ++base_function;
405 ++values_at_gauss_pts;
406 }
407 }
409 }
410
411private:
412 boost::shared_ptr<VectorDouble> dataPtr;
413 const EntityHandle zeroAtType;
414};
415
420
421/**
422 * \deprecated Name inconsistent with other operators
423 *
424 */
426
427/**@}*/
428
429/** \name Vector field values at integration points */
430
431/**@{*/
432
433/**
434 * @brief Calculate field values for tensor field rank 1, i.e. vector field
435 *
436 * This template structure calculates vector field values at integration points
437 * and stores them in a matrix container. It supports various tensor dimensions,
438 * matrix storage types through template parameters.
439 *
440 * @tparam Tensor_Dim Dimension of the vector field (e.g., 2 for 2D, 3 for 3D)
441 * @tparam M Matrix storage type for the field values
442 */
443template <int Tensor_Dim, typename M = MatrixDouble>
446
447 /**
448 * @brief Constructor for vector field values calculation operator
449 *
450 * @param field_name Name of the vector field to calculate values for
451 * @param data_ptr Shared pointer to ublas matrix for storing calculated values
452 * @param zero_type Entity type for zero-level entities (default: MBVERTEX)
453 */
455 const std::string field_name,
456 boost::shared_ptr<M> data_ptr,
457 const EntityType zero_type = MBVERTEX)
460 dataPtr(data_ptr), zeroType(zero_type) {
461 if (!dataPtr)
462 THROW_MESSAGE("Pointer is not set");
463 }
464
465 /**
466 * \brief calculate values of vector field at integration points
467 * @param side side entity number
468 * @param type side entity type
469 * @param data entity data
470 * @return error code
471 */
472 MoFEMErrorCode doWork(int side, EntityType type,
474
475protected:
476 boost::shared_ptr<M> dataPtr;
477 const EntityHandle zeroType;
478};
479
480template <int Tensor_Dim, typename M>
483 int side, EntityType type, EntitiesFieldData::EntData &data) {
485 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
486 "Not implemented for matrix type = %s and dim = %d",
487 typeid(M).name(), // boost::core::demangle(typeid(M).name()),
488 Tensor_Dim);
490}
491
492/** \brief Calculate field values (template specialization) for tensor field
493 * rank 1, i.e. vector field
494 *
495 */
496template <int Tensor_Dim>
499
501 boost::shared_ptr<MatrixDouble> data_ptr,
502 const EntityType zero_type = MBVERTEX,
503 const int max_order = -1)
506 dataPtr(data_ptr), zeroType(zero_type), maxOrder(max_order) {
507 if (!dataPtr)
508 THROW_MESSAGE("Pointer is not set");
509 }
510
512 boost::shared_ptr<MatrixDouble> data_ptr,
513 SmartPetscObj<Vec> data_vec,
514 const EntityType zero_type = MBVERTEX,
515 const int max_order = -1)
518 dataPtr(data_ptr), dataVec(data_vec), zeroType(zero_type),
519 maxOrder(max_order) {
520 if (!dataPtr)
521 THROW_MESSAGE("Pointer is not set");
522 }
523
525 SmartPetscObj<DM> data_dm,
527 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
528 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX,
529 const int max_order = -1)
531 dataPtr(data_ptr), dataVec(data_vec), dataDm(data_dm),
532 zeroType(zero_type), maxOrder(max_order) {
535 THROW_MESSAGE("Cross-DM field evaluation requires OPROW or OPCOL");
536 if (!dataPtr)
537 THROW_MESSAGE("Pointer is not set");
538 }
539
540 MoFEMErrorCode doWork(int side, EntityType type,
542
543protected:
544 boost::shared_ptr<MatrixDouble> dataPtr;
547 const EntityHandle zeroType;
549 int maxOrder = -1;
550};
551
552/**
553 * \brief Member function specialization calculating values for tenor field rank
554 *
555 */
556template <int Tensor_Dim>
558 Tensor_Dim, MatrixDouble>::doWork(int, EntityType type,
561
562 const size_t nb_gauss_pts = getGaussPts().size2();
563 auto &mat = *dataPtr;
564
566 auto get_values_at_gauss_pts =
567 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim, -1, DL>, DL>::size(
568 mat, nb_gauss_pts);
569 if (type == zeroType) {
570 mat.clear();
571 }
572
573 const size_t nb_dofs = data.getFieldData().size();
574 if (nb_dofs) {
575
576 auto max_order =
577 (maxOrder == -1) ? MAX_DOFS_ON_ENTITY : maxOrder;
578 const auto max_size =
579 (type == MBVERTEX) ? MAX_DOFS_ON_ENTITY
580 : data.getFieldDofs()[0]->getOrderNbDofs(max_order);
581
582 if (dataVec.use_count()) {
583 dotVector.resize(nb_dofs, false);
584 const double *array;
585 CHKERR VecGetArrayRead(dataVec, &array);
586 if (dataDm) {
587 const Problem *problem_ptr;
588 CHKERR DMMoFEMGetProblemPtr(dataDm, &problem_ptr);
589 const NumeredDofEntityByUId *dofs_by_uid;
590 switch (getOpType()) {
592 dofs_by_uid = &problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>();
593 break;
595 dofs_by_uid = &problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>();
596 break;
597 default:
598 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
599 "Cross-DM field evaluation requires OPROW or OPCOL");
600 }
601 const auto &field_dofs = data.getFieldDofs();
602 for (size_t i = 0; i != field_dofs.size(); ++i) {
603 const auto dof_it =
604 dofs_by_uid->find(field_dofs[i]->getLocalUniqueId());
605 dotVector[i] = (dof_it != dofs_by_uid->end())
606 ? array[(*dof_it)->getPetscLocalDofIdx()]
607 : 0;
608 }
609 } else {
610 const auto &local_indices = data.getLocalIndices();
611 for (size_t i = 0; i != local_indices.size(); ++i)
612 if (local_indices[i] != -1)
613 dotVector[i] = array[local_indices[i]];
614 else
615 dotVector[i] = 0;
616 }
617 CHKERR VecRestoreArrayRead(dataVec, &array);
618 data.getFieldData().swap(dotVector);
619 }
620
621 if (nb_gauss_pts) {
622 const size_t nb_base_functions = data.getN().size2();
623 auto base_function = data.getFTensor0N();
624 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
625 FTensor::Index<'I', Tensor_Dim> I;
626 const size_t size = nb_dofs / Tensor_Dim;
627 if (nb_dofs % Tensor_Dim) {
628 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
629 "Nb. of DOFs is inconsistent with Tensor_Dim");
630 }
631 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
632 auto field_data = data.getFTensor1FieldData<Tensor_Dim>();
633
634 #ifndef NDEBUG
635 if (field_data.l2() != field_data.l2()) {
636 MOFEM_LOG("SELF", Sev::error) << "field data: " << field_data;
637 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
638 "Wrong number in coefficients");
639 }
640 #endif
641
642 size_t bb = 0;
643 for (; bb != size; ++bb) {
644
645 #ifndef SINGULARITY
646 #ifndef NDEBUG
647 if (base_function != base_function) {
648 MOFEM_LOG("SELF", Sev::error) << "base function: " << base_function;
649 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
650 "Wrong number number in base functions");
651 }
652 #endif
653 #endif
654
655 if (bb <= max_size) {
656 t_values_at_gauss_pts(I) += field_data(I) * base_function;
657 }
658 ++field_data;
659 ++base_function;
660 }
661 // Number of dofs can be smaller than number of Tensor_Dim x base
662 // functions
663 for (; bb < nb_base_functions; ++bb)
664 ++base_function;
665 ++t_values_at_gauss_pts;
666 }
667 }
668
669 if (dataVec.use_count()) {
670 data.getFieldData().swap(dotVector);
671 }
672 }
674}
675
676/**
677 * @brief Specialization for MatrixDouble vector field values calculation
678 *
679 * This structure is a specialization of OpCalculateVectorFieldValues_General
680 * for vector fields stored in MatrixDouble. It provides a convenient interface
681 * for calculating vector field values at integration points.
682 *
683 * @tparam Tensor_Dim Dimension of the vector field (e.g., 2 for 2D, 3 for 3D)
684 *
685 * @ingroup mofem_forces_and_sources_user_data_operators
686 */
687template <int Tensor_Dim>
689 : public OpCalculateVectorFieldValues_General<Tensor_Dim> {
690
692 Tensor_Dim>::OpCalculateVectorFieldValues_General;
693};
694
695/**@}*/
696
697/** \name Vector field values at integration points */
698
699/**@{*/
700
701/**
702 * @brief Calculate divergence of vector field at integration points
703 *
704 * This template structure calculates the divergence of a vector field at
705 * integration points. It supports different coordinate systems and tensor
706 * dimensions, making it suitable for various physical applications.
707 *
708 * @tparam Tensor_Dim Dimension of the vector field (e.g., 2 for 2D, 3 for 3D)
709 * @tparam COORDINATE_SYSTEM Coordinate system type (default: CARTESIAN)
710 */
711template <int Tensor_Dim, CoordinateTypes COORDINATE_SYSTEM = CARTESIAN>
714
715 /**
716 * @brief Constructor for vector field divergence calculation operator
717 *
718 * @param field_name Name of the vector field to calculate divergence for
719 * @param data_ptr Shared pointer to VectorDouble for storing calculated divergence values
720 * @param zero_type Entity type for zero-level entities (default: MBVERTEX)
721 */
723 const std::string field_name, boost::shared_ptr<VectorDouble> data_ptr,
724 const EntityType zero_type = MBVERTEX)
727 dataPtr(data_ptr), zeroType(zero_type) {
728 if (!dataPtr)
729 THROW_MESSAGE("Pointer is not set");
730 }
731
732 MoFEMErrorCode doWork(int side, EntityType type,
735
736 // When we move to C++17 add if constexpr()
737 if constexpr (COORDINATE_SYSTEM == POLAR || COORDINATE_SYSTEM == SPHERICAL)
738 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
739 "%s coordiante not implemented",
740 CoordinateTypesNames[COORDINATE_SYSTEM]);
741
742 const size_t nb_gauss_pts = getGaussPts().size2();
743 auto &vec = *dataPtr;
744 if (type == zeroType) {
745 vec.resize(nb_gauss_pts, false);
746 vec.clear();
747 }
748
749 const size_t nb_dofs = data.getFieldData().size();
750 if (nb_dofs) {
751
752 if (nb_gauss_pts) {
753 const size_t nb_base_functions = data.getN().size2();
754 auto values_at_gauss_pts = getFTensor0FromVec(vec);
755 FTensor::Index<'I', Tensor_Dim> I;
756 const size_t size = nb_dofs / Tensor_Dim;
757 #ifndef NDEBUG
758 if (nb_dofs % Tensor_Dim) {
759 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
760 "Number of dofs should multiple of dimensions");
761 }
762 #endif
763
764 // When we move to C++17 add if constexpr()
765 if constexpr (COORDINATE_SYSTEM == CARTESIAN) {
766 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim>();
767 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
768 auto field_data = data.getFTensor1FieldData<Tensor_Dim>();
769 size_t bb = 0;
770 for (; bb != size; ++bb) {
771 values_at_gauss_pts += field_data(I) * diff_base_function(I);
772 ++field_data;
773 ++diff_base_function;
774 }
775 // Number of dofs can be smaller than number of Tensor_Dim x base
776 // functions
777 for (; bb < nb_base_functions; ++bb)
778 ++diff_base_function;
779 ++values_at_gauss_pts;
780 }
781 }
782
783 // When we move to C++17 add if constexpr()
784 if constexpr (COORDINATE_SYSTEM == CYLINDRICAL) {
785 auto t_coords = getFTensor1CoordsAtGaussPts();
786 auto values_at_gauss_pts = getFTensor0FromVec(vec);
787 auto base_function = data.getFTensor0N();
788 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim>();
789 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
790 auto field_data = data.getFTensor1FieldData<Tensor_Dim>();
791 size_t bb = 0;
792 for (; bb != size; ++bb) {
793 values_at_gauss_pts += field_data(I) * diff_base_function(I);
794 values_at_gauss_pts +=
795 base_function * (field_data(0) / t_coords(0));
796 ++field_data;
797 ++base_function;
798 ++diff_base_function;
799 }
800 // Number of dofs can be smaller than number of Tensor_Dim x base
801 // functions
802 for (; bb < nb_base_functions; ++bb) {
803 ++base_function;
804 ++diff_base_function;
805 }
806 ++values_at_gauss_pts;
807 ++t_coords;
808 }
809 }
810 }
811 }
813 }
814
815protected:
816 boost::shared_ptr<VectorDouble> dataPtr;
817 const EntityHandle zeroType;
818};
819
820/** \brief Approximate field values for given petsc vector
821 *
822 * \note Look at PetscData to see what vectors could be extracted with that user
823 * data operator.
824 *
825 * \ingroup mofem_forces_and_sources_user_data_operators
826 */
827template <int Tensor_Dim, PetscData::DataContext CTX>
830
832 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
833 const EntityType zero_at_type = MBVERTEX, bool throw_error = true)
836 dataPtr(data_ptr), zeroAtType(zero_at_type), throwError(throw_error) {
837 if (!dataPtr)
838 THROW_MESSAGE("Pointer is not set");
839 }
840
841 MoFEMErrorCode doWork(int side, EntityType type,
844
845 auto &local_indices = data.getLocalIndices();
846 const size_t nb_dofs = local_indices.size();
847 const size_t nb_gauss_pts = getGaussPts().size2();
848
849 MatrixDouble &mat = *dataPtr;
851 auto get_values_at_gauss_pts =
852 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim, -1, DL>,
853 DL>::size(mat, nb_gauss_pts);
854 if (type == zeroAtType) {
855 mat.clear();
856 }
857 if (!nb_dofs)
859
860 if (!throwError) {
861 if ((getFEMethod()->data_ctx & PetscData::Switches(CTX)).none()) {
863 }
864 }
865
866 const double *array;
867
868 auto get_array = [&](const auto ctx, auto vec) {
870 #ifndef NDEBUG
871 if ((getFEMethod()->data_ctx & ctx).none()) {
872 MOFEM_LOG_CHANNEL("SELF");
873 MOFEM_LOG("SELF", Sev::error)
874 << "In this case field degrees of freedom are read from vector. "
875 "That usually happens when time solver is used, and access to "
876 "first or second rates is needed. You probably not set ts_u, "
877 "ts_u_t, or ts_u_tt and associated data structure, i.e. "
878 "data_ctx to CTX_SET_X, CTX_SET_DX, CTX_SET_X_T, or "
879 "CTX_SET_X_TT respectively";
880 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set");
881 }
882 #endif
883 CHKERR VecGetArrayRead(vec, &array);
885 };
886
887 auto restore_array = [&](auto vec) {
888 return VecRestoreArrayRead(vec, &array);
889 };
890
891 switch (CTX) {
893 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->ts_u);
894 break;
896 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->dx);
897 break;
899 CHKERR get_array(PetscData::CtxSetX_T, getFEMethod()->ts_u_t);
900 break;
902 CHKERR get_array(PetscData::CtxSetX_TT, getFEMethod()->ts_u_tt);
903 break;
904 default:
905 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
906 "That case is not implemented");
907 }
908
909 dotVector.resize(local_indices.size());
910 for (int i = 0; i != local_indices.size(); ++i)
911 if (local_indices[i] != -1)
912 dotVector[i] = array[local_indices[i]];
913 else
914 dotVector[i] = 0;
915
916 switch (CTX) {
918 CHKERR restore_array(getFEMethod()->ts_u);
919 break;
921 CHKERR restore_array(getFEMethod()->dx);
922 break;
924 CHKERR restore_array(getFEMethod()->ts_u_t);
925 break;
927 CHKERR restore_array(getFEMethod()->ts_u_tt);
928 break;
929 default:
930 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
931 "That case is not implemented");
932 }
933
934 const size_t nb_base_functions = data.getN().size2();
935 auto base_function = data.getFTensor0N();
936 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
937
938 FTensor::Index<'I', Tensor_Dim> I;
939 const size_t size = nb_dofs / Tensor_Dim;
940 if (nb_dofs % Tensor_Dim) {
941 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Data inconsistency");
942 }
943 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
944 auto field_data = getFTensor1FromArray<Tensor_Dim, Tensor_Dim>(dotVector);
945 size_t bb = 0;
946 for (; bb != size; ++bb) {
947 t_values_at_gauss_pts(I) += field_data(I) * base_function;
948 ++field_data;
949 ++base_function;
950 }
951 // Number of dofs can be smaller than number of Tensor_Dim x base
952 // functions
953 for (; bb < nb_base_functions; ++bb)
954 ++base_function;
955 ++t_values_at_gauss_pts;
956 }
958 }
959
960protected:
961 boost::shared_ptr<MatrixDouble> dataPtr;
962 const EntityHandle zeroAtType;
965};
966
967/** \brief Get rate of values at integration pts for tensor field
968 * rank 1, i.e. vector field
969 *
970 * \ingroup mofem_forces_and_sources_user_data_operators
971 */
972template <int Tensor_Dim>
976
977/** \brief Get second rate of values at integration pts for tensor
978 * field rank 1, i.e. vector field
979 *
980 * \ingroup mofem_forces_and_sources_user_data_operators
981 */
982template <int Tensor_Dim>
986
987/** \brief Get second time second update vector at integration pts for tensor
988 * field rank 1, i.e. vector field
989 *
990 * \ingroup mofem_forces_and_sources_user_data_operators
991 */
992template <int Tensor_Dim>
996
997/**@}*/
998
999/** \name Tensor field values at integration points */
1000
1001/**@{*/
1002
1003/** \brief Calculate field values for tenor field rank 2.
1004 *
1005 */
1006template <int Tensor_Dim0, int Tensor_Dim1, typename M = MatrixDouble>
1009
1011 const std::string field_name,
1012 boost::shared_ptr<M> data_ptr,
1013 const EntityType zero_type = MBVERTEX)
1016 dataPtr(data_ptr), zeroType(zero_type) {
1017 if (!dataPtr)
1018 THROW_MESSAGE("Pointer is not set");
1019 }
1020
1021 MoFEMErrorCode doWork(int side, EntityType type,
1023
1024protected:
1025 boost::shared_ptr<M> dataPtr;
1026 const EntityHandle zeroType;
1027};
1028
1029template <int Tensor_Dim0, int Tensor_Dim1, typename M>
1032 doWork(int side, EntityType type, EntitiesFieldData::EntData &data) {
1034 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1035 "Not implemented for matrix type = %s, dim0 = %d and dim1 = %d",
1036 typeid(M).name(), // boost::core::demangle(typeid(M).name()),
1037 Tensor_Dim0, Tensor_Dim1);
1039}
1040
1041template <int Tensor_Dim0, int Tensor_Dim1>
1042struct OpCalculateTensor2FieldValues_General<Tensor_Dim0, Tensor_Dim1,
1045
1048 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1049 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX)
1051 dataPtr(data_ptr), zeroType(zero_type), dataVec(data_vec) {
1052 if (!dataPtr)
1053 THROW_MESSAGE("Pointer is not set");
1054 }
1055
1057 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1058 const EntityType zero_type = MBVERTEX)
1061 SmartPetscObj<Vec>(), zero_type) {}
1062
1064 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1065 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBVERTEX)
1068 data_vec, zero_type) {}
1069
1070 MoFEMErrorCode doWork(int side, EntityType type,
1072
1073protected:
1074 boost::shared_ptr<MatrixDouble> dataPtr;
1075 const EntityHandle zeroType;
1078};
1079
1080template <int Tensor_Dim0, int Tensor_Dim1>
1082 Tensor_Dim0, Tensor_Dim1, MatrixDouble>::doWork(
1083 int side, EntityType type, EntitiesFieldData::EntData &data) {
1085
1087 MatrixDouble &mat = *dataPtr;
1088 const size_t nb_gauss_pts = data.getN().size1();
1089 auto get_values_at_gauss_pts =
1090 MatrixSizeHelper<GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
1091 DL>::size(mat, nb_gauss_pts);
1092 if (type == zeroType)
1093 mat.clear();
1094
1095 const size_t nb_dofs = data.getFieldData().size();
1096
1097 if (dataVec.use_count()) {
1098 dotVector.resize(nb_dofs, false);
1099 const double *array;
1100 CHKERR VecGetArrayRead(dataVec, &array);
1101 const auto &local_indices = data.getLocalIndices();
1102 for (int i = 0; i != local_indices.size(); ++i)
1103 if (local_indices[i] != -1)
1104 dotVector[i] = array[local_indices[i]];
1105 else
1106 dotVector[i] = 0;
1107 CHKERR VecRestoreArrayRead(dataVec, &array);
1108 data.getFieldData().swap(dotVector);
1109 }
1110
1111 if (nb_dofs) {
1112 const size_t nb_base_functions = data.getN().size2();
1113 auto base_function = data.getFTensor0N();
1114 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
1115 FTensor::Index<'i', Tensor_Dim0> i;
1116 FTensor::Index<'j', Tensor_Dim1> j;
1117 const size_t size = nb_dofs / (Tensor_Dim0 * Tensor_Dim1);
1118 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
1119 auto field_data = data.getFTensor2FieldData<Tensor_Dim0, Tensor_Dim1>();
1120 size_t bb = 0;
1121 for (; bb != size; ++bb) {
1122 t_values_at_gauss_pts(i, j) += field_data(i, j) * base_function;
1123 ++field_data;
1124 ++base_function;
1125 }
1126 for (; bb < nb_base_functions; ++bb)
1127 ++base_function;
1128 ++t_values_at_gauss_pts;
1129 }
1130
1131 if (dataVec.use_count()) {
1132 data.getFieldData().swap(dotVector);
1133 }
1134 }
1136}
1137
1138/** \brief Get values at integration pts for tensor field rank 2, i.e. matrix
1139 * field
1140 *
1141 * \ingroup mofem_forces_and_sources_user_data_operators
1142 */
1143template <int Tensor_Dim0, int Tensor_Dim1>
1145 : public OpCalculateTensor2FieldValues_General<Tensor_Dim0,
1146 Tensor_Dim1> {
1147
1149 Tensor_Dim0, Tensor_Dim1>::OpCalculateTensor2FieldValues_General;
1150};
1151
1152/** \brief Get time direvarive values at integration pts for tensor field rank
1153 * 2, i.e. matrix field
1154 *
1155 * \ingroup mofem_forces_and_sources_user_data_operators
1156 */
1157template <int Tensor_Dim0, int Tensor_Dim1>
1160
1162 boost::shared_ptr<MatrixDouble> data_ptr,
1163 const EntityType zero_at_type = MBVERTEX)
1166 dataPtr(data_ptr), zeroAtType(zero_at_type) {
1167 if (!dataPtr)
1168 THROW_MESSAGE("Pointer is not set");
1169 }
1170
1171 MoFEMErrorCode doWork(int side, EntityType type,
1174
1176 const size_t nb_gauss_pts = getGaussPts().size2();
1177 MatrixDouble &mat = *dataPtr;
1178 auto get_values_at_gauss_pts =
1180 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
1181 DL>::size(mat, nb_gauss_pts);
1182 if (type == zeroAtType)
1183 mat.clear();
1184 const auto &local_indices = data.getLocalIndices();
1185 const size_t nb_dofs = local_indices.size();
1186 if (nb_dofs) {
1187 dotVector.resize(nb_dofs, false);
1188 const double *array;
1189 CHKERR VecGetArrayRead(getFEMethod()->ts_u_t, &array);
1190 for (size_t i = 0; i != local_indices.size(); ++i)
1191 if (local_indices[i] != -1)
1192 dotVector[i] = array[local_indices[i]];
1193 else
1194 dotVector[i] = 0;
1195 CHKERR VecRestoreArrayRead(getFEMethod()->ts_u_t, &array);
1196
1197 const size_t nb_base_functions = data.getN().size2();
1198
1199 auto base_function = data.getFTensor0N();
1200 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
1201 FTensor::Index<'i', Tensor_Dim0> i;
1202 FTensor::Index<'j', Tensor_Dim1> j;
1203 const size_t size = nb_dofs / (Tensor_Dim0 * Tensor_Dim1);
1204 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
1205 auto field_data =
1206 getFTensor2FromPtr<Tensor_Dim0, Tensor_Dim1>(&*dotVector.begin());
1207 size_t bb = 0;
1208 for (; bb != size; ++bb) {
1209 t_values_at_gauss_pts(i, j) += field_data(i, j) * base_function;
1210 ++field_data;
1211 ++base_function;
1212 }
1213 for (; bb < nb_base_functions; ++bb)
1214 ++base_function;
1215 ++t_values_at_gauss_pts;
1216 }
1217 }
1219 }
1220
1221protected:
1222 boost::shared_ptr<MatrixDouble> dataPtr; ///< Data computed into this matrix
1223 EntityType zeroAtType; ///< Zero values at Gauss point at this type
1224 VectorDouble dotVector; ///< Keeps temporary values of time derivatives
1225};
1226
1227/**
1228 * @brief Calculate symmetric tensor field values at integration pts.
1229 *
1230 * @tparam Tensor_Dim
1231
1232 * \ingroup mofem_forces_and_sources_user_data_operators
1233 */
1234template <int Tensor_Dim>
1237
1239 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1240 const EntityType zero_type = MBEDGE, const int zero_side = 0)
1243 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
1244 if (!dataPtr)
1245 THROW_MESSAGE("Pointer is not set");
1246 }
1247
1249 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1250 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBEDGE,
1251 const int zero_side = 0)
1254 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side),
1255 dataVec(data_vec) {
1256 if (!dataPtr)
1257 THROW_MESSAGE("Pointer is not set");
1258 }
1259
1261 SmartPetscObj<DM> data_dm,
1263 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1264 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBEDGE,
1265 const int zero_side = 0)
1267 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side),
1268 dataVec(data_vec), dataDm(data_dm) {
1271 THROW_MESSAGE("Cross-DM field evaluation requires OPROW or OPCOL");
1272 if (!dataPtr)
1273 THROW_MESSAGE("Pointer is not set");
1274 }
1275
1276 MoFEMErrorCode doWork(int side, EntityType type,
1279 MatrixDouble &mat = *dataPtr;
1280 const int nb_gauss_pts = getGaussPts().size2();
1282 auto get_values_at_gauss_pts =
1284 DL>::size(mat, nb_gauss_pts);
1285 if (type == this->zeroType && side == zeroSide) {
1286 mat.clear();
1287 }
1288 const int nb_dofs = data.getFieldData().size();
1289 if (!nb_dofs)
1291
1292 if (dataVec.use_count()) {
1293 dotVector.resize(nb_dofs, false);
1294 const double *array;
1295 CHKERR VecGetArrayRead(dataVec, &array);
1296 if (dataDm) {
1297 const Problem *problem_ptr;
1298 CHKERR DMMoFEMGetProblemPtr(dataDm, &problem_ptr);
1299 const NumeredDofEntityByUId *dofs_by_uid;
1300 switch (getOpType()) {
1302 dofs_by_uid = &problem_ptr->numeredRowDofsPtr->get<Unique_mi_tag>();
1303 break;
1305 dofs_by_uid = &problem_ptr->numeredColDofsPtr->get<Unique_mi_tag>();
1306 break;
1307 default:
1308 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1309 "Cross-DM field evaluation requires OPROW or OPCOL");
1310 }
1311 const auto &field_dofs = data.getFieldDofs();
1312 for (int i = 0; i != field_dofs.size(); ++i) {
1313 const auto dof_it =
1314 dofs_by_uid->find(field_dofs[i]->getLocalUniqueId());
1315 dotVector[i] = (dof_it != dofs_by_uid->end())
1316 ? array[(*dof_it)->getPetscLocalDofIdx()]
1317 : 0;
1318 }
1319 } else {
1320 const auto &local_indices = data.getLocalIndices();
1321 for (int i = 0; i != local_indices.size(); ++i)
1322 if (local_indices[i] != -1)
1323 dotVector[i] = array[local_indices[i]];
1324 else
1325 dotVector[i] = 0;
1326 }
1327 CHKERR VecRestoreArrayRead(dataVec, &array);
1328 data.getFieldData().swap(dotVector);
1329 }
1330
1331 const int nb_base_functions = data.getN().size2();
1332 auto base_function = data.getFTensor0N();
1333 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
1334 FTensor::Index<'i', Tensor_Dim> i;
1335 FTensor::Index<'j', Tensor_Dim> j;
1336 const int size = nb_dofs / ((Tensor_Dim * (Tensor_Dim + 1)) / 2);
1337 for (int gg = 0; gg != nb_gauss_pts; ++gg) {
1338 auto field_data = data.getFTensor2SymmetricFieldData<Tensor_Dim>();
1339 int bb = 0;
1340 for (; bb != size; ++bb) {
1341 t_values_at_gauss_pts(i, j) += field_data(i, j) * base_function;
1342 ++field_data;
1343 ++base_function;
1344 }
1345 for (; bb < nb_base_functions; ++bb)
1346 ++base_function;
1347 ++t_values_at_gauss_pts;
1348 }
1349
1350 if (dataVec.use_count()) {
1351 data.getFieldData().swap(dotVector);
1352 }
1353
1355 }
1356
1357protected:
1358 boost::shared_ptr<MatrixDouble> dataPtr;
1359 const EntityHandle zeroType;
1360 const int zeroSide;
1364};
1365
1366/** Orthonormal coordinates for three-dimensional symmetric deviators.
1367 * Three coordinates retain the planar E1, E2, E3 subspace; five span all
1368 * symmetric trace-free tensors. Both reconstructions return a 3x3 tensor.
1369 */
1371 /// Basis columns (11-22)/sqrt(2), (11+22-2*33)/sqrt(6), 12, 13, 23.
1373 static const auto t_basis = [] {
1374 FTENSOR_INDEXES(3, i, j);
1375 FTensor::Index<'A', 5> A;
1377 t_basis(i, j, A) = 0.;
1378 constexpr double inverse_sqrt_two = 0.70710678118654752440;
1379 constexpr double inverse_sqrt_six = 0.40824829046386301637;
1380 t_basis(0, 0, 0) = inverse_sqrt_two;
1381 t_basis(1, 1, 0) = -inverse_sqrt_two;
1382 t_basis(0, 0, 1) = inverse_sqrt_six;
1383 t_basis(1, 1, 1) = inverse_sqrt_six;
1384 t_basis(2, 2, 1) = -2. * inverse_sqrt_six;
1385 t_basis(0, 1, 2) = inverse_sqrt_two;
1386 t_basis(0, 2, 3) = inverse_sqrt_two;
1387 t_basis(1, 2, 4) = inverse_sqrt_two;
1388 return t_basis;
1389 }();
1390 return t_basis;
1391 }
1392
1393 /// Reconstruct D + theta*I/3; input may be an owning tensor or a view.
1394 template <typename T, int Size>
1397 const double theta = 0.) {
1398 static_assert(Size == 3 || Size == 5, "Expected three or five coordinates");
1399 FTENSOR_INDEXES(3, i, j);
1400 FTensor::Index<'A', Size> A;
1401 constexpr auto t_identity = FTensor::Kronecker_Delta_symmetric<int>();
1402 const auto &t_basis = getBasis();
1404 t_tensor(i, j) =
1405 t_basis(i, j, A) * t_coordinates(A) + (theta / 3.) * t_identity(i, j);
1406 return t_tensor;
1407 }
1408
1409 /// Project a full or symmetric tensor onto the five orthonormal columns.
1410 template <typename Tensor>
1411 static FTensor::Tensor1<double, 5> getCoordinates(const Tensor &t_tensor) {
1412 FTENSOR_INDEXES(3, i, j);
1413 FTensor::Index<'A', 5> A;
1414 const auto &t_basis = getBasis();
1415 FTensor::Tensor1<double, 5> t_coordinates;
1416 t_coordinates(A) = t_basis(i, j, A) * t_tensor(i, j);
1417 return t_coordinates;
1418 }
1419};
1420
1421
1422/** Interpolate deviator coordinates using the ordinary field evaluator.
1423 * Output is a symmetric 3x3 tensor in GaussByCoeffs storage. The optional
1424 * coordinates matrix shares the interpolated values with constitutive kernels
1425 * that work in coefficient space, without evaluating the field twice.
1426 */
1427template <int CoordinateSize>
1429 : public OpCalculateVectorFieldValues<CoordinateSize> {
1430 static_assert(CoordinateSize == 3 || CoordinateSize == 5,
1431 "Expected three or five deviator coordinates");
1433 using MatrixPtr = boost::shared_ptr<MatrixDouble>;
1434
1436 const std::string field_name, MatrixPtr data_ptr,
1437 const EntityType zero_type = MBEDGE, const int zero_side = 0)
1439 field_name, data_ptr, SmartPetscObj<Vec>(), zero_type, zero_side) {}
1440
1442 const std::string field_name, MatrixPtr data_ptr,
1443 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBEDGE,
1444 const int zero_side = 0, MatrixPtr coordinates = nullptr)
1445 : Base(field_name, coordinates ? coordinates : boost::make_shared<MatrixDouble>(),
1446 data_vec, MBMAXTYPE),
1447 tensorPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
1448 if (!tensorPtr)
1449 THROW_MESSAGE("Pointer is not set");
1450 }
1451
1453 SmartPetscObj<DM> data_dm,
1455 const std::string field_name, MatrixPtr data_ptr,
1456 SmartPetscObj<Vec> data_vec, const EntityType zero_type = MBEDGE,
1457 const int zero_side = 0, MatrixPtr coordinates = nullptr)
1458 : Base(data_dm, op_type, field_name,
1459 coordinates ? coordinates : boost::make_shared<MatrixDouble>(),
1460 data_vec, MBMAXTYPE),
1461 tensorPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
1462 if (!tensorPtr)
1463 THROW_MESSAGE("Pointer is not set");
1464 }
1465
1466 MoFEMErrorCode doWork(int side, EntityType type,
1467 EntitiesFieldData::EntData &data) override {
1470 const int nb_gauss_pts = this->getGaussPts().size2();
1471 // Reset at the same entity/side as the symmetric field evaluator. The
1472 // vector evaluator uses MBMAXTYPE so later sides accumulate normally.
1473 MatrixSizeHelper<GetFTensor1FromMatType<CoordinateSize, -1, DL>, DL>::size(
1474 *this->dataPtr, nb_gauss_pts);
1475 if (type == zeroType && side == zeroSide)
1476 this->dataPtr->clear();
1477 CHKERR Base::doWork(side, type, data);
1478
1479 auto get_coordinates =
1480 MatrixSizeHelper<GetFTensor1FromMatType<CoordinateSize, -1, DL>, DL>::get(
1481 *this->dataPtr, nb_gauss_pts);
1482 auto get_tensor =
1484 *tensorPtr, nb_gauss_pts);
1485 auto t_coordinates = get_coordinates();
1486 auto t_tensor = get_tensor();
1487 FTENSOR_INDEXES(3, i, j);
1488 for (int gg = 0; gg != nb_gauss_pts; ++gg) {
1489 const auto t_deviator = Tensor2SymmetricDeviatorBasis::getTensor(t_coordinates);
1490 t_tensor(i, j) = t_deviator(i, j);
1491 ++t_coordinates;
1492 ++t_tensor;
1493 }
1495 }
1496
1497protected:
1499 const EntityHandle zeroType;
1500 const int zeroSide;
1501};
1502
1503/** Evaluate a symmetric deviator field in the fixed orthonormal material basis.
1504 * @tparam SpaceDim Spatial dimension, 2 or 3. Both cases output a 3x3 tensor.
1505 * @ingroup mofem_forces_and_sources_user_data_operators
1506 */
1508
1509/** Planar deviator: three coefficients with D13=D23=0 and D33=-D11-D22. */
1510template <>
1514 3>::OpCalculateTensor2SymmetricDeviatorFieldValues_General;
1515};
1516
1517/** Three-dimensional deviator: all five orthonormal coefficients. */
1518template <>
1522 5>::OpCalculateTensor2SymmetricDeviatorFieldValues_General;
1523};
1524
1525/**
1526 * @brief Calculate symmetric tensor field rates ant integratio pts.
1527 *
1528 * @tparam Tensor_Dim
1529 *
1530 * \ingroup mofem_forces_and_sources_user_data_operators
1531 */
1532template <int Tensor_Dim>
1535
1537 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
1538 const EntityType zero_type = MBEDGE, const int zero_side = 0)
1541 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
1542 if (!dataPtr)
1543 THROW_MESSAGE("Pointer is not set");
1544 }
1545
1546 MoFEMErrorCode doWork(int side, EntityType type,
1549 const int nb_gauss_pts = getGaussPts().size2();
1550 MatrixDouble &mat = *dataPtr;
1551 constexpr auto symm_size = (Tensor_Dim * (Tensor_Dim + 1)) / 2;
1553 auto get_values_at_gauss_pts =
1555 DL>::size(mat, nb_gauss_pts);
1556 if (type == zeroType && side == zeroSide) {
1557 mat.clear();
1558 }
1559 auto &local_indices = data.getLocalIndices();
1560 const int nb_dofs = local_indices.size();
1561 if (!nb_dofs)
1563
1564 #ifndef NDEBUG
1565 if ((getFEMethod()->data_ctx & PetscData::CtxSetX_T).none()) {
1566 MOFEM_LOG_CHANNEL("SELF");
1567 MOFEM_LOG("SELF", Sev::error)
1568 << "In this case field degrees of freedom are read from vector. "
1569 "That usually happens when time solver is used, and acces to "
1570 "first rates is needed. You probably not set "
1571 "ts_u_t and associated data structure data_ctx to CTX_SET_X_T "
1572 "respectively";
1573 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set!");
1574 }
1575 #endif
1576
1577 dotVector.resize(nb_dofs, false);
1578 const double *array;
1579 CHKERR VecGetArrayRead(getFEMethod()->ts_u_t, &array);
1580 for (int i = 0; i != local_indices.size(); ++i)
1581 if (local_indices[i] != -1)
1582 dotVector[i] = array[local_indices[i]];
1583 else
1584 dotVector[i] = 0;
1585 CHKERR VecRestoreArrayRead(getFEMethod()->ts_u_t, &array);
1586
1587 const int nb_base_functions = data.getN().size2();
1588
1589 auto base_function = data.getFTensor0N();
1590 auto t_values_at_gauss_pts = get_values_at_gauss_pts();
1591 FTensor::Index<'i', Tensor_Dim> i;
1592 FTensor::Index<'j', Tensor_Dim> j;
1593 const int size = nb_dofs / symm_size;
1594 for (int gg = 0; gg != nb_gauss_pts; ++gg) {
1595 auto field_data = getFTensorDotData<Tensor_Dim>();
1596 int bb = 0;
1597 for (; bb != size; ++bb) {
1598 t_values_at_gauss_pts(i, j) += field_data(i, j) * base_function;
1599 ++field_data;
1600 ++base_function;
1601 }
1602 for (; bb < nb_base_functions; ++bb)
1603 ++base_function;
1604 ++t_values_at_gauss_pts;
1605 }
1606
1608 }
1609
1610protected:
1611 boost::shared_ptr<MatrixDouble> dataPtr;
1612 const EntityHandle zeroType;
1613 const int zeroSide;
1615
1616 template <int Dim> inline auto getFTensorDotData() {
1617 static_assert(Dim || !Dim, "not implemented");
1618 }
1619};
1620
1621template <>
1622template <>
1623inline auto
1626 &dotVector[0], &dotVector[1], &dotVector[2], &dotVector[3], &dotVector[4],
1627 &dotVector[5]);
1628}
1629
1630template <>
1631template <>
1632inline auto
1635 &dotVector[0], &dotVector[1], &dotVector[2]);
1636}
1637
1638/**@}*/
1639
1640/** \name Gradients and Hessian of scalar fields at integration points */
1641
1642/**@{*/
1643
1644/**
1645 * \brief Evaluate field gradient values for scalar field, i.e. gradient is
1646 * tensor rank 1 (vector)
1647 *
1648 */
1649template <int Tensor_Dim, typename M = MatrixDouble>
1651 : public OpCalculateVectorFieldValues_General<Tensor_Dim, M> {
1652
1654 Tensor_Dim, M>::OpCalculateVectorFieldValues_General;
1655};
1656
1657/** \brief Evaluate field gradient values for scalar field, i.e. gradient is
1658 * tensor rank 1 (vector), specialization
1659 *
1660 */
1661template <int Tensor_Dim>
1663 : public OpCalculateVectorFieldValues_General<Tensor_Dim, MatrixDouble> {
1664
1666 Tensor_Dim, MatrixDouble>::OpCalculateVectorFieldValues_General;
1667
1668 /**
1669 * \brief calculate gradient values of scalar field at integration points
1670 * @param side side entity number
1671 * @param type side entity type
1672 * @param data entity data
1673 * @return error code
1674 */
1675 MoFEMErrorCode doWork(int side, EntityType type,
1677};
1678
1679/**
1680 * \brief Member function specialization calculating scalar field gradients for
1681 * tenor field rank 1
1682 *
1683 */
1684template <int Tensor_Dim>
1686 Tensor_Dim, MatrixDouble>::doWork(int side, EntityType type,
1689
1690 const size_t nb_gauss_pts = this->getGaussPts().size2();
1691 auto &mat = *this->dataPtr;
1693 auto get_gradients_at_pts =
1694 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim, -1, DL>,
1695 DL>::size(mat, nb_gauss_pts);
1696 if (type == this->zeroType) {
1697 mat.clear();
1698 }
1699
1700 const int nb_dofs = data.getFieldData().size();
1701 if (nb_dofs) {
1702
1703 if (this->dataVec.use_count()) {
1704 this->dotVector.resize(nb_dofs, false);
1705 // DOFs without local indices (e.g. all element vertices on a removed
1706 // boundary give empty local indices) are set to zero
1707 this->dotVector.clear();
1708 const double *array;
1709 CHKERR VecGetArrayRead(this->dataVec, &array);
1710 const auto &local_indices = data.getLocalIndices();
1711 for (int i = 0; i != local_indices.size(); ++i)
1712 if (local_indices[i] != -1)
1713 this->dotVector[i] = array[local_indices[i]];
1714 else
1715 this->dotVector[i] = 0;
1716 CHKERR VecRestoreArrayRead(this->dataVec, &array);
1717 data.getFieldData().swap(this->dotVector);
1718 }
1719
1720 if (nb_gauss_pts) {
1721 const int nb_base_functions = data.getN().size2();
1722 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim>();
1723 auto t_gradients_at_pts = get_gradients_at_pts();
1724
1725 #ifndef NDEBUG
1726 if (nb_dofs > nb_base_functions)
1727 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1728 "Number of base functions inconsistent with number of DOFs "
1729 "(%d > %d)",
1730 nb_dofs, nb_base_functions);
1731
1732 if (data.getDiffN().size2() != nb_base_functions * Tensor_Dim)
1733 SETERRQ(
1734 PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1735 "Number of base functions inconsistent with number of derivatives "
1736 "(%zu != %d)",
1737 data.getDiffN().size2(), nb_base_functions);
1738
1739 if (data.getDiffN().size1() != nb_gauss_pts)
1740 SETERRQ(
1741 PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1742 "Number of base functions inconsistent with number of integration "
1743 "pts (%zu != %zu)",
1744 data.getDiffN().size1(), nb_gauss_pts);
1745
1746 #endif
1747
1748 FTensor::Index<'I', Tensor_Dim> I;
1749 for (int gg = 0; gg < nb_gauss_pts; ++gg) {
1750 auto field_data = data.getFTensor0FieldData();
1751 int bb = 0;
1752 for (; bb != nb_dofs; ++bb) {
1753 t_gradients_at_pts(I) += field_data * diff_base_function(I);
1754 ++field_data;
1755 ++diff_base_function;
1756 }
1757 // Number of dofs can be smaller than number of base functions
1758 for (; bb < nb_base_functions; ++bb)
1759 ++diff_base_function;
1760 ++t_gradients_at_pts;
1761 }
1762 }
1763
1764 if (this->dataVec.use_count()) {
1765 data.getFieldData().swap(this->dotVector);
1766 }
1767 }
1768
1770}
1771
1772/** \brief Get field gradients at integration pts for scalar field rank 0, i.e.
1773 * vector field
1774 *
1775 * \ingroup mofem_forces_and_sources_user_data_operators
1776 */
1777template <int Tensor_Dim>
1779 : public OpCalculateScalarFieldGradient_General<Tensor_Dim> {
1781 Tensor_Dim>::OpCalculateScalarFieldGradient_General;
1782};
1783
1784/** \brief Evaluate field gradient values for scalar field, i.e. gradient is
1785 * tensor rank 1 (vector), specialization
1786 *
1787 */
1788template <int Tensor_Dim>
1790 : public OpCalculateVectorFieldValues_General<Tensor_Dim> {
1791
1793 Tensor_Dim>::OpCalculateVectorFieldValues_General;
1794
1795 /**
1796 * \brief calculate gradient values of scalar field at integration points
1797 * @param side side entity number
1798 * @param type side entity type
1799 * @param data entity data
1800 * @return error code
1801 */
1802 MoFEMErrorCode doWork(int side, EntityType type,
1804};
1805
1806template <int Tensor_Dim>
1808 int side, EntityType type, EntitiesFieldData::EntData &data) {
1810
1811 const size_t nb_gauss_pts = this->getGaussPts().size2();
1813 auto &mat = *this->dataPtr;
1814 auto get_hessian_at_gauss_pts =
1815 MatrixSizeHelper<GetFTensor2FromMatType<Tensor_Dim, Tensor_Dim, -1, DL>,
1816 DL>::size(mat, nb_gauss_pts);
1817 if (type == this->zeroType)
1818 mat.clear();
1819
1820 const int nb_dofs = data.getFieldData().size();
1821 if (nb_dofs) {
1822
1823 if (nb_gauss_pts) {
1824 const int nb_base_functions = data.getN().size2();
1825
1826 auto &hessian_base = data.getN(BaseDerivatives::SecondDerivative);
1827 #ifndef NDEBUG
1828 if (hessian_base.size1() != nb_gauss_pts) {
1829 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1830 "Wrong number of integration pts (%ld != %ld)",
1831 static_cast<long>(hessian_base.size1()),
1832 static_cast<long>(nb_gauss_pts));
1833 }
1834 if (hessian_base.size2() != nb_base_functions * Tensor_Dim * Tensor_Dim) {
1835 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1836 "Wrong number of base functions (%ld != %ld)",
1837 static_cast<long>(hessian_base.size2() /
1838 (Tensor_Dim * Tensor_Dim)),
1839 static_cast<long>(nb_base_functions));
1840 }
1841 if (hessian_base.size2() < nb_dofs * Tensor_Dim * Tensor_Dim) {
1842 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1843 "Wrong number of base functions (%ld < %ld)",
1844 static_cast<long>(hessian_base.size2()),
1845 static_cast<long>(nb_dofs * Tensor_Dim * Tensor_Dim));
1846 }
1847 #endif
1848
1849 auto t_diff2_base_function = getFTensor2FromPtr<Tensor_Dim, Tensor_Dim>(
1850 &*hessian_base.data().begin());
1851
1852 auto t_hessian_at_gauss_pts = get_hessian_at_gauss_pts();
1853
1854 FTensor::Index<'I', Tensor_Dim> I;
1855 FTensor::Index<'J', Tensor_Dim> J;
1856 for (int gg = 0; gg != nb_gauss_pts; ++gg) {
1857 auto field_data = data.getFTensor0FieldData();
1858 int bb = 0;
1859 for (; bb != nb_dofs; ++bb) {
1860 t_hessian_at_gauss_pts(I, J) +=
1861 field_data * t_diff2_base_function(I, J);
1862 ++field_data;
1863 ++t_diff2_base_function;
1864 }
1865 // Number of dofs can be smaller than number of base functions
1866 for (; bb < nb_base_functions; ++bb) {
1867 ++t_diff2_base_function;
1868 }
1869
1870 ++t_hessian_at_gauss_pts;
1871 }
1872 }
1873 }
1874
1876}
1877
1878/**}*/
1879
1880/** \name Gradients and hessian of tensor fields at integration points */
1881
1882/**@{*/
1883
1884/**
1885 * \brief Evaluate field gradient values for vector field, i.e. gradient is
1886 * tensor rank 2
1887 *
1888 * \tparam Tensor_Dim0 Dimension of the vector field
1889 * \tparam Tensor_Dim1 Dimension of the gradient (usually spatial dimension)
1890 * \tparam S Storage order for the field data
1891 * \tparam M Matrix storage type
1892 *
1893 */
1894template <int Tensor_Dim0, int Tensor_Dim1, int S,
1895 typename M = MatrixDouble>
1897 : public OpCalculateTensor2FieldValues_General<Tensor_Dim0, Tensor_Dim1,
1898 M> {
1899
1901 Tensor_Dim0, Tensor_Dim1, M>::OpCalculateTensor2FieldValues_General;
1902};
1903
1904template <int Tensor_Dim0, int Tensor_Dim1, int S>
1905struct OpCalculateVectorFieldGradient_General<Tensor_Dim0, Tensor_Dim1, S,
1908 Tensor_Dim0, Tensor_Dim1, MatrixDouble> {
1909
1911 Tensor_Dim0, Tensor_Dim1, MatrixDouble>::OpCalculateTensor2FieldValues_General;
1912
1913 /**
1914 * \brief calculate values of vector field at integration points
1915 * @param side side entity number
1916 * @param type side entity type
1917 * @param data entity data
1918 * @return error code
1919 */
1920 MoFEMErrorCode doWork(int side, EntityType type,
1922};
1923
1924/**
1925 * \brief Member function specialization calculating vector field gradients for
1926 * tenor field rank 2
1927 *
1928 */
1929template <int Tensor_Dim0, int Tensor_Dim1, int S>
1931 Tensor_Dim0, Tensor_Dim1, S, MatrixDouble>::doWork(
1932 int side, EntityType type, EntitiesFieldData::EntData &data) {
1934 if (!this->dataPtr)
1935 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1936 "Data pointer not allocated");
1937
1938 const size_t nb_gauss_pts = this->getGaussPts().size2();
1940 auto &mat = *this->dataPtr;
1941 auto get_gradients_at_pts =
1943 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
1944 DL>::size(mat, nb_gauss_pts);
1945 if (type == this->zeroType)
1946 mat.clear();
1947
1948 if (nb_gauss_pts) {
1949 const size_t nb_dofs = data.getFieldData().size();
1950
1951 if (nb_dofs) {
1952
1953 if (this->dataVec.use_count()) {
1954 this->dotVector.resize(nb_dofs, false);
1955 const double *array;
1956 CHKERR VecGetArrayRead(this->dataVec, &array);
1957 const auto &local_indices = data.getLocalIndices();
1958 for (int i = 0; i != local_indices.size(); ++i)
1959 if (local_indices[i] != -1)
1960 this->dotVector[i] = array[local_indices[i]];
1961 else
1962 this->dotVector[i] = 0;
1963 CHKERR VecRestoreArrayRead(this->dataVec, &array);
1964 data.getFieldData().swap(this->dotVector);
1965 }
1966
1967 const int nb_base_functions = data.getN().size2();
1968 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim1>();
1969 auto t_gradients_at_pts = get_gradients_at_pts();
1970 FTensor::Index<'I', Tensor_Dim0> I;
1971 FTensor::Index<'J', Tensor_Dim1> J;
1972 int size = nb_dofs / Tensor_Dim0;
1973 if (nb_dofs % Tensor_Dim0) {
1974 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1975 "Data inconsistency");
1976 }
1977 for (int gg = 0; gg < nb_gauss_pts; ++gg) {
1978 auto field_data = getFTensor1FromPtr<Tensor_Dim0, S>(
1979 data.getFieldData().data().data());
1980
1981 #ifndef NDEBUG
1982 if (field_data.l2() != field_data.l2()) {
1983 MOFEM_LOG("SELF", Sev::error) << "field data " << field_data;
1984 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1985 "Wrong number in coefficients");
1986 }
1987 #endif
1988
1989 int bb = 0;
1990 for (; bb < size; ++bb) {
1991 #ifndef SINGULARITY
1992 #ifndef NDEBUG
1993 if (diff_base_function.l2() != diff_base_function.l2()) {
1994 MOFEM_LOG("SELF", Sev::error)
1995 << "diff_base_function: " << diff_base_function;
1996 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1997 "Wrong number number in base functions");
1998 }
1999 #endif
2000 #endif
2001
2002 t_gradients_at_pts(I, J) += field_data(I) * diff_base_function(J);
2003 ++field_data;
2004 ++diff_base_function;
2005 }
2006 // Number of dofs can be smaller than number of Tensor_Dim0 x base
2007 // functions
2008 for (; bb != nb_base_functions; ++bb)
2009 ++diff_base_function;
2010 ++t_gradients_at_pts;
2011 }
2012
2013 if (this->dataVec.use_count()) {
2014 data.getFieldData().swap(this->dotVector);
2015 }
2016 }
2017 }
2019}
2020
2021/** \brief Get field gradients at integration pts for scalar field rank 0, i.e.
2022 * vector field
2023 *
2024 * \tparam Tensor_Dim0 Dimension of the vector field
2025 * \tparam Tensor_Dim1 Dimension of the gradient (usually spatial dimension)
2026 * \tparam S Stride in the storage of the vector field, default is Tensor_Dim0
2027 *
2028 * \ingroup mofem_forces_and_sources_user_data_operators
2029 */
2030template <int Tensor_Dim0, int Tensor_Dim1, int S = Tensor_Dim0>
2032 : public OpCalculateVectorFieldGradient_General<Tensor_Dim0, Tensor_Dim1,
2033 S> {
2034
2036 Tensor_Dim0, Tensor_Dim1, S>::OpCalculateVectorFieldGradient_General;
2037};
2038
2039/** \brief Get field gradients time derivative at integration pts for scalar
2040 * field rank 0, i.e. vector field
2041 *
2042 * \ingroup mofem_forces_and_sources_user_data_operators
2043 */
2044template <int Tensor_Dim0, int Tensor_Dim1>
2047
2049 boost::shared_ptr<MatrixDouble> data_ptr,
2050 const EntityType zero_at_type = MBVERTEX)
2053 dataPtr(data_ptr), zeroAtType(zero_at_type) {
2054 if (!dataPtr)
2055 THROW_MESSAGE("Pointer is not set");
2056 }
2057
2058 MoFEMErrorCode doWork(int side, EntityType type,
2061
2062 const auto &local_indices = data.getLocalIndices();
2063 const int nb_dofs = local_indices.size();
2064 const int nb_gauss_pts = this->getGaussPts().size2();
2065
2067 auto &mat = *this->dataPtr;
2068 auto get_gradients_at_pts =
2070 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
2071 DL>::size(mat, nb_gauss_pts);
2072 if (type == this->zeroAtType)
2073 mat.clear();
2074 if (!nb_dofs)
2076
2077 dotVector.resize(nb_dofs, false);
2078 const double *array;
2079 CHKERR VecGetArrayRead(getFEMethod()->ts_u_t, &array);
2080 for (int i = 0; i != local_indices.size(); ++i)
2081 if (local_indices[i] != -1)
2082 dotVector[i] = array[local_indices[i]];
2083 else
2084 dotVector[i] = 0;
2085 CHKERR VecRestoreArrayRead(getFEMethod()->ts_u_t, &array);
2086
2087 const int nb_base_functions = data.getN().size2();
2088 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim1>();
2089 auto t_gradients_at_pts = get_gradients_at_pts();
2090 FTensor::Index<'I', Tensor_Dim0> I;
2091 FTensor::Index<'J', Tensor_Dim1> J;
2092 int size = nb_dofs / Tensor_Dim0;
2093 if (nb_dofs % Tensor_Dim0) {
2094 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Data inconsistency");
2095 }
2096
2097 for (int gg = 0; gg < nb_gauss_pts; ++gg) {
2098 auto field_data = getFTensor1FromPtr<Tensor_Dim0>(&*dotVector.begin());
2099 int bb = 0;
2100 for (; bb < size; ++bb) {
2101 t_gradients_at_pts(I, J) += field_data(I) * diff_base_function(J);
2102 ++field_data;
2103 ++diff_base_function;
2104 }
2105 // Number of dofs can be smaller than number of Tensor_Dim0 x base
2106 // functions
2107 for (; bb != nb_base_functions; ++bb)
2108 ++diff_base_function;
2109 ++t_gradients_at_pts;
2110 }
2112 }
2113
2114private:
2115 boost::shared_ptr<MatrixDouble> dataPtr; ///< Data computed into this matrix
2116 EntityType zeroAtType; ///< Zero values at Gauss point at this type
2117 VectorDouble dotVector; ///< Keeps temporary values of time derivatives
2118};
2119
2120/**
2121 * \brief Evaluate field gradient values for symmetric 2nd order tensor field,
2122 * i.e. gradient is tensor rank 3
2123 *
2124 */
2125template <int Tensor_Dim0, int Tensor_Dim1, typename M = MatrixDouble>
2127 : public OpCalculateTensor2FieldValues_General<Tensor_Dim0, Tensor_Dim1,
2128 M> {
2129
2131 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
2132 const EntityType zero_type = MBVERTEX)
2133 : OpCalculateTensor2FieldValues_General<Tensor_Dim0, Tensor_Dim1, M>(
2134 field_name, data_ptr, zero_type) {}
2135};
2136
2137template <int Tensor_Dim0, int Tensor_Dim1>
2139 Tensor_Dim1,
2142 Tensor_Dim0, Tensor_Dim1, MatrixDouble> {
2143
2145 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
2146 const EntityType zero_type = MBVERTEX)
2147 : OpCalculateTensor2FieldValues_General<Tensor_Dim0, Tensor_Dim1,
2148 MatrixDouble>(
2149 field_name, data_ptr, zero_type) {}
2150
2151 /**
2152 * \brief calculate values of vector field at integration points
2153 * @param side side entity number
2154 * @param type side entity type
2155 * @param data entity data
2156 * @return error code
2157 */
2158 MoFEMErrorCode doWork(int side, EntityType type,
2160};
2161
2162/**
2163 * \brief Member function specialization calculating tensor field gradients for
2164 * symmetric tensor field rank 2
2165 *
2166 */
2167template <int Tensor_Dim0, int Tensor_Dim1>
2168MoFEMErrorCode OpCalculateTensor2SymmetricFieldGradient_General<
2169 Tensor_Dim0, Tensor_Dim1, MatrixDouble>::doWork(
2170 int side, EntityType type, EntitiesFieldData::EntData &data) {
2172 if (!this->dataPtr)
2173 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2174 "Data pointer not allocated");
2175
2176 const size_t nb_gauss_pts = this->getGaussPts().size2();
2177 constexpr size_t msize = (Tensor_Dim0 * (Tensor_Dim0 + 1)) / 2;
2178 auto &mat = *this->dataPtr;
2179 if (type == this->zeroType) {
2180 mat.resize(msize * Tensor_Dim1, nb_gauss_pts, false);
2181 mat.clear();
2182 }
2183
2184 if (nb_gauss_pts) {
2185 const size_t nb_dofs = data.getFieldData().size();
2186
2187 if (nb_dofs) {
2188
2189 const int nb_base_functions = data.getN().size2();
2190 auto diff_base_function = data.getFTensor1DiffN<Tensor_Dim1>();
2191 auto gradients_at_pts =
2192 getFTensor3DgFromMat<Tensor_Dim0, Tensor_Dim1, -1,
2194 FTensor::Index<'I', Tensor_Dim0> I;
2195 FTensor::Index<'J', Tensor_Dim0> J;
2196 FTensor::Index<'K', Tensor_Dim1> K;
2197 int size = nb_dofs / msize;
2198 if (nb_dofs % msize) {
2199 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2200 "Data inconsistency");
2201 }
2202 for (int gg = 0; gg < nb_gauss_pts; ++gg) {
2203 auto field_data = data.getFTensor2SymmetricFieldData<Tensor_Dim0>();
2204 int bb = 0;
2205 for (; bb < size; ++bb) {
2206 gradients_at_pts(I, J, K) +=
2207 field_data(I, J) * diff_base_function(K);
2208 ++field_data;
2209 ++diff_base_function;
2210 }
2211 // Number of dofs can be smaller than number of Tensor_Dim0 x base
2212 // functions
2213 for (; bb != nb_base_functions; ++bb)
2214 ++diff_base_function;
2215 ++gradients_at_pts;
2216 }
2217 }
2218 }
2220}
2221
2222/** \brief Get field gradients at integration pts for symmetric tensorial field
2223 * rank 2
2224 *
2225 * \ingroup mofem_forces_and_sources_user_data_operators
2226 */
2227template <int Tensor_Dim0, int Tensor_Dim1>
2230 Tensor_Dim0, Tensor_Dim1> {
2231
2233 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
2234 const EntityType zero_type = MBVERTEX)
2236 Tensor_Dim0, Tensor_Dim1>(field_name, data_ptr, zero_type) {}
2237};
2238
2239template <int Tensor_Dim0, int Tensor_Dim1>
2241 : public OpCalculateTensor2FieldValues_General<Tensor_Dim0,
2242 Tensor_Dim1> {
2243
2245 Tensor_Dim0, Tensor_Dim1>::OpCalculateTensor2FieldValues_General;
2246
2247 /**
2248 * \brief calculate values of vector field at integration points
2249 * @param side side entity number
2250 * @param type side entity type
2251 * @param data entity data
2252 * @return error code
2253 */
2254 MoFEMErrorCode doWork(int side, EntityType type,
2256};
2257
2258/**
2259 * \brief Member function specialization calculating vector field gradients for
2260 * tenor field rank 2
2261 *
2262 */
2263template <int Tensor_Dim0, int Tensor_Dim1>
2265 int side, EntityType type, EntitiesFieldData::EntData &data) {
2267 if (!this->dataPtr)
2268 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2269 "Data pointer not allocated");
2270
2271 const size_t nb_gauss_pts = this->getGaussPts().size2();
2272 auto &mat = *this->dataPtr;
2274 auto get_hessian_at_gauss_pts = MatrixSizeHelper<
2275 GetFTensor3FromMatType<Tensor_Dim0, Tensor_Dim1, Tensor_Dim1, -1, DL>,
2276 DL>::size(mat, nb_gauss_pts);
2277 if (type == this->zeroType) {
2278 mat.clear();
2279 }
2280
2281 if (nb_gauss_pts) {
2282 const size_t nb_dofs = data.getFieldData().size();
2283
2284 if (nb_dofs) {
2285
2286 if (this->dataVec.use_count()) {
2287 this->dotVector.resize(nb_dofs, false);
2288 const double *array;
2289 CHKERR VecGetArrayRead(this->dataVec, &array);
2290 const auto &local_indices = data.getLocalIndices();
2291 for (int i = 0; i != local_indices.size(); ++i)
2292 if (local_indices[i] != -1)
2293 this->dotVector[i] = array[local_indices[i]];
2294 else
2295 this->dotVector[i] = 0;
2296 CHKERR VecRestoreArrayRead(this->dataVec, &array);
2297 data.getFieldData().swap(this->dotVector);
2298 }
2299
2300 const int nb_base_functions = data.getN().size2();
2301
2302 auto &hessian_base = data.getN(BaseDerivatives::SecondDerivative);
2303 #ifndef NDEBUG
2304 if (hessian_base.size1() != nb_gauss_pts) {
2305 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2306 "Wrong number of integration pts (%ld != %ld)",
2307 static_cast<long>(hessian_base.size1()),
2308 static_cast<long>(nb_gauss_pts));
2309 }
2310 if (hessian_base.size2() !=
2311 nb_base_functions * Tensor_Dim1 * Tensor_Dim1) {
2312 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2313 "Wrong number of base functions (%ld != %ld)",
2314 static_cast<long>(hessian_base.size2() /
2315 (Tensor_Dim1 * Tensor_Dim1)),
2316 static_cast<long>(nb_base_functions));
2317 }
2318 if (hessian_base.size2() <
2319 (nb_dofs / Tensor_Dim0) * Tensor_Dim1 * Tensor_Dim1) {
2320 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2321 "Wrong number of base functions (%ld < %ld)",
2322 static_cast<long>(hessian_base.size2()),
2323 static_cast<long>((nb_dofs / Tensor_Dim0) * Tensor_Dim1 *
2324 Tensor_Dim1));
2325 }
2326 #endif
2327
2328 auto t_diff2_base_function = getFTensor2FromPtr<Tensor_Dim1, Tensor_Dim1>(
2329 &*hessian_base.data().begin());
2330
2331 auto t_hessian_at_gauss_pts = get_hessian_at_gauss_pts();
2332
2333 FTensor::Index<'I', Tensor_Dim0> I;
2334 FTensor::Index<'J', Tensor_Dim1> J;
2335 FTensor::Index<'K', Tensor_Dim1> K;
2336
2337 int size = nb_dofs / Tensor_Dim0;
2338 #ifndef NDEBUG
2339 if (nb_dofs % Tensor_Dim0) {
2340 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2341 "Data inconsistency");
2342 }
2343 #endif
2344
2345 for (int gg = 0; gg < nb_gauss_pts; ++gg) {
2346 auto field_data = data.getFTensor1FieldData<Tensor_Dim0>();
2347 int bb = 0;
2348 for (; bb < size; ++bb) {
2349 t_hessian_at_gauss_pts(I, J, K) +=
2350 field_data(I) * t_diff2_base_function(J, K);
2351 ++field_data;
2352 ++t_diff2_base_function;
2353 }
2354 // Number of dofs can be smaller than number of Tensor_Dim0 x base
2355 // functions
2356 for (; bb != nb_base_functions; ++bb)
2357 ++t_diff2_base_function;
2358 ++t_hessian_at_gauss_pts;
2359 }
2360
2361 if (this->dataVec.use_count()) {
2362 data.getFieldData().swap(this->dotVector);
2363 }
2364 }
2365 }
2367}
2368
2369/**@}*/
2370
2371/** \name Transform tensors and vectors */
2372
2373/**@{*/
2374
2375/**
2376 * @brief Calculate \f$ \pmb\sigma_{ij} = \mathbf{D}_{ijkl} \pmb\varepsilon_{kl}
2377 * \f$
2378 *
2379 * @tparam DIM
2380 *
2381 * \ingroup mofem_forces_and_sources_user_data_operators
2382 */
2383template <int DIM_01, int DIM_23, int S = 0>
2386
2389
2390 /**
2391 * @deprecated Do not use this constructor
2392 */
2395 boost::shared_ptr<MatrixDouble> in_mat,
2396 boost::shared_ptr<MatrixDouble> out_mat,
2397 boost::shared_ptr<MatrixDouble> d_mat)
2398 : UserOp(field_name, OPCOL), inMat(in_mat), outMat(out_mat), dMat(d_mat) {
2399 // Only is run for vertices
2400 std::fill(&doEntities[MBEDGE], &doEntities[MBMAXTYPE], false);
2401 if (!inMat)
2402 THROW_MESSAGE("Pointer for in mat is null");
2403 if (!outMat)
2404 THROW_MESSAGE("Pointer for out mat is null");
2405 if (!dMat)
2406 THROW_MESSAGE("Pointer for tensor mat is null");
2407 }
2408
2409 OpTensorTimesSymmetricTensor(boost::shared_ptr<MatrixDouble> in_mat,
2410 boost::shared_ptr<MatrixDouble> out_mat,
2411 boost::shared_ptr<MatrixDouble> d_mat)
2412 : UserOp(NOSPACE, OPSPACE), inMat(in_mat), outMat(out_mat), dMat(d_mat) {
2413 // Only is run for vertices
2414 if (!inMat)
2415 THROW_MESSAGE("Pointer for in mat is null");
2416 if (!outMat)
2417 THROW_MESSAGE("Pointer for out mat is null");
2418 if (!dMat)
2419 THROW_MESSAGE("Pointer for tensor mat is null");
2420 }
2421
2422 MoFEMErrorCode doWork(int, EntityType, EntData &) {
2424 const size_t nb_gauss_pts = getGaussPts().size2();
2426 auto get_D_at_pts =
2428 DL>::get(*dMat, nb_gauss_pts);
2429 auto get_in_at_pts =
2431 DL>::get(*inMat, nb_gauss_pts);
2432 auto get_out_at_pts =
2434 DL>::size(*outMat, nb_gauss_pts);
2435 auto t_D_at_pts = get_D_at_pts();
2436 auto t_in_at_pts = get_in_at_pts();
2437 auto t_out_at_pts = get_out_at_pts();
2438 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
2439 t_out_at_pts(i, j) = t_D_at_pts(i, j, k, l) * t_in_at_pts(k, l);
2440 ++t_in_at_pts;
2441 ++t_out_at_pts;
2442 ++t_D_at_pts;
2443 }
2445 }
2446
2447private:
2448 FTensor::Index<'i', DIM_01> i;
2449 FTensor::Index<'j', DIM_01> j;
2450 FTensor::Index<'k', DIM_23> k;
2451 FTensor::Index<'l', DIM_23> l;
2452
2453 boost::shared_ptr<MatrixDouble> inMat;
2454 boost::shared_ptr<MatrixDouble> outMat;
2455 boost::shared_ptr<MatrixDouble> dMat;
2456};
2457
2458/**
2459 * @brief Operator for symmetrizing tensor fields
2460 *
2461 * This template structure symmetrizes tensor fields by computing the symmetric
2462 * part of an input tensor and storing the result in an output matrix. It's
2463 * commonly used in mechanics where symmetric tensors (like stress and strain)
2464 * are required.
2465 *
2466 * @tparam DIM Dimension of the tensor field
2467 */
2468template <int DIM>
2470
2473
2474 /**
2475 * @deprecated Do not use this constructor
2476 */
2478 boost::shared_ptr<MatrixDouble> in_mat,
2479 boost::shared_ptr<MatrixDouble> out_mat)
2480 : UserOp(field_name, OPCOL), inMat(in_mat), outMat(out_mat) {
2481 // Only is run for vertices
2482 std::fill(&doEntities[MBEDGE], &doEntities[MBMAXTYPE], false);
2483 if (!inMat)
2484 THROW_MESSAGE("Pointer not set for in matrix");
2485 if (!outMat)
2486 THROW_MESSAGE("Pointer not set for in matrix");
2487 }
2488
2489 /**
2490 * @brief Constructor for tensor symmetrization operator
2491 *
2492 * @param in_mat Shared pointer to input matrix containing asymmetric tensor
2493 * @param out_mat Shared pointer to output matrix for storing symmetric tensor
2494 */
2495 OpSymmetrizeTensor(boost::shared_ptr<MatrixDouble> in_mat,
2496 boost::shared_ptr<MatrixDouble> out_mat)
2497 : UserOp(NOSPACE, OPSPACE), inMat(in_mat), outMat(out_mat) {
2498 // Only is run for vertices
2499 if (!inMat)
2500 THROW_MESSAGE("Pointer not set for in matrix");
2501 if (!outMat)
2502 THROW_MESSAGE("Pointer not set for in matrix");
2503 }
2504
2505 MoFEMErrorCode doWork(int, EntityType, EntData &) {
2507 const size_t nb_gauss_pts = getGaussPts().size2();
2509 auto get_in_at_pts =
2510 MatrixSizeHelper<GetFTensor2FromMatType<DIM, DIM, -1, DL>, DL>::get(
2511 *inMat, nb_gauss_pts);
2512 auto t_in_at_pts = get_in_at_pts();
2513 auto get_out_at_pts =
2515 DL>::size(*outMat, nb_gauss_pts);
2516 auto t_out_at_pts = get_out_at_pts();
2517 for (size_t gg = 0; gg != nb_gauss_pts; ++gg) {
2518 t_out_at_pts(i, j) = (t_in_at_pts(i, j) || t_in_at_pts(j, i)) / 2;
2519 ++t_in_at_pts;
2520 ++t_out_at_pts;
2521 }
2523 }
2524
2525private:
2528 boost::shared_ptr<MatrixDouble> inMat;
2529 boost::shared_ptr<MatrixDouble> outMat;
2530};
2531
2532/**
2533 * @brief Operator for scaling matrix values by a scalar factor
2534 *
2535 * This structure performs element-wise scaling of matrix data by multiplying
2536 * all elements by a scalar value. It's useful for applying material properties,
2537 * coordinate transformations, or other scaling operations in finite element
2538 * computations.
2539 */
2541
2544
2545 /**
2546 * @deprecated Do not use this constructor
2547 */
2548 DEPRECATED OpScaleMatrix(const std::string field_name, const double scale,
2549 boost::shared_ptr<MatrixDouble> in_mat,
2550 boost::shared_ptr<MatrixDouble> out_mat)
2551 : UserOp(field_name, OPCOL), inMat(in_mat), outMat(out_mat) {
2552 scalePtr = boost::make_shared<double>(scale);
2553 // Only is run for vertices
2554 std::fill(&doEntities[MBEDGE], &doEntities[MBMAXTYPE], false);
2555 if (!inMat)
2556 THROW_MESSAGE("Pointer not set for in matrix");
2557 if (!outMat)
2558 THROW_MESSAGE("Pointer not set for in matrix");
2559 }
2560
2561 /**
2562 * @brief Constructor for matrix scaling operator
2563 *
2564 * @param scale_ptr Shared pointer to scalar value for scaling matrix elements
2565 * @param in_mat Shared pointer to input matrix to be scaled
2566 * @param out_mat Shared pointer to output matrix for storing scaled results
2567 */
2568 OpScaleMatrix(boost::shared_ptr<double> scale_ptr,
2569 boost::shared_ptr<MatrixDouble> in_mat,
2570 boost::shared_ptr<MatrixDouble> out_mat)
2571 : UserOp(NOSPACE, OPSPACE), scalePtr(scale_ptr), inMat(in_mat),
2572 outMat(out_mat) {
2573 if (!scalePtr)
2574 THROW_MESSAGE("Pointer not set for scale");
2575 if (!inMat)
2576 THROW_MESSAGE("Pointer not set for in matrix");
2577 if (!outMat)
2578 THROW_MESSAGE("Pointer not set for in matrix");
2579 }
2580
2581 MoFEMErrorCode doWork(int, EntityType, EntData &) {
2583 outMat->resize(inMat->size1(), inMat->size2(), false);
2584 noalias(*outMat) = (*scalePtr) * (*inMat);
2586 }
2587
2588private:
2589 boost::shared_ptr<double> scalePtr;
2590 boost::shared_ptr<MatrixDouble> inMat;
2591 boost::shared_ptr<MatrixDouble> outMat;
2592};
2593
2594/**@}*/
2595
2596/** \name H-div/H-curls (Vectorial bases) values at integration points */
2597
2598/**@{*/
2599
2600/** \brief Get vector field for H-div approximation
2601 * \ingroup mofem_forces_and_sources_user_data_operators
2602 */
2603template <int Base_Dim, int Field_Dim, typename M = MatrixDouble>
2605
2606/** \brief Get vector field for H-div approximation
2607 * \ingroup mofem_forces_and_sources_user_data_operators
2608 */
2609template <int Field_Dim>
2612
2614 boost::shared_ptr<MatrixDouble> data_ptr,
2615 SmartPetscObj<Vec> data_vec,
2616 const EntityType zero_type = MBEDGE,
2617 const int zero_side = 0)
2620 dataPtr(data_ptr), dataVec(data_vec), zeroType(zero_type),
2621 zeroSide(zero_side) {
2622 if (!dataPtr)
2623 THROW_MESSAGE("Pointer is not set");
2624 }
2625
2627 boost::shared_ptr<MatrixDouble> data_ptr,
2628 const EntityType zero_type = MBEDGE,
2629 const int zero_side = 0)
2631 field_name, data_ptr, SmartPetscObj<Vec>(), zero_type, zero_side) {}
2632
2633 /**
2634 * \brief Calculate values of vector field at integration points
2635 * @param side side entity number
2636 * @param type side entity type
2637 * @param data entity data
2638 * @return error code
2639 */
2640 MoFEMErrorCode doWork(int side, EntityType type,
2642
2643private:
2644 boost::shared_ptr<MatrixDouble> dataPtr;
2646 const EntityHandle zeroType;
2647 const int zeroSide;
2649};
2650
2651template <int Field_Dim>
2653 3, Field_Dim, MatrixDouble>::doWork(int side, EntityType type,
2656 const size_t nb_integration_points = this->getGaussPts().size2();
2657 auto &mat = *dataPtr;
2659 auto get_data_at_pts =
2660 MatrixSizeHelper<GetFTensor1FromMatType<Field_Dim, -1, DL>,
2661 DL>::size(mat, nb_integration_points);
2662 if (type == zeroType && side == zeroSide) {
2663 mat.clear();
2664 }
2665 const size_t nb_dofs = data.getFieldData().size();
2666 if (!nb_dofs)
2668
2669 if (dataVec.use_count()) {
2670 dotVector.resize(nb_dofs, false);
2671 const double *array;
2672 CHKERR VecGetArrayRead(dataVec, &array);
2673 const auto &local_indices = data.getLocalIndices();
2674 for (int i = 0; i != local_indices.size(); ++i)
2675 if (local_indices[i] != -1)
2676 dotVector[i] = array[local_indices[i]];
2677 else
2678 dotVector[i] = 0;
2679 CHKERR VecRestoreArrayRead(dataVec, &array);
2680 data.getFieldData().swap(dotVector);
2681 }
2682
2683 const size_t nb_base_functions = data.getN().size2() / 3;
2684 FTensor::Index<'i', Field_Dim> i;
2685 auto t_n_hdiv = data.getFTensor1N<3>();
2686 auto t_data_at_pts = get_data_at_pts();
2687 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
2688 auto t_dof = data.getFTensor0FieldData();
2689 int bb = 0;
2690 for (; bb != nb_dofs; ++bb) {
2691 t_data_at_pts(i) += t_n_hdiv(i) * t_dof;
2692 ++t_n_hdiv;
2693 ++t_dof;
2694 }
2695 for (; bb != nb_base_functions; ++bb)
2696 ++t_n_hdiv;
2697 ++t_data_at_pts;
2698 }
2699
2700 if (dataVec.use_count()) {
2701 data.getFieldData().swap(dotVector);
2702 }
2704}
2705
2706/** \brief Get vector field for H-div approximation
2707 *
2708 * \ingroup mofem_forces_and_sources_user_data_operators
2709 */
2710template <int Base_Dim, int Field_Dim = Base_Dim>
2712 : public OpCalculateHVecVectorField_General<Base_Dim, Field_Dim> {
2714 Base_Dim, Field_Dim>::OpCalculateHVecVectorField_General;
2715};
2716
2717/** \brief Get vector field for H-div approximation
2718 * \ingroup mofem_forces_and_sources_user_data_operators
2719 */
2720template <int Base_Dim, int Field_Dim = Base_Dim>
2722
2723template <int Field_Dim>
2726
2728 boost::shared_ptr<MatrixDouble> data_ptr,
2729 const EntityType zero_type = MBEDGE,
2730 const int zero_side = 0)
2733 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
2734 if (!dataPtr)
2735 THROW_MESSAGE("Pointer is not set");
2736 }
2737
2738 /**
2739 * \brief Calculate values of vector field at integration points
2740 * @param side side entity number
2741 * @param type side entity type
2742 * @param data entity data
2743 * @return error code
2744 */
2745 MoFEMErrorCode doWork(int side, EntityType type,
2747
2748private:
2749 boost::shared_ptr<MatrixDouble> dataPtr;
2750 const EntityHandle zeroType;
2751 const int zeroSide;
2752};
2753
2754template <int Field_Dim>
2756 int side, EntityType type, EntitiesFieldData::EntData &data) {
2758
2759 const size_t nb_integration_points = this->getGaussPts().size2();
2760 auto &mat = *dataPtr;
2762 auto get_data_at_pts =
2763 MatrixSizeHelper<GetFTensor1FromMatType<Field_Dim, -1, DL>,
2764 DL>::size(mat, nb_integration_points);
2765 if (type == zeroType && side == zeroSide) {
2766 mat.clear();
2767 }
2768
2769 auto &local_indices = data.getIndices();
2770 const size_t nb_dofs = local_indices.size();
2771 if (nb_dofs) {
2772
2773 std::array<double, MAX_DOFS_ON_ENTITY> dot_dofs_vector;
2774 const double *array;
2775 CHKERR VecGetArrayRead(getFEMethod()->ts_u_t, &array);
2776 for (size_t i = 0; i != nb_dofs; ++i)
2777 if (local_indices[i] != -1)
2778 dot_dofs_vector[i] = array[local_indices[i]];
2779 else
2780 dot_dofs_vector[i] = 0;
2781 CHKERR VecRestoreArrayRead(getFEMethod()->ts_u_t, &array);
2782
2783 const size_t nb_base_functions = data.getN().size2() / 3;
2784 FTensor::Index<'i', Field_Dim> i;
2785 auto t_n_hdiv = data.getFTensor1N<3>();
2786 auto t_data_at_pts = get_data_at_pts();
2787 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
2788 size_t bb = 0;
2789 for (; bb != nb_dofs; ++bb) {
2790 t_data_at_pts(i) += t_n_hdiv(i) * dot_dofs_vector[bb];
2791 ++t_n_hdiv;
2792 }
2793 for (; bb != nb_base_functions; ++bb)
2794 ++t_n_hdiv;
2795 ++t_data_at_pts;
2796 }
2797 }
2798
2800}
2801
2802/**
2803 * @brief Calculate divergence of vector field
2804 * @ingroup mofem_forces_and_sources_user_data_operators
2805 *
2806 * @tparam BASE_DIM
2807 * @tparam SPACE_DIM
2808 */
2809template <int BASE_DIM, int SPACE_DIM>
2812
2814 boost::shared_ptr<VectorDouble> data_ptr,
2815 const EntityType zero_type = MBEDGE,
2816 const int zero_side = 0)
2819 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
2820 if (!dataPtr)
2821 THROW_MESSAGE("Pointer is not set");
2822 }
2823
2824 MoFEMErrorCode doWork(int side, EntityType type,
2827 const size_t nb_integration_points = getGaussPts().size2();
2828 if (type == zeroType && side == zeroSide) {
2829 dataPtr->resize(nb_integration_points, false);
2830 dataPtr->clear();
2831 }
2832 const size_t nb_dofs = data.getFieldData().size();
2833 if (!nb_dofs)
2835 const size_t nb_base_functions = data.getN().size2() / BASE_DIM;
2838 auto t_n_diff_hdiv = data.getFTensor2DiffN<BASE_DIM, SPACE_DIM>();
2839 auto t_data = getFTensor0FromVec(*dataPtr);
2840 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
2841 auto t_dof = data.getFTensor0FieldData();
2842 size_t bb = 0;
2843 for (; bb != nb_dofs; ++bb) {
2844 t_data += t_dof * t_n_diff_hdiv(j, j);
2845 ++t_n_diff_hdiv;
2846 ++t_dof;
2847 }
2848 for (; bb != nb_base_functions; ++bb)
2849 ++t_n_diff_hdiv;
2850 ++t_data;
2851 }
2853 }
2854
2855private:
2856 boost::shared_ptr<VectorDouble> dataPtr;
2857 const EntityHandle zeroType;
2858 const int zeroSide;
2859};
2860
2861/**
2862 * @brief Calculate gradient of vector field
2863 * @ingroup mofem_forces_and_sources_user_data_operators
2864 *
2865 * @tparam BASE_DIM
2866 * @tparam SPACE_DIM
2867 */
2868template <int BASE_DIM, int SPACE_DIM>
2871
2873 boost::shared_ptr<MatrixDouble> data_ptr,
2874 const EntityType zero_type = MBEDGE,
2875 const int zero_side = 0)
2878 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
2879 if (!dataPtr)
2880 THROW_MESSAGE("Pointer is not set");
2881 }
2882
2883 MoFEMErrorCode doWork(int side, EntityType type,
2886 const size_t nb_integration_points = getGaussPts().size2();
2888 auto get_data_at_pts =
2891 DL>::size(*dataPtr, nb_integration_points);
2892 if (type == zeroType && side == zeroSide)
2893 dataPtr->clear();
2894 const size_t nb_dofs = data.getFieldData().size();
2895 if (!nb_dofs)
2897 const size_t nb_base_functions = data.getN().size2() / BASE_DIM;
2900 auto t_base_diff = data.getFTensor2DiffN<BASE_DIM, SPACE_DIM>();
2901 auto t_data_at_pts = get_data_at_pts();
2902 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
2903 auto t_dof = data.getFTensor0FieldData();
2904 size_t bb = 0;
2905 for (; bb != nb_dofs; ++bb) {
2906 t_data_at_pts(i, j) += t_dof * t_base_diff(i, j);
2907 ++t_base_diff;
2908 ++t_dof;
2909 }
2910 for (; bb != nb_base_functions; ++bb)
2911 ++t_base_diff;
2912 ++t_data_at_pts;
2913 }
2915 }
2916
2917private:
2918 boost::shared_ptr<MatrixDouble> dataPtr;
2919 const EntityHandle zeroType;
2920 const int zeroSide;
2921};
2922
2923/**
2924 * @brief Calculate gradient of tensor field
2925 * @ingroup mofem_forces_and_sources_user_data_operators
2926 *
2927 * @tparam BASE_DIM
2928 * @tparam FIELD_DIM
2929 * @tparam SPACE_DIM
2930 */
2931template <int BASE_DIM, int FIELD_DIM, int SPACE_DIM>
2933
2934/**
2935 * @brief Specialisation for 3D tensor field gradient calculation
2936 * @ingroup mofem_forces_and_sources_user_data_operators
2937 *
2938 */
2939template <>
2942
2944 boost::shared_ptr<MatrixDouble> data_ptr,
2945 const EntityType zero_type = MBEDGE,
2946 const int zero_side = 0)
2949 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
2950 if (!dataPtr)
2951 THROW_MESSAGE("Pointer is not set");
2952 }
2953
2954 MoFEMErrorCode doWork(int side, EntityType type,
2957
2958 const size_t nb_integration_points = getGaussPts().size2();
2960 auto get_data_at_pts =
2962 DL>::size(*dataPtr, nb_integration_points);
2963 if (type == zeroType && side == zeroSide) {
2964 dataPtr->clear();
2965 }
2966
2967 #ifndef NDEBUG
2968 if (data.getFieldData().size() % 3) {
2969 SETERRQ(
2970 PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
2971 "Data inconsistency, nb_dofs %% COEFF_DIM != 0, that is %ld %% %d "
2972 "!= 0",
2973 data.getFieldData().size(), 3);
2974 }
2975 #endif
2976
2977 const auto nb_dofs = data.getFieldData().size() / 3;
2978 if (!nb_dofs)
2980
2981 const size_t nb_base_functions = data.getN().size2() / 3;
2982 FTensor::Index<'i', 3> i;
2983 FTensor::Index<'j', 3> j;
2984 FTensor::Index<'k', 3> k;
2985
2986 auto t_base_diff = data.getFTensor2DiffN<3, 3>();
2987 auto t_data_at_pts = get_data_at_pts();
2988 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
2989 auto t_dof = data.getFTensor1FieldData<3>();
2990 size_t bb = 0;
2991 for (; bb != nb_dofs; ++bb) {
2992 t_data_at_pts(k, i, j) += t_base_diff(i, j) * t_dof(k);
2993 ++t_base_diff;
2994 ++t_dof;
2995 }
2996 for (; bb != nb_base_functions; ++bb)
2997 ++t_base_diff;
2998 ++t_data_at_pts;
2999 }
3001 }
3002
3003private:
3004 boost::shared_ptr<MatrixDouble> dataPtr;
3005 const EntityHandle zeroType;
3006 const int zeroSide;
3007};
3008
3009template <>
3012
3014 boost::shared_ptr<MatrixDouble> data_ptr,
3015 const EntityType zero_type = MBEDGE,
3016 const int zero_side = 0)
3019 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
3020 if (!dataPtr)
3021 THROW_MESSAGE("Pointer is not set");
3022 }
3023
3024 MoFEMErrorCode doWork(int side, EntityType type,
3027
3028 const size_t nb_integration_points = getGaussPts().size2();
3030 auto get_data_at_pts =
3032 DL>::size(*dataPtr, nb_integration_points);
3033 if (type == zeroType && side == zeroSide) {
3034 dataPtr->clear();
3035 }
3036
3037 const auto nb_dofs = data.getFieldData().size();
3038 if (!nb_dofs)
3040
3041 const size_t nb_base_functions = data.getN().size2() / 9;
3042
3043 #ifndef NDEBUG
3044 if (data.getDiffN().size1() != nb_integration_points) {
3045 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3046 "Wrong number of integration pts (%ld != %ld)",
3047 static_cast<long>(data.getDiffN().size1()),
3048 static_cast<long>(nb_integration_points));
3049 }
3050 if (data.getDiffN().size2() != nb_base_functions * 27) {
3051 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3052 "Wrong number of base functions (%ld != %ld)",
3053 static_cast<long>(data.getDiffN().size2() / 27),
3054 static_cast<long>(nb_base_functions));
3055 }
3056 if (nb_base_functions < nb_dofs) {
3057 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3058 "Wrong number of base functions (%ld < %ld)",
3059 static_cast<long>(nb_base_functions),
3060 static_cast<long>(nb_dofs));
3061 }
3062 #endif
3063
3064 FTensor::Index<'i', 3> i;
3065 FTensor::Index<'j', 3> j;
3066 FTensor::Index<'k', 3> k;
3067
3068 auto t_base_diff = data.getFTensor3DiffN<3, 3, 3>();
3069 auto t_data_at_pts = get_data_at_pts();
3070 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3071 auto t_dof = data.getFTensor0FieldData();
3072 size_t bb = 0;
3073 for (; bb != nb_dofs; ++bb) {
3074 t_data_at_pts(k, i, j) += t_base_diff(k, i, j) * t_dof;
3075 ++t_base_diff;
3076 ++t_dof;
3077 }
3078 for (; bb != nb_base_functions; ++bb)
3079 ++t_base_diff;
3080 ++t_data_at_pts;
3081 }
3082
3084 }
3085
3086private:
3087 boost::shared_ptr<MatrixDouble> dataPtr;
3088 const EntityHandle zeroType;
3089 const int zeroSide;
3090};
3091
3092/**
3093 * @brief Calculate gradient of vector field
3094 * @ingroup mofem_forces_and_sources_user_data_operators
3095 *
3096 * @tparam BASE_DIM
3097 * @tparam SPACE_DIM
3098 */
3099template <int BASE_DIM, int SPACE_DIM>
3102
3104 boost::shared_ptr<MatrixDouble> data_ptr,
3105 const EntityType zero_type = MBEDGE,
3106 const int zero_side = 0)
3109 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
3110 if (!dataPtr)
3111 THROW_MESSAGE("Pointer is not set");
3112 }
3113
3114 MoFEMErrorCode doWork(int side, EntityType type,
3117 const size_t nb_integration_points = getGaussPts().size2();
3119 auto get_data_at_pts = MatrixSizeHelper<
3121 DL>::size(*dataPtr, nb_integration_points);
3122 if (type == zeroType && side == zeroSide) {
3123 dataPtr->clear();
3124 }
3125 const size_t nb_dofs = data.getFieldData().size();
3126 if (!nb_dofs)
3128
3129 const int nb_base_functions = data.getN().size2() / BASE_DIM;
3130
3131 #ifndef NDEBUG
3132 auto &hessian_base = data.getN(BaseDerivatives::SecondDerivative);
3133 if (hessian_base.size1() != nb_integration_points) {
3134 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3135 "Wrong number of integration pts (%ld != %ld)",
3136 static_cast<long>(hessian_base.size1()),
3137 static_cast<long>(nb_integration_points));
3138 }
3139 if (hessian_base.size2() !=
3140 BASE_DIM * nb_base_functions * SPACE_DIM * SPACE_DIM) {
3141 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3142 "Wrong number of base functions (%ld != %ld)",
3143 static_cast<long>(hessian_base.size2() /
3145 static_cast<long>(nb_base_functions));
3146 }
3147 if (hessian_base.size2() < BASE_DIM * nb_dofs * SPACE_DIM * SPACE_DIM) {
3148 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
3149 "Wrong number of base functions (%ld < %ld)",
3150 static_cast<long>(hessian_base.size2()),
3151 static_cast<long>(BASE_DIM * nb_dofs * SPACE_DIM * SPACE_DIM));
3152 }
3153 #endif
3154
3158
3159 auto t_base_diff2 =
3161 auto t_data_at_pts = get_data_at_pts();
3162 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3163 auto t_dof = data.getFTensor0FieldData();
3164 int bb = 0;
3165 for (; bb != nb_dofs; ++bb) {
3166 t_data_at_pts(i, j, k) += t_dof * t_base_diff2(i, j, k);
3167
3168 ++t_base_diff2;
3169 ++t_dof;
3170 }
3171 for (; bb != nb_base_functions; ++bb)
3172 ++t_base_diff2;
3173 ++t_data_at_pts;
3174 }
3176 }
3177
3178private:
3179 boost::shared_ptr<MatrixDouble> dataPtr;
3180 const EntityHandle zeroType;
3181 const int zeroSide;
3182};
3183
3184/**
3185 * @brief Calculate divergence of vector field dot
3186 * @ingroup mofem_forces_and_sources_user_data_operators
3187 *
3188 * @tparam Tensor_Dim dimension of space
3189 */
3190template <int Tensor_Dim1, int Tensor_Dim2>
3193
3195 boost::shared_ptr<VectorDouble> data_ptr,
3196 const EntityType zero_type = MBEDGE,
3197 const int zero_side = 0)
3200 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
3201 if (!dataPtr)
3202 THROW_MESSAGE("Pointer is not set");
3203 }
3204
3205 MoFEMErrorCode doWork(int side, EntityType type,
3208 const size_t nb_integration_points = getGaussPts().size2();
3209 if (type == zeroType && side == zeroSide) {
3210 dataPtr->resize(nb_integration_points, false);
3211 dataPtr->clear();
3212 }
3213
3214 const auto &local_indices = data.getLocalIndices();
3215 const int nb_dofs = local_indices.size();
3216 if (nb_dofs) {
3217
3218 std::array<double, MAX_DOFS_ON_ENTITY> dot_dofs_vector;
3219 const double *array;
3220 CHKERR VecGetArrayRead(getFEMethod()->ts_u_t, &array);
3221 for (size_t i = 0; i != local_indices.size(); ++i)
3222 if (local_indices[i] != -1)
3223 dot_dofs_vector[i] = array[local_indices[i]];
3224 else
3225 dot_dofs_vector[i] = 0;
3226 CHKERR VecRestoreArrayRead(getFEMethod()->ts_u_t, &array);
3227
3228 const size_t nb_base_functions = data.getN().size2() / Tensor_Dim1;
3229 FTensor::Index<'i', Tensor_Dim1> i;
3230 auto t_n_diff_hdiv = data.getFTensor2DiffN<Tensor_Dim1, Tensor_Dim2>();
3231 auto t_data = getFTensor0FromVec(*dataPtr);
3232 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3233 int bb = 0;
3234 for (; bb != nb_dofs; ++bb) {
3235 double div = 0;
3236 for (auto ii = 0; ii != Tensor_Dim2; ++ii)
3237 div += t_n_diff_hdiv(ii, ii);
3238 t_data += dot_dofs_vector[bb] * div;
3239 ++t_n_diff_hdiv;
3240 }
3241 for (; bb != nb_base_functions; ++bb)
3242 ++t_n_diff_hdiv;
3243 ++t_data;
3244 }
3245 }
3247 }
3248
3249private:
3250 boost::shared_ptr<VectorDouble> dataPtr;
3251 const EntityHandle zeroType;
3252 const int zeroSide;
3253};
3254
3255/**
3256 * @brief Calculate curl of vector field
3257 * @ingroup mofem_forces_and_sources_user_data_operators
3258 *
3259 * @tparam Base_Dim base function dimension
3260 * @tparam Space_Dim dimension of space
3261 * @tparam Hcurl field dimension
3262 */
3263template <int Base_Dim, int Space_Dim> struct OpCalculateHcurlVectorCurl;
3264
3265/**
3266 * @brief Calculate curl of vector field
3267 * @ingroup mofem_forces_and_sources_user_data_operators
3268 *
3269 * @tparam Base_Dim base function dimension
3270 * @tparam Space_Dim dimension of space
3271 * @tparam Hcurl field dimension
3272 */
3273template <>
3276 OpCalculateHcurlVectorCurl(const std::string field_name,
3277 boost::shared_ptr<MatrixDouble> data_ptr,
3278 const EntityType zero_type = MBEDGE,
3279 const int zero_side = 0);
3280 MoFEMErrorCode doWork(int side, EntityType type,
3282
3283private:
3284 boost::shared_ptr<MatrixDouble> dataPtr;
3285 const EntityHandle zeroType;
3286 const int zeroSide;
3287};
3288
3289/**
3290 * @brief Calculate curl of vector field
3291 * @ingroup mofem_forces_and_sources_user_data_operators
3292 *
3293 * @tparam Field_Dim dimension of field
3294 * @tparam Space_Dim dimension of space
3295 */
3296template <>
3299
3300 OpCalculateHcurlVectorCurl(const std::string field_name,
3301 boost::shared_ptr<MatrixDouble> data_ptr,
3302 const EntityType zero_type = MBVERTEX,
3303 const int zero_side = 0);
3304
3305 MoFEMErrorCode doWork(int side, EntityType type,
3307
3308private:
3309 boost::shared_ptr<MatrixDouble> dataPtr;
3310 const EntityHandle zeroType;
3311 const int zeroSide;
3312};
3313
3314/**
3315 * @brief Calculate curl of vector field
3316 * @ingroup mofem_forces_and_sources_user_data_operators
3317 *
3318 * @tparam Field_Dim dimension of field
3319 * @tparam Space_Dim dimension of space
3320 */
3321template <>
3324
3325 OpCalculateHcurlVectorCurl(const std::string field_name,
3326 boost::shared_ptr<MatrixDouble> data_ptr,
3327 const EntityType zero_type = MBVERTEX,
3328 const int zero_side = 0);
3329
3330 MoFEMErrorCode doWork(int side, EntityType type,
3332
3333private:
3334 boost::shared_ptr<MatrixDouble> dataPtr;
3335 const EntityHandle zeroType;
3336 const int zeroSide;
3337};
3338
3339/**
3340 * @brief Calculate tenor field using vectorial base, i.e. Hdiv/Hcurl
3341 * \ingroup mofem_forces_and_sources_user_data_operators
3342 *
3343 * @tparam Tensor_Dim0 rank of the field
3344 * @tparam Tensor_Dim1 dimension of space
3345 */
3346template <int Tensor_Dim0, int Tensor_Dim1>
3349
3351 boost::shared_ptr<MatrixDouble> data_ptr,
3352 boost::shared_ptr<double> scale_ptr,
3354 const EntityType zero_type = MBEDGE,
3355 const int zero_side = 0)
3358 dataPtr(data_ptr), scalePtr(scale_ptr), dataVec(data_vec),
3359 zeroType(zero_type), zeroSide(zero_side) {
3360 if (!dataPtr)
3361 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "Pointer is not set");
3362 }
3363
3365 boost::shared_ptr<MatrixDouble> data_ptr,
3366 const EntityType zero_type = MBEDGE,
3367 const int zero_side = 0)
3368 : OpCalculateHVecTensorField(field_name, data_ptr, nullptr,
3369 SmartPetscObj<Vec>(), zero_type, zero_side) {
3370 }
3371
3372 MoFEMErrorCode doWork(int side, EntityType type,
3375 const size_t nb_integration_points = getGaussPts().size2();
3377 auto get_data_at_pts =
3379 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
3380 DL>::size(*dataPtr, nb_integration_points);
3381 if (type == zeroType && side == zeroSide)
3382 dataPtr->clear();
3383 const size_t nb_dofs = data.getFieldData().size();
3384 if (nb_dofs) {
3385
3386 if (dataVec.use_count()) {
3387 dotVector.resize(nb_dofs, false);
3388 const double *array;
3389 CHKERR VecGetArrayRead(dataVec, &array);
3390 const auto &local_indices = data.getLocalIndices();
3391 for (int i = 0; i != local_indices.size(); ++i)
3392 if (local_indices[i] != -1)
3393 dotVector[i] = array[local_indices[i]];
3394 else
3395 dotVector[i] = 0;
3396 CHKERR VecRestoreArrayRead(dataVec, &array);
3397 data.getFieldData().swap(dotVector);
3398 }
3399
3400 double scale = (scalePtr) ? *scalePtr : 1.0;
3401 const size_t nb_base_functions = data.getN().size2() / 3;
3402 FTensor::Index<'i', Tensor_Dim0> i;
3403 FTensor::Index<'j', Tensor_Dim1> j;
3404 auto t_n_hvec = data.getFTensor1N<3>();
3405 auto t_data_at_pts = get_data_at_pts();
3406 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3407 auto t_dof = data.getFTensor1FieldData<Tensor_Dim0>();
3408 size_t bb = 0;
3409 for (; bb != nb_dofs / Tensor_Dim0; ++bb) {
3410 t_data_at_pts(i, j) += (scale * t_dof(i)) * t_n_hvec(j);
3411 ++t_n_hvec;
3412 ++t_dof;
3413 }
3414 for (; bb < nb_base_functions; ++bb)
3415 ++t_n_hvec;
3416 ++t_data_at_pts;
3417 }
3418
3419 if (dataVec.use_count()) {
3420 data.getFieldData().swap(dotVector);
3421 }
3422 }
3424 }
3425
3426private:
3427 boost::shared_ptr<MatrixDouble> dataPtr;
3428 boost::shared_ptr<double> scalePtr;
3430 const EntityHandle zeroType;
3431 const int zeroSide;
3432 VectorDouble dotVector; ///< Keeps temporary values of time derivatives
3433};
3434
3435/** \brief Approximate Hdiv/Hcurl tensor field values for a given PETSc vector
3436 *
3437 * \note Look at PetscData to see what vectors could be extracted with that user
3438 * data operator.
3439 *
3440 * \ingroup mofem_forces_and_sources_user_data_operators
3441 */
3442template <int Tensor_Dim0, int Tensor_Dim1, PetscData::DataContext CTX>
3445
3447 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
3448 const EntityType zero_type = MBEDGE, const int zero_side = 0)
3451 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side) {
3452 if (!dataPtr)
3453 THROW_MESSAGE("Pointer is not set");
3454 }
3455
3456 MoFEMErrorCode doWork(int side, EntityType type,
3459
3460 const size_t nb_integration_points = getGaussPts().size2();
3462 auto get_data_at_pts =
3464 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
3465 DL>::size(*dataPtr, nb_integration_points);
3466 if (type == zeroType && side == zeroSide)
3467 dataPtr->clear();
3468
3469 const auto &local_indices = data.getLocalIndices();
3470 const size_t nb_dofs = local_indices.size();
3471 if (!nb_dofs)
3473
3474 const double *array;
3475
3476 auto get_array = [&](const auto ctx, auto vec) {
3478 #ifndef NDEBUG
3479 if ((getFEMethod()->data_ctx & ctx).none()) {
3480 MOFEM_LOG_CHANNEL("SELF");
3481 MOFEM_LOG("SELF", Sev::error)
3482 << "In this case field degrees of freedom are read from vector. "
3483 "That usually happens when time solver is used, and access to "
3484 "first or second rates is needed. You probably not set ts_u, "
3485 "ts_u_t, or ts_u_tt and associated data structure, i.e. "
3486 "data_ctx to CTX_SET_X, CTX_SET_DX, CTX_SET_X_T, or "
3487 "CTX_SET_X_TT respectively";
3488 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set");
3489 }
3490 #endif
3491 CHKERR VecGetArrayRead(vec, &array);
3493 };
3494
3495 auto restore_array = [&](auto vec) {
3496 return VecRestoreArrayRead(vec, &array);
3497 };
3498
3499 switch (CTX) {
3501 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->ts_u);
3502 break;
3504 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->dx);
3505 break;
3507 CHKERR get_array(PetscData::CtxSetX_T, getFEMethod()->ts_u_t);
3508 break;
3510 CHKERR get_array(PetscData::CtxSetX_TT, getFEMethod()->ts_u_tt);
3511 break;
3512 default:
3513 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
3514 "That case is not implemented");
3515 }
3516
3517 dotVector.resize(local_indices.size(), false);
3518 for (int i = 0; i != local_indices.size(); ++i)
3519 if (local_indices[i] != -1)
3520 dotVector[i] = array[local_indices[i]];
3521 else
3522 dotVector[i] = 0;
3523
3524 switch (CTX) {
3526 CHKERR restore_array(getFEMethod()->ts_u);
3527 break;
3529 CHKERR restore_array(getFEMethod()->dx);
3530 break;
3532 CHKERR restore_array(getFEMethod()->ts_u_t);
3533 break;
3535 CHKERR restore_array(getFEMethod()->ts_u_tt);
3536 break;
3537 default:
3538 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
3539 "That case is not implemented");
3540 }
3541
3542 const size_t nb_base_functions = data.getN().size2() / 3;
3543 FTensor::Index<'i', Tensor_Dim0> i;
3544 FTensor::Index<'j', Tensor_Dim1> j;
3545 auto t_n_hvec = data.getFTensor1N<3>();
3546 auto t_data_at_pts = get_data_at_pts();
3547 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3548 auto t_dof = getFTensor1FromArray<Tensor_Dim0, Tensor_Dim0>(dotVector);
3549 size_t bb = 0;
3550 for (; bb != nb_dofs / Tensor_Dim0; ++bb) {
3551 t_data_at_pts(i, j) += t_dof(i) * t_n_hvec(j);
3552 ++t_n_hvec;
3553 ++t_dof;
3554 }
3555 for (; bb < nb_base_functions; ++bb)
3556 ++t_n_hvec;
3557 ++t_data_at_pts;
3558 }
3559
3561 }
3562
3563private:
3564 boost::shared_ptr<MatrixDouble> dataPtr;
3565 const EntityHandle zeroType;
3566 const int zeroSide;
3569};
3570
3571template <int Tensor_Dim0, int Tensor_Dim1>
3573 OpCalculateHVecTensorFieldFromPetscVecImpl<Tensor_Dim0, Tensor_Dim1,
3575
3576/** \brief Approximate tensor field values for a given PETSc vector on a tensor
3577 * basis
3578 *
3579 * \note Look at PetscData to see what vectors could be extracted with that user
3580 * data operator.
3581 *
3582 * \ingroup mofem_forces_and_sources_user_data_operators
3583 */
3584template <int Tensor_Dim0, int Tensor_Dim1, PetscData::DataContext CTX>
3587
3589 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
3590 const EntityType zero_type = MBEDGE, const int zero_side = 0,
3591 bool throw_error = true)
3594 dataPtr(data_ptr), zeroType(zero_type), zeroSide(zero_side),
3595 throwError(throw_error) {
3596 if (!dataPtr)
3597 THROW_MESSAGE("Pointer is not set");
3598 }
3599
3600 MoFEMErrorCode doWork(int side, EntityType type,
3603
3604 const size_t nb_integration_points = getGaussPts().size2();
3606 auto get_data_at_pts =
3608 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
3609 DL>::size(*dataPtr, nb_integration_points);
3610 if (type == zeroType && side == zeroSide)
3611 dataPtr->clear();
3612
3613 const auto &local_indices = data.getLocalIndices();
3614 const size_t nb_dofs = local_indices.size();
3615 if (!nb_dofs)
3617
3618 if (!throwError) {
3619 if ((getFEMethod()->data_ctx & PetscData::Switches(CTX)).none()) {
3621 }
3622 }
3623
3624 const double *array;
3625
3626 auto get_array = [&](const auto ctx, auto vec) {
3628 #ifndef NDEBUG
3629 if ((getFEMethod()->data_ctx & ctx).none()) {
3630 MOFEM_LOG_CHANNEL("SELF");
3631 MOFEM_LOG("SELF", Sev::error)
3632 << "In this case field degrees of freedom are read from vector. "
3633 "That usually happens when time solver is used, and access to "
3634 "first or second rates is needed. You probably not set ts_u, "
3635 "ts_u_t, or ts_u_tt and associated data structure, i.e. "
3636 "data_ctx to CTX_SET_X, CTX_SET_DX, CTX_SET_X_T, or "
3637 "CTX_SET_X_TT respectively";
3638 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Vector not set");
3639 }
3640 #endif
3641 CHKERR VecGetArrayRead(vec, &array);
3643 };
3644
3645 auto restore_array = [&](auto vec) {
3646 return VecRestoreArrayRead(vec, &array);
3647 };
3648
3649 switch (CTX) {
3651 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->ts_u);
3652 break;
3654 CHKERR get_array(PetscData::CtxSetX, getFEMethod()->dx);
3655 break;
3657 CHKERR get_array(PetscData::CtxSetX_T, getFEMethod()->ts_u_t);
3658 break;
3660 CHKERR get_array(PetscData::CtxSetX_TT, getFEMethod()->ts_u_tt);
3661 break;
3662 default:
3663 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
3664 "That case is not implemented");
3665 }
3666
3667 dotVector.resize(local_indices.size(), false);
3668 for (int i = 0; i != local_indices.size(); ++i)
3669 if (local_indices[i] != -1)
3670 dotVector[i] = array[local_indices[i]];
3671 else
3672 dotVector[i] = 0;
3673
3674 switch (CTX) {
3676 CHKERR restore_array(getFEMethod()->ts_u);
3677 break;
3679 CHKERR restore_array(getFEMethod()->dx);
3680 break;
3682 CHKERR restore_array(getFEMethod()->ts_u_t);
3683 break;
3685 CHKERR restore_array(getFEMethod()->ts_u_tt);
3686 break;
3687 default:
3688 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
3689 "That case is not implemented");
3690 }
3691
3692 const size_t nb_base_functions =
3693 data.getN().size2() / (Tensor_Dim0 * Tensor_Dim1);
3694 FTensor::Index<'i', Tensor_Dim0> i;
3695 FTensor::Index<'j', Tensor_Dim1> j;
3696 auto t_n_hten = data.getFTensor2N<Tensor_Dim0, Tensor_Dim1>();
3697 auto t_data_at_pts = get_data_at_pts();
3698 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3699 auto t_dof = getFTensor0FromVec(dotVector);
3700 size_t bb = 0;
3701 for (; bb != nb_dofs; ++bb) {
3702 t_data_at_pts(i, j) += t_dof * t_n_hten(i, j);
3703 ++t_n_hten;
3704 ++t_dof;
3705 }
3706 for (; bb < nb_base_functions; ++bb)
3707 ++t_n_hten;
3708 ++t_data_at_pts;
3709 }
3710
3712 }
3713
3714private:
3715 boost::shared_ptr<MatrixDouble> dataPtr;
3716 const EntityHandle zeroType;
3717 const int zeroSide;
3720};
3721
3722template <int Tensor_Dim0, int Tensor_Dim1>
3724 OpCalculateHTensorTensorFieldFromPetscVecImpl<Tensor_Dim0, Tensor_Dim1,
3726
3727/** \brief Get tensor field for H-div approximation
3728 * \ingroup mofem_forces_and_sources_user_data_operators
3729 *
3730 * \warning This operator is not tested
3731 */
3732template <int Tensor_Dim0, int Tensor_Dim1>
3735
3737
3739 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
3740 SmartPetscObj<Vec> data_vec, EntityType broken_type,
3741 boost::shared_ptr<Range> broken_range_ptr = nullptr,
3742 boost::shared_ptr<double> scale_ptr = nullptr,
3743 const EntityType zero_type = MBEDGE, const int zero_side = 0)
3745 dataPtr(data_ptr), dataVec(data_vec), brokenType(broken_type),
3746 brokenRangePtr(broken_range_ptr), zeroType(zero_type) {
3747 if (!dataPtr)
3748 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "Pointer is not set");
3749 }
3750
3751 /**
3752 * \brief Calculate values of vector field at integration points
3753 * @param side side entity number
3754 * @param type side entity type
3755 * @param data entity data
3756 * @return error code
3757 */
3758 MoFEMErrorCode doWork(int side, EntityType type,
3760
3761private:
3762 boost::shared_ptr<MatrixDouble> dataPtr;
3764 EntityType brokenType;
3765 boost::shared_ptr<Range> brokenRangePtr;
3766 boost::shared_ptr<double> scalePtr;
3767 const EntityHandle zeroType;
3769};
3770
3771template <int Tensor_Dim0, int Tensor_Dim1>
3774 int side, EntityType type, EntitiesFieldData::EntData &data) {
3776 const size_t nb_integration_points = OP::getGaussPts().size2();
3778 auto get_data_at_pts =
3780 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
3781 DL>::size(*dataPtr, nb_integration_points);
3782 if (type == zeroType)
3783 dataPtr->clear();
3784 const size_t nb_dofs = data.getFieldData().size();
3785 if (!nb_dofs)
3787
3788 if (dataVec.use_count()) {
3789 dotVector.resize(nb_dofs, false);
3790 const double *array;
3791 CHKERR VecGetArrayRead(dataVec, &array);
3792 const auto &local_indices = data.getLocalIndices();
3793 for (int i = 0; i != local_indices.size(); ++i)
3794 if (local_indices[i] != -1)
3795 dotVector[i] = array[local_indices[i]];
3796 else
3797 dotVector[i] = 0;
3798 CHKERR VecRestoreArrayRead(dataVec, &array);
3799 data.getFieldData().swap(dotVector);
3800 }
3801
3802 /**
3803 * @brief Get side face dofs
3804 *
3805 * Find which base functions on borken space have adjacent given entity type
3806 * and are in the range ptr if given.
3807 *
3808 */
3809 auto get_get_side_face_dofs = [&]() {
3810 auto fe_type = OP::getFEType();
3811
3812 BaseFunction::DofsSideMap &side_dof_map =
3813 data.getFieldEntities()[0]->getDofSideMap().at(fe_type);
3814 std::vector<int> side_face_dofs;
3815 side_face_dofs.reserve(data.getIndices().size() / Tensor_Dim0);
3816
3817 for (
3818
3819 auto it = side_dof_map.get<1>().begin();
3820 it != side_dof_map.get<1>().end(); ++it
3821
3822 ) {
3823 if ((Tensor_Dim0 * it->dof) >= data.getIndices().size()) {
3824 break;
3825 }
3826 if (it->type == brokenType) {
3827 if (brokenRangePtr) {
3828 auto ent = OP::getSideEntity(it->side, brokenType);
3829 if (brokenRangePtr->find(ent) != brokenRangePtr->end()) {
3830 side_face_dofs.push_back(it->dof);
3831 }
3832 } else {
3833 side_face_dofs.push_back(it->dof);
3834 }
3835 }
3836 }
3837
3838 return side_face_dofs;
3839 };
3840
3841 auto side_face_dofs = get_get_side_face_dofs();
3842
3843 FTensor::Index<'i', Tensor_Dim0> i;
3844 FTensor::Index<'j', Tensor_Dim1> j;
3845 auto t_data_at_pts = get_data_at_pts();
3846 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3847 for (auto b : side_face_dofs) {
3848 auto t_row_base = data.getFTensor1N<3>(gg, b);
3849 auto t_dof = getFTensor1FromPtr<Tensor_Dim0>(data.getFieldData().data() +
3850 b * Tensor_Dim0);
3851 t_data_at_pts(i, j) += t_dof(i) * t_row_base(j);
3852 }
3853 ++t_data_at_pts;
3854 }
3855 *dataPtr *= (scalePtr) ? *scalePtr : 1.0;
3856
3857 if (dataVec.use_count()) {
3858 data.getFieldData().swap(dotVector);
3859 }
3860
3862}
3863
3864/**
3865 * @brief Calculate tenor field using tensor base, i.e. Hdiv/Hcurl
3866 * \ingroup mofem_forces_and_sources_user_data_operators
3867 *
3868 * @tparam Tensor_Dim0 rank of the field
3869 * @tparam Tensor_Dim1 dimension of space
3870 */
3871template <int Tensor_Dim0, int Tensor_Dim1>
3874
3876 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
3877 boost::shared_ptr<double> scale_ptr,
3879 const EntityType zero_type = MBEDGE, const int zero_side = 0)
3882 dataPtr(data_ptr), scalePtr(scale_ptr), dataVec(data_vec),
3883 zeroType(zero_type), zeroSide(zero_side) {
3884 if (!dataPtr)
3885 THROW_MESSAGE("Pointer is not set");
3886 }
3887
3889 boost::shared_ptr<MatrixDouble> data_ptr,
3890 const EntityType zero_type = MBEDGE,
3891 const int zero_side = 0)
3892 : OpCalculateHTensorTensorField(field_name, data_ptr, nullptr,
3893 SmartPetscObj<Vec>(), zero_type,
3894 zero_side) {}
3895
3896 MoFEMErrorCode doWork(int side, EntityType type,
3899 const size_t nb_integration_points = getGaussPts().size2();
3901 auto get_data_at_pts =
3903 GetFTensor2FromMatType<Tensor_Dim0, Tensor_Dim1, -1, DL>,
3904 DL>::size(*dataPtr, nb_integration_points);
3905 if (type == zeroType && side == zeroSide)
3906 dataPtr->clear();
3907 const size_t nb_dofs = data.getFieldData().size();
3908 if (!nb_dofs)
3910
3911 if (dataVec.use_count()) {
3912 dotVector.resize(nb_dofs, false);
3913 const double *array;
3914 CHKERR VecGetArrayRead(dataVec, &array);
3915 const auto &local_indices = data.getLocalIndices();
3916 for (int i = 0; i != local_indices.size(); ++i)
3917 if (local_indices[i] != -1)
3918 dotVector[i] = array[local_indices[i]];
3919 else
3920 dotVector[i] = 0;
3921 CHKERR VecRestoreArrayRead(dataVec, &array);
3922 data.getFieldData().swap(dotVector);
3923 }
3924
3925 double scale = (scalePtr) ? *scalePtr : 1.0;
3926 const size_t nb_base_functions =
3927 data.getN().size2() / (Tensor_Dim0 * Tensor_Dim1);
3928 FTensor::Index<'i', Tensor_Dim0> i;
3929 FTensor::Index<'j', Tensor_Dim1> j;
3930 auto t_n_hten = data.getFTensor2N<Tensor_Dim0, Tensor_Dim1>();
3931 auto t_data_at_pts = get_data_at_pts();
3932 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
3933 auto t_dof = data.getFTensor0FieldData();
3934 size_t bb = 0;
3935 for (; bb != nb_dofs; ++bb) {
3936 t_data_at_pts(i, j) += (scale * t_dof) * t_n_hten(i, j);
3937 ++t_n_hten;
3938 ++t_dof;
3939 }
3940 for (; bb < nb_base_functions; ++bb)
3941 ++t_n_hten;
3942 ++t_data_at_pts;
3943 }
3944
3945 if (dataVec.use_count()) {
3946 data.getFieldData().swap(dotVector);
3947 }
3948
3950 }
3951
3952private:
3953 boost::shared_ptr<MatrixDouble> dataPtr;
3954 boost::shared_ptr<double> scalePtr;
3956 const EntityHandle zeroType;
3957 const int zeroSide;
3958 VectorDouble dotVector; ///< Keeps temporary values of time derivatives
3959};
3960
3961/**
3962 * @brief Calculate divergence of tonsorial field using vectorial base
3963 * \ingroup mofem_forces_and_sources_user_data_operators
3964 *
3965 * @tparam Tensor_Dim0 rank of the field
3966 * @tparam Tensor_Dim1 dimension of space
3967 */
3968template <int Tensor_Dim0, int Tensor_Dim1,
3969 CoordinateTypes CoordSys = CARTESIAN>
3972
3974 boost::shared_ptr<MatrixDouble> data_ptr,
3975 SmartPetscObj<Vec> data_vec,
3976 const EntityType zero_type = MBEDGE,
3977 const int zero_side = 0)
3980 dataPtr(data_ptr), dataVec(data_vec), zeroType(zero_type),
3981 zeroSide(zero_side) {
3982 if (!dataPtr)
3983 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "Pointer is not set");
3984 }
3985
3987 boost::shared_ptr<MatrixDouble> data_ptr,
3988 const EntityType zero_type = MBEDGE,
3989 const int zero_side = 0)
3991 field_name, data_ptr, SmartPetscObj<Vec>(), zero_type, zero_side) {}
3992
3993 MoFEMErrorCode doWork(int side, EntityType type,
3996 const size_t nb_integration_points = getGaussPts().size2();
3997 auto &mat = *dataPtr;
3999 auto get_data_at_pts =
4000 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim0, -1, DL>,
4001 DL>::size(mat, nb_integration_points);
4002 if (type == zeroType && side == zeroSide) {
4003 mat.clear();
4004 }
4005 const size_t nb_dofs = data.getFieldData().size();
4006 if (nb_dofs) {
4007
4008 if (dataVec.use_count()) {
4009 dotVector.resize(nb_dofs, false);
4010 const double *array;
4011 CHKERR VecGetArrayRead(dataVec, &array);
4012 const auto &local_indices = data.getLocalIndices();
4013 for (int i = 0; i != local_indices.size(); ++i)
4014 if (local_indices[i] != -1)
4015 dotVector[i] = array[local_indices[i]];
4016 else
4017 dotVector[i] = 0;
4018 CHKERR VecRestoreArrayRead(dataVec, &array);
4019 data.getFieldData().swap(dotVector);
4020 }
4021
4022 const size_t nb_base_functions = data.getN().size2() / 3;
4023 FTensor::Index<'i', Tensor_Dim0> i;
4024 FTensor::Index<'j', Tensor_Dim1> j;
4025 auto t_n_diff_hvec = data.getFTensor2DiffN<3, Tensor_Dim1>();
4026 auto t_data_at_pts = get_data_at_pts();
4027 auto t_base = data.getFTensor1N<3>();
4028 auto t_coords = getFTensor1CoordsAtGaussPts();
4029 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
4030 auto t_dof = data.getFTensor1FieldData<Tensor_Dim0>();
4031 size_t bb = 0;
4032 for (; bb != nb_dofs / Tensor_Dim0; ++bb) {
4033 double div = t_n_diff_hvec(j, j);
4034 t_data_at_pts(i) += t_dof(i) * div;
4035 if constexpr (CoordSys == CYLINDRICAL) {
4036 t_data_at_pts(i) += t_base(0) * (t_dof(i) / t_coords(0));
4037 }
4038 ++t_n_diff_hvec;
4039 ++t_dof;
4040 ++t_base;
4041 }
4042 for (; bb < nb_base_functions; ++bb) {
4043 ++t_base;
4044 ++t_n_diff_hvec;
4045 }
4046 ++t_data_at_pts;
4047 ++t_coords;
4048 }
4049
4050 if (dataVec.use_count()) {
4051 data.getFieldData().swap(dotVector);
4052 }
4053 }
4055 }
4056
4057private:
4058 boost::shared_ptr<MatrixDouble> dataPtr;
4060 const EntityHandle zeroType;
4061 const int zeroSide;
4062
4063 VectorDouble dotVector; ///< Keeps temporary values of time derivatives
4064};
4065
4066/**
4067 * @brief Calculate divergence of tonsorial field using vectorial base
4068 * \ingroup mofem_forces_and_sources_user_data_operators
4069 *
4070 * \warning This operator is not tested
4071 *
4072 * @tparam Tensor_Dim0 rank of the field
4073 * @tparam Tensor_Dim1 dimension of space
4074 */
4075template <int Tensor_Dim0, int Tensor_Dim1,
4076 CoordinateTypes CoordSys = CARTESIAN>
4079
4081
4083 const std::string field_name, boost::shared_ptr<MatrixDouble> data_ptr,
4084 SmartPetscObj<Vec> data_vec, EntityType broken_type,
4085 boost::shared_ptr<Range> broken_range_ptr = nullptr,
4086 boost::shared_ptr<double> scale_ptr = nullptr,
4087 const EntityType zero_type = MBEDGE)
4089 dataPtr(data_ptr), dataVec(data_vec), brokenType(broken_type),
4090 brokenRangePtr(broken_range_ptr), scalePtr(scale_ptr),
4091 zeroType(zero_type) {
4092 if (!dataPtr)
4093 CHK_THROW_MESSAGE(MOFEM_DATA_INCONSISTENCY, "Pointer is not set");
4094 }
4095
4096 MoFEMErrorCode doWork(int side, EntityType type,
4099 const size_t nb_integration_points = getGaussPts().size2();
4100 auto &mat = *dataPtr;
4102 auto get_data_at_pts =
4103 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim0, -1, DL>,
4104 DL>::size(mat, nb_integration_points);
4105 if (type == zeroType && side == 0) {
4106 mat.clear();
4107 }
4108
4109 const size_t nb_dofs = data.getFieldData().size();
4110 if (nb_dofs) {
4111
4112 if (dataVec.use_count()) {
4113 dotVector.resize(nb_dofs, false);
4114 const double *array;
4115 CHKERR VecGetArrayRead(dataVec, &array);
4116 const auto &local_indices = data.getLocalIndices();
4117 for (int i = 0; i != local_indices.size(); ++i)
4118 if (local_indices[i] != -1)
4119 dotVector[i] = array[local_indices[i]];
4120 else
4121 dotVector[i] = 0;
4122 CHKERR VecRestoreArrayRead(dataVec, &array);
4123 data.getFieldData().swap(dotVector);
4124 }
4125
4126 /**
4127 * @brief Get side face dofs
4128 *
4129 * Find which base functions on borken space have adjacent given entity
4130 * type and are in the range ptr if given.
4131 *
4132 */
4133 auto get_get_side_face_dofs = [&]() {
4134 auto fe_type = OP::getFEType();
4135
4136 BaseFunction::DofsSideMap &side_dof_map =
4137 data.getFieldEntities()[0]->getDofSideMap().at(fe_type);
4138 std::vector<int> side_face_dofs;
4139 side_face_dofs.reserve(data.getIndices().size() / Tensor_Dim0);
4140
4141 for (
4142
4143 auto it = side_dof_map.get<1>().begin();
4144 it != side_dof_map.get<1>().end(); ++it
4145
4146 ) {
4147 if ((Tensor_Dim0 * it->dof) >= data.getIndices().size()) {
4148 break;
4149 }
4150 if (it->type == brokenType) {
4151 if (brokenRangePtr) {
4152 auto ent = OP::getSideEntity(it->side, brokenType);
4153 if (brokenRangePtr->find(ent) != brokenRangePtr->end()) {
4154 side_face_dofs.push_back(it->dof);
4155 }
4156 } else {
4157 side_face_dofs.push_back(it->dof);
4158 }
4159 }
4160 }
4161
4162 return side_face_dofs;
4163 };
4164
4165 auto side_face_dofs = get_get_side_face_dofs();
4166
4167 FTensor::Index<'i', Tensor_Dim0> i;
4168 FTensor::Index<'j', Tensor_Dim1> j;
4169 auto t_data_at_pts = get_data_at_pts();
4170 auto t_coords = getFTensor1CoordsAtGaussPts();
4171 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
4172 for (auto b : side_face_dofs) {
4173 auto t_dof = getFTensor1FromPtr<Tensor_Dim0>(
4174 data.getFieldData().data() + b * Tensor_Dim0);
4175 auto t_base = data.getFTensor1N<3>(gg, b);
4176 auto t_diff_base = data.getFTensor2DiffN<3, Tensor_Dim1>(gg, b);
4177 double div = t_diff_base(j, j);
4178 t_data_at_pts(i) += t_dof(i) * div;
4179 if constexpr (CoordSys == CYLINDRICAL) {
4180 t_data_at_pts(i) += t_base(0) * (t_dof(i) / t_coords(0));
4181 }
4182 }
4183 ++t_data_at_pts;
4184 ++t_coords;
4185 }
4186 }
4187
4188 if (dataVec.use_count()) {
4189 data.getFieldData().swap(dotVector);
4190 }
4191
4193 }
4194
4195private:
4196 boost::shared_ptr<MatrixDouble> dataPtr;
4198 EntityType brokenType;
4199 boost::shared_ptr<Range> brokenRangePtr;
4200 boost::shared_ptr<double> scalePtr;
4201 const EntityHandle zeroType;
4203};
4204
4205/**
4206 * @brief Calculate trace of vector (Hdiv/Hcurl) space
4207 *
4208 * @tparam Tensor_Dim
4209 * @tparam OpBase
4210 */
4211template <int Tensor_Dim, typename OpBase>
4213
4215 boost::shared_ptr<MatrixDouble> data_ptr,
4216 boost::shared_ptr<double> scale_ptr,
4217 const EntityType zero_type = MBEDGE,
4218 const int zero_side = 0)
4219 : OpBase(field_name, OpBase::OPCOL), dataPtr(data_ptr),
4220 scalePtr(scale_ptr), zeroType(zero_type), zeroSide(zero_side) {
4221 if (!dataPtr)
4222 THROW_MESSAGE("Pointer is not set");
4223 }
4224
4226 boost::shared_ptr<MatrixDouble> data_ptr,
4227 const EntityType zero_type = MBEDGE,
4228 const int zero_side = 0)
4229 : OpCalculateHVecTensorTrace(field_name, data_ptr, nullptr, zero_type,
4230 zero_side) {}
4231
4232 MoFEMErrorCode doWork(int side, EntityType type,
4235 const size_t nb_integration_points = OpBase::getGaussPts().size2();
4236 auto &mat = *dataPtr;
4238 auto get_data_at_pts =
4239 MatrixSizeHelper<GetFTensor1FromMatType<Tensor_Dim, -1, DL>,
4240 DL>::size(mat, nb_integration_points);
4241 if (type == zeroType && side == 0) {
4242 mat.clear();
4243 }
4244 const size_t nb_dofs = data.getFieldData().size();
4245 if (nb_dofs) {
4246 double scale_val = (scalePtr) ? *scalePtr : 1.0;
4247 auto t_normal = OpBase::getFTensor1NormalsAtGaussPts();
4248 const size_t nb_base_functions = data.getN().size2() / 3;
4249 auto t_base = data.getFTensor1N<3>();
4250 auto t_data_at_pts = get_data_at_pts();
4251 for (size_t gg = 0; gg != nb_integration_points; ++gg) {
4252 FTensor::Tensor1<double, Tensor_Dim> t_normalized_normal;
4253 t_normalized_normal(j) = t_normal(j);
4254 t_normalized_normal.normalize();
4255 auto t_dof = data.getFTensor1FieldData<Tensor_Dim>();
4256 size_t bb = 0;
4257 for (; bb != nb_dofs / Tensor_Dim; ++bb) {
4258 t_data_at_pts(i) +=
4259 (scale_val * t_dof(i)) * (t_base(j) * t_normalized_normal(j));
4260 ++t_base;
4261 ++t_dof;
4262 }
4263 for (; bb < nb_base_functions; ++bb) {
4264 ++t_base;
4265 }
4266 ++t_data_at_pts;
4267 ++t_normal;
4268 }
4269 }
4271 }
4272
4273private:
4274 boost::shared_ptr<MatrixDouble> dataPtr;
4275 boost::shared_ptr<double> scalePtr;
4276 const EntityHandle zeroType;
4277 const int zeroSide;
4278 FTensor::Index<'i', Tensor_Dim> i;
4279 FTensor::Index<'j', Tensor_Dim> j;
4280};
4281
4282/**@}*/
4283
4284/** \name Other operators */
4285
4286/**@{*/
4287
4288/**@}*/
4289
4290/** \name Operators for faces */
4291
4292/**@{*/
4293
4294/** \brief Transform local reference derivatives of shape functions to global
4295derivatives
4296
4297\ingroup mofem_forces_and_sources_tri_element
4298
4299*/
4300template <int DIM, int DERIVATIVE = 1> struct OpSetInvJacSpaceForFaceImpl;
4301
4304
4306 boost::shared_ptr<MatrixDouble> inv_jac_ptr);
4307
4308protected:
4309 /**
4310 * @brief Apply transformation to the input matrix
4311 *
4312 * @tparam D1 dimension of the derivative of base functions in input
4313 * @tparam D2 dimension of the derivative of base functions in output
4314 * @tparam J1 nb of rows in jacobian (= dimension of space)
4315 * @tparam J2 nb of columns in jacobian (= dimension of reference element)
4316 * @param diff_n
4317 * @return MoFEMErrorCode
4318 */
4319 template <int D1, int D2, int J1, int J2>
4322
4323 static_assert(D2 == J2, "Dimension of jacobian and dimension of <out> "
4324 "directive does not match");
4325
4326 size_t nb_functions = diff_n.size2() / D1;
4327 if (nb_functions) {
4328 size_t nb_gauss_pts = diff_n.size1();
4329
4330 #ifndef NDEBUG
4331 if (nb_gauss_pts != getGaussPts().size2())
4332 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4333 "Wrong number of Gauss Pts");
4334 if (diff_n.size2() % D1)
4335 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4336 "Number of directives of base functions and D1 dimension does "
4337 "not match");
4338 #endif
4339
4340 diffNinvJac.resize(diff_n.size1(), D2 * nb_functions, false);
4341
4342 FTensor::Index<'i', D2> i;
4343 FTensor::Index<'k', D1> k;
4344 auto t_diff_n = getFTensor1FromPtr<D2>(&*diffNinvJac.data().begin());
4345 auto t_diff_n_ref = getFTensor1FromPtr<D1>(&*diff_n.data().begin());
4347 auto get_inv_jac_at_pts =
4348 MatrixSizeHelper<GetFTensor2FromMatType<J1, J2, -1, DL>, DL>::get(
4349 *invJacPtr, nb_gauss_pts);
4350 auto t_inv_jac_at_pts = get_inv_jac_at_pts();
4351 for (size_t gg = 0; gg != nb_gauss_pts; ++gg, ++t_inv_jac_at_pts) {
4352 for (size_t dd = 0; dd != nb_functions; ++dd) {
4353 t_diff_n(i) = t_inv_jac_at_pts(k, i) * t_diff_n_ref(k);
4354 ++t_diff_n;
4355 ++t_diff_n_ref;
4356 }
4357 }
4358
4359 diff_n.swap(diffNinvJac);
4360 }
4362 }
4363
4364 boost::shared_ptr<MatrixDouble> invJacPtr;
4366};
4367
4368template <>
4371
4373
4374 MoFEMErrorCode doWork(int side, EntityType type,
4376};
4377
4378template <>
4380 : public OpSetInvJacSpaceForFaceImpl<2, 1> {
4381
4382 using OpSetInvJacSpaceForFaceImpl<2, 1>::OpSetInvJacSpaceForFaceImpl;
4383
4384 MoFEMErrorCode doWork(int side, EntityType type,
4386};
4387
4388template <>
4390 : public OpSetInvJacSpaceForFaceImpl<2, 1> {
4391
4392 using OpSetInvJacSpaceForFaceImpl<2, 1>::OpSetInvJacSpaceForFaceImpl;
4393
4394 MoFEMErrorCode doWork(int side, EntityType type,
4396};
4397
4398template <int DERIVARIVE = 1>
4400 : public OpSetInvJacSpaceForFaceImpl<2, DERIVARIVE> {
4401 OpSetInvJacH1ForFace(boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4402 : OpSetInvJacSpaceForFaceImpl<2, DERIVARIVE>(H1, inv_jac_ptr) {}
4403};
4404
4405template <int DERIVARIVE = 1>
4407 : public OpSetInvJacSpaceForFaceImpl<2, DERIVARIVE> {
4408 OpSetInvJacL2ForFace(boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4409 : OpSetInvJacSpaceForFaceImpl<2, DERIVARIVE>(L2, inv_jac_ptr) {}
4410};
4411
4412template <int DERIVARIVE = 1>
4414 : public OpSetInvJacSpaceForFaceImpl<3, DERIVARIVE> {
4416 boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4417 : OpSetInvJacSpaceForFaceImpl<3, DERIVARIVE>(H1, inv_jac_ptr) {}
4418};
4419
4420template <int DERIVARIVE = 1>
4422 : public OpSetInvJacSpaceForFaceImpl<3, DERIVARIVE> {
4424 boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4425 : OpSetInvJacSpaceForFaceImpl<3, DERIVARIVE>(L2, inv_jac_ptr) {}
4426};
4427
4428/**
4429 * \brief Transform local reference derivatives of shape function to
4430 global derivatives for face
4431
4432 * \ingroup mofem_forces_and_sources_tri_element
4433 */
4434template <int DIM> struct OpSetInvJacHcurlFaceImpl;
4435
4436template <>
4439
4440 OpSetInvJacHcurlFaceImpl(boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4442 invJacPtr(inv_jac_ptr) {}
4443
4444 MoFEMErrorCode doWork(int side, EntityType type,
4446
4447protected:
4448 boost::shared_ptr<MatrixDouble> invJacPtr;
4450};
4451
4452template <>
4454 using OpSetInvJacHcurlFaceImpl<2>::OpSetInvJacHcurlFaceImpl;
4455 MoFEMErrorCode doWork(int side, EntityType type,
4457};
4458
4461
4462/**
4463 * @brief Make Hdiv space from Hcurl space in 2d
4464 * @ingroup mofem_forces_and_sources_tri_element
4465 */
4475
4476/** \brief Transform Hcurl base fluxes from reference element to physical
4477 * triangle
4478 */
4480
4481/** \brief Apply contravariant (Piola) transfer to Hdiv space on face
4482 *
4483 * Covariant Piola transformation
4484 \f[
4485 \psi_i|_t = J^{-1}_{ij}\hat{\psi}_j\\
4486 \left.\frac{\partial \psi_i}{\partial \xi_j}\right|_t
4487 = J^{-1}_{ik}\frac{\partial \hat{\psi}_k}{\partial \xi_j}
4488 \f]
4489
4490 */
4491template <>
4494
4496 boost::shared_ptr<MatrixDouble> inv_jac_ptr);
4497
4498 MoFEMErrorCode doWork(int side, EntityType type,
4500
4501private:
4502 boost::shared_ptr<MatrixDouble> invJacPtr;
4503
4506};
4507
4510
4511/** \brief Apply contravariant (Piola) transfer to Hdiv space on face
4512 *
4513 * \note Hdiv space is generated by Hcurl space in 2d.
4514 *
4515 * Contravariant Piola transformation
4516 * \f[
4517 * \psi_i|_t = \frac{1}{\textrm{det}(J)}J_{ij}\hat{\psi}_j\\
4518 * \left.\frac{\partial \psi_i}{\partial \xi_j}\right|_t
4519 * =
4520 * \frac{1}{\textrm{det}(J)}J_{ik}\frac{\partial \hat{\psi}_k}{\partial \xi_j}
4521 * \f]
4522 *
4523 * \ingroup mofem_forces_and_sources
4524 *
4525 */
4527
4528template <>
4531
4533 boost::shared_ptr<MatrixDouble> jac_ptr)
4535 jacPtr(jac_ptr) {}
4536
4537 MoFEMErrorCode doWork(int side, EntityType type,
4539
4540protected:
4541 boost::shared_ptr<MatrixDouble> jacPtr;
4544};
4545
4546template <>
4550 2>::OpSetContravariantPiolaTransformOnFace2DImpl;
4551
4552 MoFEMErrorCode doWork(int side, EntityType type,
4554};
4555
4560
4561/**@}*/
4562
4563/** \name Operators for edges */
4564
4565/**@{*/
4566
4576
4577/**
4578 * @deprecated Name is deprecated and this is added for backward compatibility
4579 */
4582
4583/**@}*/
4584
4585/** \name Operator for fat prisms */
4586
4587/**@{*/
4588
4589/**
4590 * @brief Operator for fat prism element updating integration weights in the
4591 * volume.
4592 *
4593 * Jacobian on the distorted element is nonconstant. This operator updates
4594 * integration weight on prism to take into account nonconstat jacobian.
4595 *
4596 * \f[
4597 * W_i = w_i \left( \frac{1}{2V} \left\| \frac{\partial \mathbf{x}}{\partial
4598 * \pmb\xi} \right\| \right)
4599 * \f]
4600 * where \f$w_i\f$ is integration weight at integration point \f$i\f$,
4601 * \f$\mathbf{x}\f$ is physical coordinate, and \f$\pmb\xi\f$ is reference
4602 * element coordinate.
4603 *
4604 */
4614
4615/** \brief Calculate inverse of jacobian for face element
4616
4617 It is assumed that face element is XY plane. Applied
4618 only for 2d problems.
4619
4620 FIXME Generalize function for arbitrary face orientation in 3d space
4621 FIXME Calculate to Jacobins for two faces
4622
4623 \ingroup mofem_forces_and_sources_prism_element
4624
4625*/
4628
4629 OpCalculateInvJacForFatPrism(boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4631 invJacPtr(inv_jac_ptr), invJac(*invJacPtr) {}
4632
4636 MoFEMErrorCode doWork(int side, EntityType type,
4638
4639private:
4640 const boost::shared_ptr<MatrixDouble> invJacPtr;
4642};
4643
4644/** \brief Transform local reference derivatives of shape functions to global
4645derivatives
4646
4647FIXME Generalize to curved shapes
4648FIXME Generalize to case that top and bottom face has different shape
4649
4650\ingroup mofem_forces_and_sources_prism_element
4651
4652*/
4655
4656 OpSetInvJacH1ForFatPrism(boost::shared_ptr<MatrixDouble> inv_jac_ptr)
4658 invJacPtr(inv_jac_ptr), invJac(*invJacPtr) {}
4659
4663
4664 MoFEMErrorCode doWork(int side, EntityType type,
4666
4667private:
4668 const boost::shared_ptr<MatrixDouble> invJacPtr;
4671};
4672
4673// Flat prism
4674
4675/** \brief Calculate inverse of jacobian for face element
4676
4677 It is assumed that face element is XY plane. Applied
4678 only for 2d problems.
4679
4680 FIXME Generalize function for arbitrary face orientation in 3d space
4681 FIXME Calculate to Jacobins for two faces
4682
4683 \ingroup mofem_forces_and_sources_prism_element
4684
4685*/
4698
4699/** \brief Transform local reference derivatives of shape functions to global
4700derivatives
4701
4702FIXME Generalize to curved shapes
4703FIXME Generalize to case that top and bottom face has different shape
4704
4705\ingroup mofem_forces_and_sources_prism_element
4706
4707*/
4722
4723/**@}*/
4724
4725/** \name Operation on matrices at integration points */
4726
4727/**@{*/
4728
4729/**
4730 * @brief Operator for inverting matrices at integration points
4731 *
4732 * This template structure computes the inverse of square matrices and their
4733 * determinants at integration points. It's commonly used in finite element
4734 * methods for coordinate transformations, constitutive relations, and other
4735 * matrix operations requiring matrix inversion.
4736 *
4737 * @tparam DIM Dimension of the square matrix to be inverted
4738 */
4739template <int DIM>
4741
4742 /**
4743 * @brief Constructor for matrix inversion operator
4744 *
4745 * @param in_ptr Shared pointer to input matrix to be inverted
4746 * @param det_ptr Shared pointer to vector for storing matrix determinants
4747 * @param out_ptr Shared pointer to output matrix for storing inverted matrices
4748 */
4749 template <typename T>
4750 OpInvertMatrix(boost::shared_ptr<MatrixDouble> in_ptr,
4751 boost::shared_ptr<T> det_ptr,
4752 boost::shared_ptr<MatrixDouble> out_ptr)
4754 outPtr(out_ptr), detPtrVariant(det_ptr) {}
4755
4756 MoFEMErrorCode doWork(int side, EntityType type,
4758
4759private:
4760 boost::shared_ptr<MatrixDouble> inPtr;
4761 boost::shared_ptr<MatrixDouble> outPtr;
4762 std::variant<boost::shared_ptr<VectorDouble>, boost::shared_ptr<MatrixDouble>>
4764};
4765
4766template <int DIM>
4770
4771#ifndef NDEBUG
4772 if (!inPtr)
4773 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4774 "Pointer for inPtr matrix not allocated");
4775
4776 if (!std::holds_alternative<boost::shared_ptr<VectorDouble>>(detPtrVariant) &&
4777 !std::holds_alternative<boost::shared_ptr<MatrixDouble>>(detPtrVariant)) {
4778 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4779 "detPtrVariant must hold either VectorDouble or MatrixDouble");
4780 }
4781#endif
4782 const auto nb_integration_pts = inPtr->size1();
4783
4784#ifndef NDEBUG
4785 const auto nb_rows = inPtr->size2();
4786 if (nb_rows != DIM * DIM)
4787 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4788 "Wrong number of matrix coefficients");
4789#endif
4790
4791 std::visit(
4792 [&](auto ptr) {
4793 using T = std::decay_t<decltype(ptr)>;
4794
4795 if constexpr (std::is_same_v<T, boost::shared_ptr<VectorDouble>>) {
4796 ptr->resize(nb_integration_pts, false);
4797 } else if constexpr (std::is_same_v<T, boost::shared_ptr<MatrixDouble>>) {
4798 ptr->resize(nb_integration_pts, 1, false);
4799 }
4800 },
4801 detPtrVariant);
4802
4804 auto get_in_at_pts =
4805 MatrixSizeHelper<GetFTensor2FromMatType<DIM, DIM, -1, DL>, DL>::get(
4806 *inPtr, nb_integration_pts);
4807
4808 // Calculate determinant
4809 {
4810 auto t_in_at_pts = get_in_at_pts();
4811 auto det_it = std::visit(
4812 [](auto p) -> std::vector<double>::iterator {
4813 return p->data().begin();
4814 },
4815 detPtrVariant);
4816 for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
4817 *det_it = determinantTensor(t_in_at_pts);
4818 ++t_in_at_pts;
4819 ++det_it;
4820 }
4821 }
4822
4823 // Invert jacobian
4824 if (outPtr) {
4825 auto get_out_at_pts =
4826 MatrixSizeHelper<GetFTensor2FromMatType<DIM, DIM, -1, DL>, DL>::size(
4827 *outPtr, nb_integration_pts);
4828 auto t_in_at_pts = get_in_at_pts();
4829 auto t_out_at_pts = get_out_at_pts();
4830 auto det_it = std::visit(
4831 [](auto p) -> std::vector<double>::iterator {
4832 return p->data().begin();
4833 },
4834 detPtrVariant);
4835 for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
4836 CHKERR invertTensor(t_in_at_pts, *det_it, t_out_at_pts);
4837 ++t_in_at_pts;
4838 ++t_out_at_pts;
4839 ++det_it;
4840 }
4841 }
4842
4844}
4845
4846/**@}*/
4847
4848/**
4849 * @brief Operator for calculating the trace of matrices at integration points
4850 *
4851 * This template structure computes the trace (sum of diagonal elements) of
4852 * square matrices at integration points. The trace is commonly used in
4853 * mechanics for calculating volumetric strain, pressure, and other scalar
4854 * quantities derived from tensors.
4855 *
4856 * @tparam DIM Dimension of the square matrix
4857 *
4858 * @ingroup mofem_forces_and_sources
4859 */
4860template <int DIM>
4862
4863 /**
4864 * @brief Constructor for matrix trace calculation operator
4865 *
4866 * @param in_ptr Shared pointer to input matrix for trace calculation
4867 * @param out_ptr Shared pointer to output vector for storing calculated traces
4868 */
4869 OpCalculateTraceFromMat(boost::shared_ptr<MatrixDouble> in_ptr,
4870 boost::shared_ptr<VectorDouble> out_ptr)
4872 outPtr(out_ptr) {}
4873
4874 MoFEMErrorCode doWork(int side, EntityType type,
4876
4877private:
4879 boost::shared_ptr<MatrixDouble> inPtr;
4880 boost::shared_ptr<VectorDouble> outPtr;
4881};
4882
4883template <int DIM>
4888
4889 if (!inPtr)
4890 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4891 "Pointer for inPtr matrix not allocated");
4892
4893 const auto nb_integration_pts = inPtr->size1();
4894 // Invert jacobian
4895 if (outPtr) {
4897 auto get_in_at_pts =
4898 MatrixSizeHelper<GetFTensor2FromMatType<DIM, DIM, -1, DL>, DL>::get(
4899 *inPtr, nb_integration_pts);
4900 outPtr->resize(nb_integration_pts, false);
4901 auto t_in_at_pts = get_in_at_pts();
4902 auto t_out = getFTensor0FromVec(*outPtr);
4903
4904 for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
4905 t_out = t_in_at_pts(i, i);
4906 ++t_in_at_pts;
4907 ++t_out;
4908 }
4909 }
4910
4912}
4913
4914/**@}*/
4915
4916/** \brief Calculates the trace of an input matrix
4917
4918\ingroup mofem_forces_and_sources
4919
4920*/
4921
4922template <int DIM>
4925
4926 OpCalculateTraceFromSymmMat(boost::shared_ptr<MatrixDouble> in_ptr,
4927 boost::shared_ptr<VectorDouble> out_ptr)
4929 outPtr(out_ptr) {}
4930
4931 MoFEMErrorCode doWork(int side, EntityType type,
4933
4934private:
4936 boost::shared_ptr<MatrixDouble> inPtr;
4937 boost::shared_ptr<VectorDouble> outPtr;
4938};
4939
4940template <int DIM>
4945
4946 if (!inPtr)
4947 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
4948 "Pointer for inPtr matrix not allocated");
4949
4950 const auto nb_integration_pts = inPtr->size1();
4951 // Invert jacobian
4952 if (outPtr) {
4953 outPtr->resize(nb_integration_pts, false);
4955 auto get_in_at_pts =
4957 DL>::get(*inPtr, nb_integration_pts);
4958 auto t_in_at_pts = get_in_at_pts();
4959 auto t_out = getFTensor0FromVec(*outPtr);
4960
4961 for (size_t gg = 0; gg != nb_integration_pts; ++gg) {
4962 t_out = t_in_at_pts(i, i);
4963 ++t_in_at_pts;
4964 ++t_out;
4965 }
4966 }
4967
4969}
4970
4971} // namespace MoFEM
4972
4973#endif // __USER_DATA_OPERATORS_HPP__
4974
4975/**
4976 * \defgroup mofem_forces_and_sources_user_data_operators Users Operators
4977 *
4978 * \brief Classes and functions used to evaluate fields at integration pts,
4979 *jacobians, etc..
4980 *
4981 * \ingroup mofem_forces_and_sources
4982 **/
std::vector< int > size
std::vector< std::array< double, 3 > > coordinates
std::string type
It it
Definition Schur.cpp:2568
It end
Definition Schur.cpp:2568
#define FTENSOR_INDEXES(DIM,...)
std::string name
constexpr int SPACE_DIM
Kronecker Delta class symmetric.
Tensor1< T, Tensor_Dim > normalize()
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
static const char *const CoordinateTypesNames[]
Coordinate system names.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
FieldSpace
approximation spaces
Definition definitions.h:82
@ L2
field with C-1 continuity
Definition definitions.h:88
@ H1
continuous field
Definition definitions.h:85
@ NOSPACE
Definition definitions.h:83
@ HCURL
field with continuous tangents
Definition definitions.h:86
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
CoordinateTypes
Coodinate system.
@ CYLINDRICAL
@ POLAR
@ CARTESIAN
@ SPHERICAL
#define DEPRECATED
Definition definitions.h:17
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
constexpr int BASE_DIM
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition DMMoFEM.cpp:451
NumeredDofEntity_multiIndex::index< Unique_mi_tag >::type NumeredDofEntityByUId
Numbered DoF multi-index by UId.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
VecAllocator< double > DoubleAllocator
Definition Types.hpp:62
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
decltype(GetFTensor2SymmetricFromMatImpl< Tensor_Dim, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor2SymmetricFromMatType
static auto getFTensor3DgFromMat(M &data)
Get symmetric tensor rank 3 on the first two indices from form data matrix.
static MoFEMErrorCode invertTensor(FTensor::Tensor2< T1, DIM, DIM > &t, T2 &det, FTensor::Tensor2< T3, DIM, DIM > &inv_t)
static auto determinantTensor(FTensor::Tensor2< T, DIM, DIM > &t)
Calculate the determinant of a tensor of rank DIM.
OpCalculateScalarFieldValuesFromPetscVecImpl< PetscData::CTX_SET_X_T > OpCalculateScalarFieldValuesDot
decltype(GetFTensor1FromMatImpl< Tensor_Dim, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor1FromMatType
static auto getFTensor0FromVec(V &data)
Get tensor rank 0 (scalar) form data vector.
decltype(GetFTensor3FromMatImpl< Tensor_Dim0, Tensor_Dim1, Tensor_Dim2, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor3FromMatType
decltype(GetFTensor2FromMatImpl< Tensor_Dim0, Tensor_Dim1, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor2FromMatType
constexpr IntegrationType I
constexpr AssemblyType A
double scale
Definition plastic.cpp:124
constexpr auto field_name
multi_index_container< DofsSideMapData, indexed_by< ordered_non_unique< tag< TypeSide_mi_tag >, composite_key< DofsSideMapData, member< DofsSideMapData, EntityType, &DofsSideMapData::type >, member< DofsSideMapData, int, &DofsSideMapData::side > > >, ordered_unique< tag< EntDofIdx_mi_tag >, member< DofsSideMapData, int, &DofsSideMapData::dof > > > > DofsSideMap
Map entity stype and side to element/entity dof index.
std::array< bool, MBMAXTYPE > doEntities
If true operator is executed for entity.
virtual MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Operator for bi-linear form, usually to calculate values on left hand side.
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor2< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 >, Tensor_Dim0, Tensor_Dim1 > getFTensor2DiffN(FieldApproximationBase base)
Get derivatives of base functions for Hdiv space.
auto getFTensor2SymmetricFieldData()
Return symmetric FTensor rank 2, i.e. matrix from field data coefficients.
auto getFTensor2FieldData()
Return FTensor rank 2, i.e. matrix from field data coefficients.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
MatrixDouble & getDiffN(const FieldApproximationBase base)
get derivatives of base functions
const VectorFieldEntities & getFieldEntities() const
Get field entities (const version)
auto getFTensor1FieldData()
Return FTensor of rank 1, i.e. vector from field data coefficients.
auto getFTensor2N(FieldApproximationBase base)
Get base functions for Hdiv/Hcurl spaces.
auto getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
Get DOF values on entity.
FTensor::Tensor3< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 *Tensor_Dim2 >, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > getFTensor3Diff2N(FieldApproximationBase base)
Get second derivatives of base functions for Hvec space.
const VectorInt & getLocalIndices() const
Get local indices of degrees of freedom on entity.
auto getFTensor1N(FieldApproximationBase base)
Get base functions for Hdiv/Hcurl spaces.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0FieldData()
Return scalar files as a FTensor of rank 0.
const VectorDofs & getFieldDofs() const
Get DOF data structures (const version)
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
FTensor::Tensor3< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 *Tensor_Dim2 >, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > getFTensor3DiffN(FieldApproximationBase base)
Get derivatives of base functions for tonsorial Hdiv space.
EntityType getFEType() const
Get dimension of finite element.
auto getFTensor1CoordsAtGaussPts()
Get coordinates at integration points assuming linear geometry.
EntityHandle getSideEntity(const int side_number, const EntityType type)
Get the side entity.
OpType
Controls loop over entities on element.
@ OPCOL
operator doWork function is executed on FE columns
@ OPROW
operator doWork function is executed on FE rows
@ OPSPACE
operator do Work is execute on space data
const FEMethod * getFEMethod() const
Return raw pointer to Finite Element Method object.
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element
structure to get information from mofem into EntitiesFieldData
Calculate divergence of tonsorial field using vectorial base.
OpCalculateBrokenHVecTensorDivergence(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, EntityType broken_type, boost::shared_ptr< Range > broken_range_ptr=nullptr, boost::shared_ptr< double > scale_ptr=nullptr, const EntityType zero_type=MBEDGE)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Get tensor field for H-div approximation.
boost::shared_ptr< MatrixDouble > dataPtr
OpCalculateBrokenHVecTensorField(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, EntityType broken_type, boost::shared_ptr< Range > broken_range_ptr=nullptr, boost::shared_ptr< double > scale_ptr=nullptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Calculate values of vector field at integration points.
Calculate divergence of vector field at integration points.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateDivergenceVectorFieldValues(const std::string field_name, boost::shared_ptr< VectorDouble > data_ptr, const EntityType zero_type=MBVERTEX)
Constructor for vector field divergence calculation operator.
Approximate tensor field values for a given PETSc vector on a tensor basis.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHTensorTensorFieldFromPetscVecImpl(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0, bool throw_error=true)
Calculate tenor field using tensor base, i.e. Hdiv/Hcurl.
VectorDouble dotVector
Keeps temporary values of time derivatives.
OpCalculateHTensorTensorField(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, boost::shared_ptr< double > scale_ptr, SmartPetscObj< Vec > data_vec=SmartPetscObj< Vec >(), const EntityType zero_type=MBEDGE, const int zero_side=0)
boost::shared_ptr< MatrixDouble > dataPtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHTensorTensorField(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
Calculate divergence of tonsorial field using vectorial base.
boost::shared_ptr< MatrixDouble > dataPtr
VectorDouble dotVector
Keeps temporary values of time derivatives.
OpCalculateHVecTensorDivergence(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHVecTensorDivergence(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
Approximate Hdiv/Hcurl tensor field values for a given PETSc vector.
OpCalculateHVecTensorFieldFromPetscVecImpl(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Calculate tenor field using vectorial base, i.e. Hdiv/Hcurl.
OpCalculateHVecTensorField(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, boost::shared_ptr< double > scale_ptr, SmartPetscObj< Vec > data_vec=SmartPetscObj< Vec >(), const EntityType zero_type=MBEDGE, const int zero_side=0)
boost::shared_ptr< MatrixDouble > dataPtr
OpCalculateHVecTensorField(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
VectorDouble dotVector
Keeps temporary values of time derivatives.
boost::shared_ptr< double > scalePtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHVecTensorGradient(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
OpCalculateHVecTensorGradient(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Calculate gradient of tensor field.
Calculate trace of vector (Hdiv/Hcurl) space.
boost::shared_ptr< MatrixDouble > dataPtr
boost::shared_ptr< double > scalePtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
OpCalculateHVecTensorTrace(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
FTensor::Index< 'j', Tensor_Dim > j
FTensor::Index< 'i', Tensor_Dim > i
OpCalculateHVecTensorTrace(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, boost::shared_ptr< double > scale_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
OpCalculateHVecVectorFieldDot(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
Get vector field for H-div approximation.
OpCalculateHVecVectorField_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
OpCalculateHVecVectorField_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0)
Get vector field for H-div approximation.
Get vector field for H-div approximation.
Calculate gradient of vector field.
boost::shared_ptr< MatrixDouble > dataPtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHVecVectorGradient(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
Calculate gradient of vector field.
boost::shared_ptr< MatrixDouble > dataPtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateHVecVectorHessian(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
boost::shared_ptr< MatrixDouble > dataPtr
boost::shared_ptr< MatrixDouble > dataPtr
boost::shared_ptr< MatrixDouble > dataPtr
Calculate curl of vector field.
Calculate divergence of vector field dot.
boost::shared_ptr< VectorDouble > dataPtr
OpCalculateHdivVectorDivergenceDot(const std::string field_name, boost::shared_ptr< VectorDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Calculate divergence of vector field.
boost::shared_ptr< VectorDouble > dataPtr
OpCalculateHdivVectorDivergence(const std::string field_name, boost::shared_ptr< VectorDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Calculate inverse of jacobian for face element.
OpCalculateInvJacForFatPrism(MatrixDouble &inv_jac)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateInvJacForFatPrism(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
const boost::shared_ptr< MatrixDouble > invJacPtr
Calculate inverse of jacobian for face element.
OpCalculateInvJacForFlatPrism(MatrixDouble &inv_jac_f3)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Evaluate field gradient values for scalar field, i.e. gradient is tensor rank 1 (vector)
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Evaluate field gradient values for scalar field, i.e. gradient is tensor rank 1 (vector),...
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate gradient values of scalar field at integration points
Calculate scalar field values from PETSc vector at integration points.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateScalarFieldValuesFromPetscVecImpl(const std::string field_name, boost::shared_ptr< VectorDouble > data_ptr, const EntityType zero_at_type=MBVERTEX)
Constructor for PETSc vector-based scalar field calculation.
Scalar field values at integration points.
OpCalculateScalarFieldValues_General(const std::string field_name, boost::shared_ptr< ublas::vector< T, A > > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX)
OpCalculateScalarFieldValues_General(SmartPetscObj< DM > data_dm, const ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, boost::shared_ptr< ublas::vector< T, A > > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX)
Constructor with PETSc vector support for a different problem layout.
boost::shared_ptr< ublas::vector< T, A > > dataPtr
OpCalculateScalarFieldValues_General(const ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, boost::shared_ptr< ublas::vector< T, A > > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX)
Constructor with PETSc vector support.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of scalar field at integration points
OpCalculateScalarFieldValues_General(const std::string field_name, boost::shared_ptr< ublas::vector< T, A > > data_ptr, const EntityType zero_type=MBVERTEX)
Constructor for scalar field values calculation operator.
Specialization for double precision scalar field values calculation.
MoFEMErrorCode doWork(int, EntityType type, EntitiesFieldData::EntData &data)
calculate values of scalar field at integration points
Get time direvarive values at integration pts for tensor field rank 2, i.e. matrix field.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateTensor2FieldValuesDot(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_at_type=MBVERTEX)
EntityType zeroAtType
Zero values at Gauss point at this type.
VectorDouble dotVector
Keeps temporary values of time derivatives.
boost::shared_ptr< MatrixDouble > dataPtr
Data computed into this matrix.
OpCalculateTensor2FieldValues_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBVERTEX)
OpCalculateTensor2FieldValues_General(ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX)
OpCalculateTensor2FieldValues_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX)
Calculate field values for tenor field rank 2.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateTensor2FieldValues_General(const std::string field_name, boost::shared_ptr< M > data_ptr, const EntityType zero_type=MBVERTEX)
Get values at integration pts for tensor field rank 2, i.e. matrix field.
OpCalculateTensor2SymmetricDeviatorFieldValues_General(const std::string field_name, MatrixPtr data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
OpCalculateTensor2SymmetricDeviatorFieldValues_General(SmartPetscObj< DM > data_dm, const ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, MatrixPtr data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0, MatrixPtr coordinates=nullptr)
OpCalculateTensor2SymmetricDeviatorFieldValues_General(const std::string field_name, MatrixPtr data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0, MatrixPtr coordinates=nullptr)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data) override
Operator for linear form, usually to calculate values on right hand side.
OpCalculateTensor2SymmetricFieldGradient_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBVERTEX)
Evaluate field gradient values for symmetric 2nd order tensor field, i.e. gradient is tensor rank 3.
OpCalculateTensor2SymmetricFieldGradient_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBVERTEX)
Get field gradients at integration pts for symmetric tensorial field rank 2.
OpCalculateTensor2SymmetricFieldGradient(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBVERTEX)
Calculate symmetric tensor field rates ant integratio pts.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateTensor2SymmetricFieldValuesDot(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
Calculate symmetric tensor field values at integration pts.
OpCalculateTensor2SymmetricFieldValues(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0)
OpCalculateTensor2SymmetricFieldValues(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBEDGE, const int zero_side=0)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateTensor2SymmetricFieldValues(SmartPetscObj< DM > data_dm, const ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBEDGE, const int zero_side=0)
Operator for calculating the trace of matrices at integration points.
boost::shared_ptr< MatrixDouble > inPtr
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
boost::shared_ptr< VectorDouble > outPtr
OpCalculateTraceFromMat(boost::shared_ptr< MatrixDouble > in_ptr, boost::shared_ptr< VectorDouble > out_ptr)
Constructor for matrix trace calculation operator.
Calculates the trace of an input matrix.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
boost::shared_ptr< VectorDouble > outPtr
boost::shared_ptr< MatrixDouble > inPtr
OpCalculateTraceFromSymmMat(boost::shared_ptr< MatrixDouble > in_ptr, boost::shared_ptr< VectorDouble > out_ptr)
Get field gradients time derivative at integration pts for scalar field rank 0, i....
boost::shared_ptr< MatrixDouble > dataPtr
Data computed into this matrix.
OpCalculateVectorFieldGradientDot(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_at_type=MBVERTEX)
EntityType zeroAtType
Zero values at Gauss point at this type.
VectorDouble dotVector
Keeps temporary values of time derivatives.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Evaluate field gradient values for vector field, i.e. gradient is tensor rank 2.
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of vector field at integration points
Approximate field values for given petsc vector.
OpCalculateVectorFieldValuesFromPetscVecImpl(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_at_type=MBVERTEX, bool throw_error=true)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpCalculateVectorFieldValues_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX, const int max_order=-1)
OpCalculateVectorFieldValues_General(const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, const EntityType zero_type=MBVERTEX, const int max_order=-1)
OpCalculateVectorFieldValues_General(SmartPetscObj< DM > data_dm, const ForcesAndSourcesCore::UserDataOperator::OpType op_type, const std::string field_name, boost::shared_ptr< MatrixDouble > data_ptr, SmartPetscObj< Vec > data_vec, const EntityType zero_type=MBVERTEX, const int max_order=-1)
Calculate field values for tensor field rank 1, i.e. vector field.
OpCalculateVectorFieldValues_General(const std::string field_name, boost::shared_ptr< M > data_ptr, const EntityType zero_type=MBVERTEX)
Constructor for vector field values calculation operator.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
calculate values of vector field at integration points
Specialization for MatrixDouble vector field values calculation.
Operator for inverting matrices at integration points.
OpInvertMatrix(boost::shared_ptr< MatrixDouble > in_ptr, boost::shared_ptr< T > det_ptr, boost::shared_ptr< MatrixDouble > out_ptr)
Constructor for matrix inversion operator.
boost::shared_ptr< MatrixDouble > outPtr
boost::shared_ptr< MatrixDouble > inPtr
std::variant< boost::shared_ptr< VectorDouble >, boost::shared_ptr< MatrixDouble > > detPtrVariant
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Make Hdiv space from Hcurl space in 2d.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Operator for fat prism element updating integration weights in the volume.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Operator for scaling matrix values by a scalar factor.
boost::shared_ptr< MatrixDouble > outMat
DEPRECATED OpScaleMatrix(const std::string field_name, const double scale, boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat)
boost::shared_ptr< double > scalePtr
OpScaleMatrix(boost::shared_ptr< double > scale_ptr, boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat)
Constructor for matrix scaling operator.
boost::shared_ptr< MatrixDouble > inMat
MoFEMErrorCode doWork(int, EntityType, EntData &)
Operator for linear form, usually to calculate values on right hand side.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpSetContravariantPiolaTransformOnEdge2D(const FieldSpace space=HCURL)
OpSetContravariantPiolaTransformOnFace2DImpl(boost::shared_ptr< MatrixDouble > jac_ptr)
Apply contravariant (Piola) transfer to Hdiv space on face.
Apply contravariant (Piola) transfer to Hdiv space on face.
Transform Hcurl base fluxes from reference element to physical triangle.
OpSetInvJacH1ForFaceEmbeddedIn3DSpace(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
OpSetInvJacH1ForFace(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
Transform local reference derivatives of shape functions to global derivatives.
const boost::shared_ptr< MatrixDouble > invJacPtr
OpSetInvJacH1ForFatPrism(MatrixDouble &inv_jac)
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpSetInvJacH1ForFatPrism(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
Transform local reference derivatives of shape functions to global derivatives.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
OpSetInvJacH1ForFlatPrism(MatrixDouble &inv_jac_f3)
boost::shared_ptr< MatrixDouble > invJacPtr
OpSetInvJacHcurlFaceImpl(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
Transform local reference derivatives of shape function to global derivatives for face.
OpSetInvJacL2ForFaceEmbeddedIn3DSpace(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
OpSetInvJacL2ForFace(boost::shared_ptr< MatrixDouble > inv_jac_ptr)
Transform local reference derivatives of shape functions to global derivatives.
MoFEMErrorCode applyTransform(MatrixDouble &diff_n)
Apply transformation to the input matrix.
OpSetInvJacToScalarBasesBasic(FieldSpace space, boost::shared_ptr< MatrixDouble > inv_jac_ptr)
boost::shared_ptr< MatrixDouble > invJacPtr
Operator for symmetrizing tensor fields.
FTensor::Index< 'i', DIM > i
boost::shared_ptr< MatrixDouble > outMat
OpSymmetrizeTensor(boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat)
Constructor for tensor symmetrization operator.
MoFEMErrorCode doWork(int, EntityType, EntData &)
Operator for linear form, usually to calculate values on right hand side.
FTensor::Index< 'j', DIM > j
DEPRECATED OpSymmetrizeTensor(const std::string field_name, boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat)
boost::shared_ptr< MatrixDouble > inMat
boost::shared_ptr< MatrixDouble > dMat
OpTensorTimesSymmetricTensor(boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat, boost::shared_ptr< MatrixDouble > d_mat)
boost::shared_ptr< MatrixDouble > inMat
MoFEMErrorCode doWork(int, EntityType, EntData &)
Operator for linear form, usually to calculate values on right hand side.
DEPRECATED OpTensorTimesSymmetricTensor(const std::string field_name, boost::shared_ptr< MatrixDouble > in_mat, boost::shared_ptr< MatrixDouble > out_mat, boost::shared_ptr< MatrixDouble > d_mat)
boost::shared_ptr< MatrixDouble > outMat
static constexpr Switches CtxSetX
Solution vector switch.
static constexpr Switches CtxSetX_TT
Second time derivative switch.
std::bitset< 8 > Switches
Bitset type for context switches.
static constexpr Switches CtxSetX_T
First time derivative switch.
@ CTX_SET_X_T
Time derivative X_t is set.
@ CTX_SET_DX
Solution increment DX is set.
@ CTX_SET_X
Solution vector X is set.
@ CTX_SET_X_TT
Second time derivative X_tt is set.
keeps basic data about problem
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredRowDofsPtr
store DOFs on rows for this problem
boost::shared_ptr< NumeredDofEntity_multiIndex > numeredColDofsPtr
store DOFs on columns for this problem
intrusive_ptr for managing petsc objects
static FTensor::Tensor2_symmetric< double, 3 > getTensor(const FTensor::Tensor1< T, Size > &t_coordinates, const double theta=0.)
Reconstruct D + theta*I/3; input may be an owning tensor or a view.
static FTensor::Tensor1< double, 5 > getCoordinates(const Tensor &t_tensor)
Project a full or symmetric tensor onto the five orthonormal columns.
static const FTensor::Dg< double, 3, 5 > & getBasis()
Basis columns (11-22)/sqrt(2), (11+22-2*33)/sqrt(6), 12, 13, 23.