Commit 90ecd9a2 authored by Kevin Dugan's avatar Kevin Dugan

Registering giraffe objects in main

parent 040ab65f
#ifndef NEKINTERFACE_H
#define NEKINTERFACE_H
#include "Moose.h"
// String length for file paths in Nek5000
#define PATHLEN 132
namespace Nek5000
{
// Nek Fortran interface
extern "C" {
// CFILES common block
extern struct {
char \
reafle[PATHLEN], \
fldfle[PATHLEN], \
dmpfle[PATHLEN], \
hisfle[PATHLEN], \
schfle[PATHLEN], \
orefle[PATHLEN], \
nrefle[PATHLEN];
} cfiles_;
// DIMN common block
extern struct {
int \
nelv, \
nelt, \
nx1, \
ny1, \
nz1, \
nx2, \
ny2, \
nz2, \
nx3, \
ny3, \
nz3, \
ndim, \
nfield,\
npert, \
nid, \
nxd, \
nyd, \
nzd;
} dimn_;
// DIMN common block
extern struct {
double flux_moose, temp_nek;
} test_passing_;
extern struct {
double coeff_tij[];
} expansion_tcoef_;
extern struct {
double coeff_fij[];
} expansion_fcoef_;
// subroutine nek_init(intracomm)
void FORTRAN_CALL(nek_init)(const int&); // Ron likes this better now
void FORTRAN_CALL(nek_init_step)();
void FORTRAN_CALL(nek_step)();
void FORTRAN_CALL(nek_finalize_step)();
void FORTRAN_CALL(nek_expansion)();
void FORTRAN_CALL(flux_reconstruction)();
}
}
#endif /* NEKINTERFACE_H */
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef FOURIERLEGENDRERECONSTRUCTION_H
#define FOURIERLEGENDRERECONSTRUCTION_H
#include "Function.h"
#include "math.h"
#include "FourierPolynomial.h"
#include "LegendrePolynomial.h"
class FourierLegendreReconstruction : public Function
{
public:
FourierLegendreReconstruction(const InputParameters & parameters);
virtual ~FourierLegendreReconstruction();
virtual Real value(Real t, const Point & p);
protected:
/// Debug flag to print debug output
bool _dbg;
/// The coordinate directions of the integration for Legendre polynomial
int _l_direction;
/// The coordinate directions of the itnegration for Fourier polynomials
int _f_direction_1;
int _f_direction_2;
/// The order of the Legendre expansion
int _l_order;
/// The order of the Fourier expansion
int _f_order;
/// The vector of scalar variables holding the coefficients
std::vector<VariableValue *> _poly_scalars;
/// Legendre polynomial object. TODO address dynamic casting of this object
LegendrePolynomial & _legendre_poly_function;
/// Fourier polynomial object. TODO address dynamic casting of this object
FourierPolynomial & _fourier_poly_function;
private:
};
template<>
InputParameters validParams<FourierLegendreReconstruction>();
#endif
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef FOURIERPOLYNOMIAL_H
#define FOURIERPOLYNOMIAL_H
#include "Function.h"
#include "math.h"
class FourierPolynomial : public Function
{
public:
FourierPolynomial(const InputParameters & parameters);
virtual ~FourierPolynomial();
virtual Real value(Real t, const Point & p);
Real getPolynomialValue(Real t, Real p1, Real p2, int n);
protected:
private:
bool _dbg; // Debug flag to print debug output
};
template<>
InputParameters validParams<FourierPolynomial>();
#endif
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef LEGENDREPOLYNOMIAL_H
#define LEGENDREPOLYNOMIAL_H
#include "Function.h"
#include "math.h"
class LegendrePolynomial : public Function
{
public:
LegendrePolynomial(const InputParameters & parameters);
virtual ~LegendrePolynomial();
virtual Real value(Real t, const Point & p);
Real getPolynomialValue(Real t, Real p, int n);
protected:
private:
std::vector<Real> _geom_norm; // Pin Radius that is used for normalization
Real _dz; // Total length of the domain
bool _dbg; // Debug flag to print debug output
};
template<>
InputParameters validParams<LegendrePolynomial>();
#endif
#ifndef MULTIAPPPOLYNOMIALTONEK_H
#define MULTIAPPPOLYNOMIALTONEK_H
// MOOSE includes
#include "MultiAppTransfer.h"
// Forward declerations
class MultiAppPolynomialToNek;
template<>
InputParameters validParams<MultiAppPolynomialToNek>();
/**
* Copies the value of a Postprocessor from one app to a scalar AuxVariable in another.
*/
class MultiAppPolynomialToNek :
public MultiAppTransfer
{
public:
MultiAppPolynomialToNek(const InputParameters & parameters);
/**
* Execute the transfer
*/
virtual void execute() override;
protected:
std::vector<VariableName> _source_variable_names;
std::vector<VariableName> _to_aux_names;
};
#endif /* MULTIAPPPOLYNOMIALTONEK_H */
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef NEKSIDEINTEGRALVARIABLEUSEROBJECT_H
#define NEKSIDEINTEGRALVARIABLEUSEROBJECT_H
#include "SideIntegralUserObject.h"
#include "MooseVariableInterface.h"
#include "LegendrePolynomial.h"
#include "FourierPolynomial.h"
//Forward Declarations
class NekSideIntegralVariableUserObject;
template<>
InputParameters validParams<NekSideIntegralVariableUserObject>();
/**
* This postprocessor computes the projection of solution field to an expansion
*/
class NekSideIntegralVariableUserObject :
public SideIntegralUserObject,
public MooseVariableInterface<Real>
{
public:
NekSideIntegralVariableUserObject(const InputParameters & parameters);
protected:
virtual Real computeQpIntegral() override;
virtual void finalize() override;
/// Holds the solution at current quadrature points
const VariableValue & _u;
/// Legendre polynomial object. TODO address dynamic casting of this object
LegendrePolynomial & _legendre_poly_function;
/// Fourier polynomial object. TODO address dynamic casting of this object
FourierPolynomial & _fourier_poly_function;
/// The coordinate directions of the integration for Legendre polynomial
int _l_direction;
/// The coordinate directions of the itnegration for Fourier polynomials
int _f_direction_1;
int _f_direction_2;
/// The order of the Legendre polynomial
int _l_order;
/// The order of the Fourier polynomial
int _f_order;
/// The name of the aux scalar index by l_order
std::string _aux_scalar_name;
/// The coupled gradient for heat flux
const VariableGradient & _coupled_grad;
/// Thermal conductivity (diffusion coefficient)
const MaterialProperty<Real> & _diffusion_coefficient;
/// The name of the post processor that calculates the surface area
const PostprocessorValue & _surface_area_pp;
};
#endif
......@@ -4,6 +4,17 @@
#include "ModulesApp.h"
#include "MooseSyntax.h"
// Functions
#include "LegendrePolynomial.h"
#include "FourierPolynomial.h"
#include "FourierLegendreReconstruction.h"
// User Objects
#include "NekSideIntegralVariableUserObject.h"
// Transfers
#include "MultiAppPolynomialToNek.h"
template <>
InputParameters
validParams<GiraffeApp>()
......@@ -39,6 +50,14 @@ void
GiraffeApp::registerObjects(Factory & factory)
{
Registry::registerObjectsTo(factory, {"GiraffeApp"});
registerFunction(LegendrePolynomial);
registerFunction(FourierPolynomial);
registerFunction(FourierLegendreReconstruction);
registerUserObject(NekSideIntegralVariableUserObject);
registerTransfer(MultiAppPolynomialToNek);
}
void
......
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "FourierLegendreReconstruction.h"
template<>
InputParameters validParams<FourierLegendreReconstruction>()
{
InputParameters params = validParams<Function>();
params.addParam<bool>("dbg", false, "Print debug output");
params.addRequiredParam<int>("l_order", "The order of the Legendre expansion");
params.addRequiredParam<int>("f_order", "The order of the Fourier expansion");
params.addRequiredParam<int>("l_direction", "Direction of integration for Legendre polynomial");
params.addRequiredParam<std::string>("legendre_function_name", "Name of function to compute Legendre polynomial value at a point");
params.addRequiredParam<std::string>("fourier_function_name", "Name of function to compute Fourier polynomial value at a point");
params.addRequiredCoupledVar("poly_scalars", "Name of aux variable containing the Zernike coefficients");
return params;
}
FourierLegendreReconstruction::FourierLegendreReconstruction(const InputParameters & parameters) :
Function(parameters),
_dbg(parameters.get<bool>("dbg")),
_l_direction(parameters.get<int>("l_direction")),
_l_order(parameters.get<int>("l_order")),
_f_order(parameters.get<int>("f_order")),
_legendre_poly_function(dynamic_cast<LegendrePolynomial&>(_mci_feproblem.getFunction(parameters.get<std::string>("legendre_function_name")))),
_fourier_poly_function(dynamic_cast<FourierPolynomial&>(_mci_feproblem.getFunction(parameters.get<std::string>("fourier_function_name"))))
{
// For now hard code that l_direction better be 2
// TODO come back and put logic in to determine f diections given l directions
if ( _l_direction == 2)
{
_f_direction_1 = 0;
_f_direction_2 = 1;
}
else
{
mooseError("Need to implement logic for l direction not equal to 2");
}
// Get the coupled scalar variables storing the expansion coefficients
for(int i=0; i < _f_order; i++)
_poly_scalars.push_back(&coupledScalarValue("poly_scalars",i));
}
FourierLegendreReconstruction::~FourierLegendreReconstruction()
{
}
Real
FourierLegendreReconstruction::value(Real t, const Point & p)
{
Real val = 0.0;
for (int f=0; f<_f_order; f++)
{
for (int l=0; l<_l_order; l++)
{
val += (*_poly_scalars[f])[l]
* _legendre_poly_function.getPolynomialValue(t,p(_l_direction),l)
* _fourier_poly_function.getPolynomialValue(t,p(_f_direction_1),p(_f_direction_2),f);
}
}
return val;
}
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "FourierPolynomial.h"
template<>
InputParameters validParams<FourierPolynomial>()
{
InputParameters params = validParams<Function>();
params.addParam<bool>("dbg", "Print debug output");
return params;
}
FourierPolynomial::FourierPolynomial(const InputParameters & parameters) :
Function(parameters),
_dbg(parameters.get<bool>("dbg"))
{
}
FourierPolynomial::~FourierPolynomial()
{
}
Real
FourierPolynomial::value(Real t, const Point & p)
{
mooseWarning("value() in FourierPolynomial should not be used");
return 0.0;
}
Real
FourierPolynomial::getPolynomialValue(Real t, Real p1, Real p2, int n)
{
Real phi = atan2(p2, p1);
if (n == 0)
return 1.0 / ( sqrt(2.0 * M_PI) );
else
return cos(n * phi) / ( sqrt(M_PI) );
}
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "LegendrePolynomial.h"
template<>
InputParameters validParams<LegendrePolynomial>()
{
InputParameters params = validParams<Function>();
params.addRequiredParam<std::vector<Real> >("l_geom_norm","Lengths needed for Legendre polynomial normalization (min, max)");
params.addParam<bool>("dbg", false, "Print debug output");
return params;
}
LegendrePolynomial::LegendrePolynomial(const InputParameters & parameters) :
Function(parameters),
_geom_norm(parameters.get<std::vector<Real> >("l_geom_norm")),
_dbg(parameters.get<bool>("dbg"))
{
_dz = _geom_norm[1] - _geom_norm[0];
}
LegendrePolynomial::~LegendrePolynomial()
{
}
Real
LegendrePolynomial::value(Real t, const Point & p)
{
mooseWarning("value() in LegendrePolynomial should not be used");
return 0.0;
}
Real
LegendrePolynomial::getPolynomialValue(Real t, Real p, int n)
{
Real z; // Normalized position
Real plm2 = 0.0; // L-2 Legendre polynomial value
Real plm1 = 0.0; // L-1 Legendre polynomial value
Real plm = 0.0; // L Legendre polynomial value
z = 2.0 * (p - _geom_norm[0])/(_dz) - 1.0;
if(_dbg)
{
Moose::out<<"point: " << p << std::endl;
Moose::out<<"dz = "<< _dz << std::endl;
Moose::out<<"_geom_norm[0] = "<<_geom_norm[0]<<std::endl;
Moose::out<<"Normalized z = "<<z<<std::endl;
}
// 0th order
if (n == 0) // O order
return 1.0 / sqrt(2.0);
if (n == 1) // 1 order
return sqrt(3.0 / 2.0) * z;
else
{
plm2 = 1.0;
plm1 = z;
for(int ii=2; ii <= n; ii++)
{
plm = z*(2.0*ii - 1.0)/ii * plm1 - (ii - 1.0)/(ii)*plm2;
plm2 = plm1;
plm1 = plm;
}
if(_dbg)
Moose::out<<"Legendre total value = "<<(plm * (2.0 * n + 1.0) / _dz)<<std::endl;
return (plm * sqrt((2.0 * n + 1.0) / 2.0));
}
}
#include "MultiAppPolynomialToNek.h"
#include "NekInterface.h"
// MOOSE includes
#include "MooseTypes.h"
#include "FEProblem.h"
#include "MultiApp.h"
#include "MooseVariableScalar.h"
#include "SystemBase.h"
// libMesh includes
#include "libmesh/meshfree_interpolation.h"
#include "libmesh/system.h"
// Define the input parameters
template<>
InputParameters validParams<MultiAppPolynomialToNek>()
{
InputParameters params = validParams<MultiAppTransfer>();
params.addRequiredParam<std::vector<VariableName> >("source_variable", "The auxiliary scalar variable to read values from");
params.addRequiredParam<std::vector<VariableName> >("to_aux_scalar", "The name of the scalar Aux variable in the MultiApp to transfer the value to.");
return params;
}
MultiAppPolynomialToNek::MultiAppPolynomialToNek(const InputParameters & parameters) :
MultiAppTransfer(parameters),
_source_variable_names(getParam<std::vector<VariableName> >("source_variable")),
_to_aux_names(getParam<std::vector<VariableName> >("to_aux_scalar"))
{
}
void
MultiAppPolynomialToNek::execute()
{
_console << "Beginning PolynomialToNekTransfer " << name() << std::endl;
// Perform action based on the transfer direction
switch (_direction)
{
// MasterApp -> SubApp
case TO_MULTIAPP:
{
FEProblemBase & from_problem = _multi_app->problemBase();
std::vector<MooseVariableScalar *> source_variables(_source_variable_names.size());
for (auto i = beginIndex(_source_variable_names); i < _source_variable_names.size(); ++i)
{
source_variables[i] = &from_problem.getScalarVariable(_tid, _source_variable_names[i]);
source_variables[i]->reinit();
}
// Loop through each of the sub apps
for (unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
{
// TODO: Access Nek Common blocks and write values
for (auto i = beginIndex(_source_variable_names); i < _source_variable_names.size(); ++i)
{
_console << _source_variable_names[i] << '\n';
auto & solution_values = source_variables[i]->sln();
for (auto j = beginIndex(solution_values); j < solution_values.size(); ++j)
{
_console << solution_values[j] << ' ';
Nek5000::expansion_fcoef_.coeff_fij[i*100+j] = solution_values[j];
}
_console << '\n';
}
}
FORTRAN_CALL(Nek5000::flux_reconstruction)();
break;
}
// SubApp -> MasterApp
case FROM_MULTIAPP:
{
FORTRAN_CALL(Nek5000::nek_expansion)();
// The number of sub applications
unsigned int num_apps = _multi_app->numGlobalApps();
std::vector<MooseVariableScalar *> to_variables(_to_aux_names.size());
for (auto i = beginIndex(_to_aux_names); i < _to_aux_names.size(); ++i)
{
to_variables[i] = &_multi_app->problemBase().getScalarVariable(_tid, _to_aux_names[i]);
to_variables[i]->reinit();
}
for (auto i = beginIndex(_to_aux_names); i < _to_aux_names.size(); ++i)
{
// The dof indices for the scalar variable of interest
std::vector<dof_id_type> & dof = to_variables[i]->dofIndices();
// // Error if there is a size mismatch between the scalar AuxVariable and the number of sub apps
// if (num_apps != scalar.sln().size())
// mooseError("The number of sub apps (" << num_apps << ") must be equal to the order of the scalar AuxVariable (" << scalar.order() << ")");
// Loop over each sub-app and populate the AuxVariable values from the postprocessors
// for (unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
// if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor())
// Note: This can't be done using MooseScalarVariable::insert() because different processors will be setting dofs separately.
auto & solution_values = to_variables[i]->sln();
for (auto j = beginIndex(solution_values); j < solution_values.size(); ++j)
{
to_variables[i]->sys().solution().set(dof[j], Nek5000::expansion_tcoef_.coeff_tij[i*100+j]);
to_variables[i]->sys().solution().close();
}
}
break;
}
}
_console << "Finished PolynomialToNekTransfer" << name() << std::endl;
}
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "NekSideIntegralVariableUserObject.h"
#include "MooseVariableScalar.h"
#include "SystemBase.h"
template<>
InputParameters validParams<NekSideIntegralVariableUserObject>()
{
InputParameters params = validParams<SideIntegralUserObject>();
params.addRequiredCoupledVar("variable", "The name of the variable that will be integrated");
params.addRequiredParam<std::string>("legendre_function_name", "Name of function to compute Legendre polynomial value at a point");
params.addRequiredParam<std::string>("fourier_function_name", "Name of function to compute Fourier polynomial value at a point");
params.addRequiredParam<int>("l_direction", "Direction of integration for Legendre polynomial");
params.addRequiredParam<int>("l_order", "The order of the Legendre expansion");
params.addRequiredParam<int>("f_order", "The order of the Fourier expansion");
params.addRequiredParam<std::string>("aux_scalar_name", "Aux scalar to store the Legendre expansion coefficient");
params.addParam<MaterialPropertyName>("diffusion_coefficient_name",
"thermal_conductivity",
"Property name of the diffusivity (Default: thermal_conductivity)");
params.addRequiredParam<std::string>("surface_area_pp", "The name of the post processor that calculates surface area");
return params;
}
NekSideIntegralVariableUserObject::NekSideIntegralVariableUserObject(const InputParameters & parameters) :
// TODO we really shouldn't have to dynamic cast into FourierPolynomial and Legendre Polynomial here
// but this was a quick example