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
timeset.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: 2005-01-12
7 
8  Copyright (C) 2005,2006 EPFL
9  Copyright (C) 2006-2012 Universite Joseph Fourier
10 
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Lesser General Public
14  License as published by the Free Software Foundation; either
15  version 3.0 of the License, or (at your option) any later version.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Lesser General Public License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with this library; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
32 #ifndef __timeSet_H
33 #define __timeSet_H 1
34 
35 #include <set>
36 #include <fstream>
37 #include <sstream>
38 #include <algorithm>
39 
40 
41 #include <boost/shared_ptr.hpp>
42 #include <boost/optional.hpp>
43 #include <boost/operators.hpp>
44 
45 #include <boost/filesystem/operations.hpp>
46 #include <boost/filesystem/fstream.hpp>
47 
48 #include <boost/archive/binary_oarchive.hpp>
49 #include <boost/archive/binary_iarchive.hpp>
50 
51 #include <boost/serialization/split_member.hpp>
52 #include <boost/serialization/utility.hpp>
53 #include <boost/serialization/map.hpp>
54 #include <boost/serialization/string.hpp>
55 
56 // #include <boost/numeric/ublas/vector_serialize.hpp>
57 
58 #include <feel/feelcore/feel.hpp>
59 #include <feel/feelcore/context.hpp>
60 
61 #include <feel/feelalg/glas.hpp>
63 
64 #include <feel/feeldiscr/mesh.hpp>
65 #include <feel/feeldiscr/functionspace.hpp>
67 
68 
69 namespace Feel
70 {
71 namespace fs = boost::filesystem;
72 
73 enum
74 {
75  STEP_NEW = ( 1<<0 ),
76  STEP_HAS_DATA = ( 1<<1 ),
77  STEP_ON_DISK = ( 1<<2 ),
78  STEP_IN_MEMORY = ( 1<<3 ),
79  STEP_OVERWRITE = ( 1<<10 )
80 };
81 template<typename A0,typename A1,typename A2,typename A3,typename A4> class FunctionSpace;
89 template<typename MeshType, int N = 1>
90 class TimeSet
91 {
92 public:
93 
97  typedef MeshType mesh_type;
98  typedef boost::shared_ptr<mesh_type> mesh_ptrtype;
99 
100 
107  typedef boost::shared_ptr<scalar_p0_space_type> scalar_p0_space_ptrtype;
108  typedef boost::shared_ptr<vector_p0_space_type> vector_p0_space_ptrtype;
109  typedef boost::shared_ptr<tensor2_p0_space_type> tensor2_p0_space_ptrtype;
110  typedef boost::shared_ptr<scalar_p1_space_type> scalar_p1_space_ptrtype;
111  typedef boost::shared_ptr<vector_p1_space_type> vector_p1_space_ptrtype;
112  typedef boost::shared_ptr<tensor2_p1_space_type> tensor2_p1_space_ptrtype;
113 
114 
115  typedef typename scalar_p0_space_type::element_type element_scalar_type;
116  typedef typename vector_p0_space_type::element_type element_vector_type;
117  typedef typename tensor2_p0_space_type::element_type element_tensor2_type;
118  typedef typename scalar_p1_space_type::element_type nodal_scalar_type;
119  typedef typename vector_p1_space_type::element_type nodal_vector_type;
120  typedef typename tensor2_p1_space_type::element_type nodal_tensor2_type;
121 
122 
126  class Step
127  :
128  boost::equality_comparable<Step>,
129  boost::less_than_comparable<Step>
130  {
131  public:
132 
136  typedef Step step_type;
137  typedef MeshType mesh_type;
138  typedef boost::shared_ptr<mesh_type> mesh_ptrtype;
139 
140 
147  typedef boost::shared_ptr<scalar_p0_space_type> scalar_p0_space_ptrtype;
148  typedef boost::shared_ptr<vector_p0_space_type> vector_p0_space_ptrtype;
149  typedef boost::shared_ptr<tensor2_p0_space_type> tensor2_p0_space_ptrtype;
150  typedef boost::shared_ptr<scalar_p1_space_type> scalar_p1_space_ptrtype;
151  typedef boost::shared_ptr<vector_p1_space_type> vector_p1_space_ptrtype;
152  typedef boost::shared_ptr<tensor2_p1_space_type> tensor2_p1_space_ptrtype;
153 
154 
155  typedef typename scalar_p0_space_type::element_type element_scalar_type;
156  typedef typename vector_p0_space_type::element_type element_vector_type;
157  typedef typename tensor2_p0_space_type::element_type element_tensor2_type;
158  typedef typename scalar_p1_space_type::element_type nodal_scalar_type;
159  typedef typename vector_p1_space_type::element_type nodal_vector_type;
160  typedef typename tensor2_p1_space_type::element_type nodal_tensor2_type;
161 
162  typedef std::map<std::string, std::pair<scalar_type,bool> > map_scalar_type;
163  typedef std::map<std::string, std::pair<complex_type,bool> > map_complex_type;
164  typedef std::map<std::string, nodal_scalar_type> map_nodal_scalar_type;
165  typedef std::map<std::string, nodal_vector_type> map_nodal_vector_type;
166  typedef std::map<std::string, nodal_tensor2_type> map_nodal_tensor2_type;
167  typedef std::map<std::string, element_scalar_type> map_element_scalar_type;
168  typedef std::map<std::string, element_vector_type> map_element_vector_type;
169  typedef std::map<std::string, element_tensor2_type> map_element_tensor2_type;
170 
171  typedef typename map_scalar_type::iterator scalar_iterator;
172  typedef typename map_scalar_type::const_iterator scalar_const_iterator;
173 
174  typedef typename map_complex_type::iterator complex_iterator;
175  typedef typename map_complex_type::const_iterator complex_const_iterator;
176 
177  typedef typename map_nodal_scalar_type::iterator nodal_scalar_iterator;
178  typedef typename map_nodal_scalar_type::const_iterator nodal_scalar_const_iterator;
179 
180  typedef typename map_nodal_vector_type::iterator nodal_vector_iterator;
181  typedef typename map_nodal_vector_type::const_iterator nodal_vector_const_iterator;
182 
183  typedef typename map_nodal_tensor2_type::iterator nodal_tensor2_iterator;
184  typedef typename map_nodal_tensor2_type::const_iterator nodal_tensor2_const_iterator;
185 
186  typedef typename map_element_scalar_type::iterator element_scalar_iterator;
187  typedef typename map_element_scalar_type::const_iterator element_scalar_const_iterator;
188 
189  typedef typename map_element_vector_type::iterator element_vector_iterator;
190  typedef typename map_element_vector_type::const_iterator element_vector_const_iterator;
191 
192  typedef typename map_element_tensor2_type::iterator element_tensor2_iterator;
193  typedef typename map_element_tensor2_type::const_iterator element_tensor2_const_iterator;
194 
196 
200 
205 
207 
211 
216  bool isNew() const
217  {
218  return M_state.test( STEP_NEW );
219  }
220 
225  bool hasData() const
226  {
227  return M_state.test( STEP_HAS_DATA );
228  }
229 
234  bool isOnDisk() const
235  {
236  return M_state.test( STEP_ON_DISK );
237  }
238 
243  bool isInMemory() const
244  {
245  return M_state.test( STEP_IN_MEMORY );
246  }
247 
252  size_type state() const
253  {
254  return M_state.context();
255  }
256 
260  Real time() const
261  {
262  return M_time;
263  }
264 
268  size_type index() const
269  {
270  return M_index;
271  }
272 
276  bool hasMesh() const
277  {
278  return M_mesh;
279  }
280 
284  mesh_ptrtype mesh()
285  {
286  return M_mesh.get();
287  }
288 
292  scalar_const_iterator beginScalar() const { return M_scalar.begin(); }
293 
297  scalar_const_iterator endScalar() const { return M_scalar.end(); }
298 
304  scalar_type scalar( std::string const& __n ) const
305  {
306  if ( M_scalar.find( __n ) == M_scalar.end() )
307  {
308  std::ostringstream __err;
309  __err << "invalid scalar value name " << __n;
310  throw std::logic_error( __err.str() );
311  }
312 
313  return M_scalar.find( __n )->second.first;
314  }
315 
316 
322  nodal_scalar_type nodalScalar( std::string const& __n ) const
323  {
324  if ( M_nodal_scalar.find( __n ) == M_nodal_scalar.end() )
325  {
326  std::ostringstream __err;
327  __err << "invalid nodal scalar field name " << __n;
328  throw std::logic_error( __err.str() );
329  }
330 
331  return M_nodal_scalar.find( __n )->second.first;
332  }
333 
339  nodal_vector_type nodalVector( std::string const& __n ) const
340  {
341  if ( M_nodal_vector.find( __n ) == M_nodal_vector.end() )
342  {
343  std::ostringstream __err;
344  __err << "invalid nodal vector field name " << __n;
345  throw std::logic_error( __err.str() );
346  }
347 
348  return M_nodal_vector.find( __n )->second;
349  }
350 
356  nodal_tensor2_type nodalTensor2( std::string const& __n ) const
357  {
358  if ( M_nodal_tensor2.find( __n ) == M_nodal_tensor2.end() )
359  {
360  std::ostringstream __err;
361  __err << "invalid nodal tensor2 field name " << __n;
362  throw std::logic_error( __err.str() );
363  }
364 
365  return M_nodal_tensor2.find( __n )->second;
366  }
367 
373  element_scalar_type elementScalar( std::string const& __n ) const
374  {
375  if ( M_element_scalar.find( __n ) == M_element_scalar.end() )
376  {
377  std::ostringstream __err;
378  __err << "invalid element scalar field name " << __n;
379  throw std::logic_error( __err.str() );
380  }
381 
382  return M_element_scalar.find( __n )->second;
383  }
384 
390  element_vector_type elementVector( std::string const& __n ) const
391  {
392  if ( M_element_vector.find( __n ) == M_element_vector.end() )
393  {
394  std::ostringstream __err;
395  __err << "invalid element vector field name " << __n;
396  throw std::logic_error( __err.str() );
397  }
398 
399  return M_element_vector.find( __n )->second;
400  }
401 
407  element_tensor2_type elementTensor2( std::string const& __n ) const
408  {
409  if ( M_element_tensor2.find( __n ) == M_element_tensor2.end() )
410  {
411  std::ostringstream __err;
412  __err << "invalid element tensor2 field name " << __n;
413  throw std::logic_error( __err.str() );
414  }
415 
416  return M_element_tensor2.find( __n )->second;
417  }
418 
420 
424 
425  void setState( size_type __st )
426  {
427  executeState( __st );
428  showMe( "Step::setState" );
429  }
430  void setMesh( mesh_ptrtype const& __m )
431  {
432  DVLOG(2) << "[TimeSet::setMesh] setMesh start\n";
433  M_mesh = __m;
434 
435  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
436  M_state.clear( STEP_ON_DISK );
437  DVLOG(2) << "[TimeSet::setMesh] setMesh start\n";
438  }
439 
440  void addScalar( std::string const& name, scalar_type const& __s, bool cst = false )
441  {
442  M_scalar[name] = std::make_pair( __s, cst );
443  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
444  M_state.clear( STEP_ON_DISK );
445  }
446 
447  void addComplex( std::string const& name, complex_type const& __s )
448  {
449  M_complex[name] = __s;
450  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
451  M_state.clear( STEP_ON_DISK );
452  }
453 
454  void addNodal( nodal_scalar_type const& __s )
455  {
456  M_nodal_scalar[__s.name()] = __s;
457  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
458  M_state.clear( STEP_ON_DISK );
459  }
460 
461  void addNodal( nodal_vector_type const& __s )
462  {
463  M_nodal_vector[__s.name()] = __s;
464  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
465  M_state.clear( STEP_ON_DISK );
466  }
467 
468  void
469  addRegions( std::string prefix = "" )
470  {
471  VLOG(1) << "[timeset] Adding regions...\n";
472  if ( !M_ts->M_scalar_p0 )
473  {
474  VLOG(1) << "[timeset] creating space...\n";
475  if ( Environment::worldComm().numberOfSubWorlds() > 1 )
476  {
477  auto wc = std::vector<WorldComm>( 1, Environment::worldComm().subWorld(Environment::worldComm().numberOfSubWorlds()) );
478  M_ts->M_scalar_p0 = scalar_p0_space_type::New ( _mesh=M_mesh.get(), _worldscomm=wc );
479  }
480  else
481  {
482  auto wc = std::vector<WorldComm>( 1, Environment::worldComm() );
483  M_ts->M_scalar_p0 = scalar_p0_space_type::New ( _mesh=M_mesh.get(), _worldscomm=wc );
484  }
485  M_scalar_p0 = M_ts->M_scalar_p0;
486  }
487  VLOG(1) << "[timeset] adding pid...\n";
488  if ( prefix.empty() )
489  add( "pid", regionProcess( M_scalar_p0 ) );
490  else
491  add( prefix + "." + "pid", regionProcess( M_scalar_p0 ) );
492  //add( "marker", regionMarker( M_scalar_p0 ) );
493  //add( "marker2", regionMarker2( M_scalar_p0 ) );
494  //add( "marker3", regionMarker3( M_scalar_p0 ) );
495  }
496 
497  template<typename FunctionType>
498  void add( std::initializer_list<std::string> __n, FunctionType const& func )
499  {
500  std::vector<std::string> str( __n );
501  add_( str, func, mpl::bool_<(FunctionType::functionspace_type::nSpaces>1)>() );
502  }
503 
504  template<typename FunctionType>
505  void add( std::vector<std::string> const& __n, FunctionType const& func )
506  {
507  add_( __n, func, mpl::bool_<(FunctionType::functionspace_type::nSpaces>1)>() );
508  }
509  template<typename FunctionType>
510  void add( std::string const& __n, FunctionType const& func )
511  {
512  add_( __n, func, mpl::bool_<(FunctionType::functionspace_type::nSpaces>1)>() );
513  }
514 
515  template<typename TSet>
516  struct AddFunctionProduct
517  {
518  AddFunctionProduct( TSet& tset ) : M_tset( tset ) {}
519  TSet& M_tset;
520 
521  template<typename T>
522  void
523  operator()( T const& fun ) const
524  {
525  LOG(INFO) << "export " << fun.name() << " ...\n";
526  M_tset.add_( fun.name(), fun, mpl::bool_<false>() );
527  }
528  };
529  template<typename FunctionType>
530  void add_( std::vector<std::string> const& __n, FunctionType const& func, mpl::bool_<true> )
531  {
532  std::vector<std::string> s = __n;
533  FEELPP_ASSERT( s.size() == FunctionType::functionspace_type::nSpaces );
534  // implement elements() which returns a fusion vector of the components
535  fusion::for_each( subelements(func,s), AddFunctionProduct<step_type>( *this ) );
536  }
537  template<typename FunctionType>
538  void add_( std::string const& __n, FunctionType const& func, mpl::bool_<true> )
539  {
540  std::vector<std::string> s;
541  // s.push_back(__n);
542  for(int i=0; i<FunctionType::functionspace_type::nSpaces; i++)
543  {
544  std::ostringstream i_str;
545  i_str << "_" << i;
546  s.push_back(__n + i_str.str());
547  }
548  FEELPP_ASSERT( s.size() == FunctionType::functionspace_type::nSpaces );
549  // implement elements() which returns a fusion vector of the components
550  fusion::for_each( subelements(func,s), AddFunctionProduct<step_type>( *this ) );
551  }
552  template<typename FunctionType>
553  void add_( std::string const& __n, FunctionType const& func, mpl::bool_<false> )
554  {
555  typedef typename mpl::or_<is_shared_ptr<FunctionType>, boost::is_pointer<FunctionType> >::type is_ptr_or_shared_ptr;
556  add( __n,func,is_ptr_or_shared_ptr() );
557  }
558  template<typename FunctionType>
559  void add( std::string const& __n, std::string const& __fname, FunctionType const& func )
560  {
561  typedef typename mpl::or_<is_shared_ptr<FunctionType>, boost::is_pointer<FunctionType> >::type is_ptr_or_shared_ptr;
562  add( __n,__fname,func,is_ptr_or_shared_ptr() );
563  }
564 
565  template<typename FunctionType>
566  void add( std::string const& __n, FunctionType const& func, mpl::bool_<true> )
567  {
568  add( __n,*func, mpl::bool_<false>() );
569  }
570  template<typename FunctionType>
571  void add( std::string const& __n, std::string const& __fname, FunctionType const& func, mpl::bool_<true> )
572  {
573  add( __n,__fname,*func, mpl::bool_<false>() );
574  }
575 
576  template<typename FunctionType>
577  void add( std::string const& __n, FunctionType const& func, mpl::bool_<false> )
578  {
579  add( __n, __n, func, mpl::bool_<false>(), mpl::bool_<FunctionType::is_continuous || FunctionType::functionspace_type::continuity_type::is_discontinuous_locally>() );
580  }
581  template<typename FunctionType>
582  void add( std::string const& __n, std::string const& __fname, FunctionType const& func, mpl::bool_<false> )
583  {
584  add( __n, __fname, func, mpl::bool_<false>(), mpl::bool_<FunctionType::is_continuous || FunctionType::functionspace_type::continuity_type::is_discontinuous_locally>() );
585  }
586  template<typename FunctionType>
587  void add( std::string const& __n, std::string const& __fname, FunctionType const& func, mpl::bool_<false>, mpl::bool_<true> )
588  {
589 
590  if ( FunctionType::is_scalar )
591  {
592  boost::timer t;
593 
594  if ( !M_ts->M_scalar_p1 )
595  {
596  M_ts->M_scalar_p1 = scalar_p1_space_ptrtype( new scalar_p1_space_type ( M_mesh.get(),
597  MESH_RENUMBER | MESH_CHECK,
598  typename scalar_p1_space_type::periodicity_type(),
599  func.worldsComm() ) );
600  M_scalar_p1 = M_ts->M_scalar_p1;
601  DVLOG(2) << "[TimeSet::setMesh] setMesh space scalar p1 created\n";
602  }
603 
604  else if ( M_mesh.get() == M_ts->M_scalar_p1->mesh() )
605  {
606  M_scalar_p1 = M_ts->M_scalar_p1;
607  }
608 
609  if ( M_mesh.get() != M_ts->M_scalar_p1->mesh() && !M_scalar_p1 )
610  {
611  M_scalar_p1 = scalar_p1_space_ptrtype( new scalar_p1_space_type ( M_mesh.get(),
612  MESH_RENUMBER | MESH_CHECK,
613  typename scalar_p1_space_type::periodicity_type(),
614  func.worldsComm() ) );
615  DVLOG(2) << "[TimeSet::setMesh] setMesh space scalar p1 created\n";
616  }
617 
618  M_nodal_scalar.insert( std::make_pair( __fname, M_scalar_p1->element( __n ) ) );
619 
620  //M_nodal_scalar[__fname].setName( __n );
621  //M_nodal_scalar[__fname].setFunctionSpace( M_scalar_p1 );
622  if ( func.worldComm().isActive() )
623  interpolate( M_scalar_p1, func, M_nodal_scalar[__fname] );
624 
625  DVLOG(2) << "[timset::add] scalar time : " << t.elapsed() << "\n";
626  }
627 
628  else if ( FunctionType::is_vectorial )
629  {
630  boost::timer t;
631 
632  if ( !M_ts->M_vector_p1 )
633  {
634  M_ts->M_vector_p1 = vector_p1_space_ptrtype( new vector_p1_space_type ( M_mesh.get(),
635  MESH_RENUMBER | MESH_CHECK,
636  typename vector_p1_space_type::periodicity_type(),
637  func.worldsComm() ) );
638  M_vector_p1 = M_ts->M_vector_p1;
639  DVLOG(2) << "[TimeSet::setMesh] setMesh space scalar p1 created\n";
640  }
641 
642  else if ( M_mesh.get() == M_ts->M_vector_p1->mesh() )
643  {
644  M_vector_p1 = M_ts->M_vector_p1;
645  }
646 
647  if ( M_mesh.get() != M_ts->M_vector_p1->mesh() && !M_vector_p1 )
648  {
649  M_vector_p1 = vector_p1_space_ptrtype( new vector_p1_space_type ( M_mesh.get(),
650  MESH_RENUMBER | MESH_CHECK,
651  typename vector_p1_space_type::periodicity_type(),
652  func.worldsComm() ) );
653  DVLOG(2) << "[timeset::add] setmesh : " << t.elapsed() << "\n";
654  DVLOG(2) << "[TimeSet::setMesh] setMesh space vector p1 created\n";
655  }
656 
657  t.restart();
658  M_nodal_vector.insert( std::make_pair( __fname,M_vector_p1->element( __n ) ) );
659  //M_nodal_vector[__fname].setName( __n );
660  //M_nodal_vector[__fname].setFunctionSpace( M_vector_p1 );
661  DVLOG(2) << "[timeset::add] setmesh : " << t.elapsed() << "\n";
662  t.restart();
663 
664  if ( func.worldComm().isActive() )
665  interpolate( M_vector_p1, func, M_nodal_vector[__fname] );
666 
667  DVLOG(2) << "[timset::add] scalar time : " << t.elapsed() << "\n";
668  }
669 
670  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
671  M_state.clear( STEP_ON_DISK );
672 
673  showMe( "Step::add" );
674  }
675 
676  template<typename FunctionType>
677  void add( std::string const& __n, std::string const& __fname, FunctionType const& func, mpl::bool_<false>, mpl::bool_<false> )
678  {
679  if ( !func.worldComm().isActive() ) return;
680 
681  if ( FunctionType::is_scalar )
682  {
683  if ( !M_ts->M_scalar_p0 )
684  {
685  M_ts->M_scalar_p0 = scalar_p0_space_ptrtype( new scalar_p0_space_type ( M_mesh.get(),
686  MESH_RENUMBER | MESH_CHECK,
687  typename scalar_p0_space_type::periodicity_type(),
688  func.worldsComm() ) );
689  M_scalar_p0 = M_ts->M_scalar_p0;
690  DVLOG(2) << "[TimeSet::setMesh] setMesh space scalar p0 created\n";
691  }
692 
693  else if ( M_mesh.get() == M_ts->M_scalar_p0->mesh() )
694  {
695  M_scalar_p0 = M_ts->M_scalar_p0;
696  }
697 
698  if ( M_mesh.get() != M_ts->M_scalar_p0->mesh() && !M_scalar_p0 )
699  {
700  M_scalar_p0 = scalar_p0_space_ptrtype( new scalar_p0_space_type ( M_mesh.get(),
701  MESH_RENUMBER | MESH_CHECK,
702  typename scalar_p0_space_type::periodicity_type(),
703  func.worldsComm() ) );
704  DVLOG(2) << "[TimeSet::setMesh] setMesh space scalar p0 created\n";
705  }
706 
707  M_element_scalar.insert( std::make_pair( __fname,M_scalar_p0->element( __n ) ) );
708  //M_element_scalar[__fname].setName( __n );
709  //M_element_scalar[__fname].setFunctionSpace( M_scalar_p0 );
710 
711  if ( func.worldComm().isActive() )
712  interpolate( M_scalar_p0, func, M_element_scalar[__fname] );
713 
714  //std::copy( func.begin(), func.end(), M_element_scalar[__fname].begin() );
715  DVLOG(2) << "[TimeSet::add] scalar p0 function " << __n << " added to exporter with filename " << __fname << "\n";
716  }
717 
718  else if ( FunctionType::is_vectorial )
719  {
720  if ( !M_ts->M_vector_p0 )
721  {
722  M_ts->M_vector_p0 = vector_p0_space_ptrtype( new vector_p0_space_type ( M_mesh.get(),
723  MESH_RENUMBER | MESH_CHECK,
724  typename vector_p0_space_type::periodicity_type(),
725  func.worldsComm() ) );
726  M_vector_p0 = M_ts->M_vector_p0;
727  DVLOG(2) << "[TimeSet::setMesh] setMesh space vector p0 created\n";
728  }
729 
730  else if ( M_mesh.get() == M_ts->M_vector_p0->mesh() )
731  {
732  M_vector_p0 = M_ts->M_vector_p0;
733  }
734 
735  if ( M_mesh.get() != M_ts->M_vector_p0->mesh() && !M_vector_p0 )
736  {
737  M_vector_p0 = vector_p0_space_ptrtype( new vector_p0_space_type ( M_mesh.get(),
738  MESH_RENUMBER | MESH_CHECK,
739  typename vector_p0_space_type::periodicity_type(),
740  func.worldsComm() ) );
741  DVLOG(2) << "[TimeSet::setMesh] setMesh space vector p0 created\n";
742  //M_tensor2_p0 = tensor2_p0_space_ptrtype( new tensor2_p0_space_type ( M_mesh.get() ) );
743  }
744 
745  M_element_vector.insert( std::make_pair( __fname,M_vector_p0->element( __n ) ) );
746  //M_element_vector[__fname].setName( __n );
747  //M_element_vector[__fname].setFunctionSpace( M_vector_p0 );
748 
749  if ( func.worldComm().isActive() )
750  interpolate( M_vector_p0, func, M_element_vector[__fname] );
751 
752  //std::copy( func.begin(), func.end(), M_element_vector[__fname].begin() );
753  }
754 
755  else if ( FunctionType::is_tensor2 )
756  {
757  M_element_tensor2[__fname].setName( __n );
758  M_element_tensor2[__fname].setFunctionSpace( M_tensor2_p0 );
759 
760  if ( func.worldComm().isActive() )
761  interpolate( M_tensor2_p0, func, M_element_tensor2[__fname] );
762 
763  //std::copy( func.begin(), func.end(), M_element_tensor2[__fname].begin() );
764  }
765 
766  M_state.set( STEP_HAS_DATA|STEP_IN_MEMORY );
767  M_state.clear( STEP_ON_DISK );
768  showMe( "Step::addElement" );
769  DVLOG(2) << "[TimeSet::add] p0 function done\n";
770  }
771 
773 
777 
778  nodal_scalar_const_iterator beginNodalScalar() const
779  {
780  return M_nodal_scalar.begin();
781  }
782  nodal_scalar_const_iterator endNodalScalar() const
783  {
784  return M_nodal_scalar.end();
785  }
786  nodal_vector_const_iterator beginNodalVector() const
787  {
788  return M_nodal_vector.begin();
789  }
790  nodal_vector_const_iterator endNodalVector() const
791  {
792  return M_nodal_vector.end();
793  }
794  nodal_tensor2_const_iterator beginNodalTensor2() const
795  {
796  return M_nodal_tensor2.begin();
797  }
798  nodal_tensor2_const_iterator endNodalTensor2() const
799  {
800  return M_nodal_tensor2.end();
801  }
802 
803  element_scalar_const_iterator beginElementScalar() const
804  {
805  return M_element_scalar.begin();
806  }
807  element_scalar_const_iterator endElementScalar() const
808  {
809  return M_element_scalar.end();
810  }
811  element_vector_const_iterator beginElementVector() const
812  {
813  return M_element_vector.begin();
814  }
815  element_vector_const_iterator endElementVector() const
816  {
817  return M_element_vector.end();
818  }
819  element_tensor2_const_iterator beginElementTensor2() const
820  {
821  return M_element_tensor2.begin();
822  }
823  element_tensor2_const_iterator endElementTensor2() const
824  {
825  return M_element_tensor2.end();
826  }
827 
828  bool operator==( Step const& __s ) const
829  {
830  return this->index() == __s.index();
831  }
832  bool operator<( Step const& __s ) const
833  {
834  return this->index() < __s.index();
835  }
836 
837  void load()
838  {
839  this->setState( STEP_IN_MEMORY );
840  }
841  void showMe( std::string str ) const
842  {
843  DVLOG(2) << str << " index : " << M_index << "\n";
844  DVLOG(2) << str << " time : " << M_time << "\n";
845  DVLOG(2) << str << " isNew() " << isNew() << "\n";
846  DVLOG(2) << str << " hasData() " << hasData() << "\n";
847  DVLOG(2) << str << " isOnDisk() " << isOnDisk() << "\n";
848  DVLOG(2) << str << " isInMemory() " << isInMemory() << "\n";
849  }
851 
852 
853  private:
854 
856  friend class TimeSet;
857 
861 
865  Step();
866 
874  Step( TimeSet* ts, Real time, size_type index, size_type __state = STEP_NEW|STEP_OVERWRITE );
875 
876 
880  Step( Step const & );
881 
882 
883 
885 
889 
890  Step& operator=( Step const& );
891 
893 
894  friend class boost::serialization::access;
895 
896  template<class Archive>
897  void save( Archive & ar, const unsigned int /*version*/ ) const
898  {
899  size_type s;
900 
901  // values
902  s = M_scalar.size();
903  ar & boost::serialization::make_nvp( "map_scalar_size", s );
904 
905  scalar_const_iterator __its= M_scalar.begin();
906  scalar_const_iterator __ens= M_scalar.end();
907 
908  for ( ; __its!= __ens; ++__its )
909  {
910  ar & boost::serialization::make_nvp( "scalar", *__its );
911  }
912 
913  s = M_complex.size();
914  ar & boost::serialization::make_nvp( "map_complex_size", s );
915 
916  complex_const_iterator __itc = M_complex.begin();
917  complex_const_iterator __enc = M_complex.end();
918 
919  for ( ; __itc!= __enc; ++__itc )
920  {
921  ar & boost::serialization::make_nvp( "complex", ( std::string const& )__itc->first );
922  ar & boost::serialization::make_nvp( "real", ( scalar_type const& )__itc->second.first.real() );
923  ar & boost::serialization::make_nvp( "imaginary", ( scalar_type const& )__itc->second.first.imag() );
924  }
925 
926  s = M_nodal_scalar.size();
927  ar & boost::serialization::make_nvp( "map_nodal_scalar_size", s );
928  DVLOG(2) << "(saving) serialized size of nodal scalar (" << s << ")\n";
929  nodal_scalar_const_iterator __itscalar = M_nodal_scalar.begin();
930  nodal_scalar_const_iterator __enscalar = M_nodal_scalar.end();
931 
932  for ( ; __itscalar != __enscalar; ++__itscalar )
933  {
934  ar & ( nodal_scalar_type const& ) __itscalar->second;
935  }
936 
937  s = M_nodal_vector.size();
938  ar & boost::serialization::make_nvp( "map_nodal_vector_size", s );
939 
940  nodal_vector_const_iterator __itvector= M_nodal_vector.begin();
941  nodal_vector_const_iterator __envector= M_nodal_vector.end();
942 
943  for ( ; __itvector!= __envector; ++__itvector )
944  {
945  ar & ( nodal_vector_type const& ) __itvector->second;
946  }
947 
948  s = M_nodal_tensor2.size();
949  ar & boost::serialization::make_nvp( "map_nodal_tensor2_size", s );
950 
951  nodal_tensor2_const_iterator __ittensor2= M_nodal_tensor2.begin();
952  nodal_tensor2_const_iterator __entensor2= M_nodal_tensor2.end();
953 
954  for ( ; __ittensor2!= __entensor2; ++__ittensor2 )
955  {
956  ar & ( nodal_tensor2_type const& ) __ittensor2->second;
957  }
958 
959  s = M_element_scalar.size();
960  ar & boost::serialization::make_nvp( "map_element_scalar_size", s );
961  DVLOG(2) << "(saving) serialized size of element scalar (" << s << ")\n";
962  element_scalar_const_iterator __eitscalar = M_element_scalar.begin();
963  element_scalar_const_iterator __eenscalar = M_element_scalar.end();
964 
965  for ( ; __eitscalar != __eenscalar; ++__eitscalar )
966  {
967  ar & ( element_scalar_type const& ) __eitscalar->second;
968  }
969 
970  s = M_element_vector.size();
971  ar & boost::serialization::make_nvp( "map_element_vector_size", s );
972 
973  element_vector_const_iterator __eitvector= M_element_vector.begin();
974  element_vector_const_iterator __eenvector= M_element_vector.end();
975 
976  for ( ; __eitvector!= __eenvector; ++__eitvector )
977  {
978  ar & ( element_vector_type const& ) __eitvector->second;
979  }
980 
981  s = M_element_tensor2.size();
982  ar & boost::serialization::make_nvp( "map_element_tensor2_size", s );
983 
984  element_tensor2_const_iterator __eittensor2= M_element_tensor2.begin();
985  element_tensor2_const_iterator __eentensor2= M_element_tensor2.end();
986 
987  for ( ; __eittensor2!= __eentensor2; ++__eittensor2 )
988  {
989  ar & ( element_tensor2_type const& ) __eittensor2->second;
990  }
991  }
992 
993  template<class Archive>
994  void load( Archive & ar, const unsigned int /*version*/ )
995  {
996 
997  // loading
998  size_type s( 0 );
999 
1000  ar & boost::serialization::make_nvp( "map_scalar_size", s );
1001  DVLOG(2) << "(loading) serialized size of scalar (" << s << ")\n";
1002 
1003  for ( size_type __i = 0; __i < s; ++__i )
1004  {
1005  std::pair<std::string, std::pair<scalar_type,bool> > v;
1006  ar & v;
1007 
1008  DVLOG(2) << "(loading) dserialized scalar " << v.first
1009  << " with value " << v.second.first << "\n";
1010 
1011  std::pair<scalar_iterator,bool> __it = M_scalar.insert( v );
1012 
1013  if ( __it.second )
1014  DVLOG(2) << v.first << " loaded and inserted (value: " << v.second.first << ")\n";
1015 
1016  else
1017  DVLOG(2) << v.first << " was loaded but not inserted (value: " << v.second.first << ")\n";
1018  }
1019 
1020  ar & boost::serialization::make_nvp( "map_complex_size", s );
1021  DVLOG(2) << "(loading) serialized size of complex (" << s << ")\n";
1022 
1023  for ( size_type __i = 0; __i < s; ++__i )
1024  {
1025  std::pair<std::string, std::pair<complex_type,bool> > v;
1026  scalar_type v_real;
1027  scalar_type v_imag;
1028 
1029  ar & boost::serialization::make_nvp( "complex", v.first );
1030  ar & boost::serialization::make_nvp( "real", v_real );
1031  ar & boost::serialization::make_nvp( "imaginary", v_imag );
1032 
1033  v.second.first = complex_type( v_real, v_imag );
1034 
1035  // DVLOG(2) << "(loading) dserialized complex " << v.first
1036  // << " with value " << v.second << "\n";
1037 
1038  std::pair<complex_iterator,bool> __it = M_complex.insert( v );
1039 
1040  if ( __it.second )
1041  DVLOG(2) << v.first << " loaded and inserted\n";
1042 
1043  else
1044  DVLOG(2) << v.first << " was loaded but not inserted\n";
1045  }
1046 
1047  // nodal scalar
1048  s = 0;
1049  ar & boost::serialization::make_nvp( "map_nodal_scalar_size", s );
1050  DVLOG(2) << "(loading) serialized size of nodal scalar (" << s << ")\n";
1051 
1052  for ( size_type __i = 0; __i < s; ++__i )
1053  {
1054  nodal_scalar_type v;
1055  ar & v;
1056 
1057  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1058  << " of size " << v.size() << "\n";
1059 
1060  std::pair<nodal_scalar_iterator,bool> __it = M_nodal_scalar.insert( std::make_pair( v.name(), v ) );
1061 
1062  if ( __it.second )
1063  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1064 
1065  else
1066  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1067  }
1068 
1069  s = 0;
1070  ar & boost::serialization::make_nvp( "map_nodal_vector_size", s );
1071  DVLOG(2) << "(loading) serialized size of nodal scalar (" << s << ")\n";
1072 
1073  for ( size_type __i = 0; __i < s; ++__i )
1074  {
1075  nodal_vector_type v;
1076  ar & v;
1077 
1078  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1079  << " of size " << v.size() << "\n";
1080 
1081  std::pair<nodal_vector_iterator,bool> __it = M_nodal_vector.insert( std::make_pair( v.name(), v ) );
1082 
1083  if ( __it.second )
1084  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1085 
1086  else
1087  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1088  }
1089 
1090  s = 0;
1091  ar & boost::serialization::make_nvp( "map_nodal_tensor2_size", s );
1092  DVLOG(2) << "(loading) serialized size of nodal scalar (" << s << ")\n";
1093 
1094  for ( size_type __i = 0; __i < s; ++__i )
1095  {
1096  nodal_tensor2_type v;
1097  ar & v;
1098 
1099  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1100  << " of size " << v.size() << "\n";
1101 
1102  std::pair<nodal_tensor2_iterator,bool> __it = M_nodal_tensor2.insert( std::make_pair( v.name(), v ) );
1103 
1104  if ( __it.second )
1105  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1106 
1107  else
1108  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1109  }
1110 
1111  // element scalar
1112  s = 0;
1113  ar & boost::serialization::make_nvp( "map_element_scalar_size", s );
1114  DVLOG(2) << "(loading) serialized size of element scalar (" << s << ")\n";
1115 
1116  for ( size_type __i = 0; __i < s; ++__i )
1117  {
1118  element_scalar_type v;
1119  ar & v;
1120 
1121  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1122  << " of size " << v.size() << "\n";
1123 
1124  std::pair<element_scalar_iterator,bool> __it = M_element_scalar.insert( std::make_pair( v.name(), v ) );
1125 
1126  if ( __it.second )
1127  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1128 
1129  else
1130  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1131  }
1132 
1133  s = 0;
1134  ar & boost::serialization::make_nvp( "map_element_vector_size", s );
1135  DVLOG(2) << "(loading) serialized size of element scalar (" << s << ")\n";
1136 
1137  for ( size_type __i = 0; __i < s; ++__i )
1138  {
1139  element_vector_type v;
1140  ar & v;
1141 
1142  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1143  << " of size " << v.size() << "\n";
1144 
1145  std::pair<element_vector_iterator,bool> __it = M_element_vector.insert( std::make_pair( v.name(), v ) );
1146 
1147  if ( __it.second )
1148  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1149 
1150  else
1151  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1152  }
1153 
1154  s = 0;
1155  ar & boost::serialization::make_nvp( "map_element_tensor2_size", s );
1156  DVLOG(2) << "(loading) serialized size of element scalar (" << s << ")\n";
1157 
1158  for ( size_type __i = 0; __i < s; ++__i )
1159  {
1160  element_tensor2_type v;
1161  ar & v;
1162 
1163  DVLOG(2) << "(loading) dserialized scalar field " << v.name()
1164  << " of size " << v.size() << "\n";
1165 
1166  std::pair<element_tensor2_iterator,bool> __it = M_element_tensor2.insert( std::make_pair( v.name(), v ) );
1167 
1168  if ( __it.second )
1169  DVLOG(2) << v.name() << " loaded and inserted (size: " << v.size() << ")\n";
1170 
1171  else
1172  DVLOG(2) << v.name() << " was loaded but not inserted (size: " << v.size() << ")\n";
1173  }
1174  }
1175 
1176  template<class Archive>
1177  void serialize( Archive & ar, const unsigned int file_version )
1178  {
1179  boost::serialization::split_member( ar, *this, file_version );
1180  }
1181 
1186  void executeState( size_type state );
1187 
1188  private:
1189 
1190  TimeSet* M_ts;
1191 
1195  Real M_time;
1196 
1200  size_type M_index;
1201 
1202  boost::optional<mesh_ptrtype> M_mesh;
1203 
1204  map_scalar_type M_scalar;
1205  map_complex_type M_complex;
1206  map_nodal_scalar_type M_nodal_scalar;
1207  map_nodal_vector_type M_nodal_vector;
1208  map_nodal_tensor2_type M_nodal_tensor2;
1209  map_element_scalar_type M_element_scalar;
1210  map_element_vector_type M_element_vector;
1211  map_element_tensor2_type M_element_tensor2;
1212 
1213  Context M_state;
1214 
1215 
1216  scalar_p0_space_ptrtype M_scalar_p0;
1217  vector_p0_space_ptrtype M_vector_p0;
1218  tensor2_p0_space_ptrtype M_tensor2_p0;
1219  scalar_p1_space_ptrtype M_scalar_p1;
1220  vector_p1_space_ptrtype M_vector_p1;
1221  tensor2_p1_space_ptrtype M_tensor2_p1;
1222 
1223 
1224  };
1225 
1226  struct ltstep
1227  {
1228  bool operator()( boost::shared_ptr<Step> const& s1,
1229  boost::shared_ptr<Step> const& s2 ) const
1230  {
1231  return *s1 < *s2;
1232  }
1233  };
1234 
1238 
1239  typedef Step step_type;
1240  typedef boost::shared_ptr<Step> step_ptrtype;
1241  typedef std::set<step_ptrtype,ltstep> step_set_type;
1242  typedef typename step_set_type::iterator step_iterator;
1243  typedef typename step_set_type::const_iterator step_const_iterator;
1244  typedef typename step_set_type::reverse_iterator step_reverse_iterator;
1245  typedef typename step_set_type::const_reverse_iterator step_const_reverse_iterator;
1247 
1248 
1249 
1250 
1252 
1256 
1263  TimeSet( std::string filename = "undefined", bool init = false );
1264  TimeSet( TimeSet const & );
1265  ~TimeSet();
1266 
1268 
1272 
1273  TimeSet& operator=( TimeSet const& );
1274 
1276 
1280 
1284  std::string const& name() const
1285  {
1286  return M_name;
1287  }
1288 
1292  uint32_type index() const
1293  {
1294  return M_index;
1295  }
1296 
1301  {
1302  return M_step_set.size();
1303  }
1304 
1309  {
1310  return M_stepIgnored_set.size();
1311  }
1312 
1316  size_type numberOfSteps( mpl::bool_<false> ) const
1317  {
1318  return M_step_set.size();
1319  }
1320 
1324  size_type numberOfSteps( mpl::bool_<true> ) const
1325  {
1326  return M_stepIgnored_set.size();
1327  }
1328 
1333  {
1334  return M_step_set.size()+M_stepIgnored_set.size();
1335  }
1336 
1340  Real timeIncrement() const
1341  {
1342  return M_time_increment;
1343  }
1344 
1348  //step_set_type & step_set( mpl::bool_<false> /**/ ) { return M_step_set; }
1349 
1353  //step_set_type & step_set( mpl::bool_<true> /**/ ) { return M_stepIgnored_set; }
1354 
1356 
1360 
1364  void setTimeIncrement( Real __incr )
1365  {
1366  M_time_increment = __incr;
1367  }
1368 
1369 
1370  void setNumberOfStepsInMemory( uint16_type __i )
1371  {
1372  M_keep_steps = __i;
1373  }
1374 
1376 
1380 
1386  step_ptrtype step( Real __time, bool __ignoreStep=false )
1387  {
1388  if ( __ignoreStep )
1389  return step< mpl::bool_<true> >( __time );
1390 
1391  else
1392  return step< mpl::bool_<false> >( __time );
1393  }
1394 
1395  template <typename IgnoreStepType>
1396  step_ptrtype step( Real __time );
1397 
1398 
1399  step_iterator beginStep()
1400  {
1401  return M_step_set.begin();
1402  }
1403  step_const_iterator beginStep() const
1404  {
1405  return M_step_set.begin();
1406  }
1407 
1408  step_reverse_iterator rbeginStep()
1409  {
1410  return M_step_set.rbegin();
1411  }
1412  step_const_reverse_iterator rbeginStep() const
1413  {
1414  return M_step_set.rbegin();
1415  }
1416 
1417  step_iterator endStep()
1418  {
1419  return M_step_set.end();
1420  }
1421  step_const_iterator endStep() const
1422  {
1423  return M_step_set.end();
1424  }
1425 
1426  step_reverse_iterator rendStep()
1427  {
1428  return M_step_set.rend();
1429  }
1430  step_const_reverse_iterator rendStep() const
1431  {
1432  return M_step_set.rend();
1433  }
1434 
1435 
1436  step_iterator beginStep( mpl::bool_<false> )
1437  {
1438  return M_step_set.begin();
1439  }
1440  step_const_iterator beginStep( mpl::bool_<false> ) const
1441  {
1442  return M_step_set.begin();
1443  }
1444  step_iterator endStep( mpl::bool_<false> )
1445  {
1446  return M_step_set.end();
1447  }
1448  step_const_iterator endStep( mpl::bool_<false> ) const
1449  {
1450  return M_step_set.end();
1451  }
1452 
1453  step_iterator beginStep( mpl::bool_<true> )
1454  {
1455  return M_stepIgnored_set.begin();
1456  }
1457  step_const_iterator beginStep( mpl::bool_<true> ) const
1458  {
1459  return M_stepIgnored_set.begin();
1460  }
1461  step_iterator endStep( mpl::bool_<true> )
1462  {
1463  return M_stepIgnored_set.end();
1464  }
1465  step_const_iterator endStep( mpl::bool_<true> ) const
1466  {
1467  return M_stepIgnored_set.end();
1468  }
1469 
1470  std::pair<step_iterator,bool> insertStep( step_ptrtype __step, mpl::bool_<false> )
1471  {
1472  return M_step_set.insert( __step );
1473  }
1474  std::pair<step_iterator,bool> insertStep( step_ptrtype __step, mpl::bool_<true> )
1475  {
1476  return M_stepIgnored_set.insert( __step );
1477  }
1478 
1479  void clear()
1480  {
1481  M_step_set.clear();
1482  M_stepIgnored_set.clear();
1483  }
1484 
1485  void load( std::string _nameFile, Real __time )
1486  {
1487  fs::ifstream ifs( _nameFile );
1488  // load data from archive
1489  boost::archive::text_iarchive ia( ifs );
1490  ia >> *this;
1491 
1492  resetPreviousTime( __time );
1493  }
1494 
1495  void save( std::string _nameFile )
1496  {
1497  setNumberOfStepsInMemory( 0 );
1498  cleanup();
1499  setNumberOfStepsInMemory( 1 );
1500 
1501  fs::ofstream ofs( _nameFile );
1502  // save data from archive
1503  boost::archive::text_oarchive oa( ofs );
1504  oa << *this;
1505  }
1506 
1507 
1509 
1510 protected:
1511 
1515  std::string M_name;
1516 
1520  uint32_type M_index;
1521 
1525  step_set_type M_step_set;
1526 
1530  step_set_type M_stepIgnored_set;
1531 
1536 
1537  uint16_type M_keep_steps;
1538 private:
1539 
1540  friend class boost::serialization::access;
1541 
1542  template<class Archive>
1543  void serialize( Archive & ar, const unsigned int /*version*/ )
1544  {
1545  ar & boost::serialization::make_nvp( "name", M_name );
1546  ar & boost::serialization::make_nvp( "index", M_index );
1547  ar & boost::serialization::make_nvp( "time_increment", M_time_increment );
1548  ar & boost::serialization::make_nvp( "keep_steps", M_keep_steps );
1549 
1550  if ( Archive::is_saving::value )
1551  {
1552  size_type s = M_step_set.size();
1553  ar & boost::serialization::make_nvp( "number_of_steps", s );
1554  size_type s2 = M_stepIgnored_set.size();
1555  ar & boost::serialization::make_nvp( "number_of_steps_ignored", s2 );
1556 
1557  step_iterator __it = M_step_set.begin();
1558  step_iterator __en = M_step_set.end();
1559 
1560  for ( ; __it != __en; ++__it )
1561  {
1562  if ( !( *__it )->isOnDisk() )
1563  {
1564  DVLOG(2) << "not including step " << ( *__it )->index()
1565  << " at time " << ( *__it )->time() << "\n";
1566  ( *__it )->showMe( "TimeSet::serialize" );
1567  continue;
1568  }
1569 
1570  double t = ( *__it )->time();
1571  ar & boost::serialization::make_nvp( "time", t );
1572  size_type ind = ( *__it )->index();
1573  ar & boost::serialization::make_nvp( "index", ind );
1574  size_type state = ( *__it )->state();
1575  ar & boost::serialization::make_nvp( "state", state );
1576  }
1577 
1578  __it = M_stepIgnored_set.begin();
1579  __en = M_stepIgnored_set.end();
1580 
1581  for ( ; __it != __en; ++__it )
1582  {
1583  if ( !( *__it )->isOnDisk() )
1584  {
1585  DVLOG(2) << "not including step " << ( *__it )->index()
1586  << " at time " << ( *__it )->time() << "\n";
1587  ( *__it )->showMe( "TimeSet::serialize" );
1588  continue;
1589  }
1590 
1591  double t = ( *__it )->time();
1592  ar & boost::serialization::make_nvp( "time_ignored", t );
1593  size_type ind = ( *__it )->index();
1594  ar & boost::serialization::make_nvp( "index_ignored", ind );
1595  size_type state = ( *__it )->state();
1596  ar & boost::serialization::make_nvp( "state_ignored", state );
1597  }
1598  }
1599 
1600  if ( Archive::is_loading::value )
1601  {
1602  size_type s( 0 );
1603  ar & boost::serialization::make_nvp( "number_of_steps", s );
1604  size_type s2( 0 );
1605  ar & boost::serialization::make_nvp( "number_of_steps_ignored", s2 );
1606 
1607  for ( size_type __i = 0; __i < s; ++__i )
1608  {
1609  double t = 0;
1610  ar & boost::serialization::make_nvp( "time", t );
1611 
1612  size_type ind = 0;
1613  ar & boost::serialization::make_nvp( "index", ind );
1614 
1615  size_type __state = 0;
1616  ar & boost::serialization::make_nvp( "state", __state );
1617 
1618  step_iterator __sit;
1619  bool __inserted;
1620  boost::tie( __sit, __inserted ) = M_step_set.insert( step_ptrtype( new Step( this, t,ind, __state ) ) );
1621 
1622  FEELPP_ASSERT( __inserted )( t )( ind ).error ( "insertion failed" );
1623  }
1624 
1625  for ( size_type __i = 0; __i < s2; ++__i )
1626  {
1627  double t = 0;
1628  ar & boost::serialization::make_nvp( "time_ignored", t );
1629 
1630  size_type ind = 0;
1631  ar & boost::serialization::make_nvp( "index_ignored", ind );
1632 
1633  size_type __state = 0;
1634  ar & boost::serialization::make_nvp( "state_ignored", __state );
1635 
1636  step_iterator __sit;
1637  bool __inserted;
1638  boost::tie( __sit, __inserted ) = M_stepIgnored_set.insert( step_ptrtype( new Step( this, t,ind, __state ) ) );
1639 
1640  FEELPP_ASSERT( __inserted )( t )( ind ).error ( "insertion failed" );
1641  }
1642 
1643  }
1644  }
1645 
1647  void cleanup();
1648 
1650  void resetPreviousTime( Real __time );
1651 
1652 public:
1653  void setMesh( mesh_ptrtype m ) { M_mesh = m; }
1654  bool hasMesh() const { return M_mesh; }
1655  mesh_ptrtype mesh() const
1656  {
1657  DLOG_IF( WARNING, hasMesh() ) << "Time Set has no mesh data structure associated\n";
1658  return M_mesh.get();
1659  }
1660 
1661 
1662 public:
1663  boost::optional<mesh_ptrtype> M_mesh;
1664 
1665 
1666  scalar_p0_space_ptrtype M_scalar_p0;
1667  vector_p0_space_ptrtype M_vector_p0;
1668  tensor2_p0_space_ptrtype M_tensor2_p0;
1669  scalar_p1_space_ptrtype M_scalar_p1;
1670  vector_p1_space_ptrtype M_vector_p1;
1671  tensor2_p1_space_ptrtype M_tensor2_p1;
1672 private:
1673 
1677  static uint32_type _S_current_index;
1678 
1679 
1680 };
1681 template<typename MeshType, int N>
1682 inline FEELPP_EXPORT bool operator<( TimeSet<MeshType, N> const& __ts1, TimeSet<MeshType, N> const& __ts2 )
1683 {
1684  return __ts1.index() < __ts2.index();
1685 }
1686 
1687 template<typename MeshType, int N>
1688 inline FEELPP_EXPORT bool operator<( boost::shared_ptr<TimeSet<MeshType, N> > const& __ts1,
1689  boost::shared_ptr<TimeSet<MeshType, N> > const& __ts2 )
1690 {
1691  return __ts1->index() < __ts2->index();
1692 }
1693 
1694 template<typename MeshType, int N>
1695 FEELPP_NO_EXPORT bool operator<( typename TimeSet<MeshType, N>::step_type const& __s1,
1696  typename TimeSet<MeshType, N>::step_type const& __s2 )
1697 {
1698  //return __s1->index() < __s2->index();
1699  return __s1->time() < __s2->time();
1700 }
1701 
1702 template<typename MeshType, int N>
1703 FEELPP_NO_EXPORT bool operator<( typename TimeSet<MeshType, N>::step_ptrtype const& __s1,
1704  typename TimeSet<MeshType, N>::step_ptrtype const& __s2 )
1705 {
1706  return __s1->index() < __s2->index();
1707 }
1708 
1709 template<typename MeshType, int N>
1710 TimeSet<MeshType, N>::TimeSet( std::string __name, bool init )
1711  :
1712  M_name( __name ),
1713  M_index( _S_current_index++ ),
1714  M_time_increment( 0.1 ),
1715  M_keep_steps( 1 )
1716 {
1717  std::ostringstream __str;
1718  __str << M_name << ".ts";
1719 
1720  if ( fs::exists( __str.str() ) && !init )
1721  {
1722 #if 0
1723  std::ifstream ifs( __str.str().c_str() );
1724  boost::archive::binary_iarchive ia( ifs );
1725 
1726  ia >> *this;
1727 
1728  ifs.close();
1729 #endif
1730  }
1731 
1732  else if ( fs::exists( __str.str() ) )
1733  fs::remove( __str.str() );
1734 }
1735 
1736 template<typename MeshType, int N>
1738  :
1739  M_name( __ts.M_name ),
1740  M_index( __ts.M_index ),
1741  M_time_increment( __ts.M_time_increment ),
1742  M_keep_steps( __ts.M_keep_steps )
1743 {
1744 }
1745 
1746 template<typename MeshType, int N>
1747 TimeSet<MeshType, N>::~TimeSet()
1748 {
1749 #if 0
1750  step_iterator __it = M_step_set.begin();
1751  step_iterator __en = M_step_set.end();
1752 
1753  for ( ; __it != __en; ++__it )
1754  {
1755  ( *__it )->setState( STEP_ON_DISK );
1756  }
1757 
1758 
1759  // FIXME: saving the timeset is disabled for now
1760 
1761  std::ostringstream __str;
1762  __str << M_name << ".ts";
1763 
1764  std::ofstream ofs( __str.str().c_str() );
1765 
1766  if ( !ofs.fail() )
1767  {
1768  boost::archive::binary_oarchive oa( ofs );
1769 
1770  oa << const_cast<TimeSet<MeshType, N>const&>( *this );
1771 
1772  ofs.close();
1773  }
1774 
1775 #endif
1776 
1777  --_S_current_index;
1778 
1779 
1780 }
1781 
1782 template<typename MeshType, int N>
1783 TimeSet<MeshType, N>&
1784 TimeSet<MeshType, N>::operator=( TimeSet const& __ts )
1785 {
1786  if ( this != &__ts )
1787  {
1788  M_name = __ts.M_name;
1789  M_index = __ts.M_index;
1790  M_time_increment = __ts.M_time_increment;
1791  }
1792 
1793  return *this;
1794 }
1795 
1796 template<typename MeshType, int N>
1797 void
1798 TimeSet<MeshType, N>::cleanup()
1799 {
1800  step_iterator __it = M_step_set.begin();
1801  step_iterator __en = M_step_set.end();
1802 
1803  for ( ; __it != __en; ++__it )
1804  {
1805  if ( ( *__it )->index() <= M_step_set.size() - M_keep_steps )
1806  ( *__it )->setState( STEP_ON_DISK );
1807  }
1808 
1809  __it = M_stepIgnored_set.begin();
1810  __en = M_stepIgnored_set.end();
1811 
1812  for ( ; __it != __en; ++__it )
1813  {
1814  if ( ( *__it )->index() <= M_stepIgnored_set.size() - M_keep_steps )
1815  ( *__it )->setState( STEP_ON_DISK );
1816  }
1817 
1818 
1819 #if 0
1820  std::ostringstream __str;
1821  __str << M_name << ".ts";
1822 
1823  std::ofstream ofs( __str.str().c_str() );
1824 
1825  if ( !ofs.fail() )
1826  {
1827  boost::archive::binary_oarchive oa( ofs );
1828 
1829  oa << const_cast<TimeSet<MeshType, N>const&>( *this );
1830 
1831  ofs.close();
1832  }
1833 
1834 #endif
1835 }
1836 
1837 template<typename MeshType, int N>
1838 void
1839 TimeSet<MeshType, N>::resetPreviousTime( Real __time )
1840 {
1841  step_iterator __it = M_step_set.begin();
1842  step_iterator __en = M_step_set.end();
1843  bool find=false;
1844 
1845  while ( !find && __it != __en )
1846  {
1847  if ( !( *__it )->isOnDisk() )
1848  {
1849  DVLOG(2) << "not including step " << ( *__it )->index()
1850  << " at time " << ( *__it )->time() << "\n";
1851  ( *__it )->showMe( "TimeSet::resetPreviousTime" );
1852  ++__it;
1853  }
1854 
1855  else
1856  {
1857  double t = ( *__it )->time();
1858  double eps = 1e-10;
1859 
1860  if ( ( t-eps ) <= __time ) ++__it;
1861 
1862  else find=true;
1863  }
1864  }
1865 
1866  if ( find ) M_step_set.erase( __it,__en );
1867 
1868  __it = M_stepIgnored_set.begin();
1869  __en = M_stepIgnored_set.end();
1870  find=false;
1871 
1872  while ( !find && __it != __en )
1873  {
1874  if ( !( *__it )->isOnDisk() )
1875  {
1876  DVLOG(2) << "not including step " << ( *__it )->index()
1877  << " at time " << ( *__it )->time() << "\n";
1878  ( *__it )->showMe( "TimeSet::resetPreviousTime" );
1879  ++__it;
1880  }
1881 
1882  else
1883  {
1884  double t = ( *__it )->time();
1885  double eps = 1e-10;
1886 
1887  if ( ( t-eps ) <= __time ) ++__it;
1888 
1889  else find=true;
1890  }
1891  }
1892 
1893  if ( find ) M_stepIgnored_set.erase( __it,__en );
1894 
1895 }
1896 
1897 
1898 template<typename MeshType, int N>
1899 template <typename IgnoreStepType>
1900 typename TimeSet<MeshType, N>::step_ptrtype
1901 TimeSet<MeshType, N>::step( Real __time )
1902 {
1903  namespace lambda = boost::lambda;
1904  /*
1905  step_iterator __sit = std::find_if( M_step_set.begin(), M_step_set.end(),
1906  lambda::bind( &Step::time, lambda::_1 ) - __time < 1e-10 &&
1907  lambda::bind( &Step::time, lambda::_1 ) - __time > -1e-10 );
1908  */
1909  step_iterator __sit = beginStep( mpl::bool_<IgnoreStepType::value>() );
1910 
1911  for ( ; __sit != endStep( mpl::bool_<IgnoreStepType::value>() ); ++__sit )
1912  {
1913  if ( math::abs( ( *__sit )->time() - __time ) < 1e-10 )
1914  break;
1915  }
1916 
1917  if ( __sit == endStep( mpl::bool_<IgnoreStepType::value>() ) )
1918  {
1919  bool __inserted;
1920 
1921  DVLOG(2) << "[TimeSet<MeshType, N>::step] Inserting new step at time " << __time << " with index "
1922  << numberOfSteps( mpl::bool_<IgnoreStepType::value>() ) << "\n";
1923 
1924  step_ptrtype thestep( new Step( this, __time, numberOfSteps( mpl::bool_<IgnoreStepType::value>() ) + 1 ) );
1925  if ( this->hasMesh() )
1926  thestep->setMesh( this->mesh() );
1927  boost::tie( __sit, __inserted ) = insertStep( thestep,mpl::bool_<IgnoreStepType::value>() );
1928 
1929  //boost::tie( __sit, __inserted ) = M_step_set.insert( step_ptrtype( new Step( this, __time,
1930  // M_step_set.size() + 1 ) ) );
1931 
1932  DVLOG(2) << "[TimeSet<MeshType, N>::step] step was inserted properly? " << ( __inserted?"yes":"no" ) << "\n";
1933  DVLOG(2) << "[TimeSet<MeshType, N>::step] step index : " << ( *__sit )->index() << " time : " << ( *__sit )->time() << "\n";
1934  namespace lambda = boost::lambda;
1935  //std::cerr << "time values:";
1936  //std::for_each( M_step_set.begin(), M_step_set.end(),
1937  // std::cerr << lambda::bind( &step_type::time, *lambda::_1 ) << boost::lambda::constant( ' ' ) );
1938  //std::cerr << "\n";
1939 
1940  cleanup();
1941  }
1942 
1943  else
1944  {
1945  DVLOG(2) << "[TimeSet<MeshType, N>::step] found step at time " << __time << " with index "
1946  << ( *__sit )->index() << "\n";
1947  ( *__sit )->showMe( "TimesSet::step(t)" );
1948  }
1949 
1950  return *__sit;
1951 }
1952 
1953 template<typename MeshType, int N>
1954 uint32_type TimeSet<MeshType, N>::_S_current_index = 1;
1955 
1956 //
1957 // TimeSet<MeshType, N>::Step
1958 //
1959 
1960 template<typename MeshType, int N>
1961 TimeSet<MeshType, N>::Step::Step()
1962  :
1963  M_time( 0 ),
1964  M_index( 0 ),
1965  M_state( STEP_NEW|STEP_OVERWRITE )
1966 {
1967 }
1968 
1969 template<typename MeshType, int N>
1970 TimeSet<MeshType, N>::Step::Step( TimeSet* ts, Real __t, size_type __index, size_type __state )
1971  :
1972  M_ts( ts ),
1973  M_time( __t ),
1974  M_index( __index ),
1975  M_state( __state )
1976 {
1977  showMe( "Step::Step()" );
1978 }
1979 
1980 template<typename MeshType, int N>
1981 TimeSet<MeshType, N>::Step::Step( Step const& __step )
1982  :
1983  M_time( __step.M_time ),
1984  M_index( __step.M_index ),
1985  M_state( __step.M_state )
1986 {
1987 }
1988 
1989 template<typename MeshType, int N>
1991 {
1992  this->setState( STEP_ON_DISK );
1993  showMe( "Step::~Step()" );
1994 }
1995 
1996 template<typename MeshType, int N>
1997 void
1999 {
2000  Context __state( __st );
2001  DVLOG(2) << "executeState: isOnDisk() : " << __state.test( STEP_ON_DISK ) << "\n";
2002  DVLOG(2) << "executeState: isInMemory() : " << __state.test( STEP_IN_MEMORY ) << "\n";
2003 
2004  if ( hasData() && isInMemory() && __state.test( STEP_ON_DISK ) )
2005  {
2006 #if 0
2007  DVLOG(2) << "saving step " << this->index() << " at time " << this->time() << " on disk\n";
2008  std::ostringstream __str;
2009  __str << "step-" << this->index();
2010 
2011  if ( !fs::exists( __str.str() ) || M_state.test( STEP_OVERWRITE ) )
2012  {
2013  std::ofstream ofs( __str.str().c_str() );
2014  boost::archive::binary_oarchive oa( ofs );
2015 
2016  oa << const_cast<typename TimeSet<MeshType, N>::Step const&>( *this );
2017 
2018  ofs.close();
2019  }
2020 
2021 #endif
2022 
2023  if ( hasData() )
2024  {
2025  DVLOG(2) << "releasing step " << M_index << " at time " << M_time << " allocated memory for this step\n";
2026 
2027  {
2028  nodal_scalar_iterator __itscalar = M_nodal_scalar.begin();
2029  nodal_scalar_iterator __enscalar = M_nodal_scalar.end();
2030 
2031  for ( ; __itscalar != __enscalar; ++__itscalar )
2032  {
2033  __itscalar->second.clear();
2034  }
2035 
2036  nodal_vector_iterator __itvector= M_nodal_vector.begin();
2037  nodal_vector_iterator __envector= M_nodal_vector.end();
2038 
2039  for ( ; __itvector!= __envector; ++__itvector )
2040  {
2041  __itvector->second.clear();
2042  }
2043 
2044  nodal_tensor2_iterator __ittensor2= M_nodal_tensor2.begin();
2045  nodal_tensor2_iterator __entensor2= M_nodal_tensor2.end();
2046 
2047  for ( ; __ittensor2!= __entensor2; ++__ittensor2 )
2048  {
2049  __ittensor2->second.clear();
2050  }
2051  }
2052  {
2053  element_scalar_iterator __itscalar = M_element_scalar.begin();
2054  element_scalar_iterator __enscalar = M_element_scalar.end();
2055 
2056  for ( ; __itscalar != __enscalar; ++__itscalar )
2057  {
2058  __itscalar->second.clear();
2059  }
2060 
2061  element_vector_iterator __itvector= M_element_vector.begin();
2062  element_vector_iterator __envector= M_element_vector.end();
2063 
2064  for ( ; __itvector!= __envector; ++__itvector )
2065  {
2066  __itvector->second.clear();
2067  }
2068 
2069  element_tensor2_iterator __ittensor2= M_element_tensor2.begin();
2070  element_tensor2_iterator __entensor2= M_element_tensor2.end();
2071 
2072  for ( ; __ittensor2!= __entensor2; ++__ittensor2 )
2073  {
2074  __ittensor2->second.clear();
2075  }
2076  }
2077  M_state.clear( STEP_IN_MEMORY );
2078  }
2079 
2080  M_state.set( STEP_ON_DISK );
2081  }
2082 
2083  if ( hasData() && isOnDisk() && __state.test( STEP_IN_MEMORY ) )
2084  {
2085  DVLOG(2) << "loading step " << this->index() << " at time " << this->time() << " in memory\n";
2086 #if 0
2087  std::ostringstream __str;
2088  __str << "step-" << this->index();
2089 
2090  if ( fs::exists( __str.str() ) )
2091  {
2092  std::ifstream ifs( __str.str().c_str() );
2093  boost::archive::binary_iarchive ia( ifs );
2094 
2095  ia >> *this;
2096 
2097  ifs.close();
2098  }
2099 
2100 #endif
2101  M_state.set( STEP_IN_MEMORY|STEP_HAS_DATA );
2102  M_state.clear( STEP_ON_DISK );
2103  }
2104 }
2105 
2106 }
2107 #endif /* __TimeSet_H */
nodal_vector_type nodalVector(std::string const &__n) const
Definition: timeset.hpp:339
bool hasMesh() const
Definition: timeset.hpp:276
size_type numberOfSteps(mpl::bool_< false >) const
Definition: timeset.hpp:1316
bool isInMemory() const
Definition: timeset.hpp:243
mesh_ptrtype mesh()
Definition: timeset.hpp:284
size_type numberOfSteps(mpl::bool_< true >) const
Definition: timeset.hpp:1324
element_vector_type elementVector(std::string const &__n) const
Definition: timeset.hpp:390
std::string const & name() const
Definition: timeset.hpp:1284
friend class TimeSet
Definition: timeset.hpp:856
data TimeSet
Definition: timeset.hpp:90
step_set_type M_stepIgnored_set
Definition: timeset.hpp:1530
size_type numberOfStepsIgnored() const
Definition: timeset.hpp:1308
size_type index() const
Definition: timeset.hpp:268
step_set_type M_step_set
Definition: timeset.hpp:1525
std::string M_name
Definition: timeset.hpp:1515
scalar_const_iterator beginScalar() const
Definition: timeset.hpp:292
Real M_time_increment
Definition: timeset.hpp:1535
bool hasData() const
Definition: timeset.hpp:225
scalar_type scalar(std::string const &__n) const
Definition: timeset.hpp:304
size_type numberOfSteps() const
Definition: timeset.hpp:1300
FEELPP_NO_EXPORT ~Step()
Definition: timeset.hpp:1990
static pointer_type New(mesh_ptrtype const &__m, std::vector< Dof > const &dofindices)
Definition: functionspace.hpp:3241
TimeSet(std::string filename="undefined", bool init=false)
Definition: timeset.hpp:1710
nodal_scalar_type nodalScalar(std::string const &__n) const
Definition: timeset.hpp:322
Definition: functionspace.hpp:1374
size_type state() const
Definition: timeset.hpp:252
a step in a time set
Definition: timeset.hpp:126
nodal_tensor2_type nodalTensor2(std::string const &__n) const
Definition: timeset.hpp:356
#define FEELPP_NO_EXPORT
Definition: feelmacros.hpp:217
size_type context() const
Definition: feelcore/context.hpp:150
Real time() const
Definition: timeset.hpp:260
Real timeIncrement() const
Definition: timeset.hpp:1340
bool isNew() const
Definition: timeset.hpp:216
step_ptrtype step(Real __time, bool __ignoreStep=false)
Definition: timeset.hpp:1386
size_t size_type
Indices (starting from 0)
Definition: feelcore/feel.hpp:319
element_tensor2_type elementTensor2(std::string const &__n) const
Definition: timeset.hpp:407
uint32_type index() const
Definition: timeset.hpp:1292
element_scalar_type elementScalar(std::string const &__n) const
Definition: timeset.hpp:373
bool isOnDisk() const
Definition: timeset.hpp:234
Elements & operator=(Elements const &e)
Definition: elements.hpp:335
void setTimeIncrement(Real __incr)
Definition: timeset.hpp:1364
scalar_const_iterator endScalar() const
Definition: timeset.hpp:297
Context class.
Definition: feelcore/context.hpp:63
#define FEELPP_EXPORT
Load time improvements for DSO libraries.
Definition: feelmacros.hpp:216
void interpolate(boost::shared_ptr< SpaceType > const &space, FunctionType const &f, typename SpaceType::element_type &interp, int same_mesh=INTERPOLATE_DIFFERENT_MESH)
Definition: interpolate.hpp:51
uint32_type M_index
Definition: timeset.hpp:1520
size_type numberOfTotalSteps() const
Definition: timeset.hpp:1332

Generated on Sun Dec 22 2013 13:11:15 for Feel++ by doxygen 1.8.5