Skip to content

Commit

Permalink
Add matrix and rhs population functions for reaction and source kerne…
Browse files Browse the repository at this point in the history
…ls. (#25722)
  • Loading branch information
German committed Nov 8, 2023
1 parent cb2a73e commit 743e1a9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 8 deletions.
13 changes: 9 additions & 4 deletions framework/include/base/LinearSystemContributionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "TaggingInterface.h"
#include "SystemBase.h"

#include "libmesh/linear_implicit_system.h"

class FEProblemBase;
class MooseMesh;
class SubProblem;
Expand Down Expand Up @@ -56,11 +58,11 @@ class LinearSystemContributionObject : public MooseObject,
*/
LinearSystemContributionObject(const InputParameters & parameters);

/// Compute this object's contribution to the residual
virtual void computeMatrixContribution() = 0;
/// Add this object's contribution to the system matrix
virtual void addMatrixContribution() = 0;

/// Compute this object's contribution to the diagonal Jacobian entries
virtual void computeRightHandSideContribution() = 0;
/// Add this object's contribution to the system right hand side
virtual void addRightHandSideContribution() = 0;

/**
* Returns the variable that this object operates on.
Expand Down Expand Up @@ -91,6 +93,9 @@ class LinearSystemContributionObject : public MooseObject,
/// Reference to the system this object contributes to
SystemBase & _sys;

/// Reference to the libmesh linear system this object contributes to
libMesh::LinearImplicitSystem & _linear_system;

/// The thread ID for this object
THREAD_ID _tid;

Expand Down
22 changes: 21 additions & 1 deletion framework/include/linearfvkernel/ElementalLinearFVKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@
#pragma once

#include "LinearFVKernel.h"
#include "ElemInfo.h"
#include "MooseVariableFV.h"
#include "MooseVariableInterface.h"

class ElementalLinearFVKernel : public LinearFVKernel
class ElementalLinearFVKernel : public LinearFVKernel, public MooseVariableInterface<Real>
{
public:
static InputParameters validParams();
ElementalLinearFVKernel(const InputParameters & params);

/// Compute this object's contribution to the residual
virtual void addMatrixContribution() override;

/// Compute this object's contribution to the diagonal Jacobian entries
virtual void addRightHandSideContribution() override;

/// Set current element
void setCurrentElemInfo(const ElemInfo * elem_info) { _current_elem_info = elem_info; }

virtual Real computeMatrixContribution() = 0;

virtual Real computeRightHandSideContribution() = 0;

protected:
const ElemInfo * _current_elem_info;
MooseVariableFV<Real> & _var;
};
7 changes: 7 additions & 0 deletions framework/include/linearfvkernel/LinearFVReactionKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ class LinearFVReactionKernel : public ElementalLinearFVKernel
public:
static InputParameters validParams();
LinearFVReactionKernel(const InputParameters & params);

virtual Real computeMatrixContribution() override;

virtual Real computeRightHandSideContribution() override;

protected:
const Real _coeff;
};
7 changes: 7 additions & 0 deletions framework/include/linearfvkernel/LinearFVSourceKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ class LinearFVSourceKernel : public ElementalLinearFVKernel
public:
static InputParameters validParams();
LinearFVSourceKernel(const InputParameters & params);

virtual Real computeMatrixContribution() override;

virtual Real computeRightHandSideContribution() override;

protected:
const Real _source_density;
};
2 changes: 2 additions & 0 deletions framework/src/base/LinearSystemContributionObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LinearSystemContributionObject.h"
#include "SubProblem.h"
#include "InputParameters.h"
#include "libmesh/linear_implicit_system.h"

InputParameters
LinearSystemContributionObject::validParams()
Expand Down Expand Up @@ -46,6 +47,7 @@ LinearSystemContributionObject::LinearSystemContributionObject(const InputParame
_subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
_fe_problem(*parameters.get<FEProblemBase *>("_fe_problem_base")),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")),
_linear_system(libMesh::cast_ref<libMesh::LinearImplicitSystem &>(_sys.system())),
_tid(parameters.get<THREAD_ID>("_tid")),
_mesh(_subproblem.mesh())
{
Expand Down
23 changes: 22 additions & 1 deletion framework/src/linearfvkernels/ElementalLinearFVKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ ElementalLinearFVKernel::validParams()
}

ElementalLinearFVKernel::ElementalLinearFVKernel(const InputParameters & params)
: LinearFVKernel(params)
: LinearFVKernel(params),
MooseVariableInterface(this,
false,
"variable",
Moose::VarKindType::VAR_NONLINEAR,
Moose::VarFieldType::VAR_FIELD_STANDARD),
_current_elem_info(nullptr),
_var(*mooseVariableFV())
{
}

void
ElementalLinearFVKernel::addMatrixContribution()
{
const auto dof_id = _current_elem_info->dofIndices()[_var.sys().number()][_var.number()];
(*_linear_system.matrix).add(dof_id, dof_id, computeMatrixContribution());
}

void
ElementalLinearFVKernel::addRightHandSideContribution()
{
const auto dof_id = _current_elem_info->dofIndices()[_var.sys().number()][_var.number()];
(*_linear_system.rhs).add(dof_id, computeRightHandSideContribution());
}
15 changes: 14 additions & 1 deletion framework/src/linearfvkernels/LinearFVReactionKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ InputParameters
LinearFVReactionKernel::validParams()
{
InputParameters params = ElementalLinearFVKernel::validParams();
params.addParam<Real>("coeff", 1.0, "The reaction coefficient.");
return params;
}

LinearFVReactionKernel::LinearFVReactionKernel(const InputParameters & params)
: ElementalLinearFVKernel(params)
: ElementalLinearFVKernel(params), _coeff(getParam<Real>("coeff"))
{
}

Real
LinearFVReactionKernel::computeMatrixContribution()
{
return _coeff * _current_elem_info->volume();
}

Real
LinearFVReactionKernel::computeRightHandSideContribution()
{
return 0.0;
}
15 changes: 14 additions & 1 deletion framework/src/linearfvkernels/LinearFVSourceKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ InputParameters
LinearFVSourceKernel::validParams()
{
InputParameters params = ElementalLinearFVKernel::validParams();
params.addParam<Real>("source_density", 1.0, "The source density.");
return params;
}

LinearFVSourceKernel::LinearFVSourceKernel(const InputParameters & params)
: ElementalLinearFVKernel(params)
: ElementalLinearFVKernel(params), _source_density(getParam<Real>("source_density"))
{
}

Real
LinearFVSourceKernel::computeMatrixContribution()
{
return 0.0;
}

Real
LinearFVSourceKernel::computeRightHandSideContribution()
{
return _source_density * _current_elem_info->volume();
}

0 comments on commit 743e1a9

Please sign in to comment.