From 27ae7d5b0010a1b2d2c7b3cdcfd5ef7bd1515f37 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 9 Dec 2016 14:38:15 +0000 Subject: [PATCH 1/8] STYLE: minor comments added to ensightSurfaceReader --- .../readers/ensight/ensightSurfaceReader.C | 20 +++++++++---------- .../readers/ensight/ensightSurfaceReader.H | 14 ++++++------- .../ensight/ensightSurfaceReaderTemplates.C | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C index bd026f2b91..2c21271939 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C @@ -212,14 +212,14 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is) } // Start reading time information - readLine(is, buffer); // time set: 1 + readLine(is, buffer); // time set: readLine(is, buffer); - readFromLine(3, buffer, nTimeSteps_); + readFromLine(3, buffer, nTimeSteps_); // number of steps: readLine(is, buffer); - readFromLine(3, buffer, timeStartIndex_); + readFromLine(3, buffer, timeStartIndex_); // filename start number: readLine(is, buffer); - readFromLine(2, buffer, timeIncrement_); + readFromLine(2, buffer, timeIncrement_); // filename increment: if (debug) { @@ -369,7 +369,7 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry() // Read faces - may be a mix of tris, quads and polys DynamicList faces(ceil(nPoints/3)); - DynamicList > schema(faces.size()); + DynamicList> schema(faces.size()); string faceType = ""; label nFace = 0; while (is.good()) // (is.peek() != EOF) @@ -494,7 +494,7 @@ Foam::wordList Foam::ensightSurfaceReader::fieldNames } -Foam::tmp > Foam::ensightSurfaceReader::field +Foam::tmp> Foam::ensightSurfaceReader::field ( const label timeIndex, const label fieldIndex, @@ -505,7 +505,7 @@ Foam::tmp > Foam::ensightSurfaceReader::field } -Foam::tmp > Foam::ensightSurfaceReader::field +Foam::tmp> Foam::ensightSurfaceReader::field ( const label timeIndex, const label fieldIndex, @@ -516,7 +516,7 @@ Foam::tmp > Foam::ensightSurfaceReader::field } -Foam::tmp > +Foam::tmp> Foam::ensightSurfaceReader::field ( const label timeIndex, @@ -528,7 +528,7 @@ Foam::ensightSurfaceReader::field } -Foam::tmp > Foam::ensightSurfaceReader::field +Foam::tmp> Foam::ensightSurfaceReader::field ( const label timeIndex, const label fieldIndex, @@ -539,7 +539,7 @@ Foam::tmp > Foam::ensightSurfaceReader::field } -Foam::tmp > Foam::ensightSurfaceReader::field +Foam::tmp> Foam::ensightSurfaceReader::field ( const label timeIndex, const label fieldIndex, diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H index 0ba7e1c49b..75c760341a 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H @@ -86,7 +86,7 @@ protected: //- Pointer to the surface autoPtr surfPtr_; - List > schema_; + List> schema_; // Protected Member Functions @@ -126,7 +126,7 @@ protected: //- Helper function to return a field template - tmp > readField + tmp> readField ( const label timeIndex, const label fieldIndex @@ -160,7 +160,7 @@ public: virtual wordList fieldNames(const label timeIndex) const; //- Return a scalar field at a given time - virtual tmp > field + virtual tmp> field ( const label timeIndex, const label fieldIndex, @@ -168,7 +168,7 @@ public: ) const; //- Return a scalar field at a given time - virtual tmp > field + virtual tmp> field ( const label timeIndex, const label fieldIndex, @@ -176,7 +176,7 @@ public: ) const; //- Return a sphericalTensor field at a given time - virtual tmp > field + virtual tmp> field ( const label timeIndex, const label fieldIndex, @@ -184,7 +184,7 @@ public: ) const; //- Return a symmTensor field at a given time - virtual tmp > field + virtual tmp> field ( const label timeIndex, const label fieldIndex, @@ -192,7 +192,7 @@ public: ) const; //- Return a tensor field at a given time - virtual tmp > field + virtual tmp> field ( const label timeIndex, const label fieldIndex, diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C index 5b8b3f5559..df6f466390 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C @@ -57,7 +57,7 @@ void Foam::ensightSurfaceReader::readFromLine template -Foam::tmp > Foam::ensightSurfaceReader::readField +Foam::tmp> Foam::ensightSurfaceReader::readField ( const label timeIndex, const label fieldIndex @@ -126,7 +126,7 @@ Foam::tmp > Foam::ensightSurfaceReader::readField is.read(iValue); // Allocate storage for data as a list per component - List > values(pTraits::nComponents); + List> values(pTraits::nComponents); label n = surfPtr_->size(); forAll(values, cmptI) { @@ -164,7 +164,7 @@ Foam::tmp > Foam::ensightSurfaceReader::readField } } - tmp > tField(new Field(n, pTraits::zero)); + tmp> tField(new Field(n, pTraits::zero)); Field& field = tField.ref(); for From eb00c8021d55ebe357b31f262a1a849503c36f2c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 9 Dec 2016 14:44:26 +0000 Subject: [PATCH 2/8] ENH: provide log option for top-level builds (issue #333) --- wmake/scripts/AllwmakeParseArguments | 35 +++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/wmake/scripts/AllwmakeParseArguments b/wmake/scripts/AllwmakeParseArguments index c8bb3ccb71..e4abb9aabc 100644 --- a/wmake/scripts/AllwmakeParseArguments +++ b/wmake/scripts/AllwmakeParseArguments @@ -46,6 +46,10 @@ Usage: $Script [OPTIONS] Executing $Script is equivalent to wmake -all [OPTIONS] + +With these additional options: + -l | -log + USAGE wmake -help @@ -57,8 +61,7 @@ USAGE # Parse the arguments and options #------------------------------------------------------------------------------ -fromWmake= -qOpt= +unset fromWmake optLog optQueue for arg in "$@" do @@ -70,17 +73,20 @@ do usage exit 0 ;; - # Check if called from wmake to avoid recusion -fromWmake) - fromWmake="fromWmake" + # If called from wmake (to avoid recursion) + fromWmake=true ;; - -q) - qOpt="-q" - # Permanently remove arg - continue + -l | -log) + optLog=true + continue # Permanently remove arg + ;; + -q | -queue) + optQueue="-q" + continue # Permanently remove arg ;; - # Target type lib | libo | libso | dep | objects) + # Target type targetType=$arg ;; esac @@ -96,7 +102,13 @@ done if [ -z "$fromWmake" ] then - exec wmake -all $qOpt $* + if [ -z "$optLog" ] + then + exec wmake -all $optQueue $* + else + echo "logging wmake -all output to 'log.Allwmake'" 1>&2 + exec wmake -all $optQueue $* 2>&1 | tee log.Allwmake + fi fi @@ -114,7 +126,8 @@ fi # Cleanup local variables and functions #------------------------------------------------------------------------------ -unset Script usage fromWmake +unset Script fromWmake optLog optQueue +unset -f usage #------------------------------------------------------------------------------ From 8321f1ffcc9a2984b544237bc6480a53e68a4aa7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 7 Dec 2016 12:09:21 +0000 Subject: [PATCH 3/8] ENH: initial support for handling subRegions in regionFunctionObject - propagate updated objectRegistry methods (eg, lookupObjectRef etc) into regionFunctionObject --- .../regionFunctionObject.C | 54 ++++++++++++++----- .../regionFunctionObject.H | 49 ++++++++++++++--- .../regionFunctionObjectTemplates.C | 42 ++++++++++++--- 3 files changed, 119 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C index 6fdfe07eb1..b1d9f5f59f 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,19 +40,46 @@ namespace functionObjects // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // +const Foam::objectRegistry& +Foam::functionObjects::regionFunctionObject::whichSubRegistry +( + const objectRegistry& obr, + const dictionary& dict +) +{ + word subName; + if (dict.readIfPresent("subRegion", subName)) + { + return obr.lookupObject(subName); + } + else + { + return obr; + } +} + + +const Foam::objectRegistry& +Foam::functionObjects::regionFunctionObject::obr() const +{ + return subObr_; +} + + bool Foam::functionObjects::regionFunctionObject::writeObject ( const word& fieldName ) { - if (obr_.foundObject(fieldName)) + const regIOobject* objPtr = + this->lookupObjectPtr(fieldName); + + if (objPtr) { - const regIOobject& field = obr_.lookupObject(fieldName); - Log << " functionObjects::" << type() << " " << name() - << " writing field: " << field.name() << endl; + << " writing field: " << objPtr->name() << endl; - field.write(); + objPtr->write(); return true; } @@ -68,13 +95,12 @@ bool Foam::functionObjects::regionFunctionObject::clearObject const word& fieldName ) { - if (foundObject(fieldName)) + regIOobject* objPtr = lookupObjectRefPtr(fieldName); + if (objPtr) { - const regIOobject& resultObject = lookupObject(fieldName); - - if (resultObject.ownedByRegistry()) + if (objPtr->ownedByRegistry()) { - return const_cast(resultObject).checkOut(); + return objPtr->checkOut(); } else { @@ -104,7 +130,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject ( dict.lookupOrDefault("region", polyMesh::defaultRegion) ) - ) + ), + subObr_(whichSubRegistry(obr_, dict)) {} @@ -116,7 +143,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject ) : stateFunctionObject(name, obr.time()), - obr_(obr) + obr_(obr), + subObr_(whichSubRegistry(obr_, dict)) {} diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H index e9be6e3487..70be4fccfe 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H @@ -27,6 +27,8 @@ Class Description Specialization of Foam::functionObject for a region and providing a reference to the region Foam::objectRegistry. + Also provides support for referencing a sub-region, which is typically + needed when dealing with surfMesh and their fields. See also Foam::functionObjects::stateFunctionObject @@ -68,18 +70,51 @@ protected: //- Reference to the region objectRegistry const objectRegistry& obr_; + //- Optional reference to the sub-region objectRegistry. + // If a sub-region is not in effect, this reference is identical + // to the usual region objectRegistry. + const objectRegistry& subObr_; + // Protected member functions - //- Find field in the objectRegistry + //- Selector for alternative sub-registry, + // when the keyword %subRegion is present in the dictionary + static const objectRegistry& whichSubRegistry + ( + const objectRegistry& obr, + const dictionary& dict + ); + + //- The region or sub-region registry being used + const objectRegistry& obr() const; + + + //- Find object (eg, a field) in the (sub) objectRegistry template bool foundObject(const word& fieldName) const; - //- Lookup field from the objectRegistry + //- Lookup and return object (eg, a field) from the (sub) objectRegistry template const ObjectType& lookupObject(const word& fieldName) const; - //- Store the given field in the objectRegistry under the given name + //- Lookup and return object (eg, a field) from the (sub) objectRegistry + template + ObjectType& lookupObjectRef(const word& fieldName) const; + + //- Lookup and return pointer to the object, + // otherwise nullptr if the object was not found, + // or had the incorrect type. + template + const ObjectType* lookupObjectPtr(const word& fieldName) const; + + //- Lookup and return non-const pointer to the object, + // otherwise nullptr if the object was not found, + // or had the incorrect type. + template + ObjectType* lookupObjectRefPtr(const word& fieldName) const; + + //- Store the given field in the (sub) objectRegistry under the given name // Note: sets the fieldName to tfield().name() if not already set template bool store @@ -89,10 +124,10 @@ protected: bool cacheable = false ); - //- Write field if present in objectRegistry + //- Write field if present in the (sub) objectRegistry bool writeObject(const word& fieldName); - //- Clear field from the objectRegistry if present + //- Clear field from the (sub) objectRegistry if present bool clearObject(const word& fieldName); @@ -101,10 +136,10 @@ private: // Private Member Functions //- Disallow default bitwise copy construct - regionFunctionObject(const regionFunctionObject&); + regionFunctionObject(const regionFunctionObject&) = delete; //- Disallow default bitwise assignment - void operator=(const regionFunctionObject&); + void operator=(const regionFunctionObject&) = delete; public: diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C index 5c803a73df..c318770cc0 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C @@ -34,7 +34,7 @@ bool Foam::functionObjects::regionFunctionObject::foundObject const word& fieldName ) const { - return obr_.foundObject(fieldName); + return obr().foundObject(fieldName); } @@ -44,7 +44,37 @@ const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject const word& fieldName ) const { - return obr_.lookupObject(fieldName); + return obr().lookupObject(fieldName); +} + + +template +ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef +( + const word& fieldName +) const +{ + return obr().lookupObjectRef(fieldName); +} + + +template +const ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectPtr +( + const word& fieldName +) const +{ + return obr().lookupObjectPtr(fieldName); +} + + +template +ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectRefPtr +( + const word& fieldName +) const +{ + return obr().lookupObjectRefPtr(fieldName); } @@ -72,8 +102,8 @@ bool Foam::functionObjects::regionFunctionObject::store { const ObjectType& field = lookupObject(fieldName); - // If there is a result field already registered assign to the new - // result field otherwise transfer ownership of the new result field to + // If there is a result field already registered, assign to the new + // result field. Otherwise transfer ownership of the new result field to // the object registry if (&field != &tfield()) { @@ -81,7 +111,7 @@ bool Foam::functionObjects::regionFunctionObject::store } else { - obr_.objectRegistry::store(tfield.ptr()); + obr().objectRegistry::store(tfield.ptr()); } } else @@ -95,7 +125,7 @@ bool Foam::functionObjects::regionFunctionObject::store fieldName = tfield().name(); } - obr_.objectRegistry::store(tfield.ptr()); + obr().objectRegistry::store(tfield.ptr()); } return true; From 08f0f3dddb553637a1f2230f489b4349febee181 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 7 Dec 2016 17:32:31 +0000 Subject: [PATCH 4/8] STYLE: avoid refCast in favour of the fvMeshFunctionObject mesh_ variable --- .../field/fluxSummary/fluxSummary.C | 87 +++++++++---------- .../forces/forceCoeffs/forceCoeffs.C | 14 ++- 2 files changed, 46 insertions(+), 55 deletions(-) diff --git a/src/functionObjects/field/fluxSummary/fluxSummary.C b/src/functionObjects/field/fluxSummary/fluxSummary.C index cfe7a3e18c..63344f52e3 100644 --- a/src/functionObjects/field/fluxSummary/fluxSummary.C +++ b/src/functionObjects/field/fluxSummary/fluxSummary.C @@ -79,21 +79,19 @@ void Foam::functionObjects::fluxSummary::initialiseFaceZone DynamicList>& faceSign ) const { - const fvMesh& mesh = refCast(obr_); - - label zonei = mesh.faceZones().findZoneID(faceZoneName); + label zonei = mesh_.faceZones().findZoneID(faceZoneName); if (zonei == -1) { FatalErrorInFunction << "Unable to find faceZone " << faceZoneName - << ". Valid faceZones are: " << mesh.faceZones().names() + << ". Valid faceZones are: " << mesh_.faceZones().names() << exit(FatalError); } faceZoneNames.append(faceZoneName); - const faceZone& fZone = mesh.faceZones()[zonei]; + const faceZone& fZone = mesh_.faceZones()[zonei]; DynamicList