MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Interpol.cpp
Go to the documentation of this file.
1 // Interpol.cpp ---
2 //
3 // Filename: Interpol.cpp
4 // Description:
5 // Author: Subhasis Ray
6 // Maintainer:
7 // Created: Wed Jun 25 15:25:24 2014 (+0530)
8 // Version:
9 // Last-Updated:
10 // By:
11 // Update #: 0
12 // URL:
13 // Keywords:
14 // Compatibility:
15 //
16 //
17 
18 // Commentary:
19 //
20 //
21 //
22 //
23 
24 // Change log:
25 //
26 //
27 //
28 //
29 // This program is free software; you can redistribute it and/or
30 // modify it under the terms of the GNU General Public License as
31 // published by the Free Software Foundation; either version 3, or
32 // (at your option) any later version.
33 //
34 // This program is distributed in the hope that it will be useful,
35 // but WITHOUT ANY WARRANTY; without even the implied warranty of
36 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 // General Public License for more details.
38 //
39 // You should have received a copy of the GNU General Public License
40 // along with this program; see the file COPYING. If not, write to
41 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 // Floor, Boston, MA 02110-1301, USA.
43 //
44 //
45 
46 //
47 
48 #include "header.h"
49 #include "../utility/numutil.h"
50 #include "TableBase.h"
51 #include "Interpol.h"
52 
53 
55 {
56  static SrcFinfo1< double > lookupOut( "lookupOut",
57  "respond to a request for a value lookup" );
58  return &lookupOut;
59 }
60 
62 {
64  // Field Definitions
67  "xmin",
68  "Minimum value of x. x below this will result in y[0] being returned.",
71  );
73  "xmax",
74  "Maximum value of x. x above this will result in y[last] being"
75  " returned.",
78 
80  "y",
81  "Looked up value.",
84  // MsgDest Definitions
86 
87  static DestFinfo input( "input",
88  "Interpolates using the input as x value.",
90 
91  static DestFinfo process( "process",
92  "Handles process call, updates internal time stamp.",
94  static DestFinfo reinit( "reinit",
95  "Handles reinit call.",
98  // SharedMsg Definitions
100  static Finfo* procShared[] = {
101  &process, &reinit
102  };
103  static SharedFinfo proc( "proc",
104  "Shared message for process and reinit",
105  procShared, sizeof( procShared ) / sizeof( const Finfo* )
106  );
107 
109  // Field Element for the vector data
110  // Use a limit of 2^20 entries for the tables, about 1 million.
112 
113  static Finfo* interpolFinfos[] = {
114  &xmin, // Value
115  &xmax, // Value
116  &y,
117  // &xdivs, // Value
118  lookupOut(),
119  &input, // DestFinfo
120  &proc, // SharedFinfo
121  };
122 
123  static string doc[] =
124  {
125  "Name", "Interpol",
126  "Author", "Upinder Bhalla, Subhasis Ray, 2014, NCBS",
127  "Description", "Interpol: Interpolation class. "
128  "Handles lookup from a 1-dimensional array of real-numbered values."
129  "Returns 'y' value based on given 'x' value. "
130  "Can either use interpolation or roundoff to the nearest index.",
131  };
132 
133  static Dinfo< Interpol > dinfo;
134  static Cinfo interpolCinfo (
135  "Interpol",
137  interpolFinfos,
138  sizeof( interpolFinfos ) / sizeof ( Finfo* ),
139  &dinfo,
140  doc,
141  sizeof(doc) / sizeof(string));
142 
143  return &interpolCinfo;
144 }
145 
147 
148 Interpol::Interpol(): xmin_(0.0), xmax_(1.0)
149 {
150 }
151 
152 Interpol::Interpol(double xmin, double xmax)
153  : xmin_(xmin),
154  xmax_(xmax)
155 {}
156 
158 {
159  if (almostEqual(value, xmax_)){
160  cerr << "Error: Interpol::setXmin: Xmin ~= Xmax : Assignment failed\n";
161  return;
162  }
163  xmin_ = value;
164 }
165 
166 double Interpol::getXmin() const
167 {
168  return xmin_;
169 }
170 
172 {
173  if (almostEqual(value, xmin_)){
174  cerr << "Error: Interpol::setXmax: Xmin ~= Xmax : Assignment failed\n";
175  return;
176  }
177  xmax_ = value;
178 }
179 
180 double Interpol::getXmax() const
181 {
182  return xmax_;
183 }
184 
185 double Interpol::getY() const
186 {
187  return y_;
188 }
189 
191 // MsgDest Definitions
193 
194 void Interpol::process( const Eref& e, ProcPtr p )
195 {
196  y_ = interpolate(xmin_, xmax_, x_);
197  lookupOut()->send( e, y_ );
198 }
199 
200 void Interpol::reinit( const Eref& e, ProcPtr p )
201 {
202  x_ = 0.0;
203 }
204 
206 // Used to handle direct messages into the interpol, or
207 // returned plot data from queried objects.
209 void Interpol::handleInput( double v )
210 {
211  x_ = v;
212 }
213 
214 //
215 // Interpol.cpp ends here
uint32_t value
Definition: moosemodule.h:42
static const Cinfo * interpolCinfo
Definition: Interpol.cpp:146
bool almostEqual(float x, float y, float epsilon)
Definition: numutil.cpp:27
void setXmin(double value)
Definition: Interpol.cpp:157
Definition: Dinfo.h:60
double xmin_
Definition: Interpol.h:82
double interpolate(double x, double xmin, double xmax) const
Definition: TableBase.cpp:440
void handleInput(double x)
Definition: Interpol.cpp:209
void process(const Eref &e, ProcPtr p)
Definition: Interpol.cpp:194
static SrcFinfo1< double > * lookupOut()
Definition: Interpol.cpp:54
void reinit(const Eref &e, ProcPtr p)
Definition: Interpol.cpp:200
static const Cinfo * initCinfo()
Definition: TableBase.cpp:15
double xmax_
Definition: Interpol.h:83
Definition: OpFunc.h:27
Definition: Eref.h:26
static const Cinfo * initCinfo()
Definition: Interpol.cpp:61
void setXmax(double value)
Definition: Interpol.cpp:171
double x_
Definition: Interpol.h:81
double getXmin() const
Definition: Interpol.cpp:166
double y_
Definition: Interpol.h:84
double getY() const
Definition: Interpol.cpp:185
Definition: Cinfo.h:18
double getXmax() const
Definition: Interpol.cpp:180
Definition: Finfo.h:12