tetra_element_linear.h
Go to the documentation of this file.
1 //
2 // This file is part of the FFEA simulation package
3 //
4 // Copyright (c) by the Theory and Development FFEA teams,
5 // as they appear in the README.md file.
6 //
7 // FFEA is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // FFEA is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with FFEA. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // To help us fund FFEA development, we humbly ask that you cite
21 // the research papers on the package.
22 //
23 
24 /*
25  * tetra_element_linear.hpp
26  */
27 
28 #ifndef TETRA_ELEMENT_LINEAR_H_INCLUDED
29 #define TETRA_ELEMENT_LINEAR_H_INCLUDED
30 
31 #include <stddef.h>
32 #include <stdio.h>
33 #include <map>
34 #include "mat_vec_fns.h"
35 #include "SimulationParams.h"
36 #include "FFEA_return_codes.h"
37 #include "RngStream.h"
38 #include "SecondOrderFunctions.h"
39 #include "PoissonMatrixQuadratic.h"
40 #include "MassMatrixLinear.h"
41 #include "MassMatrixQuadratic.h"
42 
43 class Blob;
44 
45 #define NUM_NODES_LINEAR_TET 4
46 #define NUM_NODES_QUADRATIC_TET 10
47 
48 /*
49  * A preprocessor macro generating code that calculates a submatrix of the bulk viscous
50  * matrix. 'I' specifies what position in the matrix 'V' this 4x4 submatrix should be
51  * inserted to (position I,I in the matrix).
52  *
53  * N.B. This macro only deals with submatrices *on the diagonal* of the bulk viscous matrix.
54  */
55 #define BULK_VISCOUS_SUBMATRIX_DIAG(V,I) \
56  V[I + 0][I + 0] = dpsi[I + 0] * dpsi[I + 0] * (A + B); \
57  V[I + 1][I + 1] = dpsi[I + 1] * dpsi[I + 1] * (A + B); \
58  V[I + 2][I + 2] = dpsi[I + 2] * dpsi[I + 2] * (A + B); \
59  V[I + 3][I + 3] = dpsi[I + 3] * dpsi[I + 3] * (A + B); \
60  V[I + 0][I + 1] = dpsi[I + 1] * dpsi[I + 0] * (A + B); \
61  V[I + 0][I + 2] = dpsi[I + 2] * dpsi[I + 0] * (A + B); \
62  V[I + 0][I + 3] = dpsi[I + 3] * dpsi[I + 0] * (A + B); \
63  V[I + 1][I + 2] = dpsi[I + 1] * dpsi[I + 2] * (A + B); \
64  V[I + 1][I + 3] = dpsi[I + 1] * dpsi[I + 3] * (A + B); \
65  V[I + 2][I + 3] = dpsi[I + 2] * dpsi[I + 3] * (A + B);
66 
67 /*
68  * A preprocessor macro generating code that calculates a submatrix of the bulk viscous
69  * matrix. 'I' and 'J' specify what position in the matrix 'V' this 4x4 submatrix should
70  * be inserted to (position I,J in the matrix).
71  *
72  * N.B. This code will calculate submatrices anywhere in the bulk viscous matrix,
73  * but the BULK_VISCOUS_SUBMATRIX_DIAG macro above provides simpler more efficient
74  * code for the case in which the submatrix lies on the diagonal of the bulk viscous
75  * matrix.
76  */
77 #define BULK_VISCOUS_SUBMATRIX_OFFDIAG(V, I, J) \
78  K[0][0] = dpsi[I] * dpsi[J]; \
79  K[0][1] = dpsi[J + 1] * dpsi[I]; \
80  K[0][2] = dpsi[J + 2] * dpsi[I]; \
81  K[0][3] = dpsi[J + 3] * dpsi[I]; \
82  \
83  K[1][0] = dpsi[I + 1] * dpsi[J]; \
84  K[1][1] = dpsi[I + 1] * dpsi[J + 1]; \
85  K[1][2] = dpsi[I + 1] * dpsi[J + 2]; \
86  K[1][3] = dpsi[I + 1] * dpsi[J + 3]; \
87  \
88  K[2][0] = dpsi[I + 2] * dpsi[J]; \
89  K[2][1] = dpsi[I + 2] * dpsi[J + 1]; \
90  K[2][2] = dpsi[I + 2] * dpsi[J + 2]; \
91  K[2][3] = dpsi[I + 2] * dpsi[J + 3]; \
92  \
93  K[3][0] = dpsi[I + 3] * dpsi[J]; \
94  K[3][1] = dpsi[I + 3] * dpsi[J + 1]; \
95  K[3][2] = dpsi[I + 3] * dpsi[J + 2]; \
96  K[3][3] = dpsi[I + 3] * dpsi[J + 3]; \
97  \
98  V[I + 0][J + 0] = (B + A) * K[0][0]; \
99  V[I + 0][J + 1] = B * K[0][1] + A * K[1][0]; \
100  V[I + 0][J + 2] = B * K[0][2] + A * K[2][0]; \
101  V[I + 0][J + 3] = B * K[0][3] + A * K[3][0]; \
102  \
103  V[I + 1][J + 0] = B * K[1][0] + A * K[0][1]; \
104  V[I + 1][J + 1] = (B + A) * K[1][1]; \
105  V[I + 1][J + 2] = B * K[1][2] + A * K[2][1]; \
106  V[I + 1][J + 3] = B * K[1][3] + A * K[3][1]; \
107  \
108  V[I + 2][J + 0] = B * K[2][0] + A * K[0][2]; \
109  V[I + 2][J + 1] = B * K[2][1] + A * K[1][2]; \
110  V[I + 2][J + 2] = (B + A) * K[2][2]; \
111  V[I + 2][J + 3] = B * K[2][3] + A * K[3][2]; \
112  \
113  V[I + 3][J + 0] = B * K[3][0] + A * K[0][3]; \
114  V[I + 3][J + 1] = B * K[3][1] + A * K[1][3]; \
115  V[I + 3][J + 2] = B * K[3][2] + A * K[2][3]; \
116  V[I + 3][J + 3] = (B + A) * K[3][3]; \
117 
118 #define RAND(A, B) ((A) + ((B)-(A))*(rng[thread_id].RandU01()))
119 
120 #define DPSI1_DX 0
121 #define DPSI2_DX 1
122 #define DPSI3_DX 2
123 #define DPSI4_DX 3
124 #define DPSI1_DY 4
125 #define DPSI2_DY 5
126 #define DPSI3_DY 6
127 #define DPSI4_DY 7
128 #define DPSI1_DZ 8
129 #define DPSI2_DZ 9
130 #define DPSI3_DZ 10
131 #define DPSI4_DZ 11
132 
137 public:
138 
140 
141  /* Properties of this element */
149 
152 
155 
161 
163 
166 
169 
172 
175 
178 
181 
184 
185  /* Blob this element is a part of */
187 
189  int index;
190 
192 
196  scalar * get_K_alpha_element_mem_loc(int ni, int nj);
197 
199  void calculate_K_alpha();
200 
203 
204  void add_K_alpha(scalar *K, int num_nodes);
205 
207  void get_grad_phi_at_stu(vector3 &grad_phi, scalar s, scalar t, scalar u);
208 
211 
213  void calculate_jacobian(matrix3 J);
214 
216  void calc_deformation(matrix3 J);
217 
220 
238 
243 
248 
254 
255  /*
256  *
257  */
258  void add_shear_elastic_stress(matrix3 J, matrix3 stress);
259 
260  /*
261  *
262  */
263  void add_bulk_elastic_stress(matrix3 stress);
265 
273  void add_fluctuating_stress(SimulationParams *params, RngStream rng[], matrix3 stress, int thread_id);
274 
278  void apply_stress_tensor(matrix3 stress, vector12 du);
279 
284 
289 
291  void add_force_to_node(int i, vector3 *f);
292 
294  int what_node_is_this(int index);
295 
296  void print();
297  void print_viscosity_matrix();
298 
304 
305  void volume_coord_to_xyz(scalar eta0, scalar eta1, scalar eta2, scalar eta3, vector3 *r);
306 
307  void zero_force();
308 
309  void linearise_element();
310 
311  void calc_centroid();
312 
313  int get_opposite_node(int n1, int n2, int n3);
314 
316 
317 private:
318 
323 
327  void calc_del2_matrix();
328 
330 
334  };
335 
336 };
337 
338 #endif
339 
void add_element_force_vector(vector12 force)
Add this element&#39;s nodal forces to those given in the force 12-vector.
Definition: tetra_element_linear.cpp:474
void volume_coord_to_xyz(scalar eta0, scalar eta1, scalar eta2, scalar eta3, vector3 *r)
Definition: tetra_element_linear.cpp:555
int what_node_is_this(int index)
A roundabout and inefficient way of working out what node (from 0 to 9) this index corresponds to...
Definition: tetra_element_linear.cpp:499
scalar vol
The current volume of this element.
Definition: tetra_element_linear.h:171
Definition: tetra_element_linear.h:136
vector3 node_force[NUM_NODES_QUADRATIC_TET]
Store the contribution from this element to the force on each of its four nodes.
Definition: tetra_element_linear.h:165
scalar vol_0
The rest volume of this element.
Definition: tetra_element_linear.h:168
Definition: Blob.h:94
void add_bulk_elastic_stress_OLD(matrix3 stress)
scalar matrix3[3][3]
Definition: mat_vec_types.h:132
void calc_centroid()
Definition: tetra_element_linear.cpp:593
scalar * get_K_alpha_element_mem_loc(int ni, int nj)
Get the memory location of the specified element of K_alpha.
Definition: tetra_element_linear.cpp:56
Blob * daddy_blob
Definition: tetra_element_linear.h:186
void calculate_jacobian(matrix3 J)
Calculates the Jacobian matrix for this element.
Definition: tetra_element_linear.cpp:193
void get_element_velocity_vector(vector12 v)
Sets the given 12-vector to the velocities of this element&#39;s four nodes,.
Definition: tetra_element_linear.cpp:454
scalar W
Definition: tetra_element_linear.h:332
matrix12 viscosity_matrix
Viscosity Matrix for the internal forces of this element.
Definition: tetra_element_linear.h:183
void get_grad_phi_at_stu(vector3 &grad_phi, scalar s, scalar t, scalar u)
Returns the gradient of the potential at the given (s,t,u) position in the element.
Definition: tetra_element_linear.cpp:85
scalar calc_volume()
Uses above functions to get volume. Easy.
Definition: tetra_element_linear.cpp:343
PoissonMatrixQuadratic K_alpha
Definition: tetra_element_linear.h:162
void zero_force()
Definition: tetra_element_linear.cpp:561
scalar internal_stress_mag
The double contraction of the internal stress tensor, including elastic and thermal stresses...
Definition: tetra_element_linear.h:177
scalar vector12[12]
Definition: mat_vec_types.h:122
matrix3 F_ij
The gradient deformation tensor for this element (needed for potential energy calculation) ...
Definition: tetra_element_linear.h:174
Definition: MassMatrixLinear.h:33
scalar A
shear viscosity
Definition: tetra_element_linear.h:143
void calculate_K_alpha()
Calc the diffusion matrix for this element.
Definition: tetra_element_linear.cpp:61
scalar B
second coefficient of viscosity
Definition: tetra_element_linear.h:144
tetra_element_linear()
Definition: tetra_element_linear.cpp:30
scalar eta[4]
Definition: tetra_element_linear.h:333
void calc_elastic_force_vector(vector12 F)
Calculate the elastic contribution to the force.
Definition: tetra_element_linear.cpp:354
upper_triangular_matrix4 del2
The del2 matrix for this element (in upper triangular form, since it&#39;s symmetric). Used in constructing the diffusion matrix and the poisson matrix.
Definition: tetra_element_linear.h:160
void print()
Definition: tetra_element_linear.cpp:509
scalar length_of_longest_edge()
Definition: tetra_element_linear.cpp:692
void construct_element_mass_matrix(MassMatrixQuadratic *M_alpha)
Definition: tetra_element_linear.cpp:66
int index
Index of this element in the parent Blob.
Definition: tetra_element_linear.h:189
const scalar force
force = E/l
Definition: dimensions.h:37
void print_structural_details()
Prints a variety of structural details about the element to analyse it&#39;s configuration.
Definition: tetra_element_linear.cpp:333
int get_opposite_node(int n1, int n2, int n3)
Definition: tetra_element_linear.cpp:645
void add_shear_elastic_stress(matrix3 J, matrix3 stress)
Definition: tetra_element_linear.cpp:378
void add_fluctuating_stress(SimulationParams *params, RngStream rng[], matrix3 stress, int thread_id)
Given the shape function derivatives, the element volume and a random number generator, this function calculates the fluctuating stress tensor, generating a stochastic change in the nodal velocities for the element under consideration. This function will add its contribution to the given 12-vector du.
Definition: tetra_element_linear.cpp:417
scalar last_det
The last determinant of this element&#39;s transformation (used to work out whether it has inverted itsel...
Definition: tetra_element_linear.h:322
scalar matrix12[12][12]
Definition: mat_vec_types.h:127
matrix3 J_inv_0
The inverse jacobian of this element at rest.
Definition: tetra_element_linear.h:180
scalar mass
Definition: tetra_element_linear.h:148
Definition: mat_vec_types.h:142
void apply_stress_tensor(matrix3 stress, vector12 du)
Applies the given stress tensor to the shape function derivatives to get the contribution to du...
Definition: tetra_element_linear.cpp:441
Definition: RngStream.h:43
vector12 dpsi
The 12-vector containing the shape function derivatives for this element.
Definition: tetra_element_linear.h:154
scalar E
bulk modulus
Definition: tetra_element_linear.h:146
void calc_del2_matrix()
Creates del2 matrix from the shape function derivatives.
Definition: tetra_element_linear.cpp:599
int calc_shape_function_derivatives_and_volume(matrix3 J)
Inverts the given jacobian matrix J, using this to calculate the derivatives of the shape functions w...
Definition: tetra_element_linear.cpp:223
scalar rho
density
Definition: tetra_element_linear.h:142
mesh_node * n[NUM_NODES_QUADRATIC_TET]
A quadratic tetrahedron has 10 nodes. Keep pointers to the actual memory location of the nodes...
Definition: tetra_element_linear.h:151
void print_viscosity_matrix()
Definition: tetra_element_linear.cpp:520
Definition: mesh_node.h:39
Definition: MassMatrixQuadratic.h:35
Definition: SimulationParams.h:75
scalar dielectric
Definition: tetra_element_linear.h:147
void calculate_electrostatic_forces()
Calculates the force on each node of the element due to the electrostatic potential gradient there...
Definition: tetra_element_linear.cpp:109
scalar G
shear modulus
Definition: tetra_element_linear.h:145
void add_bulk_elastic_stress(matrix3 stress)
Definition: tetra_element_linear.cpp:401
void apply_element_mass_matrix(vector12 du)
Applies the mass matrix (for a linear tetrahedral element of density rho and equilibrium volume vol_0...
Definition: tetra_element_linear.cpp:534
Definition: tetra_element_linear.h:331
static const int i
index of ith thing
Definition: rod_math_v9.h:63
vector3 centroid
Definition: tetra_element_linear.h:191
#define NUM_NODES_QUADRATIC_TET
Definition: tetra_element_linear.h:46
void calc_deformation(matrix3 J)
Calculates Deformation Gradient.
Definition: tetra_element_linear.cpp:370
void create_viscosity_matrix()
Builds the viscosity matrix from the shape function derivatives, the shear and bulk viscosity constan...
Definition: tetra_element_linear.cpp:299
Definition: PoissonMatrixQuadratic.h:44
void linearise_element()
Definition: tetra_element_linear.cpp:567
Definition: mat_vec_types.h:90
void add_K_alpha(scalar *K, int num_nodes)
Definition: tetra_element_linear.cpp:76
double scalar
Definition: mat_vec_types.h:36
void add_force_to_node(int i, vector3 *f)
Add given force to the specified node of this element.
Definition: tetra_element_linear.cpp:492
void add_diffusion_matrix(matrix12 V)
Definition: tetra_element_linear.cpp:621