Xyce  6.1
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-2015 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.15 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:23 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #include<iostream>
49 
50 // ---------- Standard Includes ----------
51 
52 
53 // ---------- Xyce Includes ----------
54 #include <N_DEV_MembranePassive.h>
55 #include <N_LAS_Vector.h>
56 #include <N_LAS_Matrix.h>
57 #include <N_DEV_SolverState.h>
58 
59 namespace Xyce {
60 namespace Device {
61 
62 //-----------------------------------------------------------------------------
63 // Function : MembranePassive::MembranePassive
64 // Purpose :
65 // Special Notes :
66 // Scope : public
67 // Creator : Richard Schiek, Electrical and Microsytem Modeling
68 // Creation Date : 08/11/2010
69 //-----------------------------------------------------------------------------
70 MembranePassive::MembranePassive(const SolverState & ss1, double cMem, double gMem, double vRest)
71  : MembraneModel(ss1),
72  gMem_(gMem),
73  cMem_(cMem),
74  vRest_(vRest)
75 {
76  // passive membrane just has voltage as its unknown variable
77  // so set up numIndependentVars_ for that
79 }
80 
81 //-----------------------------------------------------------------------------
82 // Function : MembranePassive::setJacStamp
83 // Purpose :
84 // Special Notes :
85 // Scope : public
86 // Creator : Richard Schiek, Electrical and Microsytem Modeling
87 // Creation Date : 08/11/2010
88 //-----------------------------------------------------------------------------
89 void MembranePassive::setJacStamp( int numExtVars, int segmentNumber, int vOffset, std::vector< std::vector< int > > & segmentJacStamp )
90 {
91  // In a passive cable the membrane is just two passive elements, a capacitor and a resistor
92  // thus the membrane current, I = f(Vsegment).
93 
94  /*
95  int offset = numExtVars + numIndependentVars_*segmentNumber;
96 
97  int jacobianRowSize = segmentJacStamp[offset].size();
98  */
99  /* need to handle these in a better way
100  currently they can confuse parameter testing when dummy devices are created.
101  if( jacobianRowSize == 1 )
102  {
103  if( segmentJacStamp[ offset ][0] != offset )
104  {
105  Xyce::dout() << "Potential error in MembranePassive::setJacStamp(). segmentJacStamp[ " << offset << " ][0] != " << offset << std::endl;
106  }
107  }
108  else if( jacobianRowSize > 1 )
109  {
110  if( segmentJacStamp[ offset ][1] != offset )
111  {
112  Xyce::dout() << "Potential error in MembranePassive::setJacStamp(). segmentJacStamp[ " << offset << " ][1] != " << offset << std::endl;
113  }
114  }
115  */
116 
117 }
118 
119 //-----------------------------------------------------------------------------
120 // Function : MembranePassive::loadDAEQVector
121 // Purpose :
122 // Special Notes :
123 // Scope : public
124 // Creator : Richard Schiek, Electrical and Microsytem Modeling
125 // Creation Date : 08/11/2010
126 //-----------------------------------------------------------------------------
127 void MembranePassive::loadDAEQVector( int segmentNumber, std::vector< int > & lidIndexVector, Linear::Vector * solnVecPtr, Linear::Vector * daeQVecPtr, double segArea)
128 {
129  // Each segment will have numIndependentVars_ with segment voltage being the first
130  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
131  // in the case of the passive cable numIndependentVars_=1.
132  (*daeQVecPtr)[lidIndexVector[segmentNumber]] += cMem_ * segArea * (*solnVecPtr)[lidIndexVector[segmentNumber]];
133 }
134 
135 //-----------------------------------------------------------------------------
136 // Function : MembranePassive::loadDAEFVector
137 // Purpose :
138 // Special Notes :
139 // Scope : public
140 // Creator : Richard Schiek, Electrical and Microsytem Modeling
141 // Creation Date : 08/11/2010
142 //-----------------------------------------------------------------------------
143 void MembranePassive::loadDAEFVector( int segmentNumber, std::vector< int > & lidIndexVector, Linear::Vector * solnVecPtr, Linear::Vector * daeFVecPtr, double segArea)
144 {
145  // Each segment will have numIndependentVars_ with segment voltage being the first
146  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
147  // in the case of the passive cable numIndependentVars_=1.
148  (*daeFVecPtr)[lidIndexVector[segmentNumber]] += gMem_ * segArea * ((*solnVecPtr)[lidIndexVector[segmentNumber]] - vRest_ );
149 }
150 
151 //-----------------------------------------------------------------------------
152 // Function : MembranePassive::loadDAEdQdx
153 // Purpose :
154 // Special Notes :
155 // Scope : public
156 // Creator : Richard Schiek, Electrical and Microsytem Modeling
157 // Creation Date : 08/11/2010
158 //-----------------------------------------------------------------------------
159 void MembranePassive::loadDAEdQdx( int segmentNumber, int vOffset, std::vector< int > & lidIndexVector, std::vector< std::vector< int > > & jacobianOffsets, Linear::Vector * solnVecPtr, Linear::Matrix * dQdxMatPtr, double segArea)
160 {
161  // while lidIndexVector lists LID's for just the segment variables (just V in the case
162  // of a passive cable). The jacobianOffsets includes the Vin and Vout as the first
163  // two variables. Thus, there is a constant offset of 2 for everything in jacobianOffsets
164 
165  // And, as in the Q and F load functions, Each segment will have numIndependentVars_ with segment voltage being the first
166  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
167  // in the case of the passive cable numIndependentVars_=1.
168 
169  int row = numExternalVars_ + segmentNumber; // numExternalVars_ a contant of 2 assumed in MembraneModel base class
170 
171  (*dQdxMatPtr)[lidIndexVector[segmentNumber]][jacobianOffsets[row][vOffset]] += cMem_ * segArea;
172 }
173 
174 //-----------------------------------------------------------------------------
175 // Function : MembranePassive::loadDAEdFdx
176 // Purpose :
177 // Special Notes :
178 // Scope : public
179 // Creator : Richard Schiek, Electrical and Microsytem Modeling
180 // Creation Date : 08/11/2010
181 //-----------------------------------------------------------------------------
182 void MembranePassive::loadDAEdFdx( int segmentNumber, int vOffset, std::vector< int > & lidIndexVector, std::vector< std::vector< int > > & jacobianOffsets, Linear::Vector * solnVecPtr, Linear::Matrix * dFdxMatPtr, double segArea)
183 {
184  // while lidIndexVector lists LID's for just the segment variables (just V in the case
185  // of a passive cable). The jacobianOffsets includes the Vin and Vout as the first
186  // two variables. Thus, there is a constant offset of 2 for everything in jacobianOffsets
187 
188  // And, as in the Q and F load functions, Each segment will have numIndependentVars_ with segment voltage being the first
189  // so, the cMem dV/dt term will be at segmentNumber * numIndependentVars_.
190  // in the case of the passive cable numIndependentVars_=1.
191 
192  int row = numExternalVars_ + segmentNumber; // numExternalVars_ a contant of 2 assumed in MembraneModel base class
193 
194  (*dFdxMatPtr)[lidIndexVector[segmentNumber]][jacobianOffsets[row][vOffset]] += gMem_ * segArea;
195 
196 }
197 
198 } // namespace Device
199 } // namespace Xyce
void loadDAEdQdx(int segmentNumber, int vOffset, std::vector< int > &lidIndexVector, std::vector< std::vector< int > > &jacobianOffsets, Linear::Vector *solnVecPtr, Linear::Matrix *dQdxMatPtr, double segArea)
void loadDAEdFdx(int segmentNumber, int vOffset, std::vector< int > &lidIndexVector, std::vector< std::vector< int > > &jacobianOffsets, Linear::Vector *solnVecPtr, Linear::Matrix *dFdxMatPtr, double segArea)
Pure virtual class to augment a linear system.
void loadDAEFVector(int segmentNumber, std::vector< int > &lidIndexVector, Linear::Vector *solnVecPtr, Linear::Vector *daeFVecPtr, double segArea)
void loadDAEQVector(int segmentNumber, std::vector< int > &lidIndexVector, Linear::Vector *solnVecPtr, Linear::Vector *daeQVecPtr, double segArea)
void setJacStamp(int numExtVars, int segmentNumber, int vOffset, std::vector< std::vector< int > > &segmentJacStamp)
MembranePassive(const SolverState &ss1, double cMem, double gMem, double vRest)