Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_OpAmp.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 : N_DEV_OpAmp.h
27 //
28 // Purpose : Ideal Operational Amplifier Model
29 //
30 // Special Notes : This model assumes infinite gain
31 // and unbounded output voltages
32 //
33 // Creator : Brian Fett, SNL
34 //
35 // Creation Date : 08/02/05
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.49 $
41 //
42 // Revision Date : $Date: 2014/05/21 18:25:50 $
43 //
44 // Current Owner : $Author: dgbaur $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_DEV_OpAmp_h
48 #define Xyce_N_DEV_OpAmp_h
49 
50 // ---------- Xyce Includes ----------
51 #include <N_DEV_Configuration.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 
56 namespace Xyce {
57 namespace Device {
58 namespace OpAmp {
59 
60 class Model;
61 class Instance;
62 
63 struct Traits : public DeviceTraits<Model, Instance>
64 {
65  static const char *name() {return "Operational Amplifier";}
66  static const char *deviceTypeName() {return "OpAmp level 1";}
67  static int numNodes() {return 3;}
68  static bool modelRequired() {return true;}
69  static bool isLinearDevice() {return true;}
70 
71  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
72  static void loadModelParameters(ParametricData<Model> &model_parameters);
73  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
74 };
75 
76 //-----------------------------------------------------------------------------
77 // Class : Instance
78 // Purpose :
79 // Special Notes :
80 // Creator : Brian Fett
81 // Creation Date : 08/28/05
82 //-----------------------------------------------------------------------------
83 class Instance : public DeviceInstance
84 {
85  friend class ParametricData<Instance>;
86  friend class Model;
87  friend class Traits;
88 
89 public:
90 
91  Instance(
92  const Configuration & configuration,
93  const InstanceBlock & IB,
94  Model & iter,
95  const FactoryBlock & factory_block);
96 
97  ~Instance();
98 
99 private:
100  Instance(const Instance &);
101  Instance &operator=(const Instance &);
102 
103 public:
104  void registerLIDs( const std::vector<int> & intLIDVecRef,
105  const std::vector<int> & extLIDVecRef );
106  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
107 
108  const std::vector< std::vector<int> > & jacobianStamp() const;
109  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
110 
111  bool processParams ();
112 
113  bool updateIntermediateVars ();
114  bool updatePrimaryState ();
115 
116  // load functions, residual:
117  bool loadDAEQVector () {return true;}
118  bool loadDAEFVector ();
119 
120  // load functions, Jacobian:
121  bool loadDAEdQdx () {return true;}
122  bool loadDAEdFdx ();
123 
124  // iterator reference to the OpAmp model which owns this instance.
125  // Getters and setters
127  {
128  return model_;
129  }
130 
131 private:
132  static std::vector< std::vector<int> > jacStamp;
133 
134  Model & model_; //< Owning model
135 
136  // state variables:
137  double outCurrent;
138  double deltaVoltage;
139 
140 
141  // Parameters
142  double FAKEPARAM;
143 
144  // load variables
145  double v_pos, v_neg, v_out, i_bra;
146 
147  // indices into state vector:
148  int istate_I; // index for i0;
149 
150  // Matrix equation index variables:
151  //local indices (offsets)
152  int li_Pos;
153  int li_Neg;
154  int li_Out;
155  int li_Bra;
156 
157  // Jacobian matrix indices:
158  //Locally indexed offsets for jacobian
159  int ABraEquPosNodeOffset; // Offset, pos. input voltage contribution
160  // branch current equation.
161 
162  int ABraEquNegNodeOffset; // Offset, neg. input voltage contribution
163  // branch current equation.
164 
165  int AOutEquBraVarOffset; // Offset, branch current variable
166  // contribution, KCL of output node
167 };
168 
169 //-----------------------------------------------------------------------------
170 // Class : Model
171 // Purpose :
172 // Special Notes :
173 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
174 // Creation Date : 04/06/00
175 // Modified by : Brian Fett, SNL
176 // Modify Date : 08/02/05
177 //-----------------------------------------------------------------------------
178 class Model : public DeviceModel
179 {
180  typedef std::vector<Instance *> InstanceVector;
181 
182  friend class ParametricData<Model>;
183  friend class Instance;
184  friend class Traits;
185 
186 public:
187  Model(
188  const Configuration & configuration,
189  const ModelBlock & MB,
190  const FactoryBlock & factory_block);
191  ~Model ();
192 
193 private:
194  Model();
195  Model(const Model &);
196  Model &operator=(const Model &);
197 
198 public:
199  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
200 
201  virtual std::ostream &printOutInstances(std::ostream &os) const;
202  virtual bool processParams()
203  {
204  return true;
205  }
206 
207  virtual bool processInstanceParams()
208  {
209  return true;
210  }
211 
212 public:
213  void addInstance(Instance *instance)
214  {
215  instanceContainer.push_back(instance);
216  }
217 
218 private:
219  std::vector<Instance*> instanceContainer;
220 
221 private:
222 
223  // Data Members for Associations
224  double FAKEPARAM;
225 };
226 
227 void registerDevice();
228 
229 } // namespace OpAmp
230 } // namespace Device
231 } // namespace Xyce
232 
235 
236 #endif