Xyce  6.1
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-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_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.80.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:11 $
42 //
43 // Current Owner : $Author: tvrusso $
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  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
184 
185  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
186 
187  const std::vector<std::string> & getDepSolnVars();
188 
189  const std::vector< std::vector<int> > & jacobianStamp() const;
190  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
191 
192  bool processParams ();
193  bool updateTemperature(const double & temp_tmp);
194  void updateInductanceMatrix();
195  bool updateIntermediateVars ();
196  bool updatePrimaryState ();
197  void loadErrorWeightMask ();
198  bool setIC ();
199 
200  void varTypes( std::vector<char> & varTypeVec );
201 
202  void setupPointers();
203 
204  // load functions, residual:
205  bool loadDAEQVector ();
206  bool loadDAEFVector ();
207 
208  // load functions, Jacobian:
209  bool loadDAEdQdx ();
210  bool loadDAEdFdx ();
211 
212  void auxDAECalculations ();
213 
214  // iterator reference to the inductor model which owns this instance.
215  // Getters and setters
217  {
218  return model_;
219  }
220 
221 private:
222 
223  Model & model_; //< Owning model
224 
225  // This container bundles up the physical data for each inductor
226  // involved in this mutual inductor
228  std::vector< InductorInstanceData* > instanceData;
229 
230  // These vectors let the new param options load and set inductor data
231  // the parser passes all of these to us
232  std::vector< std::string > inductorNames;
233  std::vector< double > inductorInductances;
234  std::vector< std::string > inductorsNode1;
235  std::vector< std::string > inductorsNode2;
236  // and here's the list of ones we are coupling
237  std::vector< std::string > couplingInductor;
238  std::vector< double > couplingCoefficient;
239  //Pointers to expressions used by coupling coefficients
240  std::vector<Util::Expression *> expPtrs;
241  // derivatives with respect to expression variables:
242  std::vector< std::vector<double> > couplingCoefficientVarDerivs;
243  std::vector< std::vector<double> > couplingCoefficientVarDerivsDDT;
244  // count of number of variables each coupling coefficient depends on
245  std::vector<int> numCoupDepVars;
246  std::vector< std::vector< double > > mutualCouplingCoef;
247  std::vector< std::vector< double > > mutualCouplingCoefDerivs;
248  std::vector<std::pair<int,int> > indexPairs;
249  std::vector<int> li_coupling; // for storage of coupling coeffs in
250  // state vector (needed for old DAE)
251  std::vector<std::vector<int> > li_couplingVarDerivs; // storing the derivatives
252  // of the coupling coefficients
253  // for old DAE
254  double mutualCup; // mutual coupling value
256 
257  std::vector< double > inductanceVals; // the inductances of the inductors
258  std::vector< std::vector< double > > LO; // L' * L (matrix)
259  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
260  std::vector< double > dIdt; // time derivatives of currents.
261  // (used by old DAE)
262  std::vector< double > LOI; // LO * I (col vector).
263 
264  double temp; // temperature of this instance
265  bool tempGiven; // flag if temp was given
266 
267  // scaling crontrol for new equations
268  double scalingRHS; // scaling for loading DAE or RHS components
269 
270  // this can't be static as each instance may have a different
271  // number of inductors in it so they'll each have a different
272  // size jacStamp
273  std::vector< std::vector<int> > jacStamp;
274 };
275 
276 //-----------------------------------------------------------------------------
277 // Class : Model
278 // Purpose :
279 // Special Notes :
280 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
281 // Creation Date : 3/21/05
282 //-----------------------------------------------------------------------------
283 class Model : public DeviceModel
284 {
285  typedef std::vector<Instance *> InstanceVector;
286 
287  friend class ParametricData<Model>;
288  friend class Instance;
289  friend class Traits;friend class Master;
290 
291 public:
292  Model(
293  const Configuration & configuration,
294  const ModelBlock & MB,
295  const FactoryBlock & factory_block);
296  ~Model();
297 
298 private:
299  Model();
300  Model(const Model &);
301  Model &operator=(const Model &);
302 
303 public:
304  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
305 
306  virtual std::ostream &printOutInstances(std::ostream &os) const;
307 
308  bool processParams ();
309  bool processInstanceParams ();
310 
311 
312 public:
313  void addInstance(Instance *instance)
314  {
315  instanceContainer.push_back(instance);
316  }
317 
318 private:
319  std::vector<Instance*> instanceContainer;
320 
321 private:
322 
323  double tempCoeff1; // first order temperature coeff.
324  double tempCoeff2; // second order temperature coeff.
325  double tnom; // reference temperature
326  // flags indicating if temperature parameters were given
327  bool tc1Given;
328  bool tc2Given;
329  bool tnomGiven;
330 };
331 
332 //-----------------------------------------------------------------------------
333 // Class : Master
334 // Purpose :
335 // Special Notes :
336 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
337 // Creation Date : 12/12/08
338 //-----------------------------------------------------------------------------
339 class Master : public DeviceMaster<Traits>
340 {
341  friend class Instance;
342  friend class Model;
343 
344 public:
346  const Configuration & configuration,
347  const FactoryBlock & factory_block,
348  const SolverState & ss1,
349  const DeviceOptions & do1)
350  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
351  {}
352 
353  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
354 
355  // new DAE stuff:
356  // new DAE load functions:
357  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
358  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
359 };
360 
361 void registerDevice();
362 
363 } // namespace MutIndLin
364 } // namespace Device
365 } // namespace Xyce
366 
367 #endif
368 
std::vector< std::vector< int > > li_couplingVarDerivs
std::vector< double * > f_inductorCurrentPtrs
std::vector< std::vector< double > > mutualCouplingCoef
std::vector< Instance * > InstanceVector
static const char * primaryParameter()
Pure virtual class to augment a linear system.
const std::vector< std::string > & getDepSolnVars()
std::vector< std::vector< int > > jacStamp
std::vector< int > ABraEquDepVarOffsets
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
std::vector< std::vector< double > > couplingCoefficientVarDerivs
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
const std::vector< std::vector< int > > & jacobianStamp() const
std::vector< std::string > inductorsNode1
std::vector< std::string > inductorNames
bool updateTemperature(const double &temp_tmp)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Iiter, const FactoryBlock &factory_block)
void addInstance(Instance *instance)
DeviceMaster instantiates a device as described by the device traits T.
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
std::vector< std::vector< double > > couplingCoefficientVarDerivsDDT
bool processInstanceParams()
processInstanceParams
void varTypes(std::vector< char > &varTypeVec)
std::vector< double * > f_BraEquDepVarPtrs
std::vector< std::string > couplingInductor
std::vector< std::pair< int, int > > depVarPairs
std::vector< double > inductorCurrents
static void loadModelParameters(ParametricData< Model > &model_parameters)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Populates the device's ExternData object with these pointers.
bool processParams()
processParams
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static const char * deviceTypeName()
std::vector< double * > q_BraEquDepVarPtrs
std::vector< double > inductanceVals
Class Configuration contains device configuration data.
virtual std::ostream & printOutInstances(std::ostream &os) const
std::vector< int > inductorCurrentOffsets
std::vector< double > inductorInductances
Instance & operator=(const Instance &)
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
std::vector< double * > q_inductorCurrentPtrs
std::vector< double > couplingCoefficient
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
std::vector< std::pair< int, int > > indexPairs
ModelBlock represents a .MODEL line from the netlist.
std::vector< Util::Expression * > expPtrs
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.
std::vector< Instance * > instanceContainer
Model & operator=(const Model &)
std::vector< std::vector< double > > LO
std::vector< std::vector< double > > mutualCouplingCoefDerivs
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
std::vector< InductorInstanceData * > instanceData
std::vector< std::string > inductorsNode2
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)