Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
ef289be
Implement initial test solver for foam variable shadowing
mattfalcone1997 Sep 12, 2025
f6542c9
Implement initial test case for foam variable shadowing
mattfalcone1997 Sep 12, 2025
ae6c9cc
Add FoamVariableField class and associated test files for variable sh…
mattfalcone1997 Sep 12, 2025
61f4801
Add basic transfer of scalar variable
mattfalcone1997 Sep 12, 2025
d05e34b
Implement basic tests for variable transfer
mattfalcone1997 Sep 12, 2025
d135ee7
Introduce base calss for FoamVariables
mattfalcone1997 Sep 15, 2025
28b3af5
Add class for shadowing functionObjects
mattfalcone1997 Sep 15, 2025
a3fa011
Add tests for functionObject moose variable
mattfalcone1997 Sep 15, 2025
a721416
Implement more rigorous test for wallHeatFlux
mattfalcone1997 Sep 16, 2025
6bee5de
Improve code comments for FoamVariable implementation
mattfalcone1997 Sep 16, 2025
32ad392
Update Makefile to build OpenFOAM test solvers
mattfalcone1997 Sep 16, 2025
a11ec3c
Update transferTestSolver LIB path
mattfalcone1997 Sep 16, 2025
b34dd05
Remove FoamVariableBase in favour of direct inheritance from FoamVari…
mattfalcone1997 Sep 16, 2025
ef03a7f
Create function to return name of shadowed FoamVariable
mattfalcone1997 Sep 19, 2025
111e758
Add table output for OpenFOAM variables
mattfalcone1997 Sep 19, 2025
4967236
Initial untested but compiling implementation of new action syntax fo…
mattfalcone1997 Sep 25, 2025
bb80716
Add action syntax test
mattfalcone1997 Sep 25, 2025
db8898c
Add more detailed commenbts
mattfalcone1997 Sep 25, 2025
b30e5f7
Update existing foam_variable test to use FoamVariables block
mattfalcone1997 Sep 25, 2025
4588818
Add initial passing implementation of the FoamBC action and input fil…
mattfalcone1997 Sep 16, 2025
b3cde0d
Add initial test case for the input file syntax
mattfalcone1997 Sep 16, 2025
6f683e2
Implement initial MWE FoamBCBase class
mattfalcone1997 Sep 17, 2025
6eaffb9
Implement initial MWE action syntax for FoamBCs
mattfalcone1997 Sep 17, 2025
02d1d30
Implement MWE for FoamFixedValueBC
mattfalcone1997 Sep 17, 2025
05d58e7
Temporaily remove test for FoamBC Action pending development of a tes…
mattfalcone1997 Sep 17, 2025
247dd99
Fix patch counts and offsets determination
mattfalcone1997 Sep 17, 2025
05b23ff
Implement initial test solver for the Foam BCs
mattfalcone1997 Sep 17, 2025
0c813ea
Implement initial test for FixedValue BCs
mattfalcone1997 Sep 17, 2025
e6bee56
Update hippo python reader with docstrings and OpenFOAM function to g…
mattfalcone1997 Sep 18, 2025
929bade
Implement boundary restrictions on the FoamBCs
mattfalcone1997 Sep 18, 2025
71d4e0c
Clean up FoamBC implementation and improve comments
mattfalcone1997 Sep 18, 2025
6a0c02e
Actually use the foam_variable in the parameters. Silly me.
mattfalcone1997 Sep 18, 2025
59a547d
Rename fixed value test
mattfalcone1997 Sep 18, 2025
084e703
Implement initial fixed gradient BC
mattfalcone1997 Sep 18, 2025
acfa574
Add laplacian solver to bcTestSolver
mattfalcone1997 Sep 18, 2025
93afa42
Correct laplacian solver in bcTestSolver
mattfalcone1997 Sep 18, 2025
9374e92
Add simple test for fixed-gradient boundary condition
mattfalcone1997 Sep 18, 2025
1a27a92
Fix assert messages for debug builds
mattfalcone1997 Sep 18, 2025
ffc721b
Implement test FoamBC for testing action and input file syntax
mattfalcone1997 Sep 18, 2025
bdc25dd
Add verification function for FoamBCs
mattfalcone1997 Sep 18, 2025
6bf83e6
Add warning for cases where a BC is imposed for a variable but not fo…
mattfalcone1997 Sep 18, 2025
99943ed
Add action tests for FoamBCs
mattfalcone1997 Sep 18, 2025
5205e6c
Add exception check for fixed gradient bc
mattfalcone1997 Sep 19, 2025
b6867a1
Add table of information for FoamBCs
mattfalcone1997 Sep 19, 2025
30b3c86
Ensure comments up to date for FoamBC
mattfalcone1997 Sep 19, 2025
5c24d3b
Fix initial rebase issue for variables and bcs
mattfalcone1997 Sep 25, 2025
4decaef
Deprecate old syntax to faciliate conversion to new general syntax
mattfalcone1997 Sep 25, 2025
6b077b8
Get all existing tests passing on the new input file syntax
mattfalcone1997 Sep 26, 2025
3aff1f0
Fully implement deprecation of old input file BC/shadowing syntax.
mattfalcone1997 Sep 26, 2025
99758e4
Implement tests for deprecation of old input file syntax
mattfalcone1997 Sep 26, 2025
7325fb0
Add all boundaries default in constructor for BCs
mattfalcone1997 Sep 26, 2025
de5706b
Test and fix deprecated variable/BC syntax
mattfalcone1997 Sep 29, 2025
60b134c
Add further comments on deprecation foam_temp etc.
mattfalcone1997 Sep 29, 2025
bcb5bf1
Remove unnecessary code from switch to new bc/variable system
mattfalcone1997 Sep 29, 2025
cbde2e9
Simplify transfer variable function
mattfalcone1997 Sep 29, 2025
e07a895
Implement changes based on code review
mattfalcone1997 Sep 29, 2025
0a12149
Initial attempt at fixing exodiff failure
mattfalcone1997 Sep 30, 2025
3d5a38d
Add temporary ICs block before FoamVariables get full variable parame…
mattfalcone1997 Sep 30, 2025
70d9c2c
Repeat previous change on parallel test
mattfalcone1997 Sep 30, 2025
d9066d0
Use action to create AuxVariable for FoamVariables
mattfalcone1997 Oct 1, 2025
d327c14
Remove need for AuxVariable with FoamBC
mattfalcone1997 Oct 1, 2025
0f43e65
Reintroduce optional AuxVariable in FoamBC
mattfalcone1997 Oct 1, 2025
3ef9817
Reintroduce check on variable existance and monomial constant
mattfalcone1997 Oct 1, 2025
e226cd0
Update tests to reflect BC changes
mattfalcone1997 Oct 1, 2025
6b85024
Move input error tests to action
mattfalcone1997 Oct 1, 2025
14776ff
Minor improvements after review
mattfalcone1997 Oct 1, 2025
776972f
Update BC implementation based on code review
mattfalcone1997 Oct 23, 2025
a3f288d
Remove old transfer completely - no deprecation
mattfalcone1997 Nov 1, 2025
faaf1a0
Create utils header for internal functions and classes and other chan…
mattfalcone1997 Nov 1, 2025
a3a3753
Update docs for new transfer system
mattfalcone1997 Nov 6, 2025
8c87cc4
Add fluid mesh to shell and tube heat exchanger problem
mattfalcone1997 Nov 6, 2025
dcbcb57
Fix error in docs
mattfalcone1997 Nov 6, 2025
64813d6
Update doc/content/step_by_step.md
mattfalcone1997 Nov 10, 2025
88534ae
Add semantic line breaks and clearly state the origin of shell and tu…
mattfalcone1997 Nov 10, 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
# as they are written.
include test/OpenFOAM/foam_modules.mk
94 changes: 44 additions & 50 deletions doc/content/step_by_step.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ For more info on the OpenFOAM case structure, see the

