Xyce  6.1
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-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_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.35 $
40 //
41 // Revision Date : $Date: 2015/04/24 20:25:45 $
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_RCP.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 
116  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
117 
118  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
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  void acceptStep();
136 
137  // load functions, residual:
138  bool loadDAEQVector ();
139  bool loadDAEFVector ();
140 
141  // load functions, Jacobian:
142  bool loadDAEdQdx ();
143  bool loadDAEdFdx ();
144 
145  void auxDAECalculations ();
146 
147  bool outputPlotFiles(bool force_final_output);
148 
149  // iterator reference to the inductor model which owns this instance.
150  // Getters and setters
152  {
153  return model_;
154  }
155 
156 private:
157 
158  Model & model_; //< Owning model
159 
160  // This container bundles up the physical data for each inductor
161  // involved in this mutual inductor
163  double L;
164  std::vector< InductorInstanceData* > instanceData;
165 
166  // These vectors let the new param options load and set inductor data
167  // the parser passes all of these to us
168  std::vector< std::string > inductorNames;
169  std::vector< double > inductorInductances;
170  std::vector< std::string > inductorsNode1;
171  std::vector< std::string > inductorsNode2;
172  // and here's the list of ones we are coupling
173  std::vector< std::string > couplingInductor;
174  std::vector< double > couplingCoefficient;
175  //std::vector< std::vector< double > > mutualCouplingCoef;
176 
177  // local indices for extra equations
178  //int li_deltaHappVar;
180 
181  // offsets in the jacobian
182  //int deltaHappEquDeltaHappOffset;
183  //std::vector< int > deltaHappEquInductorOffsets;
184 
186  //int deltaMEquDeltaHappOffset;
187  std::vector< int > deltaMEquInductorOffsets;
188 
189  double nonlinFlag; // flag created by parser. Don't need it but must read it in
191  double mutualCup; // mutaul coupling value
193 
194  std::vector< double > inductanceVals; // the inductances of the inductors
195  std::vector< std::vector< double > > LO; // L' * L (matrix)
196  std::vector< double > inductorCurrents; // currents through inductors (col vec.)
197  std::vector< double > LOI; // LO * I (col vector).
198 
199  double temp; // temperature of this instance
200  bool tempGiven; // flag if temp was given
201 
204  double P;
206  double dP_dM;
208  double dP_dV1Pos;
209  double dP_dV1Neg;
210  double mEquFval;
211  std::vector<double> dHe_dI;
212  std::vector<double> dManp_dI;
213  std::vector<double> ddelM_dI;
214  std::vector<double> dMirrp_dI;
215  std::vector<double> dP_dI;
216  double MagVar;
217  double oldBranchCurrentSum; // last branch current sum.
218  double MagVarUpdate;
221  std::vector<double> branchCurrentSumHistory; // these two vectors are used for 4th order RK
222  std::vector<double> PFunctionHistory; // integration of dM/dH.
223 
224  bool includeDeltaM; // flag to include deltaM in solution
225 
226  // non static jacStamp as each mutual inductor will have a variable number of components
227  std::vector< std::vector<int> > jacStamp;
228 
229  // output stream for output of internal state if requested by user
230  Teuchos::RCP< std::ofstream > outputFileStreamPtr;
232 
233  // this is a templated function for a complicated term P(M,I_1... I_n) that relates
234  // the magnetic saturation of the mutual indcutor to the individual currents
235  // through the inductors. We'll need dP_dM and this tempated function automates
236  // that calculation via Sacado
237  template <typename ScalarT>
238  ScalarT Pcalc( const ScalarT & Mag, const ScalarT & CurrentSum, const ScalarT & Vpos, const ScalarT & Vneg);
239 };
240 
241 //-----------------------------------------------------------------------------
242 // Class : Model
243 // Purpose :
244 // Special Notes :
245 // Creator : Rich Schiek, SNL, Parallel Computational Sciences
246 // Creation Date : 3/21/05
247 //-----------------------------------------------------------------------------
248 class Model : public DeviceModel
249 {
250  typedef std::vector<Instance *> InstanceVector;
251 
252  friend class ParametricData<Model>;
253  friend class Instance;
254  friend class Traits;
255 
256 public:
257  Model(
258  const Configuration & configuration,
259  const ModelBlock & MB,
260  const FactoryBlock & factory_block);
261  ~Model();
262 
263 private:
264  Model();
265  Model(const Model &);
266  Model &operator=(const Model &);
267 
268 public:
269  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
270 
271  virtual std::ostream &printOutInstances(std::ostream &os) const;
272 
273  bool processParams ();
274  bool processInstanceParams ();
275 
276  // Data Members for Associations
277 
278 public:
279  void addInstance(Instance *instance)
280  {
281  instanceContainer.push_back(instance);
282  }
283 
284 private:
285  std::vector<Instance*> instanceContainer;
286 
287 private:
288 
289  double A; // Thermal energy parameter (amp/m)
290  double Alpha; // domain coupling parameter (dimensionless)
291  double Area; // mean magnetic cross-sectional area (m^2)
292  double BetaH; // modeling constant (dimensionless)
293  double BetaM; // modeling constant (dimensionless)
294  double C; // domain flesing parameter (dimensionless)
295  double DeltaV; // smoothing coefficient for V_1 in tanh
296  double Gap; // effective air gap (m)
297  double Kirr; // domain anisotropy parameter (amp/m)
298  double Ms; // saturation magnetization (amp/m)
299  double LevelIgnored; // for pspice compatibility -- ignored
300  double PackIgnored; // for pspice compatibility -- ignored
301  double Path; // total mean magnetic path (m)
302  double Vinf; // smoothing coefficient for V+1 in tanh
303  double tempCoeff1; // first order temperature coeff.
304  double tempCoeff2; // second order temperature coeff.
305  double tnom; // reference temperature
306  double pZeroTol; // absolute value below which to consider P=0
307  double mVarScaling; // scaling for M variable
308  double rVarScaling; // scaling for R variable
309  double mEqScaling; // scaling for M equation
310  double rEqScaling; // scaling for r equation
311  int outputStateVars; // flag indicating if user wants M,H and R output
312 
313  int factorMS; // flag to factor Ms out of M (not used in level 2)
314  int includeDeltaM; // flag to make delta M calculation implicit
315  int useRKIntegration; // flag to use 4th order runga-kutta for dM/dH integration
316  int useStateDeriv; // flag to use state vector for dH/dt calculation
317  int voltageLimiterFlag; // flag indicating that we should use limiting on internal vars Mag and R
318  double magLimitThres; // iteration threshold overwhich changes in Mag var are limited
319  double rLimitThres; // iteration threshold over which changes in R var are limited
320 
321  // flags indicating if temperature parameters were given
322  bool tc1Given;
323  bool tc2Given;
324  bool tnomGiven;
327 };
328 
329 void registerDevice();
330 
331 } // namespace MutIndNonLin2
332 } // namespace Device
333 } // namespace Xyce
334 
335 #endif
static void loadModelParameters(ParametricData< Model > &model_parameters)
Instance & operator=(const Instance &)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Teuchos::RCP< std::ofstream > outputFileStreamPtr
std::vector< std::string > couplingInductor
std::vector< Instance * > InstanceVector
void varTypes(std::vector< char > &varTypeVec)
Pure virtual class to augment a linear system.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
bool outputPlotFiles(bool force_final_output)
bool updateTemperature(const double &temp_tmp)
std::vector< Instance * > instanceContainer
std::vector< InductorInstanceData * > instanceData
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
const std::vector< std::vector< int > > & jacobianStamp() const
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual std::ostream & printOutInstances(std::ostream &os) const
bool processInstanceParams()
processInstanceParams
std::vector< std::vector< int > > jacStamp
std::vector< std::string > inductorsNode1
Class Configuration contains device configuration data.
std::vector< std::string > inductorNames
Model & operator=(const Model &)
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Iiter, const FactoryBlock &factory_block)
ScalarT Pcalc(const ScalarT &Mag, const ScalarT &CurrentSum, const ScalarT &Vpos, const ScalarT &Vneg)
std::vector< std::vector< double > > LO
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
std::vector< std::string > inductorsNode2
InstanceBlock represent a device instance line from the netlist.
void addInstance(Instance *instance)