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
00031
00032
00033
00034
00035
00036
00037 #ifndef _ABSTRACTTETRAHEDRALMESHWRITER_HPP_
00038 #define _ABSTRACTTETRAHEDRALMESHWRITER_HPP_
00039
00040
00041 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00042 class AbstractTetrahedralMesh;
00043
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 class DistributedTetrahedralMesh;
00046
00047 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00048 class MixedDimensionMesh;
00049
00050 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00051 struct MeshWriterIterators;
00052
00053 #include <fstream>
00054 #include <sstream>
00055 #include <boost/scoped_array.hpp>
00056
00057 #include "AbstractMeshWriter.hpp"
00058 #include "AbstractMesh.hpp"
00059 #include "NodeMap.hpp"
00060
00061 #include "GenericEventHandler.hpp"
00063 class MeshEventHandler : public GenericEventHandler<11, MeshEventHandler>
00064 {
00065 public:
00066 static const char* EventName[11];
00069 typedef enum
00070 {
00071 TRIANGLES=0,
00072 BINTRI,
00073 VTK,
00074 PVTK,
00075 NODE,
00076 ELE,
00077 FACE,
00078 NCL,
00079 COMM1,
00080 COMM2
00081 } EventType;
00082 };
00083
00087 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00088 class AbstractTetrahedralMeshWriter : public AbstractMeshWriter<ELEMENT_DIM, SPACE_DIM>
00089 {
00090 private:
00099 void PostElement(unsigned globalIndex, unsigned indices[], unsigned numIndices, unsigned tag, double attribute)
00100 {
00101 MeshEventHandler::BeginEvent(MeshEventHandler::COMM1);
00102 MPI_Ssend(indices, numIndices, MPI_UNSIGNED, 0,
00103 tag,
00104 PETSC_COMM_WORLD);
00105 MeshEventHandler::EndEvent(MeshEventHandler::COMM1);
00106
00107 MeshEventHandler::BeginEvent(MeshEventHandler::COMM2);
00108 MPI_Ssend(&attribute, 1, MPI_DOUBLE, 0,
00109 tag,
00110 PETSC_COMM_WORLD);
00111 MeshEventHandler::EndEvent(MeshEventHandler::COMM2);
00112 }
00120 void UnpackElement(ElementData& rElementData, unsigned globalIndex, unsigned numIndices, unsigned tag)
00121 {
00122 assert( numIndices == rElementData.NodeIndices.size());
00123 boost::scoped_array<unsigned> raw_indices(new unsigned[numIndices]);
00124 MPI_Status status;
00125
00126 MeshEventHandler::BeginEvent(MeshEventHandler::COMM1);
00127 MPI_Recv(raw_indices.get(), numIndices, MPI_UNSIGNED, MPI_ANY_SOURCE,
00128 tag,
00129 PETSC_COMM_WORLD, &status);
00130 MeshEventHandler::EndEvent(MeshEventHandler::COMM1);
00131
00132 for (unsigned j=0; j< rElementData.NodeIndices.size(); j++)
00133 {
00134 rElementData.NodeIndices[j] = raw_indices[j];
00135 }
00136
00137
00138 double attribute;
00139 MeshEventHandler::BeginEvent(MeshEventHandler::COMM2);
00140 MPI_Recv(&attribute, 1U, MPI_DOUBLE, MPI_ANY_SOURCE,
00141 tag,
00142 PETSC_COMM_WORLD, &status);
00143 MeshEventHandler::EndEvent(MeshEventHandler::COMM2);
00144
00145
00146 rElementData.AttributeValue = attribute;
00147 }
00148
00155 virtual void WriteFilesUsingParallelMesh(bool keepOriginalElementIndexing=true);
00156
00164 void WriteNclFile(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00165 bool invertMeshPermutation=false);
00166
00170 virtual void CreateFilesWithHeaders();
00171
00175 virtual void AppendLocalDataToFiles();
00176
00180 virtual void WriteFilesFooter();
00181
00182 NodeMap* mpNodeMap;
00184 protected:
00185
00186 unsigned mNodesPerElement;
00187 unsigned mNodesPerBoundaryElement;
00189 AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* mpMesh;
00190 DistributedTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* mpDistributedMesh;
00191 MixedDimensionMesh<ELEMENT_DIM,SPACE_DIM>* mpMixedMesh;
00192 MeshWriterIterators<ELEMENT_DIM,SPACE_DIM>* mpIters;
00194 bool mIndexFromZero;
00195 bool mWriteMetaFile;
00196 unsigned mNodeCounterForParallelMesh;
00197 unsigned mElementCounterForParallelMesh;
00198 unsigned mBoundaryElementCounterForParallelMesh;
00199 unsigned mCableElementCounterForParallelMesh;
00200 bool mFilesAreBinary;
00202 public:
00203
00211 AbstractTetrahedralMeshWriter(const std::string& rDirectory,
00212 const std::string& rBaseName,
00213 const bool clearOutputDir=true);
00214
00218 virtual ~AbstractTetrahedralMeshWriter();
00219
00229 virtual void WriteFilesUsingMesh(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00230 bool keepOriginalElementIndexing=true);
00231
00241 void WriteFilesUsingMeshReaderAndMesh(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00242 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>& rMesh);
00243
00247 std::vector<double> GetNextNode();
00248
00249
00253 ElementData GetNextElement();
00254
00258 ElementData GetNextBoundaryElement();
00259
00263 ElementData GetNextCableElement();
00264 };
00265
00266 #endif //_ABSTRACTTETRAHEDRALMESHWRITER_HPP_