@@ -110,6 +110,8 @@ RBEIMConstruction::RBEIMConstruction (EquationSystems & es,
110110 : RBConstructionBase (es , name_in , number_in ),
111111 best_fit_type_flag (PROJECTION_BEST_FIT ),
112112 _Nmax (0 ),
113+ _set_Nmax_from_n_snapshots (false),
114+ _Nmax_from_n_snapshots_increment (0 ),
113115 _rel_training_tolerance (1.e-4 ),
114116 _abs_training_tolerance (1.e-12 ),
115117 _max_abs_value_in_training_set (0. ),
@@ -188,6 +190,12 @@ void RBEIMConstruction::print_info()
188190 libMesh ::out << std ::endl << "RBEIMConstruction parameters:" << std ::endl ;
189191 libMesh ::out << "system name: " << this -> name () << std ::endl ;
190192 libMesh ::out << "Nmax: " << get_Nmax () << std ::endl ;
193+ if (_set_Nmax_from_n_snapshots )
194+ {
195+ libMesh ::out << "Overruling Nmax based on number of snapshots, with increment set to "
196+ << _Nmax_from_n_snapshots_increment
197+ << std ::endl ;
198+ }
191199 libMesh ::out << "Greedy relative error tolerance: " << get_rel_training_tolerance () << std ::endl ;
192200 libMesh ::out << "Greedy absolute error tolerance: " << get_abs_training_tolerance () << std ::endl ;
193201 libMesh ::out << "Number of parameters: " << get_n_params () << std ::endl ;
@@ -671,6 +679,19 @@ Real RBEIMConstruction::train_eim_approximation_with_POD()
671679
672680 RBEIMEvaluation & rbe = get_rb_eim_evaluation ();
673681
682+ unsigned int n_snapshots = get_n_training_samples ();
683+
684+ // If _set_Nmax_from_n_snapshots=true, then we overrule Nmax.
685+ if (_set_Nmax_from_n_snapshots )
686+ {
687+ int updated_Nmax = (static_cast < int > (n_snapshots ) + _Nmax_from_n_snapshots_increment );
688+
689+ // We only overrule _Nmax if updated_Nmax is positive, since if Nmax=0 then we'll skip
690+ // training here entirely, which is typically not what we want.
691+ if (updated_Nmax > 0 )
692+ _Nmax = static_cast < unsigned int > (updated_Nmax );
693+ }
694+
674695 // _eim_projection_matrix is not used in the POD case, but we resize it here in any case
675696 // to be consistent with what we do in train_eim_approximation_with_greedy().
676697 // We need space for one extra interpolation point if we're using the
@@ -689,7 +710,6 @@ Real RBEIMConstruction::train_eim_approximation_with_POD()
689710 // Set up the POD "correlation matrix". This enables us to compute the POD via the
690711 // "method of snapshots", in which we compute a low rank representation of the
691712 // n_snapshots x n_snapshots matrix.
692- unsigned int n_snapshots = get_n_training_samples ();
693713 DenseMatrix < Number > correlation_matrix (n_snapshots ,n_snapshots );
694714
695715 std ::cout << "Start computing correlation matrix" << std ::endl ;
@@ -1119,6 +1139,18 @@ void RBEIMConstruction::set_Nmax(unsigned int Nmax)
11191139 _Nmax = Nmax ;
11201140}
11211141
1142+ void RBEIMConstruction ::enable_set_Nmax_from_n_snapshots (int increment )
1143+ {
1144+ _set_Nmax_from_n_snapshots = true;
1145+ _Nmax_from_n_snapshots_increment = increment ;
1146+ }
1147+
1148+ void RBEIMConstruction ::disable_set_Nmax_from_n_snapshots ()
1149+ {
1150+ _set_Nmax_from_n_snapshots = false;
1151+ _Nmax_from_n_snapshots_increment = 0 ;
1152+ }
1153+
11221154Real RBEIMConstruction ::get_max_abs_value_in_training_set () const
11231155{
11241156 return _max_abs_value_in_training_set ;
0 commit comments