Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiple objects, postprocs, transfers for FV variables #16115

Merged
merged 10 commits into from Nov 16, 2020
Merged
2 changes: 2 additions & 0 deletions framework/include/problems/DisplacedProblem.h
Expand Up @@ -142,6 +142,8 @@ class DisplacedProblem : public SubProblem
Moose::VarFieldType expected_var_field_type =
Moose::VarFieldType::VAR_FIELD_ANY) const override;
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string & var_name) override;
virtual MooseVariableFieldBase & getActualFieldVariable(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,
Expand Down
2 changes: 2 additions & 0 deletions framework/include/problems/FEProblemBase.h
Expand Up @@ -225,6 +225,8 @@ class FEProblemBase : public SubProblem, public Restartable
Moose::VarKindType expected_var_type = Moose::VarKindType::VAR_ANY,
Moose::VarFieldType expected_var_field_type =
Moose::VarFieldType::VAR_FIELD_ANY) const override;
MooseVariableFieldBase & getActualFieldVariable(THREAD_ID tid,
const std::string & var_name) override;
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string & var_name) override;
virtual VectorMooseVariable & getVectorVariable(THREAD_ID tid,
const std::string & var_name) override;
Expand Down
4 changes: 4 additions & 0 deletions framework/include/problems/SubProblem.h
Expand Up @@ -216,6 +216,10 @@ class SubProblem : public Problem
/// Returns the variable reference for requested MooseVariable which may be in any system
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string & var_name) = 0;

/// Returns the variable reference for requested MooseVariableField which may be in any system
virtual MooseVariableFieldBase & getActualFieldVariable(THREAD_ID tid,
const std::string & var_name) = 0;

/// Returns the variable reference for requested VectorMooseVariable which may be in any system
virtual VectorMooseVariable & getVectorVariable(THREAD_ID tid, const std::string & var_name) = 0;

