Xyce  6.1
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-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_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.80 $
46 //
47 // Revision Date : $Date: 2015/08/21 22:37:27 $
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_TOP_fwd.h>
60 #include <N_UTL_MachDepParams.h>
61 #include <N_NLS_NonLinearSolver.h>
63 
64 namespace Xyce {
65 namespace Nonlinear {
66 
67 //-----------------------------------------------------------------------------
68 // Class : objective function data
69 // Purpose :
70 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
71 // Creation Date : 8/17/2015
72 //-----------------------------------------------------------------------------
74 {
75 public:
77  numExpVars_(0),
78  expVal_(0.0),
79  objFuncString_(""),
80  curValue_(0.0),
81  objFuncEval_(0.0),
82  dOdp_(0.0),
83  expPtr_(0)
84  {};
85 
86 public:
87  // expression related stuff:
88  bool objFuncGiven_;
91  std::vector<std::string> expVarNames_;
92  std::vector<int> expVarGIDs_;
93  std::vector<int> expVarLocal_;
94  std::vector<double> expVarVals_;
95  std::vector<double> expVarDerivs_;
96  double expVal_;
97  std::string objFuncString_;
98  Util::Expression * expPtr_;
99 
100  double curValue_; // current value of the variable.
101  double objFuncEval_;// value of the evaluated objective function.
102  double dOdp_;
103 
104  Linear::Vector* dOdXVectorPtr_; // size of solution vector.
105 };
106 
107 //-----------------------------------------------------------------------------
108 // Class : Sensitivity
109 // Purpose :
110 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
111 // Creation Date : 10/20/02
112 //-----------------------------------------------------------------------------
114 {
115 public:
116  static void populateMetadata(IO::PkgOptionsMgr &options_manager);
117 
118  Sensitivity (
120  Topo::Topology & top_,
121  const IO::CmdParse & cp);
122 
123  ~Sensitivity ();
124 
125  bool icSensitivity (
126  std::vector<double> & objectiveVec,
127  std::vector<double> & dOdpVec,
128  std::vector<double> & dOdpAdjVec,
129  std::vector<double> & scaled_dOdpVec,
130  std::vector<double> & scaled_dOdpAdjVec);
131 
132  int solve (NonLinearSolver * nlsTmpPtr=NULL) {return -1;};
133  int solve (
134  std::vector<double> & objectiveVec,
135  std::vector<double> & dOdpVec,
136  std::vector<double> & dOdpAdjVec,
137  std::vector<double> & scaled_dOdpVec,
138  std::vector<double> & scaled_dOdpAdjVec);
139 
140  int solveDirect ();
141  int solveAdjoint ();
142 
143  void stdOutput (
144  std::string idString,
145  std::vector<double> & paramVals,
146  std::vector<double> & sensitivities,
147  std::vector<double> & scaled_sensitivities
148  );
149 
150  void fileOutput (
151  std::string idString,
152  std::vector<double> & paramVals,
153  std::vector<double> & sensitivities,
154  std::vector<double> & scaled_sensitivities
155  );
156 
157 #if 0
158  void dakOutput (
159  std::string idString,
160  std::vector<double> & paramVals,
161  std::vector<double> & sensitivities,
162  std::vector<double> & scaled_sensitivities
163  );
164 #endif
165 
166  bool calcObjFuncDerivs ();
167 
168  bool setOptions(const Util::OptionBlock& OB);
169  bool setSensitivityOptions(const Util::OptionBlock& OB);
170 
171  bool setTranOptions(const Util::OptionBlock& OB) {return true;}
172  bool setHBOptions(const Util::OptionBlock& OB) {return true;}
173  bool setNLPOptions(const Util::OptionBlock& OB) {return true;}
174 
175  // Note, many of the following are here b/c they are purely
176  // virtual functions of the nonlinear solver class.
177  // They don't have much meaning here. It may turn out that
178  // having this class derive off of the NonLinearSolver
179  // class doesn't make much sense. If so, I'll change it later. ERK
180 
181  int getNumIterations() const;
182 
183  int getDebugLevel() const;
184  bool getScreenOutputFlag() const;
185  double getDebugMinTime() const;
186  double getDebugMaxTime() const;
187  int getDebugMinTimeStep() const;
188  int getDebugMaxTimeStep() const;
189  bool getMMFormat () const;
190 
191  double getMaxNormF() const;
192  int getMaxNormFindex() const;
193 
194  int getContinuationStep() const;
195  int getParameterNumber() const;
196  bool isFirstContinuationParam() const;
197  bool isFirstSolveComplete() const;
198  void setAnalysisMode(AnalysisMode mode);
199 
200 private:
205  bool outputScaledFlag_; // include scaled sensitivities in IO
206  bool outputUnscaledFlag_; // include unscaled sensitivities in IO
208 
212  bool forceFD_;
214 
217  std::vector<objectiveFunctionData*> objFuncDataVec_;
218 
219  // finite difference variables
221  double sqrtEta_;
223 
225 
226  Linear::Vector * lambdaVectorPtr_;
227  Linear::Vector * savedRHSVectorPtr_;
228  Linear::Vector * savedNewtonVectorPtr_;
229 
231 
232  Topo::Topology & top_;
233 
236  std::vector<std::string> paramNameVec_;
237 };
238 
239 //-----------------------------------------------------------------------------
240 // Function : Sensitivity::getNumIterations
241 // Purpose : doesn't do anything, is just a placeholder.
242 // Special Notes : This one may be needed later, I'm not sure.
243 //
244 // Scope : public
245 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
246 // Creation Date : 10/31/02
247 //-----------------------------------------------------------------------------
249 {
250  return 0;
251 }
252 
253 //-----------------------------------------------------------------------------
254 // Dummy function since homotopy doesn't work with old solver
255 //-----------------------------------------------------------------------------
257 {
258  return 0;
259 }
260 
261 //-----------------------------------------------------------------------------
262 // Dummy function since homotopy doesn't work with old solver
263 //-----------------------------------------------------------------------------
265 {
266  return 0;
267 }
268 
269 //-----------------------------------------------------------------------------
270 // Dummy function since homotopy doesn't work with old solver
271 //-----------------------------------------------------------------------------
273 {
274  return true;
275 }
276 
277 //-----------------------------------------------------------------------------
278 // Dummy function since homotopy doesn't work with old solver
279 //-----------------------------------------------------------------------------
281 {
282  return true;
283 }
284 
285 //-----------------------------------------------------------------------------
286 // Function : Sensitivity::setAnalysisMode
287 // Purpose : doesn't do anything, is just a placeholder.
288 // Special Notes :
289 // Scope : public
290 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
291 // Creation Date : 10/31/02
292 //-----------------------------------------------------------------------------
294 {
295 
296 }
297 
298 //-----------------------------------------------------------------------------
299 // Function : Sensitivity::getDebugLevel
300 // Purpose :
301 // Special Notes :
302 // Scope : public
303 // Creator : Eric Keiter, SNL
304 // Creation Date : 09/17/2007
305 //-----------------------------------------------------------------------------
306 inline int Sensitivity::getDebugLevel() const
307 {
308  return -100;
309 }
310 
311 //-----------------------------------------------------------------------------
312 // Function : Sensitivity::getScreenOutputFlag
313 // Purpose :
314 // Special Notes :
315 // Scope : public
316 // Creator : Eric Keiter, SNL
317 // Creation Date : 09/17/2007
318 //-----------------------------------------------------------------------------
320 {
321  return false;
322 }
323 
324 //---------------------------------------------------------------------------
325 // Function : Sensitivity::getDebugMinTime
326 //
327 // Return Type : double
328 //---------------------------------------------------------------------------
329 inline double Sensitivity::getDebugMinTime() const
330 {
331  return 0.0;
332 }
333 
334 //---------------------------------------------------------------------------
335 // Function : Sensitivity::getDebugMaxTime
336 //
337 // Return Type : double
338 //---------------------------------------------------------------------------
339 inline double Sensitivity::getDebugMaxTime() const
340 {
341  return Util::MachineDependentParams::DoubleMax();
342 }
343 
344 //---------------------------------------------------------------------------
345 // Function : Sensitivity::getDebugMinTimeStep
346 //
347 // Return Type : int
348 //---------------------------------------------------------------------------
350 {
351  return 0;
352 }
353 
354 //---------------------------------------------------------------------------
355 // Function : Sensitivity::getDebugMaxTimeStep
356 //
357 // Return Type : int
358 //---------------------------------------------------------------------------
360 {
361  return Util::MachineDependentParams::IntMax();
362 }
363 
364 //---------------------------------------------------------------------------
365 // Function : Sensitivity::getMMFormat
366 //
367 // Return Type : bool
368 //---------------------------------------------------------------------------
369 inline bool Sensitivity::getMMFormat () const
370 {
371  return false;
372 }
373 
374 } // namespace Nonlinear
375 } // namespace Xyce
376 
377 #endif // Xyce_N_NLS_Sensitivity_h
378 
static void populateMetadata(IO::PkgOptionsMgr &options_manager)
std::vector< std::string > expVarNames_
Pure virtual class to augment a linear system.
int solve(NonLinearSolver *nlsTmpPtr=NULL)
Linear::Vector * savedNewtonVectorPtr_
void stdOutput(std::string idString, std::vector< double > &paramVals, std::vector< double > &sensitivities, std::vector< double > &scaled_sensitivities)
void fileOutput(std::string idString, std::vector< double > &paramVals, std::vector< double > &sensitivities, std::vector< double > &scaled_sensitivities)
Sensitivity(NonLinearSolver &nls_, Topo::Topology &top_, const IO::CmdParse &cp)
bool setTranOptions(const Util::OptionBlock &OB)
bool icSensitivity(std::vector< double > &objectiveVec, std::vector< double > &dOdpVec, std::vector< double > &dOdpAdjVec, std::vector< double > &scaled_dOdpVec, std::vector< double > &scaled_dOdpAdjVec)
bool setOptions(const Util::OptionBlock &OB)
bool setHBOptions(const Util::OptionBlock &OB)
bool setSensitivityOptions(const Util::OptionBlock &OB)
void setAnalysisMode(AnalysisMode mode)
bool setNLPOptions(const Util::OptionBlock &OB)
std::vector< objectiveFunctionData * > objFuncDataVec_
std::vector< std::string > paramNameVec_