36 #include "AbstractMesh.hpp"
43 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
45 : mpDistributedVectorFactory(NULL),
46 mMeshFileBaseName(
""),
47 mMeshChangesDuringSimulation(false)
51 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
55 for (
unsigned i=0; i<mNodes.size(); i++)
59 if (mpDistributedVectorFactory)
61 delete mpDistributedVectorFactory;
65 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
71 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
74 return mBoundaryNodes.size();
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>
95 unsigned local_index = SolveNodeMapping(index);
96 return mNodes[local_index];
99 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
102 return GetNode(index);
105 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
108 if (mNodePermutation.empty())
110 return GetNode(index);
114 return GetNode(mNodePermutation[index]);
118 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
125 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
131 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
134 if (mpDistributedVectorFactory == NULL)
139 SetElementOwnerships();
142 return mpDistributedVectorFactory;
144 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
147 if (mpDistributedVectorFactory)
149 EXCEPTION(
"Cannot change the mesh's distributed vector factory once it has been set.");
153 EXCEPTION(
"The distributed vector factory provided to the mesh is for the wrong number of processes.");
155 mpDistributedVectorFactory = pFactory;
158 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
164 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
167 return mBoundaryNodes.begin();
170 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
173 return mBoundaryNodes.end();
176 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
181 EXCEPTION(
"This mesh was not constructed from a file.");
184 return mMeshFileBaseName;
187 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
190 return (mMeshFileBaseName !=
"");
193 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
196 return mNodePermutation;
199 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
201 const c_vector<double, SPACE_DIM>& rLocationA,
const c_vector<double, SPACE_DIM>& rLocationB)
203 c_vector<double, SPACE_DIM> vector = rLocationB - rLocationA;
207 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
210 c_vector<double, SPACE_DIM> vector = GetVectorFromAtoB(mNodes[indexA]->rGetLocation(),
211 mNodes[indexB]->rGetLocation());
212 return norm_2(vector);
215 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
218 assert(rDimension < SPACE_DIM);
219 return CalculateBoundingBox(mNodes).GetWidth(rDimension);
222 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
226 c_vector<double, SPACE_DIM> minimum_point;
227 c_vector<double, SPACE_DIM> maximum_point;
232 minimum_point = scalar_vector<double>(SPACE_DIM, 0.0);
233 maximum_point = scalar_vector<double>(SPACE_DIM, 0.0);
237 minimum_point = scalar_vector<double>(SPACE_DIM, DBL_MAX);
238 maximum_point = scalar_vector<double>(SPACE_DIM, -DBL_MAX);
242 for (
unsigned index=0; index<rNodes.size(); index++)
244 if (!rNodes[index]->IsDeleted())
247 c_vector<double, SPACE_DIM> position;
248 position = rNodes[index]->rGetLocation();
251 for (
unsigned i=0; i<SPACE_DIM; i++)
253 if (position[i] < minimum_point[i])
255 minimum_point[i] = position[i];
257 if (position[i] > maximum_point[i])
259 maximum_point[i] = position[i];
272 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
277 return bounding_cuboid;
280 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
290 unsigned best_node_index = 0u;
291 double best_node_point_distance = DBL_MAX;
293 c_vector<double, SPACE_DIM> test_location = rTestPoint.
rGetLocation();
295 for (
unsigned node_index = 0; node_index < mNodes.size(); node_index++)
298 double node_point_distance = norm_2( GetVectorFromAtoB(mNodes[node_index]->rGetLocation(), test_location) );
300 if (node_point_distance < best_node_point_distance)
302 best_node_index = node_index;
303 best_node_point_distance = node_point_distance;
310 return mNodes[best_node_index]->GetIndex();
314 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
317 unsigned num_nodes = mNodes.size();
319 for (
unsigned i=0; i<num_nodes; i++)
321 c_vector<double, SPACE_DIM>& r_location = mNodes[i]->rGetModifiableLocation();
324 r_location[2] *= zScale;
328 r_location[1] *= yScale;
330 r_location[0] *= xScale;
336 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
338 const double xMovement,
339 const double yMovement,
340 const double zMovement)
342 c_vector<double, SPACE_DIM> displacement;
347 displacement[2] = zMovement;
349 displacement[1] = yMovement;
351 displacement[0] = xMovement;
354 Translate(displacement);
357 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
360 unsigned num_nodes = this->mNodes.size();
362 for (
unsigned i=0; i<num_nodes; i++)
364 c_vector<double, SPACE_DIM>& r_location = this->mNodes[i]->rGetModifiableLocation();
365 r_location += rDisplacement;
371 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
374 unsigned num_nodes = this->mNodes.size();
376 for (
unsigned i=0; i<num_nodes; i++)
378 c_vector<double, SPACE_DIM>& r_location = this->mNodes[i]->rGetModifiableLocation();
379 r_location = prod(rotationMatrix, r_location);
385 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
388 assert(SPACE_DIM == 3);
389 double norm = norm_2(axis);
390 c_vector<double,3> unit_axis=axis/norm;
392 c_matrix<double, SPACE_DIM,SPACE_DIM> rotation_matrix;
394 double c = cos(angle);
395 double s = sin(angle);
397 rotation_matrix(0,0) = unit_axis(0)*unit_axis(0)+c*(1-unit_axis(0)*unit_axis(0));
398 rotation_matrix(0,1) = unit_axis(0)*unit_axis(1)*(1-c) - unit_axis(2)*s;
399 rotation_matrix(1,0) = unit_axis(0)*unit_axis(1)*(1-c) + unit_axis(2)*s;
400 rotation_matrix(1,1) = unit_axis(1)*unit_axis(1)+c*(1-unit_axis(1)*unit_axis(1));
401 rotation_matrix(0,2) = unit_axis(0)*unit_axis(2)*(1-c)+unit_axis(1)*s;
402 rotation_matrix(1,2) = unit_axis(1)*unit_axis(2)*(1-c)-unit_axis(0)*s;
403 rotation_matrix(2,0) = unit_axis(0)*unit_axis(2)*(1-c)-unit_axis(1)*s;
404 rotation_matrix(2,1) = unit_axis(1)*unit_axis(2)*(1-c)+unit_axis(0)*s;
405 rotation_matrix(2,2) = unit_axis(2)*unit_axis(2)+c*(1-unit_axis(2)*unit_axis(2));
407 Rotate(rotation_matrix);
410 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
415 EXCEPTION(
"This rotation is only valid in 3D");
417 c_matrix<double , SPACE_DIM, SPACE_DIM> x_rotation_matrix=identity_matrix<double>(SPACE_DIM);
419 x_rotation_matrix(1,1) = cos(theta);
420 x_rotation_matrix(1,2) = sin(theta);
421 x_rotation_matrix(2,1) = -sin(theta);
422 x_rotation_matrix(2,2) = cos(theta);
423 Rotate(x_rotation_matrix);
426 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
431 EXCEPTION(
"This rotation is only valid in 3D");
433 c_matrix<double , SPACE_DIM, SPACE_DIM> y_rotation_matrix=identity_matrix<double>(SPACE_DIM);
435 y_rotation_matrix(0,0) = cos(theta);
436 y_rotation_matrix(0,2) = -sin(theta);
437 y_rotation_matrix(2,0) = sin(theta);
438 y_rotation_matrix(2,2) = cos(theta);
441 Rotate(y_rotation_matrix);
444 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
449 EXCEPTION(
"This rotation is not valid in less than 2D");
451 c_matrix<double , SPACE_DIM, SPACE_DIM> z_rotation_matrix=identity_matrix<double>(SPACE_DIM);
454 z_rotation_matrix(0,0) = cos(theta);
455 z_rotation_matrix(0,1) = sin(theta);
456 z_rotation_matrix(1,0) = -sin(theta);
457 z_rotation_matrix(1,1) = cos(theta);
459 Rotate(z_rotation_matrix);
462 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
468 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
473 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
476 return mMeshChangesDuringSimulation;
479 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
483 for (
unsigned local_node_index=0; local_node_index<mNodes.size(); local_node_index++)
485 unsigned num=mNodes[local_node_index]->GetNumContainingElements();
494 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
498 mMeshFileBaseName =
"";
virtual DistributedVectorFactory * GetDistributedVectorFactory()
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
const std::vector< unsigned > & rGetNodePermutation() const
bool IsMeshChanging() const
virtual void Translate(const c_vector< double, SPACE_DIM > &rDisplacement)
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()
double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
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)