Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/actions/AddFoamBCAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class AddFoamBCAction : public MooseObjectAction
void createAuxVariable();

// Create Receiver for Postprocessor-based BCs
void createReceiver(FoamProblem & problem);
void createReceiver(FEProblemBase & problem);
};
36 changes: 36 additions & 0 deletions include/base/HippoInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "InputParameters.h"
#include "MooseObject.h"
#include "fvMesh.H"

class FoamProblem;
class FoamMesh;

/*
HippoInterface is a base class containing convenient access to common
Hippo and Foam objects such as Foam::Time, Foam::fvMesh and
FoamProblem.
*/
class HippoInterface
Comment thread
k-collie marked this conversation as resolved.
Comment thread
k-collie marked this conversation as resolved.
{
public:
explicit HippoInterface(const MooseObject * moose_object);

protected:
// Retrieves FoamProblem
FoamProblem & getFoamProblem() const;

// Retrieves FoamMesh
FoamMesh & getFoamMesh() const;

// Retrieves Underlying OpenFOAM mesh object
Foam::fvMesh & getFvMesh() const;

// Retrieves OpenFOAM time object
Foam::Time & getFoamTime() const;

private:
FoamProblem & _foam_problem;
static FoamProblem & extractFoamProblem(const MooseObject *);
};
16 changes: 16 additions & 0 deletions include/base/HippoObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "InputParameters.h"
#include "MooseObject.h"
#include "HippoInterface.h"

/*
HippoObject is a base class for MooseObjects accessing OpenFOAM
objects
*/
class HippoObject : public MooseObject, protected HippoInterface
{
public:
static InputParameters validParams();
HippoObject(const InputParameters & params);
};
9 changes: 2 additions & 7 deletions include/bcs/FoamBCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

#include <Coupleable.h>
#include <InputParameters.h>
#include <MooseObject.h>
#include <MooseTypes.h>
#include <MooseVariableFieldBase.h>
#include <volFieldsFwd.H>
#include "MooseError.h"
#include "HippoObject.h"

typedef std::tuple<std::string, std::string, std::string, std::string, std::string, std::string>
BCInfoTableRow;
Expand All @@ -20,7 +18,7 @@ enum class FoamBCType
fixedGradient
};

class FoamBCBase : public MooseObject, public Coupleable
class FoamBCBase : public HippoObject, public Coupleable
{
public:
static InputParameters validParams();
Expand Down Expand Up @@ -66,9 +64,6 @@ class FoamBCBase : public MooseObject, public Coupleable
// Pointer to Moose variable used to impose BC
MooseVariableFieldBase * _moose_var;

// Pointer to the FoamMesh object
FoamMesh * _mesh;

// Boundaries that this object applies to
// TODO: Replace with inherited from BoundaryRestricted once FoamMesh is updated
std::vector<SubdomainName> _boundary;
Expand Down
24 changes: 8 additions & 16 deletions include/postprocessors/FoamPostprocessorBase.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
#pragma once

#include "GeneralPostprocessor.h"
#include "HippoInterface.h"
#include "fvCFD_moose.h"

#include "InputParameters.h"
#include "Postprocessor.h"
#include "ElementUserObject.h"

class FoamPostprocessorBase : public ElementUserObject, public Postprocessor
class FoamPostprocessorBase : public GeneralPostprocessor, protected HippoInterface
{
public:
static InputParameters validParams();

FoamPostprocessorBase(const InputParameters & params);

// We dont want the usual UserObject functions to be executed
// But we still want the Foam Postprocessors to be reported with the other
// Foam postprocessors
virtual void initialize() final;

virtual void execute() final;
// We still want the Foam Postprocessors to be reported with the other
// postprocessors but we want to define them empty
void initialize() final {};

virtual void finalize() final;
void execute() final {};

virtual void threadJoin([[maybe_unused]] const UserObject & uo) final {};
void finalize() final {};

// Compute postprocessor, to be called within FoamProblem
virtual void compute() = 0;

protected:
Foam::fvMesh * _foam_mesh;
};
2 changes: 2 additions & 0 deletions include/postprocessors/FoamSidePostprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class FoamSidePostprocessor : public FoamPostprocessorBase

FoamSidePostprocessor(const InputParameters & params);

const std::vector<SubdomainName> & boundary() const { return _boundary; }

protected:
std::vector<SubdomainName> _boundary;
};
8 changes: 2 additions & 6 deletions include/variables/FoamVariableField.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "MooseObject.h"
#include "FoamMesh.h"
#include "HippoObject.h"

