STYLE: code cleanup for surfaceCourantNumber (#3422)

- simplify some handling. Use reference (not copy) for internalField
This commit is contained in:
Mark Olesen
2025-08-18 09:17:46 +02:00
parent ac1c41a51b
commit 1fa20428a8
4 changed files with 64 additions and 73 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2020-2024 OpenCFD Ltd.
Copyright (C) 2020-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,7 +29,6 @@ License
#include "CourantNo.H"
#include "surfaceFields.H"
#include "fvcSurfaceIntegrate.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -46,38 +45,25 @@ namespace functionObjects
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField::Internal>
Foam::functionObjects::CourantNo::byRho
(
const tmp<volScalarField::Internal>& Co
) const
{
if (Co().dimensions() == dimDensity)
{
return Co/obr_.lookupObject<volScalarField>(rhoName_);
}
return Co;
}
bool Foam::functionObjects::CourantNo::calc()
{
if (foundObject<surfaceScalarField>(fieldName_))
{
const surfaceScalarField& phi =
lookupObject<surfaceScalarField>(fieldName_);
const auto& phi = lookupObject<surfaceScalarField>(fieldName_);
tmp<volScalarField::Internal> Coi
tmp<volScalarField::Internal> tCo
(
byRho
(
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
)
(0.5*mesh_.time().deltaT())
* fvc::surfaceSum(Foam::mag(phi))().internalField()
/ mesh_.V()
);
if (tCo().dimensions() == dimDensity)
{
tCo.ref() /= obr_.lookupObject<volScalarField>(rhoName_);
}
auto* resultPtr = getObjectPtr<volScalarField>(resultName_);
if (!resultPtr)
@ -99,10 +85,10 @@ bool Foam::functionObjects::CourantNo::calc()
);
regIOobject::store(resultPtr);
}
auto& Co = *resultPtr;
auto& result = *resultPtr;
Co.internalFieldRef() = Coi;
Co.correctBoundaryConditions();
result.internalFieldRef() = tCo;
result.correctBoundaryConditions();
return true;
}

View File

@ -86,8 +86,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_CourantNo_H
#define functionObjects_CourantNo_H
#ifndef Foam_functionObjects_CourantNo_H
#define Foam_functionObjects_CourantNo_H
#include "fieldExpression.H"
#include "volFields.H"
@ -115,12 +115,6 @@ class CourantNo
// Private Member Functions
//- Divide the Courant number by rho if required
tmp<volScalarField::Internal> byRho
(
const tmp<volScalarField::Internal>& Co
) const;
//- Calculate the Courant number field and return true if successful
virtual bool calc();