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