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-2018 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 {
34  defineTypeNameAndDebug(sphereToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, sphereToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, sphereToCell, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::sphereToCell::usage_
41 (
42  sphereToCell::typeName,
43  "\n Usage: sphereToCell (centreX centreY centreZ) radius\n\n"
44  " Select all cells with cellCentre within bounding sphere\n\n"
45 );
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::sphereToCell::combine(topoSet& set, const bool add) const
51 {
52  const pointField& ctrs = mesh_.cellCentres();
53 
54  const scalar radSquared = radius_*radius_;
55 
56  forAll(ctrs, celli)
57  {
58  scalar offset = magSqr(centre_ - ctrs[celli]);
59  if (offset <= radSquared)
60  {
61  addOrDelete(set, celli, add);
62  }
63  }
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 
70 (
71  const polyMesh& mesh,
72  const vector& centre,
73  const scalar radius
74 )
75 :
76  topoSetSource(mesh),
77  centre_(centre),
78  radius_(radius)
79 {}
80 
81 
83 (
84  const polyMesh& mesh,
85  const dictionary& dict
86 )
87 :
88  topoSetSource(mesh),
89  centre_(dict.lookup("centre")),
90  radius_(readScalar(dict.lookup("radius")))
91 {}
92 
93 
95 (
96  const polyMesh& mesh,
97  Istream& is
98 )
99 :
100  topoSetSource(mesh),
101  centre_(checkIs(is)),
102  radius_(readScalar(checkIs(is)))
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 (
116  const topoSetSource::setAction action,
117  topoSet& set
118 ) const
119 {
120  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
121  {
122  Info<< " Adding cells with centre within sphere, with centre = "
123  << centre_ << " and radius = " << radius_ << endl;
124 
125  combine(set, true);
126  }
127  else if (action == topoSetSource::DELETE)
128  {
129  Info<< " Removing cells with centre within sphere, with centre = "
130  << centre_ << " and radius = " << radius_ << endl;
131 
132  combine(set, false);
133  }
134 }
135 
136 
137 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual ~sphereToCell()
Destructor.
Definition: sphereToCell.C:108
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
sphereToCell(const polyMesh &mesh, const vector &centre, const scalar radius)
Construct from components.
Definition: sphereToCell.C:70
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: sphereToCell.C:115
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576