36 #include "Toroidal2dVertexMesh.hpp"
42 double cellRearrangementThreshold,
44 :
MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
65 c_vector<double, 2> vector = rLocation2 - rLocation1;
66 vector[0] = fmod(vector[0],
mWidth);
67 vector[1] = fmod(vector[1],
mHeight);
70 if (vector[0] > 0.5*
mWidth)
74 else if (vector[0] < -0.5*
mWidth)
84 else if (vector[1] < -0.5*
mHeight)
102 else if (x_coord < 0.0)
112 else if (y_coord < 0.0)
124 assert(rDimension==0 || rDimension==1);
141 SetNode(node_index, new_node_point);
150 std::vector<Node<2>*> temp_nodes(4*num_nodes);
151 std::vector<VertexElement<2, 2>*> elements;
154 for (
unsigned index=0; index<num_nodes; index++)
156 c_vector<double, 2> location =
GetNode(index)->rGetLocation();
159 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
160 temp_nodes[index] = p_node;
163 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
164 temp_nodes[num_nodes + index] = p_node;
167 p_node =
new Node<2>(2*num_nodes + index,
false, location[0], location[1] +
mHeight);
168 temp_nodes[2*num_nodes + index] = p_node;
172 temp_nodes[3*num_nodes + index] = p_node;
180 unsigned elem_index = elem_iter->
GetIndex();
181 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
183 std::vector<Node<2>*> elem_nodes;
186 bool element_straddles_left_right_boundary =
false;
187 bool element_straddles_top_bottom_boundary =
false;
189 c_vector<double, 2> this_node_location = elem_iter->GetNode(0)->rGetLocation();
190 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
192 c_vector<double, 2> next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
193 c_vector<double, 2> vector = next_node_location - this_node_location;
195 if (fabs(vector[0]) > 0.5*
mWidth)
197 element_straddles_left_right_boundary =
true;
199 if (fabs(vector[1]) > 0.5*
mHeight)
201 element_straddles_top_bottom_boundary =
true;
206 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
208 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
211 if (element_straddles_left_right_boundary)
214 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
215 if (!node_is_right_of_centre)
218 this_node_index += num_nodes;
223 if (element_straddles_top_bottom_boundary)
226 bool node_is_above_centre = (elem_iter->GetNode(local_index)->rGetLocation()[1] - 0.5*
mHeight > 0);
227 if (!node_is_above_centre)
230 this_node_index += 2*num_nodes;
234 elem_nodes.push_back(temp_nodes[this_node_index]);
238 elements.push_back(p_element);
242 std::vector<Node<2>*> nodes;
244 for (
unsigned index=0; index<temp_nodes.size(); index++)
246 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
248 if (num_elems_containing_this_node == 0)
251 delete temp_nodes[index];
256 nodes.push_back(temp_nodes[index]);
274 this->
mNodes.reserve(num_nodes);
279 std::vector<double> node_data;
280 for (
unsigned node_idx = 0 ; node_idx < num_nodes ; node_idx++)
283 node_data.pop_back();
284 this->
mNodes.push_back(
new Node<2>(node_idx, node_data,
false));
293 for (
unsigned elem_idx = 0 ; elem_idx < num_elements ; elem_idx++)
299 std::vector<Node<2>*> nodes;
300 unsigned num_nodes_in_element = element_data.
NodeIndices.size();
301 for (
unsigned j=0; j<num_nodes_in_element; j++)
303 assert(element_data.
NodeIndices[j] < this->mNodes.size());
325 double total_surface_area = 0.0;
326 for (
unsigned elem_idx = 0 ; elem_idx < num_elements ; elem_idx++)
333 EXCEPTION(
"Mesh width and height do not match sheet surface area.");
void SetAttribute(double attribute)
unsigned AddNode(Node< 2 > *pNewNode)
double GetWidth(const unsigned &rDimension) const
virtual ElementData GetNextElementData()=0
c_vector< double, DIM > & rGetLocation()
void SetIndex(unsigned index)
Node< SPACE_DIM > * GetNode(unsigned index) const
#define EXCEPTION(message)
c_vector< double, 2 > GetVectorFromAtoB(const c_vector< double, 2 > &rLocation1, const c_vector< double, 2 > &rLocation2)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
void ConstructFromMeshReader(AbstractMeshReader< 2, 2 > &rMeshReader, double width, double height)
double mCellRearrangementRatio
double mCellRearrangementThreshold
std::vector< unsigned > NodeIndices
virtual bool HasNodePermutation()
bool mMeshChangesDuringSimulation
std::vector< Node< SPACE_DIM > * > mNodes
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
virtual unsigned GetNumElements() const =0
void SetCoordinate(unsigned i, double value)
virtual void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point)
unsigned GetNumNodes() const
MutableVertexMesh< 2, 2 > * GetMeshForVtk()
virtual double GetVolumeOfElement(unsigned index)
virtual unsigned GetNumElementAttributes() const
std::vector< VertexElement< ELEMENT_DIM, SPACE_DIM > * > mElements
void SetNode(unsigned nodeIndex, ChastePoint< 2 > point)
ChastePoint< SPACE_DIM > GetPoint() const
#define CHASTE_CLASS_EXPORT(T)
virtual std::vector< double > GetNextNode()=0
unsigned GetIndex() const
VertexElementIterator GetElementIteratorEnd()
virtual unsigned GetNumNodes() const =0