Commit 9cd69522 authored by laurence's avatar laurence
Browse files

ENH: Add triad primitive type and Field/IOField

parent 6b24bdd4
......@@ -63,6 +63,7 @@ primitives/globalIndexAndTransform/globalIndexAndTransform.C
primitives/globalIndexAndTransform/vectorTensorTransform/vectorTensorTransform.C
primitives/quaternion/quaternion.C
primitives/septernion/septernion.C
primitives/triad/triad.C
/* functions, data entries */
primitives/functions/DataEntry/makeDataEntries.C
......@@ -524,6 +525,7 @@ $(Fields)/sphericalTensorField/sphericalTensorField.C
$(Fields)/diagTensorField/diagTensorField.C
$(Fields)/symmTensorField/symmTensorField.C
$(Fields)/tensorField/tensorField.C
$(Fields)/triadField/triadField.C
$(Fields)/complexFields/complexFields.C
$(Fields)/labelField/labelIOField.C
......@@ -542,6 +544,7 @@ $(Fields)/symmTensorField/symmTensorIOField.C
$(Fields)/symmTensorField/symmTensorFieldIOField.C
$(Fields)/tensorField/tensorIOField.C
$(Fields)/tensorField/tensorFieldIOField.C
$(Fields)/triadField/triadIOField.C
$(Fields)/transformField/transformField.C
pointPatchFields = fields/pointPatchFields
......
......@@ -36,6 +36,7 @@ Description
#include "sphericalTensor.H"
#include "symmTensor.H"
#include "tensor.H"
#include "triad.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triadField.H"
#include "transformField.H"
#define TEMPLATE
#include "FieldFunctionsM.C"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::triadField
Description
Specialisation of Field\<T\> for triad.
SourceFiles
triadField.C
\*---------------------------------------------------------------------------*/
#ifndef triadField_H
#define triadField_H
#include "Field.H"
#include "triad.H"
#define TEMPLATE
#include "FieldFunctionsM.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef Field<triad> triadField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
triadField with IO.
\*---------------------------------------------------------------------------*/
#include "triadIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebugWithName(triadIOField, "triadField", 0);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::triadIOField
Description
triadField with IO.
\*---------------------------------------------------------------------------*/
#ifndef triadIOField_H
#define triadIOField_H
#include "triadField.H"
#include "IOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<triad> triadIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triad.H"
#include "transform.H"
#include "tensor.H"
#include "quaternion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
const char* const triad::Vector<vector>::typeName = "triad";
template<>
const char* triad::Vector<vector>::componentNames[] = {"x", "y", "z"};
const triad triad::zero(vector::zero, vector::zero, vector::zero);
const triad triad::one(vector::one, vector::one, vector::one);
const triad triad::max(vector::max, vector::max, vector::max);
const triad triad::min(vector::min, vector::min, vector::min);
const triad triad::unset(triad::max);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::triad::triad(const quaternion& q)
{
tensor Rt(q.R().T());
x() = Rt.x();
y() = Rt.y();
z() = Rt.z();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::triad::orthogonalize()
{
// Hack for 2D z-slab cases
// if (!set(2))
// {
// operator[](2) = vector(0, 0, 1);
// }
// If only two of the axes are set, set the third
if (set(0) && set(1) && !set(2))
{
operator[](2) = orthogonal(operator[](0), operator[](1));
}
else if (set(0) && set(2) && !set(1))
{
operator[](1) = orthogonal(operator[](0), operator[](2));
}
else if (set(1) && set(2) && !set(0))
{
operator[](0) = orthogonal(operator[](1), operator[](2));
}
// If all the axes are set
if (set())
{
for (int i=0; i<2; i++)
{
scalar o01 = mag(operator[](0) & operator[](1));
scalar o02 = mag(operator[](0) & operator[](2));
scalar o12 = mag(operator[](1) & operator[](2));
if (o01 < o02 && o01 < o12)
{
operator[](2) = orthogonal(operator[](0), operator[](1));
// if (o02 < o12)
// {
// operator[](1) = orthogonal(operator[](0), operator[](2));
// }
// else
// {
// operator[](0) = orthogonal(operator[](1), operator[](2));
// }
}
else if (o02 < o12)
{
operator[](1) = orthogonal(operator[](0), operator[](2));
// if (o01 < o12)
// {
// operator[](2) = orthogonal(operator[](0), operator[](1));
// }
// else
// {
// operator[](0) = orthogonal(operator[](1), operator[](2));
// }
}
else
{
operator[](0) = orthogonal(operator[](1), operator[](2));
// if (o02 < o01)
// {
// operator[](1) = orthogonal(operator[](0), operator[](2));
// }
// else
// {
// operator[](2) = orthogonal(operator[](0), operator[](1));
// }
}
}
}
}
void Foam::triad::operator+=(const triad& t2)
{
if (t2.set(0) && !set(0))
{
operator[](0) = t2.operator[](0);
}
if (t2.set(1) && !set(1))
{
operator[](1) = t2.operator[](1);
}
if (t2.set(2) && !set(2))
{
operator[](2) = t2.operator[](2);
}
if (set() && t2.set())
{
direction correspondance[3];
short signd[3];
for (direction i=0; i<3; i++)
{
scalar mostAligned = -1;
for (direction j=0; j<3; j++)
{
bool set = false;
for (direction k=0; k<i; k++)
{
if (correspondance[k] == j)
{
set = true;
break;
}
}
if (!set)
{
scalar a = operator[](i) & t2.operator[](j);
scalar maga = mag(a);
if (maga > mostAligned)
{
correspondance[i] = j;
mostAligned = maga;
signd[i] = sign(a);
}
}
}
}
for (direction i=0; i<3; i++)
{
operator[](i) += signd[i]*t2.operator[](correspondance[i]);
}
}
}
void Foam::triad::align(const vector& v)
{
if (set())
{
vector mostAligned
(
mag(v & operator[](0)),
mag(v & operator[](1)),
mag(v & operator[](2))
);
scalar mav;
if
(
mostAligned.x() > mostAligned.y()
&& mostAligned.x() > mostAligned.z()
)
{
mav = mostAligned.x();
mostAligned = operator[](0);
}
else if (mostAligned.y() > mostAligned.z())
{
mav = mostAligned.y();
mostAligned = operator[](1);
}
else
{
mav = mostAligned.z();
mostAligned = operator[](2);
}
if (mav < 0.99)
{
tensor R(rotationTensor(mostAligned, v));
operator[](0) = transform(R, operator[](0));
operator[](1) = transform(R, operator[](1));
operator[](2) = transform(R, operator[](2));
}
}
}
Foam::triad Foam::triad::sortxyz() const
{
triad t;
if
(
mag(operator[](0).x()) > mag(operator[](1).x())
&& mag(operator[](0).x()) > mag(operator[](2).x())
)
{
t[0] = operator[](0);
if (mag(operator[](1).y()) > mag(operator[](2).y()))
{
t[1] = operator[](1);
t[2] = operator[](2);
}
else
{
t[1] = operator[](2);
t[2] = operator[](1);
}
}
else if
(
mag(operator[](1).x()) > mag(operator[](2).x())
)
{
t[0] = operator[](1);
if (mag(operator[](0).y()) > mag(operator[](2).y()))
{
t[1] = operator[](0);
t[2] = operator[](2);
}
else
{
t[1] = operator[](2);
t[2] = operator[](0);
}
}
else
{
t[0] = operator[](2);
if (mag(operator[](0).y()) > mag(operator[](1).y()))
{
t[1] = operator[](0);
t[2] = operator[](1);
}
else
{
t[1] = operator[](1);
t[2] = operator[](0);
}
}
if (t[0].x() < 0) t[0] *= -1;
if (t[1].y() < 0) t[1] *= -1;
if (t[2].z() < 0) t[2] *= -1;
return t;
}
Foam::triad::operator quaternion() const
{
tensor R;
R.xx() = x().x();
R.xy() = y().x();
R.xz() = z().x();
R.yx() = x().y();
R.yy() = y().y();
R.yz() = z().y();
R.zx() = x().z();
R.zy() = y().z();
R.zz() = z().z();
return quaternion(R);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::triad
Description
Representation of a 3D Cartesian coordinate system as a Vector of vectors.
See Also
Foam::quaternion
SourceFiles
triadI.H
triad.C
\*---------------------------------------------------------------------------*/
#ifndef triad_H
#define triad_H
#include "vector.H"
#include "contiguous.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{