14 #if !defined(KRATOS_CARTESIAN_MESH_GENERATOR_H_INCLUDED )
15 #define KRATOS_CARTESIAN_MESH_GENERATOR_H_INCLUDED
79 mrModelPart(rSourceModelPart), mElementSize(ElementSize)
107 unsigned int start_node_id = mrModelPart.
NumberOfNodes() + 1;
108 unsigned int start_element_id = 1;
115 const unsigned int number_of_nodes = mDivisionsNumber[0] * mDivisionsNumber[1] * mDivisionsNumber[2];
118 const unsigned int number_of_elements = mSegmentsNumber[0] * mSegmentsNumber[1] * mSegmentsNumber[2];
132 double x0 = mMinPoint.
X();
133 double y0 = mMinPoint.
Y();
134 double z0 = mMinPoint.
Z();
142 for(
unsigned int k = 0 ;
k < mDivisionsNumber[2] ;
k++)
143 for(
unsigned int j = 0 ;
j < mDivisionsNumber[1] ;
j++)
144 for(
unsigned int i = 0 ;
i < mDivisionsNumber[0] ;
i++)
145 temp_nodes_array[
NodeIndex(
i,
j,
k)] = NodeType::Pointer(
new NodeType(start_node_id++, x0 +
i * mElementSize, y0 +
j * mElementSize, z0 +
k * mElementSize));
147 unsigned int number_of_active_nodes = 0;
149 for(
unsigned int i = 0 ;
i < number_of_nodes ;
i++)
151 number_of_active_nodes++;
153 nodes_array.resize(number_of_active_nodes);
155 unsigned int index = 0;
157 for(
unsigned int i = 0 ;
i < number_of_nodes ;
i++)
159 nodes_array[index++]=temp_nodes_array[
i];
169 unsigned int number_of_active_elements = 0;
170 for(
unsigned int j = 0 ;
j < mSegmentsNumber[1] ;
j++)
171 for(
unsigned int i = 0 ;
i < mSegmentsNumber[0] ;
i++)
174 number_of_active_elements++;
177 elements_array.resize(number_of_active_elements);
181 for(
unsigned int j = 0 ;
j < mSegmentsNumber[1] ;
j++)
182 for(
unsigned int i = 0 ;
i < mSegmentsNumber[0] ;
i++)
186 element_nodes(0) = temp_nodes_array[
NodeIndex(
i,
j,0)];
187 element_nodes(1) = temp_nodes_array[
NodeIndex(
i+1,
j,0)];
188 element_nodes(2) = temp_nodes_array[
NodeIndex(
i+1,
j+1,0)];
189 element_nodes(3) = temp_nodes_array[
NodeIndex(
i,
j+1,0)];
199 PointType point1 = r_geometry[0] + mNormals[r_geometry[0].
Id()-1];
200 PointType point2 = r_geometry[1] + mNormals[r_geometry[1].
Id()-1];
205 element_nodes(0) = r_geometry(0);
206 element_nodes(1) = r_geometry(1);
207 element_nodes(2) = temp_nodes_array[index2];
208 element_nodes(3) = temp_nodes_array[index1];
232 std::fill(mNormals.begin(), mNormals.end(),
zero);
234 double coefficient = mElementSize / 2.00;
241 normal[0] = r_geometry[1].Y() - r_geometry[0].Y();
242 normal[1] = - (r_geometry[1].X() - r_geometry[0].X());
244 normal *= coefficient / r_geometry.
Length();
247 mNormals[r_geometry[0].
Id()-1] += normal ;
248 mNormals[r_geometry[1].
Id()-1] += normal ;
251 noalias(i_node->FastGetSolutionStepValue(NORMAL)) = mNormals[i_node->Id()-1] ;
256 double x = (rThisPoint.
X() - mMinPoint.
X()) / mElementSize;
257 double y = (rThisPoint.
Y() - mMinPoint.
Y()) / mElementSize;
259 unsigned int i =
static_cast<unsigned int>(
x);
260 unsigned int j =
static_cast<unsigned int>(
y);
266 if(rNormal[0] >= 0.00)
268 if(rNormal[1] >= 0.00)
270 if(rNormal[0] > rNormal[1])
277 if(rNormal[0] > -rNormal[1])
285 if(rNormal[1] >= 0.00)
287 if(-rNormal[0] > rNormal[1])
294 if(-rNormal[0] > -rNormal[1])
308 const unsigned int number_of_nodes = mDivisionsNumber[0] * mDivisionsNumber[1] * mDivisionsNumber[2];
310 if(mIsInside.size() != number_of_nodes)
312 mIsInside.resize(number_of_nodes, 0);
315 std::fill(mIsInside.begin(),mIsInside.end(), 0);
317 int size = mSegmentsNumber[1] + 1;
319 for(
int j = 0 ;
j < size ;
j++)
322 std::vector<double>& j_intersections = mIntersections[
j];
324 for(std::vector<double>::iterator j_x = j_intersections.begin() ; j_x != j_intersections.end() ; j_x++)
326 std::vector<double>::iterator
start = j_x++;
328 unsigned int i_start =
static_cast<unsigned int>(*
start / mElementSize);
329 unsigned int i_end =
static_cast<unsigned int>(*j_x / mElementSize);
331 for(
unsigned int i = i_start + 1 ;
i < i_end ;
i++)
339 std::vector<int> number_of_intersections(mSegmentsNumber[1] + 1, 0);
340 if(mIntersections.size() != mSegmentsNumber[1] + 1)
341 mIntersections.resize(mSegmentsNumber[1] + 1);
351 if(r_geometry[0].
Y() < r_geometry[1].
Y())
353 x1 = (r_geometry[0].X() - mMinPoint.
X());
354 x2 = (r_geometry[1].X() - mMinPoint.
X());
355 y1 = (r_geometry[0].Y() - mMinPoint.
Y());
356 y2 = (r_geometry[1].Y() - mMinPoint.
Y());
360 x1 = (r_geometry[1].X() - mMinPoint.
X());
361 x2 = (r_geometry[0].X() - mMinPoint.
X());
362 y1 = (r_geometry[1].Y() - mMinPoint.
Y());
363 y2 = (r_geometry[0].Y() - mMinPoint.
Y());
366 unsigned int i_start =
static_cast<unsigned int>(y1 / mElementSize);
367 unsigned int i_end =
static_cast<unsigned int>(y2 / mElementSize);
369 if (i_start*mElementSize < y1)
374 m = (
x2 -
x1) / (y2 - y1);
376 double delta_x =
m*mElementSize;
377 double x =
x1 + (i_start * mElementSize - y1) *
m ;
378 for(
unsigned int i = i_start ;
i <= i_end ;
i++)
380 number_of_intersections[
i]++;
381 mIntersections[
i].push_back(
x);
386 for(
int i = 0 ;
i < mIntersections.size() ;
i++)
387 std::sort(mIntersections[
i].begin(), mIntersections[
i].end());
407 rMinPoint = rThisModelPart.
ElementsBegin()->GetGeometry()[0];
408 rMaxPoint = rMinPoint;
411 i_element != rThisModelPart.
ElementsEnd() ; i_element++)
415 if(rMinPoint[
i] > (*i_point)[
i])
416 rMinPoint[
i] = (*i_point)[
i];
418 if(rMaxPoint[
i] < (*i_point)[
i])
419 rMaxPoint[
i] = (*i_point)[
i];
426 if(mElementSize == 0.00)
431 double delta = mMaxPoint[
i] - mMinPoint[
i];
432 int segments_number =
static_cast<int>(
delta / mElementSize);
434 if (((segments_number * mElementSize) <
delta))
437 mSegmentsNumber[
i] = segments_number;
440 mDivisionsNumber[
i] = segments_number + 1;
442 if(mSegmentsNumber[
i] == 0)
443 mSegmentsNumber[
i]++;
456 return i + mDivisionsNumber[0] *
j + mDivisionsNumber[0] * mDivisionsNumber[1] *
k;
461 return i + mSegmentsNumber[0] *
j + mSegmentsNumber[0] * mSegmentsNumber[1] *
k;
483 virtual std::string
Info()
const
485 return "CartesianMeshGeneratorModeler";
559 unsigned int mSegmentsNumber[3];
561 unsigned int mDivisionsNumber[3];
563 std::vector<std::vector<double> > mIntersections;
564 std::vector<int> mIsInside;
566 std::vector<array_1d<double,3> > mNormals;
580 double x1 = rGeometry[0][0];
581 double y1 = rGeometry[0][1];
582 double z1 = rGeometry[0][2];
583 double x2 = rGeometry[1][0];
584 double y2 = rGeometry[1][1];
585 double z2 = rGeometry[1][2];
587 double dx = (
x2 -
x1) / NumberOfSegments;
588 double dy = (y2 - y1) / NumberOfSegments;
589 double dz = (z2 - z1) / NumberOfSegments;
591 for(
SizeType i = 1 ;
i < NumberOfSegments - 1 ;
i++)
642 rOStream << std::endl;
Short class definition.
Definition: cartesian_mesh_generator_modeler.h:53
PointerVector< NodeType > NodesVectorType
Definition: cartesian_mesh_generator_modeler.h:69
virtual void GenerateNodes(ModelPart &ThisModelPart)
Definition: cartesian_mesh_generator_modeler.h:448
unsigned int ElementIndex(unsigned int i, unsigned int j, unsigned int k)
Definition: cartesian_mesh_generator_modeler.h:454
Modeler BaseType
Definition: cartesian_mesh_generator_modeler.h:61
unsigned int FindNearestNodeIndex(PointType &rThisPoint, array_1d< double, 3 > &rNormal)
Definition: cartesian_mesh_generator_modeler.h:254
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: cartesian_mesh_generator_modeler.h:489
unsigned int NodeIndex(unsigned int i, unsigned int j, unsigned int k)
Definition: cartesian_mesh_generator_modeler.h:459
std::size_t SizeType
Definition: cartesian_mesh_generator_modeler.h:71
virtual ~CartesianMeshGeneratorModeler()
Destructor.
Definition: cartesian_mesh_generator_modeler.h:84
virtual std::string Info() const
Turn back information as a string.
Definition: cartesian_mesh_generator_modeler.h:483
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: cartesian_mesh_generator_modeler.h:495
void CalculateIsInside(ModelPart &rThisModelPart)
Definition: cartesian_mesh_generator_modeler.h:306
void CalculateDivisionNumbers()
Definition: cartesian_mesh_generator_modeler.h:424
void GenerateMesh(ModelPart &rThisModelPart, Element const &rReferenceElement)
Definition: cartesian_mesh_generator_modeler.h:96
void CalculateBoundingBox(ModelPart &rThisModelPart, Point &rMinPoint, Point &rMaxPoint)
Definition: cartesian_mesh_generator_modeler.h:390
Geometry< NodeType > GeometryType
Definition: cartesian_mesh_generator_modeler.h:67
KRATOS_CLASS_POINTER_DEFINITION(CartesianMeshGeneratorModeler)
Pointer definition of CartesianMeshGeneratorModeler.
Point PointType
Definition: cartesian_mesh_generator_modeler.h:63
void CalculateBoundaryIntersections(ModelPart &rThisModelPart)
Definition: cartesian_mesh_generator_modeler.h:337
void CalculateNormals()
Definition: cartesian_mesh_generator_modeler.h:225
CartesianMeshGeneratorModeler(ModelPart &rSourceModelPart, double ElementSize)
constructor.
Definition: cartesian_mesh_generator_modeler.h:78
Node NodeType
Definition: cartesian_mesh_generator_modeler.h:65
Base class for all Elements.
Definition: element.h:60
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
PropertiesType::Pointer pGetProperties()
returns the pointer to the property of the element. Does not throw an error, to allow copying of elem...
Definition: element.h:1014
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Geometry base class.
Definition: geometry.h:71
virtual double Length() const
Definition: geometry.h:1332
PointsArrayType::iterator iterator
PointsArrayType typedefs.
Definition: geometry.h:213
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
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
NodeType::Pointer CreateNewNode(int Id, double x, double y, double z, VariablesList::Pointer pNewVariablesList, IndexType ThisIndex=0)
Definition: model_part.cpp:270
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
NodesContainerType::ContainerType & NodesArray(IndexType ThisIndex=0)
Definition: model_part.h:527
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
ElementsContainerType::ContainerType & ElementsArray(IndexType ThisIndex=0)
Definition: model_part.h:1209
Modeler to interact with ModelParts.
Definition: modeler.h:39
This class defines the node.
Definition: node.h:65
Point class.
Definition: point.h:59
static constexpr IndexType Dimension()
Definition: point.h:175
double Y() const
Definition: point.h:187
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
static void Start(std::string const &rIntervalName)
This method starts the timer meassures.
Definition: timer.cpp:109
static void Stop(std::string const &rIntervalName)
This method stops the timer meassures.
Definition: timer.cpp:125
#define KRATOS_WATCH(variable)
Definition: define.h:806
start
Definition: DEM_benchmarks.py:17
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
int counter
Definition: script_THERMAL_CORRECT.py:218
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17
double precision, dimension(3, 3), public delta
Definition: TensorModule.f:16
zero
Definition: test_pureconvectionsolver_benchmarking.py:94
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247