## Write a MOOSE Input File for the OpenFOAM Case

### Problem

First, we define the `Problem` block, which tells Hippo we are running an OpenFOAM case
and provides the functionality to couple OpenFOAM into the MOOSE framework.

```toml
# fluid.i

[Problem]
type = FoamProblem
[]
```

### Mesh

The first block to define is the mesh block.
Expand Down Expand Up @@ -95,72 +108,54 @@ $ hippo-opt -i fluid.i --mesh-only
$ paraview fluid_in.e
```

### Auxiliary Variables
### Transferring data from OpenFOAM to MOOSE

To transfer quantities between the OpenFOAM and MOOSE solves,
you must use MOOSE's
[AuxVariable system](https://mooseframework.inl.gov/syntax/AuxVariables/).
For this problem we need two variables,
one for the solid heat flux and one for the fluid wall temperature.
To access OpenFOAM variables from MOOSE, Hippo provides the `FoamVariable` system,
which allows you to shadow OpenFOAM volume fields and function objects with MOOSE variables,
which are automatically updated after each OpenFOAM solve. For this problem,
the fluid temperature is required by MOOSE. In OpenFOAM, the temperature is stored
in the `volScalarField` named `T`:

At present, all AuxVariables used for these transfers must
be constant and monomial.

```toml
# fluid.i

