From c1d6f266fef8561fc2f7da3771709c89c67f57ef Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 25 Nov 2009 14:40:36 +0000 Subject: [PATCH 01/37] prevent outputIndex calculation upon subcycling --- src/OpenFOAM/db/Time/Time.C | 142 +++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 68 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 7405cfb5b6..ec58c67b67 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -662,83 +662,89 @@ Foam::Time& Foam::Time::operator++() deltaTSave_ = deltaT_; setTime(value() + deltaT_, timeIndex_ + 1); - // If the time is very close to zero reset to zero - if (mag(value()) < 10*SMALL*deltaT_) + if (!subCycling_) { - setTime(0.0, timeIndex_); - } - - switch (writeControl_) - { - case wcTimeStep: - outputTime_ = !(timeIndex_ % label(writeInterval_)); - break; - - case wcRunTime: - case wcAdjustableRunTime: + // If the time is very close to zero reset to zero + if (mag(value()) < 10*SMALL*deltaT_) { - label outputIndex = - label(((value() - startTime_) + 0.5*deltaT_)/writeInterval_); + setTime(0.0, timeIndex_); + } - if (outputIndex > outputTimeIndex_) + switch (writeControl_) + { + case wcTimeStep: + outputTime_ = !(timeIndex_ % label(writeInterval_)); + break; + + case wcRunTime: + case wcAdjustableRunTime: { + label outputIndex = label + ( + ((value() - startTime_) + 0.5*deltaT_) + / writeInterval_ + ); + + if (outputIndex > outputTimeIndex_) + { + outputTime_ = true; + outputTimeIndex_ = outputIndex; + } + else + { + outputTime_ = false; + } + } + break; + + case wcCpuTime: + { + label outputIndex = label(elapsedCpuTime()/writeInterval_); + if (outputIndex > outputTimeIndex_) + { + outputTime_ = true; + outputTimeIndex_ = outputIndex; + } + else + { + outputTime_ = false; + } + } + break; + + case wcClockTime: + { + label outputIndex = label(elapsedClockTime()/writeInterval_); + if (outputIndex > outputTimeIndex_) + { + outputTime_ = true; + outputTimeIndex_ = outputIndex; + } + else + { + outputTime_ = false; + } + } + break; + } + + // see if endTime needs adjustment to stop at the next run()/end() check + if (!end()) + { + if (stopAt_ == saNoWriteNow) + { + endTime_ = value(); + } + else if (stopAt_ == saWriteNow) + { + endTime_ = value(); outputTime_ = true; - outputTimeIndex_ = outputIndex; } - else + else if (stopAt_ == saNextWrite && outputTime_ == true) { - outputTime_ = false; + endTime_ = value(); } } - break; - - case wcCpuTime: - { - label outputIndex = label(elapsedCpuTime()/writeInterval_); - if (outputIndex > outputTimeIndex_) - { - outputTime_ = true; - outputTimeIndex_ = outputIndex; - } - else - { - outputTime_ = false; - } - } - break; - - case wcClockTime: - { - label outputIndex = label(elapsedClockTime()/writeInterval_); - if (outputIndex > outputTimeIndex_) - { - outputTime_ = true; - outputTimeIndex_ = outputIndex; - } - else - { - outputTime_ = false; - } - } - break; - } - - // see if endTime needs adjustment to stop at the next run()/end() check - if (!end()) - { - if (stopAt_ == saNoWriteNow) - { - endTime_ = value(); - } - else if (stopAt_ == saWriteNow) - { - endTime_ = value(); - outputTime_ = true; - } - else if (stopAt_ == saNextWrite && outputTime_ == true) - { - endTime_ = value(); - } } return *this; From 32c8a7bf317a95374a4046faab8a23dfbabe0229 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 25 Nov 2009 14:40:50 +0000 Subject: [PATCH 02/37] change duplicate faces into warning --- .../primitiveMeshCheck/primitiveMeshCheck.C | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C index 5dda9f504d..022d8dd3e1 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C @@ -1836,19 +1836,21 @@ bool Foam::primitiveMesh::checkFaceFaces if (nErrorDuplicate > 0 || nErrorOrder > 0) { + // These are actually warnings, not errors. if (nErrorDuplicate > 0) { - Info<< " ***Number of duplicate (not baffle) faces found: " - << nErrorDuplicate << endl; + Info<< " < 0) { - Info<< " ***Number of faces with non-consecutive shared points: " - << nErrorOrder << endl; + Info<< " < Date: Thu, 26 Nov 2009 13:06:56 +0000 Subject: [PATCH 03/37] adapted angle for medial axis determination --- .../utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index 92c92d72e5..ab8adca478 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -274,7 +274,7 @@ addLayersControls maxThicknessToMedialRatio 0.3; // Angle used to pick up medial axis points - minMedianAxisAngle 130; + minMedianAxisAngle 90; // Create buffer region for new layer terminations nBufferCellsNoExtrude 0; From b8c7112e7da9331715ed482cc1e07287cdab6aa9 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 26 Nov 2009 18:01:40 +0000 Subject: [PATCH 04/37] reset triangle counter to 0 before usage --- src/surfMesh/MeshedSurface/MeshedSurface.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 1c1622c0eb..3cf72dbcbc 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -918,7 +918,7 @@ Foam::label Foam::MeshedSurface::triangulate // 'face' not '' const face& f = faceLst[faceI]; - label nTmp; + label nTmp = 0; f.triangles(this->points(), nTmp, tmpTri); for (label triI = 0; triI < nTmp; triI++) { From 2bfd449cf33d7d528dd6030df9a2e9e1bae5f8ad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 30 Nov 2009 13:33:06 +0100 Subject: [PATCH 05/37] added bin/tools/org-{batch,html,latex} - make it easier for non-emacs users to generate some of the documentation --- .gitignore | 2 + bin/tools/org-batch | 108 ++++++++++++++++++++++++++++++++++++++++++++ bin/tools/org-html | 1 + bin/tools/org-latex | 1 + 4 files changed, 112 insertions(+) create mode 100755 bin/tools/org-batch create mode 120000 bin/tools/org-html create mode 120000 bin/tools/org-latex diff --git a/.gitignore b/.gitignore index 8de178a605..f567511db3 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,9 @@ doc/[Dd]oxygen/latex doc/[Dd]oxygen/man # generated files in the main directory (e.g. ReleaseNotes-?.?.html) +# and in the doc directory /*.html +/doc/*.html # source packages - anywhere *.tar.bz2 diff --git a/bin/tools/org-batch b/bin/tools/org-batch new file mode 100755 index 0000000000..809552b54f --- /dev/null +++ b/bin/tools/org-batch @@ -0,0 +1,108 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------- +# License +# This file is part of OpenFOAM. +# +# OpenFOAM is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenFOAM; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# Script +# org-batch +# +# Description +# Batch process emacs org-mode files to create html/LaTeX etc. +# +#------------------------------------------------------------------------------ +Script=${0##*/} + +usage() { + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat</dev/null 2>&1 || usage "No emacs found in PATH" + + +for org +do + echo "Processing: $org" + echo "----------" + if [ -f "$org" ] + then + emacs --batch -l org --visit=$org \ + --funcall org-export-as-$mode-batch + else + echo "File not found" + fi + echo "----------" +done + +#------------------------------------------------------------------------------ diff --git a/bin/tools/org-html b/bin/tools/org-html new file mode 120000 index 0000000000..3c8e28ed2e --- /dev/null +++ b/bin/tools/org-html @@ -0,0 +1 @@ +org-batch \ No newline at end of file diff --git a/bin/tools/org-latex b/bin/tools/org-latex new file mode 120000 index 0000000000..3c8e28ed2e --- /dev/null +++ b/bin/tools/org-latex @@ -0,0 +1 @@ +org-batch \ No newline at end of file From 68e7c7368bf18b39ae0b294bc3871db21d69a6d8 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 10:41:17 +0100 Subject: [PATCH 06/37] add missing class/typedefs for Tensor2D innerProducts - missing in 1.6.x as well --- src/OpenFOAM/primitives/Tensor2D/Tensor2D.H | 2 +- src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H index f3c5d30e64..42fa25f07f 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H @@ -130,7 +130,7 @@ public: // Member Operators - //- Construct given SphericalTensor2D + //- Copy SphericalTensor2D inline void operator=(const SphericalTensor2D&); }; diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H index 752be90d85..385d53c16c 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H @@ -474,6 +474,14 @@ public: }; +template +class innerProduct, Tensor2D > +{ +public: + + typedef Tensor2D type; +}; + template class innerProduct, Tensor2D > { @@ -490,6 +498,23 @@ public: typedef Tensor2D type; }; +template +class innerProduct, Vector2D > +{ +public: + + typedef Vector2D type; +}; + +template +class innerProduct, Tensor2D > +{ +public: + + typedef Vector2D type; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From 4d10d06158d7036888927bf0c8643f78e5e35a70 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 11:10:25 +0100 Subject: [PATCH 07/37] IOOutputFilter - can create from IOobject directly - useful when using alternative dictionary names/locations --- .../IOOutputFilter/IOOutputFilter.C | 13 +++++++++++++ .../IOOutputFilter/IOOutputFilter.H | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C index 5346e95c2e..771a43b7dc 100644 --- a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C +++ b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.C @@ -29,6 +29,19 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +template +Foam::IOOutputFilter::IOOutputFilter +( + const word& outputFilterName, + const IOobject& ioDict, + const bool readFromFiles +) +: + IOdictionary(ioDict), + OutputFilter(outputFilterName, ioDict.db(), *this, readFromFiles) +{} + + template Foam::IOOutputFilter::IOOutputFilter ( diff --git a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H index 51ccc952ae..5781d75f17 100644 --- a/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H +++ b/src/OpenFOAM/db/functionObjects/IOOutputFilter/IOOutputFilter.H @@ -29,6 +29,11 @@ Description IOdictionary wrapper around OutputFilter to allow them to read from their associated dictionaries. +Note + The IOobject or the objectRegistry will normally have to be + derived from a fvMesh for a subsequent cast (within OutputFilter) + to work correctly. + SourceFiles IOOutputFilter.C @@ -69,6 +74,15 @@ public: // Constructors + //- Construct from an IOobject for IOdictionary + // Allow the possibility to load fields from files + IOOutputFilter + ( + const word& outputFilterName, + const IOobject& ioDict, + const bool loadFromFile = false + ); + //- Construct for given objectRegistry and dictionary // Allow dictionary to be optional // Allow the possibility to load fields from files From a0b3d145230b2c20d52707a1540adff8f9fda691 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 11:08:56 +0100 Subject: [PATCH 08/37] IOobjectList - gets sortedNames() method - could also be the default - reduce duplicate code by using some HashTable methods directly --- src/OpenFOAM/db/IOobjectList/IOobjectList.C | 47 +++++++++++---------- src/OpenFOAM/db/IOobjectList/IOobjectList.H | 12 ++++-- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index a55f68a425..41eb798407 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -58,7 +58,7 @@ Foam::IOobjectList::IOobjectList } } - // Create list file names in directory + // Create a list of file names in this directory fileNameList ObjectNames = readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE); @@ -130,8 +130,8 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const { if (IOobject::debug) { - Info<< "IOobjectList::lookup : found " << name - << endl; + Info<< "IOobjectList::lookup : found " + << name << endl; } return const_cast(*iter); @@ -140,8 +140,8 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const { if (IOobject::debug) { - Info<< "IOobjectList::lookup : could not find " << name - << endl; + Info<< "IOobjectList::lookup : could not find " + << name << endl; } return NULL; @@ -151,7 +151,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const { - IOobjectList IOobjectsOfClass(size()); + IOobjectList objectsOfClass(size()); for ( @@ -165,34 +165,26 @@ Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const if (IOobject::debug) { Info<< "IOobjectList::lookupClass : found " - << iter()->name() - << endl; + << iter.key() << endl; } - IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter())); + objectsOfClass.insert(iter.key(), new IOobject(*iter())); } } - return IOobjectsOfClass; + return objectsOfClass; } Foam::wordList Foam::IOobjectList::names() const { - wordList objectNames(size()); + return HashPtrTable::toc(); +} - label count = 0; - for - ( - HashPtrTable::const_iterator iter = begin(); - iter != end(); - ++iter - ) - { - objectNames[count++] = iter()->name(); - } - return objectNames; +Foam::wordList Foam::IOobjectList::sortedNames() const +{ + return HashPtrTable::sortedToc(); } @@ -210,7 +202,7 @@ Foam::wordList Foam::IOobjectList::names(const word& ClassName) const { if (iter()->headerClassName() == ClassName) { - objectNames[count++] = iter()->name(); + objectNames[count++] = iter.key(); } } @@ -220,4 +212,13 @@ Foam::wordList Foam::IOobjectList::names(const word& ClassName) const } +Foam::wordList Foam::IOobjectList::sortedNames(const word& ClassName) const +{ + wordList sortedLst = names(ClassName); + sort(sortedLst); + + return sortedLst; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 71c63f9d38..fc6034115f 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -84,23 +84,29 @@ public: // Member functions - //- Add an IOobject to list + //- Add an IOobject to the list bool add(IOobject&); - //- Remove an IOobject from list + //- Remove an IOobject from the list bool remove(IOobject&); //- Lookup a given name and return IOobject ptr if found else NULL IOobject* lookup(const word& name) const; - //- Return the list for all IOobjects of given class + //- Return the list for all IOobjects of a given class IOobjectList lookupClass(const word& className) const; //- Return the list of names of the IOobjects wordList names() const; + //- Return the sorted list of names of the IOobjects + wordList sortedNames() const; + //- Return the list of names of the IOobjects of given class wordList names(const word& className) const; + + //- Return the sorted list of names of the IOobjects of given class + wordList sortedNames(const word& className) const; }; From d80ce7fc33ce7ef4bfc7c17d309c21c20649b5ea Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 11:54:06 +0100 Subject: [PATCH 09/37] objectRegistry - gets sortedNames() methods - reduce duplicate code by using some HashTable methods directly --- .../db/objectRegistry/objectRegistry.C | 39 +++++++++++-------- .../db/objectRegistry/objectRegistry.H | 12 ++++-- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 452ad35ac6..a8a7390015 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -93,7 +93,7 @@ Foam::objectRegistry::~objectRegistry() } } - for (label i=0; i::toc(); +} - label count=0; - for (const_iterator iter = cbegin(); iter != cend(); ++iter) - { - objectNames[count++] = iter()->name(); - } - return objectNames; +Foam::wordList Foam::objectRegistry::sortedNames() const +{ + return HashTable::sortedToc(); } @@ -125,7 +123,7 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const { if (iter()->type() == ClassName) { - objectNames[count++] = iter()->name(); + objectNames[count++] = iter.key(); } } @@ -135,6 +133,15 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const } +Foam::wordList Foam::objectRegistry::sortedNames(const word& ClassName) const +{ + wordList sortedLst = names(ClassName); + sort(sortedLst); + + return sortedLst; +} + + const Foam::objectRegistry& Foam::objectRegistry::subRegistry ( const word& name @@ -151,8 +158,8 @@ Foam::label Foam::objectRegistry::getEvent() const if (event_ == labelMax) { WarningIn("objectRegistry::getEvent() const") - << "Event counter has overflowed. Resetting counter on all" - << " dependent objects." << endl + << "Event counter has overflowed. " + << "Resetting counter on all dependent objects." << nl << "This might cause extra evaluations." << endl; // Reset event counter @@ -202,7 +209,7 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const if (objectRegistry::debug) { Pout<< "objectRegistry::checkOut(regIOobject&) : " - << name() << " : checking out " << io.name() + << name() << " : checking out " << iter.key() << endl; } @@ -211,7 +218,8 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const if (objectRegistry::debug) { WarningIn("objectRegistry::checkOut(regIOobject&)") - << name() << " : attempt to checkOut copy of " << io.name() + << name() << " : attempt to checkOut copy of " + << iter.key() << endl; } @@ -286,8 +294,7 @@ void Foam::objectRegistry::readModifiedObjects() { Pout<< "objectRegistry::readModifiedObjects() : " << name() << " : Considering reading object " - << iter()->name() - << endl; + << iter.key() << endl; } iter()->readIfModified(); @@ -317,7 +324,7 @@ bool Foam::objectRegistry::writeObject { Pout<< "objectRegistry::write() : " << name() << " : Considering writing object " - << iter()->name() + << iter.key() << " with writeOpt " << iter()->writeOpt() << " to file " << iter()->objectPath() << endl; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 1f2d30d93e..6e7c5c04f6 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -132,9 +132,15 @@ public: //- Return the list of names of the IOobjects wordList names() const; - //- Return the list of names of the IOobjects of given class name + //- Return the sorted list of names of the IOobjects + wordList sortedNames() const; + + //- Return the list of names of IOobjects of given class name wordList names(const word& className) const; + //- Return the sorted list of names of IOobjects of given class name + wordList sortedNames(const word& className) const; + //- Return the list of names of the IOobjects of given type template wordList names() const; @@ -142,11 +148,11 @@ public: //- Lookup and return a const sub-objectRegistry const objectRegistry& subRegistry(const word& name) const; - //- Lookup and return all the object of the given Type + //- Lookup and return all objects of the given Type template HashTable lookupClass() const; - //- Is the named Type + //- Is the named Type found? template bool foundObject(const word& name) const; From 08988734b3512c416796e5f828862bc332d442ef Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 12:48:21 +0100 Subject: [PATCH 10/37] argList.H - split off templates into separate file --- src/OpenFOAM/global/argList/argList.H | 31 +++------ .../global/argList/argListTemplates.C | 63 +++++++++++++++++++ 2 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 src/OpenFOAM/global/argList/argListTemplates.C diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index 45c8de16ec..2682803807 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -234,35 +234,16 @@ public: //- Read a value from the named option template - T optionRead(const word& opt) const - { - T val; - optionLookup(opt)() >> val; - return val; - } + T optionRead(const word& opt) const; //- Read a value from the named option if present. // Return true if the named option was found. template - bool optionReadIfPresent(const word& opt, T& val) const - { - if (optionFound(opt)) - { - optionLookup(opt)() >> val; - return true; - } - else - { - return false; - } - } + bool optionReadIfPresent(const word& opt, T& val) const; //- Read a List of values from the named option template - List optionReadList(const word& opt) const - { - return readList(optionLookup(opt)()); - } + List optionReadList(const word& opt) const; // Edit @@ -300,6 +281,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository +# include "argListTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/global/argList/argListTemplates.C b/src/OpenFOAM/global/argList/argListTemplates.C new file mode 100644 index 0000000000..8bc3da3469 --- /dev/null +++ b/src/OpenFOAM/global/argList/argListTemplates.C @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +T Foam::argList::optionRead(const word& opt) const +{ + T val; + + optionLookup(opt)() >> val; + return val; +} + + +template +bool Foam::argList::optionReadIfPresent(const word& opt, T& val) const +{ + if (optionFound(opt)) + { + val = optionRead(opt); + return true; + } + else + { + return false; + } +} + + +template +Foam::List Foam::argList::optionReadList(const word& opt) const +{ + return readList(optionLookup(opt)()); +} + + +// ************************************************************************* // From 09b3c166dee90983fe4cab1f45f3c30c21394993 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 1 Dec 2009 12:04:28 +0000 Subject: [PATCH 11/37] Removed the "#remove" statements which do not appear to work. --- applications/test/dictionary/testDict | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 42a473a52b..08c325bd4c 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -71,7 +71,7 @@ boundaryField } // this should have no effect - #remove inactive + //#remove $inactive inlet_7 { $active } #inputMode overwrite @@ -105,9 +105,9 @@ baz // this should work -#remove active +//#remove active // this should work too -#remove ( bar baz ) +//#remove ( bar baz ) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From 80a27fb9da2366c4b170eb062cd97ef9587c42c1 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 1 Dec 2009 12:04:28 +0000 Subject: [PATCH 12/37] Removed the "#remove" statements which do not appear to work. --- applications/test/dictionary/testDict | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 42a473a52b..08c325bd4c 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -71,7 +71,7 @@ boundaryField } // this should have no effect - #remove inactive + //#remove $inactive inlet_7 { $active } #inputMode overwrite @@ -105,9 +105,9 @@ baz // this should work -#remove active +//#remove active // this should work too -#remove ( bar baz ) +//#remove ( bar baz ) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From 5057fad1af90fb8fb523fb00deef4ecf5a8f2761 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 1 Dec 2009 12:05:20 +0000 Subject: [PATCH 13/37] Corrected the building of the sub-dictionary names used for debug messages. --- src/OpenFOAM/db/dictionary/dictionary.C | 40 ++++++-- src/OpenFOAM/db/dictionary/dictionary.H | 93 +++++++++++++------ .../dictionaryEntry/dictionaryEntryIO.C | 4 +- src/OpenFOAM/db/dictionary/dictionaryIO.C | 6 +- src/OpenFOAM/db/dictionary/entry/entry.H | 7 +- .../compressible/LES/LESModel/LESModel.C | 2 +- .../compressible/RAS/RASModel/RASModel.C | 2 +- .../incompressible/LES/LESModel/LESModel.C | 2 +- .../incompressible/RAS/RASModel/RASModel.C | 2 +- 9 files changed, 110 insertions(+), 48 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index fb6f28af5b..9d022d5111 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -109,14 +109,21 @@ Foam::dictionary::dictionary() {} +Foam::dictionary::dictionary(const fileName& name) +: + dictionaryName(name), + parent_(dictionary::null) +{} + + Foam::dictionary::dictionary ( const dictionary& parentDict, const dictionary& dict ) : + dictionaryName(parentDict.name() + "::" + dict.name()), IDLList(dict, *this), - name_(dict.name()), parent_(parentDict) { forAllIter(IDLList, *this, iter) @@ -140,8 +147,8 @@ Foam::dictionary::dictionary const dictionary& dict ) : + dictionaryName(dict.name()), IDLList(dict, *this), - name_(dict.name()), parent_(dictionary::null) { forAllIter(IDLList, *this, iter) @@ -183,6 +190,7 @@ Foam::dictionary::dictionary parent_(parentDict) { transfer(dict()); + name() = parentDict.name() + "::" + name(); } @@ -472,6 +480,24 @@ Foam::dictionary& Foam::dictionary::subDict(const word& keyword) } +Foam::dictionary Foam::dictionary::subOrEmptyDict +( + const word& keyword +) const +{ + const entry* entryPtr = lookupEntryPtr(keyword, false, true); + + if (entryPtr == NULL) + { + return dictionary(*this, dictionary(keyword)); + } + else + { + return entryPtr->dict(); + } +} + + Foam::wordList Foam::dictionary::toc() const { wordList keys(size()); @@ -530,7 +556,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (hashedEntries_.insert(entryPtr->keyword(), entryPtr)) { - entryPtr->name() = name_ + "::" + entryPtr->keyword(); + entryPtr->name() = name() + "::" + entryPtr->keyword(); if (entryPtr->keyword().isPattern()) { @@ -558,7 +584,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (hashedEntries_.insert(entryPtr->keyword(), entryPtr)) { - entryPtr->name() = name_ + "::" + entryPtr->keyword(); + entryPtr->name() = name() + "::" + entryPtr->keyword(); IDLList::append(entryPtr); if (entryPtr->keyword().isPattern()) @@ -763,7 +789,7 @@ bool Foam::dictionary::changeKeyword // change name and HashTable, but leave DL-List untouched iter()->keyword() = newKeyword; - iter()->name() = name_ + "::" + newKeyword; + iter()->name() = name() + "::" + newKeyword; hashedEntries_.erase(oldKeyword); hashedEntries_.insert(newKeyword, iter()); @@ -838,7 +864,7 @@ void Foam::dictionary::transfer(dictionary& dict) { // changing parents probably doesn't make much sense, // but what about the names? - name_ = dict.name_; + name() = dict.name(); IDLList::transfer(dict); hashedEntries_.transfer(dict.hashedEntries_); @@ -871,7 +897,7 @@ void Foam::dictionary::operator=(const dictionary& rhs) << abort(FatalError); } - name_ = rhs.name(); + name() = rhs.name(); clear(); // Create clones of the entries in the given dictionary diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 31ac314237..bdfb7e4a8f 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -41,7 +41,7 @@ Description ToDo A merge() member function with a non-const dictionary parameter. - This would avoid unnecessary cloning in the add(entry*,bool) method + This would avoid unnecessary cloning in the add(entry*, bool) method. SourceFiles dictionary.C @@ -74,6 +74,47 @@ class SHA1Digest; Istream& operator>>(Istream&, dictionary&); Ostream& operator<<(Ostream&, const dictionary&); +/*---------------------------------------------------------------------------*\ + Class dictionaryName Declaration +\*---------------------------------------------------------------------------*/ + +class dictionaryName +{ + // Private data + + fileName name_; + + +public: + + // Constructors + + //- Construct dictionaryName null + dictionaryName() + {} + + //- Construct dictionaryName as copy of the given fileName + dictionaryName(const fileName& name) + : + name_(name) + {} + + + // Member functions + + //- Return the dictionary name + const fileName& name() const + { + return name_; + } + + //- Return the dictionary name + fileName& name() + { + return name_; + } +}; + /*---------------------------------------------------------------------------*\ Class dictionary Declaration @@ -81,13 +122,11 @@ Ostream& operator<<(Ostream&, const dictionary&); class dictionary : + public dictionaryName, public IDLList { // Private data - //- Dictionary name - fileName name_; - //- HashTable of the entries held on the DL-list for quick lookup HashTable hashedEntries_; @@ -100,6 +139,7 @@ class dictionary //- Patterns as precompiled regular expressions DLList > patternRegexps_; + // Private Member Functions //- Search patterns table for exact match or regular expression match @@ -121,16 +161,6 @@ class dictionary ); -public: - - //- Read dictionary from Istream - bool read(Istream&); - - //- Substitute the given keyword prepended by '$' with the - // corresponding sub-dictionary entries - bool substituteKeyword(const word& keyword); - - public: //- Declare friendship with the entry class for IO @@ -150,10 +180,14 @@ public: //- Construct top-level dictionary null dictionary(); - //- Construct from the parent dictionary and Istream, reading entries - // until lastEntry or EOF + //- Construct top-level empty dictionary with given name + dictionary(const fileName& name); + + //- Construct given the entry name, parent dictionary and Istream, + // reading entries until lastEntry or EOF dictionary ( + const fileName& name, const dictionary& parentDict, Istream& ); @@ -192,18 +226,6 @@ public: // Member functions - //- Return the dictionary name - const fileName& name() const - { - return name_; - } - - //- Return the dictionary name - fileName& name() - { - return name_; - } - //- Return the parent dictionary const dictionary& parent() const { @@ -320,14 +342,23 @@ public: //- Find and return a sub-dictionary for manipulation dictionary& subDict(const word&); + //- Find and return a sub-dictionary as a copy, or + // return an empty dictionary if the sub-dictionary does not exist + dictionary subOrEmptyDict(const word&) const; + //- Return the table of contents wordList toc() const; //- Return the list of available keys or patterns List keys(bool patterns=false) const; + // Editing + //- Substitute the given keyword prepended by '$' with the + // corresponding sub-dictionary entries + bool substituteKeyword(const word& keyword); + //- Add a new entry // With the merge option, dictionaries are interwoven and // primitive entries are overwritten @@ -407,6 +438,12 @@ public: Xfer xfer(); + // Read + + //- Read dictionary from Istream + bool read(Istream&); + + // Write void write(Ostream&, bool subDict=true) const; diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index 4ed3834053..175553e23a 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -58,10 +58,8 @@ Foam::dictionaryEntry::dictionaryEntry ) : entry(key), - dictionary(parentDict, is) + dictionary(key, parentDict, is) { - name() += "::" + key; - is.fatalCheck ( "dictionaryEntry::dictionaryEntry" diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index 96196e3a11..446aba828d 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -95,11 +95,12 @@ bool Foam::dictionary::substituteKeyword(const word& keyword) Foam::dictionary::dictionary ( + const fileName& name, const dictionary& parentDict, Istream& is ) : - name_(is.name()), + dictionaryName(parentDict.name() + "::" + name), parent_(parentDict) { read(is); @@ -108,7 +109,7 @@ Foam::dictionary::dictionary Foam::dictionary::dictionary(Istream& is) : - name_(is.name()), + dictionaryName(is.name()), parent_(dictionary::null) { // Reset input mode as this is a "top-level" dictionary @@ -132,6 +133,7 @@ Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict) functionEntries::inputModeEntry::clear(); dict.clear(); + dict.name() = is.name(); dict.read(is); return is; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index ddaefe7440..2286c4b4eb 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.H @@ -108,10 +108,9 @@ public: static autoPtr New(Istream& is); - // Destructor - - virtual ~entry() - {} + //- Destructor + virtual ~entry() + {} // Member functions diff --git a/src/turbulenceModels/compressible/LES/LESModel/LESModel.C b/src/turbulenceModels/compressible/LES/LESModel/LESModel.C index c32cb077d8..6ac295dea6 100644 --- a/src/turbulenceModels/compressible/LES/LESModel/LESModel.C +++ b/src/turbulenceModels/compressible/LES/LESModel/LESModel.C @@ -77,7 +77,7 @@ LESModel::LESModel ), printCoeffs_(lookupOrDefault("printCoeffs", false)), - coeffDict_(subDictPtr(type + "Coeffs")), + coeffDict_(subOrEmptyDict(type + "Coeffs")), k0_("k0", dimVelocity*dimVelocity, SMALL), diff --git a/src/turbulenceModels/compressible/RAS/RASModel/RASModel.C b/src/turbulenceModels/compressible/RAS/RASModel/RASModel.C index 642fc686d6..ffab28703b 100644 --- a/src/turbulenceModels/compressible/RAS/RASModel/RASModel.C +++ b/src/turbulenceModels/compressible/RAS/RASModel/RASModel.C @@ -79,7 +79,7 @@ RASModel::RASModel turbulence_(lookup("turbulence")), printCoeffs_(lookupOrDefault("printCoeffs", false)), - coeffDict_(subDictPtr(type + "Coeffs")), + coeffDict_(subOrEmptyDict(type + "Coeffs")), k0_("k0", dimVelocity*dimVelocity, SMALL), epsilon0_("epsilon", k0_.dimensions()/dimTime, SMALL), diff --git a/src/turbulenceModels/incompressible/LES/LESModel/LESModel.C b/src/turbulenceModels/incompressible/LES/LESModel/LESModel.C index 76c2ef0ba4..fd7791d9f3 100644 --- a/src/turbulenceModels/incompressible/LES/LESModel/LESModel.C +++ b/src/turbulenceModels/incompressible/LES/LESModel/LESModel.C @@ -76,7 +76,7 @@ LESModel::LESModel ), printCoeffs_(lookupOrDefault("printCoeffs", false)), - coeffDict_(subDictPtr(type + "Coeffs")), + coeffDict_(subOrEmptyDict(type + "Coeffs")), k0_("k0", dimVelocity*dimVelocity, SMALL), delta_(LESdelta::New("delta", U.mesh(), *this)) diff --git a/src/turbulenceModels/incompressible/RAS/RASModel/RASModel.C b/src/turbulenceModels/incompressible/RAS/RASModel/RASModel.C index 9a6a447166..1803075428 100644 --- a/src/turbulenceModels/incompressible/RAS/RASModel/RASModel.C +++ b/src/turbulenceModels/incompressible/RAS/RASModel/RASModel.C @@ -78,7 +78,7 @@ RASModel::RASModel turbulence_(lookup("turbulence")), printCoeffs_(lookupOrDefault("printCoeffs", false)), - coeffDict_(subDictPtr(type + "Coeffs")), + coeffDict_(subOrEmptyDict(type + "Coeffs")), k0_("k0", dimVelocity*dimVelocity, SMALL), epsilon0_("epsilon", k0_.dimensions()/dimTime, SMALL), From 28345f7e9709a68aa30a498d0c8cc7f170d322b0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 13:50:51 +0100 Subject: [PATCH 14/37] fixup #remove functionEntry and revert e15e32fdb7d515b - forgot to use readList in removeEntry, which caused the test failure. - remaining problem: it doesn't work as might be expected This is the problem: dict { foo xxx; bar yyy; } dict { baz zzz; #remove foo } This only removes 'foo' from the current scope (the second dict), since it occurs before the dictionary merge does. To remove from the final, merged dictionary, we'd need a new deleteEntry type that would do the right thing on the merge before self-destructing (ie, removing itself too). --- applications/test/dictionary/testDict | 6 +++--- .../db/dictionary/functionEntries/removeEntry/removeEntry.C | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 08c325bd4c..42a473a52b 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -71,7 +71,7 @@ boundaryField } // this should have no effect - //#remove $inactive + #remove inactive inlet_7 { $active } #inputMode overwrite @@ -105,9 +105,9 @@ baz // this should work -//#remove active +#remove active // this should work too -//#remove ( bar baz ) +#remove ( bar baz ) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C index 34154cce48..78facd8e23 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C @@ -65,8 +65,8 @@ bool Foam::functionEntries::removeEntry::execute Istream& is ) { - wordList dictKeys = parentDict.toc(); - wordReList patterns(is); + wordList dictKeys = parentDict.toc(); + wordReList patterns = readList(is); labelList indices = findStrings(patterns, dictKeys); From 7889df78a930eb7bb30bd0e2270ca38cf93a8d1f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 13:50:51 +0100 Subject: [PATCH 15/37] fixup #remove functionEntry and revert 09b3c166dee9098 - forgot to use readList in removeEntry, which caused the test failure. - remaining problem: it doesn't work as might be expected This is the problem: dict { foo xxx; bar yyy; } dict { baz zzz; #remove foo } This only removes 'foo' from the current scope (the second dict), since it occurs before the dictionary merge does. To remove from the final, merged dictionary, we'd need a new deleteEntry type that would do the right thing on the merge before self-destructing (ie, removing itself too). --- applications/test/dictionary/testDict | 6 +++--- .../db/dictionary/functionEntries/removeEntry/removeEntry.C | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 08c325bd4c..42a473a52b 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -71,7 +71,7 @@ boundaryField } // this should have no effect - //#remove $inactive + #remove inactive inlet_7 { $active } #inputMode overwrite @@ -105,9 +105,9 @@ baz // this should work -//#remove active +#remove active // this should work too -//#remove ( bar baz ) +#remove ( bar baz ) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C index 34154cce48..78facd8e23 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C @@ -65,8 +65,8 @@ bool Foam::functionEntries::removeEntry::execute Istream& is ) { - wordList dictKeys = parentDict.toc(); - wordReList patterns(is); + wordList dictKeys = parentDict.toc(); + wordReList patterns = readList(is); labelList indices = findStrings(patterns, dictKeys); From abc8d9619852b11dd32fe210688cfb19e0efaaec Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 14:42:46 +0100 Subject: [PATCH 16/37] sampledSurfaces - handle fields as wordReList - this allows something like this: fields( T U "Ua.*" ); to select normal fields and all the adjoint velocity fields --- .../sampledSurfaces/sampledSurfaces.C | 131 +++++++++--------- .../sampledSurfaces/sampledSurfaces.H | 12 +- 2 files changed, 76 insertions(+), 67 deletions(-) diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index d6b9613f6f..7969b010cd 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -33,6 +33,9 @@ License #include "mergePoints.H" #include "volPointInterpolation.H" +#include "IOobjectList.H" +#include "stringListOps.H" + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam @@ -70,6 +73,42 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_(1e-10); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +Foam::label Foam::sampledSurfaces::appendFieldType +( + const word& fieldName, + const word& fieldType +) +{ + if (fieldType == volScalarField::typeName) + { + scalarFields_.append(fieldName); + return 1; + } + else if (fieldType == volVectorField::typeName) + { + vectorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSphericalTensorField::typeName) + { + sphericalTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSymmTensorField::typeName) + { + symmTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volTensorField::typeName) + { + tensorFields_.append(fieldName); + return 1; + } + + return 0; +} + + Foam::label Foam::sampledSurfaces::classifyFieldTypes() { label nFields = 0; @@ -80,75 +119,40 @@ Foam::label Foam::sampledSurfaces::classifyFieldTypes() symmTensorFields_.clear(); tensorFields_.clear(); - forAll(fieldNames_, fieldI) + // check files for a particular time + if (loadFromFiles_) { - const word& fieldName = fieldNames_[fieldI]; - word fieldType = ""; + IOobjectList objects(mesh_, mesh_.time().timeName()); + wordList allFields = objects.sortedNames(); - // check files for a particular time - if (loadFromFiles_) + labelList indices = findStrings(fieldSelection_, allFields); + + forAll(indices, fieldI) { - IOobject io + const word& fieldName = allFields[indices[fieldI]]; + + nFields += appendFieldType ( fieldName, - mesh_.time().timeName(), - mesh_, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false + objects.find(fieldName)()->headerClassName() ); + } + } + else + { + wordList allFields = mesh_.sortedNames(); + labelList indices = findStrings(fieldSelection_, allFields); - if (io.headerOk()) - { - fieldType = io.headerClassName(); - } - else - { - continue; - } - } - else + forAll(indices, fieldI) { - // check objectRegistry - objectRegistry::const_iterator iter = mesh_.find(fieldName); + const word& fieldName = allFields[indices[fieldI]]; - if (iter != mesh_.objectRegistry::end()) - { - fieldType = iter()->type(); - } - else - { - continue; - } + nFields += appendFieldType + ( + fieldName, + mesh_.find(fieldName)()->type() + ); } - - - if (fieldType == volScalarField::typeName) - { - scalarFields_.append(fieldName); - nFields++; - } - else if (fieldType == volVectorField::typeName) - { - vectorFields_.append(fieldName); - nFields++; - } - else if (fieldType == volSphericalTensorField::typeName) - { - sphericalTensorFields_.append(fieldName); - nFields++; - } - else if (fieldType == volSymmTensorField::typeName) - { - symmTensorFields_.append(fieldName); - nFields++; - } - else if (fieldType == volTensorField::typeName) - { - tensorFields_.append(fieldName); - nFields++; - } - } return nFields; @@ -208,7 +212,7 @@ Foam::sampledSurfaces::sampledSurfaces mesh_(refCast(obr)), loadFromFiles_(loadFromFiles), outputPath_(fileName::null), - fieldNames_(), + fieldSelection_(), interpolationScheme_(word::null), writeFormat_(word::null), mergeList_(), @@ -304,9 +308,10 @@ void Foam::sampledSurfaces::write() void Foam::sampledSurfaces::read(const dictionary& dict) { - fieldNames_ = wordList(dict.lookup("fields")); + dict.lookup("fields") >> fieldSelection_; - const label nFields = fieldNames_.size(); + // might be okay for a size estimate, but we don't really know + const label nFields = fieldSelection_.size(); scalarFields_.reset(nFields); vectorFields_.reset(nFields); @@ -348,7 +353,7 @@ void Foam::sampledSurfaces::read(const dictionary& dict) if (Pstream::master() && debug) { - Pout<< "sample fields:" << fieldNames_ << nl + Pout<< "sample fields:" << fieldSelection_ << nl << "sample surfaces:" << nl << "(" << nl; forAll(*this, surfI) diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 4ad59c486f..cd28e1f2ca 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -41,6 +41,7 @@ SourceFiles #include "sampledSurface.H" #include "surfaceWriter.H" #include "volFieldsFwd.H" +#include "wordReList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -51,7 +52,7 @@ class fvMesh; class dictionary; /*---------------------------------------------------------------------------*\ - Class sampledSurfaces Declaration + Class sampledSurfaces Declaration \*---------------------------------------------------------------------------*/ class sampledSurfaces @@ -100,8 +101,8 @@ class sampledSurfaces void reset(const label nElem) { formatter.clear(); - DynamicList::setCapacity(nElem); - DynamicList::clear(); + DynamicList::reserve(nElem); + DynamicList::clear(); } void operator=(const word& writeFormat) @@ -161,7 +162,7 @@ class sampledSurfaces // Read from dictonary //- Names of fields to sample - wordList fieldNames_; + wordReList fieldSelection_; //- Interpolation scheme to use word interpolationScheme_; @@ -191,6 +192,9 @@ class sampledSurfaces // Private Member Functions + //- Append fieldName to the appropriate group + label appendFieldType(const word& fieldName, const word& fieldType); + //- Classify field types, returns the number of fields label classifyFieldTypes(); From b752ce5272da1d9ea757f17c6c42f8b978de9082 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 16:11:18 +0100 Subject: [PATCH 17/37] sampledSets - handle fields as wordReList - adjust code to more closely resemble sampledSurfaces --- src/sampling/Make/files | 2 + .../sampledSet/sampledSets/sampledSets.C | 173 ++++++------------ .../sampledSet/sampledSets/sampledSets.H | 46 +++-- .../sampledSets/sampledSetsGrouping.C | 125 +++++++++++++ .../sampledSets/sampledSetsTemplates.C | 61 ++---- .../sampledSurfaces/sampledSurfaces.C | 115 +----------- .../sampledSurfaces/sampledSurfaces.H | 32 +--- .../sampledSurfaces/sampledSurfacesGrouping.C | 125 +++++++++++++ .../sampledSurfacesTemplates.C | 2 +- 9 files changed, 373 insertions(+), 308 deletions(-) create mode 100644 src/sampling/sampledSet/sampledSets/sampledSetsGrouping.C create mode 100644 src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 3442889069..079294190d 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -9,6 +9,7 @@ sampledSet/midPoint/midPointSet.C sampledSet/midPointAndFace/midPointAndFaceSet.C sampledSet/sampledSet/sampledSet.C sampledSet/sampledSets/sampledSets.C +sampledSet/sampledSets/sampledSetsGrouping.C sampledSet/sampledSetsFunctionObject/sampledSetsFunctionObject.C sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C sampledSet/uniform/uniformSet.C @@ -34,6 +35,7 @@ sampledSurface/distanceSurface/distanceSurface.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledSurface/sampledSurface.C sampledSurface/sampledSurfaces/sampledSurfaces.C +sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C sampledSurface/sampledSurfacesFunctionObject/sampledSurfacesFunctionObject.C sampledSurface/thresholdCellFaces/thresholdCellFaces.C sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C index a964cab152..600f89bb9b 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.C +++ b/src/sampling/sampledSet/sampledSets/sampledSets.C @@ -34,103 +34,12 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - defineTypeNameAndDebug(sampledSets, 0); -} - +defineTypeNameAndDebug(Foam::sampledSets, 0); bool Foam::sampledSets::verbose_ = false; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::sampledSets::checkFieldTypes() -{ - wordList fieldTypes(fieldNames_.size()); - - // check files for a particular time - if (loadFromFiles_) - { - forAll(fieldNames_, fieldi) - { - IOobject io - ( - fieldNames_[fieldi], - mesh_.time().timeName(), - mesh_, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ); - - if (io.headerOk()) - { - fieldTypes[fieldi] = io.headerClassName(); - } - else - { - fieldTypes[fieldi] = "(notFound)"; - } - } - } - else - { - // check objectRegistry - forAll(fieldNames_, fieldi) - { - objectRegistry::const_iterator iter = - mesh_.find(fieldNames_[fieldi]); - - if (iter != mesh_.objectRegistry::end()) - { - fieldTypes[fieldi] = iter()->type(); - } - else - { - fieldTypes[fieldi] = "(notFound)"; - } - } - } - - - label nFields = 0; - - // classify fieldTypes - nFields += grep(scalarFields_, fieldTypes); - nFields += grep(vectorFields_, fieldTypes); - nFields += grep(sphericalTensorFields_, fieldTypes); - nFields += grep(symmTensorFields_, fieldTypes); - nFields += grep(tensorFields_, fieldTypes); - - if (Pstream::master()) - { - if (debug) - { - Pout<< "timeName = " << mesh_.time().timeName() << nl - << "scalarFields " << scalarFields_ << nl - << "vectorFields " << vectorFields_ << nl - << "sphTensorFields " << sphericalTensorFields_ << nl - << "symTensorFields " << symmTensorFields_ < 0) - { - if (debug) - { - Pout<< "Creating directory " - << outputPath_/mesh_.time().timeName() - << nl << endl; - } - - mkDir(outputPath_/mesh_.time().timeName()); - } - } - - return nFields > 0; -} - - void Foam::sampledSets::combineSampledSets ( PtrList& masterSampledSets, @@ -147,9 +56,9 @@ void Foam::sampledSets::combineSampledSets const PtrList& sampledSets = *this; - forAll(sampledSets, seti) + forAll(sampledSets, setI) { - const sampledSet& samplePts = sampledSets[seti]; + const sampledSet& samplePts = sampledSets[setI]; // Collect data from all processors List > gatheredPts(Pstream::nProcs()); @@ -190,7 +99,7 @@ void Foam::sampledSets::combineSampledSets // Sort curveDist and use to fill masterSamplePts SortableList sortedDist(allCurveDist); - indexSets[seti] = sortedDist.indices(); + indexSets[setI] = sortedDist.indices(); // Get reference point (note: only master has all points) point refPt; @@ -207,12 +116,12 @@ void Foam::sampledSets::combineSampledSets masterSampledSets.set ( - seti, + setI, new coordSet ( samplePts.name(), samplePts.axis(), - List(UIndirectList(allPts, indexSets[seti])), + List(UIndirectList(allPts, indexSets[setI])), refPt ) ); @@ -236,7 +145,7 @@ Foam::sampledSets::sampledSets loadFromFiles_(loadFromFiles), outputPath_(fileName::null), searchEngine_(mesh_, true), - fieldNames_(), + fieldSelection_(), interpolationScheme_(word::null), writeFormat_(word::null) { @@ -285,13 +194,43 @@ void Foam::sampledSets::end() void Foam::sampledSets::write() { - if (size() && checkFieldTypes()) + if (size()) { - sampleAndWrite(scalarFields_); - sampleAndWrite(vectorFields_); - sampleAndWrite(sphericalTensorFields_); - sampleAndWrite(symmTensorFields_); - sampleAndWrite(tensorFields_); + const label nFields = classifyFields(); + + if (Pstream::master()) + { + if (debug) + { + Pout<< "timeName = " << mesh_.time().timeName() << nl + << "scalarFields " << scalarFields_ << nl + << "vectorFields " << vectorFields_ << nl + << "sphTensorFields " << sphericalTensorFields_ << nl + << "symTensorFields " << symmTensorFields_ <> fieldSelection_; + clearFieldGroups(); - fieldNames_ = wordList(dict_.lookup("fields")); + interpolationScheme_ = dict.lookupOrDefault + ( + "interpolationScheme", + "cell" + ); + writeFormat_ = dict.lookupOrDefault + ( + "setFormat", + "null" + ); - interpolationScheme_ = "cell"; - dict_.readIfPresent("interpolationScheme", interpolationScheme_); - - writeFormat_ = "null"; - dict_.readIfPresent("setFormat", writeFormat_); - - scalarFields_.clear(); - vectorFields_.clear(); - sphericalTensorFields_.clear(); - symmTensorFields_.clear(); - tensorFields_.clear(); PtrList newList ( @@ -324,7 +263,7 @@ void Foam::sampledSets::read(const dictionary& dict) if (Pstream::master() && debug) { - Pout<< "sample fields:" << fieldNames_ << nl + Pout<< "sample fields:" << fieldSelection_ << nl << "sample sets:" << nl << "(" << nl; forAll(*this, si) diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.H b/src/sampling/sampledSet/sampledSets/sampledSets.H index da38f9e1c5..7302d26deb 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.H +++ b/src/sampling/sampledSet/sampledSets/sampledSets.H @@ -43,6 +43,7 @@ SourceFiles #include "interpolation.H" #include "coordSet.H" #include "writer.H" +#include "wordReList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,7 +55,7 @@ class dictionary; class fvMesh; /*---------------------------------------------------------------------------*\ - Class sampledSets Declaration + Class sampledSets Declaration \*---------------------------------------------------------------------------*/ class sampledSets @@ -67,25 +68,40 @@ class sampledSets template class fieldGroup : - public wordList + public DynamicList { public: - //- Set formatter - autoPtr > formatter; + //- The set formatter + autoPtr< writer > formatter; //- Construct null fieldGroup() : - wordList(0), + DynamicList(0), formatter(NULL) {} + //- Construct for a particular format + fieldGroup(const word& writeFormat) + : + DynamicList(0), + formatter(writer::New(writeFormat)) + {} + + //- Reset format and field list void clear() { - wordList::clear(); + DynamicList::clear(); formatter.clear(); } + + //- Assign a new formatter + void operator=(const word& writeFormat) + { + formatter = writer::New(writeFormat); + } + }; @@ -161,7 +177,7 @@ class sampledSets // Read from dictonary //- Names of fields to sample - wordList fieldNames_; + wordReList fieldSelection_; //- Interpolation scheme to use word interpolationScheme_; @@ -187,16 +203,14 @@ class sampledSets // Private Member Functions - //- Classify field types, return true if nFields > 0 - bool checkFieldTypes(); + //- Clear old field groups + void clearFieldGroups(); - //- Find the fields in the list of the given type, return count - template - label grep - ( - fieldGroup& fieldList, - const wordList& fieldTypes - ) const; + //- Append fieldName to the appropriate group + label appendFieldGroup(const word& fieldName, const word& fieldType); + + //- Classify field types, returns the number of fields + label classifyFields(); //- Combine points from all processors. Sort by curveDist and produce // index list. Valid result only on master processor. diff --git a/src/sampling/sampledSet/sampledSets/sampledSetsGrouping.C b/src/sampling/sampledSet/sampledSets/sampledSetsGrouping.C new file mode 100644 index 0000000000..6e9fb68f0e --- /dev/null +++ b/src/sampling/sampledSet/sampledSets/sampledSetsGrouping.C @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "sampledSets.H" +#include "volFields.H" +#include "IOobjectList.H" +#include "stringListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::sampledSets::clearFieldGroups() +{ + scalarFields_.clear(); + vectorFields_.clear(); + sphericalTensorFields_.clear(); + symmTensorFields_.clear(); + tensorFields_.clear(); +} + + +Foam::label Foam::sampledSets::appendFieldGroup +( + const word& fieldName, + const word& fieldType +) +{ + if (fieldType == volScalarField::typeName) + { + scalarFields_.append(fieldName); + return 1; + } + else if (fieldType == volVectorField::typeName) + { + vectorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSphericalTensorField::typeName) + { + sphericalTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSymmTensorField::typeName) + { + symmTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volTensorField::typeName) + { + tensorFields_.append(fieldName); + return 1; + } + + return 0; +} + + +Foam::label Foam::sampledSets::classifyFields() +{ + label nFields = 0; + clearFieldGroups(); + + if (loadFromFiles_) + { + // check files for a particular time + IOobjectList objects(mesh_, mesh_.time().timeName()); + wordList allFields = objects.sortedNames(); + + labelList indices = findStrings(fieldSelection_, allFields); + + forAll(indices, fieldI) + { + const word& fieldName = allFields[indices[fieldI]]; + + nFields += appendFieldGroup + ( + fieldName, + objects.find(fieldName)()->headerClassName() + ); + } + } + else + { + // check currently available fields + wordList allFields = mesh_.sortedNames(); + labelList indices = findStrings(fieldSelection_, allFields); + + forAll(indices, fieldI) + { + const word& fieldName = allFields[indices[fieldI]]; + + nFields += appendFieldGroup + ( + fieldName, + mesh_.find(fieldName)()->type() + ); + } + } + + return nFields; +} + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C index c5cfecb8a8..1450c8c7bf 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C +++ b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C @@ -46,10 +46,10 @@ Foam::sampledSets::volFieldSampler::volFieldSampler interpolation::New(interpolationScheme, field) ); - forAll(samplers, seti) + forAll(samplers, setI) { - Field& values = this->operator[](seti); - const sampledSet& samples = samplers[seti]; + Field& values = this->operator[](setI); + const sampledSet& samples = samplers[setI]; values.setSize(samples.size()); forAll(samples, samplei) @@ -79,10 +79,10 @@ Foam::sampledSets::volFieldSampler::volFieldSampler List >(samplers.size()), name_(field.name()) { - forAll(samplers, seti) + forAll(samplers, setI) { - Field& values = this->operator[](seti); - const sampledSet& samples = samplers[seti]; + Field& values = this->operator[](setI); + const sampledSet& samples = samplers[setI]; values.setSize(samples.size()); forAll(samples, samplei) @@ -105,41 +105,12 @@ Foam::sampledSets::volFieldSampler::volFieldSampler {} -template -Foam::label Foam::sampledSets::grep -( - fieldGroup& fieldList, - const wordList& fieldTypes -) const -{ - fieldList.setSize(fieldNames_.size()); - label nFields = 0; - - forAll(fieldNames_, fieldi) - { - if - ( - fieldTypes[fieldi] - == GeometricField::typeName - ) - { - fieldList[nFields] = fieldNames_[fieldi]; - nFields++; - } - } - - fieldList.setSize(nFields); - - return nFields; -} - - template void Foam::sampledSets::writeSampleFile ( const coordSet& masterSampleSet, const PtrList >& masterFields, - const label seti, + const label setI, const fileName& timeDir, const writer& formatter ) @@ -150,7 +121,7 @@ void Foam::sampledSets::writeSampleFile forAll(masterFields, fieldi) { valueSetNames[fieldi] = masterFields[fieldi].name(); - valueSets[fieldi] = &masterFields[fieldi][seti]; + valueSets[fieldi] = &masterFields[fieldi][setI]; } fileName fName @@ -180,11 +151,11 @@ void Foam::sampledSets::combineSampledValues { List > masterValues(indexSets.size()); - forAll(indexSets, seti) + forAll(indexSets, setI) { // Collect data from all processors List > gatheredData(Pstream::nProcs()); - gatheredData[Pstream::myProcNo()] = sampledFields[fieldi][seti]; + gatheredData[Pstream::myProcNo()] = sampledFields[fieldi][setI]; Pstream::gatherList(gatheredData); if (Pstream::master()) @@ -198,10 +169,10 @@ void Foam::sampledSets::combineSampledValues ) ); - masterValues[seti] = UIndirectList + masterValues[setI] = UIndirectList ( allData, - indexSets[seti] + indexSets[setI] )(); } } @@ -232,7 +203,7 @@ void Foam::sampledSets::sampleAndWrite // Create or use existing writer if (fields.formatter.empty()) { - fields.formatter = writer::New(writeFormat_); + fields = writeFormat_; } // Storage for interpolated values @@ -326,13 +297,13 @@ void Foam::sampledSets::sampleAndWrite if (Pstream::master()) { - forAll(masterSampledSets_, seti) + forAll(masterSampledSets_, setI) { writeSampleFile ( - masterSampledSets_[seti], + masterSampledSets_[setI], masterFields, - seti, + setI, outputPath_/mesh_.time().timeName(), fields.formatter() ); diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 7969b010cd..a5155a9f49 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -33,11 +33,12 @@ License #include "mergePoints.H" #include "volPointInterpolation.H" -#include "IOobjectList.H" -#include "stringListOps.H" - // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +defineTypeNameAndDebug(Foam::sampledSurfaces, 0); +bool Foam::sampledSurfaces::verbose_ = false; +Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10; + namespace Foam { //- Used to offset faces in Pstream::combineOffset @@ -63,102 +64,11 @@ namespace Foam } }; - - defineTypeNameAndDebug(sampledSurfaces, 0); } -bool Foam::sampledSurfaces::verbose_(false); -Foam::scalar Foam::sampledSurfaces::mergeTol_(1e-10); - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::label Foam::sampledSurfaces::appendFieldType -( - const word& fieldName, - const word& fieldType -) -{ - if (fieldType == volScalarField::typeName) - { - scalarFields_.append(fieldName); - return 1; - } - else if (fieldType == volVectorField::typeName) - { - vectorFields_.append(fieldName); - return 1; - } - else if (fieldType == volSphericalTensorField::typeName) - { - sphericalTensorFields_.append(fieldName); - return 1; - } - else if (fieldType == volSymmTensorField::typeName) - { - symmTensorFields_.append(fieldName); - return 1; - } - else if (fieldType == volTensorField::typeName) - { - tensorFields_.append(fieldName); - return 1; - } - - return 0; -} - - -Foam::label Foam::sampledSurfaces::classifyFieldTypes() -{ - label nFields = 0; - - scalarFields_.clear(); - vectorFields_.clear(); - sphericalTensorFields_.clear(); - symmTensorFields_.clear(); - tensorFields_.clear(); - - // check files for a particular time - if (loadFromFiles_) - { - IOobjectList objects(mesh_, mesh_.time().timeName()); - wordList allFields = objects.sortedNames(); - - labelList indices = findStrings(fieldSelection_, allFields); - - forAll(indices, fieldI) - { - const word& fieldName = allFields[indices[fieldI]]; - - nFields += appendFieldType - ( - fieldName, - objects.find(fieldName)()->headerClassName() - ); - } - } - else - { - wordList allFields = mesh_.sortedNames(); - labelList indices = findStrings(fieldSelection_, allFields); - - forAll(indices, fieldI) - { - const word& fieldName = allFields[indices[fieldI]]; - - nFields += appendFieldType - ( - fieldName, - mesh_.find(fieldName)()->type() - ); - } - } - - return nFields; -} - - void Foam::sampledSurfaces::writeGeometry() const { // Write to time directory under outputPath_ @@ -269,7 +179,7 @@ void Foam::sampledSurfaces::write() // finalize surfaces, merge points etc. update(); - const label nFields = classifyFieldTypes(); + const label nFields = classifyFields(); if (Pstream::master()) { @@ -290,8 +200,8 @@ void Foam::sampledSurfaces::write() mkDir(outputPath_/mesh_.time().timeName()); } - // write geometry first if required, or when no fields would otherwise - // be written + // write geometry first if required, + // or when no fields would otherwise be written if (nFields == 0 || genericFormatter_->separateFiles()) { writeGeometry(); @@ -309,15 +219,7 @@ void Foam::sampledSurfaces::write() void Foam::sampledSurfaces::read(const dictionary& dict) { dict.lookup("fields") >> fieldSelection_; - - // might be okay for a size estimate, but we don't really know - const label nFields = fieldSelection_.size(); - - scalarFields_.reset(nFields); - vectorFields_.reset(nFields); - sphericalTensorFields_.reset(nFields); - symmTensorFields_.reset(nFields); - tensorFields_.reset(nFields); + clearFieldGroups(); interpolationScheme_ = dict.lookupOrDefault ( @@ -340,7 +242,6 @@ void Foam::sampledSurfaces::read(const dictionary& dict) dict.lookup("surfaces"), sampledSurface::iNew(mesh_) ); - transfer(newList); if (Pstream::parRun()) diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index cd28e1f2ca..66b6472ff9 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -69,7 +69,7 @@ class sampledSurfaces { public: - //- Surface formatter + //- The surface formatter autoPtr< surfaceWriter > formatter; //- Construct null @@ -86,34 +86,19 @@ class sampledSurfaces formatter(surfaceWriter::New(writeFormat)) {} - //- Construct for a particular surface format and a list of field - // names - fieldGroup - ( - const word& writeFormat, - const wordList& fieldNames - ) - : - DynamicList(fieldNames), - formatter(surfaceWriter::New(writeFormat)) - {} - - void reset(const label nElem) + //- Reset format and field list + void clear() { - formatter.clear(); - DynamicList::reserve(nElem); DynamicList::clear(); + formatter.clear(); } + //- Assign a new formatter void operator=(const word& writeFormat) { formatter = surfaceWriter::New(writeFormat); } - void operator=(const wordList& fieldNames) - { - DynamicList::operator=(fieldNames); - } }; @@ -192,11 +177,14 @@ class sampledSurfaces // Private Member Functions + //- Clear old field groups + void clearFieldGroups(); + //- Append fieldName to the appropriate group - label appendFieldType(const word& fieldName, const word& fieldType); + label appendFieldGroup(const word& fieldName, const word& fieldType); //- Classify field types, returns the number of fields - label classifyFieldTypes(); + label classifyFields(); //- Write geometry only void writeGeometry() const; diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C new file mode 100644 index 0000000000..497c36f842 --- /dev/null +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "sampledSurfaces.H" +#include "volFields.H" +#include "IOobjectList.H" +#include "stringListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::sampledSurfaces::clearFieldGroups() +{ + scalarFields_.clear(); + vectorFields_.clear(); + sphericalTensorFields_.clear(); + symmTensorFields_.clear(); + tensorFields_.clear(); +} + + +Foam::label Foam::sampledSurfaces::appendFieldGroup +( + const word& fieldName, + const word& fieldType +) +{ + if (fieldType == volScalarField::typeName) + { + scalarFields_.append(fieldName); + return 1; + } + else if (fieldType == volVectorField::typeName) + { + vectorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSphericalTensorField::typeName) + { + sphericalTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volSymmTensorField::typeName) + { + symmTensorFields_.append(fieldName); + return 1; + } + else if (fieldType == volTensorField::typeName) + { + tensorFields_.append(fieldName); + return 1; + } + + return 0; +} + + +Foam::label Foam::sampledSurfaces::classifyFields() +{ + label nFields = 0; + clearFieldGroups(); + + // check files for a particular time + if (loadFromFiles_) + { + IOobjectList objects(mesh_, mesh_.time().timeName()); + wordList allFields = objects.sortedNames(); + + labelList indices = findStrings(fieldSelection_, allFields); + + forAll(indices, fieldI) + { + const word& fieldName = allFields[indices[fieldI]]; + + nFields += appendFieldGroup + ( + fieldName, + objects.find(fieldName)()->headerClassName() + ); + } + } + else + { + wordList allFields = mesh_.sortedNames(); + labelList indices = findStrings(fieldSelection_, allFields); + + forAll(indices, fieldI) + { + const word& fieldName = allFields[indices[fieldI]]; + + nFields += appendFieldGroup + ( + fieldName, + mesh_.find(fieldName)()->type() + ); + } + } + + return nFields; +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 6da55cfe87..b5dc2d418c 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -178,7 +178,7 @@ void Foam::sampledSurfaces::sampleAndWrite if ( - iter != mesh_.objectRegistry::end() + iter != objectRegistry::end() && iter()->type() == GeometricField::typeName ) From 49a2c73b2d6a246580140f7c286805b1a0b9a621 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 1 Dec 2009 16:43:47 +0000 Subject: [PATCH 18/37] tecplot360 converter --- .../dataConversion/foamToTecplot360/Allwmake | 6 -- .../foamToTecplot360/Make/options | 6 +- .../foamToTecplot360/foamToTecplot360.C | 68 ++++++++++--------- .../foamToTecplot360/tecplotWriter.C | 5 +- .../foamToTecplot360/tecplotWriterTemplates.C | 6 +- 5 files changed, 43 insertions(+), 48 deletions(-) delete mode 100755 applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake deleted file mode 100755 index 5866aa8f37..0000000000 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Allwmake +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -if [ "$TEC_360_2009" ] -then - wmake -fi diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options index d03f44ae8c..0c2c8b7216 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/Make/options @@ -1,14 +1,12 @@ EXE_INC = \ - -I$(TEC_360_2009)/include \ - /* -I../tecio/tecsrc/lnInclude/ */ \ + -I$(WM_THIRD_PARTY_DIR)/tecio/tecsrc/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude EXE_LIBS = \ - $(TEC_360_2009)/lib/tecio64.a \ - /* -L$(FOAM_USER_LIBBIN) -ltecio */ \ + -ltecio \ -llagrangian \ -lfiniteVolume \ -lmeshTools diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C index d514609ff2..8ed17ebffb 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/foamToTecplot360.C @@ -65,6 +65,9 @@ Usage information as a single argument. The double quotes denote a regular expression. + @param -useTimeName \n + use the time index in the VTK file name instead of the time index + \*---------------------------------------------------------------------------*/ #include "pointMesh.H" @@ -240,7 +243,7 @@ int main(int argc, char *argv[]) # include "createNamedMesh.H" // TecplotData/ directory in the case - fileName fvPath(runTime.path()/"TecplotData-bin"); + fileName fvPath(runTime.path()/"Tecplot360"); // Directory of mesh (region0 gets filtered out) fileName regionPrefix = ""; @@ -536,7 +539,8 @@ int main(int argc, char *argv[]) varLocation ); - // strandID (= some zone id) + // strandID (= piece id. Gets incremented for every piece of geometry + // that is output) INTEGER4 strandID = 1; @@ -647,7 +651,7 @@ int main(int argc, char *argv[]) writer.writePolyhedralZone ( mesh.name(), // regionName - 1, //strandID, // strandID + strandID, // strandID mesh, List(3, ValueLocation_Nodal), nFaceNodes @@ -684,7 +688,7 @@ int main(int argc, char *argv[]) writer.writePolyhedralZone ( mesh.name(), // regionName - 1, //strandID, // strandID + strandID++, // strandID mesh, varLocation, 0 @@ -776,7 +780,7 @@ int main(int argc, char *argv[]) writer.writePolygonalZone ( setName, - 1, //strandID, + strandID++, ipp, allVarLocation ); @@ -903,7 +907,7 @@ int main(int argc, char *argv[]) { label patchID = patchIDs[i]; const polyPatch& pp = patches[patchID]; - INTEGER4 strandID = 1 + i; + //INTEGER4 strandID = 1 + i; Info<< " Writing patch " << patchID << "\t" << pp.name() << "\tstrand:" << strandID << nl << endl; @@ -917,7 +921,7 @@ int main(int argc, char *argv[]) writer.writePolygonalZone ( pp.name(), - strandID, + strandID++, //strandID, ipp, allVarLocation ); @@ -1073,7 +1077,7 @@ int main(int argc, char *argv[]) writer.writePolygonalZone ( pp.name(), - 1+patchIDs.size()+zoneI, //strandID, + strandID++, //1+patchIDs.size()+zoneI, //strandID, ipp, allVarLocation ); @@ -1196,29 +1200,29 @@ int main(int argc, char *argv[]) Info<< " vectors :"; print(Info, vectorNames); - wordList sphereNames - ( - sprayObjs.names - ( - sphericalTensorIOField::typeName - ) - ); - Info<< " spherical tensors :"; - print(Info, sphereNames); - - wordList symmNames - ( - sprayObjs.names - ( - symmTensorIOField::typeName - ) - ); - Info<< " symm tensors :"; - print(Info, symmNames); - - wordList tensorNames(sprayObjs.names(tensorIOField::typeName)); - Info<< " tensors :"; - print(Info, tensorNames); + //wordList sphereNames + //( + // sprayObjs.names + // ( + // sphericalTensorIOField::typeName + // ) + //); + //Info<< " spherical tensors :"; + //print(Info, sphereNames); + // + //wordList symmNames + //( + // sprayObjs.names + // ( + // symmTensorIOField::typeName + // ) + //); + //Info<< " symm tensors :"; + //print(Info, symmNames); + // + //wordList tensorNames(sprayObjs.names(tensorIOField::typeName)); + //Info<< " tensors :"; + //print(Info, tensorNames); // Load cloud positions @@ -1277,7 +1281,7 @@ int main(int argc, char *argv[]) writer.writeOrderedZone ( cloudDirs[cloudI], - strandID, + strandID++, //strandID, parcels.size(), allVarLocation ); diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C index 47165d80a4..97e94d4982 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriter.C @@ -79,7 +79,7 @@ Pout<< endl void Foam::tecplotWriter::writePolyhedralZone ( const word& zoneName, - const INTEGER4 strandID, + INTEGER4 strandID, const fvMesh& mesh, const List& varLocArray, INTEGER4 nFaceNodes @@ -95,7 +95,6 @@ void Foam::tecplotWriter::writePolyhedralZone INTEGER4 KCellMax = 0; /* Not Used, set to zero */ double SolTime = runTime_.value(); /* solution time */ - INTEGER4 StrandID = 1; /* static zone */ INTEGER4 ParentZone = 0; /* no parent zone */ INTEGER4 IsBlock = 1; /* block format */ @@ -135,7 +134,7 @@ Pout<< "zoneName:" << zoneName &JCellMax, &KCellMax, &SolTime, - &StrandID, + &strandID, &ParentZone, &IsBlock, &NFConns, diff --git a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C index f337b20d38..f9a01d57a4 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTecplot360/tecplotWriterTemplates.C @@ -26,11 +26,11 @@ License #include "tecplotWriter.H" -extern "C" -{ +//extern "C" +//{ #include "MASTER.h" #include "GLOBAL.h" -} +//} #include "fvc.H" From 2c240854b8c3fff48266ef47a1e6e9b00cda2b2b Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 1 Dec 2009 16:44:36 +0000 Subject: [PATCH 19/37] incorrect comment --- .../polyPatches/constraint/processor/processorPolyPatch.H | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.H index 1955892727..807ea19825 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.H @@ -34,7 +34,6 @@ Description SourceFiles processorPolyPatch.C - processorPolyPatchMorph.C \*---------------------------------------------------------------------------*/ From 266738264438454a1128c41b454f0c973e3dc484 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 17:53:18 +0100 Subject: [PATCH 20/37] probes - handle fields as wordReList - adjust code to more closely resemble sampledSets / sampledSurfaces --- src/sampling/Make/files | 3 +- src/sampling/probes/probes.C | 316 +++++++----------- src/sampling/probes/probes.H | 61 ++-- .../probesFunctionObject.C | 0 .../probesFunctionObject.H | 0 src/sampling/probes/probesGrouping.C | 125 +++++++ src/sampling/probes/probesTemplates.C | 55 +-- .../sampledSet/sampledSets/sampledSets.C | 1 - 8 files changed, 293 insertions(+), 268 deletions(-) rename src/sampling/probes/{ => probesFunctionObject}/probesFunctionObject.C (100%) rename src/sampling/probes/{ => probesFunctionObject}/probesFunctionObject.H (100%) create mode 100644 src/sampling/probes/probesGrouping.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 079294190d..e9d78df7a0 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -1,5 +1,6 @@ probes/probes.C -probes/probesFunctionObject.C +probes/probesGrouping.C +probes/probesFunctionObject/probesFunctionObject.C sampledSet/cloud/cloudSet.C sampledSet/coordSet/coordSet.C diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index 5a6686aad0..cb21c6299c 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -32,243 +32,178 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - defineTypeNameAndDebug(probes, 0); -} +defineTypeNameAndDebug(Foam::probes, 0); + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::probes::findCells(const fvMesh& mesh) { - if (cellList_.empty()) + cellList_.clear(); + cellList_.setSize(size()); + + forAll(*this, probeI) { - cellList_.setSize(probeLocations_.size()); + const vector& location = operator[](probeI); - forAll(probeLocations_, probeI) + cellList_[probeI] = mesh.findCell(location); + + if (debug && cellList_[probeI] != -1) { - cellList_[probeI] = mesh.findCell(probeLocations_[probeI]); + Pout<< "probes : found point " << location + << " in cell " << cellList_[probeI] << endl; + } + } - if (debug && cellList_[probeI] != -1) + + // Check if all probes have been found. + forAll(cellList_, probeI) + { + const vector& location = operator[](probeI); + label cellI = cellList_[probeI]; + + // Check at least one processor with cell. + reduce(cellI, maxOp