Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.90 $
40 //
41 // Revision Date : $Date: 2014/08/07 17:07:35 $
42 //
43 // Current Owner : $Author: rlschie $
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_RefCountPtrDecl.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  std::map<int,std::string> & getIntNameMap();
114  std::map<int,std::string> & getStateNameMap();
115  std::map<int,std::string> & getStoreNameMap();
116 
117  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
118  void registerStoreLIDs( const std::vector<int> & staLIDVecRef );
119 
120  const std::vector< std::vector<int> > & jacobianStamp() const;
121  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
122 
123  bool processParams ();
124  bool updateTemperature(const double & temp_tmp);
125  void updateInductanceMatrix();
126  bool updateIntermediateVars ();
127  bool updatePrimaryState ();
128  bool updateSecondaryState ();
129  bool setIC ();
130 
131  bool plotfileFlag () {return true;}
132 
133  void varTypes( std::vector<char> & varTypeVec );
134 
135  // load functions, residual:
136  bool loadDAEQVector ();
137  bool loadDAEFVector ();
138 
139  // DAE load functions, Jacobian:
140  bool loadDAEdQdx ();
141  bool loadDAEdFdx ();
142 
143  void auxDAECalculations ();
144 
145  bool outputPlotFiles ();
146 
147  // iterator reference to the inductor model which owns this instance.
148  // Getters and setters
150  {
151  return model_;
152  }
153 
154 private:
155 
156  Model & model_; //< Owning model
157 
158  // This container bundles up the physical data for each inductor
159  // involved in this mutual inductor
161  double L;
162  std::vector< InductorInstanceData* > instanceData;
163 
164  // These vectors let the new param options load and set inductor data
165  // the parser passes all of these to us
166  std::vector< std::string > inductorNames;
167  std::vector< double > inductorInductances;
168  std::vector< std::string > inductorsNode1;
169  std::vector< std::string > inductorsNode2;
170  // and here's the list of ones we are coupling
171  std::vector< std::string > couplingInductor;
172  std::vector< double > couplingCoefficient;
173  //std::vector< std::vector< double > > mutualCouplingCoef;
174 
175  // local indices for extra equations
177  int li_RVar;
178 
179  // offsets in the jacobian
181  std::vector< int > mEquInductorOffsets;
183 
185  std::vector< int > rEquInductorOffsets;
186 
187  // state variable for mag, h and r
193 
194  double nonlinFlag; // flag created by parser. Don't need it but must read it in
196  double mutualCup; // mutaul coupling value
198 
199  std::vector< double > inductanceVals; // the inductances of the inductors
200  std::vector< std::vector< double > > LO; // L' * L (matrix)
201  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
202  std::vector< double > LOI; // LO * I (col vector).
203 
204  double temp; // temperature of this instance
205  bool tempGiven; // flag if temp was given
206 
207  // intermediate values needed for nonlinear model
208  double qV;
209  double delM0; // modeling constant
210  double Happ;
211  double He;
212  double Heo;
213  double delM;
214  double Mirrp;
215  double Manp;
216  double P;
217  double dP_dM;
218  double dP_dVp;
219  double dP_dVn;
220 
221  // variables for limiting of non-linear, internal vars
222  double Mag_orig;
223  double Rvar_orig;
224 
225  // these vectors are used repeadily in loadDAEdFdx
226  // so rather than create and destroy them on each call
227  // we will allocate them in the constructor.
228  std::vector< double > dHe_dI;
229  std::vector< double > dManp_dI;
230  std::vector< double > ddelM_dI;
231  std::vector< double > dMirrp_dI;
232  std::vector< double > dP_dI;
233 
234  // scaling crontrol for new equations
235  double scalingRHS; // scaling for loading DAE or RHS components
236 
237  // used in scaling the tanh() approximation to sgn()
239 
240  std::vector< std::vector<int> > jacStamp;
241 
242  // output stream for output of internal state if requested by user
243  Teuchos::RefCountPtr< std::ofstream > outputFileStreamPtr;
245 };
246 
247 //-----------------------------------------------------------------------------
248 // Class : Model
249 // Purpose :
250 // Special Notes :
251 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
252 // Creation Date : 3/21/05
253 //-----------------------------------------------------------------------------
254 class Model : public DeviceModel
255 {
256  typedef std::vector<Instance *> InstanceVector;
257 
258  friend class ParametricData<Model>;
259  friend class Instance;
260  friend class Traits;friend class Master;
261 
262 public:
263  Model(
264  const Configuration & configuration,
265  const ModelBlock & MB,
266  const FactoryBlock & factory_block);
267  ~Model();
268 
269 private:
270  Model();
271  Model(const Model &);
272  Model &operator=(const Model &);
273 
274 public:
275  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
276 
277  virtual std::ostream &printOutInstances(std::ostream &os) const;
278 
279  bool processParams ();
280  bool processInstanceParams ();
281 
282  // Data Members for Associations
283 
284 public:
285  void addInstance(Instance *instance)
286  {
287  instanceContainer.push_back(instance);
288  }
289 
290 private:
291  std::vector<Instance*> instanceContainer;
292 
293 private:
294 
295  double A; // Thermal energy parameter (amp/m)
296  double Alpha; // domain coupling parameter (dimensionless)
297  double Area; // mean magnetic cross-sectional area (m^2)
298  double BetaH; // modeling constant (dimensionless)
299  double BetaM; // modeling constant (dimensionless)
300  double C; // domain flesing parameter (dimensionless)
301  double CLim; // Value below which domain flesing parameter (dimensionless) will be treated as zero.
302  double DeltaVScaling; // smoothing coefficient for V_1 in tanh
303  double Gap; // effective air gap (m)
304  double Kirr; // domain anisotropy parameter (amp/m)
305  double Ms; // saturation magnetization (amp/m)
306  double LevelIgnored; // for pspice compatibility -- ignored
307  double PackIgnored; // for pspice compatibility -- ignored
308  double Path; // total mean magnetic path (m)
309  double tempCoeff1; // first order temperature coeff.
310  double tempCoeff2; // second order temperature coeff.
311  double tnom; // reference temperature
312  double pZeroTol; // absolute value below which to consider P=0
313  double HCgsFactor; // conversion factor to change H from SI units to CGS units (H/M to Oersted)
314  double BCgsFactor; // conversion factor to change B form SI units (Tesla) to CGS units (Gauss)
315  double mVarScaling; // scaling for M variable
316  double rVarScaling; // scaling for R variable
317  double mEqScaling; // scaling for M equation
318  double rEqScaling; // scaling for r equation
319  int outputStateVars; // flag indicating if user wants M,H and R output
320  int factorMS; // flag to factor Ms out of M
321  int BHSiUnits; // flag to indicate that B and H should be output in SI units. Default is CGS
322  // units for output while SI units are used for calculations.
323 
324  // flags indicating if temperature parameters were given
325  bool tc1Given;
326  bool tc2Given;
327  bool tnomGiven;
331 };
332 
333 //-----------------------------------------------------------------------------
334 // Class : Master
335 // Purpose :
336 // Special Notes :
337 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
338 // Creation Date : 11/26/08
339 //-----------------------------------------------------------------------------
340 class Master : public DeviceMaster<Traits>
341 {
342  friend class Instance;
343  friend class Model;
344 
345 public:
347  const Configuration & configuration,
348  const FactoryBlock & factory_block,
349  const SolverState & ss1,
350  const DeviceOptions & do1)
351  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
352  {}
353 
354  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
355  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
356 
357  // load functions, residual:
358  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
359 
360  // load functions, Jacobian:
361  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
362 };
363 
364 void registerDevice();
365 
366 } // namespace MutIndNonLin
367 } // namespace Device
368 } // namespace Xyce
369 
373 
374 #endif