Xyce  6.1
N_DEV_MutIndNonLin.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_MutIndNonLin.h,v $
27 //
28 // Purpose : Non-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.95.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_MutIndNonLin_h
47 #define Xyce_N_DEV_MutIndNonLin_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceBlock.h>
52 #include <N_DEV_DeviceInstance.h>
53 #include <N_DEV_DeviceModel.h>
54 
55 // defines simple container InductorInstanceData
56 #include <N_DEV_MutIndLin.h>
57 
58 #include <Teuchos_RCP.hpp>
59 #include <fstream>
60 
61 namespace Xyce {
62 namespace Device {
63 namespace MutIndNonLin {
64 
65 class Model;
66 class Instance;
67 
68 struct Traits : public DeviceTraits<Model, Instance>
69 {
70  static const char *name() {return "Nonlinear Mutual Inductor";}
71  static const char *deviceTypeName() {return "K level 1";}
72  static int numNodes() {return 2;}
73  static bool modelRequired() {return true;}
74  static bool isLinearDevice() {return false;}
75 
76  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
77  static void loadModelParameters(ParametricData<Model> &model_parameters);
78  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
79 };
80 
81 //-----------------------------------------------------------------------------
82 // Class : Instance
83 // Purpose : This is class refers to a single instance of the nonlinear
84 // mutual inductor device.
85 // Special Notes :
86 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
87 // Creation Date : 3/21/05
88 //-----------------------------------------------------------------------------
89 
90 class Instance : public DeviceInstance
91 {
92  friend class ParametricData<Instance>;
93  friend class Model;
94  friend class Traits;friend class Master;
95 
96 public:
97 
98  Instance(
99  const Configuration & configuration,
100  const InstanceBlock & IB,
101  Model & Iiter,
102  const FactoryBlock & factory_block);
103 
104  ~Instance();
105 
106 private:
107  Instance(const Instance &);
108  Instance &operator=(const Instance &);
109 
110 public:
111  void registerLIDs( const std::vector<int> & intLIDVecRef,
112  const std::vector<int> & extLIDVecRef );
113 
114  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
115 
116  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
117  void registerStoreLIDs( const std::vector<int> & staLIDVecRef );
118 
119  const std::vector< std::vector<int> > & jacobianStamp() const;
120  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
121 
122  bool processParams ();
123  bool updateTemperature(const double & temp_tmp);
124  void updateInductanceMatrix();
125  bool updateIntermediateVars ();
126  bool updatePrimaryState ();
127  bool updateSecondaryState ();
128  bool setIC ();
129 
130  bool plotfileFlag () {return true;}
131 
132  void varTypes( std::vector<char> & varTypeVec );
133 
134  // load functions, residual:
135  bool loadDAEQVector ();
136  bool loadDAEFVector ();
137 
138  // DAE load functions, Jacobian:
139  bool loadDAEdQdx ();
140  bool loadDAEdFdx ();
141 
142  void auxDAECalculations ();
143 
144  bool outputPlotFiles ();
145 
146  // iterator reference to the inductor model which owns this instance.
147  // Getters and setters
149  {
150  return model_;
151  }
152 
153 private:
154 
155  Model & model_; //< Owning model
156 
157  // This container bundles up the physical data for each inductor
158  // involved in this mutual inductor
160  double L;
161  std::vector< InductorInstanceData* > instanceData;
162 
163  // These vectors let the new param options load and set inductor data
164  // the parser passes all of these to us
165  std::vector< std::string > inductorNames;
166  std::vector< double > inductorInductances;
167  std::vector< std::string > inductorsNode1;
168  std::vector< std::string > inductorsNode2;
169  // and here's the list of ones we are coupling
170  std::vector< std::string > couplingInductor;
171  std::vector< double > couplingCoefficient;
172  //std::vector< std::vector< double > > mutualCouplingCoef;
173 
174  // local indices for extra equations
176  int li_RVar;
177 
178  // offsets in the jacobian
180  std::vector< int > mEquInductorOffsets;
182 
184  std::vector< int > rEquInductorOffsets;
185 
186  // state variable for mag, h and r
192 
193  double nonlinFlag; // flag created by parser. Don't need it but must read it in
195  double mutualCup; // mutaul coupling value
197 
198  std::vector< double > inductanceVals; // the inductances of the inductors
199  std::vector< std::vector< double > > LO; // L' * L (matrix)
200  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
201  std::vector< double > LOI; // LO * I (col vector).
202 
203  double temp; // temperature of this instance
204  bool tempGiven; // flag if temp was given
205 
206  // intermediate values needed for nonlinear model
207  double qV;
208  double delM0; // modeling constant
209  double Happ;
210  double He;
211  double Heo;
212  double delM;
213  double Mirrp;
214  double Manp;
215  double P;
216  double dP_dM;
217  double dP_dVp;
218  double dP_dVn;
219 
220  // variables for limiting of non-linear, internal vars
221  double Mag_orig;
222  double Rvar_orig;
223 
224  // these vectors are used repeadily in loadDAEdFdx
225  // so rather than create and destroy them on each call
226  // we will allocate them in the constructor.
227  std::vector< double > dHe_dI;
228  std::vector< double > dManp_dI;
229  std::vector< double > ddelM_dI;
230  std::vector< double > dMirrp_dI;
231  std::vector< double > dP_dI;
232 
233  // scaling crontrol for new equations
234  double scalingRHS; // scaling for loading DAE or RHS components
235 
236  // used in scaling the tanh() approximation to sgn()
238 
239  std::vector< std::vector<int> > jacStamp;
240 
241  // output stream for output of internal state if requested by user
242  Teuchos::RCP< std::ofstream > outputFileStreamPtr;
244 };
245 
246 //-----------------------------------------------------------------------------
247 // Class : Model
248 // Purpose :
249 // Special Notes :
250 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
251 // Creation Date : 3/21/05
252 //-----------------------------------------------------------------------------
253 class Model : public DeviceModel
254 {
255  typedef std::vector<Instance *> InstanceVector;
256 
257  friend class ParametricData<Model>;
258  friend class Instance;
259  friend class Traits;friend class Master;
260 
261 public:
262  Model(
263  const Configuration & configuration,
264  const ModelBlock & MB,
265  const FactoryBlock & factory_block);
266  ~Model();
267 
268 private:
269  Model();
270  Model(const Model &);
271  Model &operator=(const Model &);
272 
273 public:
274  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
275 
276  virtual std::ostream &printOutInstances(std::ostream &os) const;
277 
278  bool processParams ();
279  bool processInstanceParams ();
280 
281  // Data Members for Associations
282 
283 public:
284  void addInstance(Instance *instance)
285  {
286  instanceContainer.push_back(instance);
287  }
288 
289 private:
290  std::vector<Instance*> instanceContainer;
291 
292 private:
293 
294  double A; // Thermal energy parameter (amp/m)
295  double Alpha; // domain coupling parameter (dimensionless)
296  double Area; // mean magnetic cross-sectional area (m^2)
297  double BetaH; // modeling constant (dimensionless)
298  double BetaM; // modeling constant (dimensionless)
299  double C; // domain flesing parameter (dimensionless)
300  double CLim; // Value below which domain flesing parameter (dimensionless) will be treated as zero.
301  double DeltaVScaling; // smoothing coefficient for V_1 in tanh
302  double Gap; // effective air gap (m)
303  double Kirr; // domain anisotropy parameter (amp/m)
304  double Ms; // saturation magnetization (amp/m)
305  double LevelIgnored; // for pspice compatibility -- ignored
306  double PackIgnored; // for pspice compatibility -- ignored
307  double Path; // total mean magnetic path (m)
308  double tempCoeff1; // first order temperature coeff.
309  double tempCoeff2; // second order temperature coeff.
310  double tnom; // reference temperature
311  double pZeroTol; // absolute value below which to consider P=0
312  double HCgsFactor; // conversion factor to change H from SI units to CGS units (H/M to Oersted)
313  double BCgsFactor; // conversion factor to change B form SI units (Tesla) to CGS units (Gauss)
314  double mVarScaling; // scaling for M variable
315  double rVarScaling; // scaling for R variable
316  double mEqScaling; // scaling for M equation
317  double rEqScaling; // scaling for r equation
318  int outputStateVars; // flag indicating if user wants M,H and R output
319  int factorMS; // flag to factor Ms out of M
320  int BHSiUnits; // flag to indicate that B and H should be output in SI units. Default is CGS
321  // units for output while SI units are used for calculations.
322 
323  // flags indicating if temperature parameters were given
324  bool tc1Given;
325  bool tc2Given;
326  bool tnomGiven;
330 };
331 
332 //-----------------------------------------------------------------------------
333 // Class : Master
334 // Purpose :
335 // Special Notes :
336 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
337 // Creation Date : 11/26/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  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
355 
356  // load functions, residual:
357  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
358 
359  // load functions, Jacobian:
360  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
361 };
362 
363 void registerDevice();
364 
365 } // namespace MutIndNonLin
366 } // namespace Device
367 } // namespace Xyce
368 
369 #endif
std::vector< std::string > inductorNames
void varTypes(std::vector< char > &varTypeVec)
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
void registerStoreLIDs(const std::vector< int > &staLIDVecRef)
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Pure virtual class to augment a linear system.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
std::vector< Instance * > instanceContainer
Instance & operator=(const Instance &)
std::vector< std::vector< double > > LO
Teuchos::RCP< std::ofstream > outputFileStreamPtr
DeviceMaster instantiates a device as described by the device traits T.
std::vector< std::string > inductorsNode2
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
bool processInstanceParams()
processInstanceParams
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
std::vector< std::string > inductorsNode1
Class Configuration contains device configuration data.
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.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
bool updateTemperature(const double &temp_tmp)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Iiter, const FactoryBlock &factory_block)
virtual std::ostream & printOutInstances(std::ostream &os) const
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
void addInstance(Instance *instance)
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
std::vector< std::string > couplingInductor
std::vector< std::vector< int > > jacStamp
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
std::vector< Instance * > InstanceVector
InstanceBlock represent a device instance line from the netlist.
Model & operator=(const Model &)
const std::vector< std::vector< int > > & jacobianStamp() const
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
std::vector< InductorInstanceData * > instanceData
static void loadModelParameters(ParametricData< Model > &model_parameters)