ENH: use cmptMag, cmptMultiply instead of replacing field components
This commit is contained in:
parent
ea2bedf073
commit
5672bb296f
@ -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<vector> 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
|
||||
|
@ -227,14 +227,9 @@ void applyScaling(pointField& points, const List<scalar>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,14 +149,9 @@ void applyScaling(pointField& points, const List<scalar>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,12 +130,7 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::basicSymmetryFaPatchField<Type>::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<vectorField> diag(cmptMag(this->patch().edgeNormals()));
|
||||
|
||||
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
|
||||
}
|
||||
|
@ -131,13 +131,7 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::basicSymmetryFvPatchField<Type>::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<vectorField> diag(cmptMag(this->patch().nf()));
|
||||
|
||||
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
|
||||
}
|
||||
|
@ -171,12 +171,7 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::fixedNormalSlipFvPatchField<Type>::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<vectorField> diag(cmptMag(this->patch().nf()));
|
||||
|
||||
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
|
||||
}
|
||||
|
@ -188,12 +188,7 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::partialSlipFvPatchField<Type>::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<vectorField> diag(cmptMag(this->patch().nf()));
|
||||
|
||||
return
|
||||
valueFraction_*pTraits<Type>::one
|
||||
|
@ -67,8 +67,12 @@ void Foam::waveModels::shallowWaterAbsorption::setVelocity
|
||||
// Apply zero-gradient condition to z-component of velocity only
|
||||
const volVectorField& U = mesh_.lookupObject<volVectorField>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user