Xyce  6.1
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-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_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.36 $
40 //
41 // Revision Date : $Date: 2015/04/24 20:25:44 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_NeuronPop1_h
47 #define Xyce_N_DEV_NeuronPop1_h
48 
49 #include <fstream>
50 
51 #include <N_DEV_Configuration.h>
52 
53 // ---------- Xyce Includes ----------
54 #include <N_DEV_fwd.h>
55 #include <N_UTL_fwd.h>
56 #include <N_DEV_DeviceBlock.h>
57 #include <N_DEV_DeviceInstance.h>
58 #include <N_DEV_DeviceModel.h>
59 
60 #include <Teuchos_RCP.hpp>
61 using Teuchos::RCP;
62 using Teuchos::rcp;
63 
64 namespace Xyce {
65 namespace Device {
66 namespace NeuronPop1 {
67 
68 class Model;
69 class Instance;
70 
71 struct Traits : public DeviceTraits<Model, Instance>
72 {
73  static const char *name() {return "NeuronPopulation";}
74  static const char *deviceTypeName() {return "YNEURONPOP level 1";}
75  static int numNodes() {return 2;}
76  static bool modelRequired() {return true;}
77  static bool isLinearDevice() {return true;}
78 
79  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
80  static void loadModelParameters(ParametricData<Model> &model_parameters);
81  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
82 };
83 
84 //-----------------------------------------------------------------------------
85 // Class : Instance
86 // Purpose : This is class refers to a single instance of the
87 // Neuron device. It has two nodes associated with it, a
88 // positive and a negative node. See the NeuronInstance
89 // class for a more detailed explanation.
90 // Special Notes :
91 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
92 // Creation Date : 06/10/09
93 //-----------------------------------------------------------------------------
94 class Instance : public DeviceInstance
95 {
96  friend class ParametricData<Instance>;
97  friend class Model;
98  friend class Traits;
99 
100 public:
101 
102  Instance(
103  const Configuration & configuration,
104  const InstanceBlock & IB,
105  Model & Miter,
106  const FactoryBlock & factory_block);
107 
108  ~Instance();
109 
110 private:
111  Instance(const Instance &);
112  Instance &operator=(const Instance &);
113 
114 public:
115  void registerLIDs( const std::vector<int> & intLIDVecRef,
116  const std::vector<int> & extLIDVecRef );
117  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
118 
119  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
120 
121  const std::vector< std::vector<int> > & jacobianStamp() const;
122  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
123 
124  bool processParams ();
125  bool updateTemperature(const double & temp_tmp);
126 
127  // this function is used to communicate to the device manager when
128  // this device is changing (i.e. updating the population)
129  bool getInstanceBreakPoints (std::vector<Util::BreakPoint> &breakPointTimes);
130 
131  // updates done during the non-linear solve
132  bool updateIntermediateVars ();
133  bool updatePrimaryState ();
134  bool updateSecondaryState ();
135  bool setIC ();
136 
137  void varTypes( std::vector<char> & varTypeVec );
138 
139  // load functions, residual:
140  bool loadDAEQVector ();
141  bool loadDAEFVector ();
142 
143  void auxDAECalculations ();
144 
145  // load functions, Jacobian:
146  bool loadDAEdQdx ();
147  bool loadDAEdFdx ();
148 
149  // enable the interface to produce plot files.
150  bool plotfileFlag () {return true;}
151  bool outputPlotFiles(bool force_final_output);
152 
153  // iterator reference to the Neuron model which owns this instance.
154  // Getters and setters
156  {
157  return model_;
158  }
159 
160 private:
161  void initializePopulation();
162  void updatePopulation();
163 
164 private:
165 
166  Model & model_; //< Owning model
167 
168  std::vector< std::vector<int> > jacStamp;
169 
170  // local indices into solution vector
171  int liNodeIn;
173 
174  // local indicies into state vector
175  std::vector<int> liNeuronPopState;
176 
177  // data needed for neurons
178  bool populationInitialized; // a flag for doing the initialization calculations
179  double lastPopulationUpdateTime; // time when we last did an update to avoid doing multiple updates per time
180  double lastNeurogenesisUpdateTime; // time when we last had a neurogenesis event - to avoid doing multiple updates per time
181  int neuronPopSize; // the current size of the neuron population
182  //std::vector<float> neuronXpos;
183  //std::vector<float> neuronYpos;
184 
185  std::vector<std::string> connectionTargetPopulation;
187 
188  // data for output of the population
189  // output stream for output of internal state if requested by user
190  RCP< std::ofstream > outputFileStreamPtr;
191  bool outputPopulationVarsFlag; // this flag indicates that the user wants to output the population state
192  bool newStateToOutput; // this flag is used to output only at times when the population has changed
193 
194  // flags for updating the population
196 
197  // jacobian stamp offsets
200 };
201 
202 //-----------------------------------------------------------------------------
203 // Class : Model
204 // Purpose :
205 // Special Notes :
206 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
207 // Creation Date : 06/10/09
208 //-----------------------------------------------------------------------------
209 class Model : public DeviceModel
210 {
211  typedef std::vector<Instance *> InstanceVector;
212 
213  friend class ParametricData<Model>;
214  friend class Instance;
215  friend class Traits;
216 
217 public:
218  Model(
219  const Configuration & configuration,
220  const ModelBlock & MB,
221  const FactoryBlock & factory_block);
222  ~Model();
223 
224 private:
225  Model();
226  Model(const Model &);
227  Model &operator=(const Model &);
228 
229 public:
230  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
231 
232  virtual std::ostream &printOutInstances(std::ostream &os) const;
233 
234  bool processParams ();
235  bool processInstanceParams ();
236 
237 
238 public:
239  void addInstance(Instance *instance)
240  {
241  instanceContainer.push_back(instance);
242  }
243 
244 private:
245  std::vector<Instance*> instanceContainer;
246 
247 private:
248 
249  // model parameters
258 
259  // time at which population statistics are updated.
262 
263  int outputPopulationVars; // flag indicating if user wants neuron populaiton output
264  // (position, voltage, connectivity etc.)
265 };
266 
267 void registerDevice();
268 
269 } // namespace NeuronPop1
270 } // namespace Device
271 } // namespace Xyce
272 
273 #endif
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
std::vector< Instance * > instanceContainer
bool processInstanceParams()
processInstanceParams
const std::vector< std::vector< int > > & jacobianStamp() const
bool outputPlotFiles(bool force_final_output)
static const char * deviceTypeName()
Pure virtual class to augment a linear system.
void varTypes(std::vector< char > &varTypeVec)
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
std::vector< std::string > connectionTargetPopulation
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
bool processParams()
processParams
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
std::vector< std::vector< int > > jacStamp
static void loadModelParameters(ParametricData< Model > &model_parameters)
RCP< std::ofstream > outputFileStreamPtr
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Miter, const FactoryBlock &factory_block)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
virtual std::ostream & printOutInstances(std::ostream &os) const
std::vector< Instance * > InstanceVector
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
bool getInstanceBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Class Configuration contains device configuration data.
Model & operator=(const Model &)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
bool updateTemperature(const double &temp_tmp)
void addInstance(Instance *instance)
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
Instance & operator=(const Instance &)