MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lookupVolumeFromMesh.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) 2011 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 /*
12 #include "../mesh/VoxelJunction.h"
13 #include "../mesh/MeshEntry.h"
14 #include "../mesh/Boundary.h"
15 #include "../mesh/ChemCompt.h"
16 */
17 #include "lookupVolumeFromMesh.h"
18 
19 // Utility function: return the compartment in which the specified
20 // object is located.
21 // Simply traverses the tree toward the root till it finds a
22 // compartment. Pools use a special msg, but this works for reacs too.
24 {
25  ObjId pa = Neutral::parent( id.eref() ).id;
26  if ( pa == ObjId() )
27  return pa;
28  else if ( pa.element()->cinfo()->isA( "ChemCompt" ) )
29  return pa;
30  return getCompt( pa );
31 }
32 
33 
36 double lookupVolumeFromMesh( const Eref& e )
37 {
38  ObjId compt = getCompt( e.id() );
39  if ( compt == ObjId() )
40  return 1.0;
42  get( compt, "oneVoxelVolume", e.dataIndex() );
43 }
44 
58 unsigned int getReactantVols( const Eref& reac, const SrcFinfo* pools,
59  vector< double >& vols )
60 {
61  static const unsigned int meshIndex = 0;
62 
63  const vector< MsgFuncBinding >* mfb =
64  reac.element()->getMsgAndFunc( pools->getBindIndex() );
65  unsigned int smallIndex = 0;
66 
67  vols.resize( 0 );
68  if ( mfb ) {
69  for ( unsigned int i = 0; i < mfb->size(); ++i ) {
70  double v = 1;
71  Element* pool = Msg::getMsg( (*mfb)[i].mid )->e2();
72  if ( pool == reac.element() )
73  pool = Msg::getMsg( (*mfb)[i].mid )->e1();
74  assert( pool != reac.element() );
75  Eref pooler( pool, meshIndex );
76  if ( pool->cinfo()->isA( "PoolBase" ) ) {
77  v = lookupVolumeFromMesh( pooler );
78  } else {
79  cout << "Error: getReactantVols: pool is of unknown type\n";
80  assert( 0 );
81  }
82  vols.push_back( v );
83  if ( v < vols[0] )
84  smallIndex = i;
85  }
86  }
87  return smallIndex;
88 }
89 
114 double convertConcToNumRateUsingMesh( const Eref& e, const SrcFinfo* pools,
115  bool doPartialConversion )
116 {
117  vector< double > vols;
118  // unsigned int smallest = getReactantVols( e, pools, vols );
119  double conv = 1.0;
120  getReactantVols( e, pools, vols );
121  if ( vols.size() == 0 ) { // Should this be an assertion?
122  // cout << "Warning: convertConcToNumRateUsingMesh: zero reactants on " << e.id().path() << endl;
123  return 1.0;
124  }
125  for ( unsigned int i = 0; i < vols.size(); ++i ) {
126  conv *= vols[i] * NA;
127  }
128  if ( !doPartialConversion ) {
129  if ( pools->name() == "subOut" ) {
130  conv /= vols[0] * NA;
131  } else {
132  const Finfo* f = e.element()->cinfo()->findFinfo( "subOut" );
133  assert( f );
134  const SrcFinfo* toSub = dynamic_cast< const SrcFinfo* >( f );
135  assert( toSub );
136  vector< double > subVols;
137  getReactantVols( e, toSub, subVols );
138  if ( subVols.size() == 0 ) // no substrates!
139  return 1.0;
140  conv /= subVols[0] * NA;
141  }
142  /*
143  Id compt = getCompt( e.id() );
144  if ( compt != Id() ) {
145  Id mesh( compt.value() + 1 );
146  double meshVol = Field< double >::get( mesh, "volume" );
147  conv /= meshVol * NA;
148  }
149  */
150  }
151  return conv;
152 }
153 
154 
160 double convertConcToNumRateUsingVol( const Eref& e, const SrcFinfo* pools,
161  double volume, double scale, bool doPartialConversion )
162 {
163  const vector< MsgFuncBinding >* mfb =
164  e.element()->getMsgAndFunc( pools->getBindIndex() );
165  double conversion = 1.0;
166  if ( mfb && mfb->size() > 0 ) {
167  if ( doPartialConversion || mfb->size() > 1 ) {
168  conversion = scale * NA * volume;
169  double power = doPartialConversion + mfb->size() - 1;
170  if ( power > 1.0 ) {
171  conversion = pow( conversion, power );
172  }
173  }
174  if ( conversion <= 0 )
175  conversion = 1.0;
176  }
177 
178  return conversion;
179 }
180 
187 double convertConcToNumRateInTwoCompts( double v1, unsigned int n1,
188  double v2, unsigned int n2, double scale )
189 {
190  double conversion = 1.0;
191 
192  for ( unsigned int i = 1; i < n1; ++i )
193  conversion *= scale * NA * v1;
194  for ( unsigned int i = 0; i < n2; ++i )
195  conversion *= scale * NA * v2;
196 
197  if ( conversion <= 0 )
198  conversion = 1.0;
199 
200  return conversion;
201 }
Id id() const
Definition: Eref.cpp:62
Element * e2() const
Definition: Msg.h:68
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
const double NA
Definition: consts.cpp:15
static A get(const ObjId &dest, const string &field, L index)
Definition: SetGet.h:532
BindIndex getBindIndex() const
Definition: SrcFinfo.cpp:28
Id id
Definition: ObjId.h:98
unsigned int dataIndex() const
Definition: Eref.h:50
Definition: ObjId.h:20
unsigned int getReactantVols(const Eref &reac, const SrcFinfo *pools, vector< double > &vols)
const string & name() const
Definition: Finfo.cpp:80
Element * element() const
Definition: Eref.h:42
double convertConcToNumRateUsingVol(const Eref &e, const SrcFinfo *pools, double volume, double scale, bool doPartialConversion)
Definition: Eref.h:26
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
double convertConcToNumRateInTwoCompts(double v1, unsigned int n1, double v2, unsigned int n2, double scale)
const vector< MsgFuncBinding > * getMsgAndFunc(BindIndex b) const
Definition: Element.cpp:300
const Cinfo * cinfo() const
Definition: Element.cpp:66
double convertConcToNumRateUsingMesh(const Eref &e, const SrcFinfo *pools, bool doPartialConversion)
Element * element() const
Definition: ObjId.cpp:124
ObjId getCompt(Id id)
Definition: Id.h:17
static const Msg * getMsg(ObjId m)
Definition: Msg.cpp:59
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
double lookupVolumeFromMesh(const Eref &e)
Definition: Finfo.h:12