1 #ifndef EMBEDDED_VOLUME_TOOL_H
2 #define EMBEDDED_VOLUME_TOOL_H
48 template<std::
size_t TDim >
79 const int n_dem_elements = rfluid_model_part.
Elements().size();
80 double total_volume = 0.0;
82 for (
int i = 0;
i < n_dem_elements;
i++){
87 unsigned int n_negatives = 0;
89 for (
unsigned int j = 0;
j != 4; ++
j){
90 double distance = geom[
j].FastGetSolutionStepValue(DISTANCE);
91 distances[
j] = distance;
99 if (n_negatives == 1){
101 for (
unsigned int j = 0;
j != 4; ++
j){
103 if (distances[
j] < 0.0){
104 total_volume += CalculatePyramidVolume(
j, geom, distances);
111 else if (n_negatives == 2){
113 for (
unsigned int j = 0;
j != 3; ++
j){
115 if (distances[
j] < 0.0){
117 for (
unsigned int k =
j + 1;
j != 4; ++
k){
119 if (distances[
k] < 0.0){
120 total_volume += CalculateHexahedronVolume(
j,
k, geom, distances);
135 else if (n_negatives == 3){
137 for (
unsigned int j = 0;
j != 4; ++
j){
139 if (distances[
j] >= 0.0){
140 total_volume += fabs(CalculateVol(geom)) - CalculatePyramidVolume(
j, geom, distances);
148 else if (n_negatives == 4){
149 total_volume += fabs(CalculateVol(geom));
176 virtual std::string
Info()
const
245 return CalculateVol(geom[0].
X(), geom[0].
Y(), geom[0].
Z(),
246 geom[1].
X(), geom[1].
Y(), geom[1].
Z(),
247 geom[2].
X(), geom[2].
Y(), geom[2].
Z(),
248 geom[3].
X(), geom[3].
Y(), geom[3].
Z());
254 inline double CalculateVol(
const double x0,
const double y0,
255 const double x1,
const double y1,
256 const double x2,
const double y2)
258 return 0.5 * ((
x1 - x0) * (y2 - y0) - (y1 - y0) * (
x2 - x0));
264 inline double CalculateVol(
const double x0,
const double y0,
const double z0,
265 const double x1,
const double y1,
const double z1,
266 const double x2,
const double y2,
const double z2,
267 const double x3,
const double y3,
const double z3)
269 double x10 =
x1 - x0;
270 double y10 = y1 - y0;
271 double z10 = z1 - z0;
273 double x20 =
x2 - x0;
274 double y20 = y2 - y0;
275 double z20 = z2 - z0;
277 double x30 = x3 - x0;
278 double y30 = y3 - y0;
279 double z30 = z3 - z0;
281 double detJ = x10 * y20 * z30 - x10 * y30 * z20 +
282 y10 * z20 * x30 - y10 * x20 * z30 +
283 z10 * x20 * y30 - z10 * y20 * x30;
285 return detJ * 0.1666666666666666666667;
291 inline double CalculatePyramidVolume(
const unsigned int j,
292 const Geometry<Node >&geom,
293 const array_1d<double, 4>& signed_dist)
295 array_1d<array_1d<double, 3>, 4 > coor;
296 array_1d<double, 4>
dist;
298 for (
unsigned int i = 0;
i != 4; ++
i){
299 dist[
i] = fabs(signed_dist[
i]);
302 for (
unsigned int i = 0;
i != 4; ++
i){
305 coor[
i][0] = geom[
j].X();
306 coor[
i][1] = geom[
j].Y();
307 coor[
i][2] = geom[
j].Z();
312 coor[
i][0] = (geom[
i].X() *
dist[
j] + geom[
j].X() *
dist[
i]) * sum_d_inv;
313 coor[
i][1] = (geom[
i].Y() *
dist[
j] + geom[
j].Y() *
dist[
i]) * sum_d_inv;
314 coor[
i][2] = (geom[
i].Z() *
dist[
j] + geom[
j].Z() *
dist[
i]) * sum_d_inv;
319 return fabs(CalculateVol(coor[0][0], coor[0][1], coor[0][2],
320 coor[1][0], coor[1][1], coor[1][2],
321 coor[2][0], coor[2][1], coor[2][2],
322 coor[3][0], coor[3][1], coor[3][2]));
328 inline double CalculateHexahedronVolume(
const unsigned int j,
329 const unsigned int k,
330 const Geometry<Node >&geom,
331 const array_1d<double, 4>& signed_dist)
333 array_1d<array_1d<double, 3>, 4 > coor;
334 array_1d<double, 4>
dist;
336 for (
unsigned int i = 0;
i != 4; ++
i){
337 dist[
i] = fabs(signed_dist[
i]);
340 double sub_volume = 0.0;
343 for (
unsigned int i = 0;
i != 4; ++
i){
345 if (
i !=
j &&
i !=
k){
348 coor[
d][0] = (geom[
i].X() *
dist[
j] + geom[
j].X() *
dist[
i]) * sum_d_j_inv;
349 coor[
d][1] = (geom[
i].Y() *
dist[
j] + geom[
j].Y() *
dist[
i]) * sum_d_j_inv;
350 coor[
d][2] = (geom[
i].Z() *
dist[
j] + geom[
j].Z() *
dist[
i]) * sum_d_j_inv;
351 coor[
d + 1][0] = (geom[
i].X() *
dist[
k] + geom[
k].X() *
dist[
i]) * sum_d_k_inv;
352 coor[
d + 1][1] = (geom[
i].Y() *
dist[
k] + geom[
k].Y() *
dist[
i]) * sum_d_k_inv;
353 coor[
d + 1][2] = (geom[
i].Z() *
dist[
k] + geom[
k].Z() *
dist[
i]) * sum_d_k_inv;
359 sub_volume += fabs(CalculateVol(geom[
j].
X(), geom[
j].
Y(), geom[
j].
Z(),
360 coor[1][0], coor[1][1], coor[1][2],
361 coor[2][0], coor[2][1], coor[2][2],
362 coor[3][0], coor[3][1], coor[3][2]));
364 sub_volume += fabs(CalculateVol(geom[
j].
X(), geom[
j].
Y(), geom[
j].
Z(),
365 coor[0][0], coor[0][1], coor[0][2],
366 coor[1][0], coor[1][1], coor[1][2],
367 coor[3][0], coor[3][1], coor[3][2]));
369 sub_volume += fabs(CalculateVol(geom[
k].
X(), geom[
k].
Y(), geom[
k].
Z(),
370 coor[0][0], coor[0][1], coor[0][2],
371 coor[1][0], coor[1][1], coor[1][2],
372 geom[
j].
X(), geom[
j].
Y(), geom[
j].
Z()));
374 sub_volume += fabs(CalculateVol(geom[
k].
X(), geom[
k].
Y(), geom[
k].
Z(),
375 coor[0][0], coor[0][1], coor[0][2],
376 geom[
j].
X(), geom[
j].
Y(), geom[
j].
Z(),
377 coor[3][0], coor[3][1], coor[3][2]));
429 template<std::
size_t TDim>
434 rOStream << std::endl;
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
float dist
Definition: edgebased_PureConvection.py:89
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
int d
Definition: ode_solve.py:397
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17