Skip to content

Commit

Permalink
Add option to skip specified times in predictors ref idaholab#6506
Browse files Browse the repository at this point in the history
  • Loading branch information
bwspenc committed Mar 4, 2016
1 parent 00a34dc commit 3e5f806
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions framework/include/predictors/Predictor.h
Expand Up @@ -49,6 +49,8 @@ class Predictor :
virtual NumericVector<Number> & solutionPredictor() { return _solution_predictor; }

protected:
virtual bool shouldApply();

FEProblem & _fe_problem;
NonlinearSystem & _nl;

Expand All @@ -62,6 +64,9 @@ class Predictor :

/// Amount by which to scale the predicted value. Must be in [0,1].
Real _scale;

/// Times for which the predictor should not be applied
std::vector<Real> _skip_times;
};

#endif /* PREDICTOR_H */
2 changes: 1 addition & 1 deletion framework/include/predictors/SimplePredictor.h
Expand Up @@ -53,7 +53,7 @@ class SimplePredictor : public Predictor
virtual void apply(NumericVector<Number> & sln);

protected:
Real _scale;
virtual bool shouldApply();
};

#endif /* SIMPLEPREDICTOR_H */
4 changes: 4 additions & 0 deletions framework/src/predictors/AdamsPredictor.C
Expand Up @@ -73,6 +73,10 @@ AdamsPredictor::apply(NumericVector<Number> & sln)
// that gets called on time step begin.
// That means that history control must go here.
historyControl();

if (!shouldApply())
return;

// AB2 can only be applied if there are enough old solutions
// AB1 could potentially be used for the time step prior?
// It would be possible to do VSVO Adams, Kevin has the info
Expand Down
20 changes: 19 additions & 1 deletion framework/src/predictors/Predictor.C
Expand Up @@ -25,6 +25,7 @@ InputParameters validParams<Predictor>()
{
InputParameters params = validParams<MooseObject>();
params.addRequiredParam<Real>("scale", "The scale factor for the predictor (can range from 0 to 1)");
params.addParam<std::vector<Real> >("skip_times", "Time steps for which the predictor should not be applied");

params.registerBase("Predictor");

Expand All @@ -44,7 +45,8 @@ Predictor::Predictor(const InputParameters & parameters) :
_solution_old(_nl.solutionOld()),
_solution_older(_nl.solutionOlder()),
_solution_predictor(_nl.addVector("predictor", true, GHOSTED)),
_scale(getParam<Real>("scale"))
_scale(getParam<Real>("scale")),
_skip_times(getParam<std::vector<Real> >("skip_times"))
{
if (_scale < 0.0 || _scale > 1.0)
mooseError("Input value for scale = " << _scale << " is outside of permissible range (0 to 1)");
Expand All @@ -54,3 +56,19 @@ Predictor::~Predictor()
{
}

bool
Predictor::shouldApply()
{
bool should_apply = true;

const Real & current_time = _fe_problem.time();
for (unsigned int i=0; i<_skip_times.size(); ++i)
{
if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i]))
{
should_apply = false;
break;
}
}
return should_apply;
}
20 changes: 16 additions & 4 deletions framework/src/predictors/SimplePredictor.C
Expand Up @@ -19,14 +19,12 @@ template<>
InputParameters validParams<SimplePredictor>()
{
InputParameters params = validParams<Predictor>();
params.addRequiredParam<Real>("scale", "The scale factor for the predictor (can range from 0 to 1)");

return params;
}

SimplePredictor::SimplePredictor(const InputParameters & parameters) :
Predictor(parameters),
_scale(getParam<Real>("scale"))
Predictor(parameters)
{
}

Expand All @@ -37,7 +35,7 @@ SimplePredictor::~SimplePredictor()
void
SimplePredictor::apply(NumericVector<Number> & sln)
{
if (_dt_old > 0)
if (shouldApply())
{
// Save the original stream flags
std::ios_base::fmtflags out_flags = Moose::out.flags();
Expand All @@ -54,4 +52,18 @@ SimplePredictor::apply(NumericVector<Number> & sln)
sln.add(-dt_adjusted_scale_factor, _solution_older);
}
}
else
_console << " Skipping predictor this step" << std::endl;
}

bool
SimplePredictor::shouldApply()
{
bool should_apply = true;
should_apply = Predictor::shouldApply();

if (_dt_old <= 0)
should_apply = false;

return should_apply;
}

0 comments on commit 3e5f806

Please sign in to comment.