From 2bfd449cf33d7d528dd6030df9a2e9e1bae5f8ad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 30 Nov 2009 13:33:06 +0100 Subject: [PATCH 01/20] 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 02/20] 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 03/20] 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 04/20] 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 05/20] 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 06/20] 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 80a27fb9da2366c4b170eb062cd97ef9587c42c1 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 1 Dec 2009 12:04:28 +0000 Subject: [PATCH 07/20] 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 28345f7e9709a68aa30a498d0c8cc7f170d322b0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 13:50:51 +0100 Subject: [PATCH 08/20] 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 abc8d9619852b11dd32fe210688cfb19e0efaaec Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 14:42:46 +0100 Subject: [PATCH 09/20] 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 10/20] 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 266738264438454a1128c41b454f0c973e3dc484 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Dec 2009 17:53:18 +0100 Subject: [PATCH 11/20] 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