[AuxVariables]
[FoamVariables]
[fluid_wall_temp]
family = MONOMIAL
order = CONSTANT
initial_condition = 300
[]
[solid_heat_flux]
family = MONOMIAL
order = CONSTANT
initial_condition = 0
type = FoamVariableField
foam_variable = T
[]
[]
```
Internally, Hippo creates `AuxVariable`s which can use MOOSE's transfer system
and so can be transferred between MOOSE apps.

> +Note:+ *To save on memory, you could actually define a single AuxVariable
> and transfer the heat flux one way and temperature the other in the same
> variable. However, for clarity, we use separate variables here.*

### Problem

Next we define the 'Problem' block.
Hippo provides the `FoamProblem` class to run the OpenFOAM case
provided in the `[Mesh]` block.
### Imposing boundary conditions on OpenFOAM from MOOSE

`FoamProblem` has a set of parameters that defines which quantities are
copied to and from OpenFOAM:

- `foam_heat_flux` -
the name of the AuxVariable to copy OpenFOAM's heat flux into.
- `foam_temp` -
the name of the AuxVariable to copy OpenFOAM's wall temperature into.
- `temp` -
the name of an AuxVariable whose values will be used to set
a Dirichlet boundary condition on the OpenFOAM solve.
- `heat_flux`
the name of an AuxVariable whose values will be used to set
a Neumann boundary condition on the OpenFOAM solve.

In our example, we'll need to set `heat_flux` and `foam_temp`.
Hippo also implements the `FoamBC` system that allows you to impose boundary conditions
on OpenFOAM from the Hippo input file. In this case, we wish to impose a heat flux BC
on the temperature field. This requires the `FoamFixedGradientBC`, which mirrors OpenFOAM's
`fixedGradient` BC type. As in this case, we provide a heat flux, we must also provide the
thermal conductivity, which is specified as the `diffusivity_coefficient`.
`kappa` is the name of the thermal conductivity variable in OpenFOAM.

```toml
# fluid.i

