Skip to content

Commit 4d2c93c

Browse files
dschwenrecuero
authored andcommitted
Add FFT problem class (idaholab#401)
1 parent 47bd435 commit 4d2c93c

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

include/problems/FFTProblem.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**********************************************************************/
2+
/* DO NOT MODIFY THIS HEADER */
3+
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
4+
/* */
5+
/* Copyright 2017 Battelle Energy Alliance, LLC */
6+
/* ALL RIGHTS RESERVED */
7+
/**********************************************************************/
8+
9+
#pragma once
10+
11+
#include "FEProblem.h"
12+
#include "AuxiliarySystem.h"
13+
14+
/**
15+
* Enhanced FEProblem that supports FFT buffers as variables
16+
*/
17+
class FFTProblem : public FEProblem
18+
{
19+
public:
20+
static InputParameters validParams();
21+
22+
FFTProblem(const InputParameters & parameters);
23+
~FFTProblem();
24+
25+
virtual bool hasVariable(const std::string & var_name) const override;
26+
virtual MooseVariableFEBase & getVariable(
27+
THREAD_ID tid,
28+
const std::string & var_name,
29+
Moose::VarKindType expected_var_type = Moose::VarKindType::VAR_ANY,
30+
Moose::VarFieldType expected_var_field_type = Moose::VarFieldType::VAR_FIELD_ANY) override;
31+
32+
// getMaterialData
33+
34+
protected:
35+
/// map from variable name to list of variable objects (one per thread)
36+
std::map<std::string, std::vector<MooseVariableFEBase *>> _fft_vars;
37+
38+
/// dummy system for the FFT variables
39+
AuxiliarySystem _fft_dummy_system;
40+
41+
unsigned int _fft_var_number;
42+
};

src/problems/FFTProblem.C

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**********************************************************************/
2+
/* DO NOT MODIFY THIS HEADER */
3+
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
4+
/* */
5+
/* Copyright 2017 Battelle Energy Alliance, LLC */
6+
/* ALL RIGHTS RESERVED */
7+
/**********************************************************************/
8+
9+
#include "FFTProblem.h"
10+
#include "FFTBufferBase.h"
11+
#include "MooseFFTVariable.h"
12+
13+
#include "libmesh/system.h"
14+
15+
registerMooseObject("MagpieApp", FFTProblem);
16+
17+
defineLegacyParams(FFTProblem);
18+
19+
InputParameters
20+
FFTProblem::validParams()
21+
{
22+
InputParameters params = FEProblem::validParams();
23+
params.addClassDescription("Enhanced FEProblem that supports FFT buffers as variables.");
24+
params.set<bool>("skip_nl_system_check") = true;
25+
return params;
26+
}
27+
28+
FFTProblem::FFTProblem(const InputParameters & parameters)
29+
: FEProblem(parameters), _fft_dummy_system(*this, "FFTSystem")
30+
{
31+
}
32+
33+
FFTProblem::~FFTProblem()
34+
{
35+
// delete variable objects
36+
for (auto & var : _fft_vars)
37+
for (auto & t : var.second)
38+
delete t;
39+
}
40+
41+
bool
42+
FFTProblem::hasVariable(const std::string & var_name) const
43+
{
44+
// first check for FFT buffers
45+
std::vector<UserObject *> objs;
46+
theWarehouse().query().condition<AttribThread>(0).condition<AttribName>(var_name).queryInto(objs);
47+
if (!objs.empty() && dynamic_cast<FFTBufferBase<Real> *>(objs[0]))
48+
{
49+
mooseInfo("hasVariable returned true for '", var_name, "' for FFTBuffer");
50+
return true;
51+
}
52+
53+
// fall back to regular variable
54+
if (FEProblem::hasVariable(var_name))
55+
return true;
56+
57+
return false;
58+
}
59+
60+
MooseVariableFEBase &
61+
FFTProblem::getVariable(THREAD_ID tid,
62+
const std::string & var_name,
63+
Moose::VarKindType expected_var_type,
64+
Moose::VarFieldType expected_var_field_type)
65+
{
66+
// first check for FFT buffers
67+
std::vector<UserObject *> objs;
68+
theWarehouse().query().condition<AttribThread>(0).condition<AttribName>(var_name).queryInto(objs);
69+
if (!objs.empty() && dynamic_cast<FFTBufferBase<Real> *>(objs[0]))
70+
{
71+
mooseInfo("getVariable is returning a dummy object for '", var_name, "' for FFTBuffer");
72+
73+
auto & varlist = _fft_vars[var_name];
74+
75+
// add dummy name into the dummy system
76+
unsigned int fft_var_number;
77+
if (varlist.empty())
78+
fft_var_number = _fft_dummy_system.system().add_variable(var_name, CONSTANT, MONOMIAL);
79+
else
80+
fft_var_number = _fft_dummy_system.system().variable_number(var_name);
81+
82+
if (varlist.size() <= tid)
83+
varlist.resize(tid + 1);
84+
85+
auto params = MooseVariableBase::validParams();
86+
params.set<MooseEnum>("order") = "CONSTANT";
87+
params.set<MooseEnum>("family") = "MONOMIAL";
88+
params.set<unsigned int>("_var_num") = _fft_var_number;
89+
params.set<THREAD_ID>("tid") = tid;
90+
params.set<THREAD_ID>("_tid") = tid;
91+
params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
92+
params.set<SystemBase *>("_system_base") = &_fft_dummy_system;
93+
params.set<MooseApp *>("_moose_app") = &_app;
94+
params.set<std::string>("_type") = "MooseFFTVariable";
95+
params.set<std::string>("_object_name") = var_name;
96+
params.set<FEProblemBase *>("_fe_problem_base") = this;
97+
varlist[tid] = new MooseFFTVariable(params);
98+
99+
return *varlist[tid];
100+
}
101+
102+
return FEProblem::getVariable(tid, var_name, expected_var_type, expected_var_field_type);
103+
}

0 commit comments

Comments
 (0)