43#include "Toroidal2dMesh.hpp"
45#include "VtkMeshWriter.hpp"
68 for (
unsigned index=0; index<nodes.size(); index++)
70 Node<2>* p_temp_node = nodes[index];
73 assert( 0 <= x && x < width);
76 assert( 0 <= y && y < depth);
77 mNodes.push_back(p_temp_node);
111 c_vector<double, 2> location;
112 unsigned this_node_index = node_iter->GetIndex();
115 assert(0.0 <= node_iter->rGetLocation()[1]);
116 assert(node_iter->rGetLocation()[1] <=
mHeight);
126 c_vector<double, 2> location;
128 location[1] = location[1] +
mHeight;
138 c_vector<double, 2> location;
140 location[1] = location[1] -
mHeight;
157 c_vector<double, 2> location;
158 unsigned this_node_index = node_iter->GetIndex();
161 assert(0.0 <= node_iter->rGetLocation()[0]);
162 assert(node_iter->rGetLocation()[0] <=
mWidth);
171 c_vector<double, 2> location {};
173 location[0] = location[0] +
mWidth;
183 c_vector<double, 2> location {};
185 location[0] = location[0] -
mWidth;
203 rMap.
Resize(old_num_all_nodes);
207 for (
unsigned i=0; i<old_num_all_nodes; i++)
209 if (
mNodes[i]->IsDeleted())
242 double left_boundary = -0.5*
mWidth;
243 double right_boundary = 1.5*
mWidth;
244 double bottom_boundary = -0.5*
mHeight;
245 double top_boundary = 1.5*
mHeight;
251 unsigned num_nodes_outside = 0;
252 for (
unsigned j=0; j<3; j++)
254 Node<2>* p_node = this->
GetNode(elem_iter->GetNodeGlobalIndex(j));
257 double this_node_x_location = location[0];
258 double this_node_y_location = location[1];
260 if ((this_node_x_location < left_boundary) ||
261 (this_node_x_location > right_boundary) ||
262 (this_node_y_location < bottom_boundary) ||
263 (this_node_y_location > top_boundary))
268 if (num_nodes_outside==3)
270 elem_iter->MarkAsDeleted();
279 unsigned num_nodes_outside = 0;
280 for (
unsigned j=0; j<2; j++)
282 Node<2>* p_node = this->
GetNode((*elem_iter)->GetNodeGlobalIndex(j));
285 double this_node_x_location = location[0];
286 double this_node_y_location = location[1];
288 if ((this_node_x_location < left_boundary) ||
289 (this_node_x_location > right_boundary) ||
290 (this_node_y_location < bottom_boundary) ||
291 (this_node_y_location > top_boundary))
296 if (num_nodes_outside==2)
298 (*elem_iter)->MarkAsDeleted();
390 bool boundary_element_made =
false;
391 unsigned elem_index = 0;
393 while (elem_index<num_elements && !boundary_element_made)
398 boundary_element_made =
true;
399 std::vector<Node<2>*> nodes;
400 nodes.push_back(p_element->
GetNode(0));
401 nodes.push_back(p_element->
GetNode(1));
420 for (
unsigned i=0; i<rMap.
GetSize(); i++)
460 unsigned number_of_left_image_nodes = 0;
461 unsigned number_of_right_image_nodes = 0;
463 for (
unsigned i=0; i<3; i++)
465 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
469 number_of_left_image_nodes++;
473 number_of_right_image_nodes++;
478 if (number_of_right_image_nodes >= 1)
480 elem_iter->MarkAsDeleted();
485 if (number_of_left_image_nodes == 3)
487 elem_iter->MarkAsDeleted();
496 if (number_of_left_image_nodes == 1 || number_of_left_image_nodes == 2)
498 for (
unsigned i=0; i<3; i++)
500 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
504 elem_iter->ReplaceNode(
mNodes[this_node_index],
mNodes[it->second]);
597 unsigned number_of_bottom_image_nodes = 0;
598 unsigned number_of_top_image_nodes = 0;
600 for (
unsigned i=0; i<3; i++)
602 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
606 number_of_bottom_image_nodes++;
610 number_of_top_image_nodes++;
615 if (number_of_top_image_nodes >= 1)
617 elem_iter->MarkAsDeleted();
622 if (number_of_bottom_image_nodes == 3)
624 elem_iter->MarkAsDeleted();
633 if (number_of_bottom_image_nodes == 1 || number_of_bottom_image_nodes == 2)
635 for (
unsigned i=0; i<3; i++)
637 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
641 elem_iter->ReplaceNode(
mNodes[this_node_index],
mNodes[it->second]);
725 c_vector<double, 2> vector = rLocation2 - rLocation1;
726 vector[0] = fmod(vector[0],
mWidth);
727 vector[1] = fmod(vector[1],
mHeight);
733 if (vector[0] > 0.5*
mWidth)
737 else if (vector[0] < -0.5*
mWidth)
745 else if (vector[1] < -0.5*
mHeight)
786 assert(rDimension==0 || rDimension==1);
804 SetNode(node_index, new_node_point,
false);
833 unsigned elem_index = *left_iter;
841 c_vector<unsigned,3> original_element_node_indices;
842 c_vector<unsigned,3> corresponding_element_node_indices;
843 for (
unsigned i=0; i<3; i++)
854 unsigned corresponding_elem_index = *right_iter;
858 bool is_corresponding_node =
true;
860 for (
unsigned i=0; i<3; i++)
862 if ((corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(0)) &&
863 (corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(1)) &&
864 (corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(2)) )
866 is_corresponding_node =
false;
871 if (is_corresponding_node)
895 if (temp_left_hand_side_elements.empty() || temp_right_hand_side_elements.empty())
903 if (temp_right_hand_side_elements.size() == 2 && temp_left_hand_side_elements.size() == 2)
939 unsigned elem_index = *bottom_iter;
947 c_vector<unsigned,3> original_element_node_indices;
948 c_vector<unsigned,3> corresponding_element_node_indices;
949 for (
unsigned i=0; i<3; i++)
960 unsigned corresponding_elem_index = *top_iter;
964 bool is_corresponding_node =
true;
966 for (
unsigned i=0; i<3; i++)
968 if ((corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(0)) &&
969 (corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(1)) &&
970 (corresponding_element_node_indices[i] != p_corresponding_element->
GetNodeGlobalIndex(2)) )
972 is_corresponding_node =
false;
977 if (is_corresponding_node)
985 temp_top_hand_side_elements.erase(corresponding_elem_index);
1002 if (temp_bottom_hand_side_elements.empty() || temp_top_hand_side_elements.empty())
1010 if (temp_top_hand_side_elements.size() == 2 && temp_bottom_hand_side_elements.size() == 2)
1032 unsigned number_of_left_image_nodes = 0;
1033 unsigned number_of_right_image_nodes = 0;
1035 for (
unsigned i=0; i<3; i++)
1037 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
1041 number_of_left_image_nodes++;
1045 number_of_right_image_nodes++;
1060 if (number_of_right_image_nodes == 1 || number_of_right_image_nodes == 2)
1066 if (number_of_left_image_nodes == 1 || number_of_left_image_nodes == 2)
1113 unsigned number_of_bottom_image_nodes = 0;
1114 unsigned number_of_top_image_nodes = 0;
1116 for (
unsigned i=0; i<3; i++)
1118 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(i);
1122 number_of_bottom_image_nodes++;
1126 number_of_top_image_nodes++;
1131 if (number_of_top_image_nodes == 1 || number_of_top_image_nodes == 2)
1137 if (number_of_bottom_image_nodes == 1 || number_of_bottom_image_nodes == 2)
1156 unsigned corresponding_node_index = UINT_MAX;
1198 assert(corresponding_node_index != UINT_MAX);
1199 return corresponding_node_index;
1205 unsigned corresponding_node_index = UINT_MAX;
1216 std::vector<unsigned>::iterator top_im_iter = std::find(
mTopImages.begin(),
mTopImages.end(), nodeIndex);
1247 assert(corresponding_node_index != UINT_MAX);
1248 return corresponding_node_index;
1255 unsigned num_nodes =
mNodes.size();
1256 for (
unsigned i=0; i<num_nodes; i++)
1258 double& x_location = (
mNodes[i]->rGetModifiableLocation())[0];
1259 if (x_location < 0.0)
1263 else if (x_location >=
mWidth)
1265 x_location = fmod(x_location,
mWidth);
1267 double& y_location = (
mNodes[i]->rGetModifiableLocation())[1];
1268 if (y_location < 0.0)
1272 else if (y_location >=
mHeight)
1274 y_location = fmod(y_location,
mHeight);
#define CHASTE_CLASS_EXPORT(T)
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
unsigned GetNodeGlobalIndex(unsigned localIndex) const
virtual unsigned GetNumAllNodes() const
NodeIterator GetNodeIteratorEnd()
Node< SPACE_DIM > * GetNode(unsigned index) const
std::vector< Node< SPACE_DIM > * > mNodes
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
std::vector< BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > * >::const_iterator BoundaryElementIterator
ElementIterator GetElementIteratorEnd()
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
BoundaryElementIterator GetBoundaryElementIteratorBegin() const
unsigned GetNumAllElements() const
BoundaryElementIterator GetBoundaryElementIteratorEnd() const
std::vector< BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > * > mBoundaryElements
c_vector< double, DIM > & rGetLocation()
void SetCoordinate(unsigned i, double value)
void ReIndex(NodeMap &map)
virtual void SetNode(unsigned index, ChastePoint< SPACE_DIM > point, bool concreteMove=true)
std::vector< unsigned > mDeletedBoundaryElementIndices
std::vector< unsigned > mDeletedElementIndices
std::vector< unsigned > mDeletedNodeIndices
virtual unsigned AddNode(Node< SPACE_DIM > *pNewNode)
void SetDeleted(unsigned index)
unsigned GetNewIndex(unsigned oldIndex) const
void SetNewIndex(unsigned oldIndex, unsigned newIndex)
void Resize(unsigned size)
bool IsDeleted(unsigned index)
const c_vector< double, SPACE_DIM > & rGetLocation() const
ChastePoint< SPACE_DIM > GetPoint() const
std::vector< double > mBoundaryElementJacobianDeterminants
std::vector< c_vector< double, SPACE_DIM > > mBoundaryElementWeightedDirections
std::vector< unsigned > mBottomOriginals
std::map< unsigned, unsigned > mImageToRightOriginalNodeMap
void GenerateVectorsOfElementsStraddlingToroidalPeriodicBoundaries()
std::vector< unsigned > mLeftImages
std::vector< unsigned > mRightOriginals
Toroidal2dMesh(double width, double depth)
std::set< unsigned > mBottomPeriodicBoundaryElementIndices
void ReconstructToroidalMesh()
std::map< unsigned, unsigned > mImageToTopOriginalNodeMap
std::set< unsigned > mTopPeriodicBoundaryElementIndices
std::vector< unsigned > mLeftOriginals
unsigned GetCorrespondingToroidalNodeIndex(unsigned nodeIndex)
void SetNode(unsigned index, ChastePoint< 2 > point, bool concreteMove)
void CorrectToroidalNonPeriodicMesh()
std::set< unsigned > mLeftPeriodicBoundaryElementIndices
std::map< unsigned, unsigned > mImageToBottomOriginalNodeMap
c_vector< double, 2 > GetVectorFromAtoB(const c_vector< double, 2 > &rLocation1, const c_vector< double, 2 > &rLocation2)
std::vector< unsigned > mRightImages
std::set< unsigned > mRightPeriodicBoundaryElementIndices
std::vector< unsigned > mTopOriginals
unsigned GetCorrespondingCylindricalNodeIndex(unsigned nodeIndex)
void ReconstructCylindricalMesh()
double GetWidth(const unsigned &rDimension) const
std::vector< unsigned > mBottomImages
std::map< unsigned, unsigned > mImageToLeftOriginalNodeMap
unsigned AddNode(Node< 2 > *pNewNode)
void CorrectCylindricalNonPeriodicMesh()
std::vector< unsigned > mTopImages
void GenerateVectorsOfElementsStraddlingCylindricalPeriodicBoundaries()