Skip to content

Commit

Permalink
add coupled local dofs into moose variable and coupleable idaholab#9690
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Sep 6, 2017
1 parent 38e4c1e commit 45a1746
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 2 deletions.
32 changes: 32 additions & 0 deletions framework/include/base/Coupleable.h
Expand Up @@ -22,6 +22,11 @@
class InputParameters;
class MooseVariable;
class MooseObject;
namespace libMesh
{
template <typename T>
class DenseVector;
}

/**
* Interface for objects that needs coupling capabilities
Expand Down Expand Up @@ -278,6 +283,33 @@ class Coupleable
virtual const VariableValue & coupledNodalDot(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns DoFs in the current solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a DenseVector for the DoFs of the coupled variable
*/
virtual const DenseVector<Number> & coupledSolutionDoFs(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns DoFs in the old solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a DenseVector for the old DoFs of the coupled variable
*/
virtual const DenseVector<Number> & coupledSolutionDoFsOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns DoFs in the older solution vector of a coupled variable for the local element
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a DenseVector for the older DoFs of the coupled variable
*/
virtual const DenseVector<Number> & coupledSolutionDoFsOlder(const std::string & var_name,
unsigned int comp = 0);

protected:
// Reference to the interface's input parameters
const InputParameters & _c_parameters;
Expand Down
49 changes: 47 additions & 2 deletions framework/include/base/MooseVariable.h
Expand Up @@ -31,10 +31,10 @@ class Node;
class QBase;
template <typename T>
class NumericVector;
template <typename T>
class DenseVector;
}

#include "libmesh/dense_vector.h"

