multiFreqVectorFvPatchField.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<vector, volMesh>& iF)
39  : fixedValueFvPatchVectorField(p, iF),
40  refValue_(vector::zero),
41  amplitudes_({}),
42  frequencies_({}),
43  phases_({}),
44  component_(0),
45  endTime_(1.0e8)
46 {
47 }
48 
50  const fvPatch& p,
51  const DimensionedField<vector, volMesh>& iF,
52  const dictionary& dict)
53  : fixedValueFvPatchVectorField(p, iF),
54  refValue_(dict.lookupOrDefault<vector>("refValue", vector::zero)),
55  amplitudes_(dict.lookupOrDefault<scalarList>("amplitudes", {})),
56  frequencies_(dict.lookupOrDefault<scalarList>("frequencies", {})),
57  phases_(dict.lookupOrDefault<scalarList>("phases", {})),
58  component_(dict.lookupOrDefault<label>("component", 0)),
59  endTime_(dict.lookupOrDefault<scalar>("endTime", 1.0e8))
60 {
61  if (dict.found("value"))
62  {
63  fvPatchVectorField::operator=(
64  vectorField("value", dict, p.size()));
65  }
66  else
67  {
68  this->evaluate();
69  }
70 }
71 
73  const multiFreqVectorFvPatchField& ptf,
74  const fvPatch& p,
75  const DimensionedField<vector, volMesh>& iF,
76  const fvPatchFieldMapper& mapper)
77  : fixedValueFvPatchVectorField(p, iF),
78  refValue_(ptf.refValue_),
79  amplitudes_(ptf.amplitudes_),
80  frequencies_(ptf.frequencies_),
81  phases_(ptf.phases_),
82  component_(ptf.component_),
83  endTime_(ptf.endTime_)
84 {
85  this->evaluate();
86 }
87 
89  const multiFreqVectorFvPatchField& wbppsf)
90  : fixedValueFvPatchVectorField(wbppsf),
91  refValue_(wbppsf.refValue_),
92  amplitudes_(wbppsf.amplitudes_),
93  frequencies_(wbppsf.frequencies_),
94  phases_(wbppsf.phases_),
95  component_(wbppsf.component_),
96  endTime_(wbppsf.endTime_)
97 {
98  this->evaluate();
99 }
100 
102  const multiFreqVectorFvPatchField& wbppsf,
103  const DimensionedField<vector, volMesh>& iF)
104  : fixedValueFvPatchVectorField(wbppsf, iF),
105  refValue_(wbppsf.refValue_),
106  amplitudes_(wbppsf.amplitudes_),
107  frequencies_(wbppsf.frequencies_),
108  phases_(wbppsf.phases_),
109  component_(wbppsf.component_),
110  endTime_(wbppsf.endTime_)
111 {
112  this->evaluate();
113 }
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 {
118  // calculate patch values
119  const scalar t = this->db().time().timeOutputValue();
120  scalar bcVal = 0.0;
121  const label& nFreqs = frequencies_.size();
122 
123  for (label i = 0; i < nFreqs; i++)
124  {
125  const scalar& a = amplitudes_[i];
126  const scalar& f = frequencies_[i];
127  const scalar& p = phases_[i];
128  bcVal += a * sin(constant::mathematical::twoPi * f * t + p);
129  }
130 
131  vectorField& thisPatchRef = *this;
132  vectorField thisPatch = thisPatchRef;
133  forAll(thisPatch, idxI) thisPatch[idxI] = refValue_;
134  if (t < endTime_) // if t > endTime, do not add oscillation.
135  {
136  forAll(thisPatch, idxI) thisPatch[idxI][component_] += bcVal;
137  }
138 
139  fvPatchVectorField::operator==(thisPatch);
140 
141  fixedValueFvPatchVectorField::updateCoeffs();
142 }
143 
145 {
146  fixedValueFvPatchVectorField::write(os);
147  os.writeEntry("refValue", refValue_);
148  os.writeEntry("amplitudes", amplitudes_);
149  os.writeEntry("frequencies", frequencies_);
150  os.writeEntry("phases", phases_);
151  os.writeEntry("component", component_);
152  os.writeEntry("endTime", endTime_);
153  //writeEntry("value", os);
154 }
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 namespace Foam
159 {
161  fvPatchVectorField,
163 }
164 
165 // ************************************************************************* //
Foam::multiFreqVectorFvPatchField::multiFreqVectorFvPatchField
multiFreqVectorFvPatchField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Definition: multiFreqVectorFvPatchField.C:36
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
multiFreqVectorFvPatchField.H
p
volScalarField & p
Definition: createRefsPimple.H:6
Foam::multiFreqVectorFvPatchField::write
virtual void write(Ostream &) const
Definition: multiFreqVectorFvPatchField.C:144
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, multiFreqScalarFvPatchField)
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::multiFreqVectorFvPatchField::updateCoeffs
virtual void updateCoeffs()
Definition: multiFreqVectorFvPatchField.C:116
Foam::multiFreqVectorFvPatchField
Definition: multiFreqVectorFvPatchField.H:85