Skip to content

Commit

Permalink
Add FFT problem class (idaholab#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jan 20, 2020
1 parent 67a82f0 commit e16e74f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
40 changes: 40 additions & 0 deletions include/problems/FFTProblem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#pragma once

#include "FEProblem.h"
#include "AuxiliarySystem.h"

/**
* Enhanced FEProblem that supports FFT buffers as variables
*/
class FFTProblem : public FEProblem
{
public:
static InputParameters validParams();

FFTProblem(const InputParameters & parameters);
~FFTProblem();

virtual bool hasVariable(const std::string & var_name) const override;
virtual MooseVariableFEBase & getVariable(
THREAD_ID tid,
const std::string & var_name,
Moose::VarKindType expected_var_type = Moose::VarKindType::VAR_ANY,
Moose::VarFieldType expected_var_field_type = Moose::VarFieldType::VAR_FIELD_ANY) override;

protected:
/// map from variable name to list of variable objects (one per thread)
std::map<std::string, std::vector<MooseVariableFEBase *>> _fft_vars;

/// dummy system for the FFT variables
AuxiliarySystem _fft_dummy_system;

unsigned int _fft_var_number;
};
92 changes: 92 additions & 0 deletions src/problems/FFTProblem.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#include "FFTProblem.h"
#include "FFTBufferBase.h"
#include "MooseFFTVariable.h"

#include "libmesh/system.h"

registerMooseObject("MagpieApp", FFTProblem);

defineLegacyParams(FFTProblem);

InputParameters
FFTProblem::validParams()
{
InputParameters params = FFTProblem::validParams();
params.addClassDescription("Enhanced FEProblem that supports FFT buffers as variables.");

return params;
}

FFTProblem::FFTProblem(const InputParameters & parameters)
: FEProblem(parameters), _fft_dummy_system(*this, "FFTSystem")
{
// add dummy name into the dummy system
_fft_var_number = _fft_dummy_system.system().add_variable("DUMMYFFT", CONSTANT, MONOMIAL);
}

FFTProblem::~FFTProblem()
{
// delete variable objects
for (auto & var : _fft_vars)
for (auto & t : var.second)
delete t;
}

bool
FFTProblem::hasVariable(const std::string & var_name) const
{
// first check for FFT buffers
std::vector<UserObject *> objs;
theWarehouse().query().condition<AttribThread>(0).condition<AttribName>(var_name).queryInto(objs);
if (!objs.empty() && dynamic_cast<FFTBufferBase<Real> *>(objs[0]))
{
mooseInfo("hasVariable returned true for '", var_name, "' for FFTBuffer");
return true;
}

// fall back to regular variable
if (FEProblem::hasVariable(var_name))
return true;

return false;
}

MooseVariableFEBase &
FFTProblem::getVariable(THREAD_ID tid,
const std::string & var_name,
Moose::VarKindType expected_var_type,
Moose::VarFieldType expected_var_field_type)
{
// first check for FFT buffers
std::vector<UserObject *> objs;
theWarehouse().query().condition<AttribThread>(0).condition<AttribName>(var_name).queryInto(objs);
if (!objs.empty() && dynamic_cast<FFTBufferBase<Real> *>(objs[0]))
{
mooseInfo("getVariable is returning a dummy object for '", var_name, "' for FFTBuffer");

auto & varlist = _fft_vars[var_name];
if (varlist.size() <= tid)
varlist.resize(tid + 1);

auto params = MooseVariableBase::validParams();
params.set<MooseEnum>("order") = "CONSTANT";
params.set<MooseEnum>("family") = "MONOMIAL";
params.set<unsigned int>("_var_num") = _fft_var_number;
params.set<THREAD_ID>("tid") = tid;
params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
params.set<SystemBase *>("_system_base") = &_fft_dummy_system;
varlist[tid] = new MooseFFTVariable(params);

return *varlist[tid];
}

return FEProblem::getVariable(tid, var_name, expected_var_type, expected_var_field_type);
}

0 comments on commit e16e74f

Please sign in to comment.