MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DiffPoolVec.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-2014 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 #include <algorithm>
10 #include <vector>
11 #include <map>
12 #include <cassert>
13 #include <string>
14 #include <iostream>
15 using namespace std;
16 
17 #include "SparseMatrix.h"
18 #include "DiffPoolVec.h"
19 
26  : id_( 0 ), n_( 1, 0.0 ), nInit_( 1, 0.0 ),
27  diffConst_( 1.0e-12 ), motorConst_( 0.0 )
28 {
29  ;
30 }
31 
32 double DiffPoolVec::getNinit( unsigned int voxel ) const
33 {
34  assert( voxel < nInit_.size() );
35  return nInit_[ voxel ];
36 }
37 
38 void DiffPoolVec::setNinit( unsigned int voxel, double v )
39 {
40  assert( voxel < nInit_.size() );
41  nInit_[ voxel ] = v;
42 }
43 
44 double DiffPoolVec::getN( unsigned int voxel ) const
45 {
46  assert( voxel < n_.size() );
47  return n_[ voxel ];
48 }
49 
50 void DiffPoolVec::setN( unsigned int voxel, double v )
51 {
52  assert( voxel < n_.size() );
53  n_[ voxel ] = v;
54 }
55 
56 double DiffPoolVec::getPrev( unsigned int voxel ) const
57 {
58  assert( voxel < n_.size() );
59  return prev_[ voxel ];
60 }
61 
62 const vector< double >& DiffPoolVec::getNvec() const
63 {
64  return n_;
65 }
66 
67 void DiffPoolVec::setNvec( const vector< double >& vec )
68 {
69  assert( vec.size() == n_.size() );
70  n_ = vec;
71 }
72 
73 void DiffPoolVec::setNvec( unsigned int start, unsigned int num,
74  vector< double >::const_iterator q )
75 {
76  assert( start + num <= n_.size() );
77  vector< double >::iterator p = n_.begin() + start;
78  for ( unsigned int i = 0; i < num; ++i )
79  *p++ = *q++;
80 }
81 
83 {
84  prev_ = n_;
85 }
86 
88 {
89  return diffConst_;
90 }
91 
92 void DiffPoolVec::setDiffConst( double v )
93 {
94  diffConst_ = v;
95 }
96 
98 {
99  return motorConst_;
100 }
101 
103 {
104  motorConst_ = v;
105 }
106 
107 void DiffPoolVec::setNumVoxels( unsigned int num )
108 {
109  nInit_.resize( num, 0.0 );
110  n_.resize( num, 0.0 );
111 }
112 
113 unsigned int DiffPoolVec::getNumVoxels() const
114 {
115  return n_.size();
116 }
117 
118 void DiffPoolVec::setId( unsigned int id )
119 {
120  id_ = id;
121 }
122 
123 unsigned int DiffPoolVec::getId() const
124 {
125  return id_;
126 }
127 
128 void DiffPoolVec::setOps(const vector< Triplet< double > >& ops,
129  const vector< double >& diagVal )
130 {
131  if ( ops.size() > 0 )
132  {
133  assert( diagVal.size() == n_.size() );
134  ops_ = ops;
135  diagVal_ = diagVal;
136  }
137  else
138  {
139  ops_.clear();
140  diagVal_.clear();
141  }
142 }
143 
144 void DiffPoolVec::advance( double dt )
145 {
146  if ( ops_.size() == 0 ) return;
147  for ( vector< Triplet< double > >::const_iterator
148  i = ops_.begin(); i != ops_.end(); ++i )
149  n_[i->c_] -= n_[i->b_] * i->a_;
150 
151  assert( n_.size() == diagVal_.size() );
152  vector< double >::iterator iy = n_.begin();
153  for ( vector< double >::const_iterator
154  i = diagVal_.begin(); i != diagVal_.end(); ++i )
155  *iy++ *= *i;
156 }
157 
158 void DiffPoolVec::reinit() // Not called by the clock, but by parent.
159 {
160  assert( n_.size() == nInit_.size() );
161  prev_ = n_ = nInit_;
162 }
vector< double > prev_
Number of molecules of pool in each voxel.
Definition: DiffPoolVec.h:58
void setOps(const vector< Triplet< double > > &ops_, const vector< double > &diagVal_)
Assigns prev_ = n_.
const vector< double > & getNvec() const
Used by parent solver to manipulate 'n'.
Definition: DiffPoolVec.cpp:62
void setN(unsigned int vox, double value)
Definition: DiffPoolVec.cpp:50
unsigned int getNumVoxels() const
unsigned int getId() const
unsigned int id_
Assign operations.
Definition: DiffPoolVec.h:56
void setNvec(const vector< double > &n)
Used by parent solver to manipulate 'n'.
Definition: DiffPoolVec.cpp:67
void advance(double dt)
void setId(unsigned int id)
vector< double > n_
Integer conversion of Id of pool handled.
Definition: DiffPoolVec.h:57
double getDiffConst() const
Definition: DiffPoolVec.cpp:87
double getNinit(unsigned int vox) const
Definition: DiffPoolVec.cpp:32
vector< Triplet< double > > ops_
Motor const, ie, transport rate.
Definition: DiffPoolVec.h:62
void setNinit(unsigned int vox, double value)
Definition: DiffPoolVec.cpp:38
vector< double > diagVal_
Definition: DiffPoolVec.h:63
double diffConst_
Boundary condition: Initial 'n'.
Definition: DiffPoolVec.h:60
void setMotorConst(double value)
double motorConst_
Diffusion const, assumed uniform.
Definition: DiffPoolVec.h:61
void setNumVoxels(unsigned int num)
void setPrevVec()
Definition: DiffPoolVec.cpp:82
static char id[]
Definition: mfield.cpp:404
double getMotorConst() const
Definition: DiffPoolVec.cpp:97
void setDiffConst(double value)
Definition: DiffPoolVec.cpp:92
vector< double > nInit_
molecules of pool on previous timestep
Definition: DiffPoolVec.h:59
double getN(unsigned int vox) const
Definition: DiffPoolVec.cpp:44
double getPrev(unsigned int vox) const
Definition: DiffPoolVec.cpp:56