Skip to content

Commit

Permalink
add residual object base class idaholab#13609
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang authored and lindsayad committed Nov 11, 2020
1 parent 2d64172 commit b543657
Show file tree
Hide file tree
Showing 61 changed files with 351 additions and 762 deletions.
122 changes: 122 additions & 0 deletions framework/include/base/ResidualObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//* 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

#pragma once

#include "MooseObject.h"
#include "SetupInterface.h"
#include "CoupleableMooseVariableDependencyIntermediateInterface.h"
#include "FunctionInterface.h"
#include "UserObjectInterface.h"
#include "TransientInterface.h"
#include "PostprocessorInterface.h"
#include "VectorPostprocessorInterface.h"
#include "RandomInterface.h"
#include "Restartable.h"
#include "MeshChangedInterface.h"
#include "TaggingInterface.h"

class MooseMesh;
class SubProblem;
class KernelBase;
class Assembly;
template <typename>
class MooseVariableFE;
typedef MooseVariableFE<Real> MooseVariable;
typedef MooseVariableFE<VectorValue<Real>> VectorMooseVariable;
typedef MooseVariableFE<RealEigenVector> ArrayMooseVariable;

/**
* This is the common base class for objects that give residual contributions.
*/
class ResidualObject : public MooseObject,
public SetupInterface,
public FunctionInterface,
public UserObjectInterface,
public TransientInterface,
public PostprocessorInterface,
public VectorPostprocessorInterface,
public RandomInterface,
public Restartable,
public MeshChangedInterface,
public TaggingInterface
{
public:
static InputParameters validParams();

/**
* Class constructor.
* @param parameters The InputParameters for the object
* @param nodal Whether this object is applied to nodes or not
*/
ResidualObject(const InputParameters & parameters, bool nodal = false);

/// Compute this object's contribution to the residual
virtual void computeResidual() = 0;

/// Compute this object's contribution to the diagonal Jacobian entries
virtual void computeJacobian() = 0;

/**
* Computes Jacobian block of the variable of this object with respect to a field variable
* @param jvar The field variable
*/
virtual void computeOffDiagJacobian(MooseVariableFEBase & /*jvar*/) {}

/**
* Computes jacobian block with respect to a scalar variable
* @param jvar The number of the scalar variable
*/
virtual void computeOffDiagJacobianScalar(unsigned int /*jvar*/) {}

/**
* Compute this object's contribution to the diagonal Jacobian entries
* corresponding to nonlocal dofs of the variable
*/
virtual void computeNonlocalJacobian() {}

/**
* Computes Jacobian entries corresponding to nonlocal dofs of the jvar
*/
virtual void computeNonlocalOffDiagJacobian(unsigned int /* jvar */) {}

/**
* Returns the variable that this object operates on.
*/
virtual const MooseVariableBase & variable() const = 0;

/**
* Returns a reference to the SubProblem for which this Kernel is active
*/
SubProblem & subProblem() { return _subproblem; }

protected:
virtual void precalculateResidual() {}
virtual void precalculateJacobian() {}
virtual void precalculateOffDiagJacobian(unsigned int /* jvar */) {}

protected:
/// Reference to this kernel's SubProblem
SubProblem & _subproblem;

/// Reference to this kernel's FEProblemBase
FEProblemBase & _fe_problem;

/// Reference to the EquationSystem object
SystemBase & _sys;

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

/// Reference to this Kernel's assembly object
Assembly & _assembly;

/// Reference to this Kernel's mesh object
MooseMesh & _mesh;
};
2 changes: 1 addition & 1 deletion framework/include/bcs/ADIntegratedBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ADIntegratedBCTempl : public IntegratedBCBase, public MooseVariableInterfa

ADIntegratedBCTempl(const InputParameters & parameters);

MooseVariableFE<T> & variable() override { return _var; }
const MooseVariableFE<T> & variable() const override { return _var; }

private:
void computeJacobian() override final;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/ADNodalBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ADNodalBCTempl : public NodalBCBase, public MooseVariableInterface<T>

ADNodalBCTempl(const InputParameters & parameters);

