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