LifeV
ExporterPolicyHDF5.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 ExporterPolicyHDF5 class
29  @brief This class contains all the informations necessary to export to HDF5
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 04-12-2012
33  */
34 
35 #ifndef EXPORTERPOLICYHDF5_HPP
36 #define EXPORTERPOLICYHDF5_HPP
37 
38 #include <iostream>
39 #include <string>
40 #include <boost/shared_ptr.hpp>
41 
42 
43 #ifdef HAVE_MPI
44 #include <Epetra_MpiComm.h>
45 #else
46 #include <Epetra_SerialComm.h>
47 #endif
48 
49 #include <Teuchos_ParameterList.hpp>
50 #include <Teuchos_XMLParameterListHelpers.hpp>
51 #include <Teuchos_RCP.hpp>
52 
53 
54 #include <lifev/core/LifeV.hpp>
55 #include <lifev/core/array/VectorEpetra.hpp>
56 #include <lifev/core/util/Displayer.hpp>
57 #include <lifev/core/mesh/RegionMesh.hpp>
58 #include <lifev/core/fem/FESpace.hpp>
59 #include <lifev/core/filter/ExporterHDF5.hpp>
60 #include <lifev/core/util/LifeChrono.hpp>
61 
62 
63 namespace LifeV
64 {
65 
66 template< class mesh_Type >
68 {
69 
75  typedef FESpace< mesh_Type, map_Type > fespace_Type;
79 
80  void initExporter ( Teuchos::ParameterList& list,
81  vectorPtr_Type solution );
82  void exportSolution ();
83  void finalizeExporter();
85 
86  // Host state variables getters
87  virtual Displayer displayer() = 0;
88  virtual meshPtr_Type mesh() const = 0;
89  virtual fespacePtr_Type uFESpace() const = 0;
90  virtual fespacePtr_Type pFESpace() const = 0;
91  virtual Real currentTime() const = 0;
92 
93 };
94 
95 template< class mesh_Type >
96 void
97 ExporterPolicyHDF5< mesh_Type >::initExporter ( Teuchos::ParameterList& list,
98  vectorPtr_Type solution )
99 {
100  // Loading the parameters
101  std::string outputPath = list.get ( "Output path", "." );
102  outputPath.append ("/");
103  std::string outputFilename = list.get ( "Output filename", "solution" );
104 
105  GetPot datafile;
106  bool multipleMesh = list.get ( "Multiple mesh", false );
107  if ( multipleMesh )
108  {
109  datafile.set ( "exporter/multimesh", "true" );
110  }
111  else
112  {
113  datafile.set ( "exporter/multimesh", "false" );
114  }
115  int start = list.get ( "Start", 0 );
116  datafile.set ( "exporter/start", start );
117  int save = list.get ( "Save", 1 );
118  datafile.set ( "exporter/save", save );
119 
120  LifeChrono exporterSetupChrono;
121  exporterSetupChrono.start();
122 
123  displayer().leaderPrint ( "Defining the exporter... " );
124  M_exporter.reset ( new exporter_Type ( datafile, outputFilename ) );
125  M_exporter->setPostDir ( outputPath ); // This is a test to see if M_post_dir is working
126  M_exporter->setMeshProcId ( mesh(), mesh()->comm()->MyPID() );
127  displayer().leaderPrint ( "done\n" );
128 
129  displayer().leaderPrint ( "Updating the exporter... " );
130 
131  // Pressure offset in the vector
132  UInt pressureOffset = uFESpace()->fieldDim() * uFESpace()->dof().numTotalDof();
133 
134  M_exporter->addVariable ( ExporterData<mesh_Type>::VectorField, "velocity", uFESpace(),
135  solution, UInt ( 0 ) );
136  M_exporter->addVariable ( ExporterData<mesh_Type>::ScalarField, "pressure", pFESpace(),
137  solution, pressureOffset );
138  displayer().leaderPrint ( "done\n" );
139 
140  exporterSetupChrono.stop();
141  displayer().leaderPrintMax ("Exporter setup time: ", exporterSetupChrono.diff(), " s.\n");
142 }
143 
144 template< class mesh_Type >
145 void
147 {
148  displayer().leaderPrint ( "Exporting solution at time t = ", currentTime(), "... \n" );
149  M_exporter->postProcess ( currentTime() );
150 }
151 
152 template< class mesh_Type >
153 void
155 {
156  LifeChrono finalizeChrono;
157  finalizeChrono.start();
158  M_exporter->closeFile();
159  finalizeChrono.stop();
160  displayer().leaderPrintMax ("Exporter finalization time: ", finalizeChrono.diff(), " s.\n");
161 }
162 
163 } // namespace LifeV
164 
165 #endif /* EXPORTERPOLICYHDF5_HPP */
VectorEpetra - The Epetra Vector format Wrapper.
virtual fespacePtr_Type uFESpace() const =0
virtual fespacePtr_Type pFESpace() const =0
virtual meshPtr_Type mesh() const =0
void start()
Start the timer.
Definition: LifeChrono.hpp:93
std::shared_ptr< exporter_Type > exporterPtr_Type
std::shared_ptr< map_Type > mapPtr_Type
virtual Displayer displayer()=0
void updateInverseJacobian(const UInt &iQuadPt)
std::shared_ptr< VectorEpetra > vectorPtr_Type
std::shared_ptr< fespace_Type > fespacePtr_Type
FESpace< mesh_Type, map_Type > fespace_Type
virtual Real currentTime() const =0
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
ExporterHDF5< mesh_Type > exporter_Type
Real diff()
Compute the difference in time between start and stop.
Definition: LifeChrono.hpp:111
void set(const char *VarName, const int Value, const bool Requested=true)
Definition: GetPot.hpp:2267
double Real
Generic real data.
Definition: LifeV.hpp:175
void set(const char *VarName, const char *Value, const bool Requested=true)
Definition: GetPot.hpp:2246
void initExporter(Teuchos::ParameterList &list, vectorPtr_Type solution)
std::shared_ptr< mesh_Type > meshPtr_Type
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
Displayer - This class is used to display messages in parallel simulations.
Definition: Displayer.hpp:62
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191