Skip to content

Commit

Permalink
Initial conditions (idaholab#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jan 21, 2020
1 parent 2494078 commit 55ac4bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
3 changes: 3 additions & 0 deletions include/userobjects/FFTBufferBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ class FFTBufferBase : public GeneralUserObject

/// stride in units of double size
std::ptrdiff_t _stride;

/// optional moose sister variabe (to obtain IC from)
MooseVariable * _moose_variable;
};
58 changes: 41 additions & 17 deletions src/userobjects/FFTBufferBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#include "FFTBufferBase.h"
#include "MooseTypes.h"
#include "MyTRIMMesh.h"
Expand All @@ -14,15 +15,6 @@

#include <type_traits>

// template <>
// InputParameters
// validParams<FFTBufferBase>()
// {
// InputParameters params = validParams<GeneralUserObject>();
// params.addClassDescription("");
// return params;
// }

template <typename T>
InputParameters
FFTBufferBase<T>::validParams()
Expand All @@ -34,8 +26,13 @@ FFTBufferBase<T>::validParams()
"grid > 0",
"Number of grid cells in each dimension to compute "
"the FFT on (can be omitted when using MyTRIMMesh)");
params.addParam<unsigned int>(
"max_h_level", 0, "Further grid refinement to apply when using MyTRIMMesh with adaptivity");
if (std::is_same<T, Real>::value)
params.addParam<AuxVariableName>(
"moose_variable", "Optional AuxVariable to take the initial condition of the buffer from.");

// make sure we run the object on initial to apply the initial conditions
params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;

return params;
}

Expand All @@ -45,8 +42,8 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
_mesh(_subproblem.mesh()),
_dim(_mesh.dimension()),
_cell_volume(1.0),
_buffer_size(1)

_buffer_size(1),
_moose_variable(nullptr)
{
// make sure Real is double
static_assert(
Expand All @@ -56,6 +53,12 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
// FFT needs a regular grid of values to operate on
if (isParamValid("grid"))
{
// cannot specify a corresponding MOOSE Variable when running mesh-less
if (isParamValid("moose_variable"))
paramError("moose_variable",
"You cannot specify a corresponding MOOSE Variable when running mesh-less, i.e. "
"using the 'grid' parameter.");

// if valid use the user-supplied sampling grid
_grid = getParam<std::vector<int>>("grid");
if (_grid.size() != _dim)
Expand All @@ -72,10 +75,24 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
_grid.push_back(mytrim_mesh->getCellCountInDimension(i));
}

// refine grid by max_h_level powers of two
auto max_h_level = getParam<unsigned int>("max_h_level");
for (auto & count : _grid)
count = count << max_h_level;
// check optional coupled MOOSE variable (only for Real valued buffers)
if (std::is_same<T, Real>::value && isParamValid("moose_variable"))
{
auto name = getParam<AuxVariableName>("moose_variable");
if (!_subproblem.hasVariable(name))
paramError("moose_variable", "Variable '", name, "' does not exist.");

// get variable
_moose_variable = dynamic_cast<MooseVariable *>(&_subproblem.getVariable(
0, name, Moose::VarKindType::VAR_AUXILIARY, Moose::VarFieldType::VAR_FIELD_STANDARD));
if (!_moose_variable)
paramError(
"moose_variable", "Variable '", name, "' is not a regular auxiliary field variable.");
if (_moose_variable->order() != 0)
paramError("moose_variable", "Variable '", name, "' needs to have CONSTANT order.");
if (_moose_variable->isNodal())
paramError("moose_variable", "Variable '", name, "' must be elemental.");
}

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

template <>
void
FFTBufferBase<Real>::initialize()
{
mooseInfo("Real valued buffer");
}

template <>
Real *
FFTBufferBase<Real>::start(std::size_t i)
Expand Down

0 comments on commit 55ac4bd

Please sign in to comment.