Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a80280c
Implement initial test solver for foam variable shadowing
mattfalcone1997 Sep 12, 2025
030f47c
Implement initial test case for foam variable shadowing
mattfalcone1997 Sep 12, 2025
6a28597
Add FoamVariableField class and associated test files for variable sh…
mattfalcone1997 Sep 12, 2025
ff54912
Add basic transfer of scalar variable
mattfalcone1997 Sep 12, 2025
1089e33
Implement basic tests for variable transfer
mattfalcone1997 Sep 12, 2025
a5217b0
Introduce base calss for FoamVariables
mattfalcone1997 Sep 15, 2025
c802a90
Add class for shadowing functionObjects
mattfalcone1997 Sep 15, 2025
5ac2e55
Add tests for functionObject moose variable
mattfalcone1997 Sep 15, 2025
b5ef32f
Implement more rigorous test for wallHeatFlux
mattfalcone1997 Sep 16, 2025
1dc89ab
Improve code comments for FoamVariable implementation
mattfalcone1997 Sep 16, 2025
d5721b6
Update Makefile to build OpenFOAM test solvers
mattfalcone1997 Sep 16, 2025
2e3229b
Update transferTestSolver LIB path
mattfalcone1997 Sep 16, 2025
55d570f
Remove FoamVariableBase in favour of direct inheritance from FoamVari…
mattfalcone1997 Sep 16, 2025
db3cfe1
Create function to return name of shadowed FoamVariable
mattfalcone1997 Sep 19, 2025
62b6e51
Add table output for OpenFOAM variables
mattfalcone1997 Sep 19, 2025
de63e46
Initial untested but compiling implementation of new action syntax fo…
mattfalcone1997 Sep 25, 2025
72b37b8
Add action syntax test
mattfalcone1997 Sep 25, 2025
31c7a9a
Add more detailed commenbts
mattfalcone1997 Sep 25, 2025
d323940
Update existing foam_variable test to use FoamVariables block
mattfalcone1997 Sep 25, 2025
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,19 @@ moose/include/base/Precompiled.h.gch
# clang
.clangd

# direnv
.envrc

# OpenFOAM mesh object files
test/**/*.obj

# downloaded mesh tarballs
test/tests/**/*.tar.gz

# OpenFOAM build files
test/OpenFOAM/**/lnInclude
test/OpenFOAM/**/linux*

framework/contrib/exodiff/exodiff

# Mac garbage
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ repos:
hooks:
- id: remove-crlf
- id: forbid-tabs
exclude: '.*\.mk$'
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ include $(FRAMEWORK_DIR)/app.mk

###############################################################################
# Additional special case targets should be added here

# Add foam modules
# TODO: Reorganise build: consider single mk for all OpenFOAM modules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we open an issue for this, rather than leaving it as a TODO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add an issue but would rather leave to todo's in, so I get a reminder when I am doing it

# as they are written.
include test/OpenFOAM/foam_modules.mk
12 changes: 12 additions & 0 deletions include/actions/AddFoamVariableAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "InputParameters.h"
#include "MooseObjectAction.h"

class AddFoamVariableAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddFoamVariableAction(const InputParameters & parameters);

virtual void act() override;
};
8 changes: 7 additions & 1 deletion include/problems/FoamProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include "FoamMesh.h"
#include "FoamSolver.h"
#include "FoamVariableField.h"

#include <ExternalProblem.h>
#include <MooseTypes.h>
#include <MooseVariableFieldBase.h>
#include <SystemBase.h>
#include <libmesh/elem.h>
#include <string>

class FoamProblem : public ExternalProblem
{
Expand All @@ -18,7 +20,7 @@ class FoamProblem : public ExternalProblem
virtual void syncSolutions(Direction /* dir */) override;
virtual bool converged(const unsigned int /* nl_sys_num */) override { return true; }
virtual void addExternalVariables() override {};

virtual void initialSetup() override;
using ExternalProblem::mesh;
virtual FoamMesh const & mesh() const override { return *_foam_mesh; }
virtual FoamMesh & mesh() override { return *_foam_mesh; }
Expand All @@ -42,6 +44,10 @@ class FoamProblem : public ExternalProblem
Hippo::FoamSolver & solver() { return _solver; }

protected:
// check FoamVariables and print summarising table
void verifyFoamVariables();

FoamMesh * _foam_mesh = nullptr;
Hippo::FoamSolver _solver;
std::vector<FoamVariableField *> _foam_variables;
};
27 changes: 27 additions & 0 deletions include/variables/FoamFunctionObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "FoamVariableField.h"
#include "functionObject.H"

