Xyce  6.1
N_DEV_Bsrc.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_Bsrc.h,v $
27 //
28 // Purpose : General expression dependent source
29 //
30 // Special Notes :
31 //
32 // Creator : Robert J Hoekstra, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 06/05/01
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.109 $
40 //
41 // Revision Date : $Date: 2015/09/23 18:29:47 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Bsrc_h
47 #define Xyce_N_DEV_Bsrc_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_UTL_fwd.h>
51 
52 #include <N_DEV_Configuration.h>
53 #include <N_DEV_DeviceMaster.h>
54 #include <N_DEV_Source.h>
55 #include <N_DEV_DeviceBlock.h>
56 #include <N_DEV_DeviceInstance.h>
57 #include <N_DEV_DeviceModel.h>
58 #include <N_DEV_Param.h>
59 
60 namespace Xyce {
61 namespace Device {
62 namespace Bsrc {
63 
64 class Model;
65 class Instance;
66 
67 struct Traits : public DeviceTraits<Model, Instance>
68 {
69  static const char *name() {return "Expression Based Voltage or Current Source";}
70  static const char *deviceTypeName() {return "B level 1";}
71  static int numNodes() {return 2;}
72  static bool isLinearDevice() {return true;}
73 
74  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
75  static void loadModelParameters(ParametricData<Model> &model_parameters);
76  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
77 };
78 
79 //-----------------------------------------------------------------------------
80 // Class : Instance
81 // Purpose :
82 // Special Notes :
83 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
84 // Creation Date : 06/05/01
85 //-----------------------------------------------------------------------------
86 class Instance : public DeviceInstance
87 {
88  friend class ParametricData<Instance>;
89  friend class Model;
90  friend class Traits;friend class Master;
91 
92 public:
93 
94  Instance(
95  const Configuration & configuration,
96  const InstanceBlock & IB,
97  Model & BMiter,
98  const FactoryBlock & factory_block);
99 
100  ~Instance();
101 
102 private:
103  Instance(const Instance &);
104  Instance &operator=(const Instance &);
105 
106 public:
107  void registerLIDs(const std::vector<int> & intLIDVecRef,
108  const std::vector<int> & extLIDVecRef );
109  void registerStateLIDs(const std::vector<int> & staLIDVecRef);
110  void registerStoreLIDs(const std::vector<int> & stoLIDVecRef );
111  void registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef);
112  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
113 
114  const std::vector<std::string> & getDepSolnVars();
115 
116 
117  const std::vector< std::vector<int> > & jacobianStamp() const;
118  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
119 
120  bool processParams ();
121 
122  bool updateTemperature(const double & temp);
123  bool updateIntermediateVars ();
124  bool updatePrimaryState ();
125  bool updateSecondaryState ();
126 
127  // load functions, residual:
128  bool loadDAEQVector () {return true;}
129  bool loadDAEFVector ();
130 
131  // load functions, Jacobian:
132  bool loadDAEdQdx () {return true;}
133  bool loadDAEdFdx ();
134 
135  void setupPointers();
136 
137  void varTypes( std::vector<char> & varTypeVec );
138 
139 public:
140  // iterator reference to the bsrc model which owns this instance.
141  // Getters and setters
143  {
144  return model_;
145  }
146 
147 private:
148 
149  Model & model_; //< Owning model
150 
151  Util::Expression * Exp_ptr;
152 
156  std::list<std::string> evnList;
157 
158  std::vector<double> expVarDerivs;
159  std::vector<double> myVarVals;
160  std::vector<double> ddtVals;
161  double expVal;
162 
164 
165  // flag for voltage src, needs current variable
166  bool isVSRC;
167 
168  // Value of voltage or current expression
169  double V;
170  double I;
171 
172  double temp;
173 
174  // scale factor
175  double scale;
176  int nlstep;
177 
178  // indices into state vector:
179  std::vector<int> li_ddt;
180 
181  // solution vector indices:
182  // rhs vector indices:
183  int li_Pos;
184  int li_Neg;
185  int li_Bra;
186  int li_store_branch; // branch current stored in store vector
187  int li_branch_data; ///< Index for lead current and junction voltage (for power calculations)
188  // if it is not part of the solution vector
189 
190  // Local offset variables for all of the above index variables.
195 
196  std::vector<int> APosEquExpVarOffsets;
197  std::vector<int> ANegEquExpVarOffsets;
198  std::vector<int> ABraEquExpVarOffsets;
199 
200  // Local offset variables for all of the above index variables.
205 
206  std::vector<double *> fPosEquExpVarPtrs;
207  std::vector<double *> fNegEquExpVarPtrs;
208  std::vector<double *> fBraEquExpVarPtrs;
209 
210  std::vector< std::vector<int> > jacStamp;
211 };
212 
213 //-----------------------------------------------------------------------------
214 // Class : Model
215 // Purpose :
216 // Special Notes :
217 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
218 // Creation Date : 06/05/01
219 //-----------------------------------------------------------------------------
220 class Model : public DeviceModel
221 {
222  typedef std::vector<Instance *> InstanceVector;
223 
224  friend class ParametricData<Model>;
225  friend class Instance;
226  friend class Traits;friend class Master;
227 
228 public:
229  Model(
230  const Configuration & configuration,
231  const ModelBlock & MB,
232  const FactoryBlock & factory_block);
233  ~Model ();
234 
235 private:
236  Model();
237  Model(const Model &);
238  Model &operator=(const Model &);
239 
240 public:
241  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
242 
243  virtual std::ostream &printOutInstances(std::ostream &os) const;
244  virtual bool processParams();
245  virtual bool processInstanceParams();
246 
247 public:
248  void addInstance(Instance *instance)
249  {
250  instanceContainer.push_back(instance);
251  }
252 
253 private:
254  std::vector<Instance*> instanceContainer;
255 
256 private:
257 
258 
259  // This is the dc and transient analysis value of the
260  // source.
261  double DC_TRAN;
262 
263  // This is the AC magnitude
264  double ACMAG;
265 
266  // This is the AC phase.
267  double ACPHASE;
268 
269  // This parameter is part of the specification that the
270  // source has distortion inputs at a frequency of this
271  // magnitude. It is triggered by the DISTOF1 keyword in
272  // the netlist.
273  double F1MAG;
274 
275  // This parameter is part of the specification that the
276  // source has distortion inputs at a frequency of this
277  // magnitude. It is triggered by the DISTOF2 keyword in
278  // the netlist.
279  double F2MAG;
280 
281  // This parameter is associated with the specification that
282  // the source has a distortion input. This is the phase
283  // associated with DISTOF1.
284  double F1PHASE;
285 
286  // This parameter is associated with the specification that
287  // the source has a distortion input. This is the phase
288  // associated with DISTOF2.
289  double F2PHASE;
290 };
291 
292 //-----------------------------------------------------------------------------
293 // Class : Master
294 // Purpose :
295 // Special Notes :
296 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
297 // Creation Date : 11/26/08
298 //-----------------------------------------------------------------------------
299 class Master : public DeviceMaster<Traits>
300 {
301  friend class Instance;
302  friend class Model;
303 
304 public:
306  const Configuration & configuration,
307  const FactoryBlock & factory_block,
308  const SolverState & ss1,
309  const DeviceOptions & do1)
310  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
311  {}
312 
313  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
314  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
315 
316  // load functions, residual:
317  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
318 
319  // load functions, Jacobian:
320  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
321 };
322 
323 void registerDevice();
324 
325 } // namespace Bsrc
326 } // namespace Device
327 } // namespace Xyce
328 
329 #endif
330 
std::vector< int > APosEquExpVarOffsets
Definition: N_DEV_Bsrc.h:196
static const char * deviceTypeName()
Definition: N_DEV_Bsrc.h:70
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_Bsrc.C:300
std::vector< int > ABraEquExpVarOffsets
Definition: N_DEV_Bsrc.h:198
Pure virtual class to augment a linear system.
static bool isLinearDevice()
Definition: N_DEV_Bsrc.h:72
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_Bsrc.C:388
std::vector< Instance * > instanceContainer
Definition: N_DEV_Bsrc.h:254
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Definition: N_DEV_Bsrc.C:946
std::vector< double > expVarDerivs
Definition: N_DEV_Bsrc.h:158
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_Bsrc.C:93
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_Bsrc.C:477
virtual bool processInstanceParams()
processInstanceParams
Definition: N_DEV_Bsrc.C:840
const std::vector< std::string > & getDepSolnVars()
Definition: N_DEV_Bsrc.C:450
static const char * name()
Definition: N_DEV_Bsrc.h:69
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_Bsrc.C:1108
std::vector< double > ddtVals
Definition: N_DEV_Bsrc.h:160
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.
Definition: N_DEV_Bsrc.C:998
std::vector< int > ANegEquExpVarOffsets
Definition: N_DEV_Bsrc.h:197
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
Definition: N_DEV_Bsrc.C:370
DeviceMaster instantiates a device as described by the device traits T.
std::vector< double * > fNegEquExpVarPtrs
Definition: N_DEV_Bsrc.h:207
std::vector< Instance * > InstanceVector
Definition: N_DEV_Bsrc.h:222
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_Bsrc.C:906
std::list< std::string > evnList
Definition: N_DEV_Bsrc.h:156
bool updateTemperature(const double &temp)
Definition: N_DEV_Bsrc.C:260
std::vector< double > myVarVals
Definition: N_DEV_Bsrc.h:159
Model & operator=(const Model &)
std::vector< int > li_ddt
Definition: N_DEV_Bsrc.h:179
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Bsrc.C:73
int li_branch_data
Index for lead current and junction voltage (for power calculations)
Definition: N_DEV_Bsrc.h:187
Instance & operator=(const Instance &)
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_Bsrc.C:464
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_Bsrc.C:890
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_Bsrc.C:772
Class Configuration contains device configuration data.
std::vector< double * > fPosEquExpVarPtrs
Definition: N_DEV_Bsrc.h:206
std::vector< std::vector< int > > jacStamp
Definition: N_DEV_Bsrc.h:210
virtual bool processParams()
processParams
Definition: N_DEV_Bsrc.C:827
void addInstance(Instance *instance)
Definition: N_DEV_Bsrc.h:248
void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Definition: N_DEV_Bsrc.C:411
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_Bsrc.C:1049
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_Bsrc.C:855
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_Bsrc.C:429
ModelBlock represents a .MODEL line from the netlist.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
Definition: N_DEV_Bsrc.h:305
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.
Util::Expression * Exp_ptr
Definition: N_DEV_Bsrc.h:151
std::vector< double * > fBraEquExpVarPtrs
Definition: N_DEV_Bsrc.h:208
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &BMiter, const FactoryBlock &factory_block)
Definition: N_DEV_Bsrc.C:108