v0.15.5
Loading...
Searching...
No Matches
AdolCVolumeLengthQuality.cpp
Go to the documentation of this file.
1/**
2 * @file AdolCVolumeLengthQuality.cpp
3 * @brief ADOL-C implementation of the volume-length quality material
4 * @version 0.1
5 * @date 2026-04-03
6 *
7 * @copyright Copyright (c) 2026
8 *
9 */
10
11namespace AdolCOps {
12
13static const char *VolumeLengthQualityTypeNames[] = {
14 "QUALITY", "BARRIER_AND_QUALITY", "BARRIER_AND_CHANGE_QUALITY",
15 "BARRIER_AND_CHANGE_QUALITY_SCALED_BY_VOLUME"};
16
17template <int DIM>
19 using AdolCElasticImpl<DIM>::AdolCElasticImpl;
20
22
23 static inline constexpr std::array<std::array<int, 2>, 6> edgeNodes = {
24 std::array<int, 2>{0, 1}, std::array<int, 2>{0, 2},
25 std::array<int, 2>{0, 3}, std::array<int, 2>{1, 2},
26 std::array<int, 2>{1, 3}, std::array<int, 2>{2, 3}};
27
28 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
30
31 MOFEM_LOG_CHANNEL("WORLD");
32
33 PetscOptionsBegin(PETSC_COMM_WORLD, "",
34 "Get VolumeLengthQuality material options", "none");
35 CHKERR PetscOptionsEList(
36 "-volume_length_type", "Volume length quality type", "",
38 VolumeLengthQualityTypeNames[tYpe], &tYpe, PETSC_NULLPTR);
39 CHKERR PetscOptionsScalar("-volume_length_alpha",
40 "volume length alpha parameter", "", aLpha,
41 &aLpha, PETSC_NULLPTR);
42 CHKERR PetscOptionsScalar("-volume_length_gamma",
43 "volume length parameter (barrier)", "", gAmma,
44 &gAmma, PETSC_NULLPTR);
45 PetscOptionsEnd();
46
47 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "VolumeLengthQuality")
48 << " type = " << VolumeLengthQualityTypeNames[tYpe]
49 << " alpha = " << aLpha << " gamma = " << gAmma;
50
51 mFieldPtr = m_field_ptr;
52
54 };
55
56 MoFEMErrorCode setParams(EntityHandle ent, int gg) override {
58 (void)gg;
59
60 if (mFieldPtr == nullptr) {
61 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
62 "MoFEM interface pointer not set");
63 }
64
65 const EntityHandle *conn = nullptr;
66 int num_nodes = 0;
67 CHKERR mFieldPtr->get_moab().get_connectivity(ent, conn, num_nodes, true);
68 if (PetscUnlikely(num_nodes != 4)) {
69 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
70 "VolumeLengthQuality is implemented for 4-node tetrahedra only");
71 }
72
73 CHKERR mFieldPtr->get_moab().get_coords(conn, num_nodes, coordsTet.data());
74 set_param_vec(A::tAg, coordsTet.size(), coordsTet.data());
75
77 }
78
79 MoFEMErrorCode recordTape() override {
81 static_assert(DIM == 3,
82 "AdolCVolumeLengthQuality is implemented for 3D only");
83
84 A::adolcDataPtr->insertCommonData("grad", MatrixDouble(DIM * DIM, 1));
85 A::adolcDataPtr->insertCommonData("P", MatrixDouble(DIM * DIM, 1));
86 A::adolcDataPtr->insertCommonData("P_dF",
87 MatrixDouble(DIM * DIM, DIM * DIM));
88
89 A::adolcDataPtr->insertActiveData("F", MatrixDouble(DIM, DIM));
90 A::adolcDataPtr->insertDependentData("P", MatrixDouble(DIM, DIM));
91 A::adolcDataPtr->insertDependentDerivativesData(
92 "P_dF", MatrixDouble(DIM * DIM, DIM * DIM));
93
94 auto t_F = getFTensor2FromPtr<DIM, DIM>(
95 A::adolcDataPtr->getActiveDataPtr("F")->data().data());
96 auto t_P = getFTensor2FromPtr<DIM, DIM>(
97 A::adolcDataPtr->getDependentDataPtr("P")->data().data());
98
100
101 FTENSOR_INDEX(DIM, i);
102 FTENSOR_INDEX(DIM, j);
103 FTENSOR_INDEX(DIM, I);
104 FTENSOR_INDEX(DIM, J);
105
106 // That assumes that nodal positions are approximated.
107 t_F(i, J) = t_kd(i, J);
108
116
117 adouble det_aF;
118
119 trace_on(A::tAg);
120
121 std::array<adouble, 12> refCoords;
122 for (auto dd = 0; dd != 12; ++dd) {
123 refCoords[dd] = mkparam(coordsTet[dd]);
124 }
125
126 ta_F(i, J) <<= t_F(i, J);
127 det_aF = determinantTensor(ta_F);
128 CHKERR invertTensor(ta_F, det_aF, ta_invF);
129
130 const auto x00 = refCoords[0];
131 const auto x01 = refCoords[1];
132 const auto x02 = refCoords[2];
133 const auto x10 = refCoords[3];
134 const auto x11 = refCoords[4];
135 const auto x12 = refCoords[5];
136 const auto x20 = refCoords[6];
137 const auto x21 = refCoords[7];
138 const auto x22 = refCoords[8];
139 const auto x30 = refCoords[9];
140 const auto x31 = refCoords[10];
141 const auto x32 = refCoords[11];
142
143 const auto ax = x10 - x00;
144 const auto ay = x11 - x01;
145 const auto az = x12 - x02;
146
147 const auto bx = x20 - x00;
148 const auto by = x21 - x01;
149 const auto bz = x22 - x02;
150
151 const auto cx = x30 - x00;
152 const auto cy = x31 - x01;
153 const auto cz = x32 - x02;
154
155 const adouble signed_volume =
156 (ax * (by * cz - bz * cy) - ay * (bx * cz - bz * cx) +
157 az * (bx * cy - by * cx)) /
158 6.0;
159
160 dX_dChiT(i, J) = 0.0;
161
162 adouble lrms_squared = 0.0;
163 adouble lrms_squared0 = 0.0;
164
165 for (auto ee = 0; ee != 6; ++ee) {
166 for (auto dd = 0; dd != DIM; ++dd) {
167 delta_chi(dd) =
168 refCoords[3 * edgeNodes[ee][0] + dd] -
169 refCoords[3 * edgeNodes[ee][1] + dd];
170 }
171
172 delta_X(i) = ta_F(i, J) * delta_chi(J);
173
174 lrms_squared += (1. / 6.) * delta_X(i) * delta_X(i);
175 lrms_squared0 += (1. / 6.) * delta_chi(I) * delta_chi(I);
176 dX_dChiT(i, I) += delta_X(i) * delta_chi(I);
177 }
178
179 Q(i, j) = ta_invF(j, i) - 0.5 * dX_dChiT(i, j) / lrms_squared;
180
181 const adouble lrms_cubed0 = lrms_squared0 * sqrt(lrms_squared0);
182 const adouble b =
183 det_aF / (lrms_squared * sqrt(lrms_squared) / lrms_cubed0);
184 const adouble current_volume = det_aF * signed_volume;
185 const adouble q =
186 6. * sqrt(2.) * current_volume / (lrms_squared * sqrt(lrms_squared));
187
188 switch (tYpe) {
189 case QUALITY:
190 ta_P(i, J) = q * Q(i, J);
191 break;
192 case BARRIER_AND_QUALITY: {
193 const adouble t_mp = q / (1.0 - gAmma) - 1.0 / (q - gAmma);
194 ta_P(i, J) = t_mp * Q(i, J);
195 break;
196 }
198 const adouble t_mp = b / (1.0 - gAmma) - 1.0 / (b - gAmma);
199 ta_P(i, J) = t_mp * Q(i, J);
200 break;
201 }
203 adouble t_mp = current_volume;
204 t_mp *= b / (1.0 - gAmma) - 1.0 / (b - gAmma);
205 ta_P(i, J) = t_mp * Q(i, J);
206 break;
207 }
208 default:
209 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
210 "Unknown volume-length-quality type");
211 }
212
213 ta_P(i, J) *= aLpha / signed_volume;
214 ta_P(i, J) >>= t_P(i, J);
215
216 trace_off();
217
219 }
220
221protected:
223 double aLpha = 1.0;
224 double gAmma = 0.0;
225 std::array<double, 12> coordsTet = {
226
227 0.0, 0.0, 0.0,
228
229 1.0, 0.0, 0.0,
230
231 0.0, 1.0, 0.0,
232
233 0.0, 0.0, 1.0};
235};
236
237template <>
238boost::shared_ptr<PhysicalEquations>
240 boost::shared_ptr<ADolCData> adolc_data_ptr, int tag) {
241 return boost::make_shared<AdolCVolumeLengthQuality<3>>(adolc_data_ptr, tag);
242}
243
244} // namespace AdolCOps
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
#define FTENSOR_INDEX(DIM, I)
Kronecker Delta class.
#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
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
constexpr auto t_kd
#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
boost::shared_ptr< PhysicalEquations > createAdolCPhysicalEquationsPtr< ELASTICITY::VOLUMELENGTHQUALITY, MODEL_3D >(boost::shared_ptr< ADolCData > adolc_data_ptr, int tag)
static const char * VolumeLengthQualityTypeNames[]
@ LASTOP_VOLUMELENGTHQUALITYTYPE
@ BARRIER_AND_CHANGE_QUALITY
@ BARRIER_AND_CHANGE_QUALITY_SCALED_BY_VOLUME
constexpr IntegrationType I
MoFEMErrorCode setParams(EntityHandle ent, int gg) override
static constexpr std::array< std::array< int, 2 >, 6 > edgeNodes
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
boost::shared_ptr< ADolCData > adolcDataPtr
Definition AdolCOps.hpp:167
virtual moab::Interface & get_moab()=0
Deprecated interface functions.