Cylindrical2dVertexMesh.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Cylindrical2dVertexMesh.hpp"
00030
00031 Cylindrical2dVertexMesh::Cylindrical2dVertexMesh(double width,
00032 std::vector<Node<2>*> nodes,
00033 std::vector<VertexElement<2, 2>*> vertexElements,
00034 double cellRearrangementThreshold,
00035 double t2Threshold)
00036 : MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
00037 mWidth(width)
00038 {
00039
00040 ReMesh();
00041 }
00042
00043 Cylindrical2dVertexMesh::Cylindrical2dVertexMesh()
00044 {
00045 }
00046
00047 Cylindrical2dVertexMesh::~Cylindrical2dVertexMesh()
00048 {
00049 }
00050
00051 c_vector<double, 2> Cylindrical2dVertexMesh::GetVectorFromAtoB(const c_vector<double, 2>& rLocation1, const c_vector<double, 2>& rLocation2)
00052 {
00053 assert(mWidth > 0.0);
00054
00055 c_vector<double, 2> vector = rLocation2 - rLocation1;
00056 vector[0] = fmod(vector[0], mWidth);
00057
00058
00059 if (vector[0] > mWidth/2.0)
00060 {
00061 vector[0] -= mWidth;
00062 }
00063 else if (vector[0] < -mWidth/2.0)
00064 {
00065 vector[0] += mWidth;
00066 }
00067 return vector;
00068 }
00069
00070 void Cylindrical2dVertexMesh::SetNode(unsigned nodeIndex, ChastePoint<2> point)
00071 {
00072 double x_coord = point.rGetLocation()[0];
00073
00074
00075 if (x_coord >= mWidth)
00076 {
00077
00078 point.SetCoordinate(0, x_coord - mWidth);
00079 }
00080 else if (x_coord < 0.0)
00081 {
00082
00083 point.SetCoordinate(0, x_coord + mWidth);
00084 }
00085
00086
00087 MutableVertexMesh<2,2>::SetNode(nodeIndex, point);
00088 }
00089
00090 double Cylindrical2dVertexMesh::GetWidth(const unsigned& rDimension) const
00091 {
00092 double width = 0.0;
00093 assert(rDimension==0 || rDimension==1);
00094 if (rDimension==0)
00095 {
00096 width = mWidth;
00097 }
00098 else
00099 {
00100 width = VertexMesh<2,2>::GetWidth(rDimension);
00101 }
00102 return width;
00103 }
00104
00105 unsigned Cylindrical2dVertexMesh::AddNode(Node<2>* pNewNode)
00106 {
00107 unsigned node_index = MutableVertexMesh<2,2>::AddNode(pNewNode);
00108
00109
00110 ChastePoint<2> new_node_point = pNewNode->GetPoint();
00111 SetNode(node_index, new_node_point);
00112
00113 return node_index;
00114 }
00115
00116 double Cylindrical2dVertexMesh::GetVolumeOfElement(unsigned index)
00117 {
00118 VertexElement<2, 2>* p_element = GetElement(index);
00119
00120 c_vector<double, 2> first_node = p_element->GetNodeLocation(0);
00121 c_vector<double, 2> current_node;
00122 c_vector<double, 2> anticlockwise_node;
00123 c_vector<double, 2> transformed_current_node;
00124 c_vector<double, 2> transformed_anticlockwise_node;
00125
00126 unsigned num_nodes_in_element = p_element->GetNumNodes();
00127
00128 double element_area = 0;
00129
00130 for (unsigned local_index=0; local_index<num_nodes_in_element; local_index++)
00131 {
00132
00133 current_node = p_element->GetNodeLocation(local_index);
00134 anticlockwise_node = p_element->GetNodeLocation((local_index+1)%num_nodes_in_element);
00135
00136
00137
00138
00139
00140
00141 transformed_current_node = GetVectorFromAtoB(first_node, current_node);
00142 transformed_anticlockwise_node = GetVectorFromAtoB(first_node, anticlockwise_node);
00143
00144 element_area += 0.5*(transformed_current_node[0]*transformed_anticlockwise_node[1]
00145 - transformed_anticlockwise_node[0]*transformed_current_node[1]);
00146 }
00147
00148 return element_area;
00149 }
00150
00151 c_vector<double, 2> Cylindrical2dVertexMesh::GetCentroidOfElement(unsigned index)
00152 {
00153 VertexElement<2, 2>* p_element = GetElement(index);
00154
00155 c_vector<double, 2> centroid;
00156 c_vector<double, 2> transformed_centroid = zero_vector<double>(2);
00157 c_vector<double, 2> first_node = p_element->GetNodeLocation(0);
00158 c_vector<double, 2> current_node_location;
00159 c_vector<double, 2> next_node_location;
00160 c_vector<double, 2> transformed_current_node;
00161 c_vector<double, 2> transformed_anticlockwise_node;
00162
00163 double temp_centroid_x = 0;
00164 double temp_centroid_y = 0;
00165
00166 unsigned num_nodes_in_element = p_element->GetNumNodes();
00167
00168 for (unsigned local_index=0; local_index<num_nodes_in_element; local_index++)
00169 {
00170
00171 current_node_location = p_element->GetNodeLocation(local_index);
00172 next_node_location = p_element->GetNodeLocation((local_index+1)%num_nodes_in_element);
00173
00174
00175
00176
00177
00178
00179 transformed_current_node = GetVectorFromAtoB(first_node, current_node_location);
00180 transformed_anticlockwise_node = GetVectorFromAtoB(first_node, next_node_location);
00181
00182 temp_centroid_x += (transformed_current_node[0]+transformed_anticlockwise_node[0])*(transformed_current_node[0]*transformed_anticlockwise_node[1]-transformed_current_node[1]*transformed_anticlockwise_node[0]);
00183 temp_centroid_y += (transformed_current_node[1]+transformed_anticlockwise_node[1])*(transformed_current_node[0]*transformed_anticlockwise_node[1]-transformed_current_node[1]*transformed_anticlockwise_node[0]);
00184 }
00185
00186 double vertex_area = GetVolumeOfElement(index);
00187 double centroid_coefficient = 1.0/(6.0*vertex_area);
00188
00189 transformed_centroid(0) = centroid_coefficient*temp_centroid_x;
00190 transformed_centroid(1) = centroid_coefficient*temp_centroid_y;
00191
00192 centroid = transformed_centroid + first_node;
00193
00194 return centroid;
00195 }
00196
00197
00198 #include "SerializationExportWrapperForCpp.hpp"
00199 CHASTE_CLASS_EXPORT(Cylindrical2dVertexMesh)