forked from idaholab/magpie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FFT problem class (idaholab#401)
- Loading branch information
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |