37 #include <boost/timer.hpp>
38 #include <boost/shared_array.hpp>
39 #include <boost/lambda/lambda.hpp>
40 #include <boost/lambda/bind.hpp>
41 #include <boost/utility.hpp>
43 #include <boost/foreach.hpp>
44 #include <boost/filesystem.hpp>
45 #include <boost/filesystem/fstream.hpp>
46 #include <boost/serialization/vector.hpp>
47 #include <boost/serialization/array.hpp>
48 #include <boost/serialization/base_object.hpp>
49 #include <boost/archive/text_oarchive.hpp>
50 #include <boost/archive/text_iarchive.hpp>
51 #include <boost/archive/binary_oarchive.hpp>
52 #include <boost/archive/binary_iarchive.hpp>
54 #include <boost/numeric/ublas/vector.hpp>
55 #include <boost/numeric/ublas/vector_proxy.hpp>
57 #include <boost/parameter.hpp>
58 #include <feel/feelcore/parameter.hpp>
60 #include <feel/feelcore/feel.hpp>
62 #include <feel/feeldiscr/functionspace.hpp>
66 namespace ublas = boost::numeric::ublas;
67 namespace fs = boost::filesystem;
69 enum BDFState { BDF_UNITIALIZED = 0, BDF_RUNNING, BDF_STOPPED };
71 enum BDFTimeScheme { BDF_ORDER_ONE=1, BDF_ORDER_TWO, BDF_ORDER_THREE, BDF_ORDER_FOUR, BDF_MAX_ORDER = 4 };
72 enum BDFStragegy { BDF_STRATEGY_DT_CONSTANT,
73 BDF_STRATEGY_DT_ADAPTATIVE
78 friend class boost::serialization::access;
80 typedef std::vector<double>::iterator time_iterator;
81 typedef std::vector<double>::const_iterator time_const_iterator;
82 typedef std::vector<double> time_values_map_type;
94 M_strategy( BDF_STRATEGY_DT_CONSTANT ),
95 M_state( BDF_UNITIALIZED ),
99 M_restartAtLastSave( false ),
100 M_alpha( BDF_MAX_ORDER ),
101 M_beta( BDF_MAX_ORDER ),
102 M_saveInFile( true ),
104 M_rankProcInNameOfFiles( false ),
105 M_worldComm( Environment::worldComm() )
109 template <
class ArgumentPack>
110 BdfBase( ArgumentPack
const& args )
112 M_order( args[_order | 1] ),
113 M_name( args[_name |
"bdf"] ),
114 M_time( args[_initial_time | 0] ),
116 M_Ti( args[_initial_time | 0] ),
117 M_Tf( args[_final_time | 1] ),
118 M_dt( args[_time_step | 0.1] ),
119 M_iterations_between_order_change( 1 ),
120 M_strategy( ( BDFStragegy )args[_strategy | BDF_STRATEGY_DT_CONSTANT] ),
121 M_state( BDF_UNITIALIZED ),
123 M_restart( args[_restart | false] ),
124 M_restartPath( args[_restart_path |
""] ),
125 M_restartAtLastSave( args[_restart_at_last_save | false] )
126 M_alpha( BDF_MAX_ORDER ),
127 M_beta( BDF_MAX_ORDER ),
128 M_saveInFile( true ),
130 M_rankProcInNameOfFiles( false ),
131 M_worldComm( Environment::worldComm() )
136 BdfBase( po::variables_map
const& vm, std::string name, std::string
const& prefix, WorldComm
const& worldComm )
138 M_order( vm[prefixvm( prefix,
"bdf.order" )].as<int>() ),
139 M_order_cur( M_order ),
141 M_time( vm[prefixvm( prefix,
"bdf.time-initial" )].as<double>() ),
143 M_iterations_between_order_change( vm[prefixvm( prefix,
"bdf.iterations-between-order-change" )].as<int>() ),
144 M_Ti( vm[prefixvm( prefix,
"bdf.time-initial" )].as<double>() ),
145 M_Tf( vm[prefixvm( prefix,
"bdf.time-final" )].as<double>() ),
146 M_dt( vm[prefixvm( prefix,
"bdf.time-step" )].as<double>() ),
147 M_strategy( ( BDFStragegy )vm[prefixvm( prefix,
"bdf.strategy" )].as<int>() ),
148 M_state( BDF_UNITIALIZED ),
150 M_restart( vm[prefixvm( prefix,
"bdf.restart" )].as<bool>() ),
151 M_restartPath( vm[prefixvm( prefix,
"bdf.restart.path" )].as<std::string>() ),
152 M_restartAtLastSave( vm[prefixvm( prefix,
"bdf.restart.at-last-save" )].as<bool>() ),
153 M_alpha( BDF_MAX_ORDER ),
154 M_beta( BDF_MAX_ORDER ),
155 M_saveInFile( vm[prefixvm( prefix,
"bdf.save" )].as<bool>() ),
156 M_saveFreq( vm[prefixvm( prefix,
"bdf.save.freq" )].as<int>() ),
157 M_rankProcInNameOfFiles( vm[prefixvm( prefix,
"bdf.rank-proc-in-files-name" )].as<bool>() ),
158 M_worldComm( worldComm )
161 BdfBase( std::string name, WorldComm
const& worldComm )
168 M_iterations_between_order_change( 1 ),
172 M_strategy( ( BDFStragegy )0 ),
173 M_state( BDF_UNITIALIZED ),
177 M_restartAtLastSave( false ),
178 M_alpha( BDF_MAX_ORDER ),
179 M_beta( BDF_MAX_ORDER ),
180 M_saveInFile( true ),
182 M_worldComm( worldComm )
186 BdfBase( BdfBase
const& b )
188 M_order( b.M_order ),
189 M_order_cur( b.M_order_cur ),
192 M_iteration( b.M_iteration ),
193 M_iterations_between_order_change( b.M_iterations_between_order_change ),
197 M_strategy( b.M_strategy ),
198 M_state( b.M_state ),
199 M_n_restart( b.M_n_restart ),
200 M_restart( b.M_restart ),
201 M_restartPath( b.M_restartPath ),
202 M_restartAtLastSave( b.M_restartAtLastSave ),
203 M_time_values_map( b.M_time_values_map ),
204 M_alpha( b.M_alpha ),
206 M_saveInFile( b.M_saveInFile ),
207 M_saveFreq( b.M_saveFreq ),
208 M_rankProcInNameOfFiles( b.M_rankProcInNameOfFiles ),
209 M_worldComm( b.M_worldComm )
212 virtual ~BdfBase() {}
214 double polyCoefficient(
int i )
const
216 FEELPP_ASSERT( i >=0 && i < BDF_MAX_ORDER-1 ).error(
"[BDF] invalid index" );
217 return M_beta[this->timeOrder()-1][i];
219 double polyDerivCoefficient(
int i )
const
221 FEELPP_ASSERT( i >=0 && i <= BDF_MAX_ORDER ).error(
"[BDF] invalid index" );
222 return M_alpha[this->timeOrder()-1][i]/math::abs( this->timeStep() );
231 M_order_cur = b.M_order_cur;
234 M_iteration = b.M_iteration;
238 M_iterations_between_order_change = b.M_iterations_between_order_change;
239 M_n_restart = b.M_n_restart;
240 M_restart = b.M_restart;
241 M_restartPath = b.M_restartPath;
242 M_restartAtLastSave = b.M_restartAtLastSave;
243 M_strategy = b.M_strategy;
248 M_saveInFile = b.M_saveInFile;
249 M_rankProcInNameOfFiles = b.M_rankProcInNameOfFiles;
251 M_time_values_map = b.M_time_values_map;
252 M_worldComm = b.M_worldComm;
259 template<
class Archive>
260 void serialize( Archive & ar,
const unsigned int version )
262 DVLOG(2) <<
"[BDF::serialize] serialize BDFBase\n";
273 ar & boost::serialization::make_nvp(
"time_values", M_time_values_map );
275 DVLOG(2) <<
"[BDF::serialize] time orders size: " << M_time_orders.size() <<
"\n";
276 DVLOG(2) <<
"[BDF::serialize] time values size: " << M_time_values_map.size() <<
"\n";
278 for (
auto it = M_time_values_map.begin(), en = M_time_values_map.end(); it!=en; ++it )
281 DVLOG(2) <<
"[Bdf::serialize] value " << *it <<
"\n";
285 DVLOG(2) <<
"[BDF::serialize] serialize BDFBase done\n";
289 int timeOrder()
const
295 double timeInitial()
const
301 double timeFinal()
const
307 double timeStep()
const
313 BDFStragegy strategy()
const
319 int numberOfIterationsBetweenOrderChange()
const
321 return M_iterations_between_order_change;
325 int numberOfIterationsSinceOrderChange()
const
327 return M_iteration-M_last_iteration_since_order_change;
337 bool isRestart()
const
343 bool doRestartAtLastSave()
const
345 return M_restartAtLastSave;
355 int iteration()
const
361 double realTimePerIteration()
const
363 FEELPP_ASSERT( state() == BDF_RUNNING ).error(
"invalid BDF state" );
364 M_real_time_per_iteration = M_timer.elapsed();
365 return M_real_time_per_iteration;
369 time_values_map_type timeValues()
const
371 return M_time_values_map;
377 M_state = BDF_RUNNING;
380 M_time = M_Ti+this->timeStep();
382 M_last_iteration_since_order_change = 1;
390 M_state = BDF_RUNNING;
392 M_time = M_Ti+this->timeStep();
393 M_last_iteration_since_order_change = 1;
397 for (
int i = 2; i<=M_iteration; ++i )
399 if ( ( ( i - M_last_iteration_since_order_change ) == M_iterations_between_order_change )&&
400 M_order_cur < M_order )
402 M_last_iteration_since_order_change = i;
412 bool isFinished()
const
420 M_state = BDF_STOPPED;
429 M_state = BDF_STOPPED;
445 FEELPP_ASSERT( state() == BDF_RUNNING ).error(
"invalid BDF state" );
446 M_real_time_per_iteration = M_timer.elapsed();
451 if ( ( ( M_iteration - M_last_iteration_since_order_change ) == M_iterations_between_order_change )&&
452 M_order_cur < M_order )
454 M_last_iteration_since_order_change = M_iteration;
461 virtual void shiftRight()
464 std::ostringstream ostr;
466 if( M_rankProcInNameOfFiles )
467 ostr << M_name <<
"-" << M_iteration<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
469 ostr << M_name <<
"-" << M_iteration;
471 DVLOG(2) <<
"[BdfBase::shiftRight] solution name " << ostr.str() <<
"\n";
474 M_time_values_map.push_back( this->time() );
477 virtual void update()
479 double tn = M_time_values_map[M_iteration];
480 double tn1 = M_time_values_map[M_iteration-1];
483 if ( M_iteration >= 2 )
484 tn2 = M_time_values_map[M_iteration-2];
490 if ( M_iteration >= 3 )
491 tn3 = M_time_values_map[M_iteration-3];
495 for (
int i = 0; i < BDF_MAX_ORDER; ++i )
499 M_alpha[i][ 0 ] = 1./( tn-tn1 );
500 M_alpha[i][ 1 ] = 1./( tn-tn1 );
506 double denom = ( tn-tn1 )*( tn1-tn2 );
507 M_alpha[i][ 0 ] = 0.5*( tn1-2*tn2+tn )/denom;
508 M_alpha[i][ 1 ] = ( tn2-tn )/denom;
509 M_alpha[i][ 2 ] = 0.5/( tn1-tn2 );
510 M_beta[i][ 0 ] = 1+denom;
511 M_beta[i][ 1 ] = denom;
516 BDFState state()
const
526 fs::path restartPath()
528 return M_restartPath;
531 bool saveInFile()
const
541 bool rankProcInNameOfFiles()
const
543 return M_rankProcInNameOfFiles ;
546 WorldComm
const& worldComm()
const
551 void setOrder(
int order )
555 void setTimeInitial(
double ti )
559 void setTimeStep(
double dt )
563 void setTimeFinal(
double T )
567 void setStrategy(
int strategy )
569 M_strategy = ( BDFStragegy )strategy;
571 void setSteady(
bool steady =
true )
579 void setRestart(
bool doRestart )
583 void setRestartPath( std::string s )
587 void setRestartAtLastSave(
bool b )
589 M_restartAtLastSave=b;
591 void setSaveInFile(
bool b )
595 void setSaveFreq(
int v)
599 void setRankProcInNameOfFiles(
bool b )
601 M_rankProcInNameOfFiles = b;
606 LOG(INFO) <<
"============================================================\n";
607 LOG(INFO) <<
"BDF Information\n";
608 LOG(INFO) <<
" time step : " << this->timeStep() <<
"\n";
609 LOG(INFO) <<
"time initial : " << this->timeInitial() <<
"\n";
610 LOG(INFO) <<
" time final : " << this->timeFinal() <<
"\n";
611 LOG(INFO) <<
" time order : " << this->timeOrder() <<
"\n";
616 mutable int M_order_cur;
622 mutable double M_time;
623 mutable int M_iteration;
624 mutable int M_last_iteration_since_order_change;
625 int M_iterations_between_order_change;
637 BDFStragegy M_strategy;
640 mutable BDFState M_state;
648 fs::path M_restartPath;
651 bool M_restartAtLastSave;
654 mutable boost::timer M_timer;
657 mutable double M_real_time_per_iteration;
660 std::vector<int> M_time_orders;
663 time_values_map_type M_time_values_map;
666 fs::path M_path_save;
669 std::vector<ublas::vector<double> > M_alpha;
672 std::vector<ublas::vector<double> > M_beta;
681 bool M_rankProcInNameOfFiles;
684 WorldComm M_worldComm;
690 for (
int i = 0; i < BDF_MAX_ORDER; ++i )
692 M_alpha[ i ].resize( i+2 );
693 M_beta[ i ].resize( i+1 );
696 for (
int i = 0; i < BDF_MAX_ORDER; ++i )
700 M_alpha[i][ 0 ] = 1.;
701 M_alpha[i][ 1 ] = 1.;
707 M_alpha[i][ 0 ] = 3. / 2.;
708 M_alpha[i][ 1 ] = 2.;
709 M_alpha[i][ 2 ] = -1. / 2.;
711 M_beta[i][ 1 ] = -1.;
716 M_alpha[i][ 0 ] = 11. / 6.;
717 M_alpha[i][ 1 ] = 3.;
718 M_alpha[i][ 2 ] = -3. / 2.;
719 M_alpha[i][ 3 ] = 1. / 3.;
721 M_beta[i][ 1 ] = -3.;
727 M_alpha[i][ 0 ] = 25. / 12.;
728 M_alpha[i][ 1 ] = 4.;
729 M_alpha[i][ 2 ] = -3.;
730 M_alpha[i][ 3 ] = 4. / 3.;
731 M_alpha[i][ 4 ] = -1. / 4.;
733 M_beta[i][ 1 ] = -6.;
735 M_beta[i][ 3 ] = -1.;
739 std::ostringstream ostr;
740 ostr <<
"bdf_o_" << M_order <<
"_dt_" << M_dt;
742 M_path_save = ostr.str();
745 if ( !fs::exists( M_path_save ) && this->saveInFile() )
746 fs::create_directories( M_path_save );
753 if ( this->restartPath().empty() ) thepath=this->path()/
"metadata";
755 else thepath=this->restartPath()/this->path()/
"metadata";
758 if ( fs::exists( thepath ) )
760 DVLOG(2) <<
"[Bdf] loading metadata from " << M_path_save.string() <<
"\n";
763 fs::ifstream ifs( thepath );
766 boost::archive::text_iarchive ia( ifs );
767 ia >> BOOST_SERIALIZATION_NVP( *
this );
768 DVLOG(2) <<
"[Bdf::init()] metadata loaded\n";
773 if (this->doRestartAtLastSave()) M_Ti = M_time_values_map.back();
778 BOOST_FOREACH(
auto time, M_time_values_map )
780 if ( math::abs( time-M_Ti ) < 1e-10 )
794 DVLOG(2) <<
"[Bdf] intial time " << M_Ti <<
" not found\n";
797 M_time_values_map.clear();
803 if (this->saveFreq()==1)
805 M_time_values_map.resize( M_iteration+1 );
809 int nItBack = M_iteration % this->saveFreq();
810 M_iteration-=nItBack;
811 M_time_values_map.resize( M_iteration+1 );
812 M_Ti = M_time_values_map.back();
816 DVLOG(2) <<
"[Bdf] initial time is Ti=" << M_Ti <<
"\n";
818 DVLOG(2) <<
"[Bdf::init()] file index: " << M_iteration <<
"\n";
824 M_time_values_map.clear();
830 class BdfBaseMetadata
833 BdfBaseMetadata( BdfBase& bdf )
843 if ( M_bdf.restartPath().empty() ) ifs.open( M_bdf.path()/
"metadata" );
845 else ifs.open( M_bdf.restartPath()/M_bdf.path()/
"metadata" );
849 boost::archive::text_iarchive ia( ifs );
850 ia >> BOOST_SERIALIZATION_NVP( M_bdf );
851 DVLOG(2) <<
"[Bdf::init()] metadata loaded\n";
856 if ( !M_bdf.saveInFile() || M_bdf.worldComm().globalRank()!=M_bdf.worldComm().masterRank() )
return;
858 fs::ofstream ofs( M_bdf.path() /
"metadata" );
861 boost::archive::text_oarchive oa( ofs );
862 oa << BOOST_SERIALIZATION_NVP( ( BdfBase
const& )M_bdf );
863 DVLOG(2) <<
"[Bdf::init()] metadata saved\n";
905 template<
typename SpaceType>
906 class Bdf :
public BdfBase
908 friend class boost::serialization::access;
909 typedef BdfBase super;
911 typedef Bdf<SpaceType> bdf_type;
912 typedef boost::shared_ptr<bdf_type> bdf_ptrtype;
913 typedef SpaceType space_type;
914 typedef boost::shared_ptr<space_type> space_ptrtype;
915 typedef typename space_type::element_type element_type;
916 typedef typename space_type::return_type return_type;
917 typedef typename element_type::value_type value_type;
919 typedef boost::shared_ptr<element_type> unknown_type;
920 typedef std::vector< unknown_type > unknowns_type;
921 typedef typename node<value_type>::type node_type;
923 typedef typename super::time_iterator time_iterator;
925 BOOST_PARAMETER_CONSTRUCTOR(
926 Bdf, ( BdfBase ), tag,
927 ( required ( final_time,* ) )
941 Bdf( po::variables_map
const& vm, space_ptrtype
const& space, std::string
const& name, std::string
const& prefix=
"" );
948 Bdf( space_ptrtype
const& space, std::string
const& name );
954 M_space( b.M_space ),
955 M_unknowns( b.M_unknowns )
963 auto b = bdf_ptrtype(
new bdf_type( *
this ) );
965 for (
auto it = b->M_unknowns.begin(), en = b->M_unknowns.end(); it != en; ++ it )
967 *it = unknown_type(
new element_type( M_space ) );
989 double start( element_type
const& u0 );
990 double start( unknowns_type
const& uv0 );
1002 template<
typename container_type>
1003 void shiftRight(
typename space_type::template Element<value_type, container_type>
const& u_curr );
1011 element_type
poly()
const;
1014 unknowns_type
const&
unknowns()
const;
1017 element_type&
unknown(
int i );
1019 template<
typename container_type>
1020 void setUnknown(
int i,
typename space_type::template Element<value_type, container_type>
const& e )
1022 M_unknowns[i]->assign( e );
1025 void showMe( std::ostream& __out = std::cout )
const;
1035 template<
class Archive>
1036 void serialize( Archive & ar,
const unsigned int version )
1038 DVLOG(2) <<
"[BDF::serialize] saving/loading archive\n";
1039 ar & boost::serialization::base_object<BdfBase>( *this );
1045 space_ptrtype M_space;
1048 unknowns_type M_unknowns;
1051 template <
typename SpaceType>
1053 space_ptrtype
const& __space,
1054 std::string
const& name,
1055 std::string
const& prefix )
1057 super( vm, name, prefix, __space->worldComm() ),
1060 M_unknowns.resize( BDF_MAX_ORDER );
1062 for ( uint8_type __i = 0; __i < ( uint8_type )BDF_MAX_ORDER; ++__i )
1064 M_unknowns[__i] = unknown_type(
new element_type( M_space ) );
1065 M_unknowns[__i]->zero();
1070 template <
typename SpaceType>
1072 std::string
const& name )
1074 super( name, __space->worldComm() ),
1077 M_unknowns.resize( BDF_MAX_ORDER );
1079 for ( uint8_type __i = 0; __i < ( uint8_type )BDF_MAX_ORDER; ++__i )
1081 M_unknowns[__i] = unknown_type(
new element_type( M_space ) );
1082 M_unknowns[__i]->zero();
1087 template <
typename SpaceType>
1093 if ( this->isRestart() )
1095 for (
int p = 0; p < std::min( M_order, M_iteration+1 ); ++p )
1098 std::ostringstream ostr;
1100 if( M_rankProcInNameOfFiles )
1101 ostr << M_name <<
"-" << M_iteration-p<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
1103 ostr << M_name <<
"-" << M_iteration-p;
1105 DVLOG(2) <<
"[Bdf::init()] load file: " << ostr.str() <<
"\n";
1109 if ( this->restartPath().empty() ) ifs.open( this->path()/ostr.str() );
1111 else ifs.open( this->restartPath()/this->path()/ostr.str() );
1116 boost::archive::binary_iarchive ia( ifs );
1117 ia >> *M_unknowns[p];
1123 template <
typename SpaceType>
1124 Bdf<SpaceType>::~Bdf()
1128 template <
typename SpaceType>
1132 M_time_values_map.clear();
1133 std::ostringstream ostr;
1135 if( M_rankProcInNameOfFiles )
1136 ostr << M_name <<
"-" << 0<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
1138 ostr << M_name <<
"-" << 0;
1141 M_time_values_map.push_back( M_Ti );
1142 std::for_each( M_unknowns.begin(), M_unknowns.end(), *boost::lambda::_1 = u0 );
1143 this->saveCurrent();
1146 template <
typename SpaceType>
1150 M_time_values_map.clear();
1151 std::ostringstream ostr;
1153 if( M_rankProcInNameOfFiles )
1154 ostr << M_name <<
"-" << 0<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
1156 ostr << M_name <<
"-" << 0;
1159 M_time_values_map.push_back( M_Ti );
1161 std::copy( uv0.begin(), uv0.end(), M_unknowns.begin() );
1162 this->saveCurrent();
1165 template <
typename SpaceType>
1171 return super::start();
1174 template <
typename SpaceType>
1179 this->initialize( u0 );
1180 auto res = super::start();
1184 template <
typename SpaceType>
1189 this->initialize( uv0 );
1190 auto res = super::start();
1194 template <
typename SpaceType>
1200 return super::restart();
1203 template <
typename SpaceType>
1205 typename Bdf<SpaceType>::unknowns_type&
1211 template <
typename SpaceType>
1212 typename Bdf<SpaceType>::element_type&
1215 DVLOG(2) <<
"[Bdf::unknown] id: " << i <<
" l2norm = " << M_unknowns[i]->l2Norm() <<
"\n";
1216 return *M_unknowns[i];
1220 template <
typename SpaceType>
1222 Bdf<SpaceType>::saveCurrent()
1224 if (!this->saveInFile())
return;
1227 for ( uint8_type i = 0; i < this->timeOrder() && !doSave; ++i )
1229 int iterTranslate = M_iteration + this->timeOrder()-(i+1);
1230 if (iterTranslate % this->saveFreq()==0) doSave=
true;
1233 if (!doSave)
return;
1235 BdfBaseMetadata bdfsaver( *
this );
1239 std::ostringstream ostr;
1241 if( M_rankProcInNameOfFiles )
1242 ostr << M_name <<
"-" << M_iteration<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
1244 ostr << M_name <<
"-" << M_iteration;
1246 fs::ofstream ofs( M_path_save / ostr.str() );
1250 boost::archive::binary_oarchive oa( ofs );
1251 oa << *M_unknowns[0];
1255 template <
typename SpaceType>
1257 Bdf<SpaceType>::loadCurrent()
1259 BdfBaseMetadata bdfsaver( *
this );
1263 std::ostringstream ostr;
1265 if( M_rankProcInNameOfFiles )
1266 ostr << M_name <<
"-" << M_iteration<<
"-proc"<<Environment::worldComm().globalRank()<<
"on"<<Environment::worldComm().globalSize();
1268 ostr << M_name <<
"-" << M_iteration;
1270 fs::ifstream ifs( M_path_save / ostr.str() );
1273 boost::archive::binary_iarchive ia( ifs );
1274 ia >> *M_unknowns[0];
1278 template <
typename SpaceType>
1279 template<
typename container_type>
1283 DVLOG(2) <<
"shiftRight: inserting time " << this->time() <<
"s\n";
1284 super::shiftRight();
1287 using namespace boost::lambda;
1288 typename unknowns_type::reverse_iterator __it = boost::next( M_unknowns.rbegin() );
1289 std::for_each( M_unknowns.rbegin(), boost::prior( M_unknowns.rend() ),
1290 ( *lambda::_1 = *( *lambda::var( __it ) ), ++lambda::var( __it ) ) );
1292 *M_unknowns[0] = __new_unk;
1294 BOOST_FOREACH( boost::shared_ptr<element_type>& t, M_unknowns )
1296 DVLOG(2) <<
"[Bdf::shiftright] id: " << i <<
" l2norm = " << t->l2Norm() <<
"\n";
1301 this->saveCurrent();
1305 template <
typename SpaceType>
1306 typename Bdf<SpaceType>::element_type
1309 element_type __t( M_space );
1312 FEELPP_ASSERT( __t.size() == M_space->nDof() )( __t.size() )( M_space->nDof() ).error(
"invalid space element size" );
1313 FEELPP_ASSERT( __t.size() == M_unknowns[0]->size() )( __t.size() )( M_unknowns[0]->size() ).error(
"invalid space element size" );
1315 for ( uint8_type i = 0; i < this->timeOrder(); ++i )
1316 __t.add( this->polyDerivCoefficient( i+1 ), *M_unknowns[i] );
1321 template <
typename SpaceType>
1322 typename Bdf<SpaceType>::element_type
1325 element_type __t( M_space );
1328 FEELPP_ASSERT( __t.size() == M_space->nDof() )( __t.size() )( M_space->nDof() ).error(
"invalid space element size" );
1329 FEELPP_ASSERT( __t.size() == M_unknowns[0]->size() )( __t.size() )( M_unknowns[0]->size() ).error(
"invalid space element size" );
1331 for ( uint8_type i = 0; i < this->timeOrder(); ++i )
1332 __t.add( this->polyCoefficient( i ), *M_unknowns[ i ] );
1339 BOOST_PARAMETER_FUNCTION(
1340 ( boost::shared_ptr<
Bdf<
typename meta::remove_all<
typename parameter::binding<Args, tag::space>::type>::type::element_type> > ),
1343 ( space,*( boost::is_convertible<mpl::_,boost::shared_ptr<Feel::FunctionSpaceBase> > ) ) )
1345 ( vm,*, Environment::vm() )
1348 ( order,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.order" )].
template as<int>() )
1349 ( initial_time,*( boost::is_floating_point<mpl::_> ),vm[prefixvm( prefix,
"bdf.time-initial" )].
template as<double>() )
1350 ( final_time,*( boost::is_floating_point<mpl::_> ),vm[prefixvm( prefix,
"bdf.time-final" )].
template as<double>() )
1351 ( time_step,*( boost::is_floating_point<mpl::_> ),vm[prefixvm( prefix,
"bdf.time-step" )].
template as<double>() )
1352 ( strategy,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.strategy" )].
template as<int>() )
1353 ( steady,*(
bool ),vm[prefixvm( prefix,
"bdf.steady" )].
template as<bool>() )
1354 ( restart,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.restart" )].
template as<bool>() )
1355 ( restart_path,*,vm[prefixvm( prefix,
"bdf.restart.path" )].
template as<std::string>() )
1356 ( restart_at_last_save,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.restart.at-last-save" )].
template as<bool>() )
1357 ( save,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.save" )].
template as<bool>() )
1358 ( freq,*(boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.save.freq" )].
template as<int>() )
1359 ( rank_proc_in_files_name,*( boost::is_integral<mpl::_> ),vm[prefixvm( prefix,
"bdf.rank-proc-in-files-name" )].
template as<bool>() )
1362 typedef typename meta::remove_all<space_type>::type::element_type _space_type;
1363 auto thebdf = boost::shared_ptr<Bdf<_space_type> >(
new Bdf<_space_type>( vm,space,name,prefix ) );
1364 thebdf->setTimeInitial( initial_time );
1365 thebdf->setTimeFinal( final_time );
1366 thebdf->setTimeStep( time_step );
1367 thebdf->setOrder( order );
1368 thebdf->setSteady( steady );
1369 thebdf->setStrategy( strategy );
1370 thebdf->setRestart( restart );
1371 thebdf->setRestartPath( restart_path );
1372 thebdf->setRestartAtLastSave( restart_at_last_save );
1373 thebdf->setSaveInFile( save );
1374 thebdf->setSaveFreq( freq );
1375 thebdf->setRankProcInNameOfFiles( rank_proc_in_files_name );
element_type poly() const
Definition: bdf2.hpp:1323
element_type & unknown(int i)
Return a vector with the last n state vectors.
Definition: bdf.hpp:299
bdf_ptrtype deepCopy() const
return a deep copy of the bdf object
Definition: bdf2.hpp:961
Backward differencing formula time discretization.
Definition: bdf.hpp:91
Bdf(space_ptrtype const &space)
Definition: bdf.hpp:201
Bdf(Bdf const &b)
copy operator
Definition: bdf2.hpp:951
double restart()
Definition: bdf2.hpp:1196
double start()
Definition: bdf2.hpp:1167
element_type polyDeriv() const
Definition: bdf2.hpp:1307
void initialize(element_type const &u0)
Definition: bdf.hpp:274
void shiftRight(typename space_type::template Element< value_type, container_type > const &u_curr)
Definition: bdf.hpp:339
Elements & operator=(Elements const &e)
Definition: elements.hpp:335
BDFTimeScheme order() const
Definition: bdf.hpp:121
unknowns_type const & unknowns() const
Return a vector with the last n state vectors.
Definition: bdf.cpp:111