ENH: relocate externalFileCoupler from finiteVolume to meshTools

This commit is contained in:
Mark Olesen
2020-06-09 12:15:11 +02:00
parent e2ad9f08a8
commit 076bcc25c9
9 changed files with 64 additions and 12 deletions

View File

@ -0,0 +1,10 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
#------------------------------------------------------------------------------
# Remove old junk
rm -f comms/OpenFOAM.lock
rmdir comms
#------------------------------------------------------------------------------

View File

@ -0,0 +1,20 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
#------------------------------------------------------------------------------
# Cleanup old junk that may prevent things from starting
rm -f comms/OpenFOAM.lock
# If this exits prematurely, trigger the external solver to stop
trap '[ -e comms/OpenFOAM.lock ] && echo "status=done" > comms/OpenFOAM.lock' EXIT TERM INT
Test-externalFileCoupler -slave -max 50 &
Test-externalFileCoupler -max 25
# Give some time for the slave to find updated file
sleep 2
[ -d comms ] && echo "status=done" > comms/OpenFOAM.lock
#------------------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \ EXE_LIBS = \
-lfiniteVolume -lmeshTools

View File

@ -28,6 +28,7 @@ Application
Description Description
Test of master/slave communication etc. Test of master/slave communication etc.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "argList.H" #include "argList.H"
@ -41,55 +42,78 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::noBanner();
argList::noParallel(); argList::noParallel();
argList::addOption("sleep", "N", "sleep to add between calls");
argList::addOption("max", "N", "max number of calls (default: 1000)"); argList::addOption("max", "N", "max number of calls (default: 1000)");
argList::addBoolOption("slave", "run as slave"); argList::addBoolOption("slave", "run as slave");
#include "setRootCase.H" #include "setRootCase.H"
const label maxCount = args.getOrDefault<label>("max", 1000); const label maxCount = args.getOrDefault<label>("max", 1000);
const label sleeping = args.getOrDefault<label>("sleep", 0);
externalFileCoupler coupler; externalFileCoupler coupler;
if (args.found("slave")) if (args.found("slave"))
{ {
const word role = "slave"; const word role = "slave";
Info<< "Running as " << role << " max=" << maxCount << endl; const word other = "master";
Info<< "Running as " << role << " max=" << maxCount
<< " (sleep " << sleeping << ')' << endl;
for (label count = 0; count < maxCount; ++count) for (label count = 0; count < maxCount; ++count)
{ {
// Wait for master, but stop if status=done was seen // Wait for master, but stop if status=done was seen
Info<< role << '[' << count << "] wait for " << other << endl;
Info<< role << ": waiting for master" << endl;
if (!coupler.waitForMaster()) if (!coupler.waitForMaster())
{ {
Info<< role << ": stopping. status=done was detected" << endl; Info<< role << ": stopping. status=done was detected" << endl;
break; break;
} }
Info<< role << ": switch to master" << endl; if (sleeping)
{
sleep(sleeping);
}
// Info<< role << ": switch to " << other << endl;
coupler.useMaster(); coupler.useMaster();
} }
Info<< role << ": exiting" << endl;
} }
else else
{ {
const word role = "master"; const word role = "master";
Info<< "Running as " << role << " max=" << maxCount << endl; const word other = "slave";
Info<< "Running as " << role << " max=" << maxCount
<< " (sleep " << sleeping << ')' << endl;
for (label count = 0; count < maxCount; ++count) for (label count = 0; count < maxCount; ++count)
{ {
// Wait for slave, but stop if status=done was seen // Wait for slave, but stop if status=done was seen
Info<< role << ": waiting for slave" << endl; Info<< role << '[' << count << "] wait for " << other << endl;
if (!coupler.waitForSlave()) if (!coupler.waitForSlave())
{ {
Info<< role << ": stopping. status=done was detected" << endl; Info<< role << ": stopping. status=done was detected" << endl;
break; break;
} }
Info<< role << ": switch to slave" << endl; if (sleeping)
{
sleep(sleeping);
}
// Info<< role << ": switch to " << other << endl;
coupler.useSlave(); coupler.useSlave();
} }
// shudown - slave should notice and terminate
Info<< role << ": exiting" << endl;
} }
return 0; return 0;

View File

@ -471,9 +471,6 @@ $(general)/pressureControl/pressureControl.C
$(general)/levelSet/levelSet.C $(general)/levelSet/levelSet.C
$(general)/meshObjects/gravity/gravityMeshObject.C $(general)/meshObjects/gravity/gravityMeshObject.C
coupling = $(general)/coupling
$(coupling)/externalFileCoupler.C
solutionControl = $(general)/solutionControl solutionControl = $(general)/solutionControl
$(solutionControl)/solutionControl/solutionControl.C $(solutionControl)/solutionControl/solutionControl.C
$(solutionControl)/loopControl/loopControl.C $(solutionControl)/loopControl/loopControl.C

View File

@ -301,6 +301,8 @@ PatchFunction1/CodedField/makeCodedFields.C
meshStructure/meshStructure.C meshStructure/meshStructure.C
coupling/externalFileCoupler.C
output/foamVtkIndPatchWriter.C output/foamVtkIndPatchWriter.C
output/foamVtkInternalMeshWriter.C output/foamVtkInternalMeshWriter.C
output/foamVtkPatchMeshWriter.C output/foamVtkPatchMeshWriter.C

View File

@ -290,7 +290,6 @@ public:
//- Remove files written by OpenFOAM //- Remove files written by OpenFOAM
void removeDirectory() const; void removeDirectory() const;
}; };