truncatedConeToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "truncatedConeToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::truncatedConeToCell::combine(topoSet& set, const bool add) const
42 {
43  const vector axis = point2_ - point1_;
44  const scalar magAxisSquared = magSqr(axis);
45 
46  const pointField& ctrs = mesh_.cellCentres();
47 
48  forAll(ctrs, celli)
49  {
50  const vector d = ctrs[celli] - point1_;
51  const scalar magD = d & axis;
52 
53  if ((magD > 0) && (magD < magAxisSquared))
54  {
55  const scalar d2 = (d & d) - sqr(magD) / magAxisSquared;
56  const scalar radiusAtCell =
57  radius1_ + (radius2_ - radius1_)*magD/(axis&axis);
58 
59  if (d2 <= sqr(radiusAtCell))
60  {
61  addOrDelete(set, celli, add);
62  }
63  }
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 (
72  const polyMesh& mesh,
73  const vector& point1,
74  const vector& point2,
75  const scalar radius1,
76  const scalar radius2
77 )
78 :
79  topoSetSource(mesh),
80  point1_(point1),
81  point2_(point2),
82  radius1_(radius1),
83  radius2_(radius2)
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  const dictionary& dict
91 )
92 :
93  topoSetSource(mesh),
94  point1_(dict.lookup<point>("point1", dimLength)),
95  point2_(dict.lookup<point>("point2", dimLength)),
96  radius1_(dict.lookup<scalar>("radius1", dimLength)),
97  radius2_(dict.lookup<scalar>("radius2", dimLength))
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
102 
104 {}
105 
106 
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 
110 (
111  const topoSetSource::setAction action,
112  topoSet& set
113 ) const
114 {
115  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
116  {
117  Info<< " Adding cells with centre within cone, with point1 = "
118  << point1_
119  << ", point2 = " << point2_
120  << " and radii = " << radius1_ << " to " << radius2_ << endl;
121 
122  combine(set, true);
123  }
124  else if (action == topoSetSource::DELETE)
125  {
126  Info<< " Removing cells with centre within cone, with point1 = "
127  << point1_
128  << ", point2 = " << point2_
129  << " and radii = " << radius1_ << " to " << radius2_ << endl;
130 
131  combine(set, false);
132  }
133 }
134 
135 
136 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const vectorField & cellCentres() const
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A topoSetSource to select cells with centres inside a truncated cone.
virtual ~truncatedConeToCell()
Destructor.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
truncatedConeToCell(const polyMesh &mesh, const vector &point1, const vector &point2, const scalar radius1, const scalar radius2)
Construct from components.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
const dimensionSet dimLength
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dictionary dict