Xyce  6.1
N_ANP_AC.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-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 //-----------------------------------------------------------------------------
27 // Filename : $RCSfile: N_ANP_AC.C,v $
28 // Purpose : AC analysis functions.
29 // Special Notes :
30 // Creator : Ting Mei
31 // Creation Date : 7/11
32 //
33 // Revision Information:
34 // ---------------------
35 // Revision Number: $Revision: 1.120.2.1 $
36 // Revision Date : $Date: 2015/04/02 18:20:07 $
37 // Current Owner : $Author: tvrusso $
38 //-----------------------------------------------------------------------------
39 
40 #include <Xyce_config.h>
41 
42 #include <iomanip>
43 
44 #include <N_ANP_AC.h>
45 
46 #include <N_ANP_AnalysisManager.h>
47 #include <N_ANP_OutputMgrAdapter.h>
48 #include <N_ERH_Message.h>
49 #include <N_IO_CmdParse.h>
50 #include <N_IO_PkgOptionsMgr.h>
51 #include <N_LAS_BlockMatrix.h>
52 #include <N_LAS_BlockSystemHelpers.h>
53 #include <N_LAS_BlockVector.h>
54 #include <N_LAS_Builder.h>
55 #include <N_LAS_Matrix.h>
56 #include <N_LAS_MultiVector.h>
57 #include <N_LAS_System.h>
58 #include <N_LOA_Loader.h>
59 #include <N_NLS_Manager.h>
60 #include <N_TIA_DataStore.h>
61 #include <N_TIA_StepErrorControl.h>
64 #include <N_UTL_Diagnostic.h>
65 #include <N_TOP_Topology.h>
66 #include <N_UTL_FeatureTest.h>
67 #include <N_UTL_LogStream.h>
68 #include <N_UTL_Math.h>
69 #include <N_UTL_Timer.h>
70 
71 #include <N_PDS_ParMap.h>
72 
73 #include <Epetra_SerialComm.h>
74 #include <Epetra_Map.h>
75 #include <Epetra_BlockMap.h>
76 #include <Epetra_CrsMatrix.h>
77 #include <Epetra_CrsGraph.h>
78 #include <Epetra_MultiVector.h>
79 #include <Epetra_Vector.h>
80 #include <Epetra_Export.h>
81 #include <Epetra_LinearProblem.h>
82 #include <Amesos.h>
83 
84 #include<N_UTL_ExtendedString.h>
85 #include<N_UTL_ExpressionData.h>
86 #include<N_NLS_ReturnCodes.h>
87 
88 #include <Teuchos_RCP.hpp>
89 using Teuchos::RCP;
90 using Teuchos::rcp;
91 
92 namespace Xyce {
93 namespace Analysis {
94 
95 //-----------------------------------------------------------------------------
96 // Function : AnalysisManager::setTimeIntegratorOptions
97 // Purpose :
98 // Special Notes : These are from '.options timeint'
99 // Scope : public
100 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
101 // Creation Date : 04/18/02
102 //-----------------------------------------------------------------------------
104  const Util::OptionBlock & option_block)
105 {
106  for (Util::ParamList::const_iterator it = option_block.begin(), end = option_block.end(); it != end; ++it)
107  {
108  const Util::Param &param = *it;
109 
110  if (param.uTag() == "DEBUGLEVEL" )
111  IO::setTimeIntegratorDebugLevel(analysisManager_.getCommandLine(), param.getImmutableValue<int>());
112  else if (nonlinearManager_.setReturnCodeOption(param))
113  ;
114  else if (tiaParams_.setTimeIntegratorOption(param))
115  ;
116  else if (setDCOPOption(param))
117  ;
118  else
119  Report::UserError() << param.uTag() << " is not a recognized time integration option";
120  }
121 
122  return true;
123 }
124 
125 
126 //-----------------------------------------------------------------------------
127 // Function : AC::AC
128 // Purpose : constructor
129 // Special Notes :
130 // Scope : public
131 // Creator : Ting Mei
132 // Creation Date : 5/11
133 //-----------------------------------------------------------------------------
135  AnalysisManager & analysis_manager,
136  Linear::System & linear_system,
137  Nonlinear::Manager & nonlinear_manager,
138  Topo::Topology & topology)
139  : AnalysisBase(analysis_manager, "AC"),
140  StepEventListener(&analysis_manager),
141  analysisManager_(analysis_manager),
142  loader_(analysis_manager.getLoader()),
143  linearSystem_(linear_system),
144  nonlinearManager_(nonlinear_manager),
145  topology_(topology),
146  outputManagerAdapter_(analysis_manager.getOutputManagerAdapter()),
147  bVecRealPtr(linearSystem_.builder().createVector()),
148  bVecImagPtr(linearSystem_.builder().createVector()),
149  ACMatrix_(0),
150  B_(0),
151  X_(0),
152  blockSolver_(0),
153  blockProblem_(0),
154  acLoopSize_(0),
155  stepMult_(0.0),
156  fstep_(0.0),
157  type_("DEC"),
158  stepFlag_(false),
159  np_(10.0),
160  fStart_(1.0),
161  fStop_(1.0),
162  currentFreq_(0.0)
163 {
164  bVecRealPtr->putScalar(0.0);
165  bVecImagPtr->putScalar(0.0);
166 }
167 
168 //-----------------------------------------------------------------------------
169 // Function : AC::~AC()
170 // Purpose : destructor
171 // Special Notes :
172 // Scope : public
173 // Creator : Ting Mei
174 // Creation Date : 5/11
175 //-----------------------------------------------------------------------------
177 {
178  delete bVecRealPtr;
179  delete bVecImagPtr;
180  delete ACMatrix_;
181  delete B_;
182  delete X_;
183  delete blockSolver_;
184  delete blockProblem_;
185 }
186 
187 //-----------------------------------------------------------------------------
188 // Function : AC::notify
189 // Purpose :
190 // Special Notes :
191 // Scope : public
192 // Creator :
193 // Creation Date :
194 //-----------------------------------------------------------------------------
195 void AC::notify(const StepEvent &event)
196 {
197  if (event.state_ == StepEvent::STEP_STARTED)
198  {
200 
201  stepFlag_ = true;
203 
204  bVecRealPtr->putScalar(0.0);
205  bVecImagPtr->putScalar(0.0);
206  }
207 }
208 
209 //-----------------------------------------------------------------------------
210 // Function : AC::setAnalysisParams
211 // Purpose :
212 // Special Notes : These are from the .AC statement.
213 // Scope : public
214 // Creator : Ting Mei, SNL
215 // Creation Date : 6/11
216 //-----------------------------------------------------------------------------
217 bool
219  const Util::OptionBlock & paramsBlock)
220 {
221  for (Util::ParamList::const_iterator it = paramsBlock.begin(), end = paramsBlock.end(); it != end; ++it)
222  {
223  if ((*it).uTag() == "TYPE")
224  {
225  type_ = (*it).stringValue();
226  }
227  else if ((*it).uTag() == "NP")
228  {
229  np_ = (*it).getImmutableValue<double>();
230  }
231  else if ((*it).uTag() == "FSTART")
232  {
233  fStart_ = (*it).getImmutableValue<double>();
234  }
235  else if ((*it).uTag() == "FSTOP")
236  {
237  fStop_ = (*it).getImmutableValue<double>();
238  }
239  }
240 
241  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
242  {
243  dout() << section_divider << std::endl
244  << "AC simulation parameters"
245  << std::endl
246  << "number of points = " << np_ << std::endl
247  << "starting frequency = " << fStart_ << std::endl
248  << "stop frequency = " << fStop_
249  << std::endl;
250  }
251 
252  return true;
253 }
254 
255 //-----------------------------------------------------------------------------
256 // Function : AC::getDCOPFlag()
257 // Purpose :
258 // Special Notes :
259 // Scope : public
260 // Creator : Eric Keiter, SNL
261 // Creation Date : 3/24/2014
262 //-----------------------------------------------------------------------------
263 bool AC::getDCOPFlag() const
264 {
266 }
267 
268 //-----------------------------------------------------------------------------
269 // Function : AC::run()
270 // Purpose :
271 // Special Notes :
272 // Scope : public
273 // Creator : Ting Mei, SNL
274 // Creation Date : 5/11
275 //-----------------------------------------------------------------------------
276 bool AC::doRun()
277 {
278  return doInit() && doLoopProcess() && doFinish();
279 }
280 
281 //-----------------------------------------------------------------------------
282 // Function : AC::init()
283 // Purpose :
284 // Special Notes :
285 // Scope : public
286 // Creator : Ting Mei, SNL
287 // Creation Date : 5/11
288 //-----------------------------------------------------------------------------
290 {
291  bool bsuccess = true;
292 
294 
295  // Get set to do the operating point.
298 
299  stepNumber = 0;
302 
303  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::INITIALIZE, AnalysisEvent::AC_IC));
304 
305  // set initial guess, if there is one to be set.
306  // this setInitialGuess call is to up an initial guess in the
307  // devices that have them (usually PDE devices). This is different than
308  // the "intializeProblem" call, which sets IC's. (initial conditions are
309  // different than initial guesses.
311 
312  // If available, set initial solution (.IC, .NODESET, etc).
317 
318  // Set a constant history for operating point calculation
322 
323  // solving for DC op
330 
332  {
333  Report::UserError() << "Solving for DC operating point failed! Cannot continue AC analysis";
334  return false;
335  }
336 
337  // only output DC op if the .op was specified in the netlist
338  // or if this AC analysis is called from a .step loop
340  {
342  stepNumber,
348  objectiveVec_,
351  }
352 
353  // This for saving the data from the DC op. different from the above where we are
354  // concerned with generating normal output.
356 
358 
359 #if 0
360  Xyce::dout() << "bVecReal:" <<std::endl;
361  bVecRealPtr->printPetraObject(Xyce::dout());
362  Xyce::dout() << "bVecImag:" <<std::endl;
363  bVecImagPtr->printPetraObject(Xyce::dout());
364 #endif
365 
366  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::FINISH, AnalysisEvent::AC_IC));
367 
368  return bsuccess;
369 }
370 
371 
372 //-----------------------------------------------------------------------------
373 // Function : AC::loopProcess()
374 // Purpose : Conduct the stepping loop.
375 // Special Notes :
376 // Scope : public
377 // Creator : Ting Mei, SNL
378 // Creation Date : 5/11
379 //-----------------------------------------------------------------------------
381 {
382  analysisManager_.getDataStore()->daeQVectorPtr->putScalar(0.0);
383  analysisManager_.getDataStore()->daeFVectorPtr->putScalar(0.0);
384 
389 
400  );
401 
426 
431 
434 
435  if (DEBUG_TIME && isActive(Diag::TIME_PARAMETERS))
436  {
437  Xyce::dout() << "dQdxMatrixPtr:" << std::endl;
438  analysisManager_.getDataStore()->dQdxMatrixPtr->printPetraObject( Xyce::dout() );
439 
440  Xyce::dout() << "dFdxMatrixPtr:" << std::endl;
441  analysisManager_.getDataStore()->dFdxMatrixPtr->printPetraObject( Xyce::dout() );
442 
443  Xyce::dout() << std::endl;
444  }
445 
447 
448  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::INITIALIZE, AnalysisEvent::AC));
449 
450  for (int currentStep = 0; currentStep < acLoopSize_; ++currentStep)
451  {
452  updateCurrentFreq_(currentStep);
453 
455 
456  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_STARTED, AnalysisEvent::AC, currentFreq_, currentStep));
457 
458  bool stepAttemptStatus;
459  {
460  Stats::StatTop _nonlinearStat("Nonlinear Solve");
461  Stats::TimeBlock _nonlinearTimer(_nonlinearStat);
462 
463  stepAttemptStatus = solveLinearSystem_();
464  }
465 
466 #if 0
467  Xyce::dout()<<"AC X vector:"<<std::endl;
468  X_->printPetraObject(Xyce::dout());
469 #endif
470 
471  if (stepAttemptStatus)
472  {
473  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_SUCCESSFUL, AnalysisEvent::AC, currentFreq_, currentStep));
475  }
476  else // stepAttemptStatus (ie do this if the step FAILED)
477  {
478  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::STEP_FAILED, AnalysisEvent::AC, currentFreq_, currentStep));
480  }
481  }
482 
483  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish(AnalysisEvent(AnalysisEvent::FINISH, AnalysisEvent::AC));
484 
485  return true;
486 }
487 
488 
489 //-----------------------------------------------------------------------------
490 // Function : AC::createLinearSystem_()
491 // Purpose :
492 // Special Notes :
493 // Scope : public
494 // Creator : Ting Mei, Heidi Thornquist, SNL
495 // Creation Date : 6/20/2011
496 //-----------------------------------------------------------------------------
498 {
499  bool bsuccess = true;
500 
501  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
502 
503  RCP<N_PDS_ParMap> baseMap = rcp(pds_manager.getParallelMap( Parallel::SOLUTION ), false);
504  Epetra_CrsGraph &baseFullGraph = *pds_manager.getMatrixGraph(Parallel::JACOBIAN);
505 
506  int numBlocks = 2;
507 
508  RCP<N_PDS_ParMap> blockMap = Linear::createBlockParMap(numBlocks, *baseMap);
509 
510  // Create a block vector
511  delete B_;
512  B_ = new Linear::BlockVector(numBlocks, blockMap, baseMap);
513 
514  // -----------------------------------------------------
515  // Now test block graphs.
516  // -----------------------------------------------------
517 
518  std::vector<std::vector<int> > blockPattern(2);
519  blockPattern[0].resize(2);
520  blockPattern[0][0] = 0; blockPattern[0][1] = 1;
521  blockPattern[1].resize(2);
522  blockPattern[1][0] = 0; blockPattern[1][1] = 1;
523 
524  int offset = Linear::generateOffset( *baseMap );
525 
526  RCP<Epetra_CrsGraph> blockGraph = Linear::createBlockGraph( offset, blockPattern, *blockMap, baseFullGraph);
527 
528  delete ACMatrix_;
529  ACMatrix_ = new Linear::BlockMatrix( numBlocks, offset, blockPattern, *blockGraph, baseFullGraph);
530 
531  // First diagonal block
532  ACMatrix_->put( 0.0 ); // Zero out whole matrix
533  ACMatrix_->block( 0, 0 ).add(*G_);
534 
535  // Second diagonal block
536  ACMatrix_->block( 1, 1 ).add(*G_);
537 
538  B_->putScalar( 0.0 );
539  B_->block( 0 ).addVec( 1.0, *bVecRealPtr);
540  B_->block( 1 ).addVec( 1.0, *bVecImagPtr);
541 
542  Amesos amesosFactory;
543 
544  delete X_;
545  X_ = new Linear::BlockVector (numBlocks, blockMap, baseMap);
546  X_->putScalar( 0.0 );
547 
548  delete blockProblem_;
549  blockProblem_ = new Epetra_LinearProblem(&ACMatrix_->epetraObj(), &X_->epetraObj(), &B_->epetraObj() );
550 
551  delete blockSolver_;
552  blockSolver_ = amesosFactory.Create( "Klu", *blockProblem_ );
553 
554  // Need to reindex the linear system because of the noncontiguous block map.
555  Teuchos::ParameterList params;
556  params.set( "Reindex", true );
557  blockSolver_->SetParameters( params );
558 
559  // Call symbolic factorization without syncronizing the values, since they are not necessary here.
560  int linearStatus = blockSolver_->SymbolicFactorization();
561 
562  if (linearStatus != 0)
563  {
564  Xyce::dout() << "Amesos symbolic factorization exited with error: " << linearStatus;
565  bsuccess = false;
566  }
567 
568  return bsuccess;
569 }
570 
571 //-----------------------------------------------------------------------------
572 // Function : AC::updateLinearSystemFreq_()
573 // Purpose :
574 // Special Notes :
575 // Scope : public
576 // Creator : Ting Mei, Heidi Thornquist, SNL
577 // Creation Date : 6/20/2011
578 //-----------------------------------------------------------------------------
580 {
581  double omega = 2.0 * M_PI * currentFreq_;
582 
583  ACMatrix_->block( 0, 1).put( 0.0);
584  ACMatrix_->block( 0, 1).add(*C_);
585  ACMatrix_->block( 0, 1).scale(-omega);
586 
587  ACMatrix_->block(1, 0).put( 0.0);
588  ACMatrix_->block(1, 0).add(*C_);
589  ACMatrix_->block(1, 0).scale(omega);
590 
591  // Copy the values loaded into the blocks into the global matrix for the solve.
592  ACMatrix_->assembleGlobalMatrix();
593 
594 #if 0
595  Xyce::dout()<<"G matrix:"<<std::endl;
596  G_->printPetraObject(Xyce::dout());
597 
598  Xyce::dout()<<"C matrix:"<<std::endl;
599  C_->printPetraObject(Xyce::dout());
600 
601  Xyce::dout()<<"AC matrix:"<<std::endl;
602  ACMatrix_->printPetraObject(Xyce::dout());
603 
604  Xyce::dout()<<"AC B vector:"<<std::endl;
605  B_->printPetraObject(Xyce::dout());
606 #endif
607 
608  return true;
609 }
610 
611 //-----------------------------------------------------------------------------
612 // Function : AC::solveLinearSystem_()
613 // Purpose :
614 // Special Notes :
615 // Scope : public
616 // Creator : Ting Mei, Heidi Thornquist, SNL
617 // Creation Date : 6/2011
618 //-----------------------------------------------------------------------------
620 {
621  bool bsuccess = true;
622  // Solve the block problem
623 
624  int linearStatus = blockSolver_->NumericFactorization();
625 
626  if (linearStatus != 0)
627  {
628  Xyce::dout() << "Amesos numeric factorization exited with error: " << linearStatus;
629  bsuccess = false;
630  }
631 
632  linearStatus = blockSolver_->Solve();
633  if (linearStatus != 0)
634  {
635  Xyce::dout() << "Amesos solve exited with error: " << linearStatus;
636  bsuccess = false;
637  }
638 
639  return bsuccess;
640 }
641 
642 //-----------------------------------------------------------------------------
643 // Function : AC::processSuccessfulStep()
644 // Purpose :
645 // Special Notes :
646 // Scope : public
647 // Creator : Ting Mei, SNL
648 // Creation Date :
649 //-----------------------------------------------------------------------------
651 {
652  bool bsuccess = true;
653 
654 // Output x.
655  outputManagerAdapter_.outputAC (currentFreq_, X_->block(0), X_-> block(1));
656 
657  if ( !firstDoubleDCOPStep() )
658  {
659  stepNumber += 1;
662  }
663 
664  // This output call is for device-specific output (like from a PDE device,
665  // outputting mesh-based tecplot files). It will only work in parallel if on
666  // a machine where all processors have I/O capability.
667  loader_.output();
668 
669  return bsuccess;
670 }
671 
672 
673 //-----------------------------------------------------------------------------
674 // Function : AC::processFailedStep
675 // Purpose :
676 // Special Notes :
677 // Scope : public
678 // Creator : Ting Mei, SNL
679 // Creation Date :
680 //-----------------------------------------------------------------------------
682 {
683  bool bsuccess = true;
684 
685  stepNumber += 1;
686  acSweepFailures_.push_back(stepNumber);
689 
690  return bsuccess;
691 }
692 
693 //-----------------------------------------------------------------------------
694 // Function : AC::finish
695 // Purpose :
696 // Special Notes :
697 // Scope : public
698 // Creator : Ting Mei, SNL
699 // Creation Date :
700 //-----------------------------------------------------------------------------
702 {
703  bool bsuccess = true;
704 
705  if (DEBUG_ANALYSIS)
706  {
707  Xyce::dout() << "Calling AC::doFinish() outputs!" << std::endl;
708  }
709 
711  if (!(acSweepFailures_.empty()))
712  {
713  bsuccess = false;
714  }
715 
716  return bsuccess;
717 }
718 
719 
720 //-----------------------------------------------------------------------------
721 // Function : AC::doHandlePredictor
722 // Purpose :
723 // Special Notes :
724 // Scope : private
725 // Creator : Eric Keiter, SNL
726 // Creation Date : 06/24/2013
727 //-----------------------------------------------------------------------------
729 {
733 
734  // In case this is the upper level of a 2-level sim, tell the
735  // inner solve to do its prediction:
737 
738  return true;
739 }
740 
741 //-----------------------------------------------------------------------------
742 // Function : AC::updateCurrentFreq_(int stepNumber )
743 // Purpose :
744 // Special Notes : Used for AC analysis classes.
745 // Scope : public
746 // Creator : Ting Mei, SNL.
747 // Creation Date :
748 //-----------------------------------------------------------------------------
749 bool AC::updateCurrentFreq_(int stepNumber)
750 {
751  if (type_ == "LIN")
752  {
753 
754  currentFreq_ = fStart_ + static_cast<double>(stepNumber)*fstep_;
755  }
756  else if(type_ == "DEC" || type_ == "OCT")
757  {
758 
759  currentFreq_ = fStart_*pow(stepMult_, static_cast<double>(stepNumber) );
760  }
761  else
762  {
763  Report::DevelFatal().in("AC::updateCurrentFreq_") << "AC::updateCurrentFreq_: unsupported STEP type";
764  }
765 
766 #if 0
767  if (isActive(Diag::TIME_PARAMETERS))
768  {
769  Xyce::dout() << "currentFreq_ = " << currentFreq_ << std::endl;
770  }
771 #endif
772 
773  return true;
774 }
775 
776 //-----------------------------------------------------------------------------
777 // Function : AC::setupSweepParam_
778 // Purpose : Processes sweep parameters.
779 // Special Notes : Used for AC analysis classes.
780 // Scope : public
781 // Creator : Ting Mei, SNL.
782 // Creation Date :
783 //-----------------------------------------------------------------------------
785 {
786  double fstart, fstop;
787  double fcount = 0.0;
788 
789  fstart = fStart_;
790  fstop = fStop_;
791 
792  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
793  {
794  Xyce::dout() << std::endl << std::endl;
795  Xyce::dout() << section_divider << std::endl;
796  Xyce::dout() << "AC::setupSweepParam_" << std::endl;
797  }
798 
799  if (type_ == "LIN")
800  {
801  int np = static_cast<int>(np_);
802 
803  if ( np == 1)
804  fstep_ = 0;
805  else
806  fstep_ = (fstop - fstart)/(np_ - 1.0);
807 
808  fcount = np_;
809  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
810  {
811  Xyce::dout() << "fstep = " << fstep_ << std::endl;
812  }
813  }
814  else if (type_ == "DEC")
815  {
816  stepMult_ = pow(10.0, 1.0/np_);
817  fcount = floor(fabs(log10(fstart) - log10(fstop)) * np_ + 1.0);
818  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
819  {
820  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
821  }
822  }
823  else if (type_ == "OCT")
824  {
825  stepMult_ = pow(2.0, 1.0/np_);
826 
827  // changed to remove dependence on "log2" function, which apparently
828  // doesn't exist in the math libraries of FreeBSD or the mingw
829  // cross-compilation suite. Log_2(x)=log_e(x)/log_e(2.0)
830  double ln2 = log(2.0);
831  fcount = floor(fabs(log(fstart) - log(fstop))/ln2 * np_ + 1.0);
832  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
833  {
834  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
835  }
836  }
837  else
838  {
839  Report::DevelFatal().in("AC::setupSweepParam") << "Unsupported type";
840  }
841 
842  // At this point, pinterval equals the total number of steps
843  // for the step loop.
844  return static_cast<int> (fcount);
845 }
846 
847 namespace {
848 
849 //-----------------------------------------------------------------------------
850 // Class : ACFactory
851 // Purpose :
852 // Special Notes :
853 // Scope : public
854 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
855 // Creation Date : Thu Jan 29 12:53:02 2015
856 //-----------------------------------------------------------------------------
857 ///
858 /// Factory for parsing AC parameters from the netlist and creating AC analysis.
859 ///
860 class ACFactory : public Factory<AC>
861 {
862 public:
863  //-----------------------------------------------------------------------------
864  // Function : ACFactory
865  // Purpose :
866  // Special Notes :
867  // Scope : public
868  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
869  // Creation Date : Thu Jan 29 12:54:09 2015
870  //-----------------------------------------------------------------------------
871  ///
872  /// Constructs the AC analysis factory
873  ///
874  /// @invariant Stores the results of parsing, so if more than one of the analysis and
875  /// associated lines are parsed, the second options simply overwrite the previously parsed
876  /// values.
877  ///
878  /// @invariant The existence of the parameters specified in the constructor cannot
879  /// change.
880  ///
881  /// @param analysis_manager
882  /// @param linear_system
883  /// @param nonlinear_manager
884  /// @param topology
885  ///
886  ACFactory(
887  Analysis::AnalysisManager & analysis_manager,
888  Linear::System & linear_system,
889  Nonlinear::Manager & nonlinear_manager,
890  Topo::Topology & topology)
891  : Factory<AC>(),
892  analysisManager_(analysis_manager),
893  linearSystem_(linear_system),
894  nonlinearManager_(nonlinear_manager),
895  topology_(topology)
896  {}
897 
898  virtual ~ACFactory()
899  {}
900 
901  //-----------------------------------------------------------------------------
902  // Function : create
903  // Purpose :
904  // Special Notes :
905  // Scope : public
906  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
907  // Creation Date : Thu Jan 29 12:59:00 2015
908  //-----------------------------------------------------------------------------
909  ///
910  /// Create a new AC analysis and applies the analysis and time integrator option blocks.
911  ///
912  /// @return new AC analysis object
913  ///
914  AC *create() const
915  {
916  analysisManager_.setAnalysisMode(ANP_MODE_AC);
918  ac->setAnalysisParams(acAnalysisOptionBlock_);
919  ac->setTimeIntegratorOptions(timeIntegratorOptionBlock_);
920 
921  return ac;
922  }
923 
924  //-----------------------------------------------------------------------------
925  // Function : setACAnalysisOptionBlock
926  // Purpose :
927  // Special Notes :
928  // Scope : public
929  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
930  // Creation Date : Thu Jan 29 13:00:14 2015
931  //-----------------------------------------------------------------------------
932  ///
933  /// Saves the analysis parsed options block in the factory.
934  ///
935  /// @invariant Overwrites any previously specified analysis option block.
936  ///
937  /// @param option_block parsed option block
938  ///
939  void setACAnalysisOptionBlock(const Util::OptionBlock &option_block)
940  {
941  acAnalysisOptionBlock_ = option_block;
942  }
943 
944  //-----------------------------------------------------------------------------
945  // Function : setTimeIntegratorOptionBlock
946  // Purpose :
947  // Special Notes :
948  // Scope : public
949  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
950  // Creation Date : Thu Jan 29 13:01:27 2015
951  //-----------------------------------------------------------------------------
952  ///
953  /// Saves the time integrator parsed option block.
954  ///
955  /// @invariant Overwrites any previously specified time integrator option block.
956  ///
957  /// @param option_block parsed option block
958  ///
959  void setTimeIntegratorOptionBlock(const Util::OptionBlock &option_block)
960  {
961  timeIntegratorOptionBlock_ = option_block;
962  }
963 
964 public:
965  AnalysisManager & analysisManager_;
966  Linear::System & linearSystem_;
967  Nonlinear::Manager & nonlinearManager_;
968  Topo::Topology & topology_;
969 
970 private:
971  Util::OptionBlock acAnalysisOptionBlock_;
972  Util::OptionBlock timeIntegratorOptionBlock_;
973 };
974 
975 // .options TIMEINT
976 struct TimeIntegratorOptionsReg : public IO::PkgOptionsReg
977 {
978  TimeIntegratorOptionsReg(
979  ACFactory & factory )
980  : factory_(factory)
981  {}
982 
983  bool operator()(const Util::OptionBlock &option_block)
984  {
985  factory_.setTimeIntegratorOptionBlock(option_block);
986 
987  return true;
988  }
989 
990  ACFactory & factory_;
991 };
992 
993 // .AC
994 struct ACAnalysisReg : public IO::PkgOptionsReg
995 {
996  ACAnalysisReg(
997  ACFactory & factory )
998  : factory_(factory)
999  {}
1000 
1001  bool operator()(const Util::OptionBlock &option_block)
1002  {
1003  factory_.setACAnalysisOptionBlock(option_block);
1004 
1005  factory_.analysisManager_.addAnalysis(&factory_);
1006 
1007  return true;
1008  }
1009 
1010  ACFactory & factory_;
1011 };
1012 
1013 } // namespace <unnamed>
1014 
1015 
1016 bool
1018  const std::string & netlist_filename,
1019  IO::PkgOptionsMgr & options_manager,
1020  AnalysisManager & analysis_manager,
1021  Linear::System & linear_system,
1022  Nonlinear::Manager & nonlinear_manager,
1023  Topo::Topology & topology)
1024 {
1025  ACFactory *factory = new ACFactory(analysis_manager, linear_system, nonlinear_manager, topology);
1026 
1027  analysis_manager.addAnalysisFactory(factory);
1028 
1029  options_manager.submitRegistration("AC", netlist_filename, new ACAnalysisReg(*factory));
1030  options_manager.submitRegistration("TIMEINT", netlist_filename, new TimeIntegratorOptionsReg(*factory));
1031 
1032  return true;
1033 }
1034 
1035 } // namespace Analysis
1036 } // namespace Xyce
bool doProcessSuccessfulStep()
Definition: N_ANP_AC.C:650
Linear::Vector * lastSolutionPtr
bool doHandlePredictor()
Definition: N_ANP_AC.C:728
bool getDCOPFlag() const
Definition: N_ANP_AC.C:263
bool createLinearSystem_()
Definition: N_ANP_AC.C:497
unsigned int successfulStepsTaken_
Number of consecutive successful time-integration steps.
virtual bool setInitialGuess(Linear::Vector *solVectorPtr)
Definition: N_LOA_Loader.h:231
Linear::Vector * lastLeadDeltaVPtr
bool setAnalysisParams(const Util::OptionBlock &paramsBlock)
Definition: N_ANP_AC.C:218
bool doLoopProcess()
Definition: N_ANP_AC.C:380
Linear::Matrix * C_
Definition: N_ANP_AC.h:156
bool setTimeIntegratorOption(const Util::Param &param)
ACFactory & factory_
Definition: N_ANP_AC.C:990
void outputAC(double freq, const Linear::Vector &solnVecRealPtr, const Linear::Vector &solnVecImaginaryPtr)
Pure virtual class to augment a linear system.
TimeIntg::TIAParams tiaParams_
Definition: N_ANP_AC.h:137
int doubleDCOPStep_
current step in the DCOP loop.
void dcOutput(int dcStepNumber, Linear::Vector &currSolutionPtr, Linear::Vector &stateVecPtr, Linear::Vector &storeVecPtr, Linear::Vector &lead_current_vector, Linear::Vector &junction_voltage_vector, std::vector< double > &objectiveVec_, std::vector< double > &dOdpVec_, std::vector< double > &dOdpAdjVec_, std::vector< double > &scaled_dOdpVec_, std::vector< double > &scaled_dOdpAdjVec_)
Util::OptionBlock timeIntegratorOptionBlock_
Definition: N_ANP_AC.C:972
virtual bool loadDAEVectors(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *StaDerivVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr, Linear::Vector *stoLeadCurrQVectorPtr, Linear::Vector *nextLeadFVectorPtr, Linear::Vector *currLeadFVectorPtr, Linear::Vector *lastLeadFVectorPtr, Linear::Vector *nextLeadQVectorPtr, Linear::Vector *nextJunctionVVectorPtr, Linear::Vector *currJunctionVVectorPtr, Linear::Vector *lastJunctionVVectorPtr, Linear::Vector *QVectorPtr, Linear::Vector *FVectorPtr, Linear::Vector *BVectorPtr, Linear::Vector *dFdxdVpVectorPtr, Linear::Vector *dQdxdVpVectorPtr)
Definition: N_LOA_Loader.h:121
unsigned int stepNumber
Time-integration step number counter.
virtual bool loadBVectorsforAC(Linear::Vector *bVecRealPtr, Linear::Vector *bVecImagPtr)
Definition: N_LOA_Loader.h:202
bool doProcessFailedStep()
Definition: N_ANP_AC.C:681
Linear::Vector * currStorePtr
Linear::Vector * lastStatePtr
Topo::Topology & topology_
Definition: N_ANP_AC.C:968
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
double currentFreq_
Definition: N_ANP_AC.h:154
virtual ~AC()
Definition: N_ANP_AC.C:176
void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method)
bool setupInitialConditions(Linear::Vector &solnVec, Linear::Vector &flagVec)
bool registerACFactory(const std::string &netlist_filename, IO::PkgOptionsMgr &options_manager, AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology)
Definition: N_ANP_AC.C:1017
bool resetAll(const TIAParams &tia_params)
std::vector< int > acSweepFailures_
Definition: N_ANP_AC.h:144
Util::ListenerAutoSubscribe< StepEvent > StepEventListener
Linear::Vector * nextLeadDeltaVPtr
Linear::Vector * currStatePtr
unsigned int failedStepsAttempted_
Total number of failed time-integration steps.
Parallel::Manager * getPDSManager() const
bool setDCOPOption(const Util::Param &param)
TimeIntg::StepErrorControl & getStepErrorControl()
bool setTimeIntegratorOptions(const Util::OptionBlock &option_block)
Definition: N_ANP_AC.C:103
Linear::Vector * bVecRealPtr
Definition: N_ANP_AC.h:139
Linear::BlockVector * B_
Definition: N_ANP_AC.h:159
int setupSweepParam_()
Definition: N_ANP_AC.C:784
NonLinearSolver & getNonlinearSolver()
std::vector< double > scaled_dOdpVec_
Definition: N_ANP_AC.h:168
Linear::Vector * daeQVectorPtr
std::string type_
Definition: N_ANP_AC.h:147
Linear::Vector * lastLeadCurrentPtr
virtual bool startTimeStep()
Definition: N_LOA_Loader.h:304
void setErrorWtVector(const TIAParams &tia_params)
std::vector< double > dOdpAdjVec_
Definition: N_ANP_AC.h:167
Amesos_BaseSolver * blockSolver_
Definition: N_ANP_AC.h:162
Linear::Vector * daeFVectorPtr
Linear::Vector * currLeadCurrentQPtr
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_AC.h:134
OutputMgrAdapter & outputManagerAdapter_
Definition: N_ANP_AC.h:136
Linear::Matrix * dFdxMatrixPtr
virtual bool updateSources()
Definition: N_LOA_Loader.h:243
Linear::Vector * nextStatePtr
AC(AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology)
Definition: N_ANP_AC.C:134
Linear::Vector * dFdxdVpVectorPtr
virtual bool loadDAEMatrices(Linear::Vector *tmpSolVectorPtr, Linear::Vector *tmpStaVectorPtr, Linear::Vector *tmpStaDerivVectorPtr, Linear::Vector *tmpStoVectorPtr, Linear::Matrix *tmpdQdxMatrixPtr, Linear::Matrix *tmpdFdxMatrixPtr)
Definition: N_LOA_Loader.h:109
virtual bool updateState(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr)
Definition: N_LOA_Loader.h:188
Linear::Vector * currLeadDeltaVPtr
AnalysisManager & analysisManager_
Definition: N_ANP_AC.C:965
void addAnalysisFactory(Factory< void > *factory)
bool updateCurrentFreq_(int stepNumber)
Definition: N_ANP_AC.C:749
std::vector< double > scaled_dOdpAdjVec_
Definition: N_ANP_AC.h:169
Linear::Vector * nextSolutionPtr
Linear::BlockVector * X_
Definition: N_ANP_AC.h:160
#define M_PI
virtual bool getDoubleDCOPFlag() const
Definition: N_LOA_Loader.h:255
Linear::Vector * nextStorePtr
bool updateLinearSystemFreq_()
Definition: N_ANP_AC.C:579
The analysis factory template defines an interface for analysis type testing and analysis creation...
Definition: N_ANP_Factory.h:65
Linear::Vector * dQdxdVpVectorPtr
Util::OptionBlock acAnalysisOptionBlock_
Definition: N_ANP_AC.C:971
Linear::Vector * currLeadCurrentPtr
Linear::Vector * lastStorePtr
void setInputOPFlag(bool initial_conditions_loaded)
TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod()
const IO::CmdParse & getCommandLine() const
AnalysisManager & analysisManager_
Definition: N_ANP_AC.h:131
std::vector< double > objectiveVec_
Definition: N_ANP_AC.h:165
Linear::Vector * bVecImagPtr
Definition: N_ANP_AC.h:140
Linear::Vector * currSolutionPtr
TimeIntg::DataStore * getDataStore()
void evaluateStepError(const TIAParams &tia_params)
Linear::BlockMatrix * ACMatrix_
Definition: N_ANP_AC.h:158
bool doubleDCOPFlag_
true if doing a double-DCOP is possible.
unsigned int baseIntegrationMethod_
Current time-integration method flag.
Linear::Vector * nextStoreLeadCurrQPtr
Linear::Vector * nextStateDerivPtr
std::vector< double > dOdpVec_
Definition: N_ANP_AC.h:166
void outputDCOP(const Linear::Vector &solution)
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_AC.C:967
Linear::Matrix * dQdxMatrixPtr
bool solveLinearSystem_()
Definition: N_ANP_AC.C:619
Epetra_LinearProblem * blockProblem_
Definition: N_ANP_AC.h:163
Linear::Vector * flagSolutionPtr
void notify(const StepEvent &event)
Definition: N_ANP_AC.C:195
Loader::Loader & loader_
Definition: N_ANP_AC.h:132
Linear::Vector * daeBVectorPtr
Linear::Matrix * G_
Definition: N_ANP_AC.h:157
bool setReturnCodeOption(const Util::Param &param)
Linear::System & linearSystem_
Definition: N_ANP_AC.C:966
virtual bool output() const
Definition: N_LOA_Loader.h:260
Linear::Vector * nextLeadCurrentPtr