Skip to content

Commit

Permalink
Merge pull request #13358 from andrsd/uos-in-scalar-initial-conds
Browse files Browse the repository at this point in the history
UserObjects can be retrieved in scalar initial conditions
  • Loading branch information
permcody committed May 6, 2019
2 parents 2c897a1 + fab3ab7 commit 392158a
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 5 deletions.
3 changes: 3 additions & 0 deletions framework/doc/content/source/ics/InitialCondition.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
# InitialCondition

Base class for defining field initial conditions.
3 changes: 3 additions & 0 deletions framework/doc/content/source/ics/ScalarInitialCondition.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
# ScalarInitialCondition

Base class for defining scalar initial conditions.
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
# UserObjectInterface

`UserObjectInterface` is a class that allows to bring user objects into MOOSE systems.

The following APIs are available:

* `getUserObject` - Bring an user object using the parameter name
* `getUserObjectByName` - Bring an user object knowing its actual name
11 changes: 10 additions & 1 deletion framework/include/ics/ScalarInitialCondition.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MooseObject.h" #include "MooseObject.h"
#include "ScalarCoupleable.h" #include "ScalarCoupleable.h"
#include "FunctionInterface.h" #include "FunctionInterface.h"
#include "UserObjectInterface.h"
#include "DependencyResolverInterface.h" #include "DependencyResolverInterface.h"


// forward declarations // forward declarations
Expand All @@ -36,6 +37,7 @@ InputParameters validParams<ScalarInitialCondition>();
class ScalarInitialCondition : public MooseObject, class ScalarInitialCondition : public MooseObject,
public ScalarCoupleable, public ScalarCoupleable,
public FunctionInterface, public FunctionInterface,
public UserObjectInterface,
public DependencyResolverInterface public DependencyResolverInterface
{ {
public: public:
Expand All @@ -62,6 +64,14 @@ class ScalarInitialCondition : public MooseObject,
*/ */
virtual Real value() = 0; virtual Real value() = 0;


/**
* Gets called at the beginning of the simulation before this object is asked to do its job.
* Note: This method is normally inherited from SetupInterface. However in this case it makes
* no sense to inherit the other virtuals available in that class so we are adding this virtual
* directly to this class with out the extra inheritance.
*/
virtual void initialSetup() {}

virtual const std::set<std::string> & getRequestedItems(); virtual const std::set<std::string> & getRequestedItems();


virtual const std::set<std::string> & getSuppliedItems(); virtual const std::set<std::string> & getSuppliedItems();
Expand All @@ -83,4 +93,3 @@ class ScalarInitialCondition : public MooseObject,
std::set<std::string> _depend_vars; std::set<std::string> _depend_vars;
std::set<std::string> _supplied_vars; std::set<std::string> _supplied_vars;
}; };

29 changes: 29 additions & 0 deletions framework/include/ics/ScalarInitialConditionWarehouse.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
//* 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 "MooseObjectWarehouseBase.h"
#include "MooseTypes.h"

class ScalarInitialCondition;

/**
* Warehouse for storing scalar initial conditions
*/
class ScalarInitialConditionWarehouse : public MooseObjectWarehouseBase<ScalarInitialCondition>
{
public:
ScalarInitialConditionWarehouse();

/**
* Initial setup
*/
void initialSetup();
};
4 changes: 2 additions & 2 deletions framework/include/problems/FEProblemBase.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "VectorPostprocessorData.h" #include "VectorPostprocessorData.h"
#include "Adaptivity.h" #include "Adaptivity.h"
#include "InitialConditionWarehouse.h" #include "InitialConditionWarehouse.h"
#include "ScalarInitialConditionWarehouse.h"
#include "Restartable.h" #include "Restartable.h"
#include "SolverParams.h" #include "SolverParams.h"
#include "PetscSupport.h" #include "PetscSupport.h"
Expand Down Expand Up @@ -1664,7 +1665,7 @@ class FEProblemBase : public SubProblem, public Restartable
///@{ ///@{
/// Initial condition storage /// Initial condition storage
InitialConditionWarehouse _ics; InitialConditionWarehouse _ics;
MooseObjectWarehouseBase<ScalarInitialCondition> _scalar_ics; // use base b/c of setup methods ScalarInitialConditionWarehouse _scalar_ics; // use base b/c of setup methods
///@} ///@}


// material properties // material properties
Expand Down Expand Up @@ -1954,4 +1955,3 @@ FEProblemBase::allowOutput(bool state)
{ {
_app.getOutputWarehouse().allowOutput<T>(state); _app.getOutputWarehouse().allowOutput<T>(state);
} }

1 change: 1 addition & 0 deletions framework/src/ics/ScalarInitialCondition.C
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ScalarInitialCondition::ScalarInitialCondition(const InputParameters & parameter
: MooseObject(parameters), : MooseObject(parameters),
ScalarCoupleable(this), ScalarCoupleable(this),
FunctionInterface(this), FunctionInterface(this),
UserObjectInterface(this),
DependencyResolverInterface(), DependencyResolverInterface(),
_fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")), _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")), _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
Expand Down
24 changes: 24 additions & 0 deletions framework/src/ics/ScalarInitialConditionWarehouse.C
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
//* 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