MooseVariableFE<T> & variable() override { return _var; }
const MooseVariableFE<T> & variable() const override { return _var; }

private:
void computeResidual() override final;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/ArrayIntegratedBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ArrayIntegratedBC : public IntegratedBCBase, public MooseVariableInterface

ArrayIntegratedBC(const InputParameters & parameters);

virtual ArrayMooseVariable & variable() override { return _var; }
virtual const ArrayMooseVariable & variable() const override { return _var; }

virtual void computeResidual() override;
virtual void computeJacobian() override;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/ArrayNodalBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ArrayNodalBC : public NodalBCBase, public MooseVariableInterface<RealEigen
* Gets the variable this BC is active on
* @return the variable
*/
virtual ArrayMooseVariable & variable() override { return _var; }
virtual const ArrayMooseVariable & variable() const override { return _var; }
virtual void computeResidual() override;
virtual void computeJacobian() override;
virtual void computeOffDiagJacobian(unsigned int jvar) override;
Expand Down
65 changes: 3 additions & 62 deletions framework/include/bcs/BoundaryCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,24 @@
#pragma once

// MOOSE
#include "MooseObject.h"
#include "SetupInterface.h"
#include "ResidualObject.h"
#include "ParallelUniqueId.h"
#include "FunctionInterface.h"
#include "DistributionInterface.h"
#include "UserObjectInterface.h"
#include "TransientInterface.h"
#include "PostprocessorInterface.h"
#include "VectorPostprocessorInterface.h"
#include "GeometricSearchInterface.h"
#include "BoundaryRestrictableRequired.h"
#include "Restartable.h"
#include "MeshChangedInterface.h"
#include "TaggingInterface.h"

// Forward declerations
template <typename>
class MooseVariableFE;
typedef MooseVariableFE<Real> MooseVariable;
typedef MooseVariableFE<VectorValue<Real>> VectorMooseVariable;
class MooseMesh;
class Problem;
class SubProblem;
class SystemBase;
class BoundaryCondition;
class Assembly;

template <>
InputParameters validParams<BoundaryCondition>();

/**
* Base class for creating new types of boundary conditions.
*/
class BoundaryCondition : public MooseObject,
class BoundaryCondition : public ResidualObject,
public BoundaryRestrictableRequired,
public SetupInterface,
public FunctionInterface,
public DistributionInterface,
public UserObjectInterface,
public TransientInterface,
public PostprocessorInterface,
public VectorPostprocessorInterface,
public GeometricSearchInterface,
public Restartable,
public MeshChangedInterface,
public TaggingInterface
public GeometricSearchInterface
{
public:
/**
Expand All @@ -67,18 +39,6 @@ class BoundaryCondition : public MooseObject,

static InputParameters validParams();

/**
* Get a reference to the MooseVariableFE
* @return Reference to MooseVariableFE
*/
virtual MooseVariableFEBase & variable() = 0;

/**
* Get a reference to the subproblem
* @return Reference to SubProblem
*/
SubProblem & subProblem() { return _subproblem; }

/**
* Hook for turning the boundary condition on and off.
*
Expand All @@ -91,23 +51,4 @@ class BoundaryCondition : public MooseObject,
* @return true if the boundary condition should be applied, otherwise false
*/
virtual bool shouldApply() { return true; }

protected:
/// Reference to SubProblem
SubProblem & _subproblem;

/// Reference to FEProblemBase
FEProblemBase & _fe_problem;

/// Reference to SystemBase
SystemBase & _sys;

/// Thread id
THREAD_ID _tid;

/// Reference to assembly
Assembly & _assembly;

/// Mesh this BC is defined on
MooseMesh & _mesh;
};
2 changes: 1 addition & 1 deletion framework/include/bcs/IntegratedBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IntegratedBC : public IntegratedBCBase, public MooseVariableInterface<Real

IntegratedBC(const InputParameters & parameters);

virtual MooseVariable & variable() override { return _var; }
virtual const MooseVariable & variable() const override { return _var; }

virtual void computeResidual() override;
virtual void computeJacobian() override;
Expand Down
22 changes: 0 additions & 22 deletions framework/include/bcs/IntegratedBCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
#pragma once

