36#include "AbstractMesh.hpp"
44template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
46 : mpDistributedVectorFactory(nullptr),
47 mMeshFileBaseName(
""),
48 mMeshChangesDuringSimulation(false)
52template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
56 for (
unsigned i = 0; i < mNodes.size(); i++)
60 if (mpDistributedVectorFactory)
62 delete mpDistributedVectorFactory;
66template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
72template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
75 return mBoundaryNodes.size();
78template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
84template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
89 assert(mNodes.size() != 0u);
90 return mNodes[0]->GetNumNodeAttributes();
93template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
96 unsigned local_index = SolveNodeMapping(index);
97 return mNodes[local_index];
100template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
103 return GetNode(index);
106template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
109 if (mNodePermutation.empty())
111 return GetNode(index);
115 return GetNode(mNodePermutation[index]);
120template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
127template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
133template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
136 if (mpDistributedVectorFactory ==
nullptr)
141 SetElementOwnerships();
144 return mpDistributedVectorFactory;
147template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
150 if (mpDistributedVectorFactory)
152 EXCEPTION(
"Cannot change the mesh's distributed vector factory once it has been set.");
156 EXCEPTION(
"The distributed vector factory provided to the mesh is for the wrong number of processes.");
158 mpDistributedVectorFactory = pFactory;
162template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
169template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
172 return mBoundaryNodes.begin();
175template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
178 return mBoundaryNodes.end();
181template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
186 EXCEPTION(
"This mesh was not constructed from a file.");
189 return mMeshFileBaseName;
192template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
195 return (mMeshFileBaseName !=
"");
198template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
201 return mNodePermutation;
204template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
206 const c_vector<double, SPACE_DIM>& rLocationA,
const c_vector<double, SPACE_DIM>& rLocationB)
208 c_vector<double, SPACE_DIM> vector = rLocationB - rLocationA;
212template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
215 c_vector<double, SPACE_DIM> vector = GetVectorFromAtoB(mNodes[indexA]->rGetLocation(),
216 mNodes[indexB]->rGetLocation());
217 return norm_2(vector);
220template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
223 assert(rDimension < SPACE_DIM);
224 return CalculateBoundingBox(mNodes).GetWidth(rDimension);
227template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
231 c_vector<double, SPACE_DIM> minimum_point = zero_vector<double>(SPACE_DIM);
232 c_vector<double, SPACE_DIM> maximum_point = zero_vector<double>(SPACE_DIM);
237 minimum_point = scalar_vector<double>(SPACE_DIM, 0.0);
238 maximum_point = scalar_vector<double>(SPACE_DIM, 0.0);
242 minimum_point = scalar_vector<double>(SPACE_DIM, DBL_MAX);
243 maximum_point = scalar_vector<double>(SPACE_DIM, -DBL_MAX);
247 for (
unsigned index = 0; index < rNodes.size(); index++)
249 if (!rNodes[index]->IsDeleted())
251 c_vector<double, SPACE_DIM> position = rNodes[index]->rGetLocation();
254 for (
unsigned i = 0; i < SPACE_DIM; i++)
256 if (position[i] < minimum_point[i])
258 minimum_point[i] = position[i];
260 if (position[i] > maximum_point[i])
262 maximum_point[i] = position[i];
275template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
280 return bounding_cuboid;
283template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
297 unsigned best_node_index = 0u;
298 double best_node_point_distance = DBL_MAX;
300 const c_vector<double, SPACE_DIM>& test_location = rTestPoint.
rGetLocation();
302 for (
unsigned node_index = 0; node_index < mNodes.size(); node_index++)
305 double node_point_distance = norm_2(GetVectorFromAtoB(mNodes[node_index]->rGetLocation(), test_location));
307 if (node_point_distance < best_node_point_distance)
309 best_node_index = node_index;
310 best_node_point_distance = node_point_distance;
317 return mNodes[best_node_index]->GetIndex();
320template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
323 unsigned num_nodes = mNodes.size();
325 for (
unsigned i = 0; i < num_nodes; i++)
327 c_vector<double, SPACE_DIM>& r_location = mNodes[i]->rGetModifiableLocation();
330 r_location[2] *= zScale;
334 r_location[1] *= yScale;
336 r_location[0] *= xScale;
342template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
344 const double xMovement,
345 const double yMovement,
346 const double zMovement)
348 c_vector<double, SPACE_DIM> displacement;
353 displacement[2] = zMovement;
359 displacement[1] = yMovement;
362 displacement[0] = xMovement;
366 Translate(displacement);
369template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
372 unsigned num_nodes = this->mNodes.size();
374 for (
unsigned i = 0; i < num_nodes; i++)
376 c_vector<double, SPACE_DIM>& r_location = this->mNodes[i]->rGetModifiableLocation();
377 r_location += rDisplacement;
383template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
386 unsigned num_nodes = this->mNodes.size();
388 for (
unsigned i = 0; i < num_nodes; i++)
390 c_vector<double, SPACE_DIM>& r_location = this->mNodes[i]->rGetModifiableLocation();
391 r_location = prod(rotationMatrix, r_location);
397template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
400 assert(SPACE_DIM == 3);
401 const double norm = norm_2(axis);
402 c_vector<double, 3> unit_axis = axis / norm;
404 c_matrix<double, 3, 3> rotation_matrix;
406 const double c = cos(angle);
407 const double s = sin(angle);
409 rotation_matrix(0, 0) = unit_axis(0) * unit_axis(0) + c * (1 - unit_axis(0) * unit_axis(0));
410 rotation_matrix(0, 1) = unit_axis(0) * unit_axis(1) * (1 - c) - unit_axis(2) * s;
411 rotation_matrix(1, 0) = unit_axis(0) * unit_axis(1) * (1 - c) + unit_axis(2) * s;
412 rotation_matrix(1, 1) = unit_axis(1) * unit_axis(1) + c * (1 - unit_axis(1) * unit_axis(1));
413 rotation_matrix(0, 2) = unit_axis(0) * unit_axis(2) * (1 - c) + unit_axis(1) * s;
414 rotation_matrix(1, 2) = unit_axis(1) * unit_axis(2) * (1 - c) - unit_axis(0) * s;
415 rotation_matrix(2, 0) = unit_axis(0) * unit_axis(2) * (1 - c) - unit_axis(1) * s;
416 rotation_matrix(2, 1) = unit_axis(1) * unit_axis(2) * (1 - c) + unit_axis(0) * s;
417 rotation_matrix(2, 2) = unit_axis(2) * unit_axis(2) + c * (1 - unit_axis(2) * unit_axis(2));
419 Rotate(rotation_matrix);
422template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
427 EXCEPTION(
"This rotation is only valid in 3D");
429 c_matrix<double, 3, 3> x_rotation_matrix = identity_matrix<double>(3);
431 x_rotation_matrix(1, 1) = cos(theta);
432 x_rotation_matrix(1, 2) = sin(theta);
433 x_rotation_matrix(2, 1) = -sin(theta);
434 x_rotation_matrix(2, 2) = cos(theta);
435 Rotate(x_rotation_matrix);
438template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
443 EXCEPTION(
"This rotation is only valid in 3D");
445 c_matrix<double, 3, 3> y_rotation_matrix = identity_matrix<double>(3);
447 y_rotation_matrix(0, 0) = cos(theta);
448 y_rotation_matrix(0, 2) = -sin(theta);
449 y_rotation_matrix(2, 0) = sin(theta);
450 y_rotation_matrix(2, 2) = cos(theta);
452 Rotate(y_rotation_matrix);
455template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
460 EXCEPTION(
"This rotation is not valid in less than 2D");
462 c_matrix<double, SPACE_DIM, SPACE_DIM> z_rotation_matrix = identity_matrix<double>(SPACE_DIM);
464 z_rotation_matrix(0, 0) = cos(theta);
465 z_rotation_matrix(0, 1) = sin(theta);
466 z_rotation_matrix(1, 0) = -sin(theta);
467 z_rotation_matrix(1, 1) = cos(theta);
469 Rotate(z_rotation_matrix);
472template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
478template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
483template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
486 return mMeshChangesDuringSimulation;
489template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
492 unsigned max_num = 0u;
493 for (
unsigned local_node_index = 0; local_node_index < mNodes.size(); local_node_index++)
495 unsigned num = mNodes[local_node_index]->GetNumContainingElements();
504template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
508 mMeshFileBaseName =
"";
#define EXCEPTION(message)
virtual unsigned GetNumAllNodes() const
void RotateZ(const double theta)
virtual DistributedVectorFactory * GetDistributedVectorFactory()
void RotateY(const double theta)
virtual void Translate(const c_vector< double, SPACE_DIM > &rDisplacement)
virtual Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
virtual void RefreshMesh()
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
virtual void SetElementOwnerships()
bool IsMeshChanging() const
virtual void SetDistributedVectorFactory(DistributedVectorFactory *pFactory)
void RotateX(const double theta)
std::string GetMeshFileBaseName() const
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
virtual unsigned GetNumNodes() const
virtual ChasteCuboid< SPACE_DIM > CalculateBoundingBox() const
virtual void ReadNodesPerProcessorFile(const std::string &rNodesPerProcessorFile)
virtual double GetWidth(const unsigned &rDimension) const
virtual c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocationA, const c_vector< double, SPACE_DIM > &rLocationB)
virtual void PermuteNodes()
double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
bool IsMeshOnDisk() const
Node< SPACE_DIM > * GetNode(unsigned index) const
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
virtual void Rotate(c_matrix< double, SPACE_DIM, SPACE_DIM > rotationMatrix)
virtual unsigned GetNearestNodeIndex(const ChastePoint< SPACE_DIM > &rTestPoint)
virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0)
const std::vector< unsigned > & rGetNodePermutation() const
unsigned GetNumNodeAttributes() const
unsigned CalculateMaximumContainingElementsPerProcess() const
unsigned GetNumBoundaryNodes() const
void SetMeshHasChangedSinceLoading()
Node< SPACE_DIM > * GetNodeFromPrePermutationIndex(unsigned index) const
c_vector< double, DIM > & rGetLocation()
unsigned GetNumProcs() const