/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ 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 3 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, see . \*---------------------------------------------------------------------------*/ #include "units.H" #include "demandDrivenData.H" #include "dictionary.H" #include "symbols.H" #include "mathematicalConstants.H" using namespace Foam::constant::mathematical; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { dictionary* unitsDictPtr_(nullptr); const dictionary& unitsDict() { if (!unitsDictPtr_) { dictionary* cachedPtr = nullptr; unitsDictPtr_ = new dictionary ( debug::switchSet ( debug::configDict().found("units") ? "units" : debug::configDict().found("UnitSets") ? "UnitSets" : debug::configDict().found("DimensionSets") ? "DimensionSets" : "units", cachedPtr ) ); } return *unitsDictPtr_; } HashTable* addedUnitsPtr_(nullptr); HashTable* unitsPtr_(nullptr); // Delete the above data at the end of the run struct deleteUnitsPtr { ~deleteUnitsPtr() { deleteDemandDrivenData(unitsDictPtr_); deleteDemandDrivenData(addedUnitsPtr_); deleteDemandDrivenData(unitsPtr_); } }; deleteUnitsPtr deleteUnitsPtr_; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace units { unitSet newFraction() { return unitSet(dimensionSet(0, 0, 0, 0, 0), 1, 0, 1); } unitSet newPercent() { return unitSet(dimensionSet(0, 0, 0, 0, 0), 1, 0, 0.01); } unitSet newRadians() { return unitSet(dimensionSet(0, 0, 0, 0, 0), 0, 1, 1); } unitSet newRotations() { return unitSet(dimensionSet(0, 0, 0, 0, 0), 0, 1, 2*pi); } unitSet newDegrees() { return unitSet(dimensionSet(0, 0, 0, 0, 0), 0, 1, pi/180); } unitSet length_(dimensionSet(0, 1, 0, 0, 0), 0, 0, 1); } } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // const Foam::unitSet Foam::units::unitless(unitSet::newUnitless()); const Foam::unitSet Foam::units::any(unitSet::newAny()); const Foam::unitSet Foam::units::none(unitSet::newNone()); const Foam::unitSet Foam::units::fraction(newFraction()); const Foam::unitSet Foam::units::percent(newPercent()); const Foam::unitSet Foam::units::radians(newRadians()); const Foam::unitSet Foam::units::rotations(newRotations()); const Foam::unitSet Foam::units::degrees(newDegrees()); const Foam::unitSet& Foam::units::length = Foam::units::length_; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // const Foam::HashTable& Foam::units::table() { if (!unitsPtr_) { unitsPtr_ = new HashTable(); unitsPtr_->insert("%", newPercent()); unitsPtr_->insert("rad", newRadians()); unitsPtr_->insert("rot", newRotations()); unitsPtr_->insert("deg", newDegrees()); // Get the relevant part of the control dictionary const dictionary& unitSetDict = unitsDict().subDict(unitsDict().lookup("set")); // Read fundamental units HashTable