VtkWriter.h 4.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/



/** \file VtkVector.h */

#ifndef AMDIS_VTKWRITER_DETAIL_H
#define AMDIS_VTKWRITER_DETAIL_H

#include <string>
#include <vector>

#include "AdaptInfo.h"
#include "io/DataCollector.h"

#ifdef HAVE_COMPRESSION
#include "io/FileCompression.h"
#endif

namespace AMDiS  { namespace io {
  
    namespace VtkWriter
    {
      // A class definition of a VtkWriter, to accept Datacollectors in 
      // the constructor.
      class Aux
      {
      public:
	Aux(std::vector<DataCollector<>*> *dc)
	  : dataCollector(dc)
#ifdef HAVE_COMPRESSION
	    , compress(NONE)
#endif
	{
	  degree = (*dataCollector)[0]->getFeSpace()->getBasisFcts()->getDegree();    
	  dim = (*dataCollector)[0]->getMesh()->getDim();
	}  

	/// Writes a ParaView-VTK file.
	int writeFile(std::string name);

#ifdef HAVE_COMPRESSION
	/// Set a compressing method for file output.
	void setCompression(FileCompression c) 
	{
	  compress = c;
	}
#endif

      protected:
	/// Writes the VTK file to an arbitrary stream.
	template<typename T>
	void writeFileToStream(T &file);

	/// Writes all coordinates of vertices and interpolation points to an 
	/// output file.
	template<typename T>
	void writeVertexCoords(T &file);

	/// Writes all values of vertices and interpolation point to an output file.
	template<typename T>
	void writeVertexValues(T &file, int componentNo);

	/// Writes the connectivity of all simplices to an output file.
	template<typename OutputStream>
	void writeConnectivity(OutputStream &file);

      private:
	/// List of DataCollectors, for each component of the problem one.
	std::vector<DataCollector<>*> *dataCollector;

#ifdef HAVE_COMPRESSION
	/// Defines if the file has to be compressed for ouput, and with which
	/// kind of compress method.
	FileCompression compress;
#endif

	/// Degree of the basis function of the problem.
	int degree;
	
	/// Dimension of the geometry.
	int dim;
      };
      
      
      namespace detail
      {

	/// Adds a new entry to a ParaView animation file.
	int updateAnimationFile(AdaptInfo *adaptInfo,
				std::string valueFilename,
				std::vector< std::pair<double, std::string> > *paraViewAnimationFrames,
				std::string animationFilename);

	/// Writes a pvtu file, which contains the links to all the rank files.
	void writeParallelFile(std::string name, int nRanks,
			      std::string fnPrefix, std::string fnPostfix,
			      std::vector<std::string> &componentNames);

	/// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
	template<typename S, typename OutputStream>
	void writeConnectivity_dim2_degree2(DataCollector<S>* dataCollector, OutputStream &file);

	/// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
	template<typename S, typename OutputStream>
	void writeConnectivity_dim2_degree3(DataCollector<S>* dataCollector, OutputStream &file);

	/// Writes the connectivity for the case dim = 2 and degree = 4 to an output file.
	template<typename S, typename OutputStream>
	void writeConnectivity_dim2_degree4(DataCollector<S>* dataCollector, OutputStream &file);
	
	/// Writes a world coordinate to a given file.
	template<typename OutputStream>
	void writeCoord(OutputStream &file, WorldVector<double> coord)
	{
	  file << std::scientific;
	  file.precision(15);
	  
	  for (int i = 0; i < Global::getGeo(WORLD); i++)
	    file << " " << coord[i];
	  for (int i = Global::getGeo(WORLD); i < 3; i++)
	    file << " "<<0.0;

	  file << "\n";
	}

      } // end namespace detail
    } // end namespace VtkWriter
} } // end namespace io, AMDiS

#include "VtkWriter.hh"

#endif // AMDIS_VTKWRITER_DETAIL_H