From 5672bb296fd23ee17d3a65cc7b92919c02a0015f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 27 Jan 2023 15:21:19 +0100 Subject: [PATCH] ENH: use cmptMag, cmptMultiply instead of replacing field components --- applications/test/vector/Test-vector.C | 21 ++++++++++++++++--- .../transformPoints/transformPoints.C | 11 +++------- .../surfaceTransformPoints.C | 11 +++------- .../basicSymmetry/basicSymmetryFaPatchField.C | 7 +------ .../basicSymmetry/basicSymmetryFvPatchField.C | 8 +------ .../fixedNormalSlipFvPatchField.C | 7 +------ .../partialSlip/partialSlipFvPatchField.C | 7 +------ .../shallowWaterAbsorption.C | 8 +++++-- 8 files changed, 34 insertions(+), 46 deletions(-) diff --git a/applications/test/vector/Test-vector.C b/applications/test/vector/Test-vector.C index 020944dddd..582f8bf504 100644 --- a/applications/test/vector/Test-vector.C +++ b/applications/test/vector/Test-vector.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -153,7 +153,7 @@ int main(int argc, char *argv[]) Info<< "shuffled: " << vec2 << nl; // Vectors with some identical components - List vectors + vectorField vectors ({ {1.1, 2.2, 3.3 }, {2.2, 3.3, 4.4 }, @@ -191,8 +191,23 @@ int main(int argc, char *argv[]) std::sort(vectors.begin(), vectors.end(), vector::less_zxy); Info<< "sorted zxy:"; vectors.writeList(Info, 1) << nl; - } + vectorField vecCmptMag1(cmptMag(vectors)); + Info<< "cmptMag:"; + vecCmptMag1.writeList(Info, 1) << nl; + + vectorField vecCmptMag2(vectors.size()); + vecCmptMag2.replace(vector::X, mag(vectors.component(vector::X))); + vecCmptMag2.replace(vector::Y, mag(vectors.component(vector::Y))); + vecCmptMag2.replace(vector::Z, mag(vectors.component(vector::Z))); + + Info<< "cmptMag:"; + vecCmptMag2.writeList(Info, 1) << nl; + + Info<< "mult:"; + cmptMultiply(vecCmptMag2, vecCmptMag2, vector(2,3,4)); + vecCmptMag2.writeList(Info, 1) << nl; + } // Basic tests for fields { scalarField sfld1 diff --git a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C index e27e9b0015..0e96f21c30 100644 --- a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C +++ b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C @@ -227,14 +227,9 @@ void applyScaling(pointField& points, const List& scaling) } else if (scaling.size() == 3) { - Info<< "Scaling points by (" - << scaling[0] << ' ' - << scaling[1] << ' ' - << scaling[2] << ')' << nl; - - points.replace(vector::X, scaling[0]*points.component(vector::X)); - points.replace(vector::Y, scaling[1]*points.component(vector::Y)); - points.replace(vector::Z, scaling[2]*points.component(vector::Z)); + const vector factor(scaling[0], scaling[1], scaling[2]); + Info<< "Scaling points by " << factor << nl; + cmptMultiply(points, points, factor); } } diff --git a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C index fa0412d62f..c8b1fa0ec2 100644 --- a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C +++ b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C @@ -149,14 +149,9 @@ void applyScaling(pointField& points, const List& scaling) } else if (scaling.size() == 3) { - Info<< "Scaling points by (" - << scaling[0] << ' ' - << scaling[1] << ' ' - << scaling[2] << ')' << nl; - - points.replace(vector::X, scaling[0]*points.component(vector::X)); - points.replace(vector::Y, scaling[1]*points.component(vector::Y)); - points.replace(vector::Z, scaling[2]*points.component(vector::Z)); + const vector factor(scaling[0], scaling[1], scaling[2]); + Info<< "Scaling points by " << factor << nl; + cmptMultiply(points, points, factor); } } diff --git a/src/finiteArea/fields/faPatchFields/basic/basicSymmetry/basicSymmetryFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/basicSymmetry/basicSymmetryFaPatchField.C index 02dffa26c5..d828c81eb8 100644 --- a/src/finiteArea/fields/faPatchFields/basic/basicSymmetry/basicSymmetryFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/basic/basicSymmetry/basicSymmetryFaPatchField.C @@ -130,12 +130,7 @@ template Foam::tmp> Foam::basicSymmetryFaPatchField::snGradTransformDiag() const { - const vectorField nHat(this->patch().edgeNormals()); - vectorField diag(nHat.size()); - - diag.replace(vector::X, mag(nHat.component(vector::X))); - diag.replace(vector::Y, mag(nHat.component(vector::Y))); - diag.replace(vector::Z, mag(nHat.component(vector::Z))); + tmp diag(cmptMag(this->patch().edgeNormals())); return transformFieldMask(pow::rank>(diag)); } diff --git a/src/finiteVolume/fields/fvPatchFields/basic/basicSymmetry/basicSymmetryFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/basicSymmetry/basicSymmetryFvPatchField.C index d570de2a57..34b93a99f4 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/basicSymmetry/basicSymmetryFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/basicSymmetry/basicSymmetryFvPatchField.C @@ -131,13 +131,7 @@ template Foam::tmp> Foam::basicSymmetryFvPatchField::snGradTransformDiag() const { - const vectorField nHat(this->patch().nf()); - - vectorField diag(nHat.size()); - - diag.replace(vector::X, mag(nHat.component(vector::X))); - diag.replace(vector::Y, mag(nHat.component(vector::Y))); - diag.replace(vector::Z, mag(nHat.component(vector::Z))); + tmp diag(cmptMag(this->patch().nf())); return transformFieldMask(pow::rank>(diag)); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalSlip/fixedNormalSlipFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalSlip/fixedNormalSlipFvPatchField.C index 97863afc1b..06a994141f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalSlip/fixedNormalSlipFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedNormalSlip/fixedNormalSlipFvPatchField.C @@ -171,12 +171,7 @@ template Foam::tmp> Foam::fixedNormalSlipFvPatchField::snGradTransformDiag() const { - const vectorField nHat(this->patch().nf()); - vectorField diag(nHat.size()); - - diag.replace(vector::X, mag(nHat.component(vector::X))); - diag.replace(vector::Y, mag(nHat.component(vector::Y))); - diag.replace(vector::Z, mag(nHat.component(vector::Z))); + tmp diag(cmptMag(this->patch().nf())); return transformFieldMask(pow::rank>(diag)); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.C index f8d43846f5..d938724860 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/partialSlip/partialSlipFvPatchField.C @@ -188,12 +188,7 @@ template Foam::tmp> Foam::partialSlipFvPatchField::snGradTransformDiag() const { - const vectorField nHat(this->patch().nf()); - vectorField diag(nHat.size()); - - diag.replace(vector::X, mag(nHat.component(vector::X))); - diag.replace(vector::Y, mag(nHat.component(vector::Y))); - diag.replace(vector::Z, mag(nHat.component(vector::Z))); + tmp diag(cmptMag(this->patch().nf())); return valueFraction_*pTraits::one diff --git a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C index 22652a7caa..2f33172fb6 100644 --- a/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C +++ b/src/waveModels/waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C @@ -67,8 +67,12 @@ void Foam::waveModels::shallowWaterAbsorption::setVelocity // Apply zero-gradient condition to z-component of velocity only const volVectorField& U = mesh_.lookupObject(UName_); U_ = U.boundaryField()[patch_.index()].patchInternalField(); - U_.replace(0, 0); - U_.replace(1, 0); + + for (vector& vel : U_) + { + vel.x() = 0; + vel.y() = 0; + } }