Test-DataEntry.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 | Copyright (C) 2011-2015 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 Application
25  testDataEntry
26 
27 Description
28  Tests DataEntry
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "fvCFD.H"
33 #include "DataEntry.H"
34 #include "IOdictionary.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 int main(int argc, char *argv[])
41 {
42  #include "setRootCase.H"
43  #include "createTime.H"
44  #include "createMesh.H"
45 
46 {
48  samples[0] = 0;
49  samples[1] = 1;
50  samples[2] = 2;
51  samples[3] = 3;
52  scalarField values(4);
53  values = 1.0;
54  //values[0] = 0.0;
55  //values[1] = 1.0;
56 
57  //linearInterpolationWeights interpolator
58  splineInterpolationWeights interpolator
59  (
60  samples
61  );
62  labelList indices;
63  scalarField weights;
64 
65  interpolator.integrationWeights(1.1, 1.2, indices, weights);
66  Pout<< "indices:" << indices << endl;
67  Pout<< "weights:" << weights << endl;
68 
69  scalar baseSum = interpolator.weightedSum
70  (
71  weights,
72  UIndirectList<scalar>(values, indices)
73  );
74  Pout<< "baseSum=" << baseSum << nl << nl << endl;
75 
76 
77 // interpolator.integrationWeights(-0.01, 0, indices, weights);
78 // scalar partialSum = interpolator.weightedSum
79 // (
80 // weights,
81 // UIndirectList<scalar>(values, indices)
82 // );
83 // Pout<< "partialSum=" << partialSum << nl << nl << endl;
84 //
85 //
86 // interpolator.integrationWeights(-0.01, 1, indices, weights);
87 // //Pout<< "samples:" << samples << endl;
88 // //Pout<< "indices:" << indices << endl;
89 // //Pout<< "weights:" << weights << endl;
90 // scalar sum = interpolator.weightedSum
91 // (
92 // weights,
93 // UIndirectList<scalar>(values, indices)
94 // );
95 // Pout<< "integrand=" << sum << nl << nl << endl;
96 
97 
98  return 1;
99 }
100 
101  IOdictionary dataEntryProperties
102  (
103  IOobject
104  (
105  "dataEntryProperties",
106  runTime.constant(),
107  mesh,
108  IOobject::MUST_READ_IF_MODIFIED,
109  IOobject::NO_WRITE
110  )
111  );
112 
113  autoPtr<DataEntry<scalar> > dataEntry
114  (
116  (
117  "dataEntry",
118  dataEntryProperties
119  )
120  );
121 
122  scalar x0 = readScalar(dataEntryProperties.lookup("x0"));
123  scalar x1 = readScalar(dataEntryProperties.lookup("x1"));
124 
125  Info<< "Data entry type: " << dataEntry().type() << nl << endl;
126 
127  Info<< "Inputs" << nl
128  << " x0 = " << x0 << nl
129  << " x1 = " << x1 << nl
130  << endl;
131 
132  Info<< "Interpolation" << nl
133  << " f(x0) = " << dataEntry().value(x0) << nl
134  << " f(x1) = " << dataEntry().value(x1) << nl
135  << endl;
136 
137  Info<< "Integration" << nl
138  << " int(f(x)) lim(x0->x1) = " << dataEntry().integrate(x0, x1) << nl
139  << endl;
140 
141  return 0;
142 }
143 
144 
145 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::splineInterpolationWeights::integrationWeights
virtual bool integrationWeights(const scalar t1, const scalar t2, labelList &indices, scalarField &weights) const
Calculate weights and indices to calculate integrand of t1..t2.
Definition: splineInterpolationWeights.H:95
splineInterpolationWeights.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::interpolationWeights::weightedSum
static outerProduct< typename ListType1::value_type, typename ListType2::value_type >::type weightedSum(const ListType1 &f1, const ListType2 &f2)
Helper: weighted sum.
linearInterpolationWeights.H
samples
scalarField samples(nIntervals, 0)
DataEntry.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
main
int main(int argc, char *argv[])
Definition: Test-DataEntry.C:37
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
readScalar
#define readScalar
Definition: doubleScalar.C:38
IOdictionary.H
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
setRootCase.H
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
createMesh.H
createTime.H
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
fvCFD.H
Foam::DataEntry
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
Foam::splineInterpolationWeights
Catmull-Rom spline interpolation.
Definition: splineInterpolationWeights.H:48