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