Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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.25.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_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 #ifdef Xyce_DEBUG_DEVICE
79  friend std::ostream & operator<<(std::ostream & os, const XygraCoilData & xcd);
80 #endif
81 
82 private:
83 
84 private:
85  std::string name;
87 
88 public:
89  std::string getName() const { return name;};
90  int getNumWindings() const { return numWindings;};
91 };
92 
93 
94 namespace Xygra {
95 
96 class Model;
97 class Instance;
98 
99 struct Traits : public DeviceTraits<Model, Instance>
100 {
101  static const char *name() {return "Xygra";}
102  static const char *deviceTypeName() {return "Xygra level 1";}
103  static const int numNodes() {return 2;}
104  static const int numOptionalNodes() {return 1000;}
105  static const bool isLinearDevice() {return true;}
106 
107  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
108  static void loadModelParameters(ParametricData<Model> &model_parameters);
109  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
110 };
111 
112 //-----------------------------------------------------------------------------
113 // Class : Instance
114 // Purpose : This is class refers to a single instance of the
115 // Xygra device. It has two nodes associated with it, a
116 // positive and a negative node. See the ResistorInstance
117 // class for a more detailed explanation.
118 // Special Notes :
119 // Creator : Tom Russo
120 // Creation Date : 8/18/08
121 //-----------------------------------------------------------------------------
122 
123 class Instance : public DeviceInstance
124 {
125  friend class ParametricData<Instance>;
126  friend class Model;
127  friend class Traits;
128 
129  typedef Sacado::Fad::DFad<double> XygraFadType;
130 
131 public:
132  Instance(
133  const Configuration & configuration,
134  const InstanceBlock & IB,
135  Model & Miter,
136  const FactoryBlock &factory_block);
137 
138  ~Instance();
139 
140 private:
141  Instance(const Instance &);
142  Instance &operator=(const Instance &);
143 
144 public:
145  void registerLIDs( const std::vector<int> & intLIDVecRef,
146  const std::vector<int> & extLIDVecRef );
147  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
148 
149  std::map<int,std::string> & getIntNameMap ();
150 
151  const std::vector< std::vector<int> > & jacobianStamp() const;
152  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
153 
154  bool processParams ();
155  bool updateTemperature(const double & temp_tmp);
156 
157  bool updateIntermediateVars ();
158  bool updatePrimaryState ();
159  bool updateSecondaryState ();
160 
161  bool setIC ();
162 
163  bool getVoltages(std::vector<double> &voltageValues);
164  bool setConductances(const std::vector< std::vector<double> > &conductanceMatrix);
165  bool setK(const std::vector< std::vector<double> > &kMatrix, const double t=0);
166  bool setSources(const std::vector<double> &sourceVector,const double t=0);
167  int getNumNodes();
168  int getNumWindings();
169  void getCoilWindings(std::vector<int> &coilWindings);
170  void getCoilNames(std::vector<std::string> &coilNames);
171 
172  void varTypes( std::vector<char> & varTypeVec );
173 
174  // load functions, residual:
175  bool loadDAEQVector ();
176  bool loadDAEFVector ();
177 
178  void auxDAECalculations ();
179 
180  // load functions, Jacobian:
181  bool loadDAEdQdx ();
182  bool loadDAEdFdx ();
183 
184  CompositeParam *constructComposite (const std::string &, const std::string &);
185 
186 protected:
187 private:
188  void setupJacStamp_();
189  void interpolateSandK_();
190 
191 public:
192  // iterator reference to the Xygra model which owns this instance.
193  // Getters and setters
195  {
196  return model_;
197  }
198 
199 private:
200 
201  Model & model_; //< Owning model
202 
203  std::map<std::string, XygraCoilData *> coilDataMap;
204 
205 private:
206  // parameter variables
207 
208  // state variables
209  // This device has no state
210 
211  // local state indices (offsets)
212  // This device has no state
213 
214  // local solution indices (offsets)
215  // This device uses an array of li_ values instead of individually named
216  // variables.
217  std::vector<int> li_Nodes_;
218 
219  // Matrix equation index variables:
220 
221  // Offset variables. Again, this device uses an array instead of
222  // discrete variables.
223  // A_Equ_NodeOffests[equation][node] is the offset for node in
224  // equation
225  std::vector< std::vector<int> > A_Equ_NodeOffsets_;
226 
227  std::vector< std::vector<int> > jacStamp_;
228 
229  // These guys hold the Alegra input
230  std::vector< std::vector<double> > theConductanceMatrix_;
231  std::vector< std::vector<double> > theKMatrix_;
232  std::vector< std::vector<double> > k0_;
233  std::vector< std::vector<double> > k1_;
234  std::vector<double> theSourceVector_;
235  std::vector<double> s0_;
236  std::vector<double> s1_;
237  // times that (s0,k0) and (s1,k1) apply to.
238  double t0_;
239  double t1_;
240 
241  // For vector composite:
242  std::vector<XygraCoilData*> coilDataVec;
243  // total number of coils
244  int nCoils;
245  // number of windngs in each coil
246  std::vector<int> nWindings;
247  // names of each coil
248  std::vector<std::string> coilNames;
249  // sum over coils of number of windings per coil
251  // offsets into global node array of start of each coil's external vars
252  std::vector<int> coilExtStart;
253  // offsets into global node array of start of each coil's Internal vars
254  std::vector<int> coilIntStart;
255  // vector of pairs of nodes (pos,neg) for every winding
256  std::vector<std::pair<int,int> > windingNodes;
257 
258  // For computation of RHS/F vector and jacobian/dFdX
259  // We copy solution vars here so we can differentiate w.r.t them.
260  std::vector<XygraFadType> solutionVars;
261  // This is the vector of winding dv's
262  std::vector<XygraFadType> dV;
263  // This is the vector of winding currents
264  std::vector<XygraFadType> windingCurrents;
265  // and finally the vector of contributions into F:
266  std::vector<XygraFadType> fContributions;
267 };
268 
269 //-----------------------------------------------------------------------------
270 // Class : Model
271 // Purpose :
272 // Special Notes :
273 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
274 // Creation Date : 3/16/00
275 //-----------------------------------------------------------------------------
276 class Model : public DeviceModel
277 {
278  typedef std::vector<Instance *> InstanceVector;
279 
280  friend class ParametricData<Model>;
281  friend class Instance;
282  friend class Traits;
283 
284 public:
285  Model(
286  const Configuration & configuration,
287  const ModelBlock & MB,
288  const FactoryBlock & factory_block);
289  ~Model();
290 
291 private:
292  Model();
293  Model(const Model &);
294  Model &operator=(const Model &);
295 
296 public:
297  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
298 
299  virtual std::ostream &printOutInstances(std::ostream &os) const;
300 
301  bool processParams ();
302  bool processInstanceParams ();
303 
304 
305 public:
306  void addInstance(Instance *instance)
307  {
308  instanceContainer.push_back(instance);
309  }
310 
312  {
313  return instanceContainer;
314  }
315 
317  {
318  return instanceContainer;
319  }
320 
321 private:
322  std::vector<Instance*> instanceContainer;
323 
324 private:
325 
326  static int numOrig;
327  static int numSer;
328 
329  // Additional Implementation Declarations
330 };
331 
332 //----------------------------------------------------------------------------
333 // Function : Instance::getNumNodes
334 // Purpose : Return the number of nodes in a given instance
335 // Special Notes :
336 // Scope : public
337 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
338 // Creation Date : 08/27/2008
339 //----------------------------------------------------------------------------
341 {
342  return numExtVars+numIntVars;
343 }
344 //----------------------------------------------------------------------------
345 // Function : Instance::getNumWindings()
346 // Purpose : Return the number of windings in a given instance
347 // Special Notes :
348 // Scope : public
349 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
350 // Creation Date : 08/27/2008
351 //----------------------------------------------------------------------------
353 {
354  return totalNumWindings;
355 }
356 
357 void registerDevice();
358 
359 } // namespace Resistor
360 } // namespace Device
361 } // namespace Xyce
362 
366 
367 #endif