Skip to content

Commit

Permalink
sub-vector time derivative calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed May 22, 2024
1 parent 3ca7cff commit 759ea9f
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 34 deletions.
10 changes: 8 additions & 2 deletions framework/include/systems/DisplacedSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ class DisplacedSystem : public SystemBase
return _undisplaced_system.solutionUDotDotOld();
}

virtual Number & duDotDu() override { return _undisplaced_system.duDotDu(); }
virtual std::vector<Number> & duDotDu() override { return _undisplaced_system.duDotDu(); }
virtual Number & duDotDotDu() override { return _undisplaced_system.duDotDotDu(); }
virtual const Number & duDotDu() const override { return _undisplaced_system.duDotDu(); }
virtual const Number & duDotDu(const unsigned int var_num) const override;
virtual const Number & duDotDotDu() const override { return _undisplaced_system.duDotDotDu(); }

virtual void addDotVectors() override { _undisplaced_system.addDotVectors(); }
Expand Down Expand Up @@ -294,3 +294,9 @@ DisplacedSystem::hasSolutionState(const unsigned int state,
{
return _undisplaced_system.hasSolutionState(state, iteration_type);
}

inline const Number &
DisplacedSystem::duDotDu(const unsigned int var_num) const
{
return _undisplaced_system.duDotDu(var_num);
}
8 changes: 5 additions & 3 deletions framework/include/systems/SystemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ class SystemBase : public libMesh::ParallelObject, public ConsoleStreamInterface
*/
virtual void addDotVectors();

virtual Number & duDotDu() { return _du_dot_du; }
virtual std::vector<Number> & duDotDu() { return _du_dot_du; }
virtual Number & duDotDotDu() { return _du_dotdot_du; }
virtual const Number & duDotDu() const { return _du_dot_du; }
virtual const Number & duDotDu(const unsigned int var_num) const { return _du_dot_du[var_num]; }
virtual const Number & duDotDotDu() const { return _du_dotdot_du; }

virtual NumericVector<Number> * solutionUDot() { return _u_dot; }
Expand Down Expand Up @@ -995,7 +995,9 @@ class SystemBase : public libMesh::ParallelObject, public ConsoleStreamInterface
/// old solution vector for u^dotdot
NumericVector<Number> * _u_dotdot_old;

Real _du_dot_du;
/// Derivative of time derivative of u with respect to uj. This depends on the time integration
/// scheme
std::vector<Real> _du_dot_du;
Real _du_dotdot_du;

/// Tagged vectors (pointer)
Expand Down
8 changes: 6 additions & 2 deletions framework/include/timeintegrators/TimeIntegrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,15 @@ class TimeIntegrator : public MooseObject, public Restartable
/// residual vector for non-time contributions
NumericVector<Number> & _Re_non_time;

/// Derivative of time derivative with respect to current solution: \f$ {du^dot}\over{du} \f$
Real & _du_dot_du;
/// Derivative of time derivative with respect to current solution: \f$ {du^dot}\over{du} \f$ for
/// the different variables. We will only modify the elements in this vector corresponding to the
/// variables that we integrate
std::vector<Real> & _du_dot_du;
/// solution vectors
const NumericVector<Number> * const & _solution;
const NumericVector<Number> & _solution_old;
std::unique_ptr<NumericVector<Number>> _solution_sub;
std::unique_ptr<NumericVector<Number>> _solution_old_sub;
//
int & _t_step;
//
Expand Down
1 change: 1 addition & 0 deletions framework/src/systems/SystemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ SystemBase::addVariable(const std::string & var_type,
// getMaxVariableNumber is an API method used in Rattlesnake
if (var_num > _max_var_number)
_max_var_number = var_num;
_du_dot_du.resize(var_num + 1);
}

bool
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/AStableDirk4.C
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ AStableDirk4::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ActuallyExplicitEuler.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ ActuallyExplicitEuler::computeTimeDerivatives()
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();

_du_dot_du = 1.0 / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1.0 / _dt;
}

void
Expand Down
8 changes: 6 additions & 2 deletions framework/src/timeintegrators/BDF2.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ BDF2::computeTimeDerivatives()
if (_t_step == 1)
{
u_dot = *_solution;
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}
else
{
u_dot.zero();
_du_dot_du = _weight[0] / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = _weight[0] / _dt;
}
computeTimeDerivativeHelper(u_dot, *_solution, _solution_old, _solution_older);
u_dot.close();
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/CentralDifference.C
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ CentralDifference::computeTimeDerivatives()
u_dot.close();

// used for Jacobian calculations
_du_dot_du = 1.0 / (2 * _dt);
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1.0 / (2 * _dt);
_du_dotdot_du = 1.0 / (_dt * _dt);

// Computing udotdot "factor"
Expand Down
27 changes: 22 additions & 5 deletions framework/src/timeintegrators/CrankNicolson.C
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,26 @@ CrankNicolson::computeTimeDerivatives()
"uDotRequested() to true in FEProblemBase befor requesting `u_dot`.");

NumericVector<Number> & u_dot = *_sys.solutionUDot();
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
if (!_var_restriction)
{
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
}
else
{
auto u_dot_sub = u_dot.get_subvector(_local_indices);
_solution->create_subvector(*_solution_sub, _local_indices, false);
_solution_old.create_subvector(*_solution_old_sub, _local_indices, false);
*u_dot_sub = *_solution_sub;
computeTimeDerivativeHelper(*u_dot_sub, *_solution_old_sub);
u_dot.restore_subvector(std::move(*u_dot_sub), _local_indices);
// Scatter info needed for ghosts
u_dot.close();
}

