Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_MembraneUserDefined.h
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_MembraneUserDefined.h,v $
27 //
28 // Purpose : Neuron classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Christy Warrender, Cognitive Modeling
33 //
34 // Creation Date : 12/14/10
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.14.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_MembraneUserDefined_h
47 #define Xyce_N_DEV_MembraneUserDefined_h
48 
49 #include <Teuchos_RefCountPtr.hpp>
50 using Teuchos::RefCountPtr;
51 using Teuchos::rcp;
52 
53 // ---------- Xyce Includes ----------
54 #include <N_DEV_DeviceEntity.h>
55 #include <N_DEV_MembraneModel.h>
56 #include <N_UTL_Expression.h>
57 
58 namespace Xyce {
59 namespace Device {
60 
61 //-----------------------------------------------------------------------------
62 // Class : MembraneUserDefined
63 // Purpose : This is class defines a user-defined membrane mechanism.
64 // Special Notes :
65 // Creator : Christy Warrender, Cognitive Modeling
66 // Creation Date : 12/14/2010
67 //-----------------------------------------------------------------------------
69 {
70 public:
71  MembraneUserDefined(const SolverState & ss1, double cMem, double gMem, double vRest,
72  std::vector<std::string> & currentEqus, std::vector<std::string> & indepVars, std::vector<std::string> & fEqs,
73  std::vector<std::string> & qEqs, std::vector<std::string> & extraFunctions, std::vector<std::string> & extraParameters);
75 
76  void updateSecondaryState( double * staDerivVec );
77  void setJacStamp( int numExtVars, int segmentNumber, int vOffset, std::vector< std::vector< int > > & segmentJacStamp );
78  void loadDAEQVector( int segmentNumber, std::vector< int > & lidIndexVector, N_LAS_Vector * solnVecPtr, N_LAS_Vector * daeQVecPtr, double segArea);
79  void loadDAEFVector( int segmentNumber, std::vector< int > & lidIndexVector, N_LAS_Vector * solnVecPtr, N_LAS_Vector * daeFVecPtr, double segArea);
80  void 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);
81  void 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);
82 
83  // constitutive parameters
84  double cMem_; // membrane capacitance
85  double gMem_; // membrane conductance
86  double vRest_; // membrane rest voltage
87 
88  // values similar to what Bsrc uses, for handling a single current equation
89  // TODO - I don't think I need these, although I am currently using at least expNumVars;
90  // need to remove or properly initialize each
91  Util::Expression * Exp_ptr;
94  int expNumDdt;
95  std::list<std::string> evnList;
96  std::vector<double> expVarDerivs;
97  std::vector<double> myVarVals;
98  std::vector<double> ddtVals;
99  double expVal;
100 
101 private:
102  std::vector<std::string> currentEqus_; // list of equations for contribution to the membrane current
103  std::vector<std::string> indepVars_; // list of independent variables for this membrane model
104  std::vector<std::string> fEqs_; // list of unparsed F equations for this membrane model
105  std::vector<std::string> qEqs_; // list of unparsed Q equations for this membrane model
106  std::vector<std::string> extraFunctions_; // list of unparsed extra functions for this membrane model
107  std::vector<std::string> extraParameters_; // list of unparsed parameters for this membrane model
108 
109  std::vector<RefCountPtr<N_UTL_Expression> > currentEqusExpRCP_; // list of rcp to Util::Expressions for contribution to the membrane current
110  std::vector<RefCountPtr<N_UTL_Expression> > indepVarsExpRCP_; // list of rcp to Util::Expressions for independent variables for this membrane model
111  std::vector<RefCountPtr<N_UTL_Expression> > fEqsExpRCP_; // list of rcp to Util::Expressions for F equations for this membrane model
112  std::vector<RefCountPtr<N_UTL_Expression> > qEqsExpRCP_; // list of rcp to Util::Expressions for Q equations for this membrane model
113  std::vector<RefCountPtr<N_UTL_Expression> > extraFunctionsExpRCP_; // list of rcp to Util::Expressions for extra functions for this membrane model
114  std::vector<RefCountPtr<N_UTL_Expression> > extraParametersExpRCP_; // list of rcp to Util::Expressions for parameters for this membrane model
115 
116  std::vector<std::string> paramNames_;
117  std::vector<double> paramValues_;
118  std::vector<std::string> funcNames_;
119  std::vector< RefCountPtr<N_UTL_Expression> > funcExpRCP_;
120  std::vector< int > funcNumArgs_;
121  std::vector<std::string> userDefinedNames_; // used to get minimal collection of user defined variables/names
122  std::map< std::string, int > indepVarOffset_; // a map connecting a vars name to its local offset in solution, F, Q and jacobian (An LID map)
123  std::map< int, std::string > offsetToIndepVar_; // an inverse map of indepVarOffset_
124  std::vector< std::map< std::string, int > > systemJacOffset_;
125  // for each row in the jacobian, this gives a map relating contributing var name to offset.
126  // i.e. systemJacOffset[ row of segment jacStamp ][ "var name" ] = second index into jacobianOffset (for that given row and variable).
127 
128  // These are used to hold the variable names in the user expressions.
129  // the names can be used with indepVarOffset_ to assign values to the variables.
130  std::vector< std::vector<std::string> > currentEqusVarNames_;
131  std::vector< std::vector<std::string> > fEqsEqusVarNames_;
132  std::vector< std::vector<std::string> > qEqsEqusVarNames_;
133 
134  // These hold the variable values needed to evaluate an expression. The values have to be
135  // in the same order as the names in the std::vector< std::vector< string > > containers above.
136  std::vector< std::vector<double> > currentEqusVarValues_;
137  std::vector< std::vector<double> > fEqsEqusVarValues_;
138  std::vector< std::vector<double> > qEqsEqusVarValues_;
139 
140  void convertStringsToExpression( std::vector< std::string > & stringInput, std::vector<RefCountPtr<N_UTL_Expression> > & expRCPOut );
141  void consolidateExpressions();
142  void substituteParameters( std::vector<RefCountPtr<N_UTL_Expression> > & expRCP_ );
143  void substituteFunctions( std::vector<RefCountPtr<N_UTL_Expression> > & expRCP_ );
144  void convertSymbolsToVars( std::vector<RefCountPtr<N_UTL_Expression> > & expRCP_, std::vector< std::vector<std::string> > & expNames, std::vector< std::vector<double> > & expValsVec );
145  void makeSymbolSet();
146 
147 };
148 
149 } // namespace Device
150 } // namespace Xyce
151 
153 
154 #endif