Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid having to have separate input files for parallel runs #33

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
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