MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Nernst.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2007 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include "header.h"
11 #include "Nernst.h"
12 
13 const double Nernst::R_OVER_F = 8.6171458e-5;
14 const double Nernst::ZERO_CELSIUS = 273.15;
15 
17  // MsgSrc definitions
20  static SrcFinfo1< double > Eout( "Eout",
21  "Computed reversal potential"
22  );
23  return &Eout;
24 }
25 
27 {
29  "Computed reversal potential",
31  );
32  static ValueFinfo< Nernst, double > temperature( "Temperature",
33  "Temperature of cell",
36  );
37  static ValueFinfo< Nernst, int > valence( "valence",
38  "Valence of ion in Nernst calculation",
41  );
42  static ValueFinfo< Nernst, double > Cin( "Cin",
43  "Internal conc of ion",
46  );
47  static ValueFinfo< Nernst, double > Cout( "Cout",
48  "External conc of ion",
51  );
52  static ValueFinfo< Nernst, double > scale( "scale",
53  "Voltage scale factor",
56  );
58  // Shared definitions
60 
61 
63  // MsgDest definitions
64  // These differ from field assignments because they trigger an
65  // outgoing msg with the updated E.
67  static DestFinfo ci( "ci",
68  "Set internal conc of ion, and immediately send out the updated E",
70  );
71  static DestFinfo co( "co",
72  "Set external conc of ion, and immediately send out the updated E",
74  );
75 
77  // Field definitions
79  static Finfo* NernstFinfos[] =
80  {
81  Eout(), // SrcFinfo
82  &E, // ReadOnlyValue
83  &temperature, // Value
84  &valence, // Value
85  &Cin, // Value
86  &Cout, // Value
87  &scale, // Value
88  &ci, // Dest
89  &co, // Dest
90  };
91 
92  static string doc[] =
93  {
94  "Name", "Nernst",
95  "Author", "Upinder S. Bhalla, 2007, NCBS",
96  "Description", "Nernst: Calculates Nernst potential for a given ion based on "
97  "Cin and Cout, the inside and outside concentrations. "
98  "Immediately sends out the potential to all targets.",
99  };
100 
101  static Dinfo< Nernst > dinfo;
102  static const Cinfo NernstCinfo(
103  "Nernst",
105  NernstFinfos,
106  sizeof( NernstFinfos ) / sizeof(Finfo *),
107  &dinfo,
108  doc,
109  sizeof( doc ) / sizeof( string )
110  );
111 
112  return &NernstCinfo;
113 }
114 
117 
119  :
120  E_( 0.0 ),
121  Temperature_( 295 ),
122  valence_( 1 ),
123  Cin_( 1.0 ),
124  Cout_( 1.0 ),
125  scale_( 1.0 ),
126  factor_( scale_ * R_OVER_F * Temperature_ / valence_ )
127 {;}
129 // Field function definitions
131 
132 double Nernst::getE() const
133 {
134  return E_;
135 }
136 
138  if ( value > 0.0 ) {
141  }
142  updateE();
143 }
144 
146 {
147  return Temperature_;
148 }
149 
151  if ( value != 0 ) {
152  valence_ = value;
153  }
155  updateE();
156 }
157 
159 {
160  return valence_;
161 }
162 
163 void Nernst::setCin( double value )
164 {
165  Cin_ = value;
166  updateE();
167 }
168 double Nernst::getCin() const
169 {
170  return Cin_;
171 }
172 
173 void Nernst::setCout( double value ) {
174  Cout_ = value;
175  updateE();
176 }
177 double Nernst::getCout() const
178 {
179  return Cout_;
180 }
181 
182 void Nernst::setScale( double value ) {
183  scale_ = value;
185  updateE();
186 }
187 double Nernst::getScale() const
188 {
189  return scale_;
190 }
191 
193 // Dest function definitions
195 
197 {
198  E_ = factor_ * log( Cout_ / Cin_ );
199 }
200 
201 void Nernst::handleCin( const Eref& er, double conc )
202 {
203  Cin_ = conc;
204  updateE();
205  Eout()->send( er, E_ );
206 }
207 
208 void Nernst::handleCout( const Eref& er, double conc )
209 {
210  Cout_ = conc;
211  updateE();
212  Eout()->send( er, E_ );
213 }
214 
216 // Unit tests
218 
219 #ifdef DO_UNIT_TESTS
220 void testNernst()
221 {
222  Nernst ne;
223  ne.setValence( 1 );
224  ne.setCin( 0.01 );
225  ne.setCout( 1.0 );
226  double E = ne.getE();
227  assert( doubleApprox( E, 0.0585 * 2.0 ) );
228 
229  cout << "." << flush;
230 }
231 #endif
double getCin() const
Definition: Nernst.cpp:168
void setTemperature(double value)
Definition: Nernst.cpp:137
uint32_t value
Definition: moosemodule.h:42
static const Cinfo * nernstCinfo
Definition: Nernst.cpp:116
Definition: Nernst.h:16
Definition: Dinfo.h:60
Definition: EpFunc.h:64
void setCout(double value)
Definition: Nernst.cpp:173
void setScale(double value)
Definition: Nernst.cpp:182
double Cout_
Definition: Nernst.h:55
int valence_
Definition: Nernst.h:53
Nernst()
Definition: Nernst.cpp:118
double Temperature_
Definition: Nernst.h:52
double getE() const
Definition: Nernst.cpp:132
void setValence(int value)
Definition: Nernst.cpp:150
void log(string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
Log to console (and to a log-file)
void setCin(double value)
Definition: Nernst.cpp:163
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
double factor_
Definition: Nernst.h:57
void handleCout(const Eref &e, double conc)
Definition: Nernst.cpp:208
static SrcFinfo1< double > * Eout()
Definition: Nernst.cpp:19
double getTemperature() const
Definition: Nernst.cpp:145
double E_
Definition: Nernst.h:51
Definition: Eref.h:26
double getCout() const
Definition: Nernst.cpp:177
double Cin_
Definition: Nernst.h:54
static const Cinfo * initCinfo()
Definition: Nernst.cpp:26
static const double R_OVER_F
Definition: Nernst.h:58
double scale_
Definition: Nernst.h:56
static const double ZERO_CELSIUS
Definition: Nernst.h:59
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
double getScale() const
Definition: Nernst.cpp:187
int getValence() const
Definition: Nernst.cpp:158
void handleCin(const Eref &e, double conc)
Definition: Nernst.cpp:201
Definition: Cinfo.h:18
void updateE()
Definition: Nernst.cpp:196
Definition: Finfo.h:12