From fa697c577cf64d1669168c642b4f27317119fde5 Mon Sep 17 00:00:00 2001 From: Harry Saunders Date: Fri, 8 Nov 2024 14:27:18 +0000 Subject: [PATCH 1/3] Remove unused code --- include/base/FoamInterfaceImpl.h | 15 --------------- src/base/buoyantFoamImpl.C | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/include/base/FoamInterfaceImpl.h b/include/base/FoamInterfaceImpl.h index c7404c0..5bd621d 100644 --- a/include/base/FoamInterfaceImpl.h +++ b/include/base/FoamInterfaceImpl.h @@ -82,21 +82,6 @@ struct EnvImpl return _mesh.globalData().globalPointNumbering(); } -#if 0 - auto - getPatchInterpolator(int patch_id) - { - return Foam::PrimitivePatchInterpolation(patch_id); - } - - auto - getPatchInterpolator(std::string const & patch_name) - { - auto patch_id = getPatchID(patch_name) - return Foam::PrimitivePatchInterpolation(patch_id); - } -#endif - Foam::Time & getRuntime() { return _runtime; } Foam::argList & getArglist() { return _args.args; } Foam::fvMesh & getMesh() { return _mesh; } diff --git a/src/base/buoyantFoamImpl.C b/src/base/buoyantFoamImpl.C index 89b0266..bcfd0fa 100644 --- a/src/base/buoyantFoamImpl.C +++ b/src/base/buoyantFoamImpl.C @@ -659,6 +659,7 @@ public: }; buoyantFoamApp::~buoyantFoamApp() = default; + buoyantFoamApp::buoyantFoamApp(FoamInterface * interface) : _interface(interface), _impl(std::make_unique( From 514a26a99fdd87d4b98591189217659137f1498c Mon Sep 17 00:00:00 2001 From: Harry Saunders Date: Mon, 11 Nov 2024 17:32:20 +0000 Subject: [PATCH 2/3] Automatically pass '-parallel' flag to OpenFOAM If we're running in parallel, we detect this fact and ensure that the '-parallel' flag is passed to OpenFOAM. This means we no longer need to add the flag to the 'foam_args' option in MOOSE input files when we want to execute in parallel. --- include/base/FoamInterfaceImpl.h | 2 +- include/mesh/FoamMesh.h | 2 +- src/base/FoamInterface.C | 28 ++++++++++++++++++++++++++++ src/mesh/FoamMesh.C | 3 +-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/base/FoamInterfaceImpl.h b/include/base/FoamInterfaceImpl.h index 5bd621d..529b871 100644 --- a/include/base/FoamInterfaceImpl.h +++ b/include/base/FoamInterfaceImpl.h @@ -3,11 +3,11 @@ #include "FoamInterface.h" #include "fvCFD_moose.h" +#include #include #include #include -#include /* * Where the "generic" openFoam state lives mesh, runtime, args and decomposition info diff --git a/include/mesh/FoamMesh.h b/include/mesh/FoamMesh.h index b131cd2..58cb287 100644 --- a/include/mesh/FoamMesh.h +++ b/include/mesh/FoamMesh.h @@ -41,8 +41,8 @@ class FoamMesh : public MooseMesh protected: std::vector _foam_patch; std::vector _patch_id; - Hippo::FoamInterface * _interface; std::vector _subdomain_list; + Hippo::FoamInterface * _interface; bool _serial = true; }; // Local Variables: diff --git a/src/base/FoamInterface.C b/src/base/FoamInterface.C index 71db9de..8674160 100644 --- a/src/base/FoamInterface.C +++ b/src/base/FoamInterface.C @@ -9,6 +9,27 @@ namespace Hippo { + +namespace +{ + +constexpr auto FOAM_PARALLEL_FLAG = "-parallel"; + +/** Check if OpenFOAM's parallel flag needs to be added to the CLI arguments. + * + * Return true if the given command line arguments do not contain the parallel flag and the MPI + * communicator's size is greater than 1. + */ +bool +foamParallelFlagRequired(std::vector const & foam_args, MPI_Comm const & comm) +{ + int comm_size{0}; + MPI_Comm_size(comm, &comm_size); + return (comm_size > 1 && + std::find(foam_args.begin(), foam_args.end(), FOAM_PARALLEL_FLAG) == foam_args.end()); +} +} + FoamInterface::FoamInterface(std::vector const & foam_args, MPI_Comm const & comm) { auto cargs = cArgs("hippo"); @@ -16,6 +37,13 @@ FoamInterface::FoamInterface(std::vector const & foam_args, MPI_Com { cargs.push_arg(a); } + + // Automatically pass the '-parallel' argument to OpenFOAM if we have more than one MPI rank. + if (foamParallelFlagRequired(foam_args, comm)) + { + cargs.push_arg(FOAM_PARALLEL_FLAG); + } + _impl = std::make_unique(cargs.get_argc(), cargs.get_argv().data(), comm); } diff --git a/src/mesh/FoamMesh.C b/src/mesh/FoamMesh.C index b24accc..ebe8a1c 100644 --- a/src/mesh/FoamMesh.C +++ b/src/mesh/FoamMesh.C @@ -10,13 +10,12 @@ InputParameters FoamMesh::validParams() { auto params = MooseMesh::validParams(); - // make a vector at some point params.addRequiredParam>("foam_patch", "Name of foam boundary patches to replicate"); std::vector empty_vec; params.addParam>( - "foam_args", empty_vec, "List of arguments to be passed to openFoam solver"); + "foam_args", empty_vec, "List of arguments to be passed to OpenFoam solver"); return params; } From d60c7ca4b7fd82fba91af45cfdb2179dadd3474d Mon Sep 17 00:00:00 2001 From: Harry Saunders Date: Mon, 11 Nov 2024 17:34:06 +0000 Subject: [PATCH 3/3] Remove '-parallel' flag from test case inputs This is no longer required, as this flag is automatically added. --- test/tests/buoyantFoam/buoyantFoam_par/run.i | 2 +- test/tests/cube_slice/test_1/run.i | 2 +- test/tests/cube_slice/test_10/run.i | 2 +- test/tests/cube_slice/test_2/run.i | 2 +- test/tests/cube_slice/test_3/run.i | 2 +- test/tests/cube_slice/test_5/run.i | 2 +- test/tests/cube_slice/test_6/run.i | 2 +- test/tests/cube_slice/test_7/run.i | 2 +- test/tests/cube_slice/test_8/run.i | 2 +- test/tests/cube_slice/test_9/run.i | 2 +- test/tests/multiapps/flow_over_heated_plate/fluid.i | 2 +- .../multiapps/temperature_set_on_openfoam_boundary/par/fluid.i | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/tests/buoyantFoam/buoyantFoam_par/run.i b/test/tests/buoyantFoam/buoyantFoam_par/run.i index 1738b76..8e12aaf 100644 --- a/test/tests/buoyantFoam/buoyantFoam_par/run.i +++ b/test/tests/buoyantFoam/buoyantFoam_par/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case buoyantCavity -parallel' + foam_args = '-case buoyantCavity' foam_patch = 'topAndBottom frontAndBack' dim=2 [] diff --git a/test/tests/cube_slice/test_1/run.i b/test/tests/cube_slice/test_1/run.i index 7e6956d..052faef 100644 --- a/test/tests/cube_slice/test_1/run.i +++ b/test/tests/cube_slice/test_1/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-2 Wall-3 Wall-4 Wall-5' dim=2 [] diff --git a/test/tests/cube_slice/test_10/run.i b/test/tests/cube_slice/test_10/run.i index a88711f..bf38c8c 100644 --- a/test/tests/cube_slice/test_10/run.i +++ b/test/tests/cube_slice/test_10/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-3 Wall-5' dim=2 [] diff --git a/test/tests/cube_slice/test_2/run.i b/test/tests/cube_slice/test_2/run.i index a88711f..bf38c8c 100644 --- a/test/tests/cube_slice/test_2/run.i +++ b/test/tests/cube_slice/test_2/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-3 Wall-5' dim=2 [] diff --git a/test/tests/cube_slice/test_3/run.i b/test/tests/cube_slice/test_3/run.i index a88711f..bf38c8c 100644 --- a/test/tests/cube_slice/test_3/run.i +++ b/test/tests/cube_slice/test_3/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-3 Wall-5' dim=2 [] diff --git a/test/tests/cube_slice/test_5/run.i b/test/tests/cube_slice/test_5/run.i index 302a09d..a331716 100644 --- a/test/tests/cube_slice/test_5/run.i +++ b/test/tests/cube_slice/test_5/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-2 Wall-4' dim=2 [] diff --git a/test/tests/cube_slice/test_6/run.i b/test/tests/cube_slice/test_6/run.i index cd18e94..a91f9de 100644 --- a/test/tests/cube_slice/test_6/run.i +++ b/test/tests/cube_slice/test_6/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-3' dim=2 [] diff --git a/test/tests/cube_slice/test_7/run.i b/test/tests/cube_slice/test_7/run.i index c002c25..984dff7 100644 --- a/test/tests/cube_slice/test_7/run.i +++ b/test/tests/cube_slice/test_7/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-1 Wall-2 Wall-3 Wall-4 Wall-5' dim=2 [] diff --git a/test/tests/cube_slice/test_8/run.i b/test/tests/cube_slice/test_8/run.i index 761b109..89d7d28 100644 --- a/test/tests/cube_slice/test_8/run.i +++ b/test/tests/cube_slice/test_8/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-1 Wall-3' dim=2 [] diff --git a/test/tests/cube_slice/test_9/run.i b/test/tests/cube_slice/test_9/run.i index a6e2991..e57eba1 100644 --- a/test/tests/cube_slice/test_9/run.i +++ b/test/tests/cube_slice/test_9/run.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case foaminput -parallel' + foam_args = '-case foaminput' foam_patch = ' Wall-0 Wall-2 Wall-4 Wall-5' dim=2 [] diff --git a/test/tests/multiapps/flow_over_heated_plate/fluid.i b/test/tests/multiapps/flow_over_heated_plate/fluid.i index 66feccc..4c9a6cb 100644 --- a/test/tests/multiapps/flow_over_heated_plate/fluid.i +++ b/test/tests/multiapps/flow_over_heated_plate/fluid.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case fluid-openfoam -parallel' + foam_args = '-case fluid-openfoam' foam_patch = 'interface' dim = 2 [] diff --git a/test/tests/multiapps/temperature_set_on_openfoam_boundary/par/fluid.i b/test/tests/multiapps/temperature_set_on_openfoam_boundary/par/fluid.i index 97b23d7..b5a7e50 100644 --- a/test/tests/multiapps/temperature_set_on_openfoam_boundary/par/fluid.i +++ b/test/tests/multiapps/temperature_set_on_openfoam_boundary/par/fluid.i @@ -1,6 +1,6 @@ [Mesh] type = FoamMesh - foam_args = '-case buoyantCavity -parallel' + foam_args = '-case buoyantCavity' foam_patch = 'patch2 patch4' dim=2 []