_du_dot_du = 2. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 2. / _dt;
}

void
Expand All @@ -61,7 +76,9 @@ CrankNicolson::init()
// time derivative is assumed to be zero on initial
NumericVector<Number> & u_dot = *_sys.solutionUDot();
u_dot.zero();
_du_dot_du = 0;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 0;

// compute residual for the initial time step
// Note: we can not directly pass _residual_old in computeResidualTag because
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ExplicitEuler.C
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ ExplicitEuler::computeTimeDerivatives()
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();

_du_dot_du = 1.0 / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1.0 / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ExplicitRK2.C
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ ExplicitRK2::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old, _solution_older);

_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
u_dot.close();
}

Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ExplicitSSPRungeKutta.C
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ void
ExplicitSSPRungeKutta::computeTimeDerivatives()
{
// Only the Jacobian needs to be computed, since the mass matrix needs it
_du_dot_du = 1.0 / (_b[_stage] * _dt);
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1.0 / (_b[_stage] * _dt);
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ExplicitTVDRK2.C
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ ExplicitTVDRK2::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old, _solution_older);

_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
u_dot.close();
}

Expand Down
23 changes: 19 additions & 4 deletions framework/src/timeintegrators/ImplicitEuler.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ ImplicitEuler::computeTimeDerivatives()
"uDotRequested() to true in FEProblemBase befor requesting `u_dot`.");

NumericVector<Number> & u_dot = *_sys.solutionUDot();
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
if (!_var_restriction)
{
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
}
else
{
auto u_dot_sub = u_dot.get_subvector(_local_indices);
_solution->create_subvector(*_solution_sub, _local_indices, false);
_solution_old.create_subvector(*_solution_old_sub, _local_indices, false);
*u_dot_sub = *_solution_sub;
computeTimeDerivativeHelper(*u_dot_sub, *_solution_old_sub);
u_dot.restore_subvector(std::move(*u_dot_sub), _local_indices);
// Scatter info needed for ghosts
u_dot.close();
}

_du_dot_du = 1.0 / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1.0 / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/ImplicitMidpoint.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ ImplicitMidpoint::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/LStableDirk2.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ LStableDirk2::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/LStableDirk3.C
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ LStableDirk3::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/LStableDirk4.C
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ LStableDirk4::computeTimeDerivatives()
u_dot = *_solution;
computeTimeDerivativeHelper(u_dot, _solution_old);
u_dot.close();
_du_dot_du = 1. / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = 1. / _dt;
}

void
Expand Down
4 changes: 3 additions & 1 deletion framework/src/timeintegrators/NewmarkBeta.C
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ NewmarkBeta::computeTimeDerivatives()

// used for Jacobian calculations
_du_dotdot_du = 1.0 / _beta / _dt / _dt;
_du_dot_du = _gamma / _beta / _dt;
for (const auto i : index_range(_du_dot_du))
if (integratesVar(i))
_du_dot_du[i] = _gamma / _beta / _dt;
}

void
Expand Down
3 changes: 3 additions & 0 deletions framework/src/timeintegrators/TimeIntegrator.C
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ TimeIntegrator::init()
var_dof_indices.end(),
std::back_inserter(_local_indices));
}

_solution_sub = NumericVector<Number>::build(_solution->comm());
_solution_old_sub = NumericVector<Number>::build(_solution_old.comm());
}

void
Expand Down
2 changes: 1 addition & 1 deletion framework/src/variables/MooseVariableData.C
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ MooseVariableData<OutputType>::computeMonomialValues()
Real u_dotdot = 0;
Real u_dot_old = 0;
Real u_dotdot_old = 0;
const Real & du_dot_du = _sys.duDotDu();
const Real & du_dot_du = _sys.duDotDu(_var_num);
const Real & du_dotdot_du = _sys.duDotDotDu();

if (is_transient)
Expand Down
4 changes: 2 additions & 2 deletions framework/src/variables/MooseVariableDataBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ MooseVariableDataBase<OutputType>::fetchDoFValues()
{
_dof_du_dot_du.resize(n);
for (decltype(n) i = 0; i < n; ++i)
_dof_du_dot_du[i] = _sys.duDotDu();
_dof_du_dot_du[i] = _sys.duDotDu(_var.number());
}
if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
{
Expand Down Expand Up @@ -708,7 +708,7 @@ MooseVariableDataBase<RealEigenVector>::fetchDoFValues()
{
_dof_du_dot_du.resize(n);
for (decltype(n) i = 0; i < n; ++i)
_dof_du_dot_du[i] = _sys.duDotDu();
_dof_du_dot_du[i] = _sys.duDotDu(_var.number());
}
if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
{
Expand Down
2 changes: 1 addition & 1 deletion framework/src/variables/MooseVariableScalar.C
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ MooseVariableScalar::reinit(bool reinit_for_derivative_reordering /* = false*/)
const NumericVector<Real> * u_dotdot = sys.solutionUDotDot();
const NumericVector<Real> * u_dot_old = sys.solutionUDotOld();
const NumericVector<Real> * u_dotdot_old = sys.solutionUDotDotOld();
const Real & du_dot_du = sys.duDotDu();
const Real & du_dot_du = sys.duDotDu(number());
const Real & du_dotdot_du = sys.duDotDotDu();
auto safe_access_tagged_vectors = sys.subproblem().safeAccessTaggedVectors();
auto safe_access_tagged_matrices = sys.subproblem().safeAccessTaggedMatrices();
Expand Down

0 comments on commit 759ea9f

Please sign in to comment.