17 #if !defined(KRATOS_BODY_DISTANCE_CALCULATION_UTILS )
18 #define KRATOS_BODY_DISTANCE_CALCULATION_UTILS
29 #include "utilities/geometry_utilities.h"
133 template<
unsigned int TDim>
137 const double max_distance)
151 std::vector<double> node_distance_values;
152 node_distance_values.reserve(rElements.
size());
162 it->GetValue(IS_VISITED) = 0.0;
164 unsigned int visited_nodes = 0;
167 for (
unsigned int kk = 0; kk < TDim + 1; kk++)
169 if (geom[kk].
GetValue(IS_VISITED) == 1)
172 geom[kk].FastGetSolutionStepValue(rDistanceVar) = max_distance;
176 if (visited_nodes == TDim)
178 elements_to_solve.
push_back(*(it.base()));
179 it->GetValue(IS_VISITED) = 1;
191 while (elements_to_solve.size() != 0)
195 for (
unsigned int current_position = 0; current_position != elements_to_solve.size(); current_position++)
200 unsigned int unknown_node_index = 0;
209 for (
unsigned int iii = 0; iii < TDim + 1; iii++)
211 const double distance = geom[iii].FastGetSolutionStepValue(rDistanceVar);
212 double node_is_known = geom[iii].
GetValue(IS_VISITED);
213 if (node_is_known == 1)
214 for (
unsigned int jjj = 0; jjj < TDim; jjj++)
215 d[jjj] += DN_DX(iii, jjj) * distance;
217 unknown_node_index = iii;
224 for (
unsigned int jjj = 0; jjj < TDim; jjj++)
226 a += DN_DX(unknown_node_index, jjj) * DN_DX(unknown_node_index, jjj);
227 b +=
d[jjj] * DN_DX(unknown_node_index, jjj);
228 c +=
d[jjj] *
d[jjj];
232 double discriminant =
b *
b - 4.0 *
a*
c;
234 if (discriminant < 0.0)
236 distance = -
b / (2.0*
a);
243 double q, root1, root2;;
244 double sqrt_det = sqrt(discriminant);
247 if (
b > 0)
q = -0.5 * (
b + sqrt_det);
248 else q = -0.5 * (
b - sqrt_det);
251 if (root1 > root2) distance = root1;
252 else distance = root2;
260 active_nodes.
push_back(geom(unknown_node_index));
261 node_distance_values.push_back(distance);
269 for (
unsigned int k = 0;
k < active_nodes.
size();
k++)
272 if (active_nodes(
k)->FastGetSolutionStepValue(rDistanceVar) > node_distance_values[
k])
273 active_nodes(
k)->FastGetSolutionStepValue(rDistanceVar) = node_distance_values[
k];
275 active_nodes(
k)->GetValue(IS_VISITED) = 1;
305 elements_to_solve.
clear();
311 if(it->FastGetSolutionStepValue(rDistanceVar) < max_distance)
316 for(
auto ie : it->GetValue(NEIGHBOUR_ELEMENTS).GetContainer())
318 unsigned int visited_nodes = 0;
321 for (
unsigned int kk = 0; kk < TDim + 1; kk++)
323 if (geom[kk].
GetValue(IS_VISITED) == 1)
327 if (visited_nodes == TDim)
328 if( ie->GetValue(IS_VISITED) != 1 )
331 elements_to_solve.push_back( Element::Pointer(ie->shared_from_this()) );
344 active_nodes.
clear();
345 node_distance_values.clear();
353 unsigned int confirmed_failures = 0;
356 if (it->GetValue(IS_VISITED) != 1 )
358 confirmed_failures++;
363 if (in->GetValue(IS_VISITED) == 1)
365 davg += in->FastGetSolutionStepValue(rDistanceVar);
372 double estimated_distance = davg /
counter;
373 if(estimated_distance < max_distance)
374 it->FastGetSolutionStepValue(rDistanceVar) = estimated_distance;
376 it->FastGetSolutionStepValue(rDistanceVar) = max_distance;
384 KRATOS_THROW_ERROR(std::logic_error,
"no neighbour nodes was succesfully computed ... impossible to recover",
"");
434 class CompareElementDistance
438 CompareElementDistance(
const Variable<double>& rDistanceVar) : mrDistanceVar(rDistanceVar) { }
440 bool operator()(
const Element::Pointer
a,
441 const Element::Pointer
b)
const
443 return a->GetValue(mrDistanceVar) <
b->GetValue(mrDistanceVar);
447 const Variable<double>& mrDistanceVar;
Definition: body_distance_calculation_utils.h:93
void CalculateDistances(ElementsArrayType &rElements, Variable< double > &rDistanceVar, const double max_distance)
Definition: body_distance_calculation_utils.h:134
virtual ~BodyDistanceCalculationUtils()
Definition: body_distance_calculation_utils.h:107
ModelPart::NodesContainerType NodesArrayType
Definition: body_distance_calculation_utils.h:97
BodyDistanceCalculationUtils()
Definition: body_distance_calculation_utils.h:106
ModelPart::ElementsContainerType ElementsArrayType
Definition: body_distance_calculation_utils.h:98
Geometry base class.
Definition: geometry.h:71
void push_back(PointPointerType x)
Definition: geometry.h:548
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
Definition: amatrix_interface.h:41
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
void clear()
Definition: pointer_vector.h:309
size_type size() const
Definition: pointer_vector.h:255
iterator end()
Definition: pointer_vector.h:177
void reserve(size_type dim)
Definition: pointer_vector.h:319
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector.h:89
iterator begin()
Definition: pointer_vector.h:169
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
q
Definition: generate_convection_diffusion_explicit_element.py:109
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int d
Definition: ode_solve.py:397
int k
Definition: quadrature.py:595
int counter
Definition: script_THERMAL_CORRECT.py:218
N
Definition: sensitivityMatrix.py:29