/**
* Class for stuff related to variables
*
Expand Down Expand Up @@ -292,6 +292,36 @@ class MooseVariable : public MooseVariableBase
}
const VariableValue & nodalSlnDotNeighbor() { return _nodal_u_dot_neighbor; }
const VariableValue & nodalSlnDuDotDuNeighbor() { return _nodal_du_dot_du_neighbor; }
const DenseVector<Number> & solutionDoFs()
{
_need_solution_dofs = true;
return _solution_dofs;
}
const DenseVector<Number> & solutionDoFsOld()
{
_need_solution_dofs_old = true;
return _solution_dofs_old;
}
const DenseVector<Number> & solutionDoFsOlder()
{
_need_solution_dofs_older = true;
return _solution_dofs_older;
}
const DenseVector<Number> & solutionDoFsNeighbor()
{
_need_solution_dofs_neighbor = true;
return _solution_dofs_neighbor;
}
const DenseVector<Number> & solutionDoFsOldNeighbor()
{
_need_solution_dofs_old_neighbor = true;
return _solution_dofs_old_neighbor;
}
const DenseVector<Number> & solutionDoFsOlderNeighbor()
{
_need_solution_dofs_older_neighbor = true;
return _solution_dofs_older_neighbor;
}

/**
* Compute values at interior quadrature points
Expand Down Expand Up @@ -488,6 +518,13 @@ class MooseVariable : public MooseVariableBase
bool _need_nodal_u_previous_nl_neighbor;
bool _need_nodal_u_dot_neighbor;

bool _need_solution_dofs;
bool _need_solution_dofs_old;
bool _need_solution_dofs_older;
bool _need_solution_dofs_neighbor;
bool _need_solution_dofs_old_neighbor;
bool _need_solution_dofs_older_neighbor;

// Shape function values, gradients. second derivatives
const VariablePhiValue & _phi;
const VariablePhiGradient & _grad_phi;
Expand Down Expand Up @@ -577,6 +614,14 @@ class MooseVariable : public MooseVariableBase
VariableValue _nodal_u_dot_neighbor;
VariableValue _nodal_du_dot_du_neighbor;

/// local elemental DoFs
DenseVector<Number> _solution_dofs;
DenseVector<Number> _solution_dofs_old;
DenseVector<Number> _solution_dofs_older;
DenseVector<Number> _solution_dofs_neighbor;
DenseVector<Number> _solution_dofs_old_neighbor;
DenseVector<Number> _solution_dofs_older_neighbor;

/// if variable is nodal
bool _is_nodal;

Expand Down
7 changes: 7 additions & 0 deletions framework/include/base/NeighborCoupleable.h
Expand Up @@ -52,6 +52,13 @@ class NeighborCoupleable : public Coupleable
virtual const VariableSecond & coupledNeighborSecond(const std::string & var_name,
unsigned int i = 0);

virtual const DenseVector<Number> & coupledNeighborSolutionDoFs(const std::string & var_name,
unsigned int comp = 0);
virtual const DenseVector<Number> & coupledNeighborSolutionDoFsOld(const std::string & var_name,
unsigned int comp = 0);
virtual const DenseVector<Number> & coupledNeighborSolutionDoFsOlder(const std::string & var_name,
unsigned int comp = 0);

protected:
bool _neighbor_nodal;
};
Expand Down
63 changes: 63 additions & 0 deletions framework/src/base/Coupleable.C
Expand Up @@ -579,6 +579,69 @@ Coupleable::coupledNodalDot(const std::string & var_name, unsigned int comp)
return var->nodalValueDotNeighbor();
}

const DenseVector<Number> &
Coupleable::coupledSolutionDoFs(const std::string & var_name, unsigned int comp)
{
// default coupling is not available for elemental solutions
if (!isCoupled(var_name))
mooseError("invalid variable name for coupledSolutionDoFs");

if (_nodal)
mooseError("nodal objects should not call coupledSolutionDoFs");

coupledCallback(var_name, false);
MooseVariable * var = getVar(var_name, comp);

if (!_coupleable_neighbor)
return (_c_is_implicit) ? var->solutionDoFs() : var->solutionDoFsOld();
else
return (_c_is_implicit) ? var->solutionDoFsNeighbor() : var->solutionDoFsOldNeighbor();
}

const DenseVector<Number> &
Coupleable::coupledSolutionDoFsOld(const std::string & var_name, unsigned int comp)
{
// default coupling is not available for elemental solutions
if (!isCoupled(var_name))
mooseError("invalid variable name for coupledSolutionDoFsOld");

if (_nodal)
mooseError("nodal objects should not call coupledSolutionDoFsOld");

validateExecutionerType(var_name);
coupledCallback(var_name, true);
MooseVariable * var = getVar(var_name, comp);

if (!_coupleable_neighbor)
return (_c_is_implicit) ? var->solutionDoFsOld() : var->solutionDoFsOlder();
else
return (_c_is_implicit) ? var->solutionDoFsOldNeighbor() : var->solutionDoFsOlderNeighbor();
}

const DenseVector<Number> &
Coupleable::coupledSolutionDoFsOlder(const std::string & var_name, unsigned int comp)
{
// default coupling is not available for elemental solutions
if (!isCoupled(var_name))
mooseError("invalid variable name for coupledSolutionDoFsOlder");

if (_nodal)
mooseError("nodal objects should not call coupledSolutionDoFsOlder");

validateExecutionerType(var_name);
coupledCallback(var_name, true);
MooseVariable * var = getVar(var_name, comp);
if (_c_is_implicit)
{
if (!_coupleable_neighbor)
return var->solutionDoFsOlder();
else
return var->solutionDoFsOlderNeighbor();
}
else
mooseError("Older values not available for explicit schemes");
}

void
Coupleable::validateExecutionerType(const std::string & name) const
{
Expand Down
78 changes: 78 additions & 0 deletions framework/src/base/MooseVariable.C
Expand Up @@ -951,6 +951,15 @@ MooseVariable::computeElemValues()
_nodal_u_dot.resize(num_dofs);
}

if (_need_solution_dofs)
_solution_dofs.resize(num_dofs);

if (_need_solution_dofs_old)
_solution_dofs_old.resize(num_dofs);

if (_need_solution_dofs_older)
_solution_dofs_older.resize(num_dofs);

const NumericVector<Real> & current_solution = *_sys.currentSolution();
const NumericVector<Real> & solution_old = _sys.solutionOld();
const NumericVector<Real> & solution_older = _sys.solutionOlder();
Expand Down Expand Up @@ -996,6 +1005,9 @@ MooseVariable::computeElemValues()
if (_need_nodal_u_previous_nl)
_nodal_u_previous_nl[i] = soln_previous_nl_local;

if (_need_solution_dofs)
_solution_dofs(i) = soln_local;

if (is_transient)
{
if (_need_u_old || _need_grad_old || _need_second_old || _need_nodal_u_old)
Expand All @@ -1012,6 +1024,12 @@ MooseVariable::computeElemValues()
u_dot_local = u_dot(idx);
if (_need_nodal_u_dot)
_nodal_u_dot[i] = u_dot_local;

if (_need_solution_dofs_old)
_solution_dofs_old(i) = solution_old(idx);

if (_need_solution_dofs_older)
_solution_dofs_older(i) = solution_older(idx);
}

for (unsigned int qp = 0; qp < nqp; qp++)
Expand Down Expand Up @@ -1197,6 +1215,15 @@ MooseVariable::computeElemValuesFace()
_nodal_u_dot.resize(num_dofs);
}

if (_need_solution_dofs)
_solution_dofs.resize(num_dofs);

if (_need_solution_dofs_old)
_solution_dofs_old.resize(num_dofs);

if (_need_solution_dofs_older)
_solution_dofs_older.resize(num_dofs);

const NumericVector<Real> & current_solution = *_sys.currentSolution();
const NumericVector<Real> & solution_old = _sys.solutionOld();
const NumericVector<Real> & solution_older = _sys.solutionOlder();
Expand Down Expand Up @@ -1229,6 +1256,9 @@ MooseVariable::computeElemValuesFace()
if (_need_nodal_u_previous_nl)
_nodal_u_previous_nl[i] = soln_previous_nl_local;

if (_need_solution_dofs)
_solution_dofs(i) = soln_local;

if (is_transient)
{
if (_need_u_old || _need_grad_old || _need_second_old || _need_nodal_u_old)
Expand All @@ -1245,6 +1275,12 @@ MooseVariable::computeElemValuesFace()
u_dot_local = u_dot(idx);
if (_need_nodal_u_dot)
_nodal_u_dot[i] = u_dot_local;

if (_need_solution_dofs_old)
_solution_dofs_old(i) = solution_old(idx);

if (_need_solution_dofs_older)
_solution_dofs_older(i) = solution_older(idx);
}

for (unsigned int qp = 0; qp < nqp; ++qp)
Expand Down Expand Up @@ -1380,6 +1416,15 @@ MooseVariable::computeNeighborValuesFace()
_nodal_u_dot_neighbor.resize(num_dofs);
}

if (_need_solution_dofs_neighbor)
_solution_dofs_neighbor.resize(num_dofs);

if (_need_solution_dofs_old_neighbor)
_solution_dofs_old_neighbor.resize(num_dofs);

if (_need_solution_dofs_older_neighbor)
_solution_dofs_older_neighbor.resize(num_dofs);

const NumericVector<Real> & current_solution = *_sys.currentSolution();
const NumericVector<Real> & solution_old = _sys.solutionOld();
const NumericVector<Real> & solution_older = _sys.solutionOlder();
Expand All @@ -1401,6 +1446,12 @@ MooseVariable::computeNeighborValuesFace()
idx = _dof_indices_neighbor[i];
soln_local = current_solution(idx);

if (_need_nodal_u_neighbor)
_nodal_u_neighbor[i] = soln_local;

if (_need_solution_dofs_neighbor)
_solution_dofs_neighbor(i) = soln_local;

if (is_transient)
{
if (_need_u_old_neighbor || _need_grad_old_neighbor || _need_second_old_neighbor)
Expand All @@ -1417,6 +1468,12 @@ MooseVariable::computeNeighborValuesFace()
u_dot_local = u_dot(idx);
if (_need_nodal_u_dot_neighbor)
_nodal_u_dot_neighbor[i] = u_dot_local;

if (_need_solution_dofs_old_neighbor)
_solution_dofs_old_neighbor(i) = solution_old(idx);

if (_need_solution_dofs_older_neighbor)
_solution_dofs_older_neighbor(i) = solution_older(idx);
}

for (unsigned int qp = 0; qp < nqp; ++qp)
Expand Down Expand Up @@ -1537,6 +1594,15 @@ MooseVariable::computeNeighborValues()
_nodal_u_dot_neighbor.resize(num_dofs);
}

if (_need_solution_dofs_neighbor)
_solution_dofs_neighbor.resize(num_dofs);

if (_need_solution_dofs_old_neighbor)
_solution_dofs_old_neighbor.resize(num_dofs);

if (_need_solution_dofs_older_neighbor)
_solution_dofs_older_neighbor.resize(num_dofs);

const NumericVector<Real> & current_solution = *_sys.currentSolution();
const NumericVector<Real> & solution_old = _sys.solutionOld();
const NumericVector<Real> & solution_older = _sys.solutionOlder();
Expand All @@ -1557,6 +1623,12 @@ MooseVariable::computeNeighborValues()
idx = _dof_indices_neighbor[i];
soln_local = current_solution(idx);

if (_need_nodal_u_neighbor)
_nodal_u_neighbor[i] = soln_local;

if (_need_solution_dofs_neighbor)
_solution_dofs_neighbor(i) = soln_local;

if (is_transient)
{
if (_need_u_old_neighbor)
Expand All @@ -1573,6 +1645,12 @@ MooseVariable::computeNeighborValues()
u_dot_local = u_dot(idx);
if (_need_nodal_u_dot_neighbor)
_nodal_u_dot_neighbor[i] = u_dot_local;

if (_need_solution_dofs_old_neighbor)
_solution_dofs_old_neighbor(i) = solution_old(idx);

if (_need_solution_dofs_older_neighbor)
_solution_dofs_older_neighbor(i) = solution_older(idx);
}

for (unsigned int qp = 0; qp < nqp; ++qp)
Expand Down

0 comments on commit 45a1746

Please sign in to comment.