36 #include "AbstractMesh.hpp" 43 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
45 : mpDistributedVectorFactory(nullptr),
46 mMeshFileBaseName(
""),
47 mMeshChangesDuringSimulation(false)
51 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
55 for (
unsigned i=0; i<
mNodes.size(); i++)
65 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
71 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
77 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
83 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
88 assert(
mNodes.size() != 0u);
89 return mNodes[0]->GetNumNodeAttributes();
92 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
96 return mNodes[local_index];
99 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
105 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
119 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
126 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
132 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
146 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
151 EXCEPTION(
"Cannot change the mesh's distributed vector factory once it has been set.");
155 EXCEPTION(
"The distributed vector factory provided to the mesh is for the wrong number of processes.");
161 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
168 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
174 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
180 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
185 EXCEPTION(
"This mesh was not constructed from a file.");
191 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
197 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
203 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
205 const c_vector<double, SPACE_DIM>& rLocationA,
const c_vector<double, SPACE_DIM>& rLocationB)
207 c_vector<double, SPACE_DIM> vector = rLocationB - rLocationA;
211 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
215 mNodes[indexB]->rGetLocation());
216 return norm_2(vector);
219 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
222 assert(rDimension < SPACE_DIM);
226 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
230 c_vector<double, SPACE_DIM> minimum_point;
231 c_vector<double, SPACE_DIM> maximum_point;
236 minimum_point = scalar_vector<double>(SPACE_DIM, 0.0);
237 maximum_point = scalar_vector<double>(SPACE_DIM, 0.0);
241 minimum_point = scalar_vector<double>(SPACE_DIM, DBL_MAX);
242 maximum_point = scalar_vector<double>(SPACE_DIM, -DBL_MAX);
246 for (
unsigned index=0; index<rNodes.size(); index++)
248 if (!rNodes[index]->IsDeleted())
251 c_vector<double, SPACE_DIM> position;
252 position = rNodes[index]->rGetLocation();
255 for (
unsigned i=0; i<SPACE_DIM; i++)
257 if (position[i] < minimum_point[i])
259 minimum_point[i] = position[i];
261 if (position[i] > maximum_point[i])
263 maximum_point[i] = position[i];
276 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
281 return bounding_cuboid;
284 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
298 unsigned best_node_index = 0u;
299 double best_node_point_distance = DBL_MAX;
301 const c_vector<double, SPACE_DIM>& test_location = rTestPoint.
rGetLocation();
303 for (
unsigned node_index = 0; node_index <
mNodes.size(); node_index++)
308 if (node_point_distance < best_node_point_distance)
310 best_node_index = node_index;
311 best_node_point_distance = node_point_distance;
318 return mNodes[best_node_index]->GetIndex();
322 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
325 unsigned num_nodes =
mNodes.size();
327 for (
unsigned i=0; i<num_nodes; i++)
329 c_vector<double, SPACE_DIM>& r_location =
mNodes[i]->rGetModifiableLocation();
332 r_location[2] *= zScale;
336 r_location[1] *= yScale;
338 r_location[0] *= xScale;
344 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
346 const double xMovement,
347 const double yMovement,
348 const double zMovement)
350 c_vector<double, SPACE_DIM> displacement;
355 displacement[2] = zMovement;
357 displacement[1] = yMovement;
359 displacement[0] = xMovement;
365 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
368 unsigned num_nodes = this->
mNodes.size();
370 for (
unsigned i=0; i<num_nodes; i++)
372 c_vector<double, SPACE_DIM>& r_location = this->
mNodes[i]->rGetModifiableLocation();
373 r_location += rDisplacement;
379 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
382 unsigned num_nodes = this->
mNodes.size();
384 for (
unsigned i=0; i<num_nodes; i++)
386 c_vector<double, SPACE_DIM>& r_location = this->
mNodes[i]->rGetModifiableLocation();
387 r_location = prod(rotationMatrix, r_location);
393 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
396 assert(SPACE_DIM == 3);
397 double norm = norm_2(axis);
398 c_vector<double,3> unit_axis=axis/norm;
400 c_matrix<double, SPACE_DIM,SPACE_DIM> rotation_matrix;
402 double c = cos(angle);
403 double s = sin(angle);
405 rotation_matrix(0,0) = unit_axis(0)*unit_axis(0)+c*(1-unit_axis(0)*unit_axis(0));
406 rotation_matrix(0,1) = unit_axis(0)*unit_axis(1)*(1-c) - unit_axis(2)*s;
407 rotation_matrix(1,0) = unit_axis(0)*unit_axis(1)*(1-c) + unit_axis(2)*s;
408 rotation_matrix(1,1) = unit_axis(1)*unit_axis(1)+c*(1-unit_axis(1)*unit_axis(1));
409 rotation_matrix(0,2) = unit_axis(0)*unit_axis(2)*(1-c)+unit_axis(1)*s;
410 rotation_matrix(1,2) = unit_axis(1)*unit_axis(2)*(1-c)-unit_axis(0)*s;
411 rotation_matrix(2,0) = unit_axis(0)*unit_axis(2)*(1-c)-unit_axis(1)*s;
412 rotation_matrix(2,1) = unit_axis(1)*unit_axis(2)*(1-c)+unit_axis(0)*s;
413 rotation_matrix(2,2) = unit_axis(2)*unit_axis(2)+c*(1-unit_axis(2)*unit_axis(2));
418 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
423 EXCEPTION(
"This rotation is only valid in 3D");
425 c_matrix<double , SPACE_DIM, SPACE_DIM> x_rotation_matrix=identity_matrix<double>(SPACE_DIM);
427 x_rotation_matrix(1,1) = cos(theta);
428 x_rotation_matrix(1,2) = sin(theta);
429 x_rotation_matrix(2,1) = -sin(theta);
430 x_rotation_matrix(2,2) = cos(theta);
431 Rotate(x_rotation_matrix);
434 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
439 EXCEPTION(
"This rotation is only valid in 3D");
441 c_matrix<double , SPACE_DIM, SPACE_DIM> y_rotation_matrix=identity_matrix<double>(SPACE_DIM);
443 y_rotation_matrix(0,0) = cos(theta);
444 y_rotation_matrix(0,2) = -sin(theta);
445 y_rotation_matrix(2,0) = sin(theta);
446 y_rotation_matrix(2,2) = cos(theta);
449 Rotate(y_rotation_matrix);
452 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
457 EXCEPTION(
"This rotation is not valid in less than 2D");
459 c_matrix<double , SPACE_DIM, SPACE_DIM> z_rotation_matrix=identity_matrix<double>(SPACE_DIM);
462 z_rotation_matrix(0,0) = cos(theta);
463 z_rotation_matrix(0,1) = sin(theta);
464 z_rotation_matrix(1,0) = -sin(theta);
465 z_rotation_matrix(1,1) = cos(theta);
467 Rotate(z_rotation_matrix);
470 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
476 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
481 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
487 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
491 for (
unsigned local_node_index=0; local_node_index<
mNodes.size(); local_node_index++)
493 unsigned num=
mNodes[local_node_index]->GetNumContainingElements();
502 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
virtual DistributedVectorFactory * GetDistributedVectorFactory()
std::vector< Node< SPACE_DIM > * > mBoundaryNodes
virtual void ReadNodesPerProcessorFile(const std::string &rNodesPerProcessorFile)
virtual unsigned GetNearestNodeIndex(const ChastePoint< SPACE_DIM > &rTestPoint)
c_vector< double, DIM > & rGetLocation()
virtual void RefreshMesh()
virtual Node< SPACE_DIM > * GetNodeOrHaloNode(unsigned index) const
virtual unsigned SolveNodeMapping(unsigned index) const =0
const std::vector< unsigned > & rGetNodePermutation() const
bool IsMeshChanging() const
virtual void Translate(const c_vector< double, SPACE_DIM > &rDisplacement)
std::vector< unsigned > mNodePermutation
Node< SPACE_DIM > * GetNode(unsigned index) const
#define EXCEPTION(message)
unsigned CalculateMaximumContainingElementsPerProcess() const
std::string GetMeshFileBaseName() const
virtual ChasteCuboid< SPACE_DIM > CalculateBoundingBox() const
virtual unsigned GetNumNodes() const
virtual void PermuteNodes()
BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const
virtual unsigned GetNumAllNodes() const
virtual void SetElementOwnerships()
std::string mMeshFileBaseName
double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
bool mMeshChangesDuringSimulation
std::vector< Node< SPACE_DIM > * > mNodes
DistributedVectorFactory * mpDistributedVectorFactory
unsigned GetNumBoundaryNodes() const
unsigned GetNumNodeAttributes() const
std::vector< Node< SPACE_DIM > * >::const_iterator BoundaryNodeIterator
bool IsMeshOnDisk() const
void SetMeshHasChangedSinceLoading()
virtual double GetWidth(const unsigned &rDimension) const
virtual void Rotate(c_matrix< double, SPACE_DIM, SPACE_DIM > rotationMatrix)
virtual c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocationA, const c_vector< double, SPACE_DIM > &rLocationB)
BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const
virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0)
virtual void SetDistributedVectorFactory(DistributedVectorFactory *pFactory)
void RotateY(const double theta)
void RotateZ(const double theta)
unsigned GetNumProcs() const
Node< SPACE_DIM > * GetNodeFromPrePermutationIndex(unsigned index) const
void RotateX(const double theta)