From 7b6b758dd86d8068c67d4f09c033d1ca8160c7b9 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 8 Sep 2023 15:09:56 +0100 Subject: [PATCH] waves::fvModels::forcing: Added option to write the forcing fields e.g. waveForcing1 { type waveForcing; libs ("libwaves.so"); liquidPhase water; // Define the line along which to apply the graduation origin (600 0 0); direction (-1 0 0); // // Or, define multiple lines // origins ((600 0 0) (600 -300 0) (600 300 0)); // directions ((-1 0 0) (0 1 0) (0 -1 0)); scale { type halfCosineRamp; start 0; duration 300; } lambda 0.5; // Forcing coefficient // lambdaBoundary 2; // Optional boundary forcing coefficient // Useful when wave BCs are specified // without mean flow // Write the forcing fields: forcing:scale, forcing:forceCoeff writeForceFields true; } will write the fields forcing:scale and forcing:forceCoeff at the start of the run to visualise and check correctness. --- src/waves/fvModels/forcing/forcing.C | 25 ++++++++++--------- src/waves/fvModels/forcing/forcing.H | 7 ++++-- .../isotropicDamping/isotropicDamping.H | 3 +++ .../verticalDamping/verticalDamping.H | 3 +++ src/waves/fvModels/waveForcing/waveForcing.H | 5 +++- .../floatingObjectWaves/constant/fvModels | 3 +++ .../floatingObjectWaves/system/controlDict | 6 ----- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/waves/fvModels/forcing/forcing.C b/src/waves/fvModels/forcing/forcing.C index c85f326192..6f36f0cd94 100644 --- a/src/waves/fvModels/forcing/forcing.C +++ b/src/waves/fvModels/forcing/forcing.C @@ -42,6 +42,8 @@ namespace fv void Foam::fv::forcing::readCoeffs() { + writeForceFields_ = coeffs().lookupOrDefault("writeForceFields", false); + lambda_ = dimensionedScalar ( @@ -145,12 +147,6 @@ Foam::tmp Foam::fv::forcing::scale() const scale = max(scale, scale_->value(x)); } - // Write out the force coefficient for debugging - if (debug && mesh().time().writeTime()) - { - tscale->write(); - } - return tscale; } @@ -181,12 +177,6 @@ Foam::tmp Foam::fv::forcing::forceCoeff } } - // Write out the force coefficient for debugging - if (debug && mesh().time().writeTime()) - { - tforceCoeff->write(); - } - return tforceCoeff; } @@ -208,6 +198,7 @@ Foam::fv::forcing::forcing ) : fvModel(name, modelType, mesh, dict), + writeForceFields_(false), lambda_("lambda", dimless/dimTime, NaN), lambdaBoundary_("lambdaBoundary", dimless/dimTime, 0.0), scale_(nullptr), @@ -215,6 +206,16 @@ Foam::fv::forcing::forcing directions_() { readCoeffs(); + + if (writeForceFields_) + { + Info<< " Writing forcing fields: forcing:scale, forcing:forceCoeff" + << endl; + + const volScalarField::Internal scale(this->scale()); + scale.write(); + forceCoeff(scale)->write(); + } } diff --git a/src/waves/fvModels/forcing/forcing.H b/src/waves/fvModels/forcing/forcing.H index 989d18de82..74c0aac7f9 100644 --- a/src/waves/fvModels/forcing/forcing.H +++ b/src/waves/fvModels/forcing/forcing.H @@ -62,10 +62,13 @@ protected: // Protected Data - //- Damping coefficient [1/s] + //- Optionally write the forcing fields + bool writeForceFields_; + + //- Forcing coefficient [1/s] dimensionedScalar lambda_; - //- Optional boundary damping coefficient [1/s] + //- Optional boundary forcing coefficient [1/s] dimensionedScalar lambdaBoundary_; //- The scaling function diff --git a/src/waves/fvModels/isotropicDamping/isotropicDamping.H b/src/waves/fvModels/isotropicDamping/isotropicDamping.H index e9c9938da0..43f870fc41 100644 --- a/src/waves/fvModels/isotropicDamping/isotropicDamping.H +++ b/src/waves/fvModels/isotropicDamping/isotropicDamping.H @@ -64,6 +64,9 @@ Usage value (2 0 0); // Value towards which the field is // relaxed lambda [0 0 -1 0 0 0 0] 1; // Damping coefficient + + // Write the forcing fields: forcing:scale, forcing:forceCoeff + writeForceFields true; } \endverbatim diff --git a/src/waves/fvModels/verticalDamping/verticalDamping.H b/src/waves/fvModels/verticalDamping/verticalDamping.H index 0c77667ecc..a7007bbe3b 100644 --- a/src/waves/fvModels/verticalDamping/verticalDamping.H +++ b/src/waves/fvModels/verticalDamping/verticalDamping.H @@ -78,6 +78,9 @@ Usage timeStart 0; duration 1e6; + + // Write the forcing fields: forcing:scale, forcing:forceCoeff + writeForceFields true; } \endverbatim diff --git a/src/waves/fvModels/waveForcing/waveForcing.H b/src/waves/fvModels/waveForcing/waveForcing.H index 304dcce003..695204580b 100644 --- a/src/waves/fvModels/waveForcing/waveForcing.H +++ b/src/waves/fvModels/waveForcing/waveForcing.H @@ -64,9 +64,12 @@ Usage lambda 0.5; // Forcing coefficient - // lambda 2; // Optional boundary forcing coefficient + // lambdaBoundary 2; // Optional boundary forcing coefficient // Useful when wave BCs are specified // without mean flow + + // Write the forcing fields: forcing:scale, forcing:forceCoeff + writeForceFields true; } \endverbatim diff --git a/tutorials/incompressibleVoF/floatingObjectWaves/constant/fvModels b/tutorials/incompressibleVoF/floatingObjectWaves/constant/fvModels index 870980f48d..e278f77855 100644 --- a/tutorials/incompressibleVoF/floatingObjectWaves/constant/fvModels +++ b/tutorials/incompressibleVoF/floatingObjectWaves/constant/fvModels @@ -47,6 +47,9 @@ forcing lambda 5; lambdaBoundary 25; + + // Write the forcing fields: forcing:scale, forcing:forceCoeff + writeForceFields true; } diff --git a/tutorials/incompressibleVoF/floatingObjectWaves/system/controlDict b/tutorials/incompressibleVoF/floatingObjectWaves/system/controlDict index c3dac56239..f9794a79d8 100644 --- a/tutorials/incompressibleVoF/floatingObjectWaves/system/controlDict +++ b/tutorials/incompressibleVoF/floatingObjectWaves/system/controlDict @@ -62,10 +62,4 @@ functions0 } } -DebugSwitches -{ - // Write the forcing and damping scale and force fields - forcing 1; -} - // ************************************************************************* //