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.56.2.1 $
46 //
47 // Revision Date : $Date: 2014/08/19 16:28:07 $
48 //
49 // Current Owner : $Author: erkeite $
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_PDS_fwd.h>
59 #include <N_NLS_NLParams.h>
60 #include <N_NLS_NonLinearSolver.h>
61 
62 namespace Xyce {
63 namespace Nonlinear {
64 
66 {
71 };
72 
73 //-----------------------------------------------------------------------------
74 // Class : Sensitivity
75 // Purpose :
76 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
77 // Creation Date : 10/20/02
78 //-----------------------------------------------------------------------------
79 
81 {
82 public:
84  N_TOP_Topology & top_,
85  N_IO_CmdParse & cp);
86 
87  ~Sensitivity ();
88 
89  bool icSensitivity (
90  std::vector<double> & objectiveVec,
91  std::vector<double> & dOdpVec,
92  std::vector<double> & dOdpAdjVec,
93  std::vector<double> & scaled_dOdpVec,
94  std::vector<double> & scaled_dOdpAdjVec);
95 
96  int solve (NonLinearSolver * nlsTmpPtr=NULL) {return -1;};
97  int solve (
98  std::vector<double> & objectiveVec,
99  std::vector<double> & dOdpVec,
100  std::vector<double> & dOdpAdjVec,
101  std::vector<double> & scaled_dOdpVec,
102  std::vector<double> & scaled_dOdpAdjVec);
103 
104  int solveDirect ();
105  int solveAdjoint ();
106 
107  void stdOutput (
108  std::string idString,
109  std::vector<double> & paramVals,
110  std::vector<double> & sensitivities,
111  std::vector<double> & scaled_sensitivities
112  );
113 
114  void fileOutput (
115  std::string idString,
116  std::vector<double> & paramVals,
117  std::vector<double> & sensitivities,
118  std::vector<double> & scaled_sensitivities
119  );
120 
121  void dakOutput (
122  std::string idString,
123  std::vector<double> & paramVals,
124  std::vector<double> & sensitivities,
125  std::vector<double> & scaled_sensitivities
126  );
127 
128  bool loadSensitivityResiduals ();
129 
130  bool calcObjFuncDerivs ();
131 
132  bool setOptions(const N_UTL_OptionBlock& OB);
133  bool setSensitivityOptions(const N_UTL_OptionBlock& OB);
134  bool setTranOptions(const N_UTL_OptionBlock& OB);
135  bool setHBOptions(const N_UTL_OptionBlock& OB);
136 
137  // Note, many of the following are here b/c they are purely
138  // virtual functions of the nonlinear solver class.
139  // They don't have much meaning here. It may turn out that
140  // having this class derive off of the NonLinearSolver
141  // class doesn't make much sense. If so, I'll change it later. ERK
142 
143  int getNumIterations() const;
144 #ifdef Xyce_DEBUG_NONLINEAR
145  int getDebugLevel() const;
146  bool getScreenOutputFlag() const;
147  double getDebugMinTime() const;
148  double getDebugMaxTime() const;
149  int getDebugMinTimeStep() const;
150  int getDebugMaxTimeStep() const;
151  bool getMMFormat () const;
152 #endif
153  double getMaxNormF() const;
154  int getMaxNormFindex() const;
155 
156  int getContinuationStep() const;
157  int getParameterNumber() const;
158  bool isFirstContinuationParam() const;
159  bool isFirstSolveComplete() const;
160  void setAnalysisMode(AnalysisMode mode);
161 
162 protected:
163 private:
164 
165 public:
166 protected:
167 private:
168 
169  //bool allocateddXVec_;
174  bool outputScaledFlag_; // include scaled sensitivities in IO
175  bool outputUnscaledFlag_; // include unscaled sensitivities in IO
177 
181  bool forceFD_;
183 
184  // expression related stuff:
189  std::vector<std::string> expVarNames_;
190  std::vector<int> expVarGIDs_;
191  std::vector<int> expVarLocal_;
192  std::vector<double> expVarVals_;
193  std::vector<double> expVarDerivs_;
194  double expVal_;
195  std::string objFuncString_;
196 
197  double curValue_; // current value of the variable.
198  double objFuncEval_;// value of the evaluated objective function.
199  double dOdp_;
200  double sqrtEta_;
202 
203  N_LAS_Vector* dOdXVectorPtr_; // size of solution vector.
204 
205  N_LAS_Vector * lambdaVectorPtr_;
206  N_LAS_Vector * savedRHSVectorPtr_;
207  N_LAS_Vector * savedNewtonVectorPtr_;
208 
209  N_LAS_Vector * origFVectorPtr_;
210  N_LAS_Vector * pertFVectorPtr_;
211 
212  N_LAS_Vector * origQVectorPtr_;
213  N_LAS_Vector * pertQVectorPtr_;
214 
215  N_LAS_Vector * origBVectorPtr_;
216  N_LAS_Vector * pertBVectorPtr_;
217 
219 
220  N_TOP_Topology & top_;
221 
222  N_UTL_Expression * expPtr_;
223 
225  std::vector<std::string> paramNameVec_;
226 };
227 
228 //-----------------------------------------------------------------------------
229 // Function : Sensitivity::getNumIterations
230 // Purpose : doesn't do anything, is just a placeholder.
231 // Special Notes : This one may be needed later, I'm not sure.
232 //
233 // Scope : public
234 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
235 // Creation Date : 10/31/02
236 //-----------------------------------------------------------------------------
238 {
239  return 0;
240 }
241 
242 //-----------------------------------------------------------------------------
243 // Dummy function since homotopy doesn't work with old solver
244 //-----------------------------------------------------------------------------
246 {
247  return 0;
248 }
249 
250 //-----------------------------------------------------------------------------
251 // Dummy function since homotopy doesn't work with old solver
252 //-----------------------------------------------------------------------------
254 {
255  return 0;
256 }
257 
258 //-----------------------------------------------------------------------------
259 // Dummy function since homotopy doesn't work with old solver
260 //-----------------------------------------------------------------------------
262 {
263  return true;
264 }
265 
266 //-----------------------------------------------------------------------------
267 // Dummy function since homotopy doesn't work with old solver
268 //-----------------------------------------------------------------------------
270 {
271  return true;
272 }
273 
274 //-----------------------------------------------------------------------------
275 // Function : Sensitivity::setAnalysisMode
276 // Purpose : doesn't do anything, is just a placeholder.
277 // Special Notes :
278 // Scope : public
279 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
280 // Creation Date : 10/31/02
281 //-----------------------------------------------------------------------------
283 {
284 
285 }
286 
287 #ifdef Xyce_DEBUG_NONLINEAR
288 //-----------------------------------------------------------------------------
289 // Function : Sensitivity::getDebugLevel
290 // Purpose :
291 // Special Notes :
292 // Scope : public
293 // Creator : Eric Keiter, SNL
294 // Creation Date : 09/17/2007
295 //-----------------------------------------------------------------------------
296 inline int Sensitivity::getDebugLevel() const
297 {
298  return -100;
299 }
300 
301 //-----------------------------------------------------------------------------
302 // Function : Sensitivity::getScreenOutputFlag
303 // Purpose :
304 // Special Notes :
305 // Scope : public
306 // Creator : Eric Keiter, SNL
307 // Creation Date : 09/17/2007
308 //-----------------------------------------------------------------------------
309 inline bool Sensitivity::getScreenOutputFlag () const
310 {
311  return false;
312 }
313 
314 //---------------------------------------------------------------------------
315 // Function : Sensitivity::getDebugMinTime
316 //
317 // Return Type : double
318 //---------------------------------------------------------------------------
319 inline double Sensitivity::getDebugMinTime() const
320 {
321  return 0.0;
322 }
323 
324 //---------------------------------------------------------------------------
325 // Function : Sensitivity::getDebugMaxTime
326 //
327 // Return Type : double
328 //---------------------------------------------------------------------------
329 inline double Sensitivity::getDebugMaxTime() const
330 {
331  return N_UTL_MachineDependentParams::DoubleMax();
332 }
333 
334 //---------------------------------------------------------------------------
335 // Function : Sensitivity::getDebugMinTimeStep
336 //
337 // Return Type : int
338 //---------------------------------------------------------------------------
339 inline int Sensitivity::getDebugMinTimeStep() const
340 {
341  return 0;
342 }
343 
344 //---------------------------------------------------------------------------
345 // Function : Sensitivity::getDebugMaxTimeStep
346 //
347 // Return Type : int
348 //---------------------------------------------------------------------------
349 inline int Sensitivity::getDebugMaxTimeStep() const
350 {
351  return N_UTL_MachineDependentParams::IntMax();
352 }
353 
354 //---------------------------------------------------------------------------
355 // Function : Sensitivity::getMMFormat
356 //
357 // Return Type : bool
358 //---------------------------------------------------------------------------
359 inline bool Sensitivity::getMMFormat () const
360 {
361  return false;
362 }
363 
364 #endif // debug nonlin
365 
366 } // namespace Nonlinear
367 } // namespace Xyce
368 
370 
371 #endif // Xyce_N_NLS_Sensitivity_h
372