Skip to content

Commit

Permalink
Merge pull request #33 from aurora-multiphysics/hsaunders1904/18_avoi…
Browse files Browse the repository at this point in the history
…d_having_to_have_separate_input_files_for_parallel_runs

Avoid having to have separate input files for parallel runs
  • Loading branch information
hsaunders1904 authored Nov 14, 2024
2 parents d5fe177 + d60c7ca commit a3caff1
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 31 deletions.
17 changes: 1 addition & 16 deletions include/base/FoamInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "FoamInterface.h"
#include "fvCFD_moose.h"

#include <mpi.h>
#include <PrimitivePatchInterpolation.H>

#include <cassert>
#include <map>
#include <mpi.h>

/*
* Where the "generic" openFoam state lives mesh, runtime, args and decomposition info
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion include/mesh/FoamMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class FoamMesh : public MooseMesh
protected:
std::vector<std::string> _foam_patch;
std::vector<int32_t> _patch_id;
Hippo::FoamInterface * _interface;
std::vector<int> _subdomain_list;
Hippo::FoamInterface * _interface;
bool _serial = true;
};
// Local Variables:
Expand Down
28 changes: 28 additions & 0 deletions src/base/FoamInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,41 @@

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<std::string> 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<std::string> const & foam_args, MPI_Comm const & comm)
{
auto cargs = cArgs("hippo");
for (auto const & a : foam_args)
{
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<Hippo::EnvImpl>(cargs.get_argc(), cargs.get_argv().data(), comm);
}

Expand Down
1 change: 1 addition & 0 deletions src/base/buoyantFoamImpl.C
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public:
};

buoyantFoamApp::~buoyantFoamApp() = default;

buoyantFoamApp::buoyantFoamApp(FoamInterface * interface)
: _interface(interface),
_impl(std::make_unique<buoyantFoamImpl>(
Expand Down
3 changes: 1 addition & 2 deletions src/mesh/FoamMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ InputParameters
FoamMesh::validParams()
{
auto params = MooseMesh::validParams();
// make a vector at some point
params.addRequiredParam<std::vector<std::string>>("foam_patch",
"Name of foam boundary patches to replicate");

std::vector<std::string> empty_vec;
params.addParam<std::vector<std::string>>(
"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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/tests/buoyantFoam/buoyantFoam_par/run.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Mesh]
type = FoamMesh
foam_args = '-case buoyantCavity -parallel'
foam_args = '-case buoyantCavity'
foam_patch = 'topAndBottom frontAndBack'
dim=2
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_1/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_10/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_2/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_3/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_5/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_6/run.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Mesh]
type = FoamMesh
foam_args = '-case foaminput -parallel'
foam_args = '-case foaminput'
foam_patch = ' Wall-3'
dim=2
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_7/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_8/run.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Mesh]
type = FoamMesh
foam_args = '-case foaminput -parallel'
foam_args = '-case foaminput'
foam_patch = ' Wall-1 Wall-3'
dim=2
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/cube_slice/test_9/run.i
Original file line number Diff line number Diff line change
@@ -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
[]
Expand Down
2 changes: 1 addition & 1 deletion test/tests/multiapps/flow_over_heated_plate/fluid.i
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Mesh]
type = FoamMesh
foam_args = '-case fluid-openfoam -parallel'
foam_args = '-case fluid-openfoam'
foam_patch = 'interface'
dim = 2
[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Mesh]
type = FoamMesh
foam_args = '-case buoyantCavity -parallel'
foam_args = '-case buoyantCavity'
foam_patch = 'patch2 patch4'
dim=2
[]
Expand Down

0 comments on commit a3caff1

Please sign in to comment.