diff --git a/applications/solvers/dsmc/dsmcFoam/Make/files b/applications/solvers/discreteMethods/dsmc/dsmcFoam/Make/files similarity index 100% rename from applications/solvers/dsmc/dsmcFoam/Make/files rename to applications/solvers/discreteMethods/dsmc/dsmcFoam/Make/files diff --git a/applications/solvers/dsmc/dsmcFoam/Make/options b/applications/solvers/discreteMethods/dsmc/dsmcFoam/Make/options similarity index 100% rename from applications/solvers/dsmc/dsmcFoam/Make/options rename to applications/solvers/discreteMethods/dsmc/dsmcFoam/Make/options diff --git a/applications/solvers/dsmc/dsmcFoam/createFields.H b/applications/solvers/discreteMethods/dsmc/dsmcFoam/createFields.H similarity index 100% rename from applications/solvers/dsmc/dsmcFoam/createFields.H rename to applications/solvers/discreteMethods/dsmc/dsmcFoam/createFields.H diff --git a/applications/solvers/dsmc/dsmcFoam/dsmcFoam.C b/applications/solvers/discreteMethods/dsmc/dsmcFoam/dsmcFoam.C similarity index 100% rename from applications/solvers/dsmc/dsmcFoam/dsmcFoam.C rename to applications/solvers/discreteMethods/dsmc/dsmcFoam/dsmcFoam.C diff --git a/applications/solvers/molecularDynamics/mdEquilibrationFoam/Make/files b/applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/Make/files similarity index 100% rename from applications/solvers/molecularDynamics/mdEquilibrationFoam/Make/files rename to applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/Make/files diff --git a/applications/solvers/molecularDynamics/mdEquilibrationFoam/Make/options b/applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/Make/options similarity index 100% rename from applications/solvers/molecularDynamics/mdEquilibrationFoam/Make/options rename to applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/Make/options diff --git a/applications/solvers/molecularDynamics/mdEquilibrationFoam/mdEquilibrationFoam.C b/applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/mdEquilibrationFoam.C similarity index 100% rename from applications/solvers/molecularDynamics/mdEquilibrationFoam/mdEquilibrationFoam.C rename to applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/mdEquilibrationFoam.C diff --git a/applications/solvers/molecularDynamics/mdEquilibrationFoam/readmdEquilibrationDict.H b/applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/readmdEquilibrationDict.H similarity index 100% rename from applications/solvers/molecularDynamics/mdEquilibrationFoam/readmdEquilibrationDict.H rename to applications/solvers/discreteMethods/molecularDynamics/mdEquilibrationFoam/readmdEquilibrationDict.H diff --git a/applications/solvers/molecularDynamics/mdFoam/Make/files b/applications/solvers/discreteMethods/molecularDynamics/mdFoam/Make/files similarity index 100% rename from applications/solvers/molecularDynamics/mdFoam/Make/files rename to applications/solvers/discreteMethods/molecularDynamics/mdFoam/Make/files diff --git a/applications/solvers/molecularDynamics/mdFoam/Make/options b/applications/solvers/discreteMethods/molecularDynamics/mdFoam/Make/options similarity index 100% rename from applications/solvers/molecularDynamics/mdFoam/Make/options rename to applications/solvers/discreteMethods/molecularDynamics/mdFoam/Make/options diff --git a/applications/solvers/molecularDynamics/mdFoam/mdFoam.C b/applications/solvers/discreteMethods/molecularDynamics/mdFoam/mdFoam.C similarity index 100% rename from applications/solvers/molecularDynamics/mdFoam/mdFoam.C rename to applications/solvers/discreteMethods/molecularDynamics/mdFoam/mdFoam.C diff --git a/applications/solvers/incompressible/pimpleDyMFoam/createFields.H b/applications/solvers/incompressible/pimpleDyMFoam/createFields.H index ff3f9c51696c506eb51878d4e8a07b0837b0b89e..bc798ba988df54a0fe3518443c6382ec5375d818 100644 --- a/applications/solvers/incompressible/pimpleDyMFoam/createFields.H +++ b/applications/solvers/incompressible/pimpleDyMFoam/createFields.H @@ -1,4 +1,3 @@ - Info<< "Reading field p\n" << endl; volScalarField p ( @@ -33,7 +32,7 @@ label pRefCell = 0; scalar pRefValue = 0.0; - setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue); + setRefCell(p, mesh.solutionDict().subDict("PIMPLE"), pRefCell, pRefValue); singlePhaseTransportModel laminarTransport(U, phi); diff --git a/applications/solvers/incompressible/pimpleDyMFoam/pimpleDyMFoam.C b/applications/solvers/incompressible/pimpleDyMFoam/pimpleDyMFoam.C index b705d2bbb764d4d4ff245707a340168c59b8e12c..66692cc4a854491f4d6339ccce0e4ab11e194e25 100644 --- a/applications/solvers/incompressible/pimpleDyMFoam/pimpleDyMFoam.C +++ b/applications/solvers/incompressible/pimpleDyMFoam/pimpleDyMFoam.C @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Application - turbDyMFoam + pimpleDyMFoam.C Description Transient solver for incompressible, flow of Newtonian fluids @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) # include "createTime.H" # include "createDynamicFvMesh.H" -# include "readPISOControls.H" +# include "readPIMPLEControls.H" # include "initContinuityErrs.H" # include "createFields.H" # include "readTimeControls.H" diff --git a/applications/solvers/incompressible/pimpleDyMFoam/readControls.H b/applications/solvers/incompressible/pimpleDyMFoam/readControls.H index 9336616a1bec863a01212696f321470026eeff91..3bd20c5c5c65ece90bf200e268ca65115c1b05e1 100644 --- a/applications/solvers/incompressible/pimpleDyMFoam/readControls.H +++ b/applications/solvers/incompressible/pimpleDyMFoam/readControls.H @@ -1,14 +1,14 @@ # include "readTimeControls.H" -# include "readPISOControls.H" +# include "readPIMPLEControls.H" bool correctPhi = false; - if (piso.found("correctPhi")) + if (pimple.found("correctPhi")) { - correctPhi = Switch(piso.lookup("correctPhi")); + correctPhi = Switch(pimple.lookup("correctPhi")); } bool checkMeshCourantNo = false; - if (piso.found("checkMeshCourantNo")) + if (pimple.found("checkMeshCourantNo")) { - checkMeshCourantNo = Switch(piso.lookup("checkMeshCourantNo")); + checkMeshCourantNo = Switch(pimple.lookup("checkMeshCourantNo")); } diff --git a/applications/test/UIndirectListTest/UIndirectListTest.C b/applications/test/UIndirectListTest/UIndirectListTest.C index 575173c51e095e2488e7ad118f1699683c6e318b..9c619a4b991988b061141386aea1e70ca5947db4 100644 --- a/applications/test/UIndirectListTest/UIndirectListTest.C +++ b/applications/test/UIndirectListTest/UIndirectListTest.C @@ -28,6 +28,8 @@ Description #include "UIndirectList.H" #include "IOstreams.H" +#include "ListOps.H" +#include "OFstream.H" using namespace Foam; @@ -52,29 +54,32 @@ int main(int argc, char *argv[]) UIndirectList<double> idl(completeList, addresses); - forAll(idl, i) - { - Info<< idl[i] << token::SPACE; - } - - Info<< endl; + Info<< idl << "\n"; idl[1] = -666; - Info<< "idl[1] changed:" << idl() << endl; + Info<< "idl[1] changed:" << idl << endl; idl = -999; - Info<< "idl changed:" << idl() << endl; + Info<< "idl changed:" << idl << endl; UIndirectList<double> idl2(idl); - Info<< "idl2:" << idl2() << endl; + Info<< "idl2: " << idl2 << endl; - idl = idl2(); - Info<< "idl assigned from UList:" << idl() << endl; + { + List<double> ident(idl.size()); + + forAll(ident, i) + { + ident[i] = ident.size() - i; + } + idl = ident; + } + Info<< "idl assigned from UList:" << idl << endl; List<double> realList = UIndirectList<double>(completeList, addresses); diff --git a/applications/test/string/stringTest.C b/applications/test/string/stringTest.C index b8442102f395dd530b6a6e0a192ea7c9965ffeb6..2ed59bf88f7b4ab293a37bfe71b8251d51e38aea 100644 --- a/applications/test/string/stringTest.C +++ b/applications/test/string/stringTest.C @@ -70,6 +70,28 @@ int main(int argc, char *argv[]) string test2("~OpenFOAM/controlDict"); Info<< test2 << " => " << test2.expand() << endl; + // replace controlDict with "newName" + { + string::size_type i = test2.rfind('/'); + + if (i == string::npos) + { + test2 = "newName"; + } + else + { + // this uses the std::string::replace + test2.replace(i+1, string::npos, "newName"); + } + Info<< "after replace: " << test2 << endl; + + // do another replace + // this uses the Foam::string::replace + test2.replace("OpenFOAM", "openfoam"); + + Info<< "after replace: " << test2 << endl; + } + string s; Sin.getLine(s); @@ -78,8 +100,7 @@ int main(int argc, char *argv[]) cout<< "output string with " << s2.length() << " characters\n"; cout<< "ostream<< >" << s2 << "<\n"; Info<< "Ostream<< >" << s2 << "<\n"; - Info<< "hash:" << unsigned(string::hash()(s2)) << endl; - + Info<< "hash:" << hex << string::hash()(s2) << endl; Info << "End\n" << endl; diff --git a/applications/test/volPointInterpolation/volPointInterpolationTest.C b/applications/test/volPointInterpolation/volPointInterpolationTest.C index 07329ac3492d5978538c2ad4a49241970f4ce866..d44dcf9fa4e1743653bc9d1b363d55407f7872f5 100644 --- a/applications/test/volPointInterpolation/volPointInterpolationTest.C +++ b/applications/test/volPointInterpolation/volPointInterpolationTest.C @@ -68,8 +68,7 @@ int main(int argc, char *argv[]) mesh ); - pointMesh pMesh(mesh); - volPointInterpolation pInterp(mesh, pMesh); + const volPointInterpolation& pInterp = volPointInterpolation::New(mesh); pointScalarField pp(pInterp.interpolate(p)); pp.write(); diff --git a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C b/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C index c90594ff24ce90d46bb254e3ab40092437fb3054..9fb3a646d651fd9e49bda17cc88cb4217d295915 100644 --- a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C +++ b/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C @@ -39,24 +39,17 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - - Info<< "\nEstimating error in scalar transport equation\n" << endl; - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - Info<< "Reading transportProperties\n" << endl; + Info<< "\nEstimating error in scalar transport equation\n" + << "Reading transportProperties\n" << endl; IOdictionary transportProperties ( @@ -79,9 +72,9 @@ int main(int argc, char *argv[]) ); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C b/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C index 5ce860640d4ba212db7c55db684fd8ce2f0fccf1..c236b76eb4077d3ac58404f393fb49bc12c0f931 100644 --- a/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C +++ b/applications/utilities/errorEstimation/icoErrorEstimate/icoErrorEstimate.C @@ -38,25 +38,17 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - - Info<< "\nEstimating error in the incompressible momentum equation\n" - << endl; - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - Info<< "Reading transportProperties\n" << endl; + Info<< "\nEstimating error in the incompressible momentum equation\n" + << "Reading transportProperties\n" << endl; IOdictionary transportProperties ( @@ -75,9 +67,9 @@ int main(int argc, char *argv[]) transportProperties.lookup("nu") ); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C b/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C index 5810d64ca783a3f97f1c690ff648d025801f9cf5..67551e1eeccc631b48d02a815307f9f52e309748 100644 --- a/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C +++ b/applications/utilities/errorEstimation/icoMomentError/icoMomentError.C @@ -39,25 +39,17 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - - Info<< "\nEstimating error in the incompressible momentum equation\n" - << endl; - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - Info<< "Reading transportProperties\n" << endl; + Info<< "\nEstimating error in the incompressible momentum equation\n" + << "Reading transportProperties\n" << endl; IOdictionary transportProperties ( @@ -76,9 +68,9 @@ int main(int argc, char *argv[]) transportProperties.lookup("nu") ); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C b/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C index b1e1395bda026c9b727397af2940c97d37581d0b..f1767e75b01e6f2aa025bf39be577c686f2effa4 100644 --- a/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C +++ b/applications/utilities/errorEstimation/momentScalarError/momentScalarError.C @@ -40,24 +40,17 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - - Info<< "\nEstimating error in scalar transport equation\n" << endl; - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - Info<< "Reading transportProperties\n" << endl; + Info<< "\nEstimating error in scalar transport equation\n" + << "Reading transportProperties\n" << endl; IOdictionary transportProperties ( @@ -80,9 +73,9 @@ int main(int argc, char *argv[]) ); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C b/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C index 0a4f6d6027ba736196029f74e64715d021b91a5f..5cdbcb77e89f0d4a47aefdc6e2a80b90fc217492 100644 --- a/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C +++ b/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C @@ -61,6 +61,7 @@ See Also \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "timeSelector.H" #include "Time.H" #include "polyMesh.H" #include "STARCDMeshWriter.H" @@ -73,20 +74,17 @@ using namespace Foam; int main(int argc, char *argv[]) { argList::noParallel(); + timeSelector::addOptions(); + argList::validOptions.insert("scale", "scale"); argList::validOptions.insert("noBnd", ""); argList::validOptions.insert("tri", ""); argList::validOptions.insert("surface", ""); -# include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); bool surfaceOnly = false; if (args.options().found("surface") or args.options().found("tri")) @@ -118,17 +116,16 @@ int main(int argc, char *argv[]) # include "createPolyMesh.H" - // bool firstCheck = true; - for (label timeI = startTime; timeI < endTime; ++timeI) + forAll(timeDirs, timeI) { - runTime.setTime(Times[timeI], timeI); + runTime.setTime(timeDirs[timeI], timeI); # include "getTimeIndex.H" polyMesh::readUpdateState state = mesh.readUpdate(); - if (timeI == startTime || state != polyMesh::UNCHANGED) + if (!timeI || state != polyMesh::UNCHANGED) { meshWriters::STARCD writer(mesh, scaleFactor); diff --git a/applications/utilities/mesh/conversion/polyDualMesh/Make/files b/applications/utilities/mesh/conversion/polyDualMesh/Make/files index 752da5cfddb22955af52029c6b36312a2fedfc45..189fc19ec52d3e73eaa7009c42801334e8929793 100644 --- a/applications/utilities/mesh/conversion/polyDualMesh/Make/files +++ b/applications/utilities/mesh/conversion/polyDualMesh/Make/files @@ -1,4 +1,4 @@ meshDualiser.C -makePolyDualMesh.C +polyDualMeshApp.C EXE = $(FOAM_APPBIN)/polyDualMesh diff --git a/applications/utilities/mesh/conversion/polyDualMesh/makePolyDualMesh.C b/applications/utilities/mesh/conversion/polyDualMesh/polyDualMeshApp.C similarity index 99% rename from applications/utilities/mesh/conversion/polyDualMesh/makePolyDualMesh.C rename to applications/utilities/mesh/conversion/polyDualMesh/polyDualMeshApp.C index ab55305402154b07b5ae68e8275ddd23cd0558c9..8b03d895422f5fb09bea09eb6d814829d4ac2f23 100644 --- a/applications/utilities/mesh/conversion/polyDualMesh/makePolyDualMesh.C +++ b/applications/utilities/mesh/conversion/polyDualMesh/polyDualMeshApp.C @@ -348,8 +348,10 @@ int main(int argc, char *argv[]) # include "setRootCase.H" # include "createTime.H" + // Get times list instantList Times = runTime.times(); + # include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); @@ -509,7 +511,7 @@ int main(int argc, char *argv[]) Info<< "Writing dual mesh to " << runTime.timeName() << endl; mesh.write(); - + Info<< "End\n" << endl; return 0; diff --git a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C index e6c2560b38ebf02b02932c10bad79486f309831d..d8042fdaa8a2b522f332592793817d67e50b4e1e 100644 --- a/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C +++ b/applications/utilities/mesh/conversion/writeMeshObj/writeMeshObj.C @@ -37,6 +37,7 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "timeSelector.H" #include "Time.H" #include "polyMesh.H" #include "OFstream.H" @@ -336,6 +337,7 @@ void writePointCells int main(int argc, char *argv[]) { + timeSelector::addOptions(); argList::validOptions.insert("patchFaces", ""); argList::validOptions.insert("cell", "cellI"); argList::validOptions.insert("face", "faceI"); @@ -343,7 +345,6 @@ int main(int argc, char *argv[]) argList::validOptions.insert("cellSet", "setName"); argList::validOptions.insert("faceSet", "setName"); -# include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" runTime.functionObjects().off(); @@ -361,31 +362,23 @@ int main(int argc, char *argv[]) << "(for points, faces, cells) is consistent with" << " Foam numbering (starting from 0)." << endl << endl; - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createPolyMesh.H" - bool firstCheck = true; - - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; polyMesh::readUpdateState state = mesh.readUpdate(); - if (firstCheck || state != polyMesh::UNCHANGED) + if (!timeI || state != polyMesh::UNCHANGED) { if (patchFaces) { writePatchFaces(mesh, runTime.timeName()); - } else if (doCell) { @@ -487,9 +480,7 @@ int main(int argc, char *argv[]) Info << "No mesh." << endl; } - firstCheck = false; - - Info << endl << endl; + Info << nl << endl; } diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C index a83154ad56e65ba908f0fa072d480fbd2650e626..886281274b6f1a859db28bcd81d192e08062f3bc 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C @@ -30,8 +30,7 @@ Description #include "arcEdge.H" #include "mathematicalConstants.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -40,8 +39,7 @@ namespace Foam defineTypeNameAndDebug(arcEdge, 0); // Add the curvedEdge constructor functions to the hash tables - curvedEdge::addIstreamConstructorToTable<arcEdge> - addArcEdgeIstreamConstructorToTable_; + addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream); } diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C index c9d31ef6a189939208bc706bd0a427775124b600..6a2d41a83e31af8d938cfb8bc1a4bccdffd532b7 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C @@ -41,26 +41,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(curvedEdge, 0); - -// Define the constructor function hash tables -HashTable<curvedEdge::IstreamConstructorPtr_>* - curvedEdge::IstreamConstructorTablePtr_; - - -// Hash table Constructor called from the table add functions. - -void curvedEdge::constructTables() -{ - static bool constructed = false; - - if (!constructed) - { - curvedEdge::IstreamConstructorTablePtr_ - = new HashTable<curvedEdge::IstreamConstructorPtr_>; - - constructed = true; - } -} +defineRunTimeSelectionTable(curvedEdge, Istream); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -117,10 +98,11 @@ autoPtr<curvedEdge> curvedEdge::New(const pointField& points, Istream& is) word curvedEdgeType(is); - HashTable<IstreamConstructorPtr_>::iterator curvedEdgeConstructorIter = - IstreamConstructorTablePtr_->find(curvedEdgeType); + IstreamConstructorTable::iterator cstrIter = + IstreamConstructorTablePtr_ + ->find(curvedEdgeType); - if (curvedEdgeConstructorIter == IstreamConstructorTablePtr_->end()) + if (cstrIter == IstreamConstructorTablePtr_->end()) { FatalErrorIn("curvedEdge::New(const pointField&, Istream&)") << "Unknown curvedEdge type " << curvedEdgeType << endl << endl @@ -129,7 +111,7 @@ autoPtr<curvedEdge> curvedEdge::New(const pointField& points, Istream& is) << abort(FatalError); } - return autoPtr<curvedEdge>(curvedEdgeConstructorIter()(points, is)); + return autoPtr<curvedEdge>(cstrIter()(points, is)); } @@ -177,7 +159,6 @@ Ostream& operator<<(Ostream& os, const curvedEdge& p) } - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H index c568180d73dc7352d1d40a85c7c0b9e6b20f20e8..5ecf489d38818e2030080246e02f1ca07f5cd919 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H @@ -63,51 +63,23 @@ protected: public: - // Constructor Hash tables - - //- Construct from Istream function pointer type - typedef autoPtr<curvedEdge> (*IstreamConstructorPtr_) - (const pointField&, Istream&); - - //- Construct from Istream function pointer table pointer - static HashTable<IstreamConstructorPtr_>* - IstreamConstructorTablePtr_; - - - // Hash table constructor classes and functions - - //- Hash table Constructor. - // Must be called from the table add functions below. - static void constructTables(); + //- Runtime type information + TypeName("curvedEdge"); - //- Class to add constructor from Istream to Hash table - template<class curvedEdgeType> - class addIstreamConstructorToTable - { - public: + // Declare run-time constructor selection tables - static autoPtr<curvedEdge> New + declareRunTimeSelectionTable + ( + autoPtr, + curvedEdge, + Istream, ( const pointField& points, Istream& is - ) - { - return autoPtr<curvedEdge>(new curvedEdgeType(points, is)); - } - - addIstreamConstructorToTable() - { - curvedEdge::constructTables(); - - curvedEdge::IstreamConstructorTablePtr_ - ->insert(curvedEdgeType::typeName, New); - } - }; - - - //- Runtime type information - TypeName("curvedEdge"); + ), + (points, is) + ); // Constructors diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C index f4581ed338e2ba79ce96fa4ec48f3c27abfad7fc..7263f7184362126d8bb094cfe6cafa205d3e3d2d 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C @@ -26,6 +26,7 @@ License #include "polySplineEdge.H" #include "BSpline.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -34,8 +35,7 @@ namespace Foam defineTypeNameAndDebug(polySplineEdge, 0); // Add the curvedEdge constructor functions to the hash tables - curvedEdge::addIstreamConstructorToTable<polySplineEdge> - addPolySplineEdgeIstreamConstructorToTable_; + addToRunTimeSelectionTable(curvedEdge, polySplineEdge, Istream); } diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H index d71685782d2694911b11cdc49fc195411ce3fabd..1f59d5bf8e71ebf77603ff69d9e0764073648896 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H @@ -92,7 +92,7 @@ public: ); //- Construct from Istream setting pointsList - polySplineEdge(const pointField& points,Istream& is); + polySplineEdge(const pointField& points, Istream& is); // Destructor diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C index 8fe13aefe0b9e20193ad5240f831310d55a8cc11..b45f0ea3c29a68a63573a4838e74fba7456731aa 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C @@ -27,9 +27,8 @@ Description \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "simpleSplineEdge.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -39,10 +38,8 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(simpleSplineEdge, 0); +addToRunTimeSelectionTable(curvedEdge, simpleSplineEdge, Istream); -// Add the curvedEdge constructor functions to the hash tables -curvedEdge::addIstreamConstructorToTable<simpleSplineEdge> - addSimpleSplineEdgeIstreamConstructorToTable_; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C index 74ab53432af98dd691cb6aab1a89cf18a597b486..d226008f5cd47b64772426b6ee2272c6a9e0a68c 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C @@ -31,7 +31,9 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "timeSelector.H" #include "Time.H" + #include "polyMesh.H" #include "globalMeshData.H" @@ -45,48 +47,34 @@ using namespace Foam; int main(int argc, char *argv[]) { + timeSelector::addOptions(false); // no constant # include "addRegionOption.H" - -# include "addTimeOptionsNoConstant.H" - argList::validOptions.insert("noTopology", ""); argList::validOptions.insert("allGeometry", ""); argList::validOptions.insert("allTopology", ""); # include "setRootCase.H" - - const bool noTopology = args.options().found("noTopology"); - const bool allGeometry = args.options().found("allGeometry"); - const bool allTopology = args.options().found("allTopology"); - # include "createTime.H" - - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptionsNoConstant.H" - - runTime.setTime(Times[startTime], startTime); - + instantList timeDirs = timeSelector::select0(runTime, args); # include "createNamedPolyMesh.H" - bool firstCheck = true; + const bool noTopology = args.options().found("noTopology"); + const bool allGeometry = args.options().found("allGeometry"); + const bool allTopology = args.options().found("allTopology"); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); polyMesh::readUpdateState state = mesh.readUpdate(); if ( - firstCheck + !timeI || state == polyMesh::TOPO_CHANGE || state == polyMesh::TOPO_PATCH_CHANGE ) { - firstCheck = false; - Info<< "Time = " << runTime.timeName() << nl << endl; // Clear mesh before checking @@ -110,32 +98,30 @@ int main(int argc, char *argv[]) if (noFailedChecks == 0) { - Info<< "\nMesh OK." - << nl << endl; + Info<< "\nMesh OK.\n" << endl; } else { - Info<< "\nFailed " << noFailedChecks << " mesh checks." - << nl << endl; + Info<< "\nFailed " << noFailedChecks << " mesh checks.\n" + << endl; } } else if (state == polyMesh::POINTS_MOVED) { Info<< "Time = " << runTime.timeName() << nl << endl; - label noFailedChecks = checkGeometry(mesh, allGeometry); + label nFailedChecks = checkGeometry(mesh, allGeometry); - reduce(noFailedChecks, sumOp<label>()); + reduce(nFailedChecks, sumOp<label>()); - if (noFailedChecks == 0) + if (nFailedChecks) { - Info << "\nMesh OK." - << nl << endl; + Info<< "\nFailed " << nFailedChecks << " mesh checks.\n" + << endl; } else { - Info<< "\nFailed " << noFailedChecks << " mesh checks." - << nl << endl; + Info << "\nMesh OK.\n" << endl; } } } diff --git a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C index 317799312cabe66657a6de4ace4cb4803acdafa7..d7a84ee45a88d7cf9bbe91dd50a8ac728ecd65f6 100644 --- a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C +++ b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C @@ -31,6 +31,7 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "timeSelector.H" #include "Time.H" #include "fvMesh.H" #include "volFields.H" @@ -66,7 +67,8 @@ void RotateFields int main(int argc, char *argv[]) { -# include "addTimeOptions.H" + timeSelector::addOptions(); + argList::validArgs.append("n1"); argList::validArgs.append("n2"); @@ -105,19 +107,15 @@ int main(int argc, char *argv[]) points.write(); } - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - for (label i=startTime; i<endTime; i++) + + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index a5909c398ab77f69b9dcefb1842266d06cac3101..ff6d576b0abb121cdc58bd7b4cd730e0431d9052 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -48,8 +48,8 @@ Description #if READLINE != 0 -#include <readline/readline.h> -#include <readline/history.h> +# include <readline/readline.h> +# include <readline/history.h> #endif using namespace Foam; diff --git a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C index 35eae96a588bed8d3a614412417ade67917fbcf5..ac32c1ccc9ad54a3bf20c043dc698d363080b643 100644 --- a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C +++ b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C @@ -48,6 +48,7 @@ Description #include "OFstream.H" #include "IFstream.H" #include "IOobjectList.H" +#include "SortableList.H" using namespace Foam; @@ -107,6 +108,7 @@ int main(int argc, char *argv[]) { // Not in memory. Load it. pointSet set(*iter()); + SortableList<label> pointLabels(set.toc()); label zoneID = mesh.pointZones().findZoneID(set.name()); if (zoneID == -1) @@ -120,7 +122,7 @@ int main(int argc, char *argv[]) new pointZone ( set.name(), //name - set.toc(), //addressing + pointLabels, //addressing sz, //index mesh.pointZones() //pointZoneMesh ) @@ -131,7 +133,7 @@ int main(int argc, char *argv[]) { Info<< "Overwriting contents of existing pointZone " << zoneID << " with that of set " << set.name() << "." << endl; - mesh.pointZones()[zoneID] = set.toc(); + mesh.pointZones()[zoneID] = pointLabels; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; } } @@ -150,6 +152,7 @@ int main(int argc, char *argv[]) { // Not in memory. Load it. cellSet set(*iter()); + SortableList<label> cellLabels(set.toc()); label zoneID = mesh.cellZones().findZoneID(set.name()); if (zoneID == -1) @@ -163,7 +166,7 @@ int main(int argc, char *argv[]) new cellZone ( set.name(), //name - set.toc(), //addressing + cellLabels, //addressing sz, //index mesh.cellZones() //pointZoneMesh ) @@ -174,7 +177,7 @@ int main(int argc, char *argv[]) { Info<< "Overwriting contents of existing cellZone " << zoneID << " with that of set " << set.name() << "." << endl; - mesh.cellZones()[zoneID] = set.toc(); + mesh.cellZones()[zoneID] = cellLabels; mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE; } } @@ -193,6 +196,7 @@ int main(int argc, char *argv[]) { // Not in memory. Load it. faceSet set(*iter()); + SortableList<label> faceLabels(set.toc()); DynamicList<label> addressing(set.size()); DynamicList<bool> flipMap(set.size()); @@ -214,9 +218,9 @@ int main(int argc, char *argv[]) // Load corresponding cells cellSet cells(mesh, setName); - forAllConstIter(faceSet, set, iter) + forAll(faceLabels, i) { - label faceI = iter.key(); + label faceI = faceLabels[i]; bool flip = false; @@ -273,9 +277,10 @@ int main(int argc, char *argv[]) else { // No flip map. - forAllConstIter(faceSet, set, iter) + forAll(faceLabels, i) { - addressing.append(iter.key()); + label faceI = faceLabels[i]; + addressing.append(faceI); flipMap.append(false); } } diff --git a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C index a910b3205724828330162c86b0f71e18b319f814..6854ba0b8d53a0d08bce360e3cc1c2928267d6f2 100644 --- a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C +++ b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C @@ -29,6 +29,9 @@ Description #include "argList.H" #include "dictionary.H" +#include "IFstream.H" +#include "IOobject.H" +#include "HashSet.H" using namespace Foam; @@ -38,18 +41,108 @@ using namespace Foam; int main(int argc, char *argv[]) { argList::noParallel(); + argList::validOptions.insert("new", ""); + argList::validOptions.insert("old", ""); + + Foam::argList args(argc, argv); + + wordList currDebug(debug::debugSwitches().toc()); + wordList currInfo(debug::infoSwitches().toc()); + wordList currOpt(debug::optimisationSwitches().toc()); + + if (args.options().found("old") || args.options().found("new")) + { + dictionary controlDict(IFstream(findEtcFile("controlDict", true))()); + + wordHashSet oldDebug + ( + controlDict.subDict("DebugSwitches").toc() + ); + + wordHashSet oldInfo + ( + controlDict.subDict("InfoSwitches").toc() + ); + + wordHashSet oldOpt + ( + controlDict.subDict("OptimisationSwitches").toc() + ); + + + wordHashSet hashset; + wordList listing; + + + // list old switches - but this can't work since the (old) inserted + // switches are in both sets + // Workaround: + // 1. run without any options (get complete list) + // 2. comment out DebugSwitches, run again with -new to find new ones + // and do a diff + if (args.options().found("old")) + { + IOobject::writeDivider(Info); + + hashset = oldDebug; + hashset -= currDebug; + listing = hashset.toc(); + sort(listing); + Info<< "old DebugSwitches: " << listing << endl; + + hashset = oldInfo; + hashset -= currInfo; + listing = hashset.toc(); + sort(listing); + Info<< "old InfoSwitches: " << listing << endl; + + hashset = oldOpt; + hashset -= currOpt; + listing = hashset.toc(); + sort(listing); + Info<< "old OptimisationSwitches: " << listing << endl; + } + + // list new switches + if (args.options().found("new")) + { + IOobject::writeDivider(Info); + + hashset = currDebug; + hashset -= oldDebug; + + listing = hashset.toc(); + sort(listing); + Info<< "new DebugSwitches: " << listing << endl; + + hashset = currInfo; + hashset -= oldInfo; + listing = hashset.toc(); + sort(listing); + Info<< "new InfoSwitches: " << listing << endl; + + hashset = currOpt; + hashset -= oldOpt; + listing = hashset.toc(); + sort(listing); + Info<< "new OptimisationSwitches: " << listing << endl; + } + } + else + { + IOobject::writeDivider(Info); + + sort(currDebug); + Info<< "DebugSwitches: " << currDebug << endl; + + sort(currInfo); + Info<< "InfoSwitches: " << currInfo << endl; + + sort(currOpt); + Info<< "OptimisationSwitches: " << currOpt << endl; + } - wordList ds(debug::debugSwitches().toc()); - sort(ds); - Info<< "debug switches: " << ds << endl; - wordList is(debug::infoSwitches().toc()); - sort(is); - Info<< "info switches: " << is << endl; - - wordList os(debug::optimisationSwitches().toc()); - sort(os); - Info<< "optimisation switches: " << os << endl; Info<< "done" << endl; diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummary.C b/applications/utilities/miscellaneous/patchSummary/patchSummary.C index 8195e4d9dc69bd9a3f59048bcf863fb067693356..67ae5270274bc6a6dd84d0fc510ae9979ae954a4 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummary.C +++ b/applications/utilities/miscellaneous/patchSummary/patchSummary.C @@ -40,25 +40,19 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "addRegionOption.H" # include "setRootCase.H" # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createNamedMesh.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index fff19e006d6f36cc223b84fa36e98ae6493dd2ea..5edafcf561611abb7cab29944b824ccd6bf21cc7 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -312,7 +312,7 @@ int main(int argc, char *argv[]) fileNameList cloudDirs ( - readDir(runTime.timePath()/"lagrangian", fileName::DIRECTORY) + readDir(runTime.timePath()/cloud::prefix, fileName::DIRECTORY) ); // Particles @@ -344,7 +344,7 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudDirs[i] + cloud::prefix/cloudDirs[i] ); IOobject* positionsPtr = sprayObjs.lookup("positions"); @@ -418,7 +418,7 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudDirs[cloudI] + cloud::prefix/cloudDirs[cloudI] ); lagrangianFieldDecomposer::readFields diff --git a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C index 4f11f4d53f54594a799ed0fc398869ba17318fab..ae852298086ba05a9b5ce45199171031b8a84662 100644 --- a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C +++ b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C @@ -88,7 +88,7 @@ tmp<IOField<Type> > lagrangianFieldDecomposer::decomposeField ( field.name(), procMesh_.time().timeName(), - "lagrangian"/cloudName, + cloud::prefix/cloudName, procMesh_, IOobject::NO_READ, IOobject::NO_WRITE diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H index 0cefe9e64153e1ea4c83322f6c037a7d9c2be678..18d282a90921c8acbec203bb61ca9e6fc527dfed 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H @@ -36,6 +36,7 @@ SourceFiles #ifndef reconstructLagrangian_H #define reconstructLagrangian_H +#include "cloud.H" #include "polyMesh.H" #include "IOobjectList.H" #include "fvMesh.H" diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C index 1f357fa64f5345da704f429154db31213bb555a6..a6fc1a49a8272699bd12ea02a39b0cff9a4b1266 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C @@ -47,7 +47,7 @@ Foam::tmp<Foam::IOField<Type> > Foam::reconstructLagrangianField ( fieldName, mesh.time().timeName(), - "lagrangian"/cloudName, + cloud::prefix/cloudName, mesh, IOobject::NO_READ, IOobject::NO_WRITE @@ -61,10 +61,10 @@ Foam::tmp<Foam::IOField<Type> > Foam::reconstructLagrangianField { // Check object on local mesh IOobject localIOobject - ( + ( fieldName, meshes[i].time().timeName(), - "lagrangian"/cloudName, + cloud::prefix/cloudName, meshes[i], IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 20def06b9c9cae6f6b0f1b3d9d7b8c33ddf6a5da..9311c9b4e9af1dff26b3cec570f56106f4898df8 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -51,6 +51,7 @@ int main(int argc, char *argv[]) argList::noParallel(); # include "addRegionOption.H" argList::validOptions.insert("fields", "\"(list of fields)\""); + argList::validOptions.insert("noLagrangian", ""); # include "setRootCase.H" # include "createTime.H" @@ -61,6 +62,8 @@ int main(int argc, char *argv[]) IStringStream(args.options()["fields"])() >> selectedFields; } + bool noLagrangian = args.options().found("noLagrangian"); + // determine the processor count directly label nProcs = 0; while (isDir(args.path()/(word("processor") + name(nProcs)))) @@ -269,118 +272,121 @@ int main(int argc, char *argv[]) // the first processor that has them. They are in pass2 only used // for name and type (scalar, vector etc). - HashTable<IOobjectList> cloudObjects; - - forAll (databases, procI) + if (!noLagrangian) { - fileNameList cloudDirs - ( - readDir - ( - databases[procI].timePath()/regionPrefix/"lagrangian", - fileName::DIRECTORY - ) - ); + HashTable<IOobjectList> cloudObjects; - forAll (cloudDirs, i) + forAll (databases, procI) { - // Check if we already have cloud objects for this cloudname. - HashTable<IOobjectList>::const_iterator iter = - cloudObjects.find(cloudDirs[i]); - - if (iter == cloudObjects.end()) - { - // Do local scan for valid cloud objects. - IOobjectList sprayObjs + fileNameList cloudDirs + ( + readDir ( - procMeshes.meshes()[procI], - databases[procI].timeName(), - "lagrangian"/cloudDirs[i] - ); + databases[procI].timePath()/regionPrefix/cloud::prefix, + fileName::DIRECTORY + ) + ); - IOobject* positionsPtr = sprayObjs.lookup("positions"); + forAll (cloudDirs, i) + { + // Check if we already have cloud objects for this cloudname + HashTable<IOobjectList>::const_iterator iter = + cloudObjects.find(cloudDirs[i]); - if (positionsPtr) + if (iter == cloudObjects.end()) { - cloudObjects.insert(cloudDirs[i], sprayObjs); + // Do local scan for valid cloud objects + IOobjectList sprayObjs + ( + procMeshes.meshes()[procI], + databases[procI].timeName(), + cloud::prefix/cloudDirs[i] + ); + + IOobject* positionsPtr = sprayObjs.lookup("positions"); + + if (positionsPtr) + { + cloudObjects.insert(cloudDirs[i], sprayObjs); + } } } } - } - if (cloudObjects.size()) - { - // Pass2: reconstruct the cloud - forAllConstIter(HashTable<IOobjectList>, cloudObjects, iter) + if (cloudObjects.size()) { - const word cloudName = string::validate<word>(iter.key()); + // Pass2: reconstruct the cloud + forAllConstIter(HashTable<IOobjectList>, cloudObjects, iter) + { + const word cloudName = string::validate<word>(iter.key()); - // Objects (on arbitrary processor) - const IOobjectList& sprayObjs = iter(); + // Objects (on arbitrary processor) + const IOobjectList& sprayObjs = iter(); - Info<< "Reconstructing lagrangian fields for cloud " - << cloudName << nl << endl; + Info<< "Reconstructing lagrangian fields for cloud " + << cloudName << nl << endl; - reconstructLagrangianPositions - ( - mesh, - cloudName, - procMeshes.meshes(), - procMeshes.faceProcAddressing(), - procMeshes.cellProcAddressing() - ); - reconstructLagrangianFields<label> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); - reconstructLagrangianFields<scalar> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); - reconstructLagrangianFields<vector> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); - reconstructLagrangianFields<sphericalTensor> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); - reconstructLagrangianFields<symmTensor> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); - reconstructLagrangianFields<tensor> - ( - cloudName, - mesh, - procMeshes.meshes(), - sprayObjs - ); + reconstructLagrangianPositions + ( + mesh, + cloudName, + procMeshes.meshes(), + procMeshes.faceProcAddressing(), + procMeshes.cellProcAddressing() + ); + reconstructLagrangianFields<label> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + reconstructLagrangianFields<scalar> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + reconstructLagrangianFields<vector> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + reconstructLagrangianFields<sphericalTensor> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + reconstructLagrangianFields<symmTensor> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + reconstructLagrangianFields<tensor> + ( + cloudName, + mesh, + procMeshes.meshes(), + sprayObjs + ); + } + } + else + { + Info << "No lagrangian fields" << nl << endl; } - } - else - { - Info << "No lagrangian fields" << nl << endl; } // If there are any "uniform" directories copy them from - // the master processor. + // the master processor fileName uniformDir0 = databases[0].timePath()/"uniform"; if (isDir(uniformDir0)) diff --git a/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C b/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C index 7f5a8e29174168fee94e47981034bb200b006d8e..4a63948f422eb9f7d7d028158b8be41f93012795 100644 --- a/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C +++ b/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C @@ -38,26 +38,22 @@ Description int main(int argc, char *argv[]) { argList::noParallel(); -# include "addTimeOptions.H" + timeSelector::addOptions(false); // no constant # include "setRootCase.H" # include "createTime.H" - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptionsNoConstant.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" // make a directory called proInterface in the case mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface"); - for (label timeI = startTime; timeI < endTime; timeI++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[timeI], timeI); + runTime.setTime(timeDirs[timeI], timeI); + Info<< "Time = " << runTime.timeName() << endl; if (mesh.readUpdate()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudField.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudField.H index 3e06a1674dbe9b1a286373a21e08fc3ff4379dbe..f6cd858dc69bda78f0f520d6ff96570a479c67f7 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudField.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudField.H @@ -35,6 +35,7 @@ SourceFiles #ifndef ensightCloudField_H #define ensightCloudField_H +#include "Cloud.H" #include "IOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index bb7c1880f00cc7a8fd9d5a304c84100ac8924b75..10d261bca5e508e59f19f4535f83eb2f2cb438de 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) fileNameList cloudDirs = readDir ( - runTime.timePath()/regionPrefix/"lagrangian", + runTime.timePath()/regionPrefix/cloud::prefix, fileName::DIRECTORY ); @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudDirs[cloudI] + cloud::prefix/cloudDirs[cloudI] ); IOobject* positionsPtr = cloudObjs.lookup("positions"); @@ -266,7 +266,7 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudIter.key() + cloud::prefix/cloudIter.key() ); forAllConstIter(IOobjectList, cloudObjs, fieldIter) @@ -426,7 +426,7 @@ int main(int argc, char *argv[]) fileNameList currentCloudDirs = readDir ( - runTime.timePath()/regionPrefix/"lagrangian", + runTime.timePath()/regionPrefix/cloud::prefix, fileName::DIRECTORY ); @@ -449,7 +449,7 @@ int main(int argc, char *argv[]) ( fieldName, mesh.time().timeName(), - "lagrangian"/cloudName, + cloud::prefix/cloudName, mesh, IOobject::MUST_READ ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputCase.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputCase.H index d8f079ea6df347eeec1ae4e9d2795831699527a3..0e3530b9c0dce1e3650983108667c341902271d3 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputCase.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputCase.H @@ -42,7 +42,7 @@ forAllConstIter(HashTable<HashTable<word> >, cloudFields, cloudIter) caseFile << setw(16) << "measured: 2" - << fileName(dataMask/"lagrangian"/cloudName/"positions").c_str() + << fileName(dataMask/cloud::prefix/cloudName/"positions").c_str() << nl; } caseFile @@ -122,7 +122,7 @@ forAllConstIter(HashTable<HashTable<word> >, cloudFields, cloudIter) ensightType, fieldName, dataMask, - "lagrangian"/cloudName, + cloud::prefix/cloudName, cloudNo, 2 ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C index ca472e073cfec12cbffbb4f884db941c6c9411eb..e62b10064c7ad0a259afa025ec9666409c9fa509 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C @@ -27,7 +27,6 @@ License #include "ensightOutputFunctions.H" #include "passiveParticle.H" -#include "Cloud.H" #include "IOField.H" #include "volFields.H" #include "surfaceFields.H" @@ -101,7 +100,7 @@ void ensightParticlePositions { Cloud<passiveParticle> parcels(mesh, cloudName, false); - fileName cloudDir = subDir/"lagrangian"/cloudName; + fileName cloudDir = subDir/cloud::prefix/cloudName; fileName postFileName = cloudDir/"positions"; // the ITER/lagrangian subdirectory must exist @@ -165,7 +164,7 @@ void ensightLagrangianField { Info<< " " << fieldObject.name() << flush; - fileName cloudDir = subDir/"lagrangian"/cloudName; + fileName cloudDir = subDir/cloud::prefix/cloudName; fileName postFileName = cloudDir/fieldObject.name(); string title = diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.H index 7afc250fe31f103b4f19bf62a2fd0ae643a2b63f..75437c2d69fbdbd2e0b989614a85e92e3b983eb6 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.H @@ -23,9 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description - - miscellaneous collection of functions and template related - to Ensight data + Miscellaneous collection of functions and template related to Ensight data SourceFiles ensightOutputFunctions.C @@ -36,6 +34,7 @@ SourceFiles #define ensightOutputFunctions_H #include "ensightFile.H" +#include "Cloud.H" #include "polyMesh.H" #include "IOobject.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H index cca3fbbcd3fbc4375b5282f66cfd94146e22be6e..edfbb5ae7d9b483fad7e7d7eb876ace2914750a2 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H @@ -36,7 +36,7 @@ if (timeDirs.size() > 1) runTime.path() / timeDirs[timeDirs.size() - 1].name() / regionPrefix - / "lagrangian", + / cloud::prefix, fileName::DIRECTORY ); @@ -55,7 +55,7 @@ if (timeDirs.size() > 1) ( mesh, timeDirs[timeDirs.size() - 1].name(), - "lagrangian"/cloudName + cloud::prefix/cloudName ); bool hasPositions = false; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C index 329dda87f9ebbbb4f3821ee6b93f2125e7c288f4..af2dee175a9351de1d961dc4b37d5061cc2858be 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C @@ -324,7 +324,14 @@ int main(int argc, char *argv[]) { const word& cloudName = cloudIter.key(); - if (!isDir(runTime.timePath()/regionPrefix/"lagrangian"/cloudName)) + if + ( + !isDir + ( + runTime.timePath()/regionPrefix/ + cloud::prefix/cloudName + ) + ) { continue; } @@ -333,7 +340,7 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudName + cloud::prefix/cloudName ); // check that the positions field is present for this time @@ -365,7 +372,8 @@ int main(int argc, char *argv[]) if (!fieldObject) { Info<< "missing " - << runTime.timeName()/"lagrangian"/cloudName/fieldName + << runTime.timeName()/cloud::prefix/cloudName + / fieldName << endl; continue; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/createSprayFields.H b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/createSprayFields.H index e28a04b58cf30269fe19be2dbd544d7a72e9cb6e..a5a218de804abed8fd523d5241979e4073fc66c4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/createSprayFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/createSprayFields.H @@ -21,7 +21,7 @@ List<IOField<vector>* > sprayVectorFieldPtrs ( sprayScalarNames[fieldI], runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE @@ -53,7 +53,7 @@ List<IOField<vector>* > sprayVectorFieldPtrs ( sprayVectorNames[fieldI], runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/getFieldNames.H b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/getFieldNames.H index 9a9789962588a06ff568dafdc9a5ed4f22fda430..129d788738403040a45b32a823cc7036311c9e29 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/getFieldNames.H +++ b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/getFieldNames.H @@ -42,7 +42,7 @@ forAll(Times, timeI) // Same for spray - IOobjectList sprayObjects(mesh, runTime.timeName(), "lagrangian"); + IOobjectList sprayObjects(mesh, runTime.timeName(), cloud::prefix); { wordList fieldNames(sprayObjects.names(scalarIOField::typeName)); forAll(fieldNames, fieldI) diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C b/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C index b32952e9bba9b7939a20edee337c84609078a7c3..6c7e23ebaef33f6737fa31a2aa18e463d578ae8e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C @@ -44,21 +44,21 @@ Description int main(int argc, char *argv[]) { const label nTypes = 4; - const word fieldTypes[] = - { - "volScalarField", - "volVectorField", + const word fieldTypes[] = + { + "volScalarField", + "volVectorField", "surfaceScalarField", - "lagrangian" + cloud::prefix }; # include "setRootCase.H" - + # include "createTime.H" # include "createMesh.H" # include "readConversionProperties.H" - + // get the available time-steps instantList TimeList = runTime.times(); Info << TimeList << endl; @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) // Set Time runTime.setTime(TimeList[n], n); word CurTime = runTime.timeName(); - + IOobjectList objects(mesh, runTime.timeName()); # include "moveMesh.H" @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) // set the filename of the GMV file fileName gmvFileName = "plotGMV." + itoa(n); OFstream gmvFile(args.rootPath()/args.caseName()/gmvFileName); - + # include "gmvOutputHeader.H" # include "gmvOutput.H" # include "gmvOutputTail.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H index 76f834c431c063ee2d2e3908d1e8ae6c000c602d..03523ed2de769888547857e6e52898efc7a75d30 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H @@ -1,14 +1,14 @@ -for(label i=0; i < nTypes; i++) +for (label i=0; i < nTypes; i++) { wordList fieldNames = objects.names(fieldTypes[i]); - if ( fieldTypes[i] == "volScalarField" ) + if (fieldTypes[i] == "volScalarField") { gmvFile << "variable" << nl; } - for(label j=0; j < fieldNames.size(); j++) + for (label j=0; j < fieldNames.size(); j++) { - + word fieldName = fieldNames[j]; IOobject fieldObject @@ -19,8 +19,8 @@ for(label i=0; i < nTypes; i++) IOobject::MUST_READ, IOobject::NO_WRITE ); - - if ( fieldTypes[i] == "volScalarField" ) + + if (fieldTypes[i] == "volScalarField") { volScalarField gmvScalarField(fieldObject, mesh); gmvFile << fieldName << " 0" << nl; @@ -30,43 +30,43 @@ for(label i=0; i < nTypes; i++) } gmvFile << nl; } - - if ( fieldTypes[i] == "volVectorField" ) + + if (fieldTypes[i] == "volVectorField") { if (fieldName == vComp) { volVectorField gmvVectorField(fieldObject, mesh); gmvFile << "velocity 0" << nl; - for(label indx=0;indx<mesh.nCells();indx++) + for (label indx=0;indx<mesh.nCells();indx++) { gmvFile << gmvVectorField[indx].x() << " "; } - for(label indx=0;indx<mesh.nCells();indx++) + for (label indx=0;indx<mesh.nCells();indx++) { gmvFile << gmvVectorField[indx].y() << " "; } - for(label indx=0;indx<mesh.nCells();indx++) + for (label indx=0;indx<mesh.nCells();indx++) { gmvFile << gmvVectorField[indx].z() << " "; } gmvFile << nl; } } - - if ( fieldTypes[i] == "surfaceScalarField" ) + + if (fieldTypes[i] == "surfaceScalarField") { // ... } - + } - if ( fieldTypes[i] == "lagrangian") + if (fieldTypes[i] == cloud::prefix) { IOobject lagrangianHeader ( "positions", runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::NO_READ ); @@ -74,9 +74,9 @@ for(label i=0; i < nTypes; i++) if (lagrangianHeader.headerOk()) { Cloud<passiveParticle> particles(mesh); - - IOobjectList objects(mesh, runTime.timeName(), "lagrangian"); - + + IOobjectList objects(mesh, runTime.timeName(), cloud::prefix); + wordList lagrangianScalarNames = objects.names("scalarField"); wordList lagrangianVectorNames = objects.names("vectorField"); @@ -87,7 +87,7 @@ for(label i=0; i < nTypes; i++) } } - if ( fieldTypes[i] == "volScalarField" ) + if (fieldTypes[i] == "volScalarField") { gmvFile << "endvars" << nl; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H index 89c126c1e3ed50d4cbfb786483010bb95a6663f4..a99b94133ef4f31e7cdec776da9ff8ad554e6f96 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H @@ -42,7 +42,7 @@ forAll(lagrangianScalarNames, i) ( name, runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE @@ -73,7 +73,7 @@ forAll(lagrangianVectorNames, i) ( name, runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputSpray.H b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputSpray.H index f5d5b3c8c6da8716330c851c546e3092696128dd..3c4f629235aa0bd0dca08fb69793a397b0c076a1 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputSpray.H +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputSpray.H @@ -40,7 +40,7 @@ forAll(lagrangianScalarNames, i) ( name, runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index e03c76c05727a9f2ef596241372bb29c979e5eaa..2d5e7479906befdf04c420de5409f1db7c274328 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -225,8 +225,10 @@ labelList getSelectedPatches int main(int argc, char *argv[]) { -# include "addTimeOptions.H" + timeSelector::addOptions(); + # include "addRegionOption.H" + argList::validOptions.insert("fields", "fields"); argList::validOptions.insert("cellSet", "cellSet name"); argList::validOptions.insert("faceSet", "faceSet name"); @@ -244,7 +246,6 @@ int main(int argc, char *argv[]) # include "setRootCase.H" # include "createTime.H" - bool doWriteInternal = !args.options().found("noInternal"); bool doFaceZones = !args.options().found("noFaceZones"); bool doLinks = !args.options().found("noLinks"); @@ -312,14 +313,8 @@ int main(int argc, char *argv[]) } - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); - // Current mesh. # include "createNamedMesh.H" // VTK/ directory in the case @@ -359,11 +354,11 @@ int main(int argc, char *argv[]) // mesh wrapper; does subsetting and decomposition vtkMesh vMesh(mesh, cellSetName); - for (label timeI = startTime; timeI < endTime; timeI++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[timeI], timeI); + runTime.setTime(timeDirs[timeI], timeI); - Info<< "Time " << Times[timeI].name() << endl; + Info<< "Time: " << runTime.timeName() << endl; // Check for new polyMesh/ and update mesh, fvMeshSubset and cell // decomposition. @@ -914,7 +909,7 @@ int main(int argc, char *argv[]) ( readDir ( - runTime.timePath()/regionPrefix/"lagrangian", + runTime.timePath()/regionPrefix/cloud::prefix, fileName::DIRECTORY ) ); @@ -925,18 +920,18 @@ int main(int argc, char *argv[]) ( mesh, runTime.timeName(), - "lagrangian"/cloudDirs[i] + cloud::prefix/cloudDirs[i] ); IOobject* positionsPtr = sprayObjs.lookup("positions"); if (positionsPtr) { - mkDir(fvPath/"lagrangian"/cloudDirs[i]); + mkDir(fvPath/cloud::prefix/cloudDirs[i]); fileName lagrFileName ( - fvPath/"lagrangian"/cloudDirs[i]/cloudDirs[i] + fvPath/cloud::prefix/cloudDirs[i]/cloudDirs[i] + "_" + name(timeI) + ".vtk" ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.H index 8923ba8590d8108880fb2dc37ad98c249417216a..bd13ec2571a7622d70e0c243098c8104348b48bb 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.H @@ -39,6 +39,7 @@ SourceFiles #include "globalPointPatch.H" #include "OFstream.H" +#include "Cloud.H" #include "volFields.H" #include "pointFields.H" #include "vtkMesh.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriterTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriterTemplates.C index 37c8051383ad6870893b200f8bc7c86d850ba963..0407a58841ee0b481bfa4bb7581bea55104173ea 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriterTemplates.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriterTemplates.C @@ -41,7 +41,7 @@ void Foam::lagrangianWriter::writeIOField(const wordList& objects) ( object, vMesh_.mesh().time().timeName(), - "lagrangian"/cloudName_, + cloud::prefix/cloudName_, vMesh_.mesh(), IOobject::MUST_READ, IOobject::NO_WRITE, diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx b/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx index c824ec7e3c16aa0b1214a6282d623a57c480b658..47e919c9c310efda544786f239c8904977f4ee55 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx @@ -50,14 +50,15 @@ vtkPV3FoamReader::vtkPV3FoamReader() output0_ = NULL; +#ifdef VTKPV3FOAM_DUALPORT // Add second output for the Lagrangian this->SetNumberOfOutputPorts(2); - vtkMultiBlockDataSet *lagrangian; - lagrangian = vtkMultiBlockDataSet::New(); + vtkMultiBlockDataSet *lagrangian = vtkMultiBlockDataSet::New(); lagrangian->ReleaseData(); this->GetExecutive()->SetOutputData(1, lagrangian); lagrangian->Delete(); +#endif TimeStepRange[0] = 0; TimeStepRange[1] = 0; @@ -204,9 +205,9 @@ int vtkPV3FoamReader::RequestInformation ); } - double timeRange[2]; if (nTimeSteps) { + double timeRange[2]; timeRange[0] = timeSteps[0]; timeRange[1] = timeSteps[nTimeSteps-1]; @@ -273,46 +274,53 @@ int vtkPV3FoamReader::RequestData } } - // take port0 as the lead for other outputs - vtkInformation *outInfo = outputVector->GetInformationObject(0); + // Get the requested time step. + // We only support requests for a single time step + int nRequestTime = 0; + double requestTime[nInfo]; - vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast - ( - outInfo->Get + // taking port0 as the lead for other outputs would be nice, but fails when + // a filter is added - we need to check everything + // but since PREVIOUS_UPDATE_TIME_STEPS() is protected, relay the logic + // to the vtkPV3Foam::setTime() method + for (int infoI = 0; infoI < nInfo; ++infoI) + { + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + if ( - vtkMultiBlockDataSet::DATA_OBJECT() + outInfo->Has + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ) + && outInfo->Length + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ) >= 1 ) - ); + { + requestTime[nRequestTime++] = outInfo->Get + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + )[0]; + } + } + + if (nRequestTime) + { + foamData_->setTime(nRequestTime, requestTime); + } - vtkMultiBlockDataSet* lagrangianOutput = vtkMultiBlockDataSet::SafeDownCast + vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast ( - outputVector->GetInformationObject(1)->Get + outputVector->GetInformationObject(0)->Get ( vtkMultiBlockDataSet::DATA_OBJECT() ) ); - if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS())) - { - // Get the requested time step. - // We only support requests for a single time step - int nRequestedTimeSteps = outInfo->Length - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() - ); - if (nRequestedTimeSteps >= 1) - { - double *requestedTimeSteps = outInfo->Get - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() - ); - - foamData_->setTime(requestedTimeSteps[0]); - } - } - if (Foam::vtkPV3Foam::debug) { cout<< "update output with " @@ -361,7 +369,21 @@ int vtkPV3FoamReader::RequestData #else - foamData_->Update(output, lagrangianOutput); +#ifdef VTKPV3FOAM_DUALPORT + foamData_->Update + ( + output, + vtkMultiBlockDataSet::SafeDownCast + ( + outputVector->GetInformationObject(1)->Get + ( + vtkMultiBlockDataSet::DATA_OBJECT() + ) + ); + ); +#else + foamData_->Update(output, output); +#endif if (ShowPatchNames) { diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C index 4c4016c364a378cc1edda61bcff4729fae463db2..118e99fc9101c2fd64a0cddae1c6a9e28c198008 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C @@ -90,12 +90,21 @@ void Foam::vtkPV3Foam::reduceMemory() -int Foam::vtkPV3Foam::setTime(const double& requestedTime) +int Foam::vtkPV3Foam::setTime(int nRequest, const double requestTimes[]) { if (debug) { - Info<< "<beg> Foam::vtkPV3Foam::setTime(" << requestedTime << ")" - << endl; + Info<< "<beg> Foam::vtkPV3Foam::setTime("; + for (int requestI = 0; requestI < nRequest; ++requestI) + { + if (requestI) + { + Info<< ", "; + } + + Info<< requestTimes[requestI]; + } + Info << ") - previousIndex = " << timeIndex_ << endl; } Time& runTime = dbPtr_(); @@ -103,12 +112,26 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime) // Get times list instantList Times = runTime.times(); - int nearestIndex = Time::findClosestTimeIndex(Times, requestedTime); + int nearestIndex = timeIndex_; + + for (int requestI = 0; requestI < nRequest; ++requestI) + { + int index = Time::findClosestTimeIndex(Times, requestTimes[requestI]); + + if (index >= 0 && index != timeIndex_) + { + nearestIndex = index; + break; + } + } + + if (nearestIndex < 0) { nearestIndex = 0; } + // see what has changed if (timeIndex_ != nearestIndex) { @@ -138,10 +161,11 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime) if (debug) { - Info<< "<end> Foam::vtkPV3Foam::setTime() - selected time " - << Times[nearestIndex].name() << " index=" << nearestIndex - << " meshChanged=" << meshChanged_ - << " fieldsChanged=" << fieldsChanged_ << endl; + Info<< "<end> Foam::vtkPV3Foam::setTime() - selectedTime=" + << Times[nearestIndex].name() << " index=" << timeIndex_ + << "/" << Times.size() + << " meshChanged=" << Switch(meshChanged_) + << " fieldsChanged=" << Switch(fieldsChanged_) << endl; } return nearestIndex; @@ -441,7 +465,6 @@ void Foam::vtkPV3Foam::Update cout<< "<beg> Foam::vtkPV3Foam::Update - output with " << output->GetNumberOfBlocks() << " and " << lagrangianOutput->GetNumberOfBlocks() << " blocks\n"; - output->Print(cout); lagrangianOutput->Print(cout); printMemory(); @@ -480,8 +503,10 @@ void Foam::vtkPV3Foam::Update reader_->UpdateProgress(0.7); } +#ifdef VTKPV3FOAM_DUALPORT // restart port1 at block=0 blockNo = 0; +#endif convertMeshLagrangian(lagrangianOutput, blockNo); reader_->UpdateProgress(0.8); diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H index 927415c005aa5e32e32021dcdec6a00dea5ae064..4e203eacec8e83c9f720257c21870c039a9ef5a4 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H @@ -58,6 +58,11 @@ SourceFiles #ifndef vtkPV3Foam_H #define vtkPV3Foam_H +// do not include legacy strstream headers +#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS +# define VTK_EXCLUDE_STRSTREAM_HEADERS +#endif + #include "className.H" #include "fileName.H" #include "stringList.H" @@ -66,6 +71,8 @@ SourceFiles #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" +#undef VTKPV3FOAM_DUALPORT + // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // class vtkDataArraySelection; @@ -128,6 +135,7 @@ class vtkPV3Foam return block_; } + //- Assign block number, return previous value int block(int blockNo) { int prev = block_; @@ -713,9 +721,11 @@ public: //- Remove patch names from the display void removePatchNames(vtkRenderer* renderer); - //- set the runTime to the requested time, returns the timeIndex - // sets to "constant" on error and returns -1 - int setTime(const double& requestedTime); + //- set the runTime to the first plausible request time, + // returns the timeIndex + // sets to "constant" on error + int setTime(int count, const double requestTimes[]); + //- The current time index int timeIndex() const diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C index 9708df9ac149721624d5f9fb60fccc7f4edc94d8..38cc52f68047303136cd08d02e15c3ded723bcc7 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamFields.C @@ -266,7 +266,7 @@ void Foam::vtkPV3Foam::convertLagrangianFields ( mesh, dbPtr_().timeName(), - "lagrangian"/cloudName + cloud::prefix/cloudName ); pruneObjectList(objects, selectedFields); diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamLagrangianFields.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamLagrangianFields.H index ade6112e61de1e5fe706ea99553bce50da8aa902..58422d69f49eb4a78b1db291d32df7a7596f6783 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamLagrangianFields.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamLagrangianFields.H @@ -30,6 +30,8 @@ InClass #ifndef vtkPV3FoamLagrangianFields_H #define vtkPV3FoamLagrangianFields_H +#include "Cloud.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template<class Type> diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C index bfcffeb7876843f36971e0139382b11652452362..07d322d54250876e929526d46274ecf8e3bece92 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamMeshLagrangian.C @@ -53,7 +53,7 @@ vtkPolyData* Foam::vtkPV3Foam::lagrangianVTKMesh if (debug) { Info<< "<beg> Foam::vtkPV3Foam::lagrangianVTKMesh - timePath " - << mesh.time().timePath()/"lagrangian"/cloudName << endl; + << mesh.time().timePath()/cloud::prefix/cloudName << endl; printMemory(); } @@ -63,7 +63,7 @@ vtkPolyData* Foam::vtkPV3Foam::lagrangianVTKMesh ( mesh, mesh.time().timeName(), - "lagrangian"/cloudName + cloud::prefix/cloudName ); IOobject* positionsPtr = sprayObjs.lookup("positions"); diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C index e587c0cb1f8d56f3be89fa53120a4b8a289c0885..310a12efdf61fbff11d204c762dd8997d6bfdef0 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfo.C @@ -34,6 +34,7 @@ License #include "IOPtrList.H" #include "polyBoundaryMeshEntries.H" #include "entry.H" +#include "Cloud.H" #include "vtkPV3FoamReader.h" // local headers @@ -148,16 +149,16 @@ void Foam::vtkPV3Foam::updateInfoLagrangian() if (debug) { Info<< "<beg> Foam::vtkPV3Foam::updateInfoLagrangian" << nl - << " " << dbPtr_->timePath()/"lagrangian" << endl; + << " " << dbPtr_->timePath()/cloud::prefix << endl; } // use the db directly since this might be called without a mesh, // but the region must get added back in - fileName lagrangianPrefix("lagrangian"); + fileName lagrangianPrefix(cloud::prefix); if (meshRegion_ != polyMesh::defaultRegion) { - lagrangianPrefix = meshRegion_/"lagrangian"; + lagrangianPrefix = meshRegion_/cloud::prefix; } // Search for list of lagrangian objects for this time @@ -463,10 +464,10 @@ void Foam::vtkPV3Foam::updateInfoLagrangianFields() // use the db directly since this might be called without a mesh, // but the region must get added back in - fileName lagrangianPrefix("lagrangian"); + fileName lagrangianPrefix(cloud::prefix); if (meshRegion_ != polyMesh::defaultRegion) { - lagrangianPrefix = meshRegion_/"lagrangian"; + lagrangianPrefix = meshRegion_/cloud::prefix; } IOobjectList objects diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H index 8ef698872d37b2b0046886abaa76fd1e773e378e..7e28460a465c74ffb690359aff588df63accc756 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H @@ -40,7 +40,10 @@ void Foam::vtkPV3Foam::updateInfoFields { if (debug) { - Info<< "<beg> Foam::vtkPV3Foam::updateInfoFields" << endl; + Info<< "<beg> Foam::vtkPV3Foam::updateInfoFields <" + << meshType::Mesh::typeName + << "> [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" + << endl; } stringList enabledEntries; diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H index a7cfc94e2c03ce4e1b89a48d609dcbd5896e2d06..4925a31284242e6f792bc949943cb5189f2d0e03 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamVolFields.H @@ -326,10 +326,10 @@ void Foam::vtkPV3Foam::convertVolField const labelList& superCells = decompInfo.superCells(); vtkFloatArray* celldata = vtkFloatArray::New(); - celldata->SetNumberOfTuples( superCells.size() ); - celldata->SetNumberOfComponents( nComp ); - celldata->Allocate( nComp*superCells.size() ); - celldata->SetName( tf.name().c_str() ); + celldata->SetNumberOfTuples(superCells.size()); + celldata->SetNumberOfComponents(nComp); + celldata->Allocate(nComp*superCells.size()); + celldata->SetName(tf.name().c_str()); if (debug) { diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_gold_part_build_info.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_gold_part_build_info.H index 70d5c9f2a74bc11c1069b9e743e9caf67218a539..ca8da4727c38987c580690e034236a4d09e60054 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_gold_part_build_info.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_get_gold_part_build_info.H @@ -35,7 +35,7 @@ int USERD_get_gold_part_build_info for(label i=0; i<nPatches; i++) { word patchName(meshPtr->boundary()[i].name()); - strncpy(part_descriptions[i+1], patchName.c_str(), Z_BUFL); + strncpy(part_descriptions[i+1], patchName.c_str(), Z_BUFL); } label nHex08 = 0; @@ -101,7 +101,7 @@ int USERD_get_gold_part_build_info */ number_of_nodes[0] = meshPtr->nPoints(); - + const polyBoundaryMesh& bMesh = meshPtr->boundaryMesh(); for(label i=0; i<nPatches; i++) @@ -137,7 +137,12 @@ int USERD_get_gold_part_build_info if (Numparts_available > nPatches+1) { - strncpy(part_descriptions[nPatches+1], sprayName.c_str(), Z_BUFL); + strncpy + ( + part_descriptions[nPatches+1], + cloud::prefix.c_str(), + Z_BUFL + ); number_of_elements[nPatches+1][Z_POINT] = sprayPtr->size(); number_of_nodes[nPatches+1] = sprayPtr->size(); } diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H index 90f2d3f415ab396b48720e58f20c9bb4f9f2b7ac..83303fef717fdea9600e8e7331f3270d5cbce984 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H @@ -164,7 +164,7 @@ int USERD_set_filenames ( "positions", runTime.timeName(), - "lagrangian", + cloud::prefix, runTime, IOobject::NO_READ, IOobject::NO_WRITE, @@ -179,7 +179,7 @@ int USERD_set_filenames sprayPtr = new Cloud<passiveParticle>(*meshPtr); - IOobjectList objects(*meshPtr, runTime.timeName(), "lagrangian"); + IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix); lagrangianScalarNames = (const wordList&)objects.names(sprayScalarFieldName); diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianScalar.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianScalar.H index e9259e3cc78693babd080d7e841b55ab9867e096..39ccf6c07f288b2003285d8baedf5adde265e15f 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianScalar.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianScalar.H @@ -12,7 +12,7 @@ if (nVar >= 0) ( name, runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianVector.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianVector.H index 42fcc8560fd7067df52e8ee65832a8069028b7e3..80c71ba028062eebb8eeabb88e9607cf19e3d6b7 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianVector.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/getLagrangianVector.H @@ -14,7 +14,7 @@ if (nVar >= 0) ( name, runTime.timeName(), - "lagrangian", + cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE diff --git a/applications/utilities/postProcessing/graphics/ensightFoamReader/globalFoam.H b/applications/utilities/postProcessing/graphics/ensightFoamReader/globalFoam.H index 4606671860b8907e539a424f889b7b60e47f3293..d68861b138e6cb79159d94767c0206769c2baa5c 100644 --- a/applications/utilities/postProcessing/graphics/ensightFoamReader/globalFoam.H +++ b/applications/utilities/postProcessing/graphics/ensightFoamReader/globalFoam.H @@ -32,7 +32,6 @@ static bool isSpray[maxNames]; static word scalarName = "volScalarField"; static word vectorName = "volVectorField"; static word tensorName = "volTensorField"; -static word sprayName = "lagrangian"; static word sprayScalarFieldName = "scalarField"; static word sprayVectorFieldName = "vectorField"; static word sprayTensorFieldName = "tensorField"; diff --git a/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C b/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C index 34ebbc75dcab101e2d95655ba63dc0a3002b0de0..65356b382b26678e2db9db3a7d3ce511ce61972f 100644 --- a/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C +++ b/applications/utilities/postProcessing/miscellaneous/engineCompRatio/engineCompRatio.C @@ -40,57 +40,50 @@ Description int main(int argc, char *argv[]) { + #include "setRootCase.H" + #include "createEngineTime.H" + #include "createEngineMesh.H" -# include "setRootCase.H" -# include "createEngineTime.H" -# include "createEngineMesh.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // scalar eps = 1.0e-10; scalar fullCycle = 360.0; scalar ca0 = -180.0; scalar ca1 = 0.0; - scalar ca = runTime.theta(); - while (ca > ca0) + while (runTime.theta() > ca0) { ca0 += fullCycle; ca1 += fullCycle; } - if (mag(ca - ca0) > eps) + while (mag(runTime.theta() - ca0) > eps) { - while(mag(ca - ca0) > eps) - { - ca = runTime.theta(); - scalar t0 = runTime.userTimeToTime(ca0 - ca); - runTime.setDeltaT(t0); - runTime++; - Info << "CA = " << ca << endl; - mesh.move(); - } + scalar t0 = runTime.userTimeToTime(ca0 - runTime.theta()); + runTime.setDeltaT(t0); + runTime++; + Info<< "CA = " << runTime.theta() << endl; + mesh.move(); } scalar Vmax = sum(mesh.V().field()); - while(mag(ca-ca1) > eps) + while (mag(runTime.theta()-ca1) > eps) { - ca = runTime.theta(); - scalar t1 = runTime.userTimeToTime(ca1-ca); + scalar t1 = runTime.userTimeToTime(ca1-runTime.theta()); runTime.setDeltaT(t1); runTime++; - Info << "CA = " << runTime.theta() << endl; + Info<< "CA = " << runTime.theta() << endl; mesh.move(); } scalar Vmin = sum(mesh.V().field()); - Info << "\nVmax = " << Vmax; - Info << ", Vmin = " << Vmin << endl; - Info << "Vmax/Vmin = " << Vmax/Vmin << endl; - Info << "\n end\n"; + Info<< "\nVmax = " << Vmax; + Info<< ", Vmin = " << Vmin << endl; + Info<< "Vmax/Vmin = " << Vmax/Vmin << endl; + Info<< "\nEnd" << endl; return 0; } diff --git a/applications/utilities/postProcessing/miscellaneous/ptot/ptot.C b/applications/utilities/postProcessing/miscellaneous/ptot/ptot.C index bb41fb60d46bfaf18ba6fa32bbe5c5d13f310bc2..26d66de83e85c048d5cc96fca511ab896d873c53 100644 --- a/applications/utilities/postProcessing/miscellaneous/ptot/ptot.C +++ b/applications/utilities/postProcessing/miscellaneous/ptot/ptot.C @@ -36,25 +36,18 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/postProcessing/miscellaneous/wdot/wdot.C b/applications/utilities/postProcessing/miscellaneous/wdot/wdot.C index 79f23de3e790b0818cd45de8a847dc59d951f736..81a0c469794f1c7121e65cc79aa8088cd2519522 100644 --- a/applications/utilities/postProcessing/miscellaneous/wdot/wdot.C +++ b/applications/utilities/postProcessing/miscellaneous/wdot/wdot.C @@ -37,25 +37,18 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); mesh.readUpdate(); diff --git a/applications/utilities/postProcessing/miscellaneous/writeCellCentres/writeCellCentres.C b/applications/utilities/postProcessing/miscellaneous/writeCellCentres/writeCellCentres.C index f420edf6adad10881efc55f0954a7eb4340fbaa2..bc26ec509fbe6cc9a8dca2792aeef1373c2dccce 100644 --- a/applications/utilities/postProcessing/miscellaneous/writeCellCentres/writeCellCentres.C +++ b/applications/utilities/postProcessing/miscellaneous/writeCellCentres/writeCellCentres.C @@ -29,6 +29,8 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "timeSelector.H" +#include "Time.H" #include "fvMesh.H" #include "vectorIOField.H" #include "volFields.H" @@ -41,23 +43,18 @@ using namespace Foam; int main(int argc, char *argv[]) { -# include "addTimeOptions.H" + timeSelector::addOptions(); + # include "setRootCase.H" # include "createTime.H" - - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; @@ -77,10 +74,10 @@ int main(int argc, char *argv[]) mesh.C() ); - //Info<< "Writing cellCentre positions to " << cc.name() << " in " - // << runTime.timeName() << endl; + // Info<< "Writing cellCentre positions to " << cc.name() << " in " + // << runTime.timeName() << endl; // - //cc.write(); + // cc.write(); Info<< "Writing components of cellCentre positions to volScalarFields" << " ccx, ccy, ccz in " << runTime.timeName() << endl; @@ -104,7 +101,7 @@ int main(int argc, char *argv[]) } } - Info << nl << "End" << endl; + Info<< "\nEnd" << endl; return 0; } diff --git a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C index 6e9ee2f228690de91729390ff9ab93eb500ce6cd..18ba96c4f1919cdb9687d53b7109755f6203fb37 100644 --- a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C +++ b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C @@ -39,10 +39,12 @@ using namespace Foam; int main(int argc, char *argv[]) { timeSelector::addOptions(); +# include "addRegionOption.H" + # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); -# include "createMesh.H" +# include "createNamedMesh.H" IOprobes sniff ( diff --git a/applications/utilities/postProcessing/sampling/sample/Make/options b/applications/utilities/postProcessing/sampling/sample/Make/options index 04b22c08a43668605ad1f5dab7bc06f0a962e058..ae583f3388ec7ea9040a7e6cb68db67748cd5c53 100644 --- a/applications/utilities/postProcessing/sampling/sample/Make/options +++ b/applications/utilities/postProcessing/sampling/sample/Make/options @@ -2,6 +2,7 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude @@ -9,5 +10,6 @@ EXE_LIBS = \ -lfiniteVolume \ -lmeshTools \ -lsampling \ + -lsurfMesh \ -ltriSurface \ -llagrangian diff --git a/applications/utilities/postProcessing/sampling/sample/sample.C b/applications/utilities/postProcessing/sampling/sample/sample.C index 2735ed2dff0d1b07162d4ef36e8a8e52e869fce0..2451522ffe5d2a9f08e72e3fe882eebaade5bb82 100644 --- a/applications/utilities/postProcessing/sampling/sample/sample.C +++ b/applications/utilities/postProcessing/sampling/sample/sample.C @@ -40,6 +40,7 @@ Description - dx : DX scalar or vector format - vtk : VTK ascii format - raw : x y z value format for use with e.g. gnuplot 'splot'. + - obj : Wavefron stl. Does not contain values! - stl : ascii stl. Does not contain values! @param interpolationScheme : interpolation scheme, choice of \n diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 215add79a79ed840f9959e7e88e3076c0efae065..559eb2843678da0a0ea06eec30c154c6a82957b7 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -30,7 +30,10 @@ setFormat raw; // dx : DX scalar or vector format // vtk : VTK ascii format // raw : x y z value format for use with e.g. gnuplot 'splot'. -// stl : ascii stl. Does not contain values! +// +// Note: +// other formats such as obj, stl, etc can also be written (by proxy) +// but without any values! surfaceFormat vtk; // interpolationScheme. choice of diff --git a/applications/utilities/postProcessing/scalarField/pPrime2/pPrime2.C b/applications/utilities/postProcessing/scalarField/pPrime2/pPrime2.C index 6729389218f5ab7d2183eb622e8569451e8cf6bb..54a7b53c461a55f77fc3a8d698bb89dce87aeac4 100644 --- a/applications/utilities/postProcessing/scalarField/pPrime2/pPrime2.C +++ b/applications/utilities/postProcessing/scalarField/pPrime2/pPrime2.C @@ -38,23 +38,16 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - runTime.setTime(Times[endTime-1], endTime-1); + runTime.setTime(timeDirs[timeDirs.size()-1], timeDirs.size()-1); volScalarField pMean ( @@ -68,9 +61,9 @@ int main(int argc, char *argv[]) mesh ); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/postProcessing/stressField/stressComponents/stressComponents.C b/applications/utilities/postProcessing/stressField/stressComponents/stressComponents.C index 2c481b89278566272af3de09f3b39e69fba0db47..aa26a0e0c08e2a2bce2216314e1bc1f910233934 100644 --- a/applications/utilities/postProcessing/stressField/stressComponents/stressComponents.C +++ b/applications/utilities/postProcessing/stressField/stressComponents/stressComponents.C @@ -35,30 +35,22 @@ Description #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H" #include "zeroGradientFvPatchFields.H" - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/postProcessing/turbulence/createTurbulenceFields/createTurbulenceFields.C b/applications/utilities/postProcessing/turbulence/createTurbulenceFields/createTurbulenceFields.C index 5e15aff046e3b2e56a336d465d86072a8268ba15..c4a556f21fbdab829a0ca36c649b92cb6cb0c60c 100644 --- a/applications/utilities/postProcessing/turbulence/createTurbulenceFields/createTurbulenceFields.C +++ b/applications/utilities/postProcessing/turbulence/createTurbulenceFields/createTurbulenceFields.C @@ -42,24 +42,19 @@ Source files: int main(int argc, char *argv[]) { - #include "addTimeOptions.H" + timeSelector::addOptions(); + #include "setRootCase.H" #include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options - #include "checkTimeOptions.H" + instantList timeDirs = timeSelector::select0(runTime, args); - runTime.setTime(Times[startTime], startTime); #include "createMesh.H" - #include "createFields.H" - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< "Time = " << runTime.timeName() << endl; diff --git a/applications/utilities/postProcessing/velocityField/streamFunction/streamFunction.C b/applications/utilities/postProcessing/velocityField/streamFunction/streamFunction.C index 98c044ca3e16d7685174a57fb20e69e21b493598..68d4c8d6980891bb15dd73206a01a82c2e47804f 100644 --- a/applications/utilities/postProcessing/velocityField/streamFunction/streamFunction.C +++ b/applications/utilities/postProcessing/velocityField/streamFunction/streamFunction.C @@ -26,7 +26,7 @@ Application streamFunction Description - Calculates and writes the stream function of velocity field U at each time + Calculates and writes the stream function of velocity field U at each time \*---------------------------------------------------------------------------*/ @@ -42,27 +42,20 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - - // set startTime and endTime depending on -time and -latestTime options -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMeshNoClear.H" pointMesh pMesh(mesh); - for (label i=startTime; i<endTime; i++) + forAll(timeDirs, timeI) { - runTime.setTime(Times[i], i); + runTime.setTime(timeDirs[timeI], timeI); Info<< nl << "Time: " << runTime.timeName() << endl; diff --git a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H index 830d6d825defb5854368ea2328791a17450438dd..176a25f0f7668f00cd3f71bd4260a704fdc3ebd3 100644 --- a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H +++ b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H @@ -34,6 +34,7 @@ Description #ifndef MapLagrangianFields_H #define MapLagrangianFields_H +#include "cloud.H" #include "GeometricField.H" #include "meshToMesh.H" #include "IOobjectList.H" @@ -60,8 +61,7 @@ void MapLagrangianFields forAllIter(IOobjectList, fields, fieldIter) { - Info<< " mapping lagrangian field " - << fieldIter()->name() << endl; + Info<< " mapping lagrangian field " << fieldIter()->name() << endl; // Read field (does not need mesh) IOField<Type> fieldSource(*fieldIter()); @@ -73,7 +73,7 @@ void MapLagrangianFields ( fieldIter()->name(), meshTarget.time().timeName(), - "lagrangian"/cloudName, + cloud::prefix/cloudName, meshTarget, IOobject::NO_READ, IOobject::NO_WRITE, diff --git a/applications/utilities/preProcessing/mapFields/mapLagrangian.C b/applications/utilities/preProcessing/mapFields/mapLagrangian.C index e57aa9761c81370d6d20ab1dd8af1c00a53cb8c8..9d04dcfbecc82c6c39f71ea501575aacff67304f 100644 --- a/applications/utilities/preProcessing/mapFields/mapLagrangian.C +++ b/applications/utilities/preProcessing/mapFields/mapLagrangian.C @@ -94,7 +94,7 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp) ( readDir ( - meshSource.time().timePath()/"lagrangian", + meshSource.time().timePath()/cloud::prefix, fileName::DIRECTORY ) ); @@ -106,7 +106,7 @@ void mapLagrangian(const meshToMesh& meshToMeshInterp) ( meshSource, meshSource.time().timeName(), - "lagrangian"/cloudDirs[cloudI] + cloud::prefix/cloudDirs[cloudI] ); IOobject* positionsPtr = objects.lookup("positions"); diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C index ccd85d8e5a07731dff79d6449f5f4f1c4c2c819c..f245e4088bcb300b122f19e5ec5a6ddf2ceb97d9 100644 --- a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C +++ b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C @@ -271,13 +271,57 @@ int main(int argc, char *argv[]) args.caseName() ); + // start with "constant" + runTime.setTime(instant(0, runTime.constant()), 0); + + Info<< "runTime.instance() = " << runTime.instance() << endl; + Info<< "runTime.timeName() = " << runTime.timeName() << endl; + + + Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh" + << endl; + surf.write + ( + runTime, + "yetAnother" + ); + + surfMesh surfIn + ( + IOobject + ( + "default", + runTime.timeName(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + + + MeshedSurface<face> surfIn2(runTime, "foobar"); + + Info<<"surfIn2 = " << surfIn2.size() << endl; + + Info<< "surfIn = " << surfIn.size() << endl; + + + Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl; + surfIn.write("oldSurfIn.obj"); + + + Info<< "runTime.instance() = " << runTime.instance() << endl; + surfMesh surfOut ( IOobject ( "mySurf", runTime.instance(), - runTime + runTime, + IOobject::NO_READ, + IOobject::NO_WRITE, + false ), surf.xfer() ); @@ -299,6 +343,25 @@ int main(int argc, char *argv[]) dimless ); + Info<<" surf name= " << surfOut.name() <<nl; + Info<< "rename to anotherSurf" << endl; + surfOut.rename("anotherSurf"); + + Info<<" surf name= " << surfOut.name() <<nl; + + // advance time to 1 + runTime.setTime(instant(1), 1); + surfOut.setInstance(runTime.timeName()); + + + + Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl; + surfOut.write(); + + // write directly + surfOut.write("someName.ofs"); + +#if 1 const surfZoneList& zones = surfOut.surfZones(); forAll(zones, zoneI) { @@ -318,9 +381,10 @@ int main(int argc, char *argv[]) ( IOobject ( - "pointIds", + "zoneIds.", +// "pointIds", surfOut.instance(), - "pointFields", +// "pointFields", surfOut, IOobject::NO_READ, IOobject::NO_WRITE @@ -337,6 +401,10 @@ int main(int argc, char *argv[]) Info<< "write pointIds (for testing only): " << pointIds.objectPath() << endl; pointIds.write(); + + Info<<"surfMesh with these names: " << surfOut.names() << endl; + +#endif } } diff --git a/etc/bashrc b/etc/bashrc index e9f9c6f9cf8a3bfcd1d7adf87a765f8f948ebc08..ce10b39e78f5a061f317dcdd27d7a4a68d6ba3e7 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -77,12 +77,6 @@ export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty -# Operating System/Platform from Unix or MSWindows -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# WM_OS = Unix | MSWindows -: ${WM_OS:=Unix}; export WM_OS - - # Compiler: set to Gcc, Gcc43 or Icc (for Intel's icc) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : ${WM_COMPILER:=Gcc}; export WM_COMPILER @@ -105,7 +99,7 @@ export WM_COMPILER_LIB_ARCH= # WM_JAVAC_OPTION = Opt | Debug : ${WM_JAVAC_OPTION:=Opt}; export WM_JAVAC_OPTION -# WM_MPLIB = | OPENMPI | LAM | MPICH | MPICH-GM | HPMPI | GAMMA | MPI +# WM_MPLIB = | OPENMPI | LAM | MPICH | MPICH-GM | HPMPI | GAMMA | MPI | QSMPI : ${WM_MPLIB:=OPENMPI}; export WM_MPLIB diff --git a/etc/controlDict b/etc/controlDict index b58b605b3c58e9a7a7c60a3e041bd998946d3262..5cbe331fe591645ef53c22cab6b50f499a53427a 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -34,6 +34,7 @@ Documentation DebugSwitches { + Analytical 0; APIdiffCoefFunc 0; Ar 0; BICCG 0; @@ -57,18 +58,25 @@ DebugSwitches C8H18 0; C9H20 0; CH3OH 0; - CallbackRegistry 0; + CH4N2O 0; CarnahanStarling 0; + CallbackRegistry 0; + CentredFitData<biLinearFitPolynomial> 0; + CentredFitData<linearFitPolynomial> 0; + CentredFitData<quadraticFitPolynomial> 0; + CentredFitData<quadraticLinearFitPolynomial> 0; ChomiakInjector 0; + Cloud<basicKinematicParcel> 0; + Cloud<basicReactingParcel> 0; + Cloud<basicThermoParcel> 0; Cloud<indexedParticle> 0; - Cloud<kinematicParcel> 0; Cloud<parcel> 0; Cloud<passiveParticle> 0; - Cloud<reactingParcel> 0; - Cloud<thermoParcel> 0; Cloud<trackedParticle> 0; CoEuler 0; CompositionModel 0; + ConeInjection 0; + Constant 0; ConstantRateDevolatilisation 0; CrankNicholson 0; CrossPowerLaw 0; @@ -77,6 +85,7 @@ DebugSwitches DICGaussSeidel 0; DILU 0; DILUGaussSeidel 0; + DataEntry 0; DeardorffDiffStress 0; DispersionModel 0; DispersionRASModel 0; @@ -107,39 +116,40 @@ DebugSwitches H2O 0; HashTable 0; HeatTransferModel 0; + HerschelBulkley 0; HrenyaSinclair 0; IC8H18 0; ICCG 0; + IDDESDelta 0; IDEA 0; IFstream 0; + IOMap<dictionary> 0; IOPtrList<MRFZone> 0; IOPtrList<coordinateSystem> 0; IOPtrList<injector> 0; IOPtrList<porousZone> 0; IOobject 0; InjectionModel 0; + IntegrationScheme 0; JohnsonJackson 0; KRR4 0; - KinematicCloud<kinematicParcel> 0; - KinematicCloud<reactingParcel> 0; - KinematicCloud<thermoParcel> 0; - KinematicParcel<reactingParcel> 0; - KinematicParcel<thermoParcel> 0; + KinematicCloud<basicKinematicParcel> 0; + KinematicCloud<basicReactingParcel> 0; + KinematicCloud<basicThermoParcel> 0; + KinematicParcel<basicReactingParcel> 0; + KinematicParcel<basicThermoParcel> 0; + LESModel 0; LESdelta 0; LESfilter 0; - LESmodel 0; LISA 0; LRR 0; LRRDiffStress 0; LamBremhorstKE 0; LaunderGibsonRSTM 0; LaunderSharmaKE 0; - LduMatrix 1; LienCubicKE 0; LienCubicKELowRe 0; LienLeschzinerLowRe 0; - Lun 0; - LunSavage 0; MB 0; MC 0; MCV 0; @@ -191,11 +201,12 @@ DebugSwitches QUICK 0; QUICKV 0; QZeta 0; + RASModel 0; RK 0; RNGkEpsilon 0; RanzMarshall 0; - ReactingCloud<reactingParcel> 0; - ReactingParcel<reactingParcel> 0; + ReactingCloud<basicReactingParcel> 0; + ReactingParcel<basicReactingParcel> 0; Rebound 0; ReitzDiwakar 0; ReitzKHRT 0; @@ -208,6 +219,8 @@ DebugSwitches SIBS 0; SKA 0; SLTS 0; + SRFModel 0; + SRFVelocity 0; STARCDRotation 0; Schaeffer 0; SchillerNaumann 0; @@ -215,8 +228,9 @@ DebugSwitches SingleKineticRateDevolatilisation 0; SingleMixtureFraction 0; Smagorinsky 0; - SmoothSolver 0; SpalartAllmaras 0; + SpalartAllmarasDDES 0; + SpalartAllmarasIDDES 0; SphereDrag 0; StandardWallInteraction 0; StaticHashTable 0; @@ -228,13 +242,17 @@ DebugSwitches SyamlalOBrien 0; SyamlalRogersOBrien 0; TAB 0; - ThermoCloud<reactingParcel> 0; - ThermoCloud<thermoParcel> 0; - ThermoParcel<reactingParcel> 0; - ThermoParcel<thermoParcel> 0; + Table 0; + ThermoCloud<basicReactingParcel> 0; + ThermoCloud<basicThermoParcel> 0; + ThermoParcel<basicReactingParcel> 0; + ThermoParcel<basicThermoParcel> 0; UMIST 0; UMISTV 0; Unix 0; + UpwindFitData<cubicUpwindFitPolynomial> 0; + UpwindFitData<quadraticLinearUpwindFitPolynomial> 0; + UpwindFitData<quadraticUpwindFitPolynomial> 0; WallInteractionModel 0; WenYu 0; aC11H10 0; @@ -245,6 +263,9 @@ DebugSwitches addPoint 0; advective 0; algebraicPair 0; + alphaContactAngle 0; + alphaFixedPressure 0; + alphatWallFunction 0; angularOscillatingDisplacement 0; angularOscillatingVelocity 0; anisotropic 0; @@ -252,14 +273,21 @@ DebugSwitches atomizationModel 0; attachDetach 0; autoHexMeshDriver 0; + autoLayerDriver 0; + autoRefineDriver 0; + autoSnapDriver 0; bC11H10 0; backward 0; basePatch 0; basicKinematicCloud 0; + basicKinematicParcel 0; basicMixture 0; basicReactingCloud 0; + basicReactingParcel 0; basicThermo 0; basicThermoCloud 0; + basicThermoParcel 0; + biLinearFit 0; binaryAbsorptionEmission 0; blended 0; blobsSheetAtomization 0; @@ -274,7 +302,6 @@ DebugSwitches boxToPoint 0; breakupModel 0; calculated 0; - cartesian 0; cell 0; cellClassification 0; cellCuts 0; @@ -292,6 +319,8 @@ DebugSwitches cellToFace 0; cellToPoint 0; cellZone 0; + centredCECStencil 0; + centredCFCStencil 0; chemistryReader 0; chemistrySolver 0; chemkinReader 0; @@ -304,24 +333,25 @@ DebugSwitches commSchedule 0; commonRailInjector 0; compound 0; - conductivityModel 0; constInjector 0; constant 0; constantAbsorptionEmission 0; - constantGammaContactAngle 0; + constantAlphaContactAngle 0; constantScatter 0; coordinateRotation 0; coordinateSystem 0; + coordinateSystems 0; corrected 0; coupled 0; cubeRootVol 0; cubic 0; + cubicUpwindFit 0; curve 0; cyclic 0; cyclicLduInterface 0; cyclicLduInterfaceField 0; + cylinderToCell 0; cylindrical 0; - dataSchedule 0; decompositionMethod 0; definedHollowConeInjector 0; definedInjector 0; @@ -332,6 +362,7 @@ DebugSwitches dimensionSet 1; directMapped 0; directMappedPatch 0; + directMappedVelocityFlux 0; directionMixed 0; directional 0; disallowDefaultFvsPatchField 0; @@ -345,6 +376,7 @@ DebugSwitches displacementInterpolation 0; displacementLaplacian 0; displacementSBRStress 0; + distanceSurface 0; downwind 0; dragModel 0; duplicatePoints 0; @@ -352,8 +384,8 @@ DebugSwitches dynMixedSmagorinsky 0; dynOneEqEddy 0; dynSmagorinsky 0; + dynamicAlphaContactAngle 0; dynamicFvMesh 0; - dynamicGammaContactAngle 0; dynamicInkJetFvMesh 0; dynamicMotionSolverFvMesh 0; dynamicRefineFvMesh 0; @@ -363,6 +395,7 @@ DebugSwitches empty 0; engineMesh 0; enrichedPatch 0; + epsilonWallFunction 0; errorDrivenRefinement 0; evaporationModel 0; exponential 0; @@ -387,13 +420,20 @@ DebugSwitches filteredLinear 0; filteredLinear2 0; filteredLinear2V 0; + filteredLinear3 0; + filteredLinear3V 0; fixedEnthalpy 0; fixedFluxBuoyantPressure 0; + fixedFluxBoussinesqBuoyantPressure 0; fixedFluxPressure 0; fixedGradient 0; + fixedInternalEnergy 0; + fixedInternalValue 0; fixedNormalSlip 0; + fixedPressureCompressibleDensity 0; fixedUnburntEnthalpy 0; fixedValue 0; + flowRateInletVelocity 0; fluxCorrectedVelocity 0; foamChemistryReader 0; foamFile 0; @@ -416,8 +456,6 @@ DebugSwitches fvTensorMatrix 0; fvVectorMatrix 0; fvsPatchField 0; - gammaContactAngle 0; - gammaFixedPressure 0; general 0; generic 0; genericPatch 0; @@ -429,6 +467,7 @@ DebugSwitches gnuplot 0; gradientDispersionRAS 0; gradientEnthalpy 0; + gradientInternalEnergy 0; gradientUnburntEnthalpy 0; granularPressureModel 0; hCombustionThermo 0; @@ -459,25 +498,29 @@ DebugSwitches hhuMixtureThermo<veryInhomogeneousMixture<sutherlandTransport<specieThermo<janafThermo<perfectGas>>>>> 0; hierarchical 0; hollowConeInjector 0; + iC3H8O 0; indexedOctree 0; indexedParticle 0; injectorModel 0; injectorType 0; inletOutlet 0; inletOutletTotalTemperature 0; - inputMode 0; interfaceCompression 0; intersectedSurface 0; inverseDistance 0; inverseFaceDistance 0; inversePointDistance 0; inverseVolume 0; + isoSurface 0; + isoSurfaceCell 0; jplot 0; jumpCyclic 0; kEpsilon 0; + kOmega 0; kOmegaSST 0; + kOmegaSSTSAS 0; + kQRWallFunction 0; kinematicCloud 0; - kinematicParcel 0; labelField 0; labelList 0; labelListList 0; @@ -496,6 +539,7 @@ DebugSwitches leastSquares 0; leastSquaresVectors 0; level 2; + limitWith 0; limited 0; limitedCubic 0; limitedCubic01 0; @@ -510,6 +554,7 @@ DebugSwitches limitedSurfaceInterpolationScheme 0; limitedVanLeer 0; linear 0; + linearFit 0; linearUpwind 0; linearUpwindV 0; liquid 0; @@ -520,7 +565,6 @@ DebugSwitches localPointRegion 0; lowReOneEqEddy 0; manual 0; - massFlowRateInletVelocity 0; meshCutAndRemove 0; meshCutter 0; meshModifier 0; @@ -532,6 +576,7 @@ DebugSwitches midPointAndFace 0; mixed 0; mixedEnthalpy 0; + mixedInternalEnergy 0; mixedSmagorinsky 0; mixedUnburntEnthalpy 0; mixerFvMesh 0; @@ -544,22 +589,32 @@ DebugSwitches motionSolver 0; movingConeTopoFvMesh 0; movingWallVelocity 0; - muSgsWallFunction 0; + muSgsSpalartAllmarasWallFunction 0; multiDirRefinement 0; + multiHoleInjector 0; multivariateSelection 0; - mutStandardRoughWallFunction 0; + mutRoughWallFunction 0; + mutSpalartAllmarasStandardRoughWallFunction 0; + mutSpalartAllmarasStandardWallFunction 0; + mutSpalartAllmarasWallFunction 0; + mutWallFunction 0; + nC3H8O 0; nbrToCell 0; nearestToCell 0; + nearestToPoint 0; noAbsorptionEmission 0; noDragModel 0; noRadiation 0; none 0; normal 0; normalToFace 0; - nuSgsWallFunction 0; - nutStandardRoughWallFunction 0; - nutStandardWallFunction 0; + nuSgsSpalartAllmarasWallFunction 0; + nutRoughWallFunction 0; + nutSpalartAllmarasStandardRoughWallFunction 0; + nutSpalartAllmarasStandardWallFunction 0; + nutSpalartAllmarasWallFunction 0; nutWallFunction 0; + obj 0; objectRegistry 0; octree 0; octreeDataEdges 0; @@ -567,7 +622,7 @@ DebugSwitches octreeDataFaceList 0; octreeDataTriSurface 0; off 0; - offsetTriSurfaceMesh 0; + omegaWallFunction 0; oneEqEddy 0; orientedSurface 0; oscillatingDisplacement 0; @@ -609,11 +664,13 @@ DebugSwitches polyMeshInfo 0; polyTopoChange 0; polyTopoChanger 0; + powerLaw 0; pressureDirectedInletOutletVelocity 0; pressureDirectedInletVelocity 0; pressureInletOutletVelocity 0; pressureInletUniformVelocity 0; pressureInletVelocity 0; + pressureNormalInletOutletVelocity 0; pressureSwirlInjector 0; primitiveMesh 0; primitiveMeshGeometry 0; @@ -625,11 +682,13 @@ DebugSwitches pureMixture<sutherlandTransport<specieThermo<hConstThermo<perfectGas>>>> 0; pureMixture<sutherlandTransport<specieThermo<janafThermo<perfectGas>>>> 0; quadratic 0; - radialModel 0; + quadraticFit 0; + quadraticLinearFit 0; + quadraticLinearUpwindFit 0; + quadraticUpwindFit 0; radiationModel 0; raw 0; reactingCloud 0; - reactingParcel 0; reaction 0; realizableKE 0; refinementHistory 0; @@ -637,6 +696,7 @@ DebugSwitches reflect 0; regIOobject 0; regionSplit 0; + regionToCell 0; remove 0; removeCell 0; removeCells 0; @@ -720,11 +780,12 @@ DebugSwitches tensorAverageField 0; tensorField 0; thermoCloud 0; - thermoParcel 0; thermophysicalFunction 0; time 0; - timeVaryingGammaContactAngle 0; + timeVaryingAlphaContactAngle 0; + timeVaryingFlowRateInletVelocity 0; timeVaryingMappedFixedValue 0; + timeVaryingTotalPressure 0; timeVaryingUniformFixedValue 0; timer 0; topoAction 0; @@ -745,17 +806,19 @@ DebugSwitches treeNode 0; triSurface 0; triSurfaceMesh 0; - triSurfaceMeshes 0; turbulenceModel 0; + turbulentHeatFluxTemperature 0; turbulentInlet 0; turbulentIntensityKineticEnergyInlet 0; turbulentMixingLengthDissipationRateInlet 0; + turbulentMixingLengthFrequencyInlet 0; uncorrected 0; undoableMeshCutter 0; uniform 0; uniformFixedValue 0; unitInjector 0; upwind 0; + upwindCFCStencil 0; value 0; vanAlbada 0; vanAlbadaV 0; @@ -817,31 +880,30 @@ DimensionedConstants // SI units //- Universal gas constant [J/(kmol K)] - R 8314.51; + R 8314.51; //- Standard pressure [Pa] - Pstd 1.0e5; + Pstd 1.0e5; //- Standard temperature [K] - Tstd 298.15; + Tstd 298.15; //- Stefan-Boltzmann constant [J/(K4 m2 s)] - sigmaSB sigmaSB [1 0 -3 -4 0 0 0] 5.670e-08; - + sigmaSB sigmaSB [1 0 -3 -4 0 0 0] 5.670e-08; /* USCS units //- Universal gas constant [lbm ft2/(s2 kmol R)] - R 3406.78; + R 3406.78; //- Standard pressure [lbm/(ft2)] - Pstd 2088.6; + Pstd 2088.6; //- Standard temperature [degR] - Tstd 536.67; + Tstd 536.67; //- Stefan-Boltzmann constant [lbm /(degR4 ft s)] - sigmaSB sigmaSB [1 0 -3 -4 0 0 0] 8.2292e-08; + sigmaSB sigmaSB [1 0 -3 -4 0 0 0] 8.2292e-08; */ } diff --git a/etc/cshrc b/etc/cshrc index bcda5b6318df9a8508132de8afc976c8ec7ad940..a46cf3ee475c2221815473daec70d7cf87870fcf 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -71,12 +71,6 @@ setenv WM_PROJECT_USER_DIR $HOME/$WM_PROJECT/$LOGNAME-$WM_PROJECT_VERSION setenv WM_THIRD_PARTY_DIR $WM_PROJECT_INST_DIR/ThirdParty -# Operating System/Platform from Unix or MSWindows -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# WM_OS = Unix | MSWindows -if ( ! $?WM_OS ) setenv WM_OS Unix - - # Compiler: set to Gcc, Gcc43 or Icc (for Intel's icc) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ( ! $?WM_COMPILER ) setenv WM_COMPILER Gcc @@ -99,7 +93,7 @@ if ( ! $?WM_COMPILE_OPTION ) setenv WM_COMPILE_OPTION Opt # WM_JAVAC_OPTION = Opt | Debug if ( ! $?WM_JAVAC_OPTION ) setenv WM_JAVAC_OPTION Opt -# WM_MPLIB = | OPENMPI | LAM | MPICH | MPICH-GM | HPMPI | GAMMA | MPI +# WM_MPLIB = | OPENMPI | LAM | MPICH | MPICH-GM | HPMPI | GAMMA | MPI | QSMPI if ( ! $?WM_MPLIB ) setenv WM_MPLIB OPENMPI diff --git a/etc/settings.csh b/etc/settings.csh index a38ec5eacd63761ec7b66e90fe5a3ee6559b252e..d36a91ad5b0391a9f112a5145d26c258910fff6c 100644 --- a/etc/settings.csh +++ b/etc/settings.csh @@ -87,8 +87,8 @@ switch ("$compilerInstall") case OpenFOAM: switch ("$WM_COMPILER") case Gcc: - setenv WM_COMPILER_DIR $WM_THIRD_PARTY_DIR/gcc-4.3.2/platforms/$WM_ARCH$WM_COMPILER_ARCH - _foamAddLib $WM_THIRD_PARTY_DIR/mpfr-2.3.2/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib + setenv WM_COMPILER_DIR $WM_THIRD_PARTY_DIR/gcc-4.3.3/platforms/$WM_ARCH$WM_COMPILER_ARCH + _foamAddLib $WM_THIRD_PARTY_DIR/mpfr-2.4.1/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib _foamAddLib $WM_THIRD_PARTY_DIR/gmp-4.2.4/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib breaksw case Gcc42: @@ -231,6 +231,15 @@ case FJMPI: _foamAddLib /opt/FJSVpnidt/lib breaksw +case QSMPI: + setenv MPI_ARCH_PATH /usr/lib/mpi + setenv FOAM_MPI_LIBBIN FOAM_LIBBIN/qsmpi + + _foamAddPath $MPI_ARCH_PATH/bin + _foamAddLib $MPI_ARCH_PATH/lib + + breaksw + default: setenv FOAM_MPI_LIBBIN $FOAM_LIBBIN/dummy breaksw diff --git a/etc/settings.sh b/etc/settings.sh index 7df3f6d5900d0ce91cc69fc8d33667816c9ca641..046f624cdefbfb2848bd9e59a843a84863047412 100644 --- a/etc/settings.sh +++ b/etc/settings.sh @@ -111,8 +111,8 @@ case "$compilerInstall" in OpenFOAM) case "$WM_COMPILER" in Gcc) - export WM_COMPILER_DIR=$WM_THIRD_PARTY_DIR/gcc-4.3.2/platforms/$WM_ARCH$WM_COMPILER_ARCH - _foamAddLib $WM_THIRD_PARTY_DIR/mpfr-2.3.2/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib + export WM_COMPILER_DIR=$WM_THIRD_PARTY_DIR/gcc-4.3.3/platforms/$WM_ARCH$WM_COMPILER_ARCH + _foamAddLib $WM_THIRD_PARTY_DIR/mpfr-2.4.1/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib _foamAddLib $WM_THIRD_PARTY_DIR/gmp-4.2.4/platforms/$WM_ARCH$WM_COMPILER_ARCH/lib ;; Gcc42) @@ -259,6 +259,15 @@ FJMPI) _foamAddLib /opt/FJSVpnidt/lib ;; +QSMPI) + export MPI_ARCH_PATH=/usr/lib/mpi + export FOAM_MPI_LIBBIN=$FOAM_LIBBIN/qsmpi + + _foamAddPath $MPI_ARCH_PATH/bin + _foamAddLib $MPI_ARCH_PATH/lib + + ;; + *) export FOAM_MPI_LIBBIN=$FOAM_LIBBIN/dummy ;; diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index c3b09850f964a78082df6286505c06656ae4946b..055f785471b909e9ee65c324d2d62bfb23b1777c 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -152,17 +152,12 @@ inline void Foam::FixedList<T, Size>::checkSize(const label size) const } -// Check index i is within valid range (0 ... size-1). +// Check index i is within valid range (0 ... size-1) +// The check for zero-sized list is already done in static assert template<class T, unsigned Size> inline void Foam::FixedList<T, Size>::checkIndex(const label i) const { - if (!Size) - { - FatalErrorIn("FixedList<T, Size>::checkIndex(const label)") - << "attempt to access element from zero-sized list" - << abort(FatalError); - } - else if (i < 0 || i >= label(Size)) + if (i < 0 || unsigned(i) >= Size) { FatalErrorIn("FixedList<T, Size>::checkIndex(const label)") << "index " << i << " out of range 0 ... " << (Size-1) diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index a3c17a48900dd57ec15e880260820258b32b18c3..6d20e2b3b72af3b5ec441d8c88668f2c9158b83c 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -58,10 +58,6 @@ Foam::List<T>::List(const label s) { this->v_ = new T[this->size_]; } - else - { - this->v_ = 0; - } } @@ -87,10 +83,6 @@ Foam::List<T>::List(const label s, const T& a) List_ELEM((*this), vp, i) = a; List_END_FOR_ALL } - else - { - this->v_ = 0; - } } @@ -119,16 +111,12 @@ Foam::List<T>::List(const List<T>& a) List_END_FOR_ALL } } - else - { - this->v_ = 0; - } } // Construct by transferring the parameter contents template<class T> -Foam::List<T>::List(const Xfer<List<T> >& lst) +Foam::List<T>::List(const Xfer< List<T> >& lst) { transfer(lst()); } @@ -165,10 +153,6 @@ Foam::List<T>::List(List<T>& a, bool reUse) List_END_FOR_ALL } } - else - { - this->v_ = 0; - } } @@ -188,10 +172,6 @@ Foam::List<T>::List(const UList<T>& a, const unallocLabelList& map) List_ELEM((*this), vp, i) = List_ELEM(a, ap, (map[i])); List_END_FOR_ALL } - else - { - this->v_ = 0; - } } @@ -234,7 +214,7 @@ Foam::List<T>::List(const FixedList<T, Size>& lst) : UList<T>(NULL, Size) { - if (Size) + if (this->size_) { this->v_ = new T[this->size_]; @@ -243,10 +223,6 @@ Foam::List<T>::List(const FixedList<T, Size>& lst) this->operator[](i) = lst[i]; } } - else - { - this->v_ = 0; - } } @@ -265,10 +241,6 @@ Foam::List<T>::List(const PtrList<T>& lst) this->operator[](i) = lst[i]; } } - else - { - this->v_ = 0; - } } @@ -293,10 +265,6 @@ Foam::List<T>::List(const SLList<T>& lst) this->operator[](i++) = iter(); } } - else - { - this->v_ = 0; - } } @@ -315,10 +283,6 @@ Foam::List<T>::List(const IndirectList<T>& lst) this->operator[](i) = lst[i]; } } - else - { - this->v_ = 0; - } } @@ -337,10 +301,6 @@ Foam::List<T>::List(const UIndirectList<T>& lst) this->operator[](i) = lst[i]; } } - else - { - this->v_ = 0; - } } @@ -359,10 +319,6 @@ Foam::List<T>::List(const BiIndirectList<T>& lst) this->operator[](i) = lst[i]; } } - else - { - this->v_ = 0; - } } diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H index c762bdba7d57da1ca12e5b0d8dff12e94a6f5bf7..ec6a1b9fd6f330f6d5feb3c5e7bd4d78a8b411af 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H @@ -26,8 +26,8 @@ Class Foam::UIndirectList Description - A List with indirect addressing. Like IndirectList but does not store - addressing. + A List with indirect addressing. + Like IndirectList but does not store addressing. SourceFiles UIndirectListI.H @@ -44,8 +44,12 @@ SourceFiles namespace Foam { +// Forward declaration of friend functions and operators +template<class T> class UIndirectList; +template<class T> Ostream& operator<<(Ostream&, const UIndirectList<T>&); + /*---------------------------------------------------------------------------*\ - Class UIndirectList Declaration + Class UIndirectList Declaration \*---------------------------------------------------------------------------*/ template<class T> @@ -92,6 +96,17 @@ public: //- Assignment of all entries to the given value inline void operator=(const T&); + + // Ostream operator + + //- Write UIndirectList to Ostream + // Binary output is currently still a bit of a problem + friend Ostream& operator<< + #ifndef __CINT__ + <T> + #endif + (Ostream&, const UIndirectList<T>&); + }; @@ -103,6 +118,10 @@ public: #include "UIndirectListI.H" +#ifdef NoRepository +# include "UIndirectListIO.C" +#endif + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C new file mode 100644 index 0000000000000000000000000000000000000000..0c3be0e7697a8a7264d6192976cbe26c9665a46d --- /dev/null +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C @@ -0,0 +1,126 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "UIndirectList.H" +#include "Ostream.H" +#include "token.H" +#include "contiguous.H" + +// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // + +template<class T> +Foam::Ostream& Foam::operator<< +( + Foam::Ostream& os, + const Foam::UIndirectList<T>& L +) +{ + // Write list contents depending on data format + if (os.format() == IOstream::ASCII || !contiguous<T>()) + { + bool uniform = false; + + if (L.size() > 1 && contiguous<T>()) + { + uniform = true; + + forAll(L, i) + { + if (L[i] != L[0]) + { + uniform = false; + break; + } + } + } + + if (uniform) + { + // Write size and start delimiter + os << L.size() << token::BEGIN_BLOCK; + + // Write contents + os << L[0]; + + // Write end delimiter + os << token::END_BLOCK; + } + else if (L.size() < 11 && contiguous<T>()) + { + // Write size and start delimiter + os << L.size() << token::BEGIN_LIST; + + // Write contents + forAll(L, i) + { + if (i) os << token::SPACE; + os << L[i]; + } + + // Write end delimiter + os << token::END_LIST; + } + else + { + // Write size and start delimiter + os << nl << L.size() << nl << token::BEGIN_LIST; + + // Write contents + forAll(L, i) + { + os << nl << L[i]; + } + + // Write end delimiter + os << nl << token::END_LIST << nl; + } + } + else + { + // this is annoying, and wasteful, but there's currently no alternative + + os << nl << L.size() << nl; + + if (L.size()) + { + List<T> lst = L(); + + os.write + ( + reinterpret_cast<const char*>(lst.cdata()), + lst.byteSize() + ); + } + } + + // Check state of IOstream + os.check("Ostream& operator<<(Ostream&, const UIndirectList&)"); + + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index d2fc9a6ba1aa1175ecf159bf81bbd970b531902d..5fc5a839b13d8d86a06828551200584335ca9f4c 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -359,6 +359,10 @@ public: template<class Stream> static inline Stream& writeDivider(Stream& os); + //- Write the standard end file divider + template<class Stream> + static inline Stream& writeEndDivider(Stream& os); + //- Write header bool writeHeader(Ostream&) const; diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index 71af2039f6a1785ba29a286e5dc2ada8fe6795a5..4ac1df926bcf1656375e0b529eac037e8d388761 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -82,5 +82,14 @@ inline Stream& Foam::IOobject::writeDivider(Stream& os) return os; } +template<class Stream> +inline Stream& Foam::IOobject::writeEndDivider(Stream& os) +{ + os << "\n\n" + "// ************************************************************************* //\n"; + + return os; +} + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.H b/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.H index fffccc452590b74f942929e5ebb6ea33d0810da5..37811c0d6739039dc073d80c71cfe8a901eaa453 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/readHexLabel.H @@ -45,7 +45,7 @@ namespace Foam { //- Read a hex label from an input stream -label readHexLabel(ISstream& is); +label readHexLabel(ISstream&); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/Time/instant/instant.C b/src/OpenFOAM/db/Time/instant/instant.C index 0b4389e4b25ba45056bc903c59489a4a765c9e14..80ed886e4dbd53588225f47c71bfa608e84bec23 100644 --- a/src/OpenFOAM/db/Time/instant/instant.C +++ b/src/OpenFOAM/db/Time/instant/instant.C @@ -36,16 +36,16 @@ const char* const Foam::instant::typeName = "instant"; Foam::instant::instant() {} -Foam::instant::instant(const scalar tval, const word& tname) +Foam::instant::instant(const scalar val, const word& tname) : - value_(tval), + value_(val), name_(tname) {} -Foam::instant::instant(const scalar tval) +Foam::instant::instant(const scalar val) : - value_(tval), - name_(Time::timeName(tval)) + value_(val), + name_(Time::timeName(val)) {} Foam::instant::instant(const word& tname) @@ -57,20 +57,19 @@ Foam::instant::instant(const word& tname) // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // -int Foam::operator==(const instant& I1, const instant& I2) +bool Foam::operator==(const instant& a, const instant& b) { return ( - I1.value_ < I2.value_ + SMALL - && I1.value_ > I2.value_ - SMALL + a.value_ < b.value_ + SMALL + && a.value_ > b.value_ - SMALL ); } -int Foam::operator != (const instant& I1, const instant& I2) +bool Foam::operator!=(const instant& a, const instant& b) { - // Invert the '==' operator ('0'='false') - return I1 == I2 ? 0 : 1; + return !operator==(a, b); } diff --git a/src/OpenFOAM/db/Time/instant/instant.H b/src/OpenFOAM/db/Time/instant/instant.H index 02c76500e750b20bd9949e302f8efc21891824e3..032b29998759060e5bd43f3533e9e53560d69620 100644 --- a/src/OpenFOAM/db/Time/instant/instant.H +++ b/src/OpenFOAM/db/Time/instant/instant.H @@ -50,8 +50,8 @@ class instant; // Friend Operators -int operator==(const instant&, const instant&); -int operator!=(const instant&, const instant&); +bool operator==(const instant&, const instant&); +bool operator!=(const instant&, const instant&); // IOstream Operators @@ -79,9 +79,9 @@ public: { public: - bool operator()(const instant& one, const instant& two) const + bool operator()(const instant& a, const instant& b) const { - return one.value() < two.value(); + return a.value() < b.value(); } }; @@ -137,8 +137,8 @@ public: // Friend Operators - friend int operator==(const instant&, const instant&); - friend int operator!=(const instant&, const instant&); + friend bool operator==(const instant&, const instant&); + friend bool operator!=(const instant&, const instant&); // IOstream Operators diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index a757caebcc9729ffbe51019c3cc2e3c35abe9543..fd89f0f608fec6e5e355735fad46e7785dcf5e86 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -117,12 +117,7 @@ Foam::dictionary::dictionary name_(dict.name()), parent_(parentDict) { - for - ( - IDLList<entry>::iterator iter = begin(); - iter != end(); - ++iter - ) + forAllIter(IDLList<entry>, *this, iter) { hashedEntries_.insert(iter().keyword(), &iter()); @@ -147,12 +142,7 @@ Foam::dictionary::dictionary name_(dict.name()), parent_(dictionary::null) { - for - ( - IDLList<entry>::iterator iter = begin(); - iter != end(); - ++iter - ) + forAllIter(IDLList<entry>, *this, iter) { hashedEntries_.insert(iter().keyword(), &iter()); @@ -238,12 +228,7 @@ Foam::SHA1Digest Foam::dictionary::digest() const OSHA1stream os; // process entries - for - ( - IDLList<entry>::const_iterator iter = begin(); - iter != end(); - ++iter - ) + forAllConstIter(IDLList<entry>, *this, iter) { os << *iter; } @@ -262,7 +247,8 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const { if (patternEntries_.size()) { - DLList<entry*>::const_iterator wcLink = patternEntries_.begin(); + DLList<entry*>::const_iterator wcLink = + patternEntries_.begin(); DLList<autoPtr<regExp> >::const_iterator reLink = patternRegexps_.begin(); @@ -475,12 +461,7 @@ Foam::wordList Foam::dictionary::toc() const wordList keys(size()); label nKeys = 0; - for - ( - IDLList<entry>::const_iterator iter = begin(); - iter != end(); - ++iter - ) + forAllConstIter(IDLList<entry>::const_iterator, *this, iter) { keys[nKeys++] = iter().keyword(); } @@ -494,12 +475,7 @@ Foam::List<Foam::keyType> Foam::dictionary::keys(bool patterns) const List<keyType> keys(size()); label nKeys = 0; - for - ( - IDLList<entry>::const_iterator iter = begin(); - iter != end(); - ++iter - ) + forAllConstIter(IDLList<entry>, *this, iter) { if (iter().keyword().isPattern() ? patterns : !patterns) { @@ -553,7 +529,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) } else { - IOWarningIn("dictionary::add(entry*)", (*this)) + IOWarningIn("dictionary::add(entry*, bool)", (*this)) << "problem replacing entry "<< entryPtr->keyword() << " in dictionary " << name() << endl; @@ -582,7 +558,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) } else { - IOWarningIn("dictionary::add(entry* entryPtr)", (*this)) + IOWarningIn("dictionary::add(entry*, bool)", (*this)) << "attempt to add entry "<< entryPtr->keyword() << " which already exists in dictionary " << name() << endl; @@ -598,11 +574,13 @@ void Foam::dictionary::add(const entry& e, bool mergeEntry) add(e.clone(*this).ptr(), mergeEntry); } + void Foam::dictionary::add(const keyType& k, const word& w, bool overwrite) { add(new primitiveEntry(k, token(w)), overwrite); } + void Foam::dictionary::add ( const keyType& k, @@ -613,16 +591,19 @@ void Foam::dictionary::add add(new primitiveEntry(k, token(s)), overwrite); } + void Foam::dictionary::add(const keyType& k, const label l, bool overwrite) { add(new primitiveEntry(k, token(l)), overwrite); } + void Foam::dictionary::add(const keyType& k, const scalar s, bool overwrite) { add(new primitiveEntry(k, token(s)), overwrite); } + void Foam::dictionary::add ( const keyType& k, @@ -652,6 +633,7 @@ void Foam::dictionary::set(const entry& e) set(e.clone(*this).ptr()); } + void Foam::dictionary::set(const keyType& k, const dictionary& d) { set(new dictionaryEntry(k, *this, d)); @@ -665,8 +647,10 @@ bool Foam::dictionary::remove(const word& Keyword) if (iter != hashedEntries_.end()) { // Delete from patterns first - DLList<entry*>::iterator wcLink = patternEntries_.begin(); - DLList<autoPtr<regExp> >::iterator reLink = patternRegexps_.begin(); + DLList<entry*>::iterator wcLink = + patternEntries_.begin(); + DLList<autoPtr<regExp> >::iterator reLink = + patternRegexps_.begin(); // Find in pattern using exact match only if (findInPatterns(false, Keyword, wcLink, reLink)) @@ -792,12 +776,7 @@ bool Foam::dictionary::merge(const dictionary& dict) bool changed = false; - for - ( - IDLList<entry>::const_iterator iter = dict.begin(); - iter != dict.end(); - ++iter - ) + forAllConstIter(IDLList<entry>, dict, iter) { HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword()); @@ -882,12 +861,7 @@ void Foam::dictionary::operator=(const dictionary& rhs) // Create clones of the entries in the given dictionary // resetting the parentDict to this dictionary - for - ( - IDLList<entry>::const_iterator iter = rhs.begin(); - iter != rhs.end(); - ++iter - ) + forAllConstIter(IDLList<entry>, rhs, iter) { add(iter().clone(*this).ptr()); } @@ -904,12 +878,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs) << abort(FatalError); } - for - ( - IDLList<entry>::const_iterator iter = rhs.begin(); - iter != rhs.end(); - ++iter - ) + forAllConstIter(IDLList<entry>, rhs, iter) { add(iter().clone(*this).ptr()); } @@ -926,12 +895,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs) << abort(FatalError); } - for - ( - IDLList<entry>::const_iterator iter = rhs.begin(); - iter != rhs.end(); - ++iter - ) + forAllConstIter(IDLList<entry>, rhs, iter) { if (!found(iter().keyword())) { @@ -951,12 +915,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs) << abort(FatalError); } - for - ( - IDLList<entry>::const_iterator iter = rhs.begin(); - iter != rhs.end(); - ++iter - ) + forAllConstIter(IDLList<entry>, rhs, iter) { set(iter().clone(*this).ptr()); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index 2f0987d16b7e2b4ebafd8ce7ad63184696f49d97..96196e3a11ab9a9b8e2913405f54f85f28262302 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -154,12 +154,8 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const // Write entry os << e; - // Add new line if applicable - if - ( - (e.isDict() || (!e.isDict() && parent()==dictionary::null)) - && e != *last() - ) + // Add extra new line between entries for "top-level" dictionaries + if (!subDict && parent() == dictionary::null && e != *last()) { os << nl; } @@ -167,7 +163,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const // Check stream before going to next entry. if (!os.good()) { - WarningIn("dictionary::write(Ostream& os, bool subDict)") + WarningIn("dictionary::write(Ostream&, bool subDict)") << "Can't write entry " << iter().keyword() << " for dictionary " << name() << endl; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C index 601674ac7e9795b766e57675aedde565cf96cff3..e36de4108c2c0062c1f4d88a21912ec831ee3db9 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C @@ -103,14 +103,13 @@ bool Foam::functionEntry::execute is.fatalCheck ( "functionEntry::execute" - "(const word& functionName, const dictionary& parentDict, " - "primitiveEntry&, Istream&)" + "(const word&, const dictionary&, primitiveEntry&, Istream&)" ); if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_) { cerr<<"functionEntry::execute" - << "(const word&, dictionary&, primitiveEntry&, Istream&)" + << "(const word&, const dictionary&, primitiveEntry&, Istream&)" << " not yet initialized, function = " << functionName.c_str() << std::endl; @@ -126,8 +125,7 @@ bool Foam::functionEntry::execute FatalErrorIn ( "functionEntry::execute" - "(const word& functionName, const dictionary& parentDict, " - "primitiveEntry&, Istream&)" + "(const word&, const dictionary&, primitiveEntry&, Istream&)" ) << "Unknown functionEntry " << functionName << endl << endl << "Valid functionEntries are :" << endl diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H index f4d1702b4f12430dcea56cf636da29de8f1cea10..ebfd49470bc2ef649045e5ee096b2186d1c0a943 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H @@ -95,7 +95,7 @@ public: ( const word& functionName, dictionary& parentDict, - Istream& is + Istream& ); declareMemberFunctionSelectionTable @@ -117,8 +117,8 @@ public: ( const word& functionName, const dictionary& parentDict, - primitiveEntry& entry, - Istream& is + primitiveEntry&, + Istream& ); diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index e9f11d56a5dea1721aad81de30148293f66697a2..7879369017deaa7cf3b354128025d3c3ed7bee71 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -62,8 +62,7 @@ namespace functionEntries } } - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // Foam::fileName Foam::functionEntries::includeEntry::includeFileName ( @@ -73,6 +72,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName fileName fName(is); fName.expand(); + // relative name if (fName.size() && fName[0] != '/') { fName = fileName(is.name()).path()/fName; @@ -82,17 +82,19 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + bool Foam::functionEntries::includeEntry::execute ( dictionary& parentDict, Istream& is ) { - IFstream fileStream(includeFileName(is)); + IFstream ifs(includeFileName(is)); - if (fileStream) + if (ifs) { - parentDict.read(fileStream); + parentDict.read(ifs); return true; } else @@ -100,9 +102,9 @@ bool Foam::functionEntries::includeEntry::execute FatalIOErrorIn ( "functionEntries::includeEntry::includeEntry" - "(dictionary& parentDict,Istream& is)", + "(dictionary& parentDict, Istream&)", is - ) << "Cannot open include file " << fileStream.name() + ) << "Cannot open include file " << ifs.name() << " while reading dictionary " << parentDict.name() << exit(FatalIOError); @@ -117,11 +119,11 @@ bool Foam::functionEntries::includeEntry::execute Istream& is ) { - IFstream fileStream(includeFileName(is)); + IFstream ifs(includeFileName(is)); - if (fileStream) + if (ifs) { - entry.read(parentDict, fileStream); + entry.read(parentDict, ifs); return true; } else @@ -129,9 +131,9 @@ bool Foam::functionEntries::includeEntry::execute FatalIOErrorIn ( "functionEntries::includeEntry::includeEntry" - "(dictionary& parentDict, primitiveEntry& entry, Istream& is)", + "(dictionary& parentDict, primitiveEntry& entry, Istream&)", is - ) << "Cannot open include file " << fileStream.name() + ) << "Cannot open include file " << ifs.name() << " while reading dictionary " << parentDict.name() << exit(FatalIOError); diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H index effff83a310143f9b0f225f68a4385d53d1390be..b260e3f36c624c0bb5eb410203c29306009b3850 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H @@ -58,7 +58,7 @@ namespace functionEntries { /*---------------------------------------------------------------------------*\ - Class includeEntry Declaration + Class includeEntry Declaration \*---------------------------------------------------------------------------*/ class includeEntry @@ -68,7 +68,7 @@ class includeEntry // Private Member Functions //- Read the include fileName from Istream, expand and return - static fileName includeFileName(Istream& is); + static fileName includeFileName(Istream&); //- Disallow default bitwise copy construct includeEntry(const includeEntry&); @@ -86,18 +86,14 @@ public: // Member Functions //- Execute the functionEntry in a sub-dict context - static bool execute - ( - dictionary& parentDict, - Istream& is - ); + static bool execute(dictionary& parentDict, Istream&); //- Execute the functionEntry in a primitiveEntry context static bool execute ( const dictionary& parentDict, - primitiveEntry& entry, - Istream& is + primitiveEntry&, + Istream& ); }; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C index 60c348e244231e2c8898a61134b3fdea837b84e7..f711da80aa89bfb4d46dfedd9c764c658f018f15 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C @@ -39,6 +39,9 @@ const Foam::word Foam::functionEntries::inputModeEntry::typeName // might include inputModeEntries int Foam::functionEntries::inputModeEntry::debug(0); +Foam::functionEntries::inputModeEntry::inputMode + Foam::functionEntries::inputModeEntry::mode_(MERGE); + namespace Foam { namespace functionEntries @@ -53,10 +56,6 @@ namespace functionEntries } } -// * * * * * * * * * * * * * * * * Private Data * * * * * * * * * * * * * * // - -Foam::label Foam::functionEntries::inputModeEntry::mode_ = imError; - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // we could combine this into execute() directly, but leave it here for now @@ -65,17 +64,17 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is) clear(); word mode(is); - if (mode == "merge") + if (mode == "merge" || mode == "default") { - mode_ = imMerge; + mode_ = MERGE; } else if (mode == "overwrite") { - mode_ = imOverwrite; + mode_ = OVERWRITE; } - else if (mode == "error" || mode == "default") + else if (mode == "error") { - mode_ = imError; + mode_ = ERROR; } else { @@ -101,33 +100,19 @@ bool Foam::functionEntries::inputModeEntry::execute void Foam::functionEntries::inputModeEntry::clear() { - mode_ = imError; + mode_ = MERGE; } bool Foam::functionEntries::inputModeEntry::merge() { - if (mode_ & imMerge) - { - return true; - } - else - { - return false; - } + return mode_ == MERGE; } bool Foam::functionEntries::inputModeEntry::overwrite() { - if (mode_ & imOverwrite) - { - return true; - } - else - { - return false; - } + return mode_ == OVERWRITE; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H index 394ad157798a48253f3c8ecb8b0923db4bba1c3e..9ecb558da9ad81a634cf260c18d820c0d9f35c12 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H @@ -38,7 +38,7 @@ Description @param merge merge sub-dictionaries when possible @param overwrite keep last entry and silently remove previous ones @param error flag duplicate entry as an error - @param default currently the same as error + @param default currently the same as merge SourceFiles inputModeEntry.C @@ -68,13 +68,13 @@ class inputModeEntry //- input mode options enum inputMode { - imError = 0, - imMerge = 0x1, - imOverwrite = 0x2 + ERROR, + MERGE, + OVERWRITE }; //- current input mode - static label mode_; + static inputMode mode_; // Private Member Functions @@ -98,19 +98,15 @@ public: // Member Functions //- Execute the functionEntry in a sub-dict context - static bool execute - ( - dictionary& parentDict, - Istream& - ); + static bool execute(dictionary& parentDict, Istream&); - //- Reset the inputMode to 'default' + //- Reset the inputMode to %default static void clear(); - //- Return true if the inputMode is 'merge' + //- Return true if the inputMode is %merge static bool merge(); - //- Return true if the inputMode is 'overwrite' + //- Return true if the inputMode is %overwrite static bool overwrite(); }; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H index 443d28889fefc4d10e8f80c2eb2cbc7b8cda79b3..1ed2d99639228540938aba2c4d993a3a749a6185 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H @@ -80,11 +80,7 @@ public: // Member Functions //- Execute the functionEntry in a sub-dict context - static bool execute - ( - dictionary& parentDict, - Istream& is - ); + static bool execute(dictionary& parentDict, Istream&); }; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index cbd841f8aeefc1288ce69ec7fc29d06124c9b575..9d01de9d90e8c254dc4d47678885dc2b30a8a7eb 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -101,7 +101,7 @@ Foam::wordList Foam::objectRegistry::names() const wordList objectNames(size()); label count=0; - for (const_iterator iter = begin(); iter != end(); ++iter) + for (const_iterator iter = cbegin(); iter != cend(); ++iter) { objectNames[count++] = iter()->name(); } @@ -115,7 +115,7 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const wordList objectNames(size()); label count=0; - for (const_iterator iter = begin(); iter != end(); ++iter) + for (const_iterator iter = cbegin(); iter != cend(); ++iter) { if (iter()->type() == ClassName) { @@ -234,15 +234,33 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const << " in registry " << name() << endl; } + } + + return false; +} + + +void Foam::objectRegistry::rename(const word& newName) +{ + regIOobject::rename(newName); - return false; + // adjust dbDir_ as well + string::size_type i = dbDir_.rfind('/'); + + if (i == string::npos) + { + dbDir_ = newName; + } + else + { + dbDir_.replace(i+1, string::npos, newName); } } bool Foam::objectRegistry::modified() const { - for (const_iterator iter = begin(); iter != end(); ++iter) + for (const_iterator iter = cbegin(); iter != cend(); ++iter) { if (iter()->modified()) { @@ -287,7 +305,7 @@ bool Foam::objectRegistry::writeObject { bool ok = true; - for (const_iterator iter = begin(); iter != end(); ++iter) + for (const_iterator iter = cbegin(); iter != cend(); ++iter) { if (objectRegistry::debug) { diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 061f452c0b7b3f16bb4843f5b0aef43d15173a37..1f2d30d93e716f6951b30ea8f04cc4f722065b5a 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -160,6 +160,9 @@ public: // Edit + //- Rename + virtual void rename(const word& newName); + //- Add an regIOobject to registry bool checkIn(regIOobject&) const; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 646c4513175badfc03f277a364173c6f2fe15b44..c58bacf75dfa7dba82e0d8a2f0600c035e6da380 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -147,8 +147,7 @@ const Type& Foam::objectRegistry::lookupObject(const word& name) const } } - const Type* dummyPtr_ = NULL; - return *dummyPtr_; + return *reinterpret_cast< const Type* >(0); } diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C index dc3dcf14783536bb4368b0e0f9174ac36bddc6bd..62df5dafe1512ee7fd2d9895fc86f20c052b3530 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C +++ b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C @@ -103,9 +103,7 @@ bool Foam::regIOobject::writeObject return false; } - os << "\n\n" - "// ************************************************************************* //" - << endl; + writeEndDivider(os); osGood = os.good(); } diff --git a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H index 1e043399f1d101ff4458cd419c4335130ef0d36d..7b27a9a70faa6cba4f80be9ad07e1c6bf6403777 100644 --- a/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H +++ b/src/OpenFOAM/db/runTimeSelection/addToRunTimeSelectionTable.H @@ -41,7 +41,7 @@ Description (baseType,thisType,argNames) \ \ /* Add the thisType constructor function to the table */ \ - baseType::add##argNames##ConstructorToTable<thisType> \ + baseType::add##argNames##ConstructorToTable< thisType > \ add##thisType##argNames##ConstructorTo##baseType##Table_ @@ -50,7 +50,7 @@ Description (baseType,thisType,argNames,lookup) \ \ /* Add the thisType constructor function to the table, find by lookup */ \ - baseType::add##argNames##ConstructorToTable<thisType> \ + baseType::add##argNames##ConstructorToTable< thisType > \ add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_(#lookup) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -62,7 +62,7 @@ Description (baseType,thisType,Targ,argNames) \ \ /* Add the thisType constructor function to the table */ \ - baseType::add##argNames##ConstructorToTable<thisType<Targ> > \ + baseType::add##argNames##ConstructorToTable< thisType< Targ > > \ add##thisType##Targ##argNames##ConstructorTo##baseType##Table_ @@ -72,7 +72,7 @@ Description (baseType,thisType,Targ,argNames,lookup) \ \ /* Add the thisType constructor function to the table, find by lookup */ \ - baseType::add##argNames##ConstructorToTable<thisType<Targ> > \ + baseType::add##argNames##ConstructorToTable< thisType< Targ > > \ add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Table_(#lookup) @@ -85,7 +85,7 @@ Description (baseType,thisType,Targ,argNames) \ \ /* Add the thisType constructor function to the table */ \ - baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \ + baseType< Targ >::add##argNames##ConstructorToTable< thisType< Targ > > \ add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_ @@ -95,7 +95,7 @@ Description (baseType,thisType,Targ,argNames,lookup) \ \ /* Add the thisType constructor function to the table, find by lookup */ \ - baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \ + baseType< Targ >::add##argNames##ConstructorToTable< thisType< Targ > > \ add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_(#lookup) diff --git a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H index 6518feb29b4cb577a7399f0cd0b373d4a5266182..8e9b4ea54e8f7bd30bd893f60294acceeab37785 100644 --- a/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H +++ b/src/OpenFOAM/db/runTimeSelection/runTimeSelectionTables.H @@ -54,24 +54,24 @@ Description (autoPtr,baseType,argNames,argList,parList) \ \ /* Construct from argList function pointer type */ \ - typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \ + typedef autoPtr< baseType > (*argNames##ConstructorPtr)argList; \ \ /* Construct from argList function table type */ \ - typedef HashTable<argNames##ConstructorPtr, word, string::hash> \ + typedef HashTable< argNames##ConstructorPtr, word, string::hash > \ argNames##ConstructorTable; \ \ /* Construct from argList function pointer table pointer */ \ static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ \ /* Class to add constructor from argList to table */ \ - template<class baseType##Type> \ + template< class baseType##Type > \ class add##argNames##ConstructorToTable \ { \ public: \ \ - static autoPtr<baseType> New argList \ + static autoPtr< baseType > New argList \ { \ - return autoPtr<baseType>(new baseType##Type parList); \ + return autoPtr< baseType >(new baseType##Type parList); \ } \ \ add##argNames##ConstructorToTable \ @@ -103,24 +103,24 @@ Description (autoPtr,baseType,argNames,argList,parList) \ \ /* Construct from argList function pointer type */ \ - typedef autoPtr<baseType> (*argNames##ConstructorPtr)argList; \ + typedef autoPtr< baseType > (*argNames##ConstructorPtr)argList; \ \ /* Construct from argList function table type */ \ - typedef HashTable<argNames##ConstructorPtr, word, string::hash> \ + typedef HashTable< argNames##ConstructorPtr, word, string::hash > \ argNames##ConstructorTable; \ \ /* Construct from argList function pointer table pointer */ \ static argNames##ConstructorTable* argNames##ConstructorTablePtr_; \ \ /* Class to add constructor from argList to table */ \ - template<class baseType##Type> \ + template< class baseType##Type > \ class add##argNames##ConstructorToTable \ { \ public: \ \ - static autoPtr<baseType> New##baseType argList \ + static autoPtr< baseType > New##baseType argList \ { \ - return autoPtr<baseType>(baseType##Type::New parList.ptr()); \ + return autoPtr< baseType >(baseType##Type::New parList.ptr()); \ } \ \ add##argNames##ConstructorToTable \ @@ -213,7 +213,7 @@ Description (baseType,argNames) \ \ defineRunTimeSelectionTablePtr(baseType,argNames); \ - defineRunTimeSelectionTableConstructor(baseType,argNames) \ + defineRunTimeSelectionTableConstructor(baseType,argNames); \ defineRunTimeSelectionTableDestructor(baseType,argNames) @@ -227,7 +227,7 @@ Description template<> \ defineRunTimeSelectionTablePtr(baseType,argNames); \ template<> \ - defineRunTimeSelectionTableConstructor(baseType,argNames) \ + defineRunTimeSelectionTableConstructor(baseType,argNames); \ template<> \ defineRunTimeSelectionTableDestructor(baseType,argNames) @@ -242,14 +242,14 @@ Description (baseType,argNames,Targ) \ \ /* Table constructor called from the table add function */ \ - void baseType<Targ>::construct##argNames##ConstructorTables() \ + void baseType< Targ >::construct##argNames##ConstructorTables() \ { \ static bool constructed = false; \ \ if (!constructed) \ { \ - baseType<Targ>::argNames##ConstructorTablePtr_ \ - = new baseType<Targ>::argNames##ConstructorTable; \ + baseType< Targ >::argNames##ConstructorTablePtr_ \ + = new baseType< Targ >::argNames##ConstructorTable; \ \ constructed = true; \ } \ @@ -263,12 +263,12 @@ Description (baseType,argNames,Targ) \ \ /* Table destructor called from the table add function destructor */ \ - void baseType<Targ>::destroy##argNames##ConstructorTables() \ + void baseType< Targ >::destroy##argNames##ConstructorTables() \ { \ - if (baseType<Targ>::argNames##ConstructorTablePtr_) \ + if (baseType< Targ >::argNames##ConstructorTablePtr_) \ { \ - delete baseType<Targ>::argNames##ConstructorTablePtr_; \ - baseType<Targ>::argNames##ConstructorTablePtr_ = NULL; \ + delete baseType< Targ >::argNames##ConstructorTablePtr_; \ + baseType< Targ >::argNames##ConstructorTablePtr_ = NULL; \ } \ } @@ -280,8 +280,8 @@ Description (baseType,argNames,Targ) \ \ /* Define the constructor function table */ \ - baseType<Targ>::argNames##ConstructorTable* \ - baseType<Targ>::argNames##ConstructorTablePtr_ = NULL + baseType< Targ >::argNames##ConstructorTable* \ + baseType< Targ >::argNames##ConstructorTablePtr_ = NULL // external use: @@ -294,7 +294,7 @@ Description template<> \ defineTemplatedRunTimeSelectionTablePtr(baseType,argNames,Targ); \ template<> \ - defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ) \ + defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ); \ template<> \ defineTemplatedRunTimeSelectionTableDestructor(baseType,argNames,Targ) diff --git a/src/OpenFOAM/db/typeInfo/className.H b/src/OpenFOAM/db/typeInfo/className.H index c46c3d9ba17b3600e654dad1aefe18c33068c0e6..84536bf1d5e83049056edc963a9ee747e680856d 100644 --- a/src/OpenFOAM/db/typeInfo/className.H +++ b/src/OpenFOAM/db/typeInfo/className.H @@ -44,13 +44,13 @@ Description // Without debug information #define ClassNameNoDebug(TypeNameString) \ static const char* typeName_() { return TypeNameString; } \ - static const ::Foam::word typeName; + static const ::Foam::word typeName //- Add typeName information from argument @a TypeNameString to a namespace. // Without debug information. #define NamespaceNameNoDebug(TypeNameString) \ inline const char* typeName_() { return TypeNameString; } \ - extern const ::Foam::word typeName; + extern const ::Foam::word typeName //- Add typeName information from argument @a TemplateNameString to a template class. // Without debug information. @@ -60,7 +60,7 @@ class TemplateNameString##Name \ public: \ TemplateNameString##Name() {} \ ClassNameNoDebug(#TemplateNameString); \ -}; +} @@ -89,7 +89,7 @@ class TemplateNameString##Name \ public: \ TemplateNameString##Name() {} \ ClassName(#TemplateNameString); \ -}; +} @@ -100,30 +100,30 @@ public: \ //- Define the typeName, with alternative lookup as @a Name #define defineTypeNameWithName(Type, Name) \ - const ::Foam::word Type::typeName(Name); + const ::Foam::word Type::typeName(Name) //- Define the typeName #define defineTypeName(Type) \ - defineTypeNameWithName(Type, Type::typeName_()); + defineTypeNameWithName(Type, Type::typeName_()) #ifdef __INTEL_COMPILER //- Define the typeName as @a Name for template classes # define defineTemplateTypeNameWithName(Type, Name) \ - defineTypeNameWithName(Type, Name); + defineTypeNameWithName(Type, Name) #else //- Define the typeName as @a Name for template classes # define defineTemplateTypeNameWithName(Type, Name) \ template<> \ - defineTypeNameWithName(Type, Name); + defineTypeNameWithName(Type, Name) #endif //- Define the typeName for template classes, useful with typedefs #define defineTemplateTypeName(Type) \ - defineTemplateTypeNameWithName(Type, #Type); + defineTemplateTypeNameWithName(Type, #Type) //- Define the typeName directly for template classes #define defineNamedTemplateTypeName(Type) \ - defineTemplateTypeNameWithName(Type, Type::typeName_()); + defineTemplateTypeNameWithName(Type, Type::typeName_()) @@ -134,31 +134,31 @@ public: \ //- Define the debug information, lookup as @a Name #define defineDebugSwitchWithName(Type, Name, DebugSwitch) \ - int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch)); + int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch)) //- Define the debug information #define defineDebugSwitch(Type, DebugSwitch) \ - defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch); + defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch) #ifdef __INTEL_COMPILER //- Define the debug information for templates, lookup as @a Name # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \ - defineDebugSwitchWithName(Type, Name, DebugSwitch); + defineDebugSwitchWithName(Type, Name, DebugSwitch) #else //- Define the debug information for templates, lookup as @a Name # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \ template<> \ - defineDebugSwitchWithName(Type, Name, DebugSwitch); + defineDebugSwitchWithName(Type, Name, DebugSwitch) #endif //- Define the debug information for templates // Useful with typedefs #define defineTemplateDebugSwitch(Type, DebugSwitch) \ - defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch); + defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch) //- Define the debug information directly for templates #define defineNamedTemplateDebugSwitch(Type, DebugSwitch) \ - defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch); + defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch) @@ -170,21 +170,21 @@ public: \ //- Define the typeName and debug information #define defineTypeNameAndDebug(Type, DebugSwitch) \ defineTypeName(Type); \ - defineDebugSwitch(Type, DebugSwitch); + defineDebugSwitch(Type, DebugSwitch) //- Define the typeName and debug information, lookup as @a Name #define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \ defineTemplateTypeNameWithName(Type, Name); \ - defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch); + defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) //- Define the typeName and debug information for templates, useful with typedefs #define defineTemplateTypeNameAndDebug(Type, DebugSwitch) \ - defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch); + defineTemplateTypeNameAndDebugWithName(Type, #Type, DebugSwitch) //- Define the typeName and debug information for templates #define defineNamedTemplateTypeNameAndDebug(Type, DebugSwitch) \ defineNamedTemplateTypeName(Type); \ - defineNamedTemplateDebugSwitch(Type, DebugSwitch); + defineNamedTemplateDebugSwitch(Type, DebugSwitch) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/cloud/cloud.C b/src/OpenFOAM/fields/cloud/cloud.C index 2dd30b5f3c22355b22672fe07510634fc8cb43d3..f2dbb3be4f60936e9a71b3c60a4511a737897058 100644 --- a/src/OpenFOAM/fields/cloud/cloud.C +++ b/src/OpenFOAM/fields/cloud/cloud.C @@ -29,10 +29,10 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - defineTypeNameAndDebug(cloud, 0); -} +defineTypeNameAndDebug(Foam::cloud, 0); + +const Foam::word Foam::cloud::prefix("lagrangian"); +Foam::word Foam::cloud::defaultName("defaultCloud"); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -42,9 +42,9 @@ Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName) ( IOobject ( - cloudName, + ( cloudName.size() ? cloudName : defaultName ), obr.time().timeName(), - "lagrangian", + prefix, obr, IOobject::NO_READ, IOobject::AUTO_WRITE diff --git a/src/OpenFOAM/fields/cloud/cloud.H b/src/OpenFOAM/fields/cloud/cloud.H index 68743e6e96ddfe6680cd84bc325223841112de27..0c0915464edfb6f92a00958fb473f0d9c7620e00 100644 --- a/src/OpenFOAM/fields/cloud/cloud.H +++ b/src/OpenFOAM/fields/cloud/cloud.H @@ -47,7 +47,7 @@ namespace Foam class mapPolyMesh; /*---------------------------------------------------------------------------*\ - Class cloud Declaration + Class cloud Declaration \*---------------------------------------------------------------------------*/ class cloud @@ -69,15 +69,16 @@ public: //- Runtime type information TypeName("cloud"); + //- The prefix to local: %lagrangian + static const word prefix; + + //- The default cloud name: %defaultCloud + static word defaultName; // Constructors //- Construct for the given objectRegistry and named cloud instance - cloud - ( - const objectRegistry& obr, - const word& cloudName = "defaultCloud" - ); + cloud(const objectRegistry&, const word& cloudName = ""); // Destructor diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C index 02fb26d52c697b1e810f72ef2a30bb06878c773d..c5b8c8334d1fdda7847c8569cb25c5b020b422f2 100644 --- a/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C @@ -100,6 +100,7 @@ void processorPointPatchField<Type>::initSwapAdd(Field<Type>& pField) const { if (Pstream::parRun()) { + // Get internal field into my point order Field<Type> pf(this->patchInternalField(pField)); OPstream::write @@ -130,11 +131,7 @@ void processorPointPatchField<Type>::swapAdd(Field<Type>& pField) const if (doTransform()) { - const labelList& nonGlobalPatchPoints = - procPatch_.nonGlobalPatchPoints(); - const processorPolyPatch& ppp = procPatch_.procPolyPatch(); - const labelListList& pointFaces = ppp.pointFaces(); const tensorField& forwardT = ppp.forwardT(); if (forwardT.size() == 1) @@ -143,6 +140,10 @@ void processorPointPatchField<Type>::swapAdd(Field<Type>& pField) const } else { + const labelList& nonGlobalPatchPoints = + procPatch_.nonGlobalPatchPoints(); + const labelListList& pointFaces = ppp.pointFaces(); + forAll(nonGlobalPatchPoints, pfi) { pnf[pfi] = transform diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C index aa6d0d750fe14abf03ddff76ca5ca31d070cd7b3..9ea1307ee151b0bce2f819e30e2aa4428f3d5249 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C @@ -67,11 +67,25 @@ Foam::interpolationTable<Type>::interpolationTable() template<class Type> -Foam::interpolationTable<Type>::interpolationTable(const fileName& fn) +Foam::interpolationTable<Type>::interpolationTable +( + const List<Tuple2<scalar, Type> >& values, + const boundsHandling bounds, + const fileName& fName +) +: + List<Tuple2<scalar, Type> >(values), + boundsHandling_(bounds), + fileName_(fName) +{} + + +template<class Type> +Foam::interpolationTable<Type>::interpolationTable(const fileName& fName) : List<Tuple2<scalar, Type> >(), boundsHandling_(interpolationTable::WARN), - fileName_(fn) + fileName_(fName) { readTable(); } diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H index 2637ccf808022c4490fe356317686c0867dd62d0..884c3cabd70261fecdc9768a8f4d2f5ef6848dae 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H @@ -102,8 +102,16 @@ public: //- Construct null interpolationTable(); + //- Construct from components + interpolationTable + ( + const List<Tuple2<scalar, Type> >& values, + const boundsHandling bounds, + const fileName& fName + ); + //- Construct given the name of the file containing the table of data - interpolationTable(const fileName& fn); + interpolationTable(const fileName& fName); //- Construct by reading the fileName and boundsHandling from dictionary // and read the table from that file. diff --git a/src/OpenFOAM/matrices/solution/solution.C b/src/OpenFOAM/matrices/solution/solution.C index 8672f32753db3db085a25cffa0bc1ae9d9df7ba9..8c37d28b427786e3b932ed6bccaf55c5c0fcb1ed 100644 --- a/src/OpenFOAM/matrices/solution/solution.C +++ b/src/OpenFOAM/matrices/solution/solution.C @@ -162,10 +162,7 @@ bool Foam::solution::read() relaxationFactors_ = dict.subDict("relaxationFactors"); } - if (relaxationFactors_.found("default")) - { - relaxationFactors_.lookup("default") >> defaultRelaxationFactor_; - } + relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_); if (dict.found("solvers")) { @@ -227,7 +224,7 @@ Foam::scalar Foam::solution::relaxationFactor(const word& name) const { FatalIOErrorIn ( - "Foam::solution::relaxationFactor(const word& name)", + "Foam::solution::relaxationFactor(const word&)", relaxationFactors_ ) << "Cannot find relaxationFactor for '" << name << "' or a suitable default value." @@ -242,7 +239,7 @@ const Foam::dictionary& Foam::solution::solverDict(const word& name) const { if (debug) { - InfoIn("solution::solverDict(const word& name)") + InfoIn("solution::solverDict(const word&)") << "Lookup solver for " << name << endl; } @@ -254,7 +251,7 @@ const Foam::dictionary& Foam::solution::solver(const word& name) const { if (debug) { - InfoIn("solution::solver(const word& name)") + InfoIn("solution::solver(const word&)") << "Lookup solver for " << name << endl; } diff --git a/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processor/processorPointPatch.C b/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processor/processorPointPatch.C index 2e3e001ca9184a4f674e8ccf6a3785087a43ca23..eee664b1fb6b9f6ff96106e62e6e9bea746a79ef 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processor/processorPointPatch.C +++ b/src/OpenFOAM/meshes/pointMesh/pointPatches/constraint/processor/processorPointPatch.C @@ -64,7 +64,7 @@ void Foam::processorPointPatch::initGeometry() } else { - // Slave side. Create the reversed patch and pick up its points + // Slave side. Create the reversed patch and pick up its points // so that the order is correct const polyPatch& pp = patch(); @@ -236,6 +236,7 @@ void processorPointPatch::initPatchPatchPoints() ); toNeighbProc + << ppmp.size() // number of points for checking << patchPatchPoints << patchPatchPointNormals; @@ -257,13 +258,33 @@ void Foam::processorPointPatch::calcPatchPatchPoints() neighbProcNo() ); + label nbrNPoints(readLabel(fromNeighbProc)); labelListList patchPatchPoints(fromNeighbProc); List<List<vector> > patchPatchPointNormals(fromNeighbProc); pointBoundaryMesh& pbm = const_cast<pointBoundaryMesh&>(boundaryMesh()); - const labelList& ppmp = meshPoints(); + // Simple check for the very rare situation when not the same number + // of points on both sides. This can happen with decomposed cyclics. + // If on one side the cyclic shares a point with proc faces coming from + // internal faces it will have a different number of points from + // the situation where the cyclic and the 'normal' proc faces are fully + // separate. + if (nbrNPoints != ppmp.size()) + { + WarningIn("processorPointPatch::calcPatchPatchPoints()") + << "Processor patch " << name() + << " has " << ppmp.size() << " points; coupled patch has " + << nbrNPoints << " points." << endl + << " (usually due to decomposed cyclics)." + << " This might give problems" << endl + << " when using point fields (interpolation, mesh motion)." + << endl; + } + + + // Loop over the patches looking for other patches that share points forAll(patchPatchPoints, patchi) { diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C index 00091293fa7cdb23283b3951acd5cff96af38d8f..70eafc70a88d8c4ed96982789ae03e8f916fc193 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C @@ -143,7 +143,7 @@ void Foam::processorPolyPatch::initGeometry() ( Pstream::blocking, neighbProcNo(), - 3*(sizeof(label) + size()*sizeof(vector) + sizeof(float)) + 3*(sizeof(label) + size()*sizeof(vector) + sizeof(scalar)) ); toNeighbProc @@ -163,7 +163,7 @@ void Foam::processorPolyPatch::calcGeometry() ( Pstream::blocking, neighbProcNo(), - 3*(sizeof(label) + size()*sizeof(vector) + sizeof(float)) + 3*(sizeof(label) + size()*sizeof(vector) + sizeof(scalar)) ); fromNeighbProc >> neighbFaceCentres_ diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H index f0bd005b476d9d6122fe8045df53fbddf17acdae..c741b0839ec91863cb47c5071a1c3d08c03c2a33 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H @@ -330,7 +330,9 @@ public: // Addressing into mesh - //- Return labelList of mesh points in patch + //- Return labelList of mesh points in patch. They are constructed + // walking through the faces in incremental order and not sorted + // anymore. const labelList& meshPoints() const; //- Mesh point map. Given the global point index find its diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C index 9941b024598b0f8346310f88e0680c1805210b46..30cffb6310a0e3b74fa5641b8d9ed1641cb6dd15 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C @@ -67,30 +67,56 @@ calcMeshData() const // number of faces in the patch Map<label> markedPoints(4*this->size()); - // if the point is used, set the mark to 1 + + // Important: + // ~~~~~~~~~~ + // In <= 1.5 the meshPoints would be in increasing order but this gives + // problems in processor point synchronisation where we have to find out + // how the opposite side would have allocated points. + + ////- 1.5 code: + //// if the point is used, set the mark to 1 + //forAll (*this, faceI) + //{ + // const Face& curPoints = this->operator[](faceI); + // + // forAll (curPoints, pointI) + // { + // markedPoints.insert(curPoints[pointI], -1); + // } + //} + // + //// Create the storage and store the meshPoints. Mesh points are + //// the ones marked by the usage loop above + //meshPointsPtr_ = new labelList(markedPoints.toc()); + //labelList& pointPatch = *meshPointsPtr_; + // + //// Sort the list to preserve compatibility with the old ordering + //sort(pointPatch); + // + //// For every point in map give it its label in mesh points + //forAll (pointPatch, pointI) + //{ + // markedPoints.find(pointPatch[pointI])() = pointI; + //} + + //- Unsorted version: + DynamicList<label> meshPoints(2*this->size()); forAll (*this, faceI) { const Face& curPoints = this->operator[](faceI); forAll (curPoints, pointI) { - markedPoints.insert(curPoints[pointI], -1); + if (markedPoints.insert(curPoints[pointI], meshPoints.size())) + { + meshPoints.append(curPoints[pointI]); + } } } + // Transfer to straight list (reuses storage) + meshPointsPtr_ = new labelList(meshPoints, true); - // Create the storage and store the meshPoints. Mesh points are - // the ones marked by the usage loop above - meshPointsPtr_ = new labelList(markedPoints.toc()); - labelList& pointPatch = *meshPointsPtr_; - - // Sort the list to preserve compatibility with the old ordering - sort(pointPatch); - - // For every point in map give it its label in mesh points - forAll (pointPatch, pointI) - { - markedPoints.find(pointPatch[pointI])() = pointI; - } // Create local faces. Note that we start off from copy of original face // list (even though vertices are overwritten below). This is done so diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 9b7b449a226452dab9f93d65966c3f472659bc2d..8648532a32d30d5609cccee44d57677d8bc13cbb 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -38,20 +38,20 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] = "off", "on", "no", "yes", "n", "y", + "none", "true", // is there a reasonable counterpart to "none"? "invalid" }; // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // -Foam::Switch::switchType Foam::Switch::asEnum(const bool val) +Foam::Switch::switchType Foam::Switch::asEnum(const bool b) { - return val ? Switch::TRUE : Switch::FALSE; + return b ? Switch::TRUE : Switch::FALSE; } -Foam::Switch::switchType -Foam::Switch::asEnum +Foam::Switch::switchType Foam::Switch::asEnum ( const std::string& str, const bool allowInvalid @@ -61,8 +61,8 @@ Foam::Switch::asEnum { if (str == names[sw]) { - // convert y/n to yes/no (perhaps should deprecate y/n) - if (sw == Switch::NO_1) + // convert n/y to no/yes (perhaps should deprecate y/n) + if (sw == Switch::NO_1 || sw == Switch::NONE) { return Switch::NO; } @@ -90,6 +90,7 @@ Foam::Switch::asEnum bool Foam::Switch::asBool(const switchType sw) { + // relies on (INVALID & 0x1) evaluating to false return (sw & 0x1); } @@ -103,13 +104,19 @@ bool Foam::Switch::asBool // allow invalid values, but catch after for correct error message switchType sw = asEnum(str, true); - if (sw == Switch::INVALID && !allowInvalid) + if (sw == Switch::INVALID) { - FatalErrorIn("Switch::asBool(const std::string&)") - << "unknown switch word " << str << nl - << abort(FatalError); + if (!allowInvalid) + { + FatalErrorIn("Switch::asBool(const std::string&)") + << "unknown switch word " << str << nl + << abort(FatalError); + } + + return false; } + return (sw & 0x1); } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index b37e2bbb403d5e50d381c4a13926fef0e02b8c44..adda09cf4ecfa2895f61f167f3d66d300b79b845 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -27,7 +27,7 @@ Class Description A simple wrapper around bool so that it can be read as a word: - true/false, on/off, yes/no or y/n. + true/false, on/off, yes/no or y/n or none. SourceFiles Switch.C @@ -80,6 +80,7 @@ public: OFF = 2, ON = 3, NO = 4, YES = 5, NO_1 = 6, YES_1 = 7, + NONE = 8, PLACEHOLDER = 9, INVALID }; @@ -176,9 +177,10 @@ public: } //- Assignment from bool - void operator=(const bool b) + const Switch& operator=(const bool b) { switch_ = (b ? Switch::TRUE : Switch::FALSE); + return *this; } diff --git a/src/OpenFOAM/primitives/complex/complex.H b/src/OpenFOAM/primitives/complex/complex.H index 1def519a992578a49e90c6799012fe5b6025b63c..ae94a75b66883983adf7e1445c0c024b8f789e2a 100644 --- a/src/OpenFOAM/primitives/complex/complex.H +++ b/src/OpenFOAM/primitives/complex/complex.H @@ -51,13 +51,13 @@ namespace Foam class complex; -inline scalar magSqr(const complex& c); -inline complex sqr(const complex& c); -inline scalar mag(const complex& c); -inline const complex& max(const complex& c1, const complex& c2); -inline const complex& min(const complex& c1, const complex& c2); -inline complex limit(const complex& c1, const complex& c2); -inline const complex& sum(const complex& c); +inline scalar magSqr(const complex&); +inline complex sqr(const complex&); +inline scalar mag(const complex&); +inline const complex& max(const complex&, const complex&); +inline const complex& min(const complex&, const complex&); +inline complex limit(const complex&, const complex&); +inline const complex& sum(const complex&); inline complex operator+(const complex&, const complex&); inline complex operator-(const complex&); inline complex operator-(const complex&, const complex&); @@ -67,8 +67,8 @@ inline complex operator*(const scalar, const complex&); inline complex operator*(const complex&, const scalar); inline complex operator/(const complex&, const scalar); inline complex operator/(const scalar, const complex&); -Istream& operator>>(Istream& is, complex&); -Ostream& operator<<(Ostream& os, const complex& C); +Istream& operator>>(Istream&, complex&); +Ostream& operator<<(Ostream&, const complex&); /*---------------------------------------------------------------------------*\ @@ -127,13 +127,13 @@ public: // Member operators - inline void operator=(const complex&); + inline const complex& operator=(const complex&); inline void operator+=(const complex&); inline void operator-=(const complex&); inline void operator*=(const complex&); inline void operator/=(const complex&); - inline void operator=(const scalar); + inline const complex& operator=(const scalar); inline void operator+=(const scalar); inline void operator-=(const scalar); inline void operator*=(const scalar); @@ -150,12 +150,12 @@ public: friend scalar magSqr(const complex& c); friend complex sqr(const complex& c); friend scalar mag(const complex& c); - friend const complex& max(const complex& c1, const complex& c2); - friend const complex& min(const complex& c1, const complex& c2); + friend const complex& max(const complex&, const complex&); + friend const complex& min(const complex&, const complex&); - friend complex limit(const complex& c1, const complex& c2); + friend complex limit(const complex&, const complex&); - friend const complex& sum(const complex& c); + friend const complex& sum(const complex&); // Friend operators diff --git a/src/OpenFOAM/primitives/complex/complexI.H b/src/OpenFOAM/primitives/complex/complexI.H index 8e693eb7441aa777f4dab16eda6fb5c69fb2356f..501a11519a716ffa4b853739b94dd9f62ea906bd 100644 --- a/src/OpenFOAM/primitives/complex/complexI.H +++ b/src/OpenFOAM/primitives/complex/complexI.H @@ -76,10 +76,11 @@ inline complex complex::conjugate() const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline void complex::operator=(const complex& c) +inline const complex& complex::operator=(const complex& c) { re = c.re; im = c.im; + return *this; } @@ -109,10 +110,11 @@ inline void complex::operator/=(const complex& c) } -inline void complex::operator=(const scalar s) +inline const complex& complex::operator=(const scalar s) { re = s; im = 0.0; + return *this; } @@ -234,8 +236,8 @@ inline complex operator+(const complex& c1, const complex& c2) { return complex ( - c1.re+c2.re, - c1.im+c2.im + c1.re + c2.re, + c1.im + c2.im ); } @@ -254,8 +256,8 @@ inline complex operator-(const complex& c1, const complex& c2) { return complex ( - c1.re-c2.re, - c1.im-c2.im + c1.re - c2.re, + c1.im - c2.im ); } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index c6faa26073643fadf0281c180a1a7e511504cba4..6d930e9fe8bc7b3e18d4e3e3a701c436a96c0c90 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -196,36 +196,41 @@ Foam::word Foam::fileName::component // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -void Foam::fileName::operator=(const fileName& str) +const Foam::fileName& Foam::fileName::operator=(const fileName& str) { string::operator=(str); + return *this; } -void Foam::fileName::operator=(const word& str) +const Foam::fileName& Foam::fileName::operator=(const word& str) { string::operator=(str); + return *this; } -void Foam::fileName::operator=(const string& str) +const Foam::fileName& Foam::fileName::operator=(const string& str) { string::operator=(str); stripInvalid(); + return *this; } -void Foam::fileName::operator=(const std::string& str) +const Foam::fileName& Foam::fileName::operator=(const std::string& str) { string::operator=(str); stripInvalid(); + return *this; } -void Foam::fileName::operator=(const char* str) +const Foam::fileName& Foam::fileName::operator=(const char* str) { string::operator=(str); stripInvalid(); + return *this; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index ccb2d3caa440ccbb0500f6122c2358d60f9db008..a47f53ed8007f5f5240516bee7c77b5cfd7c2de1 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -158,11 +158,11 @@ public: // Assignment - void operator=(const fileName&); - void operator=(const word&); - void operator=(const string&); - void operator=(const std::string&); - void operator=(const char*); + const fileName& operator=(const fileName&); + const fileName& operator=(const word&); + const fileName& operator=(const string&); + const fileName& operator=(const std::string&); + const fileName& operator=(const char*); // IOstream operators diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index 29f851c738df7fa002dd175ce9cf7f5774be23db..8bfd9b4d09e605bc55971de5e573aeccb876ce07 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -106,12 +106,12 @@ public: // Assignment - inline void operator=(const keyType&); - inline void operator=(const word&); + inline const keyType& operator=(const keyType&); + inline const keyType& operator=(const word&); //- Assign from regular expression. - inline void operator=(const string&); - inline void operator=(const char*); + inline const keyType& operator=(const string&); + inline const keyType& operator=(const char*); // IOstream operators diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H index 391f666affed2881434e58e5c988da1054950b57..61828468a6ad809867da129170a56901086cb0d4 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H @@ -89,34 +89,38 @@ inline bool Foam::keyType::isPattern() const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline void Foam::keyType::operator=(const keyType& s) +inline const Foam::keyType& Foam::keyType::operator=(const keyType& s) { // Bypass checking string::operator=(s); isPattern_ = s.isPattern_; + return *this; } -inline void Foam::keyType::operator=(const word& s) +inline const Foam::keyType& Foam::keyType::operator=(const word& s) { word::operator=(s); isPattern_ = false; + return *this; } -inline void Foam::keyType::operator=(const string& s) +inline const Foam::keyType& Foam::keyType::operator=(const string& s) { // Bypass checking string::operator=(s); isPattern_ = true; + return *this; } -inline void Foam::keyType::operator=(const char* s) +inline const Foam::keyType& Foam::keyType::operator=(const char* s) { // Bypass checking string::operator=(s); isPattern_ = false; + return *this; } diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 247b031d6c65cc3ac998688653f0990f28bbb282..97c6dd4d4dd7e50a6670b27704e8a9b24b57e1fb 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -144,6 +144,9 @@ public: template<class String> static inline string quotemeta(const string&, const char quote='\\'); + //- Avoid masking the normal std::string replace + using std::string::replace; + //- Replace first occurence of sub-string oldStr with newStr // starting at start string& replace diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 1c74119a279176c1a2efb124ac97701ac189a748..5c910b7891bb52a1c205bfbf94dfb9a1c66ce6c3 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -117,10 +117,10 @@ public: // Assignment - inline void operator=(const word&); - inline void operator=(const string&); - inline void operator=(const std::string&); - inline void operator=(const char*); + inline const word& operator=(const word&); + inline const word& operator=(const string&); + inline const word& operator=(const std::string&); + inline const word& operator=(const char*); // Friend Operators diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index b1daf2752c75181e1f2f246125f395053ef78700..c7f9cdb87812c7c9cb7f31ff5e277b2ba8710b1e 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -132,30 +132,34 @@ inline bool Foam::word::valid(char c) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline void Foam::word::operator=(const word& q) +inline const Foam::word& Foam::word::operator=(const word& q) { string::operator=(q); + return *this; } -inline void Foam::word::operator=(const string& q) +inline const Foam::word& Foam::word::operator=(const string& q) { string::operator=(q); stripInvalid(); + return *this; } -inline void Foam::word::operator=(const std::string& q) +inline const Foam::word& Foam::word::operator=(const std::string& q) { string::operator=(q); stripInvalid(); + return *this; } -inline void Foam::word::operator=(const char* q) +inline const Foam::word& Foam::word::operator=(const char* q) { string::operator=(q); stripInvalid(); + return *this; } diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index aee6c3a883f60f390d8f8696c6522e2c6b65ebde..741d76e553d73599a92bef534eb866bea2fd7ae9 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -41,7 +41,7 @@ Description Note If the string contents are changed - eg, by the operator+=() or by string::replace(), etc - it will be necessary to use compile() or - recompile() to sychronize the regular expression. + recompile() to synchronize the regular expression. SourceFiles wordRe.C @@ -187,22 +187,22 @@ public: //- Assign copy // Always case sensitive - inline void operator=(const wordRe&); + inline const wordRe& operator=(const wordRe&); //- Copy word, never a regular expression - inline void operator=(const word&); + inline const wordRe& operator=(const word&); //- Copy string, auto-test for regular expression // Always case sensitive - inline void operator=(const string&); + inline const wordRe& operator=(const string&); //- Copy string, auto-test for regular expression // Always case sensitive - inline void operator=(const std::string&); + inline const wordRe& operator=(const std::string&); //- Copy string, auto-test for regular expression // Always case sensitive - inline void operator=(const char*); + inline const wordRe& operator=(const char*); // IOstream operators diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H index b84694ba82b077c6d1380dce5dc8393264cbfa02..7f242eb2c5ea7f98a936e0f257e52b5ccf923eb1 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H @@ -213,7 +213,7 @@ inline void Foam::wordRe::set(const char* str, const compOption opt) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline void Foam::wordRe::operator=(const wordRe& str) +inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str) { string::operator=(str); @@ -225,34 +225,39 @@ inline void Foam::wordRe::operator=(const wordRe& str) { re_.clear(); } + return *this; } -inline void Foam::wordRe::operator=(const word& str) +inline const Foam::wordRe& Foam::wordRe::operator=(const word& str) { word::operator=(str); re_.clear(); + return *this; } -inline void Foam::wordRe::operator=(const string& str) +inline const Foam::wordRe& Foam::wordRe::operator=(const string& str) { string::operator=(str); compile(DETECT); // auto-detect regex + return *this; } -inline void Foam::wordRe::operator=(const std::string& str) +inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str) { string::operator=(str); compile(DETECT); // auto-detect regex + return *this; } -inline void Foam::wordRe::operator=(const char* str) +inline const Foam::wordRe& Foam::wordRe::operator=(const char* str) { string::operator=(str); compile(DETECT); // auto-detect regex + return *this; } diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H index 83e7dd9c69a351559e6fb234651c4e228b8ece54..9ae910b5a71c19965794151be42ef0d9759603d4 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H @@ -38,7 +38,6 @@ SourceFiles #include "autoPtr.H" #include "dictionary.H" -#include "pointField.H" #include "boolList.H" #include "wallPoint.H" #include "searchableSurfaces.H" diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index aa7ecddf8b8660aef0699fbdeea5e0ac0992f715..011417c29ecd92107e34ff596c9ba506a60cb50a 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -29,7 +29,6 @@ Description #include "autoSnapDriver.H" #include "Time.H" -#include "pointFields.H" #include "motionSmoother.H" #include "polyTopoChange.H" #include "OFstream.H" @@ -1389,11 +1388,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::repatchToSurface } } - pointField localFaceCentres(pp.size()); - forAll(pp, i) - { - localFaceCentres[i] = mesh.faceCentres()[pp.addressing()[i]]; - } + pointField localFaceCentres(mesh.faceCentres(), pp.addressing()); // Get nearest surface and region labelList hitSurface; diff --git a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C index 24c7819d8d6b50ec92b4b8d6ccd97bc0356f7d1c..d42ac05b2233d1657f30a6511c825344c531924e 100644 --- a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C +++ b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C @@ -1242,7 +1242,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::refine // Do refinement of consistent set of cells followed by truncation and // load balancing. Foam::autoPtr<Foam::mapDistributePolyMesh> - Foam::meshRefinement::refineAndBalance +Foam::meshRefinement::refineAndBalance ( const string& msg, decompositionMethod& decomposer, diff --git a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C index 9c06ccddea6156ba9ff0c1215cf0c6af1cd130ad..856f2ba9239aa3f372fbb511fa9c0693ba519817 100644 --- a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C +++ b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C @@ -193,7 +193,7 @@ void Foam::shellSurfaces::orient() if (hasSurface) { - const point outsidePt = 2 * overallBb.span(); + const point outsidePt = overallBb.max() + overallBb.span(); //Info<< "Using point " << outsidePt << " to orient shells" << endl; diff --git a/src/conversion/meshReader/meshReaderAux.C b/src/conversion/meshReader/meshReaderAux.C index a0c179a8be1e02543d66dc3ea8f8bb56826c4e2a..856d704857cdabb3a6ffbdfcc9660041ee42ec9b 100644 --- a/src/conversion/meshReader/meshReaderAux.C +++ b/src/conversion/meshReader/meshReaderAux.C @@ -97,10 +97,8 @@ void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const OFstream os(ioObj.objectPath()); ioObj.writeHeader(os); - os << interfaces_ - << "// *************************************" - << "************************************ //" - << endl; + os << interfaces_; + ioObj.writeEndDivider(os); } diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C index aff80a2ac3b2fd1fc8a0e6cdf266e0b417093bc4..d0b81bc8c2dc70d60072da72ddd2189be24fa651 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C @@ -32,6 +32,7 @@ defineTypeNameAndDebug(Foam::dynamicFvMesh, 0); defineRunTimeSelectionTable(Foam::dynamicFvMesh, IOobject); + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dynamicFvMesh::dynamicFvMesh(const IOobject& io) @@ -45,4 +46,5 @@ Foam::dynamicFvMesh::dynamicFvMesh(const IOobject& io) Foam::dynamicFvMesh::~dynamicFvMesh() {} + // ************************************************************************* // diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H index dc437ea48e7b7dce9e60a68847e00c693c09bf3d..04d7a69e59686f425d0f5ea460b077c16abff29c 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H @@ -26,7 +26,7 @@ Class Foam::dynamicFvMesh Description - The dynamicFvMesh is .. + Abstract base class for geometry and/or topology changing fvMesh. SourceFiles dynamicFvMesh.C diff --git a/src/dynamicMesh/attachDetach/attachInterface.C b/src/dynamicMesh/attachDetach/attachInterface.C index 21e4f882fd69e6b67f0a15d29627e1b732cf93ee..4c4294f8f3768cdb3d9d4ed69481c50dacaee738 100644 --- a/src/dynamicMesh/attachDetach/attachInterface.C +++ b/src/dynamicMesh/attachDetach/attachInterface.C @@ -207,7 +207,20 @@ void Foam::attachDetach::attachInterface mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID) ]; } - + + + label patchID = mesh.boundaryMesh().whichPatch(curFaceID); + label neiCell; + if (patchID == -1) + { + neiCell = nei[curFaceID]; + } + else + { + neiCell = -1; + } + + // Modify the face ref.setAction ( @@ -216,9 +229,9 @@ void Foam::attachDetach::attachInterface newFace, // modified face curFaceID, // label of face being modified own[curFaceID], // owner - nei[curFaceID], // neighbour + neiCell, // neighbour false, // face flip - mesh.boundaryMesh().whichPatch(curFaceID),// patch for face + patchID, // patch for face false, // remove from zone modifiedFaceZone, // zone for face modifiedFaceZoneFlip // face flip in zone diff --git a/src/dynamicMesh/attachDetach/detachInterface.C b/src/dynamicMesh/attachDetach/detachInterface.C index 7e0ac0a933aa80310efc458eac245e2c58e56e5b..6b57ccb6858b7f9089d0d47cb9b435f0beffdfef 100644 --- a/src/dynamicMesh/attachDetach/detachInterface.C +++ b/src/dynamicMesh/attachDetach/detachInterface.C @@ -73,6 +73,37 @@ void Foam::attachDetach::detachInterface const polyMesh& mesh = topoChanger().mesh(); const faceZoneMesh& zoneMesh = mesh.faceZones(); + // Check that zone is in increasing order (needed since adding faces + // in same order - otherwise polyTopoChange face ordering will mess up + // correspondence) + if (debug) + { + const labelList& faceLabels = zoneMesh[faceZoneID_.index()]; + if (faceLabels.size() > 0) + { + for (label i = 1; i < faceLabels.size(); i++) + { + if (faceLabels[i] <= faceLabels[i-1]) + { + FatalErrorIn + ( + "attachDetach::detachInterface" + "(polyTopoChange&) const" + ) << "faceZone " << zoneMesh[faceZoneID_.index()].name() + << " does not have mesh face labels in" + << " increasing order." << endl + << "Face label " << faceLabels[i] + << " at position " << i + << " is smaller than the previous value " + << faceLabels[i-1] + << exit(FatalError); + } + } + } + } + + + const primitiveFacePatch& masterFaceLayer = zoneMesh[faceZoneID_.index()](); const pointField& points = mesh.points(); const labelListList& meshEdgeFaces = mesh.edgeFaces(); @@ -109,14 +140,11 @@ void Foam::attachDetach::detachInterface if (edgeIsInternal) { -// Pout<< "Internal edge found: (" << mp[zoneLocalEdges[curEdgeID].start()] << " " << mp[zoneLocalEdges[curEdgeID].end()] << ")" << endl; + const edge& e = zoneLocalEdges[curEdgeID]; // Reset the point creation - addedPoints[zoneLocalEdges[curEdgeID].start()] = - mp[zoneLocalEdges[curEdgeID].start()]; - - addedPoints[zoneLocalEdges[curEdgeID].end()] = - mp[zoneLocalEdges[curEdgeID].end()]; + addedPoints[e.start()] = mp[e.start()]; + addedPoints[e.end()] = mp[e.end()]; } } // Pout << "addedPoints before point creation: " << addedPoints << endl; @@ -137,7 +165,10 @@ void Foam::attachDetach::detachInterface true // supports a cell ) ); -// Pout << "Adding point " << points[mp[pointI]] << " for original point " << mp[pointI] << endl; + //Pout<< "Adding point " << addedPoints[pointI] + // << " coord1:" << points[mp[pointI]] + // << " coord2:" << masterFaceLayer.localPoints()[pointI] + // << " for original point " << mp[pointI] << endl; } } @@ -185,6 +216,7 @@ void Foam::attachDetach::detachInterface ); // Add renumbered face into the slave patch + //label addedFaceI = ref.setAction ( polyAddFace @@ -201,7 +233,15 @@ void Foam::attachDetach::detachInterface false // zone flip ) ); -// Pout << "Flip. Modifying face: " << faces[curFaceID].reverseFace() << " next to cell: " << nei[curFaceID] << " and adding face: " << newFace << " next to cell: " << own[curFaceID] << endl; + //{ + // pointField newPts(ref.points()); + //Pout<< "Flip. Modifying face: " << ref.faces()[curFaceID] + // << " fc:" << ref.faces()[curFaceID].centre(newPts) + // << " next to cell: " << nei[curFaceID] + // << " and adding face: " << newFace + // << " fc:" << ref.faces()[addedFaceI].centre(newPts) + // << " next to cell: " << own[curFaceID] << endl; + //} } else { @@ -223,6 +263,7 @@ void Foam::attachDetach::detachInterface ); // Add renumbered face into the slave patch + //label addedFaceI = ref.setAction ( polyAddFace @@ -239,7 +280,15 @@ void Foam::attachDetach::detachInterface false // face flip in zone ) ); -// Pout << "No flip. Modifying face: " << faces[curFaceID] << " next to cell: " << own[curFaceID] << " and adding face: " << newFace << " next to cell: " << nei[curFaceID] << endl; + //{ + // pointField newPts(ref.points()); + //Pout<< "No flip. Modifying face: " << ref.faces()[curFaceID] + // << " fc:" << ref.faces()[curFaceID].centre(newPts) + // << " next to cell: " << own[curFaceID] + // << " and adding face: " << newFace + // << " fc:" << ref.faces()[addedFaceI].centre(newPts) + // << " next to cell: " << nei[curFaceID] << endl; + //} } } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C index f317573d8a0bdb8bad9908df187841ad100e3c65..d2728f8b9d634d40aa563b009502d909d9c493fe 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C @@ -1464,6 +1464,11 @@ void Foam::polyTopoChange::resetZones addressing[zoneI][nPoints[zoneI]++] = iter.key(); } + // Sort the addressing + forAll(addressing, zoneI) + { + stableSort(addressing[zoneI]); + } // So now we both have old zones and the new addressing. // Invert the addressing to get pointZoneMap. @@ -1551,6 +1556,28 @@ void Foam::polyTopoChange::resetZones addressing[zoneI][index] = faceI; flipMode[zoneI][index] = faceZoneFlip_[faceI]; } + // Sort the addressing + forAll(addressing, zoneI) + { + labelList newToOld; + sortedOrder(addressing[zoneI], newToOld); + { + labelList newAddressing(addressing[zoneI].size()); + forAll(newAddressing, i) + { + newAddressing[i] = addressing[zoneI][newToOld[i]]; + } + addressing[zoneI].transfer(newAddressing); + } + { + boolList newFlipMode(flipMode[zoneI].size()); + forAll(newFlipMode, i) + { + newFlipMode[i] = flipMode[zoneI][newToOld[i]]; + } + flipMode[zoneI].transfer(newFlipMode); + } + } // So now we both have old zones and the new addressing. // Invert the addressing to get faceZoneFaceMap. @@ -1644,6 +1671,11 @@ void Foam::polyTopoChange::resetZones addressing[zoneI][nCells[zoneI]++] = cellI; } } + // Sort the addressing + forAll(addressing, zoneI) + { + stableSort(addressing[zoneI]); + } // So now we both have old zones and the new addressing. // Invert the addressing to get cellZoneMap. diff --git a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C index f10681e48a6c843f0d72d8659194e2ea4ab362b2..76267d4fa6a86f2083f6720b2eb58fe255610d4d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C @@ -229,14 +229,8 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs() void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const { fvPatchScalarField::write(os); - if (UName_ != "U") - { - os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl; - } - if (phiName_ != "phi") - { - os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; - } + writeEntryIfDifferent<word>(os, "U", "U", UName_); + writeEntryIfDifferent<word>(os, "phi", "phi", phiName_); os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl; os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl; diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index 2134420eadf769f6e09dd30b5dd3d622757714ec..0fcf2e626d61b212bd0efec2983c0766da413146 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -1168,7 +1168,7 @@ void Foam::fvMatrix<Type>::operator*= } -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template<class Type> void Foam::checkMethod @@ -1297,7 +1297,27 @@ Foam::lduMatrix::solverPerformance Foam::solve(const tmp<fvMatrix<Type> >& tfvm) } -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // +template<class Type> +Foam::tmp<Foam::fvMatrix<Type> > Foam::correction +( + const fvMatrix<Type>& A +) +{ + return A - (A & A.psi()); +} + + +template<class Type> +Foam::tmp<Foam::fvMatrix<Type> > Foam::correction +( + const tmp<fvMatrix<Type> >& tA +) +{ + return tA - (tA() & tA().psi()); +} + + +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::operator== diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index e14c0fe4972dc0545cae050f75b3a04c8a92437d..8ae502cb570fb03fdf42d5f9157ca86f58cf5bcb 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -547,6 +547,18 @@ template<class Type> lduMatrix::solverPerformance solve(const tmp<fvMatrix<Type> >&); +//- Return the correction form of the given matrix +// by subtracting the matrix multiplied by the current field +template<class Type> +tmp<fvMatrix<Type> > correction(const fvMatrix<Type>&); + + +//- Return the correction form of the given temporary matrix +// by subtracting the matrix multiplied by the current field +template<class Type> +tmp<fvMatrix<Type> > correction(const tmp<fvMatrix<Type> >&); + + // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // template<class Type> diff --git a/src/fvMotionSolver/Make/files b/src/fvMotionSolver/Make/files index a49366e8adcaf17b46d2aa170c03ae4eb72b3f6b..41f31c0ecc79dd3972e667e08041002a0e9099ae 100644 --- a/src/fvMotionSolver/Make/files +++ b/src/fvMotionSolver/Make/files @@ -1,5 +1,6 @@ fvMotionSolvers/fvMotionSolver/fvMotionSolver.C fvMotionSolvers/velocity/laplacian/velocityLaplacianFvMotionSolver.C +fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C index 68f7280c19057c926fced877339a380ee8b4c199..8c536691819eebc97682f036ab9cdfc842d25508 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C @@ -55,25 +55,10 @@ namespace Foam Foam::displacementSBRStressFvMotionSolver::displacementSBRStressFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ) - ), + displacementFvMotionSolver(mesh, is), pointDisplacement_ ( IOobject @@ -132,7 +117,7 @@ Foam::displacementSBRStressFvMotionSolver::curPoints() const tmp<pointField> tcurPoints ( - points0_ + pointDisplacement_.internalField() + points0() + pointDisplacement_.internalField() ); twoDCorrectPoints(tcurPoints()); @@ -208,63 +193,7 @@ void Foam::displacementSBRStressFvMotionSolver::updateMesh const mapPolyMesh& mpm ) { - fvMotionSolver::updateMesh(mpm); - - // Map points0_ - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementSBRStressFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); + displacementFvMotionSolver::updateMesh(mpm); // Update diffusivity. Note two stage to make sure old one is de-registered // before creating/registering new one. diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H index 740fed7e7b708325b7260fd4b5e4350a2ecbc150..766025cf8609043c7c582baa8c1a1120a68b7b71 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H @@ -37,7 +37,7 @@ SourceFiles #ifndef displacementSBRStressFvMotionSolver_H #define displacementSBRStressFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,13 +53,10 @@ class motionDiffusivity; class displacementSBRStressFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Point motion field mutable pointVectorField pointDisplacement_; @@ -105,12 +102,6 @@ public: // Member Functions - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return reference to the point motion displacement field pointVectorField& pointDisplacement() { diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C new file mode 100644 index 0000000000000000000000000000000000000000..aa3d51bd4f6cabf8167496fe942bb04e46aa948f --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "displacementFvMotionSolver.H" +#include "addToRunTimeSelectionTable.H" +#include "mapPolyMesh.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(displacementFvMotionSolver, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::displacementFvMotionSolver::displacementFvMotionSolver +( + const polyMesh& mesh, + Istream& +) +: + fvMotionSolver(mesh), + points0_ + ( + pointIOField + ( + IOobject + ( + "points", + mesh.time().constant(), + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ) + ) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::displacementFvMotionSolver::~displacementFvMotionSolver() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::displacementFvMotionSolver::updateMesh(const mapPolyMesh& mpm) +{ + fvMotionSolver::updateMesh(mpm); + + // Map points0_. Bit special since we somehow have to come up with + // a sensible points0 position for introduced points. + // Find out scaling between points0 and current points + + // Get the new points either from the map or the mesh + const pointField& points = + ( + mpm.hasMotionPoints() + ? mpm.preMotionPoints() + : fvMesh_.points() + ); + + // Note: boundBox does reduce + const vector span0 = boundBox(points0_).span(); + const vector span = boundBox(points).span(); + + vector scaleFactors(cmptDivide(span0, span)); + + pointField newPoints0(mpm.pointMap().size()); + + forAll(newPoints0, pointI) + { + label oldPointI = mpm.pointMap()[pointI]; + + if (oldPointI >= 0) + { + label masterPointI = mpm.reversePointMap()[oldPointI]; + + if (masterPointI == pointI) + { + newPoints0[pointI] = points0_[oldPointI]; + } + else + { + // New point. Assume motion is scaling. + newPoints0[pointI] = points0_[oldPointI] + cmptMultiply + ( + scaleFactors, + points[pointI]-points[masterPointI] + ); + } + } + else + { + FatalErrorIn + ( + "displacementLaplacianFvMotionSolver::updateMesh" + "(const mapPolyMesh& mpm)" + ) << "Cannot work out coordinates of introduced vertices." + << " New vertex " << pointI << " at coordinate " + << points[pointI] << exit(FatalError); + } + } + points0_.transfer(newPoints0); +} + + +// ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H new file mode 100644 index 0000000000000000000000000000000000000000..aedd15f7044c8053b0e6dcbc4dc9d18e0799cc30 --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::displacementFvMotionSolver.H + +Description + Base class for fvMotionSolvers which calculate displacement. + +SourceFiles + displacementFvMotionSolver.C + +\*---------------------------------------------------------------------------*/ + +#ifndef displacementFvMotionSolver_H +#define displacementFvMotionSolver_H + +#include "fvMotionSolver.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class displacementFvMotionSolver Declaration +\*---------------------------------------------------------------------------*/ + +class displacementFvMotionSolver +: + public fvMotionSolver +{ + // Private data + + //- Reference point field + pointField points0_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + displacementFvMotionSolver + ( + const displacementFvMotionSolver& + ); + + //- Disallow default bitwise assignment + void operator=(const displacementFvMotionSolver&); + + +public: + + //- Runtime type information + TypeName("displacementInterpolation"); + + + // Constructors + + //- Construct from polyMesh and data stream + displacementFvMotionSolver + ( + const polyMesh&, + Istream& msDataUnused + ); + + + // Destructor + + ~displacementFvMotionSolver(); + + + // Member Functions + + //- Return reference to the reference field + const pointField& points0() const + { + return points0_; + } + + //- Update topology + virtual void updateMesh(const mapPolyMesh&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C index 178d1d1b2a4d116d0401b3a3e9b7d4f684d734ce..cdd5a999ec1290068d5fb02c141830c419a28c53 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C @@ -58,26 +58,10 @@ Foam::displacementInterpolationFvMotionSolver:: displacementInterpolationFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - mesh.time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ) - ), + displacementFvMotionSolver(mesh, is), dynamicMeshCoeffs_ ( IOdictionary @@ -174,7 +158,7 @@ displacementInterpolationFvMotionSolver forAll(fz().meshPoints(), localI) { label pointI = fz().meshPoints()[localI]; - const scalar coord = points0_[pointI][dir]; + const scalar coord = points0()[pointI][dir]; minCoord = min(minCoord, coord); maxCoord = max(maxCoord, coord); } @@ -198,7 +182,7 @@ displacementInterpolationFvMotionSolver zoneCoordinates[zoneCoordinates.size()-1] += SMALL; // Check if we have static min and max mesh bounds - const scalarField meshCoords = points0_.component(dir); + const scalarField meshCoords = points0().component(dir); scalar minCoord = gMin(meshCoords); scalar maxCoord = gMax(meshCoords); @@ -288,7 +272,7 @@ displacementInterpolationFvMotionSolver "displacementInterpolationFvMotionSolver::" "displacementInterpolationFvMotionSolver" "(const polyMesh&, Istream&)" - ) << "Did not find point " << points0_[pointI] + ) << "Did not find point " << points0()[pointI] << " coordinate " << meshCoords[pointI] << " in ranges " << rangeToCoord << abort(FatalError); @@ -344,18 +328,18 @@ Foam::displacementInterpolationFvMotionSolver:: Foam::tmp<Foam::pointField> Foam::displacementInterpolationFvMotionSolver::curPoints() const { - if (mesh().nPoints() != points0_.size()) + if (mesh().nPoints() != points0().size()) { FatalErrorIn ( "displacementInterpolationFvMotionSolver::curPoints() const" ) << "The number of points in the mesh seems to have changed." << endl - << "In constant/polyMesh there are " << points0_.size() + << "In constant/polyMesh there are " << points0().size() << " points; in the current mesh there are " << mesh().nPoints() << " points." << exit(FatalError); } - tmp<pointField> tcurPoints(new pointField(points0_)); + tmp<pointField> tcurPoints(new pointField(points0())); pointField& curPoints = tcurPoints(); // Interpolate the diplacement of the face zones. @@ -413,68 +397,4 @@ Foam::displacementInterpolationFvMotionSolver::curPoints() const } -void Foam::displacementInterpolationFvMotionSolver::updateMesh -( - const mapPolyMesh& mpm -) -{ - fvMotionSolver::updateMesh(mpm); - - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementLaplacianFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); -} - - // ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H index cd7438df06ac46f04697f5bbc0754f5a4ed43cda..d67886ac3c9c5f478343a7957718ca5720ea4775 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H @@ -48,7 +48,7 @@ SourceFiles #ifndef displacementInterpolationFvMotionSolver_H #define displacementInterpolationFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -61,13 +61,10 @@ namespace Foam class displacementInterpolationFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Additional settings for motion solver dictionary dynamicMeshCoeffs_; @@ -130,21 +127,12 @@ public: // Member Functions - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return point location obtained from the current motion field virtual tmp<pointField> curPoints() const; //- Solve for motion virtual void solve() {} - - //- Update topology - virtual void updateMesh(const mapPolyMesh&); }; diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C index a979feebb3e8973906dcf7c3aa0c0d7bddbc3319..e57a17cce9baa0d341c724ce801832b1ea0717e2 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C @@ -53,26 +53,10 @@ namespace Foam Foam::displacementLaplacianFvMotionSolver::displacementLaplacianFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ) - ), + displacementFvMotionSolver(mesh, is), pointDisplacement_ ( IOobject @@ -186,7 +170,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const } pointLocation_().internalField() = - points0_ + points0() + pointDisplacement_.internalField(); pointLocation_().correctBoundaryConditions(); @@ -198,7 +182,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const forAll(pz, i) { - pointLocation_()[pz[i]] = points0_[pz[i]]; + pointLocation_()[pz[i]] = points0()[pz[i]]; } } @@ -210,7 +194,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const { tmp<pointField> tcurPoints ( - points0_ + pointDisplacement_.internalField() + points0() + pointDisplacement_.internalField() ); // Implement frozen points @@ -220,7 +204,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const forAll(pz, i) { - tcurPoints()[pz[i]] = points0_[pz[i]]; + tcurPoints()[pz[i]] = points0()[pz[i]]; } } @@ -257,74 +241,7 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh const mapPolyMesh& mpm ) { - fvMotionSolver::updateMesh(mpm); - - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementLaplacianFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); - - if (debug & 2) - { - OFstream str(time().timePath()/"points0.obj"); - Pout<< "displacementLaplacianFvMotionSolver :" - << " Writing points0_ to " << str.name() << endl; - - forAll(points0_, pointI) - { - meshTools::writeOBJ(str, points0_[pointI]); - } - } + displacementFvMotionSolver::updateMesh(mpm); // Update diffusivity. Note two stage to make sure old one is de-registered // before creating/registering new one. diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H index 67ed89c40fb29967e1023234e45af9705d059161..6ba0c01e320b2e4a7ceb41cda6d28bcabcc872d7 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H @@ -37,7 +37,7 @@ SourceFiles #ifndef displacementLaplacianFvMotionSolver_H #define displacementLaplacianFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,13 +53,10 @@ class motionDiffusivity; class displacementLaplacianFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Point motion field mutable pointVectorField pointDisplacement_; @@ -113,13 +110,6 @@ public: // Member Functions - - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return reference to the point motion displacement field pointVectorField& pointDisplacement() { diff --git a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C index 68e0151f85e6b48c664a51a7fcc6dfa467ea73e4..8c310481d7c5ae20dfda44ff7e402437cf2f4b7a 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C @@ -29,7 +29,7 @@ License #include "Time.H" #include "transformField.H" #include "fvMesh.H" -#include "displacementLaplacianFvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,129 +52,24 @@ const NamedEnum<surfaceSlipDisplacementPointPatchVectorField::followMode, 3> surfaceSlipDisplacementPointPatchVectorField::followModeNames_; -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -surfaceSlipDisplacementPointPatchVectorField:: -surfaceSlipDisplacementPointPatchVectorField -( - const pointPatch& p, - const DimensionedField<vector, pointMesh>& iF -) -: - pointPatchVectorField(p, iF), - projectMode_(NEAREST), - projectDir_(vector::zero), - wedgePlane_(-1) -{} - - -surfaceSlipDisplacementPointPatchVectorField:: -surfaceSlipDisplacementPointPatchVectorField -( - const pointPatch& p, - const DimensionedField<vector, pointMesh>& iF, - const dictionary& dict -) -: - pointPatchVectorField(p, iF, dict), - surfacesDict_(dict.subDict("geometry")), - projectMode_(followModeNames_.read(dict.lookup("followMode"))), - projectDir_(dict.lookup("projectDirection")), - wedgePlane_(readLabel(dict.lookup("wedgePlane"))), - frozenPointsZone_(dict.lookup("frozenPointsZone")) -{} - - -surfaceSlipDisplacementPointPatchVectorField:: -surfaceSlipDisplacementPointPatchVectorField -( - const surfaceSlipDisplacementPointPatchVectorField& ppf, - const pointPatch& p, - const DimensionedField<vector, pointMesh>& iF, - const pointPatchFieldMapper& -) -: - pointPatchVectorField(p, iF), - surfacesDict_(ppf.surfacesDict()), - projectMode_(ppf.projectMode()), - projectDir_(ppf.projectDir()), - wedgePlane_(ppf.wedgePlane()), - frozenPointsZone_(ppf.frozenPointsZone()) -{} - - -surfaceSlipDisplacementPointPatchVectorField:: -surfaceSlipDisplacementPointPatchVectorField -( - const surfaceSlipDisplacementPointPatchVectorField& ppf -) -: - pointPatchVectorField(ppf), - surfacesDict_(ppf.surfacesDict()), - projectMode_(ppf.projectMode()), - projectDir_(ppf.projectDir()), - wedgePlane_(ppf.wedgePlane()), - frozenPointsZone_(ppf.frozenPointsZone()) -{} - - -surfaceSlipDisplacementPointPatchVectorField:: -surfaceSlipDisplacementPointPatchVectorField -( - const surfaceSlipDisplacementPointPatchVectorField& ppf, - const DimensionedField<vector, pointMesh>& iF -) -: - pointPatchVectorField(ppf, iF), - surfacesDict_(ppf.surfacesDict()), - projectMode_(ppf.projectMode()), - projectDir_(ppf.projectDir()), - wedgePlane_(ppf.wedgePlane()), - frozenPointsZone_(ppf.frozenPointsZone()) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -const searchableSurfaces& -surfaceSlipDisplacementPointPatchVectorField::surfaces() const -{ - if (surfacesPtr_.empty()) - { - surfacesPtr_.reset - ( - new searchableSurfaces - ( - IOobject - ( - "abc", // dummy name - db().time().constant(), // directory - "triSurface", // instance - db().time(), // registry - IOobject::MUST_READ, - IOobject::NO_WRITE - ), - surfacesDict_ - ) - ); - } - return surfacesPtr_(); -} - +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void surfaceSlipDisplacementPointPatchVectorField::evaluate +void surfaceSlipDisplacementPointPatchVectorField::calcProjection ( - const Pstream::commsTypes commsType -) + vectorField& displacement +) const { const polyMesh& mesh = patch().boundaryMesh().mesh()(); + const pointField& localPoints = patch().localPoints(); + const labelList& meshPoints = patch().meshPoints(); - // const scalar deltaT = mesh.time().deltaT().value(); + //const scalar deltaT = mesh.time().deltaT().value(); // Construct large enough vector in direction of projectDir so // we're guaranteed to hit something. - const scalar projectLen = mesh.bounds().mag(); + //- Per point projection vector: + const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min()); // For case of fixed projection vector: vector projectVec; @@ -184,18 +79,11 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate projectVec = projectLen*n; } - //- Per point projection vector: - - const pointField& localPoints = patch().localPoints(); - const labelList& meshPoints = patch().meshPoints(); - - vectorField displacement(this->patchInternalField()); - // Get fixed points (bit of a hack) const pointZone* zonePtr = NULL; - if (frozenPointsZone_.size()) + if (frozenPointsZone_.size() > 0) { const pointZoneMesh& pZones = mesh.pointZones(); @@ -207,23 +95,22 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate } // Get the starting locations from the motionSolver - const displacementLaplacianFvMotionSolver& motionSolver = - mesh.lookupObject<displacementLaplacianFvMotionSolver> + const displacementFvMotionSolver& motionSolver = + mesh.lookupObject<displacementFvMotionSolver> ( "dynamicMeshDict" ); const pointField& points0 = motionSolver.points0(); -//XXXXXX - - pointField start(meshPoints.size()); forAll(start, i) { start[i] = points0[meshPoints[i]] + displacement[i]; } + label nNotProjected = 0; + if (projectMode_ == NEAREST) { List<pointIndexHit> nearest; @@ -251,10 +138,15 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate } else { - Pout<< " point:" << meshPoints[i] - << " coord:" << localPoints[i] - << " did not find any surface within " << projectLen - << endl; + nNotProjected++; + + if (debug) + { + Pout<< " point:" << meshPoints[i] + << " coord:" << localPoints[i] + << " did not find any surface within " << projectLen + << endl; + } } } } @@ -307,7 +199,7 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate rightHit ); } - + List<pointIndexHit> leftHit; { labelList leftSurf; @@ -380,17 +272,154 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate } else { - Pout<< " point:" << meshPoints[i] - << " coord:" << localPoints[i] - << " did not find any intersection between ray from " - << start[i]-projectVecs[i] - << " to " << start[i]+projectVecs[i] - << endl; + nNotProjected++; + + if (debug) + { + Pout<< " point:" << meshPoints[i] + << " coord:" << localPoints[i] + << " did not find any intersection between" + << " ray from " << start[i]-projectVecs[i] + << " to " << start[i]+projectVecs[i] << endl; + } } } } } + reduce(nNotProjected, sumOp<label>()); + + if (nNotProjected > 0) + { + Info<< "surfaceSlipDisplacement :" + << " on patch " << patch().name() + << " did not project " << nNotProjected + << " out of " << returnReduce(localPoints.size(), sumOp<label>()) + << " points." << endl; + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +surfaceSlipDisplacementPointPatchVectorField:: +surfaceSlipDisplacementPointPatchVectorField +( + const pointPatch& p, + const DimensionedField<vector, pointMesh>& iF +) +: + pointPatchVectorField(p, iF), + projectMode_(NEAREST), + projectDir_(vector::zero), + wedgePlane_(-1) +{} + + +surfaceSlipDisplacementPointPatchVectorField:: +surfaceSlipDisplacementPointPatchVectorField +( + const pointPatch& p, + const DimensionedField<vector, pointMesh>& iF, + const dictionary& dict +) +: + pointPatchVectorField(p, iF, dict), + surfacesDict_(dict.subDict("geometry")), + projectMode_(followModeNames_.read(dict.lookup("followMode"))), + projectDir_(dict.lookup("projectDirection")), + wedgePlane_(readLabel(dict.lookup("wedgePlane"))), + frozenPointsZone_(dict.lookupOrDefault("frozenPointsZone", word::null)) +{} + + +surfaceSlipDisplacementPointPatchVectorField:: +surfaceSlipDisplacementPointPatchVectorField +( + const surfaceSlipDisplacementPointPatchVectorField& ppf, + const pointPatch& p, + const DimensionedField<vector, pointMesh>& iF, + const pointPatchFieldMapper& +) +: + pointPatchVectorField(p, iF), + surfacesDict_(ppf.surfacesDict()), + projectMode_(ppf.projectMode()), + projectDir_(ppf.projectDir()), + wedgePlane_(ppf.wedgePlane()), + frozenPointsZone_(ppf.frozenPointsZone()) +{} + + +surfaceSlipDisplacementPointPatchVectorField:: +surfaceSlipDisplacementPointPatchVectorField +( + const surfaceSlipDisplacementPointPatchVectorField& ppf +) +: + pointPatchVectorField(ppf), + surfacesDict_(ppf.surfacesDict()), + projectMode_(ppf.projectMode()), + projectDir_(ppf.projectDir()), + wedgePlane_(ppf.wedgePlane()), + frozenPointsZone_(ppf.frozenPointsZone()) +{} + + +surfaceSlipDisplacementPointPatchVectorField:: +surfaceSlipDisplacementPointPatchVectorField +( + const surfaceSlipDisplacementPointPatchVectorField& ppf, + const DimensionedField<vector, pointMesh>& iF +) +: + pointPatchVectorField(ppf, iF), + surfacesDict_(ppf.surfacesDict()), + projectMode_(ppf.projectMode()), + projectDir_(ppf.projectDir()), + wedgePlane_(ppf.wedgePlane()), + frozenPointsZone_(ppf.frozenPointsZone()) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const searchableSurfaces& +surfaceSlipDisplacementPointPatchVectorField::surfaces() const +{ + if (surfacesPtr_.empty()) + { + surfacesPtr_.reset + ( + new searchableSurfaces + ( + IOobject + ( + "abc", // dummy name + db().time().constant(), // directory + "triSurface", // instance + db().time(), // registry + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + surfacesDict_ + ) + ); + } + return surfacesPtr_(); +} + + +void surfaceSlipDisplacementPointPatchVectorField::evaluate +( + const Pstream::commsTypes commsType +) +{ + vectorField displacement(this->patchInternalField()); + + // Calculate displacement to project points onto surface + calcProjection(displacement); + // Get internal field to insert values into Field<vector>& iF = const_cast<Field<vector>&>(this->internalField()); @@ -412,8 +441,11 @@ void surfaceSlipDisplacementPointPatchVectorField::write(Ostream& os) const << token::END_STATEMENT << nl; os.writeKeyword("wedgePlane") << wedgePlane_ << token::END_STATEMENT << nl; - os.writeKeyword("frozenPointsZone") << frozenPointsZone_ - << token::END_STATEMENT << nl; + if (frozenPointsZone_ != word::null) + { + os.writeKeyword("frozenPointsZone") << frozenPointsZone_ + << token::END_STATEMENT << nl; + } } diff --git a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.H b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.H index d74ca862e2df53112db5daa3eed9ec9319fc134a..9edb42ac0d8764334c014267bbdbb327bb808596 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.H +++ b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.H @@ -107,6 +107,9 @@ private: // Private Member Functions + //- Calculate displacement to project onto surface + void calcProjection(vectorField& displacement) const; + //- Disallow default bitwise assignment void operator=(const surfaceSlipDisplacementPointPatchVectorField&); diff --git a/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.C index aea3123f89c8e4db1c0baa6ae0af35201693cc6c..f3c95afc910c1bc73415cd483e6147c18ce40b1a 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.C @@ -45,37 +45,20 @@ void Foam::coordinateRotation::calcTransform const axisOrder& order ) { - const scalar orthogonalityError = 1.0e-8; - vector a = axis1 / mag(axis1); vector b = axis2; // Absorb minor nonorthogonality into axis2 b = b - (b & a)*a; - if (mag(b) < orthogonalityError) + if (mag(b) < SMALL) { - FatalErrorIn - ( - "coordinateRotation::calcTransform()" - ) + FatalErrorIn("coordinateRotation::calcTransform()") << "axis1, axis2 appear co-linear: " << axis1 << ", " << axis2 << endl << abort(FatalError); } - // this error check is probably no longer required - if (mag(a & b)/(mag(a)*mag(b)) >= orthogonalityError) - { - FatalErrorIn - ( - "coordinateRotation::calcTransform()" - ) - << "coordinate system nonorthogonality " << nl - << "mag(axis1 & axis2) = " << mag(a & b) - << abort(FatalError); - } - b = b / mag(b); vector c = a ^ b; @@ -102,10 +85,7 @@ void Foam::coordinateRotation::calcTransform break; default: - FatalErrorIn - ( - "coordinateRotation::calcTransform()" - ) + FatalErrorIn("coordinateRotation::calcTransform()") << "programmer error" << endl << abort(FatalError); break; @@ -241,4 +221,5 @@ void Foam::coordinateRotation::operator=(const dictionary& rhs) calcTransform(axis1, axis2, order); } + // ************************************************************************* // diff --git a/src/meshTools/indexedOctree/indexedOctree.C b/src/meshTools/indexedOctree/indexedOctree.C index 9b065c36ac7f686cc39fd421a3015c93b4c360e2..2131c3aaf6ef936fcf18bbe8f4cc39ffcdde93c5 100644 --- a/src/meshTools/indexedOctree/indexedOctree.C +++ b/src/meshTools/indexedOctree/indexedOctree.C @@ -824,8 +824,10 @@ Foam::direction Foam::indexedOctree<Type>::getFace } -// Traverse a node. If intersects a triangle return first intersection point. -// Else return the bounxing box face hit: +// Traverse a node. If intersects a triangle return first intersection point: +// hitInfo.index = index of shape +// hitInfo.point = point on shape +// Else return a miss and the bounding box face hit: // hitInfo.point = coordinate of intersection of ray with bounding box // faceID = index of bounding box face template <class Type> @@ -918,10 +920,10 @@ void Foam::indexedOctree<Type>::traverseNode { faceID = 0; - WarningIn("indexedOctree<Type>::traverseNode") + FatalErrorIn("indexedOctree<Type>::traverseNode(..)") << "Did not hit side of box " << subBb << " with ray from " << start << " to " << end - << endl; + << abort(FatalError); } else { @@ -936,10 +938,10 @@ void Foam::indexedOctree<Type>::traverseNode { faceID = 0; - WarningIn("indexedOctree<Type>::traverseNode") + FatalErrorIn("indexedOctree<Type>::traverseNode(..)") << "Did not hit side of box " << subBb << " with ray from " << start << " to " << end - << endl; + << abort(FatalError); } else { diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 4703d692016e65141103c325453c9021b7446da0..877f2643414d78b9fc986fa2d765b56aac04b816 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -120,6 +120,29 @@ const Foam::fileName& Foam::triSurfaceMesh::checkFile } +bool Foam::triSurfaceMesh::addFaceToEdge +( + const edge& e, + EdgeMap<label>& facesPerEdge +) +{ + EdgeMap<label>::iterator eFnd = facesPerEdge.find(e); + if (eFnd != facesPerEdge.end()) + { + if (eFnd() == 2) + { + return false; + } + eFnd()++; + } + else + { + facesPerEdge.insert(e, 1); + } + return true; +} + + bool Foam::triSurfaceMesh::isSurfaceClosed() const { // Construct pointFaces. Let's hope surface has compact point @@ -142,48 +165,41 @@ bool Foam::triSurfaceMesh::isSurfaceClosed() const const labelledTri& f = triSurface::operator[](pFaces[i]); label fp = findIndex(f, pointI); + // Something weird: if I expand the code of addFaceToEdge in both + // below instances it gives a segmentation violation on some + // surfaces. Compiler (4.3.2) problem? + + // Forward edge + label nextPointI = f[f.fcIndex(fp)]; + + if (nextPointI > pointI) { - label p1 = f[f.fcIndex(fp)]; + bool okFace = addFaceToEdge + ( + edge(pointI, nextPointI), + facesPerEdge + ); - if (p1 > pointI) + if (!okFace) { - const edge e(pointI, p1); - EdgeMap<label>::iterator eFnd = facesPerEdge.find(e); - if (eFnd != facesPerEdge.end()) - { - if (eFnd() == 2) - { - return false; - } - eFnd()++; - } - else - { - facesPerEdge.insert(e, 1); - } + return false; } } // Reverse edge + label prevPointI = f[f.rcIndex(fp)]; + + if (prevPointI > pointI) { - label p1 = f[f.rcIndex(fp)]; + bool okFace = addFaceToEdge + ( + edge(pointI, prevPointI), + facesPerEdge + ); - if (p1 > pointI) + if (!okFace) { - const edge e(pointI, p1); - EdgeMap<label>::iterator eFnd = facesPerEdge.find(e); - if (eFnd != facesPerEdge.end()) - { - if (eFnd() == 2) - { - return false; - } - eFnd()++; - } - else - { - facesPerEdge.insert(e, 1); - } + return false; } } } diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.H b/src/meshTools/searchableSurface/triSurfaceMesh.H index a4231457d5183097cff2eceb31ca00e944c6a05d..b2ec61c14a943e4c6d4268306d5dfc4ee9157359 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.H +++ b/src/meshTools/searchableSurface/triSurfaceMesh.H @@ -42,6 +42,7 @@ SourceFiles #include "indexedOctree.H" #include "treeDataTriSurface.H" #include "treeDataEdge.H" +#include "EdgeMap.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -91,6 +92,13 @@ private: const fileName& objectName ); + //- Helper function for isSurfaceClosed + static bool addFaceToEdge + ( + const edge&, + EdgeMap<label>& + ); + //- Check whether surface is closed without calculating any permanent // addressing. bool isSurfaceClosed() const; diff --git a/src/meshTools/triSurface/orientedSurface/orientedSurface.C b/src/meshTools/triSurface/orientedSurface/orientedSurface.C index 911d06747ae1d21f6b2bcf9608f31cdb2b08f002..10e1fa8f2f930e9457352190159ea80584ef3623 100644 --- a/src/meshTools/triSurface/orientedSurface/orientedSurface.C +++ b/src/meshTools/triSurface/orientedSurface/orientedSurface.C @@ -175,6 +175,51 @@ Foam::labelList Foam::orientedSurface::edgeToFace } +void Foam::orientedSurface::walkSurface +( + const triSurface& s, + const label startFaceI, + labelList& flipState +) +{ + // List of faces that were changed in the last iteration. + labelList changedFaces(1, startFaceI); + // List of edges that were changed in the last iteration. + labelList changedEdges; + + while(true) + { + changedEdges = faceToEdge(s, changedFaces); + + if (debug) + { + Pout<< "From changedFaces:" << changedFaces.size() + << " to changedEdges:" << changedEdges.size() + << endl; + } + + if (changedEdges.empty()) + { + break; + } + + changedFaces = edgeToFace(s, changedEdges, flipState); + + if (debug) + { + Pout<< "From changedEdges:" << changedEdges.size() + << " to changedFaces:" << changedFaces.size() + << endl; + } + + if (changedFaces.empty()) + { + break; + } + } +} + + void Foam::orientedSurface::propagateOrientation ( const triSurface& s, @@ -228,42 +273,8 @@ void Foam::orientedSurface::propagateOrientation << endl; } - - // List of faces that were changed in the last iteration. - labelList changedFaces(1, nearestFaceI); - // List of edges that were changed in the last iteration. - labelList changedEdges; - - while(true) - { - changedEdges = faceToEdge(s, changedFaces); - - if (debug) - { - Pout<< "From changedFaces:" << changedFaces.size() - << " to changedEdges:" << changedEdges.size() - << endl; - } - - if (changedEdges.empty()) - { - break; - } - - changedFaces = edgeToFace(s, changedEdges, flipState); - - if (debug) - { - Pout<< "From changedEdges:" << changedEdges.size() - << " to changedFaces:" << changedFaces.size() - << endl; - } - - if (changedFaces.empty()) - { - break; - } - } + // Walk the surface from nearestFaceI, changing the flipstate. + walkSurface(s, nearestFaceI, flipState); } @@ -352,6 +363,26 @@ bool Foam::orientedSurface::orient const bool orientOutside ) { + bool anyFlipped = false; + + // Do initial flipping to make triangles consistent. Otherwise if the + // nearest is e.g. on an edge inbetween inconsistent triangles it might + // make the wrong decision. + if (s.size() > 0) + { + // Whether face has to be flipped. + // UNVISITED: unvisited + // NOFLIP: no need to flip + // FLIP: need to flip + labelList flipState(s.size(), UNVISITED); + + flipState[0] = NOFLIP; + walkSurface(s, 0, flipState); + + anyFlipped = flipSurface(s, flipState); + } + + // Whether face has to be flipped. // UNVISITED: unvisited // NOFLIP: no need to flip @@ -410,7 +441,9 @@ bool Foam::orientedSurface::orient } // Now finally flip triangles according to flipState. - return flipSurface(s, flipState); + bool geomFlipped = flipSurface(s, flipState); + + return anyFlipped || geomFlipped; } diff --git a/src/meshTools/triSurface/orientedSurface/orientedSurface.H b/src/meshTools/triSurface/orientedSurface/orientedSurface.H index c0b5ca8c4272b1a5c3396c70eeae414197449e1e..812edd31bde262d71f5b1e8466890418211472e8 100644 --- a/src/meshTools/triSurface/orientedSurface/orientedSurface.H +++ b/src/meshTools/triSurface/orientedSurface/orientedSurface.H @@ -94,6 +94,15 @@ class orientedSurface labelList& flip ); + //- Walk from face across connected faces. Change orientation to be + // consistent with startFaceI. + static void walkSurface + ( + const triSurface& s, + const label startFaceI, + labelList& flipState + ); + //- Given nearest point and face check orientation to nearest face // and flip if nessecary (only marked in flipState) and propagate. static void propagateOrientation diff --git a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C index 24c3fd53d02af7b5ef73a3b655b3cb822f45eaa9..8eb7ca65feca6864afb71f9086d62a80b19a4e31 100644 --- a/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C +++ b/src/postProcessing/functionObjects/field/fieldAverage/fieldAverage/fieldAverage.C @@ -259,7 +259,7 @@ void Foam::fieldAverage::readAveragingProperties() obr_.time().timeName(), "uniform", obr_, - IOobject::NO_READ, + IOobject::MUST_READ, IOobject::NO_WRITE, false ); diff --git a/src/postProcessing/functionObjects/utilities/Make/files b/src/postProcessing/functionObjects/utilities/Make/files index 2d37c7c8f3407f51c6872f25d263d661c9366c2e..40a33c238ddd3983b7817bd096632f1920e2ba60 100644 --- a/src/postProcessing/functionObjects/utilities/Make/files +++ b/src/postProcessing/functionObjects/utilities/Make/files @@ -1,5 +1,5 @@ -dynamicPressure/dynamicPressure.C -dynamicPressure/dynamicPressureFunctionObject.C +staticPressure/staticPressure.C +staticPressure/staticPressureFunctionObject.C dsmcFields/dsmcFields.C dsmcFields/dsmcFieldsFunctionObject.C diff --git a/src/postProcessing/functionObjects/utilities/dynamicPressure/IOdynamicPressure.H b/src/postProcessing/functionObjects/utilities/staticPressure/IOstaticPressure.H similarity index 86% rename from src/postProcessing/functionObjects/utilities/dynamicPressure/IOdynamicPressure.H rename to src/postProcessing/functionObjects/utilities/staticPressure/IOstaticPressure.H index 97a5c27353d171c1c537ca1d47a62f1c74628a06..8409c7f103b4c0d319d74acdedc5f8a85c763c53 100644 --- a/src/postProcessing/functionObjects/utilities/dynamicPressure/IOdynamicPressure.H +++ b/src/postProcessing/functionObjects/utilities/staticPressure/IOstaticPressure.H @@ -23,24 +23,24 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Typedef - Foam::IOdynamicPressure + Foam::IOstaticPressure Description - Instance of the generic IOOutputFilter for dynamicPressure. + Instance of the generic IOOutputFilter for staticPressure. \*---------------------------------------------------------------------------*/ -#ifndef IOdynamicPressure_H -#define IOdynamicPressure_H +#ifndef IOstaticPressure_H +#define IOstaticPressure_H -#include "dynamicPressure.H" +#include "staticPressure.H" #include "IOOutputFilter.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - typedef IOOutputFilter<dynamicPressure> IOdynamicPressure; + typedef IOOutputFilter<staticPressure> IOstaticPressure; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.C b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.C similarity index 88% rename from src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.C rename to src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.C index a31c913ba78a4a515d38ee93cf5b57e6a4b4bf90..9ca4f715df0025bee3e4e2c11c4e7f5cd7796d0a 100644 --- a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.C +++ b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ -#include "dynamicPressure.H" +#include "staticPressure.H" #include "volFields.H" #include "dictionary.H" @@ -32,12 +32,12 @@ License namespace Foam { - defineTypeNameAndDebug(dynamicPressure, 0); + defineTypeNameAndDebug(staticPressure, 0); } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::dynamicPressure::isKinematicPressure() +bool Foam::staticPressure::isKinematicPressure() { const volScalarField& p = obr_.lookupObject<volScalarField>(pName_); @@ -47,7 +47,7 @@ bool Foam::dynamicPressure::isKinematicPressure() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::dynamicPressure::dynamicPressure +Foam::staticPressure::staticPressure ( const word& name, const objectRegistry& obr, @@ -67,7 +67,7 @@ Foam::dynamicPressure::dynamicPressure active_ = false; WarningIn ( - "dynamicPressure::dynamicPressure" + "staticPressure::staticPressure" "(const objectRegistry&, const dictionary&)" ) << "No fvMesh available, deactivating." << nl << endl; @@ -80,7 +80,7 @@ Foam::dynamicPressure::dynamicPressure active_ = false; WarningIn ( - "dynamicPressure::dynamicPressure" + "staticPressure::staticPressure" "(const objectRegistry&, const dictionary&)" ) << "Pressure is not kinematic pressure, deactivating." << nl << endl; @@ -93,13 +93,13 @@ Foam::dynamicPressure::dynamicPressure // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -Foam::dynamicPressure::~dynamicPressure() +Foam::staticPressure::~staticPressure() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::dynamicPressure::read(const dictionary& dict) +void Foam::staticPressure::read(const dictionary& dict) { if (active_) { @@ -109,19 +109,19 @@ void Foam::dynamicPressure::read(const dictionary& dict) } -void Foam::dynamicPressure::execute() +void Foam::staticPressure::execute() { // Do nothing - only valid on write } -void Foam::dynamicPressure::end() +void Foam::staticPressure::end() { // Do nothing - only valid on write } -void Foam::dynamicPressure::write() +void Foam::staticPressure::write() { if (active_) { diff --git a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.H b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.H similarity index 82% rename from src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.H rename to src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.H index c3c6bdbb0f3d60afe65274a0bdbb014a260bdd38..0a7be2c6204bf045fd6f951e6cce23f33e8712f2 100644 --- a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressure.H +++ b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressure.H @@ -23,20 +23,22 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::dynamicPressure + Foam::staticPressure Description - Converts kinematic pressure to dynamic pressure, from the name of the - pressure field, and density. + Converts kinematic pressure to static pressure, from the name of the + pressure field, and density, i.e. + + p_static = density*p_kinematic SourceFiles - dynamicPressure.C - IOdynamicPressure.H + staticPressure.C + IOstaticPressure.H \*---------------------------------------------------------------------------*/ -#ifndef dynamicPressure_H -#define dynamicPressure_H +#ifndef staticPressure_H +#define staticPressure_H #include "pointFieldFwd.H" @@ -51,14 +53,14 @@ class dictionary; class mapPolyMesh; /*---------------------------------------------------------------------------*\ - Class dynamicPressure Declaration + Class staticPressure Declaration \*---------------------------------------------------------------------------*/ -class dynamicPressure +class staticPressure { // Private data - //- Name of this set of dynamicPressure objects + //- Name of this set of staticPressure objects word name_; const objectRegistry& obr_; @@ -79,23 +81,23 @@ class dynamicPressure bool isKinematicPressure(); //- Disallow default bitwise copy construct - dynamicPressure(const dynamicPressure&); + staticPressure(const staticPressure&); //- Disallow default bitwise assignment - void operator=(const dynamicPressure&); + void operator=(const staticPressure&); public: //- Runtime type information - TypeName("dynamicPressure"); + TypeName("staticPressure"); // Constructors //- Construct for given objectRegistry and dictionary. // Allow the possibility to load fields from files - dynamicPressure + staticPressure ( const word& name, const objectRegistry&, @@ -106,18 +108,18 @@ public: // Destructor - virtual ~dynamicPressure(); + virtual ~staticPressure(); // Member Functions - //- Return name of the set of dynamicPressure + //- Return name of the set of staticPressure virtual const word& name() const { return name_; } - //- Read the dynamicPressure data + //- Read the staticPressure data virtual void read(const dictionary&); //- Execute, currently does nothing @@ -126,7 +128,7 @@ public: //- Execute at the final time-loop, currently does nothing virtual void end(); - //- Calculate the dynamicPressure and write + //- Calculate the staticPressure and write virtual void write(); //- Update for changes of mesh diff --git a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.C b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.C similarity index 90% rename from src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.C rename to src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.C index f7c060f5862abe19e043d35c75837c0b30bfaaf7..d84c802a4a8825cbaf49cd978f10b077fbf24a33 100644 --- a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.C +++ b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.C @@ -24,18 +24,18 @@ License \*---------------------------------------------------------------------------*/ -#include "dynamicPressureFunctionObject.H" +#include "staticPressureFunctionObject.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - defineNamedTemplateTypeNameAndDebug(dynamicPressureFunctionObject, 0); + defineNamedTemplateTypeNameAndDebug(staticPressureFunctionObject, 0); addToRunTimeSelectionTable ( functionObject, - dynamicPressureFunctionObject, + staticPressureFunctionObject, dictionary ); } diff --git a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.H b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.H similarity index 81% rename from src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.H rename to src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.H index cca83745e85589559a982dbcbc61c3ea2a43385e..40f425d4b1892b8f09aa0edb442a44d2fae72614 100644 --- a/src/postProcessing/functionObjects/utilities/dynamicPressure/dynamicPressureFunctionObject.H +++ b/src/postProcessing/functionObjects/utilities/staticPressure/staticPressureFunctionObject.H @@ -23,29 +23,29 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Typedef - Foam::dynamicPressureFunctionObject + Foam::staticPressureFunctionObject Description - FunctionObject wrapper around dynamicPressure to allow it to be created via + FunctionObject wrapper around staticPressure to allow it to be created via the functions list within controlDict. SourceFiles - dynamicPressureFunctionObject.C + staticPressureFunctionObject.C \*---------------------------------------------------------------------------*/ -#ifndef dynamicPressureFunctionObject_H -#define dynamicPressureFunctionObject_H +#ifndef staticPressureFunctionObject_H +#define staticPressureFunctionObject_H -#include "dynamicPressure.H" +#include "staticPressure.H" #include "OutputFilterFunctionObject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - typedef OutputFilterFunctionObject<dynamicPressure> - dynamicPressureFunctionObject; + typedef OutputFilterFunctionObject<staticPressure> + staticPressureFunctionObject; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/Make/files b/src/sampling/Make/files index c52803251940c51fa2ee40d702e4a25be6bd3760..57306e542b83bb61dfc13cbb88434681b516e483 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -33,6 +33,8 @@ sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledSurface/sampledSurface.C sampledSurface/sampledSurfaces/sampledSurfaces.C sampledSurface/sampledSurfacesFunctionObject/sampledSurfacesFunctionObject.C +sampledSurface/thresholdCellFaces/thresholdCellFaces.C +sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C surfWriters = sampledSurface/writers @@ -40,8 +42,8 @@ $(surfWriters)/surfaceWriters.C $(surfWriters)/dx/dxSurfaceWriterRunTime.C $(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C $(surfWriters)/null/nullSurfaceWriterRunTime.C +$(surfWriters)/proxy/proxySurfaceWriterRunTime.C $(surfWriters)/raw/rawSurfaceWriterRunTime.C -$(surfWriters)/stl/stlSurfaceWriterRunTime.C $(surfWriters)/vtk/vtkSurfaceWriterRunTime.C graphField/writePatchGraph.C diff --git a/src/sampling/cuttingPlane/cuttingPlane.H b/src/sampling/cuttingPlane/cuttingPlane.H index b7e31ef906d46973d48c7612c1bf4548024b3c49..6804a9ab18197c687bbb9f84a311cd3662751e0a 100644 --- a/src/sampling/cuttingPlane/cuttingPlane.H +++ b/src/sampling/cuttingPlane/cuttingPlane.H @@ -62,10 +62,10 @@ class primitiveMesh; class cuttingPlane : public plane, - public BasicMeshedSurface<face> + public MeshedSurface<face> { //- Private typedefs for convenience - typedef BasicMeshedSurface<face> MeshStorage; + typedef MeshedSurface<face> MeshStorage; // Private data diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index 91c588c6d3ef1128ca0d7f47325f092cd027c0a8..5a6686aad04b6c7a5e17169f42bdcd91a92e3360 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -182,15 +182,24 @@ bool Foam::probes::checkFieldTypes() if (Pstream::master()) { fileName probeDir; + + fileName probeSubDir = name_; + + if (obr_.name() != polyMesh::defaultRegion) + { + probeSubDir = probeSubDir/obr_.name(); + } + probeSubDir = probeSubDir/obr_.time().timeName(); + if (Pstream::parRun()) { // Put in undecomposed case // (Note: gives problems for distributed data running) - probeDir = obr_.time().path()/".."/name_/obr_.time().timeName(); + probeDir = obr_.time().path()/".."/probeSubDir; } else { - probeDir = obr_.time().path()/name_/obr_.time().timeName(); + probeDir = obr_.time().path()/probeSubDir; } // Close the file if any fields have been removed. diff --git a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H index 45faa6b9077f9b9de27341c7216e324b1f6b8ecb..1096f6451906d066be94a06bc8f24fb0535109e2 100644 --- a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H +++ b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H @@ -81,7 +81,7 @@ public: const coordSet&, const wordList&, const List<const Field<Type>*>&, - Ostream& os + Ostream& ) const; }; diff --git a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriterRunTime.C b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriterRunTime.C index 3f019d1203e20a27cbe5265b4f32175e93d30ff7..4cdae12b55975f426174cdaec23a0182d4db5055 100644 --- a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriterRunTime.C +++ b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriterRunTime.C @@ -32,7 +32,7 @@ License namespace Foam { - makeSetWriters(gnuplotSetWriter) + makeSetWriters(gnuplotSetWriter); } // ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H index 98975205069ab1a402d12df7549cac1876d70152..940dec2abe7bb5a630aae6b3de200c9d2de08c02 100644 --- a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H +++ b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H @@ -54,7 +54,7 @@ class jplotSetWriter // Private Member Functions //- Write header - Ostream& writeHeader(Ostream& os) const; + Ostream& writeHeader(Ostream&) const; public: @@ -85,7 +85,7 @@ public: const coordSet&, const wordList&, const List<const Field<Type>*>&, - Ostream& os + Ostream& ) const; }; diff --git a/src/sampling/sampledSet/writers/jplot/jplotSetWriterRunTime.C b/src/sampling/sampledSet/writers/jplot/jplotSetWriterRunTime.C index a6a4f48884d34a1ea21791ec198488a077c8eca1..8a864712ed5f1297af4d9bfd6ea551790d43d8dc 100644 --- a/src/sampling/sampledSet/writers/jplot/jplotSetWriterRunTime.C +++ b/src/sampling/sampledSet/writers/jplot/jplotSetWriterRunTime.C @@ -32,7 +32,7 @@ License namespace Foam { - makeSetWriters(jplotSetWriter) + makeSetWriters(jplotSetWriter); } // ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/raw/rawSetWriter.H b/src/sampling/sampledSet/writers/raw/rawSetWriter.H index af502104a75b441f4ac62c350473f3312b20c8f4..346813d941c1bb36c9505a566f09fa097e6bbaa3 100644 --- a/src/sampling/sampledSet/writers/raw/rawSetWriter.H +++ b/src/sampling/sampledSet/writers/raw/rawSetWriter.H @@ -81,7 +81,7 @@ public: const coordSet&, const wordList&, const List<const Field<Type>*>&, - Ostream& os + Ostream& ) const; }; diff --git a/src/sampling/sampledSet/writers/raw/rawSetWriterRunTime.C b/src/sampling/sampledSet/writers/raw/rawSetWriterRunTime.C index 1af20c1dbf25aaad81a8045d6828b6a0dc3322a2..e3acd319a3be282a0fc60c47bd14e1f0f83459a2 100644 --- a/src/sampling/sampledSet/writers/raw/rawSetWriterRunTime.C +++ b/src/sampling/sampledSet/writers/raw/rawSetWriterRunTime.C @@ -32,7 +32,7 @@ License namespace Foam { - makeSetWriters(rawSetWriter) + makeSetWriters(rawSetWriter); } // ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/writer.H b/src/sampling/sampledSet/writers/writer.H index 263d81df5e0e0aed079a810d9b0e502e5bf62d69..e450d07c32a1fce9c8c55034e4a9a25d72ff958e 100644 --- a/src/sampling/sampledSet/writers/writer.H +++ b/src/sampling/sampledSet/writers/writer.H @@ -91,22 +91,12 @@ protected: //- Generates filename from coordSet and sampled fields fileName getBaseName(const coordSet&, const wordList&) const; - void writeCoord - ( - const coordSet& samples, - const label sampleI, - Ostream& os - ) const; + void writeCoord(const coordSet&, const label sampleI, Ostream&) const; //- Writes single-column ascii write. Column 1 is coordSet coordinate, // columns 2 is the value. Uses write() function // to write coordinate in correct format. - void writeTable - ( - const coordSet&, - const List<Type>&, - Ostream& os - ) const; + void writeTable(const coordSet&, const List<Type>&, Ostream&) const; //- Writes multi-column ascii write. Column 1 is coordSet coordinate, // columns 2..n are the values. Uses write() function @@ -139,10 +129,7 @@ public: // Selectors //- Return a reference to the selected writer - static autoPtr<writer> New - ( - const word& writeFormat - ); + static autoPtr<writer> New(const word& writeFormat); // Constructors @@ -165,8 +152,8 @@ public: ) const = 0; //- General entry point for writing. - // The data is organized in a set of point with one or - // more values per point + // The data is organized in a set of point with one or more values + // per point virtual void write ( const coordSet&, @@ -179,7 +166,7 @@ public: virtual Ostream& write(const scalar, Ostream&) const; template<class VSType> - Ostream& writeVS(const VSType& value, Ostream& os) const; + Ostream& writeVS(const VSType&, Ostream&) const; //- Write vector. Tab separated ascii virtual Ostream& write(const vector&, Ostream&) const; diff --git a/src/sampling/sampledSet/writers/writers.H b/src/sampling/sampledSet/writers/writers.H index ceb47e954ecbbeb642c9fa42363a6d70b3971a43..bf7d03342618a73509df2593d20ebb56c7af756b 100644 --- a/src/sampling/sampledSet/writers/writers.H +++ b/src/sampling/sampledSet/writers/writers.H @@ -40,27 +40,27 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Only used internally -#define makeTypeSetWritersTypeName(typeWriter, dataType) \ - \ - defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0); +#define makeTypeSetWritersTypeName(typeWriter, dataType) \ + \ + defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0) // Sometimes used externally -#define makeSetWritersTypeName(typeWriter) \ - \ - makeTypeSetWritersTypeName(typeWriter, scalar); \ - makeTypeSetWritersTypeName(typeWriter, vector); \ - makeTypeSetWritersTypeName(typeWriter, sphericalTensor); \ - makeTypeSetWritersTypeName(typeWriter, symmTensor); \ - makeTypeSetWritersTypeName(typeWriter, tensor); +#define makeSetWritersTypeName(typeWriter) \ + \ + makeTypeSetWritersTypeName(typeWriter, scalar); \ + makeTypeSetWritersTypeName(typeWriter, vector); \ + makeTypeSetWritersTypeName(typeWriter, sphericalTensor); \ + makeTypeSetWritersTypeName(typeWriter, symmTensor); \ + makeTypeSetWritersTypeName(typeWriter, tensor) // Define type info for single dataType template instantiation (eg, vector) -#define makeSetWriterType(typeWriter, dataType) \ - \ - defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0); \ - addTemplatedToRunTimeSelectionTable \ - ( \ - writer, typeWriter, dataType, word \ - ); +#define makeSetWriterType(typeWriter, dataType) \ + \ + defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0); \ + addTemplatedToRunTimeSelectionTable \ + ( \ + writer, typeWriter, dataType, word \ + ) // Define type info for scalar, vector etc. instantiations @@ -70,7 +70,7 @@ SourceFiles makeSetWriterType(typeWriter, vector); \ makeSetWriterType(typeWriter, sphericalTensor); \ makeSetWriterType(typeWriter, symmTensor); \ - makeSetWriterType(typeWriter, tensor); + makeSetWriterType(typeWriter, tensor) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H index 1da5794a8ea24acff987b418856864600b2a1166..b5abab73b525fc23aceeae04f5dbe7536941dc80 100644 --- a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H +++ b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H @@ -81,7 +81,7 @@ public: const coordSet&, const wordList&, const List<const Field<Type>*>&, - Ostream& os + Ostream& ) const; }; diff --git a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriterRunTime.C b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriterRunTime.C index 434c4655fe5d3fbe974af3a73c9c6362f002de83..e793b6f6f4966208eae36ce0b5a8d202cf7b9beb 100644 --- a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriterRunTime.C +++ b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriterRunTime.C @@ -32,7 +32,7 @@ License namespace Foam { - makeSetWriters(xmgraceSetWriter) + makeSetWriters(xmgraceSetWriter); } // ************************************************************************* // diff --git a/src/sampling/sampledSurface/isoSurface/isoSurface.H b/src/sampling/sampledSurface/isoSurface/isoSurface.H index dbe8ae85018d68494e22b4bd53329c4dc6d445b2..3ab45629d1004c0d0fabc618a4ae7f33a6cf1d00 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/isoSurface.H @@ -439,8 +439,8 @@ public: return triPointMergeMap_; } - //- Interpolates cCoords,pCoords. Takes the original fields - // used to create the iso surface. + //- Interpolates cCoords,pCoords. Uses the references to the original + // fields used to create the iso surface. template <class Type> tmp<Field<Type> > interpolate ( diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index 5fd09bda66e9ba888e5f0212c05cca58c567a70f..c2f32da1b6b37dcf300486475bcba68980975cb5 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -153,6 +153,16 @@ void Foam::sampledIsoSurface::getIsoFields() const } } + + // If averaging redo the volField. Can only be done now since needs the + // point field. + if (average_) + { + storedVolFieldPtr_.reset(average(fvm, *pointFieldPtr_).ptr()); + volFieldPtr_ = storedVolFieldPtr_.operator->(); + } + + if (debug) { Info<< "sampledIsoSurface::getIsoField() : volField " @@ -241,6 +251,20 @@ void Foam::sampledIsoSurface::getIsoFields() const pointSubFieldPtr_ = storedPointSubFieldPtr_.operator->(); } + + + // If averaging redo the volField. Can only be done now since needs the + // point field. + if (average_) + { + storedVolSubFieldPtr_.reset + ( + average(subFvm, *pointSubFieldPtr_).ptr() + ); + volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); + } + + if (debug) { Info<< "sampledIsoSurface::getIsoField() : volSubField " @@ -307,6 +331,48 @@ Foam::tmp<Foam::volScalarField> Foam::sampledIsoSurface::average } +Foam::tmp<Foam::pointScalarField> Foam::sampledIsoSurface::average +( + const pointMesh& pMesh, + const volScalarField& fld +) const +{ + tmp<pointScalarField> tpointAvg + ( + new pointScalarField + ( + IOobject + ( + "pointAvg", + fld.time().timeName(), + fld.db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + pMesh, + dimensionedScalar("zero", dimless, scalar(0.0)) + ) + ); + pointScalarField& pointAvg = tpointAvg(); + + for (label pointI = 0; pointI < fld.mesh().nPoints(); pointI++) + { + const labelList& pCells = fld.mesh().pointCells(pointI); + + forAll(pCells, i) + { + pointAvg[pointI] += fld[pCells[i]]; + } + pointAvg[pointI] /= pCells.size(); + } + // Give value to calculatedFvPatchFields + pointAvg.correctBoundaryConditions(); + + return tpointAvg; +} + + bool Foam::sampledIsoSurface::updateGeometry() const { const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); @@ -352,67 +418,33 @@ bool Foam::sampledIsoSurface::updateGeometry() const surfPtr_.clear(); facesPtr_.clear(); - if (average_) + if (subMeshPtr_.valid()) { - if (subMeshPtr_.valid()) - { - surfPtr_.reset - ( - new isoSurface - ( - average(subMeshPtr_().subMesh(), *pointSubFieldPtr_), - *pointSubFieldPtr_, - isoVal_, - regularise_, - mergeTol_ - ) - ); - } - else - { - surfPtr_.reset + surfPtr_.reset + ( + new isoSurface ( - new isoSurface - ( - average(fvm, *pointFieldPtr_), - *pointFieldPtr_, - isoVal_, - regularise_, - mergeTol_ - ) - ); - } + *volSubFieldPtr_, + *pointSubFieldPtr_, + isoVal_, + regularise_, + mergeTol_ + ) + ); } else { - if (subMeshPtr_.valid()) - { - surfPtr_.reset - ( - new isoSurface - ( - *volSubFieldPtr_, - *pointSubFieldPtr_, - isoVal_, - regularise_, - mergeTol_ - ) - ); - } - else - { - surfPtr_.reset + surfPtr_.reset + ( + new isoSurface ( - new isoSurface - ( - *volFieldPtr_, - *pointFieldPtr_, - isoVal_, - regularise_, - mergeTol_ - ) - ); - } + *volFieldPtr_, + *pointFieldPtr_, + isoVal_, + regularise_, + mergeTol_ + ) + ); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index 99324cdf5f398a66b1f1e3416d1454e12ff07f20..ccaa4d875005b3189692fa4a34799970a5450acb 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -124,6 +124,12 @@ class sampledIsoSurface const pointScalarField& ) const; + tmp<pointScalarField> average + ( + const pointMesh&, + const volScalarField& fld + ) const; + //- Create iso surface (if time has changed) // Do nothing (and return false) if no update was needed bool updateGeometry() const; diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H index fbc0b56ebeb445aaa9c610556677d5352f5d6d36..2890a7bd34349ea3439912d32aec67d7c578620f 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H @@ -50,11 +50,11 @@ namespace Foam class sampledPatch : - public BasicMeshedSurface<face>, + public MeshedSurface<face>, public sampledSurface { //- Private typedefs for convenience - typedef BasicMeshedSurface<face> MeshStorage; + typedef MeshedSurface<face> MeshStorage; // Private data diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 9eb0e73f1116eeef237df6f048fe5738e6796712..d6b9613f6f15db7b091654e5d0bffded16ced5a1 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -70,18 +70,27 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_(1e-10); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::sampledSurfaces::checkFieldTypes() +Foam::label Foam::sampledSurfaces::classifyFieldTypes() { - wordList fieldTypes(fieldNames_.size()); + label nFields = 0; + + scalarFields_.clear(); + vectorFields_.clear(); + sphericalTensorFields_.clear(); + symmTensorFields_.clear(); + tensorFields_.clear(); - // check files for a particular time - if (loadFromFiles_) + forAll(fieldNames_, fieldI) { - forAll(fieldNames_, fieldI) + const word& fieldName = fieldNames_[fieldI]; + word fieldType = ""; + + // check files for a particular time + if (loadFromFiles_) { IOobject io ( - fieldNames_[fieldI], + fieldName, mesh_.time().timeName(), mesh_, IOobject::MUST_READ, @@ -91,69 +100,96 @@ bool Foam::sampledSurfaces::checkFieldTypes() if (io.headerOk()) { - fieldTypes[fieldI] = io.headerClassName(); + fieldType = io.headerClassName(); } else { - fieldTypes[fieldI] = "(notFound)"; + continue; } } - } - else - { - // check objectRegistry - forAll(fieldNames_, fieldI) + else { - objectRegistry::const_iterator iter = - mesh_.find(fieldNames_[fieldI]); + // check objectRegistry + objectRegistry::const_iterator iter = mesh_.find(fieldName); if (iter != mesh_.objectRegistry::end()) { - fieldTypes[fieldI] = iter()->type(); + fieldType = iter()->type(); } else { - fieldTypes[fieldI] = "(notFound)"; + continue; } } + + + if (fieldType == volScalarField::typeName) + { + scalarFields_.append(fieldName); + nFields++; + } + else if (fieldType == volVectorField::typeName) + { + vectorFields_.append(fieldName); + nFields++; + } + else if (fieldType == volSphericalTensorField::typeName) + { + sphericalTensorFields_.append(fieldName); + nFields++; + } + else if (fieldType == volSymmTensorField::typeName) + { + symmTensorFields_.append(fieldName); + nFields++; + } + else if (fieldType == volTensorField::typeName) + { + tensorFields_.append(fieldName); + nFields++; + } + } + return nFields; +} - label nFields = 0; - // classify fieldTypes - nFields += grep(scalarFields_, fieldTypes); - nFields += grep(vectorFields_, fieldTypes); - nFields += grep(sphericalTensorFields_, fieldTypes); - nFields += grep(symmTensorFields_, fieldTypes); - nFields += grep(tensorFields_, fieldTypes); +void Foam::sampledSurfaces::writeGeometry() const +{ + // Write to time directory under outputPath_ + // skip surface without faces (eg, a failed cut-plane) - if (Pstream::master()) + const fileName outputDir = outputPath_/mesh_.time().timeName(); + + forAll(*this, surfI) { - if (debug) - { - Pout<< "timeName = " << mesh_.time().timeName() << nl - << "scalarFields " << scalarFields_ << nl - << "vectorFields " << vectorFields_ << nl - << "sphTensorFields " << sphericalTensorFields_ << nl - << "symTensorFields " << symmTensorFields_ <<nl - << "tensorFields " << tensorFields_ <<nl; - } + const sampledSurface& s = operator[](surfI); - if (nFields > 0) + if (Pstream::parRun()) { - if (debug) + if (Pstream::master() && mergeList_[surfI].faces.size()) { - Pout<< "Creating directory " - << outputPath_/mesh_.time().timeName() - << nl << endl; + genericFormatter_->write + ( + outputDir, + s.name(), + mergeList_[surfI].points, + mergeList_[surfI].faces + ); } - - mkDir(outputPath_/mesh_.time().timeName()); + } + else if (s.faces().size()) + { + genericFormatter_->write + ( + outputDir, + s.name(), + s.points(), + s.faces() + ); } } - - return nFields > 0; } @@ -176,6 +212,7 @@ Foam::sampledSurfaces::sampledSurfaces interpolationScheme_(word::null), writeFormat_(word::null), mergeList_(), + genericFormatter_(NULL), scalarFields_(), vectorFields_(), sphericalTensorFields_(), @@ -223,11 +260,39 @@ void Foam::sampledSurfaces::end() void Foam::sampledSurfaces::write() { - if (size() && checkFieldTypes()) + if (size()) { // finalize surfaces, merge points etc. update(); + const label nFields = classifyFieldTypes(); + + if (Pstream::master()) + { + if (debug) + { + Pout<< "timeName = " << mesh_.time().timeName() << nl + << "scalarFields " << scalarFields_ << nl + << "vectorFields " << vectorFields_ << nl + << "sphTensorFields " << sphericalTensorFields_ << nl + << "symTensorFields " << symmTensorFields_ <<nl + << "tensorFields " << tensorFields_ <<nl; + + Pout<< "Creating directory " + << outputPath_/mesh_.time().timeName() << nl << endl; + + } + + mkDir(outputPath_/mesh_.time().timeName()); + } + + // write geometry first if required, or when no fields would otherwise + // be written + if (nFields == 0 || genericFormatter_->separateFiles()) + { + writeGeometry(); + } + sampleAndWrite(scalarFields_); sampleAndWrite(vectorFields_); sampleAndWrite(sphericalTensorFields_); @@ -241,6 +306,14 @@ void Foam::sampledSurfaces::read(const dictionary& dict) { fieldNames_ = wordList(dict.lookup("fields")); + const label nFields = fieldNames_.size(); + + scalarFields_.reset(nFields); + vectorFields_.reset(nFields); + sphericalTensorFields_.reset(nFields); + symmTensorFields_.reset(nFields); + tensorFields_.reset(nFields); + interpolationScheme_ = dict.lookupOrDefault<word> ( "interpolationScheme", @@ -252,6 +325,11 @@ void Foam::sampledSurfaces::read(const dictionary& dict) "null" ); + + // define the generic (geometry) writer + genericFormatter_ = surfaceWriter<bool>::New(writeFormat_); + + PtrList<sampledSurface> newList ( dict.lookup("surfaces"), diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 7bf12aaba8e1099501ef31424a3917f1c4562a34..4ad59c486f70e1fb8271fddee07bdc03eaf54a47 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -64,24 +64,24 @@ class sampledSurfaces template<class Type> class fieldGroup : - public wordList + public DynamicList<word> { public: //- Surface formatter - autoPtr<surfaceWriter<Type> > formatter; + autoPtr< surfaceWriter<Type> > formatter; //- Construct null fieldGroup() : - wordList(0), + DynamicList<word>(0), formatter(NULL) {} //- Construct for a particular surface format fieldGroup(const word& writeFormat) : - wordList(0), + DynamicList<word>(0), formatter(surfaceWriter<Type>::New(writeFormat)) {} @@ -93,10 +93,17 @@ class sampledSurfaces const wordList& fieldNames ) : - wordList(fieldNames), + DynamicList<word>(fieldNames), formatter(surfaceWriter<Type>::New(writeFormat)) {} + void reset(const label nElem) + { + formatter.clear(); + DynamicList<word>::setCapacity(nElem); + DynamicList<word>::clear(); + } + void operator=(const word& writeFormat) { formatter = surfaceWriter<Type>::New(writeFormat); @@ -104,7 +111,7 @@ class sampledSurfaces void operator=(const wordList& fieldNames) { - wordList::operator=(fieldNames); + DynamicList<word>::operator=(fieldNames); } }; @@ -171,6 +178,9 @@ class sampledSurfaces // Calculated + //- Generic surface formatter + autoPtr< surfaceWriter<bool> > genericFormatter_; + //- Categorized scalar/vector/tensor fields fieldGroup<scalar> scalarFields_; fieldGroup<vector> vectorFields_; @@ -181,16 +191,11 @@ class sampledSurfaces // Private Member Functions - //- Classify field types, return true if nFields > 0 - bool checkFieldTypes(); + //- Classify field types, returns the number of fields + label classifyFieldTypes(); - //- Find the fields in the list of the given type, return count - template<class Type> - label grep - ( - fieldGroup<Type>& fieldList, - const wordList& fieldTypes - ) const; + //- Write geometry only + void writeGeometry() const; //- Sample and write a particular volume field template<class Type> diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index e93bb0bde72cf36208f5ddc8c5b668ef324d9ae9..6da55cfe8736220134b921afdef9403ea9f3fb6e 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -30,35 +30,6 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template<class Type> -Foam::label Foam::sampledSurfaces::grep -( - fieldGroup<Type>& fieldList, - const wordList& fieldTypes -) const -{ - fieldList.setSize(fieldNames_.size()); - label nFields = 0; - - forAll(fieldNames_, fieldI) - { - if - ( - fieldTypes[fieldI] - == GeometricField<Type, fvPatchField, volMesh>::typeName - ) - { - fieldList[nFields] = fieldNames_[fieldI]; - nFields++; - } - } - - fieldList.setSize(nFields); - - return nFields; -} - - template<class Type> void Foam::sampledSurfaces::sampleAndWrite ( @@ -67,10 +38,10 @@ void Foam::sampledSurfaces::sampleAndWrite ) { // interpolator for this field - autoPtr<interpolation<Type> > interpolator; + autoPtr< interpolation<Type> > interpolator; const word& fieldName = vField.name(); - const fileName& timeDir = vField.time().timeName(); + const fileName outputDir = outputPath_/vField.time().timeName(); forAll(*this, surfI) { @@ -128,8 +99,7 @@ void Foam::sampledSurfaces::sampleAndWrite { formatter.write ( - outputPath_, - timeDir, + outputDir, s.name(), mergeList_[surfI].points, mergeList_[surfI].faces, @@ -147,8 +117,7 @@ void Foam::sampledSurfaces::sampleAndWrite { formatter.write ( - outputPath_, - timeDir, + outputDir, s.name(), s.points(), s.faces(), @@ -217,7 +186,7 @@ void Foam::sampledSurfaces::sampleAndWrite sampleAndWrite ( mesh_.lookupObject - <GeometricField<Type, fvPatchField, volMesh> > + <GeometricField<Type, fvPatchField, volMesh> > ( fields[fieldI] ), diff --git a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C new file mode 100644 index 0000000000000000000000000000000000000000..1dd43b4be3b899c839339e2d5c2d1970eeb8a85d --- /dev/null +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C @@ -0,0 +1,333 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "sampledThresholdCellFaces.H" + +#include "dictionary.H" +#include "volFields.H" +#include "volPointInterpolation.H" +#include "addToRunTimeSelectionTable.H" +#include "fvMesh.H" +#include "thresholdCellFaces.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(sampledThresholdCellFaces, 0); + addNamedToRunTimeSelectionTable + ( + sampledSurface, + sampledThresholdCellFaces, + word, + thresholdCellFaces + ); +} + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::sampledThresholdCellFaces::updateGeometry() const +{ + const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); + + // no update needed + if (fvm.time().timeIndex() == prevTimeIndex_) + { + return false; + } + + prevTimeIndex_ = fvm.time().timeIndex(); + + // Optionally read volScalarField + autoPtr<volScalarField> readFieldPtr_; + + // 1. see if field in database + // 2. see if field can be read + const volScalarField* cellFldPtr = NULL; + if (fvm.foundObject<volScalarField>(fieldName_)) + { + if (debug) + { + Info<< "sampledThresholdCellFaces::updateGeometry() : lookup " + << fieldName_ << endl; + } + + cellFldPtr = &fvm.lookupObject<volScalarField>(fieldName_); + } + else + { + // Bit of a hack. Read field and store. + + if (debug) + { + Info<< "sampledThresholdCellFaces::updateGeometry() : reading " + << fieldName_ << " from time " << fvm.time().timeName() + << endl; + } + + readFieldPtr_.reset + ( + new volScalarField + ( + IOobject + ( + fieldName_, + fvm.time().timeName(), + fvm, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + fvm + ) + ); + + cellFldPtr = readFieldPtr_.operator->(); + } + const volScalarField& cellFld = *cellFldPtr; + + + thresholdCellFaces surf + ( + fvm, + cellFld.internalField(), + lowerThreshold_, + upperThreshold_, + triangulate_ + ); + + const_cast<sampledThresholdCellFaces&> + ( + *this + ).MeshedSurface<face>::transfer(surf); + meshCells_.transfer(surf.meshCells()); + + + if (debug) + { + Pout<< "sampledThresholdCellFaces::updateGeometry() : constructed" + << nl + << " field : " << fieldName_ << nl + << " lowerLimit : " << lowerThreshold_ << nl + << " upperLimit : " << upperThreshold_ << nl + << " point : " << points().size() << nl + << " faces : " << faces().size() << nl + << " cut cells : " << meshCells_.size() << endl; + } + + return true; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sampledThresholdCellFaces::sampledThresholdCellFaces +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + sampledSurface(name, mesh, dict), + fieldName_(dict.lookup("field")), + lowerThreshold_(dict.lookupOrDefault<scalar>("lowerLimit", -VGREAT)), + upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", VGREAT)), + zoneName_(word::null), + triangulate_(dict.lookupOrDefault("triangulate", false)), + prevTimeIndex_(-1), + meshCells_(0) +{ + if (!dict.found("lowerLimit") && !dict.found("upperLimit")) + { + FatalErrorIn + ( + "sampledThresholdCellFaces::sampledThresholdCellFaces(..)" + ) + << "require at least one of 'lowerLimit' or 'upperLimit'" << endl + << abort(FatalError); + } + + +// dict.readIfPresent("zone", zoneName_); +// +// if (debug && zoneName_.size()) +// { +// if (mesh.cellZones().findZoneID(zoneName_) < 0) +// { +// Info<< "cellZone \"" << zoneName_ +// << "\" not found - using entire mesh" << endl; +// } +// } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::sampledThresholdCellFaces::~sampledThresholdCellFaces() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sampledThresholdCellFaces::needsUpdate() const +{ + const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); + + return fvm.time().timeIndex() != prevTimeIndex_; +} + + +bool Foam::sampledThresholdCellFaces::expire() +{ + // already marked as expired + if (prevTimeIndex_ == -1) + { + return false; + } + + // force update + prevTimeIndex_ = -1; + return true; +} + + +bool Foam::sampledThresholdCellFaces::update() +{ + return updateGeometry(); +} + + +Foam::tmp<Foam::scalarField> +Foam::sampledThresholdCellFaces::sample +( + const volScalarField& vField +) const +{ + return sampleField(vField); +} + + +Foam::tmp<Foam::vectorField> +Foam::sampledThresholdCellFaces::sample +( + const volVectorField& vField +) const +{ + return sampleField(vField); +} + + +Foam::tmp<Foam::sphericalTensorField> +Foam::sampledThresholdCellFaces::sample +( + const volSphericalTensorField& vField +) const +{ + return sampleField(vField); +} + + +Foam::tmp<Foam::symmTensorField> +Foam::sampledThresholdCellFaces::sample +( + const volSymmTensorField& vField +) const +{ + return sampleField(vField); +} + + +Foam::tmp<Foam::tensorField> +Foam::sampledThresholdCellFaces::sample +( + const volTensorField& vField +) const +{ + return sampleField(vField); +} + + +Foam::tmp<Foam::scalarField> +Foam::sampledThresholdCellFaces::interpolate +( + const interpolation<scalar>& interpolator +) const +{ + return interpolateField(interpolator); +} + + +Foam::tmp<Foam::vectorField> +Foam::sampledThresholdCellFaces::interpolate +( + const interpolation<vector>& interpolator +) const +{ + return interpolateField(interpolator); +} + +Foam::tmp<Foam::sphericalTensorField> +Foam::sampledThresholdCellFaces::interpolate +( + const interpolation<sphericalTensor>& interpolator +) const +{ + return interpolateField(interpolator); +} + + +Foam::tmp<Foam::symmTensorField> +Foam::sampledThresholdCellFaces::interpolate +( + const interpolation<symmTensor>& interpolator +) const +{ + return interpolateField(interpolator); +} + + +Foam::tmp<Foam::tensorField> +Foam::sampledThresholdCellFaces::interpolate +( + const interpolation<tensor>& interpolator +) const +{ + return interpolateField(interpolator); +} + + +void Foam::sampledThresholdCellFaces::print(Ostream& os) const +{ + os << "sampledThresholdCellFaces: " << name() << " :" + << " field:" << fieldName_ + << " lowerLimit:" << lowerThreshold_ + << " upperLimit:" << upperThreshold_; + //<< " faces:" << faces().size() // possibly no geom yet + //<< " points:" << points().size(); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H new file mode 100644 index 0000000000000000000000000000000000000000..89b2c21c470e0109edd3420de6e5e808144d4434 --- /dev/null +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H @@ -0,0 +1,234 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::sampledThresholdCellFaces + +Description + A sampledSurface defined by the cell faces corresponding to a threshold + value. + +SourceFiles + sampledThresholdCellFaces.C + +\*---------------------------------------------------------------------------*/ + +#ifndef sampledThresholdCellFaces_H +#define sampledThresholdCellFaces_H + +#include "sampledSurface.H" +#include "MeshedSurface.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class sampledThresholdCellFaces Declaration +\*---------------------------------------------------------------------------*/ + +class sampledThresholdCellFaces +: + public sampledSurface, + public MeshedSurface<face> +{ + //- Private typedefs for convenience + typedef MeshedSurface<face> MeshStorage; + + // Private data + + //- Field to get isoSurface of + const word fieldName_; + + //- Threshold value + const scalar lowerThreshold_; + + //- Threshold value + const scalar upperThreshold_; + + //- zone name (if restricted to zones) + word zoneName_; + + //- Triangulated faces or keep faces as is + bool triangulate_; + + // Recreated for every time-step + + //- Time at last call, also track it surface needs an update + mutable label prevTimeIndex_; + + //- For every face the original cell in mesh + mutable labelList meshCells_; + + + // Private Member Functions + + //- Create surface (if time has changed) + // Do nothing (and return false) if no update was needed + bool updateGeometry() const; + + //- sample field on faces + template <class Type> + tmp<Field<Type> > sampleField + ( + const GeometricField<Type, fvPatchField, volMesh>& vField + ) const; + + + template <class Type> + tmp<Field<Type> > + interpolateField(const interpolation<Type>&) const; + + +public: + + //- Runtime type information + TypeName("sampledThresholdCellFaces"); + + + // Constructors + + //- Construct from dictionary + sampledThresholdCellFaces + ( + const word& name, + const polyMesh&, + const dictionary& + ); + + + // Destructor + + virtual ~sampledThresholdCellFaces(); + + + // Member Functions + + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + + //- Points of surface + virtual const pointField& points() const + { + return MeshStorage::points(); + } + + //- Faces of surface + virtual const faceList& faces() const + { + return MeshStorage::faces(); + } + + //- sample field on surface + virtual tmp<scalarField> sample + ( + const volScalarField& + ) const; + + //- sample field on surface + virtual tmp<vectorField> sample + ( + const volVectorField& + ) const; + + //- sample field on surface + virtual tmp<sphericalTensorField> sample + ( + const volSphericalTensorField& + ) const; + + //- sample field on surface + virtual tmp<symmTensorField> sample + ( + const volSymmTensorField& + ) const; + + //- sample field on surface + virtual tmp<tensorField> sample + ( + const volTensorField& + ) const; + + + //- interpolate field on surface + virtual tmp<scalarField> interpolate + ( + const interpolation<scalar>& + ) const; + + //- interpolate field on surface + virtual tmp<vectorField> interpolate + ( + const interpolation<vector>& + ) const; + + //- interpolate field on surface + virtual tmp<sphericalTensorField> interpolate + ( + const interpolation<sphericalTensor>& + ) const; + + //- interpolate field on surface + virtual tmp<symmTensorField> interpolate + ( + const interpolation<symmTensor>& + ) const; + + //- interpolate field on surface + virtual tmp<tensorField> interpolate + ( + const interpolation<tensor>& + ) const; + + //- Write + virtual void print(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "sampledThresholdCellFacesTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFacesTemplates.C similarity index 51% rename from src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C rename to src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFacesTemplates.C index e65476da677f5b9b397ded62db84d02fd6d94463..a1021340c9df1bafc0807850a8d41cf45425a7f1 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.C +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFacesTemplates.C @@ -24,55 +24,67 @@ License \*---------------------------------------------------------------------------*/ -#include "OFFsurfaceFormatCore.H" -#include "clock.H" +#include "sampledThresholdCellFaces.H" + +#include "thresholdCellFaces.H" +#include "volFieldsFwd.H" +#include "pointFields.H" +#include "volPointInterpolation.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::fileFormats::OFFsurfaceFormatCore::writeHeader +template <class Type> +Foam::tmp<Foam::Field<Type> > +Foam::sampledThresholdCellFaces::sampleField ( - Ostream& os, - const pointField& pointLst, - const label nFaces, - const UList<surfZone>& zoneLst -) + const GeometricField<Type, fvPatchField, volMesh>& vField +) const { - // Write header - os << "OFF" << endl - << "# Geomview OFF file written " << clock::dateTime().c_str() << nl - << nl - << "# points : " << pointLst.size() << nl - << "# faces : " << nFaces << nl - << "# zones : " << zoneLst.size() << nl; - - // Print zone names as comment - forAll(zoneLst, zoneI) - { - os << "# " << zoneI << " " << zoneLst[zoneI].name() - << " (nFaces: " << zoneLst[zoneI].size() << ")" << nl; - } + // Recreate geometry if time has changed + updateGeometry(); + + return tmp<Field<Type> >(new Field<Type>(vField, meshCells_)); +} + - os << nl - << "# nPoints nFaces nEdges" << nl - << pointLst.size() << ' ' << nFaces << ' ' << 0 << nl; +template <class Type> +Foam::tmp<Foam::Field<Type> > +Foam::sampledThresholdCellFaces::interpolateField +( + const interpolation<Type>& interpolator +) const +{ + // Recreate geometry if time has changed + updateGeometry(); + + // One value per point + tmp<Field<Type> > tvalues(new Field<Type>(points().size())); + Field<Type>& values = tvalues(); - os << nl - << "# <points count=\"" << pointLst.size() << "\">" << endl; + boolList pointDone(points().size(), false); - // Write vertex coords - forAll(pointLst, ptI) + forAll(faces(), cutFaceI) { - os << pointLst[ptI].x() << ' ' - << pointLst[ptI].y() << ' ' - << pointLst[ptI].z() << " #" << ptI << endl; + const face& f = faces()[cutFaceI]; + + forAll(f, faceVertI) + { + label pointI = f[faceVertI]; + + if (!pointDone[pointI]) + { + values[pointI] = interpolator.interpolate + ( + points()[pointI], + meshCells_[cutFaceI] + ); + pointDone[pointI] = true; + } + } } - os << "# </points>" << nl - << nl - << "# <faces count=\"" << nFaces << "\">" << endl; + return tvalues; } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.C b/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.C new file mode 100644 index 0000000000000000000000000000000000000000..6caaea0ff09844be1c3da3388ce3bb84ac984c40 --- /dev/null +++ b/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.C @@ -0,0 +1,288 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "thresholdCellFaces.H" + +#include "polyMesh.H" +#include "DynamicList.H" + +#include "emptyPolyPatch.H" +#include "processorPolyPatch.H" + + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::thresholdCellFaces, 0); + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::thresholdCellFaces::calculate +( + const scalarField& field, + const scalar lowerThreshold, + const scalar upperThreshold, + const bool triangulate +) +{ + const labelList& own = mesh_.faceOwner(); + const labelList& nei = mesh_.faceNeighbour(); + + const faceList& origFaces = mesh_.faces(); + const pointField& origPoints = mesh_.points(); + + const polyBoundaryMesh& bMesh = mesh_.boundaryMesh(); + + + surfZoneList surfZones(bMesh.size()+1); + + surfZones[0] = surfZone + ( + "internalMesh", + 0, // size + 0, // start + 0 // index + ); + + forAll(bMesh, patchI) + { + surfZones[patchI+1] = surfZone + ( + bMesh[patchI].name(), + 0, // size + 0, // start + patchI+1 // index + ); + } + + + label nFaces = 0; + label nPoints = 0; + + + meshCells_.clear(); + + DynamicList<face> surfFaces(0.5 * mesh_.nFaces()); + DynamicList<label> surfCells(surfFaces.size()); + + labelList oldToNewPoints(origPoints.size(), -1); + + + // internal faces only + for (label faceI = 0; faceI < mesh_.nInternalFaces(); ++faceI) + { + int side = 0; + + // check lowerThreshold + if (field[own[faceI]] > lowerThreshold) + { + if (field[nei[faceI]] < lowerThreshold) + { + side = +1; + } + } + else if (field[nei[faceI]] > lowerThreshold) + { + side = -1; + } + + // check upperThreshold + if (field[own[faceI]] < upperThreshold) + { + if (field[nei[faceI]] > upperThreshold) + { + side = +1; + } + } + else if (field[nei[faceI]] < upperThreshold) + { + side = -1; + } + + + if (side) + { + const face& f = origFaces[faceI]; + + forAll(f, fp) + { + if (oldToNewPoints[f[fp]] == -1) + { + oldToNewPoints[f[fp]] = nPoints++; + } + } + + + label cellId; + face surfFace; + + if (side > 0) + { + surfFace = f; + cellId = own[faceI]; + } + else + { + surfFace = f.reverseFace(); + cellId = nei[faceI]; + } + + + if (triangulate) + { + label count = surfFace.triangles(origPoints, surfFaces); + while (count-- > 0) + { + surfCells.append(cellId); + } + } + else + { + surfFaces.append(surfFace); + surfCells.append(cellId); + } + } + } + + surfZones[0].size() = surfFaces.size(); + + + // nothing special for processor patches? + forAll(bMesh, patchI) + { + const polyPatch& p = bMesh[patchI]; + surfZone& zone = surfZones[patchI+1]; + + zone.start() = nFaces; + + if + ( + isType<emptyPolyPatch>(p) + || (Pstream::parRun() && isType<processorPolyPatch>(p)) + ) + { + continue; + } + + label faceI = p.start(); + + // patch faces + forAll(p, localFaceI) + { + if + ( + field[own[faceI]] > lowerThreshold + && field[own[faceI]] < upperThreshold + ) + { + const face& f = origFaces[faceI]; + forAll(f, fp) + { + if (oldToNewPoints[f[fp]] == -1) + { + oldToNewPoints[f[fp]] = nPoints++; + } + } + + label cellId = own[faceI]; + + if (triangulate) + { + label count = f.triangles(origPoints, surfFaces); + while (count-- > 0) + { + surfCells.append(cellId); + } + } + else + { + surfFaces.append(f); + surfCells.append(cellId); + } + } + + ++faceI; + } + + zone.size() = surfFaces.size() - zone.start(); + } + + + surfFaces.shrink(); + surfCells.shrink(); + + // renumber + forAll(surfFaces, faceI) + { + inplaceRenumber(oldToNewPoints, surfFaces[faceI]); + } + + + pointField surfPoints(nPoints); + nPoints = 0; + forAll(oldToNewPoints, pointI) + { + if (oldToNewPoints[pointI] >= 0) + { + surfPoints[oldToNewPoints[pointI]] = origPoints[pointI]; + nPoints++; + } + } + surfPoints.setSize(nPoints); + + this->storedPoints().transfer(surfPoints); + this->storedFaces().transfer(surfFaces); + this->storedZones().transfer(surfZones); + + meshCells_.transfer(surfCells); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::thresholdCellFaces::thresholdCellFaces +( + const polyMesh& mesh, + const scalarField& field, + const scalar lowerThreshold, + const scalar upperThreshold, + const bool triangulate +) +: + mesh_(mesh) +{ + + if (lowerThreshold > upperThreshold) + { + WarningIn("thresholdCellFaces::thresholdCellFaces(...)") + << "lower > upper limit! " + << lowerThreshold << " > " << upperThreshold << endl; + } + + calculate(field, lowerThreshold, upperThreshold, triangulate); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.H b/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.H new file mode 100644 index 0000000000000000000000000000000000000000..a8428cdd089982f21bacbb4f45c1263b60e2bb94 --- /dev/null +++ b/src/sampling/sampledSurface/thresholdCellFaces/thresholdCellFaces.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::thresholdCellFaces + +Description + Selects the mesh cell faces specified by a threshold value. + Non-triangulated by default. + +SourceFiles + thresholdCellFaces.C + +\*---------------------------------------------------------------------------*/ + +#ifndef thresholdCellFaces_H +#define thresholdCellFaces_H + +#include "MeshedSurface.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class polyMesh; + +/*---------------------------------------------------------------------------*\ + Class thresholdCellFaces Declaration +\*---------------------------------------------------------------------------*/ + +class thresholdCellFaces +: + public MeshedSurface<face> +{ + //- Private typedefs for convenience + typedef MeshedSurface<face> MeshStorage; + + //- Reference to mesh + const polyMesh& mesh_; + + //- For every face the original cell in mesh + labelList meshCells_; + + // Private Member Functions + + void calculate + ( + const scalarField&, + const scalar lowerThreshold, + const scalar upperThreshold, + const bool triangulate + ); + +public: + + //- Runtime type information + TypeName("thresholdCellFaces"); + + + // Constructors + + //- Construct from mesh, field and threshold value + thresholdCellFaces + ( + const polyMesh&, + const scalarField&, + const scalar lowerThreshold, + const scalar upperThreshold, + const bool triangulate = false + ); + + + // Member Functions + + //- For every face original cell in mesh + labelList& meshCells() + { + return meshCells_; + } + + //- For every face original cell in mesh + const labelList& meshCells() const + { + return meshCells_; + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C index 592382ddf05dc9bcc6fa8325a2d4b53bd1630358..a5c613b15d50e97c39a9ae21b0df2ea53eb76d22 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -25,20 +25,19 @@ License \*---------------------------------------------------------------------------*/ #include "dxSurfaceWriter.H" -#include "fileName.H" + #include "OFstream.H" -#include "faceList.H" #include "OSspecific.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXGeometry +void Foam::dxSurfaceWriter<Type>::writeGeometry ( + Ostream& os, const pointField& points, - const faceList& faces, - Ostream& os -) const + const faceList& faces +) { // Write vertex coordinates @@ -69,7 +68,7 @@ void Foam::dxSurfaceWriter<Type>::writeDXGeometry { FatalErrorIn ( - "writeDXGeometry(Ostream&, const pointField&, const faceList&)" + "writeGeometry(Ostream&, const pointField&, const faceList&)" ) << "Face " << faceI << " vertices " << f << " is not a triangle." << exit(FatalError); @@ -82,181 +81,137 @@ void Foam::dxSurfaceWriter<Type>::writeDXGeometry } -// Write scalarField in DX format -template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXData -( - const pointField& points, - const scalarField& values, - Ostream& os -) const +namespace Foam { - // Write data - os << "object 3 class array type float rank 0 items " - << values.size() - << " data follows" << nl; - - forAll(values, elemI) + // Write scalarField in DX format + template<> + void Foam::dxSurfaceWriter<Foam::scalar>::writeData + ( + Ostream& os, + const Field<scalar>& values + ) { - os << float(values[elemI]) << nl; - } + // Write data + os << "object 3 class array type float rank 0 items " + << values.size() << " data follows" << nl; - if (values.size() == points.size()) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; + forAll(values, elemI) + { + os << float(values[elemI]) << nl; + } } -} - -// Write vectorField in DX format -template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXData -( - const pointField& points, - const vectorField& values, - Ostream& os -) const -{ - // Write data - os << "object 3 class array type float rank 1 shape 3 items " - << values.size() - << " data follows" << nl; - forAll(values, elemI) + // Write vectorField in DX format + template<> + void Foam::dxSurfaceWriter<Foam::vector>::writeData + ( + Ostream& os, + const Field<vector>& values + ) { - os << float(values[elemI].x()) << ' ' - << float(values[elemI].y()) << ' ' - << float(values[elemI].z()) << nl; - } + // Write data + os << "object 3 class array type float rank 1 shape 3 items " + << values.size() << " data follows" << nl; - if (values.size() == points.size()) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; + forAll(values, elemI) + { + os << float(values[elemI].x()) << ' ' + << float(values[elemI].y()) << ' ' + << float(values[elemI].z()) << nl; + } } -} -// Write sphericalTensorField in DX format -template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXData -( - const pointField& points, - const sphericalTensorField& values, - Ostream& os -) const -{ - // Write data - os << "object 3 class array type float rank 0 items " - << values.size() - << " data follows" << nl; - - forAll(values, elemI) + // Write sphericalTensorField in DX format + template<> + void Foam::dxSurfaceWriter<Foam::sphericalTensor>::writeData + ( + Ostream& os, + const Field<sphericalTensor>& values + ) { - os << float(values[elemI][0]) << nl; - } + // Write data + os << "object 3 class array type float rank 0 items " + << values.size() << " data follows" << nl; - if (values.size() == points.size()) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; + forAll(values, elemI) + { + os << float(values[elemI][0]) << nl; + } } -} -// Write symmTensorField in DX format -template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXData -( - const pointField& points, - const symmTensorField& values, - Ostream& os -) const -{ - // Write data - os << "object 3 class array type float rank 2 shape 3 items " - << values.size() - << " data follows" << nl; - - forAll(values, elemI) + // Write symmTensorField in DX format + template<> + void Foam::dxSurfaceWriter<Foam::symmTensor>::writeData + ( + Ostream& os, + const Field<symmTensor>& values + ) { - const symmTensor& t = values[elemI]; + // Write data + os << "object 3 class array type float rank 2 shape 3 items " + << values.size() << " data follows" << nl; - os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) - << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) - << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz()) - << nl; - } + forAll(values, elemI) + { + const symmTensor& t = values[elemI]; - if (values.size() == points.size()) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; + os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) + << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) + << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz()) + << nl; + } } - else + + + // Write tensorField in DX format + template<> + void Foam::dxSurfaceWriter<Foam::tensor>::writeData + ( + Ostream& os, + const Field<tensor>& values + ) { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; + // Write data + os << "object 3 class array type float rank 2 shape 3 items " + << values.size() << " data follows" << nl; + + forAll(values, elemI) + { + const tensor& t = values[elemI]; + + os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) + << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) + << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz()) + << nl; + } } } - // Write tensorField in DX format template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXData +void Foam::dxSurfaceWriter<Type>::writeData ( - const pointField& points, - const tensorField& values, - Ostream& os -) const + Ostream& os, + const Field<Type>& values +) { // Write data - os << "object 3 class array type float rank 2 shape 3 items " - << values.size() - << " data follows" << nl; + os << "object 3 class array type float rank 0 items " + << values.size() << " data follows" << nl; forAll(values, elemI) { - const tensor& t = values[elemI]; - - os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz()) - << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz()) - << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz()) - << nl; - } - - if (values.size() == points.size()) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; + os << float(0.0) << nl; } } // Write trailer in DX format template<class Type> -void Foam::dxSurfaceWriter<Type>::writeDXTrailer(Ostream& os) const +void Foam::dxSurfaceWriter<Type>::writeTrailer(Ostream& os) { os << "# the field, with three components: \"positions\"," << " \"connections\", and \"data\"" << nl @@ -290,8 +245,7 @@ Foam::dxSurfaceWriter<Type>::~dxSurfaceWriter() template<class Type> void Foam::dxSurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, @@ -300,27 +254,37 @@ void Foam::dxSurfaceWriter<Type>::write const bool verbose ) const { - fileName surfaceDir(samplePath/timeDir); - - if (!isDir(surfaceDir)) + if (!isDir(outputDir)) { - mkDir(surfaceDir); + mkDir(outputDir); } - fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".dx"); + OFstream os + ( + outputDir/fieldName + '_' + surfaceName + ".dx" + ); if (verbose) { - Info<< "Writing field " << fieldName << " to " << fName << endl; + Info<< "Writing field " << fieldName << " to " << os.name() << endl; } - OFstream os(fName); + writeGeometry(os, points, faces); - writeDXGeometry(points, faces, os); + writeData(os, values); - writeDXData(points, values, os); + if (values.size() == points.size()) + { + os << nl << "attribute \"dep\" string \"positions\"" + << nl << nl; + } + else + { + os << nl << "attribute \"dep\" string \"connections\"" + << nl << nl; + } - writeDXTrailer(os); + writeTrailer(os); os << "end" << nl; } diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H index 81875b8c22a6eabc1633e609f26532ec155d79b8..fcce2e6af2ee5b1ad358795a1ca73227247b9785 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H @@ -54,49 +54,11 @@ class dxSurfaceWriter // Private Member Functions - void writeDXGeometry - ( - const pointField& points, - const faceList& faces, - Ostream& os - ) const; - - void writeDXData - ( - const pointField& points, - const scalarField& values, - Ostream& os - ) const; - - void writeDXData - ( - const pointField& points, - const vectorField& values, - Ostream& os - ) const; + static void writeGeometry(Ostream&, const pointField&, const faceList&); - void writeDXData - ( - const pointField& points, - const sphericalTensorField& values, - Ostream& os - ) const; - - void writeDXData - ( - const pointField& points, - const symmTensorField& values, - Ostream& os - ) const; - - void writeDXData - ( - const pointField& points, - const tensorField& values, - Ostream& os - ) const; + static void writeData(Ostream&, const Field<Type>& values); - void writeDXTrailer(Ostream& os) const; + static void writeTrailer(Ostream&); public: @@ -122,8 +84,7 @@ public: //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C index 38ad998cc5628c0a9b5818afebbd946ab2698dee..0d68df2044d9e0ad8337a0791cccf9114ec814c5 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -25,9 +25,8 @@ License \*---------------------------------------------------------------------------*/ #include "foamFileSurfaceWriter.H" -#include "fileName.H" + #include "OFstream.H" -#include "faceList.H" #include "OSspecific.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -51,17 +50,14 @@ Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter() template<class Type> void Foam::foamFileSurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, - const fileName& fieldName, - const Field<Type>& values, const bool verbose ) const { - fileName surfaceDir(samplePath/timeDir/surfaceName); + fileName surfaceDir(outputDir/surfaceName); if (!isDir(surfaceDir)) { @@ -70,7 +66,7 @@ void Foam::foamFileSurfaceWriter<Type>::write if (verbose) { - Info<< "Writing field " << fieldName << " to " << surfaceDir << endl; + Info<< "Writing geometry to " << surfaceDir << endl; } // Points @@ -78,6 +74,34 @@ void Foam::foamFileSurfaceWriter<Type>::write // Faces OFstream(surfaceDir/"faces")() << faces; +} + + +template<class Type> +void Foam::foamFileSurfaceWriter<Type>::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const fileName& fieldName, + const Field<Type>& values, + const bool verbose +) const +{ + fileName surfaceDir(outputDir/surfaceName); + + if (!isDir(surfaceDir)) + { + mkDir(surfaceDir); + } + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << surfaceDir << endl; + } + + // geometry should already have been written // Values to separate directory (e.g. "scalarField/p") diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H index 1a5601d5f0ead967aa5a80ddaa20454f2a1c9d93..207f36c9621020296262e6f18625f461b36e5734 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H @@ -72,13 +72,26 @@ public: // Member Functions - // Write + //- Return true if the surface format supports separate files + virtual bool separateFiles() + { + return true; + } + + //- Write geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C index 7175d02303fb1d73a6c166f18186e255370db452..2a5a0834d92bff2baedd2d540bcf12528f3de6b8 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C @@ -35,6 +35,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +makeSurfaceWriterType(foamFileSurfaceWriter, bool); makeSurfaceWriters(foamFileSurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C index f0f68e2701fb2f7b0a7ed1157c7eebd21c086a39..1409750c05772cca7c73ec0eb916bbbf4423d1a4 100644 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C @@ -25,10 +25,6 @@ License \*---------------------------------------------------------------------------*/ #include "nullSurfaceWriter.H" -#include "fileName.H" -#include "OFstream.H" -#include "faceList.H" -#include "OSspecific.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -53,8 +49,7 @@ Foam::nullSurfaceWriter<Type>::~nullSurfaceWriter() template<class Type> void Foam::nullSurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H index edfb607c90c309cd7f58c2ad559070d94d102df9..24a3f70d4c7ac906fe41250df33ed60d92fb9cf3 100644 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H @@ -76,8 +76,7 @@ public: //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C index e765fc5ddbe8e46c963dde894fc1873658b72873..693f56f4eab6196b67e4b09391df336aec0d7791 100644 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C @@ -35,6 +35,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +makeSurfaceWriterType(nullSurfaceWriter, bool); makeSurfaceWriters(nullSurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C similarity index 56% rename from src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index c3ef53df858bd3b92b61745c04c32b64bb559c3a..1dce1e4664c62ad9c8787ef9bd11fdbbee0d3c2a 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -24,91 +24,65 @@ License \*---------------------------------------------------------------------------*/ -#include "stlSurfaceWriter.H" -#include "fileName.H" +#include "proxySurfaceWriter.H" + +#include "MeshedSurfaceProxy.H" #include "OFstream.H" -#include "faceList.H" #include "OSspecific.H" -#include "triSurface.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> -Foam::stlSurfaceWriter<Type>::stlSurfaceWriter() +Foam::proxySurfaceWriter<Type>::proxySurfaceWriter(const word& ext) : - surfaceWriter<Type>() + surfaceWriter<Type>(), + ext_(ext) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template<class Type> -Foam::stlSurfaceWriter<Type>::~stlSurfaceWriter() +Foam::proxySurfaceWriter<Type>::~proxySurfaceWriter() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Type> -void Foam::stlSurfaceWriter<Type>::write +void Foam::proxySurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, - const fileName& fieldName, - const Field<Type>& values, const bool verbose ) const { - fileName surfaceDir(samplePath/timeDir); - - if (!isDir(surfaceDir)) + // avoid bad values + if (ext_.empty()) { - mkDir(surfaceDir); + return; } - fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".stl"); - - if (verbose) + if (!isDir(outputDir)) { - Info<< "Writing field " << fieldName << " to " << fName << endl; + mkDir(outputDir); } - // Convert faces to triangles. - DynamicList<labelledTri> tris(faces.size()); + fileName fName(outputDir/surfaceName + "." + ext_); - forAll(faces, i) + if (verbose) { - const face& f = faces[i]; - - faceList triFaces(f.nTriangles(points)); - label nTris = 0; - f.triangles(points, nTris, triFaces); - - forAll(triFaces, triI) - { - const face& tri = triFaces[triI]; - tris.append(labelledTri(tri[0], tri[1], tri[2], 0)); - } + Info<< "Writing geometry to " << fName << endl; } - triSurface + MeshedSurfaceProxy<face> ( - tris.shrink(), - geometricSurfacePatchList - ( - 1, - geometricSurfacePatch - ( - "patch", // geometricType - string::validate<word>(fieldName), // fieldName - 0 // index - ) - ), - points + points, + faces ).write(fName); + } diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H similarity index 72% rename from src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index bfa0e6453cb83bd66f704853e8f5e550425f7f64..ceeec731a7bb8d76ea11206a2def914a8aa83262 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -23,17 +23,17 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::stlSurfaceWriter + Foam::proxySurfaceWriter Description SourceFiles - stlSurfaceWriter.C + proxySurfaceWriter.C \*---------------------------------------------------------------------------*/ -#ifndef stlSurfaceWriter_H -#define stlSurfaceWriter_H +#ifndef proxySurfaceWriter_H +#define proxySurfaceWriter_H #include "surfaceWriter.H" @@ -43,48 +43,70 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class stlSurfaceWriter Declaration + Class proxySurfaceWriter Declaration \*---------------------------------------------------------------------------*/ template<class Type> -class stlSurfaceWriter +class proxySurfaceWriter : public surfaceWriter<Type> { + // Private data + + //- The associated file extension + word ext_; + public: //- Runtime type information - TypeName("stl"); + TypeName("proxy"); // Constructors - //- Construct null - stlSurfaceWriter(); + //- Construct for a given extension + proxySurfaceWriter(const word& ext); // Destructor - virtual ~stlSurfaceWriter(); + virtual ~proxySurfaceWriter(); // Member Functions + //- Always write separate geometry file + virtual bool separateFiles() + { + return true; + } + // Write + //- Write geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + + //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, const fileName& fieldName, const Field<Type>& values, const bool verbose = false - ) const; + ) const + {} }; @@ -95,7 +117,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "stlSurfaceWriter.C" +# include "proxySurfaceWriter.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C similarity index 89% rename from src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C index 779ccd2ba30ac78a9cda88cb3dca04c9937081a4..dd3a7ebff30a95d9552a2bd5443d0e767111b5e1 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ -#include "stlSurfaceWriter.H" +#include "proxySurfaceWriter.H" #include "surfaceWriters.H" #include "addToRunTimeSelectionTable.H" @@ -35,7 +35,9 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makeSurfaceWriters(stlSurfaceWriter); +// create type names, but do not register with run-time tables +makeTypeSurfaceWritersTypeName(proxySurfaceWriter, bool); +makeSurfaceWritersTypeName(proxySurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index 301f8e69dbc554d66af8b30119fa702d6af793ab..bab2ad38f38801f6367192791ed7bef9701b095a 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -25,9 +25,8 @@ License \*---------------------------------------------------------------------------*/ #include "rawSurfaceWriter.H" -#include "fileName.H" + #include "OFstream.H" -#include "faceList.H" #include "OSspecific.H" #include "IOmanip.H" @@ -37,9 +36,9 @@ template<class Type> void Foam::rawSurfaceWriter<Type>::writeGeometry ( const pointField& points, - const label& pointI, + const label pointI, Ostream& os -) const +) { const point& pt = points[pointI]; @@ -52,15 +51,16 @@ void Foam::rawSurfaceWriter<Type>::writeGeometry ( const pointField& points, const faceList& faces, - const label& faceI, + const label faceI, Ostream& os -) const +) { const point& ct = faces[faceI].centre(points); os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' '; } + // Write scalarField in raw format template<class Type> void Foam::rawSurfaceWriter<Type>::writeData @@ -70,38 +70,29 @@ void Foam::rawSurfaceWriter<Type>::writeData const faceList& faces, const scalarField& values, Ostream& os -) const +) { // header - os << "# " << fieldName; - - if (values.size() == points.size()) - { - os << " POINT_DATA " << values.size() - << nl; - } - else - { - os << " FACE_DATA " << values.size() - << nl; - } - - os << "# x y z " << fieldName - << endl; + os << "# x y z " << fieldName << endl; // Write data - forAll(values, elemI) + if (values.size() == points.size()) { - if (values.size() == points.size()) + forAll(values, elemI) { writeGeometry(points, elemI, os); + os << values[elemI] << nl; } - else + } + else + { + forAll(values, elemI) { writeGeometry(points, faces, elemI, os); + os << values[elemI] << nl; } - os << values[elemI] << endl; } + os << nl; } @@ -115,22 +106,9 @@ void Foam::rawSurfaceWriter<Type>::writeData const faceList& faces, const vectorField& values, Ostream& os -) const +) { // header - os << "# " << fieldName; - - if (values.size() == points.size()) - { - os << " POINT_DATA " << values.size() - << nl; - } - else - { - os << " FACE_DATA " << values.size() - << nl; - } - os << "# x y z " << fieldName << "_x " << fieldName << "_y " @@ -138,21 +116,27 @@ void Foam::rawSurfaceWriter<Type>::writeData << endl; // Write data - forAll(values, elemI) + if (values.size() == points.size()) { - const vector& v = values[elemI]; - - if (values.size() == points.size()) + forAll(values, elemI) { writeGeometry(points, elemI, os); + + const vector& v = values[elemI]; + os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; } - else + } + else + { + forAll(values, elemI) { writeGeometry(points, faces, elemI, os); - } - os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; + const vector& v = values[elemI]; + os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; + } } + } @@ -165,40 +149,32 @@ void Foam::rawSurfaceWriter<Type>::writeData const faceList& faces, const sphericalTensorField& values, Ostream& os -) const +) { // header - os << "# " << fieldName; - - if (values.size() == points.size()) - { - os << " POINT_DATA " << values.size() - << nl; - } - else - { - os << " FACE_DATA " << values.size() - << nl; - } - os << "# ii "; os << fieldName << "_ii" << endl; // Write data - forAll(values, elemI) + if (values.size() == points.size()) { - const sphericalTensor& v = values[elemI]; - - if (values.size() == points.size()) + forAll(values, elemI) { writeGeometry(points, elemI, os); + + const sphericalTensor& v = values[elemI]; + os << v[0] << nl; } - else + } + else + { + forAll(values, elemI) { writeGeometry(points, faces, elemI, os); - } - os << v[0] << nl; + const sphericalTensor& v = values[elemI]; + os << v[0] << nl; + } } } @@ -212,22 +188,9 @@ void Foam::rawSurfaceWriter<Type>::writeData const faceList& faces, const symmTensorField& values, Ostream& os -) const +) { // header - os << "# " << fieldName; - - if (values.size() == points.size()) - { - os << " POINT_DATA " << values.size() - << nl; - } - else - { - os << " FACE_DATA " << values.size() - << nl; - } - os << "# xx xy xz yy yz "; for(int i=0; i<6; i++) { @@ -236,22 +199,31 @@ void Foam::rawSurfaceWriter<Type>::writeData os << endl; // Write data - forAll(values, elemI) + if (values.size() == points.size()) { - const symmTensor& v = values[elemI]; - - if (values.size() == points.size()) + forAll(values, elemI) { writeGeometry(points, elemI, os); + + const symmTensor& v = values[elemI]; + + os << v[0] << ' ' << v[1] << ' ' << v[2] + << v[3] << ' ' << v[4] << ' ' << v[5] + << nl; } - else + } + else + { + forAll(values, elemI) { writeGeometry(points, faces, elemI, os); - } - os << v[0] << ' ' << v[1] << ' ' << v[2] - << v[3] << ' ' << v[4] << ' ' << v[5] - << nl; + const symmTensor& v = values[elemI]; + + os << v[0] << ' ' << v[1] << ' ' << v[2] + << v[3] << ' ' << v[4] << ' ' << v[5] + << nl; + } } } @@ -265,46 +237,40 @@ void Foam::rawSurfaceWriter<Type>::writeData const faceList& faces, const tensorField& values, Ostream& os -) const +) { // header - os << "# " << fieldName; - - if (values.size() == points.size()) - { - os << " POINT_DATA " << values.size() - << nl; - } - else - { - os << " FACE_DATA " << values.size() - << nl; - } - os << "# xx xy xz yx yy yz zx zy zz"; - for(int i=0; i<9; i++) + for (int i=0; i<9; ++i) { os << fieldName << "_" << i << " "; } os << endl; // Write data - forAll(values, elemI) + if (values.size() == points.size()) { - const tensor& v = values[elemI]; - - if (values.size() == points.size()) + forAll(values, elemI) { writeGeometry(points, elemI, os); + + const tensor& v = values[elemI]; + os << v[0] << ' ' << v[1] << ' ' << v[2] + << v[3] << ' ' << v[4] << ' ' << v[5] + << v[6] << ' ' << v[7] << ' ' << v[8] << nl; } - else + } + else + { + forAll(values, elemI) { writeGeometry(points, faces, elemI, os); - } - os << v[0] << ' ' << v[1] << ' ' << v[2] - << v[3] << ' ' << v[4] << ' ' << v[5] - << v[6] << ' ' << v[7] << ' ' << v[8] << nl; + const tensor& v = values[elemI]; + os << v[0] << ' ' << v[1] << ' ' << v[2] + << v[3] << ' ' << v[4] << ' ' << v[5] + << v[6] << ' ' << v[7] << ' ' << v[8] << nl; + } } } @@ -330,8 +296,66 @@ Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter() template<class Type> void Foam::rawSurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + OFstream os + ( + outputDir/surfaceName + ".raw" + ); + + if (verbose) + { + Info<< "Writing geometry to " << os.name() << endl; + } + + + // header + os << "# geometry NO_DATA " << faces.size() << nl + << "# x y z" << endl; + + // Write faces + forAll(faces, elemI) + { + writeGeometry(points, faces, elemI, os); + os << nl; + } + + os << nl; +} + + +namespace Foam +{ + // bool fields aren't supported + template<> + void Foam::rawSurfaceWriter<bool>::write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const fileName& fieldName, + const Field<bool>& values, + const bool verbose + ) const + {} +} + + +template<class Type> +void Foam::rawSurfaceWriter<Type>::write +( + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, @@ -340,21 +364,35 @@ void Foam::rawSurfaceWriter<Type>::write const bool verbose ) const { - fileName surfaceDir(samplePath/timeDir); - - if (!isDir(surfaceDir)) + if (!isDir(outputDir)) { - mkDir(surfaceDir); + mkDir(outputDir); } - fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".raw"); + OFstream os + ( + outputDir/fieldName + '_' + surfaceName + ".raw" + ); if (verbose) { - Info<< "Writing field " << fieldName << " to " << fName << endl; + Info<< "Writing field " << fieldName << " to " << os.name() << endl; + } + + + // header + os << "# " << fieldName; + if (values.size() == points.size()) + { + os << " POINT_DATA "; } + else + { + os << " FACE_DATA "; + } + + os << values.size() << nl; - OFstream os(fName); writeData(fieldName, points, faces, values, os); } diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H index 3b019d14a8a6c3f9f8dfa6942e8763df9e345c64..fc9fc0804ad3af8663f5377d5d92ce97f628be88 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H @@ -53,65 +53,65 @@ class rawSurfaceWriter { // Private Member Functions - void writeGeometry + static void writeGeometry ( const pointField& points, - const label& pointI, + const label pointI, Ostream& os - ) const; + ); - void writeGeometry + static void writeGeometry ( const pointField& points, const faceList& faces, - const label& faceI, + const label faceI, Ostream& os - ) const; + ); - void writeData + static void writeData ( const fileName& fieldName, const pointField& points, const faceList& faces, const scalarField& values, Ostream& os - ) const; + ); - void writeData + static void writeData ( const fileName& fieldName, const pointField& points, const faceList& faces, const vectorField& values, Ostream& os - ) const; + ); - void writeData + static void writeData ( const fileName& fieldName, const pointField& points, const faceList& faces, const sphericalTensorField& values, Ostream& os - ) const; + ); - void writeData + static void writeData ( const fileName& fieldName, const pointField& points, const faceList& faces, const symmTensorField& values, Ostream& os - ) const; + ); - void writeData + static void writeData ( const fileName& fieldName, const pointField& points, const faceList& faces, const tensorField& values, Ostream& os - ) const; + ); public: @@ -135,11 +135,20 @@ public: // Write + //- Write geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C index 3cc908dc2316348f9863503aff63c876ac63d9db..d0f6a91d6963b8fe88c8a48b3dddfdcb503d7266 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C @@ -35,6 +35,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +makeSurfaceWriterType(rawSurfaceWriter, bool); makeSurfaceWriters(rawSurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.C b/src/sampling/sampledSurface/writers/surfaceWriter.C index 1f1ed1893681d9f850ca54318d3a91966dcd7eae..99e19b96ddd4210183e095209b366bd7925a15da 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.C +++ b/src/sampling/sampledSurface/writers/surfaceWriter.C @@ -25,54 +25,83 @@ License \*---------------------------------------------------------------------------*/ #include "surfaceWriter.H" + +#include "MeshedSurfaceProxy.H" +#include "nullSurfaceWriter.H" +#include "proxySurfaceWriter.H" + #include "HashTable.H" #include "word.H" -#include "fileName.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - template<class Type> -autoPtr<surfaceWriter<Type> > surfaceWriter<Type>::New(const word& writeType) +Foam::autoPtr< Foam::surfaceWriter<Type> > +Foam::surfaceWriter<Type>::New(const word& writeType) { typename wordConstructorTable::iterator cstrIter = - wordConstructorTablePtr_ - ->find(writeType); + wordConstructorTablePtr_->find(writeType); if (cstrIter == wordConstructorTablePtr_->end()) { - FatalErrorIn + // not supported for this data type, but it generally does work + // (it handles the 'bool' specialization - ie, geometry write) + if ( - "surfaceWriter::New(const word&)" - ) << "Unknown write type " << writeType - << endl << endl - << "Valid write types : " << endl - << wordConstructorTablePtr_->toc() - << exit(FatalError); + Foam::surfaceWriter<bool>::wordConstructorTablePtr_->found + ( + writeType + ) + ) + { + // use 'null' handler instead + return autoPtr< surfaceWriter<Type> > + ( + new nullSurfaceWriter<Type>() + ); + } + else if (MeshedSurfaceProxy<face>::canWriteType(writeType)) + { + // generally unknown, but can be written via MeshedSurfaceProxy + // use 'proxy' handler instead + return autoPtr< surfaceWriter<Type> > + ( + new proxySurfaceWriter<Type>(writeType) + ); + } + + if (cstrIter == wordConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "surfaceWriter::New(const word&)" + ) << "Unknown write type \"" << writeType << "\"\n\n" + << "Valid write types : " + << wordConstructorTablePtr_->toc() << nl + << "Valid proxy types : " + << MeshedSurfaceProxy<face>::writeTypes() << endl + << exit(FatalError); + } } - return autoPtr<surfaceWriter<Type> >(cstrIter()()); + return autoPtr< surfaceWriter<Type> >(cstrIter()()); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> -surfaceWriter<Type>::surfaceWriter() +Foam::surfaceWriter<Type>::surfaceWriter() {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template<class Type> -surfaceWriter<Type>::~surfaceWriter() +Foam::surfaceWriter<Type>::~surfaceWriter() {} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 223d0a58d3e668ae25066f7ab4143bac4f0f8e31..b645c522ef84ed0d5f1284bc35721dd0c852855e 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -37,23 +37,33 @@ SourceFiles #include "Field.H" #include "typeInfo.H" -#include "runTimeSelectionTables.H" #include "autoPtr.H" #include "pointField.H" #include "faceList.H" +#include "fileName.H" + +#include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward declaration of friend functions and operators + +template<class Type> class surfaceWriter; +template<class Type> class nullSurfaceWriter; +template<class Type> class proxySurfaceWriter; + /*---------------------------------------------------------------------------*\ - Class surfaceWriter Declaration + Class surfaceWriter Declaration \*---------------------------------------------------------------------------*/ template<class Type> class surfaceWriter { + //- friendship between writer data types + template<class Type2> friend class surfaceWriter; public: @@ -91,12 +101,30 @@ public: // Member Functions + //- Return true if the surface format supports separate files + virtual bool separateFiles() + { + return false; + } + + + //- Writes single surface geometry to file. + virtual void write + ( + const fileName& outputDir, // <root>/<case>/surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const + {} + + //- Writes single surface to file. Either one value per vertex or // one value per face (detected by values.size()==faces.size()) virtual void write ( - const fileName& samplePath, // <root>/<case>/sampleSurfaces - const fileName& timeDir, // time directory + const fileName& outputDir, // <root>/<case>/surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/surfaceWriters.C b/src/sampling/sampledSurface/writers/surfaceWriters.C index 1346f55e2b386d0d517cb058097667b7da0efa4f..af6abeb461bae81adbcb342a5b52812d34753984 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriters.C +++ b/src/sampling/sampledSurface/writers/surfaceWriters.C @@ -33,8 +33,10 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // #define defineSurfaceWriterType(dataType) \ - defineNamedTemplateTypeNameAndDebug(surfaceWriter<dataType >, 0); \ - defineTemplatedRunTimeSelectionTable(surfaceWriter, word, dataType); + defineNamedTemplateTypeNameAndDebug(surfaceWriter< dataType >, 0); \ + defineTemplatedRunTimeSelectionTable(surfaceWriter, word, dataType) + +defineSurfaceWriterType(bool); defineSurfaceWriterType(scalar); defineSurfaceWriterType(vector); diff --git a/src/sampling/sampledSurface/writers/surfaceWriters.H b/src/sampling/sampledSurface/writers/surfaceWriters.H index 0e3e60a1a6f45ddbf081bbf64ba8f6db2f0ac942..d990b04daf478e5495d5d23d99e929db9d8732f3 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriters.H +++ b/src/sampling/sampledSurface/writers/surfaceWriters.H @@ -39,7 +39,7 @@ Description // Only used internally #define makeTypeSurfaceWritersTypeName(typeWriter, dataType) \ \ - defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0); + defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0) // Sometimes used externally #define makeSurfaceWritersTypeName(typeWriter) \ @@ -48,16 +48,16 @@ Description makeTypeSurfaceWritersTypeName(typeWriter, vector); \ makeTypeSurfaceWritersTypeName(typeWriter, sphericalTensor); \ makeTypeSurfaceWritersTypeName(typeWriter, symmTensor); \ - makeTypeSurfaceWritersTypeName(typeWriter, tensor); + makeTypeSurfaceWritersTypeName(typeWriter, tensor) // Define type info for single dataType template instantiation (eg, vector) #define makeSurfaceWriterType(typeWriter, dataType) \ \ - defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0); \ + defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0); \ addTemplatedToRunTimeSelectionTable \ ( \ surfaceWriter, typeWriter, dataType, word \ - ); + ) // Define type info for scalar, vector etc. instantiations @@ -67,7 +67,7 @@ Description makeSurfaceWriterType(typeWriter, vector); \ makeSurfaceWriterType(typeWriter, sphericalTensor); \ makeSurfaceWriterType(typeWriter, symmTensor); \ - makeSurfaceWriterType(typeWriter, tensor); + makeSurfaceWriterType(typeWriter, tensor) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index d2f529588c5180fdef433f5253982430099d9d64..ff4766a3253368a19278bb8f4b675a8d18bf9ee1 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -25,9 +25,8 @@ License \*---------------------------------------------------------------------------*/ #include "vtkSurfaceWriter.H" -#include "fileName.H" + #include "OFstream.H" -#include "faceList.H" #include "OSspecific.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -35,13 +34,12 @@ License template<class Type> void Foam::vtkSurfaceWriter<Type>::writeGeometry ( + Ostream& os, const pointField& points, - const faceList& faces, - Ostream& os -) const + const faceList& faces +) { - // Write vertex coordinates - + // header os << "# vtk DataFile Version 2.0" << nl << "sampleSurface" << nl @@ -57,7 +55,7 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry << float(pt.y()) << ' ' << float(pt.z()) << nl; } - os << endl; + os << nl; // Write faces @@ -84,193 +82,133 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry } -// Write scalarField in vtk format -template<class Type> -void Foam::vtkSurfaceWriter<Type>::writeData -( - const fileName& fieldName, - const pointField& points, - const scalarField& values, - Ostream& os -) const +namespace Foam { - // Write data - if (values.size() == points.size()) - { - os << "POINT_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - else - { - os << "CELL_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - os << fieldName << " 1 " << values.size() << " float" << nl; - - forAll(values, elemI) + // Write scalarField in vtk format + template<> + void Foam::vtkSurfaceWriter<Foam::scalar>::writeData + ( + Ostream& os, + const Field<Foam::scalar>& values + ) { - if (elemI) + os << "1 " << values.size() << " float" << nl; + + forAll(values, elemI) { - if (elemI % 10) - { - os << ' '; - } - else + if (elemI) { - os << nl; + if (elemI % 10) + { + os << ' '; + } + else + { + os << nl; + } } - } - os << float(values[elemI]); - } - os << nl; -} - -// Write vectorField in vtk format -template<class Type> -void Foam::vtkSurfaceWriter<Type>::writeData -( - const fileName& fieldName, - const pointField& points, - const vectorField& values, - Ostream& os -) const -{ - // Write data - if (values.size() == points.size()) - { - os << "POINT_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - else - { - os << "CELL_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; + const scalar& v = values[elemI]; + os << float(v); + } + os << nl; } - os << fieldName << " 3 " << values.size() << " float" << nl; - - forAll(values, elemI) + // Write vectorField in vtk format + template<> + void Foam::vtkSurfaceWriter<Foam::vector>::writeData + ( + Ostream& os, + const Field<Foam::vector>& values + ) { - const vector& v = values[elemI]; + os << "3 " << values.size() << " float" << nl; - os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) << nl; + forAll(values, elemI) + { + const vector& v = values[elemI]; + os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) + << nl; + } } -} -// Write sphericalTensorField in vtk format -template<class Type> -void Foam::vtkSurfaceWriter<Type>::writeData -( - const fileName& fieldName, - const pointField& points, - const sphericalTensorField& values, - Ostream& os -) const -{ - // Write data - if (values.size() == points.size()) - { - os << "POINT_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - else + // Write sphericalTensorField in vtk format + template<> + void Foam::vtkSurfaceWriter<Foam::sphericalTensor>::writeData + ( + Ostream& os, + const Field<sphericalTensor>& values + ) { - os << "CELL_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; + os << "1 " << values.size() << " float" << nl; + + forAll(values, elemI) + { + const sphericalTensor& v = values[elemI]; + os << float(v[0]) << nl; + } } - os << fieldName << " 1 " << values.size() << " float" << nl; - forAll(values, elemI) + // Write symmTensorField in vtk format + template<> + void Foam::vtkSurfaceWriter<Foam::symmTensor>::writeData + ( + Ostream& os, + const Field<symmTensor>& values + ) { - const sphericalTensor& v = values[elemI]; - - os << float(v[0]) - << nl; - } -} + os << "6 " << values.size() << " float" << nl; + forAll(values, elemI) + { + const symmTensor& v = values[elemI]; + os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) + << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) + << nl; -// Write symmTensorField in vtk format -template<class Type> -void Foam::vtkSurfaceWriter<Type>::writeData -( - const fileName& fieldName, - const pointField& points, - const symmTensorField& values, - Ostream& os -) const -{ - // Write data - if (values.size() == points.size()) - { - os << "POINT_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - else - { - os << "CELL_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; + } } - os << fieldName << " 6 " << values.size() << " float" << nl; - forAll(values, elemI) + // Write tensorField in vtk format + template<> + void Foam::vtkSurfaceWriter<Foam::tensor>::writeData + ( + Ostream& os, + const Field<tensor>& values + ) { - const symmTensor& v = values[elemI]; + os << "9 " << values.size() << " float" << nl; - os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) - << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) - << nl; + forAll(values, elemI) + { + const tensor& v = values[elemI]; + os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) + << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) + << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8]) + << nl; + } } + } -// Write tensorField in vtk format +// Write generic field in vtk format template<class Type> void Foam::vtkSurfaceWriter<Type>::writeData ( - const fileName& fieldName, - const pointField& points, - const tensorField& values, - Ostream& os -) const + Ostream& os, + const Field<Type>& values +) { - // Write data - if (values.size() == points.size()) - { - os << "POINT_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - else - { - os << "CELL_DATA " << values.size() - << nl - << "FIELD attributes 1" << nl; - } - - os << fieldName << " 9 " << values.size() << " float" << nl; + os << "1 " << values.size() << " float" << nl; forAll(values, elemI) { - const tensor& v = values[elemI]; - - os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) - << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) - << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8]) - << nl; + os << float(0) << nl; } } @@ -297,8 +235,34 @@ Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter() template<class Type> void Foam::vtkSurfaceWriter<Type>::write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + fileName fName(outputDir/surfaceName + ".vtk"); + + if (verbose) + { + Info<< "Writing geometry to " << fName << endl; + } + + OFstream os(fName); + writeGeometry(os, points, faces); +} + + +template<class Type> +void Foam::vtkSurfaceWriter<Type>::write +( + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, @@ -307,24 +271,40 @@ void Foam::vtkSurfaceWriter<Type>::write const bool verbose ) const { - fileName surfaceDir(samplePath/timeDir); - - if (!isDir(surfaceDir)) + if (!isDir(outputDir)) { - mkDir(surfaceDir); + mkDir(outputDir); } - fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".vtk"); + OFstream os + ( + outputDir/fieldName + '_' + surfaceName + ".vtk" + ); if (verbose) { - Info<< "Writing field " << fieldName << " to " << fName << endl; + Info<< "Writing field " << fieldName << " to " << os.name() << endl; } - OFstream os(fName); + writeGeometry(os, points, faces); + + // start writing data + if (values.size() == points.size()) + { + os << "POINT_DATA "; + } + else + { + os << "CELL_DATA "; + } + + os << values.size() << nl + << "FIELD attributes 1" << nl + << fieldName << " "; + + // Write data + writeData(os, values); - writeGeometry(points, faces, os); - writeData(fieldName, points, values, os); } diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index bf25f5261276421f787523d5634a09bc069a040c..1b8736f103afc32957783e0128307239b0626e90 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -53,52 +53,9 @@ class vtkSurfaceWriter { // Private Member Functions - void writeGeometry - ( - const pointField& points, - const faceList& faces, - Ostream& os - ) const; + static void writeGeometry(Ostream&, const pointField&, const faceList&); - void writeData - ( - const fileName& fieldName, - const pointField& points, - const scalarField& values, - Ostream& os - ) const; - - void writeData - ( - const fileName& fieldName, - const pointField& points, - const vectorField& values, - Ostream& os - ) const; - - void writeData - ( - const fileName& fieldName, - const pointField& points, - const sphericalTensorField& values, - Ostream& os - ) const; - - void writeData - ( - const fileName& fieldName, - const pointField& points, - const symmTensorField& values, - Ostream& os - ) const; - - void writeData - ( - const fileName& fieldName, - const pointField& points, - const tensorField& values, - Ostream& os - ) const; + static void writeData(Ostream&, const Field<Type>& values); public: @@ -122,11 +79,21 @@ public: // Write + //- Write geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + + //- Writes single surface to file. virtual void write ( - const fileName& samplePath, - const fileName& timeDir, + const fileName& outputDir, const fileName& surfaceName, const pointField& points, const faceList& faces, diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C index 6ce03ab197aae538164318e92caa7b3987d708a0..71a2fff034f098249edfcac8025825ed1d593378 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C @@ -35,6 +35,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +makeSurfaceWriterType(vtkSurfaceWriter, bool); makeSurfaceWriters(vtkSurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C b/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C deleted file mode 100644 index 41295b44b610453809db3818f56ac15cbcfa21db..0000000000000000000000000000000000000000 --- a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C +++ /dev/null @@ -1,572 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -\*---------------------------------------------------------------------------*/ - -#include "BasicMeshedSurface.H" -#include "boundBox.H" -#include "mergePoints.H" - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class Face> -inline bool Foam::BasicMeshedSurface<Face>::isTri() -{ - return false; -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template<class Face> -Foam::BasicMeshedSurface<Face>::BasicMeshedSurface() -: - ParentType(List<Face>(), pointField()) -{} - - -template<class Face> -Foam::BasicMeshedSurface<Face>::BasicMeshedSurface -( - const Xfer< pointField >& pointLst, - const Xfer< List<Face> >& faceLst -) -: - ParentType(List<Face>(), pointField()) -{ - reset(pointLst, faceLst); -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template<class Face> -Foam::BasicMeshedSurface<Face>::~BasicMeshedSurface() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template<class Face> -void Foam::BasicMeshedSurface<Face>::clear() -{ - ParentType::clearOut(); - - storedPoints().clear(); - storedFaces().clear(); -} - - -template<class Face> -void Foam::BasicMeshedSurface<Face>::movePoints(const pointField& newPoints) -{ - // Remove all geometry dependent data - ParentType::clearTopology(); - - // Adapt for new point position - ParentType::movePoints(newPoints); - - // Copy new points - storedPoints() = newPoints; -} - - -template<class Face> -void Foam::BasicMeshedSurface<Face>::scalePoints(const scalar& scaleFactor) -{ - // avoid bad scaling - if (scaleFactor > 0 && scaleFactor != 1.0) - { - // Remove all geometry dependent data - ParentType::clearTopology(); - - // Adapt for new point position - ParentType::movePoints(pointField()); - - storedPoints() *= scaleFactor; - } -} - - -template<class Face> -void Foam::BasicMeshedSurface<Face>::reset -( - const Xfer< pointField >& pointLst, - const Xfer< List<Face> >& faceLst -) -{ - ParentType::clearOut(); - - // Take over new primitive data. - // Optimized to avoid overwriting data at all - if (&pointLst) - { - storedPoints().transfer(pointLst()); - } - - if (&faceLst) - { - storedFaces().transfer(faceLst()); - } -} - - -template<class Face> -void Foam::BasicMeshedSurface<Face>::reset -( - const Xfer< List<point> >& pointLst, - const Xfer< List<Face> >& faceLst -) -{ - ParentType::clearOut(); - - // Take over new primitive data. - // Optimized to avoid overwriting data at all - if (&pointLst) - { - storedPoints().transfer(pointLst()); - } - - if (&faceLst) - { - storedFaces().transfer(faceLst()); - } -} - - -// Remove badly degenerate faces, double faces. -template<class Face> -void Foam::BasicMeshedSurface<Face>::cleanup(const bool verbose) -{ - // merge points (already done for STL, TRI) - stitchFaces(SMALL, verbose); - - checkFaces(verbose); - this->checkTopology(verbose); -} - - -template<class Face> -bool Foam::BasicMeshedSurface<Face>::stitchFaces -( - const scalar tol, - const bool verbose -) -{ - pointField& pointLst = this->storedPoints(); - - // Merge points - labelList pointMap(pointLst.size()); - pointField newPoints(pointLst.size()); - - bool hasMerged = mergePoints(pointLst, tol, verbose, pointMap, newPoints); - - if (!hasMerged) - { - return false; - } - - if (verbose) - { - Info<< "BasicMeshedSurface::stitchFaces : Renumbering all faces" - << endl; - } - - // Set the coordinates to the merged ones - pointLst.transfer(newPoints); - - List<Face>& faceLst = this->storedFaces(); - - List<label> faceMap(faceLst.size()); - - // Reset the point labels to the unique points array - label newFaceI = 0; - forAll(faceLst, faceI) - { - Face& f = faceLst[faceI]; - forAll(f, fp) - { - f[fp] = pointMap[f[fp]]; - } - - // for extra safety: collapse face as well - if (f.collapse() >= 3) - { - if (newFaceI != faceI) - { - faceLst[newFaceI] = f; - } - faceMap[newFaceI] = faceI; - newFaceI++; - } - else if (verbose) - { - Pout<< "BasicMeshedSurface::stitchFaces : " - << "Removing collapsed face " << faceI << endl - << " vertices :" << f << endl; - } - } - pointMap.clear(); - - if (newFaceI != faceLst.size()) - { - if (verbose) - { - Pout<< "BasicMeshedSurface::stitchFaces : " - << "Removed " << faceLst.size() - newFaceI - << " faces" << endl; - } - faceLst.setSize(newFaceI); - remapFaces(faceMap); - } - faceMap.clear(); - - // Merging points might have changed geometric factors - ParentType::clearOut(); - return true; -} - - -// Remove badly degenerate faces and double faces. -template<class Face> -bool Foam::BasicMeshedSurface<Face>::checkFaces -( - const bool verbose -) -{ - bool changed = false; - List<Face>& faceLst = this->storedFaces(); - - List<label> faceMap(faceLst.size()); - - label newFaceI = 0; - // Detect badly labelled faces and mark degenerate faces - const label maxPointI = this->points().size() - 1; - forAll(faceLst, faceI) - { - Face& f = faceLst[faceI]; - - // avoid degenerate faces - if (f.collapse() >= 3) - { - forAll(f, fp) - { - if (f[fp] < 0 || f[fp] > maxPointI) - { - FatalErrorIn("BasicMeshedSurface::checkFaces(bool)") - << "face " << f - << " uses point indices outside point range 0.." - << maxPointI - << exit(FatalError); - } - } - - faceMap[faceI] = faceI; - newFaceI++; - } - else - { - // mark as bad face - faceMap[faceI] = -1; - - changed = true; - if (verbose) - { - WarningIn - ( - "BasicMeshedSurface::checkFaces(bool verbose)" - ) << "face[" << faceI << "] = " << f - << " does not have three unique vertices" << endl; - } - } - } - - // Detect doubled faces - // do not touch the faces - const labelListList& fFaces = this->faceFaces(); - newFaceI = 0; - forAll(faceLst, faceI) - { - // skip already collapsed faces: - if (faceMap[faceI] < 0) - { - continue; - } - - const Face& f = faceLst[faceI]; - - // duplicate face check - bool okay = true; - const labelList& neighbours = fFaces[faceI]; - - // Check if faceNeighbours use same points as this face. - // Note: discards normal information - sides of baffle are merged. - forAll(neighbours, neighI) - { - const label neiFaceI = neighbours[neighI]; - - if (neiFaceI <= faceI || faceMap[neiFaceI] < 0) - { - // lower numbered faces already checked - // skip neighbours that are themselves collapsed - continue; - } - - const Face& nei = faceLst[neiFaceI]; - - if (f == nei) - { - okay = false; - - if (verbose) - { - WarningIn - ( - "BasicMeshedSurface::checkFaces(bool verbose)" - ) << "faces share the same vertices:" << nl - << " face[" << faceI << "] : " << f << nl - << " face[" << neiFaceI << "] : " << nei << endl; - // printFace(Warning, " ", f, points()); - // printFace(Warning, " ", nei, points()); - } - - break; - } - } - - if (okay) - { - faceMap[faceI] = faceI; - newFaceI++; - } - else - { - faceMap[faceI] = -1; - } - } - - // Phase 1: pack - // Done to keep numbering constant in phase 1 - - if (changed || newFaceI < faceLst.size()) - { - changed = true; - - if (verbose) - { - WarningIn - ( - "BasicMeshedSurface::checkFaces(bool verbose)" - ) << "Removed " << faceLst.size() - newFaceI - << " illegal faces." << endl; - } - - // compress the face list - newFaceI = 0; - forAll(faceLst, faceI) - { - if (faceMap[faceI] >= 0) - { - if (newFaceI != faceI) - { - faceLst[newFaceI] = faceLst[faceI]; - } - faceMap[newFaceI] = faceI; - newFaceI++; - } - } - - faceLst.setSize(newFaceI); - remapFaces(faceMap); - } - faceMap.clear(); - - // Topology can change because of renumbering - ParentType::clearOut(); - return changed; -} - - -template<class Face> -Foam::label Foam::BasicMeshedSurface<Face>::triangulate() -{ - return triangulate - ( - const_cast<List<label>&>(List<label>::null()) - ); -} - - -template<class Face> -Foam::label Foam::BasicMeshedSurface<Face>::triangulate -( - List<label>& faceMapOut -) -{ - label nTri = 0; - label maxTri = 0; // the maximum number of triangles for any single face - List<Face>& faceLst = this->storedFaces(); - - // determine how many triangles will be needed - forAll(faceLst, faceI) - { - const label n = faceLst[faceI].nTriangles(); - if (maxTri < n) - { - maxTri = n; - } - nTri += n; - } - - // nothing to do - if (nTri <= faceLst.size()) - { - if (&faceMapOut) - { - faceMapOut.clear(); - } - return 0; - } - - List<Face> newFaces(nTri); - List<label> faceMap; - - // reuse storage from optional faceMap - if (&faceMapOut) - { - faceMap.transfer(faceMapOut); - } - faceMap.setSize(nTri); - - // remember the number of *additional* faces - nTri -= faceLst.size(); - - if (this->points().empty()) - { - // triangulate without points - // simple face triangulation around f[0] - label newFaceI = 0; - forAll(faceLst, faceI) - { - const Face& f = faceLst[faceI]; - - for (label fp = 1; fp < f.size() - 1; ++fp) - { - label fp1 = f.fcIndex(fp); - - newFaces[newFaceI] = triFace(f[0], f[fp], f[fp1]); - faceMap[newFaceI] = faceI; - newFaceI++; - } - } - } - else - { - // triangulate with points - List<face> tmpTri(maxTri); - - label newFaceI = 0; - forAll(faceLst, faceI) - { - // 'face' not '<Face>' - const face& f = faceLst[faceI]; - - label nTmp; - f.triangles(this->points(), nTmp, tmpTri); - for (label triI = 0; triI < nTmp; triI++) - { - newFaces[newFaceI] = Face - ( - static_cast<UList<label>&>(tmpTri[triI]) - ); - faceMap[newFaceI] = faceI; - newFaceI++; - } - } - } - - faceLst.transfer(newFaces); - remapFaces(faceMap); - - // optionally return the faceMap - if (&faceMapOut) - { - faceMapOut.transfer(faceMap); - } - faceMap.clear(); - - // Topology can change because of renumbering - ParentType::clearOut(); - return nTri; -} - - -// dummy implementation to avoid a pure virtual class -template<class Face> -void Foam::BasicMeshedSurface<Face>::remapFaces(const UList<label>&) -{ -} - - -template<class Face> -void Foam::BasicMeshedSurface<Face>::writeStats(Ostream& os) const -{ - os << "points : " << this->points().size() << nl; - if (this->isTri()) - { - os << "triangles : " << this->size() << nl; - } - else - { - label nTri = 0; - label nQuad = 0; - forAll(*this, i) - { - const label n = this->operator[](i).size(); - - if (n == 3) - { - nTri++; - } - else if (n == 4) - { - nQuad++; - } - } - - os << "faces : " << this->size() - << " (tri:" << nTri << " quad:" << nQuad - << " poly:" << (this->size() - nTri - nQuad ) << ")" << nl; - } - - os << "boundingBox : " << boundBox(this->points()) << endl; -} - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// ************************************************************************* // diff --git a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.H b/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.H deleted file mode 100644 index ab60baf93de8ab5bacd94958bb5931df297fec34..0000000000000000000000000000000000000000 --- a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.H +++ /dev/null @@ -1,223 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Class - Foam::BasicMeshedSurface - -Description - Holds surfaces without any zone information - -SourceFiles - BasicMeshedSurface.C - -\*---------------------------------------------------------------------------*/ - -#ifndef BasicMeshedSurface_H -#define BasicMeshedSurface_H - -#include "PrimitivePatch.H" -#include "PatchTools.H" -#include "pointField.H" -#include "face.H" -#include "triFace.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// Forward declaration of friend functions and operators - -/*---------------------------------------------------------------------------*\ - Class BasicMeshedSurface Declaration -\*---------------------------------------------------------------------------*/ - -template<class Face> -class BasicMeshedSurface -: - public PrimitivePatch<Face, ::Foam::List, pointField, point> -{ - - // Private typedefs - - typedef PrimitivePatch - < - Face, - ::Foam::List, - pointField, - point - > - ParentType; - -protected: - - // Protected Member Functions - - //- Non-const access to global points - pointField& storedPoints() - { - return const_cast<pointField&>(ParentType::points()); - } - - //- Non-const access to the faces - List<Face>& storedFaces() - { - return static_cast<List<Face> &>(*this); - } - - //- Set new zones from faceMap - virtual void remapFaces(const UList<label>& faceMap); - -public: - - // Static - - //- Face storage only handles triangulated faces - inline static bool isTri(); - - - // Constructors - - //- Construct null - BasicMeshedSurface(); - - //- Construct by transferring components (points, faces). - BasicMeshedSurface - ( - const Xfer< pointField >&, - const Xfer< List<Face> >& - ); - - // Destructor - - virtual ~BasicMeshedSurface(); - - // Member Functions - - // Access - - //- Return const access to the faces - inline const List<Face>& faces() const - { - return static_cast<const List<Face> &>(*this); - } - - // Edit - - //- Clear all storage - virtual void clear(); - - //- Move points - virtual void movePoints(const pointField&); - - //- Scale points. A non-positive factor is ignored - virtual void scalePoints(const scalar&); - - //- Transfer components (points, faces). - virtual void reset - ( - const Xfer< pointField >&, - const Xfer< List<Face> >& - ); - - //- Transfer components (points, faces). - virtual void reset - ( - const Xfer< List<point> >&, - const Xfer< List<Face> >& - ); - - //- Remove invalid faces - virtual void cleanup(const bool verbose); - - virtual bool stitchFaces - ( - const scalar tol=SMALL, - const bool verbose=false - ); - - virtual bool checkFaces - ( - const bool verbose=false - ); - - //- Triangulate in-place, returning the number of triangles added - virtual label triangulate(); - - //- Triangulate in-place, returning the number of triangles added - // and setting a map of original face Ids. - // The faceMap is zero-sized when no triangulation was done. - virtual label triangulate(List<label>& faceMap); - - - // Write - - void writeStats(Ostream& os) const; - -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -//- Specialization for holding triangulated information -template<> -inline bool BasicMeshedSurface<triFace>::isTri() -{ - return true; -} - -//- Specialization for holding triangulated information -template<> -inline label BasicMeshedSurface<triFace>::triangulate() -{ - return 0; -} - -//- Specialization for holding triangulated information -template<> -inline label BasicMeshedSurface<triFace>::triangulate(List<label>& faceMap) -{ - if (&faceMap) - { - faceMap.clear(); - } - - return 0; -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository -# include "BasicMeshedSurface.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/surfMesh/Make/files b/src/surfMesh/Make/files index 2a51d95fbf77bdff3098c3b67e2c1403c3a972fe..55b12af52e9310cf497cd3c9359452f083d4daee 100644 --- a/src/surfMesh/Make/files +++ b/src/surfMesh/Make/files @@ -2,16 +2,20 @@ surfZone/surfZone/surfZone.C surfZone/surfZone/surfZoneIOList.C surfZone/surfZoneIdentifier/surfZoneIdentifier.C +MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C + MeshedSurface/MeshedSurfaceCore.C MeshedSurface/MeshedSurfaces.C UnsortedMeshedSurface/UnsortedMeshedSurfaces.C +MeshedSurfaceProxy/MeshedSurfaceProxyCore.C + surfaceRegistry/surfaceRegistry.C -surfFields/surfFields.C -surfPointFields/surfPointFields.C surfMesh/surfMesh.C surfMesh/surfMeshClear.C surfMesh/surfMeshIO.C +surfFields/surfFields/surfFields.C +surfFields/surfPointFields/surfPointFields.C surfaceFormats = surfaceFormats $(surfaceFormats)/surfaceFormatsCore.C @@ -22,11 +26,10 @@ $(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C $(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C $(surfaceFormats)/nas/NASsurfaceFormatCore.C $(surfaceFormats)/nas/NASsurfaceFormatRunTime.C -$(surfaceFormats)/obj/OBJsurfaceFormatCore.C $(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C -$(surfaceFormats)/off/OFFsurfaceFormatCore.C $(surfaceFormats)/off/OFFsurfaceFormatRunTime.C -$(surfaceFormats)/smesh/SMESHsurfaceFormatCore.C +$(surfaceFormats)/ofs/OFSsurfaceFormatCore.C +$(surfaceFormats)/ofs/OFSsurfaceFormatRunTime.C $(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C $(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C $(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C @@ -37,6 +40,10 @@ $(surfaceFormats)/tri/TRIsurfaceFormatCore.C $(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C $(surfaceFormats)/vtk/VTKsurfaceFormatCore.C $(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C +$(surfaceFormats)/wrl/WRLsurfaceFormatCore.C +$(surfaceFormats)/wrl/WRLsurfaceFormatRunTime.C +$(surfaceFormats)/x3d/X3DsurfaceFormatCore.C +$(surfaceFormats)/x3d/X3DsurfaceFormatRunTime.C LIB = $(FOAM_LIBBIN)/libsurfMesh diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index b446f3c0efbf94bbce9a919e6beaef512c37050e..8bcab42089f7936519567d3e0c9ce922decee5cc 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -26,8 +26,8 @@ License #include "MeshedSurface.H" #include "UnsortedMeshedSurface.H" -#include "IFstream.H" -#include "OFstream.H" +#include "MeshedSurfaceProxy.H" +#include "mergePoints.H" #include "Time.H" #include "ListOps.H" #include "polyBoundaryMesh.H" @@ -38,6 +38,13 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +template<class Face> +inline bool Foam::MeshedSurface<Face>::isTri() +{ + return false; +} + + template<class Face> Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes() { @@ -61,21 +68,13 @@ bool Foam::MeshedSurface<Face>::canReadType const bool verbose ) { - // handle 'native' format directly - if (isNative(ext)) - { - return true; - } - else - { - return checkSupport - ( - readTypes() | SiblingType::readTypes(), - ext, - verbose, - "reading" - ); - } + return checkSupport + ( + readTypes() | FriendType::readTypes(), + ext, + verbose, + "reading" + ); } @@ -86,13 +85,13 @@ bool Foam::MeshedSurface<Face>::canWriteType const bool verbose ) { - // handle 'native' format directly - if (isNative(ext)) - { - return true; - } - - return checkSupport(writeTypes(), ext, verbose, "writing"); + return checkSupport + ( + writeTypes() | ProxyType::writeTypes(), + ext, + verbose, + "writing" + ); } @@ -116,7 +115,7 @@ template<class Face> void Foam::MeshedSurface<Face>::write ( const fileName& name, - const MeshedSurface& surf + const MeshedSurface<Face>& surf ) { if (debug) @@ -127,30 +126,36 @@ void Foam::MeshedSurface<Face>::write << endl; } - word ext = name.ext(); - - // handle 'native' format directly - if (isNative(ext)) - { - surf.write(OFstream(name)()); - return; - } + const word ext = name.ext(); typename writefileExtensionMemberFunctionTable::iterator mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext); if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) { - FatalErrorIn - ( - "MeshedSurface::write(const fileName&)" - ) << "Unknown file extension " << ext << nl << nl - << "Valid types are :" << endl - << writeTypes() - << exit(FatalError); - } + // no direct writer, delegate to proxy if possible + wordHashSet supported = ProxyType::writeTypes(); - mfIter()(name, surf); + if (supported.found(ext)) + { + MeshedSurfaceProxy<Face>(surf).write(name); + } + else + { + FatalErrorIn + ( + "MeshedSurface::write" + "(const fileName&, const MeshedSurface&)" + ) << "Unknown file extension " << ext << nl << nl + << "Valid types are :" << endl + << (supported | writeTypes()) + << exit(FatalError); + } + } + else + { + mfIter()(name, surf); + } } @@ -158,36 +163,42 @@ void Foam::MeshedSurface<Face>::write template<class Face> Foam::MeshedSurface<Face>::MeshedSurface() +: + ParentType(List<Face>(), pointField()) {} template<class Face> Foam::MeshedSurface<Face>::MeshedSurface ( - const Xfer<pointField>& pointLst, - const Xfer<List<Face> >& faceLst, - const Xfer<surfZoneList>& zoneLst + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< surfZoneList >& zoneLst ) : - ParentType(pointLst, faceLst), - zones_(zoneLst) -{} + ParentType(List<Face>(), pointField()), + zones_() +{ + reset(pointLst, faceLst, zoneLst); +} template<class Face> Foam::MeshedSurface<Face>::MeshedSurface ( - const Xfer<pointField>& pointLst, - const Xfer<List<Face> >& faceLst, + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, const UList<label>& zoneSizes, const UList<word>& zoneNames ) : - ParentType(pointLst, faceLst) + ParentType(List<Face>(), pointField()) { - if (&zoneSizes) + reset(pointLst, faceLst, Xfer<surfZoneList>()); + + if (zoneSizes.size()) { - if (&zoneNames) + if (zoneNames.size()) { addZones(zoneSizes, zoneNames); } @@ -196,10 +207,58 @@ Foam::MeshedSurface<Face>::MeshedSurface addZones(zoneSizes); } } - else +} + + +template<class Face> +Foam::MeshedSurface<Face>::MeshedSurface +( + const MeshedSurface<Face>& surf +) +: + ParentType(surf.faces(), surf.points()), + zones_(surf.surfZones()) +{} + + +template<class Face> +Foam::MeshedSurface<Face>::MeshedSurface +( + const UnsortedMeshedSurface<Face>& surf +) +: + ParentType(List<Face>(), surf.points()) +{ + labelList faceMap; + this->storedZones().transfer(surf.sortedZones(faceMap)); + + const List<Face>& origFaces = surf.faces(); + List<Face> newFaces(origFaces.size()); + + // this is somewhat like ListOps reorder and/or IndirectList + forAll(newFaces, faceI) { - oneZone(); + newFaces[faceI] = origFaces[faceMap[faceI]]; } + + this->storedFaces().transfer(newFaces); +} + + +template<class Face> +Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh) +: + ParentType(List<Face>(), pointField()) +{ + // same face type as surfMesh + MeshedSurface<face> surf + ( + xferCopy(mesh.points()), + xferCopy(mesh.faces()), + xferCopy(mesh.surfZones()) + ); + + this->transcribe(surf); } @@ -209,6 +268,8 @@ Foam::MeshedSurface<Face>::MeshedSurface const polyBoundaryMesh& bMesh, const bool useGlobalPoints ) +: + ParentType(List<Face>(), pointField()) { const polyMesh& mesh = bMesh.mesh(); const polyPatchList& bPatches = bMesh; @@ -277,14 +338,56 @@ Foam::MeshedSurface<Face>::MeshedSurface template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh) +Foam::MeshedSurface<Face>::MeshedSurface +( + const fileName& name, + const word& ext +) +: + ParentType(List<Face>(), pointField()) +{ + read(name, ext); +} + + +template<class Face> +Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name) +: + ParentType(List<Face>(), pointField()) +{ + read(name); +} + + +template<class Face> +Foam::MeshedSurface<Face>::MeshedSurface +( + const Time& t, + const word& surfName +) +: + ParentType(List<Face>(), pointField()) { + surfMesh mesh + ( + IOobject + ( + "dummyName", + t.timeName(), + t, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + surfName + ); + // same face type as surfMesh MeshedSurface<face> surf ( - xferCopy(mesh.points()), - xferCopy(mesh.faces()), - xferCopy(mesh.surfZones()) + xferMove(mesh.storedPoints()), + xferMove(mesh.storedFaces()), + xferMove(mesh.storedZones()) ); this->transcribe(surf); @@ -294,265 +397,559 @@ Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh) template<class Face> Foam::MeshedSurface<Face>::MeshedSurface ( - const UnsortedMeshedSurface<Face>& surf + const Xfer< UnsortedMeshedSurface<Face> >& surf ) +: + ParentType(List<Face>(), pointField()) { - labelList faceMap; - surfZoneList zoneLst = surf.sortedZones(faceMap); - zones_.transfer(zoneLst); - - const List<Face>& origFaces = surf.faces(); - List<Face> newFaces(origFaces.size()); - - // this is somewhat like ListOps reorder and/or IndirectList - forAll(newFaces, faceI) - { - newFaces[faceI] = origFaces[faceMap[faceI]]; - } - - reset(xferCopy(surf.points()), xferMove(newFaces)); + transfer(surf()); } template<class Face> Foam::MeshedSurface<Face>::MeshedSurface ( - const fileName& name, - const word& ext + const Xfer< MeshedSurface<Face> >& surf ) +: + ParentType(List<Face>(), pointField()) { - read(name, ext); + transfer(surf()); } + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name) +Foam::MeshedSurface<Face>::~MeshedSurface() +{} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<class Face> +void Foam::MeshedSurface<Face>::remapFaces +( + const UList<label>& faceMap +) { - read(name); + // recalculate the zone start/size + if (&faceMap && faceMap.size()) + { + surfZoneList& zones = storedZones(); + + if (zones.size() == 1) + { + // optimized for single zone case + zones[0].size() = faceMap.size(); + } + else if (zones.size()) + { + label newFaceI = 0; + label origEndI = 0; + forAll(zones, zoneI) + { + surfZone& zone = zones[zoneI]; + + // adjust zone start + zone.start() = newFaceI; + origEndI += zone.size(); + + for (label faceI = newFaceI; faceI < faceMap.size(); ++faceI) + { + if (faceMap[faceI] < origEndI) + { + ++newFaceI; + } + else + { + break; + } + } + + // adjust zone size + zone.size() = newFaceI - zone.start(); + } + } + } } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(Istream& is) +void Foam::MeshedSurface<Face>::clear() { - read(is); + ParentType::clearOut(); + + storedPoints().clear(); + storedFaces().clear(); + storedZones().clear(); } template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(const Time& d, const word& surfName) +void Foam::MeshedSurface<Face>::movePoints(const pointField& newPoints) { - read(IFstream(findMeshFile(d, surfName))()); + // Remove all geometry dependent data + ParentType::clearTopology(); + + // Adapt for new point position + ParentType::movePoints(newPoints); + + // Copy new points + storedPoints() = newPoints; } template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(const MeshedSurface& surf) -: - ParentType(surf), - zones_(surf.zones_) -{} +void Foam::MeshedSurface<Face>::scalePoints(const scalar& scaleFactor) +{ + // avoid bad scaling + if (scaleFactor > 0 && scaleFactor != 1.0) + { + // Remove all geometry dependent data + ParentType::clearTopology(); + + // Adapt for new point position + ParentType::movePoints(pointField()); + + storedPoints() *= scaleFactor; + } +} template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface +void Foam::MeshedSurface<Face>::reset ( - const Xfer<UnsortedMeshedSurface<Face> >& surf + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< surfZoneList >& zoneLst ) { - transfer(surf()); + ParentType::clearOut(); + + // Take over new primitive data. + // Optimized to avoid overwriting data at all + if (&pointLst) + { + storedPoints().transfer(pointLst()); + } + + if (&faceLst) + { + storedFaces().transfer(faceLst()); + } + + if (&zoneLst) + { + storedZones().transfer(zoneLst()); + } } template<class Face> -Foam::MeshedSurface<Face>::MeshedSurface(const Xfer<MeshedSurface>& surf) +void Foam::MeshedSurface<Face>::reset +( + const Xfer< List<point> >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< surfZoneList >& zoneLst +) { - transfer(surf()); + ParentType::clearOut(); + + // Take over new primitive data. + // Optimized to avoid overwriting data at all + if (&pointLst) + { + storedPoints().transfer(pointLst()); + } + + if (&faceLst) + { + storedFaces().transfer(faceLst()); + } + + if (&zoneLst) + { + storedZones().transfer(zoneLst()); + } } +// Remove badly degenerate faces, double faces. +template<class Face> +void Foam::MeshedSurface<Face>::cleanup(const bool verbose) +{ + // merge points (already done for STL, TRI) + stitchFaces(SMALL, verbose); + + checkFaces(verbose); + this->checkTopology(verbose); +} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template<class Face> -Foam::MeshedSurface<Face>::~MeshedSurface() -{} +bool Foam::MeshedSurface<Face>::stitchFaces +( + const scalar tol, + const bool verbose +) +{ + pointField& pointLst = this->storedPoints(); + // Merge points + labelList pointMap(pointLst.size()); + pointField newPoints(pointLst.size()); -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + bool hasMerged = mergePoints(pointLst, tol, verbose, pointMap, newPoints); + if (!hasMerged) + { + return false; + } -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + if (verbose) + { + Info<< "MeshedSurface::stitchFaces : Renumbering all faces" + << endl; + } -template<class Face> -void Foam::MeshedSurface<Face>::oneZone(const word& name) -{ - word zoneName(name); - if (zoneName.empty()) + // Set the coordinates to the merged ones + pointLst.transfer(newPoints); + + List<Face>& faceLst = this->storedFaces(); + + List<label> faceMap(faceLst.size()); + + // Reset the point labels to the unique points array + label newFaceI = 0; + forAll(faceLst, faceI) { - if (zones_.size()) + Face& f = faceLst[faceI]; + forAll(f, fp) + { + f[fp] = pointMap[f[fp]]; + } + + // for extra safety: collapse face as well + if (f.collapse() >= 3) { - zoneName = zones_[0].name(); + if (newFaceI != faceI) + { + faceLst[newFaceI] = f; + } + faceMap[newFaceI] = faceI; + newFaceI++; } - if (zoneName.empty()) + else if (verbose) { - zoneName = "zone0"; + Pout<< "MeshedSurface::stitchFaces : " + << "Removing collapsed face " << faceI << endl + << " vertices :" << f << endl; } } + pointMap.clear(); - // set single default zone - zones_.setSize(1); - zones_[0] = surfZone - ( - zoneName, - this->size(), // zone size - 0, // zone start - 0 // zone index - ); + if (newFaceI != faceLst.size()) + { + if (verbose) + { + Pout<< "MeshedSurface::stitchFaces : " + << "Removed " << faceLst.size() - newFaceI + << " faces" << endl; + } + faceLst.setSize(newFaceI); + remapFaces(faceMap); + } + faceMap.clear(); + + // Merging points might have changed geometric factors + ParentType::clearOut(); + return true; } +// Remove badly degenerate faces and double faces. template<class Face> -void Foam::MeshedSurface<Face>::checkZones() +bool Foam::MeshedSurface<Face>::checkFaces +( + const bool verbose +) { - // extra safety, ensure we have at some zones - // and they cover all the faces - fix start silently - if (zones_.size() <= 1) + bool changed = false; + List<Face>& faceLst = this->storedFaces(); + + List<label> faceMap(faceLst.size()); + + label newFaceI = 0; + // Detect badly labelled faces and mark degenerate faces + const label maxPointI = this->points().size() - 1; + forAll(faceLst, faceI) { - oneZone(); + Face& f = faceLst[faceI]; + + // avoid degenerate faces + if (f.collapse() >= 3) + { + forAll(f, fp) + { + if (f[fp] < 0 || f[fp] > maxPointI) + { + FatalErrorIn("MeshedSurface::checkFaces(bool)") + << "face " << f + << " uses point indices outside point range 0.." + << maxPointI + << exit(FatalError); + } + } + + faceMap[faceI] = faceI; + newFaceI++; + } + else + { + // mark as bad face + faceMap[faceI] = -1; + + changed = true; + if (verbose) + { + WarningIn + ( + "MeshedSurface::checkFaces(bool verbose)" + ) << "face[" << faceI << "] = " << f + << " does not have three unique vertices" << endl; + } + } } - else + + // Detect doubled faces + // do not touch the faces + const labelListList& fFaces = this->faceFaces(); + newFaceI = 0; + forAll(faceLst, faceI) { - label count = 0; - forAll(zones_, zoneI) + // skip already collapsed faces: + if (faceMap[faceI] < 0) { - zones_[zoneI].start() = count; - count += zones_[zoneI].size(); + continue; } - if (count < size()) + const Face& f = faceLst[faceI]; + + // duplicate face check + bool okay = true; + const labelList& neighbours = fFaces[faceI]; + + // Check if faceNeighbours use same points as this face. + // Note: discards normal information - sides of baffle are merged. + forAll(neighbours, neighI) { - WarningIn - ( - "MeshedSurface::checkZones()\n" - ) - << "more faces " << size() << " than zones " << count - << " ... extending final zone" - << endl; + const label neiFaceI = neighbours[neighI]; + + if (neiFaceI <= faceI || faceMap[neiFaceI] < 0) + { + // lower numbered faces already checked + // skip neighbours that are themselves collapsed + continue; + } + + const Face& nei = faceLst[neiFaceI]; + + if (f == nei) + { + okay = false; + + if (verbose) + { + WarningIn + ( + "MeshedSurface::checkFaces(bool verbose)" + ) << "faces share the same vertices:" << nl + << " face[" << faceI << "] : " << f << nl + << " face[" << neiFaceI << "] : " << nei << endl; + // printFace(Warning, " ", f, points()); + // printFace(Warning, " ", nei, points()); + } - zones_[zones_.size()-1].size() += count - size(); + break; + } } - else if (count > size()) + + if (okay) { - FatalErrorIn - ( - "MeshedSurface::checkZones()\n" - ) - << "more zones " << count << " than faces " << size() - << exit(FatalError); + faceMap[faceI] = faceI; + newFaceI++; + } + else + { + faceMap[faceI] = -1; } } -} - -template<class Face> -void Foam::MeshedSurface<Face>::sortFacesAndStore -( - const Xfer<List<Face> >& unsortedFaces, - const Xfer<List<label> >& zoneIds, - const bool sorted -) -{ - List<Face> oldFaces(unsortedFaces); - List<label> zones(zoneIds); + // Phase 1: pack + // Done to keep numbering constant in phase 1 - if (sorted) - { - // already sorted - simply transfer faces - this->storedFaces().transfer(oldFaces); - } - else + if (changed || newFaceI < faceLst.size()) { - // unsorted - determine the sorted order: - // avoid SortableList since we discard the main list anyhow - List<label> faceMap; - sortedOrder(zones, faceMap); - zones.clear(); + changed = true; - // sorted faces - List<Face> newFaces(faceMap.size()); - forAll(faceMap, faceI) + if (verbose) { - // use transfer to recover memory if possible - newFaces[faceI].transfer(oldFaces[faceMap[faceI]]); + WarningIn + ( + "MeshedSurface::checkFaces(bool verbose)" + ) << "Removed " << faceLst.size() - newFaceI + << " illegal faces." << endl; + } + + // compress the face list + newFaceI = 0; + forAll(faceLst, faceI) + { + if (faceMap[faceI] >= 0) + { + if (newFaceI != faceI) + { + faceLst[newFaceI] = faceLst[faceI]; + } + faceMap[newFaceI] = faceI; + newFaceI++; + } } - this->storedFaces().transfer(newFaces); + faceLst.setSize(newFaceI); + remapFaces(faceMap); } - zones.clear(); + faceMap.clear(); + + // Topology can change because of renumbering + ParentType::clearOut(); + return changed; } template<class Face> -void Foam::MeshedSurface<Face>::remapFaces +Foam::label Foam::MeshedSurface<Face>::triangulate() +{ + return triangulate + ( + const_cast<List<label>&>(List<label>::null()) + ); +} + + +template<class Face> +Foam::label Foam::MeshedSurface<Face>::triangulate ( - const UList<label>& faceMap + List<label>& faceMapOut ) { - // recalculate the zone start/size - if (&faceMap && faceMap.size()) + label nTri = 0; + label maxTri = 0; // the maximum number of triangles for any single face + List<Face>& faceLst = this->storedFaces(); + + // determine how many triangles will be needed + forAll(faceLst, faceI) { - if (zones_.empty()) + const label n = faceLst[faceI].nTriangles(); + if (maxTri < n) { - oneZone(); + maxTri = n; } - else if (zones_.size() == 1) + nTri += n; + } + + // nothing to do + if (nTri <= faceLst.size()) + { + if (&faceMapOut) { - // optimized for single zone case - zones_[0].size() = faceMap.size(); + faceMapOut.clear(); } - else + return 0; + } + + List<Face> newFaces(nTri); + List<label> faceMap; + + // reuse storage from optional faceMap + if (&faceMapOut) + { + faceMap.transfer(faceMapOut); + } + faceMap.setSize(nTri); + + // remember the number of *additional* faces + nTri -= faceLst.size(); + + if (this->points().empty()) + { + // triangulate without points + // simple face triangulation around f[0] + label newFaceI = 0; + forAll(faceLst, faceI) { - label newFaceI = 0; - label origEndI = 0; - forAll(zones_, zoneI) + const Face& f = faceLst[faceI]; + + for (label fp = 1; fp < f.size() - 1; ++fp) { - surfZone& zone = zones_[zoneI]; + label fp1 = f.fcIndex(fp); - // adjust zone start - zone.start() = newFaceI; - origEndI += zone.size(); + newFaces[newFaceI] = triFace(f[0], f[fp], f[fp1]); + faceMap[newFaceI] = faceI; + newFaceI++; + } + } + } + else + { + // triangulate with points + List<face> tmpTri(maxTri); - for (label faceI = newFaceI; faceI < faceMap.size(); ++faceI) - { - if (faceMap[faceI] < origEndI) - { - ++newFaceI; - } - else - { - break; - } - } + label newFaceI = 0; + forAll(faceLst, faceI) + { + // 'face' not '<Face>' + const face& f = faceLst[faceI]; - // adjust zone size - zone.size() = newFaceI - zone.start(); + label nTmp; + f.triangles(this->points(), nTmp, tmpTri); + for (label triI = 0; triI < nTmp; triI++) + { + newFaces[newFaceI] = Face + ( + static_cast<UList<label>&>(tmpTri[triI]) + ); + faceMap[newFaceI] = faceI; + newFaceI++; } } } -} + faceLst.transfer(newFaces); + remapFaces(faceMap); -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + // optionally return the faceMap + if (&faceMapOut) + { + faceMapOut.transfer(faceMap); + } + faceMap.clear(); -template<class Face> -void Foam::MeshedSurface<Face>::clear() -{ - ParentType::clear(); - zones_.clear(); + // Topology can change because of renumbering + ParentType::clearOut(); + return nTri; } + + template<class Face> Foam::MeshedSurface<Face> Foam::MeshedSurface<Face>::subsetMesh ( @@ -578,7 +975,7 @@ Foam::MeshedSurface<Face> Foam::MeshedSurface<Face>::subsetMesh } // create/copy a new zones list, each zone with zero size - surfZoneList newZones(zones_); + surfZoneList newZones(this->surfZones()); forAll(newZones, zoneI) { newZones[zoneI].size() = 0; @@ -652,88 +1049,6 @@ Foam::MeshedSurface<Face>::subsetMesh } -template<class Face> -void Foam::MeshedSurface<Face>::addZones -( - const UList<surfZone>& zones, - const bool cullEmpty -) -{ - label nZone = 0; - - zones_.setSize(zones.size()); - forAll(zones_, zoneI) - { - if (zones[zoneI].size() || !cullEmpty) - { - zones_[nZone] = surfZone(zones[zoneI], nZone); - nZone++; - } - } - zones_.setSize(nZone); -} - - -template<class Face> -void Foam::MeshedSurface<Face>::addZones -( - const UList<label>& sizes, - const UList<word>& names, - const bool cullEmpty -) -{ - label start = 0; - label nZone = 0; - - zones_.setSize(sizes.size()); - forAll(zones_, zoneI) - { - if (sizes[zoneI] || !cullEmpty) - { - zones_[nZone] = surfZone - ( - names[zoneI], - sizes[zoneI], - start, - nZone - ); - start += sizes[zoneI]; - nZone++; - } - } - zones_.setSize(nZone); -} - - -template<class Face> -void Foam::MeshedSurface<Face>::addZones -( - const UList<label>& sizes, - const bool cullEmpty -) -{ - label start = 0; - label nZone = 0; - - zones_.setSize(sizes.size()); - forAll(zones_, zoneI) - { - if (sizes[zoneI] || !cullEmpty) - { - zones_[nZone] = surfZone - ( - word("zone") + ::Foam::name(nZone), - sizes[zoneI], - start, - nZone - ); - start += sizes[zoneI]; - nZone++; - } - } - zones_.setSize(nZone); -} - template<class Face> void Foam::MeshedSurface<Face>::transfer @@ -741,10 +1056,12 @@ void Foam::MeshedSurface<Face>::transfer MeshedSurface<Face>& surf ) { - reset(xferMove(surf.storedPoints()), xferMove(surf.storedFaces())); - zones_.transfer(surf.zones_); - - surf.clear(); + reset + ( + xferMove(surf.storedPoints()), + xferMove(surf.storedFaces()), + xferMove(surf.storedZones()) + ); } @@ -758,18 +1075,35 @@ void Foam::MeshedSurface<Face>::transfer labelList faceMap; surfZoneList zoneLst = surf.sortedZones(faceMap); - List<Face>& oldFaces = surf.storedFaces(); - List<Face> newFaces(faceMap.size()); - forAll(faceMap, faceI) + if (zoneLst.size() <= 1) { - newFaces[faceI].transfer(oldFaces[faceMap[faceI]]); + reset + ( + xferMove(surf.storedPoints()), + xferMove(surf.storedFaces()), + Xfer<surfZoneList>() + ); } - faceMap.clear(); + else + { + List<Face>& oldFaces = surf.storedFaces(); + List<Face> newFaces(faceMap.size()); - reset(xferMove(surf.storedPoints()), xferMove(newFaces)); - zones_.transfer(zoneLst); + forAll(faceMap, faceI) + { + newFaces[faceI].transfer(oldFaces[faceMap[faceI]]); + } + reset + ( + xferMove(surf.storedPoints()), + xferMove(newFaces), + xferMove(zoneLst) + ); + } + + faceMap.clear(); surf.clear(); } @@ -807,24 +1141,22 @@ bool Foam::MeshedSurface<Face>::read const word& ext ) { - // handle 'native' format directly - if (isNative(ext)) - { - return read(IFstream(name)()); - } - else - { - // use selector mechanism - transfer(New(name, ext)()); - return true; - } + clear(); + + // read via selector mechanism + transfer(New(name, ext)()); + return true; } template<class Face> -void Foam::MeshedSurface<Face>::write(const Time& d, const word& surfName) const +void Foam::MeshedSurface<Face>::write +( + const Time& t, + const word& surfName +) const { - write(OFstream(findMeshFile(d, surfName))()); + MeshedSurfaceProxy<Face>(*this).write(t, surfName); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // @@ -836,7 +1168,20 @@ void Foam::MeshedSurface<Face>::operator=(const MeshedSurface& surf) this->storedPoints() = surf.points(); this->storedFaces() = surf.faces(); - zones_ = surf.zones_; + this->storedZones() = surf.surfZones(); +} + + +template<class Face> +Foam::MeshedSurface<Face>::operator +Foam::MeshedSurfaceProxy<Face>() const +{ + return MeshedSurfaceProxy<Face> + ( + this->points(), + this->faces(), + this->surfZones() + ); } // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // @@ -845,6 +1190,7 @@ void Foam::MeshedSurface<Face>::operator=(const MeshedSurface& surf) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "MeshedSurfaceZones.C" #include "MeshedSurfaceIO.C" #include "MeshedSurfaceNew.C" diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index a3e8ed5758839f5ad69952dac5fc1e061d5b1b1f..5677233e0bcf8fb35056a81c04b1fcc0d82a507d 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -26,15 +26,19 @@ Class Foam::MeshedSurface Description - A surface geometry mesh with zone information, not to be confused - with a similarily named surfaceMesh, which actually refers to - the cell faces of a volume mesh. + A surface geometry mesh with zone information, not to be confused with + the similarly named surfaceMesh, which actually refers to the cell faces + of a volume mesh. - The MeshedSurface is intended for surfaces from a variety of sources. - - A set of points and faces without any surface zone information. - - A set of points and faces with randomly ordered zone information. - This could arise, for example, from reading external file formats - such as STL, etc. + A MeshedSurface can have zero or more surface zones (roughly equivalent + to faceZones for a polyMesh). If surface zones are defined, they must + be contiguous and cover all of the faces. + + The MeshedSurface is intended for surfaces from a variety of sources. + - A set of points and faces without any surface zone information. + - A set of points and faces with randomly ordered zone information. + This could arise, for example, from reading external file formats + such as STL, etc. SourceFiles MeshedSurface.C @@ -44,7 +48,12 @@ SourceFiles #ifndef MeshedSurface_H #define MeshedSurface_H -#include "BasicMeshedSurface.H" +#include "PrimitivePatch.H" +#include "PatchTools.H" +#include "pointField.H" +#include "face.H" +#include "triFace.H" + #include "surfZoneList.H" #include "surfaceFormatsCore.H" #include "runTimeSelectionTables.H" @@ -60,14 +69,11 @@ namespace Foam class Time; class surfMesh; -template<class Face> class MeshedSurface; -template<class Face> class UnsortedMeshedSurface; - class polyBoundaryMesh; -class surfMesh; -template<class Face> -Ostream& operator<<(Ostream&, const MeshedSurface<Face>&); +template<class Face> class MeshedSurface; +template<class Face> class MeshedSurfaceProxy; +template<class Face> class UnsortedMeshedSurface; /*---------------------------------------------------------------------------*\ Class MeshedSurface Declaration @@ -76,24 +82,29 @@ Ostream& operator<<(Ostream&, const MeshedSurface<Face>&); template<class Face> class MeshedSurface : - public BasicMeshedSurface<Face>, + public PrimitivePatch<Face, ::Foam::List, pointField, point>, public fileFormats::surfaceFormatsCore { - // friends despite different faces - template<class Face2> - friend class MeshedSurface; - - // friends despite different faces - template<class Face2> - friend class UnsortedMeshedSurface; - + // friends - despite different face representationsx + template<class Face2> friend class MeshedSurface; + template<class Face2> friend class UnsortedMeshedSurface; friend class surfMesh; private: //- Private typedefs for convenience - typedef BasicMeshedSurface<Face> ParentType; - typedef UnsortedMeshedSurface<Face> SiblingType; + + typedef PrimitivePatch + < + Face, + ::Foam::List, + pointField, + point + > + ParentType; + + typedef UnsortedMeshedSurface<Face> FriendType; + typedef MeshedSurfaceProxy<Face> ProxyType; // Private Member Data @@ -101,21 +112,31 @@ private: // (face ordering nFaces/startFace only used during reading/writing) List<surfZone> zones_; - // Private member functions - - //- Read OpenFOAM Surface format - bool read(Istream&); - //- Transfer points/zones and transcribe face -> triFace - void transcribe(MeshedSurface<face>&); + // Private member functions protected: // Protected Member functions + //- Transfer points/zones and transcribe face -> triFace + void transcribe(MeshedSurface<face>&); + //- basic sanity check on zones void checkZones(); + //- Non-const access to global points + pointField& storedPoints() + { + return const_cast<pointField&>(ParentType::points()); + } + + //- Non-const access to the faces + List<Face>& storedFaces() + { + return static_cast<List<Face> &>(*this); + } + //- Non-const access to the zones surfZoneList& storedZones() { @@ -125,8 +146,8 @@ protected: //- sort faces by zones and store sorted faces void sortFacesAndStore ( - const Xfer<List<Face> >& unsortedFaces, - const Xfer<List<label> >& zoneIds, + const Xfer< List<Face> >& unsortedFaces, + const Xfer< List<label> >& zoneIds, const bool sorted ); @@ -140,6 +161,9 @@ public: // Static + //- Face storage only handles triangulated faces + inline static bool isTri(); + //- Can we read this file format? static bool canRead(const fileName&, const bool verbose=false); @@ -160,21 +184,27 @@ public: //- Construct by transferring components (points, faces, zones). MeshedSurface ( - const Xfer<pointField>&, - const Xfer<List<Face> >&, - const Xfer<surfZoneList>& + const Xfer< pointField >&, + const Xfer< List<Face> >&, + const Xfer< surfZoneList >& ); - //- Construct by transferring points, faces. - // Use zone information, or set single default zone. + //- Construct by transferring components (points, faces). + // Use zone information if available MeshedSurface ( - const Xfer<pointField>&, - const Xfer<List<Face> >&, - const UList<label>& zoneSizes = UList<label>::null(), - const UList<word>& zoneNames = UList<word>::null() + const Xfer< pointField >&, + const Xfer< List<Face> >&, + const UList<label>& zoneSizes = UList<label>(), + const UList<word>& zoneNames = UList<word>() ); + //- Construct as copy + MeshedSurface(const MeshedSurface&); + + //- Construct from a UnsortedMeshedSurface + MeshedSurface(const UnsortedMeshedSurface<Face>&); + //- Construct from a boundary mesh with local points/faces MeshedSurface ( @@ -182,9 +212,6 @@ public: const bool globalPoints=false ); - //- Construct from a UnsortedMeshedSurface - MeshedSurface(const UnsortedMeshedSurface<Face>&); - //- Construct from a surfMesh MeshedSurface(const surfMesh&); @@ -200,15 +227,9 @@ public: //- Construct from file name (uses extension to determine type) MeshedSurface(const fileName&, const word& ext); - //- Construct from Istream - MeshedSurface(Istream&); - - //- Construct from objectRegistry + //- Construct from database MeshedSurface(const Time&, const word& surfName=""); - //- Construct as copy - MeshedSurface(const MeshedSurface&); - // Declare run-time constructor selection table declareRunTimeSelectionTable @@ -244,7 +265,7 @@ public: declareMemberFunctionSelectionTable ( void, - MeshedSurface, + UnsortedMeshedSurface, write, fileExtension, ( @@ -268,41 +289,98 @@ public: return ParentType::size(); } - const List<surfZone>& zones() const + //- Return const access to the faces + inline const List<Face>& faces() const { - return zones_; + return static_cast<const List<Face> &>(*this); } - //- set a single zone, optionally with a specific name - void oneZone(const word& name = word::null); + //- Const access to the surface zones. + // If zones are defined, they must be contiguous and cover the entire + // surface. + const List<surfZone>& surfZones() const + { + return zones_; + } - //- Add zones - void addZones + //- Add surface zones + virtual void addZones ( const UList<surfZone>&, const bool cullEmpty=false ); - //- Add zones - void addZones + //- Add surface zones + virtual void addZones ( const UList<label>& sizes, const UList<word>& names, const bool cullEmpty=false ); - //- Add zones - void addZones + //- Add surface zones + virtual void addZones ( const UList<label>& sizes, const bool cullEmpty=false ); + //- Remove surface zones + virtual void removeZones(); + + // Edit //- Clear all storage virtual void clear(); + //- Move points + virtual void movePoints(const pointField&); + + //- Scale points. A non-positive factor is ignored + virtual void scalePoints(const scalar&); + + //- Reset primitive data (points, faces and zones) + // Note, optimized to avoid overwriting data (with Xfer::null) + virtual void reset + ( + const Xfer< pointField >& points, + const Xfer< List<Face> >& faces, + const Xfer< surfZoneList >& zones + ); + + //- Reset primitive data (points, faces and zones) + // Note, optimized to avoid overwriting data (with Xfer::null) + virtual void reset + ( + const Xfer< List<point> >& points, + const Xfer< List<Face> >& faces, + const Xfer< surfZoneList >& zones + ); + + //- Remove invalid faces + virtual void cleanup(const bool verbose); + + virtual bool stitchFaces + ( + const scalar tol=SMALL, + const bool verbose=false + ); + + virtual bool checkFaces + ( + const bool verbose=false + ); + + //- Triangulate in-place, returning the number of triangles added + virtual label triangulate(); + + //- Triangulate in-place, returning the number of triangles added + // and setting a map of original face Ids. + // The faceMap is zero-sized when no triangulation was done. + virtual label triangulate(List<label>& faceMap); + + //- Return new surface. // Returns return pointMap, faceMap from subsetMeshMap MeshedSurface subsetMesh @@ -338,8 +416,7 @@ public: // Write - //- Write to Ostream in simple FOAM format - virtual void write(Ostream&) const; + void writeStats(Ostream& os) const; //- Generic write routine. Chooses writer based on extension. virtual void write(const fileName& name) const @@ -355,17 +432,40 @@ public: void operator=(const MeshedSurface<Face>&); - // Ostream Operator + //- Conversion operator to MeshedSurfaceProxy + operator MeshedSurfaceProxy<Face>() const; - friend Ostream& operator<< - <Face> - ( - Ostream&, - const MeshedSurface<Face>& - ); }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Specialization for holding triangulated information +template<> +inline bool MeshedSurface<triFace>::isTri() +{ + return true; +} + +//- Specialization for holding triangulated information +template<> +inline label MeshedSurface<triFace>::triangulate() +{ + return 0; +} + +//- Specialization for holding triangulated information +template<> +inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap) +{ + if (&faceMap) + { + faceMap.clear(); + } + + return 0; +} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceCore.C b/src/surfMesh/MeshedSurface/MeshedSurfaceCore.C index 6a95b18b4ab483be1cb8c7f10f588d3e6f0366da..1ad36955bdc15935fe2ab88764cd5a88927383a8 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurfaceCore.C +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceCore.C @@ -38,7 +38,7 @@ namespace Foam // first triangulate surf.triangulate(); this->storedPoints().transfer(surf.storedPoints()); - zones_.transfer(surf.zones_); + this->storedZones().transfer(surf.storedZones()); // transcribe from face -> triFace List<face>& origFaces = surf.storedFaces(); diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C b/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C index 5beb33b0458dae663c82ff582275e4b2dc872a84..93069a5d8c64b240b9fa29d41293c570f0f24b3d 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceIO.C @@ -25,117 +25,44 @@ License \*---------------------------------------------------------------------------*/ #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" -#include "IFstream.H" -#include "OFstream.H" +#include "boundBox.H" +#include "Ostream.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Read surf grouping, points, faces directly from Istream template<class Face> -bool Foam::MeshedSurface<Face>::read(Istream& is) +void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const { - clear(); - - List<surfZone> newZones(is); - - // copy and set the indices - zones_.setSize(newZones.size()); - forAll(newZones, zoneI) + os << "points : " << this->points().size() << nl; + if (MeshedSurface<Face>::isTri()) { - zones_[zoneI] = surfZone - ( - newZones[zoneI], - zoneI - ); + os << "triangles : " << this->size() << nl; } - - // read points: - is >> this->storedPoints(); - - // must triangulate? - if (this->isTri()) + else { - List<face> faceLst(is); - - MeshedSurface<face> surf; - surf.reset - ( - Xfer<pointField>::null(), - faceLst.xfer() - ); - surf.addZones(zones_); - - // this will break if the triangulation needed points - surf.triangulate(); - zones_ = surf.zones(); - - // transcribe from face -> triFace (Face) - const List<face>& origFaces = surf.faces(); - List<Face> newFaces(origFaces.size()); - forAll(origFaces, faceI) + label nTri = 0; + label nQuad = 0; + forAll(*this, i) { - newFaces[faceI] = Face - ( - static_cast<const UList<label>&>(origFaces[faceI]) - ); + const label n = this->operator[](i).size(); + + if (n == 3) + { + nTri++; + } + else if (n == 4) + { + nQuad++; + } } - surf.clear(); - this->storedFaces().transfer(newFaces); - } - else - { - // read faces: - is >> this->storedFaces(); + os << "faces : " << this->size() + << " (tri:" << nTri << " quad:" << nQuad + << " poly:" << (this->size() - nTri - nQuad ) << ")" << nl; } - return is.good(); + os << "boundingBox : " << boundBox(this->points()) << endl; } -template<class Face> -void Foam::MeshedSurface<Face>::write(Ostream& os) const -{ - // just emit some information until we get a nice IOobject - IOobject::writeBanner(os); - os << "// OpenFOAM Surface Format" << nl - << "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl - << "// zones:" << nl - << zones_.size() << nl << token::BEGIN_LIST << incrIndent << nl; - - forAll(zones_, zoneI) - { - zones_[zoneI].writeDict(os); - } - os << decrIndent << token::END_LIST << nl; - - IOobject::writeDivider(os); - - // Note: Write with global point numbering - os << "\n// points:" << nl << this->points() << nl; - - IOobject::writeDivider(os); - os << "\n// faces:" << nl << this->faces() << nl; - - IOobject::writeDivider(os); - - // Check state of Ostream - os.check("MeshedSurface::write(Ostream&)"); -} - - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -template<class Face> -Foam::Ostream& Foam::operator<< -( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - surf.write(os); - return os; -} - // ************************************************************************* // diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C b/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C index 0655274f997dd7c7a1130ac42f6046a36f5d529c..bdaae876a1cff71ad5ae5604d32cca7949a6a812 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C @@ -31,7 +31,7 @@ License template<class Face> -Foam::autoPtr<Foam::MeshedSurface<Face> > +Foam::autoPtr< Foam::MeshedSurface<Face> > Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext) { if (debug) @@ -47,19 +47,18 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext) if (cstrIter == fileExtensionConstructorTablePtr_->end()) { // no direct reader, delegate if possible - wordHashSet supported = SiblingType::readTypes(); + wordHashSet supported = FriendType::readTypes(); if (supported.found(ext)) { // create indirectly - autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>); - surf().transfer(SiblingType::New(name, ext)()); + autoPtr< MeshedSurface<Face> > surf(new MeshedSurface<Face>); + surf().transfer(FriendType::New(name, ext)()); return surf; } // nothing left to try, issue error supported += readTypes(); - supported.insert(nativeExt); FatalErrorIn ( @@ -71,12 +70,12 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext) << exit(FatalError); } - return autoPtr<MeshedSurface<Face> >(cstrIter()(name)); + return autoPtr< MeshedSurface<Face> >(cstrIter()(name)); } template<class Face> -Foam::autoPtr<Foam::MeshedSurface<Face> > +Foam::autoPtr< Foam::MeshedSurface<Face> > Foam::MeshedSurface<Face>::New(const fileName& name) { word ext = name.ext(); diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceZones.C b/src/surfMesh/MeshedSurface/MeshedSurfaceZones.C new file mode 100644 index 0000000000000000000000000000000000000000..a31e8d6314ee75d921e8a340a04a0836b8596fc8 --- /dev/null +++ b/src/surfMesh/MeshedSurface/MeshedSurfaceZones.C @@ -0,0 +1,203 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "MeshedSurface.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<class Face> +void Foam::MeshedSurface<Face>::checkZones() +{ + // extra safety, ensure we have at some zones + // and they cover all the faces - fix start silently + surfZoneList& zones = this->storedZones(); + if (zones.size()) + { + label count = 0; + forAll(zones, zoneI) + { + zones[zoneI].start() = count; + count += zones[zoneI].size(); + } + + if (count < this->size()) + { + WarningIn + ( + "MeshedSurface::checkZones()\n" + ) + << "more faces " << this->size() << " than zones " << count + << " ... extending final zone" + << endl; + + zones[zones.size()-1].size() += count - this->size(); + } + else if (count > this->size()) + { + FatalErrorIn + ( + "MeshedSurface::checkZones()\n" + ) + << "more zones " << count << " than faces " << this->size() + << exit(FatalError); + } + } +} + + +template<class Face> +void Foam::MeshedSurface<Face>::sortFacesAndStore +( + const Xfer< List<Face> >& unsortedFaces, + const Xfer< List<label> >& zoneIds, + const bool sorted +) +{ + List<Face> oldFaces(unsortedFaces); + List<label> zones(zoneIds); + + if (sorted) + { + // already sorted - simply transfer faces + this->storedFaces().transfer(oldFaces); + } + else + { + // unsorted - determine the sorted order: + // avoid SortableList since we discard the main list anyhow + List<label> faceMap; + sortedOrder(zones, faceMap); + zones.clear(); + + // sorted faces + List<Face> newFaces(faceMap.size()); + forAll(faceMap, faceI) + { + // use transfer to recover memory where possible + newFaces[faceI].transfer(oldFaces[faceMap[faceI]]); + } + this->storedFaces().transfer(newFaces); + } + zones.clear(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Face> +void Foam::MeshedSurface<Face>::addZones +( + const UList<surfZone>& srfZones, + const bool cullEmpty +) +{ + label nZone = 0; + + surfZoneList& zones = this->storedZones(); + zones.setSize(zones.size()); + forAll(zones, zoneI) + { + if (srfZones[zoneI].size() || !cullEmpty) + { + zones[nZone] = surfZone(srfZones[zoneI], nZone); + nZone++; + } + } + zones.setSize(nZone); +} + + +template<class Face> +void Foam::MeshedSurface<Face>::addZones +( + const UList<label>& sizes, + const UList<word>& names, + const bool cullEmpty +) +{ + label start = 0; + label nZone = 0; + + surfZoneList& zones = this->storedZones(); + zones.setSize(sizes.size()); + forAll(zones, zoneI) + { + if (sizes[zoneI] || !cullEmpty) + { + zones[nZone] = surfZone + ( + names[zoneI], + sizes[zoneI], + start, + nZone + ); + start += sizes[zoneI]; + nZone++; + } + } + zones.setSize(nZone); +} + + +template<class Face> +void Foam::MeshedSurface<Face>::addZones +( + const UList<label>& sizes, + const bool cullEmpty +) +{ + label start = 0; + label nZone = 0; + + surfZoneList& zones = this->storedZones(); + zones.setSize(sizes.size()); + forAll(zones, zoneI) + { + if (sizes[zoneI] || !cullEmpty) + { + zones[nZone] = surfZone + ( + word("zone") + ::Foam::name(nZone), + sizes[zoneI], + start, + nZone + ); + start += sizes[zoneI]; + nZone++; + } + } + zones.setSize(nZone); +} + + +template<class Face> +void Foam::MeshedSurface<Face>::removeZones() +{ + this->storedZones().clear(); +} + + +// ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C new file mode 100644 index 0000000000000000000000000000000000000000..abe193ce73a1519eb2e8956e1a1a8a04f03bcb09 --- /dev/null +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "MeshedSurfaceIOAllocator.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + + +Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator +( + const IOobject& ioPoints, + const IOobject& ioFaces, + const IOobject& ioZones +) +: + points_(ioPoints), + faces_(ioFaces), + zones_(ioZones) +{} + + +Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator +( + const IOobject& ioPoints, + const pointField& points, + const IOobject& ioFaces, + const faceList& faces, + const IOobject& ioZones, + const surfZoneList& zones +) +: + points_(ioPoints, points), + faces_(ioFaces, faces), + zones_(ioZones, zones) +{} + + +Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator +( + const IOobject& ioPoints, + const Xfer< pointField >& points, + const IOobject& ioFaces, + const Xfer< faceList >& faces, + const IOobject& ioZones, + const Xfer< surfZoneList >& zones +) +: + points_(ioPoints, points), + faces_(ioFaces, faces), + zones_(ioZones, zones) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::MeshedSurfaceIOAllocator::clear() +{ + points_.clear(); + faces_.clear(); + zones_.clear(); +} + + +void Foam::MeshedSurfaceIOAllocator::resetFaces +( + const Xfer< List<face> >& faces, + const Xfer< surfZoneList >& zones +) +{ + if (&faces) + { + faces_.transfer(faces()); + } + + if (&zones) + { + zones_.transfer(zones()); + } +} + + +void Foam::MeshedSurfaceIOAllocator::reset +( + const Xfer< pointField >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones +) +{ + // Take over new primitive data. + // Optimized to avoid overwriting data at all + if (&points) + { + points_.transfer(points()); + } + + resetFaces(faces, zones); +} + + +void Foam::MeshedSurfaceIOAllocator::reset +( + const Xfer< List<point> >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones +) +{ + // Take over new primitive data. + // Optimized to avoid overwriting data at all + if (&points) + { + points_.transfer(points()); + } + + resetFaces(faces, zones); +} + + +// ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H new file mode 100644 index 0000000000000000000000000000000000000000..d3b6d5ff6a9f9aacb47224259632effa4bdc39d6 --- /dev/null +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H @@ -0,0 +1,194 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::MeshedSurfaceIOAllocator + +Description + A helper class for storing points, faces and zones with IO capabilities. + +SourceFiles + MeshedSurfaceIOAllocator.C + +\*---------------------------------------------------------------------------*/ + +#ifndef MeshedSurfaceIOAllocator_H +#define MeshedSurfaceIOAllocator_H + +#include "pointIOField.H" +#include "faceIOList.H" +#include "surfZoneIOList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class MeshedSurfaceIOAllocator Declaration +\*---------------------------------------------------------------------------*/ + +//- A helper class for storing points, faces and zones +class MeshedSurfaceIOAllocator +{ + // Private data + + //- Points + pointIOField points_; + + //- Faces + faceIOList faces_; + + //- Surface zones + surfZoneIOList zones_; + + // Private Member Functions + + //- Disallow default bitwise copy construct + MeshedSurfaceIOAllocator(const MeshedSurfaceIOAllocator&); + + //- Disallow default bitwise assignment + void operator=(const MeshedSurfaceIOAllocator&); + +public: + + // Constructors + + //- Read construct from IOobjects + MeshedSurfaceIOAllocator + ( + const IOobject& ioPoints, + const IOobject& ioFaces, + const IOobject& ioZones + ); + + //- Construct from IOobjects, copying components + MeshedSurfaceIOAllocator + ( + const IOobject& ioPoints, + const pointField& points, + const IOobject& ioFaces, + const faceList& faces, + const IOobject& ioZones, + const surfZoneList& zones + ); + + //- Construct from IOobjects, possibly transferring components + MeshedSurfaceIOAllocator + ( + const IOobject& ioPoints, + const Xfer< pointField >& points, + const IOobject& ioFaces, + const Xfer< faceList >& faces, + const IOobject& ioZones, + const Xfer< surfZoneList >& zones + ); + + // Destructor + + + // Member Functions + + // Access + + //- Non-const access to the points + pointIOField& storedIOPoints() + { + return points_; + } + + //- Non-const access to the faces + faceIOList& storedIOFaces() + { + return faces_; + } + + //- Non-const access to the zones + surfZoneIOList& storedIOZones() + { + return zones_; + } + + //- Const access to the points + const pointIOField& storedIOPoints() const + { + return points_; + } + + //- Const access to the faces + const faceIOList& storedIOFaces() const + { + return faces_; + } + + //- Const access to the zones + const surfZoneIOList& storedIOZones() const + { + return zones_; + } + + + // Storage management + + //- Clear primitive data (points, faces and zones) + void clear(); + + //- Reset primitive data (points, faces and zones) + // Note, optimized to avoid overwriting data (with Xfer::null) + void resetFaces + ( + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones + ); + + //- Reset primitive data (points, faces and zones) + // Note, optimized to avoid overwriting data (with Xfer::null) + void reset + ( + const Xfer< pointField >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones + ); + + //- Reset primitive data (points, faces and zones) + // Note, optimized to avoid overwriting data (with Xfer::null) + void reset + ( + const Xfer< List<point> >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones + ); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C new file mode 100644 index 0000000000000000000000000000000000000000..d9ba96704b8ce4dd5a3ab578517c736585ca8d7a --- /dev/null +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C @@ -0,0 +1,261 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "MeshedSurfaceProxy.H" + +#include "Time.H" +#include "surfMesh.H" +#include "OFstream.H" +#include "ListOps.H" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template<class Face> +Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes() +{ + return wordHashSet(*writefileExtensionMemberFunctionTablePtr_); +} + + +template<class Face> +bool Foam::MeshedSurfaceProxy<Face>::canWriteType +( + const word& ext, + const bool verbose +) +{ + return checkSupport(writeTypes(), ext, verbose, "writing"); +} + + +template<class Face> +void Foam::MeshedSurfaceProxy<Face>::write +( + const fileName& name, + const MeshedSurfaceProxy& surf +) +{ + if (debug) + { + Info<< "MeshedSurfaceProxy::write" + "(const fileName&, const MeshedSurfaceProxy&) : " + "writing to " << name + << endl; + } + + word ext = name.ext(); + + typename writefileExtensionMemberFunctionTable::iterator mfIter = + writefileExtensionMemberFunctionTablePtr_->find(ext); + + if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) + { + FatalErrorIn + ( + "MeshedSurfaceProxy::write(const fileName&)" + ) << "Unknown file extension " << ext << nl << nl + << "Valid types are :" << endl + << writeTypes() + << exit(FatalError); + } + + mfIter()(name, surf); +} + + +template<class Face> +void Foam::MeshedSurfaceProxy<Face>::write +( + const Time& t, + const word& surfName +) const +{ + // the surface name to be used + word name(surfName.size() ? surfName : surfaceRegistry::defaultName); + + if (debug) + { + Info<< "MeshedSurfaceProxy::write" + "(const Time&, const word&) : " + "writing to " << name + << endl; + } + + + // the local location + const fileName objectDir + ( + t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir + ); + + if (!isDir(objectDir)) + { + mkDir(objectDir); + } + + + // write surfMesh/points + { + pointIOField io + ( + IOobject + ( + "points", + t.timeName(), + surfMesh::meshSubDir, + t, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ) + ); + + OFstream os + ( + objectDir/io.name(), + t.writeFormat(), + IOstream::currentVersion, + t.writeCompression() + ); + + io.writeHeader(os); + + os << this->points(); + + io.writeEndDivider(os); + } + + + // write surfMesh/faces + { + faceIOList io + ( + IOobject + ( + "faces", + t.timeName(), + surfMesh::meshSubDir, + t, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ) + ); + + OFstream os + ( + objectDir/io.name(), + t.writeFormat(), + IOstream::currentVersion, + t.writeCompression() + ); + io.writeHeader(os); + + if (this->useFaceMap()) + { + // this is really a bit annoying (and wasteful) but no other way + os << reorder(this->faceMap(), this->faces()); + } + else + { + os << this->faces(); + } + + io.writeEndDivider(os); + } + + + // write surfMesh/surfZones + { + surfZoneIOList io + ( + IOobject + ( + "surfZones", + t.timeName(), + surfMesh::meshSubDir, + t, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ) + ); + + // write as ascii + OFstream os(objectDir/io.name()); + io.writeHeader(os); + + os << this->surfZones(); + + io.writeEndDivider(os); + } + +} + + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Face> +Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy +( + const pointField& pointLst, + const List<Face>& faceLst, + const List<surfZone>& zoneLst, + const List<label>& faceMap +) +: + points_(pointLst), + faces_(faceLst), + zones_(zoneLst), + faceMap_(faceMap) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Face> +Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy() +{} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + + +// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H new file mode 100644 index 0000000000000000000000000000000000000000..64fc7c4fcd39cc2aee4e6ad6888959a7eb5fa0ec --- /dev/null +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H @@ -0,0 +1,194 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::MeshedSurfaceProxy + +Description + A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh + to various file formats. + +SourceFiles + MeshedSurfaceProxy.C + MeshedSurfaceProxyCore.C + +\*---------------------------------------------------------------------------*/ + +#ifndef MeshedSurfaceProxy_H +#define MeshedSurfaceProxy_H + +#include "pointField.H" +#include "face.H" +#include "triFace.H" + +#include "surfZoneList.H" +#include "surfaceFormatsCore.H" +#include "runTimeSelectionTables.H" +#include "memberFunctionSelectionTables.H" +#include "HashSet.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +template<class Face> class MeshedSurface; + +/*---------------------------------------------------------------------------*\ + Class MeshedSurfaceProxy Declaration +\*---------------------------------------------------------------------------*/ + +template<class Face> +class MeshedSurfaceProxy +: + public fileFormats::surfaceFormatsCore +{ + //- Private data + + const pointField& points_; + + const List<Face>& faces_; + + const List<surfZone>& zones_; + + const List<label>& faceMap_; + +public: + + //- Runtime type information + ClassName("MeshedSurfaceProxy"); + + // Static + + //- The file format types that can be written via MeshedSurfaceProxy + static wordHashSet writeTypes(); + + //- Can this file format type be written via MeshedSurfaceProxy? + static bool canWriteType(const word& ext, const bool verbose=false); + + + // Constructors + + //- Construct from component references + MeshedSurfaceProxy + ( + const pointField&, + const List<Face>&, + const List<surfZone>& = List<surfZone>(), + const List<label>& faceMap = List<label>() + ); + + // Destructor + + virtual ~MeshedSurfaceProxy(); + + + // Member Function Selectors + + declareMemberFunctionSelectionTable + ( + void, + MeshedSurfaceProxy, + write, + fileExtension, + ( + const fileName& name, + const MeshedSurfaceProxy<Face>& surf + ), + (name, surf) + ); + + //- Write to file + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + + + // Member Functions + + // Access + + //- Return const access to the points + inline const pointField& points() const + { + return points_; + } + + //- Return const access to the faces + inline const List<Face>& faces() const + { + return faces_; + } + + //- Const access to the surface zones. + // If zones are defined, they must be contiguous and cover the entire + // surface. + inline const List<surfZone>& surfZones() const + { + return zones_; + } + + //- Const access to the faceMap, zero-sized when unused + inline const List<label>& faceMap() const + { + return faceMap_; + } + + //- Use faceMap? + inline bool useFaceMap() const + { + return faceMap_.size() == faces_.size(); + } + + // Write + + //- Generic write routine. Chooses writer based on extension. + virtual void write(const fileName& name) const + { + write(name, *this); + } + + //- Write to database + virtual void write(const Time&, const word& surfName = "") const; + + //?? void writeStats(Ostream& os) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "MeshedSurfaceProxy.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxyCore.C b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxyCore.C new file mode 100644 index 0000000000000000000000000000000000000000..41b360fd3e02c5e4ed90c4970e7fb7bad6e30b0b --- /dev/null +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxyCore.C @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "MeshedSurfaceProxy.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +#define makeSurface(surfType, faceType) \ + defineNamedTemplateTypeNameAndDebug(surfType<faceType>, 0); \ + defineTemplatedMemberFunctionSelectionTable(surfType,write,fileExtension,faceType); + + +makeSurface(MeshedSurfaceProxy, face) +makeSurface(MeshedSurfaceProxy, triFace) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C index f74ccdae0bc62f684f8668fa692fbbb26f478590..881f73ebae3b2cdcd1be8da080c92caeca0b323a 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -26,6 +26,7 @@ License #include "MeshedSurface.H" #include "UnsortedMeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "IFstream.H" #include "OFstream.H" #include "Time.H" @@ -57,21 +58,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType const bool verbose ) { - // handle 'native' format directly - if (isNative(ext)) - { - return true; - } - else - { - return checkSupport - ( - readTypes() | SiblingType::readTypes(), - ext, - verbose, - "reading" - ); - } + return checkSupport + ( + readTypes() | ParentType::readTypes(), + ext, + verbose, + "reading" + ); } @@ -82,13 +75,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canWriteType const bool verbose ) { - // handle 'native' format directly - if (isNative(ext)) - { - return true; - } - - return checkSupport(writeTypes(), ext, verbose, "writing"); + return checkSupport + ( + writeTypes(), + ext, + verbose, + "writing" + ); } @@ -125,29 +118,34 @@ void Foam::UnsortedMeshedSurface<Face>::write const word ext = name.ext(); - // handle 'native' format directly - if (isNative(ext)) - { - surf.write(OFstream(name)()); - return; - } - typename writefileExtensionMemberFunctionTable::iterator mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext); if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) { - FatalErrorIn - ( - "UnsortedMeshedSurface::write" - "(const fileName&, const UnsortedMeshedSurface&)" - ) << "Unknown file extension " << ext << nl << nl - << "Valid types are :" << endl - << writeTypes() - << exit(FatalError); - } + // no direct writer, delegate to proxy if possible + wordHashSet supported = ProxyType::writeTypes(); - mfIter()(name, surf); + if (supported.found(ext)) + { + MeshedSurfaceProxy<Face>(surf).write(name); + } + else + { + FatalErrorIn + ( + "UnsortedMeshedSurface::write" + "(const fileName&, const UnsortedMeshedSurface&)" + ) << "Unknown file extension " << ext << nl << nl + << "Valid types are :" << endl + << (supported | writeTypes()) + << exit(FatalError); + } + } + else + { + mfIter()(name, surf); + } } @@ -155,16 +153,18 @@ void Foam::UnsortedMeshedSurface<Face>::write template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface() +: + ParentType() {} template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const Xfer<pointField>& pointLst, - const Xfer<List<Face> >& faceLst, - const Xfer<List<label> >& zoneIds, - const Xfer<surfZoneIdentifierList>& zoneTofc + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< List<label> >& zoneIds, + const Xfer< surfZoneIdentifierList >& zoneTofc ) : ParentType(pointLst, faceLst), @@ -176,17 +176,17 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const Xfer<pointField>& pointLst, - const Xfer<List<Face> >& faceLst, + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, const UList<label>& zoneSizes, const UList<word>& zoneNames ) : ParentType(pointLst, faceLst) { - if (&zoneSizes) + if (zoneSizes.size()) { - if (&zoneNames) + if (zoneNames.size()) { setZones(zoneSizes, zoneNames); } @@ -197,7 +197,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface } else { - oneZone(); + setOneZone(); } } @@ -205,14 +205,17 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const polyBoundaryMesh& bMesh, - const bool useGlobalPoints + const UnsortedMeshedSurface<Face>& surf ) -{ - // creating via MeshedSurface is the easiest - MeshedSurface<Face> surf(bMesh, useGlobalPoints); - transfer(surf); -} +: + ParentType + ( + xferCopy(surf.points()), + xferCopy(surf.faces()) + ), + zoneIds_(surf.zoneIds()), + zoneToc_(surf.zoneToc()) +{} template<class Face> @@ -221,79 +224,76 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface const MeshedSurface<Face>& surf ) : - ParentType(xferCopy(surf.points()), xferCopy(surf.faces())) + ParentType + ( + xferCopy(surf.points()), + xferCopy(surf.faces()) + ) { - setZones(surf.zones()); + setZones(surf.surfZones()); } template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const fileName& name, - const word& ext + const Xfer< UnsortedMeshedSurface<Face> >& surf ) +: + ParentType() { - read(name, ext); -} - - -template<class Face> -Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name) -{ - read(name); -} - - -template<class Face> -Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(Istream& is) -{ - read(is); + transfer(surf()); } template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const Time& d, - const word& surfName + const Xfer< MeshedSurface<Face> >& surf ) +: + ParentType() { - read(IFstream(findMeshFile(d, surfName))()); + transfer(surf()); } template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const UnsortedMeshedSurface<Face>& surf + const fileName& name, + const word& ext ) : - ParentType(xferCopy(surf.points()), xferCopy(surf.faces())), - zoneIds_(surf.zoneIds_), - zoneToc_(surf.zoneToc_) -{} + ParentType() +{ + read(name, ext); +} template<class Face> -Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface -( - const Xfer<UnsortedMeshedSurface<Face> >& surf -) +Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name) +: + ParentType() { - transfer(surf()); + read(name); } template<class Face> Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface ( - const Xfer<MeshedSurface<Face> >& surf + const Time& t, + const word& surfName ) +: + ParentType() { - transfer(surf()); + MeshedSurface<Face> surf(t, surfName); + transfer(surf); } + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template<class Face> @@ -308,22 +308,19 @@ Foam::UnsortedMeshedSurface<Face>::~UnsortedMeshedSurface() // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template<class Face> -void Foam::UnsortedMeshedSurface<Face>::oneZone(const word& name) +void Foam::UnsortedMeshedSurface<Face>::setOneZone() { zoneIds_.setSize(size()); zoneIds_ = 0; - word zoneName(name); + word zoneName; + if (zoneToc_.size()) + { + zoneName = zoneToc_[0].name(); + } if (zoneName.empty()) { - if (zoneToc_.size()) - { - zoneName = zoneToc_[0].name(); - } - if (zoneName.empty()) - { - zoneName = "zone0"; - } + zoneName = "zone0"; } // set single default zone @@ -344,7 +341,6 @@ void Foam::UnsortedMeshedSurface<Face>::setZones forAll(zoneToc_, zoneI) { const surfZone& zone = zoneLst[zoneI]; - zoneToc_[zoneI] = zone; // assign sub-zone Ids @@ -416,7 +412,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces { if (zoneToc_.empty()) { - oneZone(); + setOneZone(); } else if (zoneToc_.size() == 1) { @@ -442,7 +438,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces template<class Face> void Foam::UnsortedMeshedSurface<Face>::setSize(const label s) { - ParentType::setSize(s); + this->storedFaces().setSize(s); // if zones extend: set with last zoneId zoneIds_.setSize(s, zoneToc_.size() - 1); } @@ -470,12 +466,81 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones zoneNames.insert(zoneI, zoneToc_[zoneI].name()); } - return sortedZonesById(zoneIds_, zoneNames, faceMap); + // std::sort() really seems to mix up the order. + // and std::stable_sort() might take too long / too much memory + + // Assuming that we have relatively fewer zones compared to the + // number of items, just do it ourselves + + // step 1: get zone sizes and store (origId => zoneI) + Map<label> lookup; + forAll(zoneIds_, faceI) + { + const label origId = zoneIds_[faceI]; + + Map<label>::iterator fnd = lookup.find(origId); + if (fnd != lookup.end()) + { + fnd()++; + } + else + { + lookup.insert(origId, 1); + } + } + + // step 2: assign start/size (and name) to the newZones + // re-use the lookup to map (zoneId => zoneI) + surfZoneList zoneLst(lookup.size()); + label start = 0; + label zoneI = 0; + forAllIter(Map<label>, lookup, iter) + { + label origId = iter.key(); + + word name; + Map<word>::const_iterator fnd = zoneNames.find(origId); + if (fnd != zoneNames.end()) + { + name = fnd(); + } + else + { + name = word("zone") + ::Foam::name(zoneI); + } + + zoneLst[zoneI] = surfZone + ( + name, + 0, // initialize with zero size + start, + zoneI + ); + + // increment the start for the next zone + // and save the (zoneId => zoneI) mapping + start += iter(); + iter() = zoneI++; + } + + + // step 3: build the re-ordering + faceMap.setSize(zoneIds_.size()); + + forAll(zoneIds_, faceI) + { + label zoneI = lookup[zoneIds_[faceI]]; + faceMap[faceI] = zoneLst[zoneI].start() + zoneLst[zoneI].size()++; + } + + // with reordered faces registered in faceMap + return zoneLst; } template<class Face> -Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh +Foam::UnsortedMeshedSurface<Face> +Foam::UnsortedMeshedSurface<Face>::subsetMesh ( const labelHashSet& include, labelList& pointMap, @@ -542,12 +607,39 @@ Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh template<class Face> void Foam::UnsortedMeshedSurface<Face>::reset ( - const Xfer<pointField>& pointLst, - const Xfer<List<Face> >& faceLst, - const Xfer<List<label> >& zoneIds + const Xfer< pointField >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< List<label> >& zoneIds +) +{ + ParentType::reset + ( + pointLst, + faceLst, + Xfer<surfZoneList>() + ); + + if (&zoneIds) + { + zoneIds_.transfer(zoneIds()); + } +} + + +template<class Face> +void Foam::UnsortedMeshedSurface<Face>::reset +( + const Xfer< List<point> >& pointLst, + const Xfer< List<Face> >& faceLst, + const Xfer< List<label> >& zoneIds ) { - ParentType::reset(pointLst, faceLst); + ParentType::reset + ( + pointLst, + faceLst, + Xfer<surfZoneList>() + ); if (&zoneIds) { @@ -562,12 +654,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer UnsortedMeshedSurface<Face>& surf ) { - reset + ParentType::reset ( xferMove(surf.storedPoints()), xferMove(surf.storedFaces()), - xferMove(surf.zoneIds_) + Xfer<surfZoneList>() ); + + zoneIds_.transfer(surf.zoneIds_); zoneToc_.transfer(surf.zoneToc_); surf.clear(); @@ -580,8 +674,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer MeshedSurface<Face>& surf ) { - reset(xferMove(surf.storedPoints()), xferMove(surf.storedFaces())); - setZones(surf.zones()); + ParentType::reset + ( + xferMove(surf.storedPoints()), + xferMove(surf.storedFaces()), + Xfer<surfZoneList>() + ); + + setZones(surf.surfZones()); surf.clear(); } @@ -620,28 +720,22 @@ bool Foam::UnsortedMeshedSurface<Face>::read const word& ext ) { - // handle 'native' format directly - if (isNative(ext)) - { - return read(IFstream(name)()); - } - else - { - // use selector mechanism - transfer(New(name, ext)()); - return true; - } + clear(); + + // read via use selector mechanism + transfer(New(name, ext)()); + return true; } template<class Face> void Foam::UnsortedMeshedSurface<Face>::write ( - const Time& d, + const Time& t, const word& surfName ) const { - write(OFstream(findMeshFile(d, surfName))()); + MeshedSurfaceProxy<Face>(*this).write(t, surfName); } @@ -662,13 +756,30 @@ void Foam::UnsortedMeshedSurface<Face>::operator= } +template<class Face> +Foam::UnsortedMeshedSurface<Face>::operator +Foam::MeshedSurfaceProxy<Face>() const +{ + labelList faceMap; + List<surfZone> zoneLst = this->sortedZones(faceMap); + + return MeshedSurfaceProxy<Face> + ( + this->points(), + this->faces(), + zoneLst, + faceMap + ); +} + + + // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "UnsortedMeshedSurfaceIO.C" #include "UnsortedMeshedSurfaceNew.C" // ************************************************************************* // diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H index efecda798b9a5b9598773c26daf7abdc17556708..7a272240d15a50abbcb0842878779bdf024e9ec8 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H @@ -47,7 +47,7 @@ SourceFiles #ifndef UnsortedMeshedSurface_H #define UnsortedMeshedSurface_H -#include "BasicMeshedSurface.H" +#include "MeshedSurface.H" #include "surfZoneIdentifierList.H" #include "surfZoneList.H" #include "surfaceFormatsCore.H" @@ -64,14 +64,10 @@ namespace Foam class Time; class IFstream; -template<class Face> class UnsortedMeshedSurface; -template<class Face> class MeshedSurface; - -class polyBoundaryMesh; - -template<class Face> -Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&); +template<class Face> class MeshedSurface; +template<class Face> class MeshedSurfaceProxy; +template<class Face> class UnsortedMeshedSurface; /*---------------------------------------------------------------------------*\ Class UnsortedMeshedSurface Declaration @@ -80,24 +76,20 @@ Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&); template<class Face> class UnsortedMeshedSurface : - public BasicMeshedSurface<Face>, - public fileFormats::surfaceFormatsCore + public MeshedSurface<Face> { - // friends despite different faces - template<class Face2> - friend class MeshedSurface; - - // friends despite different faces - template<class Face2> - friend class UnsortedMeshedSurface; - - friend class MeshedSurface<Face>; + // friends - despite different face representationsx + template<class Face2> friend class MeshedSurface; + template<class Face2> friend class UnsortedMeshedSurface; + friend class surfMesh; private: - //- Typedefs for convenience - typedef BasicMeshedSurface<Face> ParentType; - typedef MeshedSurface<Face> SiblingType; + //- Private typedefs for convenience + + typedef MeshedSurface<Face> ParentType; + typedef MeshedSurface<Face> FriendType; + typedef MeshedSurfaceProxy<Face> ProxyType; // Private Member Data @@ -166,10 +158,10 @@ public: // (points, faces, zone ids, zone info). UnsortedMeshedSurface ( - const Xfer<pointField>&, - const Xfer<List<Face> >&, - const Xfer<List<label> >& zoneIds, - const Xfer<surfZoneIdentifierList>& + const Xfer< pointField >&, + const Xfer< List<Face> >&, + const Xfer< List<label> >& zoneIds, + const Xfer< surfZoneIdentifierList >& ); //- Construct by transferring points, faces. @@ -178,16 +170,12 @@ public: ( const Xfer<pointField>&, const Xfer<List<Face> >&, - const UList<label>& zoneSizes = UList<label>::null(), - const UList<word>& zoneNames = UList<word>::null() + const UList<label>& zoneSizes = UList<label>(), + const UList<word>& zoneNames = UList<word>() ); - //- Construct from a boundary mesh with local points/faces - UnsortedMeshedSurface - ( - const polyBoundaryMesh&, - const bool globalPoints=false - ); + //- Construct as copy + UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&); //- Construct from a meshedSurface UnsortedMeshedSurface(const MeshedSurface<Face>&); @@ -207,12 +195,9 @@ public: //- Construct from Istream UnsortedMeshedSurface(Istream&); - //- Construct from objectRegistry + //- Construct from objectRegistry and a named surface UnsortedMeshedSurface(const Time&, const word& surfName=""); - //- Construct as copy - UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&); - // Declare run-time constructor selection table declareRunTimeSelectionTable @@ -287,13 +272,12 @@ public: return zoneToc_; } - //- Sort faces according to zone. + //- Sort faces according to zoneIds // Returns a surfZoneList and sets faceMap to index within faces() surfZoneList sortedZones(labelList& faceMap) const; //- Set zones to 0 and set a single zone - // Optionally with a specific name - void oneZone(const word& name = word::null); + void setOneZone(); //- Set zone ids and zones void setZones(const surfZoneList&); @@ -328,9 +312,17 @@ public: //- Transfer components (points, faces, zone ids). virtual void reset ( - const Xfer<pointField>&, - const Xfer<List<Face> >&, - const Xfer<List<label> >& zoneIds = Xfer<List<label> >::null() + const Xfer< pointField >&, + const Xfer< List<Face> >&, + const Xfer< List<label> >& zoneIds + ); + + //- Transfer components (points, faces, zone ids). + virtual void reset + ( + const Xfer< List<point> >&, + const Xfer< List<Face> >&, + const Xfer< List<label> >& zoneIds ); //- Transfer the contents of the argument and annull the argument @@ -354,9 +346,6 @@ public: // Write - //- Write to Ostream in simple FOAM format - virtual void write(Ostream&) const; - //- Generic write routine. Chooses writer based on extension. virtual void write(const fileName& name) const { @@ -371,15 +360,8 @@ public: void operator=(const UnsortedMeshedSurface<Face>&); - - // Ostream Operator - - friend Ostream& operator<< - <Face> - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); + //- Conversion operator to MeshedSurfaceProxy + operator MeshedSurfaceProxy<Face>() const; }; diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceIO.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceIO.C deleted file mode 100644 index 391f0dc83bddf316f8b1487bad13f6f37bf7100a..0000000000000000000000000000000000000000 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceIO.C +++ /dev/null @@ -1,108 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -\*---------------------------------------------------------------------------*/ - -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" -#include "IFstream.H" -#include "OFstream.H" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// Read surf grouping, points, faces directly from Istream -template<class Face> -bool Foam::UnsortedMeshedSurface<Face>::read(Istream& is) -{ - MeshedSurface<Face> surf(is); - - transfer(surf); - return is.good(); -} - - -// write (sorted) -template<class Face> -void Foam::UnsortedMeshedSurface<Face>::write(Ostream& os) const -{ - const List<Face>& faceLst = this->faces(); - - labelList faceMap; - surfZoneList zoneLst = sortedZones(faceMap); - - // just emit some information until we get a nice IOobject - IOobject::writeBanner(os); - os << "// OpenFOAM Surface Format" << nl - << "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl - << "// zones:" << nl - << zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl; - - forAll(zoneLst, zoneI) - { - zoneLst[zoneI].writeDict(os); - } - os << decrIndent << token::END_LIST << nl; - - IOobject::writeDivider(os); - - // Note: Write with global point numbering - os << "\n// points:" << nl << this->points() << nl; - - IOobject::writeDivider(os); - os << "\n// faces:" << nl; - os << faceLst.size() << nl << token::BEGIN_LIST << nl; - - label faceI = 0; - forAll(zoneLst, zoneI) - { - // Print all faces belonging to this zone - const surfZone& zone = zoneLst[zoneI]; - - forAll(zone, localFaceI) - { - os << faceLst[faceMap[faceI++]] << nl; - } - } - os << token::END_LIST << nl; - - IOobject::writeDivider(os); - - // Check state of Ostream - os.check("UnsortedMeshedSurface::write(Ostream&)"); -} - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -template<class Face> -Foam::Ostream& Foam::operator<< -( - Ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ - surf.write(os); - return os; -} - -// ************************************************************************* // diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C index d57cce660855e1c08ac5664d8c58cb5e874873b7..222acc40558d4c4c28414fdc1ec8c40919373390 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C @@ -30,7 +30,7 @@ License template<class Face> -Foam::autoPtr<Foam::UnsortedMeshedSurface<Face> > +Foam::autoPtr< Foam::UnsortedMeshedSurface<Face> > Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) { if (debug) @@ -45,8 +45,8 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) if (cstrIter == fileExtensionConstructorTablePtr_->end()) { - // no direct reader, delegate if possible - wordHashSet supported = SiblingType::readTypes(); + // no direct reader, use the parent if possible + wordHashSet supported = ParentType::readTypes(); if (supported.found(ext)) { // create indirectly @@ -54,14 +54,13 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) ( new UnsortedMeshedSurface<Face> ); - surf().transfer(SiblingType::New(name, ext)()); + surf().transfer(ParentType::New(name, ext)()); return surf; } // nothing left but to issue an error supported += readTypes(); - supported.insert(nativeExt); FatalErrorIn ( @@ -79,7 +78,7 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) template<class Face> -Foam::autoPtr<Foam::UnsortedMeshedSurface<Face> > +Foam::autoPtr< Foam::UnsortedMeshedSurface<Face> > Foam::UnsortedMeshedSurface<Face>::New(const fileName& name) { word ext = name.ext(); diff --git a/src/surfMesh/surfFields/surfFields.C b/src/surfMesh/surfFields/surfFields/surfFields.C similarity index 100% rename from src/surfMesh/surfFields/surfFields.C rename to src/surfMesh/surfFields/surfFields/surfFields.C diff --git a/src/surfMesh/surfFields/surfFields.H b/src/surfMesh/surfFields/surfFields/surfFields.H similarity index 100% rename from src/surfMesh/surfFields/surfFields.H rename to src/surfMesh/surfFields/surfFields/surfFields.H diff --git a/src/surfMesh/surfFields/surfFieldsFwd.H b/src/surfMesh/surfFields/surfFields/surfFieldsFwd.H similarity index 100% rename from src/surfMesh/surfFields/surfFieldsFwd.H rename to src/surfMesh/surfFields/surfFields/surfFieldsFwd.H diff --git a/src/surfMesh/surfFields/surfGeoMesh.H b/src/surfMesh/surfFields/surfFields/surfGeoMesh.H similarity index 100% rename from src/surfMesh/surfFields/surfGeoMesh.H rename to src/surfMesh/surfFields/surfFields/surfGeoMesh.H diff --git a/src/surfMesh/surfPointFields/surfPointFields.C b/src/surfMesh/surfFields/surfPointFields/surfPointFields.C similarity index 100% rename from src/surfMesh/surfPointFields/surfPointFields.C rename to src/surfMesh/surfFields/surfPointFields/surfPointFields.C diff --git a/src/surfMesh/surfPointFields/surfPointFields.H b/src/surfMesh/surfFields/surfPointFields/surfPointFields.H similarity index 100% rename from src/surfMesh/surfPointFields/surfPointFields.H rename to src/surfMesh/surfFields/surfPointFields/surfPointFields.H diff --git a/src/surfMesh/surfPointFields/surfPointFieldsFwd.H b/src/surfMesh/surfFields/surfPointFields/surfPointFieldsFwd.H similarity index 100% rename from src/surfMesh/surfPointFields/surfPointFieldsFwd.H rename to src/surfMesh/surfFields/surfPointFields/surfPointFieldsFwd.H diff --git a/src/surfMesh/surfPointFields/surfPointGeoMesh.H b/src/surfMesh/surfFields/surfPointFields/surfPointGeoMesh.H similarity index 100% rename from src/surfMesh/surfPointFields/surfPointGeoMesh.H rename to src/surfMesh/surfFields/surfPointFields/surfPointGeoMesh.H diff --git a/src/surfMesh/surfMesh/surfMesh.C b/src/surfMesh/surfMesh/surfMesh.C index c6166345da5b69bf32179e404f4df298bc27bdf6..1f2d35a54f13772f852b367668ec007b0ff48236 100644 --- a/src/surfMesh/surfMesh/surfMesh.C +++ b/src/surfMesh/surfMesh/surfMesh.C @@ -25,6 +25,8 @@ License \*---------------------------------------------------------------------------*/ #include "surfMesh.H" +#include "MeshedSurfaceProxy.H" + #include "Time.H" #include "cellIOList.H" #include "SubList.H" @@ -40,29 +42,30 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh"; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::surfMesh::oneZone() -{ - word zoneName; - - if (surfZones_.size()) - { - zoneName = surfZones_[0].name(); - } - if (zoneName.empty()) - { - zoneName = "zone0"; - } - - // set single default zone - surfZones_.setSize(1); - surfZones_[0] = surfZone - ( - zoneName, - nFaces(), // zone size - 0, // zone start - 0 // zone index - ); -} +// void Foam::surfMesh::oneZone() +// { +// word zoneName; +// +// surfZoneList& zones = Allocator::storedIOZones(); +// if (zones.size()) +// { +// zoneName = zones[0].name(); +// } +// if (zoneName.empty()) +// { +// zoneName = "zone0"; +// } +// +// // set single default zone +// zones.setSize(1); +// zones[0] = surfZone +// ( +// zoneName, +// nFaces(), // zone size +// 0, // zone start +// 0 // zone index +// ); +// } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -71,7 +74,7 @@ void Foam::surfMesh::oneZone() Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName) : surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), - surfMeshAllocator + Allocator ( IOobject ( @@ -90,11 +93,7 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName) *this, IOobject::MUST_READ, IOobject::NO_WRITE - ) - ), - MeshReference(storedFaces_, storedPoints_), - surfZones_ - ( + ), IOobject ( "surfZones", @@ -104,20 +103,21 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName) IOobject::MUST_READ, IOobject::NO_WRITE ) - ) + ), + MeshReference(this->storedIOFaces(), this->storedIOPoints()) {} Foam::surfMesh::surfMesh ( const IOobject& io, - const Xfer<pointField>& pointLst, - const Xfer<faceList>& faceLst, + const Xfer< pointField >& pointLst, + const Xfer< faceList >& faceLst, const word& surfName ) : surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), - surfMeshAllocator + Allocator ( IOobject ( @@ -138,11 +138,7 @@ Foam::surfMesh::surfMesh IOobject::NO_READ, IOobject::AUTO_WRITE ), - faceLst - ), - MeshReference(storedFaces_, storedPoints_), - surfZones_ - ( + faceLst, IOobject ( "surfZones", @@ -151,8 +147,10 @@ Foam::surfMesh::surfMesh *this, IOobject::NO_READ, IOobject::AUTO_WRITE - ) - ) + ), + Xfer<surfZoneList>() + ), + MeshReference(this->storedIOFaces(), this->storedIOPoints()) {} @@ -164,7 +162,7 @@ Foam::surfMesh::surfMesh ) : surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), - surfMeshAllocator + Allocator ( IOobject ( @@ -185,11 +183,7 @@ Foam::surfMesh::surfMesh IOobject::NO_READ, IOobject::AUTO_WRITE ), - faceList() - ), - MeshReference(storedFaces_, storedPoints_), - surfZones_ - ( + faceList(), IOobject ( "surfZones", @@ -200,9 +194,21 @@ Foam::surfMesh::surfMesh IOobject::AUTO_WRITE ), surfZoneList() - ) + ), + MeshReference(this->storedIOFaces(), this->storedIOPoints()) { - // We can also send Xfer<..>::null just to force initialization + if (debug) + { + Info<<"IOobject: " << io.path() << nl + <<" name: " << io.name() + <<" instance: " << io.instance() + <<" local: " << io.local() + <<" dbDir: " << io.db().dbDir() << endl; + Info<<"creating surfMesh at instance " << instance() << endl; + Info<<"timeName: " << instance() << endl; + } + + // We can also send Xfer<..>::null just to initialize without allocating if (&surf) { transfer(surf()); @@ -213,40 +219,50 @@ Foam::surfMesh::surfMesh Foam::surfMesh::~surfMesh() { - // clearOut(); - // resetMotion(); + // clearOut(); + // resetMotion(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::surfMesh::updatePointsRef() +{ + // assign the reference to the points (this is truly ugly) + reinterpret_cast<SubField<point>&> + ( + const_cast<Field<point>&>(MeshReference::points()) + ) = reinterpret_cast<SubField<point>&>(this->storedPoints()); +} + + +void Foam::surfMesh::updateFacesRef() +{ + // assign the reference to the faces + static_cast<UList<face>&>(*this) = this->storedFaces(); +} + + +void Foam::surfMesh::updateRefs() +{ + this->updatePointsRef(); + this->updateFacesRef(); +} + + void Foam::surfMesh::resetPrimitives ( - const Xfer<pointField>& points, - const Xfer<faceList>& faces, - const Xfer<surfZoneList>& zones, + const Xfer< pointField >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones, const bool validate ) { // Clear addressing. MeshReference::clearGeom(); - // Take over new primitive data. - // Optimized to avoid overwriting data at all - if (&points) - { - storedPoints_.transfer(points()); - } - - if (&faces) - { - storedFaces_.transfer(faces()); - } - - if (&zones) - { - surfZones_.transfer(zones()); - } + Allocator::reset(points, faces, zones); + this->updateRefs(); if (validate) { @@ -255,6 +271,7 @@ void Foam::surfMesh::resetPrimitives } + void Foam::surfMesh::transfer ( MeshedSurface<face>& surf @@ -263,9 +280,11 @@ void Foam::surfMesh::transfer // Clear addressing. MeshReference::clearGeom(); - storedPoints_.transfer(surf.storedPoints()); - storedFaces_.transfer(surf.storedFaces()); - surfZones_.transfer(surf.storedZones()); + this->storedIOPoints().transfer(surf.storedPoints()); + this->storedIOFaces().transfer(surf.storedFaces()); + this->storedIOZones().transfer(surf.storedZones()); + + this->updateRefs(); } @@ -274,9 +293,12 @@ Foam::surfMesh::xfer() { Xfer< MeshedSurface<face> > xf; - xf().storedPoints().transfer(storedPoints_); - xf().storedFaces().transfer(storedFaces_); - xf().storedZones().transfer(surfZones_); + xf().storedPoints().transfer(this->storedPoints()); + xf().storedFaces().transfer(this->storedFaces()); + xf().storedZones().transfer(this->storedZones()); + + // is this needed? + this->updateRefs(); // Clear addressing. MeshReference::clearGeom(); @@ -285,17 +307,6 @@ Foam::surfMesh::xfer() } -void Foam::surfMesh::rename(const word& newName) -{ - FatalErrorIn - ( - "surfMesh::rename(const word&)\n" - ) - << "rename does not work correctly\n"; -} - - - Foam::fileName Foam::surfMesh::meshDir() const { return dbDir()/meshSubDir; @@ -304,51 +315,53 @@ Foam::fileName Foam::surfMesh::meshDir() const const Foam::fileName& Foam::surfMesh::pointsInstance() const { - return storedPoints_.instance(); + return this->storedIOPoints().instance(); } const Foam::fileName& Foam::surfMesh::facesInstance() const { - return storedFaces_.instance(); + return this->storedIOFaces().instance(); } Foam::label Foam::surfMesh::nPoints() const { - return storedPoints_.size(); + return this->points().size(); } Foam::label Foam::surfMesh::nFaces() const { - return storedFaces_.size(); + return this->faces().size(); } const Foam::pointField& Foam::surfMesh::points() const { - return storedPoints_; + return this->storedIOPoints(); } const Foam::faceList& Foam::surfMesh::faces() const { - return storedFaces_; + return this->storedIOFaces(); } void Foam::surfMesh::checkZones() { // extra safety, ensure we have at some zones // and they cover all the faces - fix start silently - if (surfZones_.size() <= 1) + surfZoneList& zones = Allocator::storedIOZones(); + + if (zones.size() <= 1) { - oneZone(); + removeZones(); } else { label count = 0; - forAll(surfZones_, zoneI) + forAll(zones, zoneI) { - surfZones_[zoneI].start() = count; - count += surfZones_[zoneI].size(); + zones[zoneI].start() = count; + count += zones[zoneI].size(); } if (count < nFaces()) @@ -361,7 +374,7 @@ void Foam::surfMesh::checkZones() << " ... extending final zone" << endl; - surfZones_[surfZones_.size()-1].size() += count - nFaces(); + zones[zones.size()-1].size() += count - nFaces(); } else if (count > size()) { @@ -379,15 +392,15 @@ void Foam::surfMesh::checkZones() // Add boundary patches. Constructor helper void Foam::surfMesh::addZones ( - const surfZoneList& zones, + const surfZoneList& srfZones, const bool validate ) { - surfZones_.setSize(zones.size()); + surfZoneList& zones = Allocator::storedIOZones(); - forAll(surfZones_, zoneI) + forAll(zones, zoneI) { - surfZones_[zoneI] = surfZone(zones[zoneI], zoneI); + zones[zoneI] = surfZone(srfZones[zoneI], zoneI); } if (validate) @@ -412,4 +425,22 @@ void Foam::surfMesh::removeFiles() const removeFiles(instance()); } + +void Foam::surfMesh::write(const fileName& name, const surfMesh& surf) +{ + MeshedSurfaceProxy<face> + ( + surf.points(), + surf.faces(), + surf.surfZones() + ).write(name); +} + + +void Foam::surfMesh::write(const fileName& name) +{ + write(name, *this); +} + + // ************************************************************************* // diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index 358620fd61783225cec6bcbf1c36270087c88684..234971788a1409cfa8330130b5b675deac0b6bb9 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -39,66 +39,16 @@ SourceFiles #define surfMesh_H #include "surfaceRegistry.H" +#include "MeshedSurfaceIOAllocator.H" #include "PrimitivePatch.H" -#include "pointField.H" -#include "faceList.H" -#include "pointIOField.H" -#include "faceIOList.H" -#include "labelIOList.H" -#include "surfZoneIOList.H" +#include "SubField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -template<class Face> -class MeshedSurface; - -/*---------------------------------------------------------------------------*\ - Class surfMeshAllocator Declaration -\*---------------------------------------------------------------------------*/ - -//- A helper class for storing points and faces -class surfMeshAllocator -{ -protected: - pointIOField storedPoints_; - faceIOList storedFaces_; - - surfMeshAllocator(const IOobject& ioPoints, const IOobject& ioFaces) - : - storedPoints_(ioPoints), - storedFaces_(ioFaces) - {} - - surfMeshAllocator - ( - const IOobject& ioPoints, - const pointField& points, - const IOobject& ioFaces, - const faceList& faces - ) - : - storedPoints_(ioPoints, points), - storedFaces_(ioFaces, faces) - {} - - surfMeshAllocator - ( - const IOobject& ioPoints, - const Xfer<pointField>& points, - const IOobject& ioFaces, - const Xfer<faceList>& faces - ) - : - storedPoints_(ioPoints, points), - storedFaces_(ioFaces, faces) - {} - -}; - - +template<class Face> class MeshedSurface; /*---------------------------------------------------------------------------*\ Class surfMesh Declaration @@ -106,10 +56,13 @@ protected: class surfMesh : - public surfaceRegistry, - public surfMeshAllocator, - public PrimitivePatch<face, ::Foam::UList, const pointField&, point> + public surfaceRegistry, + private MeshedSurfaceIOAllocator, + public PrimitivePatch<face, ::Foam::UList, ::Foam::SubField<point>, point> { + // friends + template<class Face> friend class MeshedSurface; + template<class Face> friend class UnsortedMeshedSurface; public: @@ -117,8 +70,7 @@ public: //- Enumeration defining the state of the mesh after a read update. // Used for post-processing applications, where the mesh - // needs to update based on the files written in time - // directores + // needs to update based on the files written in time directores enum readUpdateState { UNCHANGED, @@ -132,28 +84,23 @@ private: // Private typedefs + typedef MeshedSurfaceIOAllocator Allocator; + typedef PrimitivePatch < face, ::Foam::UList, - const pointField&, + ::Foam::SubField<point>, point > MeshReference; - // Permanent data - - // Zoning information - //- Face zones - surfZoneIOList surfZones_; + // Permanent data // Private member functions - //- Set a single zone - void oneZone(); - //- Disallow construct as copy surfMesh(const surfMesh&); @@ -165,23 +112,33 @@ protected: // Protected Member Functions //- Non-const access to global points - pointIOField& storedPoints() + pointField& storedPoints() { - return surfMeshAllocator::storedPoints_; + return Allocator::storedIOPoints(); } //- Non-const access to the faces - faceIOList& storedFaces() + faceList& storedFaces() { - return surfMeshAllocator::storedFaces_; + return Allocator::storedIOFaces(); } //- Non-const access to the zones - surfZoneIOList& storedZones() + surfZoneList& storedZones() { - return surfZones_; + return Allocator::storedIOZones(); } + + //- Update references to storedFaces + virtual void updateFacesRef(); + + //- Update references to storedPoints + virtual void updatePointsRef(); + + //- Update references to storedPoints/storedFaces + virtual void updateRefs(); + public: // Public typedefs @@ -247,10 +204,10 @@ public: // Access - //- Return raw points + //- Return the number of raw points virtual label nPoints() const; - //- Return raw faces + //- Return the number of raw faces virtual label nFaces() const; //- Return number of faces @@ -260,28 +217,22 @@ public: } - //- Return raw points + //- Return points virtual const pointField& points() const; - //- Return raw faces + //- Return faces virtual const faceList& faces() const; //- Return surface zones - const surfZoneList& surfZones() const + virtual const surfZoneList& surfZones() const { - return surfZones_; - } - - //- Return non-const access to the zones - surfZoneList& surfZones() - { - return surfZones_; + return Allocator::storedIOZones(); } //- Check the surface zone definitions void checkZones(); - //- Add surface zones patches + //- Add surface zones void addZones ( const List<surfZone>&, @@ -297,15 +248,12 @@ public: //- Remove surface zones void removeZones(); - //- Rename surface - virtual void rename(const word&); - //- Reset mesh primitive data. void resetPrimitives ( - const Xfer<pointField>& points, - const Xfer<faceList>& faces, - const Xfer<surfZoneList>& zones, + const Xfer< pointField >& points, + const Xfer< faceList >& faces, + const Xfer< surfZoneList >& zones, const bool validate = true ); @@ -313,6 +261,16 @@ public: //- Transfer the contents of the argument and annull the argument void transfer(MeshedSurface<face>&); + + //- Avoid masking the normal objectRegistry write + using surfaceRegistry::write; + + //- Write to file + static void write(const fileName&, const surfMesh&); + + //- Write to file + void write(const fileName&); + // Storage management //- Transfer contents to the Xfer container as a MeshedSurface diff --git a/src/surfMesh/surfMesh/surfMeshClear.C b/src/surfMesh/surfMesh/surfMeshClear.C index 92611ef150e0e6089446c99807c169cd4dbfd780..27df24ddd427dfde1cb3b6847e1e7bd45fadae4c 100644 --- a/src/surfMesh/surfMesh/surfMeshClear.C +++ b/src/surfMesh/surfMesh/surfMeshClear.C @@ -40,7 +40,7 @@ void Foam::surfMesh::removeZones() } // Remove the surface zones - surfZones_.clear(); + storedZones().clear(); clearOut(); } diff --git a/src/surfMesh/surfMesh/surfMeshIO.C b/src/surfMesh/surfMesh/surfMeshIO.C index 9665b4e20cd715bb052426c54f63faafd5231be1..f9c44dc8ba40c3070bc91b52a85750fabe8fc336 100644 --- a/src/surfMesh/surfMesh/surfMeshIO.C +++ b/src/surfMesh/surfMesh/surfMeshIO.C @@ -31,20 +31,22 @@ License void Foam::surfMesh::setInstance(const fileName& inst) { - if (debug) + if (debug or true) { Info<< "void surfMesh::setInstance(const fileName& inst) : " << "Resetting file instance to " << inst << endl; } - storedPoints_.writeOpt() = IOobject::AUTO_WRITE; - storedPoints_.instance() = inst; + instance() = inst; + + storedIOPoints().writeOpt() = IOobject::AUTO_WRITE; + storedIOPoints().instance() = inst; - storedFaces_.writeOpt() = IOobject::AUTO_WRITE; - storedFaces_.instance() = inst; + storedIOFaces().writeOpt() = IOobject::AUTO_WRITE; + storedIOFaces().instance() = inst; - surfZones_.writeOpt() = IOobject::AUTO_WRITE; - surfZones_.instance() = inst; + storedIOZones().writeOpt() = IOobject::AUTO_WRITE; + storedIOZones().instance() = inst; } @@ -81,9 +83,9 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() // Set instance to new instance. // Note points instance can differ from faces instance. setInstance(facesInst); - storedPoints_.instance() = pointsInst; + storedIOPoints().instance() = pointsInst; - storedPoints_ = pointIOField + storedIOPoints() = pointIOField ( IOobject ( @@ -97,7 +99,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() ) ); - storedFaces_ = faceIOList + storedFaces() = faceIOList ( IOobject ( @@ -111,9 +113,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() ) ); - // synchronize sizes and references? -// MeshReference::operator=(MeshReference(storedFaces_, storedPoints_)); - // Reset the surface zones surfZoneIOList newZones ( @@ -132,15 +131,16 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() // Check that zone types and names are unchanged bool zonesChanged = false; - if (surfZones_.size() != newZones.size()) + surfZoneList& zones = this->storedIOZones(); + if (zones.size() != newZones.size()) { zonesChanged = true; } else { - forAll (surfZones_, zoneI) + forAll(zones, zoneI) { - if (surfZones_[zoneI].name() != newZones[zoneI].name()) + if (zones[zoneI].name() != newZones[zoneI].name()) { zonesChanged = true; break; @@ -148,7 +148,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() } } - surfZones_.transfer(newZones); + zones.transfer(newZones); if (zonesChanged) { @@ -173,10 +173,9 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() } clearGeom(); + storedIOPoints().instance() = pointsInst; - storedPoints_.instance() = pointsInst; - - storedPoints_ = pointIOField + storedIOPoints() = pointIOField ( IOobject ( @@ -204,4 +203,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() } + + // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C index 8347bdeee8f508040163ccd3a7df827868a7765e..13066c9f67f7cf128e7e60e7f5c56345520a07cb 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C @@ -26,7 +26,6 @@ License #include "AC3DsurfaceFormat.H" #include "clock.H" -#include "IFstream.H" #include "IStringStream.H" #include "tensor.H" #include "primitivePatch.H" @@ -281,26 +280,65 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read template<class Face> void Foam::fileFormats::AC3DsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { - writeHeader(os, zoneLst); + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); - forAll(zoneLst, zoneI) + const List<surfZone>& zones = + ( + surf.surfZones().size() + ? surf.surfZones() + : oneZone(faceLst) + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + if (useFaceMap) + { + FatalErrorIn + ( + "fileFormats::AC3DsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "output with faceMap is not supported " << filename + << exit(FatalError); + } + + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::AC3DsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + writeHeader(os, zones); + + forAll(zones, zoneI) { - const surfZone& zone = zoneLst[zoneI]; + const surfZone& zone = zones[zoneI]; os << "OBJECT poly" << nl - << "name \"" << zone.name() << '"' << endl; + << "name \"" << zone.name() << "\"\n"; // Temporary PrimitivePatch to calculate compact points & faces // use 'UList' to avoid allocations! PrimitivePatch<Face, UList, const pointField&> patch ( - faceLst, + SubList<Face> + ( + faceLst, + zone.size(), + zone.start() + ), pointLst ); @@ -310,7 +348,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write { const point& pt = patch.localPoints()[ptI]; - os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; } os << "numsurf " << patch.localFaces().size() << endl; @@ -337,72 +375,89 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write template<class Face> void Foam::fileFormats::AC3DsurfaceFormat<Face>::write ( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - write(os, surf.points(), surf.faces(), surf.zones()); -} - - -template<class Face> -void Foam::fileFormats::AC3DsurfaceFormat<Face>::write -( - Ostream& os, + const fileName& filename, const UnsortedMeshedSurface<Face>& surf ) { labelList faceMap; List<surfZone> zoneLst = surf.sortedZones(faceMap); - writeHeader(os, zoneLst); - - label faceIndex = 0; - forAll(zoneLst, zoneI) + if (zoneLst.size() <= 1) { - const surfZone& zone = zoneLst[zoneI]; - - os << "OBJECT poly" << nl - << "name \"" << zone.name() << '"' << endl; + write + ( + filename, + MeshedSurfaceProxy<Face> + ( + surf.points(), + surf.faces(), + zoneLst + ) + ); + } + else + { + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::AC3DsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } - // Create zone with only zone faces included for ease of addressing - labelHashSet include(surf.size()); + writeHeader(os, zoneLst); - forAll(zone, localFaceI) + label faceIndex = 0; + forAll(zoneLst, zoneI) { - const label faceI = faceMap[faceIndex++]; - include.insert(faceI); - } + const surfZone& zone = zoneLst[zoneI]; - UnsortedMeshedSurface<Face> subm = surf.subsetMesh(include); + os << "OBJECT poly" << nl + << "name \"" << zone.name() << "\"\n"; - // Now we have isolated surface for this patch alone. Write it. - os << "numvert " << subm.nPoints() << endl; + // Create zone with only zone faces included for ease of addressing + labelHashSet include(surf.size()); - forAll(subm.localPoints(), ptI) - { - const point& pt = subm.localPoints()[ptI]; + forAll(zone, localFaceI) + { + const label faceI = faceMap[faceIndex++]; + include.insert(faceI); + } - os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; - } + UnsortedMeshedSurface<Face> subm = surf.subsetMesh(include); - os << "numsurf " << subm.localFaces().size() << endl; + // Now we have isolated surface for this patch alone. Write it. + os << "numvert " << subm.nPoints() << endl; - forAll(subm.localFaces(), localFaceI) - { - const Face& f = subm.localFaces()[localFaceI]; + forAll(subm.localPoints(), ptI) + { + const point& pt = subm.localPoints()[ptI]; - os << "SURF 0x20" << nl // polygon - << "mat " << zoneI << nl - << "refs " << f.size() << nl; + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; + } - forAll(f, fp) + os << "numsurf " << subm.localFaces().size() << endl; + + forAll(subm.localFaces(), localFaceI) { - os << f[fp] << " 0 0" << nl; + const Face& f = subm.localFaces()[localFaceI]; + + os << "SURF 0x20" << nl // polygon + << "mat " << zoneI << nl + << "refs " << f.size() << nl; + + forAll(f, fp) + { + os << f[fp] << " 0 0" << nl; + } } - } - os << "kids 0" << endl; + os << "kids 0" << endl; + } } } diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H index 24aa25df181a5bb90e39942c470dd8728c3900c2..03345382208c285079561a90335d0f2f9bf91727 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.H @@ -31,8 +31,9 @@ Description http://www.inivis.com/ac3d/man/ac3dfileformat.html Note - The faces are already organized as zones. - The output is always sorted by zones. + On input, the faces are already organized as zones. + The output is always sorted by zones. + In the absence of zones, a single zone will be assigned. SourceFiles AC3DsurfaceFormat.C @@ -42,9 +43,8 @@ SourceFiles #ifndef AC3DsurfaceFormat_H #define AC3DsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" #include "AC3DsurfaceFormatCore.H" @@ -99,58 +99,20 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); - - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Write UnsortedMeshedSurface, the output is always sorted by zones. + static void write(const fileName&, const UnsortedMeshedSurface<Face>&); - //- Write UnsortedMeshedSurface - // The output is always sorted by zones. - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output is always sorted by zones. - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + + //- Read from file + virtual bool read(const fileName&); //- Write object - virtual void write(Ostream& os) const + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H index 93619e5a9b9039e2dc07b331225ebbe09ef3b4fe..1c3e5dc82865f9da08b5af3dfad04996ee1ec76f 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H @@ -36,10 +36,10 @@ SourceFiles #ifndef AC3DsurfaceFormatCore_H #define AC3DsurfaceFormatCore_H +#include "IFstream.H" #include "Ostream.H" #include "OFstream.H" #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C index ba802d1656c54b672dd9591df929dd868d191a3b..05bf9d0ffa1f69efb74075673dc117eb329ad595 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "AC3DsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable ac ); - +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, AC3DsurfaceFormat, face, write, @@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, AC3DsurfaceFormat, triFace, write, @@ -74,6 +74,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); +// write UnsortedMeshedSurface addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormat.H b/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormat.H index fa7401890f084d955e0308d0a81944ab66eddd6f..25883d4eb3e8ea00d470b31e1a025e87e9882aa9 100644 --- a/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormat.H @@ -26,7 +26,8 @@ Class Foam::fileFormats::FTRsurfaceFormat Description - Reading of the (now deprecated and barely used) Foam Trisurface Format. + Reading of the (now deprecated and infrequently used) + Foam Trisurface Format. SourceFiles FTRsurfaceFormat.C diff --git a/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C index a632ab0e48ee7b3eacd34d36640090074df594e3..e52c952b9d05a01b762e998e06f1eb4b1626066a 100644 --- a/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "FTRsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read UnsortedMeshedSurface addNamedTemplatedToRunTimeSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C index 0ac2f27a3566db5d2d4918e9dc68c08781dc58ae..a8b70d864eb5a27add5ac582fd54f909422fd9bc 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C @@ -25,9 +25,12 @@ License \*---------------------------------------------------------------------------*/ #include "GTSsurfaceFormat.H" +#include "surfaceFormatsCore.H" #include "clock.H" #include "IFstream.H" #include "IStringStream.H" +#include "Ostream.H" +#include "OFstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -80,9 +83,9 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read // write directly into the lists: - pointField& pointLst = this->storedPoints(); - List<Face>& faceLst = this->storedFaces(); - List<label>& zoneIds = this->storedZoneIds(); + pointField& pointLst = this->storedPoints(); + List<Face>& faceLst = this->storedFaces(); + List<label>& zoneIds = this->storedZoneIds(); pointLst.setSize(nPoints); faceLst.setSize(nElems); @@ -217,6 +220,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read } this->storedZoneToc().transfer(newZones); + return true; } @@ -224,19 +228,24 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read template<class Face> void Foam::fileFormats::GTSsurfaceFormat<Face>::write ( - Ostream& os, + const fileName& filename, const MeshedSurface<Face>& surf ) { const pointField& pointLst = surf.points(); const List<Face>& faceLst = surf.faces(); - const List<surfZone>& zoneLst = surf.zones(); + const List<surfZone>& zones = + ( + surf.surfZones().size() + ? surf.surfZones() + : surfaceFormatsCore::oneZone(faceLst) + ); // check if output triangulation would be required // It is too annoying to triangulate on-the-fly // just issue a warning and get out - if (!surf.isTri()) + if (!MeshedSurface<Face>::isTri()) { label nNonTris = 0; forAll(faceLst, faceI) @@ -252,7 +261,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write FatalErrorIn ( "fileFormats::GTSsurfaceFormat::write" - "(Ostream&, const MeshedSurface<Face>&)" + "(const fileName&, const MeshedSurface<Face>&)" ) << "Surface has " << nNonTris << "/" << faceLst.size() << " non-triangulated faces - not writing!" << endl; @@ -260,16 +269,30 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write } } + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::GTSsurfaceFormat::write" + "(const fileName&, const MeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + // Write header, print zone names as comment os << "# GTS file" << nl << "# Zones:" << nl; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { os << "# " << zoneI << " " - << zoneLst[zoneI].name() << nl; + << zones[zoneI].name() << nl; } - os << "#" << endl; + os << "#" << nl; os << "# nPoints nEdges nTriangles" << nl << pointLst.size() << ' ' << surf.nEdges() << ' ' @@ -279,9 +302,9 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write // Write vertex coords forAll(pointLst, pointI) { - os << pointLst[pointI].x() << ' ' - << pointLst[pointI].y() << ' ' - << pointLst[pointI].z() << endl; + const point& pt = pointLst[pointI]; + + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; } @@ -300,9 +323,9 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write const labelListList& faceEs = surf.faceEdges(); label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - const surfZone& zone = zoneLst[zoneI]; + const surfZone& zone = zones[zoneI]; forAll(zone, localFaceI) { @@ -320,19 +343,19 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write template<class Face> void Foam::fileFormats::GTSsurfaceFormat<Face>::write ( - Ostream& os, + const fileName& filename, const UnsortedMeshedSurface<Face>& surf ) { const pointField& pointLst = surf.points(); const List<Face>& faceLst = surf.faces(); - const List<label>& zoneIds = surf.zoneIds(); + const List<label>& zoneIds = surf.zoneIds(); const List<surfZoneIdentifier>& zoneToc = surf.zoneToc(); // check if output triangulation would be required // It is too annoying to triangulate on-the-fly // just issue a warning and get out - if (!surf.isTri()) + if (!MeshedSurface<Face>::isTri()) { label nNonTris = 0; forAll(faceLst, faceI) @@ -348,7 +371,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write FatalErrorIn ( "fileFormats::GTSsurfaceFormat::write" - "(Ostream&, const UnsortedMeshedSurfaces<Face>&)" + "(const fileName&, const UnsortedMeshedSurfaces<Face>&)" ) << "Surface has " << nNonTris << "/" << faceLst.size() << " non-triangulated faces - not writing!" << endl; @@ -356,6 +379,20 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write } } + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::GTSsurfaceFormat::write" + "(const fileName&, const UnsortedMeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + // Write header, print zone names as comment os << "# GTS file" << nl << "# Zones:" << nl; diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H index be4a7411e4e1d68717cffd80bfa7a5105966edd3..91ef7227c72455e41e9174f3e7ca562508a89bfc 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.H @@ -27,7 +27,8 @@ Class Description Provide a means of reading/writing GTS format. - The output is never sorted by zone. + The output is never sorted by zone and is only written if it consists + entirely of triangles. SourceFiles GTSsurfaceFormat.C @@ -37,9 +38,8 @@ SourceFiles #ifndef GTSsurfaceFormat_H #define GTSsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -90,49 +90,20 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); + static void write(const fileName&, const MeshedSurface<Face>&); - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Write UnsortedMeshedSurface, the output remains unsorted + static void write(const fileName&, const UnsortedMeshedSurface<Face>&); - //- Write UnsortedMeshedSurface - // The output remains unsorted - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output remains unsorted - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + + //- Read from file + virtual bool read(const fileName&); //- Write object - virtual void write(Ostream& os) const + virtual void write(const fileName& name) const { - write(os, *this); + write(name, *this); } }; diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C index 8d34c0cc17d65650657150b9bd0f4d1bfe283ac1..d3268962d25fef310e97a3ebb3c8e09d43fff6ea 100644 --- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "GTSsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read UnsortedMeshedSurface addNamedTemplatedToRunTimeSelectionTable ( UnsortedMeshedSurface, @@ -53,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable gts ); +// write MeshedSurface addNamedTemplatedToMemberFunctionSelectionTable ( MeshedSurface, @@ -72,6 +73,7 @@ addNamedTemplatedToMemberFunctionSelectionTable gts ); +// write UnsortedMeshedSurface addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C index adfa807a62f4b9285dee9d520b69757f562246a5..4933afa9d490ed3bcd5eed8be48ebddac2654779 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C @@ -76,6 +76,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read Map<label> lookup; // assume the types are not intermixed + // leave faces that didn't have a group in 0 bool sorted = true; label zoneI = 0; @@ -89,10 +90,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read label ansaId = -1; word ansaType, ansaName; - // leave faces that didn't have a group in 0 - // label groupID = 0; - // label maxGroupID = -1; - // A single warning per unrecognized command HashSet<word> unhandledCmd; @@ -374,8 +371,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read List<word> names(dynSizes.size()); forAllConstIter(Map<label>, lookup, iter) { - const label zoneI = iter(); - const label groupI = iter.key(); + const label zoneI = iter(); + const label groupI = iter.key(); Map<word>::const_iterator fnd = nameLookup.find(groupI); if (fnd != nameLookup.end()) @@ -388,7 +385,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read } } - sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted); // add zones, culling empty ones diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H index 83d735acb3b4800051c2c3fb52c784b6f3025e1d..46ea1e59c39a1fd524f98b45a4271b4c1e09e8dd 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.H @@ -44,9 +44,8 @@ SourceFiles #ifndef NASsurfaceFormat_H #define NASsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" #include "NASsurfaceFormatCore.H" diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C index 568f902e3153341b750ee0726292a8755e01926a..af182980ba6539f4ca50b04812de78801e152e21 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C @@ -25,14 +25,13 @@ License \*---------------------------------------------------------------------------*/ #include "NASsurfaceFormatCore.H" -#include "IFstream.H" #include "IStringStream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -// Do weird things to extract number +// Do weird things to extract a floating point number Foam::scalar Foam::fileFormats::NASsurfaceFormatCore::parseNASCoord ( const string& s diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C index 46d9f4aeb1d4618773a7eeaff6b30848efd500fe..7bebc54830ff0707c1eb840b116afd86eb81831a 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "NASsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,8 +35,7 @@ namespace Foam namespace fileFormats { -// .bdf (Bulk Data Format) -// .nas (Nastran) +// read MeshedSurface - .bdf (Bulk Data Format) addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -55,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable nas ); +// read MeshedSurface - .nas (Nastran) addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index db4295ce64d5b6f334e96073dd1c9ab4df251824..47ae2122eb2b99664b12349b1049212b7391c171 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -25,8 +25,11 @@ License \*---------------------------------------------------------------------------*/ #include "OBJsurfaceFormat.H" +#include "clock.H" #include "IFstream.H" #include "IStringStream.H" +#include "Ostream.H" +#include "OFstream.H" #include "ListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -213,84 +216,108 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read template<class Face> void Foam::fileFormats::OBJsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { - writeHeader(os, pointLst, faceLst.size(), zoneLst); - - label faceIndex = 0; - forAll(zoneLst, zoneI) + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + // for no zones, suppress the group name + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst, "") + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + OFstream os(filename); + if (!os.good()) { - const surfZone& zone = zoneLst[zoneI]; + FatalErrorIn + ( + "fileFormats::OBJsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } - os << "g " << zone.name() << endl; - forAll(zone, localFaceI) - { - const Face& f = faceLst[faceIndex++]; + os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl + << "o " << os.name().lessExt().name() << nl + << nl + << "# points : " << pointLst.size() << nl + << "# faces : " << faceLst.size() << nl + << "# zones : " << zones.size() << nl; - os << 'f'; - forAll(f, fp) - { - os << ' ' << f[fp] + 1; - } - os << endl; - } + // Print zone names as comment + forAll(zones, zoneI) + { + os << "# " << zoneI << " " << zones[zoneI].name() + << " (nFaces: " << zones[zoneI].size() << ")" << nl; } - os << "# </faces>" << endl; -} + os << nl + << "# <points count=\"" << pointLst.size() << "\">" << nl; -template<class Face> -void Foam::fileFormats::OBJsurfaceFormat<Face>::write -( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - write(os, surf.points(), surf.faces(), surf.zones()); -} - + // Write vertex coords + forAll(pointLst, ptI) + { + const point& pt = pointLst[ptI]; -template<class Face> -void Foam::fileFormats::OBJsurfaceFormat<Face>::write -( - Ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ - const List<Face>& faceLst = surf.faces(); + os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; + } - labelList faceMap; - List<surfZone> zoneLst = surf.sortedZones(faceMap); + os << "# </points>" << nl + << nl + << "# <faces count=\"" << faceLst.size() << "\">" << endl; - writeHeader(os, surf.points(), faceLst.size(), zoneLst); label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - // Print all faces belonging to this zone - const surfZone& zone = zoneLst[zoneI]; + const surfZone& zone = zones[zoneI]; - os << "g " << zone.name() << endl; + if (zone.name().size()) + { + os << "g " << zone.name() << endl; + } - forAll(zone, localFaceI) + if (useFaceMap) { - const Face& f = faceLst[faceMap[faceIndex++]]; + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; - os << 'f'; - forAll(f, fp) + os << 'f'; + forAll(f, fp) + { + os << ' ' << f[fp] + 1; + } + os << endl; + } + } + else + { + forAll(zone, localFaceI) { - os << ' ' << f[fp] + 1; + const Face& f = faceLst[faceIndex++]; + + os << 'f'; + forAll(f, fp) + { + os << ' ' << f[fp] + 1; + } + os << endl; } - os << endl; } } - os << "# </faces>" << endl; } + // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H index d9acc483abc1714e144c627395623389d300f1bb..424074b0f079cc11f45dd7f1e224e7dc77de6ffe 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.H @@ -38,11 +38,9 @@ SourceFiles #ifndef OBJsurfaceFormat_H #define OBJsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" -#include "OBJsurfaceFormatCore.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -58,8 +56,7 @@ namespace fileFormats template<class Face> class OBJsurfaceFormat : - public MeshedSurface<Face>, - public OBJsurfaceFormatCore + public MeshedSurface<Face> { // Private Member Functions @@ -95,58 +92,16 @@ public: // Member Functions + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + //- Read from file virtual bool read(const fileName&); - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); - - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } - - //- Write UnsortedMeshedSurface - // The output is sorted by zones - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output is sorted by zones - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } - - //- Write object - virtual void write(Ostream& os) const + //- Write object file + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C index 4752aaf53b11e45a0f5ea6f7f4a4fba7a3f3e13a..6c6789a3ad3439178a40201a34ad3063157949ca 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "OBJsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,29 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable obj ); - -addNamedTemplatedToMemberFunctionSelectionTable -( - MeshedSurface, - OBJsurfaceFormat, - face, - write, - fileExtension, - obj -); -addNamedTemplatedToMemberFunctionSelectionTable -( - MeshedSurface, - OBJsurfaceFormat, - triFace, - write, - fileExtension, - obj -); - +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - UnsortedMeshedSurface, + MeshedSurfaceProxy, OBJsurfaceFormat, face, write, @@ -84,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - UnsortedMeshedSurface, + MeshedSurfaceProxy, OBJsurfaceFormat, triFace, write, @@ -92,7 +73,6 @@ addNamedTemplatedToMemberFunctionSelectionTable obj ); - } } diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C index 7e73affa17d2e97855beac7efb255f97fe9e9a49..531e599f250a795fe591446b464a43782397d988 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C @@ -25,8 +25,11 @@ License \*---------------------------------------------------------------------------*/ #include "OFFsurfaceFormat.H" +#include "clock.H" #include "IFstream.H" #include "IStringStream.H" +#include "Ostream.H" +#include "OFstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -60,7 +63,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read { FatalErrorIn ( - "fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)" + "fileFormats::OFFsurfaceFormat::read(const fileName&)" ) << "Cannot read file " << filename << exit(FatalError); @@ -72,7 +75,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read { FatalErrorIn ( - "fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)" + "fileFormats::OFFsurfaceFormat::read(const fileName&)" ) << "OFF file " << filename << " does not start with 'OFF'" << exit(FatalError); @@ -142,11 +145,9 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read } } - // transfer to normal lists - reset(pointLst.xfer(), dynFaces.xfer()); + // transfer to normal lists, no zone information + reset(pointLst.xfer(), dynFaces.xfer(), Xfer<surfZoneList>()); - // no zone information - this->oneZone(); return true; } @@ -154,81 +155,97 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read template<class Face> void Foam::fileFormats::OFFsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { - writeHeader(os, pointLst, faceLst.size(), zoneLst); + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + const List<surfZone>& zoneLst = surf.surfZones(); - label faceIndex = 0; - forAll(zoneLst, zoneI) + OFstream os(filename); + if (!os.good()) { - os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl; - - forAll(zoneLst[zoneI], localFaceI) - { - const Face& f = faceLst[faceIndex++]; - - os << f.size(); - forAll(f, fp) - { - os << ' ' << f[fp]; - } - - // add optional zone information - os << ' ' << zoneI << endl; - } - os << "# </zone>" << endl; + FatalErrorIn + ( + "fileFormats::OFFsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); } - os << "# </faces>" << endl; -} - -template<class Face> -void Foam::fileFormats::OFFsurfaceFormat<Face>::write -( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - write(os, surf.points(), surf.faces(), surf.zones()); -} + // Write header + os << "OFF" << endl + << "# Geomview OFF file written " << clock::dateTime().c_str() << nl + << nl + << "# points : " << pointLst.size() << nl + << "# faces : " << faceLst.size() << nl + << "# zones : " << zoneLst.size() << nl; + // Print zone names as comment + forAll(zoneLst, zoneI) + { + os << "# " << zoneI << " " << zoneLst[zoneI].name() + << " (nFaces: " << zoneLst[zoneI].size() << ")" << nl; + } -template<class Face> -void Foam::fileFormats::OFFsurfaceFormat<Face>::write -( - Ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ - const List<Face>& faceLst = surf.faces(); + os << nl + << "# nPoints nFaces nEdges" << nl + << pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl + << nl + << "# <points count=\"" << pointLst.size() << "\">" << endl; - labelList faceMap; - List<surfZone> zoneLst = surf.sortedZones(faceMap); + // Write vertex coords + forAll(pointLst, ptI) + { + os << pointLst[ptI].x() << ' ' + << pointLst[ptI].y() << ' ' + << pointLst[ptI].z() << " #" << ptI << endl; + } - writeHeader(os, surf.points(), faceLst.size(), zoneLst); + os << "# </points>" << nl + << nl + << "# <faces count=\"" << faceLst.size() << "\">" << endl; label faceIndex = 0; forAll(zoneLst, zoneI) { os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl; - forAll(zoneLst[zoneI], localFaceI) + if (surf.useFaceMap()) { - const Face& f = faceLst[faceMap[faceIndex++]]; - - os << f.size(); - forAll(f, fp) + forAll(zoneLst[zoneI], localFaceI) { - os << ' ' << f[fp]; - } + const Face& f = faceLst[faceMap[faceIndex++]]; - // add optional zone information - os << ' ' << zoneI << endl; + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + + // add optional zone information + os << ' ' << zoneI << endl; + } } + else + { + forAll(zoneLst[zoneI], localFaceI) + { + const Face& f = faceLst[faceIndex++]; + + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + + // add optional zone information + os << ' ' << zoneI << endl; + } + } os << "# </zone>" << endl; } os << "# </faces>" << endl; diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H index 669be5a9a5b68fcc4481e461391c87aac8e7e0fe..bc3f608addd0e0288fdfb42be8a9995a163707e7 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.H @@ -46,11 +46,9 @@ SourceFiles #ifndef OFFsurfaceFormat_H #define OFFsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" -#include "OFFsurfaceFormatCore.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -66,8 +64,7 @@ namespace fileFormats template<class Face> class OFFsurfaceFormat : - public MeshedSurface<Face>, - public OFFsurfaceFormatCore + public MeshedSurface<Face> { // Private Member Functions @@ -101,58 +98,17 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); - - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } - //- Write UnsortedMeshedSurface - // The output is sorted by zone. - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output is sorted by zone. - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Read from file + virtual bool read(const fileName&); //- Write object - virtual void write(Ostream& os) const + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C index 8a848788be0f2592ce7f085c8ac5c36d0a599730..5989f60bf0803550586e5fc5dfdbb67c160436b5 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "OFFsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable off ); - +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, OFFsurfaceFormat, face, write, @@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, OFFsurfaceFormat, triFace, write, @@ -74,25 +74,6 @@ addNamedTemplatedToMemberFunctionSelectionTable ); -addNamedTemplatedToMemberFunctionSelectionTable -( - UnsortedMeshedSurface, - OFFsurfaceFormat, - face, - write, - fileExtension, - off -); -addNamedTemplatedToMemberFunctionSelectionTable -( - UnsortedMeshedSurface, - OFFsurfaceFormat, - triFace, - write, - fileExtension, - off -); - } } diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C new file mode 100644 index 0000000000000000000000000000000000000000..3368ff3138938ed83ca06a861b2df661e281aad8 --- /dev/null +++ b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.C @@ -0,0 +1,260 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "OFSsurfaceFormat.H" +#include "IFstream.H" +#include "IStringStream.H" +#include "ListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Face> +Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat +( + const fileName& filename +) +{ + read(filename); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Face> +bool Foam::fileFormats::OFSsurfaceFormat<Face>::read +( + const fileName& filename +) +{ + this->clear(); + + IFstream is(filename); + if (!is.good()) + { + FatalErrorIn + ( + "fileFormats::OFSsurfaceFormat::read(const fileName&)" + ) + << "Cannot read file " << filename + << exit(FatalError); + } + + // read surfZones: + is >> this->storedZones(); + + // read points: + is >> this->storedPoints(); + + // must triangulate? + if (MeshedSurface<Face>::isTri()) + { + // read faces as 'face' and transcribe to 'triFace' + List<face> faceLst(is); + + MeshedSurface<face> surf + ( + xferMove(this->storedPoints()), + xferMove(faceLst), + xferMove(this->storedZones()) + ); + + this->transcribe(surf); + } + else + { + // read faces directly + is >> this->storedFaces(); + } + + return true; +} + + +template<class Face> +bool Foam::fileFormats::OFSsurfaceFormat<Face>::read +( + Istream& is, + pointField& pointLst, + List<Face>& faceLst, + List<surfZone>& zoneLst +) +{ + if (!is.good()) + { + FatalErrorIn + ( + "fileFormats::OFSsurfaceFormat::read" + "(Istream&, pointField&, List<Face>&, List<surfZone>&)" + ) + << "read error " + << exit(FatalError); + } + + // read surfZones: + is >> zoneLst; + + // read points: + is >> pointLst; + + // must triangulate? + if (MeshedSurface<Face>::isTri()) + { + // read faces as 'face' and transcribe to 'triFace' + List<face> origFaces(is); + + MeshedSurface<face> origSurf + ( + xferMove(pointLst), + xferMove(origFaces), + xferMove(zoneLst) + ); + + MeshedSurface<Face> surf; + surf.transcribe(origSurf); + } + else + { + // read faces directly + is >> faceLst; + } + + return true; +} + + +template<class Face> +bool Foam::fileFormats::OFSsurfaceFormat<Face>::read +( + Istream& is, + MeshedSurface<Face>& surf +) +{ + surf.clear(); + + if (!is.good()) + { + FatalErrorIn + ( + "fileFormats::OFSsurfaceFormat::read" + "(Istream&, MeshedSurface<Face>&)" + ) + << "read error " + << exit(FatalError); + } + + pointField pointLst; + List<Face> faceLst; + List<surfZone> zoneLst; + + read(is, pointLst, faceLst, zoneLst); + + surf.reset + ( + xferMove(pointLst), + xferMove(faceLst), + xferMove(zoneLst) + ); + + return true; +} + + +template<class Face> +bool Foam::fileFormats::OFSsurfaceFormat<Face>::read +( + Istream& is, + UnsortedMeshedSurface<Face>& surf +) +{ + surf.clear(); + MeshedSurface<Face> origSurf(is); + surf.transfer(origSurf); + + return true; +} + + + +template<class Face> +void Foam::fileFormats::OFSsurfaceFormat<Face>::write +( + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf +) +{ + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::OFSsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + + OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones()); + + const List<surfZone>& zones = surf.surfZones(); + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + if (useFaceMap) + { + os << "\n// faces:" << nl + << faceLst.size() << token::BEGIN_LIST << nl; + + label faceI = 0; + forAll(zones, zoneI) + { + // Print all faces belonging to this zone + const surfZone& zone = zones[zoneI]; + + forAll(zone, localFaceI) + { + os << faceLst[faceMap[faceI++]] << nl; + } + } + os << token::END_LIST << nl; + } + else + { + os << "\n// faces:" << nl << faceLst << nl; + } + + IOobject::writeDivider(os); + + // Check state of Ostream + os.check("OFSsurfaceFormat<Face>::write(Ostream&)"); +} + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H new file mode 100644 index 0000000000000000000000000000000000000000..e550d04e7d192474167900982279d7484c81e5d2 --- /dev/null +++ b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormat.H @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::fileFormats::OFSsurfaceFormat + +Description + Provide a means of reading/writing the single-file OpenFOAM surface format. + +Note + This class provides more methods than the regular surface format interface.x + +SourceFiles + OFSsurfaceFormat.C + +\*---------------------------------------------------------------------------*/ + +#ifndef OFSsurfaceFormat_H +#define OFSsurfaceFormat_H + +#include "Ostream.H" +#include "OFstream.H" +#include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" +#include "UnsortedMeshedSurface.H" +#include "OFSsurfaceFormatCore.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fileFormats +{ + +/*---------------------------------------------------------------------------*\ + Class OFSsurfaceFormat Declaration +\*---------------------------------------------------------------------------*/ + +template<class Face> +class OFSsurfaceFormat +: + public MeshedSurface<Face>, + public OFSsurfaceFormatCore +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + OFSsurfaceFormat(const OFSsurfaceFormat<Face>&); + + //- Disallow default bitwise assignment + void operator=(const OFSsurfaceFormat<Face>&); + +public: + + // Constructors + + //- Construct from file name + OFSsurfaceFormat(const fileName&); + + // Selectors + + //- Read file and return surface + static autoPtr<MeshedSurface<Face> > New(const fileName& name) + { + return autoPtr<MeshedSurface<Face> > + ( + new OFSsurfaceFormat<Face>(name) + ); + } + + // Destructor + + virtual ~OFSsurfaceFormat() + {} + + + // Member Functions + + //- Read surface mesh components + static bool read + ( + Istream&, + pointField&, + List<Face>&, + List<surfZone>& + ); + + //- Read MeshedSurface + static bool read + ( + Istream&, + MeshedSurface<Face>& + ); + + //- Read UnsortedMeshedSurface + // The output is sorted by zones + static bool read + ( + Istream&, + UnsortedMeshedSurface<Face>& + ); + + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + + + //- Read from file + virtual bool read(const fileName&); + + //- Write object + virtual void write(const fileName& name) const + { + write(name, MeshedSurfaceProxy<Face>(*this)); + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fileFormats +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "OFSsurfaceFormat.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C similarity index 59% rename from src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C rename to src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C index 0095dc9279cc93bb972d5086c6bf69904f0f8964..09b4324f38b5bf6e54822cf42d469fc2b62caf0d 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.C @@ -24,48 +24,53 @@ License \*---------------------------------------------------------------------------*/ -#include "SMESHsurfaceFormatCore.H" +#include "OFSsurfaceFormatCore.H" #include "clock.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::fileFormats::SMESHsurfaceFormatCore::writeHeader +void Foam::fileFormats::OFSsurfaceFormatCore::writeHeader ( Ostream& os, const pointField& pointLst, - const label nFaces + const UList<surfZone>& zoneLst ) { - // Write header - os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl; - os << "# <points count=\"" << pointLst.size() << "\">" << endl; - os << pointLst.size() << " 3" << nl; // 3: dimensions + // just emit some information until we get a nice IOobject + IOobject::writeBanner(os) + << "// OpenFOAM Surface Format - written " + << clock::dateTime().c_str() << nl + << "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl << nl + << "// surfZones:" << nl; + - // Write vertex coords - forAll(pointLst, ptI) + // treat a single zone as being unzoned + if (zoneLst.size() <= 1) { - os << ptI - << ' ' << pointLst[ptI].x() - << ' ' << pointLst[ptI].y() - << ' ' << pointLst[ptI].z() << nl; + os << "0" << token::BEGIN_LIST << token::END_LIST << nl << nl; } - os << "# </points>" << nl - << nl - << "# <faces count=\"" << nFaces << "\">" << endl; + else + { + os << zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl; - os << nFaces << " 1" << endl; // one attribute: zone number -} + forAll(zoneLst, zoneI) + { + zoneLst[zoneI].writeDict(os); + } + os << decrIndent << token::END_LIST << nl << nl; + } + // Note: write with global point numbering -void Foam::fileFormats::SMESHsurfaceFormatCore::writeTail(Ostream& os) -{ - os << "# </faces>" << nl - << nl - << "# no holes or regions:" << nl - << '0' << nl // holes - << '0' << endl; // regions + IOobject::writeDivider(os) + << "\n// points:" << nl << pointLst << nl; + + IOobject::writeDivider(os); } + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H similarity index 86% rename from src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H rename to src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H index 42e48f75f6c1635addafb0456287009223b095ed..d9d7ef5cd39eb927b37e57db63f903eae6df84be 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatCore.H @@ -23,18 +23,18 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::fileFormats::OBJsurfaceFormatCore + Foam::fileFormats::OFSsurfaceFormatCore Description - Internal class used by the OBJsurfaceFormat + Internal class used by the OFSsurfaceFormat SourceFiles - OBJsurfaceFormatCore.C + OFSsurfaceFormatCore.C \*---------------------------------------------------------------------------*/ -#ifndef OBJsurfaceFormatCore_H -#define OBJsurfaceFormatCore_H +#ifndef OFSsurfaceFormatCore_H +#define OFSsurfaceFormatCore_H #include "Ostream.H" #include "OFstream.H" @@ -49,20 +49,19 @@ namespace fileFormats { /*---------------------------------------------------------------------------*\ - Class OBJsurfaceFormatCore Declaration + Class OFSsurfaceFormatCore Declaration \*---------------------------------------------------------------------------*/ -class OBJsurfaceFormatCore +class OFSsurfaceFormatCore { protected: // Protected Member Functions - //- Write header information with points + //- Write header information and surfZoneList static void writeHeader ( Ostream&, const pointField&, - const label nFaces, const UList<surfZone>& ); diff --git a/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C new file mode 100644 index 0000000000000000000000000000000000000000..fc1e609d67aaa2f99075514e6b1febc4f84d637d --- /dev/null +++ b/src/surfMesh/surfaceFormats/ofs/OFSsurfaceFormatRunTime.C @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "OFSsurfaceFormat.H" + +#include "addToRunTimeSelectionTable.H" +#include "addToMemberFunctionSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +namespace Foam +{ +namespace fileFormats +{ + +// read MeshedSurface +addNamedTemplatedToRunTimeSelectionTable +( + MeshedSurface, + OFSsurfaceFormat, + face, + fileExtension, + ofs +); +addNamedTemplatedToRunTimeSelectionTable +( + MeshedSurface, + OFSsurfaceFormat, + triFace, + fileExtension, + ofs +); + + +// write MeshedSurfaceProxy +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + OFSsurfaceFormat, + face, + write, + fileExtension, + ofs +); +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + OFSsurfaceFormat, + triFace, + write, + fileExtension, + ofs +); + + +} +} + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C index 3aba1aa74477362fe92161958a81c061628d3b9d..c354f4ce5a84a679606c796617b4ba6fa160065e 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C @@ -25,6 +25,10 @@ License \*---------------------------------------------------------------------------*/ #include "SMESHsurfaceFormat.H" +#include "clock.H" +#include "IFstream.H" +#include "OFstream.H" +#include "Ostream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -41,76 +45,98 @@ Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat() template<class Face> void Foam::fileFormats::SMESHsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { - writeHeader(os, pointLst, faceLst.size()); + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); - label faceIndex = 0; - forAll(zoneLst, zoneI) - { - forAll(zoneLst[zoneI], localFaceI) - { - const Face& f = faceLst[faceIndex++]; + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) + ); - os << f.size(); - forAll(f, fp) - { - os << ' ' << f[fp]; - } - os << ' ' << zoneI << endl; - } - } + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); - writeTail(os); -} + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::SMESHsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } -template<class Face> -void Foam::fileFormats::SMESHsurfaceFormat<Face>::write -( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - write(os, surf.points(), surf.faces(), surf.zones()); -} + // Write header + os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl + << "# <points count=\"" << pointLst.size() << "\">" << nl + << pointLst.size() << " 3" << nl; // 3: dimensions -template<class Face> -void Foam::fileFormats::SMESHsurfaceFormat<Face>::write -( - Ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ - const List<Face>& faceLst = surf.faces(); + // Write vertex coords + forAll(pointLst, ptI) + { + const point& pt = pointLst[ptI]; + + os << ptI << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; + } + os << "# </points>" << nl + << nl + << "# <faces count=\"" << faceLst.size() << "\">" << endl; - writeHeader(os, surf.points(), faceLst.size()); + os << faceLst.size() << " 1" << endl; // one attribute: zone number - labelList faceMap; - List<surfZone> zoneLst = surf.sortedZones(faceMap); label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - forAll(zoneLst[zoneI], localFaceI) - { - const Face& f = faceLst[faceMap[faceIndex++]]; + const surfZone& zone = zones[zoneI]; - os << f.size(); - forAll(f, fp) + if (useFaceMap) + { + forAll(zone, localFaceI) { - os << ' ' << f[fp]; + const Face& f = faceLst[faceMap[faceIndex++]]; + + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + os << ' ' << zoneI << endl; + } + } + else + { + forAll(zones[zoneI], localFaceI) + { + const Face& f = faceLst[faceIndex++]; + + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + os << ' ' << zoneI << endl; } - os << ' ' << zoneI << endl; } } - writeTail(os); + // write tail + + os << "# </faces>" << nl + << nl + << "# no holes or regions:" << nl + << '0' << nl // holes + << '0' << endl; // regions } diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H index 4ddc438cbbb64be0cf21b10deed5a6a85ceff35a..c3a472da3fefe0c8d3272bb067d47b0764fc4a29 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.H @@ -42,12 +42,9 @@ SourceFiles #ifndef SMESHsurfaceFormat_H #define SMESHsurfaceFormat_H -#include "IFstream.H" -#include "OFstream.H" -#include "Ostream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" -#include "SMESHsurfaceFormatCore.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -63,8 +60,7 @@ namespace fileFormats template<class Face> class SMESHsurfaceFormat : - public MeshedSurface<Face>, - public SMESHsurfaceFormatCore + public MeshedSurface<Face> { // Private Member Functions @@ -91,55 +87,14 @@ public: // Member Functions - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); - - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - //- Write UnsortedMeshedSurface - // The output is sorted by zone. - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output is sorted by zone. - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } //- Write object - virtual void write(Ostream& os) const + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatRunTime.C index 8f041d1bae03c6125eb7d9b8110246f74a352ea2..e985af30ad20d6ce1baf1498f765f88c6f339533 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "SMESHsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,28 +35,10 @@ namespace Foam namespace fileFormats { +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, - SMESHsurfaceFormat, - face, - write, - fileExtension, - smesh -); -addNamedTemplatedToMemberFunctionSelectionTable -( - MeshedSurface, - SMESHsurfaceFormat, - triFace, - write, - fileExtension, - smesh -); - -addNamedTemplatedToMemberFunctionSelectionTable -( - UnsortedMeshedSurface, + MeshedSurfaceProxy, SMESHsurfaceFormat, face, write, @@ -66,7 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - UnsortedMeshedSurface, + MeshedSurfaceProxy, SMESHsurfaceFormat, triFace, write, diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C index 4fcac468c2198c5c923815838d23b4d3993041ee..0daa6de71bf075b9106df57fea3a30963e48d90a 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C @@ -41,10 +41,10 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell ) { os << cellId // includes 1 offset - << " " << starcdShellShape_ // 3(shell) shape - << " " << f.size() - << " " << cellTableId - << " " << starcdShellType_; // 4(shell) + << ' ' << starcdShellShape_ // 3(shell) shape + << ' ' << f.size() + << ' ' << cellTableId + << ' ' << starcdShellType_; // 4(shell) // primitives have <= 8 vertices, but prevent overrun anyhow // indent following lines for ease of reading @@ -55,7 +55,7 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell { os << nl << " " << cellId; } - os << " " << f[fp] + 1; + os << ' ' << f[fp] + 1; count++; } os << endl; @@ -221,78 +221,49 @@ template<class Face> void Foam::fileFormats::STARCDsurfaceFormat<Face>::write ( const fileName& filename, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const MeshedSurfaceProxy<Face>& surf ) { - fileName baseName = filename.lessExt(); - - writePoints(OFstream(baseName + ".vrt")(), pointLst); - OFstream os(baseName + ".cel"); - writeHeader(os, "CELL"); - - label faceIndex = 0; - forAll(zoneLst, zoneI) - { - const surfZone& zone = zoneLst[zoneI]; - - forAll(zone, localFaceI) - { - const Face& f = faceLst[faceIndex++]; - writeShell(os, f, faceIndex, zoneI + 1); - } - } + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); - // write simple .inp file - writeCase + const List<surfZone>& zones = ( - OFstream(baseName + ".inp")(), - pointLst, - faceLst.size(), - zoneLst + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) ); -} - - -template<class Face> -void Foam::fileFormats::STARCDsurfaceFormat<Face>::write -( - const fileName& filename, - const MeshedSurface<Face>& surf -) -{ - write(filename, surf.points(), surf.faces(), surf.zones()); -} + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); -template<class Face> -void Foam::fileFormats::STARCDsurfaceFormat<Face>::write -( - const fileName& filename, - const UnsortedMeshedSurface<Face>& surf -) -{ fileName baseName = filename.lessExt(); - writePoints(OFstream(baseName + ".vrt")(), surf.points()); + writePoints(OFstream(baseName + ".vrt")(), pointLst); OFstream os(baseName + ".cel"); writeHeader(os, "CELL"); - const List<Face>& faceLst = surf.faces(); - labelList faceMap; - List<surfZone> zoneLst = surf.sortedZones(faceMap); - label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - const surfZone& zone = zoneLst[zoneI]; + const surfZone& zone = zones[zoneI]; - forAll(zone, localFaceI) + if (useFaceMap) { - const Face& f = faceLst[faceMap[faceIndex++]]; - writeShell(os, f, faceIndex, zoneI + 1); + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; + writeShell(os, f, faceIndex, zoneI + 1); + } + } + else + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceIndex++]; + writeShell(os, f, faceIndex, zoneI + 1); + } } } @@ -300,10 +271,11 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write writeCase ( OFstream(baseName + ".inp")(), - surf.points(), - surf.size(), - zoneLst + pointLst, + faceLst.size(), + zones ); } + // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H index a0e8314c262bec7df7621333c6f4f915a1c57d25..9bdb435bd7482e222296c5e0ac31f8da9ffd8ca3 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.H @@ -42,9 +42,8 @@ SourceFiles #ifndef STARCDsurfaceFormat_H #define STARCDsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" #include "STARCDsurfaceFormatCore.H" @@ -114,37 +113,17 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - //- Write surface mesh components - static void write - ( - const fileName&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - //- Write MeshedSurface - static void write - ( - const fileName&, - const MeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output is sorted by zones - static void write - ( - const fileName&, - const UnsortedMeshedSurface<Face>& - ); + //- Read from file + virtual bool read(const fileName&); - //- Write to Ostream as one large file - not really useful - virtual void write(Ostream&) const + //- Write object + virtual void write(const fileName& name) const { - notImplemented("fileFormats::STARCDsurfaceFormat::write(Ostream&)"); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C index 0539f41e583e72055dc01469fa28097baca69e8e..ab052f5229c664409bac876c44ac78be5c97ea36 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C @@ -104,7 +104,7 @@ bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints { FatalErrorIn ( - "fileFormats::STARCDsurfaceFormatCore::readPoints(const fileName&)" + "fileFormats::STARCDsurfaceFormatCore::readPoints(...)" ) << "Cannot read file " << is.name() << exit(FatalError); diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H index 0cadd394d28ed25f0fadc3ee5e4719826ad52ce1..42d5cc077eb15d418861f3722a0b82c9bed85bea 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.H @@ -26,7 +26,7 @@ Class Foam::fileFormats::STARCDsurfaceFormatCore Description - Internal class used by the OBJsurfaceFormat + Internal class used by the STARCDsurfaceFormat SourceFiles STARCDsurfaceFormatCore.C @@ -38,8 +38,8 @@ SourceFiles #include "IFstream.H" #include "Ostream.H" +#include "OFstream.H" #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatRunTime.C index 612b2c4f9235899ecf56c2f910c04e265551654f..5affcb99604187dab45319d4b1a5edfbdfa0fddc 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "STARCDsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable inp ); - +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STARCDsurfaceFormat, face, write, @@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STARCDsurfaceFormat, triFace, write, @@ -74,25 +74,6 @@ addNamedTemplatedToMemberFunctionSelectionTable ); -addNamedTemplatedToMemberFunctionSelectionTable -( - UnsortedMeshedSurface, - STARCDsurfaceFormat, - face, - write, - fileExtension, - inp -); -addNamedTemplatedToMemberFunctionSelectionTable -( - UnsortedMeshedSurface, - STARCDsurfaceFormat, - triFace, - write, - fileExtension, - inp -); - } } diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index bbc1c097303d5975f67acd06099545a1ca2ba86a..2f9d54371a584735907e988d99e1b2b174feac0a 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -111,91 +111,6 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell } -template<class Face> -void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY -( - ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst -) -{ - unsigned int nTris = 0; - if (BasicMeshedSurface<Face>::isTri()) - { - nTris = faceLst.size(); - } - else - { - // count triangles for on-the-fly triangulation - forAll(faceLst, faceI) - { - nTris += faceLst[faceI].size() - 2; - } - } - - // Write the STL header - STLsurfaceFormatCore::writeHeaderBINARY(os, nTris); - - label faceIndex = 0; - forAll(zoneLst, zoneI) - { - forAll(zoneLst[zoneI], localFaceI) - { - writeShell - ( - os, - pointLst, - faceLst[faceIndex++], - zoneI - ); - } - } -} - - -template<class Face> -void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY -( - ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ - const pointField& pointLst = surf.points(); - const List<Face>& faceLst = surf.faces(); - const List<label>& zoneIds = surf.zoneIds(); - - unsigned int nTris = 0; - if (surf.isTri()) - { - nTris = faceLst.size(); - } - else - { - // count triangles for on-the-fly triangulation - forAll(faceLst, faceI) - { - nTris += faceLst[faceI].size() - 2; - } - } - - // Write the STL header - STLsurfaceFormatCore::writeHeaderBINARY(os, nTris); - - // always write unsorted - forAll(faceLst, faceI) - { - writeShell - ( - os, - pointLst, - faceLst[faceI], - zoneIds[faceI] - ); - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Face> @@ -274,25 +189,61 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read } + template<class Face> -void Foam::fileFormats::STLsurfaceFormat<Face>::write +void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::STLsurfaceFormat::writeAscii" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { // Print all faces belonging to this zone - const surfZone& zone = zoneLst[zoneI]; + const surfZone& zone = zones[zoneI]; - os << "solid " << zone.name() << endl; - forAll(zone, localFaceI) + os << "solid " << zone.name() << nl; + + if (useFaceMap) + { + forAll(zone, localFaceI) + { + const label faceI = faceMap[faceIndex++]; + writeShell(os, pointLst, faceLst[faceI]); + } + } + else { - writeShell(os, pointLst, faceLst[faceIndex++]); + forAll(zone, localFaceI) + { + writeShell(os, pointLst, faceLst[faceIndex++]); + } } os << "endsolid " << zone.name() << endl; } @@ -300,29 +251,116 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write template<class Face> -void Foam::fileFormats::STLsurfaceFormat<Face>::write +void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary ( - Ostream& os, - const MeshedSurface<Face>& surf + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { - write(os, surf.points(), surf.faces(), surf.zones()); + std::ofstream os(filename.c_str(), std::ios::binary); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::STLsurfaceFormat::writeBinary" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + + unsigned int nTris = 0; + if (MeshedSurface<Face>::isTri()) + { + nTris = faceLst.size(); + } + else + { + // count triangles for on-the-fly triangulation + forAll(faceLst, faceI) + { + nTris += faceLst[faceI].size() - 2; + } + } + + // Write the STL header + STLsurfaceFormatCore::writeHeaderBINARY(os, nTris); + + label faceIndex = 0; + forAll(zones, zoneI) + { + const surfZone& zone = zones[zoneI]; + + if (useFaceMap) + { + forAll(zone, localFaceI) + { + writeShell + ( + os, + pointLst, + faceLst[faceMap[faceIndex++]], + zoneI + ); + } + } + else + { + forAll(zone, localFaceI) + { + writeShell + ( + os, + pointLst, + faceLst[faceIndex++], + zoneI + ); + } + } + } } template<class Face> -void Foam::fileFormats::STLsurfaceFormat<Face>::write +void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii ( - Ostream& os, + const fileName& filename, const UnsortedMeshedSurface<Face>& surf ) { - const pointField& pointLst = surf.points(); - const List<Face>& faceLst = surf.faces(); + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::STLsurfaceFormat::writeAscii" + "(const fileName&, const UnsortedMeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + // a single zone - we can skip sorting if (surf.zoneToc().size() == 1) { - // a single zone - we can skip sorting + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + os << "solid " << surf.zoneToc()[0].name() << endl; forAll(faceLst, faceI) { @@ -332,32 +370,82 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write } else { - labelList faceMap; - List<surfZone> zoneLst = surf.sortedZones(faceMap); + labelList faceMap; + List<surfZone> zoneLst = surf.sortedZones(faceMap); + + writeAscii + ( + filename, + MeshedSurfaceProxy<Face> + ( + surf.points(), + surf.faces(), + zoneLst, + faceMap + ) + ); + } +} - label faceIndex = 0; - forAll(zoneLst, zoneI) - { - // Print all faces belonging to this zone - const surfZone& zone = zoneLst[zoneI]; - os << "solid " << zone.name() << endl; - forAll(zone, localFaceI) - { - const label faceI = faceMap[faceIndex++]; - writeShell(os, pointLst, faceLst[faceI]); - } - os << "endsolid " << zone.name() << endl; +template<class Face> +void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary +( + const fileName& filename, + const UnsortedMeshedSurface<Face>& surf +) +{ + std::ofstream os(filename.c_str(), std::ios::binary); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::STLsurfaceFormat::writeBinary" + "(const fileName&, const UnsortedMeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& zoneIds = surf.zoneIds(); + + unsigned int nTris = 0; + if (MeshedSurface<Face>::isTri()) + { + nTris = faceLst.size(); + } + else + { + // count triangles for on-the-fly triangulation + forAll(faceLst, faceI) + { + nTris += faceLst[faceI].size() - 2; } - } -} + } + + // Write the STL header + STLsurfaceFormatCore::writeHeaderBINARY(os, nTris); + // always write unsorted + forAll(faceLst, faceI) + { + writeShell + ( + os, + pointLst, + faceLst[faceI], + zoneIds[faceI] + ); + } +} template<class Face> void Foam::fileFormats::STLsurfaceFormat<Face>::write ( const fileName& filename, - const MeshedSurface<Face>& surf + const MeshedSurfaceProxy<Face>& surf ) { const word ext = filename.ext(); @@ -365,18 +453,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write // handle 'stlb' as binary directly if (ext == "stlb") { - std::ofstream ofs(filename.c_str(), std::ios::binary); - writeBINARY(ofs, surf); + writeBinary(filename, surf); } else { - write - ( - OFstream(filename)(), - surf.points(), - surf.faces(), - surf.zones() - ); + writeAscii(filename, surf); } } @@ -393,12 +474,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write // handle 'stlb' as binary directly if (ext == "stlb") { - std::ofstream ofs(filename.c_str(), std::ios::binary); - writeBINARY(ofs, surf); + writeBinary(filename, surf); } else { - write(OFstream(filename)(), surf); + writeAscii(filename, surf); } } diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H index 8fa474455c6e077dc1dcc09349b48743c66496a1..ada49101aeb3398eb472a1e134a8ca51b258d579 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H @@ -43,6 +43,7 @@ SourceFiles #include "STLsurfaceFormatCore.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -63,7 +64,7 @@ class STLsurfaceFormat { // Private Member Functions - //- Write Face in ASCII + //- Write Face (ASCII) static inline void writeShell ( Ostream&, @@ -71,7 +72,7 @@ class STLsurfaceFormat const Face& ); - //- Write Face in BINARY + //- Write Face (BINARY) static inline void writeShell ( ostream&, @@ -80,19 +81,6 @@ class STLsurfaceFormat const label zoneI ); - - //- Write surface mesh components (as BINARY) - static void writeBINARY - ( - ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write UnsortedMeshedSurface - static void writeBINARY(ostream&, const UnsortedMeshedSurface<Face>&); - //- Disallow default bitwise copy construct STLsurfaceFormat(const STLsurfaceFormat<Face>&); @@ -122,51 +110,50 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); - - //- Write surface mesh components (as ASCII) - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface (as ASCII) - static void write + //- Write surface mesh components by proxy (as ASCII) + static void writeAscii ( - Ostream&, - const MeshedSurface<Face>& + const fileName&, + const MeshedSurfaceProxy<Face>& ); - //- Write MeshedSurface (ASCII or BINARY, depending on the extension) - static void write + //- Write surface mesh components by proxy (as BINARY) + static void writeBinary ( const fileName&, - const MeshedSurface<Face>& + const MeshedSurfaceProxy<Face>& ); + //- Write surface mesh components by proxy + // as ASCII or BINARY, depending on the extension + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + //- Write UnsortedMeshedSurface (as ASCII) sorted by zone - static void write + static void writeAscii ( - Ostream&, + const fileName&, const UnsortedMeshedSurface<Face>& ); - //- Write UnsortedMeshedSurface - // ASCII output is sorted by zone; binary output is unsorted - static void write + //- Write UnsortedMeshedSurface (as BINARY) unsorted by zone + static void writeBinary ( const fileName&, const UnsortedMeshedSurface<Face>& ); - //- Write object (only ASCII output) - virtual void write(Ostream& os) const + //- Write UnsortedMeshedSurface + // as ASCII or BINARY, depending on the extension + static void write(const fileName&, const UnsortedMeshedSurface<Face>&); + + + //- Read from file + virtual bool read(const fileName&); + + //- Write object + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatASCII.L b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatASCII.L index 74e9ab2245e043c177167ae6ca14f579ebc73f77..4bf7880c25d3a7724607355101d3f4aa440c3ba2 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatASCII.L +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatASCII.L @@ -403,13 +403,13 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})* // bool Foam::fileFormats::STLsurfaceFormatCore::readASCII ( - IFstream& ifs, + istream& is, const off_t dataFileSize ) { // Create the lexer with the approximate number of vertices in the STL // from the file size - STLASCIILexer lexer(&ifs.stdStream(), dataFileSize/400); + STLASCIILexer lexer(&is, dataFileSize/400); while (lexer.lex() != 0) {} sorted_ = lexer.sorted(); diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C index 6ba5f661e3bd079e90a8a4a3aa28c1b6453f7f62..f9d052d6aca30d70b3f292c216590b97493cc150 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C @@ -28,6 +28,8 @@ License #include "gzstream.h" #include "OSspecific.H" #include "Map.H" +#include "IFstream.H" +#include "Ostream.H" #undef DEBUG_STLBINARY @@ -48,8 +50,7 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY { off_t dataFileSize = Foam::fileSize(filename); - IFstream ifs(filename, IOstream::BINARY); - istream& is = ifs.stdStream(); + istream& is = IFstream(filename, IOstream::BINARY)().stdStream(); // Read the STL header char header[headerSize]; @@ -89,12 +90,11 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY ( - IFstream& ifs, + istream& is, const off_t dataFileSize ) { sorted_ = true; - istream& is = ifs.stdStream(); // Read the STL header char header[headerSize]; @@ -131,7 +131,7 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY { FatalErrorIn ( - "fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)" + "fileFormats::STLsurfaceFormatCore::readBINARY(istream&)" ) << "problem reading number of triangles, perhaps file is not binary" << exit(FatalError); @@ -230,11 +230,19 @@ Foam::fileFormats::STLsurfaceFormatCore::STLsurfaceFormatCore // auto-detect ascii/binary if (detectBINARY(filename)) { - readBINARY(IFstream(filename, IOstream::BINARY)(), dataFileSize); + readBINARY + ( + IFstream(filename, IOstream::BINARY)().stdStream(), + dataFileSize + ); } else { - readASCII(IFstream(filename)(), dataFileSize); + readASCII + ( + IFstream(filename)().stdStream(), + dataFileSize + ); } } diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H index f7c28a98f18ee5096b6264a01705b6a79b1cb2a2..7e4fe94e8a325667947614831481119586dd25c6 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H @@ -41,7 +41,6 @@ SourceFiles #include "triFace.H" #include "IFstream.H" #include "Ostream.H" -#include "OFstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -51,7 +50,7 @@ namespace fileFormats { /*---------------------------------------------------------------------------*\ - Class STLsurfaceFormatCore Declaration + Class STLsurfaceFormatCore Declaration \*---------------------------------------------------------------------------*/ class STLsurfaceFormatCore @@ -84,10 +83,10 @@ class STLsurfaceFormatCore static int detectBINARY(const fileName&); //- Read ASCII - bool readASCII(IFstream&, const off_t); + bool readASCII(istream&, const off_t); //- Read BINARY - bool readBINARY(IFstream&, const off_t); + bool readBINARY(istream&, const off_t); public: diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C index cb3d091d452611b82559d16f9a16249caead792a..8e78ce7675d521aeea800fc091b095486e1ac466 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "STLsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface (ascii) addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable stl ); +// read MeshedSurface (binary) addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -71,9 +72,10 @@ addNamedTemplatedToRunTimeSelectionTable ); +// write MeshedSurfaceProxy (ascii) addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STLsurfaceFormat, face, write, @@ -82,7 +84,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STLsurfaceFormat, triFace, write, @@ -90,9 +92,10 @@ addNamedTemplatedToMemberFunctionSelectionTable stl ); +// write MeshedSurfaceProxy (binary) addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STLsurfaceFormat, face, write, @@ -101,7 +104,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, STLsurfaceFormat, triFace, write, @@ -109,6 +112,7 @@ addNamedTemplatedToMemberFunctionSelectionTable stlb ); +// write UnsortedMeshedSurface (ascii) addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, @@ -128,6 +132,7 @@ addNamedTemplatedToMemberFunctionSelectionTable stl ); +// write UnsortedMeshedSurface (binary) addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C index 81c99e9b0da420023ca63b670bb010bcd9ab47e0..3c5a8a7344da92d870d70fe1390eefa221270440 100644 --- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C +++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C @@ -25,9 +25,10 @@ License \*---------------------------------------------------------------------------*/ #include "surfaceFormatsCore.H" + +#include "Time.H" #include "IFstream.H" #include "OFstream.H" -#include "Time.H" #include "SortableList.H" #include "surfMesh.H" @@ -37,13 +38,6 @@ Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs"); // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -bool -Foam::fileFormats::surfaceFormatsCore::isNative(const word& ext) -{ - return (ext == nativeExt); -} - - Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment ( @@ -60,7 +54,7 @@ Foam::fileFormats::surfaceFormatsCore::getLineNoComment return line; } - +#if 0 Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName(const word& surfName) { @@ -68,9 +62,7 @@ Foam::fileFormats::surfaceFormatsCore::localMeshFileName(const word& surfName) return fileName ( - surfaceRegistry::subInstance - / name - / surfMesh::meshSubDir + surfaceRegistry::prefix/name/surfMesh::meshSubDir / name + "." + nativeExt ); } @@ -79,7 +71,7 @@ Foam::fileFormats::surfaceFormatsCore::localMeshFileName(const word& surfName) Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance ( - const Time& d, + const Time& t, const word& surfName ) { @@ -88,12 +80,12 @@ Foam::fileFormats::surfaceFormatsCore::findMeshInstance // Search back through the time directories list to find the time // closest to and lower than current time - instantList ts = d.times(); + instantList ts = t.times(); label instanceI; for (instanceI = ts.size()-1; instanceI >= 0; --instanceI) { - if (ts[instanceI].value() <= d.timeOutputValue()) + if (ts[instanceI].value() <= t.timeOutputValue()) { break; } @@ -106,7 +98,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshInstance { for (label i = instanceI; i >= 0; --i) { - if (isFile(d.path()/ts[i].name()/localName)) + if (isFile(t.path()/ts[i].name()/localName)) { return ts[i].name(); } @@ -120,7 +112,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshInstance Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile ( - const Time& d, + const Time& t, const word& surfName ) { @@ -129,12 +121,12 @@ Foam::fileFormats::surfaceFormatsCore::findMeshFile // Search back through the time directories list to find the time // closest to and lower than current time - instantList ts = d.times(); + instantList ts = t.times(); label instanceI; for (instanceI = ts.size()-1; instanceI >= 0; --instanceI) { - if (ts[instanceI].value() <= d.timeOutputValue()) + if (ts[instanceI].value() <= t.timeOutputValue()) { break; } @@ -147,7 +139,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshFile { for (label i = instanceI; i >= 0; --i) { - fileName testName(d.path()/ts[i].name()/localName); + fileName testName(t.path()/ts[i].name()/localName); if (isFile(testName)) { @@ -157,94 +149,9 @@ Foam::fileFormats::surfaceFormatsCore::findMeshFile } // fallback to "constant" - return d.path()/"constant"/localName; -} - - -// Returns zone info. -// Sets faceMap to the indexing according to zone numbers. -// Zone numbers start at 0. -Foam::surfZoneList -Foam::fileFormats::surfaceFormatsCore::sortedZonesById -( - const UList<label>& zoneIds, - const Map<word>& zoneNames, - labelList& faceMap -) -{ - // determine sort order according to zone numbers - - // std::sort() really seems to mix up the order. - // and std::stable_sort() might take too long / too much memory - - // Assuming that we have relatively fewer zones compared to the - // number of items, just do it ourselves - - // step 1: get zone sizes and store (origId => zoneI) - Map<label> lookup; - forAll(zoneIds, faceI) - { - const label origId = zoneIds[faceI]; - - Map<label>::iterator fnd = lookup.find(origId); - if (fnd != lookup.end()) - { - fnd()++; - } - else - { - lookup.insert(origId, 1); - } - } - - // step 2: assign start/size (and name) to the newZones - // re-use the lookup to map (zoneId => zoneI) - surfZoneList zoneLst(lookup.size()); - label start = 0; - label zoneI = 0; - forAllIter(Map<label>, lookup, iter) - { - label origId = iter.key(); - - word name; - Map<word>::const_iterator fnd = zoneNames.find(origId); - if (fnd != zoneNames.end()) - { - name = fnd(); - } - else - { - name = word("zone") + ::Foam::name(zoneI); - } - - zoneLst[zoneI] = surfZone - ( - name, - 0, // initialize with zero size - start, - zoneI - ); - - // increment the start for the next zone - // and save the (zoneId => zoneI) mapping - start += iter(); - iter() = zoneI++; - } - - - // step 3: build the re-ordering - faceMap.setSize(zoneIds.size()); - - forAll(zoneIds, faceI) - { - label zoneI = lookup[zoneIds[faceI]]; - faceMap[faceI] = - zoneLst[zoneI].start() + zoneLst[zoneI].size()++; - } - - // with reordered faces registered in faceMap - return zoneLst; + return t.path()/"constant"/localName; } +#endif bool @@ -267,7 +174,7 @@ Foam::fileFormats::surfaceFormatsCore::checkSupport Info<<"Unknown file extension for " << functionName << " : " << ext << nl - <<"Valid types: ( " << nativeExt; + <<"Valid types: ("; // compact output: forAll(known, i) { @@ -291,6 +198,7 @@ Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore() Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore() {} + // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H index b8b227902cd00393ebb41f8f1c4daf4435f4dc74..b23ff267191650effebdb247a9d0377d1b6589d7 100644 --- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H +++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H @@ -61,48 +61,54 @@ namespace fileFormats class surfaceFormatsCore { +protected: + + //- Return a list with a single entry, + // the size corresponds to that of the container + template<class Container> + static List<surfZone> oneZone + ( + const Container& container, + const word& name = "zone0" + ) + { + return List<surfZone>(1, surfZone(name, container.size(), 0, 0)); + } + + //- Read non-comment line + static string getLineNoComment(IFstream&); + public: // Static Data - //- The file extension corresponding to 'native' surface format - // Normally "ofs" (mnemonic: OF = OpenFOAM, S = Surface) - static word nativeExt; + //- The file extension corresponding to 'native' surface format + // Normally "ofs" (mnemonic: OF = OpenFOAM, S = Surface) + static word nativeExt; // Static Member Functions - //- Check if file extension corresponds to 'native' surface format - static bool isNative(const word&); + static bool checkSupport + ( + const wordHashSet& available, + const word& ext, + const bool verbose, + const word& functionName + ); - //- Read non-comment line - static string getLineNoComment(IFstream&); //- Return the local file name (within time directory) + // NEEDS FIXING static fileName localMeshFileName(const word& surfName=""); //- Find instance with surfName + // NEEDS FIXING static fileName findMeshInstance(const Time&, const word& surfName=""); //- Find mesh file with surfName + // NEEDS FIXING static fileName findMeshFile(const Time&, const word& surfName=""); - //- Determine the sort order from the zone ids. - // Returns zone list and sets faceMap to indices within faceLst - static surfZoneList sortedZonesById - ( - const UList<label>& zoneIds, - const Map<word>& zoneNames, - labelList& faceMap - ); - - static bool checkSupport - ( - const wordHashSet& available, - const word& ext, - const bool verbose, - const word& functionName - ); - // Constructors //- Construct null diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C index 2058b3e8f3c0d8eb20547d1d426effa26c2ab68e..da5d8685140d3865c8a00ada927c49f4387b7018 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C @@ -131,19 +131,55 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read template<class Face> void Foam::fileFormats::TRIsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::TRIsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - forAll(zoneLst[zoneI], localFaceI) + const surfZone& zone = zones[zoneI]; + + if (useFaceMap) { - const Face& f = faceLst[faceIndex++]; - writeShell(os, pointLst, f, zoneI); + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; + writeShell(os, pointLst, f, zoneI); + } + } + else + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceIndex++]; + writeShell(os, pointLst, f, zoneI); + } } } } @@ -152,32 +188,37 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write template<class Face> void Foam::fileFormats::TRIsurfaceFormat<Face>::write ( - Ostream& os, - const MeshedSurface<Face>& surf -) -{ - write(os, surf.points(), surf.faces(), surf.zones()); -} - - -template<class Face> -void Foam::fileFormats::TRIsurfaceFormat<Face>::write -( - Ostream& os, + const fileName& filename, const UnsortedMeshedSurface<Face>& surf ) { const pointField& pointLst = surf.points(); const List<Face>& faceLst = surf.faces(); - bool doSort = false; + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::TRIsurfaceFormat::write" + "(const fileName&, const UnsortedMeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + // a single zone needs no sorting if (surf.zoneToc().size() == 1) { - doSort = false; - } + const List<label>& zoneIds = surf.zoneIds(); - if (doSort) + forAll(faceLst, faceI) + { + writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]); + } + } + else { labelList faceMap; List<surfZone> zoneLst = surf.sortedZones(faceMap); @@ -192,15 +233,6 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write } } } - else - { - const List<label>& zoneIds = surf.zoneIds(); - - forAll(faceLst, faceI) - { - writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]); - } - } } // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H index 6506954b0402f7b5829b6cc2c4882aa1fbbe40c0..557cb60170314dd75688d4862cf1639acc4d013e 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.H @@ -41,9 +41,8 @@ SourceFiles #define TRIsurfaceFormat_H #include "TRIsurfaceFormatCore.H" -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -102,58 +101,21 @@ public: // Member Functions - //- Read from file - virtual bool read(const fileName&); - - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Write UnsortedMeshedSurface, + // by default the output is not sorted by zones + static void write(const fileName&, const UnsortedMeshedSurface<Face>&); - //- Write UnsortedMeshedSurface - // By default, the output is not sorted by zones - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - //- Write UnsortedMeshedSurface - // By default, the output is not sorted by zones - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Read from file + virtual bool read(const fileName&); //- Write object - virtual void write(Ostream& os) const + virtual void write(const fileName& name) const { - write(os, *this); + write(name, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.H index 18855d8696d30595425a63e30a5495d7c3910634..67b459528094e02dabd773bb63bec892f6c81c05 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.H @@ -38,6 +38,7 @@ SourceFiles #include "surfaceFormatsCore.H" #include "triFace.H" + #include "IFstream.H" #include "Ostream.H" #include "OFstream.H" diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C index 8dbe5818decb772f606c4b1b92b638ccb208f4db..9f333cc4fe4580db09f644c93a92f8f580cdd414 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "TRIsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,6 +35,7 @@ namespace Foam namespace fileFormats { +// read MeshedSurface addNamedTemplatedToRunTimeSelectionTable ( MeshedSurface, @@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable tri ); - +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, TRIsurfaceFormat, face, write, @@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, TRIsurfaceFormat, triFace, write, @@ -73,6 +73,7 @@ addNamedTemplatedToMemberFunctionSelectionTable tri ); +// write UnsortedMeshedSurface addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C index 9a8723dd3b964e8145b90645da65c46fa8b7cf43..c8a1fbf1db56e1d212fa57897df65417bc71fd6a 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C @@ -61,53 +61,98 @@ Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat() template<class Face> void Foam::fileFormats::VTKsurfaceFormat<Face>::write ( - Ostream& os, - const pointField& pointLst, - const List<Face>& faceLst, - const List<surfZone>& zoneLst + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf ) { + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst) + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::VTKsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + writeHeader(os, pointLst); writeHeaderPolygons(os, faceLst); label faceIndex = 0; - forAll(zoneLst, zoneI) + forAll(zones, zoneI) { - forAll(zoneLst[zoneI], localFaceI) - { - const Face& f = faceLst[faceIndex++]; + const surfZone& zone = zones[zoneI]; - os << f.size(); - forAll(f, fp) + if (useFaceMap) + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; + + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + os << ' ' << nl; + } + } + else + { + forAll(zone, localFaceI) { - os << ' ' << f[fp]; + const Face& f = faceLst[faceIndex++]; + + os << f.size(); + forAll(f, fp) + { + os << ' ' << f[fp]; + } + os << ' ' << nl; } - os << ' ' << nl; } } - writeTail(os, zoneLst); + writeTail(os, zones); } template<class Face> void Foam::fileFormats::VTKsurfaceFormat<Face>::write ( - Ostream& os, - const MeshedSurface<Face>& surf + const fileName& filename, + const UnsortedMeshedSurface<Face>& surf ) { - write(os, surf.points(), surf.faces(), surf.zones()); -} + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::VTKsurfaceFormat::write" + "(const fileName&, const UnsortedMeshedSurface<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } -template<class Face> -void Foam::fileFormats::VTKsurfaceFormat<Face>::write -( - Ostream& os, - const UnsortedMeshedSurface<Face>& surf -) -{ const List<Face>& faceLst = surf.faces(); writeHeader(os, surf.points()); diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H index 22dc33ebc15ac8e4caa5015d0b63350495c85505..93e3510ca1c286219e8b8e444ced4e20f48b2941 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.H @@ -37,9 +37,8 @@ SourceFiles #ifndef VTKsurfaceFormat_H #define VTKsurfaceFormat_H -#include "Ostream.H" -#include "OFstream.H" #include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" #include "UnsortedMeshedSurface.H" #include "VTKsurfaceFormatCore.H" @@ -89,55 +88,17 @@ public: // Write - //- Write surface mesh components - static void write - ( - Ostream&, - const pointField&, - const List<Face>&, - const List<surfZone>& - ); - - //- Write MeshedSurface - static void write - ( - Ostream&, - const MeshedSurface<Face>& - ); - - //- Write MeshedSurface - static void write - ( - const fileName& name, - const MeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + + //- Write UnsortedMeshedSurface, the output remains unsorted + static void write(const fileName&, const UnsortedMeshedSurface<Face>&); - //- Write UnsortedMeshedSurface - // The output remains unsorted - static void write - ( - Ostream&, - const UnsortedMeshedSurface<Face>& - ); - - //- Write UnsortedMeshedSurface - // The output remains unsorted - static void write - ( - const fileName& name, - const UnsortedMeshedSurface<Face>& surf - ) - { - write(OFstream(name)(), surf); - } //- Write object virtual void write(Ostream& os) const { - write(os, *this); + write(os, MeshedSurfaceProxy<Face>(*this)); } }; diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C index fefb0de03c99719d1560effe20bd0ac8653a5ca7..c4059632f1832edd994f05e9a4d94bd7e126fe35 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C @@ -48,9 +48,9 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader os << "POINTS " << pointLst.size() << " float" << nl; forAll(pointLst, ptI) { - os << pointLst[ptI].x() << ' ' - << pointLst[ptI].y() << ' ' - << pointLst[ptI].z() << nl; + const point& pt = pointLst[ptI]; + + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; } } diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H index 5165dfea127fef49dd50541766e1cfcddd3f822c..d0f6ed1de587750a17c40b033ced59e5e08a3c72 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.H @@ -39,7 +39,6 @@ SourceFiles #include "Ostream.H" #include "OFstream.H" #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C index 5d6877c7fd3ea0cd672d0f56ab354f153e4810ec..bd300b84f728f4d03a9b0ddca44a014800d7b66c 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C @@ -25,8 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "VTKsurfaceFormat.H" -#include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" + #include "addToRunTimeSelectionTable.H" #include "addToMemberFunctionSelectionTable.H" @@ -36,9 +35,10 @@ namespace Foam namespace fileFormats { +// write MeshedSurfaceProxy addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, VTKsurfaceFormat, face, write, @@ -47,7 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable ); addNamedTemplatedToMemberFunctionSelectionTable ( - MeshedSurface, + MeshedSurfaceProxy, VTKsurfaceFormat, triFace, write, @@ -55,6 +55,7 @@ addNamedTemplatedToMemberFunctionSelectionTable vtk ); +// write UnsortedMeshedSurface addNamedTemplatedToMemberFunctionSelectionTable ( UnsortedMeshedSurface, diff --git a/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.C b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.C new file mode 100644 index 0000000000000000000000000000000000000000..c17280689e1d6e74d4beea8a6a4c1da8c52b0999 --- /dev/null +++ b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.C @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "WRLsurfaceFormat.H" + +#include "Ostream.H" +#include "OFstream.H" +#include "ListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Face> +Foam::fileFormats::WRLsurfaceFormat<Face>::WRLsurfaceFormat() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Face> +void Foam::fileFormats::WRLsurfaceFormat<Face>::write +( + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf +) +{ + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + // for no zones, suppress the group name + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst, "") + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::WRLsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + writeHeader(os, pointLst, faceLst.size(), zones); + + os << "\n" + "Group {\n" + " children [\n" + " Shape {\n"; + + writeAppearance(os); + + os << + " geometry IndexedFaceSet {\n" + " coord Coordinate {\n" + " point [\n"; + + // Write vertex coords + forAll(pointLst, ptI) + { + const point& pt = pointLst[ptI]; + + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; + } + + os << + " ]\n" // end point + " }\n" // end coord Coordinate + " coordIndex [\n"; + + label faceIndex = 0; + forAll(zones, zoneI) + { + const surfZone& zone = zones[zoneI]; + + if (useFaceMap) + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; + + forAll(f, fp) + { + os << f[fp] << ' '; + } + os << "-1,\n"; + } + } + else + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceIndex++]; + + forAll(f, fp) + { + os << ' ' << f[fp]; + } + os << " -1,\n"; + } + } + } + + os << + " ]\n" // end coordIndex + " }\n" // end geometry IndexedFaceSet + " }\n" // end Shape + " ]\n" // end children + "}\n"; // end Group + +} + + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.H b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.H new file mode 100644 index 0000000000000000000000000000000000000000..d89613d7b68c2ae8c6cba2de439f0a67b6f6b501 --- /dev/null +++ b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormat.H @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::fileFormats::WRLsurfaceFormat + +Description + Provide a means of writing VRML97 (wrl) format. + +SourceFiles + WRLsurfaceFormat.C + +\*---------------------------------------------------------------------------*/ + +#ifndef WRLsurfaceFormat_H +#define WRLsurfaceFormat_H + +#include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" +#include "UnsortedMeshedSurface.H" +#include "WRLsurfaceFormatCore.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fileFormats +{ + +/*---------------------------------------------------------------------------*\ + Class WRLsurfaceFormat Declaration +\*---------------------------------------------------------------------------*/ + +template<class Face> +class WRLsurfaceFormat +: + public MeshedSurface<Face>, + public WRLsurfaceFormatCore + +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + WRLsurfaceFormat(const WRLsurfaceFormat<Face>&); + + //- Disallow default bitwise assignment + void operator=(const WRLsurfaceFormat<Face>&); + +public: + + // Constructors + + //- Construct null + WRLsurfaceFormat(); + + // Selectors + + + // Destructor + + virtual ~WRLsurfaceFormat() + {} + + + // Member Functions + + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + + //- Write object file + virtual void write(const fileName& name) const + { + write(name, MeshedSurfaceProxy<Face>(*this)); + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fileFormats +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "WRLsurfaceFormat.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.C similarity index 74% rename from src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C rename to src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.C index c6062d54feeba1ce4caf00eee658a123966182fd..b5eb87058ad360afffc370ea765686a1c0b42e25 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.C @@ -24,24 +24,24 @@ License \*---------------------------------------------------------------------------*/ -#include "OBJsurfaceFormatCore.H" +#include "WRLsurfaceFormatCore.H" #include "clock.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::fileFormats::OBJsurfaceFormatCore::writeHeader +void Foam::fileFormats::WRLsurfaceFormatCore::writeHeader ( Ostream& os, const pointField& pointLst, const label nFaces, - const UList<surfZone>& zoneLst + const UList<surfZone>& zoneLst ) { - os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl - << "o " << os.name().lessExt().name() << nl + os << "#VRML V2.0 utf8" << nl << nl + << "# written " << clock::dateTime().c_str() << nl << "# points : " << pointLst.size() << nl << "# faces : " << nFaces << nl << "# zones : " << zoneLst.size() << nl; @@ -53,22 +53,28 @@ void Foam::fileFormats::OBJsurfaceFormatCore::writeHeader << " (nFaces: " << zoneLst[zoneI].size() << ")" << nl; } - os << nl - << "# <points count=\"" << pointLst.size() << "\">" << endl; - // Write vertex coords - forAll(pointLst, ptI) - { - os << "v " << pointLst[ptI].x() - << ' ' << pointLst[ptI].y() - << ' ' << pointLst[ptI].z() << nl; - } +} + + +void Foam::fileFormats::WRLsurfaceFormatCore::writeAppearance +( + Ostream& os +) +{ + os << + " appearance Appearance {\n" + " material Material {\n" + " diffuseColor 0.8 0.8 0.8\n" + " specularColor 1.0 1.0 1.0\n" + " shininess 0.5\n" + " transparency 0.0\n" + " }\n" // end material + " }\n"; // end appearance - os << "# </points>" << nl - << nl - << "# <faces count=\"" << nFaces << "\">" << endl; } + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.H similarity index 85% rename from src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H rename to src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.H index e72bc82ee7e13e1aa916385eb54a72bb9d246008..a291ff77809dd38dcbb2cbc6ed543ceceb083e95 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatCore.H @@ -23,23 +23,22 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::fileFormats::OFFsurfaceFormatCore + Foam::fileFormats::WRLsurfaceFormatCore Description - Internal class used by the OFFsurfaceFormat + Internal class used by the WRLsurfaceFormat SourceFiles - OFFsurfaceFormatCore.C + WRLsurfaceFormatCore.C \*---------------------------------------------------------------------------*/ -#ifndef OFFsurfaceFormatCore_H -#define OFFsurfaceFormatCore_H +#ifndef WRLsurfaceFormatCore_H +#define WRLsurfaceFormatCore_H #include "Ostream.H" #include "OFstream.H" #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,15 +48,15 @@ namespace fileFormats { /*---------------------------------------------------------------------------*\ - Class OFFsurfaceFormatCore Declaration + Class WRLsurfaceFormatCore Declaration \*---------------------------------------------------------------------------*/ -class OFFsurfaceFormatCore +class WRLsurfaceFormatCore { protected: // Protected Member Functions - //- Write header information with points + //- Write file header static void writeHeader ( Ostream&, @@ -66,6 +65,10 @@ protected: const UList<surfZone>& ); + + //- Write appearance node + static void writeAppearance(Ostream&); + }; diff --git a/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatRunTime.C new file mode 100644 index 0000000000000000000000000000000000000000..f621be7a98ad2537f0f07a34af74fe1789af2e7c --- /dev/null +++ b/src/surfMesh/surfaceFormats/wrl/WRLsurfaceFormatRunTime.C @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "WRLsurfaceFormat.H" + +#include "addToRunTimeSelectionTable.H" +#include "addToMemberFunctionSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +namespace Foam +{ +namespace fileFormats +{ + +// write MeshedSurfaceProxy +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + WRLsurfaceFormat, + face, + write, + fileExtension, + wrl +); +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + WRLsurfaceFormat, + triFace, + write, + fileExtension, + wrl +); + +} +} + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C new file mode 100644 index 0000000000000000000000000000000000000000..f2e5afbcb83ace4802cb9e7f8fc72a8e4a67ca61 --- /dev/null +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C @@ -0,0 +1,149 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "X3DsurfaceFormat.H" +#include "clock.H" +#include "IFstream.H" +#include "IStringStream.H" +#include "Ostream.H" +#include "OFstream.H" +#include "ListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Face> +Foam::fileFormats::X3DsurfaceFormat<Face>::X3DsurfaceFormat() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Face> +void Foam::fileFormats::X3DsurfaceFormat<Face>::write +( + const fileName& filename, + const MeshedSurfaceProxy<Face>& surf +) +{ + const pointField& pointLst = surf.points(); + const List<Face>& faceLst = surf.faces(); + const List<label>& faceMap = surf.faceMap(); + + // for no zones, suppress the group name + const List<surfZone>& zones = + ( + surf.surfZones().size() > 1 + ? surf.surfZones() + : oneZone(faceLst, "") + ); + + const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); + + OFstream os(filename); + if (!os.good()) + { + FatalErrorIn + ( + "fileFormats::X3DsurfaceFormat::write" + "(const fileName&, const MeshedSurfaceProxy<Face>&)" + ) + << "Cannot open file for writing " << filename + << exit(FatalError); + } + + writeHeader(os); + + os << "\n" + "<Group>\n" + " <Shape>\n"; + + writeAppearance(os); + + + // NOTE: we could provide an optimized IndexedTriangleSet output for + // triangulated surfaces too + + os << + " <IndexedFaceSet coordIndex='\n"; + + label faceIndex = 0; + forAll(zones, zoneI) + { + const surfZone& zone = zones[zoneI]; + + if (useFaceMap) + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceMap[faceIndex++]]; + + forAll(f, fp) + { + os << f[fp] << ' '; + } + os << "-1\n"; + } + } + else + { + forAll(zone, localFaceI) + { + const Face& f = faceLst[faceIndex++]; + + forAll(f, fp) + { + os << f[fp] << ' '; + } + os << "-1\n"; + } + } + } + + os << + "' >\n" + " <Coordinate point='\n"; + + // Write vertex coords + forAll(pointLst, ptI) + { + const point& pt = pointLst[ptI]; + + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; + } + + os << + "' />\n" // end Coordinate + " </IndexedFaceSet>\n" + " </Shape>\n" + " </Group>\n" + "</X3D>\n"; + +} + + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.H b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.H new file mode 100644 index 0000000000000000000000000000000000000000..130bb226c8b53a1295972f20cd7b294c01a8a77a --- /dev/null +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::fileFormats::X3DsurfaceFormat + +Description + Provide a means of writing x3d format. + +SourceFiles + X3DsurfaceFormat.C + +\*---------------------------------------------------------------------------*/ + +#ifndef X3DsurfaceFormat_H +#define X3DsurfaceFormat_H + +#include "MeshedSurface.H" +#include "MeshedSurfaceProxy.H" +#include "UnsortedMeshedSurface.H" +#include "X3DsurfaceFormatCore.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fileFormats +{ + +/*---------------------------------------------------------------------------*\ + Class X3DsurfaceFormat Declaration +\*---------------------------------------------------------------------------*/ + +template<class Face> +class X3DsurfaceFormat +: + public MeshedSurface<Face>, + public X3DsurfaceFormatCore +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + X3DsurfaceFormat(const X3DsurfaceFormat<Face>&); + + //- Disallow default bitwise assignment + void operator=(const X3DsurfaceFormat<Face>&); + +public: + + // Constructors + + //- Construct null + X3DsurfaceFormat(); + + // Selectors + + + // Destructor + + virtual ~X3DsurfaceFormat() + {} + + + // Member Functions + + //- Write surface mesh components by proxy + static void write(const fileName&, const MeshedSurfaceProxy<Face>&); + + //- Write object file + virtual void write(const fileName& name) const + { + write(name, MeshedSurfaceProxy<Face>(*this)); + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fileFormats +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "X3DsurfaceFormat.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.C new file mode 100644 index 0000000000000000000000000000000000000000..104fb8e5f72967a74782cc9c8148d52f786f307b --- /dev/null +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.C @@ -0,0 +1,70 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "X3DsurfaceFormatCore.H" +#include "clock.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::fileFormats::X3DsurfaceFormatCore::writeHeader +( + Ostream& os +) +{ + os << + "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.0//EN\" \"http://www.web3d.org/specifications/x3d-3.0.dtd\">\n" + "<X3D\n" + " version='3.0'\n" + " profile='Immersive'\n" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance'\n" + " xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.0.xsd'\n" + " >\n"; +} + + +void Foam::fileFormats::X3DsurfaceFormatCore::writeAppearance +( + Ostream& os +) +{ + os << + " <Appearance>\n" + " <Material" + " diffuseColor='0.8 0.8 0.8'" + " specularColor='1.0 1.0 1.0'" + " shininess='0.5'" + " transparency='0.0'" + " />\n" // end material + " </Appearance>\n"; +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H similarity index 78% rename from src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H rename to src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H index a50f2a50d75d9568c5ec55270b3e50feb419ce67..16b0b02b9b980a9c2ff7056f9e1f032657de2ad2 100644 --- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormatCore.H +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatCore.H @@ -23,22 +23,22 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::fileFormats::SMESHsurfaceFormatCore + Foam::fileFormats::X3DsurfaceFormatCore Description - Internal class used by the SMESHsurfaceFormat + Internal class used by the X3DsurfaceFormat SourceFiles - SMESHsurfaceFormatCore.C + X3DsurfaceFormatCore.C \*---------------------------------------------------------------------------*/ -#ifndef SMESHsurfaceFormatCore_H -#define SMESHsurfaceFormatCore_H +#ifndef X3DsurfaceFormatCore_H +#define X3DsurfaceFormatCore_H #include "Ostream.H" +#include "OFstream.H" #include "MeshedSurface.H" -#include "UnsortedMeshedSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -48,24 +48,19 @@ namespace fileFormats { /*---------------------------------------------------------------------------*\ - Class SMESHsurfaceFormatCore Declaration + Class X3DsurfaceFormatCore Declaration \*---------------------------------------------------------------------------*/ -class SMESHsurfaceFormatCore +class X3DsurfaceFormatCore { protected: // Protected Member Functions - //- Write header information with points - static void writeHeader - ( - Ostream&, - const pointField&, - const label nFaces - ); + //- Write file header + static void writeHeader(Ostream&); - //- Write tail information - static void writeTail(Ostream&); + //- Write appearance node + static void writeAppearance(Ostream&); }; diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatRunTime.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatRunTime.C new file mode 100644 index 0000000000000000000000000000000000000000..6a17897ba708e98c43f4b26929ef36e8b00cf9ca --- /dev/null +++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormatRunTime.C @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "X3DsurfaceFormat.H" + +#include "addToRunTimeSelectionTable.H" +#include "addToMemberFunctionSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +namespace Foam +{ +namespace fileFormats +{ + +// write MeshedSurfaceProxy +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + X3DsurfaceFormat, + face, + write, + fileExtension, + x3d +); +addNamedTemplatedToMemberFunctionSelectionTable +( + MeshedSurfaceProxy, + X3DsurfaceFormat, + triFace, + write, + fileExtension, + x3d +); + +} +} + +// ************************************************************************* // diff --git a/src/surfMesh/surfaceRegistry/surfaceRegistry.C b/src/surfMesh/surfaceRegistry/surfaceRegistry.C index 335acfff0d8854299ce7a6e6ceb4ed49afa98ed4..ed0460cdf07e38d0cb1e32f256879d074dd6139c 100644 --- a/src/surfMesh/surfaceRegistry/surfaceRegistry.C +++ b/src/surfMesh/surfaceRegistry/surfaceRegistry.C @@ -31,7 +31,7 @@ License defineTypeNameAndDebug(Foam::surfaceRegistry, 0); -const Foam::word Foam::surfaceRegistry::subInstance("surfaces"); +const Foam::word Foam::surfaceRegistry::prefix("surfaces"); Foam::word Foam::surfaceRegistry::defaultName("default"); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -48,7 +48,7 @@ Foam::surfaceRegistry::surfaceRegistry ( ( surfName.size() ? surfName : defaultName ), obr.time().timeName(), - subInstance, + prefix, obr, IOobject::NO_READ, IOobject::NO_WRITE diff --git a/src/surfMesh/surfaceRegistry/surfaceRegistry.H b/src/surfMesh/surfaceRegistry/surfaceRegistry.H index fa4bad64eacc187a897479a184c0284d716bf34f..11e02255061986d1fb1aec3584422bb081bb6837 100644 --- a/src/surfMesh/surfaceRegistry/surfaceRegistry.H +++ b/src/surfMesh/surfaceRegistry/surfaceRegistry.H @@ -66,8 +66,8 @@ public: //- Runtime type information TypeName("surfaceRegistry"); - //- The subInstance (local) to prefix: %surfaces - static const word subInstance; + //- The prefix to local: %surfaces + static const word prefix; //- The default surface name: %default static word defaultName; diff --git a/src/thermophysicalModels/basic/basicThermo/makeBasicThermo.H b/src/thermophysicalModels/basic/basicThermo/makeBasicThermo.H index 00df45971cc91fc4d4811e034adcb6869d52c201..59165247a470305374d758aee6475680bf4cc9b5 100644 --- a/src/thermophysicalModels/basic/basicThermo/makeBasicThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/makeBasicThermo.H @@ -44,7 +44,7 @@ typedef Cthermo<Mixture<Transport<specieThermo<Thermo<EqnOfState> > > > > \ defineTemplateTypeNameAndDebugWithName \ (Cthermo##Mixture##Transport##Thermo##EqnOfState, \ #Cthermo \ - "<"#Mixture"<"#Transport"<specieThermo<"#Thermo"<"#EqnOfState">>>>>", 0) \ + "<"#Mixture"<"#Transport"<specieThermo<"#Thermo"<"#EqnOfState">>>>>", 0); \ \ addToRunTimeSelectionTable \ ( \ diff --git a/src/thermophysicalModels/combustion/hCombustionThermo/hCombustionThermos.C b/src/thermophysicalModels/combustion/hCombustionThermo/hCombustionThermos.C index 40ad4cc650aa82d5e6d368e3b0bf0697b4b98c67..fbfa73c85626e09068c819b01f2c6852bec099d0 100644 --- a/src/thermophysicalModels/combustion/hCombustionThermo/hCombustionThermos.C +++ b/src/thermophysicalModels/combustion/hCombustionThermo/hCombustionThermos.C @@ -138,7 +138,7 @@ makeCombustionThermo // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Reaction thermo -defineTemplateTypeNameAndDebug(hMixtureThermo<reactingMixture>, 0) +defineTemplateTypeNameAndDebug(hMixtureThermo<reactingMixture>, 0); typedef hMixtureThermo<reactingMixture> hMixtureThermoReactingMixture; diff --git a/src/thermophysicalModels/combustion/hCombustionThermo/makeCombustionThermo.H b/src/thermophysicalModels/combustion/hCombustionThermo/makeCombustionThermo.H index 9c31f3240fe43418eb702b420a3d26d4c7db0cc3..f961d0ca0c532d035828d8dc2cd6183755392fa0 100644 --- a/src/thermophysicalModels/combustion/hCombustionThermo/makeCombustionThermo.H +++ b/src/thermophysicalModels/combustion/hCombustionThermo/makeCombustionThermo.H @@ -43,7 +43,7 @@ typedef MixtureThermo \ defineTemplateTypeNameAndDebugWithName \ (MixtureThermo##Mixture##Transport##Thermo##EqnOfState, \ #MixtureThermo \ - "<"#Mixture"<"#Transport"<specieThermo<"#Thermo"<"#EqnOfState">>>>>", 0) \ + "<"#Mixture"<"#Transport"<specieThermo<"#Thermo"<"#EqnOfState">>>>>", 0); \ \ addToRunTimeSelectionTable \ ( \ diff --git a/src/thermophysicalModels/laminarFlameSpeed/Gulders/Gulders.C b/src/thermophysicalModels/laminarFlameSpeed/Gulders/Gulders.C index 27443c98ee25f463e6efab5ca2386bad154729de..7655455a739a3add7461e70dad05b6d0ac112313 100644 --- a/src/thermophysicalModels/laminarFlameSpeed/Gulders/Gulders.C +++ b/src/thermophysicalModels/laminarFlameSpeed/Gulders/Gulders.C @@ -218,7 +218,7 @@ Foam::laminarFlameSpeedModels::Gulders::operator()() const dimensionedScalar ( hhuCombustionThermo_.lookup("stoichiometricAirFuelMassRatio") - )*ft/(scalar(1) - ft) + )*ft/((1 + SMALL) - ft) ); } else diff --git a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H index cac45b19edd723df7ccc3e72f2de457e84109412..43ea40834915278bfbbd973f5cf46235f0f1e89c 100644 --- a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H +++ b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H @@ -167,7 +167,7 @@ public: ) const; - //- Calculate the mean molecular weigth [kg/kmol] + //- Calculate the mean molecular weight [kg/kmol] // from mole fractions scalar W(const scalarField& x) const; diff --git a/src/thermophysicalModels/radiation/Make/files b/src/thermophysicalModels/radiation/Make/files index 9b385e8a5675a2cb704020f20a6d9649f1a840e8..4e7fb1b11cbaab0879b316bb76a2bde95eb4fa0d 100644 --- a/src/thermophysicalModels/radiation/Make/files +++ b/src/thermophysicalModels/radiation/Make/files @@ -1,13 +1,15 @@ /* Radiation constants */ radiationConstants/radiationConstants.C - /* Radiation model */ radiationModel/radiationModel/radiationModel.C radiationModel/radiationModel/newRadiationModel.C radiationModel/noRadiation/noRadiation.C radiationModel/P1/P1.C - +radiationModel/fvDOM/fvDOM/fvDOM.C +radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.C +radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.C +radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.C /* Scatter model */ submodels/scatterModel/scatterModel/scatterModel.C @@ -21,11 +23,14 @@ submodels/absorptionEmissionModel/absorptionEmissionModel/newAbsorptionEmissionM submodels/absorptionEmissionModel/noAbsorptionEmission/noAbsorptionEmission.C submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.C submodels/absorptionEmissionModel/binaryAbsorptionEmission/binaryAbsorptionEmission.C +submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.C +submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C /* Boundary conditions */ derivedFvPatchFields/MarshakRadiation/MarshakRadiationMixedFvPatchScalarField.C derivedFvPatchFields/MarshakRadiationFixedT/MarshakRadiationFixedTMixedFvPatchScalarField.C - +derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.C +derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.C LIB = $(FOAM_LIBBIN)/libradiation diff --git a/src/thermophysicalModels/radiation/Make/options b/src/thermophysicalModels/radiation/Make/options index 31643f8150d84cd09d3ad0af0b22eb84303a4ba8..98956f2b6dbcf83ff7d0dcd2b20a2c9783c225af 100644 --- a/src/thermophysicalModels/radiation/Make/options +++ b/src/thermophysicalModels/radiation/Make/options @@ -1,6 +1,9 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/combustion/lnInclude \ + -I$(LIB_SRC)/OpenFOAM/lnInclude \ + -I radiationModel/fvDOM/interpolationLookUpTable LIB_LIBS = \ -lfiniteVolume diff --git a/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.C b/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.C new file mode 100644 index 0000000000000000000000000000000000000000..567eff9dafc283e9f8d44f86aee7fd4d19bb0de8 --- /dev/null +++ b/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.C @@ -0,0 +1,247 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "greyDiffusiveRadiationMixedFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" + +#include "fvDOM.H" +#include "radiationConstants.H" +#include "mathematicalConstants.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +greyDiffusiveRadiationMixedFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(p, iF), + TName_("undefinedT"), + emissivity_(0.0) +{ + refValue() = 0.0; + refGrad() = 0.0; + valueFraction() = 1.0; +} + + +Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +greyDiffusiveRadiationMixedFvPatchScalarField +( + const greyDiffusiveRadiationMixedFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const fvPatchFieldMapper& mapper +) +: + mixedFvPatchScalarField(ptf, p, iF, mapper), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +greyDiffusiveRadiationMixedFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const dictionary& dict +) +: + mixedFvPatchScalarField(p, iF), + TName_(dict.lookup("T")), + emissivity_(readScalar(dict.lookup("emissivity"))) +{ + const scalarField& Tp = + patch().lookupPatchField<volScalarField, scalar>(TName_); + + refValue() = + emissivity_*4.0*radiation::sigmaSB.value()*pow4(Tp) + /Foam::mathematicalConstant::pi; + + refGrad() = 0.0; + + if (dict.found("value")) + { + fvPatchScalarField::operator= + ( + scalarField("value", dict, p.size()) + ); + } + else + { + fvPatchScalarField::operator=(refValue()); + } +} + + +Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +greyDiffusiveRadiationMixedFvPatchScalarField +( + const greyDiffusiveRadiationMixedFvPatchScalarField& ptf +) +: + mixedFvPatchScalarField(ptf), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +greyDiffusiveRadiationMixedFvPatchScalarField +( + const greyDiffusiveRadiationMixedFvPatchScalarField& ptf, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(ptf, iF), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField:: +updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const scalarField& Tp = + patch().lookupPatchField<volScalarField, scalar>(TName_); + + const radiationModel& radiation = + db().lookupObject<radiationModel>("radiationProperties"); + + const fvDOM& dom(refCast<const fvDOM>(radiation)); + + label rayId = -1; + label lambdaId = -1; + dom.setRayIdLambdaId(dimensionedInternalField().name(), rayId, lambdaId); + + const label patchI = patch().index(); + + if (dom.nLambda() != 1) + { + FatalErrorIn + ( + "Foam::radiation::" + "greyDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs" + ) << " a grey boundary condition is used with a non-grey " + << "absorption model" << nl << exit(FatalError); + } + + scalarField& Iw = *this; + vectorField n = patch().Sf()/patch().magSf(); + + radiativeIntensityRay& ray = + const_cast<radiativeIntensityRay&>(dom.IRay(rayId)); + + ray.Qr().boundaryField()[patchI] += Iw*(-n & ray.dAve()); + + forAll(Iw, faceI) + { + scalar Ir = 0.0; + + for (label rayI=0; rayI < dom.nRay(); rayI++) + { + const vector& d = dom.IRay(rayI).d(); + + const scalarField& IFace = + dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI]; + + if ((-n[faceI] & d) < 0.0) + { + // q into the wall + const vector& dAve = dom.IRay(rayI).dAve(); + Ir += IFace[faceI]*mag(n[faceI] & dAve); + } + } + + const vector& d = dom.IRay(rayId).d(); + + if ((-n[faceI] & d) > 0.0) + { + // direction out of the wall + refGrad()[faceI] = 0.0; + valueFraction()[faceI] = 1.0; + refValue()[faceI] = + ( + Ir*(1.0 - emissivity_) + + emissivity_*radiation::sigmaSB.value()*pow4(Tp[faceI]) + ) + /mathematicalConstant::pi; + + } + else + { + // direction into the wall + valueFraction()[faceI] = 0.0; + refGrad()[faceI] = 0.0; + refValue()[faceI] = 0.0; //not used + } + } + + mixedFvPatchScalarField::updateCoeffs(); +} + + +void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::write +( + Ostream& os +) const +{ + fvPatchScalarField::write(os); + os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl; + os.writeKeyword("emissivity") << emissivity_ << token::END_STATEMENT << nl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + makePatchTypeField + ( + fvPatchScalarField, + greyDiffusiveRadiationMixedFvPatchScalarField + ); +} +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.H b/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.H new file mode 100644 index 0000000000000000000000000000000000000000..005fe768652354f712917046ac6cdc302a0aeec5 --- /dev/null +++ b/src/thermophysicalModels/radiation/derivedFvPatchFields/greyDiffusiveRadiation/greyDiffusiveRadiationMixedFvPatchScalarField.H @@ -0,0 +1,184 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::greyDiffusiveRadiationMixedFvPatchScalarField + +Description + Radiation temperature specified + +SourceFiles + greyDiffusiveRadiationMixedFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef greyDiffusiveRadiationMixedFvPatchScalarField_H +#define greyDiffusiveRadiationMixedFvPatchScalarField_H + +#include "mixedFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ +/*---------------------------------------------------------------------------*\ + Class greyDiffusiveRadiationMixedFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class greyDiffusiveRadiationMixedFvPatchScalarField +: + public mixedFvPatchScalarField +{ + // Private data + + //- Name of temperature field + word TName_; + + //- Emissivity + scalar emissivity_; + + +public: + + //- Runtime type information + TypeName("greyDiffusiveRadiation"); + + + // Constructors + + //- Construct from patch and internal field + greyDiffusiveRadiationMixedFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct from patch, internal field and dictionary + greyDiffusiveRadiationMixedFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const dictionary& + ); + + //- Construct by mapping given a + // greyDiffusiveRadiationMixedFvPatchScalarField onto a new patch + greyDiffusiveRadiationMixedFvPatchScalarField + ( + const greyDiffusiveRadiationMixedFvPatchScalarField&, + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + greyDiffusiveRadiationMixedFvPatchScalarField + ( + const greyDiffusiveRadiationMixedFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp<fvPatchScalarField> clone() const + { + return tmp<fvPatchScalarField> + ( + new greyDiffusiveRadiationMixedFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + greyDiffusiveRadiationMixedFvPatchScalarField + ( + const greyDiffusiveRadiationMixedFvPatchScalarField&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp<fvPatchScalarField> clone + ( + const DimensionedField<scalar, volMesh>& iF + ) const + { + return tmp<fvPatchScalarField> + ( + new greyDiffusiveRadiationMixedFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Return the temperature field name + const word& TName() const + { + return TName_; + } + + //- Return reference to the temperature field name to allow + // adjustment + word& TName() + { + return TName_; + } + + //- Return the emissivity + const scalar& emissivity() const + { + return emissivity_; + } + + //- Return reference to the emissivity to allow adjustment + scalar& emissivity() + { + return emissivity_; + } + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + // I-O + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.C b/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.C new file mode 100644 index 0000000000000000000000000000000000000000..b3669bd6fa45708e430c6cea388bf13254f1c8a3 --- /dev/null +++ b/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.C @@ -0,0 +1,243 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "wideBandDiffusiveRadiationMixedFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" + +#include "fvDOM.H" +#include "wideBandAbsorptionEmission.H" +#include "radiationConstants.H" +#include "mathematicalConstants.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +wideBandDiffusiveRadiationMixedFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(p, iF), + TName_("undefinedT"), + emissivity_(0.0) +{ + refValue() = 0.0; + refGrad() = 0.0; + valueFraction() = 1.0; +} + + +Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +wideBandDiffusiveRadiationMixedFvPatchScalarField +( + const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const fvPatchFieldMapper& mapper +) +: + mixedFvPatchScalarField(ptf, p, iF, mapper), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +wideBandDiffusiveRadiationMixedFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const dictionary& dict +) +: + mixedFvPatchScalarField(p, iF), + TName_(dict.lookup("T")), + emissivity_(readScalar(dict.lookup("emissivity"))) +{ + const scalarField& Tp = + patch().lookupPatchField<volScalarField, scalar>(TName_); + + refValue() = + emissivity_*4.0*radiation::sigmaSB.value()*pow4(Tp) + /Foam::mathematicalConstant::pi; + refGrad() = 0.0; + + if (dict.found("value")) + { + fvPatchScalarField::operator= + ( + scalarField("value", dict, p.size()) + ); + } + else + { + fvPatchScalarField::operator=(refValue()); + } +} + + +Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +wideBandDiffusiveRadiationMixedFvPatchScalarField +( + const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf +) +: + mixedFvPatchScalarField(ptf), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +wideBandDiffusiveRadiationMixedFvPatchScalarField +( + const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(ptf, iF), + TName_(ptf.TName_), + emissivity_(ptf.emissivity_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField:: +updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const radiationModel& radiation = + db().lookupObject<radiationModel>("radiationProperties"); + + const fvDOM& dom(refCast<const fvDOM>(radiation)); + + label rayId = -1; + label lambdaId = -1; + dom.setRayIdLambdaId(dimensionedInternalField().name(), rayId, lambdaId); + + const label patchI = patch().index(); + + if (dom.nLambda() == 0) + { + FatalErrorIn + ( + "Foam::radiation::" + "wideBandDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs" + ) << " a non-grey boundary condition is used with a grey " + << "absorption model" << nl << exit(FatalError); + } + + scalarField& Iw = *this; + vectorField n = patch().Sf()/patch().magSf(); + + radiativeIntensityRay& ray = + const_cast<radiativeIntensityRay&>(dom.IRay(rayId)); + + ray.Qr().boundaryField()[patchI] += Iw*(-n & ray.dAve()); + + const scalarField Eb = + dom.blackBody().bLambda(lambdaId).boundaryField()[patchI]; + + forAll(Iw, faceI) + { + scalar Ir = 0.0; + for (label rayI=0; rayI < dom.nRay(); rayI++) + { + const vector& d = dom.IRay(rayI).d(); + + const scalarField& IFace = + dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI]; + + if ((-n[faceI] & d) < 0.0) // qin into the wall + { + const vector& dAve = dom.IRay(rayI).dAve(); + Ir = Ir + IFace[faceI]*mag(n[faceI] & dAve); + } + } + + const vector& d = dom.IRay(rayId).d(); + + if ((-n[faceI] & d) > 0.0) + { + // direction out of the wall + refGrad()[faceI] = 0.0; + valueFraction()[faceI] = 1.0; + refValue()[faceI] = + ( + Ir*(1.0 - emissivity_) + + emissivity_*Eb[faceI] + ) + /mathematicalConstant::pi; + } + else + { + // direction into the wall + valueFraction()[faceI] = 0.0; + refGrad()[faceI] = 0.0; + refValue()[faceI] = 0.0; //not used + } + } + + mixedFvPatchScalarField::updateCoeffs(); +} + + +void Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::write +( + Ostream& os +) const +{ + fvPatchScalarField::write(os); + os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl; + os.writeKeyword("emissivity") << emissivity_ << token::END_STATEMENT << nl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + makePatchTypeField + ( + fvPatchScalarField, + wideBandDiffusiveRadiationMixedFvPatchScalarField + ); +} +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.H b/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.H new file mode 100644 index 0000000000000000000000000000000000000000..9d170131b273ef0843fa59f291551c92b66b5662 --- /dev/null +++ b/src/thermophysicalModels/radiation/derivedFvPatchFields/wideBandDiffusiveRadiation/wideBandDiffusiveRadiationMixedFvPatchScalarField.H @@ -0,0 +1,184 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::wideBandDiffusiveRadiationMixedFvPatchScalarField + +Description + Radiation temperature specified + +SourceFiles + wideBandDiffusiveRadiationMixedFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef wideBandDiffusiveRadiationMixedFvPatchScalarField_H +#define wideBandDiffusiveRadiationMixedFvPatchScalarField_H + +#include "mixedFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ +/*---------------------------------------------------------------------------*\ + Class wideBandDiffusiveRadiationMixedFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class wideBandDiffusiveRadiationMixedFvPatchScalarField +: + public mixedFvPatchScalarField +{ + // Private data + + //- Name of temperature field + word TName_; + + //- Emissivity + scalar emissivity_; + + +public: + + //- Runtime type information + TypeName("wideBandDiffusiveRadiation"); + + + // Constructors + + //- Construct from patch and internal field + wideBandDiffusiveRadiationMixedFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct from patch, internal field and dictionary + wideBandDiffusiveRadiationMixedFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const dictionary& + ); + + //- Construct by mapping given GreyDiffusiveRadiationMixedFvPatchField + // onto a new patch + wideBandDiffusiveRadiationMixedFvPatchScalarField + ( + const wideBandDiffusiveRadiationMixedFvPatchScalarField&, + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + wideBandDiffusiveRadiationMixedFvPatchScalarField + ( + const wideBandDiffusiveRadiationMixedFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp<fvPatchScalarField> clone() const + { + return tmp<fvPatchScalarField> + ( + new wideBandDiffusiveRadiationMixedFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + wideBandDiffusiveRadiationMixedFvPatchScalarField + ( + const wideBandDiffusiveRadiationMixedFvPatchScalarField&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp<fvPatchScalarField> clone + ( + const DimensionedField<scalar, volMesh>& iF + ) const + { + return tmp<fvPatchScalarField> + ( + new wideBandDiffusiveRadiationMixedFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Return the temperature field name + const word& TName() const + { + return TName_; + } + + //- Return reference to the temperature field name to allow + // adjustment + word& TName() + { + return TName_; + } + + //- Return the emissivity + const scalar& emissivity() const + { + return emissivity_; + } + + //- Return reference to the emissivity to allow adjustment + scalar& emissivity() + { + return emissivity_; + } + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + // I-O + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/P1/P1.C b/src/thermophysicalModels/radiation/radiationModel/P1/P1.C index 8679ac2861eafd5ecd7a794a25fea4f6516ed5ce..dee96292927b8c0032fd5ab2400cfb77c1b78611 100644 --- a/src/thermophysicalModels/radiation/radiationModel/P1/P1.C +++ b/src/thermophysicalModels/radiation/radiationModel/P1/P1.C @@ -50,9 +50,9 @@ namespace Foam } } + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct from components Foam::radiation::P1::P1(const volScalarField& T) : radiationModel(typeName, T), @@ -133,12 +133,8 @@ bool Foam::radiation::P1::read() } -void Foam::radiation::P1::correct() +void Foam::radiation::P1::calculate() { - if (!radiation_) - { - return; - } a_ = absorptionEmission_->a(); e_ = absorptionEmission_->e(); E_ = absorptionEmission_->E(); diff --git a/src/thermophysicalModels/radiation/radiationModel/P1/P1.H b/src/thermophysicalModels/radiation/radiationModel/P1/P1.H index 7215664cf7b95e8e3104e68223874011022adb12..c0249e28dbd592828a21fc78e18a2d4a501bd1eb 100644 --- a/src/thermophysicalModels/radiation/radiationModel/P1/P1.H +++ b/src/thermophysicalModels/radiation/radiationModel/P1/P1.H @@ -59,7 +59,6 @@ class P1 : public radiationModel { - // Private data //- Incident radiation / [W/m2] @@ -97,18 +96,17 @@ public: // Destructor - - ~P1(); + virtual ~P1(); // Member functions // Edit - //- Update radiationSource varible - void correct(); + //- Solve radiation equation(s) + void calculate(); - //- Read radiationProperties dictionary + //- Read radiation properties dictionary bool read(); diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.C b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.C new file mode 100644 index 0000000000000000000000000000000000000000..3452797b3eb23f61faf17dc2d07f56be7cf7f820 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.C @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "absorptionCoeffs.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::absorptionCoeffs::absorptionCoeffs(Istream& is) +: + Tcommon_(readScalar(is)), + Tlow_(readScalar(is)), + Thigh_(readScalar(is)), + invTemp_(readBool(is)) +{ + for (label coefLabel=0; absorptionCoeffs::nCoeffs_; coefLabel++) + { + is >> highACoeffs_[coefLabel]; + } + + for (label coefLabel=0; absorptionCoeffs::nCoeffs_; coefLabel++) + { + is >> lowACoeffs_[coefLabel]; + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * // + +Foam::radiation::absorptionCoeffs::~absorptionCoeffs() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::radiation::absorptionCoeffs::checkT(const scalar T) const +{ + if (T < Tlow_ || T > Thigh_) + { + FatalErrorIn + ( + "absorptionCoeffs::checkT(const scalar T) const" + ) << "attempt to use absCoeff out of temperature range:" << nl + << " " << Tlow_ << " -> " << Thigh_ << "; T = " << T + << nl << abort(FatalError); + } +} + + +const Foam::radiation::absorptionCoeffs::coeffArray& +Foam::radiation::absorptionCoeffs::coeffs +( + const scalar T +) const +{ + checkT(T); + + if (T < Tcommon_) + { + return lowACoeffs_; + } + else + { + return highACoeffs_; + } +} + + +void Foam::radiation::absorptionCoeffs::initialise(Istream&) +{ + absorptionCoeffs(Istream); +} + + +void Foam::radiation::absorptionCoeffs::initialise(const dictionary& dict) +{ + dict.lookup("Tcommon") >> Tcommon_; + dict.lookup("Tlow") >> Tlow_; + dict.lookup("Tlow") >> Thigh_; + dict.lookup("invTemp") >> invTemp_; + + dict.lookup("loTcoeffs") >> lowACoeffs_; + dict.lookup("hiTcoeffs") >> highACoeffs_; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.H new file mode 100644 index 0000000000000000000000000000000000000000..1a79e310b908f435d1c23ea41fd2a8355d46bc15 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffs.H @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::janafThermo + +Description + Absorption coefficients class used in greyMeanAbsorptionEmission and + wideBandAbsorptionEmission + +SourceFiles + absorptionCoeffs.C + +\*---------------------------------------------------------------------------*/ + +#ifndef absorptionCoeffs_H +#define absorptionCoeffs_H + +#include "List.H" +#include "IOstreams.H" +#include "IOdictionary.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +namespace Foam +{ +namespace radiation +{ + +/*---------------------------------------------------------------------------*\ + Class absorptionCoeffs Declaration +\*---------------------------------------------------------------------------*/ + +class absorptionCoeffs +{ +public: + + // Public data members + + static const int nCoeffs_ = 6; + typedef FixedList<scalar, nCoeffs_> coeffArray; + + +private: + + // Private data + + // Temperature limits of applicability for functions + + scalar Tcommon_; + + scalar Tlow_; + + scalar Thigh_; + + + // Polynomial using inverse temperatures + bool invTemp_; + + coeffArray highACoeffs_; + coeffArray lowACoeffs_; + + + // Private member functions + + //- Check given temperature is within the range of the fitted coeffs + void checkT(const scalar T) const; + + +public: + + // Constructors + + //- Construct from Istream + absorptionCoeffs(Istream&); + + // Null constructor + absorptionCoeffs() + {} + + + // Destructor + ~absorptionCoeffs(); + + + // Member functions + + //- Return the coefficients corresponding to the given temperature + const coeffArray& coeffs(const scalar T) const; + + // Initialise from a dictionary + void initialise(const dictionary&); + + // Initialise from an Istream + void initialise(Istream&); + + + // Access Functions + + inline bool invTemp() const; + + inline scalar Tcommon() const; + + inline scalar Tlow() const; + + inline scalar Thigh() const; + + inline const coeffArray& highACoeffs() const; + + inline const coeffArray& lowACoeffs() const; +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam +} // End namespace radiation + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "absorptionCoeffsI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffsI.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffsI.H new file mode 100644 index 0000000000000000000000000000000000000000..c7759db4772a908cbc4f7b8ce8640436f5c8125b --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/absorptionCoeffs/absorptionCoeffsI.H @@ -0,0 +1,65 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +inline bool Foam::radiation::absorptionCoeffs::invTemp() const +{ + return invTemp_; +} + + +inline Foam::scalar Foam::radiation::absorptionCoeffs::Tcommon() const +{ + return Tcommon_; +} + + +inline Foam::scalar Foam::radiation::absorptionCoeffs::Tlow() const +{ + return Tlow_; +} + + +inline Foam::scalar Foam::radiation::absorptionCoeffs::Thigh() const +{ + return Thigh_; +} + + +inline const Foam::radiation::absorptionCoeffs::coeffArray& +Foam::radiation::absorptionCoeffs::highACoeffs() const +{ + return highACoeffs_; +} + + +inline const Foam::radiation::absorptionCoeffs::coeffArray& +Foam::radiation::absorptionCoeffs::lowACoeffs() const +{ + return lowACoeffs_; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.C b/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.C new file mode 100644 index 0000000000000000000000000000000000000000..dee5647366936e75e202bf93426e042bd8f49ea2 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.C @@ -0,0 +1,256 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "blackBodyEmission.H" +#include "dimensionedConstants.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::List<Foam::Tuple2<Foam::scalar, Foam::scalar> > +Foam::radiation::blackBodyEmission::emissivePowerTable +( + IStringStream + ( + "(" + "( 1000 0.00032)" + "( 1100 0.00091)" + "( 1200 0.00213)" + "( 1300 0.00432)" + "( 1400 0.00779)" + "( 1500 0.01280)" + "( 1600 0.01972)" + "( 1700 0.02853)" + "( 1800 0.03934)" + "( 1900 0.05210)" + "( 2000 0.06672)" + "( 2100 0.08305)" + "( 2200 0.10088)" + "( 2300 0.12002)" + "( 2400 0.14025)" + "( 2500 0.16135)" + "( 2600 0.18311)" + "( 2700 0.20535)" + "( 2800 0.22788)" + "( 2900 0.25055)" + "( 3000 0.27322)" + "( 3100 0.29576)" + "( 3200 0.31809)" + "( 3300 0.34009)" + "( 3400 0.36172)" + "( 3500 0.38290)" + "( 3600 0.40359)" + "( 3700 0.42375)" + "( 3800 0.44336)" + "( 3900 0.46240)" + "( 4000 0.48085)" + "( 4100 0.49872)" + "( 4200 0.51599)" + "( 4300 0.53267)" + "( 4400 0.54877)" + "( 4500 0.56429)" + "( 4600 0.57925)" + "( 4700 0.59366)" + "( 4800 0.60753)" + "( 4900 0.62088)" + "( 5000 0.63372)" + "( 5100 0.64606)" + "( 5200 0.65794)" + "( 5300 0.66935)" + "( 5400 0.68033)" + "( 5500 0.69087)" + "( 5600 0.70101)" + "( 5700 0.71076)" + "( 5800 0.72012)" + "( 5900 0.72913)" + "( 6000 0.73778)" + "( 6100 0.74610)" + "( 6200 0.75410)" + "( 6300 0.76180)" + "( 6400 0.76920)" + "( 6500 0.77631)" + "( 6600 0.78316)" + "( 6700 0.78975)" + "( 6800 0.79609)" + "( 6900 0.80219)" + "( 7000 0.80807)" + "( 7100 0.81373)" + "( 7200 0.81918)" + "( 7300 0.82443)" + "( 7400 0.82949)" + "( 7500 0.83436)" + "( 7600 0.83906)" + "( 7700 0.84359)" + "( 7800 0.84796)" + "( 7900 0.85218)" + "( 8000 0.85625)" + "( 8100 0.86017)" + "( 8200 0.86396)" + "( 8300 0.86762)" + "( 8400 0.87115)" + "( 8500 0.87456)" + "( 8600 0.87786)" + "( 8700 0.88105)" + "( 8800 0.88413)" + "( 8900 0.88711)" + "( 9000 0.88999)" + "( 9100 0.89277)" + "( 9200 0.89547)" + "( 9300 0.89807)" + "( 9400 0.90060)" + "( 9500 0.90304)" + "( 9600 0.90541)" + "( 9700 0.90770)" + "( 9800 0.90992)" + "( 9900 0.91207)" + "(10000 0.91415)" + "(12000 0.94505)" + "(15000 0.96893)" + "(20000 0.98555)" + "(30000 0.99529)" + "(40000 0.99792)" + "(50000 0.99890)" + ")" + )() +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::blackBodyEmission::blackBodyEmission +( + const label nLambda, + const volScalarField& T +) +: + table_ + ( + emissivePowerTable, + interpolationTable<scalar>::CLAMP, + "blackBodyEmissivePower" + ), + C1_("C1", dimensionSet(1, 4, 3, 0, 0, 0, 0), 3.7419e-16), + C2_("C2", dimensionSet(0, 1, 0, 1, 0, 0, 0), 14.388e-6), + bLambda_(nLambda), + T_(T) +{ + forAll(bLambda_, lambdaI) + { + bLambda_.set + ( + lambdaI, + new volScalarField + ( + IOobject + ( + "bLambda_" + Foam::name(lambdaI) , + T.mesh().time().timeName(), + T.mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + radiation::sigmaSB*pow4(T) + ) + ); + + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::radiation::blackBodyEmission::~blackBodyEmission() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::radiation::blackBodyEmission::fLambdaT +( + const scalar lambdaT +) const +{ + return table_(lambdaT*1.0e6); +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::blackBodyEmission::EbDeltaLambdaT +( + const volScalarField& T, + const Vector2D<scalar>& band +) const +{ + tmp<volScalarField> Eb + ( + new volScalarField + ( + IOobject + ( + "Eb", + T.mesh().time().timeName(), + T.mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + radiation::sigmaSB*pow4(T) + ) + ); + + + if (band == Vector2D<scalar>::one) + { + return Eb; + } + else + { + forAll(T, i) + { + scalar T1 = fLambdaT(band[1]*T[i]); + scalar T2 = fLambdaT(band[0]*T[i]); + dimensionedScalar fLambdaDelta + ( + "fLambdaDelta", + dimless, + T1 - T2 + ); + Eb()[i] = Eb()[i]*fLambdaDelta.value(); + } + return Eb; + } +} + + +void Foam::radiation::blackBodyEmission::correct +( + const label lambdaI, + const Vector2D<scalar>& band +) +{ + bLambda_[lambdaI] = EbDeltaLambdaT(T_, band); +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.H new file mode 100644 index 0000000000000000000000000000000000000000..01719e50764880cb8d436034a8ffba5366f706c4 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/blackBodyEmission/blackBodyEmission.H @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::radiation::blackBodyEmission + +Description + Class black body emission + + Table of black body emissive power taken from: + Modest, "Radiative Heat Transfer", pp.775-777, 1993 + +SourceFiles + blackBodyEmission.C + +\*---------------------------------------------------------------------------*/ + +#ifndef blackModyEmission_H +#define blackModyEmission_H + +#include "volFields.H" +#include "dimensionedScalar.H" +#include "mathematicalConstants.H" +#include "radiationConstants.H" +#include "interpolationTable.H" +#include "Vector2D.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + +/*---------------------------------------------------------------------------*\ + Class blackBodyEmission Declaration +\*---------------------------------------------------------------------------*/ + +class blackBodyEmission +{ +public: + + //- Static table of black body emissive power + static const List<Tuple2<scalar, scalar> > emissivePowerTable; + + +private: + + // Private data + + //- Interpolation table of black body emissive power + mutable interpolationTable<scalar> table_; + + //- Constant C1 + const dimensionedScalar C1_; + + //- Constant C2 + const dimensionedScalar C2_; + + // Ptr List for black body emission energy field for each wavelength + PtrList<volScalarField> bLambda_; + + // Reference to the temperature field + const volScalarField& T_; + + + // Private member functions + + scalar fLambdaT(const scalar lambdaT) const; + + +public: + + // Constructors + + //- Construct from components + blackBodyEmission + ( + const label nLambda, + const volScalarField& T + ); + + + // Destructor + ~blackBodyEmission(); + + + // Member functions + + // Access + + //- Black body spectrum + inline const volScalarField& bLambda(const label lambdaI) const + { + return bLambda_[lambdaI]; + } + + //- Spectral emission for the black body at T and lambda + inline dimensionedScalar EblambdaT + ( + const dimensionedScalar& T, + const scalar lambda + ) const + { + return (C1_/(pow5(lambda)*(exp(C2_/(lambda*T)) - 1.0))); + } + + //- Integral energy at T from lambda1 to lambda2 + tmp<Foam::volScalarField> EbDeltaLambdaT + ( + const volScalarField& T, + const Vector2D<scalar>& band + ) const; + + + // Edit + + // Update black body emission + void correct(const label lambdaI, const Vector2D<scalar>& band); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam +} // End namespace radiation + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.C b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.C new file mode 100644 index 0000000000000000000000000000000000000000..6d07cc3bea2f9e4b84cdc2bf656ec93b02338566 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.C @@ -0,0 +1,383 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "fvDOM.H" +#include "addToRunTimeSelectionTable.H" +#include "fvm.H" + +#include "absorptionEmissionModel.H" +#include "scatterModel.H" +#include "mathematicalConstants.H" +#include "radiationConstants.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace radiation + { + defineTypeNameAndDebug(fvDOM, 0); + + addToRunTimeSelectionTable + ( + radiationModel, + fvDOM, + dictionary + ); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::fvDOM::fvDOM(const volScalarField& T) +: + radiationModel(typeName, T), + G_ + ( + IOobject + ( + "G", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("G", dimMass/pow3(dimTime), 0.0) + ), + Qr_ + ( + IOobject + ( + "Qr", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh_, + dimensionedScalar("Qr", dimMass/pow3(dimTime), 0.0) + ), + a_ + ( + IOobject + ( + "a", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh_, + dimensionedScalar("a", dimless/dimLength, 0.0) + ), + e_ + ( + IOobject + ( + "e", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("a", dimless/dimLength, 0.0) + ), + E_ + ( + IOobject + ( + "E", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("E", dimMass/dimLength/pow3(dimTime), 0.0) + ), + nTheta_(readLabel(coeffs_.lookup("nTheta"))), + nPhi_(readLabel(coeffs_.lookup("nPhi"))), + nRay_(0), + nLambda_(absorptionEmission_->nBands()), + aLambda_(nLambda_), + blackBody_(nLambda_, T), + IRay_(0), + convergence_(coeffs_.lookupOrDefault<scalar>("convergence", 0.0)), + maxIter_(coeffs_.lookupOrDefault<label>("maxIter", 50)) +{ + if (mesh_.nSolutionD() == 3) //3D + { + nRay_ = 4*nPhi_*nTheta_; + IRay_.setSize(nRay_); + scalar deltaPhi = mathematicalConstant::pi/(2.0*nPhi_); + scalar deltaTheta = mathematicalConstant::pi/nTheta_; + label i = 0; + for (label n = 1; n <= nTheta_; n++) + { + for (label m = 1; m <= 4*nPhi_; m++) + { + scalar thetai = (2.0*n - 1.0)*deltaTheta/2.0; + scalar phii = (2.0*m - 1.0)*deltaPhi/2.0; + IRay_.set + ( + i, + new radiativeIntensityRay + ( + *this, + mesh_, + phii, + thetai, + deltaPhi, + deltaTheta, + nLambda_, + absorptionEmission_, + blackBody_ + ) + ); + i++; + } + } + } + else + { + if (mesh_.nSolutionD() == 2) //2D (X & Y) + { + scalar thetai = mathematicalConstant::pi/2.0; + scalar deltaTheta = mathematicalConstant::pi; + nRay_ = 4*nPhi_; + IRay_.setSize(nRay_); + scalar deltaPhi = mathematicalConstant::pi/(2.0*nPhi_); + label i = 0; + for (label m = 1; m <= 4*nPhi_; m++) + { + scalar phii = (2.0*m - 1.0)*deltaPhi/2.0; + IRay_.set + ( + i, + new radiativeIntensityRay + ( + *this, + mesh_, + phii, + thetai, + deltaPhi, + deltaTheta, + nLambda_, + absorptionEmission_, + blackBody_ + ) + ); + i++; + } + } + else //1D (X) + { + scalar thetai = mathematicalConstant::pi/2.0; + scalar deltaTheta = mathematicalConstant::pi; + nRay_ = 2; + IRay_.setSize(nRay_); + scalar deltaPhi = mathematicalConstant::pi; + label i = 0; + for (label m = 1; m <= 2; m++) + { + scalar phii = (2.0*m - 1.0)*deltaPhi/2.0; + IRay_.set + ( + i, + new radiativeIntensityRay + ( + *this, + mesh_, + phii, + thetai, + deltaPhi, + deltaTheta, + nLambda_, + absorptionEmission_, + blackBody_ + ) + ); + i++; + } + + } + } + + + // Construct absorption field for each wavelength + forAll(aLambda_, lambdaI) + { + aLambda_.set + ( + lambdaI, + new volScalarField + ( + IOobject + ( + "aLambda_" + Foam::name(lambdaI) , + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + a_ + ) + ); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::radiation::fvDOM::~fvDOM() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::radiation::fvDOM::read() +{ + if (radiationModel::read()) + { + // nothing to read + +// coeffs_.lookup("nTheta") >> nTheta_; +// coeffs_.lookup("nPhi") >> nPhi_; + + return true; + } + else + { + return false; + } +} + + +void Foam::radiation::fvDOM::calculate() +{ + absorptionEmission_->correct(a_, aLambda_); + + updateBlackBodyEmission(); + + scalar maxResidual = 0.0; + label radIter = 0; + do + { + radIter++; + forAll(IRay_, rayI) + { + maxResidual = 0.0; + scalar maxBandResidual = IRay_[rayI].correct(); + maxResidual = max(maxBandResidual, maxResidual); + } + + Info << "Radiation solver iter: " << radIter << endl; + + } while(maxResidual > convergence_ && radIter < maxIter_); + + updateG(); +} + + +Foam::tmp<Foam::volScalarField> Foam::radiation::fvDOM::Rp() const +{ + return tmp<volScalarField> + ( + new volScalarField + ( + IOobject + ( + "Rp", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + 4.0*a_*radiation::sigmaSB //absorptionEmission_->a() + ) + ); +} + + +Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> > +Foam::radiation::fvDOM::Ru() const +{ + + const DimensionedField<scalar, volMesh>& G = + G_.dimensionedInternalField(); + const DimensionedField<scalar, volMesh> E = + absorptionEmission_->ECont()().dimensionedInternalField(); + const DimensionedField<scalar, volMesh> a = + a_.dimensionedInternalField(); //absorptionEmission_->aCont()() + + return a*G - 4.0*E; +} + + +void Foam::radiation::fvDOM::updateBlackBodyEmission() +{ + for (label j=0; j < nLambda_; j++) + { + blackBody_.correct(j, absorptionEmission_->bands(j)); + } +} + + +void Foam::radiation::fvDOM::updateG() +{ + G_ = dimensionedScalar("zero",dimMass/pow3(dimTime), 0.0); + Qr_ = dimensionedScalar("zero",dimMass/pow3(dimTime), 0.0); + + forAll(IRay_, rayI) + { + IRay_[rayI].addIntensity(); + G_ += IRay_[rayI].I()*IRay_[rayI].omega(); + Qr_ += IRay_[rayI].Qr(); + } +} + + +void Foam::radiation::fvDOM::setRayIdLambdaId +( + const word& name, + label& rayId, + label& lambdaId +) const +{ + // assuming name is in the form: CHARS_rayId_lambdaId + size_type i1 = name.find_first_of("_"); + size_type i2 = name.find_last_of("_"); + + rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))()); + lambdaId = readLabel(IStringStream(name.substr(i2+1, name.size()-1))()); +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.H new file mode 100644 index 0000000000000000000000000000000000000000..f91163805a46f899a8253d65ea5b22f267861cb7 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOM.H @@ -0,0 +1,235 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::radiation::fvDOM + +Description + + Finite Volume Discrete Ordinary Method. Solves the RTE equation for n + directions in a participating media, not including scatter. + + Available absorption models: + greyMeanAbsoprtionEmission + wideBandAbsorptionEmission + + i.e. dictionary + fvDOMCoeffs + { + nPhi 1; // azimuthal angles in PI/2 on X-Y.(from Y to X) + nTheta 2; // polar angles in PI (from Z to X-Y plane) + convergence 1e-4; // convergence criteria for radiation iteration + } + + solverFreq 1; // Number of flow iterations per radiation iteration + + The total number of solid angles is 4*nPhi*nTheta. + + In 1D the direction of the rays is X (nPhi and nTheta are ignored) + In 2D the direction of the rays is on X-Y plane (only nPhi is considered) + In 3D (nPhi and nTheta are considered) + +SourceFiles + fvDOM.C + +\*---------------------------------------------------------------------------*/ + +#ifndef radiationModelfvDOM_H +#define radiationModelfvDOM_H + +#include "radiativeIntensityRay.H" +#include "radiationModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + +/*---------------------------------------------------------------------------*\ + Class fvDOM Declaration +\*---------------------------------------------------------------------------*/ + +class fvDOM +: + public radiationModel +{ + // Private data + + //- Incident radiation [W/m2] + volScalarField G_; + + //- Total radiative heat flux [W/m2] + volScalarField Qr_; + + //- Total absorption coefficient [1/m] + volScalarField a_; + + //- Total emission coefficient [1/m] + volScalarField e_; + + //- Emission contribution [Kg/m/s^3] + volScalarField E_; + + //- Number of solid angles in theta + label nTheta_; + + //- Number of solid angles in phi + label nPhi_ ; + + //- Total number of rays (1 per direction) + label nRay_; + + //- Number of wavelength bands + label nLambda_; + + //- Wavelength total absorption coefficient [1/m] + PtrList<volScalarField> aLambda_; + + //- Black body + blackBodyEmission blackBody_; + + //- List of pointers to radiative intensity rays + PtrList<radiativeIntensityRay> IRay_; + + //- Convergence criterion + scalar convergence_; + + //- Maximum number of iterations + scalar maxIter_; + + + // Private member functions + + //- Disallow default bitwise copy construct + fvDOM(const fvDOM&); + + //- Disallow default bitwise assignment + void operator=(const fvDOM&); + + //- Update nlack body emission + void updateBlackBodyEmission(); + + +public: + + //- Runtime type information + TypeName("fvDOM"); + + + // Constructors + + //- Construct from components + fvDOM(const volScalarField& T); + + + //- Destructor + virtual ~fvDOM(); + + + // Member functions + + // Edit + + //- Solve radiation equation(s) + void calculate(); + + //- Read radiation properties dictionary + bool read(); + + //- Update G and calculate total heat flux on boundary + void updateG(); + + //- Set the rayId and lambdaId from by decomposing an intensity + // field name + void setRayIdLambdaId + ( + const word& name, + label& rayId, + label& lambdaId + ) const; + + //- Source term component (for power of T^4) + virtual tmp<volScalarField> Rp() const; + + //- Source term component (constant) + virtual tmp<DimensionedField<scalar, volMesh> > Ru() const; + + + // Access + + //- Ray intensity for rayI + inline const radiativeIntensityRay& IRay(const label rayI) const; + + //- Ray intensity for rayI and lambda bandwidth + inline const volScalarField& IRayLambda + ( + const label rayI, + const label lambdaI + ) const; + + //- Number of angles in theta + inline label nTheta() const; + + //- Number of angles in phi + inline label nPhi() const; + + //- Number of rays + inline label nRay() const; + + //- Number of wavelengths + inline label nLambda() const; + + //- Const access to total absorption coefficient + inline const volScalarField& a() const; + + //- Const access to wavelength total absorption coefficient + inline const volScalarField& aLambda(const label lambdaI) const; + + //- Const access to incident radiation field + inline const volScalarField& G() const; + + //- Const access to total radiative heat flux field + inline const volScalarField& Qr() const; + + //- Const access to black body + inline const blackBodyEmission& blackBody() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "fvDOMI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace radiation +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOMI.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOMI.H new file mode 100644 index 0000000000000000000000000000000000000000..594b5bee0ac72a6dde43be556d2d616813353e4a --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/fvDOM/fvDOMI.H @@ -0,0 +1,103 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +inline const Foam::radiation::radiativeIntensityRay& +Foam::radiation::fvDOM::IRay(const label rayI) const +{ + return IRay_[rayI]; +} + + +inline const Foam::volScalarField& +Foam::radiation::fvDOM::IRayLambda +( + const label rayI, + const label lambdaI +) const +{ + return IRay_[rayI].ILambda(lambdaI); +} + + +inline Foam::label Foam::radiation::fvDOM::nTheta() const +{ + return nTheta_; +} + + +inline Foam::label Foam::radiation::fvDOM::nPhi() const +{ + return nPhi_; +} + + +inline Foam::label Foam::radiation::fvDOM::nRay() const +{ + return nRay_; +} + + +inline Foam::label Foam::radiation::fvDOM::nLambda() const +{ + return nLambda_; +} + + +inline const Foam::volScalarField& Foam::radiation::fvDOM::a() const +{ + return a_; +} + + +inline const Foam::volScalarField& Foam::radiation::fvDOM::aLambda +( + const label lambdaI +) const +{ + return aLambda_[lambdaI]; +} + + +inline const Foam::volScalarField& Foam::radiation::fvDOM::G() const +{ + return G_; +} + + +inline const Foam::volScalarField& Foam::radiation::fvDOM::Qr() const +{ + return Qr_; +} + + +inline const Foam::radiation::blackBodyEmission& +Foam::radiation::fvDOM::blackBody() const +{ + return blackBody_; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.C b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.C new file mode 100755 index 0000000000000000000000000000000000000000..f000e43fa3910ef87653e3d620b315809d67388f --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.C @@ -0,0 +1,509 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "IFstream.H" + +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +template <class Type> +Foam::label Foam::interpolationLookUpTable<Type>::index +( + const List<scalar>& indices, + const bool lastDim +) const +{ + label totalIndex = 0; + + forAll(dim_, i) + { + label dim = 1; + for (int j = i + 1; j < dim_.size(); j++) + { + dim *= dim_[j] + 1; + } + + totalIndex += + dim + *min + ( + max(label((indices[i] - min_[i])/delta_[i]), 0), + dim_[i] + ); + } + + if (lastDim) + { + label iLastdim = dim_.size() - 1; + totalIndex += Foam::min + ( + max + ( + label((indices[iLastdim] - min_[iLastdim])/delta_[iLastdim]), + 0 + ), + dim_[iLastdim] + ); + } + + return totalIndex; +} + + +template <class Type> +Foam::label Foam::interpolationLookUpTable<Type>::index +( + const scalar indice +) const +{ + label i = 0; + label totalIndex = + Foam::min + ( + Foam::max + ( + label((indice - min_[i])/delta_[i]), + 0 + ), + dim_[i] + ); + + return totalIndex; +} + + +template<class Type> +bool Foam::interpolationLookUpTable<Type>::checkRange +( + const scalar lookUpValue, + const label interfield +) const +{ + if (lookUpValue >= min_[interfield] && lookUpValue <= max_[interfield]) + { + return true; + } + else + { + return false; + } +} + + +template<class Type> +Foam::scalar Foam::interpolationLookUpTable<Type>::interpolate +( + const label lo, + const label hi, + const scalar lookUpValue, + const label ofield, + const label interfield +) const +{ + if + ( + List<scalarField>::operator[](interfield).operator[](hi) + != List<scalarField>::operator[](interfield).operator[](lo) + ) + { + scalar output + ( + List<scalarField>::operator[](ofield).operator[](lo) + + ( + List<scalarField>::operator[](ofield).operator[](hi) + - List<scalarField>::operator[](ofield).operator[](lo) + ) + *( + lookUpValue + - List<scalarField>::operator[](interfield).operator[](lo) + ) + /( + List<scalarField>::operator[](interfield).operator[](hi) + - List<scalarField>::operator[](interfield).operator[](lo) + ) + ); + return output; + } + else + { + return List<scalarField>::operator[](ofield).operator[](lo); + } +} + + +template<class Type> +void Foam::interpolationLookUpTable<Type>::dimensionTable() +{ + min_.setSize(entries_.size()); + dim_.setSize(entries_.size()); + delta_.setSize(entries_.size()); + max_.setSize(entries_.size()); + entryIndices_.setSize(entries_.size()); + outputIndices_.setSize(output_.size()); + label index = 0; + label tableDim = 1; + + forAll(entries_,i) + { + dim_[i] = readLabel(entries_[i].lookup("N")); + max_[i] = readScalar(entries_[i].lookup("max")); + min_[i] = readScalar(entries_[i].lookup("min")); + delta_[i] = (max_[i] - min_[i])/dim_[i]; + tableDim *= dim_[i] + 1; + fieldIndices_.insert(entries_[i].lookup("name"), index); + entryIndices_[i] = index; + index++; + } + + forAll(output_,i) + { + fieldIndices_.insert(output_[i].lookup("name"), index); + outputIndices_[i] = index; + index++; + } + + List<scalarField>& internal = *this; + + internal.setSize(entries_.size() + output_.size()); + + interpOutput_.setSize(entries_.size() + output_.size()); + + forAll(internal, i) + { + internal[i].setSize(tableDim); + } +} + + +template<class Type> +void Foam::interpolationLookUpTable<Type>::readTable +( + const word& instance, + const fvMesh& mesh +) +{ + IOdictionary control + ( + IOobject + ( + fileName_, + instance, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + + control.lookup("fields") >> entries_; + control.lookup("output") >> output_; + control.lookup("values") >> *this; + + dimensionTable(); + + check(); + + if (this->size() == 0) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::readTable()" + ) << "table is empty" << nl << exit(FatalError); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::interpolationLookUpTable<Type>::interpolationLookUpTable() +: + List<scalarField>(), + fileName_("fileNameIsUndefined") +{} + + +template<class Type> +Foam::interpolationLookUpTable<Type>::interpolationLookUpTable +( + const fileName& fn, const word& instance, const fvMesh& mesh +) +: + List<scalarField>(), + fileName_(fn), + dim_(0), + min_(0), + delta_(0.0), + max_(0.0), + entries_(0), + output_(0), + entryIndices_(0), + outputIndices_(0), + interpOutput_(0) +{ + readTable(instance, mesh); +} + + +template<class Type> +Foam::interpolationLookUpTable<Type>::interpolationLookUpTable +( + const interpolationLookUpTable& interpTable +) +: + List<scalarField>(interpTable), + fileName_(interpTable.fileName_), + entryIndices_(interpTable.entryIndices_), + outputIndices_(interpTable.outputIndices_), + dim_(interpTable.dim_), + min_(interpTable.min_), + delta_(interpTable.delta_), + max_(interpTable.max_), + entries_(0), + output_(0), + interpOutput_(interpTable.interpOutput_) +{} + + +template<class Type> +Foam::interpolationLookUpTable<Type>::interpolationLookUpTable +( + const dictionary& dict +) +: + List<scalarField>(), + fileName_(fileName(dict.lookup("fileName")).expand()), + dim_(0), + min_(0.0), + delta_(0.0), + max_(0.0), + entries_(dict.lookup("fields")), + output_(dict.lookup("output")), + entryIndices_(0), + outputIndices_(0), + fieldIndices_(0), + interpOutput_(0) +{ + dimensionTable(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +void Foam::interpolationLookUpTable<Type>::check() const +{ + // check order in the first dimension. + scalar prevValue = List<scalarField>::operator[](0).operator[](0); + label dim = 1; + for (int j = 1; j < dim_.size(); j++) + { + dim *= dim_[j] + 1; + } + + for (label i = 1; i < dim_[0]; i++) + { + label index = i*dim; + const scalar currValue = + List<scalarField>::operator[](0).operator[](index); + + // avoid duplicate values (divide-by-zero error) + if (currValue <= prevValue) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::checkOrder() const" + ) << "out-of-order value: " << currValue + << " at index " << index << nl << exit(FatalError); + } + prevValue = currValue; + } +} + + +template<class Type> +void Foam::interpolationLookUpTable<Type>::write +( + Ostream& os, + const fileName& fn, + const word& instance, + const fvMesh& mesh +) const +{ + IOdictionary control + ( + IOobject + ( + fn, + instance, + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ) + ); + + control.writeHeader(os); + + os.writeKeyword("fields"); + os << entries_ << token::END_STATEMENT << nl; + + os.writeKeyword("output"); + os << output_ << token::END_STATEMENT << nl; + + if (this->size() == 0) + { + FatalErrorIn + ( + "Foam::interpolationTable<Type>::write()" + ) << "table is empty" << nl << exit(FatalError); + } + os.writeKeyword("values"); + os << *this << token::END_STATEMENT << nl; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template<class Type> +Foam::scalarField& +Foam::interpolationLookUpTable<Type>::operator[](const label i) +{ + label ii = i; + label n = this->size(); + + if (n <= 1) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[](const label)" + ) << "table has (" << n << ") columns" << nl << exit(FatalError); + } + else if (ii < 0) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[](const label)" + ) << "index (" << ii << ") underflow" << nl << exit(FatalError); + } + else if (ii > n) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[](const label)" + ) << "index (" << ii << ") overflow" << nl << exit(FatalError); + } + + return List<scalarField>::operator[](ii); +} + + +template<class Type> +const Foam::scalarField& +Foam::interpolationLookUpTable<Type>::operator[](const label i) const +{ + label ii = i; + label n = this->size(); + + if (n <= 1) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[]" + "(const label) const" + ) << "table has (" << n << ") columns" << nl << exit(FatalError); + } + else if (ii < 0) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[]" + "(const label) const" + ) << "index (" << ii << ") underflow" << nl << exit(FatalError); + } + + else if (ii > n) + { + FatalErrorIn + ( + "Foam::interpolationLookUpTable<Type>::operator[]" + "(const label) const" + ) << "index (" << ii << ") overflow" << nl + << exit(FatalError); + } + + return List<scalarField>::operator[](ii); +} + + +template<class Type> +bool Foam::interpolationLookUpTable<Type>::found(const word& fieldName) const +{ + return fieldIndices_.found(fieldName); +} + + +template<class Type> +const Foam::scalarList& +Foam::interpolationLookUpTable<Type>::lookUp(const scalar retvals) +{ + const label lo = index(retvals); + findHi(lo, retvals); + return interpOutput_; +} + + +template<class Type> +void Foam::interpolationLookUpTable<Type>::findHi +( + const label lo, + const scalar retvals +) +{ + forAll(outputIndices_,j) + { + scalar tmp = 0; + label ofield = outputIndices_[j]; + scalar baseValue = List<scalarField>::operator[](ofield).operator[](lo); + + forAll(entryIndices_,i) + { + if (checkRange(retvals, entryIndices_[i])) + { + label dim = 1; + + label hi = Foam::min(lo + dim, (*this)[0].size() - 1); + + tmp += interpolate(lo, hi, retvals, ofield, entryIndices_[i]) + - baseValue; + } + interpOutput_[entryIndices_[i]] = retvals; + } + + tmp += baseValue; + interpOutput_[outputIndices_[j]] = tmp; + } +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.H new file mode 100755 index 0000000000000000000000000000000000000000..6140ae4bc3a6527acc6f1b30b3e05419c0f15b62 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTable.H @@ -0,0 +1,234 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::interpolationLookUpTable + +Description + A list of lists. Interpolates based on the first dimension. + The values must be positive and monotonically increasing in each dimension + +Note + - Accessing an empty list results in an error. + - Accessing a list with a single element always returns the same value. + +SourceFiles + interpolationLookUpTable.C + +\*---------------------------------------------------------------------------*/ + +#ifndef interpolationLookUpTable_H +#define interpolationLookUpTable_H + +#include "List.H" +#include "ListOps.H" +#include "scalarField.H" +#include "HashTable.H" +#include "IOdictionary.H" +#include "fvCFD.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class interpolationLookUpTable Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class interpolationLookUpTable +: + public List<scalarField> +{ +private: + + // Privsate data + + //- File name + fileName fileName_; + + //- Table dimensions + List<label> dim_; + + //- Min on each dimension + List<scalar> min_; + + //- Deltas on each dimension + List<scalar> delta_; + + //- Maximum on each dimension + List<scalar> max_; + + //- Dictionary entries + List<dictionary> entries_; + + //- Output dictionaries + List<dictionary> output_; + + //- Input indices from the look up table + List<label> entryIndices_; + + //- Output Indeces from the Look Up Table + List<label> outputIndices_; + + //- Field names and indices + HashTable<label> fieldIndices_; + + //- Output list containing input and interpolation values of outputs + List<scalar> interpOutput_; + + + // Private Member Functions + + //- Read the table of data from file + void readTable(const word& instance, const fvMesh& mesh); + + //- Dimension table from dictionaries input and output + void dimensionTable(); + + //- Find table index by scalarList + label index(const List<scalar>&, const bool lastDim=true) const; + + //- Find table index by scalar + label index(const scalar) const; + + //- Check range of lookup value + bool checkRange(const scalar, const label) const; + + //- Interpolate function return an scalar + scalar interpolate + ( + const label lo, + const label hi, + const scalar lookUpValue, + const label ofield, + const label interfield + ) const; + + // Check list is monotonically increasing + void check() const; + + // find hi index, interpolate and populate interpOutput_ + void findHi(const label lo, const scalar retvals); + + +public: + + // Constructors + + //- Construct null + interpolationLookUpTable(); + + //- Construct given the name of the file containing the table of data + interpolationLookUpTable + ( + const fileName& fn, + const word& instance, + const fvMesh& mesh + ); + + //- Construct from dictionary + interpolationLookUpTable(const dictionary& dict); + + //- Construct copy + interpolationLookUpTable(const interpolationLookUpTable& interpTable); + + + // Member Functions + + //- Return true if the filed exists in the table + bool found(const word& fieldName) const; + + //- Return the output list given a single input scalar + const List<scalar>& lookUp(const scalar); + + //- Write Look Up Table to filename. + void write + ( + Ostream& os, + const fileName& fn, + const word& instance, + const fvMesh& mesh + ) const; + + + // Access + + //- Return the index of a field by name + inline label findFieldIndex(const word& fieldName) const; + + //- Return const access to the output dictionaries + inline const List<dictionary>& output() const; + + //- Return const access tp the dictionary entries + inline const List<dictionary>& entries() const; + + //- Return const access to the list of min dimensions + inline const List<scalar>& min() const; + + //- Return const access to the list of dimensions + inline const List<label>& dim() const; + + //- Return const access to the deltas in each dimension + inline const List<scalar>& delta() const; + + //- Return const access to the list of max dimensions + inline const List<scalar>& max() const; + + //- Return const access to the table name + inline word tableName() const; + + + // Member Operators + + //- Return an element of constant List<scalar, Type> + const scalarField& operator[](const label) const; + + //- Return an element of List<scalar, Type> + scalarField& operator[](const label); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "interpolationLookUpTableI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +#ifdef NoRepository +# include "interpolationLookUpTable.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTableI.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTableI.H new file mode 100644 index 0000000000000000000000000000000000000000..5829db3148e534ecdbcaaeb797427426db55acd0 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/interpolationLookUpTable/interpolationLookUpTableI.H @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +template<class Type> +inline Foam::label +Foam::interpolationLookUpTable<Type>::findFieldIndex +( + const word& fieldName +) const +{ + return fieldIndices_[fieldName]; +} + + +template<class Type> +inline const Foam::List<Foam::dictionary>& +Foam::interpolationLookUpTable<Type>::output() const +{ + return output_; +} + + +template<class Type> +inline const Foam::List<Foam::dictionary>& +Foam::interpolationLookUpTable<Type>::entries() const +{ + return entries_; +} + + +template<class Type> +inline const Foam::List<Foam::scalar>& +Foam::interpolationLookUpTable<Type>::min() const +{ + return min_; +} + + +template<class Type> +inline const Foam::List<Foam::label>& +Foam::interpolationLookUpTable<Type>::dim() const +{ + return dim_; +} + + +template<class Type> +inline const Foam::List<Foam::scalar>& +Foam::interpolationLookUpTable<Type>::delta() const +{ + return delta_; +} + + +template<class Type> +inline const Foam::List<Foam::scalar>& +Foam::interpolationLookUpTable<Type>::max() const +{ + return max_; +} + + +template<class Type> +inline Foam::word Foam::interpolationLookUpTable<Type>::tableName() const +{ + return fileName_.name(); +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.C b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.C new file mode 100644 index 0000000000000000000000000000000000000000..6af99c86a46957cbf4e7bd7c7c9c886dec90a4c7 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.C @@ -0,0 +1,238 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "radiativeIntensityRay.H" +#include "fvm.H" +#include "fvDOM.H" + +#include "absorptionEmissionModel.H" +#include "scatterModel.H" +#include "mathematicalConstants.H" +#include "radiationConstants.H" +#include "radiationModel.H" +#include "Vector2D.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +Foam::label Foam::radiation::radiativeIntensityRay::rayId(0); + +const Foam::word +Foam::radiation::radiativeIntensityRay::intensityPrefix("ILambda"); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::radiativeIntensityRay::radiativeIntensityRay +( + const fvDOM& dom, + const fvMesh& mesh, + const scalar phi, + const scalar theta, + const scalar deltaPhi, + const scalar deltaTheta, + const label nLambda, + const absorptionEmissionModel& absorptionEmission, + const blackBodyEmission& blackBody +) +: + dom_(dom), + mesh_(mesh), + absorptionEmission_(absorptionEmission), + blackBody_(blackBody), + I_ + ( + IOobject + ( + "I" + name(rayId), + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("I", dimMass/pow3(dimTime), 0.0) + ), + Qr_ + ( + IOobject + ( + "Qr" + name(rayId), + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("Qr", dimMass/pow3(dimTime), 0.0) + ), + d_(vector::zero), + dAve_(vector::zero), + theta_(theta), + phi_(phi), + omega_(0.0), + nLambda_(nLambda), + ILambda_(nLambda) +{ + scalar sinTheta = Foam::sin(theta); + scalar cosTheta = Foam::cos(theta); + scalar sinPhi = Foam::sin(phi); + scalar cosPhi = Foam::cos(phi); + + omega_ = 2.0*sinTheta*Foam::sin(deltaTheta/2.0)*deltaPhi; + d_ = vector(sinTheta*sinPhi, sinTheta*cosPhi, cosTheta); + dAve_ = vector + ( + sinPhi + *Foam::sin(0.5*deltaPhi) + *(deltaTheta - Foam::cos(2.0*theta) + *Foam::sin(deltaTheta)), + cosPhi + *Foam::sin(0.5*deltaPhi) + *(deltaTheta - Foam::cos(2.0*theta) + *Foam::sin(deltaTheta)), + 0.5*deltaPhi*Foam::sin(2.0*theta)*Foam::sin(deltaTheta) + ); + + + autoPtr<volScalarField> IDefaultPtr; + + forAll(ILambda_, lambdaI) + { + IOobject IHeader + ( + intensityPrefix + "_" + name(rayId) + "_" + name(lambdaI), + mesh_.time().timeName(), + mesh_, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ); + + // check if field exists and can be read + if (IHeader.headerOk()) + { + ILambda_.set + ( + lambdaI, + new volScalarField(IHeader, mesh_) + ); + } + else + { + // Demand driven load the IDefault field + if (!IDefaultPtr.valid()) + { + IDefaultPtr.reset + ( + new volScalarField + ( + IOobject + ( + "IDefault", + mesh_.time().timeName(), + mesh_, + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + mesh_ + ) + ); + } + + // Reset the MUST_READ flag + IOobject noReadHeader(IHeader); + noReadHeader.readOpt() = IOobject::NO_READ; + + ILambda_.set + ( + lambdaI, + new volScalarField(noReadHeader, IDefaultPtr()) + ); + } + } + rayId++; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::radiation::radiativeIntensityRay::~radiativeIntensityRay() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::radiation::radiativeIntensityRay::correct() +{ + // reset boundary heat flux to zero + Qr_ = dimensionedScalar("zero", dimMass/pow3(dimTime), 0.0); + + scalar maxResidual = -GREAT; + + forAll(ILambda_, lambdaI) + { + const volScalarField& k = dom_.aLambda(lambdaI); + + surfaceScalarField Ji = dAve_ & mesh_.Sf(); + + fvScalarMatrix IiEq + ( + fvm::div(Ji, ILambda_[lambdaI], "div(Ji,Ii_h)") + + fvm::Sp(k*omega_, ILambda_[lambdaI]) + == + 1.0/Foam::mathematicalConstant::pi + *( + k*omega_*blackBody_.bLambda(lambdaI) + + absorptionEmission_.ECont(lambdaI) + ) + ); + + IiEq.relax(); + + scalar eqnResidual = solve + ( + IiEq, + mesh_.solver("Ii") + ).initialResidual(); + + maxResidual = max(eqnResidual, maxResidual); + } + + return maxResidual; +} + + +void Foam::radiation::radiativeIntensityRay::addIntensity() +{ + I_ = dimensionedScalar("zero", dimMass/pow3(dimTime), 0.0); + + forAll(ILambda_, lambdaI) + { + I_ += absorptionEmission_.addIntensity(lambdaI, ILambda_[lambdaI]); + } +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.H new file mode 100644 index 0000000000000000000000000000000000000000..1e558c8f3cdf4e42b7a92498be2c07e8744aed98 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRay.H @@ -0,0 +1,210 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::radiation::radiativeIntensityRay + +Description + Radiation intensity for a ray in a given direction + +SourceFiles + radiativeIntensityRay.C + +\*---------------------------------------------------------------------------*/ + +#ifndef radiativeIntensityRay_H +#define radiativeIntensityRay_H + +#include "absorptionEmissionModel.H" +#include "blackBodyEmission.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + +// Forward declaration of classes +class fvDOM; + +/*---------------------------------------------------------------------------*\ + Class radiativeIntensityRay Declaration +\*---------------------------------------------------------------------------*/ + +class radiativeIntensityRay +{ +public: + + static const word intensityPrefix; + + +private: + + // Private data + + //- Refence to the owner fvDOM object + const fvDOM& dom_; + + //- Reference to the mesh + const fvMesh& mesh_; + + //- Absorption/emission model + const absorptionEmissionModel& absorptionEmission_; + + //- Black body + const blackBodyEmission& blackBody_; + + //- Total radiative intensity / [W/m2] + volScalarField I_; + + //- Total radiative heat flux on boundary + volScalarField Qr_; + + //- Direction + vector d_; + + //- Average direction vector inside the solid angle + vector dAve_; + + //- Theta angle + scalar theta_; + + //- Phi angle + scalar phi_; + + //- Solid angle + scalar omega_; + + //- Number of wavelengths/bands + label nLambda_; + + //- List of pointers to radiative intensity fields for given wavelengths + PtrList<volScalarField> ILambda_; + + //- Global ray id - incremented in constructor + static label rayId; + + + // Private member functions + + //- Disallow default bitwise copy construct + radiativeIntensityRay(const radiativeIntensityRay&); + + //- Disallow default bitwise assignment + void operator=(const radiativeIntensityRay&); + + +public: + + // Constructors + + //- Construct form components + radiativeIntensityRay + ( + const fvDOM& dom, + const fvMesh& mesh, + const scalar phi, + const scalar theta, + const scalar deltaPhi, + const scalar deltaTheta, + const label lambda, + const absorptionEmissionModel& absEmmModel_, + const blackBodyEmission& blackBody + ); + + + // Destructor + ~radiativeIntensityRay(); + + + // Member functions + + // Edit + + //- Update radiative intensity on i direction + scalar correct(); + + //- Initialise the ray in i direction + void init + ( + const scalar phi, + const scalar theta, + const scalar deltaPhi, + const scalar deltaTheta, + const scalar lambda + ); + + //- Add radiative intensities from all the bands + void addIntensity(); + + + // Access + + //- Return intensity + inline const volScalarField& I() const; + + //- Return const access to the boundary heat flux + inline const volScalarField& Qr() const; + + //- Return non-const access to the boundary heat flux + inline volScalarField& Qr(); + + //- Return direction + inline const vector& d() const; + + //- Return the average vector inside the solid angle + inline const vector& dAve() const; + + //- Return the number of bands + inline scalar nLambda() const; + + //- Return the phi angle + inline scalar phi() const; + + //- Return the theta angle + inline scalar theta() const; + + //- Return the solid angle + inline scalar omega() const; + + //- Return the radiative intensity for a given wavelength + inline const volScalarField& ILambda(const label lambdaI) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace radiation +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "radiativeIntensityRayI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRayI.H b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRayI.H new file mode 100644 index 0000000000000000000000000000000000000000..0efd423a6dc08efb6a113900e5ac8c6f43b44874 --- /dev/null +++ b/src/thermophysicalModels/radiation/radiationModel/fvDOM/radiativeIntensityRay/radiativeIntensityRayI.H @@ -0,0 +1,90 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +inline const Foam::volScalarField& Foam::radiation::radiativeIntensityRay::I() const +{ + return I_; +} + + +inline const Foam::volScalarField& Foam::radiation::radiativeIntensityRay::Qr() const +{ + return Qr_; +} + + +inline Foam::volScalarField& Foam::radiation::radiativeIntensityRay::Qr() +{ + return Qr_; +} + + +inline const Foam::vector& Foam::radiation::radiativeIntensityRay::d() const +{ + return d_; +} + + +inline const Foam::vector& Foam::radiation::radiativeIntensityRay::dAve() const +{ + return dAve_; +} + + +inline Foam::scalar Foam::radiation::radiativeIntensityRay::nLambda() const +{ + return nLambda_; +} + + +inline Foam::scalar Foam::radiation::radiativeIntensityRay::phi() const +{ + return phi_; +} + + +inline Foam::scalar Foam::radiation::radiativeIntensityRay::theta() const +{ + return theta_; +} + + +inline Foam::scalar Foam::radiation::radiativeIntensityRay::omega() const +{ + return omega_; +} + + +inline const Foam::volScalarField& Foam::radiation::radiativeIntensityRay::ILambda +( + const label lambdaI +) const +{ + return ILambda_[lambdaI]; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.C b/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.C index ca814fe305a7fca33ce3fe564e35b49ffb12dfcd..fc6fbc549a3e3237ba7238436db5dbc8f93e2d8f 100644 --- a/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.C +++ b/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.C @@ -50,10 +50,9 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct from components Foam::radiation::noRadiation::noRadiation(const volScalarField& T) : - radiationModel(typeName, T) + radiationModel(T) {} @@ -71,7 +70,7 @@ bool Foam::radiation::noRadiation::read() } -void Foam::radiation::noRadiation::correct() +void Foam::radiation::noRadiation::calculate() { // Do nothing } diff --git a/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.H b/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.H index f94617e8fc2ad9e0dcb8b79c22f82c590e253a80..2527ab1211fac521aa8d55b8fb4a4b90ca873316 100644 --- a/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.H +++ b/src/thermophysicalModels/radiation/radiationModel/noRadiation/noRadiation.H @@ -54,7 +54,6 @@ class noRadiation : public radiationModel { - // Private member functions //- Disallow default bitwise copy construct @@ -76,17 +75,16 @@ public: noRadiation(const volScalarField& T); - // Destructor - - ~noRadiation(); + //- Destructor + virtual ~noRadiation(); // Member functions // Edit - //- Update radiation source - void correct(); + //- Solve radiation equation(s) + void calculate(); //- Read radiationProperties dictionary bool read(); diff --git a/src/thermophysicalModels/radiation/radiationModel/radiationModel/newRadiationModel.C b/src/thermophysicalModels/radiation/radiationModel/radiationModel/newRadiationModel.C index 9822578114692dcfbcd05db74144e421eae87507..c7840d9433599e97c0435390dc694b1fb134676f 100644 --- a/src/thermophysicalModels/radiation/radiationModel/radiationModel/newRadiationModel.C +++ b/src/thermophysicalModels/radiation/radiationModel/radiationModel/newRadiationModel.C @@ -52,8 +52,8 @@ autoPtr<radiationModel> radiationModel::New IOobject ( "radiationProperties", - T.time().constant(), - T.db(), + T.mesh().time().constant(), + T.mesh().objectRegistry::db(), IOobject::MUST_READ, IOobject::NO_WRITE ) @@ -75,7 +75,7 @@ autoPtr<radiationModel> radiationModel::New "radiationModel::New(const volScalarField&)" ) << "Unknown radiationModel type " << radiationModelTypeName << nl << nl - << "Valid radiationModel types are :" << nl + << "Valid radiationModel types are:" << nl << dictionaryConstructorTablePtr_->toc() << exit(FatalError); } @@ -86,7 +86,7 @@ autoPtr<radiationModel> radiationModel::New // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace radiation +} // End radiation } // End namespace Foam // ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.C b/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.C index adc5c53558d63697d7220a54692e283329eabfe3..92c6397fb5d75e77b6b6bc2cbb1d54b6bddf85c1 100644 --- a/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.C +++ b/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.C @@ -43,6 +43,30 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::radiation::radiationModel::radiationModel(const volScalarField& T) +: + IOdictionary + ( + IOobject + ( + "radiationProperties", + T.time().constant(), + T.mesh(), + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ), + mesh_(T.mesh()), + time_(T.time()), + T_(T), + radiation_(false), + coeffs_(dictionary::null), + solverFreq_(0), + absorptionEmission_(NULL), + scatter_(NULL) +{} + + Foam::radiation::radiationModel::radiationModel ( const word& type, @@ -55,18 +79,22 @@ Foam::radiation::radiationModel::radiationModel ( "radiationProperties", T.time().constant(), - T.db(), + T.mesh(), IOobject::MUST_READ, IOobject::NO_WRITE ) ), - T_(T), mesh_(T.mesh()), + time_(T.time()), + T_(T), radiation_(lookup("radiation")), - radiationModelCoeffs_(subDict(type + "Coeffs")), + coeffs_(subDict(type + "Coeffs")), + solverFreq_(readLabel(lookup("solverFreq"))), absorptionEmission_(absorptionEmissionModel::New(*this, mesh_)), scatter_(scatterModel::New(*this, mesh_)) -{} +{ + solverFreq_ = max(1, solverFreq_); +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * // @@ -82,7 +110,7 @@ bool Foam::radiation::radiationModel::read() if (regIOobject::read()) { lookup("radiation") >> radiation_; - radiationModelCoeffs_ = subDict(type() + "Coeffs"); + coeffs_ = subDict(type() + "Coeffs"); return true; } @@ -93,6 +121,20 @@ bool Foam::radiation::radiationModel::read() } +void Foam::radiation::radiationModel::correct() +{ + if (!radiation_) + { + return; + } + + if ((time_.timeIndex() == 0) || (time_.timeIndex() % solverFreq_ == 0)) + { + calculate(); + } +} + + Foam::tmp<Foam::fvScalarMatrix> Foam::radiation::radiationModel::Sh ( basicThermo& thermo diff --git a/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.H b/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.H index 4fc4e25c43874d656a5e620150f5e37e5ac920ed..4d01dee1cf158d11c2ce49b21cf3d16aa3934d6c 100644 --- a/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.H +++ b/src/thermophysicalModels/radiation/radiationModel/radiationModel/radiationModel.H @@ -28,7 +28,6 @@ Namespace Description Namespace for radiation modelling - Class Foam::radiation::radiationModel @@ -49,6 +48,7 @@ SourceFiles #include "volFields.H" #include "basicThermo.H" #include "fvMatrices.H" +#include "blackBodyEmission.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -57,33 +57,40 @@ namespace Foam namespace radiation { +// Forward declaration of classes class absorptionEmissionModel; class scatterModel; /*---------------------------------------------------------------------------*\ - Class radiationModel Declaration + Class radiationModel Declaration \*---------------------------------------------------------------------------*/ class radiationModel : public IOdictionary { - protected: // Protected data + //- Reference to the mesh database + const fvMesh& mesh_; + + //- Reference to the time database + const Time& time_; + //- Reference to the temperature field const volScalarField& T_; - //- Reference to the mesh - const fvMesh& mesh_; - //- Model specific dictionary input parameters Switch radiation_; //- Radiation model dictionary - dictionary radiationModelCoeffs_; + dictionary coeffs_; + + //- Radiation solver frequency - number flow solver iterations per + // radiation solver iteration + label solverFreq_; // References to the radiation sub-models @@ -128,34 +135,32 @@ public: // Constructors + //- Null constructor + radiationModel(const volScalarField& T); + //- Construct from components - radiationModel - ( - const word& type, - const volScalarField& T - ); + radiationModel(const word& type, const volScalarField& T); // Selectors //- Return a reference to the selected radiation model - static autoPtr<radiationModel> New - ( - const volScalarField& T - ); - + static autoPtr<radiationModel> New(const volScalarField& T); - // Destructor - virtual ~radiationModel(); + //- Destructor + virtual ~radiationModel(); // Member Functions // Edit + //- Main update/correction routine + virtual void correct(); + //- Solve radiation equation(s) - virtual void correct() = 0; + virtual void calculate() = 0; //- Read radiationProperties dictionary virtual bool read() = 0; @@ -170,10 +175,7 @@ public: virtual tmp<DimensionedField<scalar, volMesh> > Ru() const = 0; //- Enthalpy source term - virtual tmp<fvScalarMatrix> Sh - ( - basicThermo& thermo - ) const; + virtual tmp<fvScalarMatrix> Sh(basicThermo& thermo) const; }; diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.C b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.C index 84e65549ee43abcd85a09721a6b917dd860043ce..f67d0d33891781435ec8fcbd97d4301eea711b60 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.C +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.C @@ -59,14 +59,14 @@ Foam::radiation::absorptionEmissionModel::~absorptionEmissionModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::a() const +Foam::radiation::absorptionEmissionModel::a(const label bandI) const { - return aDisp() + aCont(); + return aDisp(bandI) + aCont(bandI); } Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::aCont() const +Foam::radiation::absorptionEmissionModel::aCont(const label bandI) const { return tmp<volScalarField> ( @@ -89,7 +89,7 @@ Foam::radiation::absorptionEmissionModel::aCont() const Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::aDisp() const +Foam::radiation::absorptionEmissionModel::aDisp(const label bandI) const { return tmp<volScalarField> ( @@ -112,14 +112,14 @@ Foam::radiation::absorptionEmissionModel::aDisp() const Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::e() const +Foam::radiation::absorptionEmissionModel::e(const label bandI) const { - return eDisp() + eCont(); + return eDisp(bandI) + eCont(bandI); } Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::eCont() const +Foam::radiation::absorptionEmissionModel::eCont(const label bandI) const { return tmp<volScalarField> ( @@ -142,7 +142,7 @@ Foam::radiation::absorptionEmissionModel::eCont() const Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::eDisp() const +Foam::radiation::absorptionEmissionModel::eDisp(const label bandI) const { return tmp<volScalarField> ( @@ -165,14 +165,14 @@ Foam::radiation::absorptionEmissionModel::eDisp() const Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::E() const +Foam::radiation::absorptionEmissionModel::E(const label bandI) const { - return EDisp() + ECont(); + return EDisp(bandI) + ECont(bandI); } Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::ECont() const +Foam::radiation::absorptionEmissionModel::ECont(const label bandI) const { return tmp<volScalarField> ( @@ -195,7 +195,7 @@ Foam::radiation::absorptionEmissionModel::ECont() const Foam::tmp<Foam::volScalarField> -Foam::radiation::absorptionEmissionModel::EDisp() const +Foam::radiation::absorptionEmissionModel::EDisp(const label bandI) const { return tmp<volScalarField> ( @@ -217,4 +217,45 @@ Foam::radiation::absorptionEmissionModel::EDisp() const } +Foam::label Foam::radiation::absorptionEmissionModel::nBands() const +{ + return pTraits<label>::one; +} + + +const Foam::Vector2D<Foam::scalar>& +Foam::radiation::absorptionEmissionModel::bands(const label n) const +{ + return Vector2D<scalar>::one; +} + + +bool Foam::radiation::absorptionEmissionModel::isGrey() const +{ + return false; +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::absorptionEmissionModel::addIntensity +( + const label rayI, + const volScalarField& ILambda +) const +{ + return ILambda; +} + + +void Foam::radiation::absorptionEmissionModel::correct +( + volScalarField& a, + PtrList<volScalarField>& aj +) const +{ + a.internalField() = this->a(); + aj[0].internalField() = a.internalField(); +} + + // ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.H index 25596ba4376cf5cb44dba2a68fbf17af91d9e8c7..d7a0230b16a7ee6ca45ebc1ddce3ad8292276234 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/absorptionEmissionModel/absorptionEmissionModel.H @@ -38,6 +38,7 @@ Description #include "autoPtr.H" #include "runTimeSelectionTables.H" #include "volFields.H" +#include "Vector2D.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -95,57 +96,94 @@ public: //- Selector - - static autoPtr<absorptionEmissionModel> New - ( - const dictionary& dict, - const fvMesh& mesh - ); + static autoPtr<absorptionEmissionModel> New + ( + const dictionary& dict, + const fvMesh& mesh + ); //- Destructor - - virtual ~absorptionEmissionModel(); + virtual ~absorptionEmissionModel(); // Member Functions // Access + //- Reference to the mesh + inline const fvMesh& mesh() const + { + return mesh_; + } + + //- Reference to the dictionary + inline const dictionary& dict() const + { + return dict_; + } + + // Absorption coefficient //- Absorption coefficient (net) - virtual tmp<volScalarField> a() const; + virtual tmp<volScalarField> a(const label bandI = 0) const; //- Absorption coefficient for continuous phase - virtual tmp<volScalarField> aCont() const; + virtual tmp<volScalarField> aCont(const label bandI = 0) const; //- Absorption coefficient for dispersed phase - virtual tmp<volScalarField> aDisp() const; + virtual tmp<volScalarField> aDisp(const label bandI = 0) const; // Emission coefficient //- Emission coefficient (net) - virtual tmp<volScalarField> e() const; + virtual tmp<volScalarField> e(const label bandI = 0) const; //- Return emission coefficient for continuous phase - virtual tmp<volScalarField> eCont() const; + virtual tmp<volScalarField> eCont(const label bandI = 0) const; //- Return emission coefficient for dispersed phase - virtual tmp<volScalarField> eDisp() const; + virtual tmp<volScalarField> eDisp(const label bandI = 0) const; // Emission contribution //- Emission contribution (net) - virtual tmp<volScalarField> E() const; + virtual tmp<volScalarField> E(const label bandI = 0) const; //- Emission contribution for continuous phase - virtual tmp<volScalarField> ECont() const; + virtual tmp<volScalarField> ECont(const label bandI = 0) const; //- Emission contribution for dispersed phase - virtual tmp<volScalarField> EDisp() const; + virtual tmp<volScalarField> EDisp(const label bandI = 0) const; + + + //- Const access to the number of bands - defaults to 1 for grey + // absorption/emission + virtual label nBands() const; + + //- Const access to the bands - defaults to Vector2D::one for grey + // absorption/emission + virtual const Vector2D<scalar>& bands(const label n) const; + + //- Flag for whether the absorption/emission is for a grey gas + virtual bool isGrey() const; + + //- Add radiative intensity for ray i + virtual tmp<volScalarField> addIntensity + ( + const label rayI, + const volScalarField& ILambda + ) const; + + //- Correct absorption coefficients + virtual void correct + ( + volScalarField& a, + PtrList<volScalarField>& aj + ) const; }; diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/binaryAbsorptionEmission/binaryAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/binaryAbsorptionEmission/binaryAbsorptionEmission.H index 4aab30405fa6ee8c1f6645815a627d5b19718aba..68ad204b84a3dab0d32d02ab65937fc5e7bee28d 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/binaryAbsorptionEmission/binaryAbsorptionEmission.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/binaryAbsorptionEmission/binaryAbsorptionEmission.H @@ -53,7 +53,6 @@ class binaryAbsorptionEmission : public absorptionEmissionModel { - // Private data //- Coefficients dictionary @@ -83,8 +82,7 @@ public: // Destructor - - ~binaryAbsorptionEmission(); + virtual ~binaryAbsorptionEmission(); // Member Operators diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.C b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.C index 1ab215c6b7fee4679587db4f9cbf2ca841b96515..8809bf03d8dbbc4e3423ea85b6f849de8833cb33 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.C +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.C @@ -70,7 +70,7 @@ Foam::radiation::constantAbsorptionEmission::~constantAbsorptionEmission() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::tmp<Foam::volScalarField> -Foam::radiation::constantAbsorptionEmission::aCont() const +Foam::radiation::constantAbsorptionEmission::aCont(const label bandI) const { tmp<volScalarField> ta ( @@ -95,7 +95,7 @@ Foam::radiation::constantAbsorptionEmission::aCont() const Foam::tmp<Foam::volScalarField> -Foam::radiation::constantAbsorptionEmission::eCont() const +Foam::radiation::constantAbsorptionEmission::eCont(const label bandI) const { tmp<volScalarField> te ( @@ -120,7 +120,7 @@ Foam::radiation::constantAbsorptionEmission::eCont() const Foam::tmp<Foam::volScalarField> -Foam::radiation::constantAbsorptionEmission::ECont() const +Foam::radiation::constantAbsorptionEmission::ECont(const label bandI) const { tmp<volScalarField> tE ( diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.H index 3c54ce29c2eb83d86ba15ebd8b917f2c37ce9a73..f4e7656b027b9f2a42ca7fe16d07251956975205 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/constantAbsorptionEmission/constantAbsorptionEmission.H @@ -54,7 +54,6 @@ class constantAbsorptionEmission : public absorptionEmissionModel { - // Private data //- Absorption model dictionary @@ -87,8 +86,7 @@ public: // Destructor - - ~constantAbsorptionEmission(); + virtual ~constantAbsorptionEmission(); // Member Operators @@ -98,19 +96,27 @@ public: // Absorption coefficient //- Absorption coefficient for continuous phase - tmp<volScalarField> aCont() const; + tmp<volScalarField> aCont(const label bandI = 0) const; // Emission coefficient //- Emission coefficient for continuous phase - tmp<volScalarField> eCont() const; + tmp<volScalarField> eCont(const label bandI = 0) const; // Emission contribution //- Emission contribution for continuous phase - tmp<volScalarField> ECont() const; + tmp<volScalarField> ECont(const label bandI = 0) const; + + + // Member Functions + + inline bool isGrey() const + { + return true; + } }; diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.C b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.C new file mode 100644 index 0000000000000000000000000000000000000000..dccbbbad25064f2f278d6b93a813041fdc8b3d38 --- /dev/null +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.C @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "greyMeanAbsorptionEmission.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace radiation + { + defineTypeNameAndDebug(greyMeanAbsorptionEmission, 0); + + addToRunTimeSelectionTable + ( + absorptionEmissionModel, + greyMeanAbsorptionEmission, + dictionary + ); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::greyMeanAbsorptionEmission::greyMeanAbsorptionEmission +( + const dictionary& dict, + const fvMesh& mesh +) +: + absorptionEmissionModel(dict, mesh), + coeffsDict_((dict.subDict(typeName + "Coeffs"))), + speciesNames_(0), + specieIndex_(0), + lookUpTable_ + ( + fileName(coeffsDict_.lookup("lookUpTableFileName")), + mesh.time().constant(), + mesh + ), + thermo_(mesh.lookupObject<basicThermo>("thermophysicalProperties")), + EhrrCoeff_(readScalar(coeffsDict_.lookup("EhrrCoeff"))), + Yj_(nSpecies_) +{ + label nFunc = 0; + const dictionary& functionDicts = dict.subDict(typeName + "Coeffs"); + + forAllConstIter(dictionary, functionDicts, iter) + { + // safety: + if (!iter().isDict()) + { + continue; + } + const word& key = iter().keyword(); + speciesNames_.insert(key, nFunc); + const dictionary& dict = iter().dict(); + coeffs_[nFunc].initialise(dict); + nFunc++; + } + + // Check that all the species on the dictionary are present in the + // look-up table and save the corresponding indices of the look-up table + + label j = 0; + forAllConstIter(HashTable<label>, speciesNames_, iter) + { + if (mesh.foundObject<volScalarField>("ft")) + { + if (lookUpTable_.found(iter.key())) + { + label index = lookUpTable_.findFieldIndex(iter.key()); + + Info<< "specie: " << iter.key() << " found on look-up table " + << " with index: " << index << endl; + + specieIndex_[iter()] = index; + } + else if (mesh.foundObject<volScalarField>(iter.key())) + { + volScalarField& Y = + const_cast<volScalarField&> + ( + mesh.lookupObject<volScalarField>(iter.key()) + ); + Yj_.set(j, &Y); + specieIndex_[iter()] = 0; + j++; + Info<< "specie: " << iter.key() << " is being solved" << endl; + } + else + { + FatalErrorIn + ( + "Foam::radiation::greyMeanAbsorptionEmission(const" + "dictionary& dict, const fvMesh& mesh)" + ) << "specie: " << iter.key() + << " is neither in look-up table: " + << lookUpTable_.tableName() + << " nor is being solved" << nl + << exit(FatalError); + } + } + else + { + FatalErrorIn + ( + "Foam::radiation::greyMeanAbsorptionEmission(const" + "dictionary& dict, const fvMesh& mesh)" + ) << "specie ft is not present " << nl + << exit(FatalError); + + } + } +} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::radiation::greyMeanAbsorptionEmission::~greyMeanAbsorptionEmission() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::tmp<Foam::volScalarField> +Foam::radiation::greyMeanAbsorptionEmission::aCont(const label bandI) const +{ + const volScalarField& T = thermo_.T(); + const volScalarField& p = thermo_.p(); + const volScalarField& ft = mesh_.lookupObject<volScalarField>("ft"); + + label nSpecies = speciesNames_.size(); + + tmp<volScalarField> ta + ( + new volScalarField + ( + IOobject + ( + "a", + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh(), + dimensionedScalar("a", dimless/dimLength, 0.0) + ) + ); + + scalarField& a = ta().internalField(); + + forAll(a, i) + { + const List<scalar>& species = lookUpTable_.lookUp(ft[i]); + + for (label n=0; n<nSpecies; n++) + { + label l = 0; + scalar Yipi = 0; + if (specieIndex_[n] != 0) + { + //moles x pressure [atm] + Yipi = species[specieIndex_[n]]*p[i]*9.869231e-6; + } + else + { + // mass fraction + Yipi = Yj_[l][i]; + l++; + } + + const absorptionCoeffs::coeffArray& b = coeffs_[n].coeffs(T[i]); + + scalar Ti = T[i]; + // negative temperature exponents + if (coeffs_[n].invTemp()) + { + Ti = 1./T[i]; + } + a[i] += + Yipi + *( + ((((b[5]*Ti + b[4])*Ti + b[3])*Ti + b[2])*Ti + b[1])*Ti + + b[0] + ); + } + } + return ta; +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::greyMeanAbsorptionEmission::eCont(const label bandI) const +{ + tmp<volScalarField> e + ( + new volScalarField + ( + IOobject + ( + "e", + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh(), + dimensionedScalar("e", dimless/dimLength, 0.0) + ) + ); + + return e; +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::greyMeanAbsorptionEmission::ECont(const label bandI) const +{ + tmp<volScalarField> E + ( + new volScalarField + ( + IOobject + ( + "E", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("E", dimMass/dimLength/pow3(dimTime), 0.0) + ) + ); + + if (mesh_.foundObject<volScalarField>("hrr")) + { + const volScalarField& hrr = mesh_.lookupObject<volScalarField>("hrr"); + E().internalField() = EhrrCoeff_*hrr.internalField(); + } + + return E; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H new file mode 100644 index 0000000000000000000000000000000000000000..2c24af42c49d7ceb08cd90209c717cd6183f009e --- /dev/null +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H @@ -0,0 +1,207 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::radiation::greyMeanAbsorptionEmission + +Description + greyMeanAbsorptionEmission radiation absorption and emission coefficients + for continuous phase + + The coefficients for the species in the Look up table have to be specified + for use in moles x P [atm], i.e. (k[i] = species[i]*p*9.869231e-6). + + The coefficients for CO and soot or any other added are multiplied by the + respective mass fraction being solved + + All the species in the dictionary need either to be in the look-up table or + being solved. Conversely, all the species solved do not need to be included + in the calculation of the absorption coefficient + + The names of the species in the absorption dictionary must match exactly the + name in the look-up table or the name of the field being solved + + The look-up table ("speciesTable") file should be in constant + + i.e. dictionary + + LookUpTableFileName "speciesTable"; + + EhrrCoeff 0.0; + + CO2 + { + Tcommon 300.; // Common Temp + invTemp true; // Is the polynomial using inverse temperature? + Tlow 300.; // Low Temp + Thigh 2500.; // High Temp + + loTcoeffs // coeffs for T < Tcommon + ( + 0 // a0 + + 0 // a1*T + + 0 // a2*T^(+/-)2 + + 0 // a3*T^(+/-)3 + + 0 // a4*T^(+/-)4 + + 0 // a5*T^(+/-)5 + + ); + hiTcoeffs // coeffs for T > Tcommon + ( + 18.741 + -121.31e3 + 273.5e6 + -194.05e9 + 56.31e12 + -5.8169e15 + ); + + } + +SourceFiles + greyMeanAbsorptionEmission.C + +\*---------------------------------------------------------------------------*/ + +#ifndef greyMeanAbsorptionEmission_H +#define greyMeanAbsorptionEmission_H + +#include "interpolationLookUpTable.H" +#include "absorptionEmissionModel.H" +#include "HashTable.H" +#include "absorptionCoeffs.H" +#include "basicThermo.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + +/*---------------------------------------------------------------------------*\ + Class greyMeanAbsorptionEmission Declaration +\*---------------------------------------------------------------------------*/ + +class greyMeanAbsorptionEmission +: + public absorptionEmissionModel +{ +public: + + // Public data + + // - Maximum number of species considered for absorptivity + static const int nSpecies_ = 5; + + // Absorption Coefficients + absorptionCoeffs coeffs_[nSpecies_]; + + +private: + + // Private data + + //- Absorption model dictionary + dictionary coeffsDict_; + + //- Hash table of species names + HashTable<label> speciesNames_; + + // Indices of species in the look-up table + FixedList<label, nSpecies_> specieIndex_; + + // Look-up table of species related to ft + mutable interpolationLookUpTable<scalar> lookUpTable_; + + // Thermo package + const basicThermo& thermo_; + + //- Emission constant coefficient + const scalar EhrrCoeff_; + + //- Pointer list of species in the registry involved in the absorption + UPtrList<volScalarField> Yj_; + + +public: + + //- Runtime type information + TypeName("greyMeanAbsorptionEmission"); + + + // Constructors + + //- Construct from components + greyMeanAbsorptionEmission + ( + const dictionary& dict, + const fvMesh& mesh + ); + + + // Destructor + virtual ~greyMeanAbsorptionEmission(); + + + // Member Operators + + // Access + + // Absorption coefficient + + //- Absorption coefficient for continuous phase + tmp<volScalarField> aCont(const label bandI = 0) const; + + + // Emission coefficient + + //- Emission coefficient for continuous phase + tmp<volScalarField> eCont(const label bandI = 0) const; + + + // Emission contribution + + //- Emission contribution for continuous phase + tmp<volScalarField> ECont(const label bandI = 0) const; + + + // Member Functions + + inline bool isGrey() const + { + return true; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace radiation +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/noAbsorptionEmission/noAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/noAbsorptionEmission/noAbsorptionEmission.H index 5e978e862e30ceab36db476a8e308e069816f22e..0010dc98fe5f7babbe81ec47ab948ddc8b39bb42 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/noAbsorptionEmission/noAbsorptionEmission.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/noAbsorptionEmission/noAbsorptionEmission.H @@ -71,8 +71,7 @@ public: // Destructor - - ~noAbsorptionEmission(); + virtual ~noAbsorptionEmission(); }; diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C new file mode 100644 index 0000000000000000000000000000000000000000..a96deeb0b40273b0e69d26305bde5bb38c0f9924 --- /dev/null +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C @@ -0,0 +1,322 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "wideBandAbsorptionEmission.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace radiation + { + defineTypeNameAndDebug(wideBandAbsorptionEmission, 0); + + addToRunTimeSelectionTable + ( + absorptionEmissionModel, + wideBandAbsorptionEmission, + dictionary + ); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission +( + const dictionary& dict, + const fvMesh& mesh +) +: + absorptionEmissionModel(dict, mesh), + coeffsDict_((dict.subDict(typeName + "Coeffs"))), + speciesNames_(0), + specieIndex_(0), + lookUpTable_ + ( + fileName(coeffsDict_.lookup("lookUpTableFileName")), + mesh.time().constant(), + mesh + ), + thermo_(mesh.lookupObject<basicThermo>("thermophysicalProperties")), + Yj_(nSpecies_), + totalWaveLength_(0) +{ + label nBand = 0; + const dictionary& functionDicts = dict.subDict(typeName +"Coeffs"); + forAllConstIter(dictionary, functionDicts, iter) + { + // safety: + if (!iter().isDict()) + { + continue; + } + + const dictionary& dict = iter().dict(); + dict.lookup("bandLimits") >> iBands_[nBand]; + dict.lookup("EhrrCoeff") >> iEhrrCoeffs_[nBand]; + totalWaveLength_ += iBands_[nBand][1] - iBands_[nBand][0]; + + label nSpec = 0; + const dictionary& specDicts = dict.subDict("species"); + forAllConstIter(dictionary, specDicts, iter) + { + const word& key = iter().keyword(); + if (nBand == 0) + { + speciesNames_.insert(key, nSpec); + } + else + { + if (!speciesNames_.found(key)) + { + FatalErrorIn + ( + "Foam::radiation::wideBandAbsorptionEmission(const" + "dictionary& dict, const fvMesh& mesh)" + ) << "specie: " << key << "is not in all the bands" + << nl << exit(FatalError); + } + } + coeffs_[nSpec][nBand].initialise(specDicts.subDict(key)); + nSpec++; + } + nBand++; + } + nBands_ = nBand; + + // Check that all the species on the dictionary are present in the + // look-up table and save the corresponding indices of the look-up table + + label j = 0; + forAllConstIter(HashTable<label>, speciesNames_, iter) + { + if (lookUpTable_.found(iter.key())) + { + label index = lookUpTable_.findFieldIndex(iter.key()); + Info<< "specie: " << iter.key() << " found in look-up table " + << " with index: " << index << endl; + specieIndex_[iter()] = index; + } + else if (mesh.foundObject<volScalarField>(iter.key())) + { + volScalarField& Y = const_cast<volScalarField&> + (mesh.lookupObject<volScalarField>(iter.key())); + + Yj_.set(j, &Y); + + specieIndex_[iter()] = 0.0; + j++; + Info<< "species: " << iter.key() << " is being solved" << endl; + } + else + { + FatalErrorIn + ( + "radiation::wideBandAbsorptionEmission(const" + "dictionary& dict, const fvMesh& mesh)" + ) << "specie: " << iter.key() + << " is neither in look-up table : " + << lookUpTable_.tableName() << " nor is being solved" + << exit(FatalError); + } + } +} + + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::radiation::wideBandAbsorptionEmission::~wideBandAbsorptionEmission() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::tmp<Foam::volScalarField> +Foam::radiation::wideBandAbsorptionEmission::aCont(const label bandI) const +{ + const volScalarField& T = thermo_.T(); + const volScalarField& p = thermo_.p(); + const volScalarField& ft = mesh_.lookupObject<volScalarField>("ft"); + + label nSpecies = speciesNames_.size(); + + tmp<volScalarField> ta + ( + new volScalarField + ( + IOobject + ( + "a", + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh(), + dimensionedScalar("a", dimless/dimLength, 0.0) + ) + ); + + scalarField& a = ta().internalField(); + + forAll(a, i) + { + const List<scalar>& species = lookUpTable_.lookUp(ft[i]); + + for (label n=0; n<nSpecies; n++) + { + label l = 0; + scalar Yipi = 0.0; + if (specieIndex_[n] != 0) + { + // moles x pressure [atm] + Yipi = species[specieIndex_[n]]*p[i]*9.869231e-6; + } + else + { + // mass fraction from species being solved + Yipi = Yj_[l][i]; + l++; + } + + scalar Ti = T[i]; + + const absorptionCoeffs::coeffArray& b = + coeffs_[n][bandI].coeffs(T[i]); + + if (coeffs_[n][bandI].invTemp()) + { + Ti = 1.0/T[i]; + } + + a[i]+= + Yipi + *( + ((((b[5]*Ti + b[4])*Ti + b[3])*Ti + b[2])*Ti + b[1])*Ti + + b[0] + ); + } + } + + return ta; +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::wideBandAbsorptionEmission::eCont(const label bandI) const +{ + tmp<volScalarField> e + ( + new volScalarField + ( + IOobject + ( + "e", + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh(), + dimensionedScalar("e", dimless/dimLength, 0.0) + ) + ); + + return e; +} + + +Foam::tmp<Foam::volScalarField> +Foam::radiation::wideBandAbsorptionEmission::ECont(const label bandI) const +{ + tmp<volScalarField> E + ( + new volScalarField + ( + IOobject + ( + "E", + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh(), + dimensionedScalar("E", dimMass/dimLength/pow3(dimTime), 0.0) + ) + ); + + if (mesh().foundObject<volScalarField>("hrr")) + { + const volScalarField& hrr = mesh().lookupObject<volScalarField>("hrr"); + E().internalField() = + iEhrrCoeffs_[bandI] + *hrr.internalField() + *(iBands_[bandI][1] - iBands_[bandI][0]) + /totalWaveLength_; + } + + return E; +} + +Foam::tmp<Foam::volScalarField> +Foam::radiation::wideBandAbsorptionEmission::addIntensity +( + const label i, + const volScalarField& ILambda +) const +{ + return ILambda*(iBands_[i][1] - iBands_[i][0])/totalWaveLength_; +} + + +void Foam::radiation::wideBandAbsorptionEmission::correct +( + volScalarField& a, + PtrList<volScalarField>& aLambda +) const +{ + a = dimensionedScalar("zero", dimless/dimLength, 0.0); + + for (label j=0; j<nBands_; j++) + { + Info<< "Calculating absorption in band: " << j << endl; + aLambda[j].internalField() = this->a(j); + Info<< "Calculated absorption in band: " << j << endl; + a.internalField() += + aLambda[j].internalField() + *(iBands_[j][1] - iBands_[j][0]) + /totalWaveLength_; + } + +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H new file mode 100644 index 0000000000000000000000000000000000000000..21e10c400b63385c9a047b1d655e1a0f662c8c2f --- /dev/null +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H @@ -0,0 +1,261 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::radiation::greyMeanAbsorptionEmission + +Description + + wideBandAbsorptionEmission radiation absorption and emission coefficients + for continuous phase. + + All the bands should have the same number of species and have to be entered + in the same order. + + There is no check of continuity of the bands. They should not ovelap or + have gaps. + + The emission constant proportionality is specified per band (EhrrCoeff). + + The coefficients for the species in the LookUpTable have to be specified + for use in moles x P [atm].i.e. (k[i] = species[i]*p*9.869231e-6). + + The coefficients for CO and soot or any other added are multiplied by the + respective mass fraction being solved. + + The look Up table file should be in the constant directory. + + band dictionary: + + band0 + { + bandLimits (1.0e-6 2.63e-6); + EhrrCoeff 0.0; + species + { + CH4 + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + CO2 + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + + H2O + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + + Ysoot + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + } + } + + +SourceFiles + wideBandAbsorptionEmission.C + +\*---------------------------------------------------------------------------*/ + +#ifndef wideBandAbsorptionEmission_H +#define wideBandAbsorptionEmission_H + +#include "interpolationLookUpTable.H" +#include "absorptionEmissionModel.H" +#include "HashTable.H" +#include "absorptionCoeffs.H" +#include "basicThermo.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace radiation +{ + +/*---------------------------------------------------------------------------*\ + Class wideBandAbsorptionEmission Declaration +\*---------------------------------------------------------------------------*/ + +class wideBandAbsorptionEmission +: + public absorptionEmissionModel +{ +public: + + // Public data + + //- Maximum number of species considered for absorptivity + static const int nSpecies_ = 5; + + //- Maximum number of bands + static const int maxBands_ = 10; + + //- Absorption coefficients + FixedList<FixedList<absorptionCoeffs, nSpecies_>, maxBands_> coeffs_; + + +private: + + // Private data + + //- Absorption model dictionary + dictionary coeffsDict_; + + //- Hash table with species names + HashTable<label> speciesNames_; + + //- Indices of species in the look-up table + FixedList<label, nSpecies_> specieIndex_; + + //- Bands + FixedList<Vector2D<scalar>, maxBands_> iBands_; + + //- Proportion of the heat released rate emitted + FixedList<scalar, maxBands_> iEhrrCoeffs_; + + //- Look-up table of species related to ft + mutable interpolationLookUpTable<scalar> lookUpTable_; + + //- Thermo package + const basicThermo& thermo_; + + //- Bands + label nBands_; + + //- Pointer list of species being solved involved in the absorption + UPtrList<volScalarField> Yj_; + + // Total wave length covered by the bands + scalar totalWaveLength_; + + +public: + + //- Runtime type information + TypeName("wideBandAbsorptionEmission"); + + + // Constructors + + //- Construct from components + wideBandAbsorptionEmission + ( + const dictionary& dict, + const fvMesh& mesh + ); + + + // Destructor + virtual ~wideBandAbsorptionEmission(); + + + // Member Functions + + // Access + + // Absorption coefficient + + //- Absorption coefficient for continuous phase + tmp<volScalarField> aCont(const label bandI = 0) const; + + + // Emission coefficient + + //- Emission coefficient for continuous phase + tmp<volScalarField> eCont(const label bandI = 0) const; + + + // Emission contribution + + //- Emission contribution for continuous phase + tmp<volScalarField> ECont(const label bandI = 0) const; + + + inline bool isGrey() const + { + return false; + } + + //- Number of bands + inline label nBands() const + { + return nBands_; + } + + //- Lower and upper limit of band i + inline const Vector2D<scalar>& bands(const label i) const + { + return iBands_[i]; + } + + //- Add contribution of ILambda to the total radiative intensity in + // direction i + tmp<volScalarField> addIntensity + ( + const label i, + const volScalarField& ILambda + ) const; + + void correct + ( + volScalarField& a_, + PtrList<volScalarField>& aLambda + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace radiation +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C b/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C index 2f3804afdec02b029f572c2f884f2d086c0c3075..dedf725e247942f7384a9dcd1e758805ef27e271 100644 --- a/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C +++ b/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C @@ -343,7 +343,7 @@ bool Foam::movingConeTopoFvMesh::update() // << endl; { - OFstream str(thisDb().path()/"meshPoints.obj"); + OFstream str(time().timePath()/"meshPoints.obj"); Pout<< "Writing mesh with meshPoints to " << str.name() << endl; @@ -361,7 +361,7 @@ bool Foam::movingConeTopoFvMesh::update() } } { - OFstream str(thisDb().path()/"preMotionPoints.obj"); + OFstream str(time().timePath()/"preMotionPoints.obj"); Pout<< "Writing mesh with preMotionPoints to " << str.name() << endl; diff --git a/src/triSurface/faceTriangulation/faceTriangulation.C b/src/triSurface/faceTriangulation/faceTriangulation.C index f0df3371077d31883cb5fbd1a2bb6a7d6ff2d14c..675ae91db8b559bad6019a491725dcc7219dcb36 100644 --- a/src/triSurface/faceTriangulation/faceTriangulation.C +++ b/src/triSurface/faceTriangulation/faceTriangulation.C @@ -88,7 +88,7 @@ void Foam::faceTriangulation::calcHalfAngle scalar sin = (e0 ^ e1) & normal; - if (sin < -SMALL) + if (sin < -ROOTVSMALL) { // 3rd or 4th quadrant cosHalfAngle = - Foam::sqrt(0.5*(1 + cos)); @@ -366,7 +366,7 @@ Foam::label Foam::faceTriangulation::findStart const vector& rightEdge = edges[right(size, fp)]; const vector leftEdge = -edges[left(size, fp)]; - if (((rightEdge ^ leftEdge) & normal) < SMALL) + if (((rightEdge ^ leftEdge) & normal) < ROOTVSMALL) { scalar cos = rightEdge & leftEdge; if (cos < minCos) diff --git a/tutorials/compressible/rhoCentralFoam/LadenburgJet60psi/system/sampleDict b/tutorials/compressible/rhoCentralFoam/LadenburgJet60psi/system/sampleDict index 39efd421b7d3cdcf9ba43f7ad9aa5e9976df61fc..2c124296c5fe0bea3e4101338fbd04ec46d789d0 100644 --- a/tutorials/compressible/rhoCentralFoam/LadenburgJet60psi/system/sampleDict +++ b/tutorials/compressible/rhoCentralFoam/LadenburgJet60psi/system/sampleDict @@ -19,7 +19,33 @@ interpolationScheme cellPointFace; writeFormat raw; -sampleSets ( face { name cone25 ; axis x ; start ( 0 0 0 ) ; end ( 0.09208087 0.042939 0 ) ; nPoints 92 ; } face { name cone55 ; axis x ; start ( 0.09208087 0.042939 0 ) ; end ( 0.153683 0.13092 0 ) ; nPoints 61 ; } face { name base ; axis x ; start ( 0.153683 0.13092 0 ) ; end ( 0.193675 0.13092 0 ) ; nPoints 40 ; } ); +sampleSets +( + face + { + name cone25; + axis x; + start ( 0 0 0 ); + end ( 0.09208087 0.042939 0 ); + nPoints 92; + } + face + { + name cone55; + axis x; + start ( 0.09208087 0.042939 0 ); + end ( 0.153683 0.13092 0 ); + nPoints 61; + } + face + { + name base; + axis x; + start ( 0.153683 0.13092 0 ); + end ( 0.193675 0.13092 0 ); + nPoints 40; + } +); fields ( p wallHeatTransRate ); diff --git a/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/system/sampleDict b/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/system/sampleDict index d578a3cadd806453a97ffcffaa1d26d6822c92a4..9e80185a572f032cd492521b8284d8fe13ca1c82 100644 --- a/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/system/sampleDict +++ b/tutorials/compressible/rhoCentralFoam/biconic25-55Run35/system/sampleDict @@ -21,7 +21,33 @@ setFormat raw; surfaceFormat vtk; -sets ( cone25 { type face ; axis x ; start ( 0 0 0 ) ; end ( 0.09208087 0.042939 0 ) ; nPoints 92 ; } cone55 { type face ; axis x ; start ( 0.09208087 0.042939 0 ) ; end ( 0.153683 0.13092 0 ) ; nPoints 61 ; } base { type face ; axis x ; start ( 0.153683 0.13092 0 ) ; end ( 0.193675 0.13092 0 ) ; nPoints 40 ; } ); +sets +( + cone25 + { + type face; + axis x; + start ( 0 0 0 ); + end ( 0.09208087 0.042939 0 ); + nPoints 92; + } + cone55 + { + type face; + axis x; + start ( 0.09208087 0.042939 0 ); + end ( 0.153683 0.13092 0 ); + nPoints 61; + } + base + { + type face; + axis x; + start ( 0.153683 0.13092 0 ); + end ( 0.193675 0.13092 0 ); + nPoints 40; + } +); surfaces ( ); diff --git a/tutorials/compressible/rhoCentralFoam/shockTube/system/sampleDict b/tutorials/compressible/rhoCentralFoam/shockTube/system/sampleDict index d8e4f7301d62fdcb2de27a553192f4c058f8a394..f8985b263244f45a632d4565782ce26864aa2dad 100644 --- a/tutorials/compressible/rhoCentralFoam/shockTube/system/sampleDict +++ b/tutorials/compressible/rhoCentralFoam/shockTube/system/sampleDict @@ -21,9 +21,19 @@ setFormat raw; surfaceFormat vtk; -sets ( line { type face ; axis x ; start ( -5 0 0 ) ; end ( 5 0 0 ) ; nPoints 100 ; } ); - -surfaces ( ); +sets +( + line + { + type face; + axis x; + start ( -5 0 0 ); + end ( 5 0 0 ); + nPoints 100; + } +); + +surfaces (); fields ( p U.component(0) T rho ); diff --git a/tutorials/compressible/rhoSonicFoam/shockTube/system/sampleDict b/tutorials/compressible/rhoSonicFoam/shockTube/system/sampleDict index 9d71da62e2e4a3822de0ccbc361e2a9631bc88fd..5f44c51ade6d03cb16b5ff8b5ee51bc48347a0f0 100644 --- a/tutorials/compressible/rhoSonicFoam/shockTube/system/sampleDict +++ b/tutorials/compressible/rhoSonicFoam/shockTube/system/sampleDict @@ -19,9 +19,19 @@ interpolationScheme cellPoint; setFormat raw; -sets ( data { type uniform ; axis x ; start ( -4.995 0 0 ) ; end ( 4.995 0 0 ) ; nPoints 1000 ; } ); +sets +( + data + { + type uniform; + axis x; + start ( -4.995 0 0 ); + end ( 4.995 0 0 ); + nPoints 1000; + } +); -surfaces ( ); +surfaces (); fields ( T magU p ); diff --git a/tutorials/compressible/sonicFoam/laminar/shockTube/system/sampleDict b/tutorials/compressible/sonicFoam/laminar/shockTube/system/sampleDict index 9d71da62e2e4a3822de0ccbc361e2a9631bc88fd..5f44c51ade6d03cb16b5ff8b5ee51bc48347a0f0 100644 --- a/tutorials/compressible/sonicFoam/laminar/shockTube/system/sampleDict +++ b/tutorials/compressible/sonicFoam/laminar/shockTube/system/sampleDict @@ -19,9 +19,19 @@ interpolationScheme cellPoint; setFormat raw; -sets ( data { type uniform ; axis x ; start ( -4.995 0 0 ) ; end ( 4.995 0 0 ) ; nPoints 1000 ; } ); +sets +( + data + { + type uniform; + axis x; + start ( -4.995 0 0 ); + end ( 4.995 0 0 ); + nPoints 1000; + } +); -surfaces ( ); +surfaces (); fields ( T magU p ); diff --git a/tutorials/molecularDynamics/gnemdFoam/Allclean b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/Allclean similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/Allclean rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/Allclean diff --git a/tutorials/molecularDynamics/gnemdFoam/Allrun b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/Allrun similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/Allrun rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/Allrun diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/blockMeshDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/blockMeshDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/blockMeshDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/blockMeshDict diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/boundary b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/boundary similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/boundary rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/constant/polyMesh/boundary diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/controlDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/controlDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/controlDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/controlDict diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSchemes b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSchemes similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSchemes rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSchemes diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSolution b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSolution similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSolution rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/fvSolution diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/mdSolution b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/mdSolution similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/mdSolution rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/mdSolution diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/molConfigDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/molConfigDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/molConfigDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/molConfigDict diff --git a/tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/potentialDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/potentialDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/constrictedChannel/system/potentialDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/constrictedChannel/system/potentialDict diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/blockMeshDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/blockMeshDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/blockMeshDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/blockMeshDict diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/boundary b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/boundary similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/boundary rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/constant/polyMesh/boundary diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/controlDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/controlDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/controlDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/controlDict diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/decomposeParDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/decomposeParDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/decomposeParDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/decomposeParDict diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSchemes b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSchemes similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSchemes rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSchemes diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSolution b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSolution similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSolution rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/fvSolution diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/mdSolution b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/mdSolution similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/mdSolution rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/mdSolution diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/molConfigDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/molConfigDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/molConfigDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/molConfigDict diff --git a/tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/potentialDict b/tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/potentialDict similarity index 100% rename from tutorials/molecularDynamics/gnemdFoam/nanoNozzle/system/potentialDict rename to tutorials/discreteMethods/molecularDynamics/gnemdFoam/nanoNozzle/system/potentialDict diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/Allclean b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/Allclean rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allclean diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/Allrun b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/Allrun rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/Allrun diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/blockMeshDict b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/blockMeshDict similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/blockMeshDict rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/blockMeshDict diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/boundary b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/boundary similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/boundary rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/constant/polyMesh/boundary diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/controlDict b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/controlDict similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/controlDict rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/controlDict diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSchemes b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSchemes similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSchemes rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSchemes diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSolution b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSolution similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSolution rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/fvSolution diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdEquilibrationDict b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdEquilibrationDict similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdEquilibrationDict rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdEquilibrationDict diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdSolution b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdSolution similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdSolution rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/mdSolution diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/molConfigDict b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/molConfigDict similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/molConfigDict rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/molConfigDict diff --git a/tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/potentialDict b/tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/potentialDict similarity index 100% rename from tutorials/molecularDynamics/mdEquilibrationFoam/periodicCube/system/potentialDict rename to tutorials/discreteMethods/molecularDynamics/mdEquilibrationFoam/periodicCube/system/potentialDict diff --git a/tutorials/electromagnetics/mhdFoam/hartmann/system/sampleDict b/tutorials/electromagnetics/mhdFoam/hartmann/system/sampleDict index 9fa14b49198962c11fe51b74e772d8fc31102bbd..f107f4f0ebad5e399ae370dbdb6c8e98a6366c59 100644 --- a/tutorials/electromagnetics/mhdFoam/hartmann/system/sampleDict +++ b/tutorials/electromagnetics/mhdFoam/hartmann/system/sampleDict @@ -19,9 +19,19 @@ interpolationScheme cellPoint; setFormat raw; -sets ( line_centreProfile { type uniform ; axis distance ; start ( 10.001 -1 0.01 ) ; end ( 10.001 1 0.01 ) ; nPoints 100 ; } ); +sets +( + line_centreProfile + { + type uniform; + axis distance; + start ( 10.001 -1 0.01 ); + end ( 10.001 1 0.01 ); + nPoints 100; + } +); -surfaces ( ); +surfaces (); fields ( Ux ); diff --git a/tutorials/incompressible/pimpleFoam/t-junction/0/epsilon b/tutorials/incompressible/pimpleFoam/t-junction/0/epsilon index 2c4cfab1c0ef7e56f4a23057641739d0ef5999e9..5b446a2d8a95af1c6635e1615c267eb0d389fdfc 100644 --- a/tutorials/incompressible/pimpleFoam/t-junction/0/epsilon +++ b/tutorials/incompressible/pimpleFoam/t-junction/0/epsilon @@ -24,7 +24,7 @@ boundaryField inlet { type turbulentMixingLengthDissipationRateInlet; - mixingLength 0.01; + mixingLength 0.01; // 1cm - half channel height value uniform 1; } diff --git a/tutorials/incompressible/pimpleFoam/t-junction/0/k b/tutorials/incompressible/pimpleFoam/t-junction/0/k index 51c0ab7cd30397abad14e0c782189481316cb8c6..ad217bc9e476cda1ff0b268aa0f160f4c13c2701 100644 --- a/tutorials/incompressible/pimpleFoam/t-junction/0/k +++ b/tutorials/incompressible/pimpleFoam/t-junction/0/k @@ -24,7 +24,7 @@ boundaryField inlet { type turbulentIntensityKineticEnergyInlet; - intensity 0.05; + intensity 0.05; // 5% turbulent intensity value uniform 1; } diff --git a/tutorials/incompressible/pimpleFoam/t-junction/0/p b/tutorials/incompressible/pimpleFoam/t-junction/0/p index b3d464605830159b73ceec6b1d2c199c5cf6eab4..2446eb2f7ca708a350ffb6383e6e390e328c42e3 100644 --- a/tutorials/incompressible/pimpleFoam/t-junction/0/p +++ b/tutorials/incompressible/pimpleFoam/t-junction/0/p @@ -22,8 +22,14 @@ boundaryField { inlet { - type totalPressure; - p0 uniform 100040; + //type totalPressure; + //p0 uniform 100040; + + type timeVaryingTotalPressure; + p0 100040; // only used for restarts + outOfBounds clamp; + fileName "$FOAM_CASE/constant/p0vsTime"; + U U; phi phi; rho none; diff --git a/tutorials/incompressible/pimpleFoam/t-junction/constant/p0vsTime b/tutorials/incompressible/pimpleFoam/t-junction/constant/p0vsTime new file mode 100644 index 0000000000000000000000000000000000000000..a9ee6bb3e731e823200464b47f6437328c7f48ef --- /dev/null +++ b/tutorials/incompressible/pimpleFoam/t-junction/constant/p0vsTime @@ -0,0 +1,4 @@ +( + (0 100010) + (1 100040) +) diff --git a/tutorials/incompressible/pimpleFoam/t-junction/constant/turbulenceProperties b/tutorials/incompressible/pimpleFoam/t-junction/constant/turbulenceProperties new file mode 100644 index 0000000000000000000000000000000000000000..a18cc53b5b0174947114313719191445155d7ede --- /dev/null +++ b/tutorials/incompressible/pimpleFoam/t-junction/constant/turbulenceProperties @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 1.5 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object turbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType RASModel; + +// ************************************************************************* // diff --git a/tutorials/incompressible/pimpleFoam/t-junction/system/controlDict b/tutorials/incompressible/pimpleFoam/t-junction/system/controlDict index a5ba827eec16c5ec76ce494560e118be21230596..2d7aaa81da9252399b685813d750274b20462569 100644 --- a/tutorials/incompressible/pimpleFoam/t-junction/system/controlDict +++ b/tutorials/incompressible/pimpleFoam/t-junction/system/controlDict @@ -52,16 +52,24 @@ functions probes { type probes; - name probes; + // Where to load it from functionObjectLibs ( "libsampling.so" ); + // Name of the directory for probe data + name probes; probeLocations ( - ( 1e-06 0 0.01 ) - ( 0.21 -0.20999 0.01 ) - ( 0.21 0.20999 0.01 ) - ( 0.21 0 0.01 ) + ( 1e-06 0 0.01 ) // at inlet + ( 0.21 -0.20999 0.01 ) // at outlet1 + ( 0.21 0.20999 0.01 ) // at outlet2 + ( 0.21 0 0.01 ) // at central block ); + + // Fields to be probed fields ( p U ); + + // Write at same frequency as fields + outputControl outputTime; + outputInterval 1; } } diff --git a/tutorials/multiphase/interFoam/laminar/damBreak/system/setFieldsDict b/tutorials/multiphase/interFoam/laminar/damBreak/system/setFieldsDict index 21e4416d79807159d602cdb72a0f9df7367950ea..d719028fc537ebf98817f8160bf703a6cd95c8eb 100644 --- a/tutorials/multiphase/interFoam/laminar/damBreak/system/setFieldsDict +++ b/tutorials/multiphase/interFoam/laminar/damBreak/system/setFieldsDict @@ -15,9 +15,23 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -defaultFieldValues ( volScalarFieldValue alpha1 0 volVectorFieldValue U ( 0 0 0 ) ); +defaultFieldValues +( + volScalarFieldValue alpha1 0 + volVectorFieldValue U (0 0 0) +); -regions ( boxToCell { box ( 0 0 -1 ) ( 0.1461 0.292 1 ) ; fieldValues ( volScalarFieldValue alpha1 1 ) ; } ); +regions +( + boxToCell + { + box (0 0 -1) (0.1461 0.292 1); + fieldValues + ( + volScalarFieldValue alpha1 1 + ); + } +); // ************************************************************************* // diff --git a/tutorials/multiphase/interFoam/ras/damBreak/system/setFieldsDict b/tutorials/multiphase/interFoam/ras/damBreak/system/setFieldsDict index bafb3a32c09ce67dbcbe79d8e1b4e566f2a991dd..d719028fc537ebf98817f8160bf703a6cd95c8eb 100644 --- a/tutorials/multiphase/interFoam/ras/damBreak/system/setFieldsDict +++ b/tutorials/multiphase/interFoam/ras/damBreak/system/setFieldsDict @@ -15,9 +15,23 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -defaultFieldValues ( volScalarFieldValue gamma 0 volVectorFieldValue U ( 0 0 0 ) ); +defaultFieldValues +( + volScalarFieldValue alpha1 0 + volVectorFieldValue U (0 0 0) +); -regions ( boxToCell { box ( 0 0 -1 ) ( 0.1461 0.292 1 ) ; fieldValues ( volScalarFieldValue gamma 1 ) ; } ); +regions +( + boxToCell + { + box (0 0 -1) (0.1461 0.292 1); + fieldValues + ( + volScalarFieldValue alpha1 1 + ); + } +); // ************************************************************************* // diff --git a/tutorials/stressAnalysis/solidDisplacementFoam/plateHole/system/sampleDict b/tutorials/stressAnalysis/solidDisplacementFoam/plateHole/system/sampleDict index db2a9715f298a40a8e7d5d702733d50106ef7592..b956f363f9e6083a5a8f8addda8d0dd2d295bee0 100644 --- a/tutorials/stressAnalysis/solidDisplacementFoam/plateHole/system/sampleDict +++ b/tutorials/stressAnalysis/solidDisplacementFoam/plateHole/system/sampleDict @@ -19,9 +19,19 @@ interpolationScheme cellPoint; setFormat raw; -sets ( leftPatch { type uniform ; axis y ; start ( 0 0.5 0.25 ) ; end ( 0 2 0.25 ) ; nPoints 100 ; } ); +sets +( + leftPatch + { + type uniform; + axis y; + start ( 0 0.5 0.25 ); + end ( 0 2 0.25 ); + nPoints 100; + } +); -surfaces ( ); +surfaces (); fields ( sigmaxx ); diff --git a/wmake/rules/linux64Gcc/mplibQSMPI b/wmake/rules/linux64Gcc/mplibQSMPI new file mode 100644 index 0000000000000000000000000000000000000000..95ea327379f54d7bab8d03218d9bcf114f63a75b --- /dev/null +++ b/wmake/rules/linux64Gcc/mplibQSMPI @@ -0,0 +1,4 @@ +PFLAGS = +PINC = -I$(MPI_ARCH_PATH)/include +PLIBS = -L$(MPI_ARCH_PATH)/lib -lmpi +