Skip to content

Commit

Permalink
a compilable stage with variable, coupleable, assembly and systems ex…
Browse files Browse the repository at this point in the history
…tended to array variable idaholab#6881
  • Loading branch information
YaqiWang committed Jul 7, 2019
1 parent 183d9b9 commit 9aafb0d
Show file tree
Hide file tree
Showing 31 changed files with 1,866 additions and 459 deletions.
26 changes: 25 additions & 1 deletion framework/include/base/Assembly.h
Expand Up @@ -52,6 +52,7 @@ class MooseVariableFE;
class MooseVariableScalar;
typedef MooseVariableFE<Real> MooseVariable;
typedef MooseVariableFE<RealVectorValue> VectorMooseVariable;
typedef MooseVariableFE<RealArrayValue> ArrayMooseVariable;
class XFEMInterface;
class SubProblem;

Expand Down Expand Up @@ -905,6 +906,7 @@ class Assembly
return _second_phi_face_neighbor;
}

// Writeable references with vector variable
VectorVariablePhiValue & phi(const VectorMooseVariable &) { return _vector_phi; }
VectorVariablePhiGradient & gradPhi(const VectorMooseVariable &) { return _vector_grad_phi; }
VectorVariablePhiSecond & secondPhi(const VectorMooseVariable &) { return _vector_second_phi; }
Expand Down Expand Up @@ -934,7 +936,6 @@ class Assembly
{
return _vector_curl_phi_neighbor;
}

VectorVariablePhiValue & phiFaceNeighbor(const VectorMooseVariable &)
{
return _vector_phi_face_neighbor;
Expand All @@ -952,6 +953,29 @@ class Assembly
return _vector_curl_phi_face_neighbor;
}

// Writeable references with array variable
VariablePhiValue & phi(const ArrayMooseVariable &) { return _phi; }
VariablePhiGradient & gradPhi(const ArrayMooseVariable &) { return _grad_phi; }
VariablePhiSecond & secondPhi(const ArrayMooseVariable &) { return _second_phi; }

VariablePhiValue & phiFace(const ArrayMooseVariable &) { return _phi_face; }
VariablePhiGradient & gradPhiFace(const ArrayMooseVariable &) { return _grad_phi_face; }
VariablePhiSecond & secondPhiFace(const ArrayMooseVariable &) { return _second_phi_face; }

VariablePhiValue & phiNeighbor(const ArrayMooseVariable &) { return _phi_neighbor; }
VariablePhiGradient & gradPhiNeighbor(const ArrayMooseVariable &) { return _grad_phi_neighbor; }
VariablePhiSecond & secondPhiNeighbor(const ArrayMooseVariable &) { return _second_phi_neighbor; }

VariablePhiValue & phiFaceNeighbor(const ArrayMooseVariable &) { return _phi_face_neighbor; }
VariablePhiGradient & gradPhiFaceNeighbor(const ArrayMooseVariable &)
{
return _grad_phi_face_neighbor;
}
VariablePhiSecond & secondPhiFaceNeighbor(const ArrayMooseVariable &)
{
return _second_phi_face_neighbor;
}

template <typename OutputType>
const typename OutputTools<OutputType>::VariablePhiValue & fePhi(FEType type) const
{
Expand Down
184 changes: 165 additions & 19 deletions framework/include/interfaces/Coupleable.h
Expand Up @@ -110,6 +110,15 @@ class Coupleable
return _coupled_vector_moose_vars;
}

/**
* Get the list of array coupled variables
* @return The list of array coupled variables
*/
const std::vector<ArrayMooseVariable *> & getCoupledArratMooseVars() const
{
return _coupled_array_moose_vars;
}

void addFEVariableCoupleableVectorTag(TagID tag) { _fe_coupleable_vector_tags.insert(tag); }

void addFEVariableCoupleableMatrixTag(TagID tag) { _fe_coupleable_matrix_tags.insert(tag); }
Expand All @@ -119,6 +128,12 @@ class Coupleable
std::set<TagID> & getFEVariableCoupleableMatrixTags() { return _fe_coupleable_matrix_tags; }

protected:
/**
* A call-back function provided by the derived object for actions before coupling a variable
* with functions such as coupledValue.
*/
virtual void coupledCallback(const std::string & /*var_name*/, bool /*is_old*/) {}

/**
* Returns true if a variables has been coupled as name.
* @param var_name The name the kernel wants to refer to the variable as.
Expand All @@ -134,8 +149,6 @@ class Coupleable
*/
unsigned int coupledComponents(const std::string & var_name);

virtual void coupledCallback(const std::string & var_name, bool is_old);

