Skip to content

Commit

Permalink
cut: Templated point type
Browse files Browse the repository at this point in the history
This allows for different information to be passed around the cut
routines; in particular, classes representing the topology of the cuts.
  • Loading branch information
Will Bainbridge committed Jun 13, 2019
1 parent ac5b46b commit 47d1954
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
30 changes: 15 additions & 15 deletions src/OpenFOAM/meshes/primitiveShapes/cut/cut.H
Expand Up @@ -124,8 +124,8 @@ public:
}

//- Operate on a triangle or tetrahedron
template<unsigned Size>
result operator()(const FixedList<point, Size>& p) const
template<class Type, unsigned Size>
result operator()(const FixedList<Type, Size>& p) const
{
return result();
}
Expand Down Expand Up @@ -400,7 +400,7 @@ public:
Class listOp Declaration
\*---------------------------------------------------------------------------*/

template<unsigned Size>
template<class Type, unsigned Size>
class listOp
:
public uniformOp<nil>
Expand All @@ -412,16 +412,16 @@ public:
//- Result class
class result
:
public DynamicList<FixedList<point, Size>>
public DynamicList<FixedList<Type, Size>>
{
public:

// Constructors

//- Construct from a single element
result(const FixedList<point, Size>& x)
result(const FixedList<Type, Size>& x)
:
DynamicList<FixedList<point, Size>>(1, x)
DynamicList<FixedList<Type, Size>>(1, x)
{}


Expand Down Expand Up @@ -459,17 +459,17 @@ public:
}

//- Operate on a triangle or tetrahedron
result operator()(const FixedList<point, Size>& p) const
result operator()(const FixedList<Type, Size>& p) const
{
return result(p);
}
};


typedef listOp<3> listTriOp;
typedef listOp<point, 3> listTriOp;


typedef listOp<4> listTetOp;
typedef listOp<point, 4> listTetOp;


/*---------------------------------------------------------------------------*\
Expand Down Expand Up @@ -513,8 +513,8 @@ public:
}

//- Operate on a triangle or tetrahedron
template<unsigned Size>
result operator()(const FixedList<point, Size>& p) const
template<class Type, unsigned Size>
result operator()(const FixedList<Type, Size>& p) const
{
this->data().append(p);
return result();
Expand Down Expand Up @@ -569,10 +569,10 @@ public:
//- Cut a triangle along the zero plane defined by the given levels. Templated
// on aboveOp and belowOp; the operations applied to the regions on either side
// of the cut.
template<class AboveOp, class BelowOp>
template<class Point, class AboveOp, class BelowOp>
typename cut::opAddResult<AboveOp, BelowOp>::type triCut
(
const FixedList<point, 3>& tri,
const FixedList<Point, 3>& tri,
const FixedList<scalar, 3>& level,
const AboveOp& aboveOp,
const BelowOp& belowOp
Expand All @@ -589,10 +589,10 @@ typename cut::opAddResult<AboveOp, BelowOp>::type triCut
);

//- As triCut, but for a tetrahedron.
template<class AboveOp, class BelowOp>
template<class Point, class AboveOp, class BelowOp>
typename cut::opAddResult<AboveOp, BelowOp>::type tetCut
(
const FixedList<point, 4>& tet,
const FixedList<Point, 4>& tet,
const FixedList<scalar, 4>& level,
const AboveOp& aboveOp,
const BelowOp& belowOp
Expand Down
44 changes: 22 additions & 22 deletions src/OpenFOAM/meshes/primitiveShapes/cut/cutI.H
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -157,7 +157,7 @@ inline FixedList<Type, 3> triCutTri
result[0] = x[0];
for (label i = 0; i < 2; ++ i)
{
result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
result[i+1] = (1 - f[i])*x[0] + f[i]*x[i+1];
}
return result;
}
Expand All @@ -175,7 +175,7 @@ inline FixedList<Type, 4> triCutQuad
for (label i = 0; i < 2; ++ i)
{
result[i] = x[i+1];
result[3-i] = x[0] + f[i]*(x[i+1] - x[0]);
result[3-i] = (1 - f[i])*x[0] + f[i]*x[i+1];
}
return result;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ inline FixedList<Type, 4> tetCutTet
result[0] = x[0];
for (label i = 0; i < 3; ++ i)
{
result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
result[i+1] = (1 - f[i])*x[0] + f[i]*x[i+1];
}
return result;
}
Expand All @@ -227,7 +227,7 @@ inline FixedList<Type, 6> tetCutPrism0
FixedList<Type, 6> result;
for (label i = 0; i < 3; ++ i)
{
result[i] = x[0] + f[i]*(x[i+1] - x[0]);
result[i] = (1 - f[i])*x[0] + f[i]*x[i+1];
result[i+3] = x[i+1];
}
return result;
Expand All @@ -248,7 +248,7 @@ inline FixedList<Type, 6> tetCutPrism01
result[3*i] = x[i];
for (label j = 0; j < 2; ++ j)
{
result[3*i+j+1] = x[i] + f[2*i+j]*(x[j+2] - x[i]);
result[3*i+j+1] = (1 - f[2*i+j])*x[i] + f[2*i+j]*x[j+2];
}
}

Expand All @@ -275,11 +275,11 @@ inline FixedList<Type, 6> tetCutPrism23
//- Cut a tri from a tri and apply an operation to the result. The cut is made
// along the two edges connected to vertex 0, and the cut locations are given
// as factors along these edges. The result is the side connected to vertex 0.
template<class Op>
template<class Op, class Point>
inline typename Op::result triCutTri
(
const Op& op,
const FixedList<point, 3>& p,
const FixedList<Point, 3>& p,
const Pair<scalar>& f
)
{
Expand All @@ -288,11 +288,11 @@ inline typename Op::result triCutTri


//- Apply an operation to a quad. Splits the quad into two tris.
template<class Op, class OpData>
template<class Op, class OpData, class Point>
inline typename Op::result quadOp
(
const OpData& opData,
const FixedList<point, 4>& p
const FixedList<Point, 4>& p
)
{
static const FixedList<FixedList<label, 3>, 2> i =
Expand All @@ -306,11 +306,11 @@ inline typename Op::result quadOp
//- Cut a quad from a tri and apply an operation to the result. The cuts are
// the same as for triCutTri. The result is the side connected to vertices 1
// and 2.
template<class Op>
template<class Op, class Point>
inline typename Op::result triCutQuad
(
const Op& op,
const FixedList<point, 3>& p,
const FixedList<Point, 3>& p,
const FixedList<scalar, 2>& f
)
{
Expand All @@ -321,11 +321,11 @@ inline typename Op::result triCutQuad
//- Cut a tet from a tet and apply an operation to the result. The cut is made
// along the three edges connected to vertex 0, and the cut locations are given
// as factors along these edges. The result is the side connected to vertex 0.
template<class Op>
template<class Op, class Point>
inline typename Op::result tetCutTet
(
const Op& op,
const FixedList<point, 4>& p,
const FixedList<Point, 4>& p,
const FixedList<scalar, 3>& f
)
{
Expand All @@ -334,11 +334,11 @@ inline typename Op::result tetCutTet


//- Apply an operation to a prism. Splits the prism into three tets.
template<class Op, class OpData>
template<class Op, class OpData, class Point>
inline typename Op::result prismOp
(
const OpData& opData,
const FixedList<point, 6>& p
const FixedList<Point, 6>& p
)
{
static const FixedList<FixedList<label, 4>, 3> i =
Expand All @@ -353,11 +353,11 @@ inline typename Op::result prismOp
//- Cut a prism from a tet and apply an operation to the result. The cuts are
// the same as for tetCutTet. The result is the side connected to vertices 1,
// 2 and 3.
template<class Op>
template<class Op, class Point>
inline typename Op::result tetCutPrism0
(
const Op& op,
const FixedList<point, 4>& p,
const FixedList<Point, 4>& p,
const FixedList<scalar, 3>& f
)
{
Expand All @@ -368,11 +368,11 @@ inline typename Op::result tetCutPrism0
//- Cut a prism from a tet and apply an operation to the result. The cut is made
// along four edges, not edges 01 or 23, and the cut locations are given as
// factors along these edges. The result is the side connected to edge 01.
template<class Op>
template<class Op, class Point>
inline typename Op::result tetCutPrism01
(
const Op& op,
const FixedList<point, 4>& p,
const FixedList<Point, 4>& p,
const FixedList<scalar, 4>& f
)
{
Expand All @@ -382,11 +382,11 @@ inline typename Op::result tetCutPrism01

//- Cut a prism from a tet and apply an operation to the result. The cuts are
// the same as for tetCutPrism01. The result is the side connected to edge 23.
template<class Op>
template<class Op, class Point>
inline typename Op::result tetCutPrism23
(
const Op& op,
const FixedList<point, 4>& p,
const FixedList<Point, 4>& p,
const FixedList<scalar, 4>& f
)
{
Expand Down
14 changes: 7 additions & 7 deletions src/OpenFOAM/meshes/primitiveShapes/cut/cutTemplates.C
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand All @@ -27,10 +27,10 @@ License

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

template<class AboveOp, class BelowOp>
template<class Point, class AboveOp, class BelowOp>
typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::triCut
(
const FixedList<point, 3>& tri,
const FixedList<Point, 3>& tri,
const FixedList<scalar, 3>& level,
const AboveOp& aboveOp,
const BelowOp& belowOp
Expand Down Expand Up @@ -73,7 +73,7 @@ typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::triCut
}

// Permute the data
const FixedList<point, 3> p = triReorder(tri, indices);
const FixedList<Point, 3> p = triReorder(tri, indices);
const FixedList<scalar, 3> l = triReorder(level, indices);
AboveOp a = triReorder(aboveOp, indices);
BelowOp b = triReorder(belowOp, indices);
Expand Down Expand Up @@ -116,10 +116,10 @@ typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::triCut
}


template<class AboveOp, class BelowOp>
template<class Point, class AboveOp, class BelowOp>
typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::tetCut
(
const FixedList<point, 4>& tet,
const FixedList<Point, 4>& tet,
const FixedList<scalar, 4>& level,
const AboveOp& aboveOp,
const BelowOp& belowOp
Expand Down Expand Up @@ -188,7 +188,7 @@ typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::tetCut
}

// Permute the data
const FixedList<point, 4> p = tetReorder(tet, indices);
const FixedList<Point, 4> p = tetReorder(tet, indices);
const FixedList<scalar, 4> l = tetReorder(level, indices);
AboveOp a = tetReorder(aboveOp, indices);
BelowOp b = tetReorder(belowOp, indices);
Expand Down

0 comments on commit 47d1954

Please sign in to comment.