Skip to content

Commit

Permalink
COMP: to allow strict aliasing - remove reinterpret_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijs committed Aug 19, 2010
1 parent 0c9c8c0 commit 24257a0
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 125 deletions.
16 changes: 8 additions & 8 deletions src/OpenFOAM/fields/Fields/Field/Field.C
Expand Up @@ -66,7 +66,7 @@ template<class Type>
Field<Type>::Field
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
:
List<Type>(mapAddressing.size())
Expand All @@ -78,7 +78,7 @@ template<class Type>
Field<Type>::Field
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
:
List<Type>(mapAddressing.size())
Expand Down Expand Up @@ -297,7 +297,7 @@ template<class Type>
void Field<Type>::map
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
{
Field<Type>& f = *this;
Expand Down Expand Up @@ -326,7 +326,7 @@ template<class Type>
void Field<Type>::map
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
{
map(tmapF(), mapAddressing);
Expand Down Expand Up @@ -455,7 +455,7 @@ template<class Type>
void Field<Type>::rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
{
Field<Type>& f = *this;
Expand All @@ -475,7 +475,7 @@ template<class Type>
void Field<Type>::rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
)
{
rmap(tmapF(), mapAddressing);
Expand All @@ -487,7 +487,7 @@ template<class Type>
void Field<Type>::rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing,
const unallocLabelList& mapAddressing,
const scalarList& mapWeights
)
{
Expand All @@ -505,7 +505,7 @@ template<class Type>
void Field<Type>::rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing,
const unallocLabelList& mapAddressing,
const scalarList& mapWeights
)
{
Expand Down
16 changes: 8 additions & 8 deletions src/OpenFOAM/fields/Fields/Field/Field.H
Expand Up @@ -127,14 +127,14 @@ public:
Field
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- Construct by 1 to 1 mapping from the given tmp field
Field
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- Construct by interpolative mapping from the given field
Expand Down Expand Up @@ -208,14 +208,14 @@ public:
void map
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- 1 to 1 map from the given tmp field
void map
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- Interpolative map from the given field
Expand Down Expand Up @@ -258,29 +258,29 @@ public:
void rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- 1 to 1 reverse-map from the given tmp field
void rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing
const unallocLabelList& mapAddressing
);

//- Interpolative reverse map from the given field
void rmap
(
const UList<Type>& mapF,
const labelList& mapAddressing,
const unallocLabelList& mapAddressing,
const scalarList& weights
);

//- Interpolative reverse map from the given tmp field
void rmap
(
const tmp<Field<Type> >& tmapF,
const labelList& mapAddressing,
const unallocLabelList& mapAddressing,
const scalarList& weights
);

Expand Down
23 changes: 15 additions & 8 deletions src/OpenFOAM/primitives/Tensor/Tensor.H
Expand Up @@ -100,6 +100,14 @@ public:
//- Construct given SymmTensor
inline Tensor(const SymmTensor<Cmpt>&);

//- Construct given the three vectors
inline Tensor
(
const Vector<Cmpt>& x,
const Vector<Cmpt>& y,
const Vector<Cmpt>& z
);

//- Construct given the nine components
inline Tensor
(
Expand All @@ -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;
Expand All @@ -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;

Expand Down
46 changes: 21 additions & 25 deletions src/OpenFOAM/primitives/Tensor/TensorI.H
Expand Up @@ -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
Expand All @@ -90,40 +105,21 @@ inline Tensor<Cmpt>::Tensor(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

template <class Cmpt>
inline const Vector<Cmpt>& Tensor<Cmpt>::x() const
{
return reinterpret_cast<const Vector<Cmpt>&>(this->v_[XX]);
}

template <class Cmpt>
inline const Vector<Cmpt>& Tensor<Cmpt>::y() const
{
return reinterpret_cast<const Vector<Cmpt>&>(this->v_[YX]);
}

template <class Cmpt>
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()
inline const Vector<Cmpt> Tensor<Cmpt>::x() const
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[XX]);
return Vector<Cmpt>(this->v_[XX], this->v_[XY], this->v_[XZ]);
}

template <class Cmpt>
inline Vector<Cmpt>& Tensor<Cmpt>::y()
inline const Vector<Cmpt> Tensor<Cmpt>::y() const
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[YX]);
return Vector<Cmpt>(this->v_[YX], this->v_[YY], this->v_[YZ]);
}

template <class Cmpt>
inline Vector<Cmpt>& Tensor<Cmpt>::z()
inline const Vector<Cmpt> Tensor<Cmpt>::z() const
{
return reinterpret_cast<Vector<Cmpt>&>(this->v_[ZX]);
return Vector<Cmpt>(this->v_[ZX], this->v_[ZY], this->v_[ZZ]);
}


Expand Down
20 changes: 12 additions & 8 deletions src/OpenFOAM/primitives/Tensor/tensor/tensor.C
Expand Up @@ -265,10 +265,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;
}
Expand Down Expand Up @@ -460,10 +462,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;
}
Expand Down
21 changes: 14 additions & 7 deletions src/OpenFOAM/primitives/Tensor2D/Tensor2D.H
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -123,6 +124,12 @@ public:
inline Cmpt& yx();
inline Cmpt& yy();

// Access vector components.
// Note: returning const only to find out lhs usage

inline const Vector2D<Cmpt> x() const;
inline const Vector2D<Cmpt> y() const;

//- Transpose
inline Tensor2D<Cmpt> T() const;

Expand Down

0 comments on commit 24257a0

Please sign in to comment.