diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H index c8484f8f7..a38cffc63 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H @@ -121,13 +121,7 @@ forAll(fluidRegions, i) ) ); - dimensionedScalar ghRef - ( - mag(gFluid[i].value()) > small - ? gFluid[i] - & (cmptMag(gFluid[i].value())/mag(gFluid[i].value()))*hRefFluid[i] - : dimensionedScalar("ghRef", gFluid[i].dimensions()*dimLength, 0) - ); + dimensionedScalar ghRef(- mag(gFluid[i])*hRefFluid[i]); Info<< " Adding to ghFluid\n" << endl; ghFluid.set diff --git a/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.C b/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.C index 192dee724..d2a3ca2c2 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.C +++ b/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.C @@ -26,7 +26,7 @@ License #include "twoPhaseMixtureThermo.H" #include "gradientEnergyFvPatchScalarField.H" #include "mixedEnergyFvPatchScalarField.H" - +#include "collatedFileOperation.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -50,6 +50,12 @@ Foam::twoPhaseMixtureThermo::twoPhaseMixtureThermo thermo1_(nullptr), thermo2_(nullptr) { + // Note: we're writing files to be read in immediately afterwards. + // Avoid any thread-writing problems. + float bufSz = + fileOperations::collatedFileOperation::maxThreadFileBufferSize; + fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0; + { volScalarField T1 ( @@ -80,6 +86,10 @@ Foam::twoPhaseMixtureThermo::twoPhaseMixtureThermo T2.write(); } + fileOperations::collatedFileOperation::maxThreadFileBufferSize = + bufSz; + + thermo1_ = rhoThermo::New(U.mesh(), phase1Name()); thermo2_ = rhoThermo::New(U.mesh(), phase2Name()); diff --git a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePair/phasePair.C b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePair/phasePair.C index 1cff0aa63..77d113817 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePair/phasePair.C +++ b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePair/phasePair.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "phasePair.H" -#include "surfaceTensionModel.H" +#include "phaseSystem.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -165,15 +165,7 @@ Foam::tmp Foam::phasePair::EoH2() const Foam::tmp Foam::phasePair::sigma() const { - return - phase1().mesh().lookupObject - ( - IOobject::groupName - ( - surfaceTensionModel::typeName, - phasePair::name() - ) - ).sigma(); + return phase1().fluid().sigma(phasePair(phase1(), phase2())); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H index e9b2e121e..5599ac865 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -626,6 +626,15 @@ class vtkPVFoam const wordHashSet& ); + //- Get the list of selected objects + IOobjectList getObjects + ( + const wordHashSet& selected, + const fvMesh& mesh, + const fileName& instance, + const fileName& local = "" + ); + //- Retrieve the current selections static wordHashSet getSelected(vtkDataArraySelection*); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C index 2554b2cae..66e2439bc 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,37 +23,53 @@ License \*---------------------------------------------------------------------------*/ -#include "vtkPVFoam.H" - -// OpenFOAM includes -#include "IOobjectList.H" -#include "vtkPVFoamReader.h" - // VTK includes #include "vtkDataArraySelection.h" #include "vtkPolyData.h" #include "vtkUnstructuredGrid.h" -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - +// OpenFOAM includes +#include "IOobjectList.H" +#include "vtkPVFoam.H" +#include "vtkPVFoamReader.h" #include "vtkPVFoamVolFields.H" #include "vtkPVFoamPointFields.H" #include "vtkPVFoamLagrangianFields.H" -void Foam::vtkPVFoam::pruneObjectList +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::IOobjectList Foam::vtkPVFoam::getObjects ( - IOobjectList& objects, - const wordHashSet& selected + const wordHashSet& selected, + const fvMesh& mesh, + const fileName& instance, + const fileName& local ) { - // hash all the selected field names + // If nothing is selected then return an empty list if (selected.empty()) { - objects.clear(); + return IOobjectList(0); } - // only keep selected fields + // Create the list of objects at the instance + IOobjectList objects(mesh, instance, local); + + // Add any objects from constant that are not already present + IOobjectList objectsConstant(mesh, dbPtr_().constant(), local); + forAllIter(IOobjectList, objectsConstant, iter) + { + if (!objects.found(iter.key())) + { + objects.add + ( + *objectsConstant.HashPtrTable::remove(iter) + ); + } + } + + // Remove everything that is not selected forAllIter(IOobjectList, objects, iter) { if (!selected.found(iter()->name())) @@ -61,6 +77,8 @@ void Foam::vtkPVFoam::pruneObjectList objects.erase(iter); } } + + return objects; } @@ -83,8 +101,15 @@ void Foam::vtkPVFoam::convertVolFields // Get objects (fields) for this time - only keep selected fields // the region name is already in the mesh db - IOobjectList objects(mesh, dbPtr_().timeName()); - pruneObjectList(objects, selectedFields); + IOobjectList objects + ( + getObjects + ( + selectedFields, + mesh, + dbPtr_().timeName() + ) + ); if (objects.empty()) { @@ -174,8 +199,15 @@ void Foam::vtkPVFoam::convertPointFields // Get objects (fields) for this time - only keep selected fields // the region name is already in the mesh db - IOobjectList objects(mesh, dbPtr_().timeName()); - pruneObjectList(objects, selectedFields); + IOobjectList objects + ( + getObjects + ( + selectedFields, + mesh, + dbPtr_().timeName() + ) + ); if (objects.empty()) { @@ -267,11 +299,14 @@ void Foam::vtkPVFoam::convertLagrangianFields // the region name is already in the mesh db IOobjectList objects ( - mesh, - dbPtr_().timeName(), - cloud::prefix/cloudName + getObjects + ( + selectedFields, + mesh, + dbPtr_().timeName(), + cloud::prefix/cloudName + ) ); - pruneObjectList(objects, selectedFields); if (objects.empty()) { diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index 121b4b8da..486290c8d 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -859,7 +859,7 @@ bool Foam::decomposedBlockData::writeBlocks label startProc = 1; label nSendProcs = nProcs-1; - while (nSendProcs > 0) + while (nSendProcs > 0 && startProc < nProcs) { nSendProcs = calcNumProcs ( @@ -873,7 +873,7 @@ bool Foam::decomposedBlockData::writeBlocks startProc ); - if (startProc == nProcs || nSendProcs == 0) + if (nSendProcs == 0) { break; } diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C index 07a19f368..2d6f39ebd 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C @@ -265,7 +265,11 @@ void Foam::OFstreamCollator::waitForBufferSpace(const off_t wantedSize) const } } - if (totalSize == 0 || (totalSize+wantedSize) <= maxBufferSize_) + if + ( + totalSize == 0 + || (wantedSize >= 0 && (totalSize+wantedSize) <= maxBufferSize_) + ) { break; } @@ -354,7 +358,8 @@ bool Foam::OFstreamCollator::write IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, - const bool append + const bool append, + const bool useThread ) { // Determine (on master) sizes to receive. Note: do NOT use thread @@ -374,7 +379,7 @@ bool Foam::OFstreamCollator::write Pstream::scatter(maxLocalSize, Pstream::msgType(), localComm_); } - if (maxBufferSize_ == 0 || maxLocalSize > maxBufferSize_) + if (!useThread || maxBufferSize_ == 0 || maxLocalSize > maxBufferSize_) { if (debug) { @@ -589,4 +594,20 @@ bool Foam::OFstreamCollator::write } +void Foam::OFstreamCollator::waitAll() +{ + // Wait for all buffer space to be available i.e. wait for all jobs + // to finish + if (Pstream::master(localComm_)) + { + if (debug) + { + Pout<< "OFstreamCollator : waiting for thread to have consumed all" + << endl; + } + waitForBufferSpace(-1); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H index 92ef9068b..594634199 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H @@ -206,8 +206,12 @@ public: IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, - const bool append + const bool append, + const bool useThread = true ); + + //- Wait for all thread actions to have finished + void waitAll(); }; diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C index c7c6830ac..614e846af 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C @@ -556,14 +556,32 @@ bool Foam::fileOperations::collatedFileOperation::writeObject } else { + // Re-check static maxThreadFileBufferSize variable to see + // if needs to use threading + bool useThread = (maxThreadFileBufferSize > 0); + if (debug) { Pout<< "collatedFileOperation::writeObject :" << " For object : " << io.name() - << " starting collating output to " << pathName << endl; + << " starting collating output to " << pathName + << " useThread:" << useThread << endl; } - threadedCollatedOFstream os(writer_, pathName, fmt, ver, cmp); + if (!useThread) + { + writer_.waitAll(); + } + + threadedCollatedOFstream os + ( + writer_, + pathName, + fmt, + ver, + cmp, + useThread + ); // If any of these fail, return (leave error handling to Ostream // class) diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C index df919680f..c35ba0c1f 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,13 +35,15 @@ Foam::threadedCollatedOFstream::threadedCollatedOFstream const fileName& pathName, streamFormat format, versionNumber version, - compressionType compression + compressionType compression, + const bool useThread ) : OStringStream(format, version), writer_(writer), pathName_(pathName), - compression_(compression) + compression_(compression), + useThread_(useThread) {} @@ -57,7 +59,8 @@ Foam::threadedCollatedOFstream::~threadedCollatedOFstream() IOstream::BINARY, version(), compression_, - false // append + false, // append + useThread_ ); } diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H index e296e1132..f9b02eed6 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,6 +60,8 @@ class threadedCollatedOFstream const IOstream::compressionType compression_; + const bool useThread_; + public: @@ -72,7 +74,8 @@ public: const fileName& pathname, streamFormat format=ASCII, versionNumber version=currentVersion, - compressionType compression=UNCOMPRESSED + compressionType compression=UNCOMPRESSED, + const bool useThread = true ); diff --git a/src/finiteVolume/cfdTools/general/include/gh.H b/src/finiteVolume/cfdTools/general/include/gh.H index 24774c74e..12ca32f0c 100644 --- a/src/finiteVolume/cfdTools/general/include/gh.H +++ b/src/finiteVolume/cfdTools/general/include/gh.H @@ -1,9 +1,4 @@ Info<< "Calculating field g.h\n" << endl; - dimensionedScalar ghRef - ( - mag(g.value()) > small - ? g & (cmptMag(g.value())/mag(g.value()))*hRef - : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0) - ); + dimensionedScalar ghRef(- mag(g)*hRef); volScalarField gh("gh", (g & mesh.C()) - ghRef); surfaceScalarField ghf("ghf", (g & mesh.Cf()) - ghRef); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/PrghPressure/PrghPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/PrghPressure/PrghPressureFvPatchScalarField.C index b17a8f973..3428350b3 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/PrghPressure/PrghPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/PrghPressure/PrghPressureFvPatchScalarField.C @@ -118,12 +118,7 @@ updateCoeffs() const uniformDimensionedScalarField& hRef = this->db().template lookupObject("hRef"); - dimensionedScalar ghRef - ( - mag(g.value()) > small - ? g & (cmptMag(g.value())/mag(g.value()))*hRef - : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0) - ); + const dimensionedScalar ghRef(- mag(g)*hRef); this->operator== ( diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C index 1760a340a..4449d1f65 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C @@ -140,12 +140,7 @@ void Foam::uniformDensityHydrostaticPressureFvPatchScalarField::updateCoeffs() const uniformDimensionedScalarField& hRef = db().lookupObject("hRef"); - ghRef = - ( - mag(g.value()) > small - ? (g & (cmptMag(g.value())/mag(g.value()))*hRef).value() - : 0 - ); + ghRef = - mag(g.value())*hRef.value(); } operator== diff --git a/src/fvOptions/sources/derived/tabulatedAccelerationSource/tabulatedAccelerationSourceTemplates.C b/src/fvOptions/sources/derived/tabulatedAccelerationSource/tabulatedAccelerationSourceTemplates.C index df0cd5706..ce89e6161 100644 --- a/src/fvOptions/sources/derived/tabulatedAccelerationSource/tabulatedAccelerationSourceTemplates.C +++ b/src/fvOptions/sources/derived/tabulatedAccelerationSource/tabulatedAccelerationSourceTemplates.C @@ -51,12 +51,7 @@ void Foam::fv::tabulatedAccelerationSource::addSup g = g0_ - dimensionedVector("a", dimAcceleration, acceleration.x()); - dimensionedScalar ghRef - ( - mag(g.value()) > small - ? g & (cmptMag(g.value())/mag(g.value()))*hRef - : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0) - ); + dimensionedScalar ghRef(- mag(g)*hRef); mesh_.lookupObjectRef("gh") = (g & mesh_.C()) - ghRef; diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.C b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.C index 8977ada27..0f7ad0f01 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.C +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.C @@ -520,6 +520,10 @@ void Foam::ReactingMultiphaseParcel::calcDevolatilisation // Check that model is active if (!cloud.devolatilisation().active()) { + if (canCombust != -1) + { + canCombust = 1; + } return; }