class FoamVariableField : public MooseObject
class FoamVariableField : public HippoObject
{
public:
static InputParameters validParams();
Expand All @@ -19,7 +18,4 @@ class FoamVariableField : public MooseObject
protected:
// variable name or functionObject to be shadowed
std::string _foam_variable;

// Pointer to the FoamMesh object
FoamMesh * _mesh;
};
10 changes: 3 additions & 7 deletions src/actions/AddFoamBCAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,20 @@ AddFoamBCAction::AddFoamBCAction(const InputParameters & params) : MooseObjectAc
void
AddFoamBCAction::act()
{
auto foam_problem = dynamic_cast<FoamProblem *>(_problem.get());

// Adding BCs using [FoamBC] syntax
if (_current_task == "add_foam_bc")
{
if (!foam_problem)
mooseError("FoamBCs system can only be used with FoamProblem.");
Comment thread
mattfalcone1997 marked this conversation as resolved.

// Do not create aux variable if variable provided.
if (findParamKey(_moose_object_pars, "v") && !_moose_object_pars.isParamSetByUser("v"))
createAuxVariable();

// Create receiver if pp_name not provided and pp_name is an allowed parameter
if (findParamKey(_moose_object_pars, "pp_name") &&
!_moose_object_pars.isParamSetByUser("pp_name"))
createReceiver(*foam_problem);
createReceiver(*_problem);

foam_problem->addObject<FoamBCBase>(_type, _name, _moose_object_pars, false);
_problem->addObject<FoamBCBase>(_type, _name, _moose_object_pars, false);
}
}

Expand Down Expand Up @@ -74,7 +70,7 @@ AddFoamBCAction::createAuxVariable()
}

void
AddFoamBCAction::createReceiver(FoamProblem & problem)
AddFoamBCAction::createReceiver(FEProblemBase & problem)
{
auto params = _factory.getValidParams("Receiver");

Expand Down
6 changes: 1 addition & 5 deletions src/actions/AddFoamVariableAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ AddFoamVariableAction::AddFoamVariableAction(const InputParameters & parameters)
void
AddFoamVariableAction::act()
{
auto * foam_problem = dynamic_cast<FoamProblem *>(_problem.get());

// Add variable through [FoamVariables] block
if (_current_task == "add_foam_variable")
{
if (!foam_problem)
mooseError("FoamVariables system can only be used with FoamProblem.");

createAuxVariable();

foam_problem->addObject<FoamVariableField>(_type, _name, _moose_object_pars, false);
_problem->addObject<FoamVariableField>(_type, _name, _moose_object_pars, false);
}
}

Expand Down
45 changes: 45 additions & 0 deletions src/base/HippoInterface.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "FoamProblem.h"
#include "HippoInterface.h"
#include "InputParameters.h"
#include "MooseObject.h"
#include "OutputInterface.h"

HippoInterface::HippoInterface(const MooseObject * moose_object)
: _foam_problem(extractFoamProblem(moose_object))
{
}

FoamProblem &
HippoInterface::getFoamProblem() const
{
return _foam_problem;
}

FoamMesh &
HippoInterface::getFoamMesh() const
{
return _foam_problem.mesh();
}

Foam::fvMesh &
HippoInterface::getFvMesh() const
{
return getFoamMesh().fvMesh();
}

Foam::Time &
HippoInterface::getFoamTime() const
{
return const_cast<Foam::Time &>(getFvMesh().time());
}

FoamProblem &
HippoInterface::extractFoamProblem(const MooseObject * moose_object)
{
const InputParameters & params = moose_object->parameters();
auto * problem = params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base");
auto * foam_problem = dynamic_cast<FoamProblem *>(problem);
if (!foam_problem)
mooseError(moose_object->type(), " can only be used with FoamProblem");
return *foam_problem;
}
11 changes: 11 additions & 0 deletions src/base/HippoObject.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "HippoObject.h"

InputParameters
HippoObject::validParams()
{
return MooseObject::validParams();
}

HippoObject::HippoObject(const InputParameters & params) : MooseObject(params), HippoInterface(this)
{
}
42 changes: 16 additions & 26 deletions src/bcs/FoamBCBase.C
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#include "FoamBCBase.h"
#include "FoamProblem.h"
#include "HippoObject.h"

#include <Coupleable.h>
#include <InputParameters.h>
#include <MooseError.h>
#include <MooseObject.h>
#include <MooseTypes.h>
#include <MooseVariableFieldBase.h>
#include <Registry.h>
Expand Down Expand Up @@ -34,13 +34,11 @@ bc_type_to_string(FoamBCType const & bc_type)
InputParameters
FoamBCBase::validParams()
{
InputParameters params = MooseObject::validParams();
InputParameters params = HippoObject::validParams();
params.addRequiredParam<std::string>("foam_variable",
"Name of a Foam field. e.g. T (temperature) U (velocity).");
params.addParam<std::vector<SubdomainName>>("boundary",
"Boundaries that the boundary condition applies to.");
params.addRequiredParam<std::string>("foam_variable",
"Name of a Foam field. e.g. T (temperature) U (velocity).");

params.registerSystemAttributeName("FoamBC");
params.registerBase("FoamBC");
Expand All @@ -49,25 +47,19 @@ FoamBCBase::validParams()
}

FoamBCBase::FoamBCBase(const InputParameters & params, const FoamBCType bc_type)
: MooseObject(params),
: HippoObject(params),
Coupleable(this, false),
_foam_variable(params.get<std::string>("foam_variable")),
_boundary(params.get<std::vector<SubdomainName>>("boundary")),
_patch_replaced(false)
{
auto * problem = dynamic_cast<FoamProblem *>(&_c_fe_problem);
if (!problem)
mooseError("FoamBC system can only be used with FoamProblem");

_mesh = &problem->mesh();

// check that the foam variable exists
if (!params.isPrivate("foam_variable") &&
!_mesh->foamHasObject<Foam::volScalarField>(_foam_variable))
!getFoamMesh().foamHasObject<Foam::volScalarField>(_foam_variable))
mooseError("There is no OpenFOAM field named '", _foam_variable, "'");

// check that the boundary is in the FoamMesh
auto all_subdomain_names = _mesh->getSubdomainNames(_mesh->getSubdomainList());
auto all_subdomain_names = getFoamMesh().getSubdomainNames(getFoamMesh().getSubdomainList());
for (auto subdomain : _boundary)
{
auto it = std::find(all_subdomain_names.begin(), all_subdomain_names.end(), subdomain);
Expand All @@ -80,9 +72,9 @@ FoamBCBase::FoamBCBase(const InputParameters & params, const FoamBCType bc_type)

for (auto subdomain : _boundary)
{
if (_mesh->foamHasObject<Foam::volScalarField>(_foam_variable))
if (getFoamMesh().foamHasObject<Foam::volScalarField>(_foam_variable))
constructFoamScalarPatch(subdomain, bc_type);
else if (_mesh->foamHasObject<Foam::volVectorField>(_foam_variable))
else if (getFoamMesh().foamHasObject<Foam::volVectorField>(_foam_variable))
constructFoamVectorPatch(subdomain, bc_type);
else
mooseError("Variable must have type scalar or vector.");
Expand All @@ -92,9 +84,8 @@ FoamBCBase::FoamBCBase(const InputParameters & params, const FoamBCType bc_type)
void
FoamBCBase::constructFoamScalarPatch(const std::string & patch_name, const FoamBCType bc_type)
{
auto & foam_mesh = _mesh->fvMesh();
auto & var = foam_mesh.lookupObjectRef<Foam::volScalarField>(_foam_variable);
Foam::label id = foam_mesh.boundary().findIndex(patch_name);
auto & var = getFvMesh().lookupObjectRef<Foam::volScalarField>(_foam_variable);
Foam::label id = getFvMesh().boundary().findIndex(patch_name);

if (bc_type_to_string(bc_type) == var.boundaryField()[id].type())
return;
Expand All @@ -116,7 +107,7 @@ FoamBCBase::constructFoamScalarPatch(const std::string & patch_name, const FoamB
var.boundaryFieldRef().set(
id,
Foam::fvPatchField<Foam::scalar>::New(
foam_mesh.boundary()[id], var.boundaryField()[id].internalField(), bcDict));
getFvMesh().boundary()[id], var.boundaryField()[id].internalField(), bcDict));

// If temperature is replaced, internal energy or enthalpy typically needs replacing.
updateEnergyPatch(var, id, bc_type);
Expand All @@ -125,9 +116,8 @@ FoamBCBase::constructFoamScalarPatch(const std::string & patch_name, const FoamB
void
FoamBCBase::constructFoamVectorPatch(const std::string & patch_name, const FoamBCType bc_type)
{
auto & foam_mesh = _mesh->fvMesh();
auto & var = foam_mesh.lookupObjectRef<Foam::volVectorField>(_foam_variable);
Foam::label id = foam_mesh.boundary().findIndex(patch_name);
auto & var = getFvMesh().lookupObjectRef<Foam::volVectorField>(_foam_variable);
Foam::label id = getFvMesh().boundary().findIndex(patch_name);

if (bc_type_to_string(bc_type) == var.boundaryField()[id].type())
return;
Expand All @@ -145,9 +135,9 @@ FoamBCBase::constructFoamVectorPatch(const std::string & patch_name, const FoamB
bcDict.add("value", "uniform (0. 0. 0.)");
}

var.boundaryFieldRef().set(
id,
Foam::fvPatchField<Foam::vector>::New(foam_mesh.boundary()[id], var.internalField(), bcDict));
var.boundaryFieldRef().set(id,
Foam::fvPatchField<Foam::vector>::New(
getFvMesh().boundary()[id], var.internalField(), bcDict));
}

void
Expand All @@ -156,7 +146,7 @@ FoamBCBase::updateEnergyPatch(const Foam::volScalarField & var,
const FoamBCType bc_type)
{

auto thermos = var.mesh().lookupClass<Foam::basicThermo>();
auto thermos = getFvMesh().lookupClass<Foam::basicThermo>();

for (const auto & item : thermos)
{
Expand Down
Loading
Loading