Xyce  6.1
N_DEV_Xygra.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_Xygra.h,v $
27 //
28 // Purpose : Xygra classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 02/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.33 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:24 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Xygra_h
47 #define Xyce_N_DEV_Xygra_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <Sacado.hpp>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 #include <N_DEV_CompositeParam.h>
56 
57 namespace Xyce {
58 namespace Device {
59 
60 //-----------------------------------------------------------------------------
61 // Class : XygraCoilData
62 // Purpose : This is class is a CompositeParameter type for managing
63 // coil vector-composite data
64 // Special Notes :
65 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
66 // Creation Date : 9/11/2008
67 //-----------------------------------------------------------------------------
69 {
71 
72 public:
74 
75  XygraCoilData();
76 
77  void processParams();
78  friend std::ostream & operator<<(std::ostream & os, const XygraCoilData & xcd);
79 
80 private:
81  std::string name;
83 
84 public:
85  std::string getName() const { return name;};
86  int getNumWindings() const { return numWindings;};
87 };
88 
89 
90 namespace Xygra {
91 
92 class Model;
93 class Instance;
94 
95 struct Traits : public DeviceTraits<Model, Instance>
96 {
97  static const char *name() {return "Xygra";}
98  static const char *deviceTypeName() {return "Xygra level 1";}
99  static int numNodes() {return 2;}
100  static int numOptionalNodes() {return 1000;}
101  static bool isLinearDevice() {return true;}
102 
103  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
104  static void loadModelParameters(ParametricData<Model> &model_parameters);
105  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
106 };
107 
108 //-----------------------------------------------------------------------------
109 // Class : Instance
110 // Purpose : This is class refers to a single instance of the
111 // Xygra device. It has two nodes associated with it, a
112 // positive and a negative node. See the ResistorInstance
113 // class for a more detailed explanation.
114 // Special Notes :
115 // Creator : Tom Russo
116 // Creation Date : 8/18/08
117 //-----------------------------------------------------------------------------
118 
119 class Instance : public DeviceInstance
120 {
121  friend class ParametricData<Instance>;
122  friend class Model;
123  friend class Traits;
124 
125  typedef Sacado::Fad::DFad<double> XygraFadType;
126 
127 public:
128  Instance(
129  const Configuration & configuration,
130  const InstanceBlock & IB,
131  Model & Miter,
132  const FactoryBlock &factory_block);
133 
134  ~Instance();
135 
136 private:
137  Instance(const Instance &);
138  Instance &operator=(const Instance &);
139 
140 public:
141  void registerLIDs( const std::vector<int> & intLIDVecRef,
142  const std::vector<int> & extLIDVecRef );
143  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
144 
145  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
146 
147  const std::vector< std::vector<int> > & jacobianStamp() const;
148  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
149 
150  bool processParams ();
151  bool updateTemperature(const double & temp_tmp);
152 
153  bool updateIntermediateVars ();
154  bool updatePrimaryState ();
155  bool updateSecondaryState ();
156 
157  bool setIC ();
158 
159  bool getVoltages(std::vector<double> &voltageValues);
160  bool setConductances(const std::vector< std::vector<double> > &conductanceMatrix);
161  bool setK(const std::vector< std::vector<double> > &kMatrix, const double t=0);
162  bool setSources(const std::vector<double> &sourceVector,const double t=0);
163  int getNumNodes();
164  int getNumWindings();
165  void getCoilWindings(std::vector<int> &coilWindings);
166  void getCoilNames(std::vector<std::string> &coilNames);
167 
168  void varTypes( std::vector<char> & varTypeVec );
169 
170  // load functions, residual:
171  bool loadDAEQVector ();
172  bool loadDAEFVector ();
173 
174  void auxDAECalculations ();
175 
176  // load functions, Jacobian:
177  bool loadDAEdQdx ();
178  bool loadDAEdFdx ();
179 
180  CompositeParam *constructComposite (const std::string &, const std::string &);
181 
182 protected:
183 private:
184  void setupJacStamp_();
185  void interpolateSandK_();
186 
187 public:
188  // iterator reference to the Xygra model which owns this instance.
189  // Getters and setters
191  {
192  return model_;
193  }
194 
195 private:
196 
197  Model & model_; //< Owning model
198 
199  std::map<std::string, XygraCoilData *> coilDataMap;
200 
201 private:
202  // parameter variables
203 
204  // state variables
205  // This device has no state
206 
207  // local state indices (offsets)
208  // This device has no state
209 
210  // local solution indices (offsets)
211  // This device uses an array of li_ values instead of individually named
212  // variables.
213  std::vector<int> li_Nodes_;
214 
215  // Matrix equation index variables:
216 
217  // Offset variables. Again, this device uses an array instead of
218  // discrete variables.
219  // A_Equ_NodeOffests[equation][node] is the offset for node in
220  // equation
221  std::vector< std::vector<int> > A_Equ_NodeOffsets_;
222 
223  std::vector< std::vector<int> > jacStamp_;
224 
225  // These guys hold the Alegra input
226  std::vector< std::vector<double> > theConductanceMatrix_;
227  std::vector< std::vector<double> > theKMatrix_;
228  std::vector< std::vector<double> > k0_;
229  std::vector< std::vector<double> > k1_;
230  std::vector<double> theSourceVector_;
231  std::vector<double> s0_;
232  std::vector<double> s1_;
233  // times that (s0,k0) and (s1,k1) apply to.
234  double t0_;
235  double t1_;
236 
237  // For vector composite:
238  std::vector<XygraCoilData*> coilDataVec;
239  // total number of coils
240  int nCoils;
241  // number of windngs in each coil
242  std::vector<int> nWindings;
243  // names of each coil
244  std::vector<std::string> coilNames;
245  // sum over coils of number of windings per coil
247  // offsets into global node array of start of each coil's external vars
248  std::vector<int> coilExtStart;
249  // offsets into global node array of start of each coil's Internal vars
250  std::vector<int> coilIntStart;
251  // vector of pairs of nodes (pos,neg) for every winding
252  std::vector<std::pair<int,int> > windingNodes;
253 
254  // For computation of RHS/F vector and jacobian/dFdX
255  // We copy solution vars here so we can differentiate w.r.t them.
256  std::vector<XygraFadType> solutionVars;
257  // This is the vector of winding dv's
258  std::vector<XygraFadType> dV;
259  // This is the vector of winding currents
260  std::vector<XygraFadType> windingCurrents;
261  // and finally the vector of contributions into F:
262  std::vector<XygraFadType> fContributions;
263 };
264 
265 //-----------------------------------------------------------------------------
266 // Class : Model
267 // Purpose :
268 // Special Notes :
269 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
270 // Creation Date : 3/16/00
271 //-----------------------------------------------------------------------------
272 class Model : public DeviceModel
273 {
274  typedef std::vector<Instance *> InstanceVector;
275 
276  friend class ParametricData<Model>;
277  friend class Instance;
278  friend class Traits;
279 
280 public:
281  Model(
282  const Configuration & configuration,
283  const ModelBlock & MB,
284  const FactoryBlock & factory_block);
285  ~Model();
286 
287 private:
288  Model();
289  Model(const Model &);
290  Model &operator=(const Model &);
291 
292 public:
293  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
294 
295  virtual std::ostream &printOutInstances(std::ostream &os) const;
296 
297  bool processParams ();
298  bool processInstanceParams ();
299 
300 
301 public:
302  void addInstance(Instance *instance)
303  {
304  instanceContainer.push_back(instance);
305  }
306 
307 private:
308  std::vector<Instance*> instanceContainer;
309 
310 private:
311 
312  static int numOrig;
313  static int numSer;
314 
315  // Additional Implementation Declarations
316 };
317 
318 //----------------------------------------------------------------------------
319 // Function : Instance::getNumNodes
320 // Purpose : Return the number of nodes in a given instance
321 // Special Notes :
322 // Scope : public
323 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
324 // Creation Date : 08/27/2008
325 //----------------------------------------------------------------------------
327 {
328  return numExtVars+numIntVars;
329 }
330 //----------------------------------------------------------------------------
331 // Function : Instance::getNumWindings()
332 // Purpose : Return the number of windings in a given instance
333 // Special Notes :
334 // Scope : public
335 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
336 // Creation Date : 08/27/2008
337 //----------------------------------------------------------------------------
339 {
340  return totalNumWindings;
341 }
342 
343 void registerDevice();
344 
345 } // namespace Resistor
346 } // namespace Device
347 } // namespace Xyce
348 
349 #endif
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_Xygra.C:1333
std::vector< double > theSourceVector_
Definition: N_DEV_Xygra.h:230
friend std::ostream & operator<<(std::ostream &os, const XygraCoilData &xcd)
Definition: N_DEV_Xygra.C:119
std::vector< XygraCoilData * > coilDataVec
Definition: N_DEV_Xygra.h:238
std::vector< std::vector< double > > theConductanceMatrix_
Definition: N_DEV_Xygra.h:226
std::vector< int > coilIntStart
Definition: N_DEV_Xygra.h:250
std::string getName() const
Definition: N_DEV_Xygra.h:85
std::map< std::string, XygraCoilData * > coilDataMap
Definition: N_DEV_Xygra.h:199
std::vector< int > li_Nodes_
Definition: N_DEV_Xygra.h:213
std::vector< Instance * > InstanceVector
Definition: N_DEV_Xygra.h:274
bool setK(const std::vector< std::vector< double > > &kMatrix, const double t=0)
Definition: N_DEV_Xygra.C:400
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_Xygra.C:136
bool setSources(const std::vector< double > &sourceVector, const double t=0)
Definition: N_DEV_Xygra.C:542
Pure virtual class to augment a linear system.
static ParametricData< XygraCoilData > & getParametricData()
Definition: N_DEV_Xygra.C:78
void addInstance(Instance *instance)
Definition: N_DEV_Xygra.h:302
bool processParams()
processParams
Definition: N_DEV_Xygra.C:1234
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Miter, const FactoryBlock &factory_block)
Definition: N_DEV_Xygra.C:182
std::vector< std::vector< int > > jacStamp_
Definition: N_DEV_Xygra.h:223
std::vector< XygraFadType > windingCurrents
Definition: N_DEV_Xygra.h:260
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_Xygra.C:768
bool getVoltages(std::vector< double > &voltageValues)
Definition: N_DEV_Xygra.C:477
void getCoilNames(std::vector< std::string > &coilNames)
Definition: N_DEV_Xygra.C:528
CompositeParam * constructComposite(const std::string &, const std::string &)
Definition: N_DEV_Xygra.C:1207
std::vector< std::vector< double > > k1_
Definition: N_DEV_Xygra.h:229
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
std::vector< XygraFadType > dV
Definition: N_DEV_Xygra.h:258
std::vector< XygraFadType > fContributions
Definition: N_DEV_Xygra.h:262
std::vector< std::vector< double > > theKMatrix_
Definition: N_DEV_Xygra.h:227
std::vector< std::pair< int, int > > windingNodes
Definition: N_DEV_Xygra.h:252
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_Xygra.C:1247
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_Xygra.C:813
std::vector< std::vector< int > > A_Equ_NodeOffsets_
Definition: N_DEV_Xygra.h:221
static const char * deviceTypeName()
Definition: N_DEV_Xygra.h:98
std::vector< int > coilExtStart
Definition: N_DEV_Xygra.h:248
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
std::vector< Instance * > instanceContainer
Definition: N_DEV_Xygra.h:308
Model & operator=(const Model &)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_Xygra.C:1371
void getCoilWindings(std::vector< int > &coilWindings)
Definition: N_DEV_Xygra.C:513
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_Xygra.C:1378
Class Configuration contains device configuration data.
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_Xygra.C:665
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_Xygra.C:826
static const char * name()
Definition: N_DEV_Xygra.h:97
Instance & operator=(const Instance &)
void processParams()
processParams post processes the parameters that have been set in the object of the derived class...
Definition: N_DEV_Xygra.C:107
bool setConductances(const std::vector< std::vector< double > > &conductanceMatrix)
Definition: N_DEV_Xygra.C:349
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_Xygra.C:1193
Sacado::Fad::DFad< double > XygraFadType
Definition: N_DEV_Xygra.h:125
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_Xygra.C:797
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.
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Xygra.C:130
std::vector< double > s0_
Definition: N_DEV_Xygra.h:231
std::vector< double > s1_
Definition: N_DEV_Xygra.h:232
std::vector< std::vector< double > > k0_
Definition: N_DEV_Xygra.h:228
bool updateTemperature(const double &temp_tmp)
Definition: N_DEV_Xygra.C:168
std::vector< int > nWindings
Definition: N_DEV_Xygra.h:242
CompositeParam is the base class for classes that wish to only manage the processing of parameter dat...
static bool isLinearDevice()
Definition: N_DEV_Xygra.h:101
std::vector< std::string > coilNames
Definition: N_DEV_Xygra.h:244
std::vector< XygraFadType > solutionVars
Definition: N_DEV_Xygra.h:256