diff --git a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C index 94891beba0..75362d8bcf 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C +++ b/applications/utilities/preProcessing/viewFactorsGen/viewFactorsGen.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,6 +53,7 @@ Description #include "scalarListIOList.H" #include "polygonTriangulate.H" #include "vtkWritePolyData.H" +#include "scalarMatrices.H" using namespace Foam; diff --git a/etc/controlDict b/etc/controlDict index bfc244900e..ee2c1d4430 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -200,18 +200,14 @@ DimensionSets acceleration [m s^-2] 1; kinematicPressure [Pa density^-1] 1; - // Scaled units. Only allowed in dimensionedType (dimensionedScalar, - // dimensionedVector etc.) and UniformDimensionedField, not - // in DimensionedField or GeometricField + // Scaled units. Supported in dimensionedType and + // UniformDimensionedField. Not supported in DimensionedField or + // GeometricField. cm [m] 1e-2; mm [m] 1e-3; km [m] 1e3; ms [s] 1e-3; us [s] 1e-6; - - // Set of units used for printing. Can be any basic or derived - // but not scaled (only supported for dimensionedScalar, etc) - // writeUnits (kg m s K mol A Cd); } USCSCoeffs @@ -224,10 +220,6 @@ DimensionSets mol [0 0 0 0 1 0 0] 1; A [0 0 0 0 0 1 0] 1; Cd [0 0 0 0 0 0 1] 1; - - // Set of units used for printing. Can be any basic or derived - // but not scaled (only supported for dimensionedScalar, etc) - // writeUnits (lb ft s R mol A Cd); } } diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.H b/src/OpenFOAM/dimensionSet/dimensionSet.H index 96cc28c7ba..fa0fc1b12c 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSet.H +++ b/src/OpenFOAM/dimensionSet/dimensionSet.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,6 @@ Description SourceFiles dimensionSet.C dimensionSetIO.C - dimensionSets.C \*---------------------------------------------------------------------------*/ @@ -55,7 +54,6 @@ namespace Foam // Forward declaration of friend functions and operators class dimensionSet; -class dimensionSets; // Friend Functions @@ -174,6 +172,7 @@ private: void unpop(const token&); + public: // Constructors @@ -202,24 +201,27 @@ private: }; + // Private Data + + //- Array of dimension exponents + scalar exponents_[nDimensions]; + + + // Private Member Functions + //- Reset exponents to nearest integer if close to it. Used to // handle reading with insufficient precision. void round(const scalar tol); + //- Parse tokens into a dimensioned scalar dimensionedScalar parse ( const label lastPrior, tokeniser& tis, - const HashTable& + const HashTable& readSet ) const; - // private data - - // dimensionSet stored as an array of dimension exponents - scalar exponents_[nDimensions]; - - public: // Declare name of the class and its debug switch @@ -275,43 +277,12 @@ public: // I/O - //- Read using provided units. Used only in initial parsing - Istream& read - ( - Istream& is, - scalar& multiplier, - const dictionary& - ); + //- Read using units from the system table. Return the multiplier with + // which to convert associated values to the given units. + Istream& read(Istream& is, scalar& multiplier); - //- Read using provided units - Istream& read - ( - Istream& is, - scalar& multiplier, - const HashTable& - ); - - //- Read using system units - Istream& read - ( - Istream& is, - scalar& multiplier - ); - - //- Write using provided units - Ostream& write - ( - Ostream& os, - scalar& multiplier, - const dimensionSets& - ) const; - - //- Write using system units - Ostream& write - ( - Ostream& os, - scalar& multiplier - ) const; + //- Write + Ostream& write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/dimensionSet/dimensionSetIO.C b/src/OpenFOAM/dimensionSet/dimensionSetIO.C index 67a99d90e7..fc2635687c 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSetIO.C +++ b/src/OpenFOAM/dimensionSet/dimensionSetIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,24 +28,7 @@ License #include "dimensionedScalar.H" #include -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::dimensionSet::dimensionSet(Istream& is) -{ - is >> *this; -} - - -Foam::dimensionSet::tokeniser::tokeniser(Istream& is) -: - is_(is), - tokens_(100), - start_(0), - size_(0) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::dimensionSet::tokeniser::push(const token& t) { @@ -79,141 +62,6 @@ void Foam::dimensionSet::tokeniser::unpop(const token& t) } -bool Foam::dimensionSet::tokeniser::hasToken() const -{ - return size_ || is_.good(); -} - - -bool Foam::dimensionSet::tokeniser::valid(char c) -{ - return - ( - !isspace(c) - && c != '"' // string quote - && c != '\'' // string quote - && c != '/' // div - && c != ';' // end statement - && c != '{' // beg subdict - && c != '}' // end subdict - && c != '(' // beg expr - && c != ')' // end expr - && c != '[' // beg dim - && c != ']' // end dim - && c != '^' // power - && c != '*' // mult - ); -} - - -Foam::label Foam::dimensionSet::tokeniser::priority(const token& t) -{ - if (!t.isPunctuation()) - { - return 0; - } - else if - ( - t.pToken() == token::MULTIPLY - || t.pToken() == token::DIVIDE - ) - { - return 2; - } - else if (t.pToken() == '^') - { - return 3; - } - else - { - return 0; - } -} - - -void Foam::dimensionSet::tokeniser::splitWord(const word& w) -{ - size_t start = 0; - for (size_t i=0; i start) - { - word subWord = w(start, i-start); - if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) - { - push(token(readScalar(IStringStream(subWord)()))); - } - else - { - push(token(subWord)); - } - } - if (w[i] != token::SPACE) - { - if (isdigit(w[i])) - { - push(token(readScalar(IStringStream(w[i])()))); - } - else - { - push(token::punctuationToken(w[i])); - } - } - start = i+1; - } - } - if (start < w.size()) - { - word subWord = w(start, w.size()-start); - if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) - { - push(token(readScalar(IStringStream(subWord)()))); - } - else - { - push(token(subWord)); - } - } -} - - -Foam::token Foam::dimensionSet::tokeniser::nextToken() -{ - if (size_ == 0) - { - token t(is_); - if (t.isWord()) - { - splitWord(t.wordToken()); - return pop(); - } - else - { - return t; - } - } - else - { - return pop(); - } -} - - -void Foam::dimensionSet::tokeniser::putBack(const token& t) -{ - if (size_ == 0) - { - push(t); - } - else - { - unpop(t); - } -} - - void Foam::dimensionSet::round(const scalar tol) { for (int i=0; i < dimensionSet::nDimensions; ++i) @@ -253,7 +101,6 @@ Foam::dimensionedScalar Foam::dimensionSet::parse // symbols and assume multiplication bool haveReadSymbol = false; - while (true) { if (nextToken.isWord()) @@ -348,8 +195,10 @@ Foam::dimensionedScalar Foam::dimensionSet::parse dimensionedScalar exp(parse(nextPrior, tis, readSet)); ds.dimensions().reset(pow(ds.dimensions(), exp.value())); + // Round to nearest integer if close to it ds.dimensions().round(10*smallExponent); + ds.value() = Foam::pow(ds.value(), exp.value()); } else @@ -399,11 +248,164 @@ Foam::dimensionedScalar Foam::dimensionSet::parse } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::dimensionSet::dimensionSet(Istream& is) +{ + is >> *this; +} + + +Foam::dimensionSet::tokeniser::tokeniser(Istream& is) +: + is_(is), + tokens_(100), + start_(0), + size_(0) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::dimensionSet::tokeniser::hasToken() const +{ + return size_ || is_.good(); +} + + +Foam::token Foam::dimensionSet::tokeniser::nextToken() +{ + if (size_ == 0) + { + token t(is_); + if (t.isWord()) + { + splitWord(t.wordToken()); + return pop(); + } + else + { + return t; + } + } + else + { + return pop(); + } +} + + +void Foam::dimensionSet::tokeniser::putBack(const token& t) +{ + if (size_ == 0) + { + push(t); + } + else + { + unpop(t); + } +} + + +void Foam::dimensionSet::tokeniser::splitWord(const word& w) +{ + size_t start = 0; + for (size_t i=0; i start) + { + word subWord = w(start, i-start); + if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) + { + push(token(readScalar(IStringStream(subWord)()))); + } + else + { + push(token(subWord)); + } + } + if (w[i] != token::SPACE) + { + if (isdigit(w[i])) + { + push(token(readScalar(IStringStream(w[i])()))); + } + else + { + push(token::punctuationToken(w[i])); + } + } + start = i+1; + } + } + if (start < w.size()) + { + word subWord = w(start, w.size()-start); + if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT) + { + push(token(readScalar(IStringStream(subWord)()))); + } + else + { + push(token(subWord)); + } + } +} + + +bool Foam::dimensionSet::tokeniser::valid(char c) +{ + return + ( + !isspace(c) + && c != '"' // string quote + && c != '\'' // string quote + && c != '/' // div + && c != ';' // end statement + && c != '{' // beg subdict + && c != '}' // end subdict + && c != '(' // beg expr + && c != ')' // end expr + && c != '[' // beg dim + && c != ']' // end dim + && c != '^' // power + && c != '*' // mult + ); +} + + +Foam::label Foam::dimensionSet::tokeniser::priority(const token& t) +{ + if (!t.isPunctuation()) + { + return 0; + } + else if + ( + t.pToken() == token::MULTIPLY + || t.pToken() == token::DIVIDE + ) + { + return 2; + } + else if (t.pToken() == '^') + { + return 3; + } + else + { + return 0; + } +} + + Foam::Istream& Foam::dimensionSet::read ( Istream& is, - scalar& multiplier, - const HashTable& readSet + scalar& multiplier ) { multiplier = 1.0; @@ -430,7 +432,7 @@ Foam::Istream& Foam::dimensionSet::read tokeniser tis(is); - dimensionedScalar ds(parse(0, tis, readSet)); + dimensionedScalar ds(parse(0, tis, unitSet())); multiplier = ds.value(); for (int i=0; i < dimensionSet::nDimensions; ++i) @@ -477,145 +479,6 @@ Foam::Istream& Foam::dimensionSet::read << exit(FatalIOError); } } - // Check state of Istream - is.check("Istream& operator>>(Istream&, dimensionSet&)"); - - return is; -} - - -Foam::Istream& Foam::dimensionSet::read -( - Istream& is, - scalar& multiplier -) -{ - return read(is, multiplier, unitSet()); -} - - -Foam::Istream& Foam::dimensionSet::read -( - Istream& is, - scalar& multiplier, - const dictionary& readSet -) -{ - multiplier = 1.0; - - // Read beginning of dimensionSet - token startToken(is); - - if (startToken != token::BEGIN_SQR) - { - FatalIOErrorInFunction - ( - is - ) << "expected a " << token::BEGIN_SQR << " in dimensionSet" - << endl << "in stream " << is.info() - << exit(FatalIOError); - } - - // Read next token - token nextToken(is); - - if (nextToken.isWord()) - { - bool continueParsing = true; - do - { - word symbolPow = nextToken.wordToken(); - if (symbolPow[symbolPow.size()-1] == token::END_SQR) - { - symbolPow = symbolPow(0, symbolPow.size()-1); - continueParsing = false; - } - - - // Parse unit - dimensionSet symbolSet(dimless); - - size_t index = symbolPow.find('^'); - if (index != string::npos) - { - word symbol = symbolPow(0, index); - word exp = symbolPow(index+1, symbolPow.size()-index+1); - scalar exponent = readScalar(IStringStream(exp)()); - - dimensionedScalar s; - s.read(readSet[symbol], readSet); - - symbolSet.reset(pow(s.dimensions(), exponent)); - // Round to nearest integer if close to it - symbolSet.round(10*smallExponent); - multiplier *= Foam::pow(s.value(), exponent); - } - else - { - dimensionedScalar s; - s.read(readSet[symbolPow], readSet); - - symbolSet.reset(s.dimensions()); - multiplier *= s.value(); - } - - // Add dimensions without checking - for (int i=0; i < dimensionSet::nDimensions; ++i) - { - exponents_[i] += symbolSet[i]; - } - - if (continueParsing) - { - nextToken = token(is); - - if (!nextToken.isWord() || nextToken == token::END_SQR) - { - continueParsing = false; - } - } - } - while (continueParsing); - } - else - { - // Read first five dimensions - exponents_[dimensionSet::MASS] = nextToken.number(); - for (int Dimension=1; Dimension> exponents_[Dimension]; - } - - // Read next token - token nextToken(is); - - // If next token is another number - // read last two dimensions - // and then read another token for the end of the dimensionSet - if (nextToken.isNumber()) - { - exponents_[dimensionSet::CURRENT] = nextToken.number(); - is >> nextToken; - exponents_[dimensionSet::LUMINOUS_INTENSITY] = nextToken.number(); - is >> nextToken; - } - else - { - exponents_[dimensionSet::CURRENT] = 0; - exponents_[dimensionSet::LUMINOUS_INTENSITY] = 0; - } - - // Check end of dimensionSet - if (nextToken != token::END_SQR) - { - FatalIOErrorInFunction - ( - is - ) << "expected a " << token::END_SQR << " in dimensionSet " - << endl << "in stream " << is.info() - << exit(FatalIOError); - } - } // Check state of Istream is.check("Istream& operator>>(Istream&, dimensionSet&)"); @@ -624,72 +487,16 @@ Foam::Istream& Foam::dimensionSet::read } -Foam::Ostream& Foam::dimensionSet::write -( - Ostream& os, - scalar& multiplier, - const dimensionSets& writeUnits -) const +Foam::Ostream& Foam::dimensionSet::write(Ostream& os) const { - multiplier = 1.0; - os << token::BEGIN_SQR; - if (writeUnits.valid() && os.format() == IOstream::ASCII) + for (int d=0; d::digits10 - ); - - forAll(exponents, i) - { - if (mag(exponents[i]) > smallExponent) - { - const dimensionedScalar& ds = writeUnits.units()[i]; - - if (hasPrinted) - { - os << token::SPACE; - } - hasPrinted = true; - os << ds.name(); - if (mag(exponents[i]-1) > smallExponent) - { - os << '^' << exponents[i]; - - multiplier *= Foam::pow(ds.value(), exponents[i]); - } - else - { - multiplier *= ds.value(); - } - } - } - - // Reset precision - os.precision(oldPrecision); - } - else - { - for (int d=0; d>(Istream& is, dimensionSet& dset) Foam::Ostream& Foam::operator<<(Ostream& os, const dimensionSet& dset) { - scalar multiplier; - dset.write(os, multiplier); + dset.write(os); // Check state of Ostream os.check("Ostream& operator<<(Ostream&, const dimensionSet&)"); diff --git a/src/OpenFOAM/dimensionSet/dimensionSets.C b/src/OpenFOAM/dimensionSet/dimensionSets.C index 5739c4761b..c97991a9a2 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSets.C +++ b/src/OpenFOAM/dimensionSet/dimensionSets.C @@ -29,150 +29,6 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - -// Since dimensionSystems() can be reread we actually store a copy of -// the controlDict subDict (v.s. a reference to the subDict for e.g. -// dimensionedConstants) -dictionary* dimensionSystemsPtr_(nullptr); -HashTable* addedUnitsPtr_(nullptr); -HashTable* unitSetPtr_(nullptr); -dimensionSets* writeUnitSetPtr_(nullptr); - -// Delete the above data at the end of the run -struct deleteDimensionSystemsPtr -{ - ~deleteDimensionSystemsPtr() - { - deleteDemandDrivenData(dimensionSystemsPtr_); - deleteDemandDrivenData(unitSetPtr_); - deleteDemandDrivenData(writeUnitSetPtr_); - } -}; - -deleteDimensionSystemsPtr deleteDimensionSystemsPtr_; - -} - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -Foam::dictionary& Foam::dimensionSystems() -{ - if (!dimensionSystemsPtr_) - { - dictionary* cachedPtr = nullptr; - dimensionSystemsPtr_ = new dictionary - ( - debug::switchSet - ( - "DimensionSets", - cachedPtr - ) - ); - } - return *dimensionSystemsPtr_; -} - - -void Foam::addUnit(const dimensionedScalar& unit) -{ - deleteDemandDrivenData(unitSetPtr_); - deleteDemandDrivenData(writeUnitSetPtr_); - - if (!addedUnitsPtr_) - { - addedUnitsPtr_ = new HashTable(); - } - - addedUnitsPtr_->insert(unit.name(), unit); -} - - -const Foam::HashTable& Foam::unitSet() -{ - if (!unitSetPtr_) - { - const dictionary& dict = dimensionSystems(); - - if (!dict.found("unitSet")) - { - FatalIOErrorInFunction(dict) - << "Cannot find unitSet in dictionary " << dict.name() - << exit(FatalIOError); - } - - const word unitSetCoeffs(word(dict.lookup("unitSet")) + "Coeffs"); - - if (!dict.found(unitSetCoeffs)) - { - FatalIOErrorInFunction(dict) - << "Cannot find " << unitSetCoeffs << " in dictionary " - << dict.name() << exit(FatalIOError); - } - - const dictionary& unitDict = dict.subDict(unitSetCoeffs); - - unitSetPtr_ = new HashTable(unitDict.size()); - - forAllConstIter(dictionary, unitDict, iter) - { - if (iter().keyword() != "writeUnits") - { - dimensionedScalar dt(iter().keyword(), iter().stream()); - const bool ok = unitSetPtr_->insert(iter().keyword(), dt); - if (!ok) - { - FatalIOErrorInFunction(dict) - << "Duplicate unit " << iter().keyword() - << " in DimensionSets dictionary" - << exit(FatalIOError); - } - } - } - - if (addedUnitsPtr_) - { - forAllConstIter(HashTable, *addedUnitsPtr_, iter) - { - unitSetPtr_->insert(iter.key(), iter()); - } - } - - const wordList writeUnitNames - ( - unitDict.lookupOrDefault - ( - "writeUnits", - wordList(0) - ) - ); - - writeUnitSetPtr_ = new dimensionSets(*unitSetPtr_, writeUnitNames); - - if (writeUnitNames.size() != 0 && writeUnitNames.size() != 7) - { - FatalIOErrorInFunction(dict) - << "Cannot find entry \"writeUnits\" in " << unitDict.name() - << " or it is not a wordList of size 7" - << exit(FatalIOError); - } - } - - return *unitSetPtr_; -} - - -const Foam::dimensionSets& Foam::writeUnitSet() -{ - if (!writeUnitSetPtr_) - { - (void)unitSet(); - } - return *writeUnitSetPtr_; -} - - const Foam::dimensionSet Foam::dimless(0, 0, 0, 0, 0, 0, 0); const Foam::dimensionSet Foam::dimMass(1, 0, 0, 0, 0, 0, 0); @@ -207,56 +63,126 @@ const Foam::dimensionSet Foam::dimFlux(dimArea*dimVelocity); const Foam::dimensionSet Foam::dimMassFlux(dimDensity*dimFlux); -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::dimensionSets::dimensionSets -( - const HashTable& units, - const wordList& unitNames -) -: - units_(unitNames.size()), - conversion_(unitNames.size()), - conversionPivots_(unitNames.size()), - valid_(false) +namespace Foam { - forAll(unitNames, i) + +dictionary* dimensionSetsDictPtr_(nullptr); + +const dictionary& dimensionSetsDict() +{ + if (!dimensionSetsDictPtr_) { - units_.set + dictionary* cachedPtr = nullptr; + dimensionSetsDictPtr_ = new dictionary ( - i, - new dimensionedScalar + debug::switchSet ( - units[unitNames[i]] + "DimensionSets", + cachedPtr ) ); } - if (unitNames.size() == 7) + return *dimensionSetsDictPtr_; +} + +HashTable* addedUnitsPtr_(nullptr); +HashTable* unitSetPtr_(nullptr); + +// Delete the above data at the end of the run +struct deleteDimensionSystemsPtr +{ + ~deleteDimensionSystemsPtr() { - valid_ = true; - - // Determine conversion from basic units to write units - for (label rowI = 0; rowI < conversion_.m(); rowI++) - { - scalar* row = conversion_[rowI]; - - for (label columnI = 0; columnI < conversion_.n(); columnI++) - { - const dimensionedScalar& dSet = units_[columnI]; - row[columnI] = dSet.dimensions()[rowI]; - } - } - - conversionPivots_.setSize(conversion_.m()); - LUDecompose(conversion_, conversionPivots_); + deleteDemandDrivenData(dimensionSetsDictPtr_); + deleteDemandDrivenData(addedUnitsPtr_); + deleteDemandDrivenData(unitSetPtr_); } +}; + +deleteDimensionSystemsPtr deleteDimensionSystemsPtr_; + +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +void Foam::addUnit(const dimensionedScalar& unit) +{ + deleteDemandDrivenData(dimensionSetsDictPtr_); + + if (!addedUnitsPtr_) + { + addedUnitsPtr_ = new HashTable(); + } + + addedUnitsPtr_->insert(unit.name(), unit); + + deleteDemandDrivenData(unitSetPtr_); } -void Foam::dimensionSets::coefficients(scalarField& exponents) const +const Foam::HashTable& Foam::unitSet() { - LUBacksubstitute(conversion_, conversionPivots_, exponents); + if (!unitSetPtr_) + { + const dictionary& dimSetsDict = dimensionSetsDict(); + + if (!dimSetsDict.found("unitSet")) + { + FatalIOErrorInFunction(dimSetsDict) + << "Cannot find unitSet in dictionary " << dimSetsDict.name() + << exit(FatalIOError); + } + + const word unitSetDictName = + dimSetsDict.lookup("unitSet") + "Coeffs"; + + if (!dimSetsDict.found(unitSetDictName)) + { + FatalIOErrorInFunction(dimSetsDict) + << "Cannot find " << unitSetDictName << " in dictionary " + << dimSetsDict.name() << exit(FatalIOError); + } + + const dictionary& unitSetDict = dimSetsDict.subDict(unitSetDictName); + + unitSetPtr_ = new HashTable(unitSetDict.size()); + + forAllConstIter(dictionary, unitSetDict, iter) + { + const dimensionedScalar dt(iter().keyword(), iter().stream()); + + const bool ok = unitSetPtr_->insert(iter().keyword(), dt); + + if (!ok) + { + FatalIOErrorInFunction(dimSetsDict) + << "Duplicate unit " << iter().keyword() + << " read from dictionary" + << exit(FatalIOError); + } + } + + if (addedUnitsPtr_) + { + forAllConstIter(HashTable, *addedUnitsPtr_, iter) + { + const bool ok = unitSetPtr_->insert(iter.key(), iter()); + + if (!ok) + { + FatalIOErrorInFunction(dimSetsDict) + << "Duplicate unit " << iter.key() + << " added to dictionary" + << exit(FatalIOError); + } + } + } + } + + return *unitSetPtr_; } diff --git a/src/OpenFOAM/dimensionSet/dimensionSets.H b/src/OpenFOAM/dimensionSet/dimensionSets.H index bef693410e..10c4a39eea 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSets.H +++ b/src/OpenFOAM/dimensionSet/dimensionSets.H @@ -35,9 +35,7 @@ SourceFiles #ifndef dimensionSets_H #define dimensionSets_H -#include "scalarMatrices.H" -#include "dimensionedScalarFwd.H" -#include "PtrList.H" +#include "dimensionSet.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,65 +78,12 @@ extern const dimensionSet dimFlux; extern const dimensionSet dimMassFlux; -class dimensionSets -{ - // Private Data - - //- Set of dimensions - PtrList units_; - - //- LU decomposition of dimensions - scalarSquareMatrix conversion_; - - //- See above - labelList conversionPivots_; - - //- Is LU decomposition valid - bool valid_; - - -public: - - // Constructors - - //- Construct from all units and set of units to use for inversion - dimensionSets - ( - const HashTable&, - const wordList& unitNames - ); - - - // Member Functions - - //- Return the units - const PtrList& units() const - { - return units_; - } - - //- Is there a valid inverse of the selected unit - bool valid() const - { - return valid_; - } - - //- (if valid) obtain set of coefficients of unitNames - void coefficients(scalarField&) const; -}; - - -//- Top level dictionary -dictionary& dimensionSystems(); - //- Add a unit void addUnit(const dimensionedScalar& unit); -//- Set of all dimensions -const HashTable& unitSet(); -//- Set of units -const dimensionSets& writeUnitSet(); +//- Set of all units +const HashTable& unitSet(); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index edef2f6c38..43f4008609 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -334,60 +334,6 @@ bool Foam::dimensioned::readIfPresent(const dictionary& dict) } -template -Foam::Istream& -Foam::dimensioned::read(Istream& is, const dictionary& readSet) -{ - // Read name - is >> name_; - - // Read dimensionSet + multiplier - scalar mult; - dimensions_.read(is, mult, readSet); - - // Read value - is >> value_; - value_ *= mult; - - // Check state of Istream - is.check - ( - "Istream& dimensioned::read(Istream& is, const dictionary&)" - ); - - return is; -} - - -template -Foam::Istream& Foam::dimensioned::read -( - Istream& is, - const HashTable& readSet -) -{ - // Read name - is >> name_; - - // Read dimensionSet + multiplier - scalar mult; - dimensions_.read(is, mult, readSet); - - // Read value - is >> value_; - value_ *= mult; - - // Check state of Istream - is.check - ( - "Istream& dimensioned::read" - "(Istream& is, const HashTable&)" - ); - - return is; -} - - template Foam::Istream& Foam::dimensioned::read(Istream& is) { @@ -645,13 +591,12 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dimensioned& dt) os << dt.name() << token::SPACE; // Write the dimensions - scalar mult; - dt.dimensions().write(os, mult); + dt.dimensions().write(os); os << token::SPACE; // Write the value - os << dt.value()/mult; + os << dt.value(); // Check state of Ostream os.check("Ostream& operator<<(Ostream&, const dimensioned&)"); diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H index f6e5b67d1c..ad7842c669 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -198,13 +198,7 @@ public: // I/O - //- Read value from stream and units from dictionary - Istream& read(Istream& is, const dictionary&); - - //- Read value from stream and units from table - Istream& read(Istream& is, const HashTable&); - - //- Read value from stream and units from system table + //- Read value from stream using units from the system table Istream& read(Istream& is); diff --git a/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.C b/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.C index 09826fe706..e25c65efcd 100644 --- a/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.C +++ b/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -96,10 +96,9 @@ Foam::UniformDimensionedField::~UniformDimensionedField() template bool Foam::UniformDimensionedField::writeData(Ostream& os) const { - scalar multiplier; writeKeyword(os, "dimensions"); - this->dimensions().write(os, multiplier) << token::END_STATEMENT << nl; - writeEntry(os, "value", this->value()/multiplier); + this->dimensions().write(os) << token::END_STATEMENT << nl; + writeEntry(os, "value", this->value()); os << nl; return (os.good()); diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index c6e27cb49c..0d5c059748 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,6 +36,7 @@ License #include "symmTensor2D.H" #include "transform.H" #include "OSspecific.H" +#include "scalarMatrices.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //