multiFreqScalarFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  This file is modified from OpenFOAM's source code
7  src/finiteVolume/fields/fvPatchFields/basic/fixedValue/fixedValueFvPatchField.C
8 
9  OpenFOAM: The Open Source CFD Toolbox
10 
11  Copyright (C): 2011-2016 OpenFOAM Foundation
12 
13  OpenFOAM License:
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
31 #include "volFields.H"
32 #include "addToRunTimeSelectionTable.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37  const fvPatch& p,
38  const DimensionedField<scalar, volMesh>& iF)
39  : fixedValueFvPatchScalarField(p, iF),
40  refValue_(0.0),
41  amplitudes_({}),
42  frequencies_({}),
43  phases_({})
44 {
45 }
46 
48  const fvPatch& p,
49  const DimensionedField<scalar, volMesh>& iF,
50  const dictionary& dict)
51  : fixedValueFvPatchScalarField(p, iF),
52  refValue_(dict.lookupOrDefault<scalar>("refValue", 0.0)),
53  amplitudes_(dict.lookupOrDefault<scalarList>("amplitudes", {})),
54  frequencies_(dict.lookupOrDefault<scalarList>("frequencies", {})),
55  phases_(dict.lookupOrDefault<scalarList>("phases", {}))
56 {
57 
58  if (dict.found("value"))
59  {
60  fvPatchScalarField::operator=(
61  scalarField("value", dict, p.size()));
62  }
63  else
64  {
65  this->evaluate();
66  }
67 }
68 
70  const multiFreqScalarFvPatchField& ptf,
71  const fvPatch& p,
72  const DimensionedField<scalar, volMesh>& iF,
73  const fvPatchFieldMapper& mapper)
74  : fixedValueFvPatchScalarField(p, iF),
75  refValue_(ptf.refValue_),
76  amplitudes_(ptf.amplitudes_),
77  frequencies_(ptf.frequencies_),
78  phases_(ptf.phases_)
79 {
80  this->evaluate();
81 }
82 
84  const multiFreqScalarFvPatchField& wbppsf)
85  : fixedValueFvPatchScalarField(wbppsf),
86  refValue_(wbppsf.refValue_),
87  amplitudes_(wbppsf.amplitudes_),
88  frequencies_(wbppsf.frequencies_),
89  phases_(wbppsf.phases_)
90 {
91  this->evaluate();
92 }
93 
95  const multiFreqScalarFvPatchField& wbppsf,
96  const DimensionedField<scalar, volMesh>& iF)
97  : fixedValueFvPatchScalarField(wbppsf, iF),
98  refValue_(wbppsf.refValue_),
99  amplitudes_(wbppsf.amplitudes_),
100  frequencies_(wbppsf.frequencies_),
101  phases_(wbppsf.phases_)
102 {
103  this->evaluate();
104 }
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 {
109  // calculate patch values
110  const scalar t = this->db().time().timeOutputValue();
111  scalar bcVal = 0.0;
112  const label& nFreqs = frequencies_.size();
113 
114  for (label i = 0; i < nFreqs; i++)
115  {
116  const scalar& a = amplitudes_[i];
117  const scalar& f = frequencies_[i];
118  const scalar& p = phases_[i];
119  bcVal += a * sin(constant::mathematical::twoPi * f * t + p);
120  }
121 
122  scalarField& thisPatchRef = *this;
123  scalarField thisPatch = thisPatchRef;
124  forAll(thisPatch, idxI) thisPatch[idxI] = refValue_;
125  forAll(thisPatch, idxI) thisPatch[idxI] += bcVal;
126 
127  fvPatchScalarField::operator==(thisPatch);
128 
129  fixedValueFvPatchScalarField::updateCoeffs();
130 }
131 
133 {
134  fixedValueFvPatchScalarField::write(os);
135  os.writeEntry("refValue", refValue_);
136  os.writeEntry("amplitudes", amplitudes_);
137  os.writeEntry("frequencies", frequencies_);
138  os.writeEntry("phases", phases_);
139  //writeEntry("value", os);
140 }
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 namespace Foam
145 {
147  fvPatchScalarField,
149 }
150 
151 // ************************************************************************* //
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::multiFreqScalarFvPatchField::write
virtual void write(Ostream &) const
Definition: multiFreqScalarFvPatchField.C:132
Foam::multiFreqScalarFvPatchField::updateCoeffs
virtual void updateCoeffs()
Definition: multiFreqScalarFvPatchField.C:107
p
volScalarField & p
Definition: createRefsPimple.H:6
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, multiFreqScalarFvPatchField)
Foam
Definition: multiFreqScalarFvPatchField.C:144
multiFreqScalarFvPatchField.H
Foam::multiFreqScalarFvPatchField
Definition: multiFreqScalarFvPatchField.H:82
Foam::multiFreqScalarFvPatchField::multiFreqScalarFvPatchField
multiFreqScalarFvPatchField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Definition: multiFreqScalarFvPatchField.C:36