Commit 0b1221c2 authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

parents 271d9518 ba21ae89
......@@ -86,9 +86,25 @@ if (mesh.changing())
fvm::laplacian(rAUf, pcorr) == fvc::div(phi)
);
//pcorrEqn.setReference(refCellI2, 0.0, true);
scalarList values(nZones, 0.0);
pcorrEqn.setReferences(refCells, values, true);
// Only set reference for cells that are CALCULATED
{
DynamicList<label> validCells(refCells.size());
forAll(refCells, zoneId)
{
if (refCells[zoneId] != -1)
{
validCells.append(refCells[zoneId]);
}
}
pcorrEqn.setReferences
(
validCells,
scalarList(validCells.size(), 0.0),
true
);
}
const dictionary& d = mesh.solver
(
......@@ -97,6 +113,7 @@ if (mesh.changing())
pimple.finalInnerIter()
)
);
//Bypass virtual layer
mesh.fvMesh::solve(pcorrEqn, d);
if (pimple.finalNonOrthogonalIter())
......
......@@ -96,9 +96,25 @@
fvm::laplacian(rAUf, pcorr) == fvc::div(phi)
);
//pcorrEqn.setReference(refCellI2, 0, true);
scalarList values(nZones, 0.0);
pcorrEqn.setReferences(refCells, values, true);
// Only set reference for cells that are CALCULATED
{
DynamicList<label> validCells(refCells.size());
forAll(refCells, zoneId)
{
if (refCells[zoneId] != -1)
{
validCells.append(refCells[zoneId]);
}
}
pcorrEqn.setReferences
(
validCells,
scalarList(validCells.size(), 0.0),
true
);
}
const dictionary& d = mesh.solver
(
......@@ -117,9 +133,9 @@
}
}
if (runTime.outputTime())
{
volScalarField("contPhiPcorr", fvc::div(phi)).write();
pcorr.write();
}
//if (runTime.outputTime())
//{
// volScalarField("contPhiPcorr", fvc::div(phi)).write();
// pcorr.write();
//}
}
Test-externalCoupler.C
EXE = $(FOAM_USER_APPBIN)/Test-externalCoupler
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lumpedPointMotion/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-llumpedPointMotion
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-externalCoupler
Description
Test of master/slave communication etc.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "externalCoupler.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::addOption("max", "N", "max number of calls (default: 1000)");
argList::addBoolOption("slave", "run as slave");
#include "setRootCase.H"
const label maxCount = args.optionLookupOrDefault<label>("max", 1000);
externalCoupler coupler;
if (args.optionFound("slave"))
{
const word role = "slave";
Info<< "Running as " << role << " max=" << maxCount << endl;
for (label count = 0; count < maxCount; ++count)
{
// Wait for master, but stop if status=done was seen
Info<< role << ": waiting for master" << endl;
if (!coupler.waitForMaster())
{
Info<< role << ": stopping. status=done was detected" << endl;
break;
}
Info<< role << ": switch to master" << endl;
coupler.useMaster();
}
}
else
{
const word role = "master";
Info<< "Running as " << role << " max=" << maxCount << endl;
for (label count = 0; count < maxCount; ++count)
{
// Wait for slave, but stop if status=done was seen
Info<< role << ": waiting for slave" << endl;
if (!coupler.waitForSlave())
{
Info<< role << ": stopping. status=done was detected" << endl;
break;
}
Info<< role << ": switch to slave" << endl;
coupler.useSlave();
}
}
return 0;
}
// ************************************************************************* //
lumpedPointForces.C
EXE = $(FOAM_APPBIN)/lumpedPointForces
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lumpedPointMotion/lnInclude
EXE_LIBS = \
-lmeshTools \
-lfiniteVolume \
-llumpedPointMotion
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
lumpedPointForces
Description
Extract force/moment information from existing calculations based
on the segmentation of the pressure integration zones.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "timeSelector.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoFieldType>
autoPtr<GeoFieldType> loadField
(
const volMesh::Mesh& mesh,
const IOobject* io
)
{
if (io && io->headerClassName() == GeoFieldType::typeName)
{
Info<< "Reading " << GeoFieldType::typeName
<< ' ' << io->name() << endl;
return autoPtr<GeoFieldType>
(
new GeoFieldType
(
IOobject
(
io->name(),
io->instance(),
io->local(),
io->db(),
IOobject::MUST_READ,
IOobject::AUTO_WRITE,
io->registerObject()
),
mesh
)
);
}
return autoPtr<GeoFieldType>();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Extract force/moment information from existing calculations based "
"on the lumpedPoints pressure zones."
);
argList::addBoolOption
(
"vtk",
"create visualization files of the forces"
);
timeSelector::addOptions(true, false);
argList::noFunctionObjects(); // Never use function objects
#include "addRegionOption.H"
#include "setRootCase.H"
const bool withVTK = args.optionFound("vtk");
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New
(
runTime
);
if (!movement.valid())
{
Info<< "no valid movement given" << endl;
return 1;
}
const labelList patchLst = lumpedPointTools::lumpedPointPatchList(mesh);
if (patchLst.empty())
{
Info<< "no patch list found" << endl;
return 2;
}
movement().setMapping(mesh, patchLst, lumpedPointTools::points0Field(mesh));
List<vector> forces, moments;
forAll(timeDirs, timei)
{
runTime.setTime(timeDirs[timei], timei);
Info<< "Time = " << runTime.timeName() << endl;
if (mesh.readUpdate())
{
Info<< " Read new mesh" << nl;
}
// Search for list of objects for this time
IOobjectList objects(mesh, runTime.timeName());
// Pressure field
autoPtr<volScalarField> pField
= loadField<volScalarField>(mesh, objects.lookup("p"));
// The forces per zone
if (movement().forcesAndMoments(mesh, forces, moments))
{
Info<<"forces per zone: " << forces << endl;
Info<<"moments per zone: " << moments << endl;
if (withVTK && Pstream::master())
{
const word outputName =
Foam::name("forces_%06d.vtp", runTime.timeIndex());
Info<<" " << outputName << endl;
movement().writeForcesAndMomentsVTP
(
outputName,
forces,
moments
);
}
}
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
lumpedPointMovement.C
EXE = $(FOAM_APPBIN)/lumpedPointMovement
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lumpedPointMotion/lnInclude
EXE_LIBS = \
-lmeshTools \
-lfiniteVolume \
-llumpedPointMotion
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
lumpedPointMovement
Description
Thus utility can be used to produce VTK files to visualize the response
points/rotations and the corresponding movement of the building surfaces.
Uses the tabulated responses from the specified file.
Optionally, it can also be used to a dummy responder for the
externalCoupler logic, which makes it useful as a debugging facility
as well demonstrating how an external application could communicate
with the lumpedPointMovement point-patch boundary condition.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "timeSelector.H"
#include "OFstream.H"
#include "lumpedPointTools.H"
#include "lumpedPointIOMovement.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Visualize lumpedPoint movements or provide a slave responder "
"for diagnostic purposes."
);
argList::noParallel();
argList::noFunctionObjects(); // Never use function objects
argList::addOption
(
"max",
"N",
"maximum number of outputs"
);
argList::addOption
(
"span",
"N",
"increment each input by factor N (default: 1)"
);
argList::addOption
(
"scale",
"factor",
"relaxation/scaling factor for movement (default: 1)"
);
argList::addBoolOption
(
"removeLock",
"remove lock-file on termination of slave"
);
argList::addBoolOption
(
"slave",
"invoke as a slave responder for testing"
);
argList::validArgs.insert("responseFile");
#include "setRootCase.H"
const label maxOut =
Foam::max(0, args.optionLookupOrDefault<label>("max", 0));
const label span =
Foam::max(1, args.optionLookupOrDefault<label>("span", 1));
const scalar relax = args.optionLookupOrDefault<scalar>("scale", 1);
const bool slave = args.optionFound("slave");
const bool removeLock = args.optionFound("removeLock");
#include "createTime.H"
autoPtr<lumpedPointIOMovement> movement = lumpedPointIOMovement::New
(
runTime
);
if (!movement.valid())
{
Info<< "no valid movement given" << endl;
return 1;
}
List<lumpedPointStateTuple> responseTable =
lumpedPointTools::lumpedPointStates(args[1]);
Info<< "Using response table with " << responseTable.size()
<< " entries" << endl;
Info << "Increment input by " << span << nl;
if (maxOut)
{
Info<< "Stopping after " << maxOut << " outputs" << endl;
}
if (slave)
{
Info<< "Running as slave responder" << endl;
externalCoupler& coupler = movement().coupler();
label count = 0;
for (label index = 0; index < responseTable.size(); index += span)
{
Info<< args.executable() << ": waiting for master" << endl;
// Wait for master, but stop if status=done was seen
if (!coupler.waitForMaster())
{
Info<< args.executable()
<< ": stopping status=done was detected" << endl;
break;
}
lumpedPointState state = responseTable[index].second();
state.relax(relax, movement().state0());
// Generate input for OpenFOAM
OFstream os(coupler.resolveFile(movement().inputName()));
if
(
movement().inputFormat()
== lumpedPointState::inputFormatType::PLAIN
)
{
state.writePlain(os);
}
else
{
os.writeEntry("time", responseTable[index].first());
state.writeDict(os);
}
Info<< args.executable()
<< ": updated to state " << index
<< " - switch to master"
<< endl;
// Let OpenFOAM know that it can continue
coupler.useMaster();
if (maxOut && ++count >= maxOut)
{
Info<< args.executable()
<<": stopping after " << maxOut << " outputs" << endl;
break;
}
}
if (removeLock)
{