Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
AbstractTetrahedralMeshWriter.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36
37#ifndef _ABSTRACTTETRAHEDRALMESHWRITER_HPP_
38#define _ABSTRACTTETRAHEDRALMESHWRITER_HPP_
39
40// Forward declaration prevents circular include chain
41template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
43
44template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
46
47template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
49
50template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
52
53#include <fstream>
54#include <sstream>
55#include <boost/scoped_array.hpp>
56
57#include "AbstractMeshWriter.hpp"
58#include "AbstractMesh.hpp"
59#include "NodeMap.hpp"
60
61#include "GenericEventHandler.hpp"
63class MeshEventHandler : public GenericEventHandler<11, MeshEventHandler>
64{
65public:
66 static const char* EventName[11];
69 typedef enum
70 {
71 TRIANGLES=0,
72 BINTRI,
73 VTK,
74 PVTK,
75 NODE,
76 ELE,
77 FACE,
78 NCL,
79 COMM1,
80 COMM2
81 } EventType;
82};
83
87template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
88class AbstractTetrahedralMeshWriter : public AbstractMeshWriter<ELEMENT_DIM, SPACE_DIM>
89{
90private:
99 void PostElement(unsigned globalIndex, unsigned indices[], unsigned numIndices, unsigned tag, double attribute)
100 {
101 MeshEventHandler::BeginEvent(MeshEventHandler::COMM1);
102 MPI_Ssend(indices, numIndices, MPI_UNSIGNED, 0,
103 tag, //Elements sent with tags offset
104 PETSC_COMM_WORLD);
105 MeshEventHandler::EndEvent(MeshEventHandler::COMM1);
106 // Attribute value has the same tag (assume that it doesn't overtake the previous message)
107 MeshEventHandler::BeginEvent(MeshEventHandler::COMM2);
108 MPI_Ssend(&attribute, 1, MPI_DOUBLE, 0,
109 tag, //Elements sent with tags offset
110 PETSC_COMM_WORLD);
111 MeshEventHandler::EndEvent(MeshEventHandler::COMM2);
112 }
120 void UnpackElement(ElementData& rElementData, unsigned globalIndex, unsigned numIndices, unsigned tag)
121 {
122 assert( numIndices == rElementData.NodeIndices.size());
123 boost::scoped_array<unsigned> raw_indices(new unsigned[numIndices]);
124 MPI_Status status;
125 // Get it from elsewhere
126 MeshEventHandler::BeginEvent(MeshEventHandler::COMM1);
127 MPI_Recv(raw_indices.get(), numIndices, MPI_UNSIGNED, MPI_ANY_SOURCE,
128 tag,
129 PETSC_COMM_WORLD, &status);
130 MeshEventHandler::EndEvent(MeshEventHandler::COMM1);
131 // Convert to std::vector
132 for (unsigned j=0; j< rElementData.NodeIndices.size(); j++)
133 {
134 rElementData.NodeIndices[j] = raw_indices[j];
135 }
136
137 // Attribute value has the same tag (assume that it doesn't overtake the previous message)
138 double attribute;
139 MeshEventHandler::BeginEvent(MeshEventHandler::COMM2);
140 MPI_Recv(&attribute, 1U, MPI_DOUBLE, MPI_ANY_SOURCE,
141 tag,
142 PETSC_COMM_WORLD, &status);
143 MeshEventHandler::EndEvent(MeshEventHandler::COMM2);
144
145 // Attribute value
146 rElementData.AttributeValue = attribute;
147 }
148
155 virtual void WriteFilesUsingParallelMesh(bool keepOriginalElementIndexing=true);
156
165 bool invertMeshPermutation=false);
166
170 virtual void CreateFilesWithHeaders();
171
175 virtual void AppendLocalDataToFiles();
176
180 virtual void WriteFilesFooter();
181
184protected:
185
202public:
203
211 AbstractTetrahedralMeshWriter(const std::string& rDirectory,
212 const std::string& rBaseName,
213 const bool clearOutputDir=true);
214
219
230 bool keepOriginalElementIndexing=true);
231
243
247 std::vector<double> GetNextNode();
248
249
254
259
264};
265
266#endif //_ABSTRACTTETRAHEDRALMESHWRITER_HPP_
void WriteNclFile(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, bool invertMeshPermutation=false)
void PostElement(unsigned globalIndex, unsigned indices[], unsigned numIndices, unsigned tag, double attribute)
void UnpackElement(ElementData &rElementData, unsigned globalIndex, unsigned numIndices, unsigned tag)
MixedDimensionMesh< ELEMENT_DIM, SPACE_DIM > * mpMixedMesh
MeshWriterIterators< ELEMENT_DIM, SPACE_DIM > * mpIters
virtual void WriteFilesUsingMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, bool keepOriginalElementIndexing=true)
void WriteFilesUsingMeshReaderAndMesh(AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > &rMeshReader, AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
virtual void WriteFilesUsingParallelMesh(bool keepOriginalElementIndexing=true)
DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpDistributedMesh
static const char * EventName[11]
std::vector< unsigned > NodeIndices