sphereToCell.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) 2011-2021 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 "sphereToCell.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::sphereToCell::combine(topoSet& set, const bool add) const
42 {
43  const pointField& ctrs = mesh_.cellCentres();
44 
45  const scalar radSquared = radius_*radius_;
46 
47  forAll(ctrs, celli)
48  {
49  scalar offset = magSqr(centre_ - ctrs[celli]);
50  if (offset <= radSquared)
51  {
52  addOrDelete(set, celli, add);
53  }
54  }
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 (
62  const polyMesh& mesh,
63  const vector& centre,
64  const scalar radius
65 )
66 :
67  topoSetSource(mesh),
68  centre_(centre),
69  radius_(radius)
70 {}
71 
72 
74 (
75  const polyMesh& mesh,
76  const dictionary& dict
77 )
78 :
79  topoSetSource(mesh),
80  centre_(dict.lookup("centre")),
81  radius_(dict.lookup<scalar>("radius"))
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
86 
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 (
95  const topoSetSource::setAction action,
96  topoSet& set
97 ) const
98 {
99  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
100  {
101  Info<< " Adding cells with centre within sphere, with centre = "
102  << centre_ << " and radius = " << radius_ << endl;
103 
104  combine(set, true);
105  }
106  else if (action == topoSetSource::DELETE)
107  {
108  Info<< " Removing cells with centre within sphere, with centre = "
109  << centre_ << " and radius = " << radius_ << endl;
110 
111  combine(set, false);
112  }
113 }
114 
115 
116 // ************************************************************************* //
#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:160
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const vectorField & cellCentres() const
A topoSetSource to select cells based on cell centres inside sphere.
Definition: sphereToCell.H:51
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: sphereToCell.C:94
sphereToCell(const polyMesh &mesh, const vector &centre, const scalar radius)
Construct from components.
Definition: sphereToCell.C:61
virtual ~sphereToCell()
Destructor.
Definition: sphereToCell.C:87
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 class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
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
void offset(label &lst, const label o)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict