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