From b2eb6059628894d59cbce1db227d14ddd1648bb6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 20 Mar 2009 15:17:36 +0100 Subject: [PATCH 1/3] Switch: handle "none" as equivalent to "no" --- src/OpenFOAM/primitives/bools/Switch/Switch.C | 27 ++++++++++++------- src/OpenFOAM/primitives/bools/Switch/Switch.H | 3 ++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 9b7b449a22..8648532a32 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -38,20 +38,20 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] = "off", "on", "no", "yes", "n", "y", + "none", "true", // is there a reasonable counterpart to "none"? "invalid" }; // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // -Foam::Switch::switchType Foam::Switch::asEnum(const bool val) +Foam::Switch::switchType Foam::Switch::asEnum(const bool b) { - return val ? Switch::TRUE : Switch::FALSE; + return b ? Switch::TRUE : Switch::FALSE; } -Foam::Switch::switchType -Foam::Switch::asEnum +Foam::Switch::switchType Foam::Switch::asEnum ( const std::string& str, const bool allowInvalid @@ -61,8 +61,8 @@ Foam::Switch::asEnum { if (str == names[sw]) { - // convert y/n to yes/no (perhaps should deprecate y/n) - if (sw == Switch::NO_1) + // convert n/y to no/yes (perhaps should deprecate y/n) + if (sw == Switch::NO_1 || sw == Switch::NONE) { return Switch::NO; } @@ -90,6 +90,7 @@ Foam::Switch::asEnum bool Foam::Switch::asBool(const switchType sw) { + // relies on (INVALID & 0x1) evaluating to false return (sw & 0x1); } @@ -103,13 +104,19 @@ bool Foam::Switch::asBool // allow invalid values, but catch after for correct error message switchType sw = asEnum(str, true); - if (sw == Switch::INVALID && !allowInvalid) + if (sw == Switch::INVALID) { - FatalErrorIn("Switch::asBool(const std::string&)") - << "unknown switch word " << str << nl - << abort(FatalError); + if (!allowInvalid) + { + FatalErrorIn("Switch::asBool(const std::string&)") + << "unknown switch word " << str << nl + << abort(FatalError); + } + + return false; } + return (sw & 0x1); } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index 4eaa2dd12b..adda09cf4e 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -27,7 +27,7 @@ Class Description A simple wrapper around bool so that it can be read as a word: - true/false, on/off, yes/no or y/n. + true/false, on/off, yes/no or y/n or none. SourceFiles Switch.C @@ -80,6 +80,7 @@ public: OFF = 2, ON = 3, NO = 4, YES = 5, NO_1 = 6, YES_1 = 7, + NONE = 8, PLACEHOLDER = 9, INVALID }; From 549c78f9fecdc2e7ec01609a0f76d593c2574e47 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 23 Mar 2009 14:53:14 +0100 Subject: [PATCH 2/3] PV3FoamReader fix - using a filter such as clip-plane on a multi-port source causes inconsistent UPDATE_TIME_STEPS() on each port. This looks like a VTK/Paraview bug to me. Workaround: check both ports and take the first one that has a value different than the last time set. --- .../PV3FoamReader/vtkPV3FoamReader.cxx | 65 ++++++++++++------- .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C | 40 +++++++++--- .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H | 9 ++- .../vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H | 5 +- 4 files changed, 82 insertions(+), 37 deletions(-) diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx b/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx index c824ec7e3c..0d99f3e95b 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx @@ -52,8 +52,7 @@ vtkPV3FoamReader::vtkPV3FoamReader() // Add second output for the Lagrangian this->SetNumberOfOutputPorts(2); - vtkMultiBlockDataSet *lagrangian; - lagrangian = vtkMultiBlockDataSet::New(); + vtkMultiBlockDataSet *lagrangian = vtkMultiBlockDataSet::New(); lagrangian->ReleaseData(); this->GetExecutive()->SetOutputData(1, lagrangian); @@ -204,9 +203,9 @@ int vtkPV3FoamReader::RequestInformation ); } - double timeRange[2]; if (nTimeSteps) { + double timeRange[2]; timeRange[0] = timeSteps[0]; timeRange[1] = timeSteps[nTimeSteps-1]; @@ -273,19 +272,53 @@ int vtkPV3FoamReader::RequestData } } - // take port0 as the lead for other outputs - vtkInformation *outInfo = outputVector->GetInformationObject(0); + // Get the requested time step. + // We only support requests for a single time step + + int nRequestTime = 0; + double requestTime[nInfo]; + + // taking port0 as the lead for other outputs would be nice, but fails when + // a filter is added - we need to check everything + // but since PREVIOUS_UPDATE_TIME_STEPS() is protected, relay the logic + // to the vtkPV3Foam::setTime() method + for (int infoI = 0; infoI < nInfo; ++infoI) + { + vtkInformation *outInfo = outputVector->GetInformationObject(infoI); + + if + ( + outInfo->Has + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ) + && outInfo->Length + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + ) >= 1 + ) + { + requestTime[nRequestTime++] = outInfo->Get + ( + vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() + )[0]; + } + } + + if (nRequestTime) + { + foamData_->setTime(nRequestTime, requestTime); + } vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast ( - outInfo->Get + outputVector->GetInformationObject(0)->Get ( vtkMultiBlockDataSet::DATA_OBJECT() ) ); - vtkMultiBlockDataSet* lagrangianOutput = vtkMultiBlockDataSet::SafeDownCast ( outputVector->GetInformationObject(1)->Get @@ -294,24 +327,6 @@ int vtkPV3FoamReader::RequestData ) ); - if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS())) - { - // Get the requested time step. - // We only support requests for a single time step - int nRequestedTimeSteps = outInfo->Length - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() - ); - if (nRequestedTimeSteps >= 1) - { - double *requestedTimeSteps = outInfo->Get - ( - vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS() - ); - - foamData_->setTime(requestedTimeSteps[0]); - } - } if (Foam::vtkPV3Foam::debug) { diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C index 4c4016c364..624358b4a0 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C @@ -90,12 +90,21 @@ void Foam::vtkPV3Foam::reduceMemory() -int Foam::vtkPV3Foam::setTime(const double& requestedTime) +int Foam::vtkPV3Foam::setTime(int nRequest, const double requestTimes[]) { if (debug) { - Info<< " Foam::vtkPV3Foam::setTime(" << requestedTime << ")" - << endl; + Info<< " Foam::vtkPV3Foam::setTime("; + for (int requestI = 0; requestI < nRequest; ++requestI) + { + if (requestI) + { + Info<< ", "; + } + + Info<< requestTimes[requestI]; + } + Info << ") - previousIndex = " << timeIndex_ << endl; } Time& runTime = dbPtr_(); @@ -103,12 +112,26 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime) // Get times list instantList Times = runTime.times(); - int nearestIndex = Time::findClosestTimeIndex(Times, requestedTime); + int nearestIndex = timeIndex_; + + for (int requestI = 0; requestI < nRequest; ++requestI) + { + int index = Time::findClosestTimeIndex(Times, requestTimes[requestI]); + + if (index >= 0 && index != timeIndex_) + { + nearestIndex = index; + break; + } + } + + if (nearestIndex < 0) { nearestIndex = 0; } + // see what has changed if (timeIndex_ != nearestIndex) { @@ -138,10 +161,11 @@ int Foam::vtkPV3Foam::setTime(const double& requestedTime) if (debug) { - Info<< " Foam::vtkPV3Foam::setTime() - selected time " - << Times[nearestIndex].name() << " index=" << nearestIndex - << " meshChanged=" << meshChanged_ - << " fieldsChanged=" << fieldsChanged_ << endl; + Info<< " Foam::vtkPV3Foam::setTime() - selectedTime=" + << Times[nearestIndex].name() << " index=" << timeIndex_ + << "/" << Times.size() + << " meshChanged=" << Switch(meshChanged_) + << " fieldsChanged=" << Switch(fieldsChanged_) << endl; } return nearestIndex; diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H index 59e7e86b59..c6dd65af9e 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H @@ -133,6 +133,7 @@ class vtkPV3Foam return block_; } + //- Assign block number, return previous value int block(int blockNo) { int prev = block_; @@ -718,9 +719,11 @@ public: //- Remove patch names from the display void removePatchNames(vtkRenderer* renderer); - //- set the runTime to the requested time, returns the timeIndex - // sets to "constant" on error and returns -1 - int setTime(const double& requestedTime); + //- set the runTime to the first plausible request time, + // returns the timeIndex + // sets to "constant" on error + int setTime(int count, const double requestTimes[]); + //- The current time index int timeIndex() const diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H index 8ef698872d..7e28460a46 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInfoFields.H @@ -40,7 +40,10 @@ void Foam::vtkPV3Foam::updateInfoFields { if (debug) { - Info<< " Foam::vtkPV3Foam::updateInfoFields" << endl; + Info<< " Foam::vtkPV3Foam::updateInfoFields <" + << meshType::Mesh::typeName + << "> [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" + << endl; } stringList enabledEntries; From be8cbc10187fb5194866149fe93dfb83a343e6b7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 23 Mar 2009 16:57:26 +0100 Subject: [PATCH 3/3] use timeSelector mechanism in a few more utilities --- .../estimateScalarError/estimateScalarError.C | 19 +++---- .../icoErrorEstimate/icoErrorEstimate.C | 20 +++---- .../icoMomentError/icoMomentError.C | 20 +++---- .../momentScalarError/momentScalarError.C | 19 +++---- .../foamToStarMesh/foamToStarMesh.C | 17 +++--- .../mesh/conversion/polyDualMesh/Make/files | 2 +- .../{makePolyDualMesh.C => polyDualMeshApp.C} | 4 +- .../conversion/writeMeshObj/writeMeshObj.C | 23 +++----- .../mesh/manipulation/checkMesh/checkMesh.C | 52 +++++++------------ .../mesh/manipulation/rotateMesh/rotateMesh.C | 16 +++--- .../mesh/manipulation/setSet/setSet.C | 4 +- .../miscellaneous/patchSummary/patchSummary.C | 14 ++--- .../foamDataToFluent/foamDataToFluent.C | 14 ++--- .../dataConversion/foamToVTK/foamToVTK.C | 19 +++---- .../postProcessing/miscellaneous/ptot/ptot.C | 15 ++---- .../postProcessing/miscellaneous/wdot/wdot.C | 15 ++---- .../writeCellCentres/writeCellCentres.C | 25 ++++----- .../scalarField/pPrime2/pPrime2.C | 17 ++---- .../stressComponents/stressComponents.C | 16 ++---- .../createTurbulenceFields.C | 15 ++---- .../streamFunction/streamFunction.C | 17 ++---- 21 files changed, 124 insertions(+), 239 deletions(-) rename applications/utilities/mesh/conversion/polyDualMesh/{makePolyDualMesh.C => polyDualMeshApp.C} (99%) diff --git a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C b/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C index c90594ff24..9fb3a646d6 100644 --- a/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C +++ b/applications/utilities/errorEstimation/estimateScalarError/estimateScalarError.C @@ -39,24 +39,17 @@ Description int main(int argc, char *argv[]) { + timeSelector::addOptions(); -# include "addTimeOptions.H" # include "setRootCase.H" - - Info<< "\nEstimating error in scalar transport equation\n" << endl; - # include "createTime.H" - // Get times list - instantList Times = runTime.times(); - -# include "checkTimeOptions.H" - - runTime.setTime(Times[startTime], startTime); + instantList timeDirs = timeSelector::select0(runTime, args); # include "createMesh.H" - Info<< "Reading transportProperties\n" << endl; + Info<< "\nEstimating error in scalar transport equation\n" + << "Reading transportProperties\n" << endl; IOdictionary transportProperties ( @@ -79,9 +72,9 @@ int main(int argc, char *argv[]) ); - for (label i=startTime; i