Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.41.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_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 const int numNodes() {return 2;}
68  static const int numOptionalNodes() {return 1000;}
69  static const char *instanceDefaultParameter() {return "BASE_FILENAME";}
70  static const 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  std::map<int,std::string> & getIntNameMap ();
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  bool loadDeviceMask ();
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 
256  {
257  return instanceContainer;
258  }
259 
261  {
262  return instanceContainer;
263  }
264 
265 private:
266  std::vector<Instance*> instanceContainer;
267 
268 private:
269 
270 };
271 
272 //-----------------------------------------------------------------------------
273 // Class : Master
274 // Purpose :
275 // Special Notes :
276 // Creator : Heidi Thornquist, SNL, Parallel Computational Sciences
277 // Creation Date : 12/11/09
278 //-----------------------------------------------------------------------------
279 class Master : public DeviceMaster<Traits>
280 {
281  friend class Instance;
282  friend class Model;
283 
284 public:
286  const Configuration & configuration,
287  const FactoryBlock & factory_block,
288  const SolverState & ss1,
289  const DeviceOptions & do1)
290  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
291  {}
292 
293  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
294 
295  void printMatrix (std::string vname, double * Matrix, int Nrows, int Ncols); // BNB
296 
297  // load functions:
298  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
299  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
300 };
301 
302 void registerDevice();
303 
304 } // namespace ROM
305 } // namespace Device
306 } // namespace Xyce
307 
311 
312 #endif // Xyce__h
313