Xyce  6.1
N_DEV_ROM.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_ROM.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Heidi Thornquist, SNL
33 //
34 // Creation Date : 12/11/09
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.50.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:11 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_ROM_h
47 #define Xyce_N_DEV_ROM_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.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 ROM {
59 
60 class Model;
61 class Instance;
62 
63 struct Traits : public DeviceTraits<Model, Instance>
64 {
65  static const char *name() {return "ROM";}
66  static const char *deviceTypeName() {return "ROM level 1";}
67  static int numNodes() {return 2;}
68  static int numOptionalNodes() {return 1000;}
69  static const char *instanceDefaultParameter() {return "BASE_FILENAME";}
70  static bool isLinearDevice() {return true;}
71 
72  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
73  static void loadModelParameters(ParametricData<Model> &model_parameters);
74  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
75 };
76 
77 //-----------------------------------------------------------------------------
78 // Class : Instance
79 // Purpose :
80 // Special Notes :
81 // Creator : Heidi Thornquist, SNL, Parallel Computational Sciences
82 // Creation Date : 12/11/09
83 //-----------------------------------------------------------------------------
84 
85 class Instance : public DeviceInstance
86 {
87  friend class ParametricData<Instance>;
88  friend class Model;
89  friend class Traits;friend class Master;
90 
91 public:
92 
93  Instance(
94  const Configuration & configuration,
95  const InstanceBlock & IB,
96  Model & Citer,
97  const FactoryBlock & factory_block);
98 
99 
100  ~Instance();
101 
102 private:
103  Instance(const Instance &);
104  Instance &operator=(const Instance &);
105 
106 public:
107  // Additional Public Declarations
108  void registerLIDs( const std::vector<int> & intLIDVecRef,
109  const std::vector<int> & extLIDVecRef );
110  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
111 
112  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
113 
114  const std::vector< std::vector<int> > & jacobianStamp() const;
115  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
116 
117  bool processParams ();
118  bool updateTemperature(const double & temp_tmp);
119 
120  bool updateIntermediateVars () { return true; };
121  bool updatePrimaryState ();
122 
123  bool setIC ();
124 
125  void loadErrorWeightMask ();
126 
127  // load functions, residual:
128  bool loadDAEQVector ();
129  bool loadDAEFVector ();
130 
131  // load functions, Jacobian:
132  bool loadDAEdQdx ();
133  bool loadDAEdFdx ();
134 
135  void setupPointers();
136 
137  void varTypes( std::vector<char> & varTypeVec );
138 
139 public:
140  // iterator reference to the resistor 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  // Data Members for Class Attributes
152  bool isCSparse;
153  bool isGSparse;
154 
155  // User-specified parameters:
159  std::string baseFileName; // base file name for reduced-order model files
160  std::vector<double> Chat; // Reduced-order model V'*C*V
161  std::vector<int> Chat_colIdx, Chat_rowPtr; // Chat structures if stored in CSR format
162  std::vector<double> Ghat; // Reduced-order model V'*G*V
163  std::vector<int> Ghat_colIdx, Ghat_rowPtr; // Ghat structures if stored in CSR format
164  std::vector<int> CG_colIdx, CG_rowPtr; // Union of Chat and Ghat maps stored in CSR format
165  std::vector<double> Bhat; // Reduced-order model V'*B
166  std::vector<double> Lhat; // Reduced-order model L'*V
167  std::vector<double> Qhat; // Workspace Qhat = Chat * xhat
168  std::vector<double> Fhat; // Workspace Fhat = [Iq - Lhat'* xhat; Ghat*xhat - Bhat*up]
169  std::vector<double> i_ip; // Storage for Iq
170 
171  // Two-level stamps (BNB)
172  std::vector<double> Jstamp; // stamp for Jacobian
173  std::vector<double> Fstamp; // stamp for F
174  std::vector<double> G2; // intermediate variable
175  std::vector<double> C2; // intermediate varaible
176  std::vector<double> A2; // intermediate varaible
177  std::vector<double> A2last;
178  std::vector<double> G2p; // intermediate varaible
179  std::vector<double> Gp2; // intermediate varaible
180  std::vector<double> A2sol; // intermediate variable
184  std::vector<int> ipiv_A2; // for LAPACK math
185 
186  //local id's (offsets)
187  std::vector<int> li_ROM; // Interior variables
188  std::vector<int> li_state; // Internal state
189 
190  // Offsets for Jacobian
191  std::vector<int> AEqu_up_NodeOffset;
192  std::vector<int> AEqu_ip_NodeOffset;
193  std::vector< std::vector<int> > AEqu_NodeOffset;
194  std::vector<int> ROMEqu_Lt_NodeOffset;
195  std::vector<int> ROMEqu_B_NodeOffset;
196  std::vector<int> ROMEqu_GpC_NodeOffset;
197  // Offsets for sparse C and C in Jacobian
198  std::vector<int> ROMEqu_C_NodeOffset;
199  std::vector<int> ROMEqu_G_NodeOffset;
200 
201  // Pointers for Jacobian
202  std::vector<double *> fEqu_up_NodePtr;
203  std::vector<double *> fEqu_ip_NodePtr;
204  std::vector<double *> fEqu_un_NodePtr; // BNB
205 
206  std::vector<double *> qROMEqu_Chat_VarsPtrs;
207  std::vector<double *> fROMEqu_Ghat_VarsPtrs;
208  std::vector<double *> fROMEqu_Lhat_VarsPtrs;
209  std::vector<double *> fROMEqu_Bhat_VarsPtrs;
210 
211  std::vector< std::vector<int> > jacStamp;
212 };
213 
214 //-----------------------------------------------------------------------------
215 // Class : Model
216 // Purpose :
217 // Special Notes :
218 // Creator : Heidi Thornquist, SNL, Parallel Computational Sciences
219 // Creation Date : 12/11/09
220 //-----------------------------------------------------------------------------
221 class Model : public DeviceModel
222 {
223  typedef std::vector<Instance *> InstanceVector;
224 
225  friend class ParametricData<Model>;
226  friend class Instance;
227  friend class Traits;friend class Master;
228 
229 public:
230 
231  Model(
232  const Configuration & configuration,
233  const ModelBlock & MB,
234  const FactoryBlock & factory_block);
235  ~Model ();
236 
237 private:
238  Model();
239  Model(const Model &);
240  Model &operator=(const Model &);
241 
242 public:
243  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
244 
245  virtual std::ostream &printOutInstances(std::ostream &os) const;
246  bool processParams ();
247  bool processInstanceParams ();
248 
249 public:
250  void addInstance(Instance *instance)
251  {
252  instanceContainer.push_back(instance);
253  }
254 
255 private:
256  std::vector<Instance*> instanceContainer;
257 
258 private:
259 
260 };
261 
262 //-----------------------------------------------------------------------------
263 // Class : Master
264 // Purpose :
265 // Special Notes :
266 // Creator : Heidi Thornquist, SNL, Parallel Computational Sciences
267 // Creation Date : 12/11/09
268 //-----------------------------------------------------------------------------
269 class Master : public DeviceMaster<Traits>
270 {
271  friend class Instance;
272  friend class Model;
273 
274 public:
276  const Configuration & configuration,
277  const FactoryBlock & factory_block,
278  const SolverState & ss1,
279  const DeviceOptions & do1)
280  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
281  {}
282 
283  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
284 
285  void printMatrix (std::string vname, double * Matrix, int Nrows, int Ncols); // BNB
286 
287  // load functions:
288  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
289  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
290 };
291 
292 void registerDevice();
293 
294 } // namespace ROM
295 } // namespace Device
296 } // namespace Xyce
297 
298 #endif // Xyce_N_DEV_ROM_h
299 
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_ROM.C:1265
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_ROM.C:746
std::vector< int > li_state
Definition: N_DEV_ROM.h:188
std::vector< int > CG_rowPtr
Definition: N_DEV_ROM.h:164
std::vector< double > Ghat
Definition: N_DEV_ROM.h:162
static int numOptionalNodes()
Definition: N_DEV_ROM.h:68
std::vector< std::vector< int > > AEqu_NodeOffset
Definition: N_DEV_ROM.h:193
std::vector< double > Qhat
Definition: N_DEV_ROM.h:167
std::vector< double > Fhat
Definition: N_DEV_ROM.h:168
std::vector< double > Gp2
Definition: N_DEV_ROM.h:179
std::vector< double * > fEqu_ip_NodePtr
Definition: N_DEV_ROM.h:203
std::vector< double > G2p
Definition: N_DEV_ROM.h:178
std::vector< Instance * > instanceContainer
Definition: N_DEV_ROM.h:256
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_ROM.C:655
std::vector< double > A2last
Definition: N_DEV_ROM.h:177
Pure virtual class to augment a linear system.
std::vector< double > Fstamp
Definition: N_DEV_ROM.h:173
std::vector< double > Chat
Definition: N_DEV_ROM.h:160
std::vector< double * > fROMEqu_Bhat_VarsPtrs
Definition: N_DEV_ROM.h:209
std::vector< int > AEqu_up_NodeOffset
Definition: N_DEV_ROM.h:191
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_ROM.C:728
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_ROM.C:1860
std::vector< int > Chat_rowPtr
Definition: N_DEV_ROM.h:161
std::vector< int > AEqu_ip_NodeOffset
Definition: N_DEV_ROM.h:192
std::vector< double * > fROMEqu_Ghat_VarsPtrs
Definition: N_DEV_ROM.h:207
std::vector< double * > qROMEqu_Chat_VarsPtrs
Definition: N_DEV_ROM.h:206
std::vector< int > Ghat_rowPtr
Definition: N_DEV_ROM.h:163
std::vector< int > CG_colIdx
Definition: N_DEV_ROM.h:164
std::vector< int > ROMEqu_C_NodeOffset
Definition: N_DEV_ROM.h:198
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_ROM.C:1237
static bool isLinearDevice()
Definition: N_DEV_ROM.h:70
DeviceMaster instantiates a device as described by the device traits T.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
std::vector< double * > fEqu_up_NodePtr
Definition: N_DEV_ROM.h:202
std::vector< double > Lhat
Definition: N_DEV_ROM.h:166
std::vector< std::vector< int > > jacStamp
Definition: N_DEV_ROM.h:211
std::vector< int > Ghat_colIdx
Definition: N_DEV_ROM.h:163
std::vector< int > ipiv_A2
Definition: N_DEV_ROM.h:184
bool updateTemperature(const double &temp_tmp)
Definition: N_DEV_ROM.C:124
void registerDevice()
Definition: N_DEV_ROM.C:1866
std::vector< double > G2
Definition: N_DEV_ROM.h:174
std::vector< double * > fROMEqu_Lhat_VarsPtrs
Definition: N_DEV_ROM.h:208
static const char * instanceDefaultParameter()
Definition: N_DEV_ROM.h:69
std::vector< int > ROMEqu_GpC_NodeOffset
Definition: N_DEV_ROM.h:196
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_ROM.C:759
std::vector< int > ROMEqu_Lt_NodeOffset
Definition: N_DEV_ROM.h:194
void addInstance(Instance *instance)
Definition: N_DEV_ROM.h:250
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_ROM.C:98
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_ROM.C:1339
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_ROM.C:1378
Class Configuration contains device configuration data.
std::vector< double * > fEqu_un_NodePtr
Definition: N_DEV_ROM.h:204
bool processParams()
processParams
Definition: N_DEV_ROM.C:1252
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_ROM.C:707
Instance & operator=(const Instance &)
std::vector< double > Jstamp
Definition: N_DEV_ROM.h:172
std::vector< double > A2sol
Definition: N_DEV_ROM.h:180
static const char * deviceTypeName()
Definition: N_DEV_ROM.h:66
std::vector< Instance * > InstanceVector
Definition: N_DEV_ROM.h:223
std::vector< int > Chat_colIdx
Definition: N_DEV_ROM.h:161
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
Definition: N_DEV_ROM.h:275
std::vector< double > C2
Definition: N_DEV_ROM.h:175
std::vector< double > i_ip
Definition: N_DEV_ROM.h:169
void printMatrix(std::string vname, double *Matrix, int Nrows, int Ncols)
Definition: N_DEV_ROM.C:1608
static int numNodes()
Definition: N_DEV_ROM.h:67
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.
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_ROM.C:1629
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_ROM.C:1681
std::vector< int > ROMEqu_B_NodeOffset
Definition: N_DEV_ROM.h:195
Model & operator=(const Model &)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Citer, const FactoryBlock &factory_block)
Definition: N_DEV_ROM.C:137
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_ROM.C:91
static const char * name()
Definition: N_DEV_ROM.h:65
std::vector< int > li_ROM
Definition: N_DEV_ROM.h:187
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_ROM.C:1395
std::vector< int > ROMEqu_G_NodeOffset
Definition: N_DEV_ROM.h:199
std::vector< double > Bhat
Definition: N_DEV_ROM.h:165
std::vector< double > A2
Definition: N_DEV_ROM.h:176