Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_MutIndLin.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_MutIndLin.h,v $
27 //
28 // Purpose : Linear Mutual Inductor classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 03/21/05
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.75 $
40 //
41 // Revision Date : $Date: 2014/05/22 17:40:29 $
42 //
43 // Current Owner : $Author: erkeite $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_MutIndLin_h
47 #define Xyce_N_DEV_MutIndLin_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 #include <N_UTL_fwd.h>
56 
57 namespace Xyce {
58 namespace Device {
59 
60 //-----------------------------------------------------------------------------
61 // Class : InductorInstancePhysicalData
62 // Purpose : This class handles the physical data for an inductor
63 // so that the mutual inductor classes have a clean
64 // contain object.
65 // Special Notes :
66 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
67 // Creation Date : 3/21/05
68 //-----------------------------------------------------------------------------
70 {
71 public:
73  std::string name; // name of inductor
74  double L; // User specified inductance
75  double IC; // Initial condition: initial, time-zero inductor current(A)
76  bool ICGiven; // flag if IC was given
77  double baseL; // the baseline inductance before temperature effects
78  // local row indicies for external variables
79  int li_Pos; // positive node
80  int li_Neg; // negative node
81  int li_Branch; // branch equation
82  // offsets for jacobian enteries
88  std::vector< int > inductorCurrentOffsets;
89  // offsets for dependent variables
90  std::vector<int> ABraEquDepVarOffsets;
91  // keep track of which coupling coefficients' dependent vars map to
92  // our dependencies.
93  std::vector<std::pair<int,int> > depVarPairs;
94  // offsets only needed in nonlinear application
95  int magOffset;
98 
99 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
100  // Pointers for dFdx entries:
106  std::vector< double * > f_inductorCurrentPtrs;
107  // offsets for dependent variables
108  std::vector<double *> f_BraEquDepVarPtrs;
109 
110  // offsets only needed in nonlinear application
111  double * f_magPtr;
112  double * f_vPosPtr;
113  double * f_vNegPtr;
114 
115  // Pointers for dQdx entries:
121  std::vector< double * > q_inductorCurrentPtrs;
122  // offsets for dependent variables
123  std::vector<double *> q_BraEquDepVarPtrs;
124 
125  // offsets only needed in nonlinear application
126  double * q_magPtr;
127  double * q_vPosPtr;
128  double * q_vNegPtr;
129 #endif
130 };
131 
132 namespace MutIndLin {
133 
134 class Model;
135 class Instance;
136 
137 struct Traits : public DeviceTraits<Model, Instance>
138 {
139  static const char *name() {return "Linear Mutual Inductor";}
140  static const char *deviceTypeName() {return "K level 1";}
141  static int numNodes() {return 2;}
142  static const char *primaryParameter() {return "COUP_VAL";}
143  static bool isLinearDevice() {return true;}
144 
145  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
146  static void loadModelParameters(ParametricData<Model> &model_parameters);
147  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
148 };
149 
150 //-----------------------------------------------------------------------------
151 // Class : Instance
152 // Purpose : This is class refers to a single instance of the linear
153 // mutual inductor device.
154 // Special Notes :
155 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
156 // Creation Date : 3/21/05
157 //-----------------------------------------------------------------------------
158 
159 class Instance : public DeviceInstance
160 {
161  friend class ParametricData<Instance>;
162  friend class Model;
163  friend class Traits;friend class Master;
164 
165 public:
166 
167  Instance(
168  const Configuration & configuration,
169  const InstanceBlock & IB,
170  Model & Iiter,
171  const FactoryBlock & factory_block);
172 
173  ~Instance();
174 
175 private:
176  Instance(const Instance &);
177  Instance &operator=(const Instance &);
178 
179 public:
180  void registerLIDs( const std::vector<int> & intLIDVecRef,
181  const std::vector<int> & extLIDVecRef );
182 
183  std::map<int,std::string> & getIntNameMap ();
184  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
185 
186  const std::vector<std::string> & getDepSolnVars();
187 
188  const std::vector< std::vector<int> > & jacobianStamp() const;
189  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
190 
191  bool processParams ();
192  bool updateTemperature(const double & temp_tmp);
193  void updateInductanceMatrix();
194  bool updateIntermediateVars ();
195  bool updatePrimaryState ();
196  bool loadDeviceMask ();
197  bool setIC ();
198 
199  void varTypes( std::vector<char> & varTypeVec );
200 
201  void setupPointers();
202 
203  // load functions, residual:
204  bool loadDAEQVector ();
205  bool loadDAEFVector ();
206 
207  // load functions, Jacobian:
208  bool loadDAEdQdx ();
209  bool loadDAEdFdx ();
210 
211  void auxDAECalculations ();
212 
213  // iterator reference to the inductor model which owns this instance.
214  // Getters and setters
216  {
217  return model_;
218  }
219 
220 private:
221 
222  Model & model_; //< Owning model
223 
224  // This container bundles up the physical data for each inductor
225  // involved in this mutual inductor
227  std::vector< InductorInstanceData* > instanceData;
228 
229  // These vectors let the new param options load and set inductor data
230  // the parser passes all of these to us
231  std::vector< std::string > inductorNames;
232  std::vector< double > inductorInductances;
233  std::vector< std::string > inductorsNode1;
234  std::vector< std::string > inductorsNode2;
235  // and here's the list of ones we are coupling
236  std::vector< std::string > couplingInductor;
237  std::vector< double > couplingCoefficient;
238  //Pointers to expressions used by coupling coefficients
239  std::vector<N_UTL_Expression *> expPtrs;
240  // derivatives with respect to expression variables:
241  std::vector< std::vector<double> > couplingCoefficientVarDerivs;
242  std::vector< std::vector<double> > couplingCoefficientVarDerivsDDT;
243  // count of number of variables each coupling coefficient depends on
244  std::vector<int> numCoupDepVars;
245  std::vector< std::vector< double > > mutualCouplingCoef;
246  std::vector< std::vector< double > > mutualCouplingCoefDerivs;
247  std::vector<std::pair<int,int> > indexPairs;
248  std::vector<int> li_coupling; // for storage of coupling coeffs in
249  // state vector (needed for old DAE)
250  std::vector<std::vector<int> > li_couplingVarDerivs; // storing the derivatives
251  // of the coupling coefficients
252  // for old DAE
253  double mutualCup; // mutual coupling value
255 
256  std::vector< double > inductanceVals; // the inductances of the inductors
257  std::vector< std::vector< double > > LO; // L' * L (matrix)
258  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
259  std::vector< double > dIdt; // time derivatives of currents.
260  // (used by old DAE)
261  std::vector< double > LOI; // LO * I (col vector).
262 
263  double temp; // temperature of this instance
264  bool tempGiven; // flag if temp was given
265 
266  // scaling crontrol for new equations
267  double scalingRHS; // scaling for loading DAE or RHS components
268 
269  // this can't be static as each instance may have a different
270  // number of inductors in it so they'll each have a different
271  // size jacStamp
272  std::vector< std::vector<int> > jacStamp;
273 };
274 
275 //-----------------------------------------------------------------------------
276 // Class : Model
277 // Purpose :
278 // Special Notes :
279 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
280 // Creation Date : 3/21/05
281 //-----------------------------------------------------------------------------
282 class Model : public DeviceModel
283 {
284  typedef std::vector<Instance *> InstanceVector;
285 
286  friend class ParametricData<Model>;
287  friend class Instance;
288  friend class Traits;friend class Master;
289 
290 public:
291  Model(
292  const Configuration & configuration,
293  const ModelBlock & MB,
294  const FactoryBlock & factory_block);
295  ~Model();
296 
297 private:
298  Model();
299  Model(const Model &);
300  Model &operator=(const Model &);
301 
302 public:
303  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
304 
305  virtual std::ostream &printOutInstances(std::ostream &os) const;
306 
307  bool processParams ();
308  bool processInstanceParams ();
309 
310 
311 public:
312  void addInstance(Instance *instance)
313  {
314  instanceContainer.push_back(instance);
315  }
316 
317 private:
318  std::vector<Instance*> instanceContainer;
319 
320 private:
321 
322  double tempCoeff1; // first order temperature coeff.
323  double tempCoeff2; // second order temperature coeff.
324  double tnom; // reference temperature
325  // flags indicating if temperature parameters were given
326  bool tc1Given;
327  bool tc2Given;
328  bool tnomGiven;
329 };
330 
331 //-----------------------------------------------------------------------------
332 // Class : Master
333 // Purpose :
334 // Special Notes :
335 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
336 // Creation Date : 12/12/08
337 //-----------------------------------------------------------------------------
338 class Master : public DeviceMaster<Traits>
339 {
340  friend class Instance;
341  friend class Model;
342 
343 public:
345  const Configuration & configuration,
346  const FactoryBlock & factory_block,
347  const SolverState & ss1,
348  const DeviceOptions & do1)
349  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
350  {}
351 
352  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
353 
354  // new DAE stuff:
355  // new DAE load functions:
356  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
357  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
358 };
359 
360 void registerDevice();
361 
362 } // namespace MutIndLin
363 } // namespace Device
364 } // namespace Xyce
365 
369 
370 #endif
371