BUG: various reinterpret_cast to enable strict-aliasing

This commit is contained in:
mattijs
2010-08-19 15:44:17 +01:00
parent c34ed7bfcc
commit 69526c6c1c
31 changed files with 159 additions and 141 deletions

View File

@ -398,7 +398,12 @@ int main(int argc, char *argv[])
)
{
// Make the eigenvectors a right handed orthogonal triplet
eVec.z() *= sign((eVec.x() ^ eVec.y()) & eVec.z());
eVec = tensor
(
eVec.x(),
eVec.y(),
eVec.z() * sign((eVec.x() ^ eVec.y()) & eVec.z())
);
// Finding the most natural transformation. Using Lists
// rather than tensors to allow indexed permutation.
@ -557,9 +562,7 @@ int main(int argc, char *argv[])
eVal = tEVal;
}
eVec.x() = principal[0];
eVec.y() = principal[1];
eVec.z() = principal[2];
eVec = tensor(principal[0], principal[1], principal[2]);
// {
// tensor R = rotationTensor(vector(1, 0, 0), eVec.x());

View File

@ -66,7 +66,7 @@ template<class Type>
Field<Type>::Field
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
:
List<Type>(mapAddressing.size())
@ -78,7 +78,7 @@ template<class Type>
Field<Type>::Field
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
:
List<Type>(mapAddressing.size())
@ -297,7 +297,7 @@ template<class Type>
void Field<Type>::map
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
{
Field<Type>& f = *this;
@ -326,7 +326,7 @@ template<class Type>
void Field<Type>::map
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
{
map(tmapF(), mapAddressing);
@ -455,7 +455,7 @@ template<class Type>
void Field<Type>::rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
{
Field<Type>& f = *this;
@ -475,7 +475,7 @@ template<class Type>
void Field<Type>::rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
)
{
rmap(tmapF(), mapAddressing);
@ -487,8 +487,8 @@ template<class Type>
void Field<Type>::rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing,
const scalarList& mapWeights
const UList<label>& mapAddressing,
const UList<scalar>& mapWeights
)
{
Field<Type>& f = *this;
@ -505,8 +505,8 @@ template<class Type>
void Field<Type>::rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing,
const scalarList& mapWeights
const UList<label>& mapAddressing,
const UList<scalar>& mapWeights
)
{
rmap(tmapF(), mapAddressing, mapWeights);

View File

@ -127,14 +127,14 @@ public:
Field
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- Construct by 1 to 1 mapping from the given tmp field
Field
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- Construct by interpolative mapping from the given field
@ -208,14 +208,14 @@ public:
void map
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- 1 to 1 map from the given tmp field
void map
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- Interpolative map from the given field
@ -258,30 +258,30 @@ public:
void rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- 1 to 1 reverse-map from the given tmp field
void rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const UList<label>& mapAddressing
);
//- Interpolative reverse map from the given field
void rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing,
const scalarList& weights
const UList<label>& mapAddressing,
const UList<scalar>& weights
);
//- Interpolative reverse map from the given tmp field
void rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing,
const scalarList& weights
const UList<label>& mapAddressing,
const UList<scalar>& weights
);
//- Negate this field

View File

@ -100,6 +100,14 @@ public:
//- Construct given SymmTensor
inline Tensor(const SymmTensor<Cmpt>&);
//- Construct given the three vector components
inline Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
);
//- Construct given the nine components
inline Tensor
(
@ -116,14 +124,6 @@ public:
// Access
inline const Vector<Cmpt>& x() const;
inline const Vector<Cmpt>& y() const;
inline const Vector<Cmpt>& z() const;
inline Vector<Cmpt>& x();
inline Vector<Cmpt>& y();
inline Vector<Cmpt>& z();
inline const Cmpt& xx() const;
inline const Cmpt& xy() const;
inline const Cmpt& xz() const;
@ -144,6 +144,13 @@ public:
inline Cmpt& zy();
inline Cmpt& zz();
// Access vector components.
// Note: returning const only to find out lhs usage
inline const Vector<Cmpt> x() const;
inline const Vector<Cmpt> y() const;
inline const Vector<Cmpt> z() const;
//- Transpose
inline Tensor<Cmpt> T() const;

View File

@ -64,6 +64,21 @@ inline Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
}
//- Construct given the three vector components
template <class Cmpt>
inline Tensor<Cmpt>::Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
)
{
this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z();
this->v_[YX] = y.x(); this->v_[YY] = y.y(); this->v_[YZ] = y.z();
this->v_[ZX] = z.x(); this->v_[ZY] = z.y(); this->v_[ZZ] = z.z();
}
//- Construct from components
template <class Cmpt>
inline Tensor<Cmpt>::Tensor
@ -90,40 +105,21 @@ inline Tensor<Cmpt>::Tensor(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template <class Cmpt>
inline const Vector<Cmpt>& Tensor<Cmpt>::x() const
inline const Vector<Cmpt> Tensor<Cmpt>::x() const
{
return reinterpret_cast<const Vector<Cmpt>&>(this->v_[XX]);
return Vector<Cmpt>(this->v_[XX], this->v_[XY], this->v_[XZ]);
}
template <class Cmpt>
inline const Vector<Cmpt>& Tensor<Cmpt>::y() const
inline const Vector<Cmpt> Tensor<Cmpt>::y() const
{
return reinterpret_cast<const Vector<Cmpt>&>(this->v_[YX]);
return Vector<Cmpt>(this->v_[YX], this->v_[YY], this->v_[YZ]);
}
template <class Cmpt>
inline const Vector<Cmpt>& Tensor<Cmpt>::z() const
inline const Vector<Cmpt> Tensor<Cmpt>::z() const
{
return reinterpret_cast<const Vector<Cmpt>&>(this->v_[ZX]);
}
template <class Cmpt>
inline Vector<Cmpt>& Tensor<Cmpt>::x()
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[XX]);
}
template <class Cmpt>
inline Vector<Cmpt>& Tensor<Cmpt>::y()
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[YX]);
}
template <class Cmpt>
inline Vector<Cmpt>& Tensor<Cmpt>::z()
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[ZX]);
return Vector<Cmpt>(this->v_[ZX], this->v_[ZY], this->v_[ZZ]);
}

View File

@ -269,10 +269,12 @@ tensor eigenVectors(const tensor& t)
{
vector evals(eigenValues(t));
tensor evs;
evs.x() = eigenVector(t, evals.x());
evs.y() = eigenVector(t, evals.y());
evs.z() = eigenVector(t, evals.z());
tensor evs
(
eigenVector(t, evals.x()),
eigenVector(t, evals.y()),
eigenVector(t, evals.z())
);
return evs;
}
@ -468,10 +470,12 @@ tensor eigenVectors(const symmTensor& t)
{
vector evals(eigenValues(t));
tensor evs;
evs.x() = eigenVector(t, evals.x());
evs.y() = eigenVector(t, evals.y());
evs.z() = eigenVector(t, evals.z());
tensor evs
(
eigenVector(t, evals.x()),
eigenVector(t, evals.y()),
eigenVector(t, evals.z())
);
return evs;
}

View File

