Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_MembranePassive.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2011 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_MembranePassive.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, Electrical and Microsytem Modeling
33 //
34 // Creation Date : 08/11/2010
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.12 $
40 //
41 // Revision Date : $Date: 2014/01/23 16:19:04 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #include<iostream>
49 
50 // ---------- Standard Includes ----------
51 
52 #include <N_UTL_Misc.h>
53 
54 // ---------- Xyce Includes ----------
55 #include <N_DEV_MembranePassive.h>
56 #include <N_LAS_Vector.h>
57 #include <N_LAS_Matrix.h>
58 #include <N_DEV_SolverState.h>
59 
60 namespace Xyce {
61 namespace Device {
62 
63 //-----------------------------------------------------------------------------
64 // Function : MembranePassive::MembranePassive
65 // Purpose :
66 // Special Notes :
67 // Scope : public
68 // Creator : Richard Schiek, Electrical and Microsytem Modeling
69 // Creation Date : 08/11/2010
70 //-----------------------------------------------------------------------------
71 MembranePassive::MembranePassive(const SolverState & ss1, double cMem, double gMem, double vRest)
72  : MembraneModel(ss1),
73  gMem_(gMem),
74  cMem_(cMem),
75  vRest_(vRest)
76 {
77  // passive membrane just has voltage as its unknown variable
78  // so set up numIndependentVars_ for that
80 }
81 
82 //-----------------------------------------------------------------------------
83 // Function : MembranePassive::setJacStamp
84 // Purpose :
85 // Special Notes :
86 // Scope : public
87 // Creator : Richard Schiek, Electrical and Microsytem Modeling
88 // Creation Date : 08/11/2010
89 //-----------------------------------------------------------------------------
90 void MembranePassive::setJacStamp( int numExtVars, int segmentNumber, int vOffset, std::vector< std::vector< int > > & segmentJacStamp )
91 {
92  // In a passive cable the membrane is just two passive elements, a capacitor and a resistor
93  // thus the membrane current, I = f(Vsegment).
94 
95  /*
96  int offset = numExtVars + numIndependentVars_*segmentNumber;
97 
98  int jacobianRowSize = segmentJacStamp[offset].size();
99  */
100  /* need to handle these in a better way
101  currently they can confuse parameter testing when dummy devices are created.
102  if( jacobianRowSize == 1 )
103  {
104  if( segmentJacStamp[ offset ][0] != offset )
105  {
106  Xyce::dout() << "Potential error in MembranePassive::setJacStamp(). segmentJacStamp[ " << offset << " ][0] != " << offset << std::endl;
107  }
108  }
109  else if( jacobianRowSize > 1 )
110  {
111  if( segmentJacStamp[ offset ][1] != offset )
112  {
113  Xyce::dout() << "Potential error in MembranePassive::setJacStamp(). segmentJacStamp[ " << offset << " ][1] != " << offset << std::endl;
114  }
115  }
116  */
117 
118 }
119 
120 //-----------------------------------------------------------------------------
121 // Function : MembranePassive::loadDAEQVector
122 // Purpose :
123 // Special Notes :
124 // Scope : public
125 // Creator : Richard Schiek, Electrical and Microsytem Modeling
126 // Creation Date : 08/11/2010
127 //-----------------------------------------------------------------------------
128 void MembranePassive::loadDAEQVector( int segmentNumber, std::vector< int > & lidIndexVector, N_LAS_Vector * solnVecPtr, N_LAS_Vector * daeQVecPtr, double segArea)
129 {
130  // Each segment will have numIndependentVars_ with segment voltage being the first
131  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
132  // in the case of the passive cable numIndependentVars_=1.
133  (*daeQVecPtr)[lidIndexVector[segmentNumber]] += cMem_ * segArea * (*solnVecPtr)[lidIndexVector[segmentNumber]];
134 }
135 
136 //-----------------------------------------------------------------------------
137 // Function : MembranePassive::loadDAEFVector
138 // Purpose :
139 // Special Notes :
140 // Scope : public
141 // Creator : Richard Schiek, Electrical and Microsytem Modeling
142 // Creation Date : 08/11/2010
143 //-----------------------------------------------------------------------------
144 void MembranePassive::loadDAEFVector( int segmentNumber, std::vector< int > & lidIndexVector, N_LAS_Vector * solnVecPtr, N_LAS_Vector * daeFVecPtr, double segArea)
145 {
146  // Each segment will have numIndependentVars_ with segment voltage being the first
147  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
148  // in the case of the passive cable numIndependentVars_=1.
149  (*daeFVecPtr)[lidIndexVector[segmentNumber]] += gMem_ * segArea * ((*solnVecPtr)[lidIndexVector[segmentNumber]] - vRest_ );
150 }
151 
152 //-----------------------------------------------------------------------------
153 // Function : MembranePassive::loadDAEdQdx
154 // Purpose :
155 // Special Notes :
156 // Scope : public
157 // Creator : Richard Schiek, Electrical and Microsytem Modeling
158 // Creation Date : 08/11/2010
159 //-----------------------------------------------------------------------------
160 void MembranePassive::loadDAEdQdx( int segmentNumber, int vOffset, std::vector< int > & lidIndexVector, std::vector< std::vector< int > > & jacobianOffsets, N_LAS_Vector * solnVecPtr, N_LAS_Matrix * dQdxMatPtr, double segArea)
161 {
162  // while lidIndexVector lists LID's for just the segment variables (just V in the case
163  // of a passive cable). The jacobianOffsets includes the Vin and Vout as the first
164  // two variables. Thus, there is a constant offset of 2 for everything in jacobianOffsets
165 
166  // And, as in the Q and F load functions, Each segment will have numIndependentVars_ with segment voltage being the first
167  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
168  // in the case of the passive cable numIndependentVars_=1.
169 
170  int row = numExternalVars_ + segmentNumber; // numExternalVars_ a contant of 2 assumed in MembraneModel base class
171 
172  (*dQdxMatPtr)[lidIndexVector[segmentNumber]][jacobianOffsets[row][vOffset]] += cMem_ * segArea;
173 }
174 
175 //-----------------------------------------------------------------------------
176 // Function : MembranePassive::loadDAEdFdx
177 // Purpose :
178 // Special Notes :
179 // Scope : public
180 // Creator : Richard Schiek, Electrical and Microsytem Modeling
181 // Creation Date : 08/11/2010
182 //-----------------------------------------------------------------------------
183 void MembranePassive::loadDAEdFdx( int segmentNumber, int vOffset, std::vector< int > & lidIndexVector, std::vector< std::vector< int > > & jacobianOffsets, N_LAS_Vector * solnVecPtr, N_LAS_Matrix * dFdxMatPtr, double segArea)
184 {
185  // while lidIndexVector lists LID's for just the segment variables (just V in the case
186  // of a passive cable). The jacobianOffsets includes the Vin and Vout as the first
187  // two variables. Thus, there is a constant offset of 2 for everything in jacobianOffsets
188 
189  // And, as in the Q and F load functions, Each segment will have numIndependentVars_ with segment voltage being the first
190  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
191  // in the case of the passive cable numIndependentVars_=1.
192 
193  int row = numExternalVars_ + segmentNumber; // numExternalVars_ a contant of 2 assumed in MembraneModel base class
194 
195  (*dFdxMatPtr)[lidIndexVector[segmentNumber]][jacobianOffsets[row][vOffset]] += gMem_ * segArea;
196 
197 }
198 
199 } // namespace Device
200 } // namespace Xyce