8 #ifndef _DEM_AUXILIARY_FUNCTIONS_H
9 #define _DEM_AUXILIARY_FUNCTIONS_H
19 namespace AuxiliaryFunctions {
21 static inline void CalculateAlphaFactor3D(
const int n_neighbours,
const double external_sphere_area,
const double total_equiv_area ,
double&
alpha) {
23 double external_polyhedron_area = 0.0;
25 switch (n_neighbours) {
28 external_polyhedron_area = 3.30797*external_sphere_area;
32 external_polyhedron_area = 2.60892*external_sphere_area;
36 external_polyhedron_area = 1.90986*external_sphere_area;
40 external_polyhedron_area = 1.78192*external_sphere_area;
44 external_polyhedron_area = 1.65399*external_sphere_area;
48 external_polyhedron_area = 1.57175*external_sphere_area;
52 external_polyhedron_area = 1.48951*external_sphere_area;
56 external_polyhedron_area = 1.40727*external_sphere_area;
60 external_polyhedron_area = 1.32503*external_sphere_area;
64 external_polyhedron_area = 1.31023*external_sphere_area;
68 external_polyhedron_area = 1.29542*external_sphere_area;
72 external_polyhedron_area = 1.28061*external_sphere_area;
76 external_polyhedron_area = 1.26580*external_sphere_area;
80 external_polyhedron_area = 1.25099*external_sphere_area;
84 external_polyhedron_area = 1.23618*external_sphere_area;
88 external_polyhedron_area = 1.22138*external_sphere_area;
92 external_polyhedron_area = 1.20657*external_sphere_area;
96 external_polyhedron_area = 1.15000*external_sphere_area;
101 alpha = external_polyhedron_area/total_equiv_area;
105 static inline void CalculateAlphaFactor2D(
const int n_neighbours,
const double external_circle_perimeter,
const double total_equiv_perimeter ,
double&
alpha) {
107 double external_polygon_perimeter = 0.0;
109 switch (n_neighbours) {
112 external_polygon_perimeter = 1.65399*external_circle_perimeter;
116 external_polygon_perimeter = 1.27324*external_circle_perimeter;
120 external_polygon_perimeter = 1.15633*external_circle_perimeter;
124 external_polygon_perimeter = 1.10266*external_circle_perimeter;
128 external_polygon_perimeter = 1.07303*external_circle_perimeter;
132 external_polygon_perimeter = 1.05479*external_circle_perimeter;
136 external_polygon_perimeter = 1.04270*external_circle_perimeter;
140 external_polygon_perimeter = 1.03425*external_circle_perimeter;
144 external_polygon_perimeter = 1.02811*external_circle_perimeter;
148 external_polygon_perimeter = 1.02349*external_circle_perimeter;
152 external_polygon_perimeter = 1.01993*external_circle_perimeter;
156 external_polygon_perimeter = 1.01713*external_circle_perimeter;
160 external_polygon_perimeter = 1.0*external_circle_perimeter;
166 alpha = external_polygon_perimeter/total_equiv_perimeter;
170 static inline void SwitchCase(
const int case_opt,
bool& delta_OPTION,
bool& continuum_simulation_OPTION) {
175 delta_OPTION =
false;
176 continuum_simulation_OPTION =
false;
181 continuum_simulation_OPTION =
false;
186 continuum_simulation_OPTION =
true;
190 delta_OPTION =
false;
191 continuum_simulation_OPTION =
true;
195 delta_OPTION =
false;
196 continuum_simulation_OPTION =
false;
203 return externally_applied_force_now;
213 double Z_coord = 0.0;
214 double RX_bottom = 0.0;
215 double RY_bottom = 0.0;
216 double RZ_bottom = 0.0;
220 double RX_average = 0.0;
221 double RY_average = 0.0;
222 double RZ_average = 0.0;
225 ElementsArrayType::iterator elem_iterator_begin = pElements.ptr_begin();
226 ElementsArrayType::iterator elem_iterator_end = pElements.ptr_end();
228 for (ElementsArrayType::iterator elem_iterator = elem_iterator_begin; elem_iterator != elem_iterator_end; ++elem_iterator) {
230 array_1d<double, 3>& reaction_force = elem_iterator->GetGeometry()[0].FastGetSolutionStepValue(FORCE_REACTION);
232 Z_coord = elem_iterator->GetGeometry()[0].Coordinates()[2];
235 if (Z_coord < 0.25) {
236 RX_bottom += reaction_force[0];
237 RY_bottom += reaction_force[1];
238 RZ_bottom += reaction_force[2];
240 RX_top += reaction_force[0];
241 RY_top += reaction_force[1];
242 RZ_top += reaction_force[2];
247 RX_average = 0.5 * (RX_bottom - RX_top);
248 RY_average = 0.5 * (RY_bottom - RY_top);
249 RZ_average = 0.5 * (RZ_bottom - RZ_top);
251 std::ofstream outputfileX(
"reaction_forces_X.txt",
std::ios_base::out | std::ios_base::app);
252 std::ofstream outputfileZ(
"reaction_forces_Z.txt",
std::ios_base::out | std::ios_base::app);
253 std::ofstream outputfileYZ(
"reaction_forces_YZ.txt",
std::ios_base::out | std::ios_base::app);
255 outputfileX <<
time <<
" " << RX_bottom <<
" " << RX_top <<
" " << RX_average <<
"\n";
256 outputfileZ <<
time <<
" " << RZ_bottom <<
" " << RZ_top <<
" " << RZ_average <<
"\n";
257 outputfileYZ <<
time <<
" " << RY_bottom <<
" " << RY_top <<
" " << RY_average <<
" " << RZ_bottom <<
" " << RZ_top <<
" " << RZ_average <<
"\n";
261 outputfileYZ.close();
266 const int dim=
A.size1();
269 const double p1 =
A(0,1)*
A(0,1) +
A(0,2)*
A(0,2) +
A(1,2)*
A(1,2);
277 const double q = 0.333333333333333333333333 * (
A(0,0) +
A(1,1) +
A(2,2));
278 const double p2 = (
A(0,0) -
q) * (
A(0,0) -
q) + (
A(1,1) -
q) * (
A(1,1) -
q) + (
A(2,2) -
q) * (
A(2,2) -
q) + 2.0 * p1;
279 const double p = sqrt(0.16666666666666666666666667 * p2);
282 const double inv_p = 1.0/
p;
285 B(0,0) = inv_p * (
A(0,0) -
q);
286 B(1,1) = inv_p * (
A(1,1) -
q);
287 B(2,2) = inv_p * (
A(2,2) -
q);
288 B(0,1) = inv_p *
A(0,1);
289 B(1,0) = inv_p *
A(1,0);
290 B(0,2) = inv_p *
A(0,2);
291 B(2,0) = inv_p *
A(2,0);
292 B(1,2) = inv_p *
A(1,2);
293 B(2,1) = inv_p *
A(2,1);
296 double r = 0.5 * (
B(0,0)*
B(1,1)*
B(2,2) +
B(0,1)*
B(1,2)*
B(2,0) +
B(1,0)*
B(2,1)*
B(0,2) -
B(2,0)*
B(1,1)*
B(0,2) -
B(1,0)*
B(0,1)*
B(2,2) -
B(0,0)*
B(2,1)*
B(1,2) );
302 else if (r >= 1) {
phi = 0.0; }
303 else {
phi = 0.333333333333333333333333 * acos(r);}
306 Result[0] =
q + 2.0 *
p * std::cos(
phi);
307 Result[2] =
q + 2.0 *
p * std::cos(
phi + (0.6666666666666666666666*
Globals::Pi));
308 Result[1] = 3.0 *
q - Result[0] - Result[2];
315 namespace DemDebugFunctions {
318 if(std::isnan(vector[0]) || std::isnan(vector[1]) || std::isnan(vector[2])){
324 static inline void CheckIfNan(
const double vector[3],
const std::string& sentence) {
326 if(std::isnan(vector[0]) || std::isnan(vector[1]) || std::isnan(vector[2])){
332 static inline void CheckIfNan(
const double& value,
const std::string& sentence) {
334 if(std::isnan(value)){
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
#define KRATOS_ERROR
Definition: exception.h:161
end_time
Definition: DEM_benchmarks.py:174
static void CalculateAlphaFactor2D(const int n_neighbours, const double external_circle_perimeter, const double total_equiv_perimeter, double &alpha)
Definition: AuxiliaryFunctions.h:105
static Vector EigenValuesDirectMethod(const BoundedMatrix< double, 3, 3 > &A)
Definition: AuxiliaryFunctions.h:264
static void CalculateAlphaFactor3D(const int n_neighbours, const double external_sphere_area, const double total_equiv_area, double &alpha)
Definition: AuxiliaryFunctions.h:21
static void SwitchCase(const int case_opt, bool &delta_OPTION, bool &continuum_simulation_OPTION)
Definition: AuxiliaryFunctions.h:170
static void ComputeReactionOnTopAndBottomSpheres(ModelPart &r_model_part)
Definition: AuxiliaryFunctions.h:207
array_1d< double, 3 > LinearTimeIncreasingFunction(const array_1d< double, 3 > &external_total_applied_force, const double current_time, const double end_time)
Definition: AuxiliaryFunctions.h:200
static void CheckIfNan(const array_1d< double, 3 > &vector, const std::string &sentence)
Definition: AuxiliaryFunctions.h:316
constexpr double Pi
Definition: global_variables.h:25
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
ModelPart::ElementsContainerType ElementsArrayType
Definition: gid_gauss_point_container.h:41
time
Definition: face_heat.py:85
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
q
Definition: generate_convection_diffusion_explicit_element.py:109
out
Definition: isotropic_damage_automatic_differentiation.py:200
phi
Definition: isotropic_damage_automatic_differentiation.py:168
A
Definition: sensitivityMatrix.py:70
p
Definition: sensitivityMatrix.py:52
int dim
Definition: sensitivityMatrix.py:25
B
Definition: sensitivityMatrix.py:76