Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_NeuronPop1.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_NeuronPop1.h,v $
27 //
28 // Purpose : Neuron classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
33 //
34 // Creation Date : 06/10/09
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.26.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_NeuronPop1_h
47 #define Xyce_N_DEV_NeuronPop1_h
48 
49 #include <N_DEV_Configuration.h>
50 #include <Teuchos_RefCountPtr.hpp>
51 using Teuchos::RefCountPtr;
52 using Teuchos::rcp;
53 
54 // ---------- Xyce Includes ----------
55 #include <N_DEV_fwd.h>
56 #include <N_UTL_fwd.h>
57 #include <N_DEV_DeviceBlock.h>
58 #include <N_DEV_DeviceInstance.h>
59 #include <N_DEV_DeviceModel.h>
60 
61 #ifdef HAVE_MATH_H
62 #include <math.h>
63 #endif
64 #include <fstream>
65 
66 namespace Xyce {
67 namespace Device {
68 namespace NeuronPop1 {
69 
70 class Model;
71 class Instance;
72 
73 struct Traits : public DeviceTraits<Model, Instance>
74 {
75  static const char *name() {return "NeuronPopulation";}
76  static const char *deviceTypeName() {return "YNEURONPOP level 1";}
77  static const int numNodes() {return 2;}
78  static const bool modelRequired() {return true;}
79  static const bool isLinearDevice() {return true;}
80 
81  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
82  static void loadModelParameters(ParametricData<Model> &model_parameters);
83  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
84 };
85 
86 //-----------------------------------------------------------------------------
87 // Class : Instance
88 // Purpose : This is class refers to a single instance of the
89 // Neuron device. It has two nodes associated with it, a
90 // positive and a negative node. See the NeuronInstance
91 // class for a more detailed explanation.
92 // Special Notes :
93 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
94 // Creation Date : 06/10/09
95 //-----------------------------------------------------------------------------
96 class Instance : public DeviceInstance
97 {
98  friend class ParametricData<Instance>;
99  friend class Model;
100  friend class Traits;
101 
102 public:
103 
104  Instance(
105  const Configuration & configuration,
106  const InstanceBlock & IB,
107  Model & Miter,
108  const FactoryBlock & factory_block);
109 
110  ~Instance();
111 
112 private:
113  Instance(const Instance &);
114  Instance &operator=(const Instance &);
115 
116 public:
117  void registerLIDs( const std::vector<int> & intLIDVecRef,
118  const std::vector<int> & extLIDVecRef );
119  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
120 
121  std::map<int,std::string> & getIntNameMap ();
122  bool loadDeviceMask ();
123  const std::vector< std::vector<int> > & jacobianStamp() const;
124  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
125 
126  bool processParams ();
127  bool updateTemperature(const double & temp_tmp);
128 
129  // this function is used to communicate to the device manager when
130  // this device is changing (i.e. updating the population)
131  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
132 
133  // updates done during the non-linear solve
134  bool updateIntermediateVars ();
135  bool updatePrimaryState ();
136  bool updateSecondaryState ();
137  bool setIC ();
138 
139  void varTypes( std::vector<char> & varTypeVec );
140 
141  // load functions, residual:
142  bool loadDAEQVector ();
143  bool loadDAEFVector ();
144 
145  void auxDAECalculations ();
146 
147  // load functions, Jacobian:
148  bool loadDAEdQdx ();
149  bool loadDAEdFdx ();
150 
151  // enable the interface to produce plot files.
152  bool plotfileFlag () {return true;}
153  bool outputPlotFiles ();
154 
155  // iterator reference to the Neuron model which owns this instance.
156  // Getters and setters
158  {
159  return model_;
160  }
161 
162 private:
163  void initializePopulation();
164  void updatePopulation();
165 
166 private:
167 
168  Model & model_; //< Owning model
169 
170  std::vector< std::vector<int> > jacStamp;
171 
172  // local indices into solution vector
173  int liNodeIn;
175 
176  // local indicies into state vector
177  std::vector<int> liNeuronPopState;
178 
179  // data needed for neurons
180  bool populationInitialized; // a flag for doing the initialization calculations
181  double lastPopulationUpdateTime; // time when we last did an update to avoid doing multiple updates per time
182  double lastNeurogenesisUpdateTime; // time when we last had a neurogenesis event - to avoid doing multiple updates per time
183  int neuronPopSize; // the current size of the neuron population
184  //std::vector<float> neuronXpos;
185  //std::vector<float> neuronYpos;
186 
187  std::vector<std::string> connectionTargetPopulation;
189 
190  // data for output of the population
191  // output stream for output of internal state if requested by user
192  Teuchos::RefCountPtr< std::ofstream > outputFileStreamPtr;
193  bool outputPopulationVarsFlag; // this flag indicates that the user wants to output the population state
194  bool newStateToOutput; // this flag is used to output only at times when the population has changed
195 
196  // flags for updating the population
198 
199  // jacobian stamp offsets
202 };
203 
204 //-----------------------------------------------------------------------------
205 // Class : Model
206 // Purpose :
207 // Special Notes :
208 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
209 // Creation Date : 06/10/09
210 //-----------------------------------------------------------------------------
211 class Model : public DeviceModel
212 {
213  typedef std::vector<Instance *> InstanceVector;
214 
215  friend class ParametricData<Model>;
216  friend class Instance;
217  friend class Traits;
218 
219 public:
220  Model(
221  const Configuration & configuration,
222  const ModelBlock & MB,
223  const FactoryBlock & factory_block);
224  ~Model();
225 
226 private:
227  Model();
228  Model(const Model &);
229  Model &operator=(const Model &);
230 
231 public:
232  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
233 
234  virtual std::ostream &printOutInstances(std::ostream &os) const;
235 
236  bool processParams ();
237  bool processInstanceParams ();
238 
239 
240 public:
241  void addInstance(Instance *instance)
242  {
243  instanceContainer.push_back(instance);
244  }
245 
247  {
248  return instanceContainer;
249  }
250 
252  {
253  return instanceContainer;
254  }
255 
256 private:
257  std::vector<Instance*> instanceContainer;
258 
259 private:
260 
261  // model parameters
270 
271  // time at which population statistics are updated.
274 
275  int outputPopulationVars; // flag indicating if user wants neuron populaiton output
276  // (position, voltage, connectivity etc.)
277 };
278 
279 void registerDevice();
280 
281 } // namespace NeuronPop1
282 } // namespace Device
283 } // namespace Xyce
284 
287 
288 #endif