[Problem]
type = FoamProblem
# Take the heat flux from MOOSE and set it on the OpenFOAM mesh.
heat_flux = solid_heat_flux
# Take the boundary temperature from OpenFOAM and set it on the MOOSE mesh.
foam_temp = fluid_wall_temp
[FoamBCs]
[solid_heat_flux]
type = FoamFixedGradientBC
foam_variable = T
diffusivity_coefficient = kappa
[]
[]
```

Similar to `FoamVariable`, this creates an `AuxVariable` with name `solid_heat_flux`
under the hood.
MOOSE's transfers system can be used to set the values in the `AuxVariable`,
that are then imposed on the OpenFOAM solver's boundary.

### Executioner

Set the time step settings in the `Executioner` block.
Expand Down Expand Up @@ -372,6 +367,7 @@ To couple the solves we're going to:

[Transfers]
# Copy the wall temperature from the fluid into an AuxVariable.
# This was stored in the FoamVariable fluid_wall_temp
[wall_temperature_from_fluid]
type = MultiAppGeometricInterpolationTransfer
source_variable = fluid_wall_temp
Expand All @@ -381,9 +377,7 @@ To couple the solves we're going to:
[]

# Copy the heat flux from the 'wall_heat_flux' aux variable into the
# multiapp.
# Remember we marked the 'solid_heat_flux' variable in 'fluid.i' to be
# used as a heat flux boundary condition on the OpenFOAM solve.
# 'solid_heat_flux' FoamBC in the multiapp.
[heat_flux_to_fluid]
type = MultiAppGeometricInterpolationTransfer
source_variable = wall_heat_flux
Expand Down
18 changes: 18 additions & 0 deletions include/actions/AddFoamBCAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "InputParameters.h"
#include "MooseObjectAction.h"

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

AddFoamBCAction(const InputParameters & parameters);

virtual void act() override;

protected:
// Create AuxVariable associated with new-style BCs
void createAuxVariable();
};
18 changes: 18 additions & 0 deletions include/actions/AddFoamVariableAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "InputParameters.h"
#include "MooseObjectAction.h"

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

AddFoamVariableAction(const InputParameters & parameters);

virtual void act() override;

protected:
// Create AuxVariable associated with new-style variable shadowing
void createAuxVariable();
};
10 changes: 0 additions & 10 deletions include/base/FoamSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,8 @@ class FoamSolver

// Run a timestep of the OpenFOAM solver.
void run();

// Append temperature values from the OpenFOAM patch (boundary) to the end of
// the given vector.
std::size_t appendPatchTemperatures(int patch_id, std::vector<double> & foam_t);
// Return the number of faces in the given patch (boundary).
std::size_t patchSize(int patch_id);
// Set the temperature values of the OpenFOAM patch (boundary).
void setPatchTemperatures(int patch_id, const std::vector<double> & moose_t);
// Set the negative heat flux values on the OpenFOAM patch (boundary).
void setPatchNegativeHeatFlux(int patch_id, std::vector<double> & negative_hf);
// Get or calculate the wall heat flux for the given patch.
std::size_t wallHeatFlux(int patch_id, std::vector<double> & fill_vector);
// Set the solver's time step size.
void setTimeDelta(double dt) { runTime().setDeltaTNoAdjust(dt); }
// Set the solver to the given time.
Expand Down
50 changes: 50 additions & 0 deletions include/bcs/FoamBCBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "FoamMesh.h"

#include <Coupleable.h>
#include <InputParameters.h>
#include <MooseObject.h>
#include <MooseTypes.h>
#include <MooseVariableFieldBase.h>

class FoamBCBase : public MooseObject, public Coupleable
{
public:
static InputParameters validParams();

explicit FoamBCBase(const InputParameters & params);

virtual void imposeBoundaryCondition() = 0;

// returns foam variable BC applies to
std::string foamVariable() const { return _foam_variable; };

// returns the moose AuxVariable imposed on OpenFOAM
AuxVariableName mooseVariable() const { return _moose_var->name(); }

// returns the name of the foam boundaries the BC applies to
std::vector<SubdomainName> boundary() const { return _boundary; };

virtual void initialSetup();

protected:
// OpenFOAM variable which this BC is to be imposed on
std::string _foam_variable;

// Get the value of the MOOSE variable at an element
Real variableValueAtElement(const libMesh::Elem * elem);

// Get the data vector of the MOOSE field on a subdomain
std::vector<Real> getMooseVariableArray(int subdomain_id);

// 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;
};
21 changes: 21 additions & 0 deletions include/bcs/FoamFixedGradientBC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "FoamBCBase.h"
#include "InputParameters.h"

class FoamFixedGradientBC : public FoamBCBase
{
public:
// Validate input file parameters
static InputParameters validParams();

// Constructor
explicit FoamFixedGradientBC(const InputParameters & parameters);

// Impose boundary conditions (to be called from FoamProblem class)
virtual void imposeBoundaryCondition() override;

protected:
// name of diffusivity coefficient used to divide flux
std::string _diffusivity_coefficient;
};
17 changes: 17 additions & 0 deletions include/bcs/FoamFixedValueBC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "FoamBCBase.h"
#include "InputParameters.h"

class FoamFixedValueBC : public FoamBCBase
{
public:
// Validate input file parameters
static InputParameters validParams();

// Constructor
explicit FoamFixedValueBC(const InputParameters & parameters);

// Impose boundary conditions (to be called from FoamProblem class)
virtual void imposeBoundaryCondition() override;
};
33 changes: 29 additions & 4 deletions include/mesh/FoamMesh.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#pragma once

#include "FoamRuntime.h"
#include "libmesh/elem.h"
#include "Foam2MooseMeshGen.h"

#include <MooseTypes.h>
#include <MooseMesh.h>
#include <libmesh/elem.h>
#include <fixedGradientFvPatchField.H>
#include <fvPatchField.H>
#include <typeInfo.H>
#include <volFieldsFwd.H>
#include <argList.H>
#include <fvMesh.H>
#include <MooseMesh.h>

#include <memory>

Expand All @@ -31,28 +36,48 @@ class FoamMesh : public MooseMesh
~FoamMesh() = default;
virtual std::unique_ptr<MooseMesh> safeClone() const override;
virtual void buildMesh() override;
std::vector<int> & getSubdomainList();
std::vector<SubdomainID> & getSubdomainList();
bool isSerial() const { return _serial; }
libMesh::Elem * getElemPtr(int local) const;
Foam::fvMesh & fvMesh() { return _foam_mesh; }
// Create a MOOSE element from a Foam face, removing collinear points on edges.
std::unique_ptr<Elem> createElement(Hippo::Foam2MooseMeshAdapter * mesh_adapter,
const Hippo::FoamFace & face);

int64_t getPatchCount(int subdomain_id) const { return _patch_counts.at(subdomain_id); };
int64_t getPatchOffset(int subdomain_id) const { return _patch_offsets.at(subdomain_id); };
std::vector<int32_t> n_faces{0};
// The index offset into the MOOSE element array, for the current rank.
// This can be used with `getElemPtr` like so:
// getElemPtr(rank_offset + i)
// to get the i-th element owned by the current rank from the mesh.
size_t rank_element_offset{0};

// Check if Foam mesh object has object of type T called name
template <typename T>
bool foamHasObject(Foam::word const & name)
{
return _foam_mesh.foundObject<T>(name);
}

// Returns the gradient BC array for field and subdomain
template <typename GeoField, typename Type>
Foam::Field<Type> & getGradientBCField(SubdomainID subdomain, Foam::word const & field)
{
auto & var = const_cast<Foam::fvPatchField<Type> &>(
_foam_mesh.boundary()[subdomain].lookupPatchField<GeoField, Type>(field));
return Foam::refCast<Foam::fixedGradientFvPatchField<Type>>(var).gradient();
}

protected:
std::vector<std::string> _foam_patch;
Hippo::FoamRuntime _foam_runtime;
Foam::fvMesh _foam_mesh;
std::vector<int32_t> _patch_id;
std::vector<int> _subdomain_list;
std::vector<SubdomainID> _subdomain_list;
bool _serial = true;
std::map<int, int64_t> _patch_counts;
std::map<int, int64_t> _patch_offsets;
};
// Local Variables:
// mode: c++
Expand Down
Loading