MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
EndoMesh.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 #include "SparseMatrix.h"
12 #include "ElementValueFinfo.h"
13 #include "../utility/Vec.h"
14 #include "Boundary.h"
15 #include "MeshEntry.h"
16 // #include "Stencil.h"
17 #include "ChemCompt.h"
18 #include "MeshCompt.h"
19 #include "CubeMesh.h"
20 #include "CylBase.h"
21 #include "NeuroNode.h"
22 // #include "NeuroStencil.h"
23 #include "NeuroMesh.h"
24 #include "EndoMesh.h"
25 #include "../utility/numutil.h"
27 {
29  // Field Definitions
32  "rPower",
33  "Used in rEndo = rScale * pow(surroundVol, rPower)."
34  "Used to obtain radius of each endo voxel from matching "
35  "surround voxel. Defaults to 1/3",
38  );
40  "rScale",
41  "Used in rEndo = rScale * pow(surroundVol, rPower)."
42  "Used to obtain radius of each endo voxel from matching "
43  "surround voxel. Defaults to 0.5",
46  );
48  "aPower",
49  "Used in rEndo = aScale * pow(surroundVol, aPower)."
50  "Used to obtain area of each endo voxel from matching "
51  "surround voxel. Defaults to 1/2",
54  );
56  "aScale",
57  "Used in rEndo = aScale * pow(surroundVol, aPower)."
58  "Used to obtain area of each endo voxel from matching "
59  "surround voxel. Defaults to 0.25",
62  );
64  "vPower",
65  "Used in rEndo = vScale * pow(surroundVol, vPower)."
66  "Used to obtain volume of each endo voxel from matching "
67  "surround voxel. Defaults to 1.",
70  );
72  "vScale",
73  "Used in rEndo = vScale * pow(surroundVol, vPower)."
74  "Used to obtain volume of each endo voxel from matching "
75  "surround voxel. Defaults to 0.125",
78  );
79 
81  "surround",
82  "ObjId of compartment surrounding current EndoMesh",
85  );
86 
87  static ElementValueFinfo< EndoMesh, bool > doAxialDiffusion(
88  "doAxialDiffusion",
89  "Flag to determine if endoMesh should undertake axial "
90  "diffusion. Defaults to 'false'. "
91  "Should only be used within NeuroMesh and CylMesh. "
92  "Must be assigned before Dsolver is built.",
95  );
96 
97 
99  // MsgDest Definitions
101 
103  // Field Elements
105 
106  static Finfo* endoMeshFinfos[] = {
107  &rPower, // Value
108  &rScale, // Value
109  &aPower, // Value
110  &aScale, // Value
111  &vPower, // Value
112  &vScale, // Value
113  &surround, // Value
114  &doAxialDiffusion, // Value
115  };
116 
117  static Dinfo< EndoMesh > dinfo;
118  static Cinfo endoMeshCinfo (
119  "EndoMesh",
121  endoMeshFinfos,
122  sizeof( endoMeshFinfos ) / sizeof ( Finfo* ),
123  &dinfo
124  );
125 
126  return &endoMeshCinfo;
127 }
128 
130 // Basic class Definitions
132 
134 
136 // Class stuff.
139  :
140  parent_( 0 ),
141  rPower_( 1.0 / 3.0 ),
142  rScale_( 0.5 ),
143  aPower_( 0.5 ),
144  aScale_( 0.25 ),
145  vPower_( 1.0 ),
146  vScale_( 0.125 ),
147  doAxialDiffusion_( false )
148 {
149  ;
150 }
151 
153 {
154  ;
155 }
156 
158 // Field assignment stuff
160 //
161 void EndoMesh::setRpower( const Eref& e, double v )
162 {
163  rPower_ = v;
164 }
165 
166 double EndoMesh::getRpower( const Eref& e ) const
167 {
168  return rPower_;
169 }
170 
171 void EndoMesh::setRscale( const Eref& e, double v )
172 {
173  rScale_ = v;
174 }
175 
176 double EndoMesh::getRscale( const Eref& e ) const
177 {
178  return rScale_;
179 }
180 
181 void EndoMesh::setApower( const Eref& e, double v )
182 {
183  aPower_ = v;
184 }
185 
186 double EndoMesh::getApower( const Eref& e ) const
187 {
188  return aPower_;
189 }
190 
191 void EndoMesh::setAscale( const Eref& e, double v )
192 {
193  aScale_ = v;
194 }
195 
196 double EndoMesh::getAscale( const Eref& e ) const
197 {
198  return aScale_;
199 }
200 
201 void EndoMesh::setVpower( const Eref& e, double v )
202 {
203  vPower_ = v;
204 }
205 
206 double EndoMesh::getVpower( const Eref& e ) const
207 {
208  return vPower_;
209 }
210 
211 void EndoMesh::setVscale( const Eref& e, double v )
212 {
213  vScale_ = v;
214 }
215 
216 double EndoMesh::getVscale( const Eref& e ) const
217 {
218  return vScale_;
219 }
220 
221 void EndoMesh::setSurround( const Eref& e, ObjId v )
222 {
223  if ( !v.element()->cinfo()->isA( "ChemCompt" ) ) {
224  cout << "Warning: 'surround' may only be set to an object of class 'ChemCompt'\n";
225  cout << v.path() << " is of class " << v.element()->cinfo()->name() << endl;
226  return;
227  }
228  surround_ = v;
229  parent_ = reinterpret_cast< const MeshCompt* >( v.data() );
230 }
231 
233 {
234  return surround_;
235 }
236 
237 void EndoMesh::setDoAxialDiffusion( const Eref& e, bool v )
238 {
239  doAxialDiffusion_ = v;
240 }
241 
242 bool EndoMesh::getDoAxialDiffusion( const Eref& e ) const
243 {
244  return doAxialDiffusion_;
245 }
246 
248 // FieldElement assignment stuff for MeshEntries
250 
252 unsigned int EndoMesh::getMeshType( unsigned int fid ) const
253 {
254  return ENDO;
255 }
256 
258 unsigned int EndoMesh::getMeshDimensions( unsigned int fid ) const
259 {
260  return 3;
261 }
262 
264 unsigned int EndoMesh::innerGetDimensions() const
265 {
266  return 1;
267 }
269 double EndoMesh::getMeshEntryVolume( unsigned int fid ) const
270 {
271  double vpa = parent_->getMeshEntryVolume( fid );
272  return vScale_ * pow( vpa, vPower_ );
273 }
274 
277 vector< double > EndoMesh::getCoordinates( unsigned int fid ) const
278 {
279  vector< double > temp = parent_->getCoordinates( fid );
280  vector< double > ret;
281  if ( temp.size() > 6 ) {
282  ret.resize( 4 );
283  ret[0] = 0.5 * (temp[0] + temp[3] );
284  ret[1] = 0.5 * (temp[1] + temp[4] );
285  ret[2] = 0.5 * (temp[2] + temp[5] );
286  ret[3] = 0;
287  }
288  return ret;
289 }
290 
293 vector< double > EndoMesh::getDiffusionArea( unsigned int fid ) const
294 {
295  return vector< double >( parent_->getNumEntries(), 0.0 );
296 }
297 
300 vector< double > EndoMesh::getDiffusionScaling( unsigned int fid ) const
301 {
302  return vector< double >( parent_->getNumEntries(), 0.0 );
303 }
304 
307 double EndoMesh::extendedMeshEntryVolume( unsigned int fid ) const
308 {
309  double vpa = parent_->extendedMeshEntryVolume( fid );
310  return vScale_ * pow( vpa, vPower_ );
311 }
312 
314 // Dest funcs
316 
319  const SrcFinfo2< unsigned int, vector< double > >* meshStatsFinfo
320  )
321 {
322  vector< double > ret( vGetEntireVolume() / parent_->getNumEntries(), 1);
323  meshStatsFinfo->send( e, 1, ret );
324 }
325 
327  const Eref& e,
328  unsigned int numNodes, unsigned int numThreads )
329 {
330 }
332 
336 unsigned int EndoMesh::innerGetNumEntries() const
337 {
338  return parent_->innerGetNumEntries();
339 }
340 
345 void EndoMesh::innerSetNumEntries( unsigned int n )
346 {
347 }
348 
349 
351  double volume, unsigned int numEntries )
352 {
353 }
354 
361 vector< unsigned int > EndoMesh::getParentVoxel() const
362 {
363  if ( doAxialDiffusion_ )
364  return parent_->getParentVoxel();
365 
366  vector< unsigned int > ret( parent_->innerGetNumEntries(), -1U );
367  return ret;
368 }
369 
370 const vector< double >& EndoMesh::vGetVoxelVolume() const
371 {
372  static vector< double > ret;
373  ret = parent_->vGetVoxelVolume();
374  for ( auto i = ret.begin(); i != ret.end(); ++i )
375  *i = vScale_ * pow( *i, vPower_ );
376  return ret;
377 }
378 
379 const vector< double >& EndoMesh::vGetVoxelMidpoint() const
380 {
381  return parent_->vGetVoxelMidpoint();
382 }
383 
384 const vector< double >& EndoMesh::getVoxelArea() const
385 {
386  static vector< double > ret;
387  ret = parent_->vGetVoxelVolume();
388  for ( auto i = ret.begin(); i != ret.end(); ++i )
389  *i = aScale_ * pow( *i, aPower_ );
390  return ret;
391 }
392 
393 const vector< double >& EndoMesh::getVoxelLength() const
394 {
395  static vector< double > ret;
396  ret = parent_->vGetVoxelVolume();
397  for ( auto i = ret.begin(); i != ret.end(); ++i )
398  *i = vScale_ * pow( *i, vPower_ );
399  return ret;
400 }
401 
403 {
404  double vol = 0.0;
405  auto vec = vGetVoxelVolume();
406  for ( auto i = vec.begin(); i != vec.end(); ++i )
407  vol += *i;
408  return vol;
409 }
410 
411 bool EndoMesh::vSetVolumeNotRates( double volume )
412 {
413  return true; // maybe should be false? Unsure
414 }
415 
417 // Utility function for junctions
419 
421  vector< VoxelJunction >& ret ) const
422 {
431  vector< double > vol = other->vGetVoxelVolume();
432  const MeshCompt* mc = static_cast< const MeshCompt* >( other );
433  vector< double > len = mc->getVoxelLength();
434  assert( vol.size() == len.size() );
435  ret.resize( vol.size() );
436  vector< double > myVol = vGetVoxelVolume();
437  assert( myVol.size() == vol.size() );
438  vector< double > myArea = getVoxelArea();
439  assert( myArea.size() == vol.size() );
440 
441  for ( unsigned int i = 0; i < vol.size(); ++i ) {
442  double rSurround = sqrt( vol[i] / (len[i] * PI ) );
443  ret[i].first = ret[i].second = i;
444  ret[i].firstVol = myVol[i];
445  ret[i].secondVol = vol[i];
446 
447  // For now we don't consider internal EndoMeshes.
448  ret[i].diffScale = 2.0 * myArea[i] / rSurround;
449  }
450 }
451 
452 // This function returns the index.
453 double EndoMesh::nearest( double x, double y, double z,
454  unsigned int& index ) const
455 {
456  return parent_->nearest( x, y, z, index );
457 }
458 
459 // This function returns the index.
460 void EndoMesh::indexToSpace( unsigned int index,
461  double &x, double &y, double &z ) const
462 {
463  parent_->indexToSpace( index, x, y, z );
464 }
static const Cinfo * initCinfo()
Definition: ChemCompt.cpp:25
virtual double nearest(double x, double y, double z, unsigned int &index) const =0
char * data() const
Definition: ObjId.cpp:113
unsigned int getMeshDimensions(unsigned int fid) const
Virtual function to return dimensions of specified entry.
Definition: EndoMesh.cpp:258
const MeshCompt * parent_
Definition: EndoMesh.h:131
const vector< double > & getVoxelArea() const
Definition: EndoMesh.cpp:384
void setRpower(const Eref &e, double v)
Definition: EndoMesh.cpp:161
double getRpower(const Eref &e) const
Definition: EndoMesh.cpp:166
Definition: Dinfo.h:60
vector< double > getDiffusionArea(unsigned int fid) const
Virtual function to return diffusion X-section area.
Definition: EndoMesh.cpp:293
unsigned int innerGetNumEntries() const
Definition: EndoMesh.cpp:336
void indexToSpace(unsigned int index, double &x, double &y, double &z) const
Definition: EndoMesh.cpp:460
double extendedMeshEntryVolume(unsigned int fid) const
Virtual function to return volume of mesh Entry, including.
Definition: MeshCompt.cpp:36
bool vSetVolumeNotRates(double volume)
Inherited virtual. Resizes len and dia of each voxel.
Definition: EndoMesh.cpp:411
Definition: ObjId.h:20
bool doAxialDiffusion_
vEndo = vScale * pow( surroundVol, vPower_)
Definition: EndoMesh.h:147
void innerHandleRequestMeshStats(const Eref &e, const SrcFinfo2< unsigned int, vector< double > > *meshStatsFinfo)
More inherited virtual funcs: request comes in for mesh stats.
Definition: EndoMesh.cpp:318
const int numEntries
Definition: proc.cpp:60
double getMeshEntryVolume(unsigned int fid) const
Virtual function to return volume of mesh Entry.
Definition: EndoMesh.cpp:269
Definition: MeshEntry.h:22
double aPower_
rEndo = rScale * pow( surroundVol, rPower_)
Definition: EndoMesh.h:142
virtual vector< double > getCoordinates(unsigned int fid) const =0
Virtual function to return coords of mesh Entry.
void innerSetNumEntries(unsigned int n)
Inherited virtual func.
Definition: EndoMesh.cpp:345
virtual vector< unsigned int > getParentVoxel() const =0
void setApower(const Eref &e, double v)
Definition: EndoMesh.cpp:181
double vScale_
vEndo = vScale * pow( surroundVol, vPower_)
Definition: EndoMesh.h:145
double getAscale(const Eref &e) const
Definition: EndoMesh.cpp:196
double getVscale(const Eref &e) const
Definition: EndoMesh.cpp:216
unsigned int getNumEntries() const
Definition: ChemCompt.cpp:390
void innerHandleNodeInfo(const Eref &e, unsigned int numNodes, unsigned int numThreads)
Definition: EndoMesh.cpp:326
const std::string & name() const
Definition: Cinfo.cpp:260
static const Cinfo * initCinfo()
Definition: EndoMesh.cpp:26
double getVpower(const Eref &e) const
Definition: EndoMesh.cpp:206
double rPower_
EndoMeshes inside. Used to update.
Definition: EndoMesh.h:140
double getRscale(const Eref &e) const
Definition: EndoMesh.cpp:176
void setVpower(const Eref &e, double v)
Definition: EndoMesh.cpp:201
virtual const vector< double > & vGetVoxelVolume() const =0
Virtual func so that derived classes can pass voxel volume back.
string path() const
Definition: ObjId.cpp:119
void innerBuildDefaultMesh(const Eref &e, double volume, unsigned int numEntries)
Virtual func to make a mesh with specified Volume and numEntries.
Definition: EndoMesh.cpp:350
virtual unsigned int innerGetNumEntries() const =0
const vector< double > & vGetVoxelMidpoint() const
Virtual func so that derived classes can return voxel midpoint.
Definition: EndoMesh.cpp:379
double getApower(const Eref &e) const
Definition: EndoMesh.cpp:186
vector< unsigned int > getParentVoxel() const
Inherited virtual, do nothing for now.
Definition: EndoMesh.cpp:361
virtual void indexToSpace(unsigned int index, double &x, double &y, double &z) const =0
const vector< double > & vGetVoxelVolume() const
Virtual func so that derived classes can pass voxel volume back.
Definition: EndoMesh.cpp:370
double vPower_
aEndo = aScale * pow( surroundVol, aPower_)
Definition: EndoMesh.h:144
Definition: Eref.h:26
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
const Cinfo * cinfo() const
Definition: Element.cpp:66
ObjId getSurround(const Eref &e) const
Definition: EndoMesh.cpp:232
void setDoAxialDiffusion(const Eref &e, bool v)
Definition: EndoMesh.cpp:237
unsigned int getMeshType(unsigned int fid) const
Virtual function to return MeshType of specified entry.
Definition: EndoMesh.cpp:252
void setAscale(const Eref &e, double v)
Definition: EndoMesh.cpp:191
void setRscale(const Eref &e, double v)
Definition: EndoMesh.cpp:171
double nearest(double x, double y, double z, unsigned int &index) const
Definition: EndoMesh.cpp:453
Element * element() const
Definition: ObjId.cpp:124
ObjId surround_
Definition: EndoMesh.h:130
static unsigned int numNodes
virtual const vector< double > & getVoxelLength() const =0
vector< double > getCoordinates(unsigned int fid) const
Virtual function to return coords of mesh Entry.
Definition: EndoMesh.cpp:277
double aScale_
aEndo = aScale * pow( surroundVol, aPower_)
Definition: EndoMesh.h:143
const double PI
Definition: consts.cpp:12
double extendedMeshEntryVolume(unsigned int fid) const
Volume of mesh Entry including abutting diff-coupled voxels.
Definition: EndoMesh.cpp:307
virtual const vector< double > & vGetVoxelMidpoint() const =0
Virtual func so that derived classes can return voxel midpoint.
unsigned int innerGetDimensions() const
Virtual function to return # of spatial dimensions of mesh.
Definition: EndoMesh.cpp:264
bool getDoAxialDiffusion(const Eref &e) const
Definition: EndoMesh.cpp:242
double vGetEntireVolume() const
Inherited virtual. Returns entire volume of compartment.
Definition: EndoMesh.cpp:402
virtual double getMeshEntryVolume(unsigned int fid) const =0
Virtual function to return volume of mesh Entry.
static const Cinfo * endoMeshCinfo
Definition: EndoMesh.cpp:133
void setSurround(const Eref &e, ObjId v)
Definition: EndoMesh.cpp:221
void matchMeshEntries(const ChemCompt *other, vector< VoxelJunction > &ret) const
Definition: EndoMesh.cpp:420
const vector< double > & getVoxelLength() const
Definition: EndoMesh.cpp:393
vector< double > getDiffusionScaling(unsigned int fid) const
Virtual function to return scale factor for diffusion. 1 here.
Definition: EndoMesh.cpp:300
double rScale_
rEndo = rScale * pow( surroundVol, rPower_)
Definition: EndoMesh.h:141
Definition: Cinfo.h:18
void setVscale(const Eref &e, double v)
Definition: EndoMesh.cpp:211
Definition: Finfo.h:12