Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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 //-----------------------------------------------------------------------------
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.55 $
36 // Revision Date : $Date: 2014/02/24 23:49:12 $
37 // Current Owner : $Author: tvrusso $
38 //-----------------------------------------------------------------------------
39 
40 #include <Xyce_config.h>
41 
42 
43 // ---------- Standard Includes ----------
44 #include <iomanip>
45 
46 
47 // ---------- Xyce Includes ----------
48 #include <N_ANP_AnalysisManager.h>
49 #include <N_TIA_Assembler.h>
50 #include <N_TIA_DataStore.h>
51 #include <N_LOA_Loader.h>
52 #include <N_LAS_Matrix.h>
53 #include <N_LAS_System.h>
54 #include <N_MPDE_Manager.h>
55 #include <N_IO_OutputMgr.h>
56 #include <N_TIA_StepErrorControl.h>
57 #include <N_UTL_Timer.h>
58 #include <N_UTL_LogStream.h>
59 
60 #include <N_IO_CmdParse.h>
61 
62 #include<N_ANP_AC.h>
63 
64 #include <N_UTL_Misc.h>
65 #include <N_LAS_MultiVector.h>
66 #include <N_LAS_BlockMatrix.h>
67 #include <N_LAS_BlockVector.h>
68 #include <N_LAS_BlockSystemHelpers.h>
69 
70 #include <N_PDS_ParMap.h>
71 #ifdef Xyce_PARALLEL_MPI
72 #include <N_PDS_ParComm.h>
73 #include <mpi.h>
74 #else
75 #include <N_PDS_SerialComm.h>
76 #endif
77 
78 #include <Epetra_SerialComm.h>
79 #include <Epetra_Map.h>
80 #include <Epetra_BlockMap.h>
81 #include <Epetra_CrsMatrix.h>
82 #include <Epetra_CrsGraph.h>
83 #include <Epetra_MultiVector.h>
84 #include <Epetra_Vector.h>
85 #include <Epetra_Export.h>
86 #include <Epetra_LinearProblem.h>
87 #include <Amesos.h>
88 
89 #include<N_UTL_ExpressionData.h>
90 #include<N_NLS_ReturnCodes.h>
91 
92 namespace Xyce {
93 namespace Analysis {
94 
95 //-----------------------------------------------------------------------------
96 // Function : AC::AC( AnalysisManager * )
97 // Purpose : constructor
98 // Special Notes :
99 // Scope : public
100 // Creator : Ting Mei
101 // Creation Date : 5/11
102 //-----------------------------------------------------------------------------
103 AC::AC( AnalysisManager * anaManagerPtr ) :
104  AnalysisBase(anaManagerPtr),
105 // initialIntegrationMethod_(TIAMethod_BACKWARD_EULER),
106  dcopFlag_(true),
107  bVecRealPtr(0),
108  bVecImagPtr(0),
109  acLoopSize_(0),
110  stepMult_(0.0),
111  fstep_(0.0),
112  currentFreq_(0.0)
113 {
114  bVecRealPtr = lasSystemRCPtr_->builder().createVector();
115  bVecImagPtr = lasSystemRCPtr_->builder().createVector();
116 
117  bVecRealPtr->putScalar(0.0);
118  bVecImagPtr->putScalar(0.0);
119 
120 }
121 
122 //-----------------------------------------------------------------------------
123 // Function : AC::~AC()
124 // Purpose : destructor
125 // Special Notes :
126 // Scope : public
127 // Creator : Ting Mei
128 // Creation Date : 5/11
129 //-----------------------------------------------------------------------------
131 {
132 
133  if (bVecRealPtr) { delete bVecRealPtr; bVecRealPtr=0; }
134 
135  if (bVecImagPtr) { delete bVecImagPtr; bVecImagPtr=0; }
136 
137 }
138 
139 //-----------------------------------------------------------------------------
140 // Function : AC::setAnalysisParams
141 // Purpose :
142 // Special Notes : These are from the .AC statement.
143 // Scope : public
144 // Creator : Ting Mei, SNL
145 // Creation Date : 6/11
146 //-----------------------------------------------------------------------------
147 bool AC::setAnalysisParams(const N_UTL_OptionBlock & paramsBlock)
148 {
149  std::list<N_UTL_Param>::const_iterator it_tp;
150  std::list<N_UTL_Param>::const_iterator first = paramsBlock.getParams().begin();
151  std::list<N_UTL_Param>::const_iterator last = paramsBlock.getParams().end();
152  for (it_tp = first; it_tp != last; ++it_tp)
153  {
154  if (it_tp->uTag() == "TYPE")
155  {
156  tiaParams.type = it_tp->stringValue();
157 // tiaParams.tStartGiven = true;
158  }
159  else if (it_tp->uTag() == "NP")
160  {
161  tiaParams.np = it_tp->getImmutableValue<double>();
162  }
163  else if (it_tp->uTag() == "FSTART")
164  {
165  tiaParams.fStart = it_tp->getImmutableValue<double>();
166  }
167  else if (it_tp->uTag() == "FSTOP")
168  {
169  tiaParams.fStop = it_tp->getImmutableValue<double>();
170  }
171  }
172 
173 // tiaParams.debugLevel = 1;
174  if (DEBUG_ANALYSIS && tiaParams.debugLevel > 0)
175  {
176  dout() << section_divider << std::endl
177  << "AC simulation parameters"
178  //<< Util::push << std::endl
179  << std::endl
180  << "number of points = " << tiaParams.np << std::endl
181  << "starting frequency = " << tiaParams.fStart << std::endl
182  << "stop frequency = " << tiaParams.fStop
183  //<< Util::pop << std::endl;
184  << std::endl;
185  }
186 
187  return true;
188 }
189 
190 //-----------------------------------------------------------------------------
191 // Function : AC::run()
192 // Purpose :
193 // Special Notes :
194 // Scope : public
195 // Creator : Ting Mei, SNL
196 // Creation Date : 5/11
197 //-----------------------------------------------------------------------------
198 bool AC::run()
199 {
200  bool bsuccess = true;
201 
202  bsuccess = bsuccess & init();
203  bsuccess = bsuccess & loopProcess();
204 
205  // if processing the loop failed,
206  // then skip finish step
207  if( bsuccess )
208  {
209  bsuccess = bsuccess & finish();
210  }
211 
212  return bsuccess;
213 }
214 
215 //-----------------------------------------------------------------------------
216 // Function : AC::init()
217 // Purpose :
218 // Special Notes :
219 // Scope : public
220 // Creator : Ting Mei, SNL
221 // Creation Date : 5/11
222 //-----------------------------------------------------------------------------
223 bool AC::init()
224 {
225  bool bsuccess = true;
226 
228 
229  if(dcopFlag_)
230  {
231  anaManagerRCPtr_->currentMode_ = 0;
232  }
233 
234  // Get set to do the operating point.
236  wimRCPtr_->createTimeIntegMethod(integrationMethod_);
237 
238  stepNumber = 0;
239  doubleDCOPFlag_ = loaderRCPtr_->getDoubleDCOPFlag ();
241 
242  // set initial guess, if there is one to be set.
243  // this setInitialGuess call is to up an initial guess in the
244  // devices that have them (usually PDE devices). This is different than
245  // the "intializeProblem" call, which sets IC's. (initial conditions are
246  // different than initial guesses.
247  loaderRCPtr_->setInitialGuess (anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr);
248 
249  // If available, set initial solution (.IC, .NODESET, etc).
250  inputOPFlag_ = outputMgrAdapterRCPtr_->setupInitialConditions( *(anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr), *(anaManagerRCPtr_->getTIADataStore()->flagSolutionPtr));
251 
252  // Set a constant history for operating point calculation
253  anaManagerRCPtr_->getTIADataStore()->setConstantHistory();
254  anaManagerRCPtr_->getTIADataStore()->computeDividedDifferences();
255  wimRCPtr_->obtainCorrectorDeriv();
256 
257  // solving for DC op
258  handlePredictor();
259  loaderRCPtr_->updateSources();
260  secRCPtr_->newtonConvergenceStatus = nlsMgrRCPtr_->solve();
261  anaManagerRCPtr_->getTIADataStore()->stepLinearCombo ();
263  secRCPtr_->evaluateStepError ();
264 
265  if ( secRCPtr_->newtonConvergenceStatus <= 0)
266  {
267  std::string msg=
268  "Solving for DC operating point failed! Cannot continue AC analysis.";
269  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
270  }
271 
272  // only output DC op if the .op was specified in the netlist
273  // or if this AC analysis is called from a .step loop
274  if ( anaManagerRCPtr_->getStepFlag() || anaManagerRCPtr_->getDotOpFlag() )
275  {
276  outputMgrAdapterRCPtr_->dcOutput(
277  stepNumber,
278  *anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr,
279  *anaManagerRCPtr_->getTIADataStore()->nextStatePtr,
280  *anaManagerRCPtr_->getTIADataStore()->nextStorePtr,
281  objectiveVec_,
283  outputMgrAdapterRCPtr_->finishOutput();
284  }
285 
286  // This for saving the data from the DC op. different from the above where we are
287  // concerned with generating normal output.
288  outputMgrAdapterRCPtr_->outputDCOP( *(anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr) );
289  loaderRCPtr_->loadBVectorsforAC (bVecRealPtr, bVecImagPtr);
290 
291  return bsuccess;
292 }
293 
294 
295 //-----------------------------------------------------------------------------
296 // Function : AC::loopProcess()
297 // Purpose : Conduct the stepping loop.
298 // Special Notes :
299 // Scope : public
300 // Creator : Ting Mei, SNL
301 // Creation Date : 5/11
302 //-----------------------------------------------------------------------------
304 {
305  bool bsuccess = true;
306 
307  anaManagerRCPtr_->getTIADataStore()->daeQVectorPtr->putScalar(0.0);
308  anaManagerRCPtr_->getTIADataStore()->daeFVectorPtr->putScalar(0.0);
309 
310  anaManagerRCPtr_->getTIADataStore()->dFdxdVpVectorPtr->putScalar(0.0);
311  anaManagerRCPtr_->getTIADataStore()->dQdxdVpVectorPtr->putScalar(0.0);
312  anaManagerRCPtr_->getTIADataStore()->dQdxMatrixPtr->put(0.0);
313  anaManagerRCPtr_->getTIADataStore()->dFdxMatrixPtr->put(0.0);
314 
315 // integrationMethod_ = 6;
316 
317  loaderRCPtr_->updateState
318  ((anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr),
319  (anaManagerRCPtr_->getTIADataStore()->currSolutionPtr),
320  (anaManagerRCPtr_->getTIADataStore()->lastSolutionPtr),
321  (anaManagerRCPtr_->getTIADataStore()->nextStatePtr),
322  (anaManagerRCPtr_->getTIADataStore()->currStatePtr),
323  (anaManagerRCPtr_->getTIADataStore()->lastStatePtr),
324  (anaManagerRCPtr_->getTIADataStore()->nextStorePtr),
325  (anaManagerRCPtr_->getTIADataStore()->currStorePtr),
326  (anaManagerRCPtr_->getTIADataStore()->lastStorePtr)
327  );
328 
329  loaderRCPtr_->loadDAEVectors
330  ((anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr),
331  (anaManagerRCPtr_->getTIADataStore()->currSolutionPtr),
332  (anaManagerRCPtr_->getTIADataStore()->lastSolutionPtr),
333  (anaManagerRCPtr_->getTIADataStore()->nextStatePtr),
334  (anaManagerRCPtr_->getTIADataStore()->currStatePtr),
335  (anaManagerRCPtr_->getTIADataStore()->lastStatePtr),
336  (anaManagerRCPtr_->getTIADataStore()->nextStateDerivPtr),
337  (anaManagerRCPtr_->getTIADataStore()->nextStorePtr),
338  (anaManagerRCPtr_->getTIADataStore()->currStorePtr),
339  (anaManagerRCPtr_->getTIADataStore()->lastStorePtr),
340  (anaManagerRCPtr_->getTIADataStore()->nextStoreLeadCurrQCompPtr),
341  (anaManagerRCPtr_->getTIADataStore()->daeQVectorPtr),
342  (anaManagerRCPtr_->getTIADataStore()->daeFVectorPtr),
343  (anaManagerRCPtr_->getTIADataStore()->dFdxdVpVectorPtr),
344  (anaManagerRCPtr_->getTIADataStore()->dQdxdVpVectorPtr) );
345 
346 // loaderRCPtr_->loadDAEMatrices(anaManagerRCPtr_->getTIADataStore()->currSolutionPtr,
347 // anaManagerRCPtr_->getTIADataStore()->currStatePtr, anaManagerRCPtr_->getTIADataStore()->currStateDerivPtr,
348 // anaManagerRCPtr_->getTIADataStore()->dQdxMatrixPtr, anaManagerRCPtr_->getTIADataStore()->dFdxMatrixPtr);
349 
350  loaderRCPtr_->loadDAEMatrices(anaManagerRCPtr_->getTIADataStore()->nextSolutionPtr,
351  anaManagerRCPtr_->getTIADataStore()->nextStatePtr, anaManagerRCPtr_->getTIADataStore()->nextStateDerivPtr,
352  anaManagerRCPtr_->getTIADataStore()->nextStorePtr,
353  anaManagerRCPtr_->getTIADataStore()->dQdxMatrixPtr, anaManagerRCPtr_->getTIADataStore()->dFdxMatrixPtr);
354 
355  CPtr_ = rcp(anaManagerRCPtr_->getTIADataStore()->dQdxMatrixPtr, false);
356  GPtr_ = rcp(anaManagerRCPtr_->getTIADataStore()->dFdxMatrixPtr, false);
357 
358  if (tiaParams.debugLevel > 0)
359  {
360  Xyce::dout() << "dQdxMatrixPtr:" << std::endl;
361  anaManagerRCPtr_->getTIADataStore()->dQdxMatrixPtr->printPetraObject( Xyce::dout() );
362 
363  Xyce::dout() << "dFdxMatrixPtr:" << std::endl;
364  anaManagerRCPtr_->getTIADataStore()->dFdxMatrixPtr->printPetraObject( Xyce::dout() );
365 
366  Xyce::dout() << std::endl;
367  }
368 
370 
371  int currentStep = 0;
372  int finalStep = acLoopSize_;
373 
374  bool stepAttemptStatus;
375 
376  while (currentStep < finalStep)
377  {
378  updateCurrentFreq_(currentStep);
379 
381 
382  stepAttemptStatus = solveLinearSystem_();
383 
384  currentStep++;
385 
386  if (stepAttemptStatus)
387  {
389  }
390  else // stepAttemptStatus (ie do this if the step FAILED)
391  {
393  }
394 
395  }
396 
397  return bsuccess;
398 }
399 
400 
401 //-----------------------------------------------------------------------------
402 // Function : AC::createLinearSystem_()
403 // Purpose :
404 // Special Notes :
405 // Scope : public
406 // Creator : Ting Mei, Heidi Thornquist, SNL
407 // Creation Date : 6/20/2011
408 //-----------------------------------------------------------------------------
410 {
411 
412  bool bsuccess = true;
413 
414  RCP<N_PDS_Manager> pdsMgrPtr_;
415  pdsMgrPtr_ = rcp(lasSystemRCPtr_->getPDSManager(), false);
416 
417  RCP<N_PDS_ParMap> baseMap;
418  RCP<Epetra_CrsGraph> BaseFullGraph_;
419 
420  baseMap = rcp(pdsMgrPtr_->getParallelMap( "SOLUTION" ), false);
421  BaseFullGraph_ = rcp( pdsMgrPtr_->getMatrixGraph("JACOBIAN"), false );
422 
423  int numBlocks = 2;
424 
425  RCP<N_PDS_ParMap> blockMap = createBlockParMap(numBlocks, *baseMap);
426 
427  // Create a block vector
428  BPtr_ = rcp ( new N_LAS_BlockVector ( numBlocks, blockMap, baseMap ) );
429 
430  // -----------------------------------------------------
431  // Now test block graphs.
432  // -----------------------------------------------------
433 
434  std::vector<std::vector<int> > blockPattern(2);
435  blockPattern[0].resize(2);
436  blockPattern[0][0] = 0; blockPattern[0][1] = 1;
437  blockPattern[1].resize(2);
438  blockPattern[1][0] = 0; blockPattern[1][1] = 1;
439 
440  int offset = generateOffset( *baseMap );
441 
442  RCP<Epetra_CrsGraph> blockGraph = createBlockGraph( offset, blockPattern, *blockMap, *BaseFullGraph_);
443 
444  ACMatrixPtr_ = rcp ( new N_LAS_BlockMatrix( numBlocks, offset, blockPattern, *blockGraph, *BaseFullGraph_) );
445 
446  // First diagonal block
447  ACMatrixPtr_->put( 0.0 ); // Zero out whole matrix
448  ACMatrixPtr_->block( 0, 0 ).add(*GPtr_);
449  // Second diagonal block
450  ACMatrixPtr_->block( 1, 1 ).add(*GPtr_);
451 
452  BPtr_->putScalar( 0.0 );
453  BPtr_->block( 0 ).addVec( 1.0, *bVecRealPtr);
454  BPtr_->block( 1 ).addVec( 1.0, *bVecImagPtr);
455 
456  Amesos amesosFactory;
457 
458  XPtr_ = rcp ( new N_LAS_BlockVector (numBlocks, blockMap, baseMap) );
459  XPtr_->putScalar( 0.0 );
460 
461  blockProblem = rcp(new Epetra_LinearProblem(&ACMatrixPtr_->epetraObj(), &XPtr_->epetraObj(), &BPtr_->epetraObj() ) );
462 
463  blockSolver = rcp( amesosFactory.Create( "Klu", *blockProblem ) );
464 
465  // Need to reindex the linear system because of the noncontiguous block map.
466  Teuchos::ParameterList params;
467  params.set( "Reindex", true );
468  blockSolver->SetParameters( params );
469 
470  // Call symbolic factorization without syncronizing the values, since they are not necessary here.
471  int linearStatus = blockSolver->SymbolicFactorization();
472 
473  if (linearStatus != 0)
474  {
475  Xyce::dout() << "Amesos symbolic factorization exited with error: " << linearStatus;
476  bsuccess = false;
477  }
478 
479  return bsuccess;
480 
481 }
482 
483 //-----------------------------------------------------------------------------
484 // Function : AC::updateLinearSystemFreq_()
485 // Purpose :
486 // Special Notes :
487 // Scope : public
488 // Creator : Ting Mei, Heidi Thornquist, SNL
489 // Creation Date : 6/20/2011
490 //-----------------------------------------------------------------------------
491 
493 {
494  double omega;
495 
496  omega = 2.0 * M_PI * currentFreq_;
497 
498  ACMatrixPtr_->block( 0, 1).put( 0.0);
499  ACMatrixPtr_->block( 0, 1).add(*CPtr_);
500  ACMatrixPtr_->block( 0, 1).scale(-omega);
501 
502  ACMatrixPtr_->block(1, 0).put( 0.0);
503  ACMatrixPtr_->block(1, 0).add(*CPtr_);
504  ACMatrixPtr_->block(1, 0).scale(omega);
505 
506  // Copy the values loaded into the blocks into the global matrix for the solve.
507  ACMatrixPtr_->assembleGlobalMatrix();
508 
509  return true;
510 }
511 
512 //-----------------------------------------------------------------------------
513 // Function : AC::solveLinearSystem_()
514 // Purpose :
515 // Special Notes :
516 // Scope : public
517 // Creator : Ting Mei, Heidi Thornquist, SNL
518 // Creation Date : 6/2011
519 //-----------------------------------------------------------------------------
520 
522 {
523 
524  bool bsuccess = true;
525  // Solve the block problem
526 
527  int linearStatus = blockSolver->NumericFactorization();
528 
529  if (linearStatus != 0)
530  {
531  Xyce::dout() << "Amesos numeric factorization exited with error: " << linearStatus;
532  bsuccess = false;
533  }
534 
535  linearStatus = blockSolver->Solve();
536  if (linearStatus != 0)
537  {
538  Xyce::dout() << "Amesos solve exited with error: " << linearStatus;
539  bsuccess = false;
540  }
541 
542  return bsuccess;
543 }
544 
545 //-----------------------------------------------------------------------------
546 // Function : Transient::resetForStepAnalysis()
547 // Purpose : When doing a .STEP sweep, some data must be reset to its
548 // initial state.
549 // Special Notes :
550 // Scope : public
551 // Creator : T. Mei
552 // Creation Date : 04/16/12
553 //-----------------------------------------------------------------------------
555 {
557  stepNumber = 0;
558  beginningIntegration = true;
559 
560 // nlsMgrRCPtr_->resetAll(DC_OP);
561 // secRCPtr_->resetAll();
562 
563  bVecRealPtr->putScalar(0.0);
564  bVecImagPtr->putScalar(0.0);
565  return true;
566 }
567 
568 //-----------------------------------------------------------------------------
569 // Function : AC::processSuccessfulStep()
570 // Purpose :
571 // Special Notes :
572 // Scope : public
573 // Creator : Ting Mei, SNL
574 // Creation Date :
575 //-----------------------------------------------------------------------------
577 {
578  bool bsuccess = true;
579 
580 // Output x.
581  outputMgrAdapterRCPtr_->outputAC (currentFreq_, XPtr_->block(0), XPtr_-> block(1));
582 
583  if ( !firstDoubleDCOPStep_() )
584  {
585  stepNumber += 1;
588  }
589 
590  // This output call is for device-specific output (like from a PDE device,
591  // outputting mesh-based tecplot files). It will only work in parallel if on
592  // a machine where all processors have I/O capability.
593  loaderRCPtr_->output();
594 
595  return bsuccess;
596 }
597 
598 
599 //-----------------------------------------------------------------------------
600 // Function : AC::processFailedStep
601 // Purpose :
602 // Special Notes :
603 // Scope : public
604 // Creator : Ting Mei, SNL
605 // Creation Date :
606 //-----------------------------------------------------------------------------
608 {
609  bool bsuccess = true;
610 
611  stepNumber += 1;
612  acSweepFailures_.push_back(stepNumber);
614  secRCPtr_->numberSuccessiveFailures += 1;
615 
616  return bsuccess;
617 }
618 
619 //-----------------------------------------------------------------------------
620 // Function : AC::finish
621 // Purpose :
622 // Special Notes :
623 // Scope : public
624 // Creator : Ting Mei, SNL
625 // Creation Date :
626 //-----------------------------------------------------------------------------
628 {
629  bool bsuccess = true;
630 
631 #ifdef Xyce_DEBUG_ANALYSIS
632  Xyce::dout() << "Calling AC::finish() outputs!" << std::endl;
633 #endif
634  outputMgrAdapterRCPtr_->finishOutput();
635  if (!(acSweepFailures_.empty()))
636  {
637  bsuccess = false;
638  }
639 
640  return bsuccess;
641 }
642 
643 
644 //-----------------------------------------------------------------------------
645 // Function : AC::handlePredictor
646 // Purpose :
647 // Special Notes :
648 // Scope : private
649 // Creator : Eric Keiter, SNL
650 // Creation Date : 06/24/2013
651 //-----------------------------------------------------------------------------
653 {
654  anaManagerRCPtr_->getTIADataStore()->setErrorWtVector();
655  wimRCPtr_->obtainPredictor();
656  wimRCPtr_->obtainPredictorDeriv();
657 
658  // In case this is the upper level of a 2-level sim, tell the
659  // inner solve to do its prediction:
660  loaderRCPtr_->startTimeStep ();
661 
662  return true;
663 }
664 
665 //-----------------------------------------------------------------------------
666 // Function : AC::updateCurrentFreq_(int stepNumber )
667 // Purpose :
668 // Special Notes : Used for AC analysis classes.
669 // Scope : public
670 // Creator : Ting Mei, SNL.
671 // Creation Date :
672 //-----------------------------------------------------------------------------
673 bool AC::updateCurrentFreq_(int stepNumber)
674 {
675  double fstart;
676  fstart = tiaParams.fStart;
677 
678 // tiaParams.debugLevel = 1;
679 
680  if (tiaParams.type=="LIN")
681  {
682 
683  currentFreq_ = fstart + static_cast<double>(stepNumber)*fstep_;
684  }
685  else if(tiaParams.type=="DEC" || tiaParams.type=="OCT")
686  {
687 
688  currentFreq_ = fstart*pow(stepMult_, static_cast<double>(stepNumber) );
689  }
690  else
691  {
692  std::string msg=
693  "AC::updateCurrentFreq_: unsupported STEP type";
694  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
695 
696  }
697 
698  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
699  {
700  Xyce::dout() << "currentFreq_ = " << currentFreq_ << std::endl;
701  }
702 
703  return true;
704 }
705 
706 //-----------------------------------------------------------------------------
707 // Function : AC::setupSweepParam_
708 // Purpose : Processes sweep parameters.
709 // Special Notes : Used for AC analysis classes.
710 // Scope : public
711 // Creator : Ting Mei, SNL.
712 // Creation Date :
713 //-----------------------------------------------------------------------------
715 {
716  double fstart, fstop;
717  double fcount = 0.0;
718 
719  fstart = tiaParams.fStart;
720  fstop = tiaParams.fStop;
721 
722 #ifdef Xyce_DEBUG_ANALYSIS
723  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
724  {
725  Xyce::dout() << std::endl << std::endl;
726  Xyce::dout() << section_divider << std::endl;
727  Xyce::dout() << "AC::setupSweepParam_" << std::endl;
728  }
729 #endif
730 
731  if (tiaParams.type=="LIN")
732  {
733  int np = static_cast<int> (tiaParams.np);
734 
735  if ( np == 1)
736  fstep_ = 0;
737  else
738  fstep_ = (fstop - fstart)/(tiaParams.np - 1);
739 
740  fcount = tiaParams.np;
741 #ifdef Xyce_DEBUG_ANALYSIS
742  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
743  {
744  Xyce::dout() << "fstep = " << fstep_ << std::endl;
745  }
746 #endif
747  }
748  else if(tiaParams.type=="DEC")
749  {
750  stepMult_ = pow(10,(1/tiaParams.np));
751  fcount = floor(fabs(log10(fstart) - log10(fstop)) * tiaParams.np + 1);
752 #ifdef Xyce_DEBUG_ANALYSIS
753  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
754  {
755  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
756  }
757 #endif
758  }
759  else if(tiaParams.type=="OCT")
760  {
761  stepMult_ = pow(2,1/(tiaParams.np));
762 
763  // changed to remove dependence on "log2" function, which apparently
764  // doesn't exist in the math libraries of FreeBSD or the mingw
765  // cross-compilation suite. Log_2(x)=log_e(x)/log_e(2.0)
766  double ln2=log(2.0);
767  fcount = floor(fabs(log(fstart) - log(fstop))/ln2 * tiaParams.np + 1);
768 #ifdef Xyce_DEBUG_ANALYSIS
769  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
770  {
771  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
772  }
773 #endif
774  }
775  else
776  {
777  std::string msg=
778  "AC::setupSweepParam: unsupported type";
779  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
780 
781  }
782 
783  // At this point, pinterval equals the total number of steps
784  // for the step loop.
785  return static_cast<int> (fcount);
786 }
787 
788 } // namespace Analysis
789 } // namespace Xyce