/**
* Returns the index for a coupled variable by name
* @param var_name Name of coupled variable
Expand Down Expand Up @@ -208,6 +221,16 @@ class Coupleable
virtual const VectorVariableValue & coupledVectorValue(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns value of a coupled array variable
* @param var_name Name of coupled vector variable
* @param comp Component number for vector of coupled vector variables
* @return Reference to a ArrayVariableValue for the coupled vector variable
* @see ArrayKernel::_u
*/
virtual const ArrayVariableValue & coupledArrayValue(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns a *writable* reference to a coupled variable. Note: you
* should not have to use this very often (use coupledValue()
Expand Down Expand Up @@ -254,7 +277,7 @@ class Coupleable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableValue containing the old value of the coupled variable
* @see Kernel::_u_old
* @see VectorKernel::_u_old
*/
virtual const VectorVariableValue & coupledVectorValueOld(const std::string & var_name,
unsigned int comp = 0);
Expand All @@ -264,11 +287,31 @@ class Coupleable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a VectorVariableValue containing the older value of the coupled variable
* @see Kernel::_u_older
* @see VectorKernel::_u_older
*/
virtual const VectorVariableValue & coupledVectorValueOlder(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns an old value from previous time step of a coupled array variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a ArrayVariableValue containing the old value of the coupled variable
* @see ArrayKernel::_u_old
*/
virtual const ArrayVariableValue & coupledArrayValueOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns an old value from two time steps previous of a coupled array variable
* @param var_name Name of coupled variable
* @param comp Component number for vector of coupled variables
* @return Reference to a ArrayVariableValue containing the older value of the coupled variable
* @see ArrayKernel::_u_older
*/
virtual const ArrayVariableValue & coupledArrayValueOlder(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns gradient of a coupled variable
* @param var_name Name of coupled variable
Expand Down Expand Up @@ -401,6 +444,36 @@ class Coupleable
virtual const VectorVariableGradient & coupledVectorGradientOlder(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns gradient of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a VectorVariableGradient containing the gradient of the coupled array
* variable
*/
virtual const ArrayVariableGradient & coupledArrayGradient(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns an old gradient from previous time step of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a VectorVariableGradient containing the old gradient of the coupled array
* variable
*/
virtual const ArrayVariableGradient & coupledArrayGradientOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns an old gradient from two time steps previous of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a ArrayVariableGradient containing the older gradient of the coupled
* array variable
*/
virtual const ArrayVariableGradient & coupledArrayGradientOlder(const std::string & var_name,
unsigned int comp = 0);

/**
* Returns curl of a coupled variable
* @param var_name Name of coupled variable
Expand Down Expand Up @@ -566,6 +639,46 @@ class Coupleable
virtual const VectorVariableValue & coupledVectorDotDotOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Time derivative of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a ArrayVariableValue containing the time derivative of the coupled
* variable
*/
virtual const ArrayVariableValue & coupledArrayDot(const std::string & var_name,
unsigned int comp = 0);

/**
* Second time derivative of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a ArrayVariableValue containing the time derivative of the coupled
* variable
*/
virtual const ArrayVariableValue & coupledArrayDotDot(const std::string & var_name,
unsigned int comp = 0);

/**
* Old time derivative of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a ArrayVariableValue containing the time derivative of the coupled
* variable
*/
virtual const ArrayVariableValue & coupledArrayDotOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Old second time derivative of a coupled array variable
* @param var_name Name of coupled array variable
* @param comp Component number for vector of coupled array variables
* @return Reference to a ArrayVariableValue containing the time derivative of the coupled
* variable
*/
virtual const ArrayVariableValue & coupledArrayDotDotOld(const std::string & var_name,
unsigned int comp = 0);

/**
* Time derivative of a coupled variable with respect to the coefficients
* @param var_name Name of coupled variable
Expand Down Expand Up @@ -641,12 +754,6 @@ class Coupleable
template <typename T>
const T & coupledNodalDot(const std::string & var_name, unsigned int comp = 0);

/**
* Get nodal default value
*/
template <typename T>
const T & getNodalDefaultValue(const std::string & var_name, unsigned int comp = 0);

/**
* Nodal values of second time derivative of a coupled variable
* @param var_name Name of coupled variable
Expand Down Expand Up @@ -745,6 +852,9 @@ class Coupleable
/// Vector of vector coupled variables
std::vector<VectorMooseVariable *> _coupled_vector_moose_vars;

/// Vector of array coupled variables
std::vector<ArrayMooseVariable *> _coupled_array_moose_vars;

/// True if we provide coupling to nodal values
bool _c_nodal;

Expand All @@ -763,6 +873,9 @@ class Coupleable
/// Will hold the default value for optional vector coupled variables.
std::map<std::string, VectorVariableValue *> _default_vector_value;

/// Will hold the default value for optional array coupled variables.
std::map<std::string, ArrayVariableValue *> _default_array_value;

/// Will hold the default value for optional vector coupled variables for automatic differentiation.
std::map<std::string, MooseArray<DualRealVectorValue> *> _ad_default_vector_value;

Expand Down Expand Up @@ -817,6 +930,18 @@ class Coupleable
/// This will always be zero because the default values for optionally coupled variables is always constant
VectorVariableCurl _default_vector_curl;

/**
* This will always be zero because the default values for optionally coupled variables is always
* constant and this is used for time derivative info
*/
ArrayVariableValue _default_array_value_zero;

/// This will always be zero because the default values for optionally coupled variables is always constant
ArrayVariableGradient _default_array_gradient;

/// This will always be zero because the default values for optionally coupled variables is always constant
ArrayVariableCurl _default_array_curl;

/**
* Check that the right kind of variable is being coupled in
*
Expand Down Expand Up @@ -854,6 +979,14 @@ class Coupleable
*/
VectorMooseVariable * getVectorVar(const std::string & var_name, unsigned int comp);

/**
* Extract pointer to a coupled array variable
* @param var_name Name of parameter desired
* @param comp Component number of multiple coupled variables
* @return Pointer to the desired variable
*/
ArrayMooseVariable * getArrayVar(const std::string & var_name, unsigned int comp);

/**
* Checks to make sure that the current Executioner has set "_is_transient" when old/older values
* are coupled in.
Expand All @@ -865,15 +998,6 @@ class Coupleable
/// Whether or not this object is a "neighbor" object: ie all of it's coupled values should be neighbor values
bool _coupleable_neighbor;

private:
/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default value
* @return a pointer to the associated VariableValue.
*/
VariableValue * getDefaultValue(const std::string & var_name, unsigned int comp);

public:
/**
* Helper method to return (and insert if necessary) the default value for Automatic
Expand Down Expand Up @@ -921,6 +1045,14 @@ class Coupleable
ADVariableSecond & getADDefaultSecond();

private:
/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled variable.
* @param var_name the name of the variable for which to retrieve a default value
* @return a pointer to the associated VariableValue.
*/
VariableValue * getDefaultValue(const std::string & var_name, unsigned int comp);

/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled vector variable.
Expand All @@ -929,6 +1061,20 @@ class Coupleable
*/
VectorVariableValue * getDefaultVectorValue(const std::string & var_name);

/**
* Helper method to return (and insert if necessary) the default value
* for an uncoupled array variable.
* @param var_name the name of the vector variable for which to retrieve a default value
* @return a pointer to the associated VectorVariableValue.
*/
ArrayVariableValue * getDefaultArrayValue(const std::string & var_name);

/**
* Get nodal default value
*/
template <typename T>
const T & getNodalDefaultValue(const std::string & var_name, unsigned int comp = 0);

/// Maximum qps for any element in this system
unsigned int _coupleable_max_qps;

Expand Down
7 changes: 7 additions & 0 deletions framework/include/problems/DisplacedProblem.h
Expand Up @@ -124,6 +124,8 @@ class DisplacedProblem : public SubProblem
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string & var_name) override;
virtual VectorMooseVariable & getVectorVariable(THREAD_ID tid,
const std::string & var_name) override;
virtual ArrayMooseVariable & getArrayVariable(THREAD_ID tid,
const std::string & var_name) override;
virtual bool hasScalarVariable(const std::string & var_name) const override;
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid,
const std::string & var_name) override;
Expand All @@ -133,6 +135,11 @@ class DisplacedProblem : public SubProblem
const FEType & type,
Real scale_factor,
const std::set<SubdomainID> * const active_subdomains = NULL);
virtual void addArrayVariable(const std::string & var_name,
const FEType & type,
unsigned int components,
const std::vector<Real> & scale_factor,
const std::set<SubdomainID> * const active_subdomains = NULL);
virtual void addAuxVariable(const std::string & var_name,
const FEType & type,
const std::set<SubdomainID> * const active_subdomains = NULL);
Expand Down
7 changes: 7 additions & 0 deletions framework/include/problems/FEProblemBase.h
Expand Up @@ -247,6 +247,8 @@ class FEProblemBase : public SubProblem, public Restartable
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string & var_name) override;
virtual VectorMooseVariable & getVectorVariable(THREAD_ID tid,
const std::string & var_name) override;
virtual ArrayMooseVariable & getArrayVariable(THREAD_ID tid,
const std::string & var_name) override;

virtual bool hasScalarVariable(const std::string & var_name) const override;
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid,
Expand Down Expand Up @@ -590,6 +592,11 @@ class FEProblemBase : public SubProblem, public Restartable
const FEType & type,
Real scale_factor,
const std::set<SubdomainID> * const active_subdomains = NULL);
virtual void addArrayVariable(const std::string & var_name,
const FEType & type,
unsigned int components,
const std::vector<Real> & scale_factor,
const std::set<SubdomainID> * const active_subdomains = NULL);
virtual void addScalarVariable(const std::string & var_name,
Order order,
Real scale_factor = 1.,
Expand Down

0 comments on commit 9aafb0d

Please sign in to comment.