Expand Down
Expand Up @@ -33,7 +33,7 @@ ElementIntegralArrayVariablePostprocessor::ElementIntegralArrayVariablePostproce
_grad_u(coupledArrayGradient("variable")),
_component(getParam<unsigned int>("component"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
Expand Up @@ -36,7 +36,7 @@ ElementVariablePostprocessor::ElementVariablePostprocessor(const InputParameters
_grad_u(coupledGradient("variable")),
_qp(0)
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

void
Expand Down
3 changes: 2 additions & 1 deletion framework/src/postprocessors/ElementalVariableValue.C
Expand Up @@ -52,7 +52,8 @@ ElementalVariableValue::getValue()
_subproblem.prepare(_element, _tid);
_subproblem.reinitElem(_element, _tid);

MooseVariable & var = _subproblem.getStandardVariable(_tid, _var_name);
MooseVariableField<Real> & var = static_cast<MooseVariableField<Real> &>(
_subproblem.getActualFieldVariable(_tid, _var_name));
const VariableValue & u = var.sln();
unsigned int n = u.size();
for (unsigned int i = 0; i < n; i++)
Expand Down
Expand Up @@ -48,7 +48,7 @@ InterfaceIntegralVariableValuePostprocessor::InterfaceIntegralVariableValuePostp
: coupledNeighborGradient("variable")),
_interface_value_type(parameters.get<MooseEnum>("interface_value_type"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
Expand Up @@ -34,7 +34,7 @@ SideIntegralVariablePostprocessor::SideIntegralVariablePostprocessor(
_u(coupledValue("variable")),
_grad_u(coupledGradient("variable"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
11 changes: 11 additions & 0 deletions framework/src/problems/DisplacedProblem.C
Expand Up @@ -423,6 +423,17 @@ DisplacedProblem::getStandardVariable(THREAD_ID tid, const std::string & var_nam
return _displaced_aux.getFieldVariable<Real>(tid, var_name);
}

MooseVariableFieldBase &
DisplacedProblem::getActualFieldVariable(THREAD_ID tid, const std::string & var_name)
{
if (_displaced_nl.hasVariable(var_name))
return _displaced_nl.getActualFieldVariable<Real>(tid, var_name);
else if (!_displaced_aux.hasVariable(var_name))
mooseError("No variable with name '" + var_name + "'");

return _displaced_aux.getActualFieldVariable<Real>(tid, var_name);
}

VectorMooseVariable &
DisplacedProblem::getVectorVariable(THREAD_ID tid, const std::string & var_name)
{
Expand Down
11 changes: 11 additions & 0 deletions framework/src/problems/FEProblemBase.C
Expand Up @@ -4463,6 +4463,17 @@ FEProblemBase::getStandardVariable(THREAD_ID tid, const std::string & var_name)
return _aux->getFieldVariable<Real>(tid, var_name);
}

MooseVariableFieldBase &
FEProblemBase::getActualFieldVariable(THREAD_ID tid, const std::string & var_name)
{
if (_nl->hasVariable(var_name))
return _nl->getActualFieldVariable<Real>(tid, var_name);
else if (!_aux->hasVariable(var_name))
mooseError("Unknown variable " + var_name);

return _aux->getActualFieldVariable<Real>(tid, var_name);
}

VectorMooseVariable &
FEProblemBase::getVectorVariable(THREAD_ID tid, const std::string & var_name)
{
Expand Down
Expand Up @@ -59,7 +59,8 @@ MultiAppVariableValueSamplePostprocessorTransfer::execute()
case TO_MULTIAPP:
{
FEProblemBase & from_problem = _multi_app->problemBase();
MooseVariable & from_var = from_problem.getStandardVariable(0, _from_var_name);
MooseVariableField<Real> & from_var = static_cast<MooseVariableField<Real> &>(
from_problem.getActualFieldVariable(0, _from_var_name));
SystemBase & from_system_base = from_var.sys();
SubProblem & from_sub_problem = from_system_base.subproblem();

Expand Down
Expand Up @@ -66,7 +66,8 @@ MultiAppVariableValueSampleTransfer::execute()
case TO_MULTIAPP:
{
FEProblemBase & from_problem = _multi_app->problemBase();
MooseVariable & from_var = from_problem.getStandardVariable(0, _from_var_name);
MooseVariableField<Real> & from_var = static_cast<MooseVariableField<Real> &>(
from_problem.getActualFieldVariable(0, _from_var_name));
SystemBase & from_system_base = from_var.sys();
SubProblem & from_sub_problem = from_system_base.subproblem();

Expand Down
Expand Up @@ -33,7 +33,7 @@ ElementIntegralVariableUserObject::ElementIntegralVariableUserObject(
_u(coupledValue("variable")),
_grad_u(coupledGradient("variable"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
Expand Up @@ -30,7 +30,7 @@ SideIntegralVariableUserObject::SideIntegralVariableUserObject(const InputParame
_u(coupledValue("variable")),
_grad_u(coupledGradient("variable"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
5 changes: 2 additions & 3 deletions framework/src/vectorpostprocessors/PointSamplerBase.C
Expand Up @@ -11,7 +11,6 @@

// MOOSE includes
#include "MooseMesh.h"
#include "MooseVariableFE.h"

#include "libmesh/mesh_tools.h"

Expand Down Expand Up @@ -44,7 +43,7 @@ PointSamplerBase::PointSamplerBase(const InputParameters & parameters)
_mesh(_subproblem.mesh()),
_pp_value(getPostprocessorValue("scaling"))
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());

std::vector<std::string> var_names(_coupled_moose_vars.size());

Expand Down Expand Up @@ -107,7 +106,7 @@ PointSamplerBase::execute()
_subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid

for (MooseIndex(_coupled_moose_vars) j = 0; j < _coupled_moose_vars.size(); ++j)
values[j] = (dynamic_cast<MooseVariable *>(_coupled_moose_vars[j]))->sln()[0] *
values[j] = (dynamic_cast<MooseVariableField<Real> *>(_coupled_moose_vars[j]))->sln()[0] *
_pp_value; // The zero is for the "qp"

_found_points[i] = true;
Expand Down
Expand Up @@ -37,7 +37,7 @@ PFCElementEnergyIntegral::PFCElementEnergyIntegral(const InputParameters & param
_u_dot(_var.uDot()),
_temp(getParam<Real>("temp")) // K
{
addMooseVariableDependency(mooseVariable());
addMooseVariableDependency(&mooseVariableField());
}

Real
Expand Down
Binary file not shown.
@@ -0,0 +1,84 @@
[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 4
ny = 4
elem_type = QUAD4
[]

[Variables]
[./u]
order = CONSTANT
family = MONOMIAL
fv = true
initial_condition = 1
[../]
[]

[Functions]
[./force_fn]
type = ParsedFunction
value = '1'
[../]

[./exact_fn]
type = ParsedFunction
value = 't'
[../]
[]

[FVKernels]
[./diff_u]
type = FVDiffusion
variable = u
coeff = '1'
block = '0'
[../]

[./ffn_u]
type = FVBodyForce
variable = u
function = force_fn
[../]
[]

[FVBCs]
[./all_u]
type = FVFunctionDirichletBC
variable = u
boundary = '0 1 2 3'
function = exact_fn
[../]
[]

[Postprocessors]
[./a]
type = ElementIntegralVariablePostprocessor
variable = u
execute_on = 'initial timestep_end'
[../]

[./total_a]
type = TotalVariableValue
value = a
execute_on = 'initial timestep_end'
[../]
[]

[Problem]
kernel_coverage_check = false
[]

[Executioner]
type = Steady
solve_type = 'PJFNK'
[]

[Outputs]
execute_on = 'timestep_end'
exodus = true
[]
14 changes: 11 additions & 3 deletions test/tests/postprocessors/element_integral_var_pps/tests
@@ -1,5 +1,5 @@
[Tests]
issues = '#1405'
issues = '#1405 #16099'
design = 'ElementIntegralVariablePostprocessor.md'

[element_integral]
Expand All @@ -10,15 +10,23 @@
input = 'initial_pps.i'
exodiff = 'out_initial_pps.e'

detail = 'during the initial setup step and'
detail = 'during the initial setup step'
[]

[pps_old_test]
type = 'Exodiff'
input = 'pps_old_value.i'
exodiff = 'pps_old_value_out.e'

detail = 'at the end of each time step.'
detail = 'and at the end of each time step, for FE variables'
[]

[pps_old_test_fv]
type = 'Exodiff'
input = 'pps_old_value_fv.i'
exodiff = 'pps_old_value_fv_out.e'

detail = 'and FV variables.'
[]
[]
[]
@@ -0,0 +1,66 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 1
ymax = 0.1
[]

[Variables]
[./u]
family = MONOMIAL
order = CONSTANT
fv = true
[../]
[]

[FVKernels]
[./diff]
type = FVDiffusion
variable = u
coeff = 0.1
[../]
[]

[FVBCs]
[./left]
type = FVDirichletBC
variable = u
boundary = left
value = 1
[../]
[./right]
type = FVDirichletBC
variable = u
boundary = right
value = 10
[../]
[]

[Executioner]
type = Steady
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Problem]
kernel_coverage_check = false
[]

[Postprocessors]
[./elem_left]
type = ElementalVariableValue
variable = u
elementid = 0
[]
[./elem_right]
type = ElementalVariableValue
variable = u
elementid = 9
[]
[]

[Outputs]
csv = true
[]
@@ -0,0 +1,3 @@
time,elem_left,elem_right
0,0,0
1,1.45,9.55
10 changes: 10 additions & 0 deletions test/tests/postprocessors/element_variable_value/tests
Expand Up @@ -9,4 +9,14 @@
issues = "#9757 #12165"
design = "ElementalVariableValue.md"
[]
[elem_var_value_fv_test]
type = CSVDiff
input = elemental_variable_value_fv.i
csvdiff = elemental_variable_value_fv_out.csv
mesh_mode = REPLICATED # Node numbering needs to be disabled for ElementVariableValue

requirement = "The system shall support sampling a specific quantity integrated over a single element with finite volume variables."
issues = "#9757 #12165 #16099"
design = "ElementalVariableValue.md"
[]
[]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.