Skip to content

Commit 55ac4bd

Browse files
committed
Initial conditions (idaholab#401)
1 parent 2494078 commit 55ac4bd

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

include/userobjects/FFTBufferBase.h

+3
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ class FFTBufferBase : public GeneralUserObject
7070

7171
/// stride in units of double size
7272
std::ptrdiff_t _stride;
73+
74+
/// optional moose sister variabe (to obtain IC from)
75+
MooseVariable * _moose_variable;
7376
};

src/userobjects/FFTBufferBase.C

+41-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/* Copyright 2017 Battelle Energy Alliance, LLC */
66
/* ALL RIGHTS RESERVED */
77
/**********************************************************************/
8+
89
#include "FFTBufferBase.h"
910
#include "MooseTypes.h"
1011
#include "MyTRIMMesh.h"
@@ -14,15 +15,6 @@
1415

1516
#include <type_traits>
1617

17-
// template <>
18-
// InputParameters
19-
// validParams<FFTBufferBase>()
20-
// {
21-
// InputParameters params = validParams<GeneralUserObject>();
22-
// params.addClassDescription("");
23-
// return params;
24-
// }
25-
2618
template <typename T>
2719
InputParameters
2820
FFTBufferBase<T>::validParams()
@@ -34,8 +26,13 @@ FFTBufferBase<T>::validParams()
3426
"grid > 0",
3527
"Number of grid cells in each dimension to compute "
3628
"the FFT on (can be omitted when using MyTRIMMesh)");
37-
params.addParam<unsigned int>(
38-
"max_h_level", 0, "Further grid refinement to apply when using MyTRIMMesh with adaptivity");
29+
if (std::is_same<T, Real>::value)
30+
params.addParam<AuxVariableName>(
31+
"moose_variable", "Optional AuxVariable to take the initial condition of the buffer from.");
32+
33+
// make sure we run the object on initial to apply the initial conditions
34+
params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
35+
3936
return params;
4037
}
4138

@@ -45,8 +42,8 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
4542
_mesh(_subproblem.mesh()),
4643
_dim(_mesh.dimension()),
4744
_cell_volume(1.0),
48-
_buffer_size(1)
49-
45+
_buffer_size(1),
46+
_moose_variable(nullptr)
5047
{
5148
// make sure Real is double
5249
static_assert(
@@ -56,6 +53,12 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
5653
// FFT needs a regular grid of values to operate on
5754
if (isParamValid("grid"))
5855
{
56+
// cannot specify a corresponding MOOSE Variable when running mesh-less
57+
if (isParamValid("moose_variable"))
58+
paramError("moose_variable",
59+
"You cannot specify a corresponding MOOSE Variable when running mesh-less, i.e. "
60+
"using the 'grid' parameter.");
61+
5962
// if valid use the user-supplied sampling grid
6063
_grid = getParam<std::vector<int>>("grid");
6164
if (_grid.size() != _dim)
@@ -72,10 +75,24 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
7275
_grid.push_back(mytrim_mesh->getCellCountInDimension(i));
7376
}
7477

75-
// refine grid by max_h_level powers of two
76-
auto max_h_level = getParam<unsigned int>("max_h_level");
77-
for (auto & count : _grid)
78-
count = count << max_h_level;
78+
// check optional coupled MOOSE variable (only for Real valued buffers)
79+
if (std::is_same<T, Real>::value && isParamValid("moose_variable"))
80+
{
81+
auto name = getParam<AuxVariableName>("moose_variable");
82+
if (!_subproblem.hasVariable(name))
83+
paramError("moose_variable", "Variable '", name, "' does not exist.");
84+
85+
// get variable
86+
_moose_variable = dynamic_cast<MooseVariable *>(&_subproblem.getVariable(
87+
0, name, Moose::VarKindType::VAR_AUXILIARY, Moose::VarFieldType::VAR_FIELD_STANDARD));
88+
if (!_moose_variable)
89+
paramError(
90+
"moose_variable", "Variable '", name, "' is not a regular auxiliary field variable.");
91+
if (_moose_variable->order() != 0)
92+
paramError("moose_variable", "Variable '", name, "' needs to have CONSTANT order.");
93+
if (_moose_variable->isNodal())
94+
paramError("moose_variable", "Variable '", name, "' must be elemental.");
95+
}
7996

8097
// get mesh extents and calculate space required and estimate spectrum bins
8198
for (unsigned int i = 0; i < _dim; ++i)
@@ -98,6 +115,13 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
98115
istride /= sizeof(Real);
99116
}
100117

118+
template <>
119+
void
120+
FFTBufferBase<Real>::initialize()
121+
{
122+
mooseInfo("Real valued buffer");
123+
}
124+
101125
template <>
102126
Real *
103127
FFTBufferBase<Real>::start(std::size_t i)

0 commit comments

Comments
 (0)