Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exporter.hpp
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2004-11-09
7 
8  Copyright (C) 2004 EPFL
9  Copyright (C) 2007-2012 Université Joseph Fourier (Grenoble I)
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef __Exporter_H
31 #define __Exporter_H 1
32 
33 #include <feel/feelcore/feel.hpp>
37 
38 #include <feel/feeldiscr/timeset.hpp>
39 
40 namespace Feel
41 {
42 enum ExporterGeometry
43 {
44  EXPORTER_GEOMETRY_STATIC = 0,
45  EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY = 1,
46  EXPORTER_GEOMETRY_CHANGE = 2
47 
48 };
52 enum file_type
53 {
54  ASCII = 0,
55  BINARY = 1
56 };
57 
81 template<typename MeshType, int N = 1>
82 class Exporter
83  :
84 public VisitorBase,
85 public Visitor<MeshType>
86 {
87 public:
88 
89 
93  typedef VisitorBase super1;
94  typedef Visitor<MeshType> super2;
95 
97  typedef typename timeset_type::mesh_type mesh_type;
98  typedef typename timeset_type::mesh_ptrtype mesh_ptrtype;
99  typedef boost::shared_ptr<timeset_type> timeset_ptrtype;
100  typedef std::vector<timeset_ptrtype> timeset_set_type;
101  typedef typename timeset_set_type::iterator timeset_iterator;
102  typedef typename timeset_set_type::const_iterator timeset_const_iterator;
103  typedef typename timeset_type::step_type step_type;
104  typedef typename timeset_type::step_ptrtype step_ptrtype;
105  struct Factory
106  {
108  };
110 
114 
118  Exporter( WorldComm const& worldComm = Environment::worldComm() );
119 
126  Exporter( std::string const& type,
127  std::string const& prefix = "",
128  int freq = 1,
129  WorldComm const& worldComm = Environment::worldComm() );
130 
137  Exporter( po::variables_map const& vm,
138  std::string const& exporter_prefix = "",
139  WorldComm const& worldComm = Environment::worldComm() );
140 
144  Exporter( Exporter const & exporter );
145 
149  virtual ~Exporter();
150 
156  static boost::shared_ptr<Exporter<MeshType,N> > New( std::string const& exportername,
157  std::string prefix = Environment::about().appName(),
158  WorldComm const& worldComm = Environment::worldComm() );
159 
165  static boost::shared_ptr<Exporter<MeshType,N> > New( po::variables_map const& vm = Environment::vm(),
166  std::string prefix = Environment::about().appName(),
167  WorldComm const& worldComm = Environment::worldComm() );
168 
170 
174 
175 
177 
181 
185  bool doExport() const
186  {
187  return M_do_export;
188  }
189 
193  std::string const& type() const
194  {
195  return M_type;
196  }
197 
201  std::string const& prefix() const
202  {
203  return M_prefix;
204  }
205 
209  int freq() const
210  {
211  return M_freq;
212  }
213 
214 
218  int cptOfSave() const
219  {
220  return M_cptOfSave;
221  }
222 
226  file_type fileType() const
227  {
228  return M_ft;
229  }
230 
234  std::string path() const
235  {
236  return M_path;
237  }
238 
240 
244 
248  void setDoExport( bool do_export )
249  {
250  M_do_export = do_export;
251  }
252 
257  virtual Exporter<MeshType,N>* setOptions( std::string const& exp_prefix = "" );
258 
263  virtual Exporter<MeshType,N>* setOptions( po::variables_map const& vm, std::string const& exp_prefix = "" ) FEELPP_DEPRECATED { return setOptions( exp_prefix ); }
264 
265 
269  Exporter<MeshType,N>* setType( std::string const& __type )
270  {
271  M_type = __type;
272  return this;
273  }
274 
279  Exporter<MeshType,N>* addPath( boost::format fmt );
280 
284  Exporter<MeshType,N>* setPrefix( std::string const& __prefix )
285  {
286  M_prefix = __prefix;
287  return this;
288  }
289 
294  {
295  M_freq = __freq;
296  return this;
297  }
298 
303  {
304  M_ft = __ft;
305  return this;
306  }
307 
308  timeset_iterator beginTimeSet()
309  {
310  return M_ts_set.begin();
311  }
312  timeset_iterator endTimeSet()
313  {
314  return M_ts_set.end();
315  }
316 
317  timeset_const_iterator beginTimeSet() const
318  {
319  return M_ts_set.begin();
320  }
321  timeset_const_iterator endTimeSet() const
322  {
323  return M_ts_set.end();
324  }
325 
326 
327  timeset_ptrtype defaultTimeSet()
328  {
329  return M_ts_set.front();
330  }
331  timeset_ptrtype timeSet( int ts )
332  {
333  return M_ts_set[ts];
334  }
335 
336  bool useSingleTransientFile() const
337  {
338  return M_use_single_transient_file;
339  }
340  void setUseSingleTransientFile( bool s )
341  {
342  M_use_single_transient_file = s;
343  }
344  void
345  setMesh( mesh_ptrtype mesh, ExporterGeometry exgeo = EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY )
346  {
347  M_ex_geometry = exgeo;
348  M_ts_set.back()->setMesh( mesh );
349  //this->step( 0 )->setMesh( mesh );
350  }
351  template<typename F>
352  void
353  add( std::string const& name, F const& u )
354  {
355  this->step( 0 )->add( this->prefix()+"."+name, u );
356  }
357 
358  void
359  addRegions()
360  {
361  this->step( 0 )->addRegions( this->prefix() );
362  }
363  step_ptrtype step( double time )
364  {
365  if ( this->cptOfSave() % this->freq() )
366  return M_ts_set.back()->step( time, true );
367 
368  else
369  return M_ts_set.back()->step( time, false );
370  }
371  step_ptrtype step( double time, int s )
372  {
373  if ( M_cptOfSave % this->freq() )
374  return M_ts_set[s]->step( time, true );
375 
376  else
377  return M_ts_set[s]->step( time, false );
378  }
379 
381 
385 
389  void addTimeSet( timeset_ptrtype const& __ts )
390  {
391  if ( __ts )
392  M_ts_set.push_back( __ts );
393  }
394 
395 
400  virtual void save() const = 0;
401 
405  void saveTimeSet() const
406  {
407  if ( this->worldComm().rank() != this->worldComm().masterRank() )
408  {
409  ++M_cptOfSave;
410  return;
411  }
412 
413  auto __ts_it = this->beginTimeSet();
414  auto __ts_en = this->endTimeSet();
415 
416  for ( ; __ts_it != __ts_en ; ++__ts_it )
417  {
418  auto filename = this->path()+"/"+prefix()+".timeset";
419  ( *__ts_it )->save( filename );
420  }
421 
422  ++M_cptOfSave;
423  }
424 
428  void restart( double __time )
429  {
430  auto __ts_it = this->beginTimeSet();
431  auto __ts_en = this->endTimeSet();
432 
433  for ( ; __ts_it != __ts_en ; ++__ts_it )
434  {
435  auto filename = this->path()+"/"+prefix()+".timeset";
436  ( *__ts_it )->load( filename,__time );
437 
438  M_cptOfSave = ( *__ts_it )->numberOfTotalSteps()+1;
439  }
440  }
441 
442  void setWorldComm( WorldComm const& wc )
443  {
444  M_worldComm = wc;
445  }
446  WorldComm const& worldComm() const
447  {
448  return M_worldComm;
449  }
450 
451  ExporterGeometry exporterGeometry() const { return M_ex_geometry; }
453 protected:
454 
455  WorldComm M_worldComm;
456 
457  bool M_do_export;
458  bool M_use_single_transient_file;
459  std::string M_type;
460  std::string M_prefix;
461  int M_freq;
462  mutable int M_cptOfSave;
463  file_type M_ft;
464  std::string M_path;
465  ExporterGeometry M_ex_geometry;
466 
467  mutable timeset_set_type M_ts_set;
468 };
469 
470 
471 
472 
473 namespace detail
474 {
475 template<typename Args>
476 struct compute_exporter_return
477 {
478  typedef typename boost::remove_pointer<
479  typename boost::remove_const<
480  typename boost::remove_reference<
481  typename parameter::binding<Args, tag::mesh>::type
482  >::type
483  >::type
484  >::type::element_type mesh_type;
485  //typename Feel::vf::detail::clean_type<Args, tag::mesh>::type::element_type mesh_type;
486  //typedef typename parameter::value_type<Args, tag::order>::type order_type;
487  //typedef boost::shared_ptr<Exporter<mesh_type,order_type::value> > type;
488  typedef Exporter<mesh_type,mesh_type::nOrder> type;
489  typedef boost::shared_ptr<type> ptrtype;
490  //typedef boost::shared_ptr<Exporter<Mesh<Simplex<2> >,1> > type;
491 
492 };
493 }
494 BOOST_PARAMETER_FUNCTION( ( typename Feel::detail::compute_exporter_return<Args>::ptrtype ),
495  exporter, // 2. name of the function template
496  tag, // 3. namespace of tag types
497  ( required // 4. one required parameter, and
498  ( mesh, * )
499  ) // required
500  ( optional // 4. one required parameter, and
501  ( fileset, *, option(_name="exporter.fileset").template as<bool>() )
502  ( order, *, mpl::int_<1>() )
503  ( name, *, Environment::about().appName() )
504  ( geo, *, option(_name="exporter.geometry").template as<int>() )
505  ( worldcomm, *, Environment::worldComm() )
506  ) )
507 {
508  typedef typename Feel::detail::compute_exporter_return<Args>::type exporter_type;
509  auto e = exporter_type::New(Environment::vm(),name,worldcomm);
510  e->setPrefix( name );
511  e->setUseSingleTransientFile( fileset );
512  e->setMesh( mesh, (ExporterGeometry) geo );
513  // addRegions not work with transient simulation!
514  //e->addRegions();
515  return e;
516  //return Exporter<Mesh<Simplex<2> >,1>::New();
517 }
518 
519 } // Feel
520 
521 //#if !defined( FEELPP_INSTANTIATION_MODE )
523 //#endif // FEELPP_INSTANTIATION_MODE
524 
525 
526 #endif /* __Exporter_H */

Generated on Fri Oct 25 2013 14:24:08 for Feel++ by doxygen 1.8.4