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