Skip to content

Commit d9e3403

Browse files
authored
Merge pull request #4063 from dknez/set_Nmax_from_n_snapshots
RB update: Added option to set Nmax from n_snapshots
2 parents 024bbfc + 7010ea3 commit d9e3403

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

include/reduced_basis/rb_eim_construction.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ class RBEIMConstruction : public RBConstructionBase<System>
238238
unsigned int get_Nmax() const;
239239
virtual void set_Nmax(unsigned int Nmax);
240240

241+
/**
242+
* Call this method to set _set_Nmax_from_n_snapshots=true and
243+
* _Nmax_from_n_snapshots_increment=increment. This means that
244+
* we will overrule Nmax to be n_snapshots + increment, where
245+
* increment can be positive or negative (typically it should be
246+
* negative to limit Nmax to be less that the number of snapshots).
247+
*/
248+
void enable_set_Nmax_from_n_snapshots(int increment);
249+
250+
/**
251+
* Call this method to set _set_Nmax_from_n_snapshots=false and
252+
* reset _Nmax_from_n_snapshots_increment to 0.
253+
*/
254+
void disable_set_Nmax_from_n_snapshots();
255+
241256
/**
242257
* Get the maximum value (across all processors) from
243258
* the parametrized functions in the training set.
@@ -472,6 +487,18 @@ class RBEIMConstruction : public RBConstructionBase<System>
472487
*/
473488
unsigned int _Nmax;
474489

490+
/**
491+
* If _set_Nmax_from_n_snapshots=true, then we overrule Nmax to be
492+
* Nmax += _Nmax_from_n_snapshots_increment. Note that the "increment
493+
* can be positive or negative. Typically we would want to set the
494+
* increment to be negative or 0 to limit Nmax based on the number
495+
* of available snapshots, but in some rare cases it could make sense
496+
* to set it to a positive value, e.g. if we are appending to a basis
497+
* that has already been generated via a previous training.
498+
*/
499+
bool _set_Nmax_from_n_snapshots;
500+
int _Nmax_from_n_snapshots_increment;
501+
475502
/**
476503
* Relative and absolute tolerances for training the EIM approximation.
477504
*/

src/reduced_basis/rb_eim_construction.C

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
11221154
Real RBEIMConstruction::get_max_abs_value_in_training_set() const
11231155
{
11241156
return _max_abs_value_in_training_set;

0 commit comments

Comments
 (0)