#include "BoundaryCondition.h"
#include "RandomInterface.h"
#include "CoupleableMooseVariableDependencyIntermediateInterface.h"
#include "MaterialPropertyInterface.h"

// Forward declarations
class IntegratedBCBase;
template <typename>
class MooseVariableFE;
typedef MooseVariableFE<Real> MooseVariable;
typedef MooseVariableFE<VectorValue<Real>> VectorMooseVariable;

template <>
InputParameters validParams<IntegratedBCBase>();
Expand All @@ -28,7 +23,6 @@ InputParameters validParams<IntegratedBCBase>();
* Base class for deriving any boundary condition of a integrated type
*/
class IntegratedBCBase : public BoundaryCondition,
public RandomInterface,
public CoupleableMooseVariableDependencyIntermediateInterface,
public MaterialPropertyInterface
{
Expand All @@ -37,10 +31,6 @@ class IntegratedBCBase : public BoundaryCondition,

IntegratedBCBase(const InputParameters & parameters);

virtual ~IntegratedBCBase();

virtual void computeResidual() = 0;
virtual void computeJacobian() = 0;
/**
* Computes d-ivar-residual / d-jvar...
*/
Expand All @@ -51,18 +41,6 @@ class IntegratedBCBase : public BoundaryCondition,
*/
virtual void computeJacobianBlockScalar(unsigned int jvar) = 0;

/**
* Compute this IntegratedBCBase's contribution to the diagonal Jacobian entries
* corresponding to nonlocal dofs of the variable
*/
virtual void computeNonlocalJacobian() {}

/**
* Computes d-residual / d-jvar... corresponding to nonlocal dofs of the jvar
* and stores the result in nonlocal ke
*/
virtual void computeNonlocalOffDiagJacobian(unsigned int /* jvar */) {}

protected:
/// current element
const Elem * const & _current_elem;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/NodalBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NodalBC : public NodalBCBase, public MooseVariableInterface<Real>
* Gets the variable this BC is active on
* @return the variable
*/
virtual MooseVariable & variable() override { return _var; }
virtual const MooseVariable & variable() const override { return _var; }
virtual void computeResidual() override;
virtual void computeJacobian() override;
virtual void computeOffDiagJacobian(unsigned int jvar) override;
Expand Down
9 changes: 5 additions & 4 deletions framework/include/bcs/NodalBCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ InputParameters validParams<NodalBCBase>();
* Base class for deriving any boundary condition that works at nodes
*/
class NodalBCBase : public BoundaryCondition,
public RandomInterface,
public CoupleableMooseVariableDependencyIntermediateInterface
{
public:
static InputParameters validParams();

NodalBCBase(const InputParameters & parameters);

virtual void computeResidual() = 0;
virtual void computeJacobian() = 0;
virtual void computeOffDiagJacobian(MooseVariableFEBase & jvar) override
{
computeOffDiagJacobian(jvar.number());
}
virtual void computeOffDiagJacobian(unsigned int jvar) = 0;

/**
* Compute the off-diagonal contributions from scalar variables
*/
virtual void computeOffDiagJacobianScalar(unsigned int /*jvar*/) {}
virtual void computeOffDiagJacobianScalar(unsigned int /*jvar*/) override {}

/**
* Whether to verify that this object is acting on a nodal variable
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/VectorIntegratedBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VectorIntegratedBC : public IntegratedBCBase, public MooseVariableInterfac

VectorIntegratedBC(const InputParameters & parameters);

virtual VectorMooseVariable & variable() override { return _var; }
virtual const VectorMooseVariable & variable() const override { return _var; }

virtual void computeResidual() override;
virtual void computeJacobian() override;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/bcs/VectorNodalBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VectorNodalBC : public NodalBCBase, public MooseVariableInterface<RealVect
* Gets the variable this BC is active on
* @return the variable
*/
virtual VectorMooseVariable & variable() override { return _var; }
virtual const VectorMooseVariable & variable() const override { return _var; }
virtual void computeResidual() override;
virtual void computeJacobian() override;
virtual void computeOffDiagJacobian(unsigned int jvar) override;
Expand Down
Loading

0 comments on commit b543657

Please sign in to comment.