Xyce  6.1
N_ANP_ROL.C
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_ANP_ROL.C,v $
27 // Purpose : .ROL class analysis functions.
28 // Special Notes :
29 // Creator :
30 // Creation Date :
31 //
32 // Revision Information:
33 // ---------------------
34 // Revision Number: $Revision: 1.17 $
35 // Revision Date : $Date: 2015/10/27 19:32:10 $
36 // Current Owner : $Author: tvrusso $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 #include <N_ANP_AnalysisManager.h>
41 #include <N_ANP_ROL.h>
42 
43 #include <N_ANP_OutputMgrAdapter.h>
44 #include <N_ANP_SweepParam.h>
45 #include <N_IO_CircuitBlock.h>
46 #include <N_IO_CmdParse.h>
47 #include <N_IO_InitialConditions.h>
48 #include <N_IO_OptionBlock.h>
49 #include <N_IO_PkgOptionsMgr.h>
50 #include <N_IO_SpiceSeparatedFieldTool.h>
51 #include <N_LOA_Loader.h>
52 #include <N_NLS_Manager.h> // TT: was not included
53 #include <N_NLS_fwd.h> // TT: was not included
54 #include <N_TIA_DataStore.h>
55 #include <N_TIA_NoTimeIntegration.h> // TT: was not included
56 #include <N_TIA_StepErrorControl.h>
57 #include <N_TIA_WorkingIntegrationMethod.h> // TT: was not included
58 
59 #include <N_UTL_Diagnostic.h>
60 #include <N_UTL_ExtendedString.h>
61 #include <N_UTL_Factory.h>
62 #include <N_UTL_FeatureTest.h>
63 #include <N_UTL_OptionBlock.h>
64 #include <N_ERH_Message.h>
65 
66 #include <N_TOP_Topology.h>
67 #include <N_LAS_System.h>
68 #include <N_LAS_Builder.h>
69 
70 
71 #include <N_ANP_StepEvent.h>
72 //#include <N_ANP_ROLEvent.h>
73 #include <N_PDS_Manager.h>
74 #include <N_UTL_Timer.h>
75 
77 
78 // ROL includes
79 // Trilinos ROL includes
80 #include <N_ANP_DCSweep.h>
81 
82 #ifdef Xyce_ROL
83 
84 #ifndef OBJTYPE
85 #define OBJTYPE 1 // 0 - L2Norm, 1 - amplifier circuit
86 #endif
87 
88 #ifndef UQ
89 #define UQ 0
90 #endif
91 
92 #include "ROL_StdVector.hpp"
93 #include "ROL_Vector.hpp"
94 
95 #include "ROL_Algorithm.hpp"
96 #include "ROL_CompositeStep.hpp"
97 #include "ROL_LineSearchStep.hpp"
98 #include "Teuchos_oblackholestream.hpp"
99 #include "Teuchos_GlobalMPISession.hpp"
100 #include "ROL_BoundConstraint.hpp"
101 #include "Teuchos_XMLParameterListHelpers.hpp"
102 #include "ROL_TrustRegionStep.hpp"
103 #include "ROL_StatusTest.hpp"
104 #include "ROL_Types.hpp"
105 #include "ROL_BundleStep.hpp"
106 #include "ROL_BundleStatusTest.hpp"
107 
108 #include "ROL_XyceVector.hpp"
109 
111 #include "ROL_Reduced_Objective_SimOpt.hpp"
112 #include "ROL_ParametrizedObjective_SimOpt.hpp"
113 #include "ROL_Reduced_ParametrizedObjective_SimOpt.hpp"
114 
115 #if UQ==1
116 #include "Teuchos_Comm.hpp"
117 #include "Teuchos_DefaultComm.hpp"
118 #include "Teuchos_CommHelpers.hpp"
119 
120 #include "ROL_RiskNeutralObjective.hpp"
121 #include "ROL_RiskAverseObjective.hpp"
122 // ROL sample generators
123 #include "ROL_MonteCarloGenerator.hpp"
124 #include "ROL_QuasiMonteCarloGenerator.hpp"
125 #include "ROL_StdTeuchosBatchManager.hpp"
126 #include "ROL_UserInputGenerator.hpp"
127 // ROL CVaR definitions
128 #include "ROL_PlusFunction.hpp"
129 #include "ROL_CVaR.hpp"
130 #include "ROL_CVaRVector.hpp"
131 #include "ROL_CVaRBoundConstraint.hpp"
132 
133 #endif
134 
135 #endif
136 
137 // std includes
138 #include <assert.h>
139 #include <fstream>
140 
141 namespace Xyce {
142 namespace Analysis {
143 
145  AnalysisManager &analysis_manager,
146  Nonlinear::Manager &nonlinear_manager, // TT
147  Loader::Loader &loader,
148  Linear::System & linear_system,
149  Topo::Topology & topology,
150  IO::InitialConditionsManager & initial_conditions_manager)
151  : AnalysisBase(analysis_manager, "ROL"),
152  analysisManager_(analysis_manager),
153  nonlinearManager_(nonlinear_manager), // TT
154  loader_(loader),
155  topology_(topology),
156  initialConditionsManager_(initial_conditions_manager),
157  linearSystem_(linear_system),
158  outputManagerAdapter_(analysis_manager.getOutputManagerAdapter()),
159  stepLoopSize_(0),
160  rolLoopInitialized_(false), // TT
161  solutionPtrVector_(0),
162  mydfdpPtrVector_(0),
163  mydqdpPtrVector_(0),
164  mydbdpPtrVector_(0),
165  mysensRHSPtrVector_(0),
166  statePtrVector_(0),
167  constraintPtrVector_(0),
168  testPtrVector_(0),
169  jvecPtrVector_(0)
170 {
171  // For testing purposes get parameters from txt file
172  std::ifstream param_file;
173  std::string deviceName,paramName,dummy;
174  RealT temp;
175  numParams_ = 0;
176  param_file.open("parameters.txt");
177  getline(param_file,dummy); // skip the first line
178  while (true)
179  {
180  if(!(param_file >> deviceName)) break;
181  if(!(param_file >> paramName)) break;
182  paramName = deviceName+":"+paramName;
183  paramNameVec_.push_back(paramName);
184  if(!(param_file >> temp)) break; // init guess
185  if(!(param_file >> temp)) break; // lo bound
186  if(!(param_file >> temp)) break; // up bound
187  numParams_ += 1;
188  }
189  param_file.close();
190 }
191 
193 
194 //TT : copied from DCSweep;
195 //-----------------------------------------------------------------------------
196 // Function : AnalysisManager::setTranOptions
197 // Purpose :
198 // Special Notes : These are from '.options timeint'
199 // Scope : public
200 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
201 // Creation Date : 04/18/02
202 //-----------------------------------------------------------------------------
204  const Util::OptionBlock & option_block)
205 {
206  for (Util::ParamList::const_iterator it = option_block.begin(), end = option_block.end(); it != end; ++it)
207  {
208  const Util::Param &param = (*it);
209 
210  if (param.uTag() == "DAESTATEDERIV")
211  analysisManager_.setDAEStateDerivFlag(static_cast<bool> (param.getImmutableValue<int>()));
212  else if (param.uTag() == "DEBUGLEVEL")
213  IO::setTimeIntegratorDebugLevel(analysisManager_.getCommandLine(), param.getImmutableValue<int>());
214  else if (nonlinearManager_.setReturnCodeOption(param))
215  ;
216  else if (tiaParams_.setTimeIntegratorOption(param))
217  ;
218  else if (setDCOPOption(param))
219  ;
220  else if (param.uTag() == "METHOD")
221  ;
222  else
223  Report::UserError() << param.uTag() << " is not a recognized time integration option";
224  }
225 
226  return true;
227 }
228 
229 
230 //-----------------------------------------------------------------------------
231 // Function : ROL::setAnalysisParams
232 // Purpose :
233 // Special Notes :
234 // Scope : public
235 // Creator : Eric R. Keiter, SNL
236 // Creation Date : 6/22/10
237 //-----------------------------------------------------------------------------
238 bool ROL::setAnalysisParams(const Util::OptionBlock & paramsBlock)
239 {
240  stepSweepVector_.push_back(parseSweepParams(paramsBlock.begin(), paramsBlock.end()));
242 
243  return true;
244 }
245 
246 const TimeIntg::TIAParams &
248 {
249  return tiaParams_; // TT
250 }
251 
254 {
255  return tiaParams_; // TT
256 }
257 
258 //-----------------------------------------------------------------------------
259 // Function : ROL::run()
260 // Purpose : This is the main controlling loop for ROL analysis.
261 //
262 // Special Notes :
263 // Scope : public
264 // Creator : Eric Keiter, SNL
265 // Creation Date : 10/04/00
266 //-----------------------------------------------------------------------------
267 // Revised: Timur Takhtaganov, 06/03/2015
268 //
270 {
271  // Instead of running DCSweep type analysis, we will run ROL analysis; the following will be only used in solve() function in the EqualityConstraint class: doInit() && doLoopProcess() && doFinish();
272  return doInit() && runROLAnalysis() && doFinish();
273  // return doInit() && doLoopProcess() && doFinish();
274 }
275 
276 //-----------------------------------------------------------------------------
277 // Function : ROL::init()
278 // Purpose :
279 // Special Notes :
280 // Scope : public
281 // Creator :
282 // Creation Date : 06/02/2015
283 //-----------------------------------------------------------------------------
285 {
286  bool status;
287 
289 
290  if ( !rolLoopInitialized_ )
291  {
292  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
293  {
294  Xyce::dout() << std::endl << std::endl;
295  Xyce::dout() << section_divider << std::endl;
296  Xyce::dout() << "ROL Sweep::init" << std::endl;
297  }
298 
299  // TT: processes sweep parameters; location N_ANP_SweepParam.C
301 
302  // status = doAllocations(stepLoopSize_,numParams_); // TT: call here if runROLAnalysis is not called
303 
304  // TT: created ROLEvent, but this still doesn't work, probably needs be included in a bunch of places
305  //Util::publish<ROLEvent>(analysisManager_, ROLEvent(ROLEvent::INITIALIZE, stepSweepVector_, stepLoopSize_));
306 
307  // TT: two lines from DCSweep, changed to Step instead of DC
308  //outputManagerAdapter_.setStepAnalysisMaxSteps( stepLoopSize_ );
310 
311  rolLoopInitialized_ = true;
312 
314 
315  }
316 
317  // analysisManager_.setStepLoopInitialized(true);
318 
319  // TT: copied from DCSweep
320  //setup for operating pt calculation
323 
324  // analysisManager_.setAnalysisMode(ANP_MODE_ROL); // TT: sets analysis mode; added ANP_MODE_ROL to N_ANP_AnalysisManager.C and N_ANP_fwd.C
325 
326  // TT: copied from DCSweep;
327  stepNumber = 0;
329  if (getDoubleDCOPEnabled() && getDoubleDCOPStep() == 0)
330  {
332  }
333 
334 
335  initializeSolution_(); // TT: this function is copied from DCSweep
336 
337  return true;
338 }
339 
340 //-----------------------------------------------------------------------------
341 // Function : ROL::initializeSolution()
342 // Purpose : Imitate the behavior of DCSweep
343 //
344 // Special Notes : Copied from DCSweep
345 // Scope : public
346 // Creator : Timur Takhtaganov
347 // Creation Date : 06/02/2015
348 //-----------------------------------------------------------------------------
350 {
351  // set initial guess, if there is one to be set.
352  // this setInitialGuess call is to up an initial guess in the
353  // devices that have them (usually PDE devices). This is different than
354  // the "intializeProblem" call, which sets IC's. (initial conditions are
355  // different than initial guesses.
356  loader_.setInitialGuess(analysisManager_.getDataStore()->nextSolutionPtr); //TT: this function calls a function by the same name in DeviceManager; sets initial guess for devices that have one (PDE?)
357 
358  // If available, set initial solution (.IC, .NODESET, etc).
359  // setInputOPFlag(
360  // outputManagerAdapter_.setupInitialConditions(
361  // *analysisManager_.getDataStore()->nextSolutionPtr,
362  // *analysisManager_.getDataStore()->flagSolutionPtr));
365  topology_.getSolutionNodeNameMap(),
368 
369  // Set a constant history for operating point calculation
373 }
374 
375 // TT: this function gets called by the value() function in EqualityConstraint class; it updates sweep parameter so that correct source term is loaded into RHS vector
376 void ROL::setSweepValue(int step)
377 {
378  bool reset = updateSweepParams(loader_, step, stepSweepVector_.begin(), stepSweepVector_.end(), false);// TT: update sweep parameters; location N_ANP_SweepParam.C
379 }
380 
381 
382 //-----------------------------------------------------------------------------
383 // Function : ROL::loopProcess()
384 // Purpose :
385 // Special Notes :
386 // Scope : public
387 // Creator : Eric Keiter, SNL
388 // Creation Date : 03/10/06
389 //-----------------------------------------------------------------------------
391 {
392  bool integration_status = true;
394 
395  //Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::INITIALIZE, stepSweepVector_, stepLoopSize_)); // TT: moved here from doInit();
396  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::INITIALIZE, AnalysisEvent::DC));
397 
398  // StepEvent step_event(StepEvent::STEP_STARTED, stepSweepVector_, currentStep);
399 
400  int currentStep = 0;
401  int finalStep = stepLoopSize_;
402  while (currentStep < finalStep)
403  {
405 
406  // Tell the manager if any of our sweeps are being reset in this loop iteration.
407  bool reset = updateSweepParams(loader_, currentStep, stepSweepVector_.begin(), stepSweepVector_.end(), false);// TT: update sweep parameters; location N_ANP_SweepParam.C
408 
409  analysisManager_.setSweepSourceResetFlag(reset);// TT: sets sweep source flag to reset in AnalysisManager
410 
412 
413  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
414  for (SweepVector::const_iterator it = stepSweepVector_.begin(), end = stepSweepVector_.end(); it != end; ++it)
415  Xyce::dout() << "ROL DC Sweep # " << currentStep <<"\t" << (*it);
416 
417  // TT
418  if (currentStep != 0 && reset)
419  {
422  }
423 
424 
425  // TT: the following line causes currSol and nextSol reset to zero
426  // Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_STARTED, stepSweepVector_, currentStep));
427 
428  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_STARTED, AnalysisEvent::DC, 0.0, currentStep));
429  //step_event.state = StepEvent::STEP_STARTED;
430  //Util::publish<StepEvent>(analysisManager_, step_event);
431 
432  takeStep_(); // TT: take integration step
433 
434  // Set things up for the next time step, based on if this one was
435  // successful.
437  {
438  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_SUCCESSFUL, AnalysisEvent::DC, 0.0, currentStep));
440  // collect solutions here
441  *(solutionPtrVector_[currentStep]) = *(ds.currSolutionPtr);
442  // solutionPtrVector_[currentStep]->printPetraObject(Xyce::dout());
443  }
444  else // stepAttemptStatus (ie do this if the step FAILED)
445  {
446  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_FAILED, AnalysisEvent::DC, 0.0, currentStep));
448  }
449 
450  currentStep = stepNumber;
451  } // end of sweep loop
452 
453  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::FINISH, AnalysisEvent::DC));
454 
455  // Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_COMPLETED, stepSweepVector_, currentStep));
456 
457  // step_event.state_ = StepEvent::STEP_COMPLETED;
458  // step_event.finalSimTime_ = getTIAParams().finalTime;
459  // Util::publish<StepEvent>(analysisManager_, step_event);
460 
461  return integration_status;
462 }
463 
464 
465 // TT: copied from DCSweep
467 {
471 
472 
473  // In case this is the upper level of a 2-level sim, tell the
474  // inner solve to do its prediction:
475  bool beginIntegrationFlag = analysisManager_.getBeginningIntegrationFlag(); // system_state.beginIntegrationFlag;
476  double nextTimeStep = analysisManager_.getStepErrorControl().currentTimeStep; // system_state.nextTimeStep;
477  double nextTime = analysisManager_.getStepErrorControl().nextTime; // system_state.nextTime;
478  int currentOrder = analysisManager_.getWorkingIntegrationMethod().getOrder(); // system_state.currentOrder;
479 
480  loader_.startTimeStep(beginIntegrationFlag, nextTimeStep, nextTime, currentOrder);
481 
482  return true;
483 }
484 
485 // TT: copied from DCSweep
487 {
488  { // Integration step predictor
489  Stats::StatTop _predictorStat("Predictor");
490  Stats::TimeBlock _predictorTimer(_predictorStat);
491 
493  }
494 
495  { // Load B/V source devices with time data
496  Stats::StatTop _updateDeviceSourceStat("Update Device Sources");
497  Stats::TimeBlock _updateDeviceSourceTimer(_updateDeviceSourceStat);
498 
500  }
501 
502  { // Nonlinear solve
503  Stats::StatTop _nonlinearSolveStat("Solve");
504  Stats::TimeBlock _nonlinearSolveTimer(_nonlinearSolveStat);
505 
507  }
508 
509  { // Add change to solution
510  Stats::StatTop _errorStat("Error Estimation");
511  Stats::TimeBlock _errorTimer(_errorStat);
512 
514 
516 
518  }
519 }
520 
521 bool ROL::doAllocations(int nc, int nz)
522 {
523  // Allocate space for solution and simulation space vectors
524  solutionPtrVector_.resize(nc);
525  statePtrVector_.resize(nc);
526  constraintPtrVector_.resize(nc);
527  jvecPtrVector_.resize(nc);
528  testPtrVector_.resize(nc);
529 
530  for (int i=0;i<nc;i++)
531  {
532  solutionPtrVector_[i] = linearSystem_.builder().createVector();
533  statePtrVector_[i] = linearSystem_.builder().createVector();
534  constraintPtrVector_[i] = linearSystem_.builder().createVector();
535  jvecPtrVector_[i] = linearSystem_.builder().createVector();
536  testPtrVector_[i] = linearSystem_.builder().createVector();
537  }
538  // Allocate space for sensitivity vectors
539  mydfdpPtrVector_.resize(nz);
540  mydqdpPtrVector_.resize(nz);
541  mydbdpPtrVector_.resize(nz);
542  mysensRHSPtrVector_.resize(nz);
543  for (int i=0;i<nz;i++)
544  {
545  mydfdpPtrVector_[i] = linearSystem_.builder().createVector();
546  mydqdpPtrVector_[i] = linearSystem_.builder().createVector();
547  mydbdpPtrVector_[i] = linearSystem_.builder().createVector();
548  mysensRHSPtrVector_[i] = linearSystem_.builder().createVector();
549  }
550 
551  return true;
552 }
553 
555 {
556  paramNameVec_.clear();
557  for (int i=0;i<stepLoopSize_;i++)
558  {
559  delete solutionPtrVector_[i];
560  solutionPtrVector_[i] = 0;
561  delete statePtrVector_[i];
562  statePtrVector_[i] = 0;
563  delete constraintPtrVector_[i];
564  constraintPtrVector_[i] = 0;
565  delete jvecPtrVector_[i];
566  jvecPtrVector_[i] = 0;
567  delete testPtrVector_[i];
568  testPtrVector_[i] = 0;
569  }
570  solutionPtrVector_.clear();
571  statePtrVector_.clear();
572  constraintPtrVector_.clear();
573  jvecPtrVector_.clear();
574  testPtrVector_.clear();
575 
576  for (int i=0;i<numParams_;i++)
577  {
578  delete mydfdpPtrVector_[i];
579  mydfdpPtrVector_[i] = 0;
580  delete mydqdpPtrVector_[i];
581  mydqdpPtrVector_[i] = 0;
582  delete mydbdpPtrVector_[i];
583  mydbdpPtrVector_[i] = 0;
584  delete mysensRHSPtrVector_[i];
585  mysensRHSPtrVector_[i] = 0;
586  }
587  mydfdpPtrVector_.clear();
588  mydqdpPtrVector_.clear();
589  mydbdpPtrVector_.clear();
590  mysensRHSPtrVector_.clear();
591 
592  return true;
593 }
594 
595 
596 // TT: copied from DCSweep
598 {
600 
601  Stats::StatTop _processSuccessfulStepStat("Successful Step");
602  Stats::TimeBlock _processSuccessfulStepTimer(_processSuccessfulStepStat);
603 
604  loader_.stepSuccess(TWO_LEVEL_MODE_DC_SWEEP); // analysisManager_.getTwoLevelMode());
605 
606  // This output call is for device-specific output, such as .OP,
607  // or internal plot output from PDE(TCAD) devices.
609 
610  // TT : not using
611  // if (sensFlag_ && !firstDoubleDCOPStep() )
612  // {
613  // nonlinearManager_.calcSensitivity(objectiveVec_, dOdpVec_, dOdpAdjVec_, scaled_dOdpVec_, scaled_dOdpAdjVec_);
614  // }
615 
616  // Do some statistics, as long as this isn't the first "double"
617  // DCOP step. (that one doesn't count)
618  if ( !firstDoubleDCOPStep() )
619  {
620  stepNumber += 1; // TT: this is inherited from AnalysisBase
623 
624  }
625 
626  // update the data arrays, output:
628 
629  //TT: print out current solution and rhs
630  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
631  {
632  if ( !firstDoubleDCOPStep() )
633  {
634  std::cout << "Current solution" << std::endl;
635  for (unsigned int k = 0; k < ds.solutionSize; k++)
636  {
637  std::cout << (*(ds.currSolutionPtr))[k] << std::endl;
638  }
639 
640  for (int i=0;i<3;i++)
641  {
642  std::cout << (*(ds.dFdxdVpVectorPtr))[i] << std::endl;
643  }
644 
645  std::cout << "Current f vector" << std::endl;
646  for (unsigned int k = 0; k < ds.daeFVectorPtr->globalLength(); k++)
647  {
648  std::cout << (*ds.daeFVectorPtr)[k] << std::endl;
649  }
650  std::cout << "Current q vector" << std::endl;
651  for (unsigned int k = 0; k < ds.daeQVectorPtr->globalLength(); k++)
652  {
653  std::cout << (*ds.daeQVectorPtr)[k] << std::endl;
654  }
655  std::cout << "Current b vector" << std::endl;
656  for (unsigned int k = 0; k < ds.daeBVectorPtr->globalLength(); k++)
657  {
658  std::cout << (*ds.daeBVectorPtr)[k] << std::endl;
659  }
660  }
661  }
662 
663  if (DEBUG_ANALYSIS & DEBUG_TIME && isActive(Diag::TIME_DUMP_SOLUTION_ARRAYS))
665 
666  //dcSweepOutput(); // TT: need something else here
667 
668  // now that output has been called, update the doubleDCOP step
669  // if neccessary. (pde-only)
670  nextDCOPStep();
671  // std::cout << "Setting analysis mode to DC_SWEEP" << std::endl;
673 
674  return true;
675 }
676 
677 //-----------------------------------------------------------------------------
678 // Function : DCSweep::processFailedStep()
679 // Purpose :
680 // Special Notes :
681 // Scope : public
682 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
683 // Creation Date : 1/28/08
684 //-----------------------------------------------------------------------------
686 {
687  Stats::StatTop _processFailedStat("Failed Steps");
688  Stats::TimeBlock _processFailedTimer(_processFailedStat);
689 
691 
692  stepNumber += 1;
693  rolSweepFailures_.push_back(stepNumber);
696 
697  return true;
698 }
699 
700 
701 //-----------------------------------------------------------------------------
702 // Function : ROL::doFinish()
703 // Purpose :
704 // Special Notes :
705 // Scope : public
706 // Creator : Eric Keiter, SNL
707 // Creation Date : 03/10/06
708 //-----------------------------------------------------------------------------
710 {
712 
713  return true;
714 }
715 
716 //-----------------------------------------------------------------------------
717 // Function : DCSweep::twoLevelStep
718 //
719 // Purpose : Used by 2-level Newton solves to execute a single DC sweep
720 // step.
721 //
722 // Special Notes : This is mostly what happens on the inner loop of
723 // dcSweepLoop, except that DC parameters are not updated,
724 // and success/failure of the step is not determined.
725 //
726 // Scope : public
727 // Creator : Eric Keiter, SNL
728 // Creation Date : 03/10/06
729 //-----------------------------------------------------------------------------
730 // TT: moved from DCSweep; I think its needed for pde devices
732 {
738 
740 }
741 
742 #if Xyce_ROL
743 typedef double RealT;
744 //-----------------------------------------------------------------------------
745 // Function : ROL::runROLAnalysis
746 // Purpose :
747 // Special Notes :
748 // Scope : public
749 // Creator : Timur Takhtaganov
750 // Creation Date : 06/02/2015
751 //-----------------------------------------------------------------------------
752 bool ROL::runROLAnalysis()
753 {
754 
755  // Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_STARTED, stepSweepVector_, currentStep));
756 
757 #if UQ==1
758  //Teuchos::GlobalMPISession mpiSession(&argc, &argv);
759  Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
760 #endif
761 
762  std::string msg;
763  bool status = true;
764  int errorFlag = 0;
765 
766  try
767  {
768 
769  int nu = analysisManager_.getDataStore()->nextSolutionPtr->globalLength(); // number of solution variables
770  int nc = stepLoopSize_; // number of constraint equations
771  int nz = numParams_; // number of optimization parameters
772 
773  status = doAllocations(nc,nz); // allocate solution and sensitivity arrays
774 
775  std::string filename = "input.xml";
776  Teuchos::RCP<Teuchos::ParameterList> parlist = Teuchos::rcp( new Teuchos::ParameterList() );
777  Teuchos::updateParametersFromXmlFile( filename, Teuchos::Ptr<Teuchos::ParameterList>(&*parlist) );
778 
779  std::string outputname = parlist->get("Output File","rol_output.txt");
780  std::ofstream out(outputname.c_str());
781  Teuchos::RCP<std::ostream> outStream = Teuchos::rcp(&out,false);
782 
783  out << "nu = " << nu << " nc = " << nc << " nz = " << nz << std::endl;
784  out << "Entering ROL loop" << std::endl;
785 
786  bool do_checks = parlist->get("Do Checks",true);
787  bool use_scale = parlist->get("Use Scaling For Epsilon-Active Sets",true);
788  bool use_sqp = parlist->get("Use SQP", true);
789  bool use_lsearch = parlist->get("Use Line Search", true);
790  bool use_TR = parlist->get("Use Trust Region", true);
791  bool use_bundle = parlist->get("Use Bundle Method", true);
792  bool use_bcon = parlist->get("Use Bound Constraints", true);
793  RealT alpha = parlist->get("Penalty Parameter", 1.e-4);
794  // amplifier problem parameters
795  RealT ampl = parlist->get("Amplifier Gain", 4.0);
796  int ptype = parlist->get("Penalty Type", 1);
797 
798 #if UQ==1
799  int nSamp = parlist->get("Number of Samples (UQ)", 10);
800  int samplertype = parlist->get("Sampler Type", 1); // 1 - MC, 2 - QMC
801  RealT gamma = parlist->get("CVaR: gamma", 1.e-4);
802  RealT prob = parlist->get("CVaR: prob", 0.99);
803  RealT coeff = parlist->get("CVaR: coeff", 1.0);
804 #endif
805 
806  //************ Equality constraint ***************//
807  //Teuchos::RCP< ::ROL::EqualityConstraint_SimOpt<RealT> > con;
808  Teuchos::RCP< ::ROL::ParametrizedEqualityConstraint_SimOpt<RealT> > con;
809  con = Teuchos::rcp(new EqualityConstraint_ROL_DC<RealT>(nu,nc,nz,analysisManager_,analysisManager_.getNonlinearEquationLoader(),nonlinearManager_.getNonlinearSolver(),linearSystem_,*this));
810 
811  //************ Optimization-space vectors ***************//
812  Teuchos::RCP<std::vector<RealT> > z_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
813  Teuchos::RCP<std::vector<RealT> > z1_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
814  Teuchos::RCP<std::vector<RealT> > z2_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
815  Teuchos::RCP<std::vector<RealT> > z3_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
816  Teuchos::RCP<std::vector<RealT> > yz_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
817  Teuchos::RCP<std::vector<RealT> > ajvz_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
818  ::ROL::StdVector<RealT> z(z_rcp);
819  ::ROL::StdVector<RealT> z1(z1_rcp);
820  ::ROL::StdVector<RealT> z2(z2_rcp);
821  ::ROL::StdVector<RealT> z3(z3_rcp);
822  ::ROL::StdVector<RealT> yz(yz_rcp);
823  ::ROL::StdVector<RealT> ajvz(ajvz_rcp);
824 
825  // Simulation and constraint space vectors
826 
827  // Using default constructor
828  // Linear::ROL_XyceVector<RealT> u(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
829  // Linear::ROL_XyceVector<RealT> yu(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
830  // Linear::ROL_XyceVector<RealT> c(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
831  // Linear::ROL_XyceVector<RealT> jv(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
832 
833  // Using copy constructor
838 
839  u.randomize();
840  yu.randomize();
841  c.randomize();
842  jv.randomize();
843 
844  // // Testing cloning
845  // Teuchos::RCP< ::ROL::Vector<RealT> > copy = u.clone();
846  // // assert (!is_null(copy));
847  // Linear::ROL_XyceVector<RealT> cop = dynamic_cast< Linear::ROL_XyceVector<RealT> &>(*copy);
848  // cop.randomize();
849  // cop.print(*outStream);
850 
851  // *outStream << "Checking linear algebra" << std::endl;
852  // std::vector<RealT> consistency = jv.checkVector(u,c,true,*outStream);
853 
854  // Get Initial Guess and bounds from file
855  std::ifstream param_file;
856  param_file.open("parameters.txt");
857  RealT temp;
858  std::string parName, dummy;
859  std::vector<RealT> up_bounds(nz,0.0);
860  std::vector<RealT> lo_bounds(nz,0.0);
861  getline(param_file,dummy); // skip the first line
862  for(int i=0;i<nz;i++)
863  {
864  param_file >> parName;
865  param_file >> parName;
866  param_file >> temp; // init guess
867  (*z_rcp)[i] = temp;
868  (*yz_rcp)[i] = temp;
869  param_file >> temp; // lo bound
870  lo_bounds[i] = temp;
871  param_file >> temp; // up bound
872  up_bounds[i] = temp;
873  }
874  param_file.close();
875 
876 #if UQ==1
877  // Get uncertain parameters and their bounds
878  param_file.open("uncertain_parameters.txt");
879  std::vector<std::vector<RealT> > ubounds;
880  std::vector<RealT> tempv(2,0);
881  std::string deviceName,paramName;
882  getline(param_file,dummy);
883  while(true)
884  {
885  if(!(param_file >> deviceName))
886  break;
887  if(deviceName[0]=='*')
888  {
889  getline(param_file,dummy);
890  continue;
891  }
892  if(!(param_file >> paramName))
893  break;
894  paramName = deviceName+":"+paramName;
895  std::cout << "Uncertain parameter " << paramName << std::endl;
896  uncertainParams_.push_back(paramName);
897  if(!(param_file >> temp)) break;
898  tempv[0] = temp;
899  if(!(param_file >> temp)) break;
900  tempv[1] = temp;
901  ubounds.push_back(tempv);
902  }
903  param_file.close();
904 #endif
905 
906  RealT tol = 1.e-12;
907 
908  Teuchos::RCP< ::ROL::Vector<RealT> > up = Teuchos::rcp(&u,false);
909  Teuchos::RCP< ::ROL::Vector<RealT> > yup = Teuchos::rcp(&yu,false);
910  Teuchos::RCP< ::ROL::Vector<RealT> > cp = Teuchos::rcp(&c,false);
911  Teuchos::RCP< ::ROL::Vector<RealT> > jvp = Teuchos::rcp(&jv,false);
912 
913  Teuchos::RCP< ::ROL::Vector<RealT> > zp = Teuchos::rcp(&z,false);
914  Teuchos::RCP< ::ROL::Vector<RealT> > z3p = Teuchos::rcp(&z3,false);
915  Teuchos::RCP< ::ROL::Vector<RealT> > yzp = Teuchos::rcp(&yz,false);
916  Teuchos::RCP< ::ROL::Vector<RealT> > ajvzp = Teuchos::rcp(&ajvz,false);
917 
918  // SimOpt vectors
919  ::ROL::Vector_SimOpt<RealT> x(up,zp);
920  ::ROL::Vector_SimOpt<RealT> y(yup,yzp);
921  ::ROL::Vector_SimOpt<RealT> ajv(jvp,ajvzp);
922 
923 #if UQ==1
924  /**********************************************************************************************/
925  /************************* CONSTRUCT SOL COMPONENTS *******************************************/
926  /**********************************************************************************************/
927  // Build samplers
928  Teuchos::RCP< ::ROL::BatchManager<double> > bman = Teuchos::rcp(new ::ROL::StdTeuchosBatchManager<double,int>(comm));
929  Teuchos::RCP< ::ROL::SampleGenerator<double> > sampler;
930  std::ifstream dirNums("new-joe-kuo-6.21201");
931  if(samplertype==1)
932  sampler = Teuchos::rcp(new ::ROL::MonteCarloGenerator<double>(50*nSamp,ubounds,bman,false,false,100));
933  else if(samplertype==2)
934  {
935  if(!dirNums)
936  out << "DirNums file not found!" << std::endl;
937  int skip = 0;
938  sampler = Teuchos::rcp(new ::ROL::QuasiMonteCarloGenerator<double>(nSamp,ubounds,bman,dirNums,skip,false,false,100));
939  }
940  con->setParameter(sampler->getMyPoint(0));
941 #endif
942 
943  con->solve(u,z,tol);
944 #if UQ==1
945  std::ofstream allsamples("all_samples.txt");
946  std::ofstream samples("good_samples.txt");
947  int nGSamp = 0; // number of "good" samples
948  out << "Generating good samples..." << std::endl;
949  for (int k=0;k<50*nSamp;k++)
950  {
951  con->setParameter(sampler->getMyPoint(k));
952 #endif
953  //======================= Separate testing of Jacobian_1 and 2 ==============================//
954 
955  out << "Checking Jacobian_1" << std::endl;
956  int numSteps = 13;
957  std::vector<RealT> steps(numSteps);
958  for(int i=0;i<numSteps;++i)
959  {
960  steps[i] = pow(10,-i);
961  }
962 
963  using ::ROL::Finite_Difference_Arrays::shifts;
964  using ::ROL::Finite_Difference_Arrays::weights;
965 
966  int numVals = 4;
967  std::vector<RealT> tmp(numVals);
968  std::vector<std::vector<RealT> > jvCheck(numSteps, tmp);
969 
970  // Compute constraint value at x.
971  Teuchos::RCP< ::ROL::Vector<RealT> > cc = c.clone();
972  con->value(*cc,*(x.get_1()),*(x.get_2()),tol);
973 
974  // Compute (Jacobian at x) times (vector v).
975  Teuchos::RCP< ::ROL::Vector<RealT> > Jv = jv.clone();
976  RealT normJv;
977  con->applyJacobian_1(*Jv, *(y.get_1()), *(x.get_1()), *(x.get_2()), tol);
978  normJv = Jv->norm();
979 
980  // Temporary vectors.
981  Teuchos::RCP< ::ROL::Vector<RealT> > cdif = c.clone();
982  Teuchos::RCP< ::ROL::Vector<RealT> > cnew = c.clone();
983  Teuchos::RCP< ::ROL::Vector<RealT> > xnew = x.clone();
984 
985  // FD order
986  int order = 1;
987  RealT minGradError = 1.e+10; // for "good" samples
988 
989  for (int i=0; i<numSteps; i++)
990  {
991 
992  RealT eta = steps[i];
993 
994  xnew->set(x);
995 
996  cdif->set(*cc);
997  cdif->scale(weights[order-1][0]);
998 
999  for(int j=0; j<order; ++j)
1000  {
1001 
1002  xnew->axpy(eta*shifts[order-1][j], y);
1003 
1004  if( weights[order-1][j+1] != 0 )
1005  {
1006  //this->update(*xnew);
1007  ::ROL::Vector_SimOpt<RealT> &xnews = Teuchos::dyn_cast< ::ROL::Vector_SimOpt<RealT> >(*xnew);
1008  con->value(*cnew,*(xnews.get_1()),z,tol);
1009  cdif->axpy(weights[order-1][j+1],*cnew);
1010  }
1011 
1012  }
1013 
1014  cdif->scale(1.0/eta);
1015 
1016  // Compute norms of Jacobian-vector products, finite-difference approximations, and error.
1017  jvCheck[i][0] = eta;
1018  jvCheck[i][1] = normJv;
1019  jvCheck[i][2] = cdif->norm();
1020  cdif->axpy(-1.0, *Jv);
1021  jvCheck[i][3] = cdif->norm();
1022 
1023  //if (printToStream)
1024  //{
1025  std::stringstream hist;
1026  if (i==0)
1027  {
1028  hist << std::right
1029  << std::setw(20) << "Step size"
1030  << std::setw(20) << "norm(Jac*vec)"
1031  << std::setw(20) << "norm(FD approx)"
1032  << std::setw(20) << "norm(abs error)"
1033  << "\n"
1034  << std::setw(20) << "---------"
1035  << std::setw(20) << "-------------"
1036  << std::setw(20) << "---------------"
1037  << std::setw(20) << "---------------"
1038  << "\n";
1039  }
1040  hist << std::scientific << std::setprecision(11) << std::right
1041  << std::setw(20) << jvCheck[i][0]
1042  << std::setw(20) << jvCheck[i][1]
1043  << std::setw(20) << jvCheck[i][2]
1044  << std::setw(20) << jvCheck[i][3]
1045  << "\n";
1046  out << hist.str();
1047 
1048  minGradError = std::min(jvCheck[i][3],minGradError);
1049  }
1050  out << "\n" << std::endl;
1051 
1052 #if UQ==1
1053  std::cout << "minGradError = " << minGradError << std::endl;
1054  for(int j=0;j<ubounds.size();j++)
1055  allsamples << std::scientific << std::setprecision(8) << (sampler->getMyPoint(k))[j] << ' ';
1056  allsamples << '\n';
1057  if( minGradError < 2.e-6 )
1058  {
1059  for(int j=0;j<ubounds.size();j++)
1060  samples << std::scientific << std::setprecision(8) << (sampler->getMyPoint(k))[j] << ' ';
1061  samples << '\n';
1062  nGSamp++;
1063  }
1064 #endif
1065 
1066  out << "Checking Jacobian_2" << std::endl;
1067 
1068  // Compute constraint value at x.
1069  con->value(*cc,*(x.get_1()),*(x.get_2()),tol);
1070 
1071  // Compute (Jacobian at x) times (vector v).
1072  con->applyJacobian_2(*Jv, *(y.get_2()), *(x.get_1()), *(x.get_2()), tol);
1073  normJv = Jv->norm();
1074 
1075  for (int i=0; i<numSteps; i++)
1076  {
1077 
1078  RealT eta = steps[i];
1079 
1080  xnew->set(x);
1081 
1082  cdif->set(*cc);
1083  cdif->scale(weights[order-1][0]);
1084 
1085  for(int j=0; j<order; ++j)
1086  {
1087 
1088  xnew->axpy(eta*shifts[order-1][j], y);
1089 
1090  if( weights[order-1][j+1] != 0 )
1091  {
1092  //this->update(*xnew);
1093  ::ROL::Vector_SimOpt<RealT> &xnews = Teuchos::dyn_cast< ::ROL::Vector_SimOpt<RealT> >(*xnew);
1094  con->value(*cnew,u,*(xnews.get_2()),tol);
1095  cdif->axpy(weights[order-1][j+1],*cnew);
1096  }
1097 
1098  }
1099 
1100  cdif->scale(1.0/eta);
1101 
1102  // Compute norms of Jacobian-vector products, finite-difference approximations, and error.
1103  jvCheck[i][0] = eta;
1104  jvCheck[i][1] = normJv;
1105  jvCheck[i][2] = cdif->norm();
1106  cdif->axpy(-1.0, *Jv);
1107  jvCheck[i][3] = cdif->norm();
1108 
1109  //if (printToStream)
1110  //{
1111  std::stringstream hist;
1112  if (i==0)
1113  {
1114  hist << std::right
1115  << std::setw(20) << "Step size"
1116  << std::setw(20) << "norm(Jac*vec)"
1117  << std::setw(20) << "norm(FD approx)"
1118  << std::setw(20) << "norm(abs error)"
1119  << "\n"
1120  << std::setw(20) << "---------"
1121  << std::setw(20) << "-------------"
1122  << std::setw(20) << "---------------"
1123  << std::setw(20) << "---------------"
1124  << "\n";
1125  }
1126  hist << std::scientific << std::setprecision(11) << std::right
1127  << std::setw(20) << jvCheck[i][0]
1128  << std::setw(20) << jvCheck[i][1]
1129  << std::setw(20) << jvCheck[i][2]
1130  << std::setw(20) << jvCheck[i][3]
1131  << "\n";
1132  out << hist.str();
1133  }
1134  out << "\n" << std::endl;
1135 
1136 
1137  //===================== end of checking Jacobian ========================//
1138 #if UQ==1
1139  }// end (loop over random params)
1140  out << "Generated " << nGSamp << " good samples." << std::endl;
1141  samples.close();
1142  allsamples.close();
1143 #endif
1144 
1145  if(do_checks)
1146  {
1147  out << "Checking full Jacobian" << std::endl;
1148  con->checkApplyJacobian(x,y,jv,true,*outStream);
1149 
1150  // // TT: the following requires implementing basis for ROL_XyceVector
1151  // std::cout << "Checking full adjoint Jacobian" << std::endl;
1152  // con->applyAdjointJacobian_1(const_cast< ::ROL::Vector<RealT> &>(*(ajv.get_1())),yu,u,z,tol);
1153  // std::cout << "norm ajvu = " << ajv.get_1()->norm() << std::endl;
1154  // con->applyAdjointJacobian_2(const_cast< ::ROL::Vector<RealT> &>(*(ajv.get_2())),yu,u,z,tol);
1155  // std::cout << "norm ajvz = " << ajv.get_2()->norm() << std::endl;
1156  // std::cout << "norm ajv = " << std::sqrt(ajv.get_1()->norm()*ajv.get_1()->norm() + ajv.get_2()->norm()*ajv.get_2()->norm()) << std::endl;
1157  // con->checkApplyAdjointJacobian(x,yu,c,ajv);
1158 
1159  out << "Checking Jacobian consistency" << std::endl;
1160  con->checkAdjointConsistencyJacobian_1(jv,yu,u,z,true,*outStream);
1161  con->checkAdjointConsistencyJacobian_2(jv,yz,u,z,true,*outStream);
1162 
1163  out << "Checking consistency of solves" << std::endl;
1164  con->checkSolve(u,z,c,true,*outStream);
1165  con->checkInverseJacobian_1(jv,yu,u,z,true,*outStream);
1166  con->checkInverseAdjointJacobian_1(yu,jv,u,z,true,*outStream);
1167 
1168  } // end(do_checks)
1169 
1170  //*********************** Initialize objective and penalty functions ***************************//
1171  Teuchos::RCP< ::ROL::ParametrizedObjective_SimOpt<RealT> > obj;
1172  Teuchos::RCP< ::ROL::ParametrizedObjective_SimOpt<RealT> > pen;
1173 
1174 #if OBJTYPE==0
1175  // L2-norm objective
1176  obj = Teuchos::rcp(new Objective_DC_L2Norm<RealT>(1.e-4,nc,nz));
1177 #elif OBJTYPE==1
1178  // AMPlifier circuit objective
1179  std::cout << "Amplifier circuit problem" << std::endl;
1180  obj = Teuchos::rcp(new Objective_DC_AMP<RealT>(nc,nz));
1181  pen = Teuchos::rcp(new Penalty_DC_AMP<RealT>(ptype,alpha,ampl,nc,nz));
1182 #endif
1183  std::vector< Teuchos::RCP< ::ROL::Objective<RealT> > > objVec;
1184  std::vector<bool> types(1,true);
1185 
1186  con->checkSolve(u,z,c,true,*outStream);
1187  if(do_checks)
1188  {
1189  out << "Checking objective" << std::endl;
1190  obj->checkGradient(x,x,y,true,*outStream);
1191  obj->checkHessVec(x,x,y,true,*outStream);
1192 #if OBJTYPE==1
1193  out << "Checking penalty" << std::endl;
1194  pen->checkGradient(x,x,y,true,*outStream);
1195  pen->checkHessVec(x,x,y,true,*outStream);
1196 #endif
1197  }
1198 
1199  //********************* Initialize reduced objective and penalty functions **********************//
1200  Teuchos::RCP< ::ROL::ParametrizedObjective<RealT> > robj = Teuchos::rcp(new ::ROL::Reduced_ParametrizedObjective_SimOpt<RealT>(obj,con,up,cp));
1201 #if OBJTYPE==1
1202  Teuchos::RCP< ::ROL::ParametrizedObjective<RealT> > rpen = Teuchos::rcp(new ::ROL::Reduced_ParametrizedObjective_SimOpt<RealT>(pen,con,up,cp));
1203 #endif
1204 
1205  if(do_checks)
1206  {
1207  *outStream << "Derivatives of reduced objective" << std::endl;
1208  robj->checkGradient(z,z,yz,true,*outStream);
1209  robj->checkHessVec(z,z,yz,true,*outStream);
1210 #if OBJTYPE==1
1211  *outStream << "Derivatives of reduced penalty" << std::endl;
1212  rpen->checkGradient(z,z,yz,true,*outStream);
1213  rpen->checkHessVec(z,z,yz,true,*outStream);
1214 #endif
1215  }
1216 
1217  //****************************** Bound constraints ****************************************//
1218  Teuchos::RCP<std::vector< RealT > > g0_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
1219  ::ROL::StdVector<RealT> g0p(g0_rcp);
1220  robj->gradient(g0p,z,tol);
1221  *outStream << std::scientific << "Norm of initial gradient = " << g0p.norm() << "\n";
1222  // Define scaling for epsilon-active sets (used in inequality constraints)
1223  RealT scale;
1224  if(use_scale)
1225  scale = 1.0e-2/g0p.norm();
1226  else
1227  scale = 1.0;
1228  *outStream << std::scientific << "Scaling: " << scale << "\n";
1229  Teuchos::RCP<::ROL::BoundConstraint<RealT> > bcon = Teuchos::rcp(new BoundConstraint_ROL_DC<RealT>(scale,lo_bounds,up_bounds));
1230  if(!use_bcon)
1231  bcon->deactivate();
1232 
1233  /**********************************************************************************************/
1234  //***************************** Optimization ************************************************//
1235  /**********************************************************************************************/
1236  *outStream << "\n Initial guess " << std::endl;
1237  for (int i=0;i<nz;i++)
1238  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1239  RealT gtol = parlist->get("Gradient Tolerance",1.e-14); // norm of gradient tolerance
1240  RealT stol = parlist->get("Step Tolerance",1.e-16); // norm of step tolerance
1241  int maxit = parlist->get("Maximum Number of Iterations",100);// maximum number of iterations
1242 
1243  con->solve(u,z,tol); // start feasible
1244 
1245 #if UQ==1
1246  //*************** Initial objective values and initial states (UQ) ***************//
1247  std::ofstream sampleWeights("weights.txt");
1248  for(int i=0;i<nSamp;i++)
1249  {
1250  sampleWeights << 1./(RealT)nSamp << '\n';
1251  }
1252  sampleWeights.close();
1253  std::string input_samples = "good_samples.txt";
1254  std::string input_weights = "weights.txt";
1255  // This sampler used to solve problem (with nSamp samples)
1256  Teuchos::RCP< ::ROL::SampleGenerator<double> > samplerSolve = Teuchos::rcp(new ::ROL::UserInputGenerator<RealT>(input_samples,input_weights,nSamp,ubounds.size(),bman));
1257  std::vector<RealT> sampleMean(ubounds.size(),0);
1258  // This sampler used to test solution (with nGSamp samples)
1259  Teuchos::RCP< ::ROL::SampleGenerator<double> > samplerTest = Teuchos::rcp(new ::ROL::UserInputGenerator<RealT>(input_samples,input_weights,nGSamp,ubounds.size(),bman));
1260  std::ofstream data_IG_UQ("data_IG_UQ.txt");
1261  std::ofstream plot_IG_UQ("plot_IG_UQ.txt");
1262  RealT sumlin = 0, sumlin2 = 0, sumgain = 0, sumgain2 = 0, gain, oval, param;
1263  Teuchos::RCP<std::vector<Teuchos::RCP<Linear::Vector> > > uup = Teuchos::rcp_const_cast<std::vector<Teuchos::RCP<Linear::Vector> > >((Teuchos::dyn_cast<Linear::ROL_XyceVector<RealT> >(u)).getVector());
1264  for(int i=0;i<nSamp;i++)
1265  {
1266  con->setParameter(samplerSolve->getMyPoint(i));
1267  con->solve(u,z,tol);
1268  oval = obj.value(u,z,tol);
1269  for(int j=0;j<nc;j++)
1270  {
1271  plot_IG_UQ << std::scientific << std::setprecision(8) << (*(*uup)[j])[3] << ' ';
1272  }
1273  plot_IG_UQ << '\n';
1274  gain = ((*(*uup)[nc-1])[3]-(*(*uup)[0])[3])/2.0;
1275  sumgain += gain;
1276  sumgain2 += gain*gain;
1277  for(int j=0;j<uncertainParams_.size();j++)
1278  {
1279  param = (samplerSolve->getMyPoint(i))[j];
1280  data_IG_UQ << std::scientific << std::setprecision(8) << param << ' ';
1281  sampleMean[j] += param/nSamp;
1282  }
1283  data_IG_UQ << oval << ' ' << gain << '\n';
1284  sumlin += oval;
1285  sumlin2 += oval*oval;
1286  }
1287  plot_IG_UQ.close();
1288  RealT meanlin = sumlin/nSamp;
1289  RealT meangain = sumgain/nSamp;
1290  RealT varlin = (sumlin2 - nSamp*meanlin*meanlin)/(RealT)(nSamp-1);
1291  RealT vargain = (sumgain2 - nSamp*meangain*meangain)/(RealT)(nSamp-1);
1292  data_IG_UQ << '\n' << "------------------------------------------" << '\n';
1293  data_IG_UQ << "mean(lin) = " << meanlin << " " << '\n';
1294  data_IG_UQ << "sqrt(sample variance)(lin) = " << std::sqrt(varlin) << '\n';
1295  data_IG_UQ << "mean(gain) = " << meangain << " " << '\n';
1296  data_IG_UQ << "sqrt(sample variance)(gain) = " << std::sqrt(vargain) << '\n';
1297  data_IG_UQ.close();
1298 
1299  /**********************************************************************************************/
1300  //************************* Build risk-averse objective function *****************************//
1301  /**********************************************************************************************/
1302  Teuchos::RCP< ::ROL::Distribution<double> > dist;
1303  Teuchos::RCP< ::ROL::PlusFunction<double> > pf;
1304  Teuchos::RCP< ::ROL::RiskMeasure<RealT> > rmobj;
1305  bool storage = true;
1306  Teuchos::RCP< ::ROL::RiskNeutralObjective<RealT> > neutobj;
1307  Teuchos::RCP< ::ROL::RiskAverseObjective<RealT> > riskobj;
1308  Teuchos::RCP< ::ROL::RiskNeutralObjective<RealT> > neutpen;
1309  Teuchos::RCP< ::ROL::RiskAverseObjective<RealT> > riskpen;
1310  Teuchos::RCP< ::ROL::BoundConstraint<RealT> >bconcvar = Teuchos::rcp(new ::ROL::CVaRBoundConstraint<RealT>(bcon));
1311  if(!use_bcon)
1312  bconcvar->deactivate();
1313 
1314  //****************************** Trust Region ********************************************//
1315  if (use_TR)
1316  {
1317  Teuchos::RCP< ::ROL::StatusTest<double> > status_tr;
1318  Teuchos::RCP< ::ROL::Step<double> > step_tr;
1319  Teuchos::RCP< ::ROL::Algorithm<double> > algo_tr;
1320  std::clock_t timer_tr = std::clock();
1321 
1322  *outStream << "\nSOLVE DETERMINISTIC MEAN-VALUE PROBLEM\n";
1323  z1.set(z);
1324  con->setParameter(sampleMean);
1325  objVec.clear();
1326  objVec.push_back(robj);
1327 #if OBJTYPE==1
1328  objVec.push_back(rpen);
1329  types.push_back(1);
1330 #endif
1331  SumObjective<RealT> fullobjDET(objVec,types);
1332  con->checkSolve(u,z,c,true,*outStream);
1333  if(do_checks)
1334  {
1335  *outStream << "Derivatives of reduced objective" << std::endl;
1336  robj->checkGradient(z1,z1,yz,true,*outStream);
1337  robj->checkHessVec(z1,z1,yz,true,*outStream);
1338 #if OBJTYPE==1
1339  *outStream << "Derivatives of reduced penalty" << std::endl;
1340  rpen->checkGradient(z1,z1,yz,true,*outStream);
1341  rpen->checkHessVec(z1,z1,yz,true,*outStream);
1342 #endif
1343  }
1344  status_tr = Teuchos::rcp(new ::ROL::StatusTest<RealT>(gtol, stol, maxit));
1345  step_tr = Teuchos::rcp(new ::ROL::TrustRegionStep<RealT>(*parlist));
1346  algo_tr = Teuchos::rcp(new ::ROL::Algorithm<RealT>(step_tr,status_tr,false));
1347  algo_tr->run(z1,fullobjDET,*bcon,true,*outStream);
1348  *outStream << "\n Solution " << std::endl;
1349  for (int i=0;i<nz;i++)
1350  {
1351  *outStream << paramNameVec_[i] << " = " << (*z1_rcp)[i] << std::endl;
1352  }
1353 
1354  *outStream << "\nSOLVE EXPECTED VALUE WITH TRUST REGION\n";
1355  out << "Using " << nSamp << " samples" << std::endl;
1356  z2.set(z1);
1357  *outStream << "\n Initial guess " << std::endl;
1358  for (int i=0;i<nz;i++)
1359  *outStream << paramNameVec_[i] << " = " << (*z2_rcp)[i] << std::endl;
1360  neutobj = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(robj,samplerSolve,storage));
1361  objVec.clear();
1362  objVec.push_back(neutobj);
1363  neutpen = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(rpen,samplerSolve,storage));
1364  objVec.push_back(neutpen);
1365  SumObjective<RealT> fullobjEXP(objVec,types);
1366  if(do_checks)
1367  {
1368  out << "Derivatives of risk neutral objective" << std::endl;
1369  neutobj->checkGradient(z2,z2,yz,true,*outStream);
1370  neutobj->checkHessVec(z2,z2,yz,true,*outStream);
1371 #if OBJTYPE==1
1372  out << "Derivatives of risk neutral penalty" << std::endl;
1373  neutpen->checkGradient(z2,z2,yz,true,*outStream);
1374  neutpen->checkHessVec(z2,z2,yz,true,*outStream);
1375 #endif
1376  }
1377  status_tr = Teuchos::rcp(new ::ROL::StatusTest<RealT>(gtol, stol, maxit));
1378  step_tr = Teuchos::rcp(new ::ROL::TrustRegionStep<RealT>(*parlist));
1379  algo_tr = Teuchos::rcp(new ::ROL::Algorithm<RealT>(step_tr,status_tr,false));
1380  algo_tr->run(z2,fullobjEXP,*bcon,true,*outStream);
1381  *outStream << "\n Solution " << std::endl;
1382  for (int i=0;i<nz;i++)
1383  {
1384  *outStream << paramNameVec_[i] << " = " << (*z2_rcp)[i] << std::endl;
1385  }
1386 
1387  *outStream << "\nSOLVE SMOOTHED CONDITIONAL VALUE AT RISK WITH TRUST REGION\n";
1388  *outStream << "prob = " << prob << ", coeff = " << coeff << ", gamma = " << gamma << std::endl;
1389  out << "Using " << nSamp << " samples" << std::endl;
1390  z3.set(z2);
1391  *outStream << "\n Initial guess " << std::endl;
1392  for (int i=0;i<nz;i++)
1393  *outStream << paramNameVec_[i] << " = " << (*z3_rcp)[i] << std::endl;
1394  // Build CVaR objective function
1395  std::vector<RealT> data(2,0.0);
1396  data[0] = -0.5; data[1] = 0.5;
1397  dist = Teuchos::rcp( new ::ROL::Distribution<RealT>(::ROL::DISTRIBUTION_PARABOLIC,data) );
1398  pf = Teuchos::rcp( new ::ROL::PlusFunction<RealT>(dist,gamma) );
1399  rmobj = Teuchos::rcp( new ::ROL::CVaR<RealT>(prob,coeff,pf) );
1400 #if 1
1401  neutobj = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(robj,samplerSolve,storage));
1402  objVec.clear();
1403  objVec.push_back(neutobj);
1404  if(coeff > 0)
1405  types[0] = 0; // if riskpen
1406 #endif
1407 #if 0
1408  riskobj = Teuchos::rcp(new ::ROL::RiskAverseObjective<RealT>(robj,rmobj,samplerSolve,storage));
1409  objVec.clear();
1410  objVec.push_back(riskobj);
1411 #endif
1412 #if OBJTYPE==1
1413  if(coeff == 0)
1414  {
1415  neutpen = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(rpen,samplerSolve,storage));
1416  objVec.push_back(neutpen);
1417  //types.push_back(0); // if riskobj
1418  types.push_back(1); // if neutobj
1419  }
1420  else
1421  {
1422  riskpen = Teuchos::rcp(new ::ROL::RiskAverseObjective<RealT>(rpen,rmobj,samplerSolve,storage));
1423  objVec.push_back(riskpen);
1424  //types.push_back(1);
1425  types[1] = 1;
1426  }
1427 #endif
1428  SumObjective<RealT> fullobj(objVec,types);
1429  status_tr = Teuchos::rcp(new ::ROL::StatusTest<RealT>(gtol, stol, maxit));
1430  step_tr = Teuchos::rcp(new ::ROL::TrustRegionStep<RealT>(*parlist));
1431  algo_tr = Teuchos::rcp(new ::ROL::Algorithm<RealT>(step_tr,status_tr,false));
1432  // Build CVaR vectors
1433  RealT z3v = (RealT)rand()/(RealT)RAND_MAX;
1434  RealT yzv = (RealT)rand()/(RealT)RAND_MAX;
1435  ::ROL::CVaRVector<RealT> z3c(z3v,z3p);
1436  ::ROL::CVaRVector<RealT> yzc(yzv,yzp);
1437  if(do_checks)
1438  {
1439  out << "Derivatives of risk neutral objective" << std::endl;
1440  neutobj->checkGradient(z3,z3,yz,true,*outStream);
1441  neutobj->checkHessVec(z3,z3,yz,true,*outStream);
1442  // out << "Derivatives of risk averse objective" << std::endl;
1443  // riskobj->checkGradient(zc,zc,yzc,true,*outStream);
1444  // riskobj->checkHessVec(zc,zc,yzc,true,*outStream);
1445 #if OBJTYPE==1
1446  if(coeff == 0)
1447  {
1448  out << "Derivatives of risk neutral penalty" << std::endl;
1449  neutpen->checkGradient(z3,z3,yz,true,*outStream);
1450  neutpen->checkHessVec(z3,z3,yz,true,*outStream);
1451  }
1452  else
1453  {
1454  out << "Derivatives of risk averse penalty" << std::endl;
1455  riskpen->checkGradient(z3c,z3c,yzc,true,*outStream);
1456  riskpen->checkHessVec(z3c,z3c,yzc,true,*outStream);
1457  }
1458 #endif
1459  }
1460  // Run ROL algorithm
1461  if(coeff > 0)
1462  algo_tr->run(z3c,fullobj,*bconcvar,true,*outStream);
1463  else
1464  algo_tr->run(z3,fullobj,*bcon,true,*outStream);
1465  *outStream << "\n Solution " << std::endl;
1466  for (int i=0;i<nz;i++)
1467  {
1468  *outStream << paramNameVec_[i] << " = " << (*z3_rcp)[i] << std::endl;
1469  }
1470  *outStream << "var = " << z3v << std::endl;
1471  *outStream << "Trust-Region required " << (std::clock()-timer_tr)/(RealT)CLOCKS_PER_SEC
1472  << " seconds.\n";
1473  }
1474 
1475  //***************************** Bundle Method *********************************//
1476  if(use_bundle)
1477  {
1478  *outStream << "\nSOLVE NONSMOOTH CVAR PROBLEM WITH BUNDLE TRUST REGION\n";
1479  // Build CVaR objective function
1480  *outStream << "prob = " << prob << ", coeff = " << coeff << std::endl;
1481  dist = Teuchos::rcp( new ::ROL::Distribution<RealT>(::ROL::DISTRIBUTION_DIRAC) );
1482  pf = Teuchos::rcp( new ::ROL::PlusFunction<RealT>(dist,1.0) );
1483  rmobj = Teuchos::rcp( new ::ROL::CVaR<RealT>(prob,coeff,pf) );
1484  neutobj = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(robj,samplerSolve,storage));
1485  objVec.clear();
1486  objVec.push_back(neutobj);
1487  if(coeff > 0)
1488  types[0] = 0; // if riskpen
1489 #if OBJTYPE==1
1490  if(coeff == 0)
1491  {
1492  neutpen = Teuchos::rcp(new ::ROL::RiskNeutralObjective<RealT>(rpen,samplerSolve,storage));
1493  objVec.push_back(neutpen);
1494  //types.push_back(0); // if riskobj
1495  types.push_back(1); // if neutobj
1496  }
1497  else
1498  {
1499  riskpen = Teuchos::rcp(new ::ROL::RiskAverseObjective<RealT>(rpen,rmobj,samplerSolve,storage));
1500  objVec.push_back(riskpen);
1501  types.push_back(1);
1502  }
1503 #endif
1504  SumObjective<RealT> fullobj(objVec,types);
1505  // Build CVaR vectors
1506  RealT zv = (RealT)rand()/(RealT)RAND_MAX;
1507  ::ROL::CVaRVector<RealT> zc(zv,zp);
1508  // Run ROL algorithm
1509  parlist->set("Bundle Step: Epsilon Solution Tolerance",gtol);
1510  ::ROL::BundleStatusTest<RealT> status_bm(gtol, maxit);
1511  ::ROL::BundleStep<RealT> step_bm(*parlist);
1512  ::ROL::Algorithm<RealT> algo_bm(Teuchos::rcp(&step_bm,false),Teuchos::rcp(&status_bm,false),false);
1513  std::clock_t timer_bm = std::clock();
1514  if(coeff > 0)
1515  algo_bm.run(zc,fullobj,*bconcvar,true,*outStream);
1516  else
1517  algo_bm.run(z,fullobj,*bcon,true,*outStream);
1518  *outStream << "\n Solution " << std::endl;
1519  for (int i=0;i<nz;i++)
1520  {
1521  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1522  }
1523  *outStream << "var = " << zv << std::endl;
1524  *outStream << "Bundle Method required " << (std::clock()-timer_bm)/(RealT)CLOCKS_PER_SEC
1525  << " seconds.\n";
1526  }
1527 
1528  // Post-processing (UQ)
1529  //****************************** Final objective values and final states (UQ) *******************//
1530  std::vector<std::string> output_data_UQ;
1531  output_data_UQ.push_back("data_UQ_DET.txt");
1532  output_data_UQ.push_back("data_UQ_EV.txt");
1533  output_data_UQ.push_back("data_UQ_CVaR.txt");
1534  std::vector<std::string> output_plot_UQ;
1535  output_plot_UQ.push_back("plot_UQ_DET.txt");
1536  output_plot_UQ.push_back("plot_UQ_EV.txt");
1537  output_plot_UQ.push_back("plot_UQ_CVaR.txt");
1538  std::vector< ::ROL::StdVector<RealT> > solutions;
1539  solutions.push_back(z1);
1540  solutions.push_back(z2);
1541  solutions.push_back(z3);
1542  // Test with the rest of "good" samples
1543  int nTestSamp = nGSamp - nSamp;
1544  out << "Using " << nTestSamp << " to approximate densities" << std::endl;
1545  for(int k=0;k<solutions.size();k++)
1546  {
1547  std::ofstream data_UQ(output_data_UQ[k].c_str());
1548  std::ofstream plot_UQ(output_plot_UQ[k].c_str());
1549  sumlin = 0; sumlin2 = 0;
1550  sumgain = 0; sumgain2 = 0;
1551  for(int i=nSamp;i<nGSamp;i++)
1552  {
1553  con->setParameter(samplerTest->getMyPoint(i));
1554  con->solve(u,solutions[k],tol);
1555  oval = obj.value(u,solutions[k],tol);
1556  for(int j=0;j<nc;j++)
1557  plot_UQ << std::scientific << std::setprecision(8) << (*(*uup)[j])[3] << ' ';
1558  plot_UQ << '\n';
1559  gain = ((*(*uup)[nc-1])[3]-(*(*uup)[0])[3])/2.0;
1560  sumgain += gain;
1561  sumgain2 += gain*gain;
1562  for(int j=0;j<uncertainParams_.size();j++)
1563  {
1564  data_UQ << std::scientific << std::setprecision(8) << (samplerTest->getMyPoint(i))[j] << ' ';
1565  }
1566  data_UQ << oval << ' ' << gain << '\n';
1567  sumlin += oval;
1568  sumlin2 += oval*oval;
1569  }
1570  plot_UQ.close();
1571  meanlin = sumlin/nTestSamp;
1572  meangain = sumgain/nTestSamp;
1573  varlin = (sumlin2 - nTestSamp*meanlin*meanlin)/(RealT)(nTestSamp-1);
1574  vargain = (sumgain2 - nTestSamp*meangain*meangain)/(RealT)(nTestSamp-1);
1575  data_UQ << "\n ------------------------------------------ \n";
1576  data_UQ << "mean(lin) = " << meanlin << " " << '\n';
1577  data_UQ << "sqrt(sample variance)(lin) = " << std::sqrt(varlin) << '\n';
1578  data_UQ << "mean(gain) = " << meangain << '\n';
1579  data_UQ << "sqrt(sample variance)(gain) = " << std::sqrt(vargain) << '\n';
1580  data_UQ.close();
1581  }
1582 
1583  //********************************************************************************************//
1584 
1585 #else
1586  //**********************************************************************************************//
1587  //******************************** Deterministic problem **************************************//
1588  //********************************************************************************************//
1589  if(use_bundle)
1590  {
1591  parlist->set("Bundle Step: Epsilon Solution Tolerance",gtol);
1592  ::ROL::BundleStatusTest<RealT> status_bm(gtol, maxit);
1593  ::ROL::BundleStep<RealT> step_bm(*parlist);
1594  ::ROL::Algorithm<RealT> algo_bm(Teuchos::rcp(&step_bm,false),Teuchos::rcp(&status_bm,false),false);
1595  std::clock_t timer_bm = std::clock();
1596  objVec.clear();
1597  objVec.push_back(robj);
1598 #if OBJTYPE==1
1599  objVec.push_back(rpen);
1600  types.push_back(1);
1601 #endif
1602  SumObjective<RealT> fullobj(objVec,types);
1603  algo_bm.run(z,fullobj,*bcon,true,*outStream);
1604  *outStream << "\n Solution " << std::endl;
1605  for (int i=0;i<nz;i++)
1606  {
1607  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1608  }
1609  *outStream << "Bundle Method required " << (std::clock()-timer_bm)/(RealT)CLOCKS_PER_SEC
1610  << " seconds.\n";
1611  }
1612  if (use_TR)
1613  {
1614  // Trust Region
1615  ::ROL::StatusTest<RealT> status_tr(gtol, stol, maxit);
1616  ::ROL::TrustRegionStep<RealT> step_tr(*parlist);
1617  ::ROL::Algorithm<RealT> algo_tr(Teuchos::rcp(&step_tr,false),Teuchos::rcp(&status_tr,false),false);
1618  std::clock_t timer_tr = std::clock();
1619  objVec.clear();
1620  objVec.push_back(robj);
1621 #if OBJTYPE==1
1622  objVec.push_back(rpen);
1623  types.push_back(1);
1624 #endif
1625  SumObjective<RealT> fullobj(objVec,types);
1626  algo_tr.run(z,fullobj,*bcon,true,*outStream);
1627  *outStream << "\n Solution " << std::endl;
1628  for (int i=0;i<nz;i++)
1629  {
1630  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1631  }
1632  *outStream << "Trust-Region required " << (std::clock()-timer_tr)/(RealT)CLOCKS_PER_SEC
1633  << " seconds.\n";
1634  }
1635  if (use_lsearch)
1636  {
1637  // Line Search
1638  ::ROL::StatusTest<RealT> status_ls(gtol, stol, maxit);
1639  ::ROL::LineSearchStep<RealT> step_ls(*parlist);
1640  ::ROL::Algorithm<RealT> algo_ls(Teuchos::rcp(&step_ls,false),Teuchos::rcp(&status_ls,false),false);
1641  std::clock_t timer_ls = std::clock();
1642  objVec.clear();
1643  objVec.push_back(robj);
1644 #if OBJTYPE==1
1645  objVec.push_back(rpen);
1646  types.push_back(1);
1647 #endif
1648  SumObjective<RealT> fullobj(objVec,types);
1649  algo_ls.run(z,fullobj,*bcon,true,*outStream);
1650  *outStream << "\n Solution " << std::endl;
1651  for (int i=0;i<nz;i++)
1652  {
1653  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1654  }
1655  *outStream << "Line-Search required " << (std::clock()-timer_ls)/(RealT)CLOCKS_PER_SEC
1656  << " seconds.\n";
1657  }
1658  if (use_sqp)
1659  {
1660  // SQP.
1661  Teuchos::RCP<std::vector<RealT> > gz_rcp = Teuchos::rcp( new std::vector<RealT> (nz, 0.0) );
1662  ::ROL::StdVector<RealT> gz(gz_rcp);
1663  Teuchos::RCP< ::ROL::Vector<RealT> > gzp = Teuchos::rcp(&gz,false);
1664  Linear::ROL_XyceVector<RealT> gu(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
1665  Teuchos::RCP< ::ROL::Vector<RealT> > gup = Teuchos::rcp(&gu,false);
1666  ::ROL::Vector_SimOpt<RealT> g(gup,gzp);
1667  Linear::ROL_XyceVector<RealT> cc(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
1668  Linear::ROL_XyceVector<RealT> l(nc,*analysisManager_.getDataStore()->nextSolutionPtr);
1669  RealT ctol = 1.e-16;
1670  ::ROL::ConstraintStatusTest<RealT> status_sqp(gtol,ctol,stol,maxit);
1671  ::ROL::CompositeStep<RealT> step_sqp(*parlist);
1672  ::ROL::Algorithm<RealT> algo_sqp(Teuchos::rcp(&step_sqp,false),Teuchos::rcp(&status_sqp, false),false);
1673  std::clock_t timer_sqp = std::clock();
1674  objVec.clear();
1675  objVec.push_back(obj);
1676 #if OBJTYPE==1
1677  objVec.push_back(pen);
1678  types.push_back(1);
1679 #endif
1680  SumObjective<RealT> fullobj(objVec,types);
1681  algo_sqp.run(x,g,l,cc,fullobj,*con,true,*outStream);
1682  out << "\n Solution " << std::endl;
1683  for (int i=0;i<nz;i++)
1684  {
1685  *outStream << paramNameVec_[i] << " = " << (*z_rcp)[i] << std::endl;
1686  }
1687  out << "Composite-Step SQP required " << (std::clock()-timer_sqp)/(RealT)CLOCKS_PER_SEC
1688  << " seconds.\n";
1689  }
1690 #endif
1691 
1692  }
1693  catch (std::logic_error err)
1694  {
1695  //out << err.what() << "\n";
1696  errorFlag = -1000;
1697  }; // end try
1698 
1699  // if (errorFlag != 0)
1700  // out << "End Result: TEST FAILED\n";
1701  // else
1702  // out << "End Result: TEST PASSED\n";
1703 
1704  doFree(); // deallocate solution and sensitivity arrays
1705 
1706  return status;
1707 }
1708 #else
1709 //TT: do the same as doLoopProcess
1711 {
1712  bool integration_status = true;
1714 
1715  //Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::INITIALIZE, stepSweepVector_, stepLoopSize_)); // TT: moved here from doInit();
1716  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::INITIALIZE, AnalysisEvent::DC));
1717 
1718  // StepEvent step_event(StepEvent::STEP_STARTED, stepSweepVector_, currentStep);
1719 
1720  //for (int currentStep = 0; currentStep < stepLoopSize_; ++i)
1721  int currentStep = 0;
1722  int finalStep = stepLoopSize_;
1723  while (currentStep < finalStep) // TT: I suspect that this might be necessary
1724  {
1726 
1727  // Tell the manager if any of our sweeps are being reset in this loop iteration.
1728  bool reset = updateSweepParams(loader_, currentStep, stepSweepVector_.begin(), stepSweepVector_.end(), false);// TT: update sweep parameters; location N_ANP_SweepParam.C
1729 
1730  analysisManager_.setSweepSourceResetFlag(reset);// TT: sets sweep source flag to reset in AnalysisManager
1731 
1732  outputManagerAdapter_.setStepSweepVector(stepSweepVector_);// TT: not sure what this is for
1733 
1734  // if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
1735  for (SweepVector::const_iterator it = stepSweepVector_.begin(), end = stepSweepVector_.end(); it != end; ++it)
1736  Xyce::dout() << "ROL DC Sweep # " << currentStep <<"\t" << (*it);
1737 
1738  // TT
1739  if (currentStep != 0 && reset)
1740  {
1743  }
1744 
1745 
1746  // TT: the following line causes currSol and nextSol reset to zero
1747  // Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_STARTED, stepSweepVector_, currentStep));
1748 
1749  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_STARTED, AnalysisEvent::DC, 0.0, currentStep));
1750  //step_event.state = StepEvent::STEP_STARTED;
1751  //Util::publish<StepEvent>(analysisManager_, step_event);
1752 
1753  takeStep_(); // TT: take integration step
1754 
1755  // Set things up for the next time step, based on if this one was
1756  // successful.
1758  {
1759  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_SUCCESSFUL, AnalysisEvent::DC, 0.0, currentStep));
1761  // collect solutions here
1762  *(solutionPtrVector_[currentStep]) = *(ds.currSolutionPtr);
1763 
1764  }
1765  else // stepAttemptStatus (ie do this if the step FAILED)
1766  {
1767  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_FAILED, AnalysisEvent::DC, 0.0, currentStep));
1769  }
1770 
1771  currentStep = stepNumber;
1772  } // end of sweep loop
1773 
1774  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::FINISH, AnalysisEvent::DC));
1775 
1776  // Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_COMPLETED, stepSweepVector_, currentStep));
1777 
1778  // step_event.state_ = StepEvent::STEP_COMPLETED;
1779  // step_event.finalSimTime_ = getTIAParams().finalTime;
1780  // Util::publish<StepEvent>(analysisManager_, step_event);
1781 
1782  return integration_status;
1783 }
1784 
1785 #endif
1786 
1787 
1788 namespace {
1789 
1790 //-----------------------------------------------------------------------------
1791 // Class : ROLFactory
1792 // Purpose :
1793 // Special Notes :
1794 // Scope : public
1795 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1796 // Creation Date : Thu Jan 29 12:53:02 2015
1797 //-----------------------------------------------------------------------------
1798 ///
1799 /// Factory for parsing ROL parameters from the netlist and creating ROL analysis.
1800 ///
1801 class ROLFactory : public Util::Factory<AnalysisBase, ROL>
1802 {
1803 public:
1804  //-----------------------------------------------------------------------------
1805  // Function : ROLFactory
1806  // Purpose :
1807  // Special Notes :
1808  // Scope : public
1809  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1810  // Creation Date : Thu Jan 29 12:54:09 2015
1811  //-----------------------------------------------------------------------------
1812  ///
1813  /// Constructs the ROL analysis factory
1814  ///
1815  /// @invariant Stores the results of parsing. Multiple ROL analysis options may be
1816  /// applied and each generates and additional step.
1817  ///
1818  /// @invariant The existence of the parameters specified in the constructor cannot
1819  /// change.
1820  ///
1821  /// @param analysis_manager
1822  /// @param linear_system
1823  /// @param nonlinear_manager
1824  ///
1825  ROLFactory(
1826  Analysis::AnalysisManager & analysis_manager,
1827  Linear::System & linear_system,
1828  Nonlinear::Manager & nonlinear_manager,
1829  Loader::Loader & loader,
1830  Topo::Topology & topology,
1831  IO::InitialConditionsManager & initial_conditions_manager)
1832  : Util::Factory<AnalysisBase, ROL>(),
1833  analysisManager_(analysis_manager),
1834  linearSystem_(linear_system),
1835  nonlinearManager_(nonlinear_manager),
1836  loader_(loader),
1837  topology_(topology),
1838  initialConditionsManager_(initial_conditions_manager),
1841  {}
1842 
1843  virtual ~ROLFactory()
1844  {}
1845 
1846  //-----------------------------------------------------------------------------
1847  // Function : create
1848  // Purpose :
1849  // Special Notes :
1850  // Scope : public
1851  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1852  // Creation Date : Thu Jan 29 12:59:00 2015
1853  //-----------------------------------------------------------------------------
1854  ///
1855  /// Create a new ROL analysis and applies the analysis and time integrator option blocks.
1856  ///
1857  /// @return new ROL analysis object
1858  ///
1859  ROL *create() const
1860  {
1861  // analysisManager_.setAnalysisMode(ANP_MODE_ROL); // TT:
1864  for (std::vector<Util::OptionBlock>::const_iterator it = stepSweepAnalysisOptionBlock_.begin(), end = stepSweepAnalysisOptionBlock_.end(); it != end; ++it)
1865  step->setAnalysisParams(*it);
1866  step->setTimeIntegratorOptions(timeIntegratorOptionBlock_);// TT
1867 
1868  return step;
1869  }
1870 
1871  //-----------------------------------------------------------------------------
1872  // Function : setROLAnalysisOptionBlock
1873  // Purpose :
1874  // Special Notes :
1875  // Scope : public
1876  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1877  // Creation Date : Thu Jan 29 13:00:14 2015
1878  //-----------------------------------------------------------------------------
1879  ///
1880  /// Saves the analysis parsed options block in the factory.
1881  ///
1882  /// @invariant Appends to any previously specified analysis option block.
1883  ///
1884  /// @param option_block parsed option block
1885  ///
1886  void setROLAnalysisOptionBlock(const Util::OptionBlock &option_block)
1887  {
1888  for (std::vector<Util::OptionBlock>::iterator it = stepSweepAnalysisOptionBlock_.begin(), end = stepSweepAnalysisOptionBlock_.end(); it != end; ++it)
1889  {
1890  if (Util::compareParamLists(option_block, *it))
1891  {
1892  (*it) = option_block;
1893  return;
1894  }
1895  }
1896 
1897  // save the new one.
1898  stepSweepAnalysisOptionBlock_.push_back(option_block); // save a copy for later.
1899 
1900  //TT
1901  std::string param_name;
1902  for (std::vector<Util::OptionBlock>::iterator it = stepSweepAnalysisOptionBlock_.begin(), end = stepSweepAnalysisOptionBlock_.end(); it != end; ++it)
1903  {
1904  param_name = (*it).getName();
1905  std::cout << "parameter = " << param_name << std::endl;
1906  }
1907  }
1908 
1909 
1910  // TT: blindly copied from DCSweep
1911  //-----------------------------------------------------------------------------
1912  // Function : setTimeIntegratorOptionBlock
1913  // Purpose :
1914  // Special Notes :
1915  // Scope : public
1916  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1917  // Creation Date : Thu Jan 29 13:01:27 2015
1918  //-----------------------------------------------------------------------------
1919  ///
1920  /// Saves the time integrator parsed option block.
1921  ///
1922  /// @invariant Overwrites any previously specified time integrator option block.
1923  ///
1924  /// @param option_block parsed option block
1925  ///
1926  bool setTimeIntegratorOptionBlock(const Util::OptionBlock &option_block)
1927  {
1928  timeIntegratorOptionBlock_ = option_block;
1929 
1930  return true;
1931  }
1932 
1933 public:
1934  AnalysisManager & analysisManager_;
1935  Linear::System & linearSystem_;
1936  Nonlinear::Manager & nonlinearManager_;
1937  Loader::Loader & loader_;
1938  Topo::Topology & topology_;
1939  IO::InitialConditionsManager & initialConditionsManager_;
1940 
1941 private:
1942  std::vector<Util::OptionBlock> stepSweepAnalysisOptionBlock_;
1943  Util::OptionBlock timeIntegratorOptionBlock_; // TT
1944 };
1945 
1946 // .ROL
1947 struct ROLAnalysisReg : public IO::PkgOptionsReg
1948 {
1949  ROLAnalysisReg(
1950  ROLFactory & factory)
1951  : factory_(factory)
1952  {}
1953 
1954  bool operator()(const Util::OptionBlock &option_block)
1955  {
1956  factory_.setROLAnalysisOptionBlock(option_block);
1957 
1958  factory_.analysisManager_.addAnalysis(&factory_);
1959 
1960  return true;
1961  }
1962 
1963  ROLFactory & factory_;
1964 };
1965 
1966 //-----------------------------------------------------------------------------
1967 // Function : extractROLData
1968 // Purpose : Extract the parameters from a netlist .ROL line held in
1969 // parsedLine.
1970 // Special Notes :
1971 // Scope : public
1972 // Creator : Eric R. Keiter, SNL
1973 // Creation Date : 10/30/2003
1974 //-----------------------------------------------------------------------------
1975 // TT: this function is copied from STEP, the parameters need to be modified
1976 // TT: I will want here a way to extract optimization parameters
1977 bool
1978 extractROLData(
1979  IO::PkgOptionsMgr & options_manager,
1980  IO::CircuitBlock & circuit_block,
1981  const std::string & netlist_filename,
1982  const IO::TokenVector & parsed_line)
1983 {
1984  Util::OptionBlock option_block("ROL", Util::OptionBlock::ALLOW_EXPRESSIONS, netlist_filename, parsed_line[0].lineNumber_);
1985 
1986  int numFields = parsed_line.size();
1987 
1988  // First check if the type has been explicitly set.
1989  // If not, set it to the default, LIN.
1990  int pos1=1;
1991 
1992  bool typeExplicitSetLinDecOct = false;
1993  bool typeExplicitSetList = false;
1994  std::string type("LIN");
1995  while ( pos1 < numFields )
1996  {
1997  ExtendedString stringVal ( parsed_line[pos1].string_ );
1998  stringVal.toUpper ();
1999  if (stringVal == "LIN" ||
2000  stringVal == "DEC" ||
2001  stringVal == "OCT")
2002  {
2003  typeExplicitSetLinDecOct = true;
2004  type = stringVal;
2005  }
2006  else if (stringVal == "LIST")
2007  {
2008  typeExplicitSetList = true;
2009  type = stringVal;
2010  }
2011 
2012  ++pos1;
2013  }
2014 
2015  // Check that the minimum required number of fields are on the line.
2016  int offset = 1;
2017  if (typeExplicitSetLinDecOct)
2018  {
2019  offset = 2;
2020  }
2021 
2022  if (!typeExplicitSetList)// if this is a list, number of fields is arbitrary.
2023  {
2024  if ( (numFields-offset)%4 != 0 )
2025  {
2026  Report::UserError0().at(netlist_filename, parsed_line[0].lineNumber_)
2027  << ".ROL line not formatted correctly.";
2028  return false;
2029  }
2030  }
2031 
2032  int linePosition = 1; // Start of parameters on .param line.
2033  Util::Param parameter("", "");
2034 
2035  // Add the type (which was determined above) to the parameter list.
2036  parameter.setTag( "TYPE" );
2037  parameter.setVal( type );
2038  option_block.addParam( parameter );
2039 
2040  if (type=="LIN")
2041  {
2042  if (typeExplicitSetLinDecOct) linePosition=2;
2043  while ( linePosition < numFields )
2044  {
2045  parameter.setTag( "PARAM" );
2046  parameter.setVal(std::string(ExtendedString(parsed_line[linePosition].string_).toUpper()));
2047  option_block.addParam( parameter );
2048  ++linePosition; // Advance to next parameter.
2049 
2050  parameter.setTag( "START" );
2051  parameter.setVal( parsed_line[linePosition].string_ );
2052  option_block.addParam( parameter );
2053  ++linePosition; // Advance to next parameter.
2054 
2055  parameter.setTag( "STOP" );
2056  parameter.setVal( parsed_line[linePosition].string_ );
2057  option_block.addParam( parameter );
2058  ++linePosition; // Advance to next parameter.
2059 
2060  parameter.setTag( "ROL" );
2061  parameter.setVal( parsed_line[linePosition].string_ );
2062  option_block.addParam( parameter );
2063  ++linePosition; // Advance to next parameter.
2064  }
2065  }
2066  else if (type=="DEC")
2067  {
2068  if (typeExplicitSetLinDecOct) linePosition=2;
2069 
2070  while ( linePosition < numFields )
2071  {
2072  parameter.setTag( "PARAM" );
2073  parameter.setVal(std::string(ExtendedString(parsed_line[linePosition].string_).toUpper()));
2074  option_block.addParam( parameter );
2075  ++linePosition; // Advance to next parameter.
2076 
2077  parameter.setTag( "START" );
2078  parameter.setVal( parsed_line[linePosition].string_ );
2079  option_block.addParam( parameter );
2080  ++linePosition; // Advance to next parameter.
2081 
2082  parameter.setTag( "STOP" );
2083  parameter.setVal( parsed_line[linePosition].string_ );
2084  option_block.addParam( parameter );
2085  ++linePosition; // Advance to next parameter.
2086 
2087  parameter.setTag( "NUMROLS" );
2088  parameter.setVal( parsed_line[linePosition].string_ );
2089  option_block.addParam( parameter );
2090  ++linePosition; // Advance to next parameter.
2091  }
2092  }
2093  else if (type=="OCT")
2094  {
2095  if (typeExplicitSetLinDecOct) linePosition=2;
2096 
2097  while ( linePosition < numFields )
2098  {
2099  parameter.setTag( "PARAM" );
2100  parameter.setVal(std::string(ExtendedString(parsed_line[linePosition].string_).toUpper()));
2101  option_block.addParam( parameter );
2102  ++linePosition; // Advance to next parameter.
2103 
2104  parameter.setTag( "START" );
2105  parameter.setVal( parsed_line[linePosition].string_ );
2106  option_block.addParam( parameter );
2107  ++linePosition; // Advance to next parameter.
2108 
2109  parameter.setTag( "STOP" );
2110  parameter.setVal( parsed_line[linePosition].string_ );
2111  option_block.addParam( parameter );
2112  ++linePosition; // Advance to next parameter.
2113 
2114  parameter.setTag( "NUMROLS" );
2115  parameter.setVal( parsed_line[linePosition].string_ );
2116  option_block.addParam( parameter );
2117  ++linePosition; // Advance to next parameter.
2118  }
2119 
2120  }
2121  else if (type=="LIST")
2122  {
2123  parameter.setTag( "PARAM" );
2124  parameter.setVal(std::string(ExtendedString(parsed_line[1].string_).toUpper()));
2125  option_block.addParam( parameter );
2126 
2127  int linePosition=3;
2128  while (linePosition<numFields)
2129  {
2130  parameter.setTag( "VAL" );
2131  parameter.setVal( parsed_line[linePosition].string_ );
2132  option_block.addParam( parameter );
2133  ++linePosition;
2134  }
2135  }
2136  else
2137  {
2138  Report::UserError0().at(netlist_filename, parsed_line[0].lineNumber_)
2139  << ".ROL line contains an unrecognized type";
2140  }
2141 
2142  circuit_block.addOptions(option_block);
2143 
2144  return true;
2145 }
2146 
2147 } // namespace <unnamed>
2148 
2149 
2150 bool
2152  FactoryBlock & factory_block)
2153 {
2154  ROLFactory *factory = new ROLFactory(factory_block.analysisManager_, factory_block.linearSystem_, factory_block.nonlinearManager_, factory_block.loader_, factory_block.topology_, factory_block.initialConditionsManager_);
2155 
2156  addAnalysisFactory(factory_block, factory);
2157 
2158  factory_block.optionsManager_.addCommandParser(".ROL", extractROLData);
2159 
2160  factory_block.optionsManager_.addCommandProcessor("ROL", new ROLAnalysisReg(*factory));
2161 
2162  factory_block.optionsManager_.addOptionsProcessor("TIMEINT", IO::createRegistrationOptions(*factory, &ROLFactory::setTimeIntegratorOptionBlock));
2163 
2164  return true;
2165 }
2166 
2167 
2168 
2169 } // namespace Analysis
2170 } // namespace Xyce
2171 
bool doProcessSuccessfulStep()
Definition: N_ANP_ROL.C:597
bool enableSensitivity(TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, Topo::Topology &topology)
int setupSweepLoop(Parallel::Machine comm, Loader::Loader &loader, std::vector< SweepParam >::iterator begin, std::vector< SweepParam >::iterator end)
void setSweepValue(int step)
Definition: N_ANP_ROL.C:376
SweepVector stepSweepVector_
Definition: N_ANP_ROL.h:155
unsigned int successfulStepsTaken_
Number of consecutive successful time-integration steps.
ROLFactory & factory_
Definition: N_ANP_ROL.C:1963
Loader::Loader & loader_
Definition: N_ANP_ROL.h:149
virtual bool setInitialGuess(Linear::Vector *solVectorPtr)
Definition: N_LOA_Loader.h:232
std::vector< Linear::Vector * > mysensRHSPtrVector_
Definition: N_ANP_ROL.h:133
double RealT
Definition: N_ANP_ROL.h:60
std::vector< int > rolSweepFailures_
Definition: N_ANP_ROL.h:144
bool setTimeIntegratorOption(const Util::Param &param)
bool doProcessFailedStep()
Definition: N_ANP_ROL.C:685
std::vector< std::string > paramNameVec_
Definition: N_ANP_ROL.h:158
void evaluateStepError(const Loader::Loader &loader, const TIAParams &tia_params)
Pure virtual class to augment a linear system.
Loader::Loader & loader_
Definition: N_ANP_ROL.C:1937
virtual void stepFailure(Analysis::TwoLevelMode analysis)
Definition: N_LOA_Loader.h:287
Util::OptionBlock timeIntegratorOptionBlock_
Definition: N_ANP_ROL.C:1943
bool doAllocations(int nc, int nz)
Definition: N_ANP_ROL.C:521
virtual bool outputPlotFiles() const
Definition: N_LOA_Loader.h:261
unsigned int stepNumber
Time-integration step number counter.
IO::InitialConditionsManager & initialConditionsManager_
Definition: N_ANP_ROL.h:151
void outputSolDataArrays(std::ostream &os)
bool doHandlePredictor()
Definition: N_ANP_ROL.C:466
bool updateSweepParams(Loader::Loader &loader, int step_count, std::vector< SweepParam >::iterator begin, std::vector< SweepParam >::iterator end, bool overrideOriginal)
void setAnalysisMode(Mode analysis_mode)
AnalysisManager & analysisManager_
Definition: N_ANP_ROL.h:147
Topo::Topology & topology_
Definition: N_ANP_ROL.C:1938
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method)
virtual int getDoubleDCOPStep() const
Parallel::Machine getComm() const
void setAnalysisMode(AnalysisMode mode)
unsigned int failedStepsAttempted_
Total number of failed time-integration steps.
void setStepSweepVector(const Analysis::SweepVector &sweep_vector)
Parallel::Manager * getPDSManager() const
bool setDCOPOption(const Util::Param &param)
TimeIntg::StepErrorControl & getStepErrorControl()
NonLinearSolver & getNonlinearSolver()
std::vector< Linear::Vector * > statePtrVector_
Definition: N_ANP_ROL.h:126
Linear::Vector * daeQVectorPtr
virtual bool startTimeStep(bool beginIntegrationFlag, double nextTimeStep, double nextTime, int currentOrder)
Definition: N_LOA_Loader.h:305
void setErrorWtVector(const TIAParams &tia_params)
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_ROL.h:148
virtual bool isPDESystem() const
Definition: N_LOA_Loader.h:256
bool registerROLFactory(FactoryBlock &factory_block)
Definition: N_ANP_ROL.C:2151
Linear::Vector * daeFVectorPtr
IO::InitialConditionsManager & initialConditionsManager_
Definition: N_ANP_ROL.C:1939
The FactoryBlock contains parameters needed by the analysis creation functions.
IO::InitialConditionsManager & initialConditionsManager_
Nonlinear::AnalysisMode nonlinearAnalysisMode(Mode mode)
Returns the nonlinear analysis mode given the analysis mode.
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_ROL.C:1936
TimeIntg::TIAParams tiaParams_
Definition: N_ANP_ROL.h:154
virtual bool updateSources()
Definition: N_LOA_Loader.h:244
std::vector< Linear::Vector * > mydqdpPtrVector_
Definition: N_ANP_ROL.h:131
void initializeSolution_()
Definition: N_ANP_ROL.C:349
ROL(AnalysisManager &analysis_manager, Nonlinear::Manager &nonlinear_manager, Loader::Loader &loader, Linear::System &linear_system, Topo::Topology &topology, IO::InitialConditionsManager &initial_conditions_manager)
Definition: N_ANP_ROL.C:144
SweepParam parseSweepParams(Util::ParamList::const_iterator first, Util::ParamList::const_iterator last)
Populate the sweep params from the parameter list.
Linear::Vector * dFdxdVpVectorPtr
Loader::NonlinearEquationLoader & getNonlinearEquationLoader()
void setDoubleDCOPEnabled(bool enable)
AnalysisManager & analysisManager_
Definition: N_ANP_ROL.C:1934
Nonlinear::Manager & nonlinearManager_
std::vector< Linear::Vector * > constraintPtrVector_
Definition: N_ANP_ROL.h:127
std::vector< Util::OptionBlock > stepSweepAnalysisOptionBlock_
Definition: N_ANP_ROL.C:1942
TimeIntegrationMethod *(* Factory)(const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store)
Linear::Vector * nextSolutionPtr
std::vector< Linear::Vector * > solutionPtrVector_
Definition: N_ANP_ROL.h:125
std::vector< Linear::Vector * > testPtrVector_
Definition: N_ANP_ROL.h:129
void addAnalysisFactory(FactoryBlock &factory_block, Util::Factory< AnalysisBase, void > *factory)
std::vector< std::string > uncertainParams_
Definition: N_ANP_ROL.h:160
void setInputOPFlag(bool initial_conditions_loaded)
TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod()
std::vector< Linear::Vector * > mydbdpPtrVector_
Definition: N_ANP_ROL.h:132
const IO::CmdParse & getCommandLine() const
Linear::Vector * currSolutionPtr
TimeIntg::DataStore * getDataStore()
std::vector< Linear::Vector * > mydfdpPtrVector_
Definition: N_ANP_ROL.h:130
unsigned int baseIntegrationMethod_
Current time-integration method flag.
std::vector< Linear::Vector * > jvecPtrVector_
Definition: N_ANP_ROL.h:128
bool setTimeIntegratorOptions(const Util::OptionBlock &option_block)
Definition: N_ANP_ROL.C:203
virtual void stepSuccess(Analysis::TwoLevelMode analysis)
Definition: N_LOA_Loader.h:284
OutputMgrAdapter & outputManagerAdapter_
Definition: N_ANP_ROL.h:153
Linear::System & linearSystem_
Definition: N_ANP_ROL.h:152
Linear::Vector * flagSolutionPtr
Topo::Topology & topology_
Definition: N_ANP_ROL.h:150
Linear::Vector * daeBVectorPtr
bool setReturnCodeOption(const Util::Param &param)
const TimeIntg::TIAParams & getTIAParams() const
Definition: N_ANP_ROL.C:247
Linear::System & linearSystem_
Definition: N_ANP_ROL.C:1935
bool setAnalysisParams(const Util::OptionBlock &paramsBlock)
Definition: N_ANP_ROL.C:238