#include "ScalarInitialConditionWarehouse.h"
#include "ScalarInitialCondition.h"

ScalarInitialConditionWarehouse::ScalarInitialConditionWarehouse()
: MooseObjectWarehouseBase<ScalarInitialCondition>(false)
{
}

void
ScalarInitialConditionWarehouse::initialSetup()
{
MooseObjectWarehouseBase<ScalarInitialCondition>::sort();
for (const auto & ic : _active_objects[0])
ic->initialSetup();
}
3 changes: 1 addition & 2 deletions framework/src/problems/FEProblemBase.C
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters)
_coupling(Moose::COUPLING_DIAG), _coupling(Moose::COUPLING_DIAG),
_distributions(/*threaded=*/false), _distributions(/*threaded=*/false),
_samplers(_app.getExecuteOnEnum()), _samplers(_app.getExecuteOnEnum()),
_scalar_ics(/*threaded=*/false),
_material_props( _material_props(
declareRestartableDataWithContext<MaterialPropertyStorage>("material_props", &_mesh)), declareRestartableDataWithContext<MaterialPropertyStorage>("material_props", &_mesh)),
_bnd_material_props( _bnd_material_props(
Expand Down Expand Up @@ -678,7 +677,7 @@ FEProblemBase::initialSetup()


for (THREAD_ID tid = 0; tid < n_threads; tid++) for (THREAD_ID tid = 0; tid < n_threads; tid++)
_ics.initialSetup(tid); _ics.initialSetup(tid);
_scalar_ics.sort(); _scalar_ics.initialSetup();
projectSolution(); projectSolution();
} }


Expand Down
32 changes: 32 additions & 0 deletions test/include/ics/ScalarUOIC.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
//* 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 "ScalarInitialCondition.h"

class ScalarUOIC;
class MTUserObject;

template <>
InputParameters validParams<ScalarUOIC>();

/**
* Scalar initial condition for setting values from a user object
*/
class ScalarUOIC : public ScalarInitialCondition
{
public:
ScalarUOIC(const InputParameters & parameters);

virtual Real value() override;

protected:
const MTUserObject & _uo;
};
34 changes: 34 additions & 0 deletions test/src/ics/ScalarUOIC.C
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,34 @@
//* 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

#include "ScalarUOIC.h"
#include "MTUserObject.h"

registerMooseObject("MooseTestApp", ScalarUOIC);

template <>
InputParameters
validParams<ScalarUOIC>()
{
InputParameters params = validParams<ScalarInitialCondition>();
params.addRequiredParam<UserObjectName>("user_object",
"The MTUserObject to be coupled into this IC");
return params;
}

ScalarUOIC::ScalarUOIC(const InputParameters & parameters)
: ScalarInitialCondition(parameters), _uo(getUserObject<MTUserObject>("user_object"))
{
}

Real
ScalarUOIC::value()
{
return _uo.doSomething();
}
3 changes: 3 additions & 0 deletions test/tests/ics/depend_on_uo/gold/scalar_ic_from_uo_out.csv
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
time,a
0,-2
1,-2
49 changes: 49 additions & 0 deletions test/tests/ics/depend_on_uo/scalar_ic_from_uo.i
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
# This test sets an initial condition of a scalar variable from an user object

[Mesh]
type = GeneratedMesh
dim = 2
nx = 8
ny = 8

# We are testing geometric ghosted functors
# so we have to use distributed mesh
parallel_type = distributed
[]

[Variables]
[./u]
[../]

[./a]
family = SCALAR
order = FIRST
[../]
[]

[ICs]
[./ghost_ic]
type = ScalarUOIC
variable = a
user_object = scalar_uo
[../]
[]

[UserObjects]
[./scalar_uo]
type = MTUserObject
[../]
[]

[Executioner]
type = Steady
[]

[Outputs]
csv = true
show = 'a'
[]

[Problem]
kernel_coverage_check = false
[]
15 changes: 15 additions & 0 deletions test/tests/ics/depend_on_uo/tests
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
type = 'Exodiff' type = 'Exodiff'
input = 'geometric_neighbors_ic.i' input = 'geometric_neighbors_ic.i'
exodiff = 'geometric_neighbors_ic_out.e' exodiff = 'geometric_neighbors_ic_out.e'
requirement = 'The system shall allow setting field initial condition from an user object'
design = 'InitialCondition.md UserObjectInterface.md'
issues = '#8810'

min_parallel = 2
max_parallel = 2
[../]

[./scalar_ic_from_uo]
type = 'CSVDiff'
input = 'scalar_ic_from_uo.i'
csvdiff = 'scalar_ic_from_uo_out.csv'
requirement = 'The system shall allow setting scalar initial condition from an user object'
design = 'ScalarInitialCondition.md UserObjectInterface.md'
issues = '#13357'


min_parallel = 2 min_parallel = 2
max_parallel = 2 max_parallel = 2
Expand Down

0 comments on commit 392158a

Please sign in to comment.