#include <volFields.H>

// Class for mirroring functionObjects
class FoamFunctionObject : public FoamVariableField
{
public:
explicit FoamFunctionObject(const InputParameters & params);

// function that executes functionObject and transfers variable from
// OpenFOAM variable to MOOSE
virtual void transferVariable();

// Destroys functionObject pointer
~FoamFunctionObject() { delete _shadow_fo; };

private:
// function to construct the functionObject
Foam::functionObject * _getFunctionObject(Foam::dictionary fo_dict);

// The function object pointer
Foam::functionObject * _shadow_fo;
};
32 changes: 32 additions & 0 deletions include/variables/FoamVariableField.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "Moose.h"
#include "MooseTypes.h"
#include "FoamMesh.h"

class FoamVariableField : public MooseObject
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would FoamFieldVariable be a better name here? It's a MOOSE variable representing an OpenFOAM field, so it feels like "foam" and "field" belong next to one-another.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that when I add handling of vectors at some point I will change it to FoamScalarField/FoamVectorField to mirror volScalarField etc. Also there is a MOOSE class called MooseVariableField so the analogy may be useful.

{
public:
static InputParameters validParams();

explicit FoamVariableField(const InputParameters & params);

// transfer variable from OpenFOAM field to MOOSE variable
virtual void transferVariable();

// returns the name of the foam variable this object shadows
std::string foamVariable() const { return _foam_variable; };

protected:
// variable name or functionObject to be shadowed
std::string _foam_variable;

// moose variable that shadows the OpenFOAM variable
MooseVariableFieldBase & _moose_var;

// Create Auxilliary variable
MooseVariableFieldBase & createMooseVariable(std::string name, const InputParameters & params);

// Pointer to the FoamMesh object
FoamMesh * _mesh;
};
34 changes: 34 additions & 0 deletions src/actions/AddFoamVariableAction.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "AddFoamVariableAction.h"
#include "FoamProblem.h"
#include "FoamVariableField.h"
#include "InputParameters.h"
#include "MooseObjectAction.h"
#include "Registry.h"

registerMooseAction("hippoApp", AddFoamVariableAction, "add_foam_variable");

InputParameters
AddFoamVariableAction::validParams()
{
auto params = MooseObjectAction::validParams();
params.addClassDescription("Adds a FoamVariable that shadows an OpenFOAM scalar field.");
return params;
}

AddFoamVariableAction::AddFoamVariableAction(const InputParameters & parameters)
: MooseObjectAction(parameters)
{
}

void
AddFoamVariableAction::act()
{
if (_current_task == "add_foam_variable")
{
auto * foam_problem = dynamic_cast<FoamProblem *>(_problem.get());
if (!foam_problem)
mooseError("FoamVariables block must be used with FoamProblem");

foam_problem->addObject<FoamVariableField>(_type, _name, _moose_object_pars, false);
}
}
5 changes: 5 additions & 0 deletions src/base/hippoApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ hippoApp::registerAll(Factory & f, ActionFactory & af, Syntax & syntax)
Registry::registerActionsTo(af, {"hippoApp"});

/* register custom execute flags, action syntax, etc. here */

// Add input file syntax for the [FoamVariables] block
registerSyntaxTask("AddFoamVariableAction", "FoamVariables/*", "add_foam_variable");
registerMooseObjectTask("add_foam_variable", FoamVariable, false);
addTaskDependency("add_external_aux_variables", "add_foam_variable");
}

