43 return (VectorA[0] * VectorB[1] - VectorB[0] * VectorA[1]);
51 const double Tolerance
55 return rGeom.
IsInside(Coords, LocalCoords, Tolerance);
64 std::vector<typename Geometry<Node>::Pointer> geometry_neighbours;
67 auto p_geometry_neighbour = (rBackgroundGridModelPart.
ElementsBegin() +
j)->pGetGeometry();
68 if (p_geometry_neighbour->Id() != rGeom.
Id())
70 for (
IndexType n = 0;
n < p_geometry_neighbour->size();
n++)
74 if (rGeom[
k].Id() == (*p_geometry_neighbour)[
n].
Id()) {
76 bool add_entry =
true;
77 for (
size_t i = 0;
i < geometry_neighbours.size();
i++)
79 if (geometry_neighbours[
i]->Id() == p_geometry_neighbour->Id())
86 geometry_neighbours.push_back(p_geometry_neighbour);
95 rGeom.
SetValue(GEOMETRY_NEIGHBOURS, geometry_neighbours);
100 GeometryType::Pointer pQuadraturePoint,
104 if (rProcessInfo.
Has(IS_FIX_EXPLICIT_MP_ON_GRID_EDGE)) {
105 if (rProcessInfo.
GetValue(IS_FIX_EXPLICIT_MP_ON_GRID_EDGE)) {
106 if (pQuadraturePoint->IntegrationPointsNumber() == 1) {
107 for (
size_t i = 0;
i < pQuadraturePoint->ShapeFunctionsValues().size2(); ++
i) {
108 if (pQuadraturePoint->ShapeFunctionsValues()(0,
i) < std::numeric_limits<double>::epsilon()) {
120 const ModelPart& rBackgroundGridModelPart,
121 const double Tolerance,
129 if (
CheckIsInside(rParentGeom, rLocalCoords, xg, Tolerance)) {
133 if (!rParentGeom.
Has(GEOMETRY_NEIGHBOURS)) {
136 auto& geometry_neighbours = rParentGeom.
GetValue(GEOMETRY_NEIGHBOURS);
137 for (
IndexType k = 0;
k < geometry_neighbours.size(); ++
k) {
138 if (
CheckIsInside(*geometry_neighbours[
k], rLocalCoords, xg, Tolerance)) {
140 return *(geometry_neighbours[
k].get());
149 const ModelPart& rBackgroundGridModelPart,
152 typename GeometryType::Pointer pQuadraturePointGeometry,
153 const double Tolerance
159 pQuadraturePointGeometry->IsInside(rCoordinates, local_coords, Tolerance);
161 local_coords, rMasterMaterialPoint, pQuadraturePointGeometry, Tolerance);
169 const ModelPart& rBackgroundGridModelPart,
170 std::vector<typename Element::Pointer>& rMissingElements,
171 const double Tolerance
174 #pragma omp parallel for
175 for (
int i = 0; i < static_cast<int>(rMPMModelPart.
Elements().size()); ++
i) {
178 bool is_found =
false;
179 std::vector<array_1d<double, 3>> xg;
180 element_itr->CalculateOnIntegrationPoints(MP_COORD, xg, rBackgroundGridModelPart.
GetProcessInfo());
183 rBackgroundGridModelPart, Tolerance, xg[0], local_coordinates,
191 (*element_itr).GetGeometry().SetGeometryParent(&r_found_geom);
193 local_coordinates, *element_itr, element_itr->pGetGeometry(), Tolerance);
196 element_itr->pGetGeometry(), local_coordinates,
197 element_itr->GetGeometry().IntegrationPoints()[0].Weight(), r_found_geom);
203 r_found_geom.
Points()[
j].Set(ACTIVE);
208 rMissingElements.
push_back(&*element_itr);
216 const ModelPart& rBackgroundGridModelPart,
217 std::vector<typename Condition::Pointer>& rMissingConditions,
218 const double Tolerance
221 #pragma omp parallel for
222 for (
int i = 0; i < static_cast<int>(rMPMModelPart.
Conditions().size()); ++
i) {
223 auto condition_itr = rMPMModelPart.
Conditions().begin() +
i;
224 std::vector<array_1d<double, 3>> xg;
225 condition_itr->CalculateOnIntegrationPoints(MPC_COORD, xg, rMPMModelPart.
GetProcessInfo());
227 if (xg.size() > 0 && condition_itr->Is(BOUNDARY)) {
229 bool is_found =
false;
232 rBackgroundGridModelPart, Tolerance, xg[0], local_coordinates,
237 condition_itr->pGetGeometry(), local_coordinates,
238 condition_itr->GetGeometry().IntegrationPoints()[0].Weight(), r_found_geom);
241 r_found_geom[
j].Set(ACTIVE);
245 rMissingConditions.
push_back(&*condition_itr);
257 if (rProcessInfo.
Has(IS_FIX_EXPLICIT_MP_ON_GRID_EDGE)) {
258 if (rProcessInfo.
GetValue(IS_FIX_EXPLICIT_MP_ON_GRID_EDGE)) {
261 if (std::abs(
N[
i]) < std::numeric_limits<double>::epsilon()) {
271 template <std::
size_t TDimension>
275 std::vector<typename Element::Pointer>& rMissingElements,
276 std::vector<typename Condition::Pointer>& rMissingConditions,
277 const std::size_t MaxNumberOfResults,
278 const double Tolerance
282 bool is_pqmpm = (r_process_info.
Has(IS_PQMPM))
283 ? r_process_info.
GetValue(IS_PQMPM) :
false;
287 const int max_result = 1000;
297 for (
int i = 0; i < static_cast<int>(rMissingElements.size()); ++
i) {
298 auto element_itr = *(rMissingElements.begin() +
i);
299 std::vector<array_1d<double, 3>> xg;
300 element_itr->CalculateOnIntegrationPoints(MP_COORD, xg, rMPMModelPart.
GetProcessInfo());
302 Element::Pointer pelem;
305 bool is_found =
SearchStructure.FindPointOnMesh(xg[0],
N, pelem, result_begin, MaxNumberOfResults, Tolerance);
313 std::vector<array_1d<double, 3>> mp_vel;
314 element_itr->CalculateOnIntegrationPoints(MP_VELOCITY, mp_vel, rMPMModelPart.
GetProcessInfo());
315 xg_nudged += r_process_info[DELTA_TIME] / 1000.0 * mp_vel[0];
316 if (
SearchStructure.FindPointOnMesh(xg_nudged,
N, pelem, result_begin, MaxNumberOfResults, Tolerance)) {
317 element_itr->SetValuesOnIntegrationPoints(MP_COORD, { xg_nudged }, rMPMModelPart.
GetProcessInfo());
318 KRATOS_INFO(
"MPMSearchElementUtility") <<
"WARNING: To prevent spurious explicit stresses, Material Point "
319 << element_itr->Id() <<
" was nudged." << std::endl;
321 is_found =
SearchStructure.FindPointOnMesh(xg[0],
N, pelem, result_begin, MaxNumberOfResults, Tolerance);
322 KRATOS_INFO(
"MPMSearchElementUtility") <<
"WARNING: Material Point " << element_itr->Id()
323 <<
" lies exactly on an element edge and may give spurious results." << std::endl;
328 (*element_itr).GetGeometry().SetGeometryParent((pelem->pGetGeometry().get()));
332 auto p_quadrature_point_geometry = element_itr->pGetGeometry();
334 pelem->pGetGeometry()->PointLocalCoordinates(local_coordinates, xg[0]);
336 p_quadrature_point_geometry, local_coordinates,
337 p_quadrature_point_geometry->IntegrationPoints()[0].Weight(), pelem->GetGeometry());
339 auto& r_geometry = element_itr->GetGeometry();
340 for (
IndexType j = 0;
j < r_geometry.PointsNumber(); ++
j) {
341 r_geometry[
j].Set(ACTIVE);
344 KRATOS_INFO(
"MPMSearchElementUtility") <<
"WARNING: Search Element for Material Point: "
345 << element_itr->Id() <<
" is failed. Geometry is cleared." << std::endl;
346 element_itr->GetGeometry().clear();
347 element_itr->Reset(ACTIVE);
348 element_itr->Set(TO_ERASE);
354 for (
int i = 0; i < static_cast<int>(rMissingConditions.size()); ++
i) {
355 auto condition_itr = *(rMissingConditions.begin() +
i);
356 std::vector<array_1d<double, 3>> xg;
357 condition_itr->CalculateOnIntegrationPoints(MPC_COORD, xg, rMPMModelPart.
GetProcessInfo());
363 Element::Pointer pelem;
366 bool is_found =
SearchStructure.FindPointOnMesh(xg[0],
N, pelem, result_begin, MaxNumberOfResults, Tolerance);
369 auto p_quadrature_point_geometry = condition_itr->pGetGeometry();
371 pelem->pGetGeometry()->PointLocalCoordinates(local_coordinates, xg[0]);
373 p_quadrature_point_geometry, local_coordinates,
374 p_quadrature_point_geometry->IntegrationPoints()[0].Weight(), pelem->GetGeometry());
376 auto& r_geometry = condition_itr->GetGeometry();
378 for (
IndexType j = 0;
j < r_geometry.PointsNumber(); ++
j) {
379 r_geometry[
j].Set(ACTIVE);
382 KRATOS_INFO(
"MPMSearchElementUtility") <<
"WARNING: Search Element for Material Point Condition: " << condition_itr->Id()
383 <<
" is failed. Geometry is cleared." << std::endl;
384 condition_itr->GetGeometry().clear();
385 condition_itr->Reset(ACTIVE);
386 condition_itr->Set(TO_ERASE);
396 #pragma omp parallel for
397 for (
int i = 0; i < static_cast<int>(rBackgroundGridModelPart.
Elements().size()); ++
i) {
398 auto element_itr = rBackgroundGridModelPart.
Elements().begin() +
i;
399 element_itr->Reset(ACTIVE);
400 auto& r_geometry = element_itr->GetGeometry();
401 for (
IndexType j = 0;
j < r_geometry.PointsNumber(); ++
j) {
402 r_geometry[
j].Reset(ACTIVE);
418 template<std::
size_t TDimension>
422 const std::size_t MaxNumberOfResults,
423 const double Tolerance
428 std::vector<typename Element::Pointer> missing_elements;
429 std::vector<typename Condition::Pointer> missing_conditions;
435 missing_elements.resize(rMPMModelPart.
Elements().size());
440 missing_conditions.resize(rMPMModelPart.
Conditions().size());
442 missing_conditions[
i] = &*(rMPMModelPart.
Conditions().begin() +
i);
446 if (missing_conditions.size() > 0 || missing_elements.size() > 0) {
447 BinBasedSearchElementsAndConditions<TDimension>(rMPMModelPart,
448 rBackgroundGridModelPart, missing_elements, missing_conditions,
449 MaxNumberOfResults, Tolerance);
This class is designed to allow the fast location of MANY points on the top of a 3D mesh.
Definition: binbased_fast_point_locator.h:68
ConfigureType::ResultIteratorType ResultIteratorType
Definition: binbased_fast_point_locator.h:82
ConfigureType::ResultContainerType ResultContainerType
Definition: binbased_fast_point_locator.h:81
static void UpdateFromLocalCoordinates(typename GeometryType::Pointer pGeometry, const array_1d< double, 3 > &rLocalCoordinates, const double rIntegrationWeight, GeometryType &rParentGeometry)
Definition: quadrature_points_utility.h:373
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
Base class for all Elements.
Definition: element.h:60
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
void SetValue(const TVariableType &rThisVariable, typename TVariableType::Type const &rValue)
Definition: geometry.h:617
void push_back(PointPointerType x)
Definition: geometry.h:548
SizeType size() const
Definition: geometry.h:518
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
virtual bool IsInside(const CoordinatesArrayType &rPointGlobalCoordinates, CoordinatesArrayType &rResult, const double Tolerance=std::numeric_limits< double >::epsilon()) const
Checks if given point in global space coordinates is inside the geometry boundaries....
Definition: geometry.h:1918
const PointsArrayType & Points() const
Definition: geometry.h:1768
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
bool Has(const Variable< TDataType > &rThisVariable) const
Definition: geometry.h:609
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
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
GeometryType::Pointer pGetGeometry(IndexType GeometryId)
Returns the Geometry::Pointer corresponding to the Id.
Definition: model_part.h:1564
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
This class defines the node.
Definition: node.h:65
static void PartitionMasterMaterialPointsIntoSubPoints(const ModelPart &rBackgroundGridModelPart, const array_1d< double, 3 > &rCoordinates, const array_1d< double, 3 > &rLocalCoords, Element &rMasterMaterialPoint, typename GeometryType::Pointer pQuadraturePointGeometry, const double Tolerance)
Definition: pqmpm_partition_utilities.cpp:25
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Definition: search_structure.h:309
void Set(IndexVector const &IndexCell, SizeVector const &_MaxSize, IteratorIteratorType const &IteratorBegin)
Definition: search_structure.h:363
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
Definition: mpm_search_element_utility.h:30
Node NodeType
Definition: mpm_search_element_utility.h:34
bool IsExplicitAndNeedsCorrection(GeometryType::Pointer pQuadraturePoint, const ProcessInfo &rProcessInfo)
Definition: mpm_search_element_utility.h:99
bool IsFixExplicitAndOnElementEdge(const Vector &N, const ProcessInfo &rProcessInfo)
Definition: mpm_search_element_utility.h:252
void NeighbourSearchConditions(const ModelPart &rMPMModelPart, const ModelPart &rBackgroundGridModelPart, std::vector< typename Condition::Pointer > &rMissingConditions, const double Tolerance)
Definition: mpm_search_element_utility.h:214
void ResetElementsAndNodes(ModelPart &rBackgroundGridModelPart)
Definition: mpm_search_element_utility.h:394
bool CheckIsInside(const GeometryType &rGeom, array_1d< double, 3 > &LocalCoords, const array_1d< double, 3 > &Coords, const double Tolerance)
Definition: mpm_search_element_utility.h:47
std::size_t SizeType
Definition: mpm_search_element_utility.h:33
std::size_t IndexType
Definition: mpm_search_element_utility.h:32
void ConstructNeighbourRelations(GeometryType &rGeom, const ModelPart &rBackgroundGridModelPart)
Definition: mpm_search_element_utility.h:59
void SearchElement(ModelPart &rBackgroundGridModelPart, ModelPart &rMPMModelPart, const std::size_t MaxNumberOfResults, const double Tolerance)
Search element connectivity for each particle.
Definition: mpm_search_element_utility.h:419
GeometryType & FindGridGeom(GeometryType &rParentGeom, const ModelPart &rBackgroundGridModelPart, const double Tolerance, const array_1d< double, 3 > &xg, array_1d< double, 3 > &rLocalCoords, const ProcessInfo &rProcessInfo, bool &IsFound)
Definition: mpm_search_element_utility.h:118
void UpdatePartitionedQuadraturePoint(const ModelPart &rBackgroundGridModelPart, const array_1d< double, 3 > &rCoordinates, Element &rMasterMaterialPoint, typename GeometryType::Pointer pQuadraturePointGeometry, const double Tolerance)
Definition: mpm_search_element_utility.h:148
ModelPart::GeometryType GeometryType
Definition: mpm_search_element_utility.h:35
void BinBasedSearchElementsAndConditions(ModelPart &rMPMModelPart, ModelPart &rBackgroundGridModelPart, std::vector< typename Element::Pointer > &rMissingElements, std::vector< typename Condition::Pointer > &rMissingConditions, const std::size_t MaxNumberOfResults, const double Tolerance)
Definition: mpm_search_element_utility.h:272
void NeighbourSearchElements(const ModelPart &rMPMModelPart, const ModelPart &rBackgroundGridModelPart, std::vector< typename Element::Pointer > &rMissingElements, const double Tolerance)
Definition: mpm_search_element_utility.h:167
double CrossProductDet2D(array_1d< double, 3 > VectorA, array_1d< double, 3 > VectorB)
Definition: mpm_search_element_utility.h:38
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17