LifeV
ExporterVTK.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief This file provides an interface for post-processing with VTK/Paraview
30  by writing files in VTK XML format
31  @date 11-2010
32 
33  ExporterVTK is inherited from Exporter.
34 
35  Usage: two steps
36  - first: add the variables using addVariable
37  - second: call postProcess( );
38 
39  @author Tiziano Passerini <tiziano@mathcs.emory.edu>
40  @maintainer Tiziano Passerini <tiziano@mathcs.emory.edu>
41  */
42 
43 #ifndef EXPORTERVTK_H
44 #define EXPORTERVTK_H 1
45 
46 #include <lifev/core/filter/Exporter.hpp>
47 #include <lifev/core/util/EncoderBase64.hpp>
48 
49 namespace LifeV
50 {
51 
52 /**
53  * @class ExporterVTK
54  * @brief ExporterVTK data exporter
55  */
56 template<typename MeshType>
57 class ExporterVTK : public Exporter<MeshType>
58 {
59 
60 public:
61 
62  //! @name Public Types
63  //@{
64 
65  /*! @enum VTK_CELL
66  A list of the cell types admitted in VTK
67  */
68  enum VTK_CELL
69  {
70  // Linear cells
73  VTK_LINE = 3,
78  VTK_PIXEL = 8,
79  VTK_QUAD = 9,
80  VTK_TETRA = 10,
81  VTK_VOXEL = 11,
83  VTK_WEDGE = 13,
85 
86  // Quadratic, isoparametric cells
92 
93  };
94 
95  /*! @enum EXPORT_MODE
96  The export modes currently supported are ascii and binary
97  */
99  {
102  };
103 
104  /*! @enum FLOAT_PRECISION
105  Currently supported are single and double precision
106  */
108  {
111  };
112 
113  typedef MeshType mesh_Type;
115  typedef typename super::meshPtr_Type meshPtr_Type;
116  typedef typename super::commPtr_Type commPtr_Type;
119  typedef typename super::feTypeToDataIdMap_Type::iterator
121  typedef const typename exporterData_Type::WhereEnum& where_Type;
122  //@}
123 
124  //! @name Static members
125 
126  //! returns the type of the map to use for the VectorEpetra
127  static MapEpetraType const MapType;
128  //@}
129 
130  //! @name Constructors & Destructor
131  //@{
132 
133  //! Default constructor
134  ExporterVTK();
135 
136  /*!
137  Constructor for ExporterVTK
138 
139  \param data_file the GetPot data file where you must provide an [exporter] section with:
140  "start" (start index for filenames 0 for 000, 1 for 001 etc.),
141  "save" (how many time steps per postprocessing)
142  "multimesh" (=true if the mesh has to be saved at each post-processing step)
143 
144  \param the prefix for the output file (ex. "test" for test.vtu)
145  */
146  ExporterVTK (const GetPot& data_file, const std::string prefix);
147 
148 private:
149  //! Copy constructor
150  ExporterVTK ( const ExporterVTK& example );
151 
152 public:
153  //! Destructor
154  virtual ~ExporterVTK();
155  //@}
156 
157  //! @name Public Methods
158  //@{
159 
160  /* *
161  Post-process the variables added to the list
162 
163  \param time the solver time
164  */
165  virtual void postProcess (const Real& time);
166 
167  //! Import data from previous simulations at a certain time
168  /*!
169  @param Time the time of the data to be imported
170 
171  Not yet implemented for ExporterVTK
172  */
173  virtual UInt importFromTime ( const Real& /*Time*/ )
174  {
175  ERROR_MSG ( "ExporterVTK::importFromTime has not yet been implemented.");
176  return -1;
177  }
178 
179  //! Import data from previous simulations and rebuild the internal time counters
180  /*!
181  @param importTime the time of the snapshot to be imported
182  @param dt the time step, is used to rebuild the history up to now
183 
184  Not yet implemented for ExporterVTK
185  */
186  virtual void import (const Real& /*Tstart*/, const Real& /*dt*/)
187  {
188  ERROR_MSG ( "ExporterVTK::importFromTime has not yet been implemented.");
189  }
190 
191  //! Import data from previous simulations
192  /*!
193  @param importTime the time of the snapshot to be imported
194  */
195  virtual void import (const Real& Tstart);
196 
197  //! temporary: the method should work form the Exporter class
198  void exportPID ( meshPtr_Type /*meshPart*/, commPtr_Type comm, const bool /*binaryFormat*/ = false )
199  {
200  if ( !comm->MyPID() )
201  {
202  std::cerr << " X- exportPID is not working with VTK" << std::endl;
203  }
204  }
205 
206  //! Set data from file.
207  /*!
208  @param dataFile data file.
209  @param section section in the data file.
210  */
211  virtual void setDataFromGetPot ( const GetPot& dataFile, const std::string& section = "exporter" );
212 
213  //@}
214 
215  //! @name Get methods
216  //@{
217  //! returns the type of the map to use for the VectorEpetra
218  virtual MapEpetraType mapType() const;
219  //@}
220 
221 private:
222 
223  //! @name Private methods
224  //@{
225  /*!
226  \param _feSpacePtr a point to the FE space descriptor
227  \return the identifier of the VTK elementary cell
228  */
229  UInt whichCellType ( const feSpacePtr_Type& _feSpacePtr );
230 
231  /*!
232  This method fills a buffer for the *.pvtu file. We will have a PVTU file for each
233  ExporterData object, basically listing the names of the VTU files containing the
234  "partitioned" data.
235 
236  \param dvar the ExporterData object
237  \param[out] pVTUStringStream the stringstream object (a file buffer)
238  */
239  void composePVTUStream ( const exporterData_Type& dvar, std::stringstream& pVTUStringStream );
240 
241  /*!
242  This method creates the data structures needed by each processor to retrieve the
243  point global IDs and coordinates.
244 
245  \param _feSpacePtr a pointer to the FE Space descriptor
246  \param[out] globalToLocalPointsMap the key of this map is the global ID of the point,
247  the value is the position in the local data structure
248  \param[out] localToGlobalPointsMap the key of this map is the position in the local data structure,
249  the value is the global ID of the point
250  \param[out] coordinatesOfPoints a nDimensionsxnumPoints matrix, storing the nDimensions coordinates
251  of the numPoints points
252  */
253  void createPointsMaps ( const feSpacePtr_Type& _feSpacePtr,
254  std::map<UInt, UInt>& globalToLocalPointsMap,
255  std::map<UInt, UInt>& localToGlobalPointsMap,
256  std::vector<Vector>& coordinatesOfPoints );
257 
258  /*!
259  This method fills a buffer for the VTK collection (a *.pvd file).
260 
261  \param time the current time
262  \param[out] vtkCollectionStringStream the stringstream object (a file buffer)
263  */
264  void composeVTKCollection ( const std::string& variableName,
265  std::stringstream& vtkCollectionStringStream);
266 
267  /*!
268  This method fills a buffer for the header part of a *.vtu file.
269 
270  \param numPoints we need to specify the dimension of the data set written in the VTU file
271  \param[out] vtuHeaderStringStream the stringstream object (a file buffer)
272  */
273  void composeVTUHeaderStream ( UInt numPoints,
274  std::stringstream& vtuHeaderStringStream );
275 
276  /*!
277  This method fills a buffer for the footer part of a *.vtu file.
278 
279  \param[out] vtuHeaderStringStream the stringstream object (a file buffer)
280  */
281  void composeVTUFooterStream ( std::stringstream& vtuFooterStringStream );
282 
283  /*!
284  This method writes in a buffer (according to the VTK XML format)
285  1- the list of points' coordinates
286  2- the connectivity of the cells
287  3- the offsets of the connectivity list
288  4- the type of each cell
289 
290  \param _feSpacePtr a pointer to the FE Space descriptor
291  \param globalToLocalPointsMap the key of this map is the global ID of the point,
292  the value is the position in the local data structure
293  \param coordinatesOfPoints a nDimensionsxnumPoints matrix, storing the nDimensions coordinates
294  of the numPoints points
295  */
296  void composeVTUGeoStream ( const feSpacePtr_Type& _feSpacePtr,
297  const std::map<UInt, UInt>& globalToLocalPointsMap,
298  const std::vector<Vector>& coordinatesOfPoints,
299  std::stringstream& vtuGeoStringStream );
300 
301  /*!
302  This method writes in a buffer (according to the VTK XML format) the header
303  of the Data section of the file. This section may be named PointData or
304  CellData, and to allow for several DataArrays to be grouped inside a single
305  PointData or CellData environment, we need a separate method taking care
306  of the header (footer)
307 
308  \param where Node or Cell
309  \param typeDataHeaderStringStream the stringstream object (a file buffer)
310  */
311 
313  std::stringstream& typeDataHeaderStringStream);
314 
315  /*!
316  \sa composeTypeDataHeaderStream
317 
318  \param where Node or Cell
319  \param typeDataHeaderStringStream the stringstream object (a file buffer)
320  */
322  std::stringstream& typeDataFooterStringStream);
323  /*!
324  This method writes in a buffer (according to the VTK XML format) the content
325  of the Data section of the file.
326 
327  \param dvar the ExporterData object
328  \param localToGlobalMap a map to query the dvar object for global IDs
329  \param dataArraysStringStream the stringstream object (a file buffer)
330  */
331  void composeDataArrayStream (const exporterData_Type& dvar,
332  const std::map<UInt, UInt>& localToGlobalMap,
333  std::stringstream& dataArraysStringStream);
334 
335  // to be checked - do not use for now
337  std::stringstream& dataArraysStringStream);
338 
339  //! The scalar reader (specialization of the parent class method)
340  /*!
341  @param dvar the ExporterData object
342  */
343  virtual void readScalar ( ExporterData<mesh_Type>& /*dvar*/ )
344  {
345  ERROR_MSG ( "ExporterVTK::readScalar has not yet been implemented.");
346  }
347  //! The vector reader (specialization of the parent class method)
348  /*!
349  @param dvar the ExporterData object
350  */
351  virtual void readVector ( ExporterData<mesh_Type>& /*dvar*/ )
352  {
353  ERROR_MSG ( "ExporterVTK::readVector has not yet been implemented.");
354  }
355  //! The reader for VTU files
356  /*!
357  @param dvar the ExporterData object
358  */
359  void readVTUFiles ( exporterData_Type& dvar );
360  //! A routine for loading values stored in binary format in a VTU file
361  /*!
362  @param line a line read from file
363  @param values the list of values extracted from the line
364  @param numBits the size of data to be read
365  */
366  void readBinaryData ( const std::string& line, std::vector<Real>& values, const UInt& numBits );
367  //! A routine for loading values stored in ASCII format in a VTU file
368  /*!
369  @param line a line read from file
370  @param values the list of values extracted from the line
371  */
372  void readASCIIData ( const std::string& line, std::vector<Real>& values );
373  //@}
374 
375  //! @name Private members
376  //@{
378 
380 
382  //@}
383 
384 };
385 
386 
387 // ==============
388 // Implementation
389 // ==============
390 
391 template<typename MeshType>
392 MapEpetraType const ExporterVTK<MeshType>::MapType (Repeated);
393 
394 // ==============
395 // Constructors
396 // ==============
397 
398 template<typename MeshType>
399 ExporterVTK<MeshType>::ExporterVTK() :
400  super(),
403 {
404 }
405 
406 
407 template<typename MeshType> ExporterVTK<MeshType >::ExporterVTK (
408  const GetPot& data_file,
409  const std::string prefix)
410  :
411  super (data_file, prefix)
412 {
413  this->setDataFromGetPot (data_file);
414 }
415 
416 
417 template<typename MeshType>
418 void ExporterVTK<MeshType >::setDataFromGetPot (
419  const GetPot& data_file,
420  const std::string& section )
421 {
422  super::setDataFromGetPot ( data_file, section );
423 
424  switch ( data_file ( (section + "/exportMode").c_str(), 1) )
425  {
426  case 1:
427  M_exportMode = ASCII_EXPORT;
428  break;
429  case 2:
430  M_exportMode = BINARY_EXPORT;
431  break;
432  default:
433  ERROR_MSG ( "Unsupported export mode!" );
434  break;
435  }
436 
437  switch ( data_file ( (section + "/floatPrecision").c_str(), 2) )
438  {
439  case 1:
440  M_floatPrecision = SINGLE_PRECISION;
441  break;
442  case 2:
443  M_floatPrecision = DOUBLE_PRECISION;
444  break;
445  default:
446  ERROR_MSG ( "Unsupported float precision requirement!" );
447  break;
448  }
449 
450 }
451 // ==============
452 // Destructor
453 // ==============
454 template<typename MeshType>
456 {
457  // Right before dying, the exporter will write a VTK collection in a pvd file
458  // This allows ParaView to load a single file for the entire time series,
459  // and each frame will be associated to the correct time value.
460  // This will happen only if at least one time step was actually post-processed
461  if ( this->M_timeSteps.size() )
462  {
463  std::stringstream buffer ("");
464 
465  // a unique time collection is produced by the leader process
466  if (this->M_procId == 0)
467  {
468  for (typename super::dataVectorIterator_Type iData = this->M_dataVector.begin();
469  iData != this->M_dataVector.end(); ++iData)
470  {
471  composeVTKCollection ( iData->variableName(), buffer );
472 
473  std::string filename ( this->M_postDir + this->M_prefix + "_" + iData->variableName() + ".pvd" );
474  std::ofstream vtkCollectionFile;
475  vtkCollectionFile.open ( filename.c_str() );
476  ASSERT (vtkCollectionFile.is_open(), "There is an error while opening " + filename );
477  ASSERT (vtkCollectionFile.good(), "There is an error while writing to " + filename );
478  vtkCollectionFile << buffer.str();
479  vtkCollectionFile.close();
480 
481  buffer.str ("");
482  }
483  }
484  }
485 
486 }
487 
488 // =====================
489 // Public methods
490 // =====================
491 
492 template<typename MeshType>
493 void ExporterVTK<MeshType>::postProcess (const Real& time)
494 {
495  // typedef std::list< ExporterData >::iterator Iterator;
496 
497  this->computePostfix();
498 
499  std::size_t found ( this->M_postfix.find ( "*" ) );
500  if ( found == std::string::npos )
501  {
502  if (this->M_procId == 0)
503  {
504  std::cout << " X- ExporterVTK post-processing" << std::flush;
505  }
506 
507  LifeChrono chrono;
508  chrono.start();
509 
510  this->M_timeSteps.push_back (time);
511 
512  for (typename super::dataVectorIterator_Type iData = this->M_dataVector.begin();
513  iData != this->M_dataVector.end(); ++iData)
514  {
515  std::ofstream vtkFile;
516  std::stringstream buffer ("");
517 
518  // a unique PVTU file + a time collection is produced by the leader process
519  if (this->M_procId == 0)
520  {
521  composePVTUStream (*iData, buffer);
522 
523  std::string vtkPFileName ( this->M_prefix + "_" + iData->variableName() +
524  this->M_postfix + ".pvtu" );
525  std::string vtkPFileNameWithDir (this->M_postDir + vtkPFileName);
526 
527  std::ofstream vtkPFile;
528  vtkPFile.open ( vtkPFileNameWithDir.c_str() );
529  ASSERT (vtkPFile.is_open(), "There is an error while opening " + vtkPFileName );
530  ASSERT (vtkPFile.good(), "There is an error while writing to " + vtkPFileName );
531  vtkPFile << buffer.str();
532  vtkPFile.close();
533 
534  buffer.str ("");
535 
536  this->M_pvtuFiles[iData->variableName()].push_back (vtkPFileName);
537 
538  }
539 
540 
541  // redundant. should be done just the first time
542  std::map<UInt, UInt> ltgPointsMap, gtlPointsMap;
543  std::vector<Vector> pointsCoords;
544  createPointsMaps ( iData->feSpacePtr(), gtlPointsMap, ltgPointsMap, pointsCoords );
545 
546  composeVTUHeaderStream ( gtlPointsMap.size(), buffer );
547  composeVTUGeoStream ( iData->feSpacePtr(), gtlPointsMap, pointsCoords, buffer );
548 
549  composeTypeDataHeaderStream (iData->where(), buffer);
550  composeDataArrayStream (*iData, ltgPointsMap, buffer);
551  composeTypeDataFooterStream (iData->where(), buffer);
552 
553  composeVTUFooterStream ( buffer );
554 
555  // each process writes its own file
556  std::string filename ( this->M_postDir + this->M_prefix + "_" + iData->variableName() +
557  this->M_postfix + "." + this->M_procId + ".vtu" );
558  vtkFile.open ( filename.c_str() );
559  ASSERT (vtkFile.is_open(), "There is an error while opening " + filename );
560  ASSERT (vtkFile.good(), "There is an error while writing to " + filename );
561  vtkFile << buffer.str();
562  vtkFile.close();
563 
564  buffer.str ("");
565 
566  }
567  chrono.stop();
568  if (!this->M_procId)
569  {
570  std::cout << "...done in " << chrono.diff() << " s." << std::endl;
571  }
572  }
573 }
574 
575 
576 template<typename MeshType>
577 void ExporterVTK<MeshType>::import (const Real& /*time*/)
578 {
579  this->computePostfix();
580 
581  assert ( this->M_postfix != "*****" );
582 
583  if (this->M_procId == 0)
584  {
585  std::cout << " X- ExporterVTK importing ..." << std::endl;
586  }
587 
588  LifeChrono chrono;
589  chrono.start();
590  for (typename super::dataVectorIterator_Type iData = this->M_dataVector.begin();
591  iData != this->M_dataVector.end(); ++iData)
592  {
593  this->readVTUFiles (*iData);
594  }
595  chrono.stop();
596  if (this->M_procId == 0)
597  {
598  std::cout << " done in " << chrono.diff() << " s." << std::endl;
599  }
600 }
601 
602 
603 // ===================
604 // Get methods
605 // ===================
606 
607 template<typename MeshType>
609 {
610  return MapType;
611 }
612 
613 
614 // ===================
615 // Private methods
616 // ===================
617 
618 template <typename MeshType>
619 UInt ExporterVTK<MeshType>::whichCellType ( const feSpacePtr_Type& _feSpacePtr )
620 {
621  ASSERT ( _feSpacePtr.get(), "\nA pointer to a valid FE object is required!");
622 
623  UInt vtkCellType (0);
624 
625  switch ( _feSpacePtr->fe().refFE().type() )
626  {
627  case FE_P1_2D:
628  // case FE_P1bubble_2D:
629  vtkCellType = VTK_TRIANGLE;
630  break;
631  case FE_P2_2D:
632  vtkCellType = VTK_QUADRATIC_TRIANGLE;
633  break;
634  case FE_P0_3D:
635  case FE_P1_3D:
636  vtkCellType = VTK_TETRA;
637  break;
638  case FE_P2_3D:
639  case FE_P2tilde_3D:
640  vtkCellType = VTK_QUADRATIC_TETRA;
641  break;
642  case FE_Q1_2D:
643  vtkCellType = VTK_QUAD;
644  break;
645  case FE_Q2_2D:
646  vtkCellType = VTK_QUADRATIC_QUAD;
647  break;
648  case FE_Q0_3D:
649  case FE_Q1_3D:
650  vtkCellType = VTK_HEXAHEDRON;
651  break;
652  case FE_Q2_3D:
653  vtkCellType = VTK_QUADRATIC_HEXAHEDRON;
654  break;
655  default:
656  ERROR_MSG ( "WARNING: the element is not yet implemented in ExporterVTK\n" )
657  break;
658  }
659 
660  return vtkCellType;
661 }
662 
663 
664 template <typename MeshType>
665 void
667  const std::map<UInt, UInt>& localToGlobalMap,
668  std::stringstream& dataArraysStringStream)
669 {
670  const UInt start ( dvar.start() );
671  const UInt numGlobalDOF ( dvar.numDOF() );
672  const UInt numMyDOF ( localToGlobalMap.size() );
673 
674  std::stringstream dataToBeEncoded;
675  dataToBeEncoded.str ("");
676  std::string encodedDataString;
677 
678  std::string formatString;
679  std::stringstream nComponents;
680  nComponents << dvar.fieldDim();
681 
682  int32_type sizeOfFloat = 4;
683  std::string floatTypeString;
684  switch ( M_floatPrecision )
685  {
686  case SINGLE_PRECISION:
687  ASSERT ( sizeof (float) == 4, "\nThis piece of code assumes sizeof(float) == 4" )
688  sizeOfFloat = sizeof (float);
689  floatTypeString = "Float32";
690  break;
691  case DOUBLE_PRECISION:
692  ASSERT ( sizeof (Real) == 8, "\nThis piece of code assumes sizeof(float) == 4" )
693  sizeOfFloat = sizeof (Real);
694  floatTypeString = "Float64";
695  break;
696  default:
697  ERROR_MSG ( "WARNING: this float precision cannot be handled in ExporterVTK\n" )
698  break;
699  }
700 
701  int32_type lengthOfRawData ( dvar.fieldDim() *numMyDOF * sizeOfFloat );
702 
703  switch ( M_exportMode )
704  {
705  case ASCII_EXPORT:
706  formatString = "ascii";
707  break;
708  case BINARY_EXPORT:
709  formatString = "binary";
710  dataToBeEncoded.write ( reinterpret_cast<char*> ( &lengthOfRawData ),
711  sizeof (int32_type) );
712  lengthOfRawData += sizeof (int32_type);
713  break;
714  default:
715  ERROR_MSG ( "WARNING: this export mode cannot be handled in ExporterVTK\n" )
716  break;
717  }
718 
719  dataArraysStringStream << "\t\t\t\t<DataArray type=\"" << floatTypeString << "\" Name=\""
720  << dvar.variableName() << "\" NumberOfComponents=\""
721  << nComponents.str() << "\" format=\"" << formatString << "\">\n";
722 
723  switch ( M_exportMode )
724  {
725  case ASCII_EXPORT:
726  dataArraysStringStream.setf (std::ios_base::fixed);
727  dataArraysStringStream.precision (5);
728  dataArraysStringStream.width (12);
729 
730  for (UInt iDOF = 0; iDOF < numMyDOF; ++iDOF)
731  {
732  const Int id = localToGlobalMap.find (iDOF)->second;
733  for (UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
734  {
735  dataArraysStringStream << dvar ( start + id +
736  iCoor * numGlobalDOF ) << " ";
737  }
738  }
739  break;
740  case BINARY_EXPORT:
741  for (UInt iDOF = 0; iDOF < numMyDOF; ++iDOF)
742  {
743  const Int id = localToGlobalMap.find (iDOF)->second;
744  for (UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
745  {
747  {
748  const float value ( dvar ( start + id + iCoor * numGlobalDOF ) );
749  dataToBeEncoded.write ( reinterpret_cast<const char*> (&value), sizeof (float) );
750  }
751  else
752  {
753  const Real value ( dvar ( start + id + iCoor * numGlobalDOF ) );
754  dataToBeEncoded.write ( reinterpret_cast<const char*> (&value), sizeof (Real) );
755  }
756  }
757  }
758 
759  encodedDataString = base64_encode (reinterpret_cast<const unsigned char*> ( dataToBeEncoded.str().c_str() ),
760  lengthOfRawData );
761  dataArraysStringStream << encodedDataString;
762 
763  break;
764  default:
765  ERROR_MSG ( "WARNING: this export mode cannot be handled in ExporterVTK\n" )
766  break;
767  }
768 
769  dataArraysStringStream << "\n\t\t\t\t</DataArray>\n";
770 
771  dataArraysStringStream << "\t\t\t\t<DataArray type=\"Int32\" NumberOfComponents=\"1\" "
772  << "Name=\"GlobalId\" format=\"ascii\">\n";
773  for ( UInt iDOF = 0; iDOF < numMyDOF; ++iDOF )
774  {
775  dataArraysStringStream << localToGlobalMap.find ( iDOF )->second << " ";
776  }
777  dataArraysStringStream << "\n\t\t\t\t</DataArray>\n";
778 }
779 
780 
781 template <typename MeshType>
782 void
784 {
785  ASSERT ( this->M_numImportProc, "The number of pieces to be loaded was not specified." );
786 
787  UInt numPoints, numCells;
788  std::vector<Real> inputValues;
789  std::vector<Real> globalIDs;
790 
791  const UInt start ( dvar.start() );
792  const UInt numGlobalDOF ( dvar.numDOF() );
793 
794  // Each processor will read all the files, and fill just its own component of the vectors
795  for ( UInt iProc = 0; iProc < this->M_numImportProc; ++iProc )
796  {
797  std::string filename ( this->M_postDir + this->M_prefix + "_" + dvar.variableName() +
798  this->M_postfix + "." + iProc + ".vtu" );
799  std::ifstream inputFile ( filename.c_str() );
800 
801  if (this->M_procId == 0)
802  {
803  std::cout << "\tfile " << filename << std::endl;
804  }
805 
806  ASSERT (inputFile.is_open(), "There is an error while opening " + filename );
807 
808  // file parsing: line by line
809  std::string line;
810  size_t found;
811  std::stringstream parseLine;
812 
813  while ( inputFile.good() && getline ( inputFile, line ) )
814  {
815  // this is essentially a consistency check: the number of DOF is explicitly
816  // written in the VTK files. We will check that the number of values read
817  // from file matches this number
818  found = line.find ( "NumberOfPoints" );
819  if ( found != std::string::npos )
820  {
821  // place the get pointer at the first " after NumberOfPoints
822  found = line.find ( "\"", found, 1 );
823  // after the " we'll find the number: parse the substring
824  parseLine.str ( line.substr (found + 1) );
825  parseLine >> numPoints;
826 
827  // do the same for NumberOfCells
828  found = line.find ( "NumberOfCells" );
829  found = line.find ( "\"", found, 1 );
830  parseLine.str ( line.substr (found + 1) );
831  parseLine >> numCells;
832  }
833 
834  // load all PointData arrays
835  if ( line.find ( "<PointData" ) != std::string::npos )
836  {
837  while ( inputFile.good() && getline ( inputFile, line ) )
838  {
839  if ( line.find ( dvar.variableName() ) != std::string::npos )
840  {
841  inputValues.resize ( dvar.fieldDim() *numPoints );
842 
843  if ( line.find ( "binary" ) != std::string::npos )
844  {
845  UInt numBitsFloat;
846  found = line.find ( "Float" );
847  parseLine.str ( line.substr (found + 5) );
848  parseLine >> numBitsFloat;
849  ASSERT (inputFile.good(), "There is an error while opening " + filename );
850  getline ( inputFile, line );
851  readBinaryData ( line, inputValues, numBitsFloat );
852  }
853  else
854  {
855  ASSERT (inputFile.good(), "There is an error while opening " + filename );
856  getline ( inputFile, line );
857  readASCIIData ( line, inputValues );
858  }
859  }
860  if ( line.find ( "GlobalId" ) != std::string::npos )
861  {
862  globalIDs.resize ( numPoints );
863  ASSERT (inputFile.good(), "There is an error while opening " + filename );
864  getline ( inputFile, line );
865  readASCIIData ( line, globalIDs );
866  }
867  }
868 
869  for (UInt iPoint = 0; iPoint < numPoints; ++iPoint)
870  {
871  const Int id = globalIDs[iPoint];
872  if ( dvar.feSpacePtr()->map().map (Repeated)->MyGID ( id ) )
873  {
874  for (UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
875  {
876  dvar ( start + id + iCoor * numGlobalDOF ) =
877  inputValues[ iPoint * dvar.fieldDim() + iCoor ];
878  }
879  }
880  }
881  }
882  }
883  inputFile.close();
884  }
885 }
886 
887 
888 template <typename MeshType>
889 void
890 ExporterVTK<MeshType>::readBinaryData ( const std::string& line, std::vector<Real>& values, const UInt& numBits )
891 {
892  std::stringstream decodedData, dataToBeDecoded;
893  dataToBeDecoded.str ("");
894  std::string decodedDataString;
895  UInt sizeOfFloat ( 0 ), sizeOfVector ( values.size() );
896 
897  switch ( numBits )
898  {
899  case 32:
900  ASSERT ( sizeof (float) == 4, "\nThis piece of code assumes sizeof(float) == 4" );
901  sizeOfFloat = sizeof (float);
902  break;
903  case 64:
904  ASSERT ( sizeof (Real) == 8, "\nThis piece of code assumes sizeof(Real) == 8" );
905  sizeOfFloat = sizeof (Real);
906  break;
907  default:
908  ERROR_MSG ( "unmanaged float type" );
909  break;
910  }
911 
912  // assign the block of char to a stringstream (to convert it into a string)
913  dataToBeDecoded.write ( line.c_str(), line.size() );
914 
915  // perform the string decoding and store the string in a stringstream
916  // (to access it "bitwise")
917  decodedDataString = base64_decode ( dataToBeDecoded.str() );
918  decodedData.str ( decodedDataString );
919 
920 #ifdef HAVE_LIFEV_DEBUG
921  UInt lengthOfRawData = sizeOfVector * sizeOfFloat + sizeof (int32_type);
922  ASSERT ( lengthOfRawData == decodedDataString.size(), "unexpected line length" );
923 #endif
924 
925  // the first value in the string is the size of the subsequent bunch of data
926  int32_type* inputInt = new int32_type;
927  decodedData.read ( reinterpret_cast< char*> ( inputInt ),
928  sizeof (int32_type) );
929 
930  ASSERT ( *inputInt - sizeOfVector, "Inconsistent size of data!" );
931 
932  switch ( numBits )
933  {
934  case 32:
935  {
936  float* inputFloat = new float[sizeOfVector];
937  decodedData.read ( reinterpret_cast< char*> ( inputFloat ),
938  sizeOfVector * sizeOfFloat );
939  std::vector<float> inputValuesTemp (sizeOfVector);
940  inputValuesTemp.assign ( inputFloat, inputFloat + sizeOfVector );
941  values.assign ( inputValuesTemp.begin(), inputValuesTemp.end() );
942  //for (UInt i = 0; i < inputValues.size(); i++)
943  // inputValues[i] = inputValuesTemp[i];
944  break;
945  }
946  case 64:
947  {
948  Real* inputReal = new Real[sizeOfVector];
949  decodedData.read ( reinterpret_cast< char*> ( inputReal ),
950  sizeOfVector * sizeOfFloat );
951  values.assign ( inputReal, inputReal + sizeOfVector );
952  break;
953  }
954  }
955 }
956 
957 
958 template <typename MeshType>
959 void
960 ExporterVTK<MeshType>::readASCIIData ( const std::string& line, std::vector<Real>& values )
961 {
962  std::stringstream readData ( line );
963 
964  // simply parse the line to fill the vector of values
965  for (UInt i = 0; i < values.size(); i++)
966  {
967  readData >> values[i];
968  }
969 
970 }
971 
972 
973 /*
974  preliminary attempt at managing simultaneously all data associated to Nodes
975  as opposed to data associated to Cells.
976 
977  Untested for now.
978  */
979 template <typename MeshType>
980 void
982  std::stringstream& dataArraysStringStream)
983 {
984 
985 
986  typename super::iterator_Type it;
987  std::pair<typename super::iterator_Type, typename super::iterator_Type> rangeFound;
988 
989  rangeFound = this->M_whereToDataMap.equal_range (where);
990 
991  if ( rangeFound.first != rangeFound.second )
992  {
993  debugStream (8000) << "\n[ExporterVTK::composeDataArrayStream] found data\n";
994 
995  dataArraysStringStream.setf (std::ios_base::fixed);
996  dataArraysStringStream.precision (5);
997  dataArraysStringStream.width (12);
998 
999  for (it = rangeFound.first; it != rangeFound.second; ++it)
1000  {
1001  switch ( it->second.fieldType() )
1002  {
1003  case exporterData_Type::ScalarField:
1004 
1005  dataArraysStringStream << "\t\t\t\t<DataArray type=\"Float32\" Name=\""
1006  << it->second.variableName() << "\" NumberOfComponents=\"1\" format=\"ascii\">\n";
1007 
1008  for (UInt iValue = 1; iValue <= it->second.size(); ++iValue)
1009  {
1010  dataArraysStringStream << it->second ( iValue ) << " ";
1011  }
1012  break;
1013  case exporterData_Type::VectorField:
1014 
1015  dataArraysStringStream << "\t\t\t\t<DataArray type=\"Float32\" Name=\""
1016  << it->second.variableName() << "\" NumberOfComponents=\""
1017  << nDimensions << "\" format=\"ascii\">\n";
1018 
1019  for (UInt iValue = 1; iValue <= it->second.size(); ++iValue)
1020  {
1021  for (UInt iCoor = 0; iCoor < nDimensions; ++iCoor)
1022  {
1023  dataArraysStringStream << it->second ( iValue + iCoor * it->second.size() ) << " ";
1024  }
1025  }
1026  break;
1027  /*case typename exporterData_Type::TensorField:
1028 
1029  dataArraysStringStream << "\t\t\t\t<DataArray type=\"Float32\" Name=\""
1030  << it->second.variableName() << "\" NumberOfComponents=\""
1031  << nDimensions*nDimensions << "\" format=\"ascii\">\n";
1032 
1033  for (UInt i=0; i<it->second.size(); ++i){
1034  for (UInt iCoor=0; iCoor< nDimensions;++iCoor){
1035  for (UInt jcoor=0; jcoor< nDimensions;++jcoor){
1036  dataArraysStringStream << it->second( i * nDimensions * nDimensions +
1037  iCoor * nDimensions + jcoor ) << " ";
1038  }
1039  }
1040  }
1041  break;*/
1042  default:
1043  ERROR_MSG ( "Unknown field type" );
1044  break;
1045  }
1046  dataArraysStringStream << "\n\t\t\t\t</DataArray>\n";
1047  }
1048  // return dataArraysStringStream;
1049  }
1050 }
1051 
1052 
1053 template <typename MeshType>
1054 void ExporterVTK<MeshType>::composePVTUStream (const exporterData_Type& dvar,
1055  std::stringstream& pVTUStringStream)
1056 {
1057 
1058  std::string floatTypeString;
1059  switch ( M_floatPrecision )
1060  {
1061  case SINGLE_PRECISION:
1062  floatTypeString = "Float32";
1063  break;
1064  case DOUBLE_PRECISION:
1065  floatTypeString = "Float64";
1066  break;
1067  default:
1068  ERROR_MSG ( "unmanaged float type" );
1069  break;
1070  }
1071 
1072  //header part of the file
1073  pVTUStringStream << "<?xml version=\"1.0\"?>\n";
1074  pVTUStringStream << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1075  pVTUStringStream << "\t<PUnstructuredGrid GhostLevel=\"0\">\n";
1076 
1077  pVTUStringStream << "\t\t<PPoints>\n";
1078  pVTUStringStream << "\t\t\t<PDataArray type=\"Float32\" NumberOfComponents=\"" << nDimensions
1079  << "\" format=\"ascii\"/>\n";
1080  pVTUStringStream << "\t\t</PPoints>\n";
1081 
1082  // connectivity
1083  // cells_size = nldof*(nV+1);
1084  pVTUStringStream << "\t\t<PCells>\n";
1085  pVTUStringStream << "\t\t\t<PDataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\"/>\n";
1086 
1087  pVTUStringStream << "\t\t\t<PDataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\"/>\n";
1088 
1089  pVTUStringStream << "\t\t\t<PDataArray type=\"Int32\" Name=\"types\" format=\"ascii\"/>\n";
1090 
1091  pVTUStringStream << "\t\t</PCells>\n";
1092 
1093  std::string whereString;
1094  switch ( dvar.where() )
1095  {
1096  case exporterData_Type::Node:
1097  whereString = "PPointData";
1098  break;
1099  case exporterData_Type::Cell:
1100  whereString = "PCellData";
1101  break;
1102  default:
1103  ERROR_MSG ( "Cannot manage this data location" );
1104  break;
1105  }
1106  pVTUStringStream << "\t\t<" << whereString << " ";
1107 
1108  pVTUStringStream << ">\n";
1109 
1110  std::string formatString;
1111  std::stringstream nComponents;
1112  nComponents << dvar.fieldDim();
1113  switch ( M_exportMode )
1114  {
1115  case ASCII_EXPORT:
1116  formatString = "ascii";
1117  break;
1118  case BINARY_EXPORT:
1119  formatString = "binary";
1120  break;
1121  default:
1122  ERROR_MSG ( "Cannot manage this export mode" );
1123  break;
1124  }
1125  pVTUStringStream << "\t\t\t<PDataArray type=\"" << floatTypeString << "\" Name=\""
1126  << dvar.variableName() << "\" NumberOfComponents=\""
1127  << nComponents.str() << "\" format=\"" << formatString << "\">\n";
1128 
1129  pVTUStringStream << "\t\t\t</PDataArray>\n";
1130 
1131  pVTUStringStream << "\t\t\t<PDataArray type=\"Int32\" Name=\"GlobalId\" NumberOfComponents=\"1\" "
1132  << "format=\"ascii\">\n";
1133  pVTUStringStream << "\t\t\t</PDataArray>\n";
1134 
1135  pVTUStringStream << "\t\t</" << whereString << ">\n";
1136 
1137  for ( Int iProc = 0; iProc < dvar.feSpacePtr()->map().comm().NumProc(); ++iProc )
1138  {
1139  std::stringstream fileName ( ( this->M_prefix + "_" + dvar.variableName() +
1140  this->M_postfix + "." + iProc + ".vtu").c_str() );
1141 
1142  //footer part of the file
1143  pVTUStringStream << "\t\t<Piece Source=\"" << fileName.str() << "\"/>\n";
1144  }
1145 
1146  pVTUStringStream << "\t</PUnstructuredGrid>\n";
1147  pVTUStringStream << "</VTKFile>\n";
1148 
1149 }
1150 
1151 
1152 template <typename MeshType>
1153 void ExporterVTK<MeshType>::createPointsMaps ( const feSpacePtr_Type& _feSpacePtr,
1154  std::map<UInt, UInt>& globalToLocalPointsMap,
1155  std::map<UInt, UInt>& localToGlobalPointsMap,
1156  std::vector<Vector>& coordinatesOfPoints )
1157 {
1158  ASSERT ( this->M_mesh.get(), "\nA pointer to a valid mesh object is required!");
1159  ASSERT ( _feSpacePtr.get(), "\nA pointer to a valid FESpace object is required!");
1160 
1161  const ID numVertices = this->M_mesh->numVertices();
1162  const ID numElements = this->M_mesh->numElements();
1163 
1164  // careful: the vertex map in the mesh is repeated. to know how many non vertex dofs I have
1165  // in the partitioned mesh I need to look at repeated maps
1166  const UInt numPoints = _feSpacePtr->map().map (Repeated)->NumMyElements() / _feSpacePtr->fieldDim();
1167 
1168  coordinatesOfPoints.resize ( nDimensions, ZeroVector (numPoints) );
1169 
1170  Real x, y, z;
1171 
1172  // The global ID of the considered DOF
1173  UInt globalPointId (0);
1174  // The local ID of the considered DOF
1175  UInt positionInPartitionedMesh (0);
1176  // Helper iterator
1177  std::pair< std::map<UInt, UInt>::iterator, bool > returnType;
1178 
1179  // Vertex based Dof: the coordinates are available from the Point List
1180  for (ID iVertex = 0; iVertex < numVertices; ++iVertex)
1181  {
1182  globalPointId = this->M_mesh->point (iVertex).id();
1183  localToGlobalPointsMap.insert ( std::pair<UInt, UInt> ( positionInPartitionedMesh, globalPointId ) );
1184  globalToLocalPointsMap.insert ( std::pair<UInt, UInt> ( globalPointId, positionInPartitionedMesh ) );
1185 
1186  for (ID jCoor = 0; jCoor < nDimensions; ++jCoor)
1187  {
1188  coordinatesOfPoints[jCoor][positionInPartitionedMesh] =
1189  this->M_mesh->point (iVertex).coordinate (jCoor);
1190  }
1191  ++positionInPartitionedMesh;
1192  }
1193  ASSERT ( positionInPartitionedMesh == numVertices, "didn't store all vertices in the maps");
1194  ASSERT ( localToGlobalPointsMap.size() == globalToLocalPointsMap.size(),
1195  "problem in storing the local to global and global to local maps" );
1196 
1197  // Now I store the coordinates of the supplementary nodes in a temporary vector
1198  for ( UInt iElement = 0; iElement < numElements; ++iElement )
1199  {
1200  _feSpacePtr->fe().update ( this->M_mesh->element ( iElement ), UPDATE_ONLY_CELL_NODES );
1201  for ( UInt iPoint = _feSpacePtr->dof().numLocalVertices();
1202  iPoint < _feSpacePtr->dof().numLocalDof(); ++iPoint )
1203  {
1204  _feSpacePtr->fe().coorMap ( x, y, z,
1205  _feSpacePtr->fe().refFE().xi ( iPoint ),
1206  _feSpacePtr->fe().refFE().eta ( iPoint ),
1207  _feSpacePtr->fe().refFE().zeta ( iPoint ) );
1208 
1209  globalPointId = _feSpacePtr->dof().localToGlobalMap ( iElement, iPoint );
1210 
1211  returnType = globalToLocalPointsMap.insert ( std::pair<UInt, UInt> ( globalPointId,
1212  positionInPartitionedMesh ) );
1213 
1214  // by looping over mesh elements I get repetition in the list of points
1215  // update the maps only when finding a new point
1216  if ( returnType.second )
1217  {
1218  localToGlobalPointsMap.insert ( std::pair<UInt, UInt> ( positionInPartitionedMesh, globalPointId ) );
1219  coordinatesOfPoints[0][positionInPartitionedMesh] = x;
1220  coordinatesOfPoints[1][positionInPartitionedMesh] = y;
1221  coordinatesOfPoints[2][positionInPartitionedMesh] = z;
1222  ++positionInPartitionedMesh;
1223  }
1224 
1225  }
1226  }
1227  ASSERT ( positionInPartitionedMesh == numPoints, "didn't store all points in the maps" );
1228  ASSERT ( localToGlobalPointsMap.size() == globalToLocalPointsMap.size(),
1229  "problem in storing the local to global and global to local maps" );
1230  ASSERT ( localToGlobalPointsMap.size() == numPoints,
1231  "problem in storing the local to global and global to local maps" );
1232 
1233 }
1234 
1235 
1236 template <typename MeshType>
1237 void ExporterVTK<MeshType>::composeVTKCollection ( const std::string& variableName,
1238  std::stringstream& vtkCollectionStringStream )
1239 {
1240  // ASSERT( this->M_timeSteps.size(), "No time values to be saved in the VTK collection!");
1241  // ASSERT( this->M_pvtuFiles[variableName].size(), "No file names to be saved in the VTK collection!");
1242  // ASSERT( this->M_pvtuFiles[variableName].size() == this->M_timeSteps.size(),
1243  // "The number of post-processed files does not match the number of time steps in the list!" );
1244 
1245  //header part of the file
1246  vtkCollectionStringStream << "<?xml version=\"1.0\"?>\n";
1247  vtkCollectionStringStream << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1248  vtkCollectionStringStream << "\t<Collection>\n";
1249 
1250  typedef std::list<Real>::const_iterator realIterator;
1251  realIterator iTime = this->M_timeSteps.begin();
1252  typedef std::list<std::string>::const_iterator stringIterator;
1253  stringIterator iFileName = this->M_pvtuFiles[variableName].begin();
1254 
1255  // Someone might have added a variable but never post processed it (so that no pvtu files are generated)
1256  if (iFileName != this->M_pvtuFiles[variableName].end() )
1257  for ( ; iTime != this->M_timeSteps.end(); ++iTime, ++iFileName)
1258  vtkCollectionStringStream << "\t\t<DataSet timestep=\"" << *iTime << "\" group=\"\" part=\"0\" "
1259  << "file=\"" << *iFileName << "\" />\n";
1260 
1261  vtkCollectionStringStream << "\t</Collection>\n";
1262  vtkCollectionStringStream << "</VTKFile>\n";
1263 
1264 }
1265 
1266 
1267 template <typename MeshType>
1268 void ExporterVTK<MeshType>::composeVTUGeoStream ( const feSpacePtr_Type& _feSpacePtr,
1269  const std::map<UInt, UInt>& globalToLocalPointsMap,
1270  //const std::map<UInt, UInt>& localToGlobalPointsMap,
1271  const std::vector<Vector>& coordinatesOfPoints,
1272  std::stringstream& vtuGeoStringStream )
1273 {
1274  ASSERT ( this->M_mesh.get(), "\nA pointer to a valid mesh object is required!");
1275  ASSERT ( _feSpacePtr.get(), "\nA pointer to a valid FESpace object is required!");
1276 
1277  debugStream (8000) << "\n[ExporterVTK::composeVTUHeaderStream]\n";
1278 
1279  const UInt numPoints = globalToLocalPointsMap.size();
1280  const UInt numElements = this->M_mesh->numElements();
1281  const UInt numLocalDof = _feSpacePtr->dof().numLocalDof();
1282 
1283  vtuGeoStringStream << "\t\t\t<Points>\n";
1284  vtuGeoStringStream << "\t\t\t\t<DataArray type=\"Float32\" NumberOfComponents=\"" << nDimensions
1285  << "\" format=\"ascii\">\n";
1286 
1287  for ( UInt iPoint = 0; iPoint < numPoints; ++iPoint )
1288  {
1289  for ( UInt iCoor = 0; iCoor < nDimensions; ++iCoor )
1290  {
1291  vtuGeoStringStream << coordinatesOfPoints[iCoor][ iPoint ] << " ";
1292  }
1293  }
1294  vtuGeoStringStream << "\n\t\t\t\t</DataArray>\n";
1295 
1296  vtuGeoStringStream << "\t\t\t</Points>\n";
1297 
1298  // connectivity
1299  // cells_size = nldof*(nV+1);
1300  vtuGeoStringStream << "\t\t\t<Cells>\n";
1301  vtuGeoStringStream << "\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
1302 
1303  for (UInt iElement = 0; iElement < numElements; ++iElement)
1304  {
1305  for ( UInt jPoint = 0; jPoint < numLocalDof; ++jPoint)
1306  {
1307  // UInt globalElementId( this->M_mesh->element(iElement).id() );
1308  const UInt globalPointId ( _feSpacePtr->dof().localToGlobalMap ( iElement, jPoint ) );
1309  ASSERT ( globalToLocalPointsMap.find ( globalPointId ) != globalToLocalPointsMap.end(),
1310  "didn't find a local ID for global point" );
1311  const UInt localId ( globalToLocalPointsMap.find ( globalPointId )->second );
1312  vtuGeoStringStream << localId << " ";
1313  }
1314  }
1315  vtuGeoStringStream << "\n\t\t\t\t</DataArray>\n";
1316 
1317  vtuGeoStringStream << "\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
1318 
1319  for (UInt iElement = 1; iElement <= numElements; ++iElement)
1320  {
1321  vtuGeoStringStream << iElement* numLocalDof << " ";
1322  }
1323 
1324  vtuGeoStringStream << "\n\t\t\t\t</DataArray>\n";
1325 
1326  vtuGeoStringStream << "\t\t\t\t<DataArray type=\"Int32\" Name=\"types\" format=\"ascii\">\n";
1327 
1328  // definition of cells types
1329  UInt vtkCellType = whichCellType (_feSpacePtr);
1330  for (UInt iElement = 1; iElement <= numElements; ++iElement)
1331  {
1332  vtuGeoStringStream << vtkCellType << " ";
1333  }
1334 
1335  vtuGeoStringStream << "\n\t\t\t\t</DataArray>\n";
1336  vtuGeoStringStream << "\t\t\t</Cells>\n";
1337 
1338 }
1339 
1340 
1341 template <typename MeshType>
1342 void ExporterVTK<MeshType>::composeVTUHeaderStream ( UInt numPoints,
1343  std::stringstream& vtuHeaderStringStream )
1344 {
1345 
1346  //header part of the file
1347  vtuHeaderStringStream << "<?xml version=\"1.0\"?>\n";
1348  vtuHeaderStringStream << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1349  vtuHeaderStringStream << "\t<UnstructuredGrid>\n";
1350  vtuHeaderStringStream << "\t\t<Piece NumberOfPoints=\"" << numPoints << "\""
1351  << " NumberOfCells=\"" << this->M_mesh->numElements() << "\">\n";
1352 
1353 
1354 }
1355 
1356 
1357 template <typename MeshType>
1358 void ExporterVTK<MeshType>::composeVTUFooterStream ( std::stringstream& vtuFooterStringStream )
1359 {
1360  debugStream (8000) << "\n[ExporterVTK::composeFooter]\n";
1361 
1362  //footer part of the file
1363  vtuFooterStringStream << "\t\t</Piece>\n";
1364  vtuFooterStringStream << "\t</UnstructuredGrid>\n";
1365  vtuFooterStringStream << "</VTKFile>\n";
1366 
1367 
1368 }
1369 
1370 
1371 template <typename MeshType>
1372 void
1374  std::stringstream& dataHeaderStringStream)
1375 {
1376  debugStream (8000) << "\n[ExporterVTK::composeTypeDataHeaderStream] where = " << where << "\n";
1377 
1378  std::string whereString;
1379  switch ( where )
1380  {
1381  case exporterData_Type::Node:
1382  whereString = "PointData";
1383  break;
1384  case exporterData_Type::Cell:
1385  whereString = "CellData";
1386  break;
1387  default:
1388  ERROR_MSG ( "Cannot manage this data location")
1389  break;
1390  }
1391  dataHeaderStringStream << "\t\t\t<" << whereString << " ";
1392 
1393  dataHeaderStringStream << ">\n";
1394 }
1395 
1396 
1397 template <typename MeshType>
1398 void
1400  std::stringstream& dataFooterStringStream)
1401 {
1402  std::string whereString;
1403  switch ( where )
1404  {
1405  case exporterData_Type::Node:
1406  whereString = "PointData";
1407  break;
1408  case exporterData_Type::Cell:
1409  whereString = "CellData";
1410  break;
1411  default:
1412  ERROR_MSG ( "Cannot manage this data location")
1413  break;
1414  }
1415  dataFooterStringStream << "\t\t\t</" << whereString << ">\n";
1416 }
1417 
1418 }
1419 #endif // define EXPORTERVTK_H
virtual void setDataFromGetPot(const GetPot &dataFile, const std::string &section="exporter")
Set data from file.
super::feTypeToDataIdMap_Type::iterator feTypeToDataIdMap_Type_Type
virtual void postProcess(const Real &time)
Post-process the variables added to the list.
void start()
Start the timer.
Definition: LifeChrono.hpp:93
void createPointsMaps(const feSpacePtr_Type &_feSpacePtr, std::map< UInt, UInt > &globalToLocalPointsMap, std::map< UInt, UInt > &localToGlobalPointsMap, std::vector< Vector > &coordinatesOfPoints)
virtual UInt importFromTime(const Real &)
Import data from previous simulations at a certain time.
#define debugStream
Definition: LifeDebug.hpp:182
void exportPID(meshPtr_Type, commPtr_Type comm, const bool=false)
temporary: the method should work form the Exporter class
virtual MapEpetraType mapType() const
returns the type of the map to use for the VectorEpetra
virtual void import(const Real &, const Real &)
Import data from previous simulations and rebuild the internal time counters.
ExporterVTK(const GetPot &data_file, const std::string prefix)
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
ExporterVTK(const ExporterVTK &example)
Copy constructor.
void composeDataArrayStream(const exporterData_Type &dvar, const std::map< UInt, UInt > &localToGlobalMap, std::stringstream &dataArraysStringStream)
ExporterVTK()
Default constructor.
void readBinaryData(const std::string &line, std::vector< Real > &values, const UInt &numBits)
A routine for loading values stored in binary format in a VTU file.
dataVector_Type::iterator dataVectorIterator_Type
Definition: Exporter.hpp:285
ExporterData - Holds the data structure of the array to import/export.
Definition: Exporter.hpp:70
virtual void readVector(ExporterData< mesh_Type > &)
The vector reader (specialization of the parent class method)
void readVTUFiles(exporterData_Type &dvar)
The reader for VTU files.
void composeVTUGeoStream(const feSpacePtr_Type &_feSpacePtr, const std::map< UInt, UInt > &globalToLocalPointsMap, const std::vector< Vector > &coordinatesOfPoints, std::stringstream &vtuGeoStringStream)
UInt whichCellType(const feSpacePtr_Type &_feSpacePtr)
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
void composeDataArrayStream(where_Type where, std::stringstream &dataArraysStringStream)
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
uint32_type ID
IDs.
Definition: LifeV.hpp:194
void readASCIIData(const std::string &line, std::vector< Real > &values)
A routine for loading values stored in ASCII format in a VTU file.
void composeVTKCollection(const std::string &variableName, std::stringstream &vtkCollectionStringStream)
const exporterData_Type::WhereEnum & where_Type
void composeTypeDataFooterStream(where_Type where, std::stringstream &typeDataFooterStringStream)
Exporter< mesh_Type > super
double Real
Generic real data.
Definition: LifeV.hpp:175
int32_t int32_type
Definition: LifeV.hpp:179
super::meshPtr_Type meshPtr_Type
EXPORT_MODE M_exportMode
NdebugStream noDebugStream(int=0, NdebugStream::stprintf=&printf)
Definition: LifeDebug.hpp:183
virtual void import(const Real &Tstart)
Import data from previous simulations.
const UInt nDimensions(NDIM)
void composeVTUHeaderStream(UInt numPoints, std::stringstream &vtuHeaderStringStream)
super::feSpacePtr_Type feSpacePtr_Type
virtual void readScalar(ExporterData< mesh_Type > &)
The scalar reader (specialization of the parent class method)
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
void composeVTUFooterStream(std::stringstream &vtuFooterStringStream)
static MapEpetraType const MapType
returns the type of the map to use for the VectorEpetra
std::map< std::string, std::list< std::string > > M_pvtuFiles
void composeTypeDataHeaderStream(where_Type where, std::stringstream &typeDataHeaderStringStream)
FLOAT_PRECISION M_floatPrecision
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
ExporterVTK data exporter.
Definition: ExporterVTK.hpp:57
super::exporterData_Type exporterData_Type
void composePVTUStream(const exporterData_Type &dvar, std::stringstream &pVTUStringStream)
super::commPtr_Type commPtr_Type
virtual ~ExporterVTK()
Destructor.
const flag_Type UPDATE_ONLY_CELL_NODES(1)