void
Expand Down
43 changes: 42 additions & 1 deletion src/problems/FoamProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <MooseError.h>
#include <MooseTypes.h>
#include <MooseVariableFieldBase.h>
#include "FoamVariableField.h"
#include "InputParameters.h"
#include "VariadicTable.h"
#include <finiteVolume/solver/solver.H>
#include <fvMesh.H>
#include <libmesh/enum_order.h>
Expand Down Expand Up @@ -60,7 +63,11 @@ FoamProblem::validParams()
FoamProblem::FoamProblem(InputParameters const & params)
: ExternalProblem(params),
_foam_mesh(dynamic_cast<FoamMesh *>(&this->ExternalProblem::mesh())),
_solver(Foam::solver::New("fluid", _foam_mesh->fvMesh()).ptr())
_solver(Foam::solver::New(_foam_mesh->fvMesh().time().controlDict().lookupOrDefault<Foam::word>(
"solver", "fluid"),
_foam_mesh->fvMesh())
.ptr()),
_foam_variables()
{
assert(_foam_mesh);

Expand Down Expand Up @@ -117,6 +124,18 @@ FoamProblem::externalSolve()
}
}

void
FoamProblem::initialSetup()
{
ExternalProblem::initialSetup();

// Get FoamVariables create by the action AddFoamVariableAction
TheWarehouse::Query query = theWarehouse().query().condition<AttribSystem>("FoamVariable");
query.queryInto(_foam_variables);

verifyFoamVariables();
}

void
FoamProblem::syncSolutions(Direction dir)
{
Expand All @@ -143,6 +162,12 @@ FoamProblem::syncSolutions(Direction dir)
{
syncFromOpenFoam<SyncVariables::WallHeatFlux>();
}

// Loop of shadowed variables and perform transfer
for (auto & var : _foam_variables)
{
var->transferVariable();
}
}
else if (dir == ExternalProblem::Direction::TO_EXTERNAL_APP)
{
Expand Down Expand Up @@ -331,3 +356,19 @@ FoamProblem::getConstantMonomialVariableFromParameters(const std::string & param
}
return var;
}

void
FoamProblem::verifyFoamVariables()
{
// Create table summarising FoamVariables
VariadicTable<std::string, std::string, std::string> vt({
"FoamVariable name",
"Type",
"Foam variable",
});
for (auto & var : _foam_variables)
{
vt.addRow(var->name(), var->type(), var->foamVariable());
}
vt.print(_console);
}
58 changes: 58 additions & 0 deletions src/variables/FoamFunctionObject.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "FoamVariableField.h"
#include "FoamFunctionObject.h"
#include "InputParameters.h"
#include "Registry.h"
#include "SystemBase.h"
#include "dictionary.H"
#include "functionObject.H"
// #include "wallHeatFlux.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this in the tests PR.

#include <functionObjects/field/wallHeatFlux/wallHeatFlux.H>

registerMooseObject("hippoApp", FoamFunctionObject);

FoamFunctionObject::FoamFunctionObject(const InputParameters & params) : FoamVariableField(params)
{
auto & mesh = _mesh->fvMesh();

// construct input Foam dictionary for the functionObject
auto fo_dict = mesh.time().controlDict().lookupOrDefault(_foam_variable, Foam::dictionary());

// create patch names where functionObject applies
// TODO: when volumetric mirror is implemented some of this may need to be
// put in the _getFunctionObject function.
std::vector<int> patch_ids{_mesh->getSubdomainList()};
Foam::wordList patch_names;
for (auto id : patch_ids)
patch_names.append(mesh.boundaryMesh()[id].name());

fo_dict.set("patches", patch_names);
fo_dict.set("writeToFile", false);

// construct functionObject and execute
_shadow_fo = _getFunctionObject(fo_dict);
_shadow_fo->execute();
}

Foam::functionObject *
FoamFunctionObject::_getFunctionObject(Foam::dictionary fo_dict)
{
// Create polymorphic pointer to each type of valid functionObject
if (_foam_variable == "wallHeatFlux")
{
Foam::functionObjects::wallHeatFlux * whf_func =
new Foam::functionObjects::wallHeatFlux("wallHeatFlux", _mesh->fvMesh().time(), fo_dict);
return static_cast<Foam::functionObject *>(whf_func);
}
else
{
mooseError("Only wallHeatFlux functionObject is currently supported");
}
}

void
FoamFunctionObject::transferVariable()
{
// execute functionObject before transfer
_shadow_fo->execute();
FoamVariableField::transferVariable();
}
Loading