ENH: use cmptMag, cmptMultiply instead of replacing field components

This commit is contained in:
Mark Olesen
2023-01-27 15:21:19 +01:00
parent ea2bedf073
commit 5672bb296f
8 changed files with 34 additions and 46 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -153,7 +153,7 @@ int main(int argc, char *argv[])
Info<< "shuffled: " << vec2 << nl; Info<< "shuffled: " << vec2 << nl;
// Vectors with some identical components // Vectors with some identical components
List<vector> vectors vectorField vectors
({ ({
{1.1, 2.2, 3.3 }, {1.1, 2.2, 3.3 },
{2.2, 3.3, 4.4 }, {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); std::sort(vectors.begin(), vectors.end(), vector::less_zxy);
Info<< "sorted zxy:"; Info<< "sorted zxy:";
vectors.writeList(Info, 1) << nl; 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 // Basic tests for fields
{ {
scalarField sfld1 scalarField sfld1

View File

@ -227,14 +227,9 @@ void applyScaling(pointField& points, const List<scalar>& scaling)
} }
else if (scaling.size() == 3) else if (scaling.size() == 3)
{ {
Info<< "Scaling points by (" const vector factor(scaling[0], scaling[1], scaling[2]);
<< scaling[0] << ' ' Info<< "Scaling points by " << factor << nl;
<< scaling[1] << ' ' cmptMultiply(points, points, factor);
<< 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));
} }
} }

View File

@ -149,14 +149,9 @@ void applyScaling(pointField& points, const List<scalar>& scaling)
} }
else if (scaling.size() == 3) else if (scaling.size() == 3)
{ {
Info<< "Scaling points by (" const vector factor(scaling[0], scaling[1], scaling[2]);
<< scaling[0] << ' ' Info<< "Scaling points by " << factor << nl;
<< scaling[1] << ' ' cmptMultiply(points, points, factor);
<< 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));
} }
} }

View File

@ -130,12 +130,7 @@ template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::basicSymmetryFaPatchField<Type>::snGradTransformDiag() const Foam::basicSymmetryFaPatchField<Type>::snGradTransformDiag() const
{ {
const vectorField nHat(this->patch().edgeNormals()); tmp<vectorField> diag(cmptMag(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)));
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag)); return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
} }

View File

@ -131,13 +131,7 @@ template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::basicSymmetryFvPatchField<Type>::snGradTransformDiag() const Foam::basicSymmetryFvPatchField<Type>::snGradTransformDiag() const
{ {
const vectorField nHat(this->patch().nf()); tmp<vectorField> diag(cmptMag(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)));
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag)); return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
} }

View File

@ -171,12 +171,7 @@ template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::fixedNormalSlipFvPatchField<Type>::snGradTransformDiag() const Foam::fixedNormalSlipFvPatchField<Type>::snGradTransformDiag() const
{ {
const vectorField nHat(this->patch().nf()); tmp<vectorField> diag(cmptMag(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)));
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag)); return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
} }

View File

@ -188,12 +188,7 @@ template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::partialSlipFvPatchField<Type>::snGradTransformDiag() const Foam::partialSlipFvPatchField<Type>::snGradTransformDiag() const
{ {
const vectorField nHat(this->patch().nf()); tmp<vectorField> diag(cmptMag(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)));
return return
valueFraction_*pTraits<Type>::one valueFraction_*pTraits<Type>::one

View File

@ -67,8 +67,12 @@ void Foam::waveModels::shallowWaterAbsorption::setVelocity
// Apply zero-gradient condition to z-component of velocity only // Apply zero-gradient condition to z-component of velocity only
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_); const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
U_ = U.boundaryField()[patch_.index()].patchInternalField(); U_ = U.boundaryField()[patch_.index()].patchInternalField();
U_.replace(0, 0);
U_.replace(1, 0); for (vector& vel : U_)
{
vel.x() = 0;
vel.y() = 0;
}
} }