@ -92,7 +92,14 @@ public:
//- Construct given SphericalTensor2D
inline Tensor2D(const SphericalTensor2D<Cmpt>&);
//- Construct given the nine components
//- Construct given the two vectors
inline Tensor2D
(
const Vector2D<Cmpt>& x,
const Vector2D<Cmpt>& y
);
//- Construct given the four components
inline Tensor2D
(
const Cmpt txx, const Cmpt txy,
@ -107,12 +114,6 @@ public:
// Access
inline const Vector2D<Cmpt>& x() const;
inline const Vector2D<Cmpt>& y() const;
inline Vector2D<Cmpt>& x();
inline Vector2D<Cmpt>& y();
inline const Cmpt& xx() const;
inline const Cmpt& xy() const;
inline const Cmpt& yx() const;
@ -123,6 +124,11 @@ public:
inline Cmpt& yx();
inline Cmpt& yy();
// Access vector components.
inline Vector2D<Cmpt> x() const;
inline Vector2D<Cmpt> y() const;
//- Transpose
inline Tensor2D<Cmpt> T() const;

View File

@ -50,6 +50,18 @@ inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
}
template <class Cmpt>
inline Tensor2D<Cmpt>::Tensor2D
(
const Vector2D<Cmpt>& x,
const Vector2D<Cmpt>& y
)
{
this->v_[XX] = x.x(); this->v_[XY] = x.y();
this->v_[YX] = y.x(); this->v_[YY] = y.y();
}
template <class Cmpt>
inline Tensor2D<Cmpt>::Tensor2D
(
@ -72,51 +84,38 @@ inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template <class Cmpt>
inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::x() const
inline Vector2D<Cmpt> Tensor2D<Cmpt>::x() const
{
return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
}
template <class Cmpt>
inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::y() const
inline Vector2D<Cmpt> Tensor2D<Cmpt>::y() const
{
return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
}
template <class Cmpt>
inline Vector2D<Cmpt>& Tensor2D<Cmpt>::x()
{
return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
}
template <class Cmpt>
inline Vector2D<Cmpt>& Tensor2D<Cmpt>::y()
{
return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
}
template <class Cmpt>
inline const Cmpt& Tensor2D<Cmpt>::xx() const
inline const Cmpt& Tensor2D<Cmpt>::xx() const
{
return this->v_[XX];
}
template <class Cmpt>
inline const Cmpt& Tensor2D<Cmpt>::xy() const
inline const Cmpt& Tensor2D<Cmpt>::xy() const
{
return this->v_[XY];
}
template <class Cmpt>
inline const Cmpt& Tensor2D<Cmpt>::yx() const
inline const Cmpt& Tensor2D<Cmpt>::yx() const
{
return this->v_[YX];
}
template <class Cmpt>
inline const Cmpt& Tensor2D<Cmpt>::yy() const
inline const Cmpt& Tensor2D<Cmpt>::yy() const
{
return this->v_[YY];
}

View File

@ -158,9 +158,11 @@ tensor2D eigenVectors(const tensor2D& t)
{
vector2D evals(eigenValues(t));
tensor2D evs;
evs.x() = eigenVector(t, evals.x());
evs.y() = eigenVector(t, evals.y());
tensor2D evs
(
eigenVector(t, evals.x()),
eigenVector(t, evals.y())
);
return evs;
}

View File

@ -287,7 +287,7 @@ public:
}
//- Return axis
const vector& axis() const
vector axis() const
{
return coordSys_.axis();
}

View File

@ -168,9 +168,11 @@ void wedgeFvPatchField<Type>::evaluate(const Pstream::commsTypes)
template<class Type>
tmp<Field<Type> > wedgeFvPatchField<Type>::snGradTransformDiag() const
{
diagTensor diagT =
const diagTensor diagT =
0.5*diag(I - refCast<const wedgeFvPatch>(this->patch()).cellT());
const vector diagV(diagT.xx(), diagT.yy(), diagT.zz());
return tmp<Field<Type> >
(
new Field<Type>
@ -180,7 +182,7 @@ tmp<Field<Type> > wedgeFvPatchField<Type>::snGradTransformDiag() const
(
pow
(
reinterpret_cast<const vector&>(diagT),
diagV,
pTraits<typename powProduct<vector, pTraits<Type>::rank>
::type>::zero
)

View File

@ -346,9 +346,12 @@ Foam::fv::cellLimitedGrad<Foam::vector>::calcGrad
forAll(gIf, celli)
{
gIf[celli].x() = cmptMultiply(limiter[celli], gIf[celli].x());
gIf[celli].y() = cmptMultiply(limiter[celli], gIf[celli].y());
gIf[celli].z() = cmptMultiply(limiter[celli], gIf[celli].z());
gIf[celli] = tensor
(
cmptMultiply(limiter[celli], gIf[celli].x()),
cmptMultiply(limiter[celli], gIf[celli].y()),
cmptMultiply(limiter[celli], gIf[celli].z())
);
}
g.correctBoundaryConditions();

View File

@ -66,27 +66,23 @@ void Foam::coordinateRotation::calcTransform
switch (order)
{
case e1e2:
Rtr.x() = a;
Rtr.y() = b;
Rtr.z() = c;
Rtr = tensor(a, b, c);
break;
case e2e3:
Rtr.x() = c;
Rtr.y() = a;
Rtr.z() = b;
Rtr = tensor(c, a, b);
break;
case e3e1:
Rtr.x() = b;
Rtr.y() = c;
Rtr.z() = a;
Rtr = tensor(b, c, a);
break;
default:
FatalErrorIn("coordinateRotation::calcTransform()")
<< "programmer error" << endl
<< abort(FatalError);
// To satisfy compiler warnings
Rtr = tensor::zero;
break;
}

View File

@ -172,19 +172,19 @@ public:
}
//- Return local Cartesian x-axis
vector& e1() const
const vector e1() const
{
return tensor::T().x();
}
//- Return local Cartesian y-axis
vector& e2() const
const vector e2() const
{
return tensor::T().y();
}
//- Return local Cartesian z-axis
vector& e3() const
const vector e3() const
{
return tensor::T().z();
}

View File

@ -346,33 +346,33 @@ public:
}
//- Return local Cartesian x-axis
const vector& e1() const
const vector e1() const
{
return Rtr_.x();
}
//- Return local Cartesian y-axis
const vector& e2() const
const vector e2() const
{
return Rtr_.y();
}
//- Return local Cartesian z-axis
const vector& e3() const
const vector e3() const
{
return Rtr_.z();
}
//- Return axis (e3: local Cartesian z-axis)
// @deprecated method e3 is preferred (deprecated Apr 2008)
const vector& axis() const
const vector axis() const
{
return Rtr_.z();
}
//- Return direction (e1: local Cartesian x-axis)
// @deprecated method e1 is preferred (deprecated Apr 2008)
const vector& direction() const
const vector direction() const
{
return Rtr_.x();
}

View File

@ -1008,7 +1008,7 @@ Foam::surfaceFilmModels::kinematicSingleLayer::T() const
"const volScalarField& kinematicSingleLayer::T() const"
) << "T field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}
@ -1020,7 +1020,7 @@ Foam::surfaceFilmModels::kinematicSingleLayer::cp() const
"const volScalarField& kinematicSingleLayer::cp() const"
) << "cp field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}

View File

@ -137,7 +137,7 @@ const Foam::volVectorField& Foam::surfaceFilmModels::noFilm::U() const
"const volScalarField& noFilm::U() const"
) << "U field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volVectorField&>(null);
return volVectorField::null();
}
@ -148,7 +148,7 @@ const Foam::volScalarField& Foam::surfaceFilmModels::noFilm::rho() const
"const volScalarField& noFilm::rho() const"
) << "rho field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}
@ -159,7 +159,7 @@ const Foam::volScalarField& Foam::surfaceFilmModels::noFilm::T() const
"const Foam::volScalarField& Foam::noFilm::T() const"
) << "T field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}
@ -170,7 +170,7 @@ const Foam::volScalarField& Foam::surfaceFilmModels::noFilm::cp() const
"const volScalarField& noFilm::cp() const"
) << "cp field not available for " << type() << abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}
@ -183,7 +183,7 @@ Foam::surfaceFilmModels::noFilm::massForPrimary() const
) << "massForPrimary field not available for " << type()
<< abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}
@ -196,7 +196,7 @@ Foam::surfaceFilmModels::noFilm::diametersForPrimary() const
) << "diametersForPrimary field not available for " << type()
<< abort(FatalError);
return reinterpret_cast<const volScalarField&>(null);
return volScalarField::null();
}

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -mabi=64
#CC = scg++ -mabi=64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor
CC = g++ -m64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m64

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m32

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m32

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m32

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m32

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
c++WARN = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
CC = g++ -m64 -mcpu=power5+

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter
c++WARN = -Wall -Wextra -Wno-unused-parameter
CC = mingw32-g++

View File

@ -1,6 +1,6 @@
.SUFFIXES: .C .cxx .cc .cpp
c++WARN = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter
c++WARN = -Wall -Wextra -Wno-unused-parameter
CC = g++