Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_MutIndNonLin2.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_MutIndNonLin2.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.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_MutIndNonLin2_h
47 #define Xyce_N_DEV_MutIndNonLin2_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_Const.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 #include <N_DEV_MutIndLin.h>
56 
57 #include <N_DEV_MutIndNonLin.h>
58 
59 #include <Teuchos_RefCountPtrDecl.hpp>
60 #include <Sacado.hpp>
61 #include <fstream>
62 
63 namespace Xyce {
64 namespace Device {
65 namespace MutIndNonLin2 {
66 
67 class Model;
68 class Instance;
69 
70 struct Traits : public DeviceTraits<Model, Instance, MutIndNonLin::Traits>
71 {
72  static const char *name() {return "Nonlinear Mutual Inductor";}
73  static const char *deviceTypeName() {return "K level 2";}
74  static int numNodes() {return 2;}
75  static bool modelRequired() {return true;}
76  static bool isLinearDevice() {return false;}
77 
78  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
79  static void loadModelParameters(ParametricData<Model> &model_parameters);
80  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
81 };
82 
83 //-----------------------------------------------------------------------------
84 // Class : Instance
85 // Purpose : This is class refers to a single instance of the nonlinear
86 // mutual inductor device.
87 // Special Notes :
88 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
89 // Creation Date : 3/21/05
90 //-----------------------------------------------------------------------------
91 
92 class Instance : public DeviceInstance
93 {
94  friend class ParametricData<Instance>;
95  friend class Model;
96  friend class Traits;
97 
98 public:
99 
100  Instance(
101  const Configuration & configuration,
102  const InstanceBlock & IB,
103  Model & Iiter,
104  const FactoryBlock & factory_block);
105 
106  ~Instance();
107 
108 private:
109  Instance(const Instance &);
110  Instance &operator=(const Instance &);
111 
112 public:
113  void registerLIDs( const std::vector<int> & intLIDVecRef,
114  const std::vector<int> & extLIDVecRef );
115  std::map<int,std::string> & getIntNameMap();
116  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
117 
118  const std::vector< std::vector<int> > & jacobianStamp() const;
119  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
120 
121  bool processParams ();
122  bool updateTemperature(const double & temp_tmp);
123  void updateInductanceMatrix();
124  bool updateIntermediateVars ();
125  bool updatePrimaryState ();
126  bool updateSecondaryState ();
127  bool loadDeviceMask();
128  bool setIC ();
129 
130  bool plotfileFlag () {return true;}
131 
132  void varTypes( std::vector<char> & varTypeVec );
133 
134  void acceptStep();
135 
136  // load functions, residual:
137  bool loadDAEQVector ();
138  bool loadDAEFVector ();
139 
140  // load functions, Jacobian:
141  bool loadDAEdQdx ();
142  bool loadDAEdFdx ();
143 
144  void auxDAECalculations ();
145 
146  bool outputPlotFiles ();
147 
148  // iterator reference to the inductor model which owns this instance.
149  // Getters and setters
151  {
152  return model_;
153  }
154 
155 private:
156 
157  Model & model_; //< Owning model
158 
159  // This container bundles up the physical data for each inductor
160  // involved in this mutual inductor
162  double L;
163  std::vector< InductorInstanceData* > instanceData;
164 
165  // These vectors let the new param options load and set inductor data
166  // the parser passes all of these to us
167  std::vector< std::string > inductorNames;
168  std::vector< double > inductorInductances;
169  std::vector< std::string > inductorsNode1;
170  std::vector< std::string > inductorsNode2;
171  // and here's the list of ones we are coupling
172  std::vector< std::string > couplingInductor;
173  std::vector< double > couplingCoefficient;
174  //std::vector< std::vector< double > > mutualCouplingCoef;
175 
176  // local indices for extra equations
177  //int li_deltaHappVar;
179 
180  // offsets in the jacobian
181  //int deltaHappEquDeltaHappOffset;
182  //std::vector< int > deltaHappEquInductorOffsets;
183 
185  //int deltaMEquDeltaHappOffset;
186  std::vector< int > deltaMEquInductorOffsets;
187 
188  double nonlinFlag; // flag created by parser. Don't need it but must read it in
190  double mutualCup; // mutaul coupling value
192 
193  std::vector< double > inductanceVals; // the inductances of the inductors
194  std::vector< std::vector< double > > LO; // L' * L (matrix)
195  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
196  std::vector< double > LOI; // LO * I (col vector).
197 
198  double temp; // temperature of this instance
199  bool tempGiven; // flag if temp was given
200 
203  double P;
205  double dP_dM;
207  double dP_dV1Pos;
208  double dP_dV1Neg;
209  double mEquFval;
210  std::vector<double> dHe_dI;
211  std::vector<double> dManp_dI;
212  std::vector<double> ddelM_dI;
213  std::vector<double> dMirrp_dI;
214  std::vector<double> dP_dI;
215  double MagVar;
216  double oldBranchCurrentSum; // last branch current sum.
217  double MagVarUpdate;
220  std::vector<double> branchCurrentSumHistory; // these two vectors are used for 4th order RK
221  std::vector<double> PFunctionHistory; // integration of dM/dH.
222 
223  bool includeDeltaM; // flag to include deltaM in solution
224 
225  // non static jacStamp as each mutual inductor will have a variable number of components
226  std::vector< std::vector<int> > jacStamp;
227 
228  // output stream for output of internal state if requested by user
229  Teuchos::RefCountPtr< std::ofstream > outputFileStreamPtr;
231 
232  // this is a templated function for a complicated term P(M,I_1... I_n) that relates
233  // the magnetic saturation of the mutual indcutor to the individual currents
234  // through the inductors. We'll need dP_dM and this tempated function automates
235  // that calculation via Sacado
236  template <typename ScalarT>
237  ScalarT Pcalc( const ScalarT & Mag, const ScalarT & CurrentSum, const ScalarT & Vpos, const ScalarT & Vneg);
238 };
239 
240 //-----------------------------------------------------------------------------
241 // Class : Model
242 // Purpose :
243 // Special Notes :
244 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
245 // Creation Date : 3/21/05
246 //-----------------------------------------------------------------------------
247 class Model : public DeviceModel
248 {
249  typedef std::vector<Instance *> InstanceVector;
250 
251  friend class ParametricData<Model>;
252  friend class Instance;
253  friend class Traits;
254 
255 public:
256  Model(
257  const Configuration & configuration,
258  const ModelBlock & MB,
259  const FactoryBlock & factory_block);
260  ~Model();
261 
262 private:
263  Model();
264  Model(const Model &);
265  Model &operator=(const Model &);
266 
267 public:
268  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
269 
270  virtual std::ostream &printOutInstances(std::ostream &os) const;
271 
272  bool processParams ();
273  bool processInstanceParams ();
274 
275  // Data Members for Associations
276 
277 public:
278  void addInstance(Instance *instance)
279  {
280  instanceContainer.push_back(instance);
281  }
282 
283 private:
284  std::vector<Instance*> instanceContainer;
285 
286 private:
287 
288  double A; // Thermal energy parameter (amp/m)
289  double Alpha; // domain coupling parameter (dimensionless)
290  double Area; // mean magnetic cross-sectional area (m^2)
291  double BetaH; // modeling constant (dimensionless)
292  double BetaM; // modeling constant (dimensionless)
293  double C; // domain flesing parameter (dimensionless)
294  double DeltaV; // smoothing coefficient for V_1 in tanh
295  double Gap; // effective air gap (m)
296  double Kirr; // domain anisotropy parameter (amp/m)
297  double Ms; // saturation magnetization (amp/m)
298  double LevelIgnored; // for pspice compatibility -- ignored
299  double PackIgnored; // for pspice compatibility -- ignored
300  double Path; // total mean magnetic path (m)
301  double Vinf; // smoothing coefficient for V+1 in tanh
302  double tempCoeff1; // first order temperature coeff.
303  double tempCoeff2; // second order temperature coeff.
304  double tnom; // reference temperature
305  double pZeroTol; // absolute value below which to consider P=0
306  double mVarScaling; // scaling for M variable
307  double rVarScaling; // scaling for R variable
308  double mEqScaling; // scaling for M equation
309  double rEqScaling; // scaling for r equation
310  int outputStateVars; // flag indicating if user wants M,H and R output
311 
312  int factorMS; // flag to factor Ms out of M (not used in level 2)
313  int includeDeltaM; // flag to make delta M calculation implicit
314  int useRKIntegration; // flag to use 4th order runga-kutta for dM/dH integration
315  int useStateDeriv; // flag to use state vector for dH/dt calculation
316  int voltageLimiterFlag; // flag indicating that we should use limiting on internal vars Mag and R
317  double magLimitThres; // iteration threshold overwhich changes in Mag var are limited
318  double rLimitThres; // iteration threshold over which changes in R var are limited
319 
320  // flags indicating if temperature parameters were given
321  bool tc1Given;
322  bool tc2Given;
323  bool tnomGiven;
326 };
327 
328 void registerDevice();
329 
330 } // namespace MutIndNonLin2
331 } // namespace Device
332 } // namespace Xyce
333 
336 
337 #endif