Xyce  6.1
N_DEV_PowerGrid.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_PowerGrid.h,v $
27 //
28 // Purpose : PowerGrid classes: provides a device that calculates the
29 // steady state power flow in a transmission grid
30 //
31 // Special Notes : Experimental new device for an LDRD.
32 //
33 // Creator : Pete Sholander, SNL, Electrical and Microsystems Modeling
34 //
35 // Creation Date : 9/12/14
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.6.2.1 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:20:11 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_DEV_PowerGrid_h
48 #define Xyce_N_DEV_PowerGrid_h
49 
50 #include <complex>
51 
52 // ---------- Xyce Includes ----------
53 #include <N_DEV_Configuration.h>
54 #include <N_DEV_DeviceBlock.h>
55 #include <N_DEV_DeviceInstance.h>
56 #include <N_DEV_DeviceModel.h>
57 
58 namespace Xyce {
59 namespace Device {
60 namespace PowerGrid {
61 
62 class Model;
63 class Instance;
64 
65 struct Traits : public DeviceTraits<Model, Instance>
66 {
67  static const char *name() {return "PowerGrid Device";}
68  static const char *deviceTypeName() {return "PowerGrid level 1";}
69  static int numNodes() {return 4;}
70  // this number may be to be increased for the monolithic PowerGrid model
71  static int numOptionalNodes() {return 100;}
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 //
83 // This is the instance class for accelerated object devices. It
84 // contains "unique" ACC device information - ie stuff that
85 // will be true of only one ACC in the circuit, such
86 // as the nodes to which it is connected. An ACC is
87 // connected to only one circuit node, from which it gets the
88 // acceleration.
89 //
90 // This class does not directly contain information about
91 // its node indices. It contains indices into the 3 parts
92 // (A, dx, and b) of the matrix problem A*dx = b, and
93 // also x. A is the Jacobian matrix, dx is the update to
94 // the solution vector x, and b is the right hand side
95 // function vector. These indices are global, and
96 // determined by topology during the initialization stage
97 // of execution.
98 //
99 // Special Notes :
100 // Creator : Pete Sholander, SNL, Electrical and Microsystems Modeling
101 // Creation Date : 9/12/14
102 //-----------------------------------------------------------------------------
103 class Instance : public DeviceInstance
104 {
105  friend class ParametricData<Instance>;
106  friend class Model;
107  friend class Traits;
108 
109 public:
110 
111  Instance(
112  const Configuration & configuration,
113  const InstanceBlock & IB,
114  Model & Riter,
115  const FactoryBlock & factory_block);
116 
117  ~Instance();
118 
119 private:
120  Instance(const Instance &);
121  Instance &operator=(const Instance &);
122 
123 public:
124  void registerLIDs( const std::vector<int> & intLIDVecRef,
125  const std::vector<int> & extLIDVecRef );
126  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
127 
128  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
129 
130  bool updateIntermediateVars ();
131  bool updatePrimaryState ();
132  //bool updateSecondaryState ();
133 
134  const std::vector< std::vector<int> > & jacobianStamp() const;
135  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
136 
137  // load functions, residual:
138  bool loadDAEQVector ();
139  bool loadDAEFVector ();
140 
141  // load functions, Jacobian:
142  bool loadDAEdQdx ();
143  bool loadDAEdFdx ();
144 
145  // functions to load initial condition and branch data from files
146  bool loadBusdata();
147  bool loadBranchData();
148  bool buildYMatrixMap();
149  bool printYMatrixMap();
150 
151 public:
152  // iterator reference to the ACC model which owns this instance.
153  // Getters and setters
155  {
156  return model_;
157  }
158 
159 private:
160  static std::vector< std::vector<int> > jacStamp;
161 
162  Model & model_; //< Owning model
163 
164  // user-specified parameters:
165  int numBus_; // number of buses in the transmission grid
166  std::string analysisType_;
167  std::string busFileName_; // file name, with initial conditions
168  std::string branchFileName_; // file name, with branch data
169 
170  // maps for various data. Some of this will go away, when the
171  // monolithic device model does
172  std::map<int,double> magICmap_;
173  std::map<int,double> angleICmap_;
174  std::map<int,double> busShuntConductance_;
175  std::map<int,double> busShuntSusceptance_;
176 
177  typedef std::pair<int,int> twodKey;
178  typedef std::map<twodKey,double> twodMap;
179  typedef std::map<twodKey,std::complex<double> > twodComplexMap;
180 
182  twodMap turnsRatio_;
183  twodComplexMap yMatrixMap_;
184 
185  // definitions for actual power grid device - intermediate vars
186  double g11, g12, g21, g22;
187  double b11, b12, b21, b22;
188 
189  // these are used for the I=YV formulation
190  double IR1, IR2, II1, II2;
191 
193 
198 
203 
208 
213 
214  // these are used for the PQ formulation
215  double P1, P2, Q1, Q2;
216 
218 
223 
228 
233 
238 
239 
240 };
241 
242 //-----------------------------------------------------------------------------
243 // Class : Model
244 // Purpose :
245 //
246 //
247 // Special Notes :
248 // Creator : Pete Sholander, SNL, Electrical and Microsystems Modeling
249 // Creation Date : 9/12/14
250 //-----------------------------------------------------------------------------
251 class Model : public DeviceModel
252 {
253  typedef std::vector<Instance *> InstanceVector;
254 
255  friend class ParametricData<Model>;
256  friend class Instance;
257  friend class Traits;
258 
259 public:
260  Model(
261  const Configuration & configuration,
262  const ModelBlock & MB,
263  const FactoryBlock & factory_block);
264  ~Model();
265 
266 private:
267  Model();
268  Model(const Model &);
269  Model &operator=(const Model &);
270 
271 public:
272  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
273 
274  virtual std::ostream &printOutInstances(std::ostream &os) const;
275 
276  virtual bool processParams()
277  {
278  return true;
279  }
280 
281  virtual bool processInstanceParams()
282  {
283  return true;
284  }
285 
286 public:
287  void addInstance(Instance *instance)
288  {
289  instanceContainer.push_back(instance);
290  }
291 
292 private:
293  std::vector<Instance*> instanceContainer;
294 
295 private:
296 };
297 
298 void registerDevice();
299 
300 } // namespace PowerGrid
301 } // namespace Device
302 } // namespace Xyce
303 
304 #endif // Xyce_N_DEV_PowerGrid_h
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
std::map< int, double > busShuntSusceptance_
Model & operator=(const Model &)
virtual bool processInstanceParams()
processInstanceParams
Pure virtual class to augment a linear system.
void addInstance(Instance *instance)
std::vector< Instance * > instanceContainer
std::map< int, double > angleICmap_
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
std::vector< Instance * > InstanceVector
static void loadModelParameters(ParametricData< Model > &model_parameters)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
static const char * deviceTypeName()
const std::vector< std::vector< int > > & jacobianStamp() const
static std::vector< std::vector< int > > jacStamp
std::map< int, double > magICmap_
static const char * name()
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.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
Class Configuration contains device configuration data.
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
virtual bool processParams()
processParams
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
std::map< twodKey, double > twodMap
std::map< twodKey, std::complex< double > > twodComplexMap
virtual std::ostream & printOutInstances(std::ostream &os) const
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
InstanceBlock represent a device instance line from the netlist.
Instance & operator=(const Instance &)
std::map< int, double > busShuntConductance_
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)