MeshalyzerMeshWriter.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 "MeshalyzerMeshWriter.hpp"
00030 #include "Version.hpp"
00031
00033
00035
00036 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00037 MeshalyzerMeshWriter<ELEMENT_DIM, SPACE_DIM>::MeshalyzerMeshWriter(const std::string &rDirectory,
00038 const std::string &rBaseName,
00039 const bool &rCleanDirectory,
00040 const bool &rSetCoolGraphics)
00041 : AbstractTetrahedralMeshWriter<ELEMENT_DIM, SPACE_DIM>(rDirectory, rBaseName, rCleanDirectory)
00042 {
00043
00044
00045
00046
00047
00048 if (rSetCoolGraphics)
00049 {
00050 this->mIndexFromZero = false;
00051 this->mWriteMetaFile = true;
00052 }
00053 else
00054 {
00055 this->mIndexFromZero = true;
00056 this->mWriteMetaFile = false;
00057 }
00058 }
00059
00060 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00061 void MeshalyzerMeshWriter<ELEMENT_DIM, SPACE_DIM>::WriteFiles()
00062 {
00063 std::string comment = "# " + ChasteBuildInfo::GetProvenanceString();
00064
00065
00066 std::string node_file_name = this->mBaseName + ".pts";
00067 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
00068
00069
00070 unsigned num_nodes = this->GetNumNodes();
00071 *p_node_file << num_nodes << "\n";
00072
00073
00074 for (unsigned item_num=0; item_num<num_nodes; item_num++)
00075 {
00076 std::vector<double> current_item = this->GetNextNode();
00077 for (unsigned i=0; i<SPACE_DIM; i++)
00078 {
00079 *p_node_file << current_item[i] << "\t";
00080 }
00081 if (SPACE_DIM==2)
00082 {
00083 *p_node_file << 0 << "\t";
00084 }
00085 if (SPACE_DIM==1)
00086 {
00087 *p_node_file << 0 << "\t" << 0 << "\t";
00088 }
00089 *p_node_file << "\n";
00090
00091 }
00092 *p_node_file << comment;
00093 p_node_file->close();
00094
00095
00096 std::string element_file_name;
00097
00098 if (ELEMENT_DIM == 3)
00099 {
00100 element_file_name = this->mBaseName + ".tetras";
00101 }
00102 else if (ELEMENT_DIM == 2)
00103 {
00104 element_file_name = this->mBaseName + ".tri";
00105 }
00106 else
00107 {
00108 element_file_name = this->mBaseName + ".cnnx";
00109 }
00110
00111 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
00112
00113
00114 unsigned num_elements = this->GetNumElements();
00115
00116 *p_element_file << num_elements << "\n";
00117
00118
00119 unsigned nodes_per_element = ELEMENT_DIM+1;
00120 for (unsigned item_num=0; item_num<num_elements; item_num++)
00121 {
00122 ElementData element_data = this->GetNextElement();
00123
00124 std::vector<unsigned> current_item = element_data.NodeIndices;
00125 for (unsigned i=0; i<nodes_per_element; i++)
00126 {
00127 if (this->mIndexFromZero)
00128 {
00129 *p_element_file << current_item[i] << "\t";
00130 }
00131 else
00132 {
00133 *p_element_file << current_item[i]+1 << "\t";
00134 }
00135 }
00136
00137 *p_element_file << element_data.AttributeValue << "\n";
00138 }
00139 *p_element_file << comment;
00140 p_element_file->close();
00141
00142 if (ELEMENT_DIM==3)
00143 {
00144
00145 std::string face_file_name = this->mBaseName + ".tri";
00146 out_stream p_face_file = this->mpOutputFileHandler->OpenOutputFile(face_file_name);
00147
00148
00149 unsigned num_faces = this->GetNumBoundaryFaces();
00150
00151 *p_face_file << num_faces << "\n";
00152
00153
00154 double material_property = 0.0;
00155 for (unsigned item_num=0; item_num<num_faces; item_num++)
00156 {
00157 std::vector<unsigned> current_item = this->mBoundaryFaceData[item_num];
00158 for (unsigned i=0; i<ELEMENT_DIM; i++)
00159 {
00160 if (this->mIndexFromZero)
00161 {
00162 *p_face_file << current_item[i] << "\t";
00163 }
00164 else
00165 {
00166 *p_face_file << current_item[i]+1 <<"\t";
00167 }
00168 }
00169 *p_face_file << material_property << "\n";
00170 }
00171 *p_face_file << comment;
00172 p_face_file->close();
00173
00174 if (this->mWriteMetaFile)
00175 {
00176 std::string meta_file_name = this->mBaseName + ".cg_in";
00177 out_stream p_meta_file = this->mpOutputFileHandler->OpenOutputFile(meta_file_name);
00178
00179 *p_meta_file << "1\n" << "0\n";
00180 *p_meta_file << face_file_name <<"\n";
00181 *p_meta_file << comment;
00182 p_meta_file->close();
00183 }
00184 }
00185 }
00186
00187 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00188 MeshalyzerMeshWriter<ELEMENT_DIM, SPACE_DIM>::~MeshalyzerMeshWriter()
00189 {
00190 }
00191
00193
00195
00196 template class MeshalyzerMeshWriter<1,1>;
00197 template class MeshalyzerMeshWriter<1,2>;
00198 template class MeshalyzerMeshWriter<1,3>;
00199 template class MeshalyzerMeshWriter<2,2>;
00200 template class MeshalyzerMeshWriter<2,3>;
00201 template class MeshalyzerMeshWriter<3,3>;