Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.97.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Bsrc_h
47 #define Xyce_N_DEV_Bsrc_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_Source.h>
53 #include <N_DEV_DeviceBlock.h>
54 #include <N_DEV_DeviceInstance.h>
55 #include <N_DEV_DeviceModel.h>
56 #include <N_DEV_Param.h>
57 #include <N_UTL_fwd.h>
58 #include <N_UTL_BreakPoint.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 const int numNodes() {return 2;}
72  static const 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 
112  std::map<int,std::string> & getIntNameMap ();
113  std::map<int,std::string> & getStoreNameMap ();
114 
115  const std::vector<std::string> & getDepSolnVars();
116 
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 
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  // scale factor
173  double scale;
174  int nlstep;
175 
176  // indices into state vector:
177  std::vector<int> li_ddt;
178 
179  // solution vector indices:
180  // rhs vector indices:
181  int li_Pos;
182  int li_Neg;
183  int li_Bra;
184  int li_store_branch; // branch current stored in store vector
185  // if it is not part of the solution vector
186 
187  // Local offset variables for all of the above index variables.
192 
193  std::vector<int> APosEquExpVarOffsets;
194  std::vector<int> ANegEquExpVarOffsets;
195  std::vector<int> ABraEquExpVarOffsets;
196 
197  // Local offset variables for all of the above index variables.
202 
203  std::vector<double *> fPosEquExpVarPtrs;
204  std::vector<double *> fNegEquExpVarPtrs;
205  std::vector<double *> fBraEquExpVarPtrs;
206 
207  std::vector< std::vector<int> > jacStamp;
208 };
209 
210 //-----------------------------------------------------------------------------
211 // Class : Model
212 // Purpose :
213 // Special Notes :
214 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
215 // Creation Date : 06/05/01
216 //-----------------------------------------------------------------------------
217 class Model : public DeviceModel
218 {
219  typedef std::vector<Instance *> InstanceVector;
220 
221  friend class ParametricData<Model>;
222  friend class Instance;
223  friend class Traits;friend class Master;
224 
225 public:
226  Model(
227  const Configuration & configuration,
228  const ModelBlock & MB,
229  const FactoryBlock & factory_block);
230  ~Model ();
231 
232 private:
233  Model();
234  Model(const Model &);
235  Model &operator=(const Model &);
236 
237 public:
238  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
239 
240  virtual std::ostream &printOutInstances(std::ostream &os) const;
241  virtual bool processParams();
242  virtual bool processInstanceParams();
243 
244 public:
245  void addInstance(Instance *instance)
246  {
247  instanceContainer.push_back(instance);
248  }
249 
251  {
252  return instanceContainer;
253  }
254 
256  {
257  return instanceContainer;
258  }
259 
260 private:
261  std::vector<Instance*> instanceContainer;
262 
263 private:
264 
265 
266  // This is the dc and transient analysis value of the
267  // source.
268  double DC_TRAN;
269 
270  // This is the AC magnitude
271  double ACMAG;
272 
273  // This is the AC phase.
274  double ACPHASE;
275 
276  // This parameter is part of the specification that the
277  // source has distortion inputs at a frequency of this
278  // magnitude. It is triggered by the DISTOF1 keyword in
279  // the netlist.
280  double F1MAG;
281 
282  // This parameter is part of the specification that the
283  // source has distortion inputs at a frequency of this
284  // magnitude. It is triggered by the DISTOF2 keyword in
285  // the netlist.
286  double F2MAG;
287 
288  // This parameter is associated with the specification that
289  // the source has a distortion input. This is the phase
290  // associated with DISTOF1.
291  double F1PHASE;
292 
293  // This parameter is associated with the specification that
294  // the source has a distortion input. This is the phase
295  // associated with DISTOF2.
296  double F2PHASE;
297 };
298 
299 //-----------------------------------------------------------------------------
300 // Class : Master
301 // Purpose :
302 // Special Notes :
303 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
304 // Creation Date : 11/26/08
305 //-----------------------------------------------------------------------------
306 class Master : public DeviceMaster<Traits>
307 {
308  friend class Instance;
309  friend class Model;
310 
311 public:
313  const Configuration & configuration,
314  const FactoryBlock & factory_block,
315  const SolverState & ss1,
316  const DeviceOptions & do1)
317  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
318  {}
319 
320  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
321  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
322 
323  // load functions, residual:
324  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
325 
326  // load functions, Jacobian:
327  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
328 };
329 
330 void registerDevice();
331 
332 } // namespace Bsrc
333 } // namespace Device
334 } // namespace Xyce
335 
339 
340 #endif
341