Curle.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "Curle.H"
29 #include "fvcDdt.H"
30 #include "mathematicalConstants.H"
32 
33 using namespace Foam::constant;
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace functionObjects
40 {
41  defineTypeNameAndDebug(Curle, 0);
42 
44  (
45  functionObject,
46  Curle,
47  dictionary
48  );
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
54 
56 {
57  if (foundObject<volScalarField>(fieldName_))
58  {
59  // Evaluate pressure force time derivative
60 
61  const volScalarField& p = lookupObject<volScalarField>(fieldName_);
62  const volScalarField dpdt(scopedName("dpdt"), fvc::ddt(p));
63  const volScalarField::Boundary& dpdtBf = dpdt.boundaryField();
64  const surfaceVectorField::Boundary& SfBf = mesh_.Sf().boundaryField();
65 
66  dimensionedVector dfdt("dfdt", p.dimensions()*dimArea/dimTime, Zero);
67 
68  for (auto patchi : patchSet_)
69  {
70  dfdt.value() += sum(dpdtBf[patchi]*SfBf[patchi]);
71  }
72 
73  reduce(dfdt.value(), sumOp<vector>());
74 
75 
76  // Construct and store Curle acoustic pressure
77 
78  const volVectorField& C = mesh_.C();
79 
80  auto tpDash = tmp<volScalarField>::New
81  (
82  IOobject
83  (
84  resultName_,
85  mesh_.time().timeName(),
86  mesh_,
89  ),
90  mesh_,
91  dimensionedScalar(p.dimensions(), Zero)
92  );
93  auto& pDash = tpDash.ref();
94 
95  const volVectorField d(scopedName("d"), C - x0_);
96  pDash = (d/magSqr(d) & dfdt)/(4.0*mathematical::pi*c0_);
97 
98  return store(resultName_, tpDash);
99  }
100 
101  return false;
102 }
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
106 Foam::functionObjects::Curle::Curle
107 (
108  const word& name,
109  const Time& runTime,
110  const dictionary& dict
111 )
112 :
114  patchSet_(),
115  x0_("x0", dimLength, Zero),
116  c0_("c0", dimVelocity, Zero)
117 {
118  read(dict);
119 
120  setResultName(typeName, fieldName_);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 {
135  {
136  patchSet_ = mesh_.boundaryMesh().patchSet(dict.get<wordRes>("patches"));
137 
138  if (patchSet_.empty())
139  {
141  << "No patches defined"
142  << endl;
143 
144  return false;
145  }
146 
147  // Read the reference speed of sound
148  dict.readEntry("c0", c0_);
149 
150 
151  // Set the location of the effective point source to the area-average
152  // of the patch face centres
153  const volVectorField::Boundary& Cbf = mesh_.C().boundaryField();
154  const surfaceScalarField::Boundary& magSfBf =
155  mesh_.magSf().boundaryField();
156 
157  x0_.value() = vector::zero;
158  scalar sumMagSf = 0;
159  for (auto patchi : patchSet_)
160  {
161  x0_.value() += sum(Cbf[patchi]*magSfBf[patchi]);
162  sumMagSf += sum(magSfBf[patchi]);
163  }
164 
165  reduce(x0_.value(), sumOp<vector>());
166  reduce(sumMagSf, sumOp<scalar>());
167 
168  x0_.value() /= sumMagSf + ROOTVSMALL;
169 
170  return true;
171  }
172 
173  return false;
174 }
175 
176 
177 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
mathematicalConstants.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::functionObjects::Curle::~Curle
virtual ~Curle()
Destructor.
Definition: Curle.C:126
Foam::constant
Different types of constants.
Definition: atomicConstants.C:38
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:404
Foam::sumOp
Definition: ops.H:213
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:60
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned< vector >
Foam::C::C
C()
Construct null.
Definition: C.C:43
Foam::functionObjects::Curle::read
virtual bool read(const dictionary &)
Read the Curle data.
Definition: Curle.C:132
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::functionObjects::fieldExpression
Base class for field expression function objects.
Definition: fieldExpression.H:60
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::functionObjects::Curle::calc
virtual bool calc()
Calculate the acoustic pressure field and return true if successful.
Definition: Curle.C:55
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::zero
static const Vector< scalar > zero
Definition: VectorSpace.H:115
fvcDdt.H
Calculate the first temporal derivative.
Foam::fvc::ddt
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:47
dpdt
volScalarField & dpdt
Definition: setRegionFluidFields.H:32
Foam::C
Graphite solid properties.
Definition: C.H:50
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Curle.H