mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use cmptMag, cmptMultiply instead of replacing field components
This commit is contained in:
@ -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
|
||||||
|
|||||||
@ -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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user