From 171101d1e539c24cec3c75e8aa4192aa5fbfb4fc Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 12 Oct 2023 10:04:40 +0100 Subject: [PATCH] fvModels: Specify source property values in field files When an fvModel source introduces fluid into a simulation it should also create a corresponding source term for all properties transported into the domain by that injection. The source is, effectively, an alternative form of inlet boundary, on which all transported properties need an inlet value specified. These values are now specified in the property field files. The following is an example of a 0/U file in which the velocity of fluid introduced by a fvModel source called "injection1" is set to a fixed value of (-1 0 0): dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { #includeEtc "caseDicts/setConstraintTypes" wall { type noSlip; } atmosphere { type pressureInletOutletVelocity; value $internalField; } } // *** NEW *** sources { injection1 { type uniformFixedValue; uniformValue (-1 0 0); } } And the following entry in the 0/k file specifies the turbulent kinetic energy introduced as a fraction of the mean flow kinetic energy: sources { injection1 { type turbulentIntensityKineticEnergy; intensity 0.05; } } The specification is directly analogous to boundary conditions. The conditions are run-time selectable and can be concisely implemented. They can access each other and be inter-dependent (e.g., the above, where turbulent kinetic energy depends on velocity). The syntax keeps field data localised and makes the source model (e.g., massSource, volumeSource, ...) specification independent from what other models and fields are present in the simulation. The 'fieldValues' entry previously required by source models is now no longer required. If source values need specifying and no source condition has been supplied in the relevant field file then an error will be generated. This error is similar to that generated for missing boundary conditions. This replaces the behaviour where sources such as these would introduce a value of zero, either silently or with a warning. This is now considered unacceptable. Zero might be a tolerable default for certain fields (U, k), but is wholly inappropriate for others (T, epsilon, rho). This change additionally makes it possible to inject fluid into a multicomponent solver with a specified temperature. Previously, it was not possible to do this as there was no means of evaluating the energy of fluid with the injected composition. --- .../decomposePar/fvFieldDecomposerTemplates.C | 3 +- .../fvFieldReconstructorTemplates.C | 3 +- .../redistributePar/redistributePar.C | 1 + .../momentumTransportModels/Make/files | 12 +- ...LengthDissipationRateFvScalarFieldSource.C | 123 ++++++ ...LengthDissipationRateFvScalarFieldSource.H | 161 ++++++++ ...MixingLengthFrequencyFvScalarFieldSource.C | 123 ++++++ ...MixingLengthFrequencyFvScalarFieldSource.H | 161 ++++++++ .../GeometricField/GeometricField.C | 109 ++++-- .../GeometricField/GeometricField.H | 52 ++- .../GeometricField/GeometricFieldI.H | 11 +- .../GeometricField/GeometricFieldSources.C | 260 +++++++++++++ .../GeometricField/GeometricFieldSources.H | 252 ++++++++++++ .../pointFields/pointFieldsFwd.H | 8 +- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 8 + src/finiteVolume/Make/files | 12 + .../cfdTools/general/fvModels/fvModel.C | 10 +- .../cfdTools/general/fvModels/fvModel.H | 10 +- .../cfdTools/general/fvModels/fvModelM.H | 9 - .../cfdTools/general/fvSource/fvSource.C | 72 ++++ .../cfdTools/general/fvSource/fvSource.H | 127 +++++++ .../cfdTools/general/fvSource/fvTotalSource.C | 133 +++++++ .../cfdTools/general/fvSource/fvTotalSource.H | 180 +++++++++ .../general/fvSource/fvTotalSourceI.H | 36 ++ .../general/fvSource/fvTotalSourceTemplates.C | 124 ++++++ .../derived/internal/internalFvFieldSource.C | 85 +++++ .../derived/internal/internalFvFieldSource.H | 126 ++++++ .../derived/internal/internalFvFieldSources.C | 44 +++ .../derived/internal/internalFvFieldSources.H | 49 +++ .../internal/internalFvFieldSourcesFwd.H | 50 +++ ...ntensityKineticEnergyFvScalarFieldSource.C | 113 ++++++ ...ntensityKineticEnergyFvScalarFieldSource.H | 160 ++++++++ .../uniformFixedValueFvFieldSource.C | 95 +++++ .../uniformFixedValueFvFieldSource.H | 163 ++++++++ .../uniformFixedValueFvFieldSources.C | 44 +++ .../uniformFixedValueFvFieldSources.H | 49 +++ .../uniformFixedValueFvFieldSourcesFwd.H | 50 +++ .../uniformInletOutletFvFieldSource.C | 97 +++++ .../uniformInletOutletFvFieldSource.H | 164 ++++++++ .../uniformInletOutletFvFieldSources.C | 44 +++ .../uniformInletOutletFvFieldSources.H | 49 +++ .../uniformInletOutletFvFieldSourcesFwd.H | 50 +++ .../fvFieldSource/fvFieldSource.C | 231 +++++++++++ .../fvFieldSource/fvFieldSource.H | 326 ++++++++++++++++ .../fvFieldSource/fvFieldSources.C | 46 +++ .../fvFieldSource/fvFieldSources.H | 36 ++ .../fvFieldSource/fvFieldSourcesFwd.H | 56 +++ .../fields/surfaceFields/surfaceFieldsFwd.H | 8 +- src/finiteVolume/fields/volFields/volFields.H | 3 +- .../fields/volFields/volFieldsFwd.H | 5 +- src/finiteVolume/surfaceMesh/surfaceMesh.H | 51 ++- src/finiteVolume/volMesh/volMesh.H | 9 +- .../zeroDimensionalFixedPressureModel.C | 5 +- src/fvModels/Make/files | 2 + src/fvModels/derived/massSource/massSource.C | 358 ++---------------- src/fvModels/derived/massSource/massSource.H | 257 +++---------- .../derived/massSource/massSourceBase.C | 235 ++++++++++++ .../derived/massSource/massSourceBase.H | 163 ++++++++ .../derived/volumeSource/volumeSource.C | 307 +++++++-------- .../derived/volumeSource/volumeSource.H | 85 +---- .../zeroDimensionalMassSource.C | 194 +--------- .../zeroDimensionalMassSource.H | 92 +---- .../zeroDimensionalMassSourceBase.C | 287 ++++++++++++++ .../zeroDimensionalMassSourceBase.H | 145 +++++++ src/generic/genericFvFields/Make/files | 1 + .../genericFvFieldSource.C | 122 ++++++ .../genericFvFieldSource.H | 130 +++++++ .../genericFvFieldSources.C | 44 +++ .../genericFvFieldSources.H | 49 +++ .../snappyHexMeshDriver/snappyLayerDriver.C | 1 + src/thermophysicalModels/basic/Make/files | 5 + .../basic/basicThermo/BasicThermo.C | 64 +++- .../basic/basicThermo/BasicThermo.H | 21 +- .../basic/basicThermo/basicThermo.C | 52 +-- .../basic/basicThermo/basicThermo.H | 16 +- .../basic/basicThermo/basicThermoTemplates.C | 36 ++ ...CalculatedTemperatureFvScalarFieldSource.C | 84 ++++ ...CalculatedTemperatureFvScalarFieldSource.H | 99 +++++ .../energy/energyFvScalarFieldSource.C | 112 ++++++ .../energy/energyFvScalarFieldSource.H | 116 ++++++ ...ixedEnergyTemperatureFvScalarFieldSource.C | 110 ++++++ ...ixedEnergyTemperatureFvScalarFieldSource.H | 138 +++++++ ...tletEnergyTemperatureFvScalarFieldSource.C | 112 ++++++ ...tletEnergyTemperatureFvScalarFieldSource.H | 144 +++++++ .../basic/pureThermo/pureThermo.H | 6 + .../basic/pureThermo/pureThermoI.H | 16 + .../include/FieldListSlice.H | 14 + .../include/GeometricFieldListSlicer.H | 18 +- .../multicomponentThermo.H | 10 + .../multicomponentThermoI.H | 32 ++ .../psiuMulticomponentThermo.H | 10 + .../psiuMulticomponentThermoI.H | 32 ++ .../constSolidThermo/constSolidThermo.C | 14 +- .../constSolidThermo/constSolidThermo.H | 7 + .../populationBalance/drift/0/U.water | 8 + .../populationBalance/drift/constant/fvModels | 8 +- .../isothermalGrowth/0/U.air1 | 9 + .../isothermalGrowth/0/f0.air1 | 9 + .../isothermalGrowth/0/fDefault.air1 | 9 + .../isothermalGrowth/constant/fvModels | 17 +- .../populationBalance/negativeDrift/0/U.water | 9 + .../negativeDrift/constant/fvModels | 8 +- tutorials/compressibleVoF/damBreak/0/T | 17 +- tutorials/compressibleVoF/damBreak/0/U | 17 +- .../damBreak/0/alpha.water.orig | 17 +- tutorials/compressibleVoF/damBreak/0/epsilon | 19 +- tutorials/compressibleVoF/damBreak/0/k | 19 +- tutorials/compressibleVoF/damBreak/0/nuTilda | 17 +- tutorials/compressibleVoF/damBreak/0/nut | 19 +- tutorials/compressibleVoF/damBreak/0/omega | 19 +- tutorials/compressibleVoF/damBreak/0/p | 19 +- tutorials/compressibleVoF/damBreak/0/p_rgh | 19 +- .../compressibleVoF/damBreakInjection/0/T | 47 +++ .../compressibleVoF/damBreakInjection/0/U | 47 +++ .../damBreakInjection/0/epsilon | 49 +++ .../compressibleVoF/damBreakInjection/0/k | 49 +++ .../damBreakInjection/Allclean | 10 +- .../compressibleVoF/damBreakInjection/Allrun | 3 +- .../constant/{fvModels.injection => fvModels} | 14 +- .../incompressibleFluid/blockedChannel/0/U | 9 + .../blockedChannel/0/tracer | 9 + .../blockedChannel/constant/fvModels | 6 - tutorials/incompressibleVoF/damBreak/0/U | 17 +- .../damBreak/0/alpha.water.orig | 17 +- .../incompressibleVoF/damBreak/0/epsilon | 19 +- tutorials/incompressibleVoF/damBreak/0/k | 19 +- .../incompressibleVoF/damBreak/0/nuTilda | 17 +- tutorials/incompressibleVoF/damBreak/0/nut | 19 +- tutorials/incompressibleVoF/damBreak/0/omega | 19 +- tutorials/incompressibleVoF/damBreak/0/p_rgh | 19 +- .../incompressibleVoF/damBreakInjection/0/U | 47 +++ .../damBreakInjection/0/epsilon | 49 +++ .../incompressibleVoF/damBreakInjection/0/k | 49 +++ .../damBreakInjection/Allclean | 10 +- .../damBreakInjection/Allrun | 5 +- .../constant/{fvModels.injection => fvModels} | 20 +- tutorials/multicomponentFluid/filter/0/H2O | 9 + tutorials/multicomponentFluid/filter/0/N2 | 9 + tutorials/multicomponentFluid/filter/0/O2 | 9 + tutorials/multicomponentFluid/filter/0/T | 9 + tutorials/multicomponentFluid/filter/0/U | 9 + .../multicomponentFluid/filter/0/epsilon | 9 + tutorials/multicomponentFluid/filter/0/k | 9 + .../filter/constant/fvModels | 10 - tutorials/multiphaseEuler/bed/0/U.air | 6 +- tutorials/multiphaseEuler/bed/0/U.water | 15 +- .../multiphaseEuler/bed/constant/fvModels | 26 +- tutorials/multiphaseEuler/bubblePipe/0/U.air1 | 9 + .../multiphaseEuler/bubblePipe/0/f0.air1 | 9 + .../multiphaseEuler/bubblePipe/0/f2.air1 | 50 +++ .../multiphaseEuler/bubblePipe/0/f5.air2 | 8 + .../bubblePipe/0/fDefault.air1 | 9 + .../bubblePipe/0/fDefault.air2 | 9 + .../bubblePipe/constant/fvModels | 15 +- tutorials/multiphaseEuler/injection/0/T.air | 9 + tutorials/multiphaseEuler/injection/0/U.air | 9 + .../injection/constant/fvModels | 12 +- .../multiphaseEuler/steamInjection/0/T.steam | 9 + .../multiphaseEuler/steamInjection/0/U.steam | 9 + .../steamInjection/constant/fvModels | 12 +- 160 files changed, 7453 insertions(+), 1612 deletions(-) create mode 100644 src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.C create mode 100644 src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.H create mode 100644 src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.C create mode 100644 src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.H create mode 100644 src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.C create mode 100644 src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.H create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvSource.C create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvSource.H create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvTotalSource.C create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvTotalSource.H create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvTotalSourceI.H create mode 100644 src/finiteVolume/cfdTools/general/fvSource/fvTotalSourceTemplates.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/internal/internalFvFieldSource.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/internal/internalFvFieldSource.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/internal/internalFvFieldSources.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/internal/internalFvFieldSources.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/internal/internalFvFieldSourcesFwd.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/turbulentIntensityKineticEnergy/turbulentIntensityKineticEnergyFvScalarFieldSource.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/turbulentIntensityKineticEnergy/turbulentIntensityKineticEnergyFvScalarFieldSource.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformFixedValue/uniformFixedValueFvFieldSource.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformFixedValue/uniformFixedValueFvFieldSource.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformFixedValue/uniformFixedValueFvFieldSources.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformFixedValue/uniformFixedValueFvFieldSources.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformFixedValue/uniformFixedValueFvFieldSourcesFwd.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformInletOutlet/uniformInletOutletFvFieldSource.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformInletOutlet/uniformInletOutletFvFieldSource.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformInletOutlet/uniformInletOutletFvFieldSources.C create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformInletOutlet/uniformInletOutletFvFieldSources.H create mode 100644 src/finiteVolume/fields/fvFieldSources/derived/uniformInletOutlet/uniformInletOutletFvFieldSourcesFwd.H create mode 100644 src/finiteVolume/fields/fvFieldSources/fvFieldSource/fvFieldSource.C create mode 100644 src/finiteVolume/fields/fvFieldSources/fvFieldSource/fvFieldSource.H create mode 100644 src/finiteVolume/fields/fvFieldSources/fvFieldSource/fvFieldSources.C create mode 100644 src/finiteVolume/fields/fvFieldSources/fvFieldSource/fvFieldSources.H create mode 100644 src/finiteVolume/fields/fvFieldSources/fvFieldSource/fvFieldSourcesFwd.H create mode 100644 src/fvModels/derived/massSource/massSourceBase.C create mode 100644 src/fvModels/derived/massSource/massSourceBase.H create mode 100644 src/fvModels/derived/zeroDimensionalMassSource/zeroDimensionalMassSourceBase.C create mode 100644 src/fvModels/derived/zeroDimensionalMassSource/zeroDimensionalMassSourceBase.H create mode 100644 src/generic/genericFvFields/genericFvFieldSource/genericFvFieldSource.C create mode 100644 src/generic/genericFvFields/genericFvFieldSource/genericFvFieldSource.H create mode 100644 src/generic/genericFvFields/genericFvFieldSource/genericFvFieldSources.C create mode 100644 src/generic/genericFvFields/genericFvFieldSource/genericFvFieldSources.H create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/energy/energyCalculatedTemperatureFvScalarFieldSource.C create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/energy/energyCalculatedTemperatureFvScalarFieldSource.H create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/energy/energyFvScalarFieldSource.C create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/energy/energyFvScalarFieldSource.H create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/uniformFixedEnergyTemperature/uniformFixedEnergyTemperatureFvScalarFieldSource.C create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/uniformFixedEnergyTemperature/uniformFixedEnergyTemperatureFvScalarFieldSource.H create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/uniformInletOutletEnergyTemperature/uniformInletOutletEnergyTemperatureFvScalarFieldSource.C create mode 100644 src/thermophysicalModels/basic/derivedFvFieldSources/uniformInletOutletEnergyTemperature/uniformInletOutletEnergyTemperatureFvScalarFieldSource.H create mode 100644 tutorials/compressibleVoF/damBreakInjection/0/T create mode 100644 tutorials/compressibleVoF/damBreakInjection/0/U create mode 100644 tutorials/compressibleVoF/damBreakInjection/0/epsilon create mode 100644 tutorials/compressibleVoF/damBreakInjection/0/k rename tutorials/compressibleVoF/damBreakInjection/constant/{fvModels.injection => fvModels} (80%) create mode 100644 tutorials/incompressibleVoF/damBreakInjection/0/U create mode 100644 tutorials/incompressibleVoF/damBreakInjection/0/epsilon create mode 100644 tutorials/incompressibleVoF/damBreakInjection/0/k rename tutorials/incompressibleVoF/damBreakInjection/constant/{fvModels.injection => fvModels} (83%) create mode 100644 tutorials/multiphaseEuler/bubblePipe/0/f2.air1 diff --git a/applications/utilities/parallelProcessing/decomposePar/fvFieldDecomposerTemplates.C b/applications/utilities/parallelProcessing/decomposePar/fvFieldDecomposerTemplates.C index bc4f0b4491..e43b26eeb4 100644 --- a/applications/utilities/parallelProcessing/decomposePar/fvFieldDecomposerTemplates.C +++ b/applications/utilities/parallelProcessing/decomposePar/fvFieldDecomposerTemplates.C @@ -197,7 +197,8 @@ Foam::fvFieldDecomposer::decomposeVolField procMeshes_[proci], field.dimensions(), Field(field.primitiveField(), cellProcAddressing_[proci]), - patchFields + patchFields, + field.sources().table() ) ); diff --git a/applications/utilities/parallelProcessing/reconstructPar/fvFieldReconstructorTemplates.C b/applications/utilities/parallelProcessing/reconstructPar/fvFieldReconstructorTemplates.C index 2412a6955b..a105666e60 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/fvFieldReconstructorTemplates.C +++ b/applications/utilities/parallelProcessing/reconstructPar/fvFieldReconstructorTemplates.C @@ -292,7 +292,8 @@ Foam::fvFieldReconstructor::reconstructVolField completeMesh_, procFields[0].dimensions(), internalField, - patchFields + patchFields, + procFields[0].sources().table() ) ); } diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index b3478ef7b2..a7b02fddeb 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -50,6 +50,7 @@ Description #include "timeSelector.H" #include "decompositionMethod.H" #include "PstreamReduceOps.H" +#include "volFields.H" #include "fvMeshDistribute.H" #include "polyDistributionMap.H" #include "IOobjectList.H" diff --git a/src/MomentumTransportModels/momentumTransportModels/Make/files b/src/MomentumTransportModels/momentumTransportModels/Make/files index ab992e7ca9..0e326c6cc2 100644 --- a/src/MomentumTransportModels/momentumTransportModels/Make/files +++ b/src/MomentumTransportModels/momentumTransportModels/Make/files @@ -56,11 +56,15 @@ fWallFunctions = $(wallFunctions)/fWallFunctions $(fWallFunctions)/fWallFunction/fWallFunctionFvPatchScalarField.C -RASBCs = RAS/derivedFvPatchFields - # Inlet turbulence BCs -$(RASBCs)/turbulentMixingLengthDissipationRateInlet/turbulentMixingLengthDissipationRateInletFvPatchScalarField.C -$(RASBCs)/turbulentMixingLengthFrequencyInlet/turbulentMixingLengthFrequencyInletFvPatchScalarField.C +RAS/derivedFvPatchFields/turbulentMixingLengthDissipationRateInlet/turbulentMixingLengthDissipationRateInletFvPatchScalarField.C +RAS/derivedFvPatchFields/turbulentMixingLengthFrequencyInlet/turbulentMixingLengthFrequencyInletFvPatchScalarField.C + + +# Turbulence model values +RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.C +RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.C + generalisedNewtonianViscosityModels = laminar/generalisedNewtonian/generalisedNewtonianViscosityModels $(generalisedNewtonianViscosityModels)/generalisedNewtonianViscosityModel/generalisedNewtonianViscosityModel.C diff --git a/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.C b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.C new file mode 100644 index 0000000000..530c710447 --- /dev/null +++ b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.C @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 "turbulentMixingLengthDissipationRateFvScalarFieldSource.H" +#include "addToRunTimeSelectionTable.H" +#include "fvCellSet.H" +#include "volFields.H" +#include "momentumTransportModel.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource:: +turbulentMixingLengthDissipationRateFvScalarFieldSource +( + const DimensionedField& iF, + const dictionary& dict +) +: + fvScalarFieldSource(iF, dict), + mixingLength_(dict.lookup("mixingLength")), + kName_(dict.lookupOrDefault("k", "k")) +{} + + +Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource:: +turbulentMixingLengthDissipationRateFvScalarFieldSource +( + const turbulentMixingLengthDissipationRateFvScalarFieldSource& field, + const DimensionedField& iF +) +: + fvScalarFieldSource(field, iF), + mixingLength_(field.mixingLength_), + kName_(field.kName_) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource:: +~turbulentMixingLengthDissipationRateFvScalarFieldSource() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::tmp +Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource::sourceValue +( + const fvSource& source +) const +{ + const scalarField ks(this->value(kName_, source)); + + const momentumTransportModel& turbModel = + db().lookupType(internalField().group()); + + const scalar Cmu = + turbModel.coeffDict().lookupOrDefault("Cmu", 0.09); + + const scalar Cmu75 = pow(Cmu, 0.75); + + return Cmu75*ks*sqrt(ks)/mixingLength_; +} + + +Foam::tmp +Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource::internalCoeff +( + const fvSource& source +) const +{ + return + neg0(source.source(internalField().name())) + *scalarField(source.nCells(), scalar(1)); +} + + +void Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource::write +( + Ostream& os +) const +{ + fvScalarFieldSource::write(os); + writeEntry(os, "mixingLength", mixingLength_); + writeEntryIfDifferent(os, "k", "k", kName_); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeTypeFieldSource + ( + fvScalarFieldSource, + turbulentMixingLengthDissipationRateFvScalarFieldSource + ); +} + +// ************************************************************************* // diff --git a/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.H b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.H new file mode 100644 index 0000000000..8556627d0a --- /dev/null +++ b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthDissipationRate/turbulentMixingLengthDissipationRateFvScalarFieldSource.H @@ -0,0 +1,161 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::turbulentMixingLengthDissipationRateFvScalarFieldSource + +Description + This source condition provides a turbulence dissipation, \f$\epsilon\f$ + (epsilon), based on a specified mixing length. The source values are + calculated using: + + \f[ + \epsilon = \frac{C_{\mu}^{0.75} k^{1.5}}{L} + \f] + + where + + \vartable + \epsilon | epsilon values + C_{\mu} | Model coefficient, set to 0.09 + k | turbulence kinetic energy + L | length scale + \endvartable + + In the case of a sink, the current cell values are used instead. + +Usage + \table + Property | Description | Required | Default value + mixingLength | Length scale [m] | yes | + k | turbulence kinetic energy field name | no | k + \endtable + + Example of the source condition specification: + \verbatim + + { + type turbulentMixingLengthDissipationRate; + mixingLength 0.005; + } + \endverbatim + +SourceFiles + turbulentMixingLengthDissipationRateFvScalarFieldSource.C + +\*---------------------------------------------------------------------------*/ + +#ifndef turbulentMixingLengthDissipationRateFvScalarFieldSource_H +#define turbulentMixingLengthDissipationRateFvScalarFieldSource_H + +#include "fvFieldSources.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class turbulentMixingLengthDissipationRateFvScalarFieldSource Declaration +\*---------------------------------------------------------------------------*/ + +class turbulentMixingLengthDissipationRateFvScalarFieldSource +: + public fvScalarFieldSource +{ +private: + + // Private Data + + //- Turbulent length scale + scalar mixingLength_; + + //- Name of the turbulent kinetic energy field + word kName_; + + +public: + + //- Runtime type information + TypeName("turbulentMixingLengthDissipationRate"); + + + // Constructors + + //- Construct from internal field and dictionary + turbulentMixingLengthDissipationRateFvScalarFieldSource + ( + const DimensionedField&, + const dictionary& dict + ); + + //- Copy constructor setting internal field reference + turbulentMixingLengthDissipationRateFvScalarFieldSource + ( + const turbulentMixingLengthDissipationRateFvScalarFieldSource&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual autoPtr clone + ( + const DimensionedField& iF + ) const + { + return autoPtr + ( + new turbulentMixingLengthDissipationRateFvScalarFieldSource + ( + *this, + iF + ) + ); + } + + + //- Destructor + virtual ~turbulentMixingLengthDissipationRateFvScalarFieldSource(); + + + // Member Functions + + //- Return the source value + virtual tmp sourceValue(const fvSource&) const; + + //- Return the internal coefficient + virtual tmp internalCoeff(const fvSource&) const; + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.C b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.C new file mode 100644 index 0000000000..c381f7ecf2 --- /dev/null +++ b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.C @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 "turbulentMixingLengthFrequencyFvScalarFieldSource.H" +#include "addToRunTimeSelectionTable.H" +#include "fvCellSet.H" +#include "volFields.H" +#include "momentumTransportModel.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::turbulentMixingLengthFrequencyFvScalarFieldSource:: +turbulentMixingLengthFrequencyFvScalarFieldSource +( + const DimensionedField& iF, + const dictionary& dict +) +: + fvScalarFieldSource(iF, dict), + mixingLength_(dict.lookup("mixingLength")), + kName_(dict.lookupOrDefault("k", "k")) +{} + + +Foam::turbulentMixingLengthFrequencyFvScalarFieldSource:: +turbulentMixingLengthFrequencyFvScalarFieldSource +( + const turbulentMixingLengthFrequencyFvScalarFieldSource& field, + const DimensionedField& iF +) +: + fvScalarFieldSource(field, iF), + mixingLength_(field.mixingLength_), + kName_(field.kName_) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::turbulentMixingLengthFrequencyFvScalarFieldSource:: +~turbulentMixingLengthFrequencyFvScalarFieldSource() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::tmp +Foam::turbulentMixingLengthFrequencyFvScalarFieldSource::sourceValue +( + const fvSource& source +) const +{ + const scalarField ks(this->value(kName_, source)); + + const momentumTransportModel& turbModel = + db().lookupType(internalField().group()); + + const scalar Cmu = + turbModel.coeffDict().lookupOrDefault("Cmu", 0.09); + + const scalar Cmu25 = pow(Cmu, 0.25); + + return ks*sqrt(ks)/(Cmu25*mixingLength_); +} + + +Foam::tmp +Foam::turbulentMixingLengthFrequencyFvScalarFieldSource::internalCoeff +( + const fvSource& source +) const +{ + return + neg0(source.source(internalField().name())) + *scalarField(source.nCells(), scalar(1)); +} + + +void Foam::turbulentMixingLengthFrequencyFvScalarFieldSource::write +( + Ostream& os +) const +{ + fvScalarFieldSource::write(os); + writeEntry(os, "mixingLength", mixingLength_); + writeEntryIfDifferent(os, "k", "k", kName_); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeTypeFieldSource + ( + fvScalarFieldSource, + turbulentMixingLengthFrequencyFvScalarFieldSource + ); +} + +// ************************************************************************* // diff --git a/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.H b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.H new file mode 100644 index 0000000000..914f9a24a3 --- /dev/null +++ b/src/MomentumTransportModels/momentumTransportModels/RAS/derivedFvFieldSources/turbulentMixingLengthFrequency/turbulentMixingLengthFrequencyFvScalarFieldSource.H @@ -0,0 +1,161 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::turbulentMixingLengthFrequencyFvScalarFieldSource + +Description + This source condition provides a turbulence specific dissipation, + \f$\omega\f$ (omega), based on a specified mixing length. The source values + are calculated using: + + \f[ + \omega = \frac{k^{0.5}}{C_{\mu}^{0.25} L} + \f] + + where + + \vartable + \omega | omega values + C_{\mu} | Model coefficient, set to 0.09 + k | turbulence kinetic energy + L | length scale + \endvartable + + In the case of a sink, the current cell values are used instead. + +Usage + \table + Property | Description | Required | Default value + mixingLength | Length scale [m] | yes | + k | turbulence kinetic energy field name | no | k + \endtable + + Example of the source condition specification: + \verbatim + + { + type turbulentMixingLengthFrequency; + mixingLength 0.005; + } + \endverbatim + +SourceFiles + turbulentMixingLengthFrequencyFvScalarFieldSource.C + +\*---------------------------------------------------------------------------*/ + +#ifndef turbulentMixingLengthFrequencyFvScalarFieldSource_H +#define turbulentMixingLengthFrequencyFvScalarFieldSource_H + +#include "fvFieldSources.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class turbulentMixingLengthFrequencyFvScalarFieldSource Declaration +\*---------------------------------------------------------------------------*/ + +class turbulentMixingLengthFrequencyFvScalarFieldSource +: + public fvScalarFieldSource +{ +private: + + // Private Data + + //- Turbulent length scale + scalar mixingLength_; + + //- Name of the turbulent kinetic energy field + word kName_; + + +public: + + //- Runtime type information + TypeName("turbulentMixingLengthFrequency"); + + + // Constructors + + //- Construct from internal field and dictionary + turbulentMixingLengthFrequencyFvScalarFieldSource + ( + const DimensionedField&, + const dictionary& dict + ); + + //- Copy constructor setting internal field reference + turbulentMixingLengthFrequencyFvScalarFieldSource + ( + const turbulentMixingLengthFrequencyFvScalarFieldSource&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual autoPtr clone + ( + const DimensionedField& iF + ) const + { + return autoPtr + ( + new turbulentMixingLengthFrequencyFvScalarFieldSource + ( + *this, + iF + ) + ); + } + + + //- Destructor + virtual ~turbulentMixingLengthFrequencyFvScalarFieldSource(); + + + // Member Functions + + //- Return the source value + virtual tmp sourceValue(const fvSource&) const; + + //- Return the internal coefficient + virtual tmp internalCoeff(const fvSource&) const; + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 00f201c873..1b59e0a796 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -55,6 +55,17 @@ void Foam::GeometricField::readFields boundaryField_.readField(*this, dict.subDict("boundaryField")); + // Don't use subOrEmptyDict here, or line numbers will be lost from any IO + // error messages. Use an actual sub-dict reference here if possible. + if (dict.found("sources")) + { + sources_.readField(*this, dict.subDict("sources")); + } + else + { + sources_.readField(*this, dictionary(dict, dictionary())); + } + if (dict.found("referenceLevel")) { Type fieldAverage(pTraits(dict.lookup("referenceLevel"))); @@ -191,7 +202,8 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary(), *this, patchFieldType) + boundaryField_(mesh.boundary(), *this, patchFieldType), + sources_() { if (debug) { @@ -209,14 +221,16 @@ Foam::GeometricField::GeometricField const Mesh& mesh, const dimensionSet& ds, const wordList& patchFieldTypes, - const wordList& actualPatchTypes + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) : Internal(io, mesh, ds, false), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes) + boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes), + sources_(*this, fieldSourceTypes) { if (debug) { @@ -240,7 +254,8 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary(), *this, patchFieldType) + boundaryField_(mesh.boundary(), *this, patchFieldType), + sources_() { if (debug) { @@ -260,14 +275,16 @@ Foam::GeometricField::GeometricField const Mesh& mesh, const dimensioned& dt, const wordList& patchFieldTypes, - const wordList& actualPatchTypes + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) : Internal(io, mesh, dt, false), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes) + boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes), + sources_(*this, fieldSourceTypes) { if (debug) { @@ -285,14 +302,16 @@ Foam::GeometricField::GeometricField ( const IOobject& io, const Internal& diField, - const PtrList>& ptfl + const PtrList>& ptfl, + const HashPtrTable& stft ) : Internal(io, diField), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(this->mesh().boundary(), *this, ptfl) + boundaryField_(this->mesh().boundary(), *this, ptfl), + sources_(*this, stft) { if (debug) { @@ -311,14 +330,16 @@ Foam::GeometricField::GeometricField const Mesh& mesh, const dimensionSet& ds, const Field& iField, - const PtrList>& ptfl + const PtrList>& ptfl, + const HashPtrTable& stft ) : Internal(io, mesh, ds, iField), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary(), *this, ptfl) + boundaryField_(mesh.boundary(), *this, ptfl), + sources_(*this, stft) { if (debug) { @@ -341,7 +362,8 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary()) + boundaryField_(mesh.boundary()), + sources_() { readFields(); @@ -377,7 +399,8 @@ Foam::GeometricField::GeometricField timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(mesh.boundary()) + boundaryField_(mesh.boundary()), + sources_() { readFields(dict); @@ -410,7 +433,8 @@ Foam::GeometricField::GeometricField timeIndex_(gf.timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, gf.boundaryField_) + boundaryField_(*this, gf.boundaryField_), + sources_(*this, gf.sources_) { if (debug) { @@ -440,7 +464,8 @@ Foam::GeometricField::GeometricField timeIndex_(gf.timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, gf.boundaryField_) + boundaryField_(*this, gf.boundaryField_), + sources_(*this, gf.sources_) { if (debug) { @@ -472,7 +497,8 @@ Foam::GeometricField::GeometricField timeIndex_(tgf().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, tgf().boundaryField_) + boundaryField_(*this, tgf().boundaryField_), + sources_(*this, tgf().sources_) { if (debug) { @@ -497,7 +523,8 @@ Foam::GeometricField::GeometricField timeIndex_(gf.timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, gf.boundaryField_) + boundaryField_(*this, gf.boundaryField_), + sources_(*this, gf.sources_) { if (debug) { @@ -533,7 +560,8 @@ Foam::GeometricField::GeometricField timeIndex_(tgf().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, tgf().boundaryField_) + boundaryField_(*this, tgf().boundaryField_), + sources_(*this, tgf().sources_) { if (debug) { @@ -559,7 +587,8 @@ Foam::GeometricField::GeometricField timeIndex_(gf.timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, gf.boundaryField_) + boundaryField_(*this, gf.boundaryField_), + sources_(*this, gf.sources_) { if (debug) { @@ -595,7 +624,8 @@ Foam::GeometricField::GeometricField timeIndex_(tgf().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(*this, tgf().boundaryField_) + boundaryField_(*this, tgf().boundaryField_), + sources_(*this, tgf().sources_) { if (debug) { @@ -620,7 +650,8 @@ Foam::GeometricField::GeometricField timeIndex_(gf.timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), - boundaryField_(this->mesh().boundary(), *this, patchFieldType) + boundaryField_(this->mesh().boundary(), *this, patchFieldType), + sources_(*this, gf.sources_) { if (debug) { @@ -648,8 +679,8 @@ Foam::GeometricField::GeometricField const IOobject& io, const GeometricField& gf, const wordList& patchFieldTypes, - const wordList& actualPatchTypes - + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) : Internal(io, gf), @@ -662,7 +693,8 @@ Foam::GeometricField::GeometricField *this, patchFieldTypes, actualPatchTypes - ) + ), + sources_(*this, fieldSourceTypes) { if (debug) { @@ -690,7 +722,8 @@ Foam::GeometricField::GeometricField const IOobject& io, const tmp>& tgf, const wordList& patchFieldTypes, - const wordList& actualPatchTypes + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) : Internal @@ -708,7 +741,8 @@ Foam::GeometricField::GeometricField *this, patchFieldTypes, actualPatchTypes - ) + ), + sources_(*this, fieldSourceTypes) { if (debug) { @@ -766,7 +800,8 @@ Foam::GeometricField::New ( const word& name, const Internal& diField, - const PtrList>& ptfl + const PtrList>& ptfl, + const HashPtrTable& stft ) { const bool cacheTmp = diField.mesh().thisDb().cacheTemporaryObject(name); @@ -785,7 +820,8 @@ Foam::GeometricField::New cacheTmp ), diField, - ptfl + ptfl, + stft ), cacheTmp ); @@ -869,7 +905,8 @@ Foam::GeometricField::New const Mesh& mesh, const dimensioned& dt, const wordList& patchFieldTypes, - const wordList& actualPatchTypes + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) { const bool cacheTmp = mesh.thisDb().cacheTemporaryObject(name); @@ -890,7 +927,8 @@ Foam::GeometricField::New mesh, dt, patchFieldTypes, - actualPatchTypes + actualPatchTypes, + fieldSourceTypes ), cacheTmp ); @@ -968,7 +1006,8 @@ Foam::GeometricField::New const word& newName, const tmp>& tgf, const wordList& patchFieldTypes, - const wordList& actualPatchTypes + const wordList& actualPatchTypes, + const HashTable& fieldSourceTypes ) { const bool cacheTmp = tgf().db().cacheTemporaryObject(newName); @@ -989,7 +1028,8 @@ Foam::GeometricField::New ), tgf, patchFieldTypes, - actualPatchTypes + actualPatchTypes, + fieldSourceTypes ), cacheTmp ); @@ -1297,6 +1337,7 @@ void Foam::GeometricField::reset Internal::reset(gf); boundaryField_.reset(gf.boundaryField()); + sources_.reset(gf.sources()); tgf.clear(); } @@ -1785,6 +1826,12 @@ Foam::Ostream& Foam::operator<< os << nl; gf.boundaryField().writeEntry("boundaryField", os); + if (!gf.sources_.empty()) + { + os << nl; + gf.sources().writeEntry("sources", os); + } + // Check state of IOstream os.check ( diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index fe9a73c322..cb7a6eaf02 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -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 @@ -41,6 +41,7 @@ SourceFiles #include "lduInterfaceFieldPtrsList.H" #include "LduInterfaceFieldPtrsList.H" #include "GeometricBoundaryField.H" +#include "GeometricFieldSources.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -103,6 +104,12 @@ public: //- Type of the boundary field typedef GeometricBoundaryField Boundary; + //- Type of the field source of which the Sources is composed + typedef typename GeoMesh::template FieldSource Source; + + //- Type of the field sources + typedef GeometricFieldSources Sources; + private: @@ -121,6 +128,9 @@ private: //- Boundary Type field containing boundary field values Boundary boundaryField_; + //- Type field sources containing field source values + Sources sources_; + // Private Member Functions @@ -163,7 +173,7 @@ public: const IOobject&, const Mesh&, const dimensionSet&, - const word& patchFieldType=PatchField::calculatedType() + const word& patchFieldType = PatchField::calculatedType() ); //- Constructor given IOobject, mesh, dimensions and patch field types. @@ -175,7 +185,8 @@ public: const Mesh&, const dimensionSet&, const wordList& wantedPatchTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); //- Constructor given IOobject, mesh, dimensioned @@ -185,7 +196,7 @@ public: const IOobject&, const Mesh&, const dimensioned&, - const word& patchFieldType=PatchField::calculatedType() + const word& patchFieldType = PatchField::calculatedType() ); //- Constructor given IOobject, mesh, dimensioned @@ -196,7 +207,8 @@ public: const Mesh&, const dimensioned&, const wordList& wantedPatchTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); //- Constructor from components @@ -204,7 +216,8 @@ public: ( const IOobject&, const Internal&, - const PtrList>& + const PtrList>&, + const HashPtrTable& = HashPtrTable() ); //- Constructor from components @@ -214,7 +227,8 @@ public: const Mesh&, const dimensionSet&, const Field&, - const PtrList>& + const PtrList>&, + const HashPtrTable& = HashPtrTable() ); //- Construct and read given IOobject @@ -283,7 +297,8 @@ public: const IOobject&, const GeometricField&, const wordList& patchFieldTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); //- Construct as copy resetting IO parameters and boundary types @@ -292,7 +307,8 @@ public: const IOobject&, const tmp>&, const wordList& patchFieldTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); //- Clone @@ -307,7 +323,8 @@ public: ( const word& name, const Internal&, - const PtrList>& + const PtrList>&, + const HashPtrTable& = HashPtrTable() ); //- Return a temporary field constructed from name, mesh, dimensionSet @@ -317,7 +334,7 @@ public: const word& name, const Mesh&, const dimensionSet&, - const word& patchFieldType=PatchField::calculatedType() + const word& patchFieldType = PatchField::calculatedType() ); //- Return a temporary field constructed from mesh, dimensioned @@ -327,7 +344,7 @@ public: const word& name, const Mesh&, const dimensioned&, - const word& patchFieldType=PatchField::calculatedType() + const word& patchFieldType = PatchField::calculatedType() ); //- Return a temporary field constructed from mesh, dimensioned @@ -338,7 +355,8 @@ public: const Mesh&, const dimensioned&, const wordList& patchFieldTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); //- Rename temporary field and return @@ -353,7 +371,7 @@ public: ( const word& newName, const tmp>&, - const word& + const word& patchFieldType ); //- Rename and reset patch fields types of temporary field and return @@ -362,7 +380,8 @@ public: const word& newName, const tmp>&, const wordList& patchFieldTypes, - const wordList& actualPatchTypes = wordList() + const wordList& actualPatchTypes = wordList(), + const HashTable& fieldSourceTypes = HashTable() ); @@ -401,6 +420,9 @@ public: //- Return const-reference to the boundary field inline const Boundary& boundaryField() const; + //- Return const-reference to the sources + inline const Sources& sources() const; + //- Return the time index of the field inline label timeIndex() const; diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H index 67143f3d18..1b88057180 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -63,6 +63,15 @@ Foam::GeometricField::boundaryField() const } +template class PatchField, class GeoMesh> +inline const typename +Foam::GeometricField::Sources& +Foam::GeometricField::sources() const +{ + return sources_; +} + + template class PatchField, class GeoMesh> inline Foam::label Foam::GeometricField::timeIndex() const diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.C new file mode 100644 index 0000000000..b2678e2bd9 --- /dev/null +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.C @@ -0,0 +1,260 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 "GeometricFieldSources.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::GeometricFieldSources::GeometricFieldSources() +: + HashPtrTable(), + errorLocation_() +{} + + +template +Foam::GeometricFieldSources::GeometricFieldSources +( + const DimensionedField& iF, + const HashPtrTable& mtf +) +: + HashPtrTable(mtf.capacity()), + errorLocation_() +{ + forAllConstIter(typename HashPtrTable, mtf, iter) + { + this->set(iter.key(), iter()->clone(iF).ptr()); + } +} + + +template +Foam::GeometricFieldSources::GeometricFieldSources +( + const DimensionedField& iF, + const GeometricFieldSources& mtf +) +: + GeometricFieldSources(iF, static_cast&>(mtf)) +{} + + +template +Foam::GeometricFieldSources::GeometricFieldSources +( + const DimensionedField& iF, + const dictionary& dict +) +: + HashPtrTable(), + errorLocation_() +{ + readField(iF, dict); +} + + +template +Foam::GeometricFieldSources::GeometricFieldSources +( + const DimensionedField& iF, + const HashTable& types +) +: + HashPtrTable(), + errorLocation_() +{ + forAllConstIter(typename HashTable, types, iter) + { + this->set + ( + iter.key(), + Source::New(iter(), iF).ptr() + ); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::GeometricFieldSources:: +~GeometricFieldSources() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template +const Foam::HashPtrTable +< + typename Foam::GeometricFieldSources::Source +>& +Foam::GeometricFieldSources::table() const +{ + return *this; +} + + +template +Foam::HashPtrTable +< + typename Foam::GeometricFieldSources::Source +>& +Foam::GeometricFieldSources::table() +{ + return *this; +} + + +template +Foam::HashTable +Foam::GeometricFieldSources::types() const +{ + HashTable result; + + forAllConstIter(typename HashPtrTable, *this, iter) + { + result.insert(iter.key(), iter()->type()); + } + + return result; +} + + +template +void Foam::GeometricFieldSources::readField +( + const DimensionedField& field, + const dictionary& dict +) +{ + this->clear(); + + errorLocation_ = IOerrorLocation(dict); + + forAllConstIter(dictionary, dict, iter) + { + if (iter().isDict()) + { + this->set + ( + iter().keyword(), + Source::New(field, iter().dict()).ptr() + ); + } + } +} + + +template +void Foam::GeometricFieldSources::reset +( + const GeometricFieldSources& mtf +) +{ + this->clear(); + + if (mtf.empty()) return; + + const DimensionedField& iF = + (**mtf.HashPtrTable::begin()).internalField(); + + errorLocation_ = mtf.errorLocation_; + + forAllConstIter(typename HashPtrTable, mtf, iter) + { + this->set(iter.key(), iter()->clone(iF).ptr()); + } +} + + +template +void Foam::GeometricFieldSources::writeEntry +( + const word& keyword, + Ostream& os +) const +{ + os << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl; + + forAllConstIter(typename HashPtrTable, *this, iter) + { + os << indent << iter.key() << nl + << indent << token::BEGIN_BLOCK << nl + << incrIndent << *iter() << decrIndent + << indent << token::END_BLOCK << endl; + } + + os << decrIndent << token::END_BLOCK << endl; + + // Check state of IOstream + os.check + ( + "GeometricFieldSources::" + "writeEntry(const word& keyword, Ostream& os) const" + ); +} + + +// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // + +template +const typename Foam::GeometricFieldSources::Source& +Foam::GeometricFieldSources::operator[] +( + const word& sourceName +) const +{ + typename HashPtrTable::const_iterator iter = this->find(sourceName); + + if (iter == this->end()) + { + FatalIOErrorInFunction(errorLocation_) + << "Cannot find fieldSource entry for " << sourceName + << exit(FatalIOError); + } + + return **iter; +} + + +// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // + +template +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const GeometricFieldSources& bf +) +{ + typedef typename GeoMesh::template FieldSource Source; + os << static_cast&>(bf); + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.H new file mode 100644 index 0000000000..ca649931b0 --- /dev/null +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldSources.H @@ -0,0 +1,252 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::GeometricFieldSources + +Description + Part of a geometric field used for setting the values associated with + optional sources + +SourceFiles + GeometricFieldSources.C + +\*---------------------------------------------------------------------------*/ + +#ifndef GeometricFieldSources_H +#define GeometricFieldSources_H + +#include "dimensionedTypes.H" +#include "DimensionedField.H" +#include "HashPtrTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class dictionary; + +/*---------------------------------------------------------------------------*\ + Class GeometricFieldSources Declaration +\*---------------------------------------------------------------------------*/ + +template +class GeometricFieldSources +: + private HashPtrTable> +{ +public: + + // Public Typedefs + + //- Type of the internal field from which this GeometricField is derived + typedef DimensionedField Internal; + + //- Type of the field source of which this field sources is composed + typedef typename GeoMesh::template FieldSource Source; + + +private: + + // Private Data + + //- Cached IO error location for delayed error messages + IOerrorLocation errorLocation_; + + +public: + + // Constructors + + //- Construct null + GeometricFieldSources(); + + //- Construct from a table of field sources + GeometricFieldSources(const Internal&, const HashPtrTable&); + + //- Construct as copy setting the reference to the internal field + GeometricFieldSources(const Internal&, const GeometricFieldSources&); + + //- Construct from dictionary + GeometricFieldSources(const Internal&, const dictionary&); + + //- Construct from types + GeometricFieldSources(const Internal&, const HashTable&); + + //- Copy constructor deleted + // as it would not set the internalField reference correctly + GeometricFieldSources(const GeometricFieldSources&) = delete; + + //- Move constructor deleted + // as it would not set the internalField reference correctly + GeometricFieldSources(GeometricFieldSources&&) = delete; + + + //- Destructor + ~GeometricFieldSources(); + + + // Member Functions + + //- Access the underlying field table + const HashPtrTable& table() const; + + //- Access the underlying field table + HashPtrTable& table(); + + //- Inherit empty test + using HashPtrTable::empty; + + //- Return a map from the source name to the field source type + HashTable types() const; + + //- Read the sources + void readField(const Internal& field, const dictionary& dict); + + //- Reset the boundary field contents to the given field + // Used for mesh to mesh mapping + void reset(const GeometricFieldSources&); + + //- Write sources as dictionary entry + void writeEntry(const word& keyword, Ostream& os) const; + + + // Member operators + + //- Find and return a field source + const Source& operator[](const word& sourceName) const; +}; + + +template +Ostream& operator<< +( + Ostream&, + const GeometricFieldSources& +); + + +/*---------------------------------------------------------------------------*\ + Class NoFieldSource Declaration +\*---------------------------------------------------------------------------*/ + +template +class NoFieldSource +{ + // Private Data + + //- Reference to internal field + const DimensionedField& internalField_; + + +public: + + // Constructors + + //- Construct from internal field + NoFieldSource + ( + const DimensionedField& iF + ) + : + internalField_(iF) + {} + + //- Dummy clone + autoPtr> clone + ( + const DimensionedField& iF + ) const + { + return + autoPtr> + ( + new NoFieldSource(iF) + ); + } + + + // Selectors + + //- Dummy selector + static autoPtr> New + ( + const word& fieldSourceType, + const DimensionedField& iF + ) + { + return + autoPtr> + ( + new NoFieldSource(iF) + ); + } + + //- Dummy selector + static autoPtr> New + ( + const DimensionedField& iF, + const dictionary& dict + ) + { + return + autoPtr> + ( + new NoFieldSource(iF) + ); + } + + + // Member Functions + + //- Return the internal field reference + const DimensionedField& internalField() const + { + return internalField_; + } +}; + + +template +Ostream& operator<<(Ostream& os, const NoFieldSource&) +{ + return os; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "GeometricFieldSources.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/GeometricFields/pointFields/pointFieldsFwd.H b/src/OpenFOAM/fields/GeometricFields/pointFields/pointFieldsFwd.H index 24130d0d72..31ba8dfe45 100644 --- a/src/OpenFOAM/fields/GeometricFields/pointFields/pointFieldsFwd.H +++ b/src/OpenFOAM/fields/GeometricFields/pointFields/pointFieldsFwd.H @@ -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 @@ -48,12 +48,18 @@ class pointMesh; template class pointPatchField; +template +class NoFieldSource; + template class PatchField, class GeoMesh> class GeometricField; template using PointField = GeometricField; +template +using pointFieldSource = NoFieldSource; + typedef PointField