35 #ifndef ABSTRACTPERELEMENTWRITER_HPP_ 36 #define ABSTRACTPERELEMENTWRITER_HPP_ 38 #include "AbstractTetrahedralMesh.hpp" 40 #include "OutputFileHandler.hpp" 41 #include "Version.hpp" 48 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM,
unsigned DATA_SIZE>
75 unsigned localElementIndex,
76 c_vector<double, DATA_SIZE>& rData)=0;
90 mpMasterFile->write((
char*)&rData[0], DATA_SIZE*
sizeof(
double));
94 for (
unsigned i=0; i<DATA_SIZE; i++)
96 (*mpMasterFile) << rData[i] <<
"\t";
98 (*mpMasterFile)<<
"\n";
131 : mFileIsBinary(false),
133 mpMasterFile(nullptr)
153 c_vector<double, DATA_SIZE> data;
158 status.MPI_ERROR = MPI_SUCCESS;
163 *mpMasterFile <<
"\tBIN\n";
167 *mpMasterFile <<
"\n";
172 unsigned local_element_index=0u;
175 for (
unsigned global_element_index=0; global_element_index<mpMesh->
GetNumElements(); global_element_index++)
181 while (&(*iter) != p_elem)
184 local_element_index++;
188 Visit(p_elem, local_element_index, data);
193 MPI_Recv(&data[0], DATA_SIZE, MPI_DOUBLE, MPI_ANY_SOURCE, global_element_index, PETSC_COMM_WORLD, &status);
198 mpMasterFile->close();
203 unsigned previous_index = 0u;
204 unsigned local_index = 0u;
207 ++iter, local_index++)
209 unsigned element_index = iter->GetIndex();
211 if (previous_index>0u)
213 assert(element_index > previous_index);
215 previous_index = element_index;
219 Visit(&(*iter), local_index, data);
221 MPI_Ssend(&data[0], DATA_SIZE, MPI_DOUBLE, 0, element_index, PETSC_COMM_WORLD);
237 mFileIsBinary = binary;
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
virtual ~AbstractPerElementWriter()
ElementIterator GetElementIteratorEnd()
virtual unsigned GetNumElements() const
virtual void PreWriteCalculations(OutputFileHandler &rOutputDirectory)
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
virtual void WriteElementOnMaster(const c_vector< double, DATA_SIZE > &rData)
virtual void WriteHeaderOnMaster()
void SetWriteFileAsBinary(bool binary=true)
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
virtual void Visit(Element< ELEMENT_DIM, SPACE_DIM > *pElement, unsigned localElementIndex, c_vector< double, DATA_SIZE > &rData)=0
void WriteData(OutputFileHandler &rHandler, const std::string &rFileName)
static std::string GetProvenanceString()
virtual bool CalculateDesignatedOwnershipOfElement(unsigned elementIndex)
AbstractPerElementWriter(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)