Skip to content

Commit

Permalink
Add source for LinearFVTimeDerivative. (#29149)
Browse files Browse the repository at this point in the history
  • Loading branch information
grmnptr committed Dec 9, 2024
1 parent 803a69f commit 200608c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
13 changes: 9 additions & 4 deletions framework/src/linearfvkernels/LinearFVElementalKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ LinearFVElementalKernel::addMatrixContribution()
{
// These only contribute to the diagonal of the matrix, so we just get
// the contribution and insert it immediately.
const auto dof_id = _current_elem_info->dofIndices()[_sys_num][_var_num];
(*_linear_system.matrix).add(dof_id, dof_id, computeMatrixContribution());
(*_linear_system.matrix).add(_dof_id, _dof_id, computeMatrixContribution());
}

void
LinearFVElementalKernel::addRightHandSideContribution()
{
// These only contribute to one entry of the right hand side, so we just get
// the contribution and insert it immediately.
const auto dof_id = _current_elem_info->dofIndices()[_sys_num][_var_num];
(*_linear_system.rhs).add(dof_id, computeRightHandSideContribution());
(*_linear_system.rhs).add(_dof_id, computeRightHandSideContribution());
}

void
LinearFVElementalKernel::setCurrentElemInfo(const ElemInfo * elem_info)
{
_current_elem_info = elem_info;
_dof_id = _current_elem_info->dofIndices()[_sys_num][_var_num];
}
59 changes: 59 additions & 0 deletions framework/src/linearfvkernels/LinearFVTimeDerivative.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "LinearFVTimeDerivative.h"

registerMooseObject("MooseApp", LinearFVTimeDerivative);

InputParameters
LinearFVTimeDerivative::validParams()
{
InputParameters params = LinearFVElementalKernel::validParams();
params.addClassDescription("Represents the matrix and right hand side contributions of a "
"time derivative term in a partial differential equation.");
params.addParam<MooseFunctorName>(
"factor", 1.0, "A multiplier on the variable within the time derivative.");
return params;
}

LinearFVTimeDerivative::LinearFVTimeDerivative(const InputParameters & params)
: LinearFVElementalKernel(params),
_factor(getFunctor<Real>("factor")),
_time_integrator(_sys.getTimeIntegrator(_var_num)),
_factor_history(_time_integrator.numStatesRequired(), 0.0),
_state_args(_time_integrator.numStatesRequired(), determineState())
{
// In case we need older states
for (const auto i : index_range(_state_args))
_state_args[i] = Moose::StateArg(i, Moose::SolutionIterationType::Time);
}

Real
LinearFVTimeDerivative::computeMatrixContribution()
{
const auto elem_arg = makeElemArg(_current_elem_info->elem());
return _factor(elem_arg, _state_args[0]) * /*_time_integrator.matrixContribution() */
_current_elem_volume;
}

Real
LinearFVTimeDerivative::computeRightHandSideContribution()
{
return /*_time_integrator.rhsContribution(_dof_id, _factor_history) */ _current_elem_volume;
}

void
LinearFVTimeDerivative::setCurrentElemInfo(const ElemInfo * elem_info)
{
LinearFVElementalKernel::setCurrentElemInfo(elem_info);

const auto elem_arg = makeElemArg(_current_elem_info->elem());
for (const auto i : index_range(_factor_history))
_factor_history[i] = _factor(elem_arg, _state_args[i]);
}

0 comments on commit 200608c

Please sign in to comment.