diff --git a/Allwmake b/Allwmake index 12d1ac68913dc4b01967e0ba6f2d96e29b3c98ea..0f69c87181b11004af7fabdbcedaf759fef8c531 100755 --- a/Allwmake +++ b/Allwmake @@ -1,22 +1,21 @@ #!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Parse arguments for library compilation -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments - -wmakeCheckPwd "$WM_PROJECT_DIR" || { - echo "Allwmake error: Current directory is not \$WM_PROJECT_DIR" - echo " The environment variables are inconsistent with the installation." - echo " Check the OpenFOAM entries in your dot-files and source them." +# Run from OPENFOAM top-level directory only +cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR" 2>/dev/null || { + echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR" + echo " Check your OpenFOAM environment and installation" exit 1 } - [ -n "$FOAM_EXT_LIBBIN" ] || { - echo "Allwmake error: FOAM_EXT_LIBBIN not set" - echo " Check the OpenFOAM entries in your dot-files and source them." + echo "Error (${0##*/}) : FOAM_EXT_LIBBIN not set" + echo " Check your OpenFOAM environment and installation" exit 1 } +# Parse arguments for library compilation +. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments + +#------------------------------------------------------------------------------ + # Compile wmake support applications (cd wmake/src && make) diff --git a/applications/Allwmake b/applications/Allwmake index d851254b23a2f237fc5d08e17369e5b2bd25365c..e78e590f9c7d5ce6eea45020350210dd0599ea1c 100755 --- a/applications/Allwmake +++ b/applications/Allwmake @@ -1,22 +1,21 @@ #!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Parse arguments for library compilation -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments - -wmakeCheckPwd "$WM_PROJECT_DIR/applications" || { - echo "Allwmake error: Current directory is not \$WM_PROJECT_DIR/applications" - echo " The environment variables are inconsistent with the installation." - echo " Check the OpenFOAM entries in your dot-files and source them." +# Run from OPENFOAM applications/ directory only +cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/applications" 2>/dev/null || { + echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR/applications" + echo " Check your OpenFOAM environment and installation" exit 1 } - [ -n "$FOAM_EXT_LIBBIN" ] || { - echo "Allwmake error: FOAM_EXT_LIBBIN not set" - echo " Check the OpenFOAM entries in your dot-files and source them." + echo "Error (${0##*/}) : FOAM_EXT_LIBBIN not set" + echo " Check your OpenFOAM environment and installation" exit 1 } +# Parse arguments for library compilation +. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments + +#------------------------------------------------------------------------------ + wmake -all $targetType solvers wmake -all $targetType utilities diff --git a/applications/test/HashPtrTable/Test-hashPtrTable.C b/applications/test/HashPtrTable/Test-hashPtrTable.C index 4b792bbae4fc72719bc40558b6ede1c926c84985..5133d784b18fd09f134de28a24feda41f7f1623b 100644 --- a/applications/test/HashPtrTable/Test-hashPtrTable.C +++ b/applications/test/HashPtrTable/Test-hashPtrTable.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,15 +31,53 @@ Description using namespace Foam; +template<class T> +void printTable(const HashPtrTable<T>& table) +{ + Info<< table.size() << nl << "(" << nl; + + for + ( + typename HashPtrTable<T>::const_iterator iter = table.cbegin(); + iter != table.cend(); + ++iter + ) + { + const T* ptr = *iter; + Info<< iter.key() << " = "; + if (ptr) + { + Info<< *ptr; + } + else + { + Info<< "nullptr"; + } + Info<< nl; + } + + Info<< ")" << endl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main() { - Foam::HashPtrTable<double> myTable; - myTable.insert("hello", new double(42.1)); + HashPtrTable<double> myTable; + myTable.insert("abc", new double(42.1)); + myTable.insert("def", nullptr); + myTable.insert("ghi", new double(3.14159)); + + // Info<< myTable << endl; + printTable(myTable); + + HashPtrTable<double> copy(myTable); - Info<< myTable << endl; + // Info<< copy << endl; + printTable(copy); + Info<< copy << endl; return 0; } diff --git a/applications/test/HashTable/Test-hashTable.C b/applications/test/HashTable/Test-hashTable.C index f4e16fecf38e6ae3f275302fefc760637c73d451..dc2f70658eb43ba2054b9131379bcd6b91c94166 100644 --- a/applications/test/HashTable/Test-hashTable.C +++ b/applications/test/HashTable/Test-hashTable.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,6 +49,8 @@ int main() {"aec", 10.0} }; + // Info<< "\ntable1: " << table1<< endl; + // Erase by key table1.erase("aaw"); @@ -60,7 +62,7 @@ int main() Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl; table1.printInfo(Info) << "table1 [" << table1.size() << "] " << endl; - forAllIter(HashTable<scalar>, table1, iter) + forAllConstIter(HashTable<scalar>, table1, iter) { Info<< iter.key() << " => " << iter() << nl; } @@ -106,7 +108,7 @@ int main() Info<< "\nerase table2 by iterator" << nl; forAllIter(HashTable<scalar>, table2, iter) { - Info<< "erasing " << iter.key() << " => " << iter() << " ... "; + Info<< "erasing " << iter.key() << " => " << iter.object() << " ... "; table2.erase(iter); Info<< "erased" << endl; } diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 65073700ab173bc4caee99792548a0e43f2afd0c..fc8fab51780bbf4d4f36f9cb274ad763fde4ff81 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,7 +42,11 @@ See also #include "vector.H" #include "ListOps.H" -#include<list> +#include "labelRange.H" +#include "ListOps.H" +#include "SubList.H" + +#include <list> using namespace Foam; @@ -61,6 +65,19 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + if (false) + { + labelList intlist(IStringStream("(0 1 2)")()); + Info<<"construct from Istream: " << intlist << endl; + + IStringStream("(3 4 5)")() >> static_cast<labelUList&>(intlist); + Info<<"is >>: " << intlist << endl; + + IStringStream("(6 7 8)")() >> intlist; + Info<<"is >>: " << intlist << endl; + } + + List<vector> list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; diff --git a/applications/test/boundBox/Test-boundBox.C b/applications/test/boundBox/Test-boundBox.C index cb72b9ca87b32d2a285a135e3fc9424676e93cb6..9c06ccf7113fcb8efb0806ac24aba9aed0f07690 100644 --- a/applications/test/boundBox/Test-boundBox.C +++ b/applications/test/boundBox/Test-boundBox.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,8 +40,8 @@ boundBox cube(scalar start, scalar width) { return boundBox ( - point(start, start, start), - point(start + width, start + width, start + width) + point::uniform(start), + point::uniform(start + width) ); } @@ -59,6 +59,69 @@ int main(int argc, char *argv[]) Info<<"boundBox faces: " << boundBox::faces << endl; Info<<"hex faces: " << hex.modelFaces() << endl; + Info<<"tree-bb faces: " << treeBoundBox::faces << endl; + Info<<"tree-bb edges: " << treeBoundBox::edges << endl; + + boundBox bb = boundBox::greatBox; + Info<<"great box: " << bb << endl; + + // bb.clear(); + // Info<<"zero box: " << bb << endl; + + bb = boundBox::invertedBox; + Info<<"invalid box: " << bb << endl; + Info<< nl << endl; + + if (Pstream::parRun()) + { + bb = cube(Pstream::myProcNo(), 1.1); + Pout<<"box: " << bb << endl; + + bb.reduce(); + Pout<<"reduced: " << bb << endl; + } + else + { + bb = cube(0, 1); + Info<<"starting box: " << bb << endl; + + point pt(Zero); + bb.add(pt); + Info<<"enclose point " << pt << " -> " << bb << endl; + + pt = point(0,1.5,0.5); + bb.add(pt); + Info<<"enclose point " << pt << " -> " << bb << endl; + + pt = point(5,2,-2); + bb.add(pt); + Info<<"enclose point " << pt << " -> " << bb << endl; + + // restart with same points + bb = boundBox::invertedBox; + bb.add(point(1,1,1)); + bb.add(point::zero); + bb.add(point(0,1.5,0.5)); + bb.add(point(5,2,-2)); + + Info<<"repeated " << bb << endl; + + boundBox box1 = cube(0, 1); + boundBox box2 = cube(0, 0.75); + boundBox box3 = cube(0.5, 1); + boundBox box4 = cube(-1, 0.5); + + Info<<"union of " << box1 << " and " << box2 << " => "; + + box1.add(box2); + Info<< box1 << endl; + + box1.add(box3); + Info<<"union with " << box3 << " => " << box1 << endl; + + box1.add(box4); + Info<<"union with " << box4 << " => " << box1 << endl; + } return 0; } diff --git a/applications/test/labelRanges/Test-labelRanges.C b/applications/test/labelRanges/Test-labelRanges.C index 9f2be334d1a53a67a6227861395ad627571573e2..dec03a06f0d6f0ab283ad6a2a936e9bee6360494 100644 --- a/applications/test/labelRanges/Test-labelRanges.C +++ b/applications/test/labelRanges/Test-labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) } + labelRange range; labelRanges ranges; bool removeMode = false; @@ -74,14 +75,16 @@ int main(int argc, char *argv[]) continue; } - label start = 0; - label size = 0; + { + label start = 0; + label size = 0; - IStringStream(args[argI])() >> start; - ++argI; - IStringStream(args[argI])() >> size; + IStringStream(args[argI])() >> start; + ++argI; + IStringStream(args[argI])() >> size; - labelRange range(start, size); + range.reset(start, size); + } Info<< "---------------" << nl; if (removeMode) @@ -107,10 +110,11 @@ int main(int argc, char *argv[]) ranges.add(range); } - Info<< "<list>" << ranges << "</list>" << nl; - forAllConstIter(labelRanges, ranges, iter) + Info<< "<list>" << ranges << "</list>" << nl + << "content:"; + for (auto i : ranges) { - Info<< " " << iter(); + Info<< " " << i; } Info<< nl; } diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index ec7defadd36072c0b3ab9dd462f7761016ed9743..cb6333b3d4dbd07b9396339e81b6251836945d65 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -69,6 +69,13 @@ int main(int argc, char *argv[]) Info<<"trimRight: " << stringOps::trimRight(test) << endl; Info<<"trim: " << stringOps::trim(test) << endl; + Info<< nl; + Info<<"camel-case => " << (word("camel") & "case") << nl; + for (const auto& s : { " text with \"spaces'", "08/15 value" }) + { + Info<<"validated \"" << s << "\" => " << word::validated(s) << nl; + } + Info<< nl; // test sub-strings via iterators string::const_iterator iter = test.end(); diff --git a/applications/test/wallDist/Test-wallDist.C b/applications/test/wallDist/Test-wallDist.C index 7a2d4f5cdf44536890ee64b62e57d076afcb6fed..d25bffc0068a951550c71b00a73dc47a2e62442c 100644 --- a/applications/test/wallDist/Test-wallDist.C +++ b/applications/test/wallDist/Test-wallDist.C @@ -66,14 +66,14 @@ int main(int argc, char *argv[]) pointField newPoints(mesh.points()); - const point half(0.5*(meshBb.min() + meshBb.max())); + const point half = meshBb.midpoint(); forAll(newPoints, pointi) { point& pt = newPoints[pointi]; // expand around half - pt.y() += pt.y() - half.y(); + pt.y() += pt.y() - half.y(); } mesh.movePoints(newPoints); diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index d48980cb8c06a4d15a9ea8b33e2980bbd11471e6..c1c5016b35f89083546df2428084603978ee30f5 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,6 +49,9 @@ Usage - \par -dict \<filename\> Specify alternative dictionary for the block mesh description. + - \par -sets + Write cellZones as cellSets too (for processing purposes) + \*---------------------------------------------------------------------------*/ #include "Time.H" @@ -85,7 +88,11 @@ int main(int argc, char *argv[]) "file", "specify alternative dictionary for the blockMesh description" ); - + argList::addBoolOption + ( + "sets", + "write cellZones as cellSets too (for processing purposes)" + ); argList::addNote ( "Block description\n" @@ -187,7 +194,6 @@ int main(int argc, char *argv[]) IOdictionary meshDict(meshDictIO); blockMesh blocks(meshDict, regionName); - if (args.optionFound("blockTopology")) { // Write mesh as edges. @@ -251,7 +257,6 @@ int main(int argc, char *argv[]) defaultFacesType ); - // Read in a list of dictionaries for the merge patch pairs if (meshDict.found("mergePatchPairs")) { @@ -271,8 +276,7 @@ int main(int argc, char *argv[]) // Set any cellZones (note: cell labelling unaffected by above // mergePatchPairs) - label nZones = blocks.numZonedBlocks(); - + const label nZones = blocks.numZonedBlocks(); if (nZones > 0) { Info<< nl << "Adding cell zones" << endl; @@ -325,11 +329,7 @@ int main(int argc, char *argv[]) } } - List<cellZone*> cz(zoneMap.size()); - - Info<< nl << "Writing cell zones as cellSets" << endl; - forAllConstIter(HashTable<label>, zoneMap, iter) { label zoneI = iter(); @@ -341,10 +341,6 @@ int main(int argc, char *argv[]) zoneI, mesh.cellZones() ); - - // Write as cellSet for ease of processing - cellSet cset(mesh, iter.key(), zoneCells[zoneI].shrink()); - cset.write(); } mesh.pointZones().setSize(0); @@ -356,7 +352,14 @@ int main(int argc, char *argv[]) // Set the precision of the points data to 10 IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); - Info<< nl << "Writing polyMesh" << endl; + Info<< nl << "Writing polyMesh with " + << mesh.cellZones().size() << " cellZones"; + if (args.optionFound("sets") && !mesh.cellZones().empty()) + { + Info<< " (written as cellSets too)"; + } + Info<< endl; + mesh.removeFiles(); if (!mesh.write()) { @@ -365,6 +368,14 @@ int main(int argc, char *argv[]) << exit(FatalError); } + if (args.optionFound("sets")) + { + forAll(mesh.cellZones(), zonei) + { + const cellZone& cz = mesh.cellZones()[zonei]; + cellSet(mesh, cz.name(), cz).write(); + } + } // // write some information diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C index 2974598fa43ed6be0ab13d8ace91d2f3f37cc05d..25d9188e015a631bc73e514c8be59097ae35c593 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -719,17 +719,13 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree() Pstream::gatherList(allBackgroundMeshBounds_); Pstream::scatterList(allBackgroundMeshBounds_); - point bbMin(GREAT, GREAT, GREAT); - point bbMax(-GREAT, -GREAT, -GREAT); - + // find global bounding box + globalBackgroundBounds_ = treeBoundBox(boundBox::invertedBox); forAll(allBackgroundMeshBounds_, proci) { - bbMin = min(bbMin, allBackgroundMeshBounds_[proci].min()); - bbMax = max(bbMax, allBackgroundMeshBounds_[proci].max()); + globalBackgroundBounds_.add(allBackgroundMeshBounds_[proci]); } - globalBackgroundBounds_ = treeBoundBox(bbMin, bbMax); - if (false) { OFstream fStr diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C index 11d6cfd523b1a26605d9c940b503422a416b9d0f..cad195d013a0d888d10eca3a369bf1887dd77996 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -558,19 +558,11 @@ Foam::label Foam::checkTopology if (allGeometry) { - const pointField& pts = pp.points(); const labelList& mp = pp.meshPoints(); if (returnReduce(mp.size(), sumOp<label>()) > 0) { - boundBox bb(point::max, point::min); - forAll(mp, i) - { - bb.min() = min(bb.min(), pts[mp[i]]); - bb.max() = max(bb.max(), pts[mp[i]]); - } - reduce(bb.min(), minOp<vector>()); - reduce(bb.max(), maxOp<vector>()); + boundBox bb(pp.points(), mp, true); // reduce Info<< ' ' << bb; } } diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C index 251b6523f4e0a0fc1009be9118ac67cb940937dc..ef68688bf7cd60df7aef8c79a7a319536eb7b9d7 100644 --- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C +++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -336,10 +336,7 @@ boundBox procBounds ) ); - boundBox domainBb(points, false); - - bb.min() = min(bb.min(), domainBb.min()); - bb.max() = max(bb.max(), domainBb.max()); + bb.add(points); } return bb; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean index 23ec6617429b08da4a80273c2bf47cadd16a3b6c..6614154374a3850893706afce944aeb5cb718d1f 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean @@ -1,7 +1,7 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory -wclean libso vtkPVReaders +wclean libso foamPv PVblockMeshReader/Allwclean PVFoamReader/Allwclean diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index df34613a03acb47ddf0ea2b1ac0940ee45d5d87b..13eb3a947067c851d93f12f1ab1765838ddb5a3a 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -7,32 +7,8 @@ export WM_CONTINUE_ON_ERROR=true # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# -# There are several prerequisites for building plugins -# -#set -x -canBuildPlugin() -{ - [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] || { - echo "==> cannot build ParaView plugins without paraview directory" - echo " ParaView_DIR=$ParaView_DIR" - return 1 - } - - [ -n "$PV_PLUGIN_PATH" ] || { - echo "==> ${PWD##*/} : invalid PV_PLUGIN_PATH for building ParaView plugins" - echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-unset}" - return 1 - } - - type cmake > /dev/null 2>&1 || { - echo "==> cannot build ParaView plugins without cmake" - return 1 - } - - return 0 # success -} - +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # ----------------------------------------------------------------------------- @@ -45,9 +21,9 @@ case "$major" in if canBuildPlugin then ( - wmake $targetType vtkPVReaders + wmakeLibPv foamPv PVblockMeshReader/Allwmake $targetType $* - PVFoamReader/Allwmake $targetType $* + PVFoamReader/Allwmake $targetType $* # Dummy directory to trigger proper 'wclean all' behaviour # - the Allwclean will otherwise not be used diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean index f0cd56dee20a9f6965864c15c771caaae5ea9a5c..4df5195cb1204b43d66fe61d131357f68dfc94a0 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwclean @@ -2,17 +2,15 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -#set -x - -# deal with client/server vs combined plugins +# Cleanup client-server and/or combined plugins rm -f $FOAM_LIBBIN/libPVFoamReader* 2>/dev/null rm -rf PVFoamReader/Make # safety: old build location wclean libso vtkPVFoam -# Where are the generated files stored? +# Cleanup generated files findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake index 7788998933d05849534a7d11f84e35d46d0e8fc7..b9f216f54eb020691d29bb4985c710645aad10b5 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/Allwmake @@ -4,49 +4,18 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions - -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" - - -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - - findObjectDir $sourceDir # Where are generated files stored? - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make - ) -} +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions +# ----------------------------------------------------------------------------- if [ -d "$ParaView_DIR" ] then - wmake $targetType vtkPVFoam + wmakeLibPv vtkPVFoam if [ "$targetType" != objects ] then - doCmake $PWD/PVFoamReader || { + cmakePv $PWD/PVFoamReader || { echo echo " WARNING: incomplete build of ParaView OpenFOAM plugin" echo diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt index 49e64bf76ca0ed0959aa7fb07dfe7d97c998acaa..819a476c3ace00544bab68651011ce80fc601b69 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/CMakeLists.txt @@ -1,84 +1,70 @@ -# Create a plugin that adds a reader to the ParaView GUI -# it is added in the file dialog when doing opens/saves. +# Create a plugin to add a reader to the ParaView GUI -# The qrc file is processed by Qt's resource compiler (rcc) -# the qrc file must have a resource prefix of "/ParaViewResources" -# and ParaView will read anything contained under that prefix -# the pqReader.xml file contains xml defining readers with their -# file extensions and descriptions. +cmake_minimum_required(VERSION 2.8) -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +find_package(ParaView REQUIRED) +include(${PARAVIEW_USE_FILE}) -FIND_PACKAGE(ParaView REQUIRED) -INCLUDE(${PARAVIEW_USE_FILE}) - -LINK_DIRECTORIES( +link_directories( $ENV{FOAM_LIBBIN} $ENV{FOAM_EXT_LIBBIN} ) -INCLUDE_DIRECTORIES( +include_directories( $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVFoam + ${PROJECT_SOURCE_DIR}/../../foamPv/lnInclude ) -ADD_DEFINITIONS( - -std=c++0x +add_definitions( + -std=c++11 -DWM_$ENV{WM_PRECISION_OPTION} -DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE} ) # Set output library destination to plugin directory -SET( +set( LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} CACHE INTERNAL "Single output directory for building all libraries." ) -# -# Defined combined plugin -# - -# Extend the auto-generated panel -QT4_WRAP_CPP(MOC_SRCS pqPVFoamReaderPanel.h) +if (PARAVIEW_QT_VERSION VERSION_GREATER "4") + qt5_wrap_cpp(MOC_SRCS + pqFoamReaderControls.h + ) +else() + qt4_wrap_cpp(MOC_SRCS + pqFoamReaderControls.h + ) +endif() -ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS - CLASS_NAME pqPVFoamReaderPanel - XML_NAME PVFoamReader # name of SourceProxy in *SM.xml - XML_GROUP sources +add_paraview_property_group_widget(IFACES0 IFACES0_SRCS + TYPE "openfoam_reader_general_controls" + CLASS_NAME pqFoamReaderControls ) -# Separate GUI_RESOURCE_FILES deprecated with paraview 4.3 -# so check if version < 4.4 +add_paraview_plugin( + PVFoamReader_SM "1.0" + SERVER_MANAGER_XML PVFoamReader_SM.xml + SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx + GUI_INTERFACES + ${IFACES0} + SOURCES + ${IFACES0_SRCS} + ${MOC_SRCS} + pqFoamReaderControls.cxx +) -IF(("${PARAVIEW_VERSION_MAJOR}" LESS 5) AND ("${PARAVIEW_VERSION_MINOR}" LESS 4)) - ADD_PARAVIEW_PLUGIN( - PVFoamReader_SM "1.0" - SERVER_MANAGER_XML PVFoamReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVFoamReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - GUI_RESOURCE_FILES PVFoamReader.xml - ) -ELSE() - ADD_PARAVIEW_PLUGIN( - PVFoamReader_SM "1.0" - SERVER_MANAGER_XML PVFoamReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVFoamReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVFoamReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - ) -ENDIF() -TARGET_LINK_LIBRARIES( +target_link_libraries( PVFoamReader_SM LINK_PUBLIC - vtkPVFoam + vtkPVFoam-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} + foamPv-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} finiteVolume OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc deleted file mode 100644 index 9bb30ea5c092c45aaa7e8b92f157197d91fb1b2f..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/ParaViewResources" > - <file>PVFoamReader.xml</file> - </qresource> -</RCC> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml deleted file mode 100644 index 5507293c67bd74b9dbe0363ce396797a3ea4fc6a..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader.xml +++ /dev/null @@ -1,7 +0,0 @@ -<ParaViewReaders> - <!-- deprecated with paraview-4.3, use hints in *SM.xml --> - <Reader name="PVFoamReader" - extensions="OpenFOAM" - file_description="OpenFOAM Reader"> - </Reader> -</ParaViewReaders> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml index 69bcfc0962555f3b32f8434cf6fd9fd8066514fd..a82c81850fa35a282bd566069b67469b21018d01 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/PVFoamReader_SM.xml @@ -5,14 +5,14 @@ class="vtkPVFoamReader"> <!-- File name - compulsory --> - <StringVectorProperty + <StringVectorProperty animateable="0" name="FileName" command="SetFileName" number_of_elements="1" - animateable="0"> + panel_visibility="never"> <FileListDomain name="files"/> <Documentation> - Specifies the filename for the OpenFOAM Reader. + The filename for the OpenFOAM reader module. </Documentation> </StringVectorProperty> @@ -27,163 +27,168 @@ </Documentation> </DoubleVectorProperty> - <!-- Cache Mesh check-box --> - <IntVectorProperty - name="UiCacheMesh" - command="SetCacheMesh" - number_of_elements="1" - is_internal="1" + <!-- Refresh (push button) --> + <Property + name="Refresh" + command="Refresh" + panel_visibility="default"> + <Documentation>Rescan for updated times/fields.</Documentation> + </Property> + +<!-- General Controls --> + + <!-- Skip Zero Time (check-box) --> + <IntVectorProperty animateable="0" + name="ZeroTime" + label="Skip Zero Time" + command="SetSkipZeroTime" default_values="1" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Cache the fvMesh in memory. + Ignore the 0/ time directory. </Documentation> </IntVectorProperty> - <!-- Refresh button --> - <IntVectorProperty - name="UiRefresh" - command="SetRefresh" - number_of_elements="1" - is_internal="0" + <!-- Include Sets (check-box) --> + <IntVectorProperty animateable="0" + name="IncludeSets" + command="SetIncludeSets" default_values="0" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Rescan for updated timesteps/fields. + Search the polyMesh/sets/ directory </Documentation> </IntVectorProperty> - <!-- Skip Zero Time check-box --> - <IntVectorProperty - name="UiZeroTime" - command="SetSkipZeroTime" - number_of_elements="1" - is_internal="1" + <!-- Include Zones (check-box) --> + <IntVectorProperty animateable="0" + name="IncludeZones" + command="SetIncludeZones" default_values="0" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Skip including the 0/ time directory + ZoneMesh information is used to find {cell,face,point}Zones. + The polyMesh/ directory is only checked on startup. </Documentation> </IntVectorProperty> - <!-- Interpolate Fields check-box --> - <IntVectorProperty - name="UiInterpolateVolFields" - command="SetInterpolateVolFields" + <!-- Show Groups Only (check-box) --> + <IntVectorProperty animateable="0" + name="ShowGroupsOnly" + label="Groups Only" + command="SetShowGroupsOnly" + default_values="0" number_of_elements="1" - is_internal="1" - default_values="1" - animateable="0"> + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Interpolate volume fields into point fields + Show patchGroups only. </Documentation> </IntVectorProperty> - <!-- Extrapolate Patches check-box --> - <IntVectorProperty - name="UiExtrapolatePatches" - command="SetExtrapolatePatches" - number_of_elements="1" - is_internal="1" + <!-- Show Patch Names (check-box) --> + <IntVectorProperty animateable="0" + name="ShowPatchNames" + label="Patch Names" + command="SetShowPatchNames" default_values="0" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Extrapolate internalField to non-constraint patches + Show patch names in render window. </Documentation> </IntVectorProperty> - <!-- Use VTK Polyhedron check-box --> - <IntVectorProperty - name="UseVTKPolyhedron" - command="SetUseVTKPolyhedron" + <!-- Interpolate Fields (check-box) --> + <IntVectorProperty animateable="0" + name="InterpolateFields" + command="SetInterpolateVolFields" + default_values="1" number_of_elements="1" - default_values="0" - animateable="0"> + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Use vtkPolyhedron instead of decomposing polyhedra. + Interpolate volFields into pointFields. </Documentation> </IntVectorProperty> - <!-- Include Sets check-box --> - <IntVectorProperty - name="UiIncludeSets" - command="SetIncludeSets" - number_of_elements="1" - is_internal="1" + <!-- Extrapolate Patches (check-box) --> + <IntVectorProperty animateable="0" + name="ExtrapolatePatches" + command="SetExtrapolatePatches" default_values="0" - animateable="0"> - <Documentation> - Search the polyMesh/sets/ directory - </Documentation> - <BooleanDomain name="bool"/> - </IntVectorProperty> - - <!-- Include Zones check-box --> - <IntVectorProperty - name="UiIncludeZones" - command="SetIncludeZones" number_of_elements="1" - is_internal="1" - default_values="0" - animateable="0"> + panel_visibility="default"> + <BooleanDomain name="bool"/> <Documentation> - ZoneMesh information is used to find {cell,face,point}Zones. - The polyMesh/ directory is only checked on startup. + Extrapolate internalField to non-constraint patches. </Documentation> - <BooleanDomain name="bool"/> </IntVectorProperty> - <!-- Show Patch Names check-box --> - <IntVectorProperty - name="UiShowPatchNames" - command="SetShowPatchNames" - number_of_elements="1" + <!-- Force GUI update (check-box) --> + <IntVectorProperty animateable="0" + name="UpdateGUI" + command="SetUpdateGUI" default_values="0" - is_internal="1" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Show patch names in render window + Force reader GUI update. </Documentation> </IntVectorProperty> - <!-- Show Groups Only check-box --> - <IntVectorProperty - name="UiShowGroupsOnly" - command="SetShowGroupsOnly" - number_of_elements="1" + <!-- Use VTK Polyhedron (check-box) --> + <IntVectorProperty animateable="0" + name="UseVTKPolyhedron" + label="Use VTK Polyhedron" + command="SetUseVTKPolyhedron" default_values="0" - is_internal="1" - animateable="0"> + number_of_elements="1" + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - Show groups only + Use vtkPolyhedron instead of decomposing polyhedra. </Documentation> </IntVectorProperty> - <!-- Force GUI update check box --> - <IntVectorProperty - name="UpdateGUI" - command="SetUpdateGUI" + <!-- Cache Mesh (check-box) --> + <IntVectorProperty animateable="0" + name="CacheMesh" + command="SetCacheMesh" + default_values="1" number_of_elements="1" - is_internal="1" - default_values="0" - animateable="0"> + panel_visibility="default"> <BooleanDomain name="bool"/> <Documentation> - A simple way to cause a reader GUI modification. + Cache the fvMesh in memory. </Documentation> </IntVectorProperty> - <!-- - | Selections - --> + <PropertyGroup + label="General Controls" + panel_widget="openfoam_reader_general_controls"> + <Property name="Refresh"/> + <Property name="ZeroTime"/> + <Property name="IncludeSets"/> + <Property name="IncludeZones"/> + <Property name="InterpolateFields"/> + <Property name="ExtrapolatePatches"/> + <Property name="ShowGroupsOnly"/> + <Property name="ShowPatchNames"/> + <Property name="UpdateGUI"/> + <Property name="UseVTKPolyhedron"/> + <Property name="CacheMesh"/> + </PropertyGroup> + +<!-- Parts Selections --> <!-- Available Parts (volume, patches, lagrangian) array --> <StringVectorProperty @@ -191,7 +196,7 @@ information_only="1"> <ArraySelectionInformationHelper attribute_name="Part"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="PartStatus" label="Mesh Parts" command="SetPartArrayStatus" @@ -199,26 +204,31 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="PartArrayStatus" - animateable="0"> + information_property="PartArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="PartArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> <Documentation> - This property contains a list of the mesh parts - (patches, groups, sets, zones). + The list of mesh parts (patches, groups, sets, zones). </Documentation> </StringVectorProperty> + <PropertyGroup label="Parts"> + <Property name="PartArrayStatus"/> + <Property name="PartStatus"/> + </PropertyGroup> + +<!-- Fields Selections --> + <!-- Available volFields array --> <StringVectorProperty name="VolFieldArrayStatus" information_only="1"> <ArraySelectionInformationHelper attribute_name="VolField"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="VolFieldStatus" label="Volume Fields" command="SetVolFieldArrayStatus" @@ -226,16 +236,13 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="VolFieldArrayStatus" - animateable="0"> + information_property="VolFieldArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="VolFieldArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> - <Documentation> - This property contains a list of the volume fields - </Documentation> + <Documentation>The list of volume fields.</Documentation> </StringVectorProperty> <!-- Available Lagrangian fields array --> @@ -244,7 +251,7 @@ information_only="1"> <ArraySelectionInformationHelper attribute_name="LagrangianField"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="LagrangianFieldStatus" label="Lagrangian Fields" command="SetLagrangianFieldArrayStatus" @@ -252,16 +259,13 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="LagrangianFieldArrayStatus" - animateable="0"> + information_property="LagrangianFieldArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="LagrangianFieldArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> - <Documentation> - This property contains a list of the lagrangian fields - </Documentation> + <Documentation>The list of Lagrangian fields.</Documentation> </StringVectorProperty> <!-- Available pointFields array --> @@ -270,7 +274,7 @@ information_only="1"> <ArraySelectionInformationHelper attribute_name="PointField"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="PointFieldStatus" label="Point Fields" command="SetPointFieldArrayStatus" @@ -278,32 +282,43 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="PointFieldArrayStatus" - animateable="0"> + information_property="PointFieldArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="PointFieldArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> + <Documentation>The list of point fields.</Documentation> + </StringVectorProperty> + + <PropertyGroup label="Fields"> + <Property name="VolFieldArrayStatus"/> + <Property name="VolFieldStatus"/> + <Property name="LagrangianFieldArrayStatus"/> + <Property name="LagrangianFieldStatus"/> + <Property name="PointFieldArrayStatus"/> + <Property name="PointFieldStatus"/> + </PropertyGroup> + +<!-- Miscellaneous --> + + <!-- Print button --> + <Property animateable="0" + name="PrintInfo" + command="PrintInfo" + panel_widget="command_button" + panel_visibility="advanced"> <Documentation> - This property contains a list of the point fields + Print basic information to stdout </Documentation> - </StringVectorProperty> + </Property> <Hints> - <Property name="FileName" show="0"/> - <Property name="UiCacheMesh" show="0"/> - <Property name="UiZeroTime" show="0"/> - <Property name="UiRefresh" show="0"/> - <Property name="UiShowPatchNames" show="0"/> - <Property name="UiShowGroupsOnly" show="0"/> - <Property name="UiIncludeSets" show="0"/> - <Property name="UiIncludeZones" show="0"/> - <ReaderFactory extensions="OpenFOAM" - file_description="OpenFOAM"/> + <ReaderFactory + extensions="OpenFOAM" + file_description="OpenFOAM reader module" /> </Hints> - </SourceProxy> </ProxyGroup> </ServerManagerConfiguration> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3b6fe3da972e3c0e8d2b5607122c23a7ab5bacee --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.cxx @@ -0,0 +1,368 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "pqFoamReaderControls.h" + +#include <QCheckBox> +#include <QFrame> +#include <QGridLayout> +#include <QPushButton> + +#include "pqPVApplicationCore.h" +#include "pqPipelineRepresentation.h" +#include "pqView.h" +#include "vtkSMDocumentation.h" +#include "vtkSMIntVectorProperty.h" +#include "vtkSMPropertyGroup.h" +#include "vtkSMSourceProxy.h" + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// file-scope +static QAbstractButton* setButtonProperties +( + QAbstractButton* b, + vtkSMProperty* prop +) +{ + QString tip; + + vtkSMDocumentation* doc = prop->GetDocumentation(); + if (doc) + { + const char* txt = doc->GetDescription(); + if (txt) + { + tip = QString(txt).simplified(); + } + } + + b->setText(prop->GetXMLLabel()); + if (tip.size()) + { + b->setToolTip(tip); + } + b->setFocusPolicy(Qt::NoFocus); // avoid dotted border + + vtkSMIntVectorProperty* intProp = + vtkSMIntVectorProperty::SafeDownCast(prop); + + // initial checked state for integer (bool) properties + if (intProp) + { + b->setChecked(intProp->GetElement(0)); + } + + return b; +} + + +static vtkSMIntVectorProperty* lookupIntProp +( + vtkSMPropertyGroup* group, + const char* name +) +{ + vtkSMProperty* prop = group->GetProperty(name); + + if (prop) + { + return vtkSMIntVectorProperty::SafeDownCast(prop); + } + + return nullptr; +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void pqFoamReaderControls::fireCommand +( + vtkSMIntVectorProperty* prop, + bool checked +) +{ + vtkSMProxy* pxy = this->proxy(); + + prop->SetElement(0, checked); // Toogle bool + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); +} + + +void pqFoamReaderControls::updateParts() +{ + vtkSMProxy* pxy = this->proxy(); + + pxy->UpdatePropertyInformation(pxy->GetProperty("PartArrayStatus")); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void pqFoamReaderControls::refreshPressed() +{ + vtkSMProxy* pxy = this->proxy(); + + // Fire off command + refresh_->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(refresh_)); + + vtkSMSourceProxy::SafeDownCast(pxy)->UpdatePipeline(); + + // Trigger a rendering (all views) + pqPVApplicationCore::instance()->render(); +} + + +void pqFoamReaderControls::cacheMesh(bool checked) +{ + fireCommand(cacheMesh_, checked); +} + + +void pqFoamReaderControls::showPatchNames(bool checked) +{ + fireCommand(showPatchNames_, checked); + + // update the active view + if (this->view()) + { + this->view()->render(); + } + // OR: update all views + // pqPVApplicationCore::instance()->render(); +} + + +void pqFoamReaderControls::showGroupsOnly(bool checked) +{ + fireCommand(showGroupsOnly_, checked); + updateParts(); +} + + +void pqFoamReaderControls::includeSets(bool checked) +{ + fireCommand(includeSets_, checked); + updateParts(); +} + + +void pqFoamReaderControls::includeZones(bool checked) +{ + fireCommand(includeZones_, checked); + updateParts(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pqFoamReaderControls::pqFoamReaderControls +( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent +) +: + Superclass(proxy, parent), + refresh_(group->GetProperty("Refresh")), + showPatchNames_(lookupIntProp(group, "ShowPatchNames")), + showGroupsOnly_(lookupIntProp(group, "ShowGroupsOnly")), + includeSets_(lookupIntProp(group, "IncludeSets")), + includeZones_(lookupIntProp(group, "IncludeZones")), + cacheMesh_(lookupIntProp(group, "CacheMesh")) +{ + typedef vtkSMIntVectorProperty intProp; + + QGridLayout* form = new QGridLayout(this); + + // ROW + // ~~~ + int row = 0; + + if (refresh_) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, refresh_); + form->addWidget(b, row, 0, Qt::AlignLeft); + + connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); + } + + intProp* zeroTime = lookupIntProp(group, "ZeroTime"); + if (zeroTime) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, zeroTime); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), zeroTime); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + if (includeSets_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, includeSets_); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeSets_); + connect(b, SIGNAL(toggled(bool)), this, SLOT(includeSets(bool))); + } + + if (showGroupsOnly_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showGroupsOnly_); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), showGroupsOnly_); + connect(b, SIGNAL(toggled(bool)), this, SLOT(showGroupsOnly(bool))); + } + + + // ROW + // ~~~ + ++row; + + if (includeZones_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, includeZones_); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), includeZones_); + connect(b, SIGNAL(toggled(bool)), this, SLOT(includeZones(bool))); + } + + if (showPatchNames_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPatchNames_); + form->addWidget(b, row, 1, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPatchNames(bool))); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + intProp* interpolate = lookupIntProp(group, "InterpolateFields"); + if (interpolate) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, interpolate); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), interpolate); + } + + intProp* extrapolate = lookupIntProp(group, "ExtrapolatePatches"); + if (extrapolate) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, extrapolate); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), extrapolate); + } + + // LINE + // ~~~~ + ++row; + { + QFrame* hline = new QFrame(this); + hline->setFrameStyle(QFrame::HLine | QFrame::Sunken); + form->addWidget(hline, row, 0, 1, 4); + } + + // ROW + // ~~~ + ++row; + + intProp* updateGui = lookupIntProp(group, "UpdateGUI"); + if (updateGui) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, updateGui); + form->addWidget(b, row, 0, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(clicked()), updateGui); + } + + intProp* usePolyhedron = lookupIntProp(group, "UseVTKPolyhedron"); + if (usePolyhedron) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, usePolyhedron); + form->addWidget(b, row, 1, Qt::AlignLeft); + + addPropertyLink(b, "checked", SIGNAL(toggled(bool)), usePolyhedron); + } + + if (cacheMesh_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, cacheMesh_); + form->addWidget(b, row, 2, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(cacheMesh(bool))); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pqFoamReaderControls::~pqFoamReaderControls() +{} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h new file mode 100644 index 0000000000000000000000000000000000000000..fc3c8d4044b7eca2ba4cb6ffccf73f6dc5624d64 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqFoamReaderControls.h @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + pqFoamReaderControls + +Description + A custom property group widget for the PVFoamReader. + +SourceFiles + pqFoamReaderControls.cxx + +\*---------------------------------------------------------------------------*/ +#ifndef pqFoamReaderControls_h +#define pqFoamReaderControls_h + +#include "pqPropertyWidget.h" + +// Forward declarations +class vtkSMProperty; +class vtkSMIntVectorProperty; + + +/*---------------------------------------------------------------------------*\ + Class pqFoamReaderControls Declaration +\*---------------------------------------------------------------------------*/ + +class pqFoamReaderControls +: + public pqPropertyWidget +{ + Q_OBJECT; + typedef pqPropertyWidget Superclass; + + // Private data + + //- Refresh (push button) + vtkSMProperty* refresh_; + + //- Show Patch Names (bool property) + vtkSMIntVectorProperty* showPatchNames_; + + //- Show Groups Only (bool property) + vtkSMIntVectorProperty* showGroupsOnly_; + + //- IncludeSets (bool property) + vtkSMIntVectorProperty* includeSets_; + + //- IncludeZones (bool property) + vtkSMIntVectorProperty* includeZones_; + + //- CacheMesh (bool property) + vtkSMIntVectorProperty* cacheMesh_; + + + // Private Member Functions + + //- Update property + void fireCommand(vtkSMProperty* prop); + + //- Toggle and update bool property + void fireCommand(vtkSMIntVectorProperty* prop, bool checked); + + + //- Disallow default bitwise copy construct + pqFoamReaderControls(const pqFoamReaderControls&) = delete; + + //- Disallow default bitwise assignment + void operator=(const pqFoamReaderControls&) = delete; + + +private slots: + + // Private Member Functions + + //- Update "PartArrayStatus" property information + void updateParts(); + + +protected slots: + + // Protected Member Functions + + void refreshPressed(); + void cacheMesh(bool checked); + void showPatchNames(bool checked); + void showGroupsOnly(bool checked); + void includeSets(bool checked); + void includeZones(bool checked); + + +public: + + //- Construct from components + pqFoamReaderControls + ( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent = nullptr + ); + + //- Destructor + virtual ~pqFoamReaderControls(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx deleted file mode 100644 index 521068d4099f4f359fa62037732e294d06eaa184..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.cxx +++ /dev/null @@ -1,485 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "pqPVFoamReaderPanel.h" - -// QT -#include <QGridLayout> -#include <QCheckBox> -#include <QLabel> -#include <QLayout> -#include <QString> -#include <QPushButton> -#include <QtDebug> - -// Paraview <-> QT UI -#include "pqAnimationScene.h" -#include "pqApplicationCore.h" -#include "pqPipelineRepresentation.h" -#include "pqServerManagerModel.h" -#include "pqView.h" - -// Paraview Server Manager -#include "vtkSMDoubleVectorProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMProperty.h" -#include "vtkSMSourceProxy.h" - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -pqPVFoamReaderPanel::pqPVFoamReaderPanel -( - pqProxy *proxy, - QWidget *p -) -: - pqAutoGeneratedObjectPanel(proxy, p) -{ - // create first sublayout (at top of the panel) - QGridLayout* form = new QGridLayout(); - this->PanelLayout->addLayout(form, 0, 0, 1, -1); - - // ROW 0 - // ~~~~~ - - vtkSMProperty* prop = 0; - - // refresh button for updating times/fields - if ((prop = this->proxy()->GetProperty("UiRefresh")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* refresh = new QPushButton("Refresh Times"); - refresh->setToolTip("Rescan for updated times/fields."); - - form->addWidget(refresh, 0, 0, Qt::AlignLeft); - QObject::connect - ( - refresh, - SIGNAL(clicked()), - this, - SLOT(RefreshPressed()) - ); - } - - // checkbox for skip zeroTime - if ((prop = this->proxy()->GetProperty("UiZeroTime")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ZeroTime_ = new QCheckBox("Skip Zero Time"); - ZeroTime_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ZeroTime_->setToolTip - ( - "Skip including the 0/ time directory." - ); - - form->addWidget(ZeroTime_, 0, 1, Qt::AlignLeft); - connect - ( - ZeroTime_, - SIGNAL(stateChanged(int)), - this, - SLOT(ZeroTimeToggled()) - ); - } - - // ROW 1 - // ~~~~~ - - QFrame* hline1 = new QFrame(this); - hline1->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline1, 1, 0, 1, 3); - - // ROW 2 - // ~~~~~ - - // checkbox for caching mesh - if ((prop = this->proxy()->GetProperty("UiCacheMesh")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - CacheMesh_ = new QCheckBox("Cache Mesh"); - CacheMesh_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - CacheMesh_->setToolTip - ( - "Cache the fvMesh in memory." - ); - - form->addWidget(CacheMesh_, 2, 0, Qt::AlignLeft); - connect - ( - CacheMesh_, - SIGNAL(stateChanged(int)), - this, - SLOT(CacheMeshToggled()) - ); - } - - // cell 2,1 empty - - // ROW 3 - // ~~~~~ - - // checkbox for include sets - if ((prop = this->proxy()->GetProperty("UiIncludeSets")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - IncludeSets_ = new QCheckBox("Include Sets"); - IncludeSets_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - IncludeSets_->setToolTip - ( - "Search the polyMesh/sets/ directory." - ); - - // row/col 1,0 - form->addWidget(IncludeSets_, 3, 0, Qt::AlignLeft); - connect - ( - IncludeSets_, - SIGNAL(stateChanged(int)), - this, - SLOT(IncludeSetsToggled()) - ); - } - - // checkbox for Groups Only - if ((prop = this->proxy()->GetProperty("UiShowGroupsOnly")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ShowGroupsOnly_ = new QCheckBox("Groups Only"); - ShowGroupsOnly_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ShowGroupsOnly_->setToolTip - ( - "Show patchGroups only." - ); - - // row/col 2, 2 - form->addWidget(ShowGroupsOnly_, 3, 1, Qt::AlignLeft); - connect - ( - ShowGroupsOnly_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowGroupsOnlyToggled()) - ); - } - - - // ROW 4 - // ~~~~~ - - // checkbox for include zones - if ((prop = this->proxy()->GetProperty("UiIncludeZones")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - IncludeZones_ = new QCheckBox("Include Zones"); - IncludeZones_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - IncludeZones_->setToolTip - ( - "ZoneMesh information is used to find {cell,face,point}Zones. " - "The polyMesh/ directory is only checked on startup." - ); - - // row/col 1,1 - form->addWidget(IncludeZones_, 4, 0, Qt::AlignLeft); - connect - ( - IncludeZones_, - SIGNAL(stateChanged(int)), - this, - SLOT(IncludeZonesToggled()) - ); - } - - // checkbox for patch names - if ((prop = this->proxy()->GetProperty("UiShowPatchNames")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ShowPatchNames_ = new QCheckBox("Patch Names"); - ShowPatchNames_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ShowPatchNames_->setToolTip - ( - "Show patch names in render window." - ); - - // row/col 0,1 - form->addWidget(ShowPatchNames_, 4, 1, Qt::AlignLeft); - connect - ( - ShowPatchNames_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowPatchNamesToggled()) - ); - } - - // ROW 5 - // ~~~~~ - - QFrame* hline2 = new QFrame(this); - hline2->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline2, 5, 0, 1, 3); - - // ROW 6 - // ~~~~~ - - // checkbox for vol field interpolation - if ((prop = this->proxy()->GetProperty("UiInterpolateVolFields")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - InterpolateVolFields_ = new QCheckBox("Interpolate volFields"); - InterpolateVolFields_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - InterpolateVolFields_->setToolTip - ( - "Interpolate volFields into pointFields" - ); - - // row/col 1,1 - form->addWidget(InterpolateVolFields_, 6, 0, Qt::AlignLeft); - connect - ( - InterpolateVolFields_, - SIGNAL(stateChanged(int)), - this, - SLOT(InterpolateVolFieldsToggled()) - ); - } - - // checkbox for extrapolate patches - if ((prop = this->proxy()->GetProperty("UiExtrapolatePatches")) != 0) - { - // immediate update on the Server Manager side - prop->SetImmediateUpdate(true); - - ExtrapolatePatches_ = new QCheckBox("Extrapolate Patches"); - ExtrapolatePatches_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - ExtrapolatePatches_->setToolTip - ( - "Extrapolate internalField to non-constraint patches" - ); - - // row/col 1,1 - form->addWidget(ExtrapolatePatches_, 6, 1, Qt::AlignLeft); - connect - ( - ExtrapolatePatches_, - SIGNAL(stateChanged(int)), - this, - SLOT(ExtrapolatePatchesToggled()) - ); - } - - // ROW 7 - // ~~~~~ - - QFrame* hline3 = new QFrame(this); - hline3->setFrameStyle(QFrame::HLine | QFrame::Sunken); - form->addWidget(hline3, 7, 0, 1, 3); - - // update GUI button - if ((prop = this->proxy()->GetProperty("UpdateGUI")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* updateGUI = new QPushButton("Update GUI"); - updateGUI->setToolTip("Update GUI"); - - form->addWidget(updateGUI, 8, 0, Qt::AlignLeft); - QObject::connect - ( - updateGUI, - SIGNAL(clicked()), - this, - SLOT(setModified()) - ); - } -} - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -void pqPVFoamReaderPanel::CacheMeshToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiCacheMesh") - )->SetElement(0, CacheMesh_->isChecked()); -} - - -void pqPVFoamReaderPanel::RefreshPressed() -{ - // update everything - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiRefresh") - )->Modified(); - - vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); - - // render all views - pqApplicationCore::instance()->render(); -} - - -void pqPVFoamReaderPanel::ZeroTimeToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiZeroTime") - )->SetElement(0, ZeroTime_->isChecked()); - - this->setModified(); -} - - -void pqPVFoamReaderPanel::ShowPatchNamesToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowPatchNames") - )->SetElement(0, ShowPatchNames_->isChecked()); - - // update the active view - if (this->view()) - { - this->view()->render(); - } - // OR: update all views - // pqApplicationCore::instance()->render(); -} - - -void pqPVFoamReaderPanel::ShowGroupsOnlyToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowGroupsOnly") - )->SetElement(0, ShowGroupsOnly_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::IncludeSetsToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiIncludeSets") - )->SetElement(0, IncludeSets_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::IncludeZonesToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiIncludeZones") - )->SetElement(0, IncludeZones_->isChecked()); - - if ((prop = this->proxy()->GetProperty("PartArrayStatus")) != 0) - { - this->proxy()->UpdatePropertyInformation(prop); - } -} - - -void pqPVFoamReaderPanel::ExtrapolatePatchesToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiExtrapolatePatches") - )->SetElement(0, ExtrapolatePatches_->isChecked()); - - this->setModified(); -} - - -void pqPVFoamReaderPanel::InterpolateVolFieldsToggled() -{ - vtkSMProperty* prop; - - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiInterpolateVolFields") - )->SetElement(0, InterpolateVolFields_->isChecked()); - - this->setModified(); -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h deleted file mode 100644 index 6ca0f3f7a5adbc8f80cfa1ba19a9752150491f86..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/pqPVFoamReaderPanel.h +++ /dev/null @@ -1,116 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Class - pqPVFoamReaderPanel - -Description - GUI modifications for the ParaView reader panel - - A custom panel for the PVFoamReader. - -SourceFiles - pqPVFoamReaderPanel.cxx - -\*---------------------------------------------------------------------------*/ -#ifndef pqPVFoamReaderPanel_h -#define pqPVFoamReaderPanel_h - - -#include "pqAutoGeneratedObjectPanel.h" - -// Forward declaration of QT classes - -class QCheckBox; -class QLineEdit; -class QTimer; -class QToolButton; - -// Forward declaration of ParaView classes -class vtkSMSourceProxy; - - -/*---------------------------------------------------------------------------*\ - Class pqPVFoamReaderPanel Declaration -\*---------------------------------------------------------------------------*/ - -class pqPVFoamReaderPanel -: - public pqAutoGeneratedObjectPanel -{ - // Private data - Q_OBJECT; - typedef pqAutoGeneratedObjectPanel Superclass; - - //- ZeroTime checkbox - QCheckBox* ZeroTime_; - - //- CacheMesh checkbox - QCheckBox* CacheMesh_; - - //- Show Patch Names checkbox - QCheckBox* ShowPatchNames_; - - //- Show Groups Only checkbox - QCheckBox* ShowGroupsOnly_; - - //- IncludeSets checkbox - QCheckBox* IncludeSets_; - - //- IncludeZones checkbox - QCheckBox* IncludeZones_; - - //- InterpolateVolFields checkbox - QCheckBox* InterpolateVolFields_; - - //- ExtrapolatePatches checkbox - QCheckBox* ExtrapolatePatches_; - - -protected slots: - - void CacheMeshToggled(); - void ZeroTimeToggled(); - void RefreshPressed(); - void ShowPatchNamesToggled(); - void ShowGroupsOnlyToggled(); - void IncludeSetsToggled(); - void IncludeZonesToggled(); - void InterpolateVolFieldsToggled(); - void ExtrapolatePatchesToggled(); - - -public: - - // Constructors - - //- Construct from components - pqPVFoamReaderPanel(pqProxy*, QWidget*); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx index 6b539c5a680b47190e6b5150f7cd5a3dbccf205e..46c01d92f7dfb5bff0a28e31fb9dd764374eda30 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.cxx @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,6 +33,7 @@ License #include "vtkDataArraySelection.h" #include "vtkInformation.h" #include "vtkInformationVector.h" +#include "vtkInformationDoubleVectorKey.h" #include "vtkMultiBlockDataSet.h" #include "vtkObjectFactory.h" #include "vtkSMRenderViewProxy.h" @@ -42,6 +43,9 @@ License // OpenFOAM includes #include "vtkPVFoam.H" +// STL includes +#include <vector> + #undef EXPERIMENTAL_TIME_CACHING // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -58,10 +62,9 @@ vtkPVFoamReader::vtkPVFoamReader() SetNumberOfInputPorts(0); - FileName = nullptr; - foamData_ = nullptr; - - output0_ = nullptr; + FileName = nullptr; + backend_ = nullptr; + output0_ = nullptr; #ifdef VTKPVFOAM_DUALPORT // Add second output for the Lagrangian @@ -76,19 +79,18 @@ vtkPVFoamReader::vtkPVFoamReader() TimeStepRange[0] = 0; TimeStepRange[1] = 0; - CacheMesh = 1; - Refresh = 0; + CacheMesh = true; - SkipZeroTime = 0; - ExtrapolatePatches = 0; - UseVTKPolyhedron = 0; - IncludeSets = 0; - IncludeZones = 0; - ShowPatchNames = 0; - ShowGroupsOnly = 0; - InterpolateVolFields = 1; + SkipZeroTime = false; + ExtrapolatePatches = false; + UseVTKPolyhedron = false; + IncludeSets = false; + IncludeZones = false; + ShowPatchNames = false; + ShowGroupsOnly = false; + InterpolateVolFields = true; - UpdateGUI = 0; + UpdateGUI = false; PartSelection = vtkDataArraySelection::New(); VolFieldSelection = vtkDataArraySelection::New(); @@ -133,11 +135,13 @@ vtkPVFoamReader::~vtkPVFoamReader() { vtkDebugMacro(<<"Deconstructor"); - if (foamData_) + if (backend_) { - // remove patch names + // Remove text actors updatePatchNamesView(false); - delete foamData_; + + delete backend_; + backend_ = nullptr; } if (FileName) @@ -151,10 +155,10 @@ vtkPVFoamReader::~vtkPVFoamReader() } - PartSelection->RemoveObserver(this->SelectionObserver); - VolFieldSelection->RemoveObserver(this->SelectionObserver); - PointFieldSelection->RemoveObserver(this->SelectionObserver); - LagrangianFieldSelection->RemoveObserver(this->SelectionObserver); + PartSelection->RemoveAllObservers(); + VolFieldSelection->RemoveAllObservers(); + PointFieldSelection->RemoveAllObservers(); + LagrangianFieldSelection->RemoveAllObservers(); SelectionObserver->Delete(); @@ -188,7 +192,7 @@ int vtkPVFoamReader::RequestInformation return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -199,60 +203,70 @@ int vtkPVFoamReader::RequestInformation } } - if (!foamData_) + if (backend_) { - foamData_ = new Foam::vtkPVFoam(FileName, this); + backend_->updateInfo(); } else { - foamData_->updateInfo(); + backend_ = new Foam::vtkPVFoam(FileName, this); } - int nTimeSteps = 0; - double* timeSteps = foamData_->findTimes(nTimeSteps); + std::vector<double> times = backend_->findTimes(this->SkipZeroTime); - if (!nTimeSteps) + if (times.empty()) { vtkErrorMacro("could not find valid OpenFOAM mesh"); // delete foamData and flag it as fatal error - delete foamData_; - foamData_ = nullptr; + delete backend_; + backend_ = nullptr; return 0; } // set identical time steps for all ports for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_STEPS(), - timeSteps, - nTimeSteps + times.data(), + static_cast<int>(times.size()) ); + + // Something like this may be useful: + // outInfo->Set + // ( + // vtkStreamingDemandDrivenPipeline::TIME_DEPENDENT_INFORMATION(), + // 1 + // ); } - if (nTimeSteps) + if (times.size()) { - double timeRange[2]; - timeRange[0] = timeSteps[0]; - timeRange[1] = timeSteps[nTimeSteps-1]; + double timeRange[2]{ times.front(), times.back() }; if (Foam::vtkPVFoam::debug > 1) { - cout<<"nTimeSteps " << nTimeSteps << "\n" - <<"timeRange " << timeRange[0] << " to " << timeRange[1] - << "\n"; + cout + <<"nInfo " << nInfo << "\n" + <<"time-range " << times.front() << ':' << times.back() << "\n" + <<"times " << times.size() << "("; - for (int timeI = 0; timeI < nTimeSteps; ++timeI) + for (const double& val : times) { - cout<< "step[" << timeI << "] = " << timeSteps[timeI] << "\n"; + cout<< ' ' << val; } + cout << " )" << std::endl; } for (int infoI = 0; infoI < nInfo; ++infoI) { - outputVector->GetInformationObject(infoI)->Set + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + outInfo->Set ( vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, @@ -261,8 +275,6 @@ int vtkPVFoamReader::RequestInformation } } - delete timeSteps; - return 1; } @@ -282,15 +294,14 @@ int vtkPVFoamReader::RequestData vtkErrorMacro("FileName has to be specified!"); return 0; } - - // catch previous error - if (!foamData_) + if (!backend_) { + // catch some previous error vtkErrorMacro("Reader failed - perhaps no mesh?"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); + const int nInfo = outputVector->GetNumberOfInformationObjects(); if (Foam::vtkPVFoam::debug) { @@ -315,23 +326,31 @@ int vtkPVFoamReader::RequestData { vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + int nsteps = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()); + if ( outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) - && outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) > 0 + && nsteps > 0 ) { - requestTime[nRequestTime++] = - outInfo->Get - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP() - ); + requestTime[nRequestTime] = + ( + 1 == nsteps + // Only one time-step available, UPDATE_TIME_STEP is unreliable + ? outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), 0) + : outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) + ); + + // outInfo->Set(vtkDataObject::DATA_TIME_STEP(), requestTime[nRequestTime]); + // this->SetTimeValue(requestedTimeValue); + ++nRequestTime; } } if (nRequestTime) { - foamData_->setTime(nRequestTime, requestTime); + backend_->setTime(nRequestTime, requestTime); } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast @@ -362,7 +381,7 @@ int vtkPVFoamReader::RequestData // but trashes the fields and still triggers the GeometryFilter if (needsUpdate) { - foamData_->Update(output); + backend_->Update(output); output0_->ShallowCopy(output); } else @@ -391,7 +410,7 @@ int vtkPVFoamReader::RequestData #else #ifdef VTKPVFOAM_DUALPORT - foamData_->Update + backend_->Update ( output, vtkMultiBlockDataSet::SafeDownCast @@ -403,7 +422,7 @@ int vtkPVFoamReader::RequestData ); ); #else - foamData_->Update(output, output); + backend_->Update(output, output); #endif updatePatchNamesView(ShowPatchNames); @@ -411,45 +430,60 @@ int vtkPVFoamReader::RequestData #endif // Do any cleanup on the OpenFOAM side - foamData_->CleanUp(); + backend_->CleanUp(); return 1; } -void vtkPVFoamReader::SetRefresh(int val) +void vtkPVFoamReader::PrintInfo() +{ + if (backend_) + { + backend_->printInfo(); + } + else + { + cout + <<"OpenFOAM reader not initialized\n" + << std::flush; + } +} + + +void vtkPVFoamReader::Refresh() { Modified(); } -void vtkPVFoamReader::SetIncludeSets(int val) +void vtkPVFoamReader::SetIncludeSets(bool val) { if (IncludeSets != val) { IncludeSets = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } -void vtkPVFoamReader::SetIncludeZones(int val) +void vtkPVFoamReader::SetIncludeZones(bool val) { if (IncludeZones != val) { IncludeZones = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } -void vtkPVFoamReader::SetShowPatchNames(int val) +void vtkPVFoamReader::SetShowPatchNames(bool val) { if (ShowPatchNames != val) { @@ -459,14 +493,14 @@ void vtkPVFoamReader::SetShowPatchNames(int val) } -void vtkPVFoamReader::SetShowGroupsOnly(int val) +void vtkPVFoamReader::SetShowGroupsOnly(bool val) { if (ShowGroupsOnly != val) { ShowGroupsOnly = val; - if (foamData_) + if (backend_) { - foamData_->updateInfo(); + backend_->updateInfo(); } } } @@ -485,7 +519,7 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) // Server manager model for querying items in the server manager pqServerManagerModel* smModel = appCore->getServerManagerModel(); - if (!smModel || !foamData_) + if (!smModel || !backend_) { return; } @@ -495,14 +529,14 @@ void vtkPVFoamReader::updatePatchNamesView(const bool show) for (int viewI=0; viewI < renderViews.size(); ++viewI) { - foamData_->renderPatchNames + backend_->renderPatchNames ( renderViews[viewI]->getRenderViewProxy()->GetRenderer(), show ); } - // use refresh here? + // Use refresh here? } @@ -514,7 +548,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) os << indent << "File name: " << (this->FileName ? this->FileName : "(none)") << "\n"; - foamData_->PrintSelf(os, indent); + backend_->PrintSelf(os, indent); os << indent << "Time step range: " << this->TimeStepRange[0] << " - " << this->TimeStepRange[1] << "\n" @@ -524,7 +558,7 @@ void vtkPVFoamReader::PrintSelf(ostream& os, vtkIndent indent) int vtkPVFoamReader::GetTimeStep() { - return foamData_ ? foamData_->timeIndex() : -1; + return backend_ ? backend_->timeIndex() : -1; } @@ -533,32 +567,24 @@ int vtkPVFoamReader::GetTimeStep() vtkDataArraySelection* vtkPVFoamReader::GetPartSelection() { - vtkDebugMacro(<<"GetPartSelection"); return PartSelection; } - int vtkPVFoamReader::GetNumberOfPartArrays() { - vtkDebugMacro(<<"GetNumberOfPartArrays"); return PartSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPartArrayName(int index) { - vtkDebugMacro(<<"GetPartArrayName"); return PartSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPartArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPartArrayStatus"); return PartSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) { vtkDebugMacro("Set mesh part \"" << name << "\" status to: " << status); @@ -579,35 +605,26 @@ void vtkPVFoamReader::SetPartArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetVolFieldSelection() { - vtkDebugMacro(<<"GetVolFieldSelection"); return VolFieldSelection; } - int vtkPVFoamReader::GetNumberOfVolFieldArrays() { - vtkDebugMacro(<<"GetNumberOfVolFieldArrays"); return VolFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetVolFieldArrayName(int index) { - vtkDebugMacro(<<"GetVolFieldArrayName"); return VolFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetVolFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetVolFieldArrayStatus"); return VolFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetVolFieldArrayStatus"); if (status) { VolFieldSelection->EnableArray(name); @@ -624,35 +641,26 @@ void vtkPVFoamReader::SetVolFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetPointFieldSelection() { - vtkDebugMacro(<<"GetPointFieldSelection"); return PointFieldSelection; } - int vtkPVFoamReader::GetNumberOfPointFieldArrays() { - vtkDebugMacro(<<"GetNumberOfPointFieldArrays"); return PointFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetPointFieldArrayName(int index) { - vtkDebugMacro(<<"GetPointFieldArrayName"); return PointFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetPointFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetPointFieldArrayStatus"); return PointFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) { - vtkDebugMacro(<<"SetPointFieldArrayStatus"); if (status) { PointFieldSelection->EnableArray(name); @@ -669,39 +677,30 @@ void vtkPVFoamReader::SetPointFieldArrayStatus(const char* name, int status) vtkDataArraySelection* vtkPVFoamReader::GetLagrangianFieldSelection() { - vtkDebugMacro(<<"GetLagrangianFieldSelection"); return LagrangianFieldSelection; } - int vtkPVFoamReader::GetNumberOfLagrangianFieldArrays() { - vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays"); return LagrangianFieldSelection->GetNumberOfArrays(); } - const char* vtkPVFoamReader::GetLagrangianFieldArrayName(int index) { - vtkDebugMacro(<<"GetLagrangianFieldArrayName"); return LagrangianFieldSelection->GetArrayName(index); } - int vtkPVFoamReader::GetLagrangianFieldArrayStatus(const char* name) { - vtkDebugMacro(<<"GetLagrangianFieldArrayStatus"); return LagrangianFieldSelection->ArrayIsEnabled(name); } - void vtkPVFoamReader::SetLagrangianFieldArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetLagrangianFieldArrayStatus"); if (status) { LagrangianFieldSelection->EnableArray(name); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h index d29b80e1ff229886342f223350eabe6825714165..c634f667fbed06eef77307d64b11170c2f5a73ef 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/PVFoamReader/vtkPVFoamReader.h @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,59 +77,63 @@ public: vtkSetStringMacro(FileName); vtkGetStringMacro(FileName); + // Description: + // Print some case information + virtual void PrintInfo(); + // Description: // OpenFOAM mesh caching control - vtkSetMacro(CacheMesh, int); - vtkGetMacro(CacheMesh, int); + vtkSetMacro(CacheMesh, bool); + vtkGetMacro(CacheMesh, bool); // Description: // OpenFOAM refresh times/fields - virtual void SetRefresh(int); + virtual void Refresh(); // Description: // OpenFOAM skip/include the 0/ time directory - vtkSetMacro(SkipZeroTime, int); - vtkGetMacro(SkipZeroTime, int); + vtkSetMacro(SkipZeroTime, bool); + vtkGetMacro(SkipZeroTime, bool); // Description: // GUI update control - vtkSetMacro(UpdateGUI, int); - vtkGetMacro(UpdateGUI, int); + vtkSetMacro(UpdateGUI, bool); + vtkGetMacro(UpdateGUI, bool); // Description: // OpenFOAM extrapolate internal values onto the patches - vtkSetMacro(ExtrapolatePatches, int); - vtkGetMacro(ExtrapolatePatches, int); + vtkSetMacro(ExtrapolatePatches, bool); + vtkGetMacro(ExtrapolatePatches, bool); // Description: // OpenFOAM use vtkPolyhedron instead of decomposing polyhedra - vtkSetMacro(UseVTKPolyhedron, int); - vtkGetMacro(UseVTKPolyhedron, int); + vtkSetMacro(UseVTKPolyhedron, bool); + vtkGetMacro(UseVTKPolyhedron, bool); // Description: // OpenFOAM read sets control - virtual void SetIncludeSets(int); - vtkGetMacro(IncludeSets, int); + virtual void SetIncludeSets(bool); + vtkGetMacro(IncludeSets, bool); // Description: // OpenFOAM read zones control - virtual void SetIncludeZones(int); - vtkGetMacro(IncludeZones, int); + virtual void SetIncludeZones(bool); + vtkGetMacro(IncludeZones, bool); // Description: // OpenFOAM display patch names control - virtual void SetShowPatchNames(int); - vtkGetMacro(ShowPatchNames, int); + virtual void SetShowPatchNames(bool); + vtkGetMacro(ShowPatchNames, bool); // Description: // OpenFOAM display patchGroups - virtual void SetShowGroupsOnly(int); - vtkGetMacro(ShowGroupsOnly, int); + virtual void SetShowGroupsOnly(bool); + vtkGetMacro(ShowGroupsOnly, bool); // Description: // OpenFOAM volField interpolation - vtkSetMacro(InterpolateVolFields, int); - vtkGetMacro(InterpolateVolFields, int); + vtkSetMacro(InterpolateVolFields, bool); + vtkGetMacro(InterpolateVolFields, bool); // Description: // Get the current timestep @@ -218,29 +222,28 @@ protected: private: //- Disallow default bitwise copy construct - vtkPVFoamReader(const vtkPVFoamReader&); + vtkPVFoamReader(const vtkPVFoamReader&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVFoamReader&); + void operator=(const vtkPVFoamReader&) = delete; //- Add/remove patch names to/from the view void updatePatchNamesView(const bool show); int TimeStepRange[2]; - int Refresh; - int CacheMesh; - int SkipZeroTime; - - int ExtrapolatePatches; - int UseVTKPolyhedron; - int IncludeSets; - int IncludeZones; - int ShowPatchNames; - int ShowGroupsOnly; - int InterpolateVolFields; + bool CacheMesh; + bool SkipZeroTime; + + bool ExtrapolatePatches; + bool UseVTKPolyhedron; + bool IncludeSets; + bool IncludeZones; + bool ShowPatchNames; + bool ShowGroupsOnly; + bool InterpolateVolFields; //- Dummy variable/switch to invoke a reader update - int UpdateGUI; + bool UpdateGUI; vtkDataArraySelection* PartSelection; vtkDataArraySelection* VolFieldSelection; @@ -250,9 +253,8 @@ private: //- Cached data for output port0 (experimental!) vtkMultiBlockDataSet* output0_; - //BTX - Foam::vtkPVFoam* foamData_; - //ETX + //- Backend portion of the reader + Foam::vtkPVFoam* backend_; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files index b26829761d796f7fb3dbc70fb6c1e5a4ff822c87..c159826919ea6fd22ad9e430bfdf49928b42979b 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/files @@ -2,10 +2,7 @@ vtkPVFoam.C vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C -vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C -vtkPVFoamMeshZone.C vtkPVFoamUpdateInfo.C -vtkPVFoamUtils.C -LIB = $(FOAM_LIBBIN)/libvtkPVFoam +LIB = $(FOAM_LIBBIN)/libvtkPVFoam-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index 0154a3bcbacab572a9f7b553a96d81529f3a04cf..4a739397116ce17d611a676c5cdb8f70f488d958 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -1,3 +1,5 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/meshTools/lnInclude \ @@ -8,7 +10,7 @@ EXE_INC = \ -I$(LIB_SRC)/conversion/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ - -I../../vtkPVReaders/lnInclude \ + -I../../foamPv/lnInclude \ -I../PVFoamReader LIB_LIBS = \ @@ -16,5 +18,5 @@ LIB_LIBS = \ -lconversion \ -lgenericPatchFields \ -llagrangian \ - -L$(FOAM_LIBBIN) -lvtkPVReaders \ + -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H deleted file mode 100644 index 2a45d73b2afe070876ae71224c3cec9ca5e60f8e..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMPoints.H +++ /dev/null @@ -1,79 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkOpenFOAMPoints_H -#define vtkOpenFOAMPoints_H - -// VTK includes -#include "vtkPoints.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -inline void vtkInsertNextOpenFOAMPoint -( - vtkPoints *points, - const Foam::point& p -) -{ - points->InsertNextPoint(p.x(), p.y(), p.z()); -} - -#if 0 -// this should be faster, but didn't get it working ... -inline void vtkSetOpenFOAMPoint -( - vtkPoints *points, - const Foam::label id, - const Foam::point& p -) -{ - points->SetPoint(id, p.x(), p.y(), p.z()); -} - - -// Convert OpenFOAM mesh vertices to VTK -inline vtkPoints* vtkSetOpenFOAMPoints(const Foam::pointField& points) -{ - vtkPoints *vtkpoints = vtkPoints::New(); - vtkpoints->SetNumberOfPoints(points.size()); - forAll(points, i) - { - const Foam::point& p = points[i]; - vtkpoints->SetPoint(i, p.x(), p.y(), p.z()); - } - - return vtkpoints; -} - -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C index 0f8e09252cfb96ce298a1dfe769980f31b2685a3..2b7ab51888cf65e035a4f71c7450c9c4328119e6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,14 +42,39 @@ License namespace Foam { -defineTypeNameAndDebug(vtkPVFoam, 0); + defineTypeNameAndDebug(vtkPVFoam, 0); } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +vtkTextActor* Foam::vtkPVFoam::createTextActor +( + const string& s, + const point& pt +) +{ + vtkTextActor* txt = vtkTextActor::New(); + txt->SetInput(s.c_str()); + + // Set text properties + vtkTextProperty* tprop = txt->GetTextProperty(); + tprop->SetFontFamilyToArial(); + tprop->BoldOn(); + tprop->ShadowOff(); + tprop->SetLineSpacing(1.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); + tprop->SetJustificationToCentered(); + + txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); + txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z()); + + return txt; +} + -#include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::vtkPVFoam::resetCounters() { @@ -116,14 +141,10 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< "<beg> Foam::vtkPVFoam::setTime("; + Info<< "<beg> setTime("; for (int requestI = 0; requestI < nRequest; ++requestI) { - if (requestI) - { - Info<< ", "; - } - + if (requestI) Info<< ", "; Info<< requestTimes[requestI]; } Info<< ") - previousIndex = " << timeIndex_ @@ -160,7 +181,7 @@ int Foam::vtkPVFoam::setTime(int nRequest, const double requestTimes[]) if (debug) { - Info<< "<end> Foam::vtkPVFoam::setTime() - selectedTime=" + Info<< "<end> setTime() - selectedTime=" << Times[nearestIndex].name() << " index=" << timeIndex_ << "/" << Times.size() << " meshChanged=" << Switch(meshChanged_) @@ -175,7 +196,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< "<beg> updateMeshPartsStatus" << endl; } vtkDataArraySelection* selection = reader_->GetPartSelection(); @@ -203,7 +224,7 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() meshChanged_ = true; } - if (debug) + if (debug > 1) { Info<< " part[" << partId << "] = " << partStatus_[partId] @@ -212,11 +233,17 @@ void Foam::vtkPVFoam::updateMeshPartsStatus() } if (debug) { - Info<< "<end> Foam::vtkPVFoam::updateMeshPartsStatus" << endl; + Info<< "<end> updateMeshPartsStatus" << endl; } } +Foam::word Foam::vtkPVFoam::getPartName(const int partId) +{ + return getFirstWord(reader_->GetPartArrayName(partId)); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::vtkPVFoam::vtkPVFoam @@ -245,7 +272,7 @@ Foam::vtkPVFoam::vtkPVFoam { if (debug) { - Info<< "Foam::vtkPVFoam::vtkPVFoam - " << FileName << endl; + Info<< "vtkPVFoam - " << FileName << endl; printMemory(); } @@ -333,7 +360,7 @@ Foam::vtkPVFoam::~vtkPVFoam() { if (debug) { - Info<< "<end> Foam::vtkPVFoam::~vtkPVFoam" << endl; + Info<< "~vtkPVFoam" << endl; } delete meshPtr_; @@ -346,7 +373,7 @@ void Foam::vtkPVFoam::updateInfo() { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfo" + Info<< "<beg> updateInfo" << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "] timeIndex=" << timeIndex_ << endl; } @@ -363,16 +390,15 @@ void Foam::vtkPVFoam::updateInfo() // time of the vtkDataArraySelection, but the qt/paraview proxy // layer doesn't care about that anyhow. - // enable 'internalMesh' on the first call - // or preserve the enabled selections stringList enabledEntries; if (!partSelection->GetNumberOfArrays() && !meshPtr_) { - enabledEntries.setSize(1); - enabledEntries[0] = "internalMesh"; + // enable 'internalMesh' on the first call + enabledEntries = { "internalMesh" }; } else { + // preserve the enabled selections enabledEntries = getSelectedArrayEntries(partSelection); } @@ -395,23 +421,12 @@ void Foam::vtkPVFoam::updateInfo() } // Update volume, point and lagrangian fields - updateInfoFields<fvPatchField, volMesh> - ( - reader_->GetVolFieldSelection() - ); - updateInfoFields<pointPatchField, pointMesh> - ( - reader_->GetPointFieldSelection() - ); - updateInfoLagrangianFields(); + updateInfoFields(); if (debug) { - // just for debug info - getSelectedArrayEntries(partSelection); - Info<< "<end> Foam::vtkPVFoam::updateInfo" << endl; + Info<< "<end> updateInfo" << endl; } - } @@ -419,7 +434,7 @@ void Foam::vtkPVFoam::updateFoamMesh() { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< "<beg> updateFoamMesh" << endl; printMemory(); } @@ -463,7 +478,7 @@ void Foam::vtkPVFoam::updateFoamMesh() if (debug) { - Info<< "<end> Foam::vtkPVFoam::updateFoamMesh" << endl; + Info<< "<end> updateFoamMesh" << endl; printMemory(); } } @@ -532,7 +547,7 @@ void Foam::vtkPVFoam::Update convertLagrangianFields(lagrangianOutput); if (debug) { - Info<< "done reader part" << endl; + Info<< "done reader part" << nl << endl; } reader_->UpdateProgress(0.95); @@ -548,68 +563,58 @@ void Foam::vtkPVFoam::CleanUp() } -double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) +std::vector<double> Foam::vtkPVFoam::findTimes(const bool skipZero) const { - int nTimes = 0; - double* tsteps = nullptr; + std::vector<double> times; if (dbPtr_.valid()) { - Time& runTime = dbPtr_(); + const Time& runTime = dbPtr_(); instantList timeLst = runTime.times(); // find the first time for which this mesh appears to exist - label timeI = 0; - for (; timeI < timeLst.size(); ++timeI) + label begIndex = timeLst.size(); + forAll(timeLst, timeI) { - const word& timeName = timeLst[timeI].name(); - if ( - isFile(runTime.path()/timeName/meshDir_/"points") - && IOobject + IOobject ( "points", - timeName, + timeLst[timeI].name(), meshDir_, runTime - ).typeHeaderOk<pointIOField>(true) + ).typeHeaderOk<pointIOField>(false, false) ) { + begIndex = timeI; break; } } - nTimes = timeLst.size() - timeI; + label nTimes = timeLst.size() - begIndex; // skip "constant" time whenever possible - if (timeI == 0 && nTimes > 1) + if (begIndex == 0 && nTimes > 1) { - if (timeLst[timeI].name() == runTime.constant()) + if (timeLst[begIndex].name() == runTime.constant()) { - ++timeI; + ++begIndex; --nTimes; } } - // skip "0/" time if requested and possible - if (nTimes > 1 && reader_->GetSkipZeroTime()) + if (skipZero && nTimes > 1 && timeLst[begIndex].name() == "0") { - if (mag(timeLst[timeI].value()) < SMALL) - { - ++timeI; - --nTimes; - } + ++begIndex; + --nTimes; } - if (nTimes) + times.reserve(nTimes); + while (nTimes-- > 0) { - tsteps = new double[nTimes]; - for (label stepI = 0; stepI < nTimes; ++stepI, ++timeI) - { - tsteps[stepI] = timeLst[timeI].value(); - } + times.push_back(timeLst[begIndex++].value()); } } else @@ -620,10 +625,7 @@ double* Foam::vtkPVFoam::findTimes(int& nTimeSteps) } } - // vector length returned via the parameter - nTimeSteps = nTimes; - - return tsteps; + return times; } @@ -633,11 +635,6 @@ void Foam::vtkPVFoam::renderPatchNames const bool show ) { - if (!meshPtr_) - { - return; - } - // always remove old actors first forAll(patchTextActorsPtrs_, patchi) @@ -647,10 +644,10 @@ void Foam::vtkPVFoam::renderPatchNames } patchTextActorsPtrs_.clear(); - if (show) + if (show && meshPtr_) { // get the display patches, strip off any suffix - wordHashSet selectedPatches = getSelected + hashedWordList selectedPatches = getSelected ( reader_->GetPartSelection(), arrayRangePatches_ @@ -764,17 +761,16 @@ void Foam::vtkPVFoam::renderPatchNames { const polyPatch& pp = pbMesh[patchi]; - label globalZoneI = 0; - // Only selected patches will have a non-zero number of zones - label nDisplayZones = min(MAXPATCHZONES, nZones[patchi]); + const label nDisplayZones = min(MAXPATCHZONES, nZones[patchi]); label increment = 1; if (nZones[patchi] >= MAXPATCHZONES) { increment = nZones[patchi]/MAXPATCHZONES; } - for (label i = 0; i < nDisplayZones; i++) + label globalZoneI = 0; + for (label i = 0; i < nDisplayZones; ++i, globalZoneI += increment) { if (debug) { @@ -783,45 +779,24 @@ void Foam::vtkPVFoam::renderPatchNames << "globalZoneI = " << globalZoneI << endl; } - vtkTextActor* txt = vtkTextActor::New(); - - txt->SetInput(pp.name().c_str()); - - // Set text properties - vtkTextProperty* tprop = txt->GetTextProperty(); - tprop->SetFontFamilyToArial(); - tprop->BoldOff(); - tprop->ShadowOff(); - tprop->SetLineSpacing(1.0); - tprop->SetFontSize(12); - tprop->SetColor(1.0, 0.0, 0.0); - tprop->SetJustificationToCentered(); - - // Set text to use 3-D world co-ordinates - txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); - - txt->GetPositionCoordinate()->SetValue + // Into a list for later removal + patchTextActorsPtrs_[displayZoneI++] = createTextActor ( - zoneCentre[patchi][globalZoneI].x(), - zoneCentre[patchi][globalZoneI].y(), - zoneCentre[patchi][globalZoneI].z() + pp.name(), + zoneCentre[patchi][globalZoneI] ); - - // Add text to each renderer - renderer->AddViewProp(txt); - - // Maintain a list of text labels added so that they can be - // removed later - patchTextActorsPtrs_[displayZoneI] = txt; - - globalZoneI += increment; - displayZoneI++; } } // Resize the patch names list to the actual number of patch names added patchTextActorsPtrs_.setSize(displayZoneI); } + + // Add text to each renderer + forAll(patchTextActorsPtrs_, actori) + { + renderer->AddViewProp(patchTextActorsPtrs_[actori]); + } } @@ -840,4 +815,24 @@ void Foam::vtkPVFoam::PrintSelf(ostream& os, vtkIndent indent) const } +void Foam::vtkPVFoam::printInfo() const +{ + std::cout + << "Region: " << meshRegion_ << "\n" + << "nPoints: " << (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n" + << "nCells: " << (meshPtr_ ? meshPtr_->nCells() : 0) << "\n" + << "nTimes: " + << (dbPtr_.valid() ? dbPtr_().times().size() : 0) << "\n"; + + std::vector<double> times = this->findTimes(reader_->GetSkipZeroTime()); + + std::cout<<" " << times.size() << "("; + for (const double& val : times) + { + std::cout<< ' ' << val; + } + std::cout << " )" << std::endl; +} + + // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H index 5fb4b0b0d8431d86025f6adc6652c29a6f267340..3f0a1ad55d700ca1d6df81dbb4bac32e427bbe52 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoam.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,24 +29,15 @@ Description SourceFiles vtkPVFoam.C - vtkPVFoam.H vtkPVFoamFields.C vtkPVFoamMesh.C vtkPVFoamMeshLagrangian.C - vtkPVFoamTemplates.C - vtkPVFoamMeshSet.C vtkPVFoamMeshVolume.C - vtkPVFoamMeshZone.C - vtkPVFoamFaceField.H - vtkPVFoamLagrangianFields.H - vtkPVFoamPatchField.H - vtkPVFoamPointFields.H - vtkPVFoamPoints.H + vtkPVFoamTemplates.C vtkPVFoamUpdateInfo.C - vtkPVFoamUpdateInfoFields.H vtkPVFoamUtils.C - vtkPVFoamVolFields.H - vtkPVFoamAddToSelection.H + vtkPVFoamFieldTemplates.C + vtkPVFoamUpdateTemplates.C // Needed by VTK: vtkDataArrayTemplateImplicit.txx @@ -56,11 +47,6 @@ SourceFiles #ifndef vtkPVFoam_H #define vtkPVFoam_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" @@ -68,6 +54,7 @@ SourceFiles #include "primitivePatch.H" #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" +#include "foamPvCore.H" #undef VTKPVFOAM_DUALPORT @@ -75,6 +62,7 @@ SourceFiles class vtkDataArraySelection; class vtkDataSet; +class vtkFloatArray; class vtkPoints; class vtkPVFoamReader; class vtkRenderer; @@ -95,10 +83,9 @@ class Time; class fvMesh; class IOobjectList; class polyPatch; -class faceSet; -class pointSet; template<class Type> class IOField; +template<class Type> class Field; template<class Type> class List; /*---------------------------------------------------------------------------*\ @@ -106,83 +93,14 @@ template<class Type> class List; \*---------------------------------------------------------------------------*/ class vtkPVFoam +: + private foamPvCore { - // Private classes - - //- Bookkeeping for GUI checklists and the multi-block organization - class arrayRange - { - const char *name_; - int block_; - int start_; - int size_; - - public: - - arrayRange(const char *name, const int blockNo=0) - : - name_(name), - block_(blockNo), - start_(0), - size_(0) - {} - - //- Return the block holding these datasets - int block() const - { - return block_; - } - - //- Assign block number, return previous value - int block(int blockNo) - { - int prev = block_; - block_ = blockNo; - return prev; - } - - //- Return block name - const char* name() const - { - return name_; - } - - //- Return array start index - int start() const - { - return start_; - } - - //- Return array end index - int end() const - { - return start_ + size_; - } - - //- Return sublist size - int size() const - { - return size_; - } - - bool empty() const - { - return !size_; - } + // Convenience typedefs + typedef PrimitivePatchInterpolation<primitivePatch> patchInterpolator; - //- Reset the size to zero and optionally assign a new start - void reset(const int startAt = 0) - { - start_ = startAt; - size_ = 0; - } - //- Increment the size - void operator+=(const int n) - { - size_ += n; - } - }; + // Private classes //- Bookkeeping for polyhedral cell decomposition // hide in extra pointMap (cellSet/cellZone) for now @@ -302,372 +220,261 @@ class vtkPVFoam //- List of patch names for rendering to window List<vtkTextActor*> patchTextActorsPtrs_; + // Private Member Functions - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static void AddToBlock - ( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange&, - const label datasetNo, - const std::string& datasetName - ); + //- Create a text actor + static vtkTextActor* createTextActor(const string& s, const point& pt); + + //- Reset data counters + void resetCounters(); + + // Update information helper functions + + //- Update the mesh parts selected in the GUI + void updateMeshPartsStatus(); + + //- Internal mesh info + void updateInfoInternalMesh(vtkDataArraySelection*); - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static vtkDataSet* GetDataSetFromBlock + //- Lagrangian info + void updateInfoLagrangian(vtkDataArraySelection*); + + //- Patch info + void updateInfoPatches(vtkDataArraySelection*, stringList&); + + //- Set info + void updateInfoSets(vtkDataArraySelection*); + + //- Zone info + void updateInfoZones(vtkDataArraySelection*); + + //- Get non-empty zone names for zoneType from file + wordList getZoneNames(const word& zoneType) const; + + //- Get names of on non-empty zones from the mesh info + template<class ZoneType> + static wordList getZoneNames ( - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo + const ZoneMesh<ZoneType, polyMesh>& zmesh ); - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static label GetNumberOfDataSets + //- Field (volume, point, lagrangian) info + void updateInfoFields(); + + //- Field info + template<template<class> class patchType, class meshType> + void updateInfoFields ( - vtkMultiBlockDataSet* output, - const arrayRange& + vtkDataArraySelection* select ); - //- Reset data counters - void resetCounters(); + //- Lagrangian field info + void updateInfoLagrangianFields(vtkDataArraySelection* select); - // Update information helper functions - //- Update the mesh parts selected in the GUI - void updateMeshPartsStatus(); + // Update helper functions - //- Internal mesh info - void updateInfoInternalMesh(vtkDataArraySelection*); + //- OpenFOAM mesh + void updateFoamMesh(); - //- Lagrangian info - void updateInfoLagrangian(vtkDataArraySelection*); + //- Reduce memory footprint after conversion + void reduceMemory(); - //- Patch info - void updateInfoPatches(vtkDataArraySelection*, stringList&); - //- Set info - void updateInfoSets(vtkDataArraySelection*); + // Mesh conversion functions - //- Zone info - void updateInfoZones(vtkDataArraySelection*); + //- Convert volume mesh + void convertMeshVolume(vtkMultiBlockDataSet* output, int& blockNo); - //- Get non-empty zone names for zoneType from file - wordList getZoneNames(const word& zoneType) const; + //- Convert Lagrangian points + void convertMeshLagrangian(vtkMultiBlockDataSet* output, int& blockNo); - //- Get non-empty zone names from mesh info - template<class ZoneType> - wordList getZoneNames - ( - const ZoneMesh<ZoneType, polyMesh>& - ) const; + //- Convert mesh patches + void convertMeshPatches(vtkMultiBlockDataSet* output, int& blockNo); - //- Add objects of Type to paraview array selection - template<class Type> - label addToSelection - ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null - ); + //- Convert cell zones + void convertMeshCellZones(vtkMultiBlockDataSet* output, int& blockNo); - //- Field info - template<template<class> class patchType, class meshType> - void updateInfoFields(vtkDataArraySelection*); + //- Convert face zones + void convertMeshFaceZones(vtkMultiBlockDataSet* output, int& blockNo); - //- Lagrangian field info - void updateInfoLagrangianFields(); + //- Convert point zones + void convertMeshPointZones(vtkMultiBlockDataSet* output, int& blockNo); + //- Convert cell sets + void convertMeshCellSets(vtkMultiBlockDataSet* output, int& blockNo); - // Update helper functions + //- Convert face sets + void convertMeshFaceSets(vtkMultiBlockDataSet* output, int& blockNo); - //- OpenFOAM mesh - void updateFoamMesh(); + //- Convert point sets + void convertMeshPointSets(vtkMultiBlockDataSet* output, int& blockNo); - //- Reduce memory footprint after conversion - void reduceMemory(); + // Add mesh functions - // Mesh conversion functions + //- Volume meshes as vtkUnstructuredGrid + vtkUnstructuredGrid* volumeVTKMesh + ( + const fvMesh& mesh, + polyDecomp& decompInfo + ); - //- Volume mesh - void convertMeshVolume(vtkMultiBlockDataSet*, int& blockNo); + //- Lagrangian positions as vtkPolyData + vtkPolyData* lagrangianVTKMesh + ( + const polyMesh& mesh, + const word& cloudName + ); - //- Lagrangian mesh - void convertMeshLagrangian(vtkMultiBlockDataSet*, int& blockNo); + //- Patches (mesh or primitive) as vtkPolyData + template<class PatchType> + vtkPolyData* patchVTKMesh + ( + const word& name, + const PatchType& p + ); - //- Patch meshes - void convertMeshPatches(vtkMultiBlockDataSet*, int& blockNo); - //- Cell zone meshes - void convertMeshCellZones(vtkMultiBlockDataSet*, int& blockNo); + // Field conversion functions - //- Face zone meshes - void convertMeshFaceZones(vtkMultiBlockDataSet*, int& blockNo); + //- Convert Field to VTK field + template<class Type> + vtkFloatArray* convertFieldToVTK + ( + const word& name, + const Field<Type>& fld + ); - //- Point zone meshes - void convertMeshPointZones(vtkMultiBlockDataSet*, int& blockNo); + //- Face set/zone field + template<class Type> + vtkFloatArray* convertFaceFieldToVTK + ( + const GeometricField<Type, fvPatchField, volMesh>& fld, + const labelUList& faceLabels + ); - //- Cell set meshes - void convertMeshCellSets(vtkMultiBlockDataSet*, int& blockNo); + //- Volume field + template<class Type> + vtkFloatArray* convertVolFieldToVTK + ( + const GeometricField<Type, fvPatchField, volMesh>& fld, + const polyDecomp& decompInfo + ); - //- Face set meshes - void convertMeshFaceSets(vtkMultiBlockDataSet*, int& blockNo); - //- Point set meshes - void convertMeshPointSets(vtkMultiBlockDataSet*, int& blockNo); + //- Convert volume fields + void convertVolFields(vtkMultiBlockDataSet* output); + //- Convert point fields + void convertPointFields(vtkMultiBlockDataSet* output); - // Add mesh functions + //- Convert Lagrangian fields + void convertLagrangianFields(vtkMultiBlockDataSet* output); - //- Add internal mesh/cell set meshes - vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&); - //- Add Lagrangian mesh - vtkPolyData* lagrangianVTKMesh - ( - const fvMesh&, - const word& cloudName - ); + // Convert OpenFOAM fields - //- Add patch mesh - template<class PatchType> - vtkPolyData* patchVTKMesh(const word& name, const PatchType&); + //- Volume field - all types + template<class Type> + void convertVolField + ( + const PtrList<patchInterpolator>& patchInterpList, + const GeometricField<Type, fvPatchField, volMesh>& fld, + vtkMultiBlockDataSet* output + ); - //- Add point zone - vtkPolyData* pointZoneVTKMesh - ( - const fvMesh&, - const labelList& pointLabels - ); + //- Volume fields - all types + template<class Type> + void convertVolFields + ( + const fvMesh& mesh, + const PtrList<patchInterpolator>& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); - //- Add face set mesh - vtkPolyData* faceSetVTKMesh - ( - const fvMesh&, - const faceSet& - ); + //- Volume internal fields (DimensionedField)- all types + template<class Type> + void convertDimFields + ( + const fvMesh& mesh, + const PtrList<patchInterpolator>& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); - //- Add point mesh - vtkPolyData* pointSetVTKMesh - ( - const fvMesh&, - const pointSet& - ); + //- Volume field - all selected parts + template<class Type> + void convertVolFieldBlock + ( + const GeometricField<Type, fvPatchField, volMesh>& fld, + autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List<polyDecomp>& decompLst + ); - // Field conversion functions + //- Lagrangian fields - all types + template<class Type> + void convertLagrangianFields + ( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo + ); - //- Convert volume fields - void convertVolFields(vtkMultiBlockDataSet*); + //- Point fields - all types + template<class Type> + void convertPointFields + ( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output + ); - //- Convert point fields - void convertPointFields(vtkMultiBlockDataSet*); + //- Point field - all selected parts + template<class Type> + void convertPointFieldBlock + ( + const GeometricField<Type, pointPatchField, pointMesh>& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List<polyDecomp>& decompLst + ); + + //- Point field + template<class Type> + void convertPointField + ( + vtkUnstructuredGrid* vtkmesh, + const GeometricField<Type, pointPatchField, pointMesh>& pfld, + const GeometricField<Type, fvPatchField, volMesh>& vfld, + const polyDecomp& decomp + ); - //- Convert Lagrangian fields - void convertLagrangianFields(vtkMultiBlockDataSet*); + // GUI selection helper functions - //- Add the fields in the selected time directory to the selection - // lists - template<class GeoField> - label addObjectsToSelection + //- Only retain specified fields + static void pruneObjectList ( - vtkDataArraySelection*, - const IOobjectList&, - const string& suffix=string::null + IOobjectList& objects, + const hashedWordList& retain ); + //- Get the first word from the reader 'parts' selection + word getPartName(const int partId); - // Convert OpenFOAM fields - - //- Volume field - all types - template<class Type> - void convertVolField - ( - const PtrList<PrimitivePatchInterpolation<primitivePatch>>&, - const GeometricField<Type, fvPatchField, volMesh>&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); - - //- Volume fields - all types - template<class Type> - void convertVolFields - ( - const fvMesh&, - const PtrList<PrimitivePatchInterpolation<primitivePatch>>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); - - //- Volume internal fields (DimensionedField)- all types - template<class Type> - void convertDimFields - ( - const fvMesh&, - const PtrList<PrimitivePatchInterpolation<primitivePatch>>&, - const IOobjectList&, - const bool interpFields, - vtkMultiBlockDataSet* output - ); - - //- Volume field - all selected parts - template<class Type> - void convertVolFieldBlock - ( - const GeometricField<Type, fvPatchField, volMesh>&, - autoPtr<GeometricField<Type, pointPatchField, pointMesh>>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List<polyDecomp>& decompLst - ); - - //- Volume field - template<class Type> - void convertVolField - ( - const GeometricField<Type, fvPatchField, volMesh>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch field - template<class Type> - void convertPatchField - ( - const word& name, - const Field<Type>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Face set/zone field - template<class Type> - void convertFaceField - ( - const GeometricField<Type, fvPatchField, volMesh>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const fvMesh&, - const labelList& faceLabels - ); - - //- Lagrangian fields - all types - template<class Type> - void convertLagrangianFields - ( - const IOobjectList&, - vtkMultiBlockDataSet* output, - const label datasetNo - ); - - //- Lagrangian field - template<class Type> - void convertLagrangianField - ( - const IOField<Type>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - //- Point fields - all types - template<class Type> - void convertPointFields - ( - const fvMesh&, - const pointMesh&, - const IOobjectList&, - vtkMultiBlockDataSet* output - ); - - //- Point field - all selected parts - template<class Type> - void convertPointFieldBlock - ( - const GeometricField<Type, pointPatchField, pointMesh>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const List<polyDecomp>& - ); - - //- Point fields - template<class Type> - void convertPointField - ( - const GeometricField<Type, pointPatchField, pointMesh>&, - const GeometricField<Type, fvPatchField, volMesh>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo, - const polyDecomp& - ); - - //- Patch point field - template<class Type> - void convertPatchPointField - ( - const word& name, - const Field<Type>&, - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - - - // GUI selection helper functions - - //- Only keep what is listed in hashSet - static void pruneObjectList - ( - IOobjectList&, - const wordHashSet& - ); - - //- Retrieve the current selections - static wordHashSet getSelected(vtkDataArraySelection*); - - //- Retrieve a sub-list of the current selections - static wordHashSet getSelected - ( - vtkDataArraySelection*, - const arrayRange& - ); - - //- Retrieve the current selections - static stringList getSelectedArrayEntries(vtkDataArraySelection*); - - //- Retrieve a sub-list of the current selections - static stringList getSelectedArrayEntries - ( - vtkDataArraySelection*, - const arrayRange& - ); - - //- Set selection(s) - static void setSelectedArrayEntries - ( - vtkDataArraySelection*, - const stringList& - ); - - //- Get the first word from the mesh parts selection - word getPartName(const int); + // Constructors //- Disallow default bitwise copy construct - vtkPVFoam(const vtkPVFoam&); + vtkPVFoam(const vtkPVFoam&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVFoam&); + void operator=(const vtkPVFoam&) = delete; public: @@ -705,9 +512,9 @@ public: //- Clean any storage void CleanUp(); - //- Allocate and return a list of selected times - // returns the count via the parameter - double* findTimes(int& nTimeSteps); + //- Return a list of selected times. + // Use STL container since these values are used by the plugin + std::vector<double> findTimes(const bool skipZero = false) const; //- Add/remove patch names to/from the view void renderPatchNames(vtkRenderer*, const bool show); @@ -730,9 +537,7 @@ public: //- Debug information void PrintSelf(ostream&, vtkIndent) const; - //- Simple memory used debugging information - static void printMemory(); - + void printInfo() const; }; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H deleted file mode 100644 index 69395405d5be6d8ff1b935ba490cfaad0324d350..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFaceField.H +++ /dev/null @@ -1,117 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamFaceField_H -#define vtkPVFoamFaceField_H - -// VTK includes -#include "vtkCellData.h" -#include "vtkFloatArray.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkPolyData.h" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template<class Type> -void Foam::vtkPVFoam::convertFaceField -( - const GeometricField<Type, fvPatchField, volMesh>& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo, - const fvMesh& mesh, - const labelList& faceLabels -) -{ - const label nComp = pTraits<Type>::nComponents; - const label nInternalFaces = mesh.nInternalFaces(); - const labelList& faceOwner = mesh.faceOwner(); - const labelList& faceNeigh = mesh.faceNeighbour(); - - vtkFloatArray* cellData = vtkFloatArray::New(); - cellData->SetNumberOfTuples(faceLabels.size()); - cellData->SetNumberOfComponents(nComp); - cellData->Allocate(nComp*faceLabels.size()); - cellData->SetName(tf.name().c_str()); - - if (debug) - { - Info<< "convert convertFaceField: " - << tf.name() - << " size = " << tf.size() - << " nComp=" << nComp - << " nTuples = " << faceLabels.size() << endl; - } - - float vec[nComp]; - - // for interior faces: average owner/neighbour - // for boundary faces: owner - forAll(faceLabels, facei) - { - const label faceNo = faceLabels[facei]; - if (faceNo < nInternalFaces) - { - Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]); - - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - } - else - { - const Type& t = tf[faceOwner[faceNo]]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - } - vtkOpenFOAMTupleRemap<Type>(vec); - - cellData->InsertTuple(facei, vec); - } - - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetCellData() - ->AddArray(cellData); - - cellData->Delete(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C new file mode 100644 index 0000000000000000000000000000000000000000..c6b9e3b86c211b6bfb3d9a37cff8ac574e8ecd9f --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -0,0 +1,909 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +InClass + vtkPVFoam + +\*---------------------------------------------------------------------------*/ + +#ifndef vtkPVFoamFieldTemplates_C +#define vtkPVFoamFieldTemplates_C + +// OpenFOAM includes +#include "emptyFvPatchField.H" +#include "wallPolyPatch.H" +#include "faceSet.H" +#include "volPointInterpolation.H" +#include "zeroGradientFvPatchField.H" +#include "interpolatePointToCell.H" +#include "foamPvFields.H" + +// vtk includes +#include "vtkFloatArray.h" +#include "vtkCellData.h" +#include "vtkPointData.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// volume-fields +// + +template<class Type> +void Foam::vtkPVFoam::convertVolField +( + const PtrList<patchInterpolator>& patchInterpList, + const GeometricField<Type, fvPatchField, volMesh>& fld, + vtkMultiBlockDataSet* output +) +{ + const fvMesh& mesh = fld.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + const bool interpField = !patchInterpList.empty(); + const bool extrapPatch = reader_->GetExtrapolatePatches(); + + // Interpolated field (demand driven) + autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr; + if (interpField) + { + if (debug) + { + Info<< "convertVolField interpolating:" << fld.name() << endl; + } + + ptfPtr.reset + ( + volPointInterpolation::New(mesh).interpolate(fld).ptr() + ); + } + + // Convert activated internalMesh regions + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertVolFieldBlock + ( + fld, + ptfPtr, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData> + ( + output, arrayRangePatches_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const fvPatchField<Type>& ptf = fld.boundaryField()[patchId]; + + if + ( + isType<emptyFvPatchField<Type>>(ptf) + || + ( + extrapPatch + && !polyPatch::constraintType(patches[patchId].type()) + ) + ) + { + fvPatch p(ptf.patch().patch(), mesh.boundary()); + + tmp<Field<Type>> tpptf + ( + fvPatchField<Type>(p, fld).patchInternalField() + ); + + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), tpptf()); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(tpptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + else + { + vtkFloatArray* cdata = convertFieldToVTK(fld.name(), ptf); + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (patchId < patchInterpList.size()) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fld.name(), + patchInterpList[patchId].faceToPointInterpolate(ptf)() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } + + // + // Convert face zones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId] || datasetNo < 0) + { + continue; + } + + const faceZoneMesh& zMesh = mesh.faceZones(); + const label zoneId = zMesh.findZoneID(zoneName); + + if (zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData> + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + zMesh[zoneId] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + } + + // TODO: points + } + + // + // Convert face sets - if activated + // + for + ( + int partId = arrayRangeFaceSets_.start(); + partId < arrayRangeFaceSets_.end(); + ++partId + ) + { + const word selectName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData> + ( + output, arrayRangeFaceSets_, datasetNo + ); + + if (!vtkmesh) + { + continue; + } + + const faceSet fSet(mesh, selectName); + + vtkFloatArray* cdata = convertFaceFieldToVTK + ( + fld, + fSet.sortedToc() + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + // TODO: points + } +} + + +template<class Type> +void Foam::vtkPVFoam::convertVolFields +( + const fvMesh& mesh, + const PtrList<patchInterpolator>& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to GeometricField<Type, ...> + if + ( + iter()->headerClassName() + != GeometricField<Type, fvPatchField, volMesh>::typeName + ) + { + continue; + } + + // Load field + GeometricField<Type, fvPatchField, volMesh> fld + ( + *iter(), + mesh + ); + + // Convert + convertVolField(patchInterpList, fld, output); + } +} + + +template<class Type> +void Foam::vtkPVFoam::convertDimFields +( + const fvMesh& mesh, + const PtrList<patchInterpolator>& patchInterpList, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to DimensionedField<Type, ...> + if + ( + iter()->headerClassName() + != DimensionedField<Type, volMesh>::typeName + ) + { + continue; + } + + // Load field + DimensionedField<Type, volMesh> dimFld(*iter(), mesh); + + // Construct volField with zero-gradient patch fields + + IOobject io(dimFld); + io.readOpt() = IOobject::NO_READ; + + PtrList<fvPatchField<Type>> patchFields(mesh.boundary().size()); + forAll(patchFields, patchI) + { + patchFields.set + ( + patchI, + fvPatchField<Type>::New + ( + zeroGradientFvPatchField<Type>::typeName, + mesh.boundary()[patchI], + dimFld + ) + ); + } + + VolFieldType volFld + ( + io, + dimFld.mesh(), + dimFld.dimensions(), + dimFld, + patchFields + ); + volFld.correctBoundaryConditions(); + + convertVolField(patchInterpList, volFld, output); + } +} + + +template<class Type> +void Foam::vtkPVFoam::convertVolFieldBlock +( + const GeometricField<Type, fvPatchField, volMesh>& fld, + autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List<polyDecomp>& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = + getDataFromBlock<vtkUnstructuredGrid>(output, range, datasetNo); + + if (!vtkmesh) + { + continue; + } + + vtkFloatArray* cdata = convertVolFieldToVTK + ( + fld, + decompLst[datasetNo] + ); + + vtkmesh->GetCellData()->AddArray(cdata); + cdata->Delete(); + + if (ptfPtr.valid()) + { + convertPointField(vtkmesh, ptfPtr(), fld, decompLst[datasetNo]); + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// point-fields +// + +template<class Type> +void Foam::vtkPVFoam::convertPointFields +( + const pointMesh& pMesh, + const IOobjectList& objects, + vtkMultiBlockDataSet* output +) +{ + const polyMesh& mesh = pMesh.mesh(); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAllConstIter(IOobjectList, objects, iter) + { + const word& fieldName = iter()->name(); + // restrict to this GeometricField<Type, ...> + if + ( + iter()->headerClassName() + != GeometricField<Type, pointPatchField, pointMesh>::typeName + ) + { + continue; + } + + if (debug) + { + Info<< "convertPointFields : " << fieldName << endl; + } + + GeometricField<Type, pointPatchField, pointMesh> pfld(*iter(), pMesh); + + + // Convert activated internalMesh regions + convertPointFieldBlock + ( + pfld, + output, + arrayRangeVolume_, + regionPolyDecomp_ + ); + + // Convert activated cellZones + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellZones_, + zonePolyDecomp_ + ); + + // Convert activated cellSets + convertPointFieldBlock + ( + pfld, + output, + arrayRangeCellSets_, + csetPolyDecomp_ + ); + + + // + // Convert patches - if activated + // + for + ( + int partId = arrayRangePatches_.start(); + partId < arrayRangePatches_.end(); + ++partId + ) + { + const word patchName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label patchId = patches.findPatchID(patchName); + + if (!partStatus_[partId] || patchId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData> + ( + output, arrayRangePatches_, datasetNo + ); + + if (vtkmesh) + { + vtkFloatArray* pdata = convertFieldToVTK + ( + fieldName, + pfld.boundaryField()[patchId].patchInternalField()() + ); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + + // + // Convert faceZones - if activated + // + for + ( + int partId = arrayRangeFaceZones_.start(); + partId < arrayRangeFaceZones_.end(); + ++partId + ) + { + const word zoneName = getPartName(partId); + const label datasetNo = partDataset_[partId]; + const label zoneId = mesh.faceZones().findZoneID(zoneName); + + if (!partStatus_[partId] || zoneId < 0) + { + continue; + } + + vtkPolyData* vtkmesh = getDataFromBlock<vtkPolyData> + ( + output, arrayRangeFaceZones_, datasetNo + ); + + if (vtkmesh) + { + // Extract the field on the zone + Field<Type> znfld + ( + pfld.primitiveField(), + mesh.faceZones()[zoneId]().meshPoints() + ); + + vtkFloatArray* pdata = convertFieldToVTK(fieldName, znfld); + + vtkmesh->GetPointData()->AddArray(pdata); + pdata->Delete(); + } + } + } +} + + +template<class Type> +void Foam::vtkPVFoam::convertPointFieldBlock +( + const GeometricField<Type, pointPatchField, pointMesh>& pfld, + vtkMultiBlockDataSet* output, + const arrayRange& range, + const List<polyDecomp>& decompLst +) +{ + for (int partId = range.start(); partId < range.end(); ++partId) + { + const label datasetNo = partDataset_[partId]; + + if (!partStatus_[partId]) + { + continue; + } + + vtkUnstructuredGrid* vtkmesh = getDataFromBlock<vtkUnstructuredGrid> + ( + output, range, datasetNo + ); + + if (vtkmesh) + { + convertPointField + ( + vtkmesh, + pfld, + GeometricField<Type, fvPatchField, volMesh>::null(), + decompLst[datasetNo] + ); + } + } +} + + +template<class Type> +void Foam::vtkPVFoam::convertPointField +( + vtkUnstructuredGrid* vtkmesh, + const GeometricField<Type, pointPatchField, pointMesh>& pfld, + const GeometricField<Type, fvPatchField, volMesh>& vfld, + const polyDecomp& decomp +) +{ + if (!vtkmesh) + { + return; + } + + const label nComp = pTraits<Type>::nComponents; + const labelUList& addPointCellLabels = decomp.addPointCellLabels(); + const labelUList& pointMap = decomp.pointMap(); + + // use a pointMap or address directly into mesh + const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size()); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(nPoints + addPointCellLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*(nPoints + addPointCellLabels.size())); + + // Note: using the name of the original volField + // not the name generated by the interpolation "volPointInterpolate(<name>)" + + if (&vfld != &GeometricField<Type, fvPatchField, volMesh>::null()) + { + fldData->SetName(vfld.name().c_str()); + } + else + { + fldData->SetName(pfld.name().c_str()); + } + + if (debug) + { + Info<< "convert Point field: " + << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + + if (pointMap.size()) + { + forAll(pointMap, i) + { + const Type& t = pfld[pointMap[i]]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i, vec); + } + } + else + { + forAll(pfld, i) + { + const Type& t = pfld[i]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i, vec); + } + } + + // continue insertion from here + label i = nPoints; + + if (&vfld != &GeometricField<Type, fvPatchField, volMesh>::null()) + { + forAll(addPointCellLabels, apI) + { + const Type& t = vfld[addPointCellLabels[apI]]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i++, vec); + } + } + else + { + forAll(addPointCellLabels, apI) + { + Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i++, vec); + } + } + + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// lagrangian-fields +// + +template<class Type> +void Foam::vtkPVFoam::convertLagrangianFields +( + const IOobjectList& objects, + vtkMultiBlockDataSet* output, + const label datasetNo +) +{ + const arrayRange& range = arrayRangeLagrangian_; + + forAllConstIter(IOobjectList, objects, iter) + { + // restrict to this IOField<Type> + if (iter()->headerClassName() == IOField<Type>::typeName) + { + vtkPolyData* vtkmesh = + getDataFromBlock<vtkPolyData>(output, range, datasetNo); + + if (vtkmesh) + { + IOField<Type> fld(*iter()); + + vtkFloatArray* fldData = convertFieldToVTK(fld.name(), fld); + vtkmesh->GetPointData()->AddArray(fldData); + fldData->Delete(); + } + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// +// low-level conversions +// + +template<class Type> +vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK +( + const word& name, + const Field<Type>& fld +) +{ + if (debug) + { + Info<< "convert Field<" << pTraits<Type>::typeName << "> " + << name + << " size=" << fld.size() + << " nComp=" << label(pTraits<Type>::nComponents) << endl; + } + + const label nComp = pTraits<Type>::nComponents; + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(fld.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*fld.size()); + fldData->SetName(name.c_str()); + + float vec[nComp]; + forAll(fld, i) + { + const Type& t = fld[i]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + + +template<class Type> +vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK +( + const GeometricField<Type, fvPatchField, volMesh>& fld, + const labelUList& faceLabels +) +{ + if (debug) + { + Info<< "convert face field: " + << fld.name() + << " size=" << faceLabels.size() + << " nComp=" << label(pTraits<Type>::nComponents) << endl; + } + + const fvMesh& mesh = fld.mesh(); + + const label nComp = pTraits<Type>::nComponents; + const label nInternalFaces = mesh.nInternalFaces(); + const labelList& faceOwner = mesh.faceOwner(); + const labelList& faceNeigh = mesh.faceNeighbour(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(faceLabels.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*faceLabels.size()); + fldData->SetName(fld.name().c_str()); + + float vec[nComp]; + + // for interior faces: average owner/neighbour + // for boundary faces: owner + forAll(faceLabels, facei) + { + const label faceNo = faceLabels[facei]; + if (faceNo < nInternalFaces) + { + Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]); + + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + } + else + { + const Type& t = fld[faceOwner[faceNo]]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(facei, vec); + } + + return fldData; +} + + +template<class Type> +vtkFloatArray* Foam::vtkPVFoam::convertVolFieldToVTK +( + const GeometricField<Type, fvPatchField, volMesh>& fld, + const polyDecomp& decompInfo +) +{ + const label nComp = pTraits<Type>::nComponents; + const labelList& superCells = decompInfo.superCells(); + + vtkFloatArray* fldData = vtkFloatArray::New(); + fldData->SetNumberOfTuples(superCells.size()); + fldData->SetNumberOfComponents(nComp); + fldData->Allocate(nComp*superCells.size()); + fldData->SetName(fld.name().c_str()); + + if (debug) + { + Info<< "convert volField: " + << fld.name() + << " size=" << superCells.size() + << " (" << fld.size() << " + " + << (superCells.size() - fld.size()) + << ") nComp=" << nComp << endl; + } + + float vec[nComp]; + forAll(superCells, i) + { + const Type& t = fld[superCells[i]]; + for (direction d=0; d<nComp; ++d) + { + vec[d] = component(t, d); + } + foamPvFields::remapTuple<Type>(vec); + + fldData->InsertTuple(i, vec); + } + + return fldData; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C index 47d2c3aa078fa5e13841f2ffb8585b371951d108..880ca89a4fb310b08c879702b1d9c0ff47c298d5 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,7 @@ License #include "vtkPVFoam.H" // OpenFOAM includes +#include "Cloud.H" #include "IOobjectList.H" #include "vtkPVFoamReader.h" @@ -34,29 +35,26 @@ License #include "vtkPolyData.h" #include "vtkUnstructuredGrid.h" -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -#include "vtkPVFoamVolFields.H" -#include "vtkPVFoamPointFields.H" -#include "vtkPVFoamLagrangianFields.H" +// Templates (only needed here) +#include "vtkPVFoamFieldTemplates.C" +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::vtkPVFoam::pruneObjectList ( IOobjectList& objects, - const wordHashSet& selected + const hashedWordList& retain ) { - // hash all the selected field names - if (selected.empty()) + if (retain.empty()) { objects.clear(); } - // only keep selected fields + // only retain specified fields forAllIter(IOobjectList, objects, iter) { - if (!selected.found(iter()->name())) + if (!retain.found(iter()->name())) { objects.erase(iter); } @@ -71,7 +69,8 @@ void Foam::vtkPVFoam::convertVolFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + const bool interpFields = reader_->GetInterpolateVolFields(); + hashedWordList selectedFields = getSelected ( reader_->GetVolFieldSelection() ); @@ -93,80 +92,50 @@ void Foam::vtkPVFoam::convertVolFields if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertVolFields" << nl - << "converting OpenFOAM volume fields" << endl; + Info<< "<beg> convert volume fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } - PtrList<PrimitivePatchInterpolation<primitivePatch>> - ppInterpList(mesh.boundaryMesh().size()); + PtrList<patchInterpolator> interpLst; - forAll(ppInterpList, i) + if (interpFields) { - ppInterpList.set - ( - i, - new PrimitivePatchInterpolation<primitivePatch> + interpLst.setSize(mesh.boundaryMesh().size()); + + forAll(interpLst, i) + { + interpLst.set ( - mesh.boundaryMesh()[i] - ) - ); + i, + new PrimitivePatchInterpolation<primitivePatch> + ( + mesh.boundaryMesh()[i] + ) + ); + } } + convertVolFields<scalar>(mesh, interpLst, objects, output); + convertVolFields<vector>(mesh, interpLst, objects, output); + convertVolFields<sphericalTensor>(mesh, interpLst, objects, output); + convertVolFields<symmTensor>(mesh, interpLst, objects, output); + convertVolFields<tensor>(mesh, interpLst, objects, output); - bool interpFields = reader_->GetInterpolateVolFields(); - - convertVolFields<scalar> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields<vector> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields<sphericalTensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields<symmTensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertVolFields<tensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); - - convertDimFields<scalar> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields<vector> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields<sphericalTensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields<symmTensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); - convertDimFields<tensor> - ( - mesh, ppInterpList, objects, interpFields, output - ); + convertDimFields<scalar>(mesh, interpLst, objects, output); + convertDimFields<vector>(mesh, interpLst, objects, output); + convertDimFields<sphericalTensor>(mesh, interpLst, objects, output); + convertDimFields<symmTensor>(mesh, interpLst, objects, output); + convertDimFields<tensor>(mesh, interpLst, objects, output); if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertVolFields" << endl; + Info<< "<end> convert volume fields" << endl; printMemory(); } } @@ -179,7 +148,7 @@ void Foam::vtkPVFoam::convertPointFields { const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetPointFieldSelection() ); @@ -205,12 +174,11 @@ void Foam::vtkPVFoam::convertPointFields if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertPointFields" << nl - << "converting OpenFOAM volume fields -> point fields" << endl; + Info<< "<beg> convert volume -> point fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } printMemory(); } @@ -218,31 +186,15 @@ void Foam::vtkPVFoam::convertPointFields // Construct interpolation on the raw mesh const pointMesh& pMesh = pointMesh::New(mesh); - - convertPointFields<scalar> - ( - mesh, pMesh, objects, output - ); - convertPointFields<vector> - ( - mesh, pMesh, objects, output - ); - convertPointFields<sphericalTensor> - ( - mesh, pMesh, objects, output - ); - convertPointFields<symmTensor> - ( - mesh, pMesh, objects, output - ); - convertPointFields<tensor> - ( - mesh, pMesh, objects, output - ); + convertPointFields<scalar>(pMesh, objects, output); + convertPointFields<vector>(pMesh, objects, output); + convertPointFields<sphericalTensor>(pMesh, objects, output); + convertPointFields<symmTensor>(pMesh, objects, output); + convertPointFields<tensor>(pMesh, objects, output); if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertPointFields" << endl; + Info<< "<end> convert volume -> point fields" << endl; printMemory(); } } @@ -256,7 +208,7 @@ void Foam::vtkPVFoam::convertLagrangianFields arrayRange& range = arrayRangeLagrangian_; const fvMesh& mesh = *meshPtr_; - wordHashSet selectedFields = getSelected + hashedWordList selectedFields = getSelected ( reader_->GetLagrangianFieldSelection() ); @@ -268,7 +220,7 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertLagrangianFields" << endl; + Info<< "<beg> convert Lagrangian fields" << endl; printMemory(); } @@ -282,7 +234,6 @@ void Foam::vtkPVFoam::convertLagrangianFields continue; } - // Get the Lagrangian fields for this time and this cloud // but only keep selected fields // the region name is already in the mesh db @@ -301,43 +252,25 @@ void Foam::vtkPVFoam::convertLagrangianFields if (debug) { - Info<< "converting OpenFOAM lagrangian fields" << nl; + Info<< "converting OpenFOAM lagrangian fields" << endl; forAllConstIter(IOobjectList, objects, iter) { Info<< " " << iter()->name() - << " == " << iter()->objectPath() << nl; + << " == " << iter()->objectPath() << endl; } } - convertLagrangianFields<label> - ( - objects, output, datasetNo - ); - convertLagrangianFields<scalar> - ( - objects, output, datasetNo - ); - convertLagrangianFields<vector> - ( - objects, output, datasetNo - ); - convertLagrangianFields<sphericalTensor> - ( - objects, output, datasetNo - ); - convertLagrangianFields<symmTensor> - ( - objects, output, datasetNo - ); - convertLagrangianFields<tensor> - ( - objects, output, datasetNo - ); + convertLagrangianFields<label>(objects, output, datasetNo); + convertLagrangianFields<scalar>(objects, output, datasetNo); + convertLagrangianFields<vector>(objects, output, datasetNo); + convertLagrangianFields<sphericalTensor>(objects, output, datasetNo); + convertLagrangianFields<symmTensor>(objects, output, datasetNo); + convertLagrangianFields<tensor>(objects, output, datasetNo); } if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertLagrangianFields" << endl; + Info<< "<end> convert Lagrangian fields" << endl; printMemory(); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamLagrangianFields.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamLagrangianFields.H deleted file mode 100644 index fcaff892ec6ea69f8c9a2c6e6da1726d1edeb0a2..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamLagrangianFields.H +++ /dev/null @@ -1,113 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamLagrangianFields_H -#define vtkPVFoamLagrangianFields_H - -#include "Cloud.H" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template<class Type> -void Foam::vtkPVFoam::convertLagrangianFields -( - const IOobjectList& objects, - vtkMultiBlockDataSet* output, - const label datasetNo -) -{ - const arrayRange& range = arrayRangeLagrangian_; - - forAllConstIter(IOobjectList, objects, iter) - { - // restrict to this IOField<Type> - if (iter()->headerClassName() == IOField<Type>::typeName) - { - IOField<Type> tf(*iter()); - convertLagrangianField(tf, output, range, datasetNo); - } - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertLagrangianField -( - const IOField<Type>& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const label nComp = pTraits<Type>::nComponents; - - vtkFloatArray* pointData = vtkFloatArray::New(); - pointData->SetNumberOfTuples(tf.size()); - pointData->SetNumberOfComponents(nComp); - pointData->Allocate(nComp*tf.size()); - pointData->SetName(tf.name().c_str()); - - if (debug) - { - Info<< "convert LagrangianField: " - << tf.name() - << " size = " << tf.size() - << " nComp=" << nComp - << " nTuples = " << tf.size() << endl; - } - - float vec[nComp]; - forAll(tf, i) - { - const Type& t = tf[i]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i, vec); - } - - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetPointData() - ->AddArray(pointData); - - pointData->Delete(); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C index d4aef5aa672f7049ee8dfea7fed53b8e296f0185..954866c540f4da18a5100a253d87dc73f97eb680 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,7 +57,7 @@ void Foam::vtkPVFoam::convertMeshVolume if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshVolume" << endl; + Info<< "<beg> convertMeshVolume" << endl; printMemory(); } @@ -80,7 +80,7 @@ void Foam::vtkPVFoam::convertMeshVolume if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, partName); + addToBlock(output, vtkmesh, range, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -95,7 +95,7 @@ void Foam::vtkPVFoam::convertMeshVolume if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshVolume" << endl; + Info<< "<end> convertMeshVolume" << endl; printMemory(); } } @@ -114,7 +114,7 @@ void Foam::vtkPVFoam::convertMeshLagrangian if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshLagrangian" << endl; + Info<< "<beg> convertMeshLagrangian" << endl; printMemory(); } @@ -131,7 +131,7 @@ void Foam::vtkPVFoam::convertMeshLagrangian if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, cloudName); + addToBlock(output, vtkmesh, range, datasetNo, cloudName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -146,7 +146,7 @@ void Foam::vtkPVFoam::convertMeshLagrangian if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshLagrangian" << endl; + Info<< "<end> convertMeshLagrangian" << endl; printMemory(); } } @@ -166,7 +166,7 @@ void Foam::vtkPVFoam::convertMeshPatches if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshPatches" << endl; + Info<< "<beg> convertMeshPatches" << endl; printMemory(); } @@ -201,26 +201,33 @@ void Foam::vtkPVFoam::convertMeshPatches { sz += patches[iter.key()].size(); } - labelList meshFaceLabels(sz); + labelList faceLabels(sz); sz = 0; forAllConstIter(labelHashSet, patchIds, iter) { const polyPatch& pp = patches[iter.key()]; forAll(pp, i) { - meshFaceLabels[sz++] = pp.start()+i; + faceLabels[sz++] = pp.start()+i; } } - UIndirectList<face> fcs(mesh.faces(), meshFaceLabels); - uindirectPrimitivePatch pp(fcs, mesh.points()); + + uindirectPrimitivePatch pp + ( + UIndirectList<face> + ( + mesh.faces(), + faceLabels + ), + mesh.points() + ); vtkmesh = patchVTKMesh(patchName, pp); } - if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, patchName); + addToBlock(output, vtkmesh, range, datasetNo, patchName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -235,7 +242,7 @@ void Foam::vtkPVFoam::convertMeshPatches if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshPatches" << endl; + Info<< "<end> convertMeshPatches" << endl; printMemory(); } } @@ -262,7 +269,7 @@ void Foam::vtkPVFoam::convertMeshCellZones if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshCellZones" << endl; + Info<< "<beg> convertMeshCellZones" << endl; printMemory(); } @@ -309,7 +316,7 @@ void Foam::vtkPVFoam::convertMeshCellZones // copy pointMap as well, otherwise pointFields fail zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap(); - AddToBlock(output, vtkmesh, range, datasetNo, zoneName); + addToBlock(output, vtkmesh, range, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -324,7 +331,7 @@ void Foam::vtkPVFoam::convertMeshCellZones if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshCellZones" << endl; + Info<< "<end> convertMeshCellZones" << endl; printMemory(); } } @@ -346,7 +353,7 @@ void Foam::vtkPVFoam::convertMeshCellSets if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshCellSets" << endl; + Info<< "<beg> convertMeshCellSets" << endl; printMemory(); } @@ -391,7 +398,7 @@ void Foam::vtkPVFoam::convertMeshCellSets // copy pointMap as well, otherwise pointFields fail csetPolyDecomp_[datasetNo].pointMap() = subsetter.pointMap(); - AddToBlock(output, vtkmesh, range, datasetNo, partName); + addToBlock(output, vtkmesh, range, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -406,7 +413,7 @@ void Foam::vtkPVFoam::convertMeshCellSets if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshCellSets" << endl; + Info<< "<end> convertMeshCellSets" << endl; printMemory(); } } @@ -430,7 +437,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshFaceZones" << endl; + Info<< "<beg> convertMeshFaceZones" << endl; printMemory(); } @@ -455,7 +462,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, zoneName); + addToBlock(output, vtkmesh, range, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -470,7 +477,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshFaceZones" << endl; + Info<< "<end> convertMeshFaceZones" << endl; printMemory(); } } @@ -489,7 +496,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshFaceSets" << endl; + Info<< "<beg> convertMeshFaceSets" << endl; printMemory(); } @@ -507,12 +514,26 @@ void Foam::vtkPVFoam::convertMeshFaceSets Info<< "Creating VTK mesh for faceSet=" << partName << endl; } - const faceSet fSet(mesh, partName); + // faces in sorted order for more reliability + uindirectPrimitivePatch p + ( + UIndirectList<face> + ( + mesh.faces(), + faceSet(mesh, partName).sortedToc() + ), + mesh.points() + ); + + if (p.empty()) + { + continue; + } - vtkPolyData* vtkmesh = faceSetVTKMesh(mesh, fSet); + vtkPolyData* vtkmesh = patchVTKMesh("faceSet:" + partName, p); if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, partName); + addToBlock(output, vtkmesh, range, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -527,7 +548,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshFaceSets" << endl; + Info<< "<end> convertMeshFaceSets" << endl; printMemory(); } } @@ -546,7 +567,7 @@ void Foam::vtkPVFoam::convertMeshPointZones if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshPointZones" << endl; + Info<< "<beg> convertMeshPointZones" << endl; printMemory(); } @@ -563,10 +584,24 @@ void Foam::vtkPVFoam::convertMeshPointZones continue; } - vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]); + const labelUList& pointLabels = zMesh[zoneId]; + + vtkPoints* vtkpoints = vtkPoints::New(); + vtkpoints->Allocate(pointLabels.size()); + + const pointField& meshPoints = mesh.points(); + forAll(pointLabels, pointi) + { + vtkpoints->InsertNextPoint(meshPoints[pointLabels[pointi]].v_); + } + + vtkPolyData* vtkmesh = vtkPolyData::New(); + vtkmesh->SetPoints(vtkpoints); + vtkpoints->Delete(); + if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, zoneName); + addToBlock(output, vtkmesh, range, datasetNo, zoneName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -582,7 +617,7 @@ void Foam::vtkPVFoam::convertMeshPointZones if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshPointZones" << endl; + Info<< "<end> convertMeshPointZones" << endl; printMemory(); } } @@ -602,7 +637,7 @@ void Foam::vtkPVFoam::convertMeshPointSets if (debug) { - Info<< "<beg> Foam::vtkPVFoam::convertMeshPointSets" << endl; + Info<< "<beg> convertMeshPointSets" << endl; printMemory(); } @@ -622,10 +657,22 @@ void Foam::vtkPVFoam::convertMeshPointSets const pointSet pSet(mesh, partName); - vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet); + vtkPoints* vtkpoints = vtkPoints::New(); + vtkpoints->Allocate(pSet.size()); + + const pointField& meshPoints = mesh.points(); + forAllConstIter(pointSet, pSet, iter) + { + vtkpoints->InsertNextPoint(meshPoints[iter.key()].v_); + } + + vtkPolyData* vtkmesh = vtkPolyData::New(); + vtkmesh->SetPoints(vtkpoints); + vtkpoints->Delete(); + if (vtkmesh) { - AddToBlock(output, vtkmesh, range, datasetNo, partName); + addToBlock(output, vtkmesh, range, datasetNo, partName); vtkmesh->Delete(); partDataset_[partId] = datasetNo++; @@ -640,7 +687,7 @@ void Foam::vtkPVFoam::convertMeshPointSets if (debug) { - Info<< "<end> Foam::vtkPVFoam::convertMeshPointSets" << endl; + Info<< "<end> convertMeshPointSets" << endl; printMemory(); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshLagrangian.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshLagrangian.C index fafbd0a28c5eac25a9e21e2473013a16fc0da92c..4527d841c56dac7b91639698e968d4527478eeaf 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshLagrangian.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshLagrangian.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,6 @@ License #include "fvMesh.H" #include "IOobjectList.H" #include "passiveParticle.H" -#include "vtkOpenFOAMPoints.H" // VTK includes #include "vtkCellArray.h" @@ -41,7 +40,7 @@ License vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh ( - const fvMesh& mesh, + const polyMesh& mesh, const word& cloudName ) { @@ -49,7 +48,7 @@ vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh if (debug) { - Info<< "<beg> Foam::vtkPVFoam::lagrangianVTKMesh - timePath " + Info<< "<beg> lagrangianVTKMesh - timePath " << mesh.time().timePath()/cloud::prefix/cloudName << endl; printMemory(); } @@ -83,7 +82,7 @@ vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh vtkIdType particleId = 0; forAllConstIter(Cloud<passiveParticle>, parcels, iter) { - vtkInsertNextOpenFOAMPoint(vtkpoints, iter().position()); + vtkpoints->InsertNextPoint(iter().position().v_); vtkcells->InsertNextCell(1, &particleId); particleId++; @@ -98,7 +97,7 @@ vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh if (debug) { - Info<< "<end> Foam::vtkPVFoam::lagrangianVTKMesh" << endl; + Info<< "<end> lagrangianVTKMesh" << endl; printMemory(); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C deleted file mode 100644 index a4c5a59e9a08b93ea07ad43a7c9299ed28fbe5be..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshSet.C +++ /dev/null @@ -1,148 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "vtkPVFoam.H" - -// OpenFOAM includes -#include "faceSet.H" -#include "pointSet.H" -#include "vtkOpenFOAMPoints.H" - -// VTK includes -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkCellArray.h" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -vtkPolyData* Foam::vtkPVFoam::faceSetVTKMesh -( - const fvMesh& mesh, - const faceSet& fSet -) -{ - vtkPolyData* vtkmesh = vtkPolyData::New(); - - if (debug) - { - Info<< "<beg> Foam::vtkPVFoam::faceSetVTKMesh" << endl; - printMemory(); - } - - // Construct primitivePatch of faces in fSet. - - const faceList& meshFaces = mesh.faces(); - faceList patchFaces(fSet.size()); - label facei = 0; - forAllConstIter(faceSet, fSet, iter) - { - patchFaces[facei++] = meshFaces[iter.key()]; - } - primitiveFacePatch p(patchFaces, mesh.points()); - - - // The balance of this routine should be identical to patchVTKMesh - - // Convert OpenFOAM mesh vertices to VTK - const pointField& points = p.localPoints(); - - vtkPoints* vtkpoints = vtkPoints::New(); - vtkpoints->Allocate(points.size()); - forAll(points, i) - { - vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]); - } - vtkmesh->SetPoints(vtkpoints); - vtkpoints->Delete(); - - // Add faces as polygons - const faceList& faces = p.localFaces(); - - vtkCellArray* vtkcells = vtkCellArray::New(); - vtkcells->Allocate(faces.size()); - - forAll(faces, facei) - { - const face& f = faces[facei]; - vtkIdType nodeIds[f.size()]; - - forAll(f, fp) - { - nodeIds[fp] = f[fp]; - } - vtkcells->InsertNextCell(f.size(), nodeIds); - } - - vtkmesh->SetPolys(vtkcells); - vtkcells->Delete(); - - if (debug) - { - Info<< "<end> Foam::vtkPVFoam::faceSetVTKMesh" << endl; - printMemory(); - } - - return vtkmesh; -} - - -vtkPolyData* Foam::vtkPVFoam::pointSetVTKMesh -( - const fvMesh& mesh, - const pointSet& pSet -) -{ - vtkPolyData* vtkmesh = vtkPolyData::New(); - - if (debug) - { - Info<< "<beg> Foam::vtkPVFoam::pointSetVTKMesh" << endl; - printMemory(); - } - - const pointField& meshPoints = mesh.points(); - - vtkPoints* vtkpoints = vtkPoints::New(); - vtkpoints->Allocate(pSet.size()); - - forAllConstIter(pointSet, pSet, iter) - { - vtkInsertNextOpenFOAMPoint(vtkpoints, meshPoints[iter.key()]); - } - - vtkmesh->SetPoints(vtkpoints); - vtkpoints->Delete(); - - if (debug) - { - Info<< "<end> Foam::vtkPVFoam::pointSetVTKMesh" << endl; - printMemory(); - } - - return vtkmesh; -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshVolume.C index 64507aaadb18c06d06a3fca81e4abecb8a67fa0c..6321e3cdfafa4355be5378d4d16bd423192f1a33 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshVolume.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshVolume.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,8 +29,6 @@ License // OpenFOAM includes #include "fvMesh.H" #include "cellModeller.H" -#include "vtkOpenFOAMPoints.H" -#include "Swap.H" // VTK includes #include "vtkCellArray.h" @@ -56,7 +54,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh if (debug) { - Info<< "<beg> Foam::vtkPVFoam::volumeVTKMesh" << endl; + Info<< "<beg> volumeVTKMesh" << endl; printMemory(); } @@ -78,11 +76,6 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh // and cells if (!reader_->GetUseVTKPolyhedron()) { - if (debug) - { - Info<< "... scanning for polyhedra" << endl; - } - forAll(cellShapes, celli) { const cellModel& model = cellShapes[celli].model(); @@ -123,21 +116,8 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh // Set size of additional cells mapping array // (from added cell to original cell) - if (debug) - { - Info<<" mesh nCells = " << mesh.nCells() << nl - <<" nPoints = " << mesh.nPoints() << nl - <<" nAddCells = " << nAddCells << nl - <<" nAddPoints = " << nAddPoints << endl; - } - superCells.setSize(mesh.nCells() + nAddCells); - if (debug) - { - Info<< "... converting points" << endl; - } - // Convert OpenFOAM mesh vertices to VTK vtkPoints* vtkpoints = vtkPoints::New(); vtkpoints->Allocate(mesh.nPoints() + nAddPoints); @@ -146,13 +126,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh forAll(points, i) { - vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]); - } - - - if (debug) - { - Info<< "... converting cells" << endl; + vtkpoints->InsertNextPoint(points[i].v_); } vtkmesh->Allocate(mesh.nCells() + nAddCells); @@ -329,7 +303,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh // The new vertex from the cell-centre const label newVertexLabel = mesh.nPoints() + addPointi; - vtkInsertNextOpenFOAMPoint(vtkpoints, mesh.C()[celli]); + vtkpoints->InsertNextPoint(mesh.C()[celli].v_); // Whether to insert cell in place of original or not. bool substituteCell = true; @@ -441,7 +415,10 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh if (debug) { - Info<< "<end> Foam::vtkPVFoam::volumeVTKMesh" << endl; + Info<<"nCells=" << mesh.nCells() <<" nPoints=" << mesh.nPoints() + <<" nAddCells=" << nAddCells <<" nAddPoints=" << nAddPoints + << nl + << "<end> volumeVTKMesh" << endl; printMemory(); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshZone.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshZone.C deleted file mode 100644 index e60a8aea4a54a6407a7416d8ab76fe4ce899e7d6..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamMeshZone.C +++ /dev/null @@ -1,75 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "vtkPVFoam.H" - -// OpenFOAM includes -#include "vtkOpenFOAMPoints.H" - -// VTK includes -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkCellArray.h" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -vtkPolyData* Foam::vtkPVFoam::pointZoneVTKMesh -( - const fvMesh& mesh, - const labelList& pointLabels -) -{ - vtkPolyData* vtkmesh = vtkPolyData::New(); - - if (debug) - { - Info<< "<beg> Foam::vtkPVFoam::pointZoneVTKMesh" << endl; - printMemory(); - } - - const pointField& meshPoints = mesh.points(); - - vtkPoints* vtkpoints = vtkPoints::New(); - vtkpoints->Allocate(pointLabels.size()); - - forAll(pointLabels, pointi) - { - vtkInsertNextOpenFOAMPoint(vtkpoints, meshPoints[pointLabels[pointi]]); - } - - vtkmesh->SetPoints(vtkpoints); - vtkpoints->Delete(); - - if (debug) - { - Info<< "<beg> Foam::vtkPVFoam::pointZoneVTKMesh" << endl; - printMemory(); - } - - return vtkmesh; -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPatchField.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPatchField.H deleted file mode 100644 index 0aafd18bd2912bb0e6c95f36c6a73375ea82da25..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPatchField.H +++ /dev/null @@ -1,129 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamPatchField_H -#define vtkPVFoamPatchField_H - -// VTK includes -#include "vtkCellData.h" -#include "vtkFloatArray.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkPointData.h" -#include "vtkPolyData.h" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template<class Type> -void Foam::vtkPVFoam::convertPatchField -( - const word& name, - const Field<Type>& ptf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const label nComp = pTraits<Type>::nComponents; - - vtkFloatArray* cellData = vtkFloatArray::New(); - cellData->SetNumberOfTuples(ptf.size()); - cellData->SetNumberOfComponents(nComp); - cellData->Allocate(nComp*ptf.size()); - cellData->SetName(name.c_str()); - - float vec[nComp]; - forAll(ptf, i) - { - const Type& t = ptf[i]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - cellData->InsertTuple(i, vec); - } - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetCellData() - ->AddArray(cellData); - - cellData->Delete(); -} - - -// as above, but with PointData() -template<class Type> -void Foam::vtkPVFoam::convertPatchPointField -( - const word& name, - const Field<Type>& pptf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const label nComp = pTraits<Type>::nComponents; - - vtkFloatArray* pointData = vtkFloatArray::New(); - pointData->SetNumberOfTuples(pptf.size()); - pointData->SetNumberOfComponents(nComp); - pointData->Allocate(nComp*pptf.size()); - pointData->SetName(name.c_str()); - - float vec[nComp]; - forAll(pptf, i) - { - const Type& t = pptf[i]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i, vec); - } - - vtkPolyData::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetPointData() - ->AddArray(pointData); - - pointData->Delete(); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPointFields.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPointFields.H deleted file mode 100644 index fc22aca9a12e3bcb4867b13ccff40ba6c19b4546..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamPointFields.H +++ /dev/null @@ -1,331 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamPointFields_H -#define vtkPVFoamPointFields_H - -// OpenFOAM includes -#include "interpolatePointToCell.H" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template<class Type> -void Foam::vtkPVFoam::convertPointFields -( - const fvMesh& mesh, - const pointMesh& pMesh, - const IOobjectList& objects, - vtkMultiBlockDataSet* output -) -{ - const polyBoundaryMesh& patches = mesh.boundaryMesh(); - - forAllConstIter(IOobjectList, objects, iter) - { - const word& fieldName = iter()->name(); - // restrict to this GeometricField<Type, ...> - if - ( - iter()->headerClassName() - != GeometricField<Type, pointPatchField, pointMesh>::typeName - ) - { - continue; - } - - if (debug) - { - Info<< "Foam::vtkPVFoam::convertPointFields : " - << fieldName << endl; - } - - GeometricField<Type, pointPatchField, pointMesh> ptf - ( - *iter(), - pMesh - ); - - - // Convert activated internalMesh regions - convertPointFieldBlock - ( - ptf, - output, - arrayRangeVolume_, - regionPolyDecomp_ - ); - - // Convert activated cellZones - convertPointFieldBlock - ( - ptf, - output, - arrayRangeCellZones_, - zonePolyDecomp_ - ); - - // Convert activated cellSets - convertPointFieldBlock - ( - ptf, - output, - arrayRangeCellSets_, - csetPolyDecomp_ - ); - - - // - // Convert patches - if activated - // - for - ( - int partId = arrayRangePatches_.start(); - partId < arrayRangePatches_.end(); - ++partId - ) - { - const word patchName = getPartName(partId); - const label datasetNo = partDataset_[partId]; - const label patchId = patches.findPatchID(patchName); - - if (!partStatus_[partId] || datasetNo < 0 || patchId < 0) - { - continue; - } - - convertPatchPointField - ( - fieldName, - ptf.boundaryField()[patchId].patchInternalField()(), - output, - arrayRangePatches_, - datasetNo - ); - } - - // - // Convert faceZones - if activated - // - for - ( - int partId = arrayRangeFaceZones_.start(); - partId < arrayRangeFaceZones_.end(); - ++partId - ) - { - const word zoneName = getPartName(partId); - const label datasetNo = partDataset_[partId]; - const label zoneId = mesh.faceZones().findZoneID(zoneName); - - if (!partStatus_[partId] || datasetNo < 0 || zoneId < 0) - { - continue; - } - - // Extract the field on the zone - Field<Type> fld - ( - ptf.primitiveField(), - mesh.faceZones()[zoneId]().meshPoints() - ); - - convertPatchPointField - ( - fieldName, - fld, - output, - arrayRangeFaceZones_, - datasetNo - ); - } - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertPointFieldBlock -( - const GeometricField<Type, pointPatchField, pointMesh>& ptf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const List<polyDecomp>& decompLst -) -{ - for (int partId = range.start(); partId < range.end(); ++partId) - { - const label datasetNo = partDataset_[partId]; - - if (datasetNo >= 0 && partStatus_[partId]) - { - convertPointField - ( - ptf, - GeometricField<Type, fvPatchField, volMesh>::null(), - output, - range, - datasetNo, - decompLst[datasetNo] - ); - } - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertPointField -( - const GeometricField<Type, pointPatchField, pointMesh>& ptf, - const GeometricField<Type, fvPatchField, volMesh>& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo, - const polyDecomp& decomp -) -{ - const label nComp = pTraits<Type>::nComponents; - const labelList& addPointCellLabels = decomp.addPointCellLabels(); - const labelList& pointMap = decomp.pointMap(); - - // use a pointMap or address directly into mesh - label nPoints; - if (pointMap.size()) - { - nPoints = pointMap.size(); - } - else - { - nPoints = ptf.size(); - } - - vtkFloatArray* pointData = vtkFloatArray::New(); - pointData->SetNumberOfTuples(nPoints + addPointCellLabels.size()); - pointData->SetNumberOfComponents(nComp); - pointData->Allocate(nComp*(nPoints + addPointCellLabels.size())); - - // Note: using the name of the original volField - // not the name generated by the interpolation "volPointInterpolate(<name>)" - - if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null()) - { - pointData->SetName(tf.name().c_str()); - } - else - { - pointData->SetName(ptf.name().c_str()); - } - - if (debug) - { - Info<< "convert convertPointField: " - << ptf.name() - << " size = " << nPoints - << " nComp=" << nComp - << " nTuples = " << (nPoints + addPointCellLabels.size()) - << endl; - } - - float vec[nComp]; - - if (pointMap.size()) - { - forAll(pointMap, i) - { - const Type& t = ptf[pointMap[i]]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i, vec); - } - } - else - { - forAll(ptf, i) - { - const Type& t = ptf[i]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i, vec); - } - } - - // continue insertion from here - label i = nPoints; - - if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null()) - { - forAll(addPointCellLabels, apI) - { - const Type& t = tf[addPointCellLabels[apI]]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i++, vec); - } - } - else - { - forAll(addPointCellLabels, apI) - { - Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]); - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - pointData->InsertTuple(i++, vec); - } - } - - vtkUnstructuredGrid::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetPointData() - ->AddArray(pointData); - - pointData->Delete(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamTemplates.C index 714d73d7ce9031e40a41843eb90863fa3de56f82..388f1bb79404b7dc0f3bd954c513115a6e886af4 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,6 @@ License // OpenFOAM includes #include "polyPatch.H" #include "primitivePatch.H" -#include "vtkOpenFOAMPoints.H" // VTK includes #include "vtkCellArray.h" @@ -48,7 +47,7 @@ vtkPolyData* Foam::vtkPVFoam::patchVTKMesh if (debug) { - Info<< "<beg> Foam::vtkPVFoam::patchVTKMesh - " << name << endl; + Info<< "<beg> patchVTKMesh - " << name << endl; printMemory(); } @@ -59,13 +58,12 @@ vtkPolyData* Foam::vtkPVFoam::patchVTKMesh vtkpoints->Allocate(points.size()); forAll(points, i) { - vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]); + vtkpoints->InsertNextPoint(points[i].v_); } vtkmesh->SetPoints(vtkpoints); vtkpoints->Delete(); - // Add faces as polygons const faceList& faces = p.localFaces(); @@ -88,7 +86,7 @@ vtkPolyData* Foam::vtkPVFoam::patchVTKMesh if (debug) { - Info<< "<end> Foam::vtkPVFoam::patchVTKMesh - " << name << endl; + Info<< "<end> patchVTKMesh - " << name << endl; printMemory(); } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C index 850a353590a15ee303281291346b139f72a3dc41..41855ddd7b5d86d6b7e74483653a334a72e45ee0 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfo.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,13 +36,12 @@ License #include "Cloud.H" #include "vtkPVFoamReader.h" -// local headers -#include "vtkPVFoamAddToSelection.H" -#include "vtkPVFoamUpdateInfoFields.H" - // VTK includes #include "vtkDataArraySelection.h" +// Templates (only needed here) +#include "vtkPVFoamUpdateTemplates.C" + // * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * // @@ -85,14 +84,14 @@ template<class ZoneType> Foam::wordList Foam::vtkPVFoam::getZoneNames ( const ZoneMesh<ZoneType, polyMesh>& zmesh -) const +) { wordList names(zmesh.size()); label nZone = 0; forAll(zmesh, zoneI) { - if (zmesh[zoneI].size()) + if (!zmesh[zoneI].empty()) { names[nZone++] = zmesh[zoneI].name(); } @@ -124,7 +123,7 @@ Foam::wordList Foam::vtkPVFoam::getZoneNames(const word& zoneType) const false ); - if (ioObj.typeHeaderOk<cellZoneMesh>(false)) + if (ioObj.typeHeaderOk<cellZoneMesh>(false, false)) { zonesEntries zones(ioObj); @@ -146,7 +145,7 @@ void Foam::vtkPVFoam::updateInfoInternalMesh { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoInternalMesh" << endl; + Info<< "<beg> updateInfoInternalMesh" << endl; } // Determine mesh parts (internalMesh, patches...) @@ -160,10 +159,7 @@ void Foam::vtkPVFoam::updateInfoInternalMesh if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVFoam::updateInfoInternalMesh" << endl; + Info<< "<end> updateInfoInternalMesh" << endl; } } @@ -175,7 +171,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoLagrangian" << nl + Info<< "<beg> updateInfoLagrangian" << nl << " " << dbPtr_->timePath()/cloud::prefix << endl; } @@ -211,10 +207,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVFoam::updateInfoLagrangian" << endl; + Info<< "<end> updateInfoLagrangian" << endl; } } @@ -227,8 +220,8 @@ void Foam::vtkPVFoam::updateInfoPatches { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoPatches" - << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; + Info<< "<beg> updateInfoPatches" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } @@ -333,7 +326,7 @@ void Foam::vtkPVFoam::updateInfoPatches ); // this should only ever fail if the mesh region doesn't exist - if (ioObj.typeHeaderOk<polyBoundaryMesh>(true)) + if (ioObj.typeHeaderOk<polyBoundaryMesh>(true, false)) { polyBoundaryMeshEntries patchEntries(ioObj); @@ -377,7 +370,7 @@ void Foam::vtkPVFoam::updateInfoPatches } else { - groups.insert(groupNames[groupI], labelList(1, patchi)); + groups.insert(groupNames[groupI], labelList{patchi}); } } } @@ -455,10 +448,7 @@ void Foam::vtkPVFoam::updateInfoPatches if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVFoam::updateInfoPatches" << endl; + Info<< "<end> updateInfoPatches" << endl; } } @@ -475,8 +465,8 @@ void Foam::vtkPVFoam::updateInfoZones if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoZones" - << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; + Info<< "<beg> updateInfoZones" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } wordList namesLst; @@ -551,10 +541,7 @@ void Foam::vtkPVFoam::updateInfoZones if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVFoam::updateInfoZones" << endl; + Info<< "<end> updateInfoZones" << endl; } } @@ -571,7 +558,7 @@ void Foam::vtkPVFoam::updateInfoSets if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoSets" << endl; + Info<< "<beg> updateInfoSets" << endl; } // Add names of sets. Search for last time directory with a sets @@ -596,7 +583,7 @@ void Foam::vtkPVFoam::updateInfoSets if (debug) { - Info<< " Foam::vtkPVFoam::updateInfoSets read " + Info<< " updateInfoSets read " << objects.names() << " from " << setsInstance << endl; } @@ -627,28 +614,41 @@ void Foam::vtkPVFoam::updateInfoSets if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVFoam::updateInfoSets" << endl; + Info<< "<end> updateInfoSets" << endl; } } -void Foam::vtkPVFoam::updateInfoLagrangianFields() +void Foam::vtkPVFoam::updateInfoFields() +{ + updateInfoFields<fvPatchField, volMesh> + ( + reader_->GetVolFieldSelection() + ); + updateInfoFields<pointPatchField, pointMesh> + ( + reader_->GetPointFieldSelection() + ); + updateInfoLagrangianFields + ( + reader_->GetLagrangianFieldSelection() + ); +} + + +void Foam::vtkPVFoam::updateInfoLagrangianFields +( + vtkDataArraySelection* select +) { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoLagrangianFields" - << endl; + Info<< "<beg> updateInfoLagrangianFields" << endl; } - vtkDataArraySelection* fieldSelection = - reader_->GetLagrangianFieldSelection(); - // preserve the enabled selections - stringList enabledEntries = getSelectedArrayEntries(fieldSelection); - fieldSelection->RemoveAllArrays(); + stringList enabledEntries = getSelectedArrayEntries(select); + select->RemoveAllArrays(); // TODO - currently only get fields from ONE cloud // have to decide if the second set of fields get mixed in @@ -678,44 +678,37 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields() lagrangianPrefix/cloudName ); - addToSelection<IOField<label>> - ( - fieldSelection, - objects - ); - addToSelection<IOField<scalar>> - ( - fieldSelection, - objects - ); - addToSelection<IOField<vector>> - ( - fieldSelection, - objects - ); - addToSelection<IOField<sphericalTensor>> - ( - fieldSelection, - - objects - ); - addToSelection<IOField<symmTensor>> - ( - fieldSelection, - objects - ); - addToSelection<IOField<tensor>> - ( - fieldSelection, - objects - ); + addToSelection<IOField<label>>(select, objects); + addToSelection<IOField<scalar>>(select, objects); + addToSelection<IOField<vector>>(select, objects); + addToSelection<IOField<sphericalTensor>>(select, objects); + addToSelection<IOField<symmTensor>>(select, objects); + addToSelection<IOField<tensor>>(select, objects); // restore the enabled selections - setSelectedArrayEntries(fieldSelection, enabledEntries); + setSelectedArrayEntries(select, enabledEntries); + + if (debug > 1) + { + boolList status; + const label nElem = getSelected(status, select); + + forAll(status, i) + { + Info<< " lagrangian[" << i << "] = " + << status[i] + << " : " << select->GetArrayName(i) << nl; + } + + if (!nElem) + { + Info<< " lagrangian[none]" << nl; + } + } if (debug) { - Info<< "<end> Foam::vtkPVFoam::updateInfoLagrangianFields - " + Info<< "<end> updateInfoLagrangianFields - " << "lagrangian objects.size() = " << objects.size() << endl; } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfoFields.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateTemplates.C similarity index 84% rename from applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfoFields.H rename to applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateTemplates.C index 561fdc0ee75b20b82bffe9bed81e56d3bcceadf1..1d2b429467b24ad68675c71543ff0232a93e6f44 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateInfoFields.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUpdateTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,8 +26,8 @@ InClass \*---------------------------------------------------------------------------*/ -#ifndef vtkPVFoamUpdateInfoFields_H -#define vtkPVFoamUpdateInfoFields_H +#ifndef vtkPVFoamUpdateTemplates_C +#define vtkPVFoamUpdateTemplates_C // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -39,19 +39,17 @@ void Foam::vtkPVFoam::updateInfoFields { if (debug) { - Info<< "<beg> Foam::vtkPVFoam::updateInfoFields <" + Info<< "<beg> updateInfoFields <" << meshType::Mesh::typeName - << "> [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" + << "> [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } stringList enabledEntries; - // enable 'p' and 'U' on the first call - if (select->GetNumberOfArrays() == 0 && !meshPtr_) + if (!select->GetNumberOfArrays() && !meshPtr_) { - enabledEntries.setSize(2); - enabledEntries[0] = "p"; - enabledEntries[1] = "U"; + // enable 'p' and 'U' only on the first call + enabledEntries = { "p", "U" }; } else { @@ -72,7 +70,7 @@ void Foam::vtkPVFoam::updateInfoFields // Search for list of objects for this time and mesh region IOobjectList objects(dbPtr_(), dbPtr_().timeName(), regionPrefix); - //- Add volume fields to GUI + // Add volume fields to GUI addToSelection<GeometricField<scalar, patchType, meshType>> ( select, @@ -93,13 +91,14 @@ void Foam::vtkPVFoam::updateInfoFields select, objects ); + addToSelection<GeometricField<tensor, patchType, meshType>> ( select, objects ); - //- Add dimensioned fields to GUI + // Add dimensioned fields to GUI addToSelection<DimensionedField<scalar, meshType>> ( select, @@ -132,7 +131,7 @@ void Foam::vtkPVFoam::updateInfoFields if (debug) { - Info<< "<end> Foam::vtkPVFoam::updateInfoFields" << endl; + Info<< "<end> updateInfoFields" << endl; } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C deleted file mode 100644 index 0280afa5aeedca6d05bf3336b6a9f4153f329bb4..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamUtils.C +++ /dev/null @@ -1,340 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Description - Misc helper methods and utilities - -\*---------------------------------------------------------------------------*/ - -#include "vtkPVFoam.H" -#include "vtkPVFoamReader.h" - -// OpenFOAM includes -#include "fvMesh.H" -#include "Time.H" -#include "IFstream.H" -#include "memInfo.H" - -// VTK includes -#include "vtkDataArraySelection.h" -#include "vtkDataSet.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkInformation.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - //! \cond fileScope - // Extract up to the first non-word characters - inline word getFirstWord(const char* str) - { - if (str) - { - label n = 0; - while (str[n] && word::valid(str[n])) - { - ++n; - } - return word(str, n, true); - } - else - { - return word::null; - } - - } - //! \endcond - -} // End namespace Foam - - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::vtkPVFoam::AddToBlock -( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange& range, - const label datasetNo, - const std::string& datasetName -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - - if (!block) - { - if (blockDO) - { - FatalErrorInFunction - << "Block already has a vtkDataSet assigned to it" - << endl; - return; - } - - block = vtkMultiBlockDataSet::New(); - output->SetBlock(blockNo, block); - block->Delete(); - } - - if (debug) - { - Info<< "block[" << blockNo << "] has " - << block->GetNumberOfBlocks() - << " datasets prior to adding set " << datasetNo - << " with name: " << datasetName << endl; - } - - block->SetBlock(datasetNo, dataset); - - // name the block when assigning dataset 0 - if (datasetNo == 0) - { - output->GetMetaData(blockNo)->Set - ( - vtkCompositeDataSet::NAME(), - range.name() - ); - } - - if (datasetName.size()) - { - block->GetMetaData(datasetNo)->Set - ( - vtkCompositeDataSet::NAME(), - datasetName.c_str() - ); - } -} - - -vtkDataSet* Foam::vtkPVFoam::GetDataSetFromBlock -( - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - - if (block) - { - return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); - } - - return 0; -} - - -// ununsed at the moment -Foam::label Foam::vtkPVFoam::GetNumberOfDataSets -( - vtkMultiBlockDataSet* output, - const arrayRange& range -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - if (block) - { - return block->GetNumberOfBlocks(); - } - - return 0; -} - - -Foam::word Foam::vtkPVFoam::getPartName(const int partId) -{ - return getFirstWord(reader_->GetPartArrayName(partId)); -} - - -Foam::wordHashSet Foam::vtkPVFoam::getSelected -( - vtkDataArraySelection* select -) -{ - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); - - for (int elemI=0; elemI < nElem; ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections.insert(getFirstWord(select->GetArrayName(elemI))); - } - } - - return selections; -} - - -Foam::wordHashSet Foam::vtkPVFoam::getSelected -( - vtkDataArraySelection* select, - const arrayRange& range -) -{ - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); - - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections.insert(getFirstWord(select->GetArrayName(elemI))); - } - } - - return selections; -} - - -Foam::stringList Foam::vtkPVFoam::getSelectedArrayEntries -( - vtkDataArraySelection* select -) -{ - stringList selections(select->GetNumberOfArrays()); - label nElem = 0; - - forAll(selections, elemI) - { - if (select->GetArraySetting(elemI)) - { - selections[nElem++] = select->GetArrayName(elemI); - } - } - selections.setSize(nElem); - - - if (debug) - { - label nElem = select->GetNumberOfArrays(); - Info<< "available("; - for (int elemI = 0; elemI < nElem; ++elemI) - { - Info<< " \"" << select->GetArrayName(elemI) << "\""; - } - Info<< " )\nselected("; - - forAll(selections, elemI) - { - Info<< " " << selections[elemI]; - } - Info<< " )\n"; - } - - return selections; -} - - -Foam::stringList Foam::vtkPVFoam::getSelectedArrayEntries -( - vtkDataArraySelection* select, - const arrayRange& range -) -{ - stringList selections(range.size()); - label nElem = 0; - - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections[nElem++] = select->GetArrayName(elemI); - } - } - selections.setSize(nElem); - - - if (debug) - { - Info<< "available("; - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - Info<< " \"" << select->GetArrayName(elemI) << "\""; - } - Info<< " )\nselected("; - - forAll(selections, elemI) - { - Info<< " " << selections[elemI]; - } - Info<< " )\n"; - } - - return selections; -} - - -void Foam::vtkPVFoam::setSelectedArrayEntries -( - vtkDataArraySelection* select, - const stringList& selections -) -{ - const int nElem = select->GetNumberOfArrays(); - select->DisableAllArrays(); - - // Loop through entries, setting values from selectedEntries - for (int elemI=0; elemI < nElem; ++elemI) - { - string arrayName(select->GetArrayName(elemI)); - - forAll(selections, elemI) - { - if (selections[elemI] == arrayName) - { - select->EnableArray(arrayName.c_str()); - break; - } - } - } -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::vtkPVFoam::printMemory() -{ - memInfo mem; - - if (mem.valid()) - { - Info<< "mem peak/size/rss: " << mem << "\n"; - } -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamVolFields.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamVolFields.H deleted file mode 100644 index 7a34bbca1ca2fe100bbb4e615ca6001cd9660e71..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamVolFields.H +++ /dev/null @@ -1,456 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVFoam - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkPVFoamVolFields_H -#define vtkPVFoamVolFields_H - -// OpenFOAM includes -#include "emptyFvPatchField.H" -#include "wallPolyPatch.H" -#include "faceSet.H" -#include "volPointInterpolation.H" -#include "zeroGradientFvPatchField.H" - -#include "vtkPVFoamFaceField.H" -#include "vtkPVFoamPatchField.H" - -#include "vtkOpenFOAMTupleRemap.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -template<class Type> -void Foam::vtkPVFoam::convertVolField -( - const PtrList<PrimitivePatchInterpolation<primitivePatch>>& ppInterpList, - const GeometricField<Type, fvPatchField, volMesh>& tf, - const bool interpFields, - vtkMultiBlockDataSet* output -) -{ - const fvMesh& mesh = tf.mesh(); - const polyBoundaryMesh& patches = mesh.boundaryMesh(); - - // Interpolated field (demand driven) - autoPtr<GeometricField<Type, pointPatchField, pointMesh>> ptfPtr; - if (interpFields) - { - if (debug) - { - Info<< "convertVolFieldBlock interpolating:" << tf.name() - << endl; - } - - ptfPtr.reset - ( - volPointInterpolation::New(mesh).interpolate(tf).ptr() - ); - } - - // Convert activated internalMesh regions - convertVolFieldBlock - ( - tf, - ptfPtr, - output, - arrayRangeVolume_, - regionPolyDecomp_ - ); - - // Convert activated cellZones - convertVolFieldBlock - ( - tf, - ptfPtr, - output, - arrayRangeCellZones_, - zonePolyDecomp_ - ); - - // Convert activated cellSets - convertVolFieldBlock - ( - tf, - ptfPtr, - output, - arrayRangeCellSets_, - csetPolyDecomp_ - ); - - - // - // Convert patches - if activated - // - for - ( - int partId = arrayRangePatches_.start(); - partId < arrayRangePatches_.end(); - ++partId - ) - { - const word patchName = getPartName(partId); - const label datasetNo = partDataset_[partId]; - const label patchId = patches.findPatchID(patchName); - - if (!partStatus_[partId] || datasetNo < 0 || patchId < 0) - { - continue; - } - - const fvPatchField<Type>& ptf = tf.boundaryField()[patchId]; - - if - ( - isType<emptyFvPatchField<Type>>(ptf) - || - ( - reader_->GetExtrapolatePatches() - && !polyPatch::constraintType(patches[patchId].type()) - ) - ) - { - fvPatch p(ptf.patch().patch(), mesh.boundary()); - - tmp<Field<Type>> tpptf - ( - fvPatchField<Type>(p, tf).patchInternalField() - ); - - convertPatchField - ( - tf.name(), - tpptf(), - output, - arrayRangePatches_, - datasetNo - ); - - if (interpFields) - { - convertPatchPointField - ( - tf.name(), - ppInterpList[patchId].faceToPointInterpolate(tpptf)(), - output, - arrayRangePatches_, - datasetNo - ); - } - } - else - { - convertPatchField - ( - tf.name(), - ptf, - output, - arrayRangePatches_, - datasetNo - ); - - if (interpFields) - { - convertPatchPointField - ( - tf.name(), - ppInterpList[patchId].faceToPointInterpolate(ptf)(), - output, - arrayRangePatches_, - datasetNo - ); - } - } - } - - // - // Convert face zones - if activated - // - for - ( - int partId = arrayRangeFaceZones_.start(); - partId < arrayRangeFaceZones_.end(); - ++partId - ) - { - const word zoneName = getPartName(partId); - const label datasetNo = partDataset_[partId]; - - if (!partStatus_[partId] || datasetNo < 0) - { - continue; - } - - const faceZoneMesh& zMesh = mesh.faceZones(); - const label zoneId = zMesh.findZoneID(zoneName); - - if (zoneId < 0) - { - continue; - } - - convertFaceField - ( - tf, - output, - arrayRangeFaceZones_, - datasetNo, - mesh, - zMesh[zoneId] - ); - - // TODO: points - } - - // - // Convert face sets - if activated - // - for - ( - int partId = arrayRangeFaceSets_.start(); - partId < arrayRangeFaceSets_.end(); - ++partId - ) - { - const word selectName = getPartName(partId); - const label datasetNo = partDataset_[partId]; - - if (!partStatus_[partId] || datasetNo < 0) - { - continue; - } - - const faceSet fSet(mesh, selectName); - - convertFaceField - ( - tf, - output, - arrayRangeFaceSets_, - datasetNo, - mesh, - fSet.toc() - ); - - // TODO: points - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertVolFields -( - const fvMesh& mesh, - const PtrList<PrimitivePatchInterpolation<primitivePatch>>& ppInterpList, - const IOobjectList& objects, - const bool interpFields, - vtkMultiBlockDataSet* output -) -{ - forAllConstIter(IOobjectList, objects, iter) - { - // restrict to GeometricField<Type, ...> - if - ( - iter()->headerClassName() - != GeometricField<Type, fvPatchField, volMesh>::typeName - ) - { - continue; - } - - // Load field - GeometricField<Type, fvPatchField, volMesh> tf - ( - *iter(), - mesh - ); - - // Convert - convertVolField(ppInterpList, tf, interpFields, output); - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertDimFields -( - const fvMesh& mesh, - const PtrList<PrimitivePatchInterpolation<primitivePatch>>& ppInterpList, - const IOobjectList& objects, - const bool interpFields, - vtkMultiBlockDataSet* output -) -{ - forAllConstIter(IOobjectList, objects, iter) - { - // restrict to DimensionedField<Type, ...> - if - ( - iter()->headerClassName() - != DimensionedField<Type, volMesh>::typeName - ) - { - continue; - } - - // Load field - DimensionedField<Type, volMesh> dimFld(*iter(), mesh); - - - // Construct volField with zero-gradient patch fields - - IOobject io(dimFld); - io.readOpt() = IOobject::NO_READ; - - PtrList<fvPatchField<Type>> patchFields(mesh.boundary().size()); - forAll(patchFields, patchI) - { - patchFields.set - ( - patchI, - fvPatchField<Type>::New - ( - zeroGradientFvPatchField<scalar>::typeName, - mesh.boundary()[patchI], - dimFld - ) - ); - } - - GeometricField<Type, fvPatchField, volMesh> volFld - ( - io, - dimFld.mesh(), - dimFld.dimensions(), - dimFld, - patchFields - ); - volFld.correctBoundaryConditions(); - - convertVolField(ppInterpList, volFld, interpFields, output); - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertVolFieldBlock -( - const GeometricField<Type, fvPatchField, volMesh>& tf, - autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const List<polyDecomp>& decompLst -) -{ - for (int partId = range.start(); partId < range.end(); ++partId) - { - const label datasetNo = partDataset_[partId]; - - if (datasetNo >= 0 && partStatus_[partId]) - { - convertVolField - ( - tf, - output, - range, - datasetNo, - decompLst[datasetNo] - ); - - if (ptfPtr.valid()) - { - convertPointField - ( - ptfPtr(), - tf, - output, - range, - datasetNo, - decompLst[datasetNo] - ); - } - } - } -} - - -template<class Type> -void Foam::vtkPVFoam::convertVolField -( - const GeometricField<Type, fvPatchField, volMesh>& tf, - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo, - const polyDecomp& decompInfo -) -{ - const label nComp = pTraits<Type>::nComponents; - 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()); - - if (debug) - { - Info<< "convert volField: " - << tf.name() - << " size = " << tf.size() - << " nComp=" << nComp - << " nTuples = " << superCells.size() << endl; - } - - float vec[nComp]; - forAll(superCells, i) - { - const Type& t = tf[superCells[i]]; - for (direction d=0; d<nComp; ++d) - { - vec[d] = component(t, d); - } - vtkOpenFOAMTupleRemap<Type>(vec); - - celldata->InsertTuple(i, vec); - } - - vtkUnstructuredGrid::SafeDownCast - ( - GetDataSetFromBlock(output, range, datasetNo) - ) ->GetCellData() - ->AddArray(celldata); - - celldata->Delete(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean index 3a81901a0bb8494663a389e04c08916fefffad26..8e0fd1a41a09b5ce60f7aeabbcb09db8cfd370c0 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwclean @@ -2,17 +2,15 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -#set -x - -# deal with client/server vs combined plugins +# Cleanup client-server and/or combined plugins rm -f $FOAM_LIBBIN/libPVblockMeshReader* 2>/dev/null rm -rf PVblockMeshReader/Make # safety: old build location wclean libso vtkPVblockMesh -# Where are the generated files stored? +# Cleanup generated files findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake index 607a6cb8e3cf8da211f9ec8fa284bad83a069270..24d577b2aef6d315af7a6964dcda0f323a6debed 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/Allwmake @@ -4,49 +4,18 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions - -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" - - -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - - findObjectDir $sourceDir # Where are generated files stored? - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make - ) -} +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions +# ----------------------------------------------------------------------------- if [ -d "$ParaView_DIR" ] then - wmake $targetType vtkPVblockMesh + wmakeLibPv vtkPVblockMesh if [ "$targetType" != objects ] then - doCmake $PWD/PVblockMeshReader || { + cmakePv $PWD/PVblockMeshReader || { echo echo " WARNING: incomplete build of ParaView BlockMesh plugin" echo diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt index 34c9353fe93d4a113802374e0db59d5be0d60344..267938563b898d0c1a4791a7d10a3e16a54ac087 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/CMakeLists.txt @@ -1,85 +1,70 @@ -# create a plugin that adds a reader to the ParaView GUI -# it is added in the file dialog when doing opens/saves. +# Create a plugin to add a reader to the ParaView GUI -# The qrc file is processed by Qt's resource compiler (rcc) -# the qrc file must have a resource prefix of "/ParaViewResources" -# and ParaView will read anything contained under that prefix -# the pqReader.xml file contains xml defining readers with their -# file extensions and descriptions. +cmake_minimum_required(VERSION 2.6) -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +find_package(ParaView REQUIRED) +include(${PARAVIEW_USE_FILE}) -FIND_PACKAGE(ParaView REQUIRED) -INCLUDE(${PARAVIEW_USE_FILE}) - -LINK_DIRECTORIES( +link_directories( $ENV{FOAM_LIBBIN} $ENV{FOAM_EXT_LIBBIN} ) -INCLUDE_DIRECTORIES( +include_directories( $ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude $ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude $ENV{WM_PROJECT_DIR}/src/meshing/blockMesh/lnInclude ${PROJECT_SOURCE_DIR}/../vtkPVblockMesh + ${PROJECT_SOURCE_DIR}/../../foamPv/lnInclude ) -ADD_DEFINITIONS( - -std=c++0x +add_definitions( + -std=c++11 -DWM_$ENV{WM_PRECISION_OPTION} -DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE} ) # Set output library destination to plugin directory -SET( +set( LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} CACHE INTERNAL "Single output directory for building all libraries." ) -# -# Define combined plugin -# -# Extend the auto-generated panel -QT4_WRAP_CPP(MOC_SRCS pqPVblockMeshReaderPanel.h) +if (PARAVIEW_QT_VERSION VERSION_GREATER "4") + qt5_wrap_cpp(MOC_SRCS + pqFoamBlockMeshControls.h + ) +else() + qt4_wrap_cpp(MOC_SRCS + pqFoamBlockMeshControls.h + ) +endif() -ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS - CLASS_NAME pqPVblockMeshReaderPanel - XML_NAME PVblockMeshReader # name of SourceProxy in *SM.xml - XML_GROUP sources +add_paraview_property_group_widget(IFACES0 IFACES0_SRCS + TYPE "openfoam_blockMesh_general_controls" + CLASS_NAME pqFoamBlockMeshControls ) -# Separate GUI_RESOURCE_FILES deprecated with paraview 4.3 -# so check if version < 4.4 - -IF(("${PARAVIEW_VERSION_MAJOR}" LESS 5) AND ("${PARAVIEW_VERSION_MINOR}" LESS 4)) - ADD_PARAVIEW_PLUGIN( - PVblockMeshReader_SM "1.0" - SERVER_MANAGER_XML PVblockMeshReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVblockMeshReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - GUI_RESOURCE_FILES PVblockMeshReader.xml - ) -ELSE() - ADD_PARAVIEW_PLUGIN( - PVblockMeshReader_SM "1.0" - SERVER_MANAGER_XML PVblockMeshReader_SM.xml - SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx - GUI_INTERFACES ${IFACES} - GUI_SOURCES pqPVblockMeshReaderPanel.cxx - ${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS} - ) -ENDIF() +add_paraview_plugin( + PVblockMeshReader_SM "1.0" + SERVER_MANAGER_XML PVblockMeshReader_SM.xml + SERVER_MANAGER_SOURCES vtkPVblockMeshReader.cxx + GUI_INTERFACES + ${IFACES0} + SOURCES + ${IFACES0_SRCS} + ${MOC_SRCS} + pqFoamBlockMeshControls.cxx +) -# Build the client-side plugin -TARGET_LINK_LIBRARIES( +target_link_libraries( PVblockMeshReader_SM LINK_PUBLIC - vtkPVblockMesh + vtkPVblockMesh-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} + foamPv-pv${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR} blockMesh OpenFOAM ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc deleted file mode 100644 index 228226bd56ae52129ac3538820218138c65fc61a..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/ParaViewResources" > - <file>PVblockMeshReader.xml</file> - </qresource> -</RCC> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml deleted file mode 100644 index 9354a13525226607a3785092249488fa1f5f2839..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader.xml +++ /dev/null @@ -1,7 +0,0 @@ -<ParaViewReaders> - <!-- deprecated with paraview-4.3, use hints in *SM.xml --> - <Reader name="PVblockMeshReader" - extensions="blockMesh" - file_description="OpenFOAM blockMesh reader"> - </Reader> -</ParaViewReaders> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml index 28df8ae78bec86b37d6bf9bc5107c9bac2545227..e0110552eec69b4fba45e2129e9efd47010f4535 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/PVblockMeshReader_SM.xml @@ -5,49 +5,58 @@ class="vtkPVblockMeshReader"> <!-- File name - compulsory --> - <StringVectorProperty + <StringVectorProperty animateable="0" name="FileName" command="SetFileName" number_of_elements="1" - animateable="0"> + panel_visibility="never"> <FileListDomain name="files"/> - <Documentation> - Specifies the filename for the OpenFOAM blockMesh Reader. - </Documentation> + <Documentation>The filename for the OpenFOAM blockMesh reader.</Documentation> </StringVectorProperty> - <!-- Show Point Numbers check-box --> - <IntVectorProperty - name="UiShowPointNumbers" - command="SetShowPointNumbers" + <!-- Refresh (push button) --> + <Property + name="Refresh" + command="Refresh" + panel_visibility="default"> + <Documentation>Rescan for updated blockMeshDict.</Documentation> + </Property> + +<!-- General Controls --> + + <!-- Show Patch Names (check-box) --> + <IntVectorProperty animateable="0" + name="ShowPatchNames" + label="Patch Names" + command="SetShowPatchNames" + default_values="0" number_of_elements="1" - default_values="1" - is_internal="1" - animateable="0"> + panel_visibility="default"> <BooleanDomain name="bool"/> - <Documentation> - Show point numbers in render window. - </Documentation> + <Documentation>Show patch names in render window.</Documentation> </IntVectorProperty> - <!-- Refresh button --> - <IntVectorProperty - name="UiRefresh" - command="SetRefresh" + <!-- Show Point Numbers (check-box) --> + <IntVectorProperty animateable="0" + name="ShowPointNumbers" + label="Point Numbers" + command="SetShowPointNumbers" + default_values="1" number_of_elements="1" - is_internal="0" - default_values="0" - animateable="0"> + panel_visibility="default"> <BooleanDomain name="bool"/> - <Documentation> - Rescan for updated blockMeshDict. - </Documentation> + <Documentation>Show point numbers in render window.</Documentation> </IntVectorProperty> + <PropertyGroup + label="General Controls" + panel_widget="openfoam_blockMesh_general_controls"> + <Property name="Refresh"/> + <Property name="ShowPatchNames"/> + <Property name="ShowPointNumbers"/> + </PropertyGroup> - <!-- - | Selections - --> +<!-- Selections --> <!-- Available Blocks array --> <StringVectorProperty @@ -55,7 +64,7 @@ information_only="1"> <ArraySelectionInformationHelper attribute_name="Block"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="BlockStatus" label="Blocks" command="SetBlockArrayStatus" @@ -63,16 +72,13 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="BlockArrayStatus" - animateable="0"> + information_property="BlockArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="BlockArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> - <Documentation> - This property contains a list of the blocks - </Documentation> + <Documentation>The list of blocks</Documentation> </StringVectorProperty> <!-- Available CurvedEdges array --> @@ -81,7 +87,7 @@ information_only="1"> <ArraySelectionInformationHelper attribute_name="CurvedEdges"/> </StringVectorProperty> - <StringVectorProperty + <StringVectorProperty animateable="0" name="CurvedEdgesStatus" label="Curved Edges" command="SetCurvedEdgesArrayStatus" @@ -89,24 +95,26 @@ repeat_command="1" number_of_elements_per_command="2" element_types="2 0" - information_property="CurvedEdgesArrayStatus" - animateable="0"> + information_property="CurvedEdgesArrayStatus"> <ArraySelectionDomain name="array_list"> <RequiredProperties> <Property name="CurvedEdgesArrayStatus" function="ArrayList"/> </RequiredProperties> </ArraySelectionDomain> - <Documentation> - This property contains a list of the curved edges - </Documentation> + <Documentation>The list of curved edges</Documentation> </StringVectorProperty> + <PropertyGroup label="Selections"> + <Property name="BlockArrayStatus"/> + <Property name="BlockStatus"/> + <Property name="CurvedEdgesArrayStatus"/> + <Property name="CurvedEdgesStatus"/> + </PropertyGroup> + <Hints> - <Property name="FileName" show="0"/> - <Property name="UiRefresh" show="0"/> - <Property name="UiShowPointNumbers" show="0"/> - <ReaderFactory extensions="blockMesh" - file_description="OpenFOAM blockMesh"/> + <ReaderFactory + extensions="blockMesh" + file_description="OpenFOAM blockMesh"/> </Hints> </SourceProxy> diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ab4a6517066433378fa09cf288e8f54d28b683df --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.cxx @@ -0,0 +1,232 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "pqFoamBlockMeshControls.h" + +#include <QCheckBox> +#include <QGridLayout> +#include <QPushButton> + +#include "pqPVApplicationCore.h" +#include "pqView.h" +#include "vtkSMDocumentation.h" +#include "vtkSMIntVectorProperty.h" +#include "vtkSMPropertyGroup.h" +#include "vtkSMSourceProxy.h" + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// file-scope +static QAbstractButton* setButtonProperties +( + QAbstractButton* b, + vtkSMProperty* prop +) +{ + QString tip; + + vtkSMDocumentation* doc = prop->GetDocumentation(); + if (doc) + { + const char* txt = doc->GetDescription(); + if (txt) + { + tip = QString(txt).simplified(); + } + } + + b->setText(prop->GetXMLLabel()); + if (tip.size()) + { + b->setToolTip(tip); + } + b->setFocusPolicy(Qt::NoFocus); // avoid dotted border + + + vtkSMIntVectorProperty* intProp = + vtkSMIntVectorProperty::SafeDownCast(prop); + + // initial checked state for integer (bool) properties + if (intProp) + { + b->setChecked(intProp->GetElement(0)); + } + + return b; +} + + +static vtkSMIntVectorProperty* lookupIntProp +( + vtkSMPropertyGroup* group, + const char* name +) +{ + vtkSMProperty* prop = group->GetProperty(name); + + if (prop) + { + return vtkSMIntVectorProperty::SafeDownCast(prop); + } + + return nullptr; +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void pqFoamBlockMeshControls::fireCommand(vtkSMProperty* prop) +{ + vtkSMProxy* pxy = this->proxy(); + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); +} + + +void pqFoamBlockMeshControls::fireCommand +( + vtkSMIntVectorProperty* prop, + bool checked +) +{ + vtkSMProxy* pxy = this->proxy(); + + prop->SetElement(0, checked); // Toogle bool + + // Fire off command + prop->Modified(); + pxy->UpdateProperty(pxy->GetPropertyName(prop)); +} + + +void pqFoamBlockMeshControls::updateParts() +{ + vtkSMProxy* pxy = this->proxy(); + + pxy->UpdatePropertyInformation(pxy->GetProperty("BlockArrayStatus")); + pxy->UpdatePropertyInformation(pxy->GetProperty("CurvedEdgesArrayStatus")); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void pqFoamBlockMeshControls::refreshPressed() +{ + fireCommand(refresh_); + + vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); + + // Trigger a rendering (all views) + pqPVApplicationCore::instance()->render(); + + updateParts(); +} + + +void pqFoamBlockMeshControls::showPatchNames(bool checked) +{ + fireCommand(showPatchNames_, checked); + + // Update the active view + if (this->view()) + { + this->view()->render(); + } + + // OR: update all views + // pqPVApplicationCore::instance()->render(); +} + + +void pqFoamBlockMeshControls::showPointNumbers(bool checked) +{ + fireCommand(showPointNumbers_, checked); + + // Update the active view + if (this->view()) + { + this->view()->render(); + } + + // OR: update all views + // pqPVApplicationCore::instance()->render(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pqFoamBlockMeshControls::pqFoamBlockMeshControls +( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent +) +: + Superclass(proxy, parent), + refresh_(group->GetProperty("Refresh")), + showPatchNames_(lookupIntProp(group, "ShowPatchNames")), + showPointNumbers_(lookupIntProp(group, "ShowPointNumbers")) +{ + QGridLayout* form = new QGridLayout(this); + + if (refresh_) + { + QPushButton* b = new QPushButton(this); + setButtonProperties(b, refresh_); + form->addWidget(b, 0, 0, Qt::AlignLeft); + + connect(b, SIGNAL(clicked()), this, SLOT(refreshPressed())); + } + + if (showPatchNames_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPatchNames_); + form->addWidget(b, 0, 1, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPatchNames(bool))); + } + + if (showPointNumbers_) + { + QCheckBox* b = new QCheckBox(this); + setButtonProperties(b, showPointNumbers_); + form->addWidget(b, 0, 2, Qt::AlignLeft); + + connect(b, SIGNAL(toggled(bool)), this, SLOT(showPointNumbers(bool))); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pqFoamBlockMeshControls::~pqFoamBlockMeshControls() +{} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h new file mode 100644 index 0000000000000000000000000000000000000000..a46cdc30528cdfdfa4fd47b1453a065d31be4467 --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqFoamBlockMeshControls.h @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + pqFoamBlockMeshControls + +Description + Customized property controls for the ParaView blockMesh reader. + + Refresh, ShowPatchNames, ShowPointNumbers. + +SourceFiles + pqFoamBlockMeshControls.cxx + +\*---------------------------------------------------------------------------*/ +#ifndef pqFoamBlockMeshControls_h +#define pqFoamBlockMeshControls_h + +#include "pqPropertyWidget.h" + +// Forward declarations (ParaView) +class vtkSMProperty; +class vtkSMIntVectorProperty; + + +/*---------------------------------------------------------------------------*\ + Class pqFoamBlockMeshControls Declaration +\*---------------------------------------------------------------------------*/ + +class pqFoamBlockMeshControls +: + public pqPropertyWidget +{ + Q_OBJECT; + typedef pqPropertyWidget Superclass; + + // Private data + + //- Refresh (push button) + vtkSMProperty* refresh_; + + //- Show Patch Names (bool property) + vtkSMIntVectorProperty* showPatchNames_; + + //- Show Point Numbers (bool property) + vtkSMIntVectorProperty* showPointNumbers_; + + + // Private Member Functions + + //- Update property + void fireCommand(vtkSMProperty* prop); + + //- Toggle and update bool property + void fireCommand(vtkSMIntVectorProperty* prop, bool checked); + + //- Update "BlockArrayStatus", "CurvedEdgesArrayStatus" information + void updateParts(); + + + //- Disallow default bitwise copy construct + pqFoamBlockMeshControls(const pqFoamBlockMeshControls&) = delete; + + //- Disallow default bitwise assignment + void operator=(const pqFoamBlockMeshControls&) = delete; + + +protected slots: + + // Protected Member Functions + + //- Trigger refresh + void refreshPressed(); + + //- Sync property with changed checkbox state, update rendered view(s) + void showPatchNames(bool checked); + + //- Sync property with changed checkbox state, update rendered view(s) + void showPointNumbers(bool checked); + + +public: + + //- Construct from components + pqFoamBlockMeshControls + ( + vtkSMProxy* proxy, + vtkSMPropertyGroup* group, + QWidget* parent = nullptr + ); + + + //- Destructor + virtual ~pqFoamBlockMeshControls(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx deleted file mode 100644 index 06f0db328d7ed755a3f4d1fc563b673b01db7053..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.cxx +++ /dev/null @@ -1,143 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "pqPVblockMeshReaderPanel.h" - -// QT -#include <QGridLayout> -#include <QCheckBox> -#include <QLabel> -#include <QLayout> -#include <QString> -#include <QPushButton> -#include <QtDebug> - -// Paraview <-> QT UI -#include "pqAnimationScene.h" -#include "pqApplicationCore.h" -#include "pqPipelineRepresentation.h" -#include "pqServerManagerModel.h" -#include "pqView.h" - -// Paraview Server Manager -#include "vtkSMDoubleVectorProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMProperty.h" -#include "vtkSMSourceProxy.h" - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -pqPVblockMeshReaderPanel::pqPVblockMeshReaderPanel -( - pqProxy *proxy, - QWidget *p -) -: - pqAutoGeneratedObjectPanel(proxy, p) -{ - // Create first sublayout (at top of the panel) - QGridLayout *form = new QGridLayout(); - this->PanelLayout->addLayout(form, 0, 0, 1, -1); - - vtkSMProperty* prop = 0; - - // Refresh button for updating blocks - if ((prop = this->proxy()->GetProperty("UiRefresh")) != 0) - { - prop->SetImmediateUpdate(1); - QPushButton* refresh = new QPushButton("Refresh"); - refresh->setToolTip("Rescan for updated blockMeshDict."); - - form->addWidget(refresh, 0, 0, Qt::AlignLeft); - QObject::connect - ( - refresh, - SIGNAL(clicked()), - this, - SLOT(RefreshPressed()) - ); - } - - // Checkbox for showing point numbers - if ((prop = this->proxy()->GetProperty("UiShowPointNumbers")) != 0) - { - prop->SetImmediateUpdate(true); - - ShowPointNumbers_ = new QCheckBox("Show Point Numbers"); - ShowPointNumbers_->setToolTip("Show point numbers in render window."); - ShowPointNumbers_->setChecked - ( - vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0) - ); - - form->addWidget(ShowPointNumbers_); - - connect - ( - ShowPointNumbers_, - SIGNAL(stateChanged(int)), - this, - SLOT(ShowPointNumbersToggled()) - ); - } - -} - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -void pqPVblockMeshReaderPanel::ShowPointNumbersToggled() -{ - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiShowPointNumbers") - )->SetElement(0, ShowPointNumbers_->isChecked()); - - // Update the active view - if (this->view()) - { - this->view()->render(); - } - // OR: update all views - // pqApplicationCore::instance()->render(); -} - - -void pqPVblockMeshReaderPanel::RefreshPressed() -{ - // Update everything - vtkSMIntVectorProperty::SafeDownCast - ( - this->proxy()->GetProperty("UiRefresh") - )->Modified(); - - vtkSMSourceProxy::SafeDownCast(this->proxy())->UpdatePipeline(); - - // Render all views - pqApplicationCore::instance()->render(); -} - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h deleted file mode 100644 index 4c15bc374ea999c3c141cf694ec61de37e806bac..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/pqPVblockMeshReaderPanel.h +++ /dev/null @@ -1,86 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Class - pqPVblockMeshReaderPanel - -Description - GUI modifications for the ParaView reader panel - - A custom panel for the PVblockMeshReader. - -SourceFiles - pqPVblockMeshReaderPanel.cxx - -\*---------------------------------------------------------------------------*/ -#ifndef pqPVblockMeshReaderPanel_h -#define pqPVblockMeshReaderPanel_h - -#include "pqAutoGeneratedObjectPanel.h" - -// Forward declaration of QT classes - -class QCheckBox; -class QLineEdit; -class QTimer; -class QToolButton; - -// Forward declaration of ParaView classes -class vtkSMSourceProxy; - - -/*---------------------------------------------------------------------------*\ - Class pqPVblockMeshReaderPanel Declaration -\*---------------------------------------------------------------------------*/ - -class pqPVblockMeshReaderPanel -: - public pqAutoGeneratedObjectPanel -{ - // Private data - Q_OBJECT; - typedef pqAutoGeneratedObjectPanel Superclass; - - //- Show Point Numbers checkbox - QCheckBox* ShowPointNumbers_; - -protected slots: - - void ShowPointNumbersToggled(); - void RefreshPressed(); - - -public: - - // Constructors - - //- Construct from components - pqPVblockMeshReaderPanel(pqProxy*, QWidget*); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx index 6d559e7a3379b175bb22705be8db2c7610807746..2c8c1ce453d2ca3c3a763cfcbe7af46d9904782f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.cxx @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,10 +56,11 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() SetNumberOfInputPorts(0); - FileName = nullptr; - foamData_ = nullptr; + FileName = nullptr; + backend_ = nullptr; - ShowPointNumbers = 1; + ShowPatchNames = false; + ShowPointNumbers = true; BlockSelection = vtkDataArraySelection::New(); CurvedEdgesSelection = vtkDataArraySelection::New(); @@ -73,7 +74,6 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() ); SelectionObserver->SetClientData(this); - BlockSelection->AddObserver ( vtkCommand::ModifiedEvent, @@ -92,13 +92,16 @@ vtkPVblockMeshReader::vtkPVblockMeshReader() vtkPVblockMeshReader::~vtkPVblockMeshReader() { - vtkDebugMacro(<<"Deconstructor"); + vtkDebugMacro(<<"Destructor"); - if (foamData_) + if (backend_) { - // Remove point numbers + // Remove text actors + updatePatchNamesView(false); updatePointNumbersView(false); - delete foamData_; + + delete backend_; + backend_ = nullptr; } if (FileName) @@ -106,11 +109,12 @@ vtkPVblockMeshReader::~vtkPVblockMeshReader() delete [] FileName; } - BlockSelection->RemoveObserver(this->SelectionObserver); - CurvedEdgesSelection->RemoveObserver(this->SelectionObserver); + BlockSelection->RemoveAllObservers(); + CurvedEdgesSelection->RemoveAllObservers(); SelectionObserver->Delete(); BlockSelection->Delete(); + CurvedEdgesSelection->Delete(); } @@ -125,35 +129,25 @@ int vtkPVblockMeshReader::RequestInformation { vtkDebugMacro(<<"RequestInformation"); - if (Foam::vtkPVblockMesh::debug) - { - cout<<"REQUEST_INFORMATION\n"; - } - if (!FileName) { vtkErrorMacro("FileName has to be specified!"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); - if (Foam::vtkPVblockMesh::debug) { - cout<<"RequestInformation with " << nInfo << " item(s)\n"; - for (int infoI = 0; infoI < nInfo; ++infoI) - { - outputVector->GetInformationObject(infoI)->Print(cout); - } + cout<<"REQUEST_INFORMATION\n"; + outputVector->GetInformationObject(0)->Print(cout); } - if (!foamData_) + if (backend_) { - foamData_ = new Foam::vtkPVblockMesh(FileName, this); + backend_->updateInfo(); } else { - foamData_->updateInfo(); + backend_ = new Foam::vtkPVblockMesh(FileName, this); } return 1; @@ -176,21 +170,16 @@ int vtkPVblockMeshReader::RequestData } // Catch previous error - if (!foamData_) + if (!backend_) { vtkErrorMacro("Reader failed - perhaps no mesh?"); return 0; } - int nInfo = outputVector->GetNumberOfInformationObjects(); - if (Foam::vtkPVblockMesh::debug) { - cout<<"RequestData with " << nInfo << " item(s)\n"; - for (int infoI = 0; infoI < nInfo; ++infoI) - { - outputVector->GetInformationObject(infoI)->Print(cout); - } + cout<<"REQUEST_DATA:\n"; + outputVector->GetInformationObject(0)->Print(cout); } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast @@ -207,32 +196,46 @@ int vtkPVblockMeshReader::RequestData << output->GetNumberOfBlocks() << " blocks\n"; } + backend_->Update(output); - foamData_->Update(output); + updatePatchNamesView(ShowPatchNames); updatePointNumbersView(ShowPointNumbers); // Do any cleanup on the OpenFOAM side - foamData_->CleanUp(); + backend_->CleanUp(); return 1; } -void vtkPVblockMeshReader::SetRefresh(int val) +void vtkPVblockMeshReader::Refresh() { // Delete the current blockMesh to force re-read and update - if (foamData_) + if (backend_) { + // Remove text actors + updatePatchNamesView(false); updatePointNumbersView(false); - delete foamData_; - foamData_ = 0; + + delete backend_; + backend_ = nullptr; } - Modified(); + this->Modified(); +} + + +void vtkPVblockMeshReader::SetShowPatchNames(bool val) +{ + if (ShowPatchNames != val) + { + ShowPatchNames = val; + updatePatchNamesView(ShowPatchNames); + } } -void vtkPVblockMeshReader::SetShowPointNumbers(const int val) +void vtkPVblockMeshReader::SetShowPointNumbers(bool val) { if (ShowPointNumbers != val) { @@ -242,7 +245,7 @@ void vtkPVblockMeshReader::SetShowPointNumbers(const int val) } -void vtkPVblockMeshReader::updatePointNumbersView(const bool show) +void vtkPVblockMeshReader::updatePatchNamesView(const bool show) { pqApplicationCore* appCore = pqApplicationCore::instance(); @@ -254,17 +257,48 @@ void vtkPVblockMeshReader::updatePointNumbersView(const bool show) // Server manager model for querying items in the server manager pqServerManagerModel* smModel = appCore->getServerManagerModel(); - if (!smModel || !foamData_) + if (!smModel || !backend_) { return; } + // Get all the pqRenderView instances + QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>(); + for (int viewI=0; viewI<renderViews.size(); ++viewI) + { + backend_->renderPatchNames + ( + renderViews[viewI]->getRenderViewProxy()->GetRenderer(), + show + ); + } + + // Use refresh here? +} + + +void vtkPVblockMeshReader::updatePointNumbersView(const bool show) +{ + pqApplicationCore* appCore = pqApplicationCore::instance(); + + // Need to check this, since our destructor calls this + if (!appCore) + { + return; + } + + // Server manager model for querying items in the server manager + pqServerManagerModel* smModel = appCore->getServerManagerModel(); + if (!smModel || !backend_) + { + return; + } // Get all the pqRenderView instances QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>(); for (int viewI=0; viewI<renderViews.size(); ++viewI) { - foamData_->renderPointNumbers + backend_->renderPointNumbers ( renderViews[viewI]->getRenderViewProxy()->GetRenderer(), show @@ -283,7 +317,7 @@ void vtkPVblockMeshReader::PrintSelf(ostream& os, vtkIndent indent) os << indent << "File name: " << (this->FileName ? this->FileName : "(none)") << "\n"; - foamData_->PrintSelf(os, indent); + backend_->PrintSelf(os, indent); } @@ -292,39 +326,30 @@ void vtkPVblockMeshReader::PrintSelf(ostream& os, vtkIndent indent) vtkDataArraySelection* vtkPVblockMeshReader::GetBlockSelection() { - vtkDebugMacro(<<"GetBlockSelection"); return BlockSelection; } - int vtkPVblockMeshReader::GetNumberOfBlockArrays() { - vtkDebugMacro(<<"GetNumberOfBlockArrays"); return BlockSelection->GetNumberOfArrays(); } - const char* vtkPVblockMeshReader::GetBlockArrayName(int index) { - vtkDebugMacro(<<"GetBlockArrayName"); return BlockSelection->GetArrayName(index); } - int vtkPVblockMeshReader::GetBlockArrayStatus(const char* name) { - vtkDebugMacro(<<"GetBlockArrayStatus"); return BlockSelection->ArrayIsEnabled(name); } - void vtkPVblockMeshReader::SetBlockArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetBlockArrayStatus"); if (status) { BlockSelection->EnableArray(name); @@ -341,39 +366,30 @@ void vtkPVblockMeshReader::SetBlockArrayStatus vtkDataArraySelection* vtkPVblockMeshReader::GetCurvedEdgesSelection() { - vtkDebugMacro(<<"GetCurvedEdgesSelection"); return CurvedEdgesSelection; } - int vtkPVblockMeshReader::GetNumberOfCurvedEdgesArrays() { - vtkDebugMacro(<<"GetNumberOfCurvedEdgesArrays"); return CurvedEdgesSelection->GetNumberOfArrays(); } - const char* vtkPVblockMeshReader::GetCurvedEdgesArrayName(int index) { - vtkDebugMacro(<<"GetCurvedEdgesArrayName"); return CurvedEdgesSelection->GetArrayName(index); } - int vtkPVblockMeshReader::GetCurvedEdgesArrayStatus(const char* name) { - vtkDebugMacro(<<"GetCurvedEdgesArrayStatus"); return CurvedEdgesSelection->ArrayIsEnabled(name); } - void vtkPVblockMeshReader::SetCurvedEdgesArrayStatus ( const char* name, int status ) { - vtkDebugMacro(<<"SetCurvedEdgesArrayStatus"); if (status) { CurvedEdgesSelection->EnableArray(name); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h index b160b7c035f5e76eaec2749e0711c1d36205920e..66805716eec674fac90a804ea2e7887f93149732 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/PVblockMeshReader/vtkPVblockMeshReader.h @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -71,29 +71,34 @@ public: vtkSetStringMacro(FileName); vtkGetStringMacro(FileName); + // Description: + // Display patch names + virtual void SetShowPatchNames(bool); + vtkGetMacro(ShowPatchNames, bool); + // Description: // Display corner point labels - virtual void SetShowPointNumbers(int); - vtkGetMacro(ShowPointNumbers, int); + virtual void SetShowPointNumbers(bool); + vtkGetMacro(ShowPointNumbers, bool); // Description: // Refresh blockMesh from changes to blockMeshDict - virtual void SetRefresh(int); + virtual void Refresh(); // Description: // Blocks selection list control vtkDataArraySelection* GetBlockSelection(); int GetNumberOfBlockArrays(); - int GetBlockArrayStatus(const char*); - void SetBlockArrayStatus(const char*, int status); + int GetBlockArrayStatus(const char* name); + void SetBlockArrayStatus(const char* name, int status); const char* GetBlockArrayName(int index); // Description: // CurvedEdges selection list control vtkDataArraySelection* GetCurvedEdgesSelection(); int GetNumberOfCurvedEdgesArrays(); - int GetCurvedEdgesArrayStatus(const char*); - void SetCurvedEdgesArrayStatus(const char*, int status); + int GetCurvedEdgesArrayStatus(const char* name); + void SetCurvedEdgesArrayStatus(const char* name, int status); const char* GetCurvedEdgesArrayName(int index); // Description: @@ -114,22 +119,22 @@ protected: vtkPVblockMeshReader(); //- Destructor - ~vtkPVblockMeshReader(); + virtual ~vtkPVblockMeshReader(); //- Return information about mesh, times, etc without loading anything virtual int RequestInformation ( - vtkInformation*, - vtkInformationVector**, - vtkInformationVector* + vtkInformation* unusedRequest, + vtkInformationVector** unusedInputVector, + vtkInformationVector* outputVector ); - //- Get the mesh/fields for a particular time + //- Get the mesh for a particular time virtual int RequestData ( - vtkInformation*, - vtkInformationVector**, - vtkInformationVector* + vtkInformation* unusedRequest, + vtkInformationVector** unusedInputVector, + vtkInformationVector* outputVector ); //- Fill in additional port information @@ -144,25 +149,29 @@ protected: private: //- Disallow default bitwise copy construct - vtkPVblockMeshReader(const vtkPVblockMeshReader&); + vtkPVblockMeshReader(const vtkPVblockMeshReader&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVblockMeshReader&); + void operator=(const vtkPVblockMeshReader&) = delete; + + //- Add/remove patch names to/from the view + void updatePatchNamesView(const bool show); //- Add/remove point numbers to/from the view void updatePointNumbersView(const bool show); + //- Show Patch Names + bool ShowPatchNames; + //- Show Point Numbers - int ShowPointNumbers; + bool ShowPointNumbers; vtkDataArraySelection* BlockSelection; - vtkDataArraySelection* CurvedEdgesSelection; - //BTX - Foam::vtkPVblockMesh* foamData_; - //ETX + //- Backend portion of the reader + Foam::vtkPVblockMesh* backend_; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files index e6e4fb230e51ae856be56d128e1682718cb1f7c3..35930f249c8e09d349b9532850847b2d4b650d90 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/files @@ -1,5 +1,4 @@ vtkPVblockMesh.C vtkPVblockMeshConvert.C -vtkPVblockMeshUtils.C -LIB = $(FOAM_LIBBIN)/libvtkPVblockMesh +LIB = $(FOAM_LIBBIN)/libvtkPVblockMesh-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options index 79abf2d7fc4066ac9e24f917a5a381f6a771e23b..295a695c7697732d1456da610f41c120c4afbe94 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/Make/options @@ -1,3 +1,5 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/meshTools/lnInclude \ @@ -5,12 +7,12 @@ EXE_INC = \ -I$(LIB_SRC)/mesh/blockMesh/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ - -I../../vtkPVReaders/lnInclude \ + -I../../foamPv/lnInclude \ -I../PVblockMeshReader LIB_LIBS = \ -lmeshTools \ -lfileFormats \ -lblockMesh \ - -L$(FOAM_LIBBIN) -lvtkPVReaders \ + -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkOpenFOAMPoints.H b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkOpenFOAMPoints.H deleted file mode 100644 index d36406984ed26077794e74634df94b8ebd895151..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkOpenFOAMPoints.H +++ /dev/null @@ -1,65 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -InClass - vtkPVblockMesh - -\*---------------------------------------------------------------------------*/ - -#ifndef vtkOpenFOAMPoints_H -#define vtkOpenFOAMPoints_H - -// VTK includes -#include "vtkPoints.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -inline void vtkInsertNextOpenFOAMPoint -( - vtkPoints *points, - const Foam::point& p -) -{ - points->InsertNextPoint(p.x(), p.y(), p.z()); -} - -inline void vtkInsertNextOpenFOAMPoint -( - vtkPoints *points, - const Foam::point& p, - const Foam::scalar scaleFactor -) -{ - points->InsertNextPoint - ( - p.x()*scaleFactor, - p.y()*scaleFactor, - p.z()*scaleFactor - ); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C index dd40c8e359459f850f56ca0f0fcc89db47b557b2..e64f031dec7ac2e5d126f93c8e2403f1db7f6520 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,7 @@ License // OpenFOAM includes #include "blockMesh.H" +#include "blockMeshTools.H" #include "Time.H" #include "patchZones.H" #include "OStringStream.H" @@ -47,6 +48,34 @@ namespace Foam } +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +vtkTextActor* Foam::vtkPVblockMesh::createTextActor +( + const string& s, + const point& pt +) +{ + vtkTextActor* txt = vtkTextActor::New(); + txt->SetInput(s.c_str()); + + // Set text properties + vtkTextProperty* tprop = txt->GetTextProperty(); + tprop->SetFontFamilyToArial(); + tprop->BoldOn(); + tprop->ShadowOff(); + tprop->SetLineSpacing(1.0); + tprop->SetFontSize(14); + tprop->SetColor(1.0, 0.0, 1.0); + tprop->SetJustificationToCentered(); + + txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); + txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z()); + + return txt; +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::vtkPVblockMesh::resetCounters() @@ -60,16 +89,18 @@ void Foam::vtkPVblockMesh::resetCounters() void Foam::vtkPVblockMesh::updateInfoBlocks ( - vtkDataArraySelection* arraySelection + vtkDataArraySelection* select ) { + arrayRange& range = arrayRangeBlocks_; + if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::updateInfoBlocks" - << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; + Info<< "<beg> updateInfoBlocks" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } - arrayRangeBlocks_.reset( arraySelection->GetNumberOfArrays() ); + range.reset(select->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; @@ -80,49 +111,46 @@ void Foam::vtkPVblockMesh::updateInfoBlocks // Display either blockI as a number or with its name // (looked up from blockMeshDict) - OStringStream os; - blockDescriptor::write(os, blockI, blkMesh.meshDict()); - word partName(os.str()); + OStringStream ostr; + blockDescriptor::write(ostr, blockI, blkMesh.meshDict()); // append the (optional) zone name if (!blockDef.zoneName().empty()) { - partName += " - " + blockDef.zoneName(); + ostr << " - " << blockDef.zoneName(); } - // Add blockId and zoneName to GUI list - arraySelection->AddArray(partName.c_str()); + // Add "blockId" or "blockId - zoneName" to GUI list + select->AddArray(ostr.str().c_str()); } - arrayRangeBlocks_ += nBlocks; + range += nBlocks; if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVblockMesh::updateInfoBlocks" << endl; + Info<< "<end> updateInfoBlocks" << endl; } } void Foam::vtkPVblockMesh::updateInfoEdges ( - vtkDataArraySelection* arraySelection + vtkDataArraySelection* select ) { + arrayRange& range = arrayRangeEdges_; + if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::updateInfoEdges" - << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "]" << endl; + Info<< "<beg> updateInfoEdges" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; } - arrayRangeEdges_.reset( arraySelection->GetNumberOfArrays() ); + range.reset(select->GetNumberOfArrays()); const blockMesh& blkMesh = *meshPtr_; const blockEdgeList& edges = blkMesh.edges(); - const int nEdges = edges.size(); forAll(edges, edgeI) { OStringStream ostr; @@ -132,17 +160,14 @@ void Foam::vtkPVblockMesh::updateInfoEdges ostr << " - " << edges[edgeI].type(); // Add "beg:end - type" to GUI list - arraySelection->AddArray(ostr.str().c_str()); + select->AddArray(ostr.str().c_str()); } - arrayRangeEdges_ += nEdges; + range += edges.size(); if (debug) { - // just for debug info - getSelectedArrayEntries(arraySelection); - - Info<< "<end> Foam::vtkPVblockMesh::updateInfoEdges" << endl; + Info<< "<end> updateInfoEdges" << endl; } } @@ -166,8 +191,7 @@ Foam::vtkPVblockMesh::vtkPVblockMesh { if (debug) { - Info<< "Foam::vtkPVblockMesh::vtkPVblockMesh - " - << FileName << endl; + Info<< "vtkPVblockMesh - " << FileName << endl; } // avoid argList and get rootPath/caseName directly from the file @@ -253,17 +277,9 @@ Foam::vtkPVblockMesh::~vtkPVblockMesh() { if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::~vtkPVblockMesh" << endl; + Info<< "~vtkPVblockMesh" << endl; } - // Hmm. pointNumberTextActors are not getting removed - // - forAll(pointNumberTextActorsPtrs_, pointi) - { - pointNumberTextActorsPtrs_[pointi]->Delete(); - } - pointNumberTextActorsPtrs_.clear(); - delete meshPtr_; } @@ -274,25 +290,20 @@ void Foam::vtkPVblockMesh::updateInfo() { if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::updateInfo" - << " [meshPtr=" << (meshPtr_ ? "set" : "nullptr") << "] " << endl; + Info<< "<beg> updateInfo" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "] " << endl; } resetCounters(); vtkDataArraySelection* blockSelection = reader_->GetBlockSelection(); - vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection(); + vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection(); - // enable 'internalMesh' on the first call - // or preserve the enabled selections + // preserve the enabled selections if possible stringList enabledParts; stringList enabledEdges; - bool firstTime = false; - if (!blockSelection->GetNumberOfArrays() && !meshPtr_) - { - firstTime = true; - } - else + const bool firstTime = (!blockSelection->GetNumberOfArrays() && !meshPtr_); + if (!firstTime) { enabledParts = getSelectedArrayEntries(blockSelection); enabledEdges = getSelectedArrayEntries(edgeSelection); @@ -306,21 +317,21 @@ void Foam::vtkPVblockMesh::updateInfo() updateFoamMesh(); // Update mesh parts list - updateInfoBlocks( blockSelection ); + updateInfoBlocks(blockSelection); // Update curved edges list - updateInfoEdges( edgeSelection ); + updateInfoEdges(edgeSelection); // restore the enabled selections if (!firstTime) { setSelectedArrayEntries(blockSelection, enabledParts); - setSelectedArrayEntries(edgeSelection, enabledEdges); + setSelectedArrayEntries(edgeSelection, enabledEdges); } if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::updateInfo" << endl; + Info<< "<end> updateInfo" << endl; } } @@ -329,7 +340,7 @@ void Foam::vtkPVblockMesh::updateFoamMesh() { if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::updateFoamMesh" << endl; + Info<< "<beg> updateFoamMesh" << endl; } // Check to see if the OpenFOAM mesh has been created @@ -379,7 +390,7 @@ void Foam::vtkPVblockMesh::updateFoamMesh() if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::updateFoamMesh" << endl; + Info<< "<end> updateFoamMesh" << endl; } } @@ -392,10 +403,10 @@ void Foam::vtkPVblockMesh::Update reader_->UpdateProgress(0.1); // Set up mesh parts selection(s) - updateBoolListStatus(blockStatus_, reader_->GetBlockSelection()); + getSelected(blockStatus_, reader_->GetBlockSelection()); // Set up curved edges selection(s) - updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection()); + getSelected(edgeStatus_, reader_->GetCurvedEdgesSelection()); reader_->UpdateProgress(0.2); @@ -421,71 +432,148 @@ void Foam::vtkPVblockMesh::CleanUp() } -void Foam::vtkPVblockMesh::renderPointNumbers +void Foam::vtkPVblockMesh::renderPatchNames ( vtkRenderer* renderer, const bool show ) { // always remove old actors first - - forAll(pointNumberTextActorsPtrs_, pointi) + forAll(patchTextActorsPtrs_, actori) { - renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointi]); - pointNumberTextActorsPtrs_[pointi]->Delete(); + renderer->RemoveViewProp(patchTextActorsPtrs_[actori]); + patchTextActorsPtrs_[actori]->Delete(); } - pointNumberTextActorsPtrs_.clear(); + patchTextActorsPtrs_.clear(); + + // the number of text actors + label nActors = 0; if (show && meshPtr_) { const blockMesh& blkMesh = *meshPtr_; + const dictionary& meshDescription = blkMesh.meshDict(); const pointField& cornerPts = blkMesh.vertices(); const scalar scaleFactor = blkMesh.scaleFactor(); - pointNumberTextActorsPtrs_.setSize(cornerPts.size()); - forAll(cornerPts, pointi) + if (!meshDescription.found("boundary")) { - vtkTextActor* txt = vtkTextActor::New(); + return; + } - // Display either pointi as a number or with its name - // (looked up from blockMeshDict) + // 8 sides per block is plenty + patchTextActorsPtrs_.setSize(8*blkMesh.size()); + + // Collect all variables + dictionary varDict(meshDescription.subOrEmptyDict("namedVertices")); + varDict.merge(meshDescription.subOrEmptyDict("namedBlocks")); + + // Read like boundary file + const PtrList<entry> patchesInfo(meshDescription.lookup("boundary")); + + forAll(patchesInfo, patchi) + { + const entry& patchInfo = patchesInfo[patchi]; + + if (!patchInfo.isDict()) { - OStringStream os; - blockVertex::write(os, pointi, blkMesh.meshDict()); - txt->SetInput(os.str().c_str()); + IOWarningInFunction(meshDescription) + << "Entry " << patchInfo << " in boundary section is not a" + << " valid dictionary." + << endl; + break; } - // Set text properties - vtkTextProperty* tprop = txt->GetTextProperty(); - tprop->SetFontFamilyToArial(); - tprop->BoldOn(); - tprop->ShadowOff(); - tprop->SetLineSpacing(1.0); - tprop->SetFontSize(14); - tprop->SetColor(1.0, 0.0, 1.0); - tprop->SetJustificationToCentered(); - - // Set text to use 3-D world co-ordinates - txt->GetPositionCoordinate()->SetCoordinateSystemToWorld(); + const word& patchName = patchInfo.keyword(); - txt->GetPositionCoordinate()->SetValue + // Read block faces + faceList patchFaces = blockMeshTools::read<face> ( - cornerPts[pointi].x()*scaleFactor, - cornerPts[pointi].y()*scaleFactor, - cornerPts[pointi].z()*scaleFactor + patchInfo.dict().lookup("faces"), + varDict ); - // Add text to each renderer - renderer->AddViewProp(txt); + forAll(patchFaces, facei) + { + const face& f = patchFaces[facei]; + + // Into a list for later removal + patchTextActorsPtrs_[nActors++] = createTextActor + ( + patchName, + f.centre(cornerPts) * scaleFactor + ); + + if (nActors == patchTextActorsPtrs_.size()) + { + // hit max allocated space - bail out + break; + } + } - // Maintain a list of text labels added so that they can be - // removed later - pointNumberTextActorsPtrs_[pointi] = txt; + if (nActors == patchTextActorsPtrs_.size()) + { + // hit max allocated space - bail out + break; + } } + + patchTextActorsPtrs_.setSize(nActors); + } + + // Add text to each renderer + forAll(patchTextActorsPtrs_, actori) + { + renderer->AddViewProp(patchTextActorsPtrs_[actori]); } } +void Foam::vtkPVblockMesh::renderPointNumbers +( + vtkRenderer* renderer, + const bool show +) +{ + // always remove old actors first + + forAll(pointTextActorsPtrs_, actori) + { + renderer->RemoveViewProp(pointTextActorsPtrs_[actori]); + pointTextActorsPtrs_[actori]->Delete(); + } + pointTextActorsPtrs_.clear(); + + if (show && meshPtr_) + { + const blockMesh& blkMesh = *meshPtr_; + const pointField& cornerPts = blkMesh.vertices(); + const scalar scaleFactor = blkMesh.scaleFactor(); + + pointTextActorsPtrs_.setSize(cornerPts.size()); + forAll(cornerPts, pointi) + { + // Display either pointi as a number or with its name + // (looked up from blockMeshDict) + OStringStream os; + blockVertex::write(os, pointi, blkMesh.meshDict()); + + // Into a list for later removal + pointTextActorsPtrs_[pointi] = createTextActor + ( + os.str(), + cornerPts[pointi]*scaleFactor + ); + } + } + + // Add text to each renderer + forAll(pointTextActorsPtrs_, actori) + { + renderer->AddViewProp(pointTextActorsPtrs_[actori]); + } +} + void Foam::vtkPVblockMesh::PrintSelf(ostream& os, vtkIndent indent) const { diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H index dc502926f42ade1b0e501c6dd20871d3b9031f91..a22316c84afce69d88d71c5559185a980c524ae9 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMesh.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,17 +41,7 @@ SourceFiles #ifndef vtkPVblockMesh_H #define vtkPVblockMesh_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" -#include "wordList.H" - -#include "primitivePatch.H" +#include "foamPvCore.H" // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // @@ -83,85 +73,9 @@ template<class Type> class List; \*---------------------------------------------------------------------------*/ class vtkPVblockMesh +: + private foamPvCore { - // Private classes - - //- Bookkeeping for GUI checklists and the multi-block organization - class arrayRange - { - const char *name_; - int block_; - int start_; - int size_; - - public: - - arrayRange(const char *name, const int blockNo=0) - : - name_(name), - block_(blockNo), - start_(0), - size_(0) - {} - - //- Return the block holding these datasets - int block() const - { - return block_; - } - - //- Assign block number, return previous value - int block(int blockNo) - { - int prev = block_; - block_ = blockNo; - return prev; - } - - //- Return block name - const char* name() const - { - return name_; - } - - //- Return array start index - int start() const - { - return start_; - } - - //- Return array end index - int end() const - { - return start_ + size_; - } - - //- Return sublist size - int size() const - { - return size_; - } - - bool empty() const - { - return !size_; - } - - //- Reset the size to zero and optionally assign a new start - void reset(const int startAt = 0) - { - start_ = startAt; - size_ = 0; - } - - //- Increment the size - void operator+=(const int n) - { - size_ += n; - } - }; - - // Private Data //- Access to the controlling vtkPVblockMeshReader @@ -195,109 +109,45 @@ class vtkPVblockMesh //- First instance and size of block corners (only partially used) arrayRange arrayRangeCorners_; - //- List of point numbers for rendering to window - List<vtkTextActor*> pointNumberTextActorsPtrs_; - - // Private Member Functions + //- List of patch names for rendering to window + List<vtkTextActor*> patchTextActorsPtrs_; - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static void AddToBlock - ( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange&, - const label datasetNo, - const std::string& datasetName - ); + //- List of point numbers for rendering to window + List<vtkTextActor*> pointTextActorsPtrs_; - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static vtkDataSet* GetDataSetFromBlock - ( - vtkMultiBlockDataSet* output, - const arrayRange&, - const label datasetNo - ); - // Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - static label GetNumberOfDataSets - ( - vtkMultiBlockDataSet* output, - const arrayRange& - ); + // Private Member Functions - //- Update boolList from GUI selection - static void updateBoolListStatus - ( - boolList&, - vtkDataArraySelection* - ); + //- Create a text actor + static vtkTextActor* createTextActor(const string& s, const point& pt); //- Reset data counters void resetCounters(); - // Update information helper functions - - //- Internal block info - void updateInfoBlocks(vtkDataArraySelection*); - - //- Block curved edges info - void updateInfoEdges(vtkDataArraySelection*); - - // Update helper functions - - //- OpenFOAM mesh - void updateFoamMesh(); - - // Mesh conversion functions - - //- Mesh blocks - void convertMeshBlocks(vtkMultiBlockDataSet*, int& blockNo); - - //- Mesh curved edges - void convertMeshEdges(vtkMultiBlockDataSet*, int& blockNo); - - //- Mesh corners - void convertMeshCorners(vtkMultiBlockDataSet*, int& blockNo); - - - // GUI selection helper functions + //- OpenFOAM mesh + void updateFoamMesh(); - //- Retrieve the current selections - static wordHashSet getSelected(vtkDataArraySelection*); + //- Internal block info + void updateInfoBlocks(vtkDataArraySelection* select); - //- Retrieve a sub-list of the current selections - static wordHashSet getSelected - ( - vtkDataArraySelection*, - const arrayRange& - ); + //- Block curved edges info + void updateInfoEdges(vtkDataArraySelection* select); - //- Retrieve the current selections - static stringList getSelectedArrayEntries(vtkDataArraySelection*); + //- Mesh blocks + void convertMeshBlocks(vtkMultiBlockDataSet*, int& blockNo); - //- Retrieve a sub-list of the current selections - static stringList getSelectedArrayEntries - ( - vtkDataArraySelection*, - const arrayRange& - ); + //- Mesh curved edges + void convertMeshEdges(vtkMultiBlockDataSet*, int& blockNo); - //- Set selection(s) - static void setSelectedArrayEntries - ( - vtkDataArraySelection*, - const stringList& - ); + //- Mesh corners + void convertMeshCorners(vtkMultiBlockDataSet*, int& blockNo); //- Disallow default bitwise copy construct - vtkPVblockMesh(const vtkPVblockMesh&); + vtkPVblockMesh(const vtkPVblockMesh&) = delete; //- Disallow default bitwise assignment - void operator=(const vtkPVblockMesh&); + void operator=(const vtkPVblockMesh&) = delete; public: @@ -331,6 +181,9 @@ public: //- Clean any storage void CleanUp(); + //- Add/remove patch names to/from the view + void renderPatchNames(vtkRenderer*, const bool show); + //- Add/remove point numbers to/from the view void renderPointNumbers(vtkRenderer*, const bool show); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C index 9c7f8a06ba80c5cdea1dcd116a1c53dd404bf8ff..51f8f4c90cac535258a505349f9858f331de50e4 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshConvert.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,8 +30,6 @@ License #include "blockMesh.H" #include "Time.H" -#include "vtkOpenFOAMPoints.H" - // VTK includes #include "vtkCellArray.h" #include "vtkDataArraySelection.h" @@ -41,6 +39,26 @@ License #include "vtkUnstructuredGrid.h" +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +//! \cond fileScope +inline static void insertNextPoint +( + vtkPoints *points, + const Foam::point& p, + const Foam::scalar scaleFactor +) +{ + points->InsertNextPoint + ( + p.x()*scaleFactor, + p.y()*scaleFactor, + p.z()*scaleFactor + ); +} + +//! \endcond + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::vtkPVblockMesh::convertMeshBlocks @@ -52,14 +70,14 @@ void Foam::vtkPVblockMesh::convertMeshBlocks vtkDataArraySelection* selection = reader_->GetBlockSelection(); arrayRange& range = arrayRangeBlocks_; range.block(blockNo); // set output block - label datasetNo = 0; // restart at dataset 0 + label datasetNo = 0; // restart at dataset 0 const blockMesh& blkMesh = *meshPtr_; const Foam::pointField& blockPoints = blkMesh.vertices(); if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::convertMeshBlocks" << endl; + Info<< "<beg> convertMeshBlocks" << endl; } int blockI = 0; @@ -79,19 +97,16 @@ void Foam::vtkPVblockMesh::convertMeshBlocks const blockDescriptor& blockDef = blkMesh[blockI]; - vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); - // Convert OpenFOAM mesh vertices to VTK vtkPoints *vtkpoints = vtkPoints::New(); - vtkpoints->Allocate( blockDef.nPoints() ); + vtkpoints->Allocate(blockDef.nPoints()); const labelList& blockLabels = blockDef.blockShape(); - vtkmesh->Allocate(1); vtkIdType nodeIds[8]; forAll(blockLabels, ptI) { - vtkInsertNextOpenFOAMPoint + insertNextPoint ( vtkpoints, blockPoints[blockLabels[ptI]], @@ -101,6 +116,8 @@ void Foam::vtkPVblockMesh::convertMeshBlocks nodeIds[ptI] = ptI; } + vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); + vtkmesh->Allocate(1); vtkmesh->InsertNextCell ( VTK_HEXAHEDRON, @@ -111,7 +128,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks vtkmesh->SetPoints(vtkpoints); vtkpoints->Delete(); - AddToBlock + addToBlock ( output, vtkmesh, range, datasetNo, selection->GetArrayName(partId) @@ -130,7 +147,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::convertMeshBlocks" << endl; + Info<< "<end> convertMeshBlocks" << endl; } } @@ -201,7 +218,7 @@ void Foam::vtkPVblockMesh::convertMeshEdges vtkIdType pointIds[edgePoints.size()]; forAll(edgePoints, ptI) { - vtkInsertNextOpenFOAMPoint + insertNextPoint ( vtkpoints, edgePoints[ptI], @@ -220,7 +237,7 @@ void Foam::vtkPVblockMesh::convertMeshEdges vtkmesh->SetPoints(vtkpoints); vtkpoints->Delete(); - AddToBlock + addToBlock ( output, vtkmesh, range, datasetNo, selection->GetArrayName(partId) @@ -234,7 +251,6 @@ void Foam::vtkPVblockMesh::convertMeshEdges } } - // anything added? if (datasetNo) { @@ -243,7 +259,7 @@ void Foam::vtkPVblockMesh::convertMeshEdges if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::convertMeshEdges" << endl; + Info<< "<end> convertMeshEdges" << endl; } } @@ -264,7 +280,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners if (debug) { - Info<< "<beg> Foam::vtkPVblockMesh::convertMeshCorners" << endl; + Info<< "<beg> convertMeshCorners" << endl; } if (true) // or some flag or other condition @@ -279,14 +295,14 @@ void Foam::vtkPVblockMesh::convertMeshCorners vtkIdType pointId = 0; forAll(blockPoints, ptI) { - vtkInsertNextOpenFOAMPoint + insertNextPoint ( vtkpoints, blockPoints[ptI], scaleFactor ); - vtkcells->InsertNextCell(1, &pointId); + vtkcells->InsertNextCell(1, &pointId); // VTK_VERTEX pointId++; } @@ -296,11 +312,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners vtkmesh->SetVerts(vtkcells); vtkcells->Delete(); - AddToBlock - ( - output, vtkmesh, range, datasetNo, - arrayRangeCorners_.name() - ); + addToBlock(output, vtkmesh, range, datasetNo, range.name()); vtkmesh->Delete(); datasetNo++; @@ -314,7 +326,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners if (debug) { - Info<< "<end> Foam::vtkPVblockMesh::convertMeshCorners" << endl; + Info<< "<end> convertMeshCorners" << endl; } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C deleted file mode 100644 index a838c5b602c3a84ee98c58ca13713cf7c689709c..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/vtkPVblockMesh/vtkPVblockMeshUtils.C +++ /dev/null @@ -1,357 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Description - Misc helper methods and utilities - -\*---------------------------------------------------------------------------*/ - -#include "vtkPVblockMesh.H" -#include "vtkPVblockMeshReader.h" - -// VTK includes -#include "vtkDataArraySelection.h" -#include "vtkDataSet.h" -#include "vtkMultiBlockDataSet.h" -#include "vtkInformation.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - //! \cond fileScope - // Extract up to the first non-word characters - inline word getFirstWord(const char* str) - { - if (str) - { - label n = 0; - while (str[n] && word::valid(str[n])) - { - ++n; - } - return word(str, n, true); - } - else - { - return word::null; - } - - } - //! \endcond - -} // End namespace Foam - - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::vtkPVblockMesh::AddToBlock -( - vtkMultiBlockDataSet* output, - vtkDataSet* dataset, - const arrayRange& range, - const label datasetNo, - const std::string& datasetName -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - - if (!block) - { - if (blockDO) - { - FatalErrorInFunction - << "Block already has a vtkDataSet assigned to it" - << endl; - return; - } - - block = vtkMultiBlockDataSet::New(); - output->SetBlock(blockNo, block); - block->Delete(); - } - - if (debug) - { - Info<< "block[" << blockNo << "] has " - << block->GetNumberOfBlocks() - << " datasets prior to adding set " << datasetNo - << " with name: " << datasetName << endl; - } - - block->SetBlock(datasetNo, dataset); - - // name the block when assigning dataset 0 - if (datasetNo == 0) - { - output->GetMetaData(blockNo)->Set - ( - vtkCompositeDataSet::NAME(), - range.name() - ); - } - - if (datasetName.size()) - { - block->GetMetaData(datasetNo)->Set - ( - vtkCompositeDataSet::NAME(), - datasetName.c_str() - ); - } -} - - -vtkDataSet* Foam::vtkPVblockMesh::GetDataSetFromBlock -( - vtkMultiBlockDataSet* output, - const arrayRange& range, - const label datasetNo -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - - if (block) - { - return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); - } - - return 0; -} - - -// ununsed at the moment -Foam::label Foam::vtkPVblockMesh::GetNumberOfDataSets -( - vtkMultiBlockDataSet* output, - const arrayRange& range -) -{ - const int blockNo = range.block(); - - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - if (block) - { - return block->GetNumberOfBlocks(); - } - - return 0; -} - - -Foam::wordHashSet Foam::vtkPVblockMesh::getSelected -( - vtkDataArraySelection* select -) -{ - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); - - for (int elemI=0; elemI < nElem; ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections.insert(getFirstWord(select->GetArrayName(elemI))); - } - } - - return selections; -} - - -Foam::wordHashSet Foam::vtkPVblockMesh::getSelected -( - vtkDataArraySelection* select, - const arrayRange& range -) -{ - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); - - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections.insert(getFirstWord(select->GetArrayName(elemI))); - } - } - - return selections; -} - - -Foam::stringList Foam::vtkPVblockMesh::getSelectedArrayEntries -( - vtkDataArraySelection* select -) -{ - stringList selections(select->GetNumberOfArrays()); - label nElem = 0; - - forAll(selections, elemI) - { - if (select->GetArraySetting(elemI)) - { - selections[nElem++] = select->GetArrayName(elemI); - } - } - selections.setSize(nElem); - - - if (debug) - { - label nElem = select->GetNumberOfArrays(); - Info<< "available("; - for (int elemI = 0; elemI < nElem; ++elemI) - { - Info<< " \"" << select->GetArrayName(elemI) << "\""; - } - Info<< " )\nselected("; - - forAll(selections, elemI) - { - Info<< " " << selections[elemI]; - } - Info<< " )\n"; - } - - return selections; -} - - -Foam::stringList Foam::vtkPVblockMesh::getSelectedArrayEntries -( - vtkDataArraySelection* select, - const arrayRange& range -) -{ - stringList selections(range.size()); - label nElem = 0; - - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - if (select->GetArraySetting(elemI)) - { - selections[nElem++] = select->GetArrayName(elemI); - } - } - selections.setSize(nElem); - - - if (debug) - { - Info<< "available("; - for (int elemI = range.start(); elemI < range.end(); ++elemI) - { - Info<< " \"" << select->GetArrayName(elemI) << "\""; - } - Info<< " )\nselected("; - - forAll(selections, elemI) - { - Info<< " " << selections[elemI]; - } - Info<< " )\n"; - } - - return selections; -} - - -void Foam::vtkPVblockMesh::setSelectedArrayEntries -( - vtkDataArraySelection* select, - const stringList& selections -) -{ - const int nElem = select->GetNumberOfArrays(); - select->DisableAllArrays(); - - // Loop through entries, setting values from selectedEntries - for (int elemI=0; elemI < nElem; ++elemI) - { - string arrayName(select->GetArrayName(elemI)); - - forAll(selections, elemI) - { - if (selections[elemI] == arrayName) - { - select->EnableArray(arrayName.c_str()); - break; - } - } - } -} - - -void Foam::vtkPVblockMesh::updateBoolListStatus -( - boolList& status, - vtkDataArraySelection* selection -) -{ - if (debug) - { - Info<< "<beg> Foam::vtkPVblockMesh::updateBoolListStatus" << endl; - } - - const label nElem = selection->GetNumberOfArrays(); - if (status.size() != nElem) - { - status.setSize(nElem); - status = false; - } - - forAll(status, elemI) - { - const int setting = selection->GetArraySetting(elemI); - - status[elemI] = setting; - - if (debug) - { - Info<< " part[" << elemI << "] = " - << status[elemI] - << " : " << selection->GetArrayName(elemI) << endl; - } - } - if (debug) - { - Info<< "<end> Foam::vtkPVblockMesh::updateBoolListStatus" << endl; - } -} - - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - - -// ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..6bace7560c49663bfdd86c1450dcfaef6f12b2ce --- /dev/null +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/files @@ -0,0 +1,3 @@ +foamPvCore.C + +LIB = $(FOAM_LIBBIN)/libfoamPv-pv${ParaView_MAJOR} diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options similarity index 62% rename from applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options rename to applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options index d84fae1560c139b3eb0a19d7ad4d9e67d5d2faf9..a5276c021d93daeb9ace59b0cf6a935bdb295186 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options @@ -1,5 +1,8 @@ +sinclude $(GENERAL_RULES)/paraview + EXE_INC = \ ${c++LESSWARN} \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.C b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C similarity index 58% rename from applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.C rename to applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C index 2197fb73616229df4e874b992058c08ff6163177..478cff22a4dc7d99b7cefd666f18964cade030c6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -21,17 +21,13 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Description - Misc helper methods and utilities - \*---------------------------------------------------------------------------*/ -#include "vtkPVReaders.H" +#include "foamPvCore.H" -// OpenFOAM includes -#include "IFstream.H" +#include "memInfo.H" +#include "DynamicList.H" -// VTK includes #include "vtkDataArraySelection.h" #include "vtkDataSet.h" #include "vtkMultiBlockDataSet.h" @@ -41,57 +37,28 @@ Description namespace Foam { -defineTypeNameAndDebug(vtkPVReaders, 0); + defineTypeNameAndDebug(foamPvCore, 0); } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - //! \cond fileScope - // Extract up to the first non-word characters - inline word getFirstWord(const char* str) - { - if (str) - { - label n = 0; - while (str[n] && word::valid(str[n])) - { - ++n; - } - return word(str, n, true); - } - else - { - return word::null; - } - - } - //! \endcond - -} // End namespace Foam - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::vtkPVReaders::AddToBlock +void Foam::foamPvCore::addToBlock ( vtkMultiBlockDataSet* output, vtkDataSet* dataset, - const partInfo& selector, + const arrayRange& selector, const label datasetNo, const std::string& datasetName ) { const int blockNo = selector.block(); - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + vtkDataObject* dataObj = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(dataObj); if (!block) { - if (blockDO) + if (dataObj) { FatalErrorInFunction << "Block already has a vtkDataSet assigned to it" @@ -114,7 +81,7 @@ void Foam::vtkPVReaders::AddToBlock block->SetBlock(datasetNo, dataset); - // name the block when assigning dataset 0 + // name the output block when assigning dataset 0 if (datasetNo == 0) { output->GetMetaData(blockNo)->Set @@ -135,95 +102,98 @@ void Foam::vtkPVReaders::AddToBlock } -vtkDataSet* Foam::vtkPVReaders::GetDataSetFromBlock +int Foam::foamPvCore::getNumberOfDataSets ( vtkMultiBlockDataSet* output, - const partInfo& selector, - const label datasetNo + const arrayRange& selector ) { const int blockNo = selector.block(); - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast + ( + output->GetBlock(blockNo) + ); if (block) { - return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); + return block->GetNumberOfBlocks(); } return 0; } -// ununsed at the moment -Foam::label Foam::vtkPVReaders::GetNumberOfDataSets +int Foam::foamPvCore::getSelected ( - vtkMultiBlockDataSet* output, - const partInfo& selector + boolList& status, + vtkDataArraySelection* selection ) { - const int blockNo = selector.block(); + const int n = selection->GetNumberOfArrays(); + if (status.size() != n) + { + status.setSize(n); + status = false; + } - vtkDataObject* blockDO = output->GetBlock(blockNo); - vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); - if (block) + int count = 0; + forAll(status, i) { - return block->GetNumberOfBlocks(); + const bool setting = selection->GetArraySetting(i); + if (setting) + { + ++count; + } + status[i] = setting; } - return 0; + return count; } -// Foam::word Foam::vtkPVReaders::getPartName(int partId) -// { -// return getFirstWord(reader_->GetPartArrayName(partId)); -// } - - -Foam::wordHashSet Foam::vtkPVReaders::getSelected +Foam::hashedWordList Foam::foamPvCore::getSelected ( vtkDataArraySelection* select ) { - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); + const int n = select->GetNumberOfArrays(); + DynamicList<word> selected(n); - for (int elemI=0; elemI < nElem; ++elemI) + for (int i=0; i < n; ++i) { - if (select->GetArraySetting(elemI)) + if (select->GetArraySetting(i)) { - selections.insert(getFirstWord(select->GetArrayName(elemI))); + selected.append(getFirstWord(select->GetArrayName(i))); } } - return selections; + return hashedWordList(selected, true); } -Foam::wordHashSet Foam::vtkPVReaders::getSelected +Foam::hashedWordList Foam::foamPvCore::getSelected ( vtkDataArraySelection* select, - const partInfo& selector + const arrayRange& selector ) { - int nElem = select->GetNumberOfArrays(); - wordHashSet selections(2*nElem); + const int n = select->GetNumberOfArrays(); + DynamicList<word> selected(n); - for (int elemI = selector.start(); elemI < selector.end(); ++elemI) + for (int i = selector.start(); i < selector.end(); ++i) { - if (select->GetArraySetting(elemI)) + if (select->GetArraySetting(i)) { - selections.insert(getFirstWord(select->GetArrayName(elemI))); + selected.append(getFirstWord(select->GetArrayName(i))); } } - return selections; + return hashedWordList(selected, true); } -Foam::stringList Foam::vtkPVReaders::getSelectedArrayEntries +Foam::stringList Foam::foamPvCore::getSelectedArrayEntries ( vtkDataArraySelection* select ) @@ -240,14 +210,13 @@ Foam::stringList Foam::vtkPVReaders::getSelectedArrayEntries } selections.setSize(nElem); - - if (debug) + if (debug > 1) { - label nElem = select->GetNumberOfArrays(); + const int n = select->GetNumberOfArrays(); Info<< "available("; - for (int elemI = 0; elemI < nElem; ++elemI) + for (int i=0; i < n; ++i) { - Info<< " \"" << select->GetArrayName(elemI) << "\""; + Info<< " \"" << select->GetArrayName(i) << "\""; } Info<< " )\nselected("; @@ -262,31 +231,30 @@ Foam::stringList Foam::vtkPVReaders::getSelectedArrayEntries } -Foam::stringList Foam::vtkPVReaders::getSelectedArrayEntries +Foam::stringList Foam::foamPvCore::getSelectedArrayEntries ( vtkDataArraySelection* select, - const partInfo& selector + const arrayRange& selector ) { stringList selections(selector.size()); label nElem = 0; - for (int elemI = selector.start(); elemI < selector.end(); ++elemI) + for (int i = selector.start(); i < selector.end(); ++i) { - if (select->GetArraySetting(elemI)) + if (select->GetArraySetting(i)) { - selections[nElem++] = select->GetArrayName(elemI); + selections[nElem++] = select->GetArrayName(i); } } selections.setSize(nElem); - - if (debug) + if (debug > 1) { Info<< "available("; - for (int elemI = selector.start(); elemI < selector.end(); ++elemI) + for (int i = selector.start(); i < selector.end(); ++i) { - Info<< " \"" << select->GetArrayName(elemI) << "\""; + Info<< " \"" << select->GetArrayName(i) << "\""; } Info<< " )\nselected("; @@ -301,19 +269,19 @@ Foam::stringList Foam::vtkPVReaders::getSelectedArrayEntries } -void Foam::vtkPVReaders::setSelectedArrayEntries +void Foam::foamPvCore::setSelectedArrayEntries ( vtkDataArraySelection* select, const stringList& selections ) { - const int nElem = select->GetNumberOfArrays(); + const int n = select->GetNumberOfArrays(); select->DisableAllArrays(); // Loop through entries, setting values from selectedEntries - for (int elemI=0; elemI < nElem; ++elemI) + for (int i=0; i < n; ++i) { - string arrayName(select->GetArrayName(elemI)); + const string arrayName(select->GetArrayName(i)); forAll(selections, elemI) { @@ -327,7 +295,33 @@ void Foam::vtkPVReaders::setSelectedArrayEntries } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +Foam::word Foam::foamPvCore::getFirstWord(const char* str) +{ + if (str) + { + label n = 0; + while (str[n] && word::valid(str[n])) + { + ++n; + } + // don't need to re-check for invalid chars + return word(str, n, false); + } + else + { + return word::null; + } +} +void Foam::foamPvCore::printMemory() +{ + memInfo mem; + + if (mem.valid()) + { + Info<< "mem peak/size/rss: " << mem << endl; + } +} + // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H similarity index 52% rename from applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H rename to applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H index 958668105f701ddcbb9c2b52de9e5daf8d42ce58..f6203690fd54f7eeb730faea212b19c9ef51c937 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/vtkPVReaders.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCore.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -21,44 +21,33 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Namespace - Foam::vtkPVReaders - Description - A collection of helper functions when building a reader interface in - ParaView3. + Helpers for OpenFOAM reader interfaces in ParaView. SourceFiles - vtkPVReaders.C + foamPvCore.C \*---------------------------------------------------------------------------*/ -#ifndef vtkPVReaders_H -#define vtkPVReaders_H - -// do not include legacy strstream headers -#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS -# define VTK_EXCLUDE_STRSTREAM_HEADERS -#endif +#ifndef foamPvCore_H +#define foamPvCore_H #include "className.H" #include "fileName.H" #include "stringList.H" +#include "boolList.H" +#include "pointList.H" #include "wordList.H" -#include "HashSet.H" +#include "Hash.H" +#include "hashedWordList.H" +#include "vtkPoints.h" // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // class vtkDataArraySelection; class vtkDataSet; -class vtkPoints; -class vtkPVFoamReader; -class vtkRenderer; -class vtkTextActor; class vtkMultiBlockDataSet; -class vtkPolyData; -class vtkUnstructuredGrid; class vtkIndent; @@ -66,13 +55,20 @@ class vtkIndent; namespace Foam { -namespace vtkPVReaders + +class IOobjectList; + +/*---------------------------------------------------------------------------*\ + Class foamPvCore Declaration +\*---------------------------------------------------------------------------*/ + +class foamPvCore { - //- Declare name of the class and its debug switch - NamespaceName("vtkPVReaders"); +public: - //- Bookkeeping for GUI checklists and the multi-block organization - class partInfo + //- Bookkeeping for GUI checklists and multi-block organization + // Works like a SubList selection. + class arrayRange { const char *name_; int block_; @@ -81,11 +77,12 @@ namespace vtkPVReaders public: - partInfo(const char *name, const int blockNo=0) + //- Construct with given name for the specified block + arrayRange(const char *name, const int blockNo=0) : name_(name), block_(blockNo), - start_(-1), + start_(0), size_(0) {} @@ -103,42 +100,47 @@ namespace vtkPVReaders return prev; } + //- Return the name const char* name() const { return name_; } + //- The array start index int start() const { return start_; } + //- The array end index int end() const { return start_ + size_; } + //- The sub-list size int size() const { return size_; } + //- True if the sub-list is empty bool empty() const { return !size_; } - void reset() + //- Reset the size to zero and optionally assign a new start + void reset(const int startAt = 0) { - start_ = -1; - size_ = 0; + start_ = startAt; + size_ = 0; } //- Assign new start and reset the size void operator=(const int i) { - start_ = i; - size_ = 0; + reset(i); } //- Increment the size @@ -146,81 +148,132 @@ namespace vtkPVReaders { size_ += n; } - }; + }; // End class arrayRange + + +private: - //- Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - void AddToBlock + // Private Member Functions + + //- Disallow default bitwise copy construct + foamPvCore(const foamPvCore&) = delete; + + //- Disallow default bitwise assignment + void operator=(const foamPvCore&) = delete; + +public: + + //- Static data members + ClassName("foamPvCore"); + + + //- Construct null + foamPvCore() + {} + + + //- Convenience method for the VTK multiblock API + static void addToBlock ( vtkMultiBlockDataSet* output, vtkDataSet* dataset, - const partInfo& selector, + const arrayRange& selector, const label datasetNo, const std::string& datasetName ); - - //- Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - vtkDataSet* GetDataSetFromBlock + //- Convenience method for the VTK multiblock API + // Always returns a nullptr if datasetNo is negative + template<class Type=vtkDataSet> + static Type* getDataFromBlock ( vtkMultiBlockDataSet* output, - const partInfo& selector, + const arrayRange& selector, const label datasetNo ); - //- Convenience method use to convert the readers from VTK 5 - // multiblock API to the current composite data infrastructure - // ununsed at the moment - label GetNumberOfDataSets + //- Convenience method for the VTK multiblock API + static int getNumberOfDataSets ( vtkMultiBlockDataSet* output, - const partInfo& selector + const arrayRange& selector ); + //- Add objects of Type to array selection + template<class Type> + static label addToSelection + ( + vtkDataArraySelection* select, + const IOobjectList& objects, + const string& suffix = string::null + ); + + + //- Retrieve the current selections into a boolList + static int getSelected + ( + boolList& lst, + vtkDataArraySelection* select + ); //- Retrieve the current selections as a wordHashSet - wordHashSet getSelected + static hashedWordList getSelected ( vtkDataArraySelection* select ); //- Retrieve a sub-list of the current selections - wordHashSet getSelected + static hashedWordList getSelected ( - vtkDataArraySelection*, - const partInfo& + vtkDataArraySelection* select, + const arrayRange& selector ); //- Retrieve the current selections - stringList getSelectedArrayEntries(vtkDataArraySelection*); + static stringList getSelectedArrayEntries + ( + vtkDataArraySelection* select + ); //- Retrieve a sub-list of the current selections - stringList getSelectedArrayEntries + static stringList getSelectedArrayEntries ( vtkDataArraySelection* select, - const partInfo& selector + const arrayRange& selector ); //- Set selection(s) - void setSelectedArrayEntries + static void setSelectedArrayEntries ( - vtkDataArraySelection*, - const stringList& + vtkDataArraySelection* select, + const stringList& selections ); + //- Extract up to the first non-word characters + static word getFirstWord(const char* str); + + //- Simple memory used debugging information + static void printMemory(); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace vtkPV +}; // End class foamPvCore } // End namespace Foam +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "foamPvCoreTemplates.C" +#endif + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamAddToSelection.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C similarity index 63% rename from applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamAddToSelection.H rename to applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C index 8368b7d350ee9dbbe75d2fc0909b3578a7e9affe..e5d1353699ea5fa62a738e42b2f069b60449082f 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkPVFoamAddToSelection.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvCoreTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,43 +23,57 @@ License \*---------------------------------------------------------------------------*/ -#ifndef vtkPVFoamAddToSelection_H -#define vtkPVFoamAddToSelection_H - -// OpenFOAM includes #include "IOobjectList.H" -#include "SortableList.H" - -// VTK includes #include "vtkDataArraySelection.h" +#include "vtkMultiBlockDataSet.h" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template<class Type> -Foam::label Foam::vtkPVFoam::addToSelection +Type* Foam::foamPvCore::getDataFromBlock +( + vtkMultiBlockDataSet* output, + const arrayRange& selector, + const label datasetNo +) +{ + const int blockNo = selector.block(); + + vtkMultiBlockDataSet* block = + ( + datasetNo < 0 + ? nullptr + : vtkMultiBlockDataSet::SafeDownCast(output->GetBlock(blockNo)) + ); + + if (block) + { + return Type::SafeDownCast(block->GetBlock(datasetNo)); + } + + return nullptr; +} + + +template<class Type> +Foam::label Foam::foamPvCore::addToSelection ( vtkDataArraySelection *select, - const IOobjectList& objectLst, + const IOobjectList& objects, const string& suffix ) { - SortableList<word> names(objectLst.names(Type::typeName)); + const wordList names = objects.sortedNames(Type::typeName); - forAll(names, nameI) + forAll(names, i) { - if (suffix.size()) + if (suffix.empty()) { - select->AddArray - ( - (names[nameI] + suffix).c_str() - ); + select->AddArray(names[i].c_str()); } else { - select->AddArray - ( - (names[nameI]).c_str() - ); + select->AddArray((names[i] + suffix).c_str()); } } @@ -67,8 +81,4 @@ Foam::label Foam::vtkPVFoam::addToSelection } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - // ************************************************************************* // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H similarity index 59% rename from applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H rename to applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H index d18bc79b3367f8c9902a286970c2df802b24ea28..69bb841fcf01a985ea170140403cc844ff7f32aa 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/foamPvFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,36 +21,57 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -InClass - vtkPVFoam +Description + Helpers for OpenFOAM reader interfaces in ParaView. \*---------------------------------------------------------------------------*/ -#ifndef vtkOpenFOAMTupleRemap_H -#define vtkOpenFOAMTupleRemap_H +#ifndef foamPvFields_H +#define foamPvFields_H -// OpenFOAM includes -#include "Swap.H" +#include "volFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template<class Type> -inline void vtkOpenFOAMTupleRemap(float vec[]); +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamPvFields Declaration +\*---------------------------------------------------------------------------*/ + +class foamPvFields +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + foamPvFields(const foamPvFields&) = delete; + + //- Disallow default bitwise assignment + void operator=(const foamPvFields&) = delete; + +public: + + //- Remapping for some data types + template<class Type> + inline static void remapTuple(float vec[]) + {} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +}; // End class foamPvFields // Template specialization for symmTensor template<> -inline void vtkOpenFOAMTupleRemap<Foam::symmTensor>(float vec[]) +inline void Foam::foamPvFields::remapTuple<Foam::symmTensor>(float vec[]) { Foam::Swap(vec[1], vec[3]); // swap XY <-> YY Foam::Swap(vec[2], vec[5]); // swap XZ <-> ZZ } -template<class Type> -inline void vtkOpenFOAMTupleRemap(float vec[]) -{} - +} // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files deleted file mode 100644 index e26a8c4979edaf598e44246acf36382211b3cc16..0000000000000000000000000000000000000000 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVReaders/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -vtkPVReaders.C - -LIB = $(FOAM_LIBBIN)/libvtkPVReaders diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions index c3c6be894831806843952b5562a15d0feb0b0326..59e1d66194a9db49f00046428d748736a3ab408f 100755 --- a/bin/tools/RunFunctions +++ b/bin/tools/RunFunctions @@ -148,8 +148,9 @@ runParallel() # Store any parsed additional arguments e.g. decomposeParDict APP_PARARGS= - # Check the default decomposeParDict if available - nProcs=$(getNumberOfProcessors system/decomposeParDict) + + # Initialise number of procs to unset value + nProcs=-1 # Parse options and executable while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do @@ -185,6 +186,8 @@ runParallel() shift done + [ "$nProcs" -eq -1 ] && nProcs=$(getNumberOfProcessors system/decomposeParDict) + if [ -f log.$LOG_SUFFIX ] && [ "$LOG_IGNORE" = "false" ] then echo "$APP_NAME already run on $PWD:" \ @@ -213,7 +216,7 @@ cloneCase() else echo "Cloning $2 case from $1" mkdir $2 - cpfiles="0 system constant" + cpfiles="0.orig 0 system constant" for f in $cpfiles do \cp -r $1/$f $2 diff --git a/doc/Doxygen/Allwmake b/doc/Doxygen/Allwmake index 8ca2ed256d326b4115cdb17b208039a72bfc71de..9947ab925d1f8184601057a17d0cbd5edb94eab7 100755 --- a/doc/Doxygen/Allwmake +++ b/doc/Doxygen/Allwmake @@ -1,10 +1,9 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory - [ -d "$WM_PROJECT_DIR" ] || { - echo " Error: WM_PROJECT_DIR directory does not exist" - echo " Check the OpenFOAM entries in your dot-files and source them." - echo " WM_PROJECT_DIR=$WM_PROJECT_DIR" + echo "Error (${0##*/}) : no \$WM_PROJECT_DIR found" + echo " Check your OpenFOAM environment and installation" + echo " WM_PROJECT_DIR=$WM_PROJECT_DIR" exit 1 } @@ -15,29 +14,29 @@ usage() { usage: ${0##*/} [OPTION] options: - -online use the links to the Github repositories instead of the local source code + -online use links to the Github repositories instead of the local source code -help USAGE exit 1 } -defineURL() { - WEB_PATH="https://develop.openfoam.com" - FOAM_REPO_VERSION="$WM_PROJECT-plus" +defineURL() { + WEB_PATH="https://develop.openfoam.com" + FOAM_REPO_VERSION="$WM_PROJECT-plus" - case "$WM_PROJECT_VERSION" in - v[0-9].[0-9]+) - FOAM_REPO_TAG="$WM_PROJECT-$WM_PROJECT_VERSION" - ;; - *) - FOAM_REPO_TAG="master" - ;; - esac + case "$WM_PROJECT_VERSION" in + v[1-9][.0-9]*) + FOAM_REPO_TAG="$WM_PROJECT-$WM_PROJECT_VERSION" + ;; + *) + FOAM_REPO_TAG="master" + ;; + esac - export FOAM_BASE_REPO="$WEB_PATH/Development/$FOAM_REPO_VERSION" - export FOAM_ONLINE_REPO="$FOAM_BASE_REPO/blob/${FOAM_REPO_TAG}" + export FOAM_BASE_REPO="$WEB_PATH/Development/$FOAM_REPO_VERSION" + export FOAM_ONLINE_REPO="$FOAM_BASE_REPO/blob/${FOAM_REPO_TAG}" } # parse options @@ -49,12 +48,12 @@ do ;; -online) defineURL - shift ;; *) - usage "unknown option/argument: '$*'" + usage "unknown option/argument: '$1'" ;; esac + shift done #------------------------------------------------------------------------------ diff --git a/src/Allwmake b/src/Allwmake index 000688c332ae9fd8902e44c5e8a486d0eaa70a5c..9d13d973f8ae4571a4d28f727863c05dd95eb863 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -1,22 +1,21 @@ #!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Parse arguments for library compilation -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments - -wmakeCheckPwd "$WM_PROJECT_DIR/src" || { - echo "Allwmake error: Current directory is not \$WM_PROJECT_DIR/src" - echo " The environment variables are inconsistent with the installation." - echo " Check the OpenFOAM entries in your dot-files and source them." +# Run from OPENFOAM src/ directory only +cd ${0%/*} && wmakeCheckPwd "$WM_PROJECT_DIR/src" 2>/dev/null || { + echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR/src" + echo " Check your OpenFOAM environment and installation" exit 1 } - [ -n "$FOAM_EXT_LIBBIN" ] || { - echo "Allwmake error: FOAM_EXT_LIBBIN not set" - echo " Check the OpenFOAM entries in your dot-files and source them." + echo "Error (${0##*/}) : FOAM_EXT_LIBBIN not set" + echo " Check your OpenFOAM environment and installation" exit 1 } +# Parse arguments for library compilation +. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments + +#------------------------------------------------------------------------------ + # Update OpenFOAM version strings if required wmakePrintBuild -check || wrmo OpenFOAM/global/global.o 2>/dev/null diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C index df115134ef3379bf3156c1700b53e5a2095db5a1..288d16dbc63bcbe81d9e0790b61aa9356cdf0d84 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,7 +45,15 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable { for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter) { - this->insert(iter.key(), new T(**iter)); + const T* ptr = *iter; + if (ptr) + { + this->insert(iter.key(), new T(*ptr)); + } + else + { + this->insert(iter.key(), nullptr); + } } } @@ -62,24 +70,24 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class T, class Key, class Hash> -T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& it) +T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter) { - T* elemPtr = *it; - HashTable<T*, Key, Hash>::erase(it); - return elemPtr; + T* ptr = *iter; + HashTable<T*, Key, Hash>::erase(iter); + return ptr; } template<class T, class Key, class Hash> -bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& it) +bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter) { - T* elemPtr = *it; + T* ptr = *iter; - if (HashTable<T*, Key, Hash>::erase(it)) + if (HashTable<T*, Key, Hash>::erase(iter)) { - if (elemPtr) + if (ptr) { - delete elemPtr; + delete ptr; } return true; @@ -128,7 +136,15 @@ void Foam::HashPtrTable<T, Key, Hash>::operator= for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter) { - this->insert(iter.key(), new T(**iter)); + const T* ptr = *iter; + if (ptr) + { + this->insert(iter.key(), new T(*ptr)); + } + else + { + this->insert(iter.key(), nullptr); + } } } diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H index 796076fe22a49226fa4f5e2105ed9863fe11226a..de85df3bd6846f81d89f4111021125122847baf5 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -70,7 +70,7 @@ class HashPtrTable //- Read from Istream using given Istream constructor class template<class INew> - void read(Istream&, const INew& inewt); + void read(Istream& is, const INew& inewt); //- Read from dictionary using given dictionary constructor class template<class INew> @@ -91,17 +91,17 @@ public: //- Construct from Istream using given Istream constructor class template<class INew> - HashPtrTable(Istream&, const INew&); + HashPtrTable(Istream& is, const INew& inewt); //- Construct from Istream using default Istream constructor class - HashPtrTable(Istream&); + HashPtrTable(Istream& is); //- Construct from dictionary using default dictionary constructor // class - HashPtrTable(const dictionary&); + HashPtrTable(const dictionary& dict); //- Construct as copy - HashPtrTable(const HashPtrTable<T, Key, Hash>&); + HashPtrTable(const HashPtrTable<T, Key, Hash>& ht); //- Destructor @@ -113,10 +113,10 @@ public: // Edit //- Remove and return the pointer specified by given iterator - T* remove(iterator&); + T* remove(iterator& iter); //- Erase an hashedEntry specified by given iterator - bool erase(iterator&); + bool erase(iterator& iter); //- Clear all entries from table void clear(); @@ -127,7 +127,8 @@ public: // Member Operators - void operator=(const HashPtrTable<T, Key, Hash>&); + //- Copy assignment + void operator=(const HashPtrTable<T, Key, Hash>& rhs); // IOstream Operators diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C index 283968a9b42f7b90d0a7972560c2e94502517959..ddd10aea4cf8923147aa5a33f816d9fb8f1dd83e 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,7 +61,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt) if (delimiter == token::BEGIN_LIST) { - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { Key key; is >> key; @@ -166,8 +166,11 @@ void Foam::HashPtrTable<T, Key, Hash>::write(Ostream& os) const ++iter ) { - const T* ptr = iter(); - ptr->write(os); + const T* ptr = *iter; + if (ptr) + { + ptr->write(os); + } } } @@ -226,7 +229,14 @@ Foam::Ostream& Foam::operator<< ++iter ) { - os << iter.key() << token::SPACE << *iter() << nl; + const T* ptr = *iter; + + os << iter.key(); + if (ptr) + { + os << token::SPACE << *ptr; + } + os << nl; } // Write end delimiter diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 037199636daca5da911422c2943b53ceb44beb7d..cc32bf9fd05e0f1501d86351971b8ef9e131eb30 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -144,10 +144,10 @@ class HashTable private: //- Disallow default bitwise copy construct - hashedEntry(const hashedEntry&); + hashedEntry(const hashedEntry&) = delete; //- Disallow default bitwise assignment - void operator=(const hashedEntry&); + void operator=(const hashedEntry&) = delete; }; @@ -400,10 +400,6 @@ public: //- Return non-const access to referenced object inline T& object(); - //- Return const access to referenced object - inline const T& cobject() const; - - public: // Member operators @@ -413,6 +409,9 @@ public: //- Return the Key corresponding to the iterator inline const Key& key() const; + //- Return const access to referenced object + inline const T& cobject() const; + //- Compare hashedEntry element pointers inline bool operator==(const iteratorBase&) const; inline bool operator!=(const iteratorBase&) const; @@ -460,11 +459,14 @@ public: // Member operators - //- Return referenced hash value + //- Return non-const access to referenced object + using iteratorBase::object; + + //- Return non-const access to referenced object inline T& operator*(); inline T& operator()(); - //- Return referenced hash value + //- Return const access to referenced object inline const T& operator*() const; inline const T& operator()() const; @@ -518,13 +520,12 @@ public: // Member operators - //- Return referenced hash value + //- Return const access to referenced object inline const T& operator*() const; inline const T& operator()() const; inline const_iterator& operator++(); inline const_iterator operator++(int); - }; diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index bbc55ec10dd7a1db58ba92aa9951f3e618a902b5..6229cb94904c4ccf241f1a9325e1b60b1191cda7 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -64,7 +64,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L) } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read L.setSize(s); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 52177d79bcb511819537e0a801ad9482f74252c2..320b22f68fe8f354742d80d9d7b6d1a00fa22889 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -183,7 +183,7 @@ bool Foam::UList<T>::operator<(const UList<T>& a) const ( const_iterator vi = begin(), ai = a.begin(); vi < end() && ai < a.end(); - vi++, ai++ + ++vi, ++ai ) { if (*vi < *ai) diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 719df10a0f00cf28afdb2549d7a1e8359510189c..a31416cc7374a5f520a486c099b003c163ea49a6 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -427,7 +427,7 @@ inline void reverse(UList<T>&); // \endcode // \sa forAllReverse #define forAll(list, i) \ - for (Foam::label i=0; i<(list).size(); i++) + for (Foam::label i=0; i<(list).size(); ++i) //- Reverse loop across all elements in \a list // \par Usage @@ -439,7 +439,7 @@ inline void reverse(UList<T>&); // \endcode // \sa forAll #define forAllReverse(list, i) \ - for (Foam::label i=(list).size()-1; i>=0; i--) + for (Foam::label i=(list).size()-1; i>=0; --i) //- Iterate across all elements in the \a container object of type // \a Container. @@ -472,8 +472,8 @@ inline void reverse(UList<T>&); #define forAllConstIter(Container,container,iter) \ for \ ( \ - Container::const_iterator iter = (container).begin(); \ - iter != (container).end(); \ + Container::const_iterator iter = (container).cbegin(); \ + iter != (container).cend(); \ ++iter \ ) diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 0e4825c79c85f578c3bfcaeedcdcce01ab316712..bd9fe339ebd7697b2924fbeee98390439615958b 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,7 +33,7 @@ template<class T> inline Foam::UList<T>::UList() : size_(0), - v_(0) + v_(nullptr) {} @@ -321,7 +321,7 @@ inline bool Foam::UList<T>::empty() const template<class T> inline void Foam::reverse(UList<T>& ul, const label n) { - for (int i=0; i<n/2; i++) + for (int i=0; i<n/2; ++i) { Swap(ul[i], ul[n-1-i]); } diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index a4648137cfc853bb1c882e96ddacfdd575ab9d20..0559a63adce6ca8d37518d09bf3359efa785881c 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -165,7 +165,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) ) ); // Check list length - label s = elems.size(); + const label s = elems.size(); if (s != L.size()) { @@ -174,14 +174,14 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) << " expected " << L.size() << exit(FatalIOError); } - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { L[i] = elems[i]; } } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read if (s != L.size()) @@ -203,7 +203,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { is >> L[i]; @@ -226,7 +226,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) "reading the single entry" ); - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { L[i] = element; } @@ -281,7 +281,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) ( typename SLList<T>::const_iterator iter = sll.begin(); iter != sll.end(); - ++iter + ++iter, ++i ) { L[i] = iter(); diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C index f1123f7519fc37981d54359bd0fa91dab0926001..5e055c1ca1cfab90240013ad3be4f0a9a77a0249 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,27 +43,35 @@ static const unsigned char base64Chars[64] = //! \endcond +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +std::size_t Foam::base64Layer::encodedLength(std::size_t n) +{ + return 4 * ((n / 3) + (n % 3 ? 1 : 0)); +} + + // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -inline unsigned char Foam::base64Layer::encode0() +inline unsigned char Foam::base64Layer::encode0() const { // Top 6 bits of char0 return base64Chars[((group_[0] & 0xFC) >> 2)]; } -inline unsigned char Foam::base64Layer::encode1() +inline unsigned char Foam::base64Layer::encode1() const { // Bottom 2 bits of char0, Top 4 bits of char1 return base64Chars[((group_[0] & 0x03) << 4) | ((group_[1] & 0xF0) >> 4)]; } -inline unsigned char Foam::base64Layer::encode2() +inline unsigned char Foam::base64Layer::encode2() const { // Bottom 4 bits of char1, Top 2 bits of char2 return base64Chars[((group_[1] & 0x0F) << 2) | ((group_[2] & 0xC0) >> 6)]; } -inline unsigned char Foam::base64Layer::encode3() +inline unsigned char Foam::base64Layer::encode3() const { // Bottom 6 bits of char2 return base64Chars[(group_[2] & 0x3F)]; diff --git a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H index 9aa4bc8d7968905e31d7e333beb59ffd737f685f..4eaaf87e83e7848975d6e870b99fc539a96a4336 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H +++ b/src/OpenFOAM/db/IOstreams/hashes/base64Layer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,7 +30,7 @@ Description Base64 encoding accoding to RFC 4648 specification (https://tools.ietf.org/html/rfc4648#page-5). It is the obligation of the caller to avoid using normal output - while the base-64 encoding layer is actively being used. + while the base-64 encoding layer is actively used. SourceFiles base64Layer.C @@ -70,10 +70,10 @@ class base64Layer // Private Member Functions - inline unsigned char encode0(); - inline unsigned char encode1(); - inline unsigned char encode2(); - inline unsigned char encode3(); + inline unsigned char encode0() const; + inline unsigned char encode1() const; + inline unsigned char encode2() const; + inline unsigned char encode3() const; //- Disallow default bitwise copy construct base64Layer(const base64Layer&) = delete; @@ -95,7 +95,7 @@ public: // Constructors //- Construct and attach to an output stream - base64Layer(std::ostream&); + base64Layer(std::ostream& os); //- Destructor @@ -104,6 +104,10 @@ public: // Member Functions + //- The encoded length has 4 bytes out for every 3 bytes in. + static std::size_t encodedLength(std::size_t n); + + //- Encode the character sequence, writing when possible. void write(const char* s, std::streamsize n); @@ -111,7 +115,7 @@ public: void reset(); //- End the encoding sequence, padding the final characters with '='. - // Return false if no encoding layer was actually used. + // Return false if no encoding was actually performed. bool close(); }; diff --git a/src/OpenFOAM/db/functionObjects/logFiles/logFiles.C b/src/OpenFOAM/db/functionObjects/logFiles/logFiles.C index a3751bc2aa1a479ce4fc96be1bca3efdfbb4b323..1281860f072d6a6a27b8c028992637693bc8d669 100644 --- a/src/OpenFOAM/db/functionObjects/logFiles/logFiles.C +++ b/src/OpenFOAM/db/functionObjects/logFiles/logFiles.C @@ -129,7 +129,7 @@ Foam::PtrList<Foam::OFstream>& Foam::functionObjects::logFiles::files() } -Foam::OFstream& Foam::functionObjects::logFiles::file(const label i) +Foam::OFstream& Foam::functionObjects::logFiles::files(const label i) { if (!Pstream::master()) { diff --git a/src/OpenFOAM/db/functionObjects/logFiles/logFiles.H b/src/OpenFOAM/db/functionObjects/logFiles/logFiles.H index fb98e6425f4ec657c251e0caba3c6bbd679452ec..2a44d38b3e3f5885ca7209f7bdb40edb03b1c31f 100644 --- a/src/OpenFOAM/db/functionObjects/logFiles/logFiles.H +++ b/src/OpenFOAM/db/functionObjects/logFiles/logFiles.H @@ -128,7 +128,7 @@ public: PtrList<OFstream>& files(); //- Return file 'i' - OFstream& file(const label i); + OFstream& files(const label i); //- Write function virtual bool write(); diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H index 09cd289b9e010aa986f551c40c2967d27a9a309c..d52304291041a1561bf2d6e805bc0ee627161de1 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H @@ -32,7 +32,7 @@ Description Note: cannot access the state dictionary until after construction of the function objects, since the owner container functionObjectList is owned by time, and time owns the state dictionary. I.e. need to wait for time - to be fully consttucted. + to be fully constructed. See also Foam::functionObject diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H index c05a1ffe4de3cb0ee3e22552de5a2b8f58fd3ab5..1f7f1edfce343457a18a0445ca3f13fc6b0ac241 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H @@ -51,7 +51,7 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjectFile Declaration + Class writeFile Declaration \*---------------------------------------------------------------------------*/ class writeFile diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index a05ab018f6916338d7236cd5f62edca49c3458ba..08da5b207a67b60e698817b7837a44936be73699 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,105 +24,62 @@ License \*---------------------------------------------------------------------------*/ #include "boundBox.H" -#include "ListOps.H" #include "PstreamReduceOps.H" #include "tmp.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::scalar Foam::boundBox::great(VGREAT); - const Foam::boundBox Foam::boundBox::greatBox ( - point(-VGREAT, -VGREAT, -VGREAT), - point(VGREAT, VGREAT, VGREAT) + point::uniform(-ROOTVGREAT), + point::uniform(ROOTVGREAT) ); - const Foam::boundBox Foam::boundBox::invertedBox ( - point(VGREAT, VGREAT, VGREAT), - point(-VGREAT, -VGREAT, -VGREAT) + point::uniform(ROOTVGREAT), + point::uniform(-ROOTVGREAT) ); - -//! \cond ignoreDocumentation -//- Skip documentation : local scope only -const Foam::label facesArray[6][4] = -{ - // point and face order as per hex cellmodel - {0, 4, 7, 3}, // x-min - {1, 2, 6, 5}, // x-max - {0, 1, 5, 4}, // y-min - {3, 7, 6, 2}, // y-max - {0, 3, 2, 1}, // z-min - {4, 5, 6, 7} // z-max -}; -//! \endcond - - const Foam::faceList Foam::boundBox::faces -( - initListList<face, label, 6, 4>(facesArray) -); +({ + // Point and face order as per hex cellmodel + face{0, 4, 7, 3}, // x-min + face{1, 2, 6, 5}, // x-max + face{0, 1, 5, 4}, // y-min + face{3, 7, 6, 2}, // y-max + face{0, 3, 2, 1}, // z-min + face{4, 5, 6, 7} // z-max +}); -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -void Foam::boundBox::calculate(const UList<point>& points, const bool doReduce) +Foam::boundBox::boundBox(const UList<point>& points, bool doReduce) +: + min_(invertedBox.min()), + max_(invertedBox.max()) { - if (points.empty()) - { - min_ = Zero; - max_ = Zero; - - if (doReduce && Pstream::parRun()) - { - // Use values that get overwritten by reduce minOp, maxOp below - min_ = point(VGREAT, VGREAT, VGREAT); - max_ = point(-VGREAT, -VGREAT, -VGREAT); - } - } - else - { - min_ = points[0]; - max_ = points[0]; - + add(points); - for (label i = 1; i < points.size(); i++) - { - min_ = ::Foam::min(min_, points[i]); - max_ = ::Foam::max(max_, points[i]); - } - } - - // Reduce parallel information if (doReduce) { - reduce(min_, minOp<point>()); - reduce(max_, maxOp<point>()); + reduce(); } } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::boundBox::boundBox(const UList<point>& points, const bool doReduce) +Foam::boundBox::boundBox(const tmp<pointField>& tpoints, bool doReduce) : - min_(Zero), - max_(Zero) + min_(invertedBox.min()), + max_(invertedBox.max()) { - calculate(points, doReduce); -} + add(tpoints); - -Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce) -: - min_(Zero), - max_(Zero) -{ - calculate(points(), doReduce); - points.clear(); + if (doReduce) + { + reduce(); + } } @@ -130,38 +87,17 @@ Foam::boundBox::boundBox ( const UList<point>& points, const labelUList& indices, - const bool doReduce + bool doReduce ) : - min_(Zero), - max_(Zero) + min_(invertedBox.min()), + max_(invertedBox.max()) { - if (points.empty() || indices.empty()) - { - if (doReduce && Pstream::parRun()) - { - // Use values that get overwritten by reduce minOp, maxOp below - min_ = point(VGREAT, VGREAT, VGREAT); - max_ = point(-VGREAT, -VGREAT, -VGREAT); - } - } - else - { - min_ = points[indices[0]]; - max_ = points[indices[0]]; + add(points, indices); - for (label i=1; i < indices.size(); ++i) - { - min_ = ::Foam::min(min_, points[indices[i]]); - max_ = ::Foam::max(max_, points[indices[i]]); - } - } - - // Reduce parallel information if (doReduce) { - reduce(min_, minOp<point>()); - reduce(max_, maxOp<point>()); + reduce(); } } @@ -170,8 +106,8 @@ Foam::boundBox::boundBox Foam::tmp<Foam::pointField> Foam::boundBox::points() const { - tmp<pointField> tPts = tmp<pointField>(new pointField(8)); - pointField& pt = tPts.ref(); + tmp<pointField> tpoints = tmp<pointField>(new pointField(8)); + pointField& pt = tpoints.ref(); pt[0] = min_; // min-x, min-y, min-z pt[1] = point(max_.x(), min_.y(), min_.z()); // max-x, min-y, min-z @@ -182,19 +118,35 @@ Foam::tmp<Foam::pointField> Foam::boundBox::points() const pt[6] = max_; // max-x, max-y, max-z pt[7] = point(min_.x(), max_.y(), max_.z()); // min-x, max-y, max-z - return tPts; + return tpoints; } void Foam::boundBox::inflate(const scalar s) { - vector ext = vector::one*s*mag(); + const vector ext = vector::one*s*mag(); min_ -= ext; max_ += ext; } +void Foam::boundBox::reduce() +{ + Foam::reduce(min_, minOp<point>()); + Foam::reduce(max_, maxOp<point>()); +} + + +bool Foam::boundBox::intersect(const boundBox& bb) +{ + min_ = ::Foam::max(min_, bb.min_); + max_ = ::Foam::min(max_, bb.max_); + + return !empty(); +} + + bool Foam::boundBox::contains(const UList<point>& points) const { if (points.empty()) diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index 940ff826c783b9eb36b1a119330cb7756d7e665a..4a8351ad84684478e6347fac0f55583335964f49 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,11 @@ Class Description A bounding box defined in terms of the points at its extremities. +Note + When a bounding box is created without any points, it creates an inverted + bounding box. Points can be added later and the bounding box will grow to + include them. + \*---------------------------------------------------------------------------*/ #ifndef boundBox_H @@ -60,26 +65,17 @@ class boundBox { // Private data - //- Minimum and maximum describing the bounding box + //- Minimum and maximum points describing the bounding box point min_, max_; - // Private Member Functions - - //- Calculate the bounding box from the given points. - // Does parallel communication (doReduce = true) - void calculate(const UList<point>&, const bool doReduce = true); - public: // Static data members - //- The great value used for greatBox and invertedBox - static const scalar great; - - //- A very large boundBox: min/max == -/+ VGREAT + //- A large boundBox: min/max == -/+ ROOTVGREAT static const boundBox greatBox; - //- A very large inverted boundBox: min/max == +/- VGREAT + //- A large inverted boundBox: min/max == +/- ROOTVGREAT static const boundBox invertedBox; //- Faces to point addressing, as per a 'hex' cell @@ -88,49 +84,58 @@ public: // Constructors - //- Construct null, setting points to zero + //- Construct without any points - an inverted bounding box inline boundBox(); + //- Construct a bounding box containing a single initial point + explicit inline boundBox(const point& pt); + //- Construct from components inline boundBox(const point& min, const point& max); //- Construct as the bounding box of the given points // Does parallel communication (doReduce = true) - boundBox(const UList<point>&, const bool doReduce = true); + explicit boundBox(const UList<point>& points, bool doReduce = true); //- Construct as the bounding box of the given temporary pointField. // Does parallel communication (doReduce = true) - boundBox(const tmp<pointField>&, const bool doReduce = true); + explicit boundBox(const tmp<pointField>& tpoints, bool doReduce = true); - //- Construct bounding box as subset of the pointField. + //- Construct bounding box as an indirect subset of the points. // The indices could be from cell/face etc. // Does parallel communication (doReduce = true) boundBox ( - const UList<point>&, + const UList<point>& points, const labelUList& indices, - const bool doReduce = true + bool doReduce = true ); - //- Construct bounding box as subset of the pointField. + //- Construct bounding box as an indirect subset of the points. // The indices could be from edge/triFace etc. // Does parallel communication (doReduce = true) template<unsigned Size> boundBox ( - const UList<point>&, + const UList<point>& points, const FixedList<label, Size>& indices, - const bool doReduce = true + bool doReduce = true ); //- Construct from Istream - inline boundBox(Istream&); + inline boundBox(Istream& is); // Member functions // Access + //- Bounding box is inverted, contains no points. + inline bool empty() const; + + //- Clear bounding box of all points - make it an inverted box + inline void clear(); + //- Minimum describing the bounding box inline const point& min() const; @@ -170,80 +175,130 @@ public: // Manipulate + //- Extend to include the second box. + inline void add(const boundBox& bb); + + //- Extend to include the point. + inline void add(const point& pt); + + //- Extend to include the points. + inline void add(const UList<point>& points); + + //- Extend to include the points from the temporary point field. + inline void add(const tmp<pointField>& tpoints); + + //- Extend to include the subset of the point field. + // The indices could be from cell/face etc. + inline void add + ( + const UList<point>& points, + const labelUList& indices + ); + + //- Extend to include the points. + template<unsigned Size> + void add(const FixedList<point, Size>& points); + + //- Extend to include the subset of the point field. + // The indices could be from edge/triFace etc. + template<unsigned Size> + void add + ( + const UList<point>& points, + const FixedList<label, Size>& indices + ); + //- Inflate box by factor*mag(span) in all dimensions void inflate(const scalar s); + //- Parallel reduction of min/max values + void reduce(); + + //- Intersection (union) with the second box. + // The return value is true if the intersection is non-empty. + bool intersect(const boundBox& bb); + // Query //- Overlaps/touches boundingBox? - inline bool overlaps(const boundBox&) const; + inline bool overlaps(const boundBox& bb) const; //- Overlaps boundingSphere (centre + sqr(radius))? - inline bool overlaps(const point&, const scalar radiusSqr) const; + inline bool overlaps + ( + const point& centre, + const scalar radiusSqr + ) const; //- Contains point? (inside or on edge) - inline bool contains(const point&) const; + inline bool contains(const point& pt) const; //- Fully contains other boundingBox? - inline bool contains(const boundBox&) const; + inline bool contains(const boundBox& bb) const; //- Contains point? (inside only) - inline bool containsInside(const point&) const; + inline bool containsInside(const point& pt) const; //- Contains all of the points? (inside or on edge) - bool contains(const UList<point>&) const; + bool contains(const UList<point>& points) const; - //- Contains all of the points? (inside or on edge) + //- Contains all of the subset of points? (inside or on edge) bool contains ( - const UList<point>&, + const UList<point>& points, const labelUList& indices ) const; - //- Contains all of the points? (inside or on edge) + //- Contains all of the subset of points? (inside or on edge) template<unsigned Size> bool contains ( - const UList<point>&, + const UList<point>& points, const FixedList<label, Size>& indices ) const; //- Contains any of the points? (inside or on edge) - bool containsAny(const UList<point>&) const; + bool containsAny(const UList<point>& points) const; - //- Contains any of the points? (inside or on edge) + //- Contains any of the subset of points? (inside or on edge) bool containsAny ( - const UList<point>&, + const UList<point>& points, const labelUList& indices ) const; - //- Contains any of the points? (inside or on edge) + //- Contains any of the subset of points? (inside or on edge) template<unsigned Size> bool containsAny ( - const UList<point>&, + const UList<point>& points, const FixedList<label, Size>& indices ) const; //- Return the nearest point on the boundBox to the supplied point. // If point is inside the boundBox then the point is returned // unchanged. - point nearest(const point&) const; + point nearest(const point& pt) const; + + + // Member Operators + + //- Extend box to include the second box, as per the add() method. + inline void operator+=(const boundBox& bb); // Friend Operators - inline friend bool operator==(const boundBox&, const boundBox&); - inline friend bool operator!=(const boundBox&, const boundBox&); + inline friend bool operator==(const boundBox& a, const boundBox& b); + inline friend bool operator!=(const boundBox& a, const boundBox& b); // IOstream operator - friend Istream& operator>>(Istream&, boundBox&); - friend Ostream& operator<<(Ostream&, const boundBox&); + friend Istream& operator>>(Istream& is, boundBox& bb); + friend Ostream& operator<<(Ostream& os, const boundBox& bb); }; diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxI.H b/src/OpenFOAM/meshes/boundBox/boundBoxI.H index 13af23e99cd3d4397c4de1d780f61696f05f46ff..c6e668e41dafb18a62a25a7d08b62c4794c2baf7 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBoxI.H +++ b/src/OpenFOAM/meshes/boundBox/boundBoxI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,15 +24,21 @@ License \*---------------------------------------------------------------------------*/ #include "boundBox.H" -#include "pointField.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::boundBox::boundBox() : - min_(Zero), - max_(Zero) + min_(invertedBox.min()), + max_(invertedBox.max()) +{} + + +inline Foam::boundBox::boundBox(const point& pt) +: + min_(pt), + max_(pt) {} @@ -51,6 +57,19 @@ inline Foam::boundBox::boundBox(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +inline bool Foam::boundBox::empty() const +{ + return (min_ > max_); +} + + +inline void Foam::boundBox::clear() +{ + min_ = invertedBox.min(); + max_ = invertedBox.max(); +} + + inline const Foam::point& Foam::boundBox::min() const { return min_; @@ -117,6 +136,52 @@ inline Foam::scalar Foam::boundBox::avgDim() const } +inline void Foam::boundBox::add(const boundBox& bb) +{ + min_ = ::Foam::min(min_, bb.min_); + max_ = ::Foam::max(max_, bb.max_); +} + + +inline void Foam::boundBox::add(const point& pt) +{ + min_ = ::Foam::min(min_, pt); + max_ = ::Foam::max(max_, pt); +} + + +inline void Foam::boundBox::add(const UList<point>& points) +{ + forAll(points, i) + { + add(points[i]); + } +} + + +inline void Foam::boundBox::add(const tmp<pointField>& tpoints) +{ + add(tpoints()); + tpoints.clear(); +} + + +inline void Foam::boundBox::add +( + const UList<point>& points, + const labelUList& indices +) +{ + if (!points.empty()) + { + forAll(indices, i) + { + add(points[indices[i]]); + } + } +} + + inline bool Foam::boundBox::overlaps(const boundBox& bb) const { return @@ -138,7 +203,7 @@ inline bool Foam::boundBox::overlaps // Find nearest point on bb. scalar distSqr = 0; - for (direction dir = 0; dir < vector::nComponents; dir++) + for (direction dir = 0; dir < vector::nComponents; ++dir) { scalar d0 = min_[dir] - centre[dir]; scalar d1 = max_[dir] - centre[dir]; @@ -178,7 +243,6 @@ inline bool Foam::boundBox::contains(const point& pt) const } -// this.bb fully contains bb inline bool Foam::boundBox::contains(const boundBox& bb) const { return contains(bb.min()) && contains(bb.max()); @@ -196,6 +260,14 @@ inline bool Foam::boundBox::containsInside(const point& pt) const } +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +inline void Foam::boundBox::operator+=(const boundBox& bb) +{ + add(bb); +} + + // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // inline bool Foam::operator==(const boundBox& a, const boundBox& b) diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C index 81aa3f267b218d67e990ce6f0c4838079b14e27e..502d89ad5eeb4ae05073ea589f61fed36e634d59 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C +++ b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,8 +25,6 @@ License #include "boundBox.H" #include "FixedList.H" -#include "PstreamReduceOps.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -35,44 +33,54 @@ Foam::boundBox::boundBox ( const UList<point>& points, const FixedList<label, Size>& indices, - const bool doReduce + bool doReduce ) : - min_(Zero), - max_(Zero) + min_(invertedBox.min()), + max_(invertedBox.max()) { - // a FixedList is never empty - if (points.empty()) + add(points, indices); + + if (doReduce) { - if (doReduce && Pstream::parRun()) - { - // Use values that get overwritten by reduce minOp, maxOp below - min_ = point(VGREAT, VGREAT, VGREAT); - max_ = point(-VGREAT, -VGREAT, -VGREAT); - } + reduce(); } - else - { - min_ = points[indices[0]]; - max_ = points[indices[0]]; +} - for (unsigned i=1; i < Size; ++i) - { - min_ = ::Foam::min(min_, points[indices[i]]); - max_ = ::Foam::max(max_, points[indices[i]]); - } - } - // Reduce parallel information - if (doReduce) +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template<unsigned Size> +void Foam::boundBox::add +( + const FixedList<point, Size>& points +) +{ + // a FixedList is never empty + for (unsigned i=0; i < Size; ++i) { - reduce(min_, minOp<point>()); - reduce(max_, maxOp<point>()); + add(points[i]); } } -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +template<unsigned Size> +void Foam::boundBox::add +( + const UList<point>& points, + const FixedList<label, Size>& indices +) +{ + // points may be empty, but a FixedList is never empty + if (!points.empty()) + { + for (unsigned i=0; i < Size; ++i) + { + add(points[indices[i]]); + } + } +} + template<unsigned Size> bool Foam::boundBox::contains @@ -81,7 +89,7 @@ bool Foam::boundBox::contains const FixedList<label, Size>& indices ) const { - // a FixedList is never empty + // points may be empty, but a FixedList is never empty if (points.empty()) { return false; @@ -106,7 +114,7 @@ bool Foam::boundBox::containsAny const FixedList<label, Size>& indices ) const { - // a FixedList is never empty + // points may be empty, but a FixedList is never empty if (points.empty()) { return false; diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C index d621df5ca39a919d8036466f4c4bdd9376475dc4..66fde47413d3e4d90256df4c893514b481dff35e 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsSearch.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -236,9 +236,8 @@ void Foam::PatchTools::calcBounds label pointi = f[fp]; if (pointIsUsed.set(pointi, 1u)) { - bb.min() = ::Foam::min(bb.min(), points[pointi]); - bb.max() = ::Foam::max(bb.max(), points[pointi]); - nPoints++; + bb.add(points[pointi]); + ++nPoints; } } } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C index 31ce6616fd45dc58b5bd6ef3a2e17551a5e4af71..c26745d96fffa7cdd5e6e85574095a7a3516e3d9 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,8 +48,7 @@ bool Foam::primitiveMesh::pointInCellBB if (inflationFraction > SMALL) { - vector inflation = inflationFraction*vector::one*mag(bb.span()); - bb = boundBox(bb.min() - inflation, bb.max() + inflation); + bb.inflate(inflationFraction); } return bb.contains(p); diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H index cb42d33d4b149ac912233fbf2f5cec479f8b9d25..8ac906ca62072f5bf373f52d124dad126a75a3cf 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H +++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -92,11 +92,10 @@ public: //- Calculate the bounding box inline treeBoundBox bounds() const { - treeBoundBox bb(operator[](0), operator[](0)); - for (label i = 1; i < size(); i++) + treeBoundBox bb(operator[](0)); + for (label i = 1; i < size(); ++i) { - bb.min() = min(bb.min(), operator[](i)); - bb.max() = max(bb.max(), operator[](i)); + bb.add(operator[](i)); } return bb; } diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triPoints.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triPoints.H index 67c7efb90247a96bb257811bb745023e73a4b00a..7f1dc8d42a7d45918ea071abe3660c91c9b7848b 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triPoints.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triPoints.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,11 +78,10 @@ public: //- Calculate the bounding box inline treeBoundBox bounds() const { - treeBoundBox bb(operator[](0), operator[](0)); - for (label i = 1; i < size(); i++) + treeBoundBox bb(operator[](0)); + for (label i = 1; i < size(); ++i) { - bb.min() = min(bb.min(), operator[](i)); - bb.max() = max(bb.max(), operator[](i)); + bb.add(operator[](i)); } return bb; } diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C index cd804fcf94a132b206a206575b65e13cdffe02c0..462c318755e603b05282db2e6829a5e63d60ac6b 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,50 +24,21 @@ License \*---------------------------------------------------------------------------*/ #include "treeBoundBox.H" -#include "ListOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::scalar Foam::treeBoundBox::great(GREAT); - -const Foam::treeBoundBox Foam::treeBoundBox::greatBox -( - vector(-GREAT, -GREAT, -GREAT), - vector(GREAT, GREAT, GREAT) -); - - -const Foam::treeBoundBox Foam::treeBoundBox::invertedBox -( - vector(GREAT, GREAT, GREAT), - vector(-GREAT, -GREAT, -GREAT) -); - - -//! \cond ignoreDocumentation -//- Skip documentation : local scope only -const Foam::label facesArray[6][4] = -{ - {0, 4, 6, 2}, // left - {1, 3, 7, 5}, // right - {0, 1, 5, 4}, // bottom - {2, 6, 7, 3}, // top - {0, 2, 3, 1}, // back - {4, 5, 7, 6} // front -}; -//! \endcond - - const Foam::faceList Foam::treeBoundBox::faces -( - initListList<face, label, 6, 4>(facesArray) -); - +({ + face{0, 4, 6, 2}, // left + face{1, 3, 7, 5}, // right + face{0, 1, 5, 4}, // bottom + face{2, 6, 7, 3}, // top + face{0, 2, 3, 1}, // back + face{4, 5, 7, 6} // front +}); -//! \cond ignoreDocumentation -//- Skip documentation : local scope only -const Foam::label edgesArray[12][2] = -{ +const Foam::edgeList Foam::treeBoundBox::edges +({ {0, 1}, // 0 {1, 3}, {2, 3}, // 2 @@ -80,48 +51,17 @@ const Foam::label edgesArray[12][2] = {1, 5}, {3, 7}, // 10 {2, 6} -}; -//! \endcond - - -const Foam::edgeList Foam::treeBoundBox::edges -( - //initListList<edge, label, 12, 2>(edgesArray) - calcEdges(edgesArray) -); - +}); const Foam::FixedList<Foam::vector, 6> Foam::treeBoundBox::faceNormals -( - calcFaceNormals() -); - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -Foam::edgeList Foam::treeBoundBox::calcEdges(const label edgesArray[12][2]) -{ - edgeList edges(12); - forAll(edges, edgeI) - { - edges[edgeI][0] = edgesArray[edgeI][0]; - edges[edgeI][1] = edgesArray[edgeI][1]; - } - return edges; -} - - -Foam::FixedList<Foam::vector, 6> Foam::treeBoundBox::calcFaceNormals() -{ - FixedList<vector, 6> normals; - normals[LEFT] = vector(-1, 0, 0); - normals[RIGHT] = vector( 1, 0, 0); - normals[BOTTOM] = vector( 0, -1, 0); - normals[TOP] = vector( 0, 1, 0); - normals[BACK] = vector( 0, 0, -1); - normals[FRONT] = vector( 0, 0, 1); - return normals; -} +({ + vector(-1, 0, 0), // left + vector( 1, 0, 0), // right + vector( 0, -1, 0), // bottom + vector( 0, 1, 0), // top + vector( 0, 0, -1), // back + vector( 0, 0, 1) // front +}); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -164,15 +104,15 @@ Foam::treeBoundBox::treeBoundBox Foam::tmp<Foam::pointField> Foam::treeBoundBox::points() const { - tmp<pointField> tPts = tmp<pointField>(new pointField(8)); - pointField& points = tPts.ref(); + tmp<pointField> tpoints = tmp<pointField>(new pointField(8)); + pointField& pts = tpoints.ref(); - forAll(points, octant) + forAll(pts, octant) { - points[octant] = corner(octant); + pts[octant] = corner(octant); } - return tPts; + return tpoints; } @@ -394,7 +334,7 @@ bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const { // Compare all components against min and max of bb - for (direction cmpt=0; cmpt<3; cmpt++) + for (direction cmpt=0; cmpt<3; ++cmpt) { if (pt[cmpt] < min()[cmpt]) { diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H index 7632b15fa126933b53b6b66d11e245ffae1a8fdd..edc42983dfe38ad412d7954b29b6e6627a0690f9 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,6 +46,10 @@ Description For the front plane add 4 to the point labels. +Note + When a bounding box is created without any points, it creates an inverted + bounding box. Points can be added later and the bounding box will grow to + include them. SourceFiles treeBoundBoxI.H @@ -74,11 +78,11 @@ class Random; class treeBoundBox; -bool operator==(const treeBoundBox&, const treeBoundBox&); -bool operator!=(const treeBoundBox&, const treeBoundBox&); +bool operator==(const treeBoundBox& a, const treeBoundBox& b); +bool operator!=(const treeBoundBox& a, const treeBoundBox& b); -Istream& operator>>(Istream& is, treeBoundBox&); -Ostream& operator<<(Ostream& os, const treeBoundBox&); +Istream& operator>>(Istream& is, treeBoundBox& bb); +Ostream& operator<<(Ostream& os, const treeBoundBox& bb); /*---------------------------------------------------------------------------*\ @@ -90,27 +94,10 @@ class treeBoundBox public boundBox { -private: - - //- To initialise edges. - static edgeList calcEdges(const label[12][2]); - - //- To initialise faceNormals. - static FixedList<vector, 6> calcFaceNormals(); - public: // Static data members - //- The great value used for greatBox and invertedBox - static const scalar great; - - //- As per boundBox::greatBox, but with GREAT instead of VGREAT - static const treeBoundBox greatBox; - - //- As per boundBox::invertedBox, but with GREAT instead of VGREAT - static const treeBoundBox invertedBox; - //- Bits used for octant/point coding. // Every octant/corner point is the combination of three faces. enum octantBit @@ -169,7 +156,7 @@ public: //- Edge to point addressing static const edgeList edges; - //- Per face the unit normal + //- The unit normal per face static const FixedList<vector, 6> faceNormals; @@ -181,16 +168,19 @@ public: //- Construct from a boundBox explicit inline treeBoundBox(const boundBox& bb); + //- Construct a bounding box containing a single initial point + explicit inline treeBoundBox(const point& pt); + //- Construct from components inline treeBoundBox(const point& min, const point& max); //- Construct as the bounding box of the given pointField. // Local processor domain only (no reduce as in boundBox) - explicit treeBoundBox(const UList<point>&); + explicit treeBoundBox(const UList<point>& points); //- Construct as subset of points // Local processor domain only (no reduce as in boundBox) - treeBoundBox(const UList<point>&, const labelUList& indices); + treeBoundBox(const UList<point>& points, const labelUList& indices); //- Construct as subset of points // The indices could be from edge/triFace etc. @@ -198,13 +188,13 @@ public: template<unsigned Size> treeBoundBox ( - const UList<point>&, + const UList<point>& points, const FixedList<label, Size>& indices ); //- Construct from Istream - inline treeBoundBox(Istream&); + inline treeBoundBox(Istream& is); // Member functions @@ -220,13 +210,13 @@ public: // Check - //- Corner point given octant - inline point corner(const direction) const; + //- Corner point of given octant + inline point corner(const direction octant) const; - //- Sub box given by octant number. Midpoint calculated. - treeBoundBox subBbox(const direction) const; + //- Sub-box of given octant. Midpoint calculated. + treeBoundBox subBbox(const direction octant) const; - //- Sub box given by octant number. Midpoint provided. + //- Sub-box given by octant number. Midpoint provided. treeBoundBox subBbox(const point& mid, const direction) const; //- Returns octant number given point and the calculated midpoint. @@ -318,10 +308,10 @@ public: bool contains(const vector& dir, const point&) const; //- Code position of point on bounding box faces - direction faceBits(const point&) const; + direction faceBits(const point& pt) const; //- Position of point relative to bounding box - direction posBits(const point&) const; + direction posBits(const point& pt) const; //- Calculate nearest and furthest (to point) vertex coords of // bounding box @@ -333,7 +323,7 @@ public: ) const; //- Returns distance point to furthest away corner. - scalar maxDist(const point&) const; + scalar maxDist(const point& pt) const; //- Compare distance to point with other bounding box // return: @@ -342,22 +332,24 @@ public: // +1 : all vertices of my bounding box are further away than // any of other // 0 : none of the above. - label distanceCmp(const point&, const treeBoundBox& other) const; + label distanceCmp(const point& pt, const treeBoundBox& other) const; //- Return slightly wider bounding box // Extends all dimensions with s*span*Random::scalar01() // and guarantees in any direction s*mag(span) minimum width - inline treeBoundBox extend(Random&, const scalar s) const; + inline treeBoundBox extend(Random& rndGen, const scalar s) const; + // Friend Operators - friend bool operator==(const treeBoundBox&, const treeBoundBox&); - friend bool operator!=(const treeBoundBox&, const treeBoundBox&); + friend bool operator==(const treeBoundBox& a, const treeBoundBox& b); + friend bool operator!=(const treeBoundBox& a, const treeBoundBox& b); + // IOstream operator - friend Istream& operator>>(Istream& is, treeBoundBox&); - friend Ostream& operator<<(Ostream& os, const treeBoundBox&); + friend Istream& operator>>(Istream& is, treeBoundBox& bb); + friend Ostream& operator<<(Ostream& os, const treeBoundBox& bb); }; diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H index 3480eac00db0a16f3dcc444e1d7a64db774d3854..4b073fd9753a40a397b8ca5258724e27d425f524 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,15 +34,21 @@ inline Foam::treeBoundBox::treeBoundBox() {} -inline Foam::treeBoundBox::treeBoundBox(const point& min, const point& max) +inline Foam::treeBoundBox::treeBoundBox(const boundBox& bb) : - boundBox(min, max) + boundBox(bb) {} -inline Foam::treeBoundBox::treeBoundBox(const boundBox& bb) +inline Foam::treeBoundBox::treeBoundBox(const point& pt) : - boundBox(bb) + boundBox(pt) +{} + + +inline Foam::treeBoundBox::treeBoundBox(const point& min, const point& max) +: + boundBox(min, max) {} @@ -312,7 +318,6 @@ inline void Foam::treeBoundBox::searchOrder } -//- Return slightly wider bounding box inline Foam::treeBoundBox Foam::treeBoundBox::extend ( Random& rndGen, @@ -326,7 +331,7 @@ inline Foam::treeBoundBox Foam::treeBoundBox::extend // Make 3D scalar minSpan = s * Foam::mag(newSpan); - for (direction dir = 0; dir < vector::nComponents; dir++) + for (direction dir = 0; dir < vector::nComponents; ++dir) { newSpan[dir] = Foam::max(newSpan[dir], minSpan); } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C index 11aacf25cb5cb7ea82b6f8b22626506760adb346..2bf9810f6c6178bef8f2972c1a99e9a2d80aa9bf 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,8 +29,6 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::labelRange::const_iterator Foam::labelRange::endIter_; - int Foam::labelRange::debug(::Foam::debug::debugSwitch("labelRange", 0)); @@ -47,13 +45,24 @@ Foam::labelRange::labelRange(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::labelRange::intersects -( - const labelRange& range, - const bool touches -) const +void Foam::labelRange::adjust() +{ + if (start_ < 0) + { + size_ += start_; + start_ = 0; + } + + if (size_ < 0) + { + size_ = 0; + } +} + + +bool Foam::labelRange::overlaps(const labelRange& range, bool touches) const { - label final = touches ? 1 : 0; + const label final = touches ? 1 : 0; return ( @@ -97,7 +106,7 @@ Foam::labelRange Foam::labelRange::join(const labelRange& range) const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) +void Foam::labelRange::operator+=(const labelRange& rhs) { if (!size_) { @@ -112,8 +121,6 @@ Foam::labelRange& Foam::labelRange::operator+=(const labelRange& rhs) start_ = lower; size_ = upper - lower + 1; } - - return *this; } @@ -127,10 +134,10 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) is.check("operator>>(Istream&, labelRange&)"); - // disallow invalid sizes - if (range.size_ <= 0) + // Disallow invalid sizes + if (range.size_ < 0) { - range.clear(); + range.size_ = 0; } return is; @@ -139,15 +146,11 @@ Foam::Istream& Foam::operator>>(Istream& is, labelRange& range) Foam::Ostream& Foam::operator<<(Ostream& os, const labelRange& range) { - // write ASCII only for now + // Write ASCII only for now os << token::BEGIN_LIST << range.start_ << token::SPACE << range.size_ << token::END_LIST; -// os << token::BEGIN_BLOCK -// << range.start_ << "-" << range.last() -// << token::END_BLOCK; - os.check("operator<<(Ostream&, const labelRange&)"); return os; } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H index 24dd33729cb1544845fccb6f1f0079c741dd4c24..3fa69c4ff379f367cedb3848ee395fb642069b9b 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRange.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::labelRange Description - A label range specifier. + A range of labels. SourceFiles labelRange.C @@ -47,8 +47,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRange; -Istream& operator>>(Istream&, labelRange&); -Ostream& operator<<(Ostream&, const labelRange&); +Istream& operator>>(Istream& is, labelRange& range); +Ostream& operator<<(Ostream& os, const labelRange& range); /*---------------------------------------------------------------------------*\ Class labelRange Declaration @@ -63,7 +63,7 @@ class labelRange public: - static int debug; + static int debug; // Public classes @@ -75,31 +75,50 @@ public: bool operator()(const labelRange& a, const labelRange& b) { - return a.first() < b.first(); + return a.operator<(b); } }; + // Constructors - //- Construct an empty range + //- Construct an empty range with zero as start and size. inline labelRange(); - //- Construct a range - // A negative size is autmatically changed to zero. - inline labelRange(const label start, const label size); + //- Construct a range from start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + inline labelRange + ( + const label start, + const label size, + const bool adjustStart = false + ); //- Construct from Istream. - labelRange(Istream&); + labelRange(Istream& is); // Member Functions - //- Reset to zero size + //- Alias for setSize(const label) + inline void resize(const label n); + + //- Adjust size + inline void setSize(const label n); + + //- Reset to zero start and zero size inline void clear(); //- Is the range empty? inline bool empty() const; + //- Adjust the start to avoid any negative indices + void adjust(); + + //- Is the range valid (non-empty)? + inline bool valid() const; + //- Return the effective size of the range inline label size() const; @@ -109,32 +128,44 @@ public: //- The (inclusive) upper value of the range inline label last() const; + //- Reset start and size. + // Optionally adjust the start to avoid any negative indices. + // Always reduce a negative size to zero. + // Return true if the updated range valid (non-empty). + inline bool reset + ( + const label start, + const label size, + const bool adjustStart = false + ); + //- Return true if the value is within the range - inline bool contains(const label) const; + inline bool contains(const label value) const; - //- Return true if the ranges intersect + //- Return true if the ranges overlap. // Optional test for ranges that also just touch each other - bool intersects(const labelRange&, const bool touches = false) const; + bool overlaps(const labelRange& range, bool touches=false) const; //- Return a joined range, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange join(const labelRange&) const; + // A prior overlaps() check can be used to avoid squashing gaps. + labelRange join(const labelRange& range) const; // Member Operators //- Return element in range, no bounds checking - inline label operator[](const label) const; + inline label operator[](const label i) const; - //- Comparison function for sorting, compares the start + //- Comparison function for sorting, compares the start. + // If the start values are equal, also compares the size. inline bool operator<(const labelRange& rhs) const; //- Join ranges, squashing any gaps in between - // A prior intersects() check can be used to avoid squashing gaps. - labelRange& operator+=(const labelRange&); + // A prior overlaps() check can be used to avoid squashing gaps. + void operator+=(const labelRange& rhs); - inline bool operator==(const labelRange&) const; - inline bool operator!=(const labelRange&) const; + inline bool operator==(const labelRange& rhs) const; + inline bool operator!=(const labelRange& rhs) const; // STL iterator @@ -142,6 +173,8 @@ public: //- An STL const_iterator class const_iterator { + friend class labelRange; + // Private data //- Reference to the range for which this is an iterator @@ -150,54 +183,48 @@ public: //- Current index label index_; - public: // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from range, moving to its 'begin' position - inline explicit const_iterator(const labelRange&); + //- Construct from range at 'begin' or 'end' position + inline const_iterator + ( + const labelRange& range, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; - - inline bool operator!=(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; - inline label operator*(); - inline label operator()(); + inline label operator*() const; + inline label operator()() const; inline const_iterator& operator++(); inline const_iterator operator++(int); }; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the range + //- A const_iterator set to the beginning of the range inline const_iterator begin() const; - //- const_iterator set to beyond the end of the range - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the range + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRange&); - friend Ostream& operator<<(Ostream&, const labelRange&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRange& range); + friend Ostream& operator<<(Ostream& os, const labelRange& range); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H index 21e839cf3cc44431fc3113fabb3cc413db155a74..927a6f57a083bdd1d1b8ac2b44d61a05d003c9d7 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangeI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,32 +33,39 @@ inline Foam::labelRange::labelRange() {} -inline Foam::labelRange::labelRange(const label start, const label size) +inline Foam::labelRange::labelRange +( + const label start, + const label size, + const bool adjustStart +) : start_(start), size_(size) { - // disallow invalid sizes - if (size_ <= 0) + if (adjustStart) + { + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) { - this->clear(); + // Disallow invalid sizes + size_ = 0; } } // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRange::const_iterator::const_iterator() -: - range_(*reinterpret_cast<Foam::labelRange* >(0)), - index_(-1) -{} - - -inline Foam::labelRange::const_iterator::const_iterator(const labelRange& range) +inline Foam::labelRange::const_iterator::const_iterator +( + const labelRange& range, + const bool endIter +) : range_(range), - index_(range_.empty() ? -1 : 0) + index_(endIter ? range_.size() : 0) {} @@ -76,17 +83,17 @@ inline bool Foam::labelRange::const_iterator::operator!= const const_iterator& iter ) const { - return !(this->operator==(iter)); + return (this->index_ != iter.index_); } -inline Foam::label Foam::labelRange::const_iterator::operator*() +inline Foam::label Foam::labelRange::const_iterator::operator*() const { return range_[index_]; } -inline Foam::label Foam::labelRange::const_iterator::operator()() +inline Foam::label Foam::labelRange::const_iterator::operator()() const { return range_[index_]; } @@ -95,12 +102,7 @@ inline Foam::label Foam::labelRange::const_iterator::operator()() inline Foam::labelRange::const_iterator& Foam::labelRange::const_iterator::operator++() { - if (++index_ >= range_.size()) - { - // equivalent to end iterator - index_ = -1; - } - + ++index_; return *this; } @@ -109,7 +111,7 @@ inline Foam::labelRange::const_iterator Foam::labelRange::const_iterator::operator++(int) { const_iterator old = *this; - this->operator++(); + ++index_; return old; } @@ -120,9 +122,9 @@ inline Foam::labelRange::const_iterator Foam::labelRange::cbegin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::cend() const +inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -132,14 +134,31 @@ inline Foam::labelRange::const_iterator Foam::labelRange::begin() const } -inline const Foam::labelRange::const_iterator& Foam::labelRange::end() const +inline const Foam::labelRange::const_iterator Foam::labelRange::end() const { - return endIter_; + return const_iterator(*this, true); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +inline void Foam::labelRange::resize(const label n) +{ + setSize(n); +} + + +inline void Foam::labelRange::setSize(const label n) +{ + size_ = n; + + if (size_ < 0) + { + size_ = 0; + } +} + + inline void Foam::labelRange::clear() { start_ = size_ = 0; @@ -152,6 +171,12 @@ inline bool Foam::labelRange::empty() const } +inline bool Foam::labelRange::valid() const +{ + return size_; +} + + inline Foam::label Foam::labelRange::size() const { return size_; @@ -170,6 +195,31 @@ inline Foam::label Foam::labelRange::last() const } +inline bool Foam::labelRange::reset +( + const label start, + const label size, + const bool adjustStart +) +{ + start_ = start; + size_ = size; + + if (adjustStart) + { + // Disallow invalid indices and sizes + adjust(); + } + else if (size_ < 0) + { + // Disallow invalid sizes + size_ = 0; + } + + return size_; +} + + inline bool Foam::labelRange::contains(const label value) const { return value >= this->first() && value <= this->last(); @@ -186,7 +236,11 @@ inline Foam::label Foam::labelRange::operator[](const label i) const inline bool Foam::labelRange::operator<(const labelRange& rhs) const { - return this->first() < rhs.first(); + return + ( + this->first() < rhs.first() + || (this->first() == rhs.first() && this->size() < rhs.size()) + ); } diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C index 101c2bce983c4acdd6d62568f300fe7e6295e89f..d9edff0e47abf2f07c347bbd74666ccb63beed19 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,11 +26,6 @@ License #include "labelRanges.H" #include "ListOps.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const Foam::labelRanges::const_iterator Foam::labelRanges::endIter_; - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::labelRanges::insertBefore @@ -141,7 +136,7 @@ bool Foam::labelRanges::add(const labelRange& range) { labelRange& currRange = ParentType::operator[](elemI); - if (currRange.intersects(range, true)) + if (currRange.overlaps(range, true)) { // absorb into the existing (adjacent/overlapping) range currRange += range; @@ -150,7 +145,7 @@ bool Foam::labelRanges::add(const labelRange& range) for (; elemI < this->size()-1; ++elemI) { labelRange& nextRange = ParentType::operator[](elemI+1); - if (currRange.intersects(nextRange, true)) + if (currRange.overlaps(nextRange, true)) { currRange += nextRange; nextRange.clear(); diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H index 6fa10b0aac58733e9f2c48bf74d3ce56fc7baca3..134acb048202aeff4d10db35b7ee02ab792c3447 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRanges.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,8 +49,8 @@ class Ostream; // Forward declaration of friend functions and operators class labelRanges; -Istream& operator>>(Istream&, labelRanges&); -Ostream& operator<<(Ostream&, const labelRanges&); +Istream& operator>>(Istream& is, labelRanges& ranges); +Ostream& operator<<(Ostream& is, const labelRanges& ranges); /*---------------------------------------------------------------------------*\ Class labelRanges Declaration @@ -68,13 +68,13 @@ class labelRanges // Private Member Functions //- Insert range before specified insertion index, by copying up - void insertBefore(const label, const labelRange&); + void insertBefore(const label insert, const labelRange& range); //- Purge empty ranges, by copying down void purgeEmpty(); //- Print the range for debugging purposes - Ostream& printRange(Ostream&, const labelRange&) const; + Ostream& printRange(Ostream& os, const labelRange& range) const; public: @@ -85,10 +85,10 @@ public: inline labelRanges(); //- Construct given size - inline explicit labelRanges(const label); + inline explicit labelRanges(const label nElem); //- Construct from Istream. - labelRanges(Istream&); + labelRanges(Istream& is); // Member Functions @@ -100,19 +100,22 @@ public: using DynamicList<labelRange>::empty; //- Return true if the value is within any of the ranges - inline bool contains(const label) const; + inline bool contains(const label value) const; //- Add the range to the list - bool add(const labelRange&); + bool add(const labelRange& range); //- Remove the range from the list - bool remove(const labelRange&); + bool remove(const labelRange& range); + // STL iterator //- An STL const_iterator class const_iterator { + friend class labelRanges; + // Private data //- Reference to the list for which this is an iterator @@ -124,22 +127,21 @@ public: //- Index of current element at listIndex label subIndex_; - public: - // Constructors - //- Construct null - equivalent to an 'end' position - inline const_iterator(); - - //- Construct from list, moving to its 'begin' position - inline explicit const_iterator(const labelRanges&); + //- Construct from ranges at 'begin' or 'end' position + inline const_iterator + ( + const labelRanges& lst, + const bool endIter = false + ); + public: // Member operators - inline bool operator==(const const_iterator&) const; - - inline bool operator!=(const const_iterator&) const; + inline bool operator==(const const_iterator& iter) const; + inline bool operator!=(const const_iterator& iter) const; inline label operator*(); inline label operator()(); @@ -149,29 +151,23 @@ public: }; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator cbegin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& cend() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator cend() const; - //- const_iterator set to the beginning of the list + //- A const_iterator set to the beginning of the list inline const_iterator begin() const; - //- const_iterator set to beyond the end of the list - inline const const_iterator& end() const; + //- A const_iterator set to beyond the end of the list + inline const const_iterator end() const; // IOstream Operators - friend Istream& operator>>(Istream&, labelRanges&); - friend Ostream& operator<<(Ostream&, const labelRanges&); - - -private: - - //- const_iterator returned by end(), cend() - static const const_iterator endIter_; + friend Istream& operator>>(Istream& is, labelRanges& ranges); + friend Ostream& operator<<(Ostream& os, const labelRanges& ranges); }; diff --git a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H index 739d582e9fe39073e963b4aae45a977136b1b73a..9ccad0e300c20cf75dabaf922bdced742ada7374 100644 --- a/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H +++ b/src/OpenFOAM/primitives/ranges/labelRange/labelRangesI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,28 +40,18 @@ inline Foam::labelRanges::labelRanges(const label nElem) // * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * // -inline Foam::labelRanges::const_iterator::const_iterator() +inline Foam::labelRanges::const_iterator::const_iterator +( + const labelRanges& lst, + const bool endIter +) : - list_(*reinterpret_cast<Foam::labelRanges* >(0)), - index_(-1), - subIndex_(-1) + list_(lst), + index_(endIter ? lst.size() : 0), + subIndex_(0) {} -inline Foam::labelRanges::const_iterator::const_iterator(const labelRanges& lst) -: - list_(lst), - index_(0), - subIndex_(0) -{ - if (list_.empty()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } -} - - inline bool Foam::labelRanges::const_iterator::operator== ( const const_iterator& iter @@ -69,7 +59,7 @@ inline bool Foam::labelRanges::const_iterator::operator== { return ( - this->index_ == iter.index_ + this->index_ == iter.index_ && this->subIndex_ == iter.subIndex_ ); } @@ -101,13 +91,9 @@ Foam::labelRanges::const_iterator::operator++() { if (++subIndex_ >= list_[index_].size()) { - // go to next list entry + // Next sub-list + ++index_; subIndex_ = 0; - if (++index_ >= list_.size()) - { - // equivalent to end iterator - index_ = subIndex_ = -1; - } } return *this; @@ -129,9 +115,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::cbegin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::cend() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::cend() const { - return endIter_; + return const_iterator(*this, true); } @@ -141,9 +127,9 @@ inline Foam::labelRanges::const_iterator Foam::labelRanges::begin() const } -inline const Foam::labelRanges::const_iterator& Foam::labelRanges::end() const +inline const Foam::labelRanges::const_iterator Foam::labelRanges::end() const { - return endIter_; + return const_iterator(*this, true); } diff --git a/src/OpenFOAM/primitives/strings/word/word.C b/src/OpenFOAM/primitives/strings/word/word.C index c8a2c1f1b74e108248790779407fb256333cc843..bbd4050a338a486438ae9cb628311710c8e63e72 100644 --- a/src/OpenFOAM/primitives/strings/word/word.C +++ b/src/OpenFOAM/primitives/strings/word/word.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,4 +32,63 @@ const char* const Foam::word::typeName = "word"; int Foam::word::debug(Foam::debug::debugSwitch(word::typeName, 0)); const Foam::word Foam::word::null; + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::word Foam::word::validated(const std::string& s) +{ + std::string::size_type count = 0; + bool prefix = false; + + // Count number of valid characters and detect if the first character + // happens to be a digit, which we'd like to avoid having since this + // will cause parse issues when read back later. + for (std::string::const_iterator it = s.cbegin(); it != s.cend(); ++it) + { + const char c = *it; + + if (word::valid(c)) + { + if (!count && isdigit(c)) + { + // First valid character was a digit - prefix with '_' + prefix = true; + ++count; + } + + ++count; + } + } + + if (count == s.size() && !prefix) + { + return word(s, false); // Already checked, can just return as word + } + + word out; + out.resize(count); + count = 0; + + // Copy valid content. + if (prefix) + { + out[count++] = '_'; + } + + for (std::string::const_iterator it = s.cbegin(); it != s.cend(); ++it) + { + const char c = *it; + + if (word::valid(c)) + { + out[count++] = c; + } + } + + out.resize(count); + + return out; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 8f29bdc943d8738eab07689e58c8e75f411e096a..1bc258bac9616738fc7a045b020c78cee85c7e3d 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,9 +48,9 @@ namespace Foam // Forward declaration of friend functions and operators class word; -inline word operator&(const word&, const word&); -Istream& operator>>(Istream&, word&); -Ostream& operator<<(Ostream&, const word&); +inline word operator&(const word& a, const word& b); +Istream& operator>>(Istream& is, word& w); +Ostream& operator<<(Ostream& os, const word& w); /*---------------------------------------------------------------------------*\ @@ -84,55 +84,60 @@ public: inline word(); //- Construct as copy - inline word(const word&); + inline word(const word& w); //- Construct as copy of character array - inline word(const char*, const bool doStripInvalid=true); + inline word(const char* s, const bool doStripInvalid=true); //- Construct as copy with a maximum number of characters inline word ( - const char*, + const char* s, const size_type, const bool doStripInvalid ); //- Construct as copy of string - inline word(const string&, const bool doStripInvalid=true); + inline word(const string& s, const bool doStripInvalid=true); //- Construct as copy of std::string - inline word(const std::string&, const bool doStripInvalid=true); + inline word(const std::string& s, const bool doStripInvalid=true); //- Construct from Istream - word(Istream&); + word(Istream& is); // Member functions - //- Is this character valid for a word - inline static bool valid(char); + //- Is this character valid for a word? + inline static bool valid(char c); + + //- Construct a validated word, in which all invalid characters have + // been stripped out and any leading digit is '_'-prefixed. + static word validated(const std::string& s); // Member operators // Assignment - inline void operator=(const word&); - inline void operator=(const string&); - inline void operator=(const std::string&); - inline void operator=(const char*); + inline void operator=(const word& w); + inline void operator=(const string& s); + inline void operator=(const std::string& s); + inline void operator=(const char* s); // Friend Operators - //- Join word a and bm capitalising first letter of b + //- Join word a and b, capitalising the first letter of b + // (so-called camelCase) friend word operator&(const word& a, const word& b); // IOstream operators - friend Istream& operator>>(Istream&, word&); - friend Ostream& operator<<(Ostream&, const word&); + friend Istream& operator>>(Istream& is, word& w); + friend Ostream& operator<<(Ostream& os, const word& w); }; diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index a4d15df4e78639e28364d19dbe1ddc9790e4b082..e19356f912d57214a5e6665cd9babb702f5cfd26 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -31,8 +31,7 @@ License inline void Foam::word::stripInvalid() { - // skip stripping unless debug is active to avoid - // costly operations + // skip stripping unless debug is active (to avoid costly operations) if (debug && string::stripInvalid<word>(*this)) { std::cerr @@ -132,29 +131,29 @@ inline bool Foam::word::valid(char c) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline void Foam::word::operator=(const word& q) +inline void Foam::word::operator=(const word& w) { - string::operator=(q); + string::operator=(w); } -inline void Foam::word::operator=(const string& q) +inline void Foam::word::operator=(const string& s) { - string::operator=(q); + string::operator=(s); stripInvalid(); } -inline void Foam::word::operator=(const std::string& q) +inline void Foam::word::operator=(const std::string& s) { - string::operator=(q); + string::operator=(s); stripInvalid(); } -inline void Foam::word::operator=(const char* q) +inline void Foam::word::operator=(const char* s) { - string::operator=(q); + string::operator=(s); stripInvalid(); } @@ -176,6 +175,5 @@ inline Foam::word Foam::operator&(const word& a, const word& b) } } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // ************************************************************************* // diff --git a/src/conversion/ccm/reader/ccmReader.C b/src/conversion/ccm/reader/ccmReader.C index 217a1e8347f923bb8f6c5837fa51520815fd048a..66b8bd95054ebb4777b672582d6e28dffb216b87 100644 --- a/src/conversion/ccm/reader/ccmReader.C +++ b/src/conversion/ccm/reader/ccmReader.C @@ -166,77 +166,6 @@ std::string Foam::ccm::reader::ccmReadOptstr } -Foam::word Foam::ccm::reader::validateWord -( - const std::string& str -) -{ - std::string::size_type ngood = 0; - bool prefix = false; - bool first = true; - - for - ( - std::string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) - { - if (word::valid(*iter)) - { - ++ngood; - if (first) - { - first = false; - - // Start with a digit? need to prefix with '_' - if (isdigit(*iter)) - { - prefix = true; - ++ngood; - } - } - } - } - - if (ngood == str.size() && !prefix) - { - return str; - } - - Foam::word out; - out.resize(ngood); - ngood = 0; - - Foam::word::iterator iter2 = out.begin(); - for - ( - std::string::const_iterator iter1 = str.begin(); - iter1 != str.end(); - ++iter1 - ) - { - register char c = *iter1; - - if (Foam::word::valid(c)) - { - if (prefix) - { - prefix = false; - *(iter2++) = '_'; - ++ngood; - } - *(iter2++) = c; - ++ngood; - } - } - - out.resize(ngood); - - return out; -} - - // Read map data and check error void Foam::ccm::reader::readMap ( @@ -435,7 +364,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion } else { - dict.add(opt, validateWord(str)); + dict.add(opt, word::validated(str)); } } @@ -476,7 +405,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion if (!str.empty()) { - dict.add(opt, validateWord(str)); + dict.add(opt, word::validated(str)); } } @@ -541,7 +470,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable str = "zone_" + ::Foam::name(Id); } - dict.add(opt, validateWord(str)); + dict.add(opt, word::validated(str)); } @@ -553,7 +482,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable if (!str.empty()) { - dict.add(opt, validateWord(str)); + dict.add(opt, word::validated(str)); } } diff --git a/src/conversion/ccm/reader/ccmReader.H b/src/conversion/ccm/reader/ccmReader.H index aa15978dd35314388bf4de9c407fe4c41c19a710..14408d3f944bf40fbc26426c609b91cf3c415eb1 100644 --- a/src/conversion/ccm/reader/ccmReader.H +++ b/src/conversion/ccm/reader/ccmReader.H @@ -320,9 +320,6 @@ private: // return empty string on failure std::string ccmReadOptstr(const char* opt, ccmID node); - //- Strip invalid characters, prefix leading digit with '_' - static word validateWord(const std::string&); - //- Read map data and check error void readMap(const ccmID& mapId, labelList& data); diff --git a/src/conversion/fire/FIREMeshReader.C b/src/conversion/fire/FIREMeshReader.C index ef8576cf5f543665a282d97ecf9250a20cbf607c..e79d70b060d28d3025c135696e0c5aa50f82bdad 100644 --- a/src/conversion/fire/FIREMeshReader.C +++ b/src/conversion/fire/FIREMeshReader.C @@ -31,80 +31,6 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::word Foam::fileFormats::FIREMeshReader::validateWord -( - const std::string& str -) -{ - std::string::size_type ngood = 0; - bool prefix = false; - bool first = true; - - for - ( - std::string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) - { - if (word::valid(*iter)) - { - ++ngood; - if (first) - { - first = false; - - // start with a digit? need to prefix with '_' - if (isdigit(*iter)) - { - prefix = true; - } - } - } - } - - if (prefix) - { - ++ngood; - } - else if (ngood == str.size()) - { - return str; - } - - Foam::word out; - out.resize(ngood); - ngood = 0; - - Foam::word::iterator iter2 = out.begin(); - for - ( - std::string::const_iterator iter1 = str.begin(); - iter1 != str.end(); - ++iter1 - ) - { - register char c = *iter1; - - if (Foam::word::valid(c)) - { - if (prefix) - { - prefix = false; - *(iter2++) = '_'; - ++ngood; - } - *(iter2++) = c; - ++ngood; - } - } - - out.resize(ngood); - - return out; -} - - void Foam::fileFormats::FIREMeshReader::readPoints ( ISstream& is, @@ -229,7 +155,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is) // index starting at 1 const label selId = ++nCellSelections; - cellTable_.setName(selId, validateWord(name)); + cellTable_.setName(selId, word::validated(name)); cellTable_.setMaterial(selId, "fluid"); for (label i = 0; i < count; ++i) @@ -244,7 +170,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is) // index starting at 0 const label selId = nFaceSelections++; - faceNames.append(validateWord(name)); + faceNames.append(word::validated(name)); for (label i = 0; i < count; ++i) { diff --git a/src/conversion/fire/FIREMeshReader.H b/src/conversion/fire/FIREMeshReader.H index 0c95cb5fa21eb39a0110168d8d4d90e0436478ac..b3e7f0b551b460983c7f3a2f75a0e6a83b0dc9c8 100644 --- a/src/conversion/fire/FIREMeshReader.H +++ b/src/conversion/fire/FIREMeshReader.H @@ -83,10 +83,6 @@ protected: void operator=(const FIREMeshReader&) = delete; - //- Validate word (eg, avoid leading digits) - static word validateWord(const std::string&); - - //- Read the mesh from the file(s) virtual bool readGeometry(const scalar scaleFactor = 1.0); diff --git a/src/conversion/fire/checkFireEdges.C b/src/conversion/fire/checkFireEdges.C index eb7c3bf9da11bc5bf539062a256357bf83b5852b..3969d1b62a49a1095cd1319822560b63559feab8 100644 --- a/src/conversion/fire/checkFireEdges.C +++ b/src/conversion/fire/checkFireEdges.C @@ -194,7 +194,7 @@ Foam::label Foam::checkFireEdges thisEdge.flip(); } - if (&points) + if (notNull(points)) { forAll(thisEdge, keyI) { @@ -220,7 +220,7 @@ Foam::label Foam::checkFireEdges { labelList keys = strayPoints.sortedToc(); - if (&points) + if (notNull(points)) { forAll(keys, keyI) { @@ -257,10 +257,9 @@ Foam::label Foam::checkFireEdges { label nPoints = -1; - if (&points) + if (notNull(points)) { nPoints = points.size(); - } else { @@ -287,10 +286,7 @@ Foam::label Foam::checkFireEdges } -Foam::label Foam::checkFireEdges -( - const polyMesh& mesh -) +Foam::label Foam::checkFireEdges(const polyMesh& mesh) { return checkFireEdges(mesh.faces(), mesh.pointFaces(), mesh.points()); } diff --git a/src/conversion/fire/checkFireEdges.H b/src/conversion/fire/checkFireEdges.H index 0f0bffe2c884c4632707499e3000e1349abc0e57..d5586378716033759ebbe7d47f7bddb1244d1a62 100644 --- a/src/conversion/fire/checkFireEdges.H +++ b/src/conversion/fire/checkFireEdges.H @@ -50,9 +50,9 @@ class polyMesh; //- check edge connectivity label checkFireEdges ( - const faceList&, + const faceList& faces, const labelListList& pointFaces, - const UList<point>& = UList<point>::null() + const UList<point>& points = UList<point>::null() ); @@ -60,12 +60,12 @@ label checkFireEdges label checkFireEdges ( const faceList&, - const UList<point>& = UList<point>::null() + const UList<point>& points = UList<point>::null() ); //- check edge connectivity -label checkFireEdges(const polyMesh&); +label checkFireEdges(const polyMesh& mesh); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/conversion/vtk/output/foamVtkOutput.C b/src/conversion/vtk/output/foamVtkOutput.C index 4ece681a85a8c8b8186ce328bfb528983c9c6205..fc2d29884189feb9a38640cb1c92a0ee61e950b2 100644 --- a/src/conversion/vtk/output/foamVtkOutput.C +++ b/src/conversion/vtk/output/foamVtkOutput.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,14 +62,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile vtmFile .xmlHeader() - .openTag("VTKFile") - ( "type", content ) - ( "version", "1.0" ) - ( "byte_order", foamVtkFormatter::byteOrder ) - ( "header_type", foamVtkFormatter::headerType ) - .closeTag(); - - vtmFile.tag(content); + .beginVTKFile(content, "1.0"); forAll(files, i) { @@ -80,7 +73,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile .closeTag(true); } - vtmFile.endTag(content).endTag("VTKFile"); + vtmFile.endTag(content).endVTKFile(); return files.size(); } diff --git a/src/conversion/vtk/output/foamVtkOutput.H b/src/conversion/vtk/output/foamVtkOutput.H index ad7964bfff7b638f1ff8837088d125feb10506d5..f0897d6675ca1658d6287ac3f1a98f7b260d14aa 100644 --- a/src/conversion/vtk/output/foamVtkOutput.H +++ b/src/conversion/vtk/output/foamVtkOutput.H @@ -58,6 +58,12 @@ class foamVtkOutput public: + // Public typedefs + + //- Use UInt64 for header data + typedef foamVtkFormatter::headerType headerType; + + // Forward declarations class legacy; diff --git a/src/conversion/vtk/part/foamVtkCells.C b/src/conversion/vtk/part/foamVtkCells.C index b4c7beacde9d7523af4cd59f61edac03fc6c2590..5846c8442d705359cd54460ce2668b80ca091588 100644 --- a/src/conversion/vtk/part/foamVtkCells.C +++ b/src/conversion/vtk/part/foamVtkCells.C @@ -326,7 +326,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 5; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_PYRAMID; @@ -373,7 +373,7 @@ void Foam::foamVtkCells::correct() nAddVerts += 4; vertOffset_[celLoc] = nAddVerts; - decompose_.superCells_[nAddCells++] = celLoc; + decompose_.superCells_[nAddCells++] = cellI; } cellTypes_[celLoc] = foamVtkCore::VTK_TETRA; diff --git a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C index fab34ba8cd1ce2d2f5f6ce252d4c89cf1191c6f2..b7cd414123fb3851d63a44e352c1e50d8217ea42 100644 --- a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C +++ b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -125,8 +125,7 @@ void Foam::polyMeshGeometry::updateCellCentresAndVols { const point& fc = faceCentres_[cFaces[cFaceI]]; cEst += fc; - bb.max() = max(bb.max(), fc); - bb.min() = min(bb.min(), fc); + bb.add(fc); } cEst /= cFaces.size(); diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 87fd35ee22b3c227489cbc79bad227c58ebc1051..ab7fe26dc28d14e0a433dd49fb4a3dc37aab39ab 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -19,6 +19,7 @@ vtk/format/foamVtkAppendBase64Formatter.C vtk/format/foamVtkAppendRawFormatter.C vtk/format/foamVtkAsciiFormatter.C vtk/format/foamVtkBase64Formatter.C +vtk/format/foamVtkBase64Layer.C vtk/format/foamVtkLegacyFormatter.C vtk/format/foamVtkFormatter.C vtk/format/foamVtkOutputOptions.C diff --git a/src/fileFormats/stl/STLCore.C b/src/fileFormats/stl/STLCore.C index a38d3a3cdf919407e8570e3b35204994e2959ab2..9b7c0c2e1c17f98a2a45c0a77819dd4549e35672 100644 --- a/src/fileFormats/stl/STLCore.C +++ b/src/fileFormats/stl/STLCore.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ bool Foam::fileFormats::STLCore::isBinaryName const STLFormat& format ) { - return (format == DETECT ? (filename.ext() == "stlb") : format == BINARY); + return (format == UNKNOWN ? (filename.ext() == "stlb") : format == BINARY); } diff --git a/src/fileFormats/stl/STLCore.H b/src/fileFormats/stl/STLCore.H index 548cfabde206b862f5c3ee433ca5c0e45ba5e703..fede83b850eb6eeb59c9fca34aa110d8aca16d63 100644 --- a/src/fileFormats/stl/STLCore.H +++ b/src/fileFormats/stl/STLCore.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,7 @@ public: { ASCII, //!< ASCII BINARY, //!< BINARY - DETECT //!< Detect based on (input) content or (output) extension + UNKNOWN //!< Detect based on (input) content or (output) extension }; diff --git a/src/fileFormats/stl/STLReader.C b/src/fileFormats/stl/STLReader.C index c507b026735658d30e25ccd14375cc4083d9f8e4..b7b91a0bb755574f216bb4d4f37a941286939610 100644 --- a/src/fileFormats/stl/STLReader.C +++ b/src/fileFormats/stl/STLReader.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +37,7 @@ bool Foam::fileFormats::STLReader::readBINARY ) { sorted_ = true; + format_ = UNKNOWN; label nTris = 0; autoPtr<istream> streamPtr = readBinaryHeader(filename, nTris); @@ -123,6 +124,7 @@ bool Foam::fileFormats::STLReader::readBINARY names_.clear(); sizes_.transfer(dynSizes); + format_ = BINARY; return true; } @@ -133,7 +135,7 @@ bool Foam::fileFormats::STLReader::readFile const STLFormat& format ) { - if (format == DETECT ? detectBinaryHeader(filename) : format == BINARY) + if (format == UNKNOWN ? detectBinaryHeader(filename) : format == BINARY) { return readBINARY(filename); } @@ -155,10 +157,11 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Auto-detect ASCII/BINARY format - readFile(filename, STLCore::DETECT); + readFile(filename, STLCore::UNKNOWN); } @@ -172,7 +175,8 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Manually specified ASCII/BINARY format readFile(filename, format); @@ -185,4 +189,17 @@ Foam::fileFormats::STLReader::~STLReader() {} +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::fileFormats::STLReader::clear() +{ + sorted_ = true; + points_.clear(); + zoneIds_.clear(); + names_.clear(); + sizes_.clear(); + format_ = UNKNOWN; +} + + // ************************************************************************* // diff --git a/src/fileFormats/stl/STLReader.H b/src/fileFormats/stl/STLReader.H index db985181d0b2384c935c3944da9279ebd7a79f32..9ed6838bc136feb7954060ad70bb93d7f0d2ba45 100644 --- a/src/fileFormats/stl/STLReader.H +++ b/src/fileFormats/stl/STLReader.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::fileFormats::STLReader Description - Internal class used by the STLsurfaceFormat + Internal class used by the STLsurfaceFormat and triSurface. SourceFiles STLReader.C @@ -72,17 +72,20 @@ class STLReader //- The solid count, in the order of their first appearance List<label> sizes_; + //- The STL format used + STLFormat format_; + // Private Member Functions //- Read ASCII - bool readASCII(const fileName&); + bool readASCII(const fileName& filename); //- Read BINARY - bool readBINARY(const fileName&); + bool readBINARY(const fileName& filename); //- Read ASCII or BINARY - bool readFile(const fileName&, const STLFormat&); + bool readFile(const fileName& filename, const STLFormat& format); //- Disallow default bitwise copy construct @@ -96,12 +99,13 @@ public: // Constructors - //- Read from file, filling in the information - STLReader(const fileName&); + //- Read from file, filling in the information. + // Auto-detect ASCII/BINARY format. + STLReader(const fileName& filename); //- Read from file, filling in the information. - // Manually selected choice of ascii/binary/detect. - STLReader(const fileName&, const STLFormat&); + // Manually selected choice of ASCII/BINARY/UNKNOWN(detect) formats. + STLReader(const fileName& filename, const STLFormat& format); //- Destructor @@ -110,45 +114,44 @@ public: // Member Functions - //- File read was already sorted - bool sorted() const - { - return sorted_; - } - //- Flush all values - void clear() + void clear(); + + //- File read was already sorted? + inline bool sorted() const { - sorted_ = true; - points_.clear(); - zoneIds_.clear(); - names_.clear(); - sizes_.clear(); + return sorted_; } //- Return full access to the points - pointField& points() + inline pointField& points() { return points_; } //- Return full access to the zoneIds - List<label>& zoneIds() + inline List<label>& zoneIds() { return zoneIds_; } //- The list of solid names in the order of their first appearance - List<word>& names() + inline List<word>& names() { return names_; } //- The list of solid sizes in the order of their first appearance - List<label>& sizes() + inline List<label>& sizes() { return sizes_; } + + //- The STL format used (ASCII or BINARY) + inline enum STLFormat stlFormat() const + { + return format_; + } }; diff --git a/src/fileFormats/stl/STLReaderASCII.L b/src/fileFormats/stl/STLReaderASCII.L index 515a1be90d8f3b5c2ec69c7d9cb1698f7486256b..0ea759151c2a05f59b2aa437dd74f11928bd952d 100644 --- a/src/fileFormats/stl/STLReaderASCII.L +++ b/src/fileFormats/stl/STLReaderASCII.L @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,13 +97,13 @@ public: // Access - //- Do all the solid groups appear in order + //- Do all the solid groups appear in order? inline bool sorted() const { return sorted_; } - //- A list of points corresponding to a pointField + //- A list of unstitched triangle points inline DynamicList<point>& points() { return points_; @@ -116,13 +116,13 @@ public: return facets_; } - //- Names + //- Solid names in the order of their appearance. inline DynamicList<word>& names() { return names_; } - //- Sizes + //- Solid sizes in the order of their appearance. inline DynamicList<label>& sizes() { return sizes_; @@ -396,6 +396,8 @@ bool Foam::fileFormats::STLReader::readASCII const fileName& filename ) { + format_ = UNKNOWN; + IFstream is(filename); if (!is) { @@ -417,6 +419,7 @@ bool Foam::fileFormats::STLReader::readASCII names_.transfer(lexer.names()); sizes_.transfer(lexer.sizes()); + format_ = ASCII; return true; } diff --git a/src/fileFormats/stl/STLpoint.H b/src/fileFormats/stl/STLpoint.H index c9862eaf9442d8a9755206616f1a9aa99ef630ec..3c432c09ee307fd7d33bc4ca305774fe4c946d69 100644 --- a/src/fileFormats/stl/STLpoint.H +++ b/src/fileFormats/stl/STLpoint.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::STLpoint Description - A vertex point representation for STL files. + A vertex point or facet normal representation for STL files. \*---------------------------------------------------------------------------*/ @@ -64,6 +64,12 @@ public: Vector<float>(x, y, z) {} + //- Construct from components + inline STLpoint(double x, double y, double z) + : + Vector<float>(float(x), float(y), float(z)) + {} + //- Construct from point inline STLpoint(const point& pt) : diff --git a/src/fileFormats/stl/STLtriangle.H b/src/fileFormats/stl/STLtriangle.H index a80f5498c53f3e90cd4acb474b266d5f92d57881..bf2bed3ea15a0f11c52f340ee7848217d9afa21c 100644 --- a/src/fileFormats/stl/STLtriangle.H +++ b/src/fileFormats/stl/STLtriangle.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,7 +46,7 @@ namespace Foam // Forward declaration of friend functions and operators class STLtriangle; -Ostream& operator<<(Ostream&, const STLtriangle&); +Ostream& operator<<(Ostream& os, const STLtriangle& tri); /*---------------------------------------------------------------------------*\ Class STLtriangle Declaration @@ -54,18 +54,20 @@ Ostream& operator<<(Ostream&, const STLtriangle&); class STLtriangle { - // Private data + // Typedefs - //- Attribute is 16-bit - typedef unsigned short STLattrib; + //- Attribute is 16-bit + typedef unsigned short STLattrib; - //- The face normal, many programs write zero or other junk - STLpoint normal_; + // Private data + // NB: The order of the members (1 normal, 3 points, 1 attribute) is + // essential when reading/writing binary content. - //- The three points defining the triangle - STLpoint a_, b_, c_; + //- The face normal and the three points defining the triangle. + // Some programs may write zero or other junk for the normal. + STLpoint normal_, a_, b_, c_; - //- The attribute information could for colour or solid id, etc + //- The attribute information could be for 'color' or solid id, etc STLattrib attrib_; @@ -87,7 +89,7 @@ public: ); //- Construct from istream (read binary) - inline STLtriangle(istream&); + inline STLtriangle(std::istream& is); // Member Functions @@ -104,13 +106,13 @@ public: // Read //- Read from istream (binary) - inline void read(istream&); + inline void read(std::istream& is); // Write //- Write to ostream (binary) - inline void write(ostream&) const; + inline void write(std::ostream& os) const; //- Write to Ostream (ASCII) inline Ostream& print(Ostream& os) const; @@ -138,7 +140,8 @@ public: // Ostream operator - inline friend Ostream& operator<<(Ostream&, const STLtriangle&); + //- Print triangle contents + inline friend Ostream& operator<<(Ostream& os, const STLtriangle& tri); }; diff --git a/src/fileFormats/stl/STLtriangleI.H b/src/fileFormats/stl/STLtriangleI.H index 85e02be3d483602e41944832275eb9c60b6812ac..541bec22bfe0bc723ae0664fd1ef9ed6d8edb2be 100644 --- a/src/fileFormats/stl/STLtriangleI.H +++ b/src/fileFormats/stl/STLtriangleI.H @@ -48,7 +48,7 @@ inline Foam::STLtriangle::STLtriangle {} -inline Foam::STLtriangle::STLtriangle(istream& is) +inline Foam::STLtriangle::STLtriangle(std::istream& is) { read(is); } @@ -86,16 +86,16 @@ inline unsigned short Foam::STLtriangle::attrib() const } -inline void Foam::STLtriangle::read(istream& is) +inline void Foam::STLtriangle::read(std::istream& is) { - is.read(reinterpret_cast<char*>(this), 4*sizeof(STLpoint)); + is.read(reinterpret_cast<char*>(&normal_), 4*sizeof(STLpoint)); is.read(reinterpret_cast<char*>(&attrib_), sizeof(STLattrib)); } -inline void Foam::STLtriangle::write(ostream& os) const +inline void Foam::STLtriangle::write(std::ostream& os) const { - os.write(reinterpret_cast<const char*>(this), 4*sizeof(STLpoint)); + os.write(reinterpret_cast<const char*>(&normal_), 4*sizeof(STLpoint)); os.write(reinterpret_cast<const char*>(&attrib_), sizeof(STLattrib)); } @@ -153,13 +153,13 @@ inline void Foam::STLtriangle::write // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // -inline Foam::Ostream& Foam::operator<<(Ostream& os, const STLtriangle& t) +inline Foam::Ostream& Foam::operator<<(Ostream& os, const STLtriangle& tri) { - os << t.normal_ << token::SPACE - << t.a_ << token::SPACE - << t.b_ << token::SPACE - << t.c_ << token::SPACE - << t.attrib_; + os << tri.normal_ << token::SPACE + << tri.a_ << token::SPACE + << tri.b_ << token::SPACE + << tri.c_ << token::SPACE + << tri.attrib_; return os; } diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C index ee8b84200f0aaa5b8d333d2e577b44c2d5289be3..3805b61812e783c4bddd29582c2cc442a45e815f 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,8 +27,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; -const char* Foam::foamVtkAppendBase64Formatter::encoding_ = "base64"; +const char* Foam::foamVtkAppendBase64Formatter::name_ = "append"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -38,14 +37,16 @@ Foam::foamVtkAppendBase64Formatter::foamVtkAppendBase64Formatter std::ostream& os ) : - foamVtkBase64Formatter(os) + foamVtkBase64Layer(os) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::foamVtkAppendBase64Formatter::~foamVtkAppendBase64Formatter() -{} +{ + base64Layer::close(); +} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // @@ -56,10 +57,4 @@ const char* Foam::foamVtkAppendBase64Formatter::name() const } -const char* Foam::foamVtkAppendBase64Formatter::encoding() const -{ - return encoding_; -} - - // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H index b7239ee7c66ffc637441b4504eb69a9a74f52a24..db3e1d6694fffda7c0869e1ae43916bce97dc2fb 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,7 @@ SourceFiles #ifndef foamVtkAppendBase64Formatter_H #define foamVtkAppendBase64Formatter_H -#include "foamVtkBase64Formatter.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,12 +49,11 @@ namespace Foam class foamVtkAppendBase64Formatter : - public foamVtkBase64Formatter + public foamVtkBase64Layer { // Private Data Members static const char* name_; - static const char* encoding_; // Private Member Functions @@ -71,7 +70,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendBase64Formatter(std::ostream&); + foamVtkAppendBase64Formatter(std::ostream& os); //- Destructor @@ -83,9 +82,6 @@ public: //- Output name for XML type ("append") virtual const char* name() const; - //- Name for the XML append encoding ("base64"). - virtual const char* encoding() const; - }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C index 9933970495ea2e8a920659bf6f61edd680933914..ae565323b8546a93739d9eca782a519a039f8b52 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,9 +71,9 @@ const char* Foam::foamVtkAppendRawFormatter::encoding() const } -void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t val) +void Foam::foamVtkAppendRawFormatter::writeSize(const uint64_t nBytes) { - write(reinterpret_cast<const char*>(&val), sizeof(uint64_t)); + write(reinterpret_cast<const char*>(&nBytes), sizeof(uint64_t)); } @@ -85,28 +85,28 @@ void Foam::foamVtkAppendRawFormatter::write(const uint8_t val) void Foam::foamVtkAppendRawFormatter::write(const label val) { - // std::cerr<<"label is:" << sizeof(val) << '\n'; + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast<const char*>(&val), sizeof(label)); } void Foam::foamVtkAppendRawFormatter::write(const float val) { - // std::cerr<<"float is:" << sizeof(val) << '\n'; + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; write(reinterpret_cast<const char*>(&val), sizeof(float)); } void Foam::foamVtkAppendRawFormatter::write(const double val) { - // std::cerr<<"write double as float:" << val << '\n'; + // std::cerr<<"double as float=" << val << '\n'; float copy(val); write(copy); } void Foam::foamVtkAppendRawFormatter::flush() -{} +{/*nop*/} // ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H index abc3db09293f7baccc6c1796ef4ba3ffe40d2e1d..1dcb9b8d55c39a2fd3845947c0e2b8915effddbe 100644 --- a/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAppendRawFormatter.H @@ -77,7 +77,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkAppendRawFormatter(std::ostream&); + foamVtkAppendRawFormatter(std::ostream& os); //- Destructor @@ -94,12 +94,14 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t nBytes); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- A no-op for this format virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C index 6a78f73f53cbf19db657bda92e828c282329d4ab..9ed22db23303d3239a446e6328f435a7f8268c6f 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,16 @@ inline void Foam::foamVtkAsciiFormatter::next() } +inline void Foam::foamVtkAsciiFormatter::done() +{ + if (pos_) + { + os()<< '\n'; + } + pos_ = 0; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter(std::ostream& os) @@ -73,7 +83,7 @@ Foam::foamVtkAsciiFormatter::foamVtkAsciiFormatter Foam::foamVtkAsciiFormatter::~foamVtkAsciiFormatter() { - flush(); + done(); } @@ -91,7 +101,7 @@ const char* Foam::foamVtkAsciiFormatter::encoding() const } -void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t) +void Foam::foamVtkAsciiFormatter::writeSize(const uint64_t ignored) {/*nop*/} @@ -125,11 +135,14 @@ void Foam::foamVtkAsciiFormatter::write(const double val) void Foam::foamVtkAsciiFormatter::flush() { - if (pos_) - { - os()<< '\n'; - } - pos_ = 0; + done(); +} + + +std::size_t +Foam::foamVtkAsciiFormatter::encodedLength(std::size_t ignored) const +{ + return 0; } diff --git a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H index 009d776f89f1d85cf3cd5335e2feb5cde8695047..8b8e06b2a226c855c2243f89f4675aeb4bc2251c 100644 --- a/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkAsciiFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,9 +62,12 @@ class foamVtkAsciiFormatter // Private Member Functions - //- Advance to next position, adding space or newline as required + //- Advance to next position, adding space or newline as needed inline void next(); + //- Finish an output line, adding newline as needed + inline void done(); + //- Disallow default bitwise copy construct foamVtkAsciiFormatter(const foamVtkAsciiFormatter&) = delete; @@ -78,10 +81,10 @@ public: // Constructors //- Construct and attach to an output stream, use default precision - foamVtkAsciiFormatter(std::ostream&); + foamVtkAsciiFormatter(std::ostream& os); //- Construct and attach to an output stream, use specified precision - foamVtkAsciiFormatter(std::ostream&, unsigned precision); + foamVtkAsciiFormatter(std::ostream& os, unsigned precision); //- Destructor @@ -95,18 +98,24 @@ public: virtual const char* name() const; //- Name for the XML append encoding - unused. - // Currently simply "ASCII", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - this is a no-op for ascii output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); + + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + //- Write a newline if needed to finish a line of output. virtual void flush(); + + //- The encoded length for ascii output is not applicable. + virtual std::size_t encodedLength(std::size_t ignored) const; + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C index a11d97bd49e573d318700e6e56f66802364daf51..f87efbb19f4972a65dd02f9c40eb56800696e0bb 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.C +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,28 +27,14 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* Foam::foamVtkBase64Formatter::name_ = "binary"; -const char* Foam::foamVtkBase64Formatter::encoding_ = "base64"; - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void Foam::foamVtkBase64Formatter::write -( - const char* s, - std::streamsize n -) -{ - base64Layer::write(s, n); -} +const char* Foam::foamVtkBase64Formatter::name_ = "binary"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) : - foamVtkFormatter(os), - base64Layer(os) + foamVtkBase64Layer(os) {} @@ -56,7 +42,10 @@ Foam::foamVtkBase64Formatter::foamVtkBase64Formatter(std::ostream& os) Foam::foamVtkBase64Formatter::~foamVtkBase64Formatter() { - flush(); + if (base64Layer::close()) + { + os().put('\n'); + } } @@ -68,46 +57,6 @@ const char* Foam::foamVtkBase64Formatter::name() const } -const char* Foam::foamVtkBase64Formatter::encoding() const -{ - return encoding_; -} - - -void Foam::foamVtkBase64Formatter::writeSize(const uint64_t val) -{ - write(reinterpret_cast<const char*>(&val), sizeof(uint64_t)); -} - - -void Foam::foamVtkBase64Formatter::write(const uint8_t val) -{ - base64Layer::add(val); -} - - -void Foam::foamVtkBase64Formatter::write(const label val) -{ - // std::cerr<<"label is:" << sizeof(val) << '\n'; - write(reinterpret_cast<const char*>(&val), sizeof(label)); -} - - -void Foam::foamVtkBase64Formatter::write(const float val) -{ - // std::cerr<<"float is:" << sizeof(val) << '\n'; - write(reinterpret_cast<const char*>(&val), sizeof(float)); -} - - -void Foam::foamVtkBase64Formatter::write(const double val) -{ - // std::cerr<<"write double as float:" << val << '\n'; - float copy(val); - write(copy); -} - - void Foam::foamVtkBase64Formatter::flush() { if (base64Layer::close()) diff --git a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H index f01bec3d9aa343159749834e47cc0f7ff14e62fe..e92fa4f9e374c21c8ead9795234d6c777b8ab381 100644 --- a/src/fileFormats/vtk/format/foamVtkBase64Formatter.H +++ b/src/fileFormats/vtk/format/foamVtkBase64Formatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,8 +33,7 @@ Description #ifndef foamVtkBase64Formatter_H #define foamVtkBase64Formatter_H -#include "foamVtkFormatter.H" -#include "base64Layer.H" +#include "foamVtkBase64Layer.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,8 +46,7 @@ namespace Foam class foamVtkBase64Formatter : - public foamVtkFormatter, - private base64Layer + public foamVtkBase64Layer { // Private Data Members @@ -64,20 +62,12 @@ class foamVtkBase64Formatter //- Disallow default bitwise assignment void operator=(const foamVtkBase64Formatter&) = delete; -protected: - - // Protected Member Functions - - //- Write - void write(const char* s, std::streamsize n); - - public: // Constructors //- Construct and attach to an output stream - foamVtkBase64Formatter(std::ostream&); + foamVtkBase64Formatter(std::ostream& os); //- Destructor @@ -90,17 +80,9 @@ public: // The lowercase version of the Legacy output type. virtual const char* name() const; - //- Name for the XML append encoding. - virtual const char* encoding() const; - - - //- Write leading size for binary output - virtual void writeSize(const uint64_t); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + //- End the encoding sequence (padding the final characters with '=') + // and write a newline to the output if any encoding was done. virtual void flush(); }; diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.C b/src/fileFormats/vtk/format/foamVtkBase64Layer.C new file mode 100644 index 0000000000000000000000000000000000000000..d66970d522b7e356eb03e711557b66985939bcd2 --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.C @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkBase64Layer.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding_ = "base64"; + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::foamVtkBase64Layer::write +( + const char* s, + std::streamsize n +) +{ + base64Layer::write(s, n); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::foamVtkBase64Layer(std::ostream& os) +: + foamVtkFormatter(os), + base64Layer(os) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::foamVtkBase64Layer::~foamVtkBase64Layer() +{ + base64Layer::close(); +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +const char* Foam::foamVtkBase64Layer::encoding() const +{ + return encoding_; +} + + +void Foam::foamVtkBase64Layer::writeSize(const uint64_t nBytes) +{ + write(reinterpret_cast<const char*>(&nBytes), sizeof(uint64_t)); +} + + +void Foam::foamVtkBase64Layer::write(const uint8_t val) +{ + base64Layer::add(val); +} + + +void Foam::foamVtkBase64Layer::write(const label val) +{ + // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast<const char*>(&val), sizeof(label)); +} + + +void Foam::foamVtkBase64Layer::write(const float val) +{ + // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n'; + write(reinterpret_cast<const char*>(&val), sizeof(float)); +} + + +void Foam::foamVtkBase64Layer::write(const double val) +{ + // std::cerr<<"double as float=" << val << '\n'; + float copy(val); + write(copy); +} + + +void Foam::foamVtkBase64Layer::flush() +{ + base64Layer::close(); +} + + +std::size_t Foam::foamVtkBase64Layer::encodedLength(std::size_t n) const +{ + return base64Layer::encodedLength(n); +} + + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkBase64Layer.H b/src/fileFormats/vtk/format/foamVtkBase64Layer.H new file mode 100644 index 0000000000000000000000000000000000000000..61527a11bc02d6047ef6ee8b28bca8e61f978584 --- /dev/null +++ b/src/fileFormats/vtk/format/foamVtkBase64Layer.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + foamVtkBase64Layer + +Description + Base-64 encoded output. + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkBase64Layer_H +#define foamVtkBase64Layer_H + +#include "foamVtkFormatter.H" +#include "base64Layer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamVtkBase64Layer Declaration +\*---------------------------------------------------------------------------*/ + +class foamVtkBase64Layer +: + public foamVtkFormatter, + protected base64Layer +{ + // Private Data Members + + static const char* encoding_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + foamVtkBase64Layer(const foamVtkBase64Layer&) = delete; + + //- Disallow default bitwise assignment + void operator=(const foamVtkBase64Layer&) = delete; + +protected: + + // Protected Member Functions + + //- Write + void write(const char* s, std::streamsize n); + + + // Constructors + + //- Construct and attach to an output stream + foamVtkBase64Layer(std::ostream& os); + +public: + + //- Destructor + virtual ~foamVtkBase64Layer(); + + + // Member Functions + + //- Name for the XML append encoding ("base64"). + virtual const char* encoding() const; + + + //- Write leading size for binary output + virtual void writeSize(const uint64_t nBytes); + + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- End the encoding sequence (padding the final characters with '=') + virtual void flush(); + + //- The encoded length for base64 encoded output. + virtual std::size_t encodedLength(std::size_t n) const; + +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index 7271dd22f5ebbee7037f5dd1484fd8b67ef5046c..5b9fded769abb084d5ed0f4e9e13fb16928919a1 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,16 +23,6 @@ License \*---------------------------------------------------------------------------*/ #include "foamVtkFormatter.H" -#include "foamVtkPTraits.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const char* const Foam::foamVtkFormatter::byteOrder - = Foam::foamVtkPTraits<endian>::typeName; - -const char* const Foam::foamVtkFormatter::headerType = - Foam::foamVtkPTraits<uint64_t>::typeName; - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -52,6 +42,12 @@ Foam::foamVtkFormatter::~foamVtkFormatter() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +std::size_t Foam::foamVtkFormatter::encodedLength(std::size_t n) const +{ + return n; +} + + void Foam::foamVtkFormatter::indent() { label n = xmlTags_.size() * 2; @@ -139,17 +135,6 @@ Foam::foamVtkFormatter::closeTag(const bool isEmpty) } -Foam::foamVtkFormatter& -Foam::foamVtkFormatter::tag(const word& tag) -{ - openTag(tag); - closeTag(); - - return *this; -} - - - Foam::foamVtkFormatter& Foam::foamVtkFormatter::endTag(const word& tag) { @@ -181,6 +166,52 @@ Foam::foamVtkFormatter::endTag(const word& tag) } +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::tag(const word& tag) +{ + openTag(tag); + closeTag(); + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginVTKFile +( + const word& contentType, + const word& contentVersion, + const bool leaveOpen +) +{ + openTag("VTKFile"); + xmlAttr("type", contentType); + xmlAttr("version", contentVersion); + xmlAttr("byte_order", foamVtkPTraits<Foam::endian>::typeName); + xmlAttr("header_type", foamVtkPTraits<headerType>::typeName); + closeTag(); + + openTag(contentType); + if (!leaveOpen) + { + closeTag(); + } + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginAppendedData() +{ + openTag("AppendedData"); + xmlAttr("encoding", encoding()); + closeTag(); + os_ << '_'; + + return *this; +} + Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr @@ -254,55 +285,35 @@ Foam::foamVtkFormatter::xmlAttr // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const std::string& v -) +Foam::foamVtkFormatter::operator()(const word& k, const std::string& v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int32_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int32_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const uint64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const uint64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const scalar v -) +Foam::foamVtkFormatter::operator()(const word& k, const scalar v) { return xmlAttr(k, v); } diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 65519b1955a0265fbd09154100be57124c111d69..9e37f2c6253ff5a70dc48becccbcf93b2287ee93 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,8 +74,8 @@ class foamVtkFormatter template<class Type> foamVtkFormatter& xmlAttribute ( - const word&, - const Type&, + const word& k, + const Type& v, const char quote ); @@ -89,13 +89,10 @@ protected: public: - // Static Data + // Public typedefs - //- VTK name for the 'byte_order' attribute - static const char* const byteOrder; - - //- VTK name for the 'header_type' attribute (UInt64) - static const char* const headerType; + //- Use UInt64 for header data + typedef uint64_t headerType; //- Destructor @@ -120,14 +117,20 @@ public: //- Write leading size for binary output - virtual void writeSize(const uint64_t) = 0; + virtual void writeSize(const uint64_t nBytes) = 0; + + virtual void write(const uint8_t val) = 0; + virtual void write(const label val) = 0; + virtual void write(const float val) = 0; + virtual void write(const double val) = 0; - virtual void write(const uint8_t) = 0; - virtual void write(const label) = 0; - virtual void write(const float) = 0; - virtual void write(const double) = 0; + //- Flush encoding, write newline etc. virtual void flush() = 0; + //- The encoded length for binary output. + // The default is pass-through. + virtual std::size_t encodedLength(std::size_t n) const; + // Member Functions @@ -138,7 +141,7 @@ public: foamVtkFormatter& xmlHeader(); //- Write XML comment (at the current indentation level) - foamVtkFormatter& comment(const std::string&); + foamVtkFormatter& comment(const std::string& text); //- Open XML tag @@ -155,6 +158,20 @@ public: //- Write XML tag without any attributes. Combines openTag/closeTag. foamVtkFormatter& tag(const word& tag); + //- Add a "VTKFile" XML tag for contentType, followed by a tag for + // the contentType itself. Optionally leave the contentType tag + // open for adding additional attributes. + foamVtkFormatter& beginVTKFile + ( + const word& contentType, + const word& contentVersion, + const bool leaveOpen = false + ); + + //- Add a "AppendedData" XML tag with the current encoding and output + // the requisite '_' prefix. + foamVtkFormatter& beginAppendedData(); + //- Open "DataArray" XML tag template<class Type, int nComp=0> @@ -168,49 +185,63 @@ public: //- End "DataArray" XML tag - foamVtkFormatter& endDataArray() + inline foamVtkFormatter& endDataArray() { return endTag("DataArray"); } + //- End "AppendedData" XML tag + inline foamVtkFormatter& endAppendedData() + { + flush(); // flush any pending encoded content + os_ << '\n'; // clear separation from content. + return endTag("AppendedData"); + } + + //- End "VTKFile" XML tag + inline foamVtkFormatter& endVTKFile() + { + return endTag("VTKFile"); + } + //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const std::string&, + const word& k, + const std::string& v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int32_t, + const word& k, + const int32_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const int64_t, + const word& k, + const int64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const uint64_t, + const word& k, + const uint64_t v, const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( - const word&, - const scalar, + const word& k, + const scalar v, const char quote = '\'' ); @@ -219,19 +250,19 @@ public: // Member Operators //- Write XML attribute - foamVtkFormatter& operator()(const word&, const std::string&); + foamVtkFormatter& operator()(const word& k, const std::string& v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int32_t); + foamVtkFormatter& operator()(const word& k, const int32_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const int64_t); + foamVtkFormatter& operator()(const word& k, const int64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const uint64_t); + foamVtkFormatter& operator()(const word& k, const uint64_t v); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const scalar); + foamVtkFormatter& operator()(const word& k, const scalar v); }; diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C index 89525ab0baa0ebf2555548a517f0fce491d4c259..a3e87264f82fc1bc30977fa0f7dd4ed02f3a86e0 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,8 +71,8 @@ const char* Foam::foamVtkLegacyFormatter::encoding() const } -void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t) -{} +void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t ignored) +{/*nop*/} void Foam::foamVtkLegacyFormatter::write(const uint8_t val) diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H index fe2395add4d143085d854c987d040b6ed051caaa..6ec5ba7e8dd37209a9bc92c6b91fa2e479e75eac 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,11 +25,10 @@ Class foamVtkLegacyFormatter Description - Binary output for the VTK legacy format, always written as big-endian. + Binary output for the VTK legacy format, always written as big-endian + and with 32-bit integers. - The legacy files are always written as big endian. - Since integers in the legacy format are limited to 32-bit, - this format should not be used for OpenFOAM with 64-bit label sizes. + This format should never be used for OpenFOAM with 64-bit label sizes. SourceFiles foamVtkLegacyFormatter.C @@ -81,7 +80,7 @@ public: // Constructors //- Construct and attach to an output stream - foamVtkLegacyFormatter(std::ostream&); + foamVtkLegacyFormatter(std::ostream& os); //- Destructor @@ -90,22 +89,25 @@ public: // Member Functions - //- Name for the Legacy output type ("BINARY") + //- Name for the legacy binary output type ("BINARY") virtual const char* name() const; //- Name for the XML append encoding (unused) - // Currently simply "BINARY", but this should not be relied upon. + // Currently identical to name(), but do not rely on this. virtual const char* encoding() const; //- Write leading size - a no-op for legacy binary output - virtual void writeSize(const uint64_t); + virtual void writeSize(const uint64_t ignored); - virtual void write(const uint8_t); - virtual void write(const label); - virtual void write(const float); - virtual void write(const double); + virtual void write(const uint8_t val); + virtual void write(const label val); + virtual void write(const float val); + virtual void write(const double val); + + //- Write a newline to the output virtual void flush(); + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.C b/src/fileFormats/vtk/format/foamVtkOutputOptions.C index 39f11a432e8e65e90660d21cbb7d18af22b56fee..c88d334594d14289c27237b66c66839fb89f5def 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.C +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,10 +45,8 @@ Foam::foamVtkOutputOptions::foamVtkOutputOptions() // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -Foam::autoPtr<Foam::foamVtkFormatter> Foam::foamVtkOutputOptions::newFormatter -( - std::ostream& os -) const +Foam::autoPtr<Foam::foamVtkFormatter> +Foam::foamVtkOutputOptions::newFormatter(std::ostream& os) const { switch (type_) { @@ -87,9 +85,9 @@ Foam::autoPtr<Foam::foamVtkFormatter> Foam::foamVtkOutputOptions::newFormatter // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -void Foam::foamVtkOutputOptions::ascii(bool b) +void Foam::foamVtkOutputOptions::ascii(bool on) { - if (b) + if (on) { // Force ASCII: @@ -132,9 +130,9 @@ void Foam::foamVtkOutputOptions::ascii(bool b) } -void Foam::foamVtkOutputOptions::append(bool b) +void Foam::foamVtkOutputOptions::append(bool on) { - if (b) + if (on) { if (!(type_ & APPEND)) { @@ -153,9 +151,9 @@ void Foam::foamVtkOutputOptions::append(bool b) } -void Foam::foamVtkOutputOptions::legacy(bool b) +void Foam::foamVtkOutputOptions::legacy(bool on) { - if (b) + if (on) { if (type_ & APPEND) { @@ -180,9 +178,9 @@ void Foam::foamVtkOutputOptions::legacy(bool b) } -void Foam::foamVtkOutputOptions::precision(unsigned val) const +void Foam::foamVtkOutputOptions::precision(unsigned prec) const { - precision_ = val; + precision_ = prec; } diff --git a/src/fileFormats/vtk/format/foamVtkOutputOptions.H b/src/fileFormats/vtk/format/foamVtkOutputOptions.H index a5f59de5144e91e0ec16b296a036d1bbc39fc82e..7e0e89b24be155f760fb45f3d16e97b71b8f57de 100644 --- a/src/fileFormats/vtk/format/foamVtkOutputOptions.H +++ b/src/fileFormats/vtk/format/foamVtkOutputOptions.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -88,7 +88,7 @@ public: // Selectors //- Return new data formatter based on the writer options - autoPtr<foamVtkFormatter> newFormatter(std::ostream&) const; + autoPtr<foamVtkFormatter> newFormatter(std::ostream& os) const; // Member Functions @@ -117,16 +117,16 @@ public: // In append mode, this switches between base64 and raw binary. // In XML mode, this switches between ASCII and base64. // In legacy mode, this switches between ASCII and binary. - void ascii(bool); + void ascii(bool on); //- Toggle append mode on/off. - void append(bool); + void append(bool on); //- Toggle legacy mode on/off. - void legacy(bool); + void legacy(bool on); //- Set the write precision to be used for new ASCII formatters - void precision(unsigned val) const; + void precision(unsigned prec) const; // Other diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.C b/src/fileFormats/vtk/type/foamVtkPTraits.C index 91bf1f3a33b647663c9077245b8252efa4d0c76a..feb5e909c25c5b20d239452ce851f3ea431b18f9 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.C +++ b/src/fileFormats/vtk/type/foamVtkPTraits.C @@ -59,11 +59,11 @@ Foam::foamVtkPTraits<double>::typeName = "Float64"; #ifdef WM_LITTLE_ENDIAN template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "LittleEndian"; +Foam::foamVtkPTraits<Foam::endian>::typeName = "LittleEndian"; #else template<> const char* const -Foam::foamVtkPTraits<::Foam::endian>::typeName = "BigEndian"; +Foam::foamVtkPTraits<Foam::endian>::typeName = "BigEndian"; #endif diff --git a/src/fileFormats/vtk/type/foamVtkPTraits.H b/src/fileFormats/vtk/type/foamVtkPTraits.H index ea95c0820d1f61f8190336f0c7dd092013ffd98d..ff77c03b8d9498f97737a2435e5235c9f6bba537 100644 --- a/src/fileFormats/vtk/type/foamVtkPTraits.H +++ b/src/fileFormats/vtk/type/foamVtkPTraits.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,28 +58,28 @@ public: template<> -const char* const foamVtkPTraits<uint8_t>::typeName; // = UInt8 +const char* const foamVtkPTraits<uint8_t>::typeName; // UInt8 template<> -const char* const foamVtkPTraits<int32_t>::typeName; // = Int32 +const char* const foamVtkPTraits<int32_t>::typeName; // Int32 template<> -const char* const foamVtkPTraits<int32_t>::typeName; // = UInt32 +const char* const foamVtkPTraits<uint32_t>::typeName; // UInt32 template<> -const char* const foamVtkPTraits<int32_t>::typeName; // = Int64 +const char* const foamVtkPTraits<int64_t>::typeName; // Int64 template<> -const char* const foamVtkPTraits<int64_t>::typeName; // = UInt64 +const char* const foamVtkPTraits<uint64_t>::typeName; // UInt64 template<> -const char* const foamVtkPTraits<float>::typeName; // = Float32 +const char* const foamVtkPTraits<float>::typeName; // Float32 template<> -const char* const foamVtkPTraits<double>::typeName; // = Float64 +const char* const foamVtkPTraits<double>::typeName; // Float64 template<> -const char* const foamVtkPTraits<::Foam::endian>::typeName; +const char* const foamVtkPTraits<Foam::endian>::typeName; // (Big|Little)Endian // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.H index 52170caa29a6cdab13f452f18320b6a41066f21e..7b4916c136f35a0a5c74bd9025ed173fb2d93d6d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.H @@ -34,7 +34,7 @@ Description Usage \table Property | Description | Required | Default value - valueFraction | fraction od value used for boundary [0-1] | yes | + valueFraction | fraction of value used for boundary [0-1] | yes | \endtable Example of the boundary condition specification: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/slip/slipFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/slip/slipFvPatchField.C index 83340f3fe56ad4adccd4c5f50b8c5f9de6820354..e2f04b79ead4b2b8c17ebff8f26c7684452f35bf 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/slip/slipFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/slip/slipFvPatchField.C @@ -34,7 +34,7 @@ Foam::slipFvPatchField<Type>::slipFvPatchField const DimensionedField<Type, volMesh>& iF ) : - basicSymmetryFvPatchField<Type>(p, iF) + basicSymmetryFvPatchField<Type>(p, iF) {} diff --git a/src/functionObjects/field/streamLine/streamLine.H b/src/functionObjects/field/streamLine/streamLine.H index 1787795b272f9858cd163e8b17f9232a01069821..0638c5fc68d2ca3fbceedc7c21c171424e7a77f5 100644 --- a/src/functionObjects/field/streamLine/streamLine.H +++ b/src/functionObjects/field/streamLine/streamLine.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,7 +76,7 @@ Usage trackLength | Tracking segment length | no | nSubCycle | Number of tracking steps per cell | no| cloudName | Cloud name to use | yes | - bounds | Bounding box to trim tracks | no | greatBox + bounds | Bounding box to trim tracks | no | invertedBox seedSampleSet| Seeding method (see below)| yes | \endtable @@ -136,10 +136,10 @@ class streamLine // Private Member Functions //- Disallow default bitwise copy construct - streamLine(const streamLine&); + streamLine(const streamLine&) = delete; //- Disallow default bitwise assignment - void operator=(const streamLine&); + void operator=(const streamLine&) = delete; public: diff --git a/src/functionObjects/field/streamLine/streamLineBase.C b/src/functionObjects/field/streamLine/streamLineBase.C index 3356524a06ef6b94167bbdb7da46e286dba5cea7..d5741a6c2bf613de9c96eff6070981a1beafd489 100644 --- a/src/functionObjects/field/streamLine/streamLineBase.C +++ b/src/functionObjects/field/streamLine/streamLineBase.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -545,8 +545,8 @@ bool Foam::functionObjects::streamLineBase::read(const dictionary& dict) } - bounds_ = boundBox::greatBox; - if (dict.readIfPresent("bounds", bounds_)) + bounds_ = boundBox::invertedBox; + if (dict.readIfPresent("bounds", bounds_) && !bounds_.empty()) { Info<< " clipping all segments to " << bounds_ << nl << endl; } @@ -701,7 +701,7 @@ bool Foam::functionObjects::streamLineBase::write() if (Pstream::master()) { - if (bounds_ != boundBox::greatBox) + if (!bounds_.empty()) { // Clip to bounding box trimToBox(treeBoundBox(bounds_)); diff --git a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H index e8609eb77d9f522429cee948c3e770cc359a525d..77dad3fb711df646aa61fece58917b295b64dbce 100644 --- a/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H +++ b/src/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,7 +79,7 @@ Usage trackLength | Tracking segment length | no | nSubCycle | Number of tracking steps per cell | no| cloudName | Cloud name to use | yes | - bounds | Bounding box to trim tracks | no | greatBox + bounds | Bounding box to trim tracks | no | invertedBox seedSampleSet| Seeding method (see below)| yes | \endtable diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwclean b/src/functionObjects/graphics/runTimePostProcessing/Allwclean index 1d94a698c53a69a7db72550e27412c37bf502723..00ff12fadbbf6abfdc54049929f5ec912e660e06 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwclean +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwclean @@ -2,10 +2,13 @@ cd ${0%/*} || exit 1 # Run from this directory # Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions -# Where are the generated files stored? -findObjectDir $PWD +# Cleanup library +rm -f $FOAM_LIBBIN/librunTimePostProcessing* 2>/dev/null + +# Cleanup generated files +findObjectDir $PWD # remove entire top-level rm -rf "$objectsDir" > /dev/null 2>&1 #------------------------------------------------------------------------------ diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwmake b/src/functionObjects/graphics/runTimePostProcessing/Allwmake index 4b2ad8b107fc5336757df7975f1b4e3f5fa17030..d7d73741dc0967dfd1d7425be1b6e339f38d0bf0 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwmake +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwmake @@ -1,52 +1,31 @@ #!/bin/sh cd ${0%/*} || exit 1 # Run from this directory -# Source the wmake functions -. $WM_DIR/scripts/wmakeFunctions +# Source CMake functions +. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions -# Ensure CMake gets the correct C/C++ compilers -[ -n "$WM_CC" ] && export CC="$WM_CC" -[ -n "$WM_CXX" ] && export CXX="$WM_CXX" +# ----------------------------------------------------------------------------- echo "======================================================================" echo "${PWD##*/} : $PWD" echo -# CMake into objectsDir, -# with an additional attempt if (possibly incorrect) CMakeCache.txt existed -doCmake() -{ - local sourceDir="$1" - - findObjectDir $sourceDir # Where are generated files stored? - test -f "$objectsDir/CMakeCache.txt" - retry=$? # CMakeCache.txt exists, but sources may have moved - - mkdir -p $objectsDir && \ - ( - cd $objectsDir || exit 1 - - cmake $sourceDir || { - if [ $retry -eq 0 ] - then - echo "Removing CMakeCache.txt and attempt again" - rm -f CMakeCache.txt - cmake $sourceDir - else - exit 1 - fi - } && make - ) -} - +unset depend +if [ -d "$VTK_DIR" ] +then + depend="VTK_DIR=$VTK_DIR" +elif [ -d "$ParaView_DIR" ] +then + depend="ParaView_DIR=$ParaView_DIR" +fi -if [ -d "$VTK_DIR" -o -d "$ParaView_DIR" ] +if [ -n "$depend" ] then if [ "$targetType" != objects ] then if type cmake > /dev/null 2>&1 then - doCmake $PWD || { + cmakeVersioned "$depend" $PWD || { echo echo " WARNING: incomplete build of VTK-based post-processing" echo diff --git a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt index 3e7a61e625fa3cdb4a8ae4d34da60e396cf3b4e3..3f23c20c3edd0d6358fe524cbf6103dc6527a028 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt +++ b/src/functionObjects/graphics/runTimePostProcessing/CMakeLists-Common.txt @@ -32,13 +32,13 @@ add_definitions( set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_FLAGS_DEBUG - "-g -O0 -std=c++0x -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual" + "-g -O0 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual" ) -set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std=c++0x") +set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE - "-O3 -std=c++0x -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual") -set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c++0x") + "-O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual") +set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c++11") # Set output library destination to plugin directory set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} @@ -46,6 +46,12 @@ set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} "" ) +## Record VTK version for general bookkeeping +# file(WRITE +# ${CMAKE_BINARY_DIR}/version +# "VTK_VERSION=${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}\n" +# ) + file(GLOB SOURCE_FILES fieldVisualisationBase.C functionObjectBase.C @@ -75,11 +81,17 @@ add_library( ${SOURCE_FILES} ) +set_target_properties( + runTimePostProcessing + PROPERTIES + VERSION ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION} + SOVERSION ${VTK_MAJOR_VERSION} +) + target_link_libraries( runTimePostProcessing ${VTK_LIBRARIES} ${OPENFOAM_LIBRARIES} ) - #----------------------------------------------------------------------------- diff --git a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H index c531f5070bf390b4cfeb3eb1a44b55966e124483..0f93924c2bdfb5efa4a8ad4abb6cd5e812c9cca0 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H +++ b/src/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.H @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Class - Foam::functionObjects::runTimePostProcessing + Foam::functionObjects::runTimePostPro::runTimePostProcessing Group grpGraphicsFunctionObjects diff --git a/src/functionObjects/graphics/runTimePostProcessing/scene.C b/src/functionObjects/graphics/runTimePostProcessing/scene.C index 4af8b0d0e83f119a19afdc3ac68df3a1546c6209..ea987cff3867fd37942a5d8f651ee12bb208b865 100644 --- a/src/functionObjects/graphics/runTimePostProcessing/scene.C +++ b/src/functionObjects/graphics/runTimePostProcessing/scene.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -179,7 +179,7 @@ void Foam::functionObjects::runTimePostPro::scene::initialise vtkSmartPointer<vtkLightKit> lightKit = vtkSmartPointer<vtkLightKit>::New(); lightKit->AddLightsToRenderer(renderer); - if (clipBox_ != boundBox::greatBox) + if (!clipBox_.empty()) { const point& min = clipBox_.min(); const point& max = clipBox_.max(); @@ -237,7 +237,7 @@ void Foam::functionObjects::runTimePostPro::scene::setCamera // Apply clipping if required // Note: possible optimisation - if the camera is static, this only needs // to be done once on initialisation - if (clipBox_ != boundBox::greatBox) + if (!clipBox_.empty()) { // Call ResetCamera() to fit clip box in view clipBoxActor_->VisibilityOn(); @@ -278,7 +278,7 @@ Foam::functionObjects::runTimePostPro::scene::scene cameraUp_(nullptr), cameraViewAngle_(nullptr), cameraZoom_(nullptr), - clipBox_(boundBox::greatBox), + clipBox_(boundBox::invertedBox), clipBoxActor_(), parallelProjection_(true), nFrameTotal_(1), diff --git a/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C b/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C index 9fbf03f4e11a0abd94ea494fbd37091cc61abd8a..fc301627e8652a789618ee06b948b22ee4527679 100644 --- a/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C +++ b/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C @@ -99,7 +99,7 @@ bool Foam::functionObjects::cloudInfo::read(const dictionary& dict) forAll(names(), i) { Info<< " " << names()[i] << nl; - writeFileHeader(file(i)); + writeFileHeader(files(i)); } Info<< endl; } @@ -148,8 +148,8 @@ bool Foam::functionObjects::cloudInfo::write() if (writeToFile()) { - writeTime(file(i)); - file(i) + writeTime(files(i)); + files(i) << token::TAB << nParcels << token::TAB << massInSystem << token::TAB diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.C b/src/functionObjects/solvers/scalarTransport/scalarTransport.C index 84b68341d8d1325d905127761678be8c9277ffd4..641241b91e6cbb2a7e6fd8c64bf966aa0e53eb28 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.C +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.C @@ -201,7 +201,7 @@ Foam::functionObjects::scalarTransport::scalarTransport resetOnStartUp_(false), schemesField_("unknown-schemesField"), fvOptions_(mesh_), - bounded01_(dict.lookupOrDefault<bool>("bounded01", true)) + bounded01_(dict.lookupOrDefault<Switch>("bounded01", true)) { read(dict); @@ -235,12 +235,7 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) dict.readIfPresent("bounded01", bounded01_); schemesField_ = dict.lookupOrDefault("schemesField", fieldName_); - - constantD_ = false; - if (dict.readIfPresent("D", D_)) - { - constantD_ = true; - } + constantD_ = dict.readIfPresent("D", D_); dict.readIfPresent("nCorr", nCorr_); dict.readIfPresent("resetOnStartUp", resetOnStartUp_); @@ -256,11 +251,11 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict) bool Foam::functionObjects::scalarTransport::execute() { - Log << type() << " write:" << endl; - volScalarField& s = transportedField(); - const surfaceScalarField& phi = + Log << type() << " execute: " << s.name() << endl; + + const surfaceScalarField& phi = mesh_.lookupObject<surfaceScalarField>(phiName_); // Calculate the diffusivity diff --git a/src/functionObjects/solvers/scalarTransport/scalarTransport.H b/src/functionObjects/solvers/scalarTransport/scalarTransport.H index e2570fc7f9f805ce3b9a3e83f9d7785be928c946..bc743e7eea2601e965340214ae3a7ab71eb125c0 100644 --- a/src/functionObjects/solvers/scalarTransport/scalarTransport.H +++ b/src/functionObjects/solvers/scalarTransport/scalarTransport.H @@ -111,17 +111,18 @@ Usage \table Property | Description | Required | Default value type | Type name: scalarTransport | yes | - phi | Name of flux field | yes | + field | Name of the scalar field | no | s + phi | Name of flux field | no | phi rho | Name of density field | no | rho - phase | Name of the phase name | no | none + phase | Name of the phase | no | none nut | Name of the turbulence viscosity | no | none D | Diffusion coefficient | no | auto generated nCorr | Number of correctors | no | 0 resetOnStartUp | Reset scalar to zero on start-up | no | no - schemesField | Name of field to specify schemes | no | fieldName + schemesField | Name of field to specify schemes | no | field name fvOptions | List of scalar sources | no | - bounded01 | Bounds scalar between 0-1 for multiphase | no |true - phasePhiCompressed |Compressed flux for VOF | no | alphaPhiUn + bounded01 | Bounds scalar between 0-1 for multiphase | no | true + phasePhiCompressed | Compressed flux for VOF | no | alphaPhiUn \endtable See also @@ -156,10 +157,10 @@ class scalarTransport { // Private data - //- Name of field to process + //- Name of the transport field. word fieldName_; - //- Name of flux field + //- Name of flux field (optional) word phiName_; //- Name of density field (optional) @@ -168,10 +169,10 @@ class scalarTransport //- Name of turbulent viscosity field (optional) word nutName_; - //- Name of phase field + //- Name of phase field (optional) word phaseName_; - //- Name of phase field compressed flux + //- Name of phase field compressed flux (optional) word phasePhiCompressedName_; //- Diffusion coefficient (optional) diff --git a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C index c6d79d45b16ca998377a84a889e098ff3b59ba91..768618bf5e0aa399c0d192d08331f48b3db3c45e 100644 --- a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C +++ b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -199,21 +199,9 @@ void Foam::shellSurfaces::orient() if (shell.triSurface::size()) { - const pointField& points = shell.points(); - hasSurface = true; - - boundBox shellBb(points[0], points[0]); // Assume surface is compact! - forAll(points, i) - { - const point& pt = points[i]; - shellBb.min() = min(shellBb.min(), pt); - shellBb.max() = max(shellBb.max(), pt); - } - - overallBb.min() = min(overallBb.min(), shellBb.min()); - overallBb.max() = max(overallBb.max(), shellBb.max()); + overallBb.add(shell.points()); } } } diff --git a/src/meshTools/AABBTree/AABBTree.C b/src/meshTools/AABBTree/AABBTree.C index adbe0ab5adb7e4aa9e83e92bf35e6262ef6cf881..19c11f33a970842855b5b91244a84162d797e6ff 100644 --- a/src/meshTools/AABBTree/AABBTree.C +++ b/src/meshTools/AABBTree/AABBTree.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -198,10 +198,10 @@ void Foam::AABBTree<Type>::createBoxes // Assign the objects to min or max bin DynamicList<label> minBinObjectIDs(objectIDs.size()); - treeBoundBox minBb(point::max, point::min); + treeBoundBox minBb(boundBox::invertedBox); DynamicList<label> maxBinObjectIDs(objectIDs.size()); - treeBoundBox maxBb(point::max, point::min); + treeBoundBox maxBb(boundBox::invertedBox); forAll(objectIDs, i) { @@ -229,16 +229,12 @@ void Foam::AABBTree<Type>::createBoxes if (intoMin) { minBinObjectIDs.append(objI); - const boundBox objBb(points, obj, false); - minBb.min() = min(minBb.min(), objBb.min()); - minBb.max() = max(minBb.max(), objBb.max()); + minBb.add(points, obj); } if (intoMax) { maxBinObjectIDs.append(objI); - const boundBox objBb(points, obj, false); - maxBb.min() = min(maxBb.min(), objBb.min()); - maxBb.max() = max(maxBb.max(), objBb.max()); + maxBb.add(points, obj); } } diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C index 471740a9245dbb838769856b3cb2d3730809df84..73983df95df5689305b3528494841f7d3f6ffd1c 100644 --- a/src/meshTools/indexedOctree/treeDataFace.C +++ b/src/meshTools/indexedOctree/treeDataFace.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,20 +41,7 @@ namespace Foam Foam::treeBoundBox Foam::treeDataFace::calcBb(const label facei) const { - const pointField& points = mesh_.points(); - - const face& f = mesh_.faces()[facei]; - - treeBoundBox bb(points[f[0]], points[f[0]]); - - for (label fp = 1; fp < f.size(); fp++) - { - const point& p = points[f[fp]]; - - bb.min() = min(bb.min(), p); - bb.max() = max(bb.max(), p); - } - return bb; + return treeBoundBox(mesh_.points(), mesh_.faces()[facei]); } diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index 00223a009e6c8abbfc843c7bdf86b6a84c19309d..f1c969762bfae8428589c936d34cb384944e209c 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,26 +31,6 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template<class PatchType> -Foam::treeBoundBox Foam::treeDataPrimitivePatch<PatchType>::calcBb -( - const pointField& points, - const face& f -) -{ - treeBoundBox bb(points[f[0]], points[f[0]]); - - for (label fp = 1; fp < f.size(); fp++) - { - const point& p = points[f[fp]]; - - bb.min() = min(bb.min(), p); - bb.max() = max(bb.max(), p); - } - return bb; -} - - template<class PatchType> void Foam::treeDataPrimitivePatch<PatchType>::update() { @@ -60,7 +40,7 @@ void Foam::treeDataPrimitivePatch<PatchType>::update() forAll(patch_, i) { - bbs_[i] = calcBb(patch_.points(), patch_[i]); + bbs_[i] = treeBoundBox(patch_.points(), patch_[i]); } } } @@ -386,19 +366,14 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps ) const { // 1. Quick rejection: bb does not intersect face bb at all - if (cacheBb_) + if + ( + cacheBb_ + ? !cubeBb.overlaps(bbs_[index]) + : !cubeBb.overlaps(treeBoundBox(patch_.points(), patch_[index])) + ) { - if (!cubeBb.overlaps(bbs_[index])) - { - return false; - } - } - else - { - if (!cubeBb.overlaps(calcBb(patch_.points(), patch_[index]))) - { - return false; - } + return false; } @@ -459,19 +434,14 @@ bool Foam::treeDataPrimitivePatch<PatchType>::overlaps ) const { // 1. Quick rejection: sphere does not intersect face bb at all - if (cacheBb_) - { - if (!bbs_[index].overlaps(centre, radiusSqr)) - { - return false; - } - } - else + if + ( + cacheBb_ + ? !bbs_[index].overlaps(centre, radiusSqr) + : !treeBoundBox(patch_.points(),patch_[index]).overlaps(centre, radiusSqr) + ) { - if (!calcBb(patch_.points(), patch_[index]).overlaps(centre, radiusSqr)) - { - return false; - } + return false; } const pointField& points = patch_.points(); diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H index b1dd87b5175bad199966a56498850e8254c56cf7..ad0a00b1ffaad7683f21140617b4e3162cf1b5d9 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H @@ -80,9 +80,6 @@ class treeDataPrimitivePatch // Private Member Functions - //- Calculate face bounding box - static treeBoundBox calcBb(const pointField&, const face&); - //- Initialise all member data void update(); diff --git a/src/meshTools/searchableSurface/searchableSurfaceCollection.C b/src/meshTools/searchableSurface/searchableSurfaceCollection.C index e85200a8b026c70b3d3b4b064ee916a079710be6..e61b690e9e2c4d25a86f0e7597178295467ee237 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceCollection.C +++ b/src/meshTools/searchableSurface/searchableSurfaceCollection.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -244,8 +244,8 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection subGeom_.setSize(surfI); indexOffset_.setSize(surfI+1); - // Bounds is the overall bounds - bounds() = boundBox(point::max, point::min); + // Bounds is the overall bounds - prepare for min/max ops + bounds() = boundBox::invertedBox; forAll(subGeom_, surfI) { diff --git a/src/meshTools/searchableSurface/searchableSurfacesQueries.C b/src/meshTools/searchableSurface/searchableSurfacesQueries.C index 12b88dbbc924c2b6246298c3e54f9e16e511a6d7..9b8788c1a48f29462c9a4900695262bb65aa2e12 100644 --- a/src/meshTools/searchableSurface/searchableSurfacesQueries.C +++ b/src/meshTools/searchableSurface/searchableSurfacesQueries.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -659,18 +659,14 @@ Foam::boundBox Foam::searchableSurfacesQueries::bounds const labelList& surfacesToTest ) { - pointField bbPoints(2*surfacesToTest.size()); + boundBox bb(boundBox::invertedBox); - forAll(surfacesToTest, testI) + forAll(surfacesToTest, testi) { - const searchableSurface& surface(allSurfaces[surfacesToTest[testI]]); - - bbPoints[2*testI] = surface.bounds().min(); - - bbPoints[2*testI + 1] = surface.bounds().max(); + bb.add(allSurfaces[surfacesToTest[testi]].bounds()); } - return boundBox(bbPoints); + return bb; } diff --git a/src/meshTools/tetOverlapVolume/tetOverlapVolume.C b/src/meshTools/tetOverlapVolume/tetOverlapVolume.C index cc54720dd33afbaa3d384ae80546079b3fdf7c82..73a5b67fbd9046b4fc822dda311bd4e8eaef5de5 100644 --- a/src/meshTools/tetOverlapVolume/tetOverlapVolume.C +++ b/src/meshTools/tetOverlapVolume/tetOverlapVolume.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,13 +55,9 @@ Foam::treeBoundBox Foam::tetOverlapVolume::pyrBb const point& fc ) { - treeBoundBox bb(fc, fc); - forAll(f, fp) - { - const point& pt = points[f[fp]]; - bb.min() = min(bb.min(), pt); - bb.max() = max(bb.max(), pt); - } + treeBoundBox bb(fc); + bb.add(points, f); + return bb; } diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 38cb229c7dfbbdb3fbeeb7677f4b0f5c85c8e91b..0f18e2a0b0f93394767720909dcaf0e8c3bdd592 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -891,39 +891,28 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs // Find bounding box for all triangles on new distribution. - // Initialise to inverted box (VGREAT, -VGREAT) + // Initialise to inverted box List<List<treeBoundBox>> bbs(Pstream::nProcs()); forAll(bbs, procI) { - bbs[procI].setSize(1); - //bbs[procI][0] = boundBox::invertedBox; - bbs[procI][0].min() = point( VGREAT, VGREAT, VGREAT); - bbs[procI][0].max() = point(-VGREAT, -VGREAT, -VGREAT); + bbs[procI].setSize(1, treeBoundBox(boundBox::invertedBox)); } forAll(s, triI) { - point& bbMin = bbs[distribution[triI]][0].min(); - point& bbMax = bbs[distribution[triI]][0].max(); - const triSurface::FaceType& f = s[triI]; - forAll(f, fp) - { - const point& pt = s.points()[f[fp]]; - bbMin = ::Foam::min(bbMin, pt); - bbMax = ::Foam::max(bbMax, pt); - } + + treeBoundBox& bb = bbs[distribution[triI]][0]; + bb.add(s.points(), f); } // Now combine for all processors and convert to correct format. forAll(bbs, procI) { - forAll(bbs[procI], i) - { - reduce(bbs[procI][i].min(), minOp<point>()); - reduce(bbs[procI][i].max(), maxOp<point>()); - } + Pstream::listCombineGather(bbs[procI], plusEqOp<boundBox>()); + Pstream::listCombineScatter(bbs[procI]); } + return bbs; } @@ -937,17 +926,14 @@ bool Foam::distributedTriSurfaceMesh::overlaps const point& p2 ) { + treeBoundBox triBb(p0); + triBb.add(p1); + triBb.add(p2); + forAll(bbs, bbI) { const treeBoundBox& bb = bbs[bbI]; - treeBoundBox triBb(p0, p0); - triBb.min() = min(triBb.min(), p1); - triBb.min() = min(triBb.min(), p2); - - triBb.max() = max(triBb.max(), p1); - triBb.max() = max(triBb.max(), p2); - // Exact test of triangle intersecting bb // Quick rejection. If whole bounding box of tri is outside cubeBb then @@ -1334,8 +1320,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh { read(); - reduce(bounds().min(), minOp<point>()); - reduce(bounds().max(), maxOp<point>()); + bounds().reduce(); if (debug) { @@ -1390,8 +1375,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io) { read(); - reduce(bounds().min(), minOp<point>()); - reduce(bounds().max(), maxOp<point>()); + bounds().reduce(); if (debug) { @@ -1452,8 +1436,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh { read(); - reduce(bounds().min(), minOp<point>()); - reduce(bounds().max(), maxOp<point>()); + bounds().reduce(); if (debug) { @@ -2026,7 +2009,7 @@ Foam::triSurface Foam::distributedTriSurfaceMesh::overlappingSurface const scalar eps = 1.0e-4; forAll(bbs, i) { - const point mid = 0.5*(bbs[i].min() + bbs[i].max()); + const point mid = bbs[i].midpoint(); const vector halfSpan = (1.0+eps)*(bbs[i].max() - mid); bbsX[i].min() = mid - halfSpan; @@ -2434,8 +2417,7 @@ void Foam::distributedTriSurfaceMesh::writeStats(Ostream& os) const boundBox bb; label nPoints; PatchTools::calcBounds(static_cast<const triSurface&>(*this), bb, nPoints); - reduce(bb.min(), minOp<point>()); - reduce(bb.max(), maxOp<point>()); + bb.reduce(); os << "Triangles : " << returnReduce(triSurface::size(), sumOp<label>()) << endl diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 8dbf6e93945abde3bbc36aa25d6a309aa508b2fc..01cce604966811c246045d285390e7fdba8efbba 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -48,7 +48,6 @@ sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C surfWriters = sampledSurface/writers $(surfWriters)/surfaceWriter.C -$(surfWriters)/dx/dxSurfaceWriter.C $(surfWriters)/ensight/ensightSurfaceWriter.C $(surfWriters)/foam/foamSurfaceWriter.C $(surfWriters)/nastran/nastranSurfaceWriter.C diff --git a/src/sampling/meshToMesh/meshToMeshParallelOps.C b/src/sampling/meshToMesh/meshToMeshParallelOps.C index 3d2173693fb3a8887a73b39e90560d7e3cdb01e9..b50341c42bf010fc6ccc0a5db91beff3df9d9ed7 100644 --- a/src/sampling/meshToMesh/meshToMeshParallelOps.C +++ b/src/sampling/meshToMesh/meshToMeshParallelOps.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -177,14 +177,13 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap const cell& c = cells[celli]; // determine bounding box of tgt cell - boundBox cellBb(point::max, point::min); + boundBox cellBb(boundBox::invertedBox); forAll(c, facei) { const face& f = faces[c[facei]]; forAll(f, fp) { - cellBb.min() = min(cellBb.min(), points[f[fp]]); - cellBb.max() = max(cellBb.max(), points[f[fp]]); + cellBb.add(points, f); } } diff --git a/src/sampling/probes/patchProbes.C b/src/sampling/probes/patchProbes.C index 80694beb77409fdfc84456cddb85178048efbc69..6fb89affa5f0f068c4875029813848076053bc77 100644 --- a/src/sampling/probes/patchProbes.C +++ b/src/sampling/probes/patchProbes.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,7 +69,7 @@ void Foam::patchProbes::findElements(const fvMesh& mesh) { // Collect mesh faces and bounding box labelList bndFaces(nFaces); - treeBoundBox overallBb(treeBoundBox::invertedBox); + treeBoundBox overallBb(boundBox::invertedBox); nFaces = 0; forAll(patchIDs, i) @@ -79,12 +79,9 @@ void Foam::patchProbes::findElements(const fvMesh& mesh) { bndFaces[nFaces++] = pp.start()+i; const face& f = pp[i]; - forAll(f, fp) - { - const point& pt = pp.points()[f[fp]]; - overallBb.min() = min(overallBb.min(), pt); - overallBb.max() = max(overallBb.max(), pt); - } + + // Without reduction. + overallBb.add(pp.points(), f); } } diff --git a/src/sampling/sampledSet/patchCloud/patchCloudSet.C b/src/sampling/sampledSet/patchCloud/patchCloudSet.C index 93b1f9c6d0ac0c698ce80b25f9a78a53ccaf8614..f2f401a778cca4cff49756d2367007eb3c29975e 100644 --- a/src/sampling/sampledSet/patchCloud/patchCloudSet.C +++ b/src/sampling/sampledSet/patchCloud/patchCloudSet.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -74,7 +74,7 @@ void Foam::patchCloudSet::calcSamples labelList patchFaces(sz); sz = 0; - treeBoundBox bb(point::max, point::min); + treeBoundBox bb(boundBox::invertedBox); forAllConstIter(labelHashSet, patchSet_, iter) { const polyPatch& pp = mesh().boundaryMesh()[iter.key()]; @@ -84,11 +84,8 @@ void Foam::patchCloudSet::calcSamples patchFaces[sz++] = pp.start()+i; } - // Do not do reduction. - const boundBox patchBb(pp.points(), pp.meshPoints(), false); - - bb.min() = min(bb.min(), patchBb.min()); - bb.max() = max(bb.max(), patchBb.max()); + // Without reduction. + bb.add(pp.points(), pp.meshPoints()); } // Not very random @@ -97,8 +94,8 @@ void Foam::patchCloudSet::calcSamples bb = bb.extend(rndGen, 1e-4); // Make sure bb is 3D. - bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); - bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + bb.min() -= point::uniform(ROOTVSMALL); + bb.max() += point::uniform(ROOTVSMALL); indexedOctree<treeDataFace> patchTree diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index ebb16d8e3716cddb6bbc452ad0e2de37b32c23fa..242bce5982c4180501cc49b2b4755e9c387cd31c 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -334,7 +334,7 @@ Foam::distanceSurface::distanceSurface cell_(dict.lookupOrDefault("cell", true)), regularise_(dict.lookupOrDefault("regularise", true)), average_(dict.lookupOrDefault("average", false)), - bounds_(dict.lookupOrDefault("bounds", boundBox::greatBox)), + bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)), zoneKey_(keyType::null), needsUpdate_(true), isoSurfCellPtr_(nullptr), diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index 4f28ad9acddd8500d57c9c1590b0c576c1e122f0..8a7a0507d7551f894668d780af149d34c3ac287a 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -145,7 +145,7 @@ public: const bool cell, const Switch regularise, const Switch average, - const boundBox& bounds = boundBox::greatBox + const boundBox& bounds = boundBox::invertedBox ); diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index a63cd5132ed27850bfe020c1f26b462d7787ce6a..5bb6cd0b5914f4c7adca4ff7469b09e3ee67a328 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -468,7 +468,7 @@ Foam::sampledIsoSurface::sampledIsoSurface sampledSurface(name, mesh, dict), isoField_(dict.lookup("isoField")), isoVal_(readScalar(dict.lookup("isoValue"))), - bounds_(dict.lookupOrDefault("bounds", boundBox::greatBox)), + bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)), mergeTol_(dict.lookupOrDefault("mergeTol", 1e-6)), regularise_(dict.lookupOrDefault("regularise", true)), average_(dict.lookupOrDefault("average", false)), diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C index 7b7628fdad8aa8f30fae7ceb1b161e4e8d284f60..5690220b7c0ca8d00511b116c7d6dc59771378dc 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -207,7 +207,7 @@ Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell MeshStorage(), isoField_(dict.lookup("isoField")), isoVal_(readScalar(dict.lookup("isoValue"))), - bounds_(dict.lookupOrDefault("bounds", boundBox::greatBox)), + bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)), regularise_(dict.lookupOrDefault("regularise", true)), average_(dict.lookupOrDefault("average", true)), zoneKey_(keyType::null), diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 875ee8ca777280da024d97eece3a633bb15734fa..ef1217b7ed257ac1881ed5184bbb613d14ff866c 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -263,7 +263,7 @@ Foam::sampledCuttingPlane::sampledCuttingPlane : sampledSurface(name, mesh, dict), plane_(dict), - bounds_(dict.lookupOrDefault("bounds", boundBox::greatBox)), + bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)), mergeTol_(dict.lookupOrDefault("mergeTol", 1e-6)), regularise_(dict.lookupOrDefault("regularise", true)), average_(dict.lookupOrDefault("average", false)), diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 135338d1fad82c67ec3a453ec823c06b17ad29ad..33ace2cd2c85f7bcbf6962363a852f3786639173 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -27,7 +27,7 @@ License #include "dictionary.H" #include "polyMesh.H" #include "volFields.H" - +#include "coordinateSystem.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index b625675eff24ab7e28d232ba254fd7b64ab15056..f0148f8ca64b2b35f536d8a8705348a0548efeac 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -63,7 +63,6 @@ SourceFiles #include "surfaceFieldsFwd.H" #include "surfaceMesh.H" #include "polyMesh.H" -#include "coordinateSystems.H" #include "interpolation.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 3b225adc6a95f66db32891b98a337b0409b68f46..f79bdf3a6813e971d43a7b452ad5487bf1123afa 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -778,8 +778,8 @@ bool Foam::sampledTriSurfaceMesh::update() surface_.triSurface::points(), surface_.triSurface::meshPoints() ); - bb.min() = max(bb.min(), mesh().bounds().min()); - bb.max() = min(bb.max(), mesh().bounds().max()); + + bb.intersect(mesh().bounds()); // Extend a bit const vector span(bb.span()); diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C deleted file mode 100644 index 6f060732570df4b8219498e4138264a5d0004b2f..0000000000000000000000000000000000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ /dev/null @@ -1,234 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "dxSurfaceWriter.H" -#include "makeSurfaceWriterMethods.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - makeSurfaceWriterType(dxSurfaceWriter); -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::dxSurfaceWriter::writeGeometry -( - Ostream& os, - const meshedSurf& surf -) -{ - const pointField& points = surf.points(); - const faceList& faces = surf.faces(); - - // Write vertex coordinates - - os << "# The irregular positions" << nl - << "object 1 class array type float rank 1 shape 3 items " - << points.size() << " data follows" << nl; - - forAll(points, pointi) - { - const point& pt = points[pointi]; - - os << float(pt.x()) << ' ' << float(pt.y()) << ' ' << float(pt.z()) - << nl; - } - os << nl; - - // Write triangles - os << "# The irregular connections (triangles)" << nl - << "object 2 class array type int rank 1 shape 3 items " - << faces.size() << " data follows" << nl; - - forAll(faces, facei) - { - const face& f = faces[facei]; - - if (f.size() != 3) - { - FatalErrorInFunction - << "Face " << facei << " vertices " << f - << " is not a triangle." - << exit(FatalError); - } - - os << f[0] << ' ' << f[1] << ' ' << f[2] << nl; - } - os << "attribute \"element type\" string \"triangles\"" << nl - << "attribute \"ref\" string \"positions\"" << nl << nl; -} - - -void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues) -{ - if (isNodeValues) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; - } - - os << "# the field, with three components: \"positions\"," - << " \"connections\", and \"data\"" << nl - << "object \"irregular positions irregular " - << "connections\" class field" - << nl - << "component \"positions\" value 1" << nl - << "component \"connections\" value 2" << nl - << "component \"data\" value 3" << nl; - - os << "end" << endl; -} - - -namespace Foam -{ - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field<scalar>& values - ) - { - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI]) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field<vector>& values - ) - { - os << "object 3 class array type float rank 1 shape 3 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI].x()) << ' ' - << float(values[elemI].y()) << ' ' - << float(values[elemI].z()) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field<sphericalTensor>& values - ) - { - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(values[elemI][0]) << nl; - } - } - - - template<> - void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field<symmTensor>& values - ) - { - os << "object 3 class array type float rank 2 shape 3 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - const symmTensor& t = values[elemI]; - - 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; - } - } - - - // Write Field<tensor> in DX format - template<> - inline void Foam::dxSurfaceWriter::writeData - ( - Ostream& os, - const Field<tensor>& values - ) - { - 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; - } - } -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::dxSurfaceWriter::dxSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::dxSurfaceWriter::~dxSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// create write methods -defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter); - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H deleted file mode 100644 index 8a169d3beb41c289599e09a76b9d5716e1d8c762..0000000000000000000000000000000000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ /dev/null @@ -1,175 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Class - Foam::dxSurfaceWriter - -Description - A surfaceWriter for OpenDX format. - -SourceFiles - dxSurfaceWriter.C - -\*---------------------------------------------------------------------------*/ - -#ifndef dxSurfaceWriter_H -#define dxSurfaceWriter_H - -#include "surfaceWriter.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class dxSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -class dxSurfaceWriter -: - public surfaceWriter -{ - - // Private Member Functions - - static void writeGeometry(Ostream&, const meshedSurf&); - static void writeTrailer(Ostream&, const bool isNodeValues); - - template<class Type> - static void writeData(Ostream&, const Field<Type>&); - - //- Templated write operation - template<class Type> - fileName writeTemplate - ( - const fileName& outputDir, - const fileName& surfaceName, - const meshedSurf& surf, - const word& fieldName, - const Field<Type>& values, - const bool isNodeValues, - const bool verbose - ) const; - - -public: - - //- Runtime type information - TypeName("dx"); - - - // Constructors - - //- Construct null - dxSurfaceWriter(); - - - //- Destructor - virtual ~dxSurfaceWriter(); - - - // Member Functions - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // <case>/surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field<scalar>& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // <case>/surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field<vector>& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // <case>/surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field<sphericalTensor>& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // <case>/surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field<symmTensor>& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual fileName write - ( - const fileName& outputDir, // <case>/surface/TIME - const fileName& surfaceName, // name of surface - const meshedSurf& surf, - const word& fieldName, // name of field - const Field<tensor>& values, - const bool isNodeValues, - const bool verbose = false - ) const; // override -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "dxSurfaceWriterTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C deleted file mode 100644 index f9bb67c99a089038d4e8e326a0c12deda667c0e1..0000000000000000000000000000000000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C +++ /dev/null @@ -1,80 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "OFstream.H" -#include "OSspecific.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template<class Type> -inline void Foam::dxSurfaceWriter::writeData -( - Ostream& os, - const Field<Type>& values -) -{ - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(0.0) << nl; - } -} - - -template<class Type> -Foam::fileName Foam::dxSurfaceWriter::writeTemplate -( - const fileName& outputDir, - const fileName& surfaceName, - const meshedSurf& surf, - const word& fieldName, - const Field<Type>& values, - const bool isNodeValues, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - OFstream os(outputDir/fieldName + '_' + surfaceName + ".dx"); - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - writeGeometry(os, surf); - writeData(os, values); - writeTrailer(os, isNodeValues); - - return os.name(); -} - - -// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C index b01b09a3552e1385d42f3e095321b93ea383c7a6..dea10f0fd3159cf30e36b272a6e6e556285ec717 100644 --- a/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C +++ b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C @@ -27,6 +27,7 @@ License #include "dictionary.H" #include "polyMesh.H" #include "volFields.H" +#include "coordinateSystem.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H index 010429e390695e558f84812c2e21af28349fcde4..6cfcee33094645c2efe42bd9d31677a5f3e0a752 100644 --- a/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H +++ b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H @@ -52,7 +52,6 @@ SourceFiles #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" #include "polyMesh.H" -#include "coordinateSystems.H" #include "interpolation.H" #include "error.H" #include "IOobjectList.H" diff --git a/src/sampling/surface/isoSurface/isoSurface.C b/src/sampling/surface/isoSurface/isoSurface.C index 4bb5d1549ebb2218826151f9834edc894e3e7593..5ec5ad1667173daa64d6c5f9886e38e495cbbcbd 100644 --- a/src/sampling/surface/isoSurface/isoSurface.C +++ b/src/sampling/surface/isoSurface/isoSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1619,7 +1619,7 @@ Foam::isoSurface::isoSurface DynamicList<label> trimTriMap; // Trimmed to original point labelList trimTriPointMap; - if (bounds_ != boundBox::greatBox) + if (!bounds_.empty()) { trimToBox ( @@ -1652,7 +1652,7 @@ Foam::isoSurface::isoSurface } - if (bounds_ != boundBox::greatBox) + if (!bounds_.empty()) { // Adjust interpolatedPoints_ inplaceRenumber(triPointMergeMap_, interpolatedPoints_); diff --git a/src/sampling/surface/isoSurface/isoSurface.H b/src/sampling/surface/isoSurface/isoSurface.H index d822fd100ed86efb4d9d09cf98a8201cc216c07e..c23044744e9a65586a232c73bb3d4c8f0380e376 100644 --- a/src/sampling/surface/isoSurface/isoSurface.H +++ b/src/sampling/surface/isoSurface/isoSurface.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -411,7 +411,7 @@ public: const scalarField& pointIsoVals, const scalar iso, const bool regularise, - const boundBox& bounds = boundBox::greatBox, + const boundBox& bounds = boundBox::invertedBox, const scalar mergeTol = 1e-6 // fraction of bounding box ); diff --git a/src/sampling/surface/isoSurface/isoSurfaceCell.C b/src/sampling/surface/isoSurface/isoSurfaceCell.C index 33f7ef6e4c85dbd17bfc2d19ccb49271ed64825d..3b22509c38dc994664dfb6e4c4d15b749e03681a 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCell.C +++ b/src/sampling/surface/isoSurface/isoSurfaceCell.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1436,7 +1436,7 @@ Foam::isoSurfaceCell::isoSurfaceCell DynamicList<label> trimTriMap; // Trimmed to original point labelList trimTriPointMap; - if (bounds_ != boundBox::greatBox) + if (!bounds_.empty()) { isoSurface::trimToBox ( @@ -1468,7 +1468,7 @@ Foam::isoSurfaceCell::isoSurfaceCell << " merged triangles." << endl; } - if (bounds_ != boundBox::greatBox) + if (!bounds_.empty()) { // Adjust interpolatedPoints_ inplaceRenumber(triPointMergeMap_, interpolatedPoints_); diff --git a/src/sampling/surface/isoSurface/isoSurfaceCell.H b/src/sampling/surface/isoSurface/isoSurfaceCell.H index c2687f29f6306a6fb1701ec01d2fdcba6ac6492a..25b70d97af43470d8dbada4c971f75de5f4b32af 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCell.H +++ b/src/sampling/surface/isoSurface/isoSurfaceCell.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -330,7 +330,7 @@ public: const scalarField& pointValues, const scalar iso, const bool regularise, - const boundBox& bounds = boundBox::greatBox, + const boundBox& bounds = boundBox::invertedBox, const scalar mergeTol = 1e-6 // fraction of bounding box ); diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index 0529da9941d8fb954e21729541371be6d22187ac..ee598a5228e87c559a0d8c32669eb63f7fba65ec 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -399,7 +399,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write ) { // Auto-detect ASCII/BINARY extension - write(filename, surf, STLCore::DETECT); + write(filename, surf, STLCore::UNKNOWN); } @@ -430,7 +430,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write ) { // Auto-detect ASCII/BINARY extension - write(filename, surf, STLCore::DETECT); + write(filename, surf, STLCore::UNKNOWN); } diff --git a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C index f976ceb902c356ce6e0554c3ab62fb806a23375b..b522df0e561f703e95a67712f92a8e775cdbe1e7 100644 --- a/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C +++ b/src/thermophysicalModels/radiation/radiationModels/solarLoad/faceShading/faceShading.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -264,15 +264,13 @@ void Foam::faceShading::calculate() { includeAllFacesPerPatch[patchI].insert ( - faceI //pp.start() + faceI ); } } } } - labelList triSurfaceToAgglom(5*nFaces); - triSurface localSurface = triangulate ( includePatches, @@ -294,9 +292,10 @@ void Foam::faceShading::calculate() dict ); - surfacesMesh.searchableSurface::write(); - - triSurfaceToAgglom.resize(surfacesMesh.size()); + if (debug) + { + surfacesMesh.searchableSurface::write(); + } scalar maxBounding = 5.0*mag(mesh_.bounds().max() - mesh_.bounds().min()); @@ -324,7 +323,7 @@ void Foam::faceShading::calculate() const vector d(direction_*maxBounding); - start.append(fc - SMALL*d); + start.append(fc - 0.001*d); startIndex.append(myFaceId); @@ -355,7 +354,7 @@ void Foam::faceShading::calculate() ( mesh_.time().path()/"allVisibleFaces.obj", end, - Cfs + start ); } diff --git a/src/triSurface/Make/files b/src/triSurface/Make/files index fab067d63e40e6fe889943c33a08fbd8ae9c8a80..ba9df9c53d6876d8f69c16e56a841f247a1d570c 100644 --- a/src/triSurface/Make/files +++ b/src/triSurface/Make/files @@ -5,8 +5,6 @@ triSurface/stitchTriangles.C interfaces = triSurface/interfaces $(interfaces)/STL/writeSTL.C $(interfaces)/STL/readSTL.C -$(interfaces)/STL/readSTLASCII.L -$(interfaces)/STL/readSTLBINARY.C $(interfaces)/GTS/writeGTS.C $(interfaces)/GTS/readGTS.C $(interfaces)/OBJ/readOBJ.C @@ -16,7 +14,6 @@ $(interfaces)/OFF/readOFF.C $(interfaces)/OFF/writeOFF.C $(interfaces)/TRI/writeTRI.C $(interfaces)/TRI/readTRI.C -$(interfaces)/DX/writeDX.C $(interfaces)/AC3D/readAC.C $(interfaces)/AC3D/writeAC.C $(interfaces)/VTK/readVTK.C diff --git a/src/triSurface/triSurface/interfaces/DX/writeDX.C b/src/triSurface/triSurface/interfaces/DX/writeDX.C deleted file mode 100644 index 9e28c0f5cbb4cc0b23436ebe2f62f1fddc9e981a..0000000000000000000000000000000000000000 --- a/src/triSurface/triSurface/interfaces/DX/writeDX.C +++ /dev/null @@ -1,257 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Description - OpenDX format. Both data-only and scalar/vector data. - -\*---------------------------------------------------------------------------*/ - -#include "triSurface.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -// Geometry (positions + connections) -// writeSorted: sort acc. to patch -void triSurface::writeDXGeometry -( - const bool writeSorted, - Ostream& os -) const -{ - labelList faceMap; - surfacePatchList patches(calcPatches(faceMap)); - - // Print patch names as comment - os << "# Patches:" << endl; - forAll(patches, patchi) - { - os << "# " << patchi << " " - << patches[patchi].name() << endl; - } - os << nl << endl; - - // Write vertex coordinates - - os << "# The irregular positions" << endl - << "object 1 class array type float rank 1 shape 3 items " - << nPoints() << " data follows" << endl; - forAll(localPoints(), pointi) - { - const point& pt = localPoints()[pointi]; - os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; - } - os << endl; - - os << "# The irregular connections (triangles)" << endl - << "object 2 class array type int rank 1 shape 3 items " - << size() << " data follows" << endl; - - if (writeSorted) - { - label faceIndex = 0; - - forAll(patches, patchi) - { - // Print all faces belonging to this patch - - for - ( - label patchFacei = 0; - patchFacei < patches[patchi].size(); - patchFacei++ - ) - { - const label facei = faceMap[faceIndex++]; - const labelledTri& f = localFaces()[facei]; - - os << f[0] << ' ' << f[1] << ' ' << f[2] << endl; - } - } - } - else - { - forAll(*this, facei) - { - const labelledTri& f = localFaces()[facei]; - - os << f[0] << ' ' << f[1] << ' ' << f[2] << endl; - } - } - os << "attribute \"element type\" string \"triangles\"" << endl - << "attribute \"ref\" string \"positions\"" << endl << endl; -} - - -// Standard trailer -void triSurface::writeDXTrailer(Ostream& os) const -{ - os << "# the field, with three components: \"positions\", \"connections\"" - << ", and \"data\"" << endl - << "object \"irregular positions irregular connections\" class field" - << endl - << "component \"positions\" value 1" << endl - << "component \"connections\" value 2" << endl - << "component \"data\" value 3" << endl; -} - - -// Geometry only (data field is either faceIndex or patchIndex) -void triSurface::writeDX(const bool writeSorted, Ostream& os) const -{ - writeDXGeometry(writeSorted, os); - - os << "object 3 class array type float rank 0 items " << size() - << " data follows" << endl; - if (writeSorted) - { - // Write patch number as data - - labelList faceMap; - surfacePatchList patches(calcPatches(faceMap)); - - forAll(patches, patchi) - { - forAll(patches[patchi], patchFacei) - { - os << patchi << endl; - } - } - } - else - { - // Write face number as data - - forAll(*this, facei) - { - os << facei << endl; - } - } - - os << endl << "attribute \"dep\" string \"connections\"" << endl << endl; - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// Geometry + scalar data -void triSurface::writeDX(const scalarField& field, Ostream& os) const -{ - writeDXGeometry(false, os); - - if (field.size() == size()) - { - // Connections dependent data - os << "object 3 class array type float rank 0 items " << field.size() - << " data follows" << endl; - forAll(field, facei) - { - os << field[facei] << endl; - } - os << endl - << "attribute \"dep\" string \"connections\"" << endl << endl; - } - else if (field.size() == nPoints()) - { - // Positions dependent data - os << "object 3 class array type float rank 0 items " << field.size() - << " data follows" << endl; - forAll(field, pointi) - { - os << field[pointi] << endl; - } - os << endl - << "attribute \"dep\" string \"positions\"" << endl << endl; - } - else - { - FatalErrorInFunction - << "Illegal field size " << field.size() << " is not equal " - << " to number of faces " << size() << " or to number " - << " of points " << nPoints() << exit(FatalError); - } - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// Geometry + vector data -void triSurface::writeDX(const vectorField& field, Ostream& os) const -{ - writeDXGeometry(false, os); - - if (field.size() == size()) - { - // Connections dependent data - os << "object 3 class array type float rank 1 shape 3 items " - << field.size() << " data follows" << endl; - forAll(field, facei) - { - os << field[facei].x() << ' ' - << field[facei].y() << ' ' - << field[facei].z() << endl; - } - os << endl - << "attribute \"dep\" string \"connections\"" << endl << endl; - } - else if (field.size() == nPoints()) - { - // Positions dependent data - os << "object 3 class array type float rank 1 shape 3 items " - << field.size() << " data follows" << endl; - forAll(field, pointi) - { - os << field[pointi].x() << ' ' - << field[pointi].y() << ' ' - << field[pointi].z() << endl; - } - os << endl - << "attribute \"dep\" string \"positions\"" << endl << endl; - } - else - { - FatalErrorInFunction - << "Illegal field size " << field.size() << " is not equal " - << " to number of faces " << size() << " or to number " - << " of points " << nPoints() << exit(FatalError); - } - - writeDXTrailer(os); - - os << "end" << endl; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/triSurface/triSurface/interfaces/STL/readSTL.C b/src/triSurface/triSurface/interfaces/STL/readSTL.C index 73dcb174fa448ea9a6dd69048c9279658f2f8904..43c9453a524e045805b69c0561a878d819b626a9 100644 --- a/src/triSurface/triSurface/interfaces/STL/readSTL.C +++ b/src/triSurface/triSurface/interfaces/STL/readSTL.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,50 +23,82 @@ License \*---------------------------------------------------------------------------*/ +#include "STLReader.H" +#include "mergePoints.H" #include "triSurface.H" -#include "IFstream.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool triSurface::readSTL(const fileName& STLfileName) +bool Foam::triSurface::readSTL(const fileName& STLfileName, bool forceBinary) { - token firstToken; + // Read in the values + fileFormats::STLReader reader + ( + STLfileName, + ( + forceBinary + ? fileFormats::STLCore::BINARY + : fileFormats::STLCore::UNKNOWN + ) + ); + + // Stitch points + labelList pointMap; + label nUniquePoints = mergePoints + ( + reader.points(), + ( + // With the merge distance depending on the input format + (reader.stlFormat() == fileFormats::STLCore::BINARY ? 10 : 100) + * SMALL + ), + false, // verbose + pointMap // old to new point map + ); + + const pointField& readpts = reader.points(); + const labelList& zoneIds = reader.zoneIds(); + + pointField& pointLst = storedPoints(); + List<Face>& faceLst = storedFaces(); + + // Sizing + pointLst.setSize(nUniquePoints); + faceLst.setSize(zoneIds.size()); + + // Assign points + forAll(readpts, pointi) { - IFstream str(STLfileName); - - if (!str.good()) - { - return false; - } - firstToken = token(str); + pointLst[pointMap[pointi]] = readpts[pointi]; } - if (firstToken.isWord()) + // Assign triangles + label pointi = 0; + forAll(faceLst, i) { - word firstWord(firstToken.wordToken()); + Face& f = faceLst[i]; - for (size_t i = 0; i < firstWord.size(); i++) - { - firstWord[i] = std::toupper(firstWord[i]); - } + f[0] = pointMap[pointi++]; + f[1] = pointMap[pointi++]; + f[2] = pointMap[pointi++]; + f.region() = zoneIds[i]; + } + + // Set patch names (and sizes) + // - there is likely a more efficient means of doing this + if (reader.stlFormat() == fileFormats::STLCore::ASCII) + { + const List<word>& names = reader.names(); - if (firstWord == "SOLID" || firstWord(5) == "SOLID") + patches_.setSize(names.size()); + forAll(names, namei) { - return readSTLASCII(STLfileName); + patches_[namei].name() = names[namei]; } + setDefaultPatches(); } - return readSTLBINARY(STLfileName); + return true; } - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/triSurface/triSurface/interfaces/STL/readSTLASCII.L b/src/triSurface/triSurface/interfaces/STL/readSTLASCII.L deleted file mode 100644 index 2de0ac13aa3d4baf7b93fa6088430c80c4c99dbd..0000000000000000000000000000000000000000 --- a/src/triSurface/triSurface/interfaces/STL/readSTLASCII.L +++ /dev/null @@ -1,490 +0,0 @@ -/*--------------------------------*- C++ -*----------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -%{ - -#undef yyFlexLexer - - /* ------------------------------------------------------------------------ *\ - ------ local definitions - \* ------------------------------------------------------------------------ */ - -#include "IFstream.H" -#include "triSurface.H" -#include "floatVector.H" -#include "OSspecific.H" -#include "mergePoints.H" -//#include "memInfo.H" - -using namespace Foam; - -// Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called -//! \cond dummy -int yyFlexLexer::yylex() -{ - FatalErrorInFunction - << "Should not have called this function" - << abort(FatalError); - return 0; -} -//! \endcond - -// Dummy yywrap to keep yylex happy at compile time. -// It is called by yylex but is not used as the mechanism to change file. -// See <<EOF>> -//! \cond dummy -#if YY_FLEX_MINOR_VERSION < 6 && YY_FLEX_SUBMINOR_VERSION < 34 -extern "C" int yywrap() -#else -int yyFlexLexer::yywrap() -#endif -{ - return 1; -} -//! \endcond - - -class STLLexer -: - public yyFlexLexer -{ - // Private data - - label nTriangles_; - short region_; // current region - short maxRegion_; // max region - - label lineNo_; - word startError_; - - DynamicList<floatVector> STLpoints_; - //DynamicList<floatVector > STLnormals_; - DynamicList<label> STLlabels_; - HashTable<label, word> STLsolidNames_; - - -public: - - // Constructors - - //- From input stream and the approximate number of vertices in the STL - STLLexer(istream* is, const label approxNpoints); - - - // Member Functions - - //- The lexer function itself - int lex(); - - // Access - - label nTriangles() const - { - return nTriangles_; - } - - DynamicList<floatVector>& STLpoints() - { - return STLpoints_; - } - - //DynamicList<floatVector>& STLnormals() - //{ - // return STLnormals_; - //} - - DynamicList<label>& STLlabels() - { - return STLlabels_; - } - - const HashTable<label, word>& STLsolidNames() const - { - return STLsolidNames_; - } -}; - - -STLLexer::STLLexer(istream* is, const label approxNpoints) -: - yyFlexLexer(is), - - nTriangles_(0), - region_(-1), - maxRegion_(0), - - lineNo_(1), - - STLpoints_(approxNpoints), - //STLnormals_(approxNpoints), - STLlabels_(approxNpoints) -{} - - - /* ------------------------------------------------------------------------ *\ - ------ cppLexer::yylex() - \* ------------------------------------------------------------------------ */ - -#define YY_DECL int STLLexer::lex() - -%} - -one_space [ \t\f\r] -space {one_space}* -some_space {one_space}+ - -alpha [_A-Za-z] -digit [0-9] - -integer {digit}+ -signedInteger [-+]?{digit}+ - -word ([[:alnum:]]|[[:punct:]])* -string {word}({some_space}{word})* - -exponent_part [eE][-+]?{digit}+ -fractional_constant [-+]?(({digit}*"."{digit}+)|({digit}+"."?)) - -floatNum (({fractional_constant}{exponent_part}?)|({digit}+{exponent_part})) - -x {floatNum} -y {floatNum} -z {floatNum} - -solid {space}("solid"|"SOLID"){space} -color {space}("color"|"COLOR"){some_space}{floatNum}{some_space}{floatNum}{some_space}{floatNum}{space} -facet {space}("facet"|"FACET"){space} -normal {space}("normal"|"NORMAL"){space} -point {space}{x}{some_space}{y}{some_space}{z}{space} -outerloop {space}("outer"{some_space}"loop")|("OUTER"{some_space}"LOOP"){space} -vertex {space}("vertex"|"VERTEX"){space} -endloop {space}("endloop"|"ENDLOOP"){space} -endfacet {space}("endfacet"|"ENDFACET"){space} -endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})* - - - /* ------------------------------------------------------------------------ *\ - ----- Exclusive start states ----- - \* ------------------------------------------------------------------------ */ - -%option stack - -%x readSolidName -%x readFacet -%x readNormal -%x readVertices -%x readVertex -%x stlerror - -%% - -%{ - // End of read character pointer returned by strtof - // char* endPtr; - - floatVector normal; - floatVector vertex; - label cmpt = 0; // component index used for reading vertex - - static const char* stateNames[7] = - { - "reading solid", - "reading solid name", - "reading facet", - "reading normal", - "reading vertices", - "reading vertex", - "error" - }; - - static const char* stateExpects[7] = - { - "'solid', 'color', 'facet' or 'endsolid'", - "<string>", - "'normal', 'outer loop' or 'endfacet'", - "<float> <float> <float>", - "'vertex' or 'endloop'", - "<float> <float> <float>", - "" - }; -%} - - - /* ------------------------------------------------------------------------ *\ - ------ Start Lexing ------ - \* ------------------------------------------------------------------------ */ - - /* ------ Reading control header ------ */ - -{solid} { - BEGIN(readSolidName); - } - -<readSolidName>{string} { - word solidName(Foam::string::validate<word>(YYText())); - if (STLsolidNames_.found(solidName)) - { - region_ = STLsolidNames_[solidName]; - } - else - { - region_ = maxRegion_++; - STLsolidNames_.insert(solidName, region_); - } - BEGIN(INITIAL); - } - -<readSolidName>{space}\n { - word solidName("solid"); - if (STLsolidNames_.found(solidName)) - { - region_ = STLsolidNames_[solidName]; - } - else - { - region_ = maxRegion_++; - STLsolidNames_.insert(solidName, region_); - } - - lineNo_++; - - BEGIN(INITIAL); - } - -{color} { - } - -{facet} { - BEGIN(readFacet); - } - -<readFacet>{normal} { - BEGIN(readNormal); - } - -<readNormal>{point} { - /* - normal.x() = strtof(YYText(), &endPtr); - normal.y() = strtof(endPtr, &endPtr); - normal.z() = strtof(endPtr, &endPtr); - STLnormals_.append(normal); - */ - BEGIN(readFacet); - } - -<readFacet>{outerloop} { - BEGIN(readVertices); - } - -<readVertices>{vertex} { - BEGIN(readVertex); - } - -<readVertex>{space}{signedInteger}{space} { - vertex[cmpt++] = atol(YYText()); - - if (cmpt == 3) - { - cmpt = 0; - STLpoints_.append(vertex); - BEGIN(readVertices); - } - } - -<readVertex>{space}{floatNum}{space} { - vertex[cmpt++] = atof(YYText()); - - if (cmpt == 3) - { - cmpt = 0; - STLpoints_.append(vertex); - BEGIN(readVertices); - } - } - -<readVertices>{endloop} { - BEGIN(readFacet); - } - -<readFacet>{endfacet} { - nTriangles_++; - STLlabels_.append(region_); - BEGIN(INITIAL); - } - -{endsolid} { - } - - - /* ------------------ Ignore remaining space and \n s. -------------------- */ - -<*>{space} {} -<*>\n { lineNo_++; } - - - /* ------------------- Any other characters are errors -------------------- */ - -<*>. { - startError_ = YYText(); - yy_push_state(stlerror); - } - - - /* ---------------------------- Error handler ----------------------------- */ - -<stlerror>.* { - yy_pop_state(); - FatalErrorInFunction - << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl - << " expected " << stateExpects[YY_START] - << " but found '" << startError_.c_str() << YYText() << "'" - << exit(FatalError); - } - - - /* ------------------------ On EOF terminate ---------------------------- */ - -<<EOF>> { - yyterminate(); - } -%% - - -#include <fstream> - -bool triSurface::readSTLASCII(const fileName& STLfileName) -{ - IFstream STLstream(STLfileName); - - if (!STLstream) - { - FatalErrorInFunction - << "file " << STLfileName << " not found" - << exit(FatalError); - } - - //memInfo memStat; - - //memStat.update(); - //Pout<< "At start:" << memStat.rss() << endl; - - // Create the lexer obtaining the approximate number of vertices in the STL - // from the file size - STLLexer lexer(&STLstream.stdStream(), Foam::fileSize(STLfileName)/400); - while (lexer.lex() != 0) - {} - - //memStat.update(); - //Pout<< "After lexing:" << memStat.rss() << endl; - - DynamicList<floatVector>& STLpoints = lexer.STLpoints(); - DynamicList<label>& STLlabels = lexer.STLlabels(); - - /* - DynamicList<floatVector>& STLnormals = lexer.STLnormals(); - - if (STLpoints.size() != 3*STLnormals.size()) - { - FatalErrorInFunction - << "in file " << STLfileName << endl - << "Problem: read " << STLnormals.size() << " normals" - << " but " << STLpoints.size() << " points" - << exit(FatalError); - } - */ - - labelList pointMap; - label nUniquePoints = mergePoints - ( - STLpoints, - 100*SMALL, // merge distance - false, // verbose - pointMap - ); - - //memStat.update(); - //Pout<< "After merging:" << memStat.rss() << endl; - - - pointField& sp = storedPoints(); - - setSize(lexer.nTriangles()); - sp.setSize(nUniquePoints); - forAll(STLpoints, pointi) - { - const floatVector& pt = STLpoints[pointi]; - sp[pointMap[pointi]] = vector - ( - scalar(pt.x()), - scalar(pt.y()), - scalar(pt.z()) - ); - } - - // Assign triangles - label pointi = 0; - forAll(*this, i) - { - operator[](i)[0] = pointMap[pointi++]; - operator[](i)[1] = pointMap[pointi++]; - operator[](i)[2] = pointMap[pointi++]; - operator[](i).region() = STLlabels[i]; - } - - //memStat.update(); - //Pout<< "After assigning:" << memStat.rss() << endl; - - - STLpoints.clear(); - STLlabels.clear(); - - - // Convert solidNames into regionNames - patches_.setSize(lexer.STLsolidNames().size()); - - for - ( - HashTable<label, word>::const_iterator iter = - lexer.STLsolidNames().begin(); - iter != lexer.STLsolidNames().end(); - ++iter - ) - { - patches_[iter()].name() = iter.key(); - } - - // Fill in the missing information in the patches - setDefaultPatches(); - - //memStat.update(); - //Pout<< "After patchifying:" << memStat.rss() << endl; - - return true; -} - - - /* ------------------------------------------------------------------------ *\ - ------ End of STLToFoam.L - \* ------------------------------------------------------------------------ */ diff --git a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C b/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C deleted file mode 100644 index d44274b12c04446939050869d233bea324d00634..0000000000000000000000000000000000000000 --- a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C +++ /dev/null @@ -1,152 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "triSurface.H" -#include "STLtriangle.H" -#include "IFstream.H" -#include "OSspecific.H" -#include "gzstream.h" -#include "floatVector.H" -#include "mergePoints.H" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::triSurface::readSTLBINARY(const fileName& STLfileName) -{ - bool compressed = false; - - autoPtr<istream> STLfilePtr - ( - new ifstream(STLfileName.c_str(), std::ios::binary) - ); - - // If the file is compressed, decompress it before reading. - if (!STLfilePtr->good() && isFile(STLfileName + ".gz", false)) - { - compressed = true; - STLfilePtr.reset(new igzstream((STLfileName + ".gz").c_str())); - } - istream& STLfile = STLfilePtr(); - - if (!STLfile.good()) - { - FatalErrorInFunction - << "Cannot read file " << STLfileName - << " or file " << STLfileName + ".gz" - << exit(FatalError); - } - - // Read the STL header - char header[STLheaderSize]; - STLfile.read(header, STLheaderSize); - - // Check that stream is OK, if not this maybe an ASCII file - if (!STLfile) - { - return false; - } - - // Read the number of triangles in the STl file - // (note: read as int so we can check whether >2^31) - int nTris; - STLfile.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); - - // Check that stream is OK and number of triangles is positive, - // if not this maybe an ASCII file - if (!STLfile || nTris < 0) - { - return false; - } - - // Compare the size of the file with that expected from the number of tris - // If the comparison is not sensible then it maybe an ASCII file - if (!compressed) - { - label dataFileSize = Foam::fileSize(STLfileName) - 80; - - if (nTris < dataFileSize/50 || nTris > dataFileSize/25) - { - return false; - } - } - - // Everything OK so go ahead and read the triangles. - - // Allocate storage for raw points - List<floatVector> STLpoints(3*nTris); - setSize(nTris); - - label pointi = 0; - - for (label i = 0; i < nTris; i++) - { - // Read an STL triangle - STLtriangle stlTri(STLfile); - - // Set the STLpoints to the vertices of the STL triangle - STLpoints[pointi++] = stlTri.a(); - STLpoints[pointi++] = stlTri.b(); - STLpoints[pointi++] = stlTri.c(); - operator[](i).region() = stlTri.attrib(); - } - - // Stitch points - labelList pointMap; - label nUniquePoints = mergePoints - ( - STLpoints, - 10*SMALL, // merge distance - false, // verbose - pointMap // old to new - ); - - pointField& sp = storedPoints(); - - sp.setSize(nUniquePoints); - forAll(STLpoints, pointi) - { - const floatVector& pt = STLpoints[pointi]; - sp[pointMap[pointi]] = vector - ( - scalar(pt.x()), - scalar(pt.y()), - scalar(pt.z()) - ); - } - - // Assign triangles - pointi = 0; - forAll(*this, i) - { - operator[](i)[0] = pointMap[pointi++]; - operator[](i)[1] = pointMap[pointi++]; - operator[](i)[2] = pointMap[pointi++]; - } - - return true; -} - - -// ************************************************************************* // diff --git a/src/triSurface/triSurface/interfaces/STL/writeSTL.C b/src/triSurface/triSurface/interfaces/STL/writeSTL.C index 3532b006ab972688d37868b7d5d03fb7c0e5c4d0..fc8c2d0b94e60cf4a691f9703a20141e1f48f650 100644 --- a/src/triSurface/triSurface/interfaces/STL/writeSTL.C +++ b/src/triSurface/triSurface/interfaces/STL/writeSTL.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,9 +24,22 @@ License \*---------------------------------------------------------------------------*/ #include "triSurface.H" -#include "STLtriangle.H" +#include "STLCore.H" #include "primitivePatch.H" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +// A file-scope helper class to expose static member(s) +// This is a temporary measure and is expected to disappear in the future +struct triSurfaceSTLCore +: + public Foam::fileFormats::STLCore +{ + using Foam::fileFormats::STLCore::writeBinaryHeader; +}; + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const @@ -53,26 +66,17 @@ void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const ) { const label facei = faceMap[faceIndex++]; - - const vector& n = faceNormals()[facei]; - - os << " facet normal " - << n.x() << ' ' << n.y() << ' ' << n.z() << nl - << " outer loop" << endl; - const labelledTri& f = (*this)[facei]; - const point& pa = points()[f[0]]; - const point& pb = points()[f[1]]; - const point& pc = points()[f[2]]; - - os << " vertex " - << pa.x() << ' ' << pa.y() << ' ' << pa.z() << nl - << " vertex " - << pb.x() << ' ' << pb.y() << ' ' << pb.z() << nl - << " vertex " - << pc.x() << ' ' << pc.y() << ' ' << pc.z() << nl - << " endloop" << nl - << " endfacet" << endl; + + // Write ASCII + STLtriangle::write + ( + os, + faceNormals()[facei], + points()[f[0]], + points()[f[1]], + points()[f[2]] + ); } os << "endsolid " << patch.name() << endl; @@ -93,46 +97,35 @@ void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const } label currentPatchi = -1; - forAll(*this, facei) { if (currentPatchi != patchIDs[facei]) { if (currentPatchi != -1) { - // Have already valid patch. Close it. - os << "endsolid " << patches[currentPatchi].name() - << nl; + // Close previous solid + os << "endsolid " << patches[currentPatchi].name() << nl; } currentPatchi = patchIDs[facei]; os << "solid " << patches[currentPatchi].name() << nl; } - const vector& n = faceNormals()[facei]; - - os << " facet normal " - << n.x() << ' ' << n.y() << ' ' << n.z() << nl - << " outer loop" << endl; - const labelledTri& f = (*this)[facei]; - const point& pa = points()[f[0]]; - const point& pb = points()[f[1]]; - const point& pc = points()[f[2]]; - - os << " vertex " - << pa.x() << ' ' << pa.y() << ' ' << pa.z() << nl - << " vertex " - << pb.x() << ' ' << pb.y() << ' ' << pb.z() << nl - << " vertex " - << pc.x() << ' ' << pc.y() << ' ' << pc.z() << nl - << " endloop" << nl - << " endfacet" << endl; + + // Write ASCII + STLtriangle::write + ( + os, + faceNormals()[facei], + points()[f[0]], + points()[f[1]], + points()[f[2]] + ); } if (currentPatchi != -1) { - os << "endsolid " << patches[currentPatchi].name() - << nl; + os << "endsolid " << patches[currentPatchi].name() << nl; } } } @@ -141,27 +134,21 @@ void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const void Foam::triSurface::writeSTLBINARY(std::ostream& os) const { // Write the STL header - string header("Foam binary STL", STLheaderSize); - os.write(header.c_str(), STLheaderSize); - - label nTris = size(); - os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); - - const vectorField& normals = faceNormals(); + triSurfaceSTLCore::writeBinaryHeader(os, this->size()); forAll(*this, facei) { const labelledTri& f = (*this)[facei]; - // Convert vector into STL single precision - STLpoint n(normals[facei]); - STLpoint pa(points()[f[0]]); - STLpoint pb(points()[f[1]]); - STLpoint pc(points()[f[2]]); - - STLtriangle stlTri(n, pa, pb, pc, f.region()); - - stlTri.write(os); + // Write BINARY + STLtriangle + ( + faceNormals()[facei], + points()[f[0]], + points()[f[1]], + points()[f[2]], + f.region() + ).write(os); } } diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index 6bc2e9d64bdf2872f34c5feb795b275dbd6adc45..2ea0e6eea8559c835c8ad3cdb512d95c1e5d8319 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -379,7 +379,7 @@ bool Foam::triSurface::read } else if (ext == "stlb") { - return readSTLBINARY(name); + return readSTL(name, true); } else if (ext == "gts") { @@ -464,10 +464,6 @@ void Foam::triSurface::write { writeTRI(sort, OFstream(name)()); } - else if (ext == "dx") - { - writeDX(sort, OFstream(name)()); - } else if (ext == "ac") { writeAC(OFstream(name)()); @@ -483,7 +479,7 @@ void Foam::triSurface::write << " for file " << name << ". Supported extensions are '.ftr', '.stl', '.stlb', " << "'.gts', '.obj', '.vtk'" - << ", '.off', '.dx', '.smesh', '.ac' and '.tri'" + << ", '.off', '.smesh', '.ac' and '.tri'" << exit(FatalError); } } @@ -1110,7 +1106,7 @@ void Foam::triSurface::writeStats(Ostream& os) const PackedBoolList pointIsUsed(points().size()); label nPoints = 0; - boundBox bb = boundBox::invertedBox; + boundBox bb(boundBox::invertedBox); forAll(*this, facei) { @@ -1121,9 +1117,8 @@ void Foam::triSurface::writeStats(Ostream& os) const label pointi = f[fp]; if (pointIsUsed.set(pointi, 1)) { - bb.min() = ::Foam::min(bb.min(), points()[pointi]); - bb.max() = ::Foam::max(bb.max(), points()[pointi]); - nPoints++; + bb.add(points()[pointi]); + ++nPoints; } } } diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index ccf47c713e29bdc26f6990b5a221867cde3dd40b..d6debc7b3a9a267b143e2e99a59e224bf9786db7 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -130,9 +130,7 @@ class triSurface //- Generic read routine. Chooses reader based on extension. bool read(const fileName&, const word& ext, const bool check = true); - bool readSTL(const fileName&); - bool readSTLASCII(const fileName&); - bool readSTLBINARY(const fileName&); + bool readSTL(const fileName&, bool forceBinary=false); bool readGTS(const fileName&); bool readOBJ(const fileName&); bool readOFF(const fileName&); @@ -178,11 +176,6 @@ class triSurface //- Write to Ostream in AC3D format. Always sorted by patch. void writeAC(Ostream&) const; - //- For DX writing. - void writeDX(const bool, Ostream&) const; - void writeDXGeometry(const bool, Ostream&) const; - void writeDXTrailer(Ostream&) const; - // Static private functions diff --git a/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.C b/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.C index a0f47ef919478f9a2333b0ce25ed5116ce367ede..1cadfeefa03716ccf1995b7be0af5a61f8c86655 100644 --- a/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.C +++ b/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -62,7 +62,7 @@ Foam::waveModels::waveAbsorptionModel::waveAbsorptionModel { if (readFields) { - read(dict); + readDict(dict); } } @@ -75,9 +75,12 @@ Foam::waveModels::waveAbsorptionModel::~waveAbsorptionModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::waveAbsorptionModel::read(const dictionary& overrideDict) +bool Foam::waveModels::waveAbsorptionModel::readDict +( + const dictionary& overrideDict +) { - if (waveModel::read(overrideDict)) + if (waveModel::readDict(overrideDict)) { // Note: always set to true activeAbsorption_ = true; diff --git a/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.H b/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.H index 0201aaaab7c94f3dd2671971c51908744fbe0c40..e30b6b5ee7aee3d77db253c19476697fdd361048 100644 --- a/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.H +++ b/src/waveModels/waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -77,7 +77,7 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); }; diff --git a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C index d6c7de6040741090ae545012a9c7f06694444f7c..e4e47820fb2c4e2908313f460b4b7a3c07486452 100644 --- a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C +++ b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -96,7 +96,7 @@ Foam::waveModels::shallowWaterAbsorption::shallowWaterAbsorption { if (readFields) { - read(dict); + readDict(dict); } } @@ -109,12 +109,12 @@ Foam::waveModels::shallowWaterAbsorption::~shallowWaterAbsorption() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::shallowWaterAbsorption::read +bool Foam::waveModels::shallowWaterAbsorption::readDict ( const dictionary& overrideDict ) { - return waveAbsorptionModel::read(overrideDict); + return waveAbsorptionModel::readDict(overrideDict); } diff --git a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.H b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.H index bbc31f78783f87ca856e13755c9f12b6f4d5297f..e390fbfff0cb50a66dc4195f11ab18a285246c8c 100644 --- a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.H +++ b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -94,7 +94,7 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); }; diff --git a/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.C b/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.C index efaa83b5524b4a861a4d61795d656e9eb586dd6c..030c590d2a58490b8140d83d83b22b2ec5264526 100644 --- a/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.C +++ b/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -86,7 +86,7 @@ Foam::waveModels::regularWaveModel::regularWaveModel { if (readFields) { - read(dict); + readDict(dict); } } @@ -99,9 +99,12 @@ Foam::waveModels::regularWaveModel::~regularWaveModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::regularWaveModel::read(const dictionary& overrideDict) +bool Foam::waveModels::regularWaveModel::readDict +( + const dictionary& overrideDict +) { - if (waveGenerationModel::read(overrideDict)) + if (waveGenerationModel::readDict(overrideDict)) { lookup("rampTime") >> rampTime_; diff --git a/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.H b/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.H index 13b6bfda73ef3bd58bae18b6e96c6c6311c83184..43a9a9096f6859dc63168fea33dfb35b2d62a358 100644 --- a/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.H +++ b/src/waveModels/waveGenerationModels/base/regularWaveModel/regularWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -105,12 +105,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.C b/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.C index 332d7e0304d011802dd8dd322724ca75b05d515f..d8d6ab34582aa489469c7239b20b33e59062dcea 100644 --- a/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.C +++ b/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -70,7 +70,7 @@ Foam::waveModels::solitaryWaveModel::solitaryWaveModel { if (readFields) { - read(dict); + readDict(dict); } } @@ -83,9 +83,12 @@ Foam::waveModels::solitaryWaveModel::~solitaryWaveModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::solitaryWaveModel::read(const dictionary& overrideDict) +bool Foam::waveModels::solitaryWaveModel::readDict +( + const dictionary& overrideDict +) { - if (waveGenerationModel::read(overrideDict)) + if (waveGenerationModel::readDict(overrideDict)) { return true; } diff --git a/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.H b/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.H index f01dff404c3d44de7b12377d07619b79a2a8946d..e0724d341371f73beacfc8a37b167384b642582c 100644 --- a/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.H +++ b/src/waveModels/waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -87,12 +87,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.C b/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.C index 44cf01006b305e6123d849dd3f43d17dc8d34268..5e52d9de93234b33a669a54f4fc2d852595f5877 100644 --- a/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.C +++ b/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -55,7 +55,7 @@ Foam::waveModels::waveGenerationModel::waveGenerationModel { if (readFields) { - read(dict); + readDict(dict); } } @@ -68,9 +68,12 @@ Foam::waveModels::waveGenerationModel::~waveGenerationModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::waveGenerationModel::read(const dictionary& overrideDict) +bool Foam::waveModels::waveGenerationModel::readDict +( + const dictionary& overrideDict +) { - if (waveModel::read(overrideDict)) + if (waveModel::readDict(overrideDict)) { lookup("activeAbsorption") >> activeAbsorption_; diff --git a/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.H b/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.H index c0ed643e7b9467975acfc5c24f90ec696bf9b485..aee9213ed69fd72813e9f03e2aaa357fb7954042 100644 --- a/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.H +++ b/src/waveModels/waveGenerationModels/base/waveGenerationModel/waveGenerationModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -80,7 +80,7 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; diff --git a/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.C b/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.C index d7e4dca2fc592d56f394e0730593b00a5c33bab6..a81f32dd8aed5f41d145218db78a845d4f941732 100644 --- a/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.C +++ b/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -101,7 +101,7 @@ Foam::vector Foam::waveModels::Boussinesq::Deta } -Foam::vector Foam::waveModels::Boussinesq::U +Foam::vector Foam::waveModels::Boussinesq::Uf ( const scalar H, const scalar h, @@ -139,6 +139,8 @@ Foam::vector Foam::waveModels::Boussinesq::U } +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + void Foam::waveModels::Boussinesq::setLevel ( const scalar t, @@ -165,44 +167,6 @@ void Foam::waveModels::Boussinesq::setLevel } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::waveModels::Boussinesq::Boussinesq -( - const dictionary& dict, - const fvMesh& mesh, - const polyPatch& patch, - const bool readFields -) -: - solitaryWaveModel(dict, mesh, patch, false) -{ - if (readFields) - { - read(dict); - } -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::waveModels::Boussinesq::~Boussinesq() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::waveModels::Boussinesq::read(const dictionary& overrideDict) -{ - if (solitaryWaveModel::read(overrideDict)) - { - return true; - } - - return false; -} - - void Foam::waveModels::Boussinesq::setVelocity ( const scalar t, @@ -224,7 +188,7 @@ void Foam::waveModels::Boussinesq::setVelocity { const label paddlei = faceToPaddle_[facei]; - const vector Uf = U + const vector Uf = this->Uf ( waveHeight_, waterDepthRef_, @@ -242,6 +206,44 @@ void Foam::waveModels::Boussinesq::setVelocity } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::waveModels::Boussinesq::Boussinesq +( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields +) +: + solitaryWaveModel(dict, mesh, patch, false) +{ + if (readFields) + { + readDict(dict); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::waveModels::Boussinesq::~Boussinesq() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::waveModels::Boussinesq::readDict(const dictionary& overrideDict) +{ + if (solitaryWaveModel::readDict(overrideDict)) + { + return true; + } + + return false; +} + + void Foam::waveModels::Boussinesq::info(Ostream& os) const { solitaryWaveModel::info(os); diff --git a/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.H b/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.H index ff76841a818fcc57b06cedea59b49cb9823d8ac6..b5071d28176fd47e1a9b086578f81b8c773ffde9 100644 --- a/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.H +++ b/src/waveModels/waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -49,12 +49,12 @@ class Boussinesq : public solitaryWaveModel { -protected: +private: - // Protected Member Functions + // Private Member Functions //- Wave height - virtual scalar eta + scalar eta ( const scalar H, const scalar h, @@ -66,7 +66,7 @@ protected: ) const; //- Wave - virtual vector Deta + vector Deta ( const scalar H, const scalar h, @@ -78,7 +78,7 @@ protected: ) const; //- Wave velocity - virtual vector U + vector Uf ( const scalar H, const scalar h, @@ -90,6 +90,11 @@ protected: const scalar z ) const; + +protected: + + // Protected Member Functions + //- Set the water level virtual void setLevel ( @@ -128,12 +133,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.C b/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.C index 8a67ea2a2db4ae3349cf47440d211dd4b82f7852..b1609348513de314a6a5d5b79f5d22f5c20e1440 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.C +++ b/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -48,6 +48,26 @@ namespace waveModels // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // +Foam::scalar Foam::waveModels::StokesI::eta +( + const scalar H, + const scalar Kx, + const scalar x, + const scalar Ky, + const scalar y, + const scalar omega, + const scalar t, + const scalar phase +) const +{ + scalar phaseTot = Kx*x + Ky*y - omega*t + phase; + + return H*0.5*cos(phaseTot); +} + + +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + Foam::scalar Foam::waveModels::StokesI::waveLength ( const scalar h, @@ -66,24 +86,7 @@ Foam::scalar Foam::waveModels::StokesI::waveLength } -Foam::scalar Foam::waveModels::StokesI::eta -( - const scalar H, - const scalar Kx, - const scalar x, - const scalar Ky, - const scalar y, - const scalar omega, - const scalar t, - const scalar phase -) const -{ - scalar phaseTot = Kx*x + Ky*y - omega*t + phase; - - return H*0.5*cos(phaseTot); -} - -Foam::vector Foam::waveModels::StokesI::U +Foam::vector Foam::waveModels::StokesI::UfBase ( const scalar H, const scalar h, @@ -141,46 +144,6 @@ void Foam::waveModels::StokesI::setLevel } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::waveModels::StokesI::StokesI -( - const dictionary& dict, - const fvMesh& mesh, - const polyPatch& patch, - const bool readFields -) -: - regularWaveModel(dict, mesh, patch, false) -{ - if (readFields) - { - read(dict); - } -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::waveModels::StokesI::~StokesI() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::waveModels::StokesI::read(const dictionary& overrideDict) -{ - if (regularWaveModel::read(overrideDict)) - { - waveLength_ = waveLength(waterDepthRef_, wavePeriod_); - - return true; - } - - return false; -} - - void Foam::waveModels::StokesI::setVelocity ( const scalar t, @@ -207,7 +170,7 @@ void Foam::waveModels::StokesI::setVelocity { const label paddlei = faceToPaddle_[facei]; - const vector Uf = U + const vector Uf = UfBase ( waveHeight_, waterDepthRef_, @@ -227,6 +190,46 @@ void Foam::waveModels::StokesI::setVelocity } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::waveModels::StokesI::StokesI +( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields +) +: + regularWaveModel(dict, mesh, patch, false) +{ + if (readFields) + { + readDict(dict); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::waveModels::StokesI::~StokesI() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::waveModels::StokesI::readDict(const dictionary& overrideDict) +{ + if (regularWaveModel::readDict(overrideDict)) + { + waveLength_ = waveLength(waterDepthRef_, wavePeriod_); + + return true; + } + + return false; +} + + void Foam::waveModels::StokesI::info(Ostream& os) const { regularWaveModel::info(os); diff --git a/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.H b/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.H index 82213261bf8add3c84dec42e4a969471c4fe3983..23a3f67e42881c36d8b004153f028ba276a259d3 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.H +++ b/src/waveModels/waveGenerationModels/derived/StokesI/StokesIWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -49,15 +49,12 @@ class StokesI : public regularWaveModel { -protected: - - // Protected Member Functions +private: - //- Return the wavelength - virtual scalar waveLength(const scalar h, const scalar T) const; + // Private Member Functions //- Wave height - virtual scalar eta + scalar eta ( const scalar H, const scalar Kx, @@ -69,8 +66,16 @@ protected: const scalar phase ) const; + +protected: + + // Protected Member Functions + + //- Return the wavelength + virtual scalar waveLength(const scalar h, const scalar T) const; + //- Wave velocity - virtual vector U + virtual vector UfBase ( const scalar H, const scalar h, @@ -84,7 +89,6 @@ protected: const scalar z ) const; - //- Set the water level virtual void setLevel ( @@ -123,12 +127,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.C b/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.C index b867959f8c91f4bf9dfe82d4a97fa4f37b62f9ca..e77122fd052a85bc140040c378abc144928dd69a 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.C +++ b/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -71,7 +71,9 @@ Foam::scalar Foam::waveModels::StokesII::eta } -Foam::vector Foam::waveModels::StokesII::U +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + +Foam::vector Foam::waveModels::StokesII::UfBase ( const scalar H, const scalar h, @@ -148,7 +150,7 @@ Foam::waveModels::StokesII::StokesII { if (readFields) { - read(dict); + readDict(dict); } } @@ -161,9 +163,9 @@ Foam::waveModels::StokesII::~StokesII() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::StokesII::read(const dictionary& overrideDict) +bool Foam::waveModels::StokesII::readDict(const dictionary& overrideDict) { - if (StokesI::read(overrideDict)) + if (StokesI::readDict(overrideDict)) { return true; } diff --git a/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.H b/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.H index 044eba4bc57cb9130e8215ca648212d56869874f..c82325b5f54c5c274832b1e261a98afe4e481dda 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.H +++ b/src/waveModels/waveGenerationModels/derived/StokesII/StokesIIWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -49,12 +49,12 @@ class StokesII : public StokesI { -protected: +private: - // Protected Member Functions + // Private Member Functions //- Wave height - virtual scalar eta + scalar eta ( const scalar H, const scalar h, @@ -67,8 +67,13 @@ protected: const scalar phase ) const; + +protected: + + // Protected Member Functions + //- Wave velocity - virtual vector U + virtual vector UfBase ( const scalar H, const scalar h, @@ -112,12 +117,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.C b/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.C index 643acedeb24b848de3334929c6e63df9bfbbf003..4ba32ea4450e51a79040722b5314b090bc4ca506 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.C +++ b/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -680,7 +680,7 @@ Foam::scalar Foam::waveModels::StokesV::eta } -Foam::vector Foam::waveModels::StokesV::U +Foam::vector Foam::waveModels::StokesV::Uf ( const scalar d, const scalar kx, @@ -722,17 +722,17 @@ Foam::vector Foam::waveModels::StokesV::U scalar u = a1u*cosh(k*z)*cos(theta) - + a2u*cosh(2.0*k*z)*cos(2.0*(theta)) - + a3u*cosh(3.0*k*z)*cos(3.0*(theta)) - + a4u*cosh(4.0*k*z)*cos(4.0*(theta)) - + a5u*cosh(5.0*k*z)*cos(5.0*(theta)); + + a2u*cosh(2*k*z)*cos(2*theta) + + a3u*cosh(3*k*z)*cos(3*theta) + + a4u*cosh(4*k*z)*cos(4*theta) + + a5u*cosh(5*k*z)*cos(5*theta); scalar w = a1u*sinh(k*z)*sin(theta) - + a2u*sinh(2.0*k*z)*sin(2.0*(theta)) - + a3u*sinh(3.0*k*z)*sin(3.0*(theta)) - + a4u*sinh(4.0*k*z)*sin(4.0*(theta)) - + a5u*sinh(5.0*k*z)*sin(5.0*(theta)); + + a2u*sinh(2*k*z)*sin(2*theta) + + a3u*sinh(3*k*z)*sin(3*theta) + + a4u*sinh(4*k*z)*sin(4*theta) + + a5u*sinh(5*k*z)*sin(5*theta); scalar v = u*sin(waveAngle_); u *= cos(waveAngle_); @@ -741,6 +741,8 @@ Foam::vector Foam::waveModels::StokesV::U } +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + void Foam::waveModels::StokesV::setLevel ( const scalar t, @@ -773,6 +775,51 @@ void Foam::waveModels::StokesV::setLevel } +void Foam::waveModels::StokesV::setVelocity +( + const scalar t, + const scalar tCoeff, + const scalarField& level +) +{ + const scalar waveK = mathematical::twoPi/waveLength_; + const scalar waveKx = waveK*cos(waveAngle_); + const scalar waveKy = waveK*sin(waveAngle_); + + forAll(U_, facei) + { + // Fraction of geometry represented by paddle - to be set + scalar fraction = 1; + + // Height - to be set + scalar z = 0; + + setPaddlePropeties(level, facei, fraction, z); + + if (fraction > 0) + { + const label paddlei = faceToPaddle_[facei]; + + const vector Uf = this->Uf + ( + waterDepthRef_, + waveKx, + waveKy, + lambda_, + wavePeriod_, + xPaddle_[paddlei], + yPaddle_[paddlei], + t, + wavePhase_, + z + ); + + U_[facei] = fraction*Uf*tCoeff; + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::waveModels::StokesV::StokesV @@ -783,12 +830,12 @@ Foam::waveModels::StokesV::StokesV const bool readFields ) : - regularWaveModel(dict, mesh, patch, false), + StokesI(dict, mesh, patch, false), lambda_(0) { if (readFields) { - read(dict); + readDict(dict); } } @@ -801,9 +848,9 @@ Foam::waveModels::StokesV::~StokesV() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::StokesV::read(const dictionary& overrideDict) +bool Foam::waveModels::StokesV::readDict(const dictionary& overrideDict) { - if (regularWaveModel::read(overrideDict)) + if (StokesI::readDict(overrideDict)) { scalar f1; scalar f2; @@ -829,8 +876,6 @@ bool Foam::waveModels::StokesV::read(const dictionary& overrideDict) << exit(FatalError); } - waveLength_ = 2.0*mathematical::pi/waveK; - return true; } @@ -838,54 +883,9 @@ bool Foam::waveModels::StokesV::read(const dictionary& overrideDict) } -void Foam::waveModels::StokesV::setVelocity -( - const scalar t, - const scalar tCoeff, - const scalarField& level -) -{ - const scalar waveK = mathematical::twoPi/waveLength_; - const scalar waveKx = waveK*cos(waveAngle_); - const scalar waveKy = waveK*sin(waveAngle_); - - forAll(U_, facei) - { - // Fraction of geometry represented by paddle - to be set - scalar fraction = 1; - - // Height - to be set - scalar z = 0; - - setPaddlePropeties(level, facei, fraction, z); - - if (fraction > 0) - { - const label paddlei = faceToPaddle_[facei]; - - const vector Uf = U - ( - waterDepthRef_, - waveKx, - waveKy, - lambda_, - wavePeriod_, - xPaddle_[paddlei], - yPaddle_[paddlei], - t, - wavePhase_, - z - ); - - U_[facei] = fraction*Uf*tCoeff; - } - } -} - - void Foam::waveModels::StokesV::info(Ostream& os) const { - regularWaveModel::info(os); + StokesI::info(os); os << " Lambda : " << lambda_ << nl << " Wave type : " << waveType() << nl; diff --git a/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.H b/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.H index 225bb9bf1ff3a7f458e9d9434e0eca2226b1d105..1450fca0a0acea8f555ceb1ad10ccfc14d16e977 100644 --- a/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.H +++ b/src/waveModels/waveGenerationModels/derived/StokesV/StokesVWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -39,7 +39,7 @@ Description #ifndef waveModels_StokesV_H #define waveModels_StokesV_H -#include "regularWaveModel.H" +#include "StokesIWaveModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,71 +54,65 @@ namespace waveModels class StokesV : - public regularWaveModel + public StokesI { -protected: - - // Proteced Data - - //- - scalar lambda_; - +private: - // Protected Member Functions + // Private Member Functions // Model coefficients - virtual scalar A11(const scalar h, const scalar k) const; + scalar A11(const scalar h, const scalar k) const; - virtual scalar A13(const scalar h, const scalar k) const; + scalar A13(const scalar h, const scalar k) const; - virtual scalar A15(const scalar h, const scalar k) const; + scalar A15(const scalar h, const scalar k) const; - virtual scalar A22(const scalar h, const scalar k) const; + scalar A22(const scalar h, const scalar k) const; - virtual scalar A24(const scalar h, const scalar k) const; + scalar A24(const scalar h, const scalar k) const; - virtual scalar A33(const scalar h, const scalar k) const; + scalar A33(const scalar h, const scalar k) const; - virtual scalar A35(const scalar h, const scalar k) const; + scalar A35(const scalar h, const scalar k) const; - virtual scalar A44(const scalar h, const scalar k) const; + scalar A44(const scalar h, const scalar k) const; - virtual scalar A55(const scalar h, const scalar k) const; + scalar A55(const scalar h, const scalar k) const; - virtual scalar B22(const scalar h, const scalar k) const; + scalar B22(const scalar h, const scalar k) const; - virtual scalar B24(const scalar h, const scalar k) const; + scalar B24(const scalar h, const scalar k) const; - virtual scalar B33(const scalar h, const scalar k) const; + scalar B33(const scalar h, const scalar k) const; - virtual scalar B33k(const scalar h, const scalar k) const; + scalar B33k(const scalar h, const scalar k) const; - virtual scalar B35(const scalar h, const scalar k) const; + scalar B35(const scalar h, const scalar k) const; - virtual scalar B35k(const scalar h, const scalar k) const; + scalar B35k(const scalar h, const scalar k) const; - virtual scalar B44(const scalar h, const scalar k) const; + scalar B44(const scalar h, const scalar k) const; - virtual scalar B55(const scalar h, const scalar k) const; + scalar B55(const scalar h, const scalar k) const; - virtual scalar B55k(const scalar h, const scalar k) const; + scalar B55k(const scalar h, const scalar k) const; - virtual scalar C1(const scalar h, const scalar k) const; + scalar C1(const scalar h, const scalar k) const; - virtual scalar C1k(const scalar h, const scalar k) const; + scalar C1k(const scalar h, const scalar k) const; - virtual scalar C2(const scalar h, const scalar k) const; + scalar C2(const scalar h, const scalar k) const; - virtual scalar C2k(const scalar h, const scalar k) const; + scalar C2k(const scalar h, const scalar k) const; - virtual scalar C3(const scalar h, const scalar k) const; + scalar C3(const scalar h, const scalar k) const; - virtual scalar C4(const scalar h, const scalar k) const; + scalar C4(const scalar h, const scalar k) const; //- Model intialisation - virtual void initialise + void initialise ( const scalar H, const scalar d, @@ -130,7 +124,7 @@ protected: ) const; //- Wave height - virtual scalar eta + scalar eta ( const scalar h, const scalar kx, @@ -144,7 +138,7 @@ protected: ) const; //- Wave velocity - virtual vector U + vector Uf ( const scalar d, const scalar kx, @@ -158,6 +152,17 @@ protected: const scalar z ) const; + +protected: + + // Proteced Data + + //- + scalar lambda_; + + + // Protected Member Functions + //- Set the water level virtual void setLevel ( @@ -196,12 +201,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.C b/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.C index 98c3873451723248f8712a832ec926761c354d52..efa9481f8f85aecb64b427dd1432212f1d324ee1 100644 --- a/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.C +++ b/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -189,7 +189,7 @@ Foam::vector Foam::waveModels::cnoidal::dEtaDx } -Foam::vector Foam::waveModels::cnoidal::U +Foam::vector Foam::waveModels::cnoidal::Uf ( const scalar H, const scalar h, @@ -231,6 +231,8 @@ Foam::vector Foam::waveModels::cnoidal::U } +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + void Foam::waveModels::cnoidal::setLevel ( const scalar t, @@ -262,6 +264,51 @@ void Foam::waveModels::cnoidal::setLevel } +void Foam::waveModels::cnoidal::setVelocity +( + const scalar t, + const scalar tCoeff, + const scalarField& level +) +{ + const scalar waveK = mathematical::twoPi/waveLength_; + const scalar waveKx = waveK*cos(waveAngle_); + const scalar waveKy = waveK*sin(waveAngle_); + + forAll(U_, facei) + { + // Fraction of geometry represented by paddle - to be set + scalar fraction = 1; + + // Height - to be set + scalar z = 0; + + setPaddlePropeties(level, facei, fraction, z); + + if (fraction > 0) + { + const label paddlei = faceToPaddle_[facei]; + + const vector Uf = this->Uf + ( + waveHeight_, + waterDepthRef_, + m_, + waveKx, + waveKy, + wavePeriod_, + xPaddle_[paddlei], + yPaddle_[paddlei], + t, + z + ); + + U_[facei] = fraction*Uf*tCoeff; + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::waveModels::cnoidal::cnoidal @@ -277,7 +324,7 @@ Foam::waveModels::cnoidal::cnoidal { if (readFields) { - read(dict); + readDict(dict); } } @@ -290,9 +337,9 @@ Foam::waveModels::cnoidal::~cnoidal() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModels::cnoidal::read(const dictionary& overrideDict) +bool Foam::waveModels::cnoidal::readDict(const dictionary& overrideDict) { - if (regularWaveModel::read(overrideDict)) + if (regularWaveModel::readDict(overrideDict)) { // Initialise m parameter and wavelength initialise @@ -311,51 +358,6 @@ bool Foam::waveModels::cnoidal::read(const dictionary& overrideDict) } -void Foam::waveModels::cnoidal::setVelocity -( - const scalar t, - const scalar tCoeff, - const scalarField& level -) -{ - const scalar waveK = mathematical::twoPi/waveLength_; - const scalar waveKx = waveK*cos(waveAngle_); - const scalar waveKy = waveK*sin(waveAngle_); - - forAll(U_, facei) - { - // Fraction of geometry represented by paddle - to be set - scalar fraction = 1; - - // Height - to be set - scalar z = 0; - - setPaddlePropeties(level, facei, fraction, z); - - if (fraction > 0) - { - const label paddlei = faceToPaddle_[facei]; - - const vector Uf = U - ( - waveHeight_, - waterDepthRef_, - m_, - waveKx, - waveKy, - wavePeriod_, - xPaddle_[paddlei], - yPaddle_[paddlei], - t, - z - ); - - U_[facei] = fraction*Uf*tCoeff; - } - } -} - - void Foam::waveModels::cnoidal::info(Ostream& os) const { regularWaveModel::info(os); diff --git a/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.H b/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.H index 3c786581543566cfd87a58a842cf78f53926dba1..5dd6162bf3413b97606a2934dd56ed91a03873ad 100644 --- a/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.H +++ b/src/waveModels/waveGenerationModels/derived/cnoidal/cnoidalWaveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -49,16 +49,11 @@ class cnoidal : public regularWaveModel { -protected: - - // Protected data - - //- `m' coefficient - scalar m_; +private: + // Private Member Functions - // Protected Member Functions - + //- Initialise void initialise ( const scalar H, @@ -69,7 +64,7 @@ protected: ) const; //- Wave height - virtual scalar eta + scalar eta ( const scalar H, const scalar Kx, @@ -107,7 +102,7 @@ protected: ) const; //- Wave velocity - virtual vector U + vector Uf ( const scalar H, const scalar h, @@ -121,6 +116,18 @@ protected: const scalar z ) const; + +protected: + + // Protected data + + //- `m' coefficient + scalar m_; + + + // Protected Member Functions + + //- Set the water level virtual void setLevel ( @@ -159,12 +166,13 @@ public: // Public Member Functions //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Info virtual void info(Ostream& os) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace waveModels diff --git a/src/waveModels/waveModel/waveModel.C b/src/waveModels/waveModel/waveModel.C index bb859aacda8463b83b65db48da9e2f3bca56e50e..1f86780e8863191705e7d42550f90f12b0aa5ce6 100644 --- a/src/waveModels/waveModel/waveModel.C +++ b/src/waveModels/waveModel/waveModel.C @@ -277,7 +277,7 @@ Foam::waveModel::waveModel { if (readFields) { - read(dict); + readDict(dict); } } @@ -290,7 +290,7 @@ Foam::waveModel::~waveModel() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::waveModel::read(const dictionary& overrideDict) +bool Foam::waveModel::readDict(const dictionary& overrideDict) { readOpt() = IOobject::READ_IF_PRESENT; if (headerOk()) diff --git a/src/waveModels/waveModel/waveModel.H b/src/waveModels/waveModel/waveModel.H index 7a0efd457053419ae0d724902c72f05f9556ae41..f7cea6c719d1b664c69ff06637043f70b627f0ba 100644 --- a/src/waveModels/waveModel/waveModel.H +++ b/src/waveModels/waveModel/waveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015 IH-Cantabria ------------------------------------------------------------------------------- License @@ -231,7 +231,7 @@ public: static word modelName(const word& patchName); //- Read from dictionary - virtual bool read(const dictionary& overrideDict); + virtual bool readDict(const dictionary& overrideDict); //- Return the latest wave velocity prediction virtual const vectorField& U() const; diff --git a/tutorials/Alltest b/tutorials/Alltest index 819cf9390552a9ef7dcaa83a891bb9fbb5005566..ac39728960170993198ac4def6a9e89325395614 100755 --- a/tutorials/Alltest +++ b/tutorials/Alltest @@ -4,7 +4,7 @@ # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation -# \\/ M anipulation | +# \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -26,20 +26,22 @@ # Alltest # # Description -# quickly tests the tutorials and writes out the scheme/solver information +# Quickly test the tutorials and write out the scheme/solver information # #------------------------------------------------------------------------------ cd ${0%/*} || exit 1 # Run from this directory usage() { + exec 1>&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat<<USAGE usage: ${0##*/} [OPTION] options: - -root <dir> specify root directory to run tests from + -git use git to retrieve the tutorials + -root dir specify root directory to run tests from -default sets up a default scheme on all schemes -help print the usage @@ -49,38 +51,54 @@ USAGE exit 1 } -#------------------------------------------------------------------------------ +# Report error and exit +die() +{ + exec 1>&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo + exit 1 +} -unset DEFAULT_SCHEMES +#------------------------------------------------------------------------------ ROOT="./" +unset DEFAULT_SCHEMES +unset useGit # parse options while [ "$#" -gt 0 ] do case "$1" in + -h | -help) + usage + ;; -r | -root) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" ROOT="$2" shift ;; - -h | -help) - usage + -git) + useGit=true ;; -d | -default) DEFAULT_SCHEMES=true ;; - -*) - usage "unknown option: '$*'" - ;; *) - usage "unknown option/argument: '$*'" + usage "unknown option/argument: '$1'" ;; esac shift done +# +# set up a default scheme on all schemes +# setDefaultFvSchemes() { cat<<EOF @@ -110,7 +128,7 @@ EOF } # -# VARIABLE +# Location of the main controlDict # unset MAIN_CONTROL_DICT @@ -152,15 +170,15 @@ SOLVERS_TEMP="FvSolution.temp" if [ -d "$TEST_RUN_DIR" ] then + echo "Removing old directory: $TEST_RUN_DIR" 1>&2 rm -rf $TEST_RUN_DIR fi -echo "Modifying ${MAIN_CONTROL_DICT}" +echo "Modifying ${MAIN_CONTROL_DICT}" 1>&2 if [ -e ${MAIN_CONTROL_DICT}.orig ] then - echo "File ${MAIN_CONTROL_DICT}.orig already exists" - echo "Did Alltest fail in some way and then run again?" - exit 1 + die "File ${MAIN_CONTROL_DICT}.orig already exists" \ + "Did Alltest fail in some way and then run again?" fi # Clean up on termination and on Ctrl-C @@ -169,31 +187,45 @@ trap 'mv ${MAIN_CONTROL_DICT}.orig ${MAIN_CONTROL_DICT} 2>/dev/null; exit 0' \ cp ${MAIN_CONTROL_DICT} ${MAIN_CONTROL_DICT}.orig sed \ --e s/"\(fvSchemes[ \t]*\)\([0-9]\);"/"\1 1;"/g \ --e s/"\(solution[ \t]*\)\([0-9]\);"/"\1 1;"/g \ -${MAIN_CONTROL_DICT}.orig > ${MAIN_CONTROL_DICT} + -e s/"\(fvSchemes[ \t]*\)\([0-9]\);"/"\1 1;"/g \ + -e s/"\(solution[ \t]*\)\([0-9]\);"/"\1 1;"/g \ + ${MAIN_CONTROL_DICT}.orig > ${MAIN_CONTROL_DICT} -echo "Copying the tutorials" -cp -a ${TUTORIALS_DIR} ${TEST_RUN_DIR} +if [ -n "$useGit" ] +then + echo "Copying the tutorials from current git branch" 1>&2 + if git rev-parse --is-inside-work-tree > /dev/null 2>&1 && \ + base="$(git rev-parse --show-toplevel 2>/dev/null)" + then + mkdir -p ${TEST_RUN_DIR} + ( cd $base/tutorials && git archive --format=tar HEAD . ) | \ + ( cd $TEST_RUN_DIR && tar -xf - ) + else + die "Not in a git-repo" + fi +else + echo "Copying the tutorials" 1>&2 + cp -a ${TUTORIALS_DIR} ${TEST_RUN_DIR} +fi -echo "Modifying the controlDicts to run only one time step" +echo "Modifying the controlDicts to run only one time step" 1>&2 cd ${TEST_RUN_DIR} || exit 1 -for CD in `find . -name "controlDict*"` +for CD in $(find . -type f -name "controlDict*") do mv ${CD} ${CD}.orig sed \ - -e s/"\(startFrom[ \t]*\)\([a-zA-Z]*\);"/"\1 latestTime;"/g \ - -e s/"\(stopAt[ \t]*\)\([a-zA-Z]*\);"/"\1 nextWrite;"/g \ - -e s/"\(writeControl[ \t]*\)\([a-zA-Z]*\);"/"\1 timeStep;"/g \ - -e s/"\(writeInterval[ \t]*\)\([0-9a-zA-Z.-]*\);"/"\1 1;"/g \ - ${CD}.orig > ${CD} + -e s/"\(startFrom[ \t]*\)\([a-zA-Z]*\);"/"\1 latestTime;"/g \ + -e s/"\(stopAt[ \t]*\)\([a-zA-Z]*\);"/"\1 nextWrite;"/g \ + -e s/"\(writeControl[ \t]*\)\([a-zA-Z]*\);"/"\1 timeStep;"/g \ + -e s/"\(writeInterval[ \t]*\)\([0-9a-zA-Z.-]*\);"/"\1 1;"/g \ + ${CD}.orig > ${CD} done if [ "$DEFAULT_SCHEMES" = true ] then - echo "Modifying the fvSchemes to contain only default schemes" - for FV_SC in `find . -name fvSchemes` + echo "Modifying the fvSchemes to contain only default schemes" 1>&2 + for FV_SC in $(find . -type f -name fvSchemes) do for S in $FV_SCHEMES do @@ -204,13 +236,13 @@ then done fi + cp -f $FOAM_TUTORIALS/Allrun . ./Allrun - sed -e :a -e '/\\$/N; s/\\\n//; ta' Allrun > temp APPLICATIONS=\ - `grep "applications=" temp | sed 's/applications=\"\([A-Za-z \t]*\)\"/\1/g'` + $(grep "applications=" temp | sed 's/applications=\"\([A-Za-z \t]*\)\"/\1/g') rm $SCHEMES_FILE > /dev/null 2>&1 for APP in $APPLICATIONS @@ -221,13 +253,13 @@ do do rm $SCHEMES_TEMP $SOLVERS_TEMP > /dev/null 2>&1 echo " ${ST}" >> $SCHEMES_FILE - for LOG in `find ${APP} -name "log.${APP}"` + for LOG in $(find ${APP} -type f -name "log.${APP}") do - for S in `grep ${ST} ${LOG} | cut -d" " -f4` + for S in $(grep ${ST} ${LOG} | cut -d" " -f4) do echo " ${S}" >> $SCHEMES_TEMP done - echo `grep solver ${LOG} | cut -d" " -f4` >> $SOLVERS_TEMP + echo $(grep solver ${LOG} | cut -d" " -f4) >> $SOLVERS_TEMP done if [ -f $SCHEMES_TEMP ] then diff --git a/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity.stl b/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity.stl index 2737bdf92797eef90239374f8a5dd88b052be40c..1d4c5e88ed4025cb4fa99bd59400be345a476453 100644 --- a/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity.stl +++ b/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity.stl @@ -1,4 +1,4 @@ -solid ascii +solid porosity facet normal 0 -1 0 outer loop vertex 0 0 -0.025 @@ -33599,4 +33599,4 @@ solid ascii vertex 0.1 0.0475 0.025 endloop endfacet -endsolid +endsolid porosity diff --git a/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity_inflated.stl b/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity_inflated.stl index 6c7c264eb0efeef7c88e0941088124d9710d21aa..7df4b08619efb3bf83abbccdc5d4d4168b4a65ca 100644 --- a/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity_inflated.stl +++ b/tutorials/incompressible/porousSimpleFoam/straightDuctImplicit/constant/triSurface/porosity_inflated.stl @@ -1,4 +1,4 @@ -solid ascii +solid porosity_inflated facet normal 0 -1 0 outer loop vertex 0 -0.005 -0.031 @@ -33599,4 +33599,4 @@ solid ascii vertex 0.1 0.052 0.029 endloop endfacet -endsolid +endsolid porosity_inflated diff --git a/wmake/rules/General/paraview b/wmake/rules/General/paraview new file mode 100644 index 0000000000000000000000000000000000000000..1df6ded1bc9d54fe550e27a88177f7036ccbc2f2 --- /dev/null +++ b/wmake/rules/General/paraview @@ -0,0 +1,8 @@ +#-------------------------------*- makefile -*--------------------------------- +# paraview values + +# major.minor: eg, /path/paraview-5.0 -> 5.0 +# +ParaView_MAJOR := $(shell echo $(ParaView_INCLUDE_DIR) | sed -e 's/^.*-//') + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/cmakeFunctions b/wmake/scripts/cmakeFunctions new file mode 100644 index 0000000000000000000000000000000000000000..a95e686aea13407cd633858f6afb80f73d6a3104 --- /dev/null +++ b/wmake/scripts/cmakeFunctions @@ -0,0 +1,163 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM. +# +# OpenFOAM is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. +# +# Script +# cmakeFunctions +# +# Description +# Helper functions for CMake +#------------------------------------------------------------------------------ + +# Source the wmake functions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions + +# Ensure CMake gets the correct C/C++ compilers +[ -n "$WM_CC" ] && export CC="$WM_CC" +[ -n "$WM_CXX" ] && export CXX="$WM_CXX" + + +#------------------------------------------------------------------------------ + +# +# Check sentinel file(s) to handle paraview / vtk version changes +# +sameDependency() +{ + local depend="$1" + findObjectDir "$2" # Where generated files are stored + local sentinel="$objectsDir/ThirdParty" + + echo $sentinel + + local prev + if read -r prev 2>/dev/null < $sentinel + then + if [ "$prev" = "$depend" ] + then + return 0 + else + echo "${depend%=*} changed between builds" 1>&2 + return 1 + fi + elif [ -f "$objectsDir/CMakeCache.txt" ] + then + echo "previous build was incomplete" 1>&2 + return 1 + else + return 0 + fi +} + + +# CMake into objectsDir with external dependency +cmakeVersioned() +{ + local depend="$1" + local sourceDir="$2" + findObjectDir $sourceDir # Where are generated files stored? + + local sentinel + + # version changed + sentinel=$(sameDependency "$depend" "$sourceDir") \ + || rm -rf "$objectsDir" > /dev/null 2>&1 + + test -f "$objectsDir/CMakeCache.txt" + retry=$? # Additional attempt if sources moved + + mkdir -p $objectsDir && \ + ( + cd $objectsDir || exit 1 + + cmake $sourceDir || { + if [ $retry -eq 0 ] + then + echo "Removing CMakeCache.txt and attempt again" 1>&2 + rm -f CMakeCache.txt + cmake $sourceDir + else + exit 1 + fi + } && make && { echo "$depend" > $sentinel; } + ) +} + + +# CMake into objectsDir with VTK_DIR dependency +cmakeVtk() +{ + cmakeVersioned "VTK_DIR=$VTK_DIR" "$1" +} + + +# CMake into objectsDir with ParaView_DIR dependency +cmakePv() +{ + cmakeVersioned "ParaView_DIR=$ParaView_DIR" "$1" +} + + +# +# Build library - use sentinel file(s) to handle paraview version changes +# +wmakeLibPv() +{ + local depend="ParaView_DIR=$ParaView_DIR" + local sentinel + + for libName + do + # version changed + sentinel=$(sameDependency "$depend" $libName) || wclean $libName + wmake $targetType $libName && { echo "$depend" > $sentinel; } + done +} + + +# +# There are several prerequisites for building plugins +# +canBuildPlugin() +{ + [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] || { + echo "==> cannot build ParaView plugins without paraview directory" + echo " ParaView_DIR=$ParaView_DIR" + return 1 + } + + [ -n "$PV_PLUGIN_PATH" ] || { + echo "==> ${PWD##*/} : invalid PV_PLUGIN_PATH for building ParaView plugins" + echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-unset}" + return 1 + } + + type cmake > /dev/null 2>&1 || { + echo "==> cannot build ParaView plugins without cmake" + return 1 + } + + return 0 # success +} + + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/wmakeFunctions b/wmake/scripts/wmakeFunctions old mode 100755 new mode 100644 index 0262350c204cf7a6330cbc4fb0da61a8844f66d3..7a12ad05459ecc6a5e5de9826464960c8f153104 --- a/wmake/scripts/wmakeFunctions +++ b/wmake/scripts/wmakeFunctions @@ -1,11 +1,10 @@ -#!/bin/sh -#------------------------------------------------------------------------------ +#----------------------------------*-sh-*-------------------------------------- # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation # \\/ M anipulation | -#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. #