From bf3a7d4bc5fe6e4f70bdfa9806820f1cca838f12 Mon Sep 17 00:00:00 2001 From: Derek Gaston Date: Sun, 7 Aug 2016 11:39:23 -0600 Subject: [PATCH] Split MooseVariableInterface into a templated base class to help with ArrayKernel refs #6881 --- framework/include/base/ArrayMooseVariable.h | 16 +- framework/include/base/DisplacedProblem.h | 1 + framework/include/base/FEProblem.h | 1 + .../include/base/MooseVariableInterface.h | 142 +-------- .../include/base/MooseVariableInterfaceBase.h | 283 ++++++++++++++++++ framework/include/base/SystemBase.h | 49 +++ framework/include/base/VariableWarehouse.h | 9 + framework/src/actions/AddVariableAction.C | 12 + framework/src/base/ArrayMooseVariable.C | 234 +++------------ framework/src/base/DisplacedProblem.C | 6 + framework/src/base/FEProblem.C | 11 + framework/src/base/MooseVariableInterface.C | 187 ------------ .../src/base/MooseVariableInterfaceBase.C | 20 ++ framework/src/base/VariableWarehouse.C | 11 + 14 files changed, 465 insertions(+), 517 deletions(-) create mode 100644 framework/include/base/MooseVariableInterfaceBase.h delete mode 100644 framework/src/base/MooseVariableInterface.C create mode 100644 framework/src/base/MooseVariableInterfaceBase.C diff --git a/framework/include/base/ArrayMooseVariable.h b/framework/include/base/ArrayMooseVariable.h index d9c931be7566..0401c597a6a0 100644 --- a/framework/include/base/ArrayMooseVariable.h +++ b/framework/include/base/ArrayMooseVariable.h @@ -20,6 +20,8 @@ #include "libmesh/dense_matrix.h" +#include "Eigen/Core" + // Forward declarations class Assembly; class SubProblem; @@ -35,9 +37,9 @@ template class NumericVector; template class DenseVector; } -typedef MooseArray > ArrayVariableValue; -typedef MooseArray > ArrayVariableGradient; -// typedef MooseArray VariableSecond; +typedef MooseArray ArrayVariableValue; +typedef MooseArray > ArrayVariableGradient; +typedef MooseArray ArrayVariableSecond; // typedef MooseArray > VariableTestValue; // typedef MooseArray > VariableTestGradient; @@ -328,6 +330,14 @@ class ArrayMooseVariable : public MooseVariableBase /// DOF indices (neighbor) std::vector _dof_indices_neighbor; + /// Cache of local dof indices for the first variable in the variable group + std::vector _local_dof_indices; + + /// Interface to raw PetscVector data + Eigen::Map _mapped_values; + + // Interface to the current gradient + Eigen::Map _mapped_grad_phi; bool _need_u_old; bool _need_u_older; diff --git a/framework/include/base/DisplacedProblem.h b/framework/include/base/DisplacedProblem.h index 97ac607d00d6..5d3303b7e331 100644 --- a/framework/include/base/DisplacedProblem.h +++ b/framework/include/base/DisplacedProblem.h @@ -112,6 +112,7 @@ class DisplacedProblem : public SubProblem virtual bool hasScalarVariable(const std::string & var_name) override; virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string & var_name) override; virtual void addVariable(const std::string & var_name, 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, Real scale_factor, unsigned int count, 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); virtual void addScalarVariable(const std::string & var_name, Order order, Real scale_factor = 1., const std::set< SubdomainID > * const active_subdomains = NULL); virtual void addAuxScalarVariable(const std::string & var_name, Order order, Real scale_factor = 1., const std::set< SubdomainID > * const active_subdomains = NULL); diff --git a/framework/include/base/FEProblem.h b/framework/include/base/FEProblem.h index f3f142e6e5f2..1b7c65374c95 100644 --- a/framework/include/base/FEProblem.h +++ b/framework/include/base/FEProblem.h @@ -435,6 +435,7 @@ class FEProblem : // NL ///// NonlinearSystem & getNonlinearSystem() { return _nl; } void addVariable(const std::string & var_name, const FEType & type, Real scale_factor, const std::set< SubdomainID > * const active_subdomains = NULL); + void addArrayVariable(const std::string & var_name, const FEType & type, Real scale_factor, unsigned int count, const std::set< SubdomainID > * const active_subdomains = NULL); void addScalarVariable(const std::string & var_name, Order order, Real scale_factor = 1., const std::set< SubdomainID > * const active_subdomains = NULL); void addKernel(const std::string & kernel_name, const std::string & name, InputParameters parameters); void addNodalKernel(const std::string & kernel_name, const std::string & name, InputParameters parameters); diff --git a/framework/include/base/MooseVariableInterface.h b/framework/include/base/MooseVariableInterface.h index 8f4b61a33c4d..9d608423471c 100644 --- a/framework/include/base/MooseVariableInterface.h +++ b/framework/include/base/MooseVariableInterface.h @@ -17,11 +17,12 @@ #include "MooseVariable.h" #include "InputParameters.h" +#include "MooseVariableInterfaceBase.h" /** * Interface for objects that need to get values of MooseVariables */ -class MooseVariableInterface +class MooseVariableInterface : public MooseVariableInterfaceBase { public: /** @@ -30,141 +31,10 @@ class MooseVariableInterface * @param nodal true if the variable is nodal * @param var_param_name the parameter name where we will find the coupled variable name */ - MooseVariableInterface(const MooseObject * moose_object, bool nodal, std::string var_param_name = "variable"); - - /** - * Get the variable that this object is using. - * @return The variable this object is using. - */ - MooseVariable * mooseVariable(); - - virtual ~MooseVariableInterface(); - -protected: - /** - * The value of the variable this object is operating on. - * - * This is computed by default and should already be available as _u - * - * @return The reference to be stored off and used later. - */ - virtual const VariableValue & value(); - - /** - * The old value of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableValue & valueOld(); - - /** - * The older value of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableValue & valueOlder(); - - /** - * The time derivative of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableValue & dot(); - - /** - * The derivative of the time derivative of the variable this object is operating on - * with respect to this variable's coefficients. - * - * This is useful for creating Jacobian entries for residual statements that use _u_dot - * - * @return The reference to be stored off and used later. - */ - virtual const VariableValue & dotDu(); - - /** - * The gradient of the variable this object is operating on. - * - * This is computed by default and should already be available as _grad_u - * - * @return The reference to be stored off and used later. - */ - virtual const VariableGradient & gradient(); - - /** - * The old gradient of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableGradient & gradientOld(); - - /** - * The older gradient of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableGradient & gradientOlder(); - - /** - * The second derivative of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableSecond & second(); - - /** - * The old second derivative of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableSecond & secondOld(); - - /** - * The older second derivative of the variable this object is operating on. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableSecond & secondOlder(); - - /** - * The second derivative of the test function. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableTestSecond & secondTest(); - - /** - * The second derivative of the test function on the current face. - * This should be called in e.g. IntegratedBC when you need second - * derivatives of the test function function on the boundary. - * - * @return The reference to be stored off and used later. - */ - virtual const VariableTestSecond & secondTestFace(); - - /** - * The second derivative of the trial function. - * - * @return The reference to be stored off and used later. - */ - virtual const VariablePhiSecond & secondPhi(); - - /** - * The second derivative of the trial function on the current face. - * This should be called in e.g. IntegratedBC when you need second - * derivatives of the trial function function on the boundary. - * - * @return The reference to be stored off and used later. - */ - virtual const VariablePhiSecond & secondPhiFace(); - - /// Whether or not this object is acting only at nodes - bool _nodal; - - /// The variable this object is acting on - MooseVariable * _variable; - -protected: - Assembly * _mvi_assembly; + MooseVariableInterface(const MooseObject * moose_object, bool nodal, std::string var_param_name = "variable") : + MooseVariableInterfaceBase(moose_object, nodal, var_param_name) + { + } }; diff --git a/framework/include/base/MooseVariableInterfaceBase.h b/framework/include/base/MooseVariableInterfaceBase.h new file mode 100644 index 000000000000..cb830759bd7b --- /dev/null +++ b/framework/include/base/MooseVariableInterfaceBase.h @@ -0,0 +1,283 @@ +/****************************************************************/ +/* DO NOT MODIFY THIS HEADER */ +/* MOOSE - Multiphysics Object Oriented Simulation Environment */ +/* */ +/* (c) 2010 Battelle Energy Alliance, LLC */ +/* ALL RIGHTS RESERVED */ +/* */ +/* Prepared by Battelle Energy Alliance, LLC */ +/* Under Contract No. DE-AC07-05ID14517 */ +/* With the U. S. Department of Energy */ +/* */ +/* See COPYRIGHT for full restrictions */ +/****************************************************************/ + +#ifndef MOOSEVARIABLEINTERFACEBASE_H +#define MOOSEVARIABLEINTERFACEBASE_H + +#include "MooseVariable.h" +#include "InputParameters.h" +#include "SubProblem.h" +#include "Assembly.h" + +/** + * Interface for objects that need to get values of MooseVariables + */ +template +class MooseVariableInterfaceBase +{ +public: + /** + * Constructing the object + * @param parameters Parameters that come from constructing the object + * @param nodal true if the variable is nodal + * @param var_param_name the parameter name where we will find the coupled variable name + */ + MooseVariableInterfaceBase(const MooseObject * moose_object, bool nodal, std::string var_param_name = "variable") : + _nodal(nodal) + { + const InputParameters & parameters = moose_object->parameters(); + + SubProblem & problem = *parameters.get("_subproblem"); + + THREAD_ID tid = parameters.get("_tid"); + + // Try the scalar version first + std::string variable_name = parameters.getMooseType(var_param_name); + if (variable_name == "") + // When using vector variables, we are only going to use the first one in the list at the interface level... + variable_name = parameters.getVecMooseType(var_param_name)[0]; + + _variable = &problem.getVariable(tid, variable_name); + + _mvi_assembly = &problem.assembly(tid); + } + + /** + * Get the variable that this object is using. + * @return The variable this object is using. + */ + MooseVariable * mooseVariable() + { + return _variable; + } + +protected: + /** + * The value of the variable this object is operating on. + * + * This is computed by default and should already be available as _u + * + * @return The reference to be stored off and used later. + */ + virtual const VariableValueType & value() + { + if (_nodal) + return _variable->nodalSln(); + else + return _variable->sln(); + } + + /** + * The old value of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableValueType & valueOld() + { + if (_nodal) + return _variable->nodalSlnOld(); + else + return _variable->slnOld(); + } + + /** + * The older value of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableValueType & valueOlder() + { + if (_nodal) + return _variable->nodalSlnOlder(); + else + return _variable->slnOlder(); + } + + /** + * The time derivative of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableValueType & dot() + { + if (_nodal) + return _variable->nodalSlnDot(); + else + return _variable->uDot(); + } + + /** + * The derivative of the time derivative of the variable this object is operating on + * with respect to this variable's coefficients. + * + * This is useful for creating Jacobian entries for residual statements that use _u_dot + * + * @return The reference to be stored off and used later. + */ + virtual const VariableValueType & dotDu() + { + if (_nodal) + return _variable->nodalSlnDuDotDu(); + else + return _variable->duDotDu(); + } + + /** + * The gradient of the variable this object is operating on. + * + * This is computed by default and should already be available as _grad_u + * + * @return The reference to be stored off and used later. + */ + virtual const VariableGradientType & gradient() + { + if (_nodal) + mooseError("Nodal variables do not have gradients"); + + return _variable->gradSln(); + } + + /** + * The old gradient of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableGradientType & gradientOld() + { + if (_nodal) + mooseError("Nodal variables do not have gradients"); + + return _variable->gradSlnOld(); + } + + /** + * The older gradient of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableGradientType & gradientOlder() + { + if (_nodal) + mooseError("Nodal variables do not have gradients"); + + return _variable->gradSlnOlder(); + } + + /** + * The second derivative of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableSecondType & second() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _variable->secondSln(); + } + + /** + * The old second derivative of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableSecondType & secondOld() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _variable->secondSlnOld(); + } + + /** + * The older second derivative of the variable this object is operating on. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableSecondType & secondOlder() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _variable->secondSlnOlder(); + } + + /** + * The second derivative of the test function. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableTestSecond & secondTest() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _variable->secondPhi(); + } + + /** + * The second derivative of the test function on the current face. + * This should be called in e.g. IntegratedBC when you need second + * derivatives of the test function function on the boundary. + * + * @return The reference to be stored off and used later. + */ + virtual const VariableTestSecond & secondTestFace() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _variable->secondPhiFace(); + } + + /** + * The second derivative of the trial function. + * + * @return The reference to be stored off and used later. + */ + virtual const VariablePhiSecond & secondPhi() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _mvi_assembly->secondPhi(); + } + + /** + * The second derivative of the trial function on the current face. + * This should be called in e.g. IntegratedBC when you need second + * derivatives of the trial function function on the boundary. + * + * @return The reference to be stored off and used later. + */ + virtual const VariablePhiSecond & secondPhiFace() + { + if (_nodal) + mooseError("Nodal variables do not have second derivatives"); + + return _mvi_assembly->secondPhiFace(); + } + + /// Whether or not this object is acting only at nodes + bool _nodal; + + /// The variable this object is acting on + MooseVariableType * _variable; + +protected: + Assembly * _mvi_assembly; +}; + + +#endif /* MOOSEVARIABLEINTERFACEBASE_H */ diff --git a/framework/include/base/SystemBase.h b/framework/include/base/SystemBase.h index 57a68d148860..e2712953b434 100644 --- a/framework/include/base/SystemBase.h +++ b/framework/include/base/SystemBase.h @@ -22,6 +22,7 @@ #include "SubProblem.h" #include "MooseVariableScalar.h" #include "MooseVariable.h" +#include "ArrayMooseVariable.h" #include "DataIO.h" // libMesh @@ -172,6 +173,17 @@ class SystemBase : public libMesh::ParallelObject */ virtual void addVariable(const std::string & var_name, const FEType & type, Real scale_factor, const std::set< SubdomainID > * const active_subdomains = NULL) = 0; + /** + * Adds an array-variable to the system + * + * @param var_name name of the variable + * @param type FE type of the variable + * @param scale_factor the scaling factor for the variable + * @param active_subdomains a list of subdomain ids this variable is active on + */ + virtual void addArrayVariable(const std::string & var_name, const FEType & type, Real scale_factor, unsigned int count, const std::set< SubdomainID > * const active_subdomains = NULL) = 0; + + /** * Query a system for a variable * @@ -454,6 +466,43 @@ class SystemTempl : public SystemBase _var_map[var_num].insert(*it); } + /** + * Add count number of variables as an ArrayVariable. + * + * Note: calling this turns off automatic variable group identification for this system... + */ + virtual void addArrayVariable(const std::string & var_name, const FEType & type, Real scale_factor, unsigned int count, const std::set< SubdomainID > * const active_subdomains = NULL) + { + // Turn off automatic variable group identification so that we can be sure that this variable + // group will be ordered exactly like it should be + _sys.identify_variable_groups(false); + + // Build up the variable names + std::vector var_names; + for (unsigned int i = 0; i < count; i++) + var_names.push_back(var_name + "_" + std::to_string(i)); + + unsigned int var_num = _sys.add_variables(var_names, type, active_subdomains); + + if (active_subdomains == NULL) + { + for (unsigned int i = 0; i < count; i++) + _var_map[var_num] = std::set(); + } + else + for (unsigned int i = 0; i < count; i++) + for (std::set::iterator it = active_subdomains->begin(); it != active_subdomains->end(); ++it) + _var_map[var_num].insert(*it); + + for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++) + { + //FIXME: we cannot refer fetype in libMesh at this point, so we will just make a copy in MooseVariableBase. + ArrayMooseVariable * var = new ArrayMooseVariable(var_num, type, *this, _subproblem.assembly(tid), _var_kind); + var->scalingFactor(scale_factor); + _vars[tid].add(var_name, var); + } + } + /** * Adds a scalar variable * @param var_name The name of the variable diff --git a/framework/include/base/VariableWarehouse.h b/framework/include/base/VariableWarehouse.h index 1cc4c2c7544f..859e1f47f328 100644 --- a/framework/include/base/VariableWarehouse.h +++ b/framework/include/base/VariableWarehouse.h @@ -24,6 +24,7 @@ class MooseVariableBase; class MooseVariable; class MooseVariableScalar; +class ArrayMooseVariable; /** * Holds variables and provides some services @@ -101,6 +102,12 @@ class VariableWarehouse */ const std::vector & scalars(); + /** + * Get the list of Array variables + * @return The list of Array variables + */ + const std::vector & arrayVars(); + protected: /// list of variable names std::vector _names; @@ -111,6 +118,8 @@ class VariableWarehouse /// Map to variables that need to be evaluated on a boundary std::map > _boundary_vars; + std::vector _array_vars; + /// list of all variables std::vector _scalar_vars; diff --git a/framework/src/actions/AddVariableAction.C b/framework/src/actions/AddVariableAction.C index 66eced83e00c..6fabfe53aca5 100644 --- a/framework/src/actions/AddVariableAction.C +++ b/framework/src/actions/AddVariableAction.C @@ -52,6 +52,9 @@ InputParameters validParams() params.addParam >("block", "The block id where this variable lives"); params.addParam("eigen", false, "True to make this variable an eigen variable"); + // For Array Variables + params.addParam("count", 1, "The multiplicity of this variable for use with ArrayKernels. 1 means just a normal variable anything more than 1 will create an ArrayMooseVariable"); + // Advanced input options params.addParam("scaling", 1.0, "Specifies a scaling factor to apply to this variable"); params.addParamNamesToGroup("scaling eigen", "Advanced"); @@ -133,6 +136,15 @@ AddVariableAction::addVariable(std::string & var_name) if (_scalar_var) _problem->addScalarVariable(var_name, _fe_type.order, scale_factor); + // Array variables + else if(getParam("count") > 1) + { + if (blocks.empty()) + _problem->addArrayVariable(var_name, _fe_type, scale_factor, getParam("count")); + else + _problem->addArrayVariable(var_name, _fe_type, scale_factor, getParam("count"), &blocks); + } + // Block restricted variable else if (blocks.empty()) _problem->addVariable(var_name, _fe_type, scale_factor); diff --git a/framework/src/base/ArrayMooseVariable.C b/framework/src/base/ArrayMooseVariable.C index 2bb3de4d3cb8..4fb0aa08f099 100644 --- a/framework/src/base/ArrayMooseVariable.C +++ b/framework/src/base/ArrayMooseVariable.C @@ -38,6 +38,9 @@ ArrayMooseVariable::ArrayMooseVariable(unsigned int var_num, const FEType & fe_t _current_side(_assembly.side()), _neighbor(_assembly.neighbor()), + _mapped_values(NULL, 0), + _mapped_grad_phi(NULL), + _need_u_old(false), _need_u_older(false), @@ -537,216 +540,65 @@ ArrayMooseVariable::computeElemValues() bool is_transient = _subproblem.isTransient(); unsigned int nqp = _qrule->n_points(); + unsigned int n_shapes = _dof_indices.size(); - _u.resize(nqp); - _grad_u.resize(nqp); - -// if (_need_second) -// _second_u.resize(nqp); - - if (is_transient) - { - _u_dot.resize(nqp); - _du_dot_du.resize(nqp); - - if (_need_u_old) - _u_old.resize(nqp); + auto var_group = _sys.system().variable_group(0); + unsigned int n_vars = var_group.n_variables(); - if (_need_u_older) - _u_older.resize(nqp); - - if (_need_grad_old) - _grad_u_old.resize(nqp); + const PetscVector & current_solution = dynamic_cast&>(*_sys.currentSolution()); + const PetscVector & solution_old = dynamic_cast&>(_sys.solutionOld()); + const PetscVector & solution_older = dynamic_cast&>(_sys.solutionOlder()); + const PetscVector & u_dot = dynamic_cast&>(_sys.solutionUDot()); + const Real & du_dot_du = _sys.duDotDu(); - if (_need_grad_older) - _grad_u_older.resize(nqp); + // We need to get array only for reading... but we need to be able to pass the raw pointer into an Eigen::Map + // Eigen::Map requires a non-const pointer... so we're going to const_cast it here + // (but we're still NOT going to modify it). + PetscScalar * current_solution_values = const_cast(current_solution.get_array_read()); -// if (_need_second_old) -// _second_u_old.resize(nqp); + _u.resize(nqp); + for (unsigned int qp = 0; qp < nqp; qp++) + { + auto & qp_value = _u[qp]; -// if (_need_second_older) -// _second_u_older.resize(nqp); + qp_value.resize(n_vars); + qp_value.setZero(); } - /* - for (unsigned int i = 0; i < nqp; ++i) + _grad_u.resize(nqp); + for (unsigned int qp = 0; qp < nqp; qp++) { - _u[i] = 0; - _grad_u[i] = 0; + auto & qp_value = _grad_u[qp]; -// if (_need_second) -// _second_u[i] = 0; + qp_value.resize(n_vars, Eigen::NoChange); + qp_value.setZero(); + } - if (is_transient) - { - _u_dot[i] = 0; - _du_dot_du[i] = 0; + auto n_dofs = _dof_indices.size(); - if (_need_u_old) - _u_old[i] = 0; + // Global to local map them + _local_dof_indices.resize(n_dofs); - if (_need_u_older) - _u_older[i] = 0; + for (unsigned int i = 0; i < n_dofs; i++) + _local_dof_indices[i] = current_solution.map_global_to_local_index(_dof_indices[i]); - if (_need_grad_old) - _grad_u_old[i] = 0; + for (unsigned int i = 0; i < n_shapes; i++) + { + new (&_mapped_values) Eigen::Map(current_solution_values + _local_dof_indices[i], n_vars); - if (_need_grad_older) - _grad_u_older[i] = 0; + for (unsigned int qp = 0; qp < nqp; qp++) + _u[qp].noalias() += _mapped_values * _phi[i][qp]; -// if (_need_second_old) -// _second_u_old[i] = 0; + for (unsigned int qp = 0; qp < nqp; qp++) + { + new (&_mapped_grad_phi) Eigen::Map(const_cast(&_grad_phi[i][qp](0))); -// if (_need_second_older) -// _second_u_older[i] = 0; + _grad_u[qp].noalias() += _mapped_values * _mapped_grad_phi.transpose(); } } - */ - -// unsigned int num_dofs = _dof_indices.size(); - - -// if (_need_nodal_u) -// _nodal_u.resize(num_dofs); -// if (is_transient) -// { -// if (_need_nodal_u_old) -// _nodal_u_old.resize(num_dofs); -// if (_need_nodal_u_older) -// _nodal_u_older.resize(num_dofs); -// if (_need_nodal_u_dot) -// _nodal_u_dot.resize(num_dofs); -// } - - const PetscVector & current_solution = dynamic_cast&>(*_sys.currentSolution()); - const PetscVector & solution_old = dynamic_cast&>(_sys.solutionOld()); - const PetscVector & solution_older = dynamic_cast&>(_sys.solutionOlder()); - const PetscVector & u_dot = dynamic_cast&>(_sys.solutionUDot()); - const Real & du_dot_du = _sys.duDotDu(); - - + const_cast &>(current_solution).restore_array(); - const PetscScalar * current_solution_values = current_solution.get_array_read(); -// -// -// -// -// -// -// dof_id_type idx = 0; -// Real soln_local = 0; -// Real soln_old_local = 0; -// Real soln_older_local = 0; -// Real u_dot_local = 0; -// -// Real phi_local = 0; -// const RealGradient * dphi_qp = NULL; -// const RealTensor * d2phi_local = NULL; -// -// RealGradient * grad_u_qp = NULL; -// -// RealGradient * grad_u_old_qp = NULL; -// RealGradient * grad_u_older_qp = NULL; -// -// // RealTensor * second_u_qp = NULL; -// -// // RealTensor * second_u_old_qp = NULL; -// // RealTensor * second_u_older_qp = NULL; -// -// for (unsigned int i=0; i < num_dofs; i++) -// { -// idx = _dof_indices[i]; -// soln_local = current_solution(idx); -// -// if (_need_nodal_u) -// _nodal_u[i] = soln_local; -// -// if (is_transient) -// { -// if (_need_u_old || _need_grad_old || /*_need_second_old*/ || _need_nodal_u_old) -// soln_old_local = solution_old(idx); -// -// if (_need_u_older || _need_grad_older || /*_need_second_older*/ || _need_nodal_u_older) -// soln_older_local = solution_older(idx); -// -// if (_need_nodal_u_old) -// _nodal_u_old[i] = soln_old_local; -// if (_need_nodal_u_older) -// _nodal_u_older[i] = soln_older_local; -// -// u_dot_local = u_dot(idx); -// if (_need_nodal_u_dot) -// _nodal_u_dot[i] = u_dot_local; -// } -// -// for (unsigned int qp=0; qp < nqp; qp++) -// { -// phi_local = _phi[i][qp]; -// dphi_qp = &_grad_phi[i][qp]; -// -// grad_u_qp = &_grad_u[qp]; -// -// if (is_transient) -// { -// if (_need_grad_old) -// grad_u_old_qp = &_grad_u_old[qp]; -// -// if (_need_grad_older) -// grad_u_older_qp = &_grad_u_older[qp]; -// } -// -// /* -// if (_need_second || _need_second_old || _need_second_older) -// { -// d2phi_local = &(*_second_phi)[i][qp]; -// -// if (_need_second) -// second_u_qp = &_second_u[qp]; -// -// if (is_transient) -// { -// if (_need_second_old) -// second_u_old_qp = &_second_u_old[qp]; -// -// if (_need_second_older) -// second_u_older_qp = &_second_u_older[qp]; -// } -// } -// */ -// -// _u[qp] += phi_local * soln_local; -// -// grad_u_qp->add_scaled(*dphi_qp, soln_local); -// -// // if (_need_second) -// // second_u_qp->add_scaled(*d2phi_local, soln_local); -// -// if (is_transient) -// { -// _u_dot[qp] += phi_local * u_dot_local; -// _du_dot_du[qp] = du_dot_du; -// -// if (_need_u_old) -// _u_old[qp] += phi_local * soln_old_local; -// -// if (_need_u_older) -// _u_older[qp] += phi_local * soln_older_local; -// -// if (_need_grad_old) -// grad_u_old_qp->add_scaled(*dphi_qp, soln_old_local); -// -// if (_need_grad_older) -// grad_u_older_qp->add_scaled(*dphi_qp, soln_older_local); -// -// // if (_need_second_old) -// // second_u_old_qp->add_scaled(*d2phi_local, soln_old_local); -// -// // if (_need_second_older) -// // second_u_older_qp->add_scaled(*d2phi_local, soln_older_local); -// } -// } -// } } // void @@ -831,7 +683,7 @@ ArrayMooseVariable::computeElemValues() // _nodal_u_dot.resize(num_dofs); // } -// const NumericVector & current_solution = *_sys.currentSolution(); +// const NumericVector & crruent_solution = *_sys.currentSolution(); // const NumericVector & solution_old = _sys.solutionOld(); // const NumericVector & solution_older = _sys.solutionOlder(); // const NumericVector & u_dot = _sys.solutionUDot(); diff --git a/framework/src/base/DisplacedProblem.C b/framework/src/base/DisplacedProblem.C index d228e98e0693..5d5673fedcd2 100644 --- a/framework/src/base/DisplacedProblem.C +++ b/framework/src/base/DisplacedProblem.C @@ -256,6 +256,12 @@ DisplacedProblem::addVariable(const std::string & var_name, const FEType & type, _displaced_nl.addVariable(var_name, type, scale_factor, active_subdomains); } +void +DisplacedProblem::addArrayVariable(const std::string & var_name, const FEType & type, Real scale_factor, unsigned int count, const std::set< SubdomainID > * const active_subdomains) +{ + _displaced_nl.addArrayVariable(var_name, type, scale_factor, count, active_subdomains); +} + void DisplacedProblem::addAuxVariable(const std::string & var_name, const FEType & type, const std::set< SubdomainID > * const active_subdomains) { diff --git a/framework/src/base/FEProblem.C b/framework/src/base/FEProblem.C index e03d1668dc19..2fdeac15ee42 100644 --- a/framework/src/base/FEProblem.C +++ b/framework/src/base/FEProblem.C @@ -1298,6 +1298,17 @@ FEProblem::addVariable(const std::string & var_name, const FEType & type, Real s _displaced_problem->addVariable(var_name, type, scale_factor, active_subdomains); } +void +FEProblem::addArrayVariable(const std::string & var_name, const FEType & type, Real scale_factor, unsigned int count, const std::set< SubdomainID > * const active_subdomains/* = NULL*/) +{ + for (unsigned int i=0; iaddArrayVariable(var_name, type, scale_factor, count, active_subdomains); + } +} + void FEProblem::addScalarVariable(const std::string & var_name, Order order, Real scale_factor, const std::set< SubdomainID > * const active_subdomains) { diff --git a/framework/src/base/MooseVariableInterface.C b/framework/src/base/MooseVariableInterface.C deleted file mode 100644 index fe2354b78612..000000000000 --- a/framework/src/base/MooseVariableInterface.C +++ /dev/null @@ -1,187 +0,0 @@ -/****************************************************************/ -/* DO NOT MODIFY THIS HEADER */ -/* MOOSE - Multiphysics Object Oriented Simulation Environment */ -/* */ -/* (c) 2010 Battelle Energy Alliance, LLC */ -/* ALL RIGHTS RESERVED */ -/* */ -/* Prepared by Battelle Energy Alliance, LLC */ -/* Under Contract No. DE-AC07-05ID14517 */ -/* With the U. S. Department of Energy */ -/* */ -/* See COPYRIGHT for full restrictions */ -/****************************************************************/ - -#include "MooseVariableInterface.h" -#include "Problem.h" -#include "SubProblem.h" -#include "MooseTypes.h" -#include "Assembly.h" -#include "MooseError.h" // mooseDeprecated - -MooseVariableInterface::MooseVariableInterface(const MooseObject * moose_object, bool nodal, std::string var_param_name) : - _nodal(nodal) -{ - const InputParameters & parameters = moose_object->parameters(); - - SubProblem & problem = *parameters.get("_subproblem"); - - THREAD_ID tid = parameters.get("_tid"); - - // Try the scalar version first - std::string variable_name = parameters.getMooseType(var_param_name); - if (variable_name == "") - // When using vector variables, we are only going to use the first one in the list at the interface level... - variable_name = parameters.getVecMooseType(var_param_name)[0]; - - _variable = &problem.getVariable(tid, variable_name); - - _mvi_assembly = &problem.assembly(tid); -} - -MooseVariableInterface::~MooseVariableInterface() -{ -} - -MooseVariable * -MooseVariableInterface::mooseVariable() -{ - return _variable; -} - -const VariableValue & -MooseVariableInterface::value() -{ - if (_nodal) - return _variable->nodalSln(); - else - return _variable->sln(); -} - -const VariableValue & -MooseVariableInterface::valueOld() -{ - if (_nodal) - return _variable->nodalSlnOld(); - else - return _variable->slnOld(); -} - -const VariableValue & -MooseVariableInterface::valueOlder() -{ - if (_nodal) - return _variable->nodalSlnOlder(); - else - return _variable->slnOlder(); -} - -const VariableValue & -MooseVariableInterface::dot() -{ - if (_nodal) - return _variable->nodalSlnDot(); - else - return _variable->uDot(); -} - -const VariableValue & -MooseVariableInterface::dotDu() -{ - if (_nodal) - return _variable->nodalSlnDuDotDu(); - else - return _variable->duDotDu(); -} - - -const VariableGradient & -MooseVariableInterface::gradient() -{ - if (_nodal) - mooseError("Nodal variables do not have gradients"); - - return _variable->gradSln(); -} - -const VariableGradient & -MooseVariableInterface::gradientOld() -{ - if (_nodal) - mooseError("Nodal variables do not have gradients"); - - return _variable->gradSlnOld(); -} - -const VariableGradient & -MooseVariableInterface::gradientOlder() -{ - if (_nodal) - mooseError("Nodal variables do not have gradients"); - - return _variable->gradSlnOlder(); -} - -const VariableSecond & -MooseVariableInterface::second() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _variable->secondSln(); -} - -const VariableSecond & -MooseVariableInterface::secondOld() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _variable->secondSlnOld(); -} - -const VariableSecond & -MooseVariableInterface::secondOlder() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _variable->secondSlnOlder(); -} - -const VariableTestSecond & -MooseVariableInterface::secondTest() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _variable->secondPhi(); -} - -const VariableTestSecond & -MooseVariableInterface::secondTestFace() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _variable->secondPhiFace(); -} - - -const VariablePhiSecond & -MooseVariableInterface::secondPhi() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _mvi_assembly->secondPhi(); -} - -const VariablePhiSecond & -MooseVariableInterface::secondPhiFace() -{ - if (_nodal) - mooseError("Nodal variables do not have second derivatives"); - - return _mvi_assembly->secondPhiFace(); -} diff --git a/framework/src/base/MooseVariableInterfaceBase.C b/framework/src/base/MooseVariableInterfaceBase.C new file mode 100644 index 000000000000..5b3a3e5abbee --- /dev/null +++ b/framework/src/base/MooseVariableInterfaceBase.C @@ -0,0 +1,20 @@ +/****************************************************************/ +/* DO NOT MODIFY THIS HEADER */ +/* MOOSE - Multiphysics Object Oriented Simulation Environment */ +/* */ +/* (c) 2010 Battelle Energy Alliance, LLC */ +/* ALL RIGHTS RESERVED */ +/* */ +/* Prepared by Battelle Energy Alliance, LLC */ +/* Under Contract No. DE-AC07-05ID14517 */ +/* With the U. S. Department of Energy */ +/* */ +/* See COPYRIGHT for full restrictions */ +/****************************************************************/ + +//#include "MooseVariableInterface.h" +//#include "Problem.h" +// +//#include "MooseTypes.h" +// +//#include "MooseError.h" // mooseDeprecated diff --git a/framework/src/base/VariableWarehouse.C b/framework/src/base/VariableWarehouse.C index 9943464169c1..3716c971b5f4 100644 --- a/framework/src/base/VariableWarehouse.C +++ b/framework/src/base/VariableWarehouse.C @@ -16,6 +16,7 @@ #include "MooseVariable.h" #include "MooseVariableScalar.h" #include "MooseTypes.h" +#include "ArrayMooseVariable.h" VariableWarehouse::VariableWarehouse() { @@ -38,6 +39,10 @@ VariableWarehouse::add(const std::string & var_name, MooseVariableBase * var) { _vars.push_back(dynamic_cast(var)); } + else if (dynamic_cast(var) != NULL) + { + _array_vars.push_back(dynamic_cast(var)); + } else if (dynamic_cast(var) != NULL) { _scalar_vars.push_back(dynamic_cast(var)); @@ -101,6 +106,12 @@ VariableWarehouse::scalars() return _scalar_vars; } +const std::vector & +VariableWarehouse::arrayVars() +{ + return _array_vars; +} + const std::set & VariableWarehouse::boundaryVars(BoundaryID bnd) {