Skip to content
Permalink
Browse files

Merge pull request #13358 from andrsd/uos-in-scalar-initial-conds

UserObjects can be retrieved in scalar initial conditions
  • Loading branch information...
permcody committed May 6, 2019
2 parents 2c897a1 + fab3ab7 commit 392158a488853903195b9b121010c941147ecea0
@@ -0,0 +1,3 @@
# InitialCondition

Base class for defining field initial conditions.
@@ -0,0 +1,3 @@
# ScalarInitialCondition

Base class for defining scalar initial conditions.
@@ -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
@@ -12,6 +12,7 @@
#include "MooseObject.h"
#include "ScalarCoupleable.h"
#include "FunctionInterface.h"
#include "UserObjectInterface.h"
#include "DependencyResolverInterface.h"

// forward declarations
@@ -36,6 +37,7 @@ InputParameters validParams<ScalarInitialCondition>();
class ScalarInitialCondition : public MooseObject,
public ScalarCoupleable,
public FunctionInterface,
public UserObjectInterface,
public DependencyResolverInterface
{
public:
@@ -62,6 +64,14 @@ class ScalarInitialCondition : public MooseObject,
*/
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> & getSuppliedItems();
@@ -83,4 +93,3 @@ class ScalarInitialCondition : public MooseObject,
std::set<std::string> _depend_vars;
std::set<std::string> _supplied_vars;
};

@@ -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();
};
@@ -16,6 +16,7 @@
#include "VectorPostprocessorData.h"
#include "Adaptivity.h"
#include "InitialConditionWarehouse.h"
#include "ScalarInitialConditionWarehouse.h"
#include "Restartable.h"
#include "SolverParams.h"
#include "PetscSupport.h"
@@ -1664,7 +1665,7 @@ class FEProblemBase : public SubProblem, public Restartable
///@{
/// Initial condition storage
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
@@ -1954,4 +1955,3 @@ FEProblemBase::allowOutput(bool state)
{
_app.getOutputWarehouse().allowOutput<T>(state);
}

@@ -29,6 +29,7 @@ ScalarInitialCondition::ScalarInitialCondition(const InputParameters & parameter
: MooseObject(parameters),
ScalarCoupleable(this),
FunctionInterface(this),
UserObjectInterface(this),
DependencyResolverInterface(),
_fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
_sys(*getCheckedPointerParam<SystemBase *>("_sys")),
@@ -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();
}
@@ -212,7 +212,6 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters)
_coupling(Moose::COUPLING_DIAG),
_distributions(/*threaded=*/false),
_samplers(_app.getExecuteOnEnum()),
_scalar_ics(/*threaded=*/false),
_material_props(
declareRestartableDataWithContext<MaterialPropertyStorage>("material_props", &_mesh)),
_bnd_material_props(
@@ -678,7 +677,7 @@ FEProblemBase::initialSetup()

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

@@ -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;
};
@@ -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();
}
@@ -0,0 +1,3 @@
time,a
0,-2
1,-2
@@ -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
[]
@@ -3,6 +3,21 @@
type = 'Exodiff'
input = 'geometric_neighbors_ic.i'
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
max_parallel = 2

0 comments on commit 392158a

Please sign in to comment.
You can’t perform that action at this time.