Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_Sensitivity.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_NLS_Sensitivity.h,v $
27 //
28 // Purpose : This file contains the sensitivity class. It mostly
29 // manages the calculations of direct (and possibly later,
30 // adjoint) sensitivities.
31 //
32 // Special Notes : The main reason that this class is derived from
33 // N_NLS_NonLinearSolver is that this class needs to
34 // do a series of linear solves, using the jacobian
35 // matrix. This seemed similar enough to the requirements
36 // of a nonlinear solver to have one derived off the other.
37 //
38 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
39 //
40 // Creation Date : 10/30/02
41 //
42 // Revision Information:
43 // ---------------------
44 //
45 // Revision Number: $Revision: 1.50 $
46 //
47 // Revision Date : $Date: 2014/02/24 23:49:24 $
48 //
49 // Current Owner : $Author: tvrusso $
50 //-------------------------------------------------------------------------
51 
52 #ifndef Xyce_N_NLS_Sensitivity_h
53 #define Xyce_N_NLS_Sensitivity_h
54 
55 #include<vector>
56 
57 #include <N_UTL_fwd.h>
58 #include <N_NLS_NLParams.h>
59 #include <N_NLS_NonLinearSolver.h>
60 
62 {
67 };
68 
69 //-----------------------------------------------------------------------------
70 // Class : N_NLS_Sensitivity
71 // Purpose :
72 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
73 // Creation Date : 10/20/02
74 //-----------------------------------------------------------------------------
75 
77 {
78 public:
80  N_TOP_Topology & top_,
81  N_IO_CmdParse & cp);
82 
84 
85  int solve (N_NLS_NonLinearSolver * nlsTmpPtr=NULL) {return -1;};
86  int solve (
87  std::vector<double> & objectiveVec,
88  std::vector<double> & dOdpVec,
89  std::vector<double> & dOdpAdjVec,
90  std::vector<double> & scaled_dOdpVec,
91  std::vector<double> & scaled_dOdpAdjVec);
92 
93  int solveDirect ();
94  int solveAdjoint ();
95 
96  void stdOutput (
97  std::string idString,
98  std::vector<double> & paramVals,
99  std::vector<double> & sensitivities,
100  std::vector<double> & scaled_sensitivities
101  );
102 
103  void fileOutput (
104  std::string idString,
105  std::vector<double> & paramVals,
106  std::vector<double> & sensitivities,
107  std::vector<double> & scaled_sensitivities
108  );
109 
110  void dakOutput (
111  std::string idString,
112  std::vector<double> & paramVals,
113  std::vector<double> & sensitivities,
114  std::vector<double> & scaled_sensitivities
115  );
116 
117  bool calcSensitivities ();
118 
119  bool calcObjFuncDerivs ();
120 
121  bool setOptions(const N_UTL_OptionBlock& OB);
122  bool setSensitivityOptions(const N_UTL_OptionBlock& OB);
123  bool setTranOptions(const N_UTL_OptionBlock& OB);
124  bool setHBOptions(const N_UTL_OptionBlock& OB);
125 
126  // Note, many of the following are here b/c they are purely
127  // virtual functions of the nonlinear solver class.
128  // They don't have much meaning here. It may turn out that
129  // having this class derive off of the N_NLS_NonLinearSolver
130  // class doesn't make much sense. If so, I'll change it later. ERK
131 
132  int getNumIterations() const;
133 #ifdef Xyce_DEBUG_NONLINEAR
134  int getDebugLevel() const;
135  bool getScreenOutputFlag() const;
136  double getDebugMinTime() const;
137  double getDebugMaxTime() const;
138  int getDebugMinTimeStep() const;
139  int getDebugMaxTimeStep() const;
140  bool getMMFormat () const;
141 #endif
142  double getMaxNormF() const;
143  int getMaxNormFindex() const;
144 
145  int getContinuationStep() const;
146  int getParameterNumber() const;
147  bool isFirstContinuationParam() const;
148  bool isFirstSolveComplete() const;
149  void setAnalysisMode(AnalysisMode mode);
150 
151 protected:
152 private:
153 
154 public:
155 protected:
156 private:
157 
163  bool outputScaledFlag_; // include scaled sensitivities in IO
164  bool outputUnscaledFlag_; // include unscaled sensitivities in IO
166 
171 
172  // expression related stuff:
177  std::vector<std::string> expVarNames_;
178  std::vector<int> expVarGIDs_;
179  std::vector<int> expVarLocal_;
180  std::vector<double> expVarVals_;
181  std::vector<double> expVarDerivs_;
182  double expVal_;
183  std::string objFuncString_;
184 
185  double curValue_; // current value of the variable.
186  double objFuncEval_;// value of the evaluated objective function.
187  double dOdp_;
188  double sqrtEta_;
190 
191  std::vector<N_LAS_Vector*> dfdpPtrVector_;
192  std::vector<N_LAS_Vector*> dXdpPtrVector_;
193 
194  N_LAS_Vector* dOdXVectorPtr_; // size of solution std::vector.
195  std::vector<double> dOdpVec_; // size = number of sensitivity params.
196  std::vector<double> dOdpAdjVec_; // size = number of sensitivity params.
197 
198  std::vector<double> scaled_dOdpVec_; // size = number of sensitivity params.
199  std::vector<double> scaled_dOdpAdjVec_; // size = number of sensitivity params.
200 
201  std::vector<double> paramOrigVals_; // size = number of sensitivity params.
202 
203  N_LAS_Vector * lambdaVectorPtr_;
204  N_LAS_Vector * savedRHSVectorPtr_;
205  N_LAS_Vector * savedNewtonVectorPtr_;
206  N_LAS_Vector * origFVectorPtr_;
207  N_LAS_Vector * pertFVectorPtr_;
208  N_LAS_Vector * testFVectorPtr_;
209 
211 
212  N_TOP_Topology & top_;
213 
214  N_UTL_Expression * expPtr_;
215 
217  std::vector<std::string> paramNameVec_;
218 };
219 
220 //-----------------------------------------------------------------------------
221 // Function : N_NLS_Sensitivity::getNumIterations
222 // Purpose : doesn't do anything, is just a placeholder.
223 // Special Notes : This one may be needed later, I'm not sure.
224 //
225 // Scope : public
226 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
227 // Creation Date : 10/31/02
228 //-----------------------------------------------------------------------------
230 {
231  return 0;
232 }
233 
234 
235 //-----------------------------------------------------------------------------
236 // Dummy function since homotopy doesn't work with old solver
237 //-----------------------------------------------------------------------------
239 {
240  return 0;
241 }
242 
243 //-----------------------------------------------------------------------------
244 // Dummy function since homotopy doesn't work with old solver
245 //-----------------------------------------------------------------------------
247 {
248  return 0;
249 }
250 
251 //-----------------------------------------------------------------------------
252 // Dummy function since homotopy doesn't work with old solver
253 //-----------------------------------------------------------------------------
255 {
256  return true;
257 }
258 
259 //-----------------------------------------------------------------------------
260 // Dummy function since homotopy doesn't work with old solver
261 //-----------------------------------------------------------------------------
263 {
264  return true;
265 }
266 
267 //-----------------------------------------------------------------------------
268 // Function : N_NLS_Sensitivity::setAnalysisMode
269 // Purpose : doesn't do anything, is just a placeholder.
270 // Special Notes :
271 // Scope : public
272 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
273 // Creation Date : 10/31/02
274 //-----------------------------------------------------------------------------
276 {
277 
278 }
279 
280 #ifdef Xyce_DEBUG_NONLINEAR
281 //-----------------------------------------------------------------------------
282 // Function : N_NLS_Sensitivity::getDebugLevel
283 // Purpose :
284 // Special Notes :
285 // Scope : public
286 // Creator : Eric Keiter, SNL
287 // Creation Date : 09/17/2007
288 //-----------------------------------------------------------------------------
289 inline int N_NLS_Sensitivity::getDebugLevel() const
290 {
291  return -100;
292 }
293 
294 //-----------------------------------------------------------------------------
295 // Function : N_NLS_Sensitivity::getScreenOutputFlag
296 // Purpose :
297 // Special Notes :
298 // Scope : public
299 // Creator : Eric Keiter, SNL
300 // Creation Date : 09/17/2007
301 //-----------------------------------------------------------------------------
302 inline bool N_NLS_Sensitivity::getScreenOutputFlag () const
303 {
304  return false;
305 }
306 
307 //---------------------------------------------------------------------------
308 // Function : N_NLS_Sensitivity::getDebugMinTime
309 //
310 // Return Type : double
311 //---------------------------------------------------------------------------
312 inline double N_NLS_Sensitivity::getDebugMinTime() const
313 {
314  return 0.0;
315 }
316 
317 //---------------------------------------------------------------------------
318 // Function : N_NLS_Sensitivity::getDebugMaxTime
319 //
320 // Return Type : double
321 //---------------------------------------------------------------------------
322 inline double N_NLS_Sensitivity::getDebugMaxTime() const
323 {
324  return N_UTL_MachineDependentParams::DoubleMax();
325 }
326 
327 //---------------------------------------------------------------------------
328 // Function : N_NLS_Sensitivity::getDebugMinTimeStep
329 //
330 // Return Type : int
331 //---------------------------------------------------------------------------
332 inline int N_NLS_Sensitivity::getDebugMinTimeStep() const
333 {
334  return 0;
335 }
336 
337 //---------------------------------------------------------------------------
338 // Function : N_NLS_Sensitivity::getDebugMaxTimeStep
339 //
340 // Return Type : int
341 //---------------------------------------------------------------------------
342 inline int N_NLS_Sensitivity::getDebugMaxTimeStep() const
343 {
344  return N_UTL_MachineDependentParams::IntMax();
345 }
346 
347 //---------------------------------------------------------------------------
348 // Function : N_NLS_Sensitivity::getMMFormat
349 //
350 // Return Type : bool
351 //---------------------------------------------------------------------------
352 inline bool N_NLS_Sensitivity::getMMFormat () const
353 {
354  return false;
355 }
356 
357 
358 #endif // debug nonlin
359 
360 #endif
361