Xyce  6.1
N_ANP_NOISE.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-NOISE04-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_NOISE.C,v $
28 // Purpose : NOISE analysis functions.
29 // Special Notes :
30 // Creator : Eric Keiter
31 // Creation Date : 12/8/2014
32 //
33 // Revision Information:
34 // ---------------------
35 // Revision Number: $Revision: 1.45 $
36 // Revision Date : $Date: 2015/09/03 22:11:39 $
37 // Current Owner : $Author: rlschie $
38 //-----------------------------------------------------------------------------
39 
40 #include <Xyce_config.h>
41 
42 #include <iomanip>
43 
44 #include <fstream>
45 
46 #include <N_ANP_NOISE.h>
47 #include <N_ANP_NoiseData.h>
48 
49 #include <N_ANP_AnalysisManager.h>
50 #include <N_ANP_OutputMgrAdapter.h>
51 #include <N_ERH_Message.h>
52 #include <N_ERH_ErrorMgr.h>
53 #include <N_IO_CircuitBlock.h>
54 #include <N_IO_CmdParse.h>
55 #include <N_IO_InitialConditions.h>
56 #include <N_IO_OptionBlock.h>
57 #include <N_IO_PkgOptionsMgr.h>
58 #include <N_IO_SpiceSeparatedFieldTool.h>
59 #include <N_LAS_BlockMatrix.h>
60 #include <N_LAS_BlockSystemHelpers.h>
61 #include <N_LAS_BlockVector.h>
62 #include <N_LAS_Builder.h>
63 #include <N_LAS_Matrix.h>
64 #include <N_LAS_MultiVector.h>
65 #include <N_LAS_System.h>
66 #include <N_LOA_Loader.h>
67 #include <N_NLS_Manager.h>
68 
69 #include <N_TIA_DataStore.h>
71 #include <N_TIA_StepErrorControl.h>
73 
74 #include <N_UTL_Diagnostic.h>
75 #include <N_UTL_FeatureTest.h>
76 #include <N_UTL_LogStream.h>
77 #include <N_UTL_Math.h>
78 #include <N_UTL_Timer.h>
79 #include <N_PDS_Comm.h>
80 #include <N_PDS_MPI.h>
81 #include <N_PDS_Manager.h>
82 #include <N_PDS_Serial.h>
83 
84 #include <N_PDS_ParMap.h>
85 
86 #include <N_TOP_Topology.h>
87 
88 #include <Epetra_SerialComm.h>
89 #include <Epetra_Map.h>
90 #include <Epetra_BlockMap.h>
91 #include <Epetra_CrsMatrix.h>
92 #include <Epetra_CrsGraph.h>
93 #include <Epetra_MultiVector.h>
94 #include <Epetra_Vector.h>
95 #include <Epetra_Export.h>
96 #include <Epetra_LinearProblem.h>
97 #include <Amesos.h>
98 
99 #include<N_UTL_ExtendedString.h>
100 #include<N_UTL_ExpressionData.h>
101 #include<N_NLS_ReturnCodes.h>
102 
103 #include <Teuchos_RCP.hpp>
104 using Teuchos::RCP;
105 using Teuchos::rcp;
106 
107 // putting these here for now (from spice3's noisedefs.h file)
108 #define N_MINLOG 1E-38 /* the smallest number we can take the log of */
109 #define N_MINGAIN 1E-20 // the smallest input-output gain we can tolerate
110  // (to calculate input-referred noise we divide
111  // the output noise by the gain)
112 
113 #define N_INTFTHRESH 1E-10 // the largest slope (of a log-log noise spectral
114  // density vs. freq plot) at which the noise
115  // spectum is still considered flat. (no need for
116  // log curve fitting)
117 #define N_INTUSELOG 1E-10 // decides which expression to use for the integral of
118  // x**k. If k is -1, then we must use a 'ln' form.
119  // Otherwise, we use a 'power' form. This
120  // parameter is the region around (k=) -1 for which
121  // use the 'ln' form.
122 
123 namespace Xyce {
124 namespace Analysis {
125 
126 //-----------------------------------------------------------------------------
127 // Function : AnalysisManager::setTimeIntegratorOptions
128 // Purpose :
129 // Special Notes : These are from '.options timeint'
130 // Scope : public
131 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
132 // Creation Date : 04/18/02
133 //-----------------------------------------------------------------------------
135  const Util::OptionBlock & option_block)
136 {
137  for (Util::ParamList::const_iterator it = option_block.begin(),
138  end = option_block.end(); it != end; ++it)
139  {
140  const Util::Param &param = *it;
141 
142  if (param.uTag() == "DEBUGLEVEL" )
143  {
144  IO::setTimeIntegratorDebugLevel(analysisManager_.getCommandLine(), param.getImmutableValue<int>());
145  }
146  else if (nonlinearManager_.setReturnCodeOption(param))
147  {
148  ;
149  }
150  else if (tiaParams_.setTimeIntegratorOption(param))
151  {
152  ;
153  }
154  else if (setDCOPOption(param))
155  {
156  ;
157  }
158  else
159  {
160  Report::UserError() << param.uTag()
161  << " is not a recognized time integration option";
162  }
163  }
164 
165  return true;
166 }
167 
168 //-----------------------------------------------------------------------------
169 // Function : NOISE::NOISE
170 // Purpose : constructor
171 // Special Notes :
172 // Scope : public
173 // Creator : Eric Keiter
174 // Creation Date : 12/8/2014
175 //-----------------------------------------------------------------------------
177  AnalysisManager & analysis_manager,
178  Linear::System & linear_system,
179  Nonlinear::Manager & nonlinear_manager,
180  Loader::Loader & loader,
181  Topo::Topology & topology,
182  IO::InitialConditionsManager & initial_conditions_manager)
183  : AnalysisBase(analysis_manager, "NOISE"),
184  StepEventListener(&analysis_manager),
185  analysisManager_(analysis_manager),
186  loader_(loader),
187  linearSystem_(linear_system),
188  nonlinearManager_(nonlinear_manager),
189  topology_(topology),
190  initialConditionsManager_(initial_conditions_manager),
191  outputManagerAdapter_(analysis_manager.getOutputManagerAdapter()),
192  bVecRealPtr(linearSystem_.builder().createVector()),
193  bVecImagPtr(linearSystem_.builder().createVector()),
194  bNoiseVecRealPtr(linearSystem_.builder().createVector()),
195  bNoiseVecImagPtr(linearSystem_.builder().createVector()),
196  hackOutputCalledBefore_(false),
197  useAdjoint_(true),
198  outputNodeSingle_(true),
199  outputNode1_(""),
200  outputNode2_(""),
201  specifiedSource_(""),
202  ACMatrix_(0),
203  B_(0),
204  X_(0),
205  saved_AC_X_(0),
206  blockSolver_(0),
207  blockProblem_(0),
208  noiseLoopSize_(0),
209  type_("DEC"),
210  stepFlag_(false),
211  np_(10.0),
212  fStart_(1.0),
213  fStop_(1.0),
214  stepMult_(0.0),
215  fstep_(0.0),
216  pts_per_summary_(0),
217  pts_per_summary_Given(false),
218  delFreq_(0.0),
219  lastFreq_(0.0),
220  currentFreq_(0.0),
221  lnFreq_(0.0),
222  lnLastFreq_(0.0),
223  delLnFreq_(0.0),
224  GainSqInv_(0.0),
225  lnGainInv_(0.0),
226  totalOutputNoise_(0.0),
227  totalInputNoise_(0.0),
228  totalOutputNoiseDens_(0.0),
229  totalInputNoiseDens_(0.0)
230 {
231  bVecRealPtr->putScalar(0.0);
232  bVecImagPtr->putScalar(0.0);
233  bNoiseVecRealPtr->putScalar(0.0);
234  bNoiseVecImagPtr->putScalar(0.0);
235 }
236 
237 //-----------------------------------------------------------------------------
238 // Function : NOISE::~NOISE()
239 // Purpose : destructor
240 // Special Notes :
241 // Scope : public
242 // Creator : Eric Keiter
243 // Creation Date : 12/8/2014
244 //-----------------------------------------------------------------------------
246 {
247  delete bVecRealPtr;
248  delete bVecImagPtr;
249  delete bNoiseVecRealPtr;
250  delete bNoiseVecImagPtr;
251  delete ACMatrix_;
252  delete B_;
253  delete X_;
254  delete saved_AC_X_;
255  delete blockSolver_;
256  delete blockProblem_;
257 
258  int size = noiseDataVec_.size();
259  for (int i=0;i<size;++i)
260  {
261  delete (noiseDataVec_[i]);
262  }
263  noiseDataVec_.clear();
264 }
265 
266 //-----------------------------------------------------------------------------
267 // Function : NOISE::notify
268 // Purpose :
269 // Special Notes :
270 // Scope : public
271 // Creator :
272 // Creation Date :
273 //-----------------------------------------------------------------------------
274 void NOISE::notify(const StepEvent &event)
275 {
276  if (event.state_ == StepEvent::STEP_STARTED)
277  {
279 
280  stepFlag_ = true;
282 
283  bVecRealPtr->putScalar(0.0);
284  bVecImagPtr->putScalar(0.0);
285  bNoiseVecRealPtr->putScalar(0.0);
286  bNoiseVecImagPtr->putScalar(0.0);
287  }
288 }
289 
290 //-----------------------------------------------------------------------------
291 // Function : NOISE::setAnalysisParams
292 // Purpose :
293 // Special Notes : These are from the .NOISE statement.
294 // Scope : public
295 // Creator : Eric Keiter, SNL
296 // Creation Date : 12/8/2014
297 //-----------------------------------------------------------------------------
298 bool NOISE::setAnalysisParams(const Util::OptionBlock & paramsBlock)
299 {
300  for (Util::ParamList::const_iterator it = paramsBlock.begin(),
301  end = paramsBlock.end(); it != end; ++it)
302  {
303  if ((*it).uTag() == "V")
304  {
305  if ((*it).getImmutableValue<double>()==1.0)
306  {
307  outputNodeSingle_ = true;
308  Util::ParamList::const_iterator itNode = it;
309  itNode++;
310  outputNode1_ = (*itNode).uTag();
311  }
312  else if ((*it).getImmutableValue<double>()==2.0)
313  {
314  outputNodeSingle_ = false;
315  Util::ParamList::const_iterator itNode = it;
316  itNode++;
317  outputNode1_ = (*itNode).uTag();
318  itNode++;
319  outputNode2_ = (*itNode).uTag();
320  }
321  }
322  else if ((*it).uTag() == "SOURCE")
323  {
324  specifiedSource_ = (*it).stringValue();
325  }
326  else if ((*it).uTag() == "TYPE")
327  {
328  type_ = (*it).stringValue();
329  }
330  else if ((*it).uTag() == "NP")
331  {
332  np_ = (*it).getImmutableValue<double>();
333  }
334  else if ((*it).uTag() == "FSTART")
335  {
336  fStart_ = (*it).getImmutableValue<double>();
337  }
338  else if ((*it).uTag() == "FSTOP")
339  {
340  fStop_ = (*it).getImmutableValue<double>();
341  }
342  else if ((*it).uTag() == "PTS_PER_SUMMARY")
343  {
344  pts_per_summary_ = (*it).getImmutableValue<int>();
345  }
346  }
347 
348  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
349  {
350  dout() << section_divider << std::endl
351  << "NOISE simulation parameters"
352  << std::endl;
353 
354  if (outputNodeSingle_)
355  {
356  dout() << "Output Node: V(" << outputNode1_ << ")" <<std::endl;
357  }
358  else
359  {
360  dout() << "Output Node: V(" << outputNode1_ << ","<<outputNode2_<<")" <<std::endl;
361  }
362 
363  dout() << "specified source = " << specifiedSource_ << std::endl
364  << "number of points = " << np_ << std::endl
365  << "starting frequency = " << fStart_ << std::endl
366  << "stop frequency = " << fStop_ << std::endl
367  << "pts_per_summary = " << pts_per_summary_
368  << std::endl;
369  }
370 
371  return true;
372 }
373 
374 //-----------------------------------------------------------------------------
375 // Function : NOISE::getDCOPFlag()
376 // Purpose :
377 // Special Notes :
378 // Scope : public
379 // Creator : Eric Keiter, SNL
380 // Creation Date : 12/8/2014
381 //-----------------------------------------------------------------------------
382 bool NOISE::getDCOPFlag() const
383 {
385 }
386 
387 //-----------------------------------------------------------------------------
388 // Function : NOISE::run()
389 // Purpose :
390 // Special Notes :
391 // Scope : public
392 // Creator : Eric Keiter, SNL
393 // Creation Date : 12/8/2014
394 //-----------------------------------------------------------------------------
396 {
397  return doInit() && doLoopProcess() && doFinish();
398 }
399 
400 //-----------------------------------------------------------------------------
401 // Function : NOISE::init()
402 // Purpose :
403 // Special Notes :
404 // Scope : public
405 // Creator : Eric Keiter, SNL
406 // Creation Date : 12/8/2014
407 //-----------------------------------------------------------------------------
409 {
410  bool bsuccess = true;
411 
413 
414  // Get set to do the operating point.
417 
418  stepNumber = 0;
420 
421  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
423 
424  // set initial guess, if there is one to be set.
425  // this setInitialGuess call is to up an initial guess in the
426  // devices that have them (usually PDE devices). This is different than
427  // the "intializeProblem" call, which sets IC's. (initial conditions are
428  // different than initial guesses.
430 
431  // If available, set initial solution (.IC, .NODESET, etc).
432  // setInputOPFlag(
433  // outputManagerAdapter_.setupInitialConditions(
434  // *analysisManager_.getDataStore()->nextSolutionPtr,
435  // *analysisManager_.getDataStore()->flagSolutionPtr));
436 
439  topology_.getSolutionNodeNameMap(),
442 
443  // Set a constant history for operating point calculation
447 
448  // solving for DC op
455 
457  {
458  Report::UserError() << "Solving for DC operating point failed! Cannot continue NOISE analysis";
459  return false;
460  }
461 
462  // only output DC op if the .op was specified in the netlist
463  // or if this NOISE analysis is called from a .step loop
465  {
467  stepNumber,
474  objectiveVec_,
477  }
478 
479  // This for saving the data from the DC op. different from the above where we are
480  // concerned with generating normal output.
481  // outputManagerAdapter_.outputDCOP(*analysisManager_.getDataStore()->nextSolutionPtr);
483 
485 
486  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
488 
490 
491  return bsuccess;
492 }
493 
494 //-----------------------------------------------------------------------------
495 // Function : NOISE::loopProcess()
496 // Purpose : Conduct the stepping loop.
497 // Special Notes :
498 // Scope : public
499 // Creator : Eric Keiter, SNL
500 // Creation Date : 12/8/2014
501 //-----------------------------------------------------------------------------
503 {
504  analysisManager_.getDataStore()->daeQVectorPtr->putScalar(0.0);
505  analysisManager_.getDataStore()->daeFVectorPtr->putScalar(0.0);
506 
511 
522  );
523 
548 
555 
558 
559 #if 0
560  if (DEBUG_TIME && isActive(Diag::TIME_PARAMETERS))
561  {
562  Xyce::dout() << "dQdxMatrixPtr:" << std::endl;
563  analysisManager_.getDataStore()->dQdxMatrixPtr->printPetraObject( Xyce::dout() );
564 
565  Xyce::dout() << "dFdxMatrixPtr:" << std::endl;
566  analysisManager_.getDataStore()->dFdxMatrixPtr->printPetraObject( Xyce::dout() );
567 
568  Xyce::dout() << std::endl;
569  }
570 #endif
571 
573 
574  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
576 
577  int numNoiseDevices = loader_.getNumNoiseDevices();
578  noiseDataVec_.resize(numNoiseDevices);
579  for (int i=0;i<numNoiseDevices;++i)
580  {
581  noiseDataVec_[i] = new NoiseData();
582  }
583 
585 
586  // clear out the integral arrays
587  for (int i=0;i<numNoiseDevices;++i)
588  {
589  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
590  for (int j=0;j<numNoiseThisDevice;++j)
591  {
592  noiseDataVec_[i]->inputNoiseTotal[j] = 0.0;
593  noiseDataVec_[i]->outputNoiseTotal[j] = 0.0;
594  }
595  }
596 
597  // loop over all the specified frequencies, do an AC solve and a NOISE solve at each.
598  if (useAdjoint_)
599  {
601  }
602 
603  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
604  N_PDS_Comm & comm = *(pds_manager.getPDSComm());
605  int myPID = comm.procID();
606 
607  ///////////////////////////////////////////////////////////////////////////
608  // frequency loop
609  for (int currentStep = 0; currentStep < noiseLoopSize_; ++currentStep)
610  {
611  // solve the AC system, to get up-to-date currents and voltages
612  updateCurrentFreq_(currentStep);
613 
615 
616  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
618 
619  bool stepAttemptStatus;
620  {
621  Stats::StatTop _nonlinearStat("Nonlinear Solve");
622  Stats::TimeBlock _nonlinearTimer(_nonlinearStat);
623 
624  stepAttemptStatus = solveACLinearSystem_();
625  }
626 
627  // save a copy of X_ (the AC solution, already computed), for output purposes, etc.
628  delete saved_AC_X_;
629  saved_AC_X_ = new Linear::BlockVector (*X_);
630 
631  // Compute AC gain.
632  Linear::Vector & Xreal = X_->block( 0 );
633  Linear::Vector & Ximag = X_->block( 1 );
634 
635  double v1r = 0.0;
636  double v1i = 0.0;
637  double v2r = 0.0;
638  double v2i = 0.0;
639 
640  //comm.barrier();
641  int root=-1;
642  if (outputVarGIDs_.size()>0)
643  {
644  if (outputVarGIDs_[0] > -1)
645  {
646  v1r = Xreal.getElementByGlobalIndex(outputVarGIDs_[0]);
647  v1i = Ximag.getElementByGlobalIndex(outputVarGIDs_[0]);
648  root = myPID;
649  }
650  Xyce::Parallel::AllReduce(comm.comm(), MPI_MAX, &root, 1);
651  comm.bcast( &v1r, 1, root );
652  comm.bcast( &v1i, 1, root );
653  }
654 
655  root=-1;
656  if (outputVarGIDs_.size()>1)
657  {
658  if (outputVarGIDs_[1] > -1)
659  {
660  v2r = Xreal.getElementByGlobalIndex(outputVarGIDs_[1]);
661  v2i = Ximag.getElementByGlobalIndex(outputVarGIDs_[1]);
662  root = myPID;
663  }
664  Xyce::Parallel::AllReduce(comm.comm(), MPI_MAX, &root, 1);
665  comm.bcast( &v2r, 1, root );
666  comm.bcast( &v2i, 1, root );
667  }
668  //comm.barrier();
669 
670  double realVal = v1r-v2r;
671  double imagVal = v1i-v2i;
672  GainSqInv_ = 1.0 / std::max(((realVal*realVal) + (imagVal*imagVal)),N_MINGAIN);
673  lnGainInv_ = std::log(GainSqInv_);
674 
675  // save previous (last) lnNoise densities
676  for (int i=0;i<noiseDataVec_.size();++i)
677  {
678  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
679  for (int j=0;j<numNoiseThisDevice;++j)
680  {
681  noiseDataVec_[i]->lastLnNoiseDens[j] = noiseDataVec_[i]->lnNoiseDens[j];
682  }
683  }
684 
685  // do NOISE analysis for this frequency.
686  if (useAdjoint_)
687  {
690  }
691  else// only here as diagnostic, not implemented yet.
692  {
694  }
695 
696  // perform total noise integrals
697  if (currentStep != 0)
698  {
699  for (int i=0;i<noiseDataVec_.size();++i)
700  {
701  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
702  for (int j=0;j<numNoiseThisDevice;++j)
703  {
704  double noizDens = noiseDataVec_[i]->outputNoiseDens[j];
705  double lnDens = noiseDataVec_[i]->lnNoiseDens[j];
706  double lnlastDens = noiseDataVec_[i]->lastLnNoiseDens[j];
707 
708  double tempOutNoise = noiseIntegral( noizDens, lnDens, lnlastDens,
710 
711  double tempInNoise = noiseIntegral(
712  noizDens * GainSqInv_,
713  lnDens + lnGainInv_,
714  lnlastDens + lnGainInv_,
716 
717 
718  noiseDataVec_[i]->outputNoiseTotal[j] += tempOutNoise;
719  noiseDataVec_[i]->inputNoiseTotal[j] += tempInNoise;
720 
721  totalOutputNoise_+=tempOutNoise;
722  totalInputNoise_+=tempInNoise;
723  }
724  }
725  }
726 
727  // process success/failure
728  if (stepAttemptStatus)
729  {
730  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
733  }
734  else // stepAttemptStatus (ie do this if the step FAILED)
735  {
736  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
739  }
740  }
741 
742  //Report::safeBarrier(comm.comm());
743  Xyce::Parallel::AllReduce(comm.comm(), MPI_SUM, &totalOutputNoise_, 1);
744  Xyce::Parallel::AllReduce(comm.comm(), MPI_SUM, &totalInputNoise_, 1);
745 
746  // Outputs to the screen:
747  Xyce::lout() << "Total Output Noise = " << totalOutputNoise_ <<std::endl;
748  Xyce::lout() << "Total Input Noise = " << totalInputNoise_ <<std::endl;
749 
750  static_cast<Xyce::Util::Notifier<AnalysisEvent> &>(analysisManager_).publish
752 
753  return true;
754 }
755 
756 //-----------------------------------------------------------------------------
757 // Function : NOISE::createACLinearSystem_()
758 // Purpose :
759 // Special Notes :
760 // Scope : public
761 // Creator : Eric Keiter, SNL
762 // Creation Date : 12/8/2014
763 //-----------------------------------------------------------------------------
765 {
766  bool bsuccess = true;
767 
768  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
769 
770  RCP<N_PDS_ParMap> baseMap = rcp(pds_manager.getParallelMap( Parallel::SOLUTION ), false);
771  Epetra_CrsGraph &baseFullGraph = *pds_manager.getMatrixGraph(Parallel::JACOBIAN);
772 
773  int numBlocks = 2;
774 
775  RCP<N_PDS_ParMap> blockMap = Linear::createBlockParMap(numBlocks, *baseMap);
776 
777  // Create a block vector
778  delete B_;
779  B_ = new Linear::BlockVector(numBlocks, blockMap, baseMap);
780 
781  // -----------------------------------------------------
782  // Now test block graphs.
783  // -----------------------------------------------------
784 
785  std::vector<std::vector<int> > blockPattern(2);
786  blockPattern[0].resize(2);
787  blockPattern[0][0] = 0; blockPattern[0][1] = 1;
788  blockPattern[1].resize(2);
789  blockPattern[1][0] = 0; blockPattern[1][1] = 1;
790 
791  int offset = Linear::generateOffset( *baseMap );
792 
793  RCP<Epetra_CrsGraph> blockGraph = Linear::createBlockGraph( offset, blockPattern, *blockMap, baseFullGraph);
794 
795  delete ACMatrix_;
796  ACMatrix_ = new Linear::BlockMatrix( numBlocks, offset, blockPattern, *blockGraph, baseFullGraph);
797 
798  // First diagonal block
799  ACMatrix_->put( 0.0 ); // Zero out whole matrix
800  ACMatrix_->block( 0, 0 ).add(*G_);
801 
802  // Second diagonal block
803  ACMatrix_->block( 1, 1 ).add(*G_);
804 
805  B_->putScalar( 0.0 );
806  B_->block( 0 ).addVec( 1.0, *bVecRealPtr);
807  B_->block( 1 ).addVec( 1.0, *bVecImagPtr);
808 
809  Amesos amesosFactory;
810 
811  delete X_;
812  X_ = new Linear::BlockVector (numBlocks, blockMap, baseMap);
813  X_->putScalar( 0.0 );
814 
815  delete saved_AC_X_;
816  saved_AC_X_ = new Linear::BlockVector (numBlocks, blockMap, baseMap);
817  saved_AC_X_->putScalar( 0.0 );
818 
819  delete blockProblem_;
820  blockProblem_ = new Epetra_LinearProblem(&ACMatrix_->epetraObj(), &X_->epetraObj(), &B_->epetraObj() );
821 
822  delete blockSolver_;
823  blockSolver_ = amesosFactory.Create( "Klu", *blockProblem_ );
824 
825  // Need to reindex the linear system because of the noncontiguous block map.
826  Teuchos::ParameterList params;
827  params.set( "Reindex", true );
828  blockSolver_->SetParameters( params );
829 
830 #if 0
831  // Call symbolic factorization without syncronizing the values, since they are not necessary here.
832  int linearStatus = blockSolver_->SymbolicFactorization();
833  if (linearStatus != 0)
834  {
835  Xyce::dout() << "Amesos symbolic factorization exited with error: " << linearStatus;
836  bsuccess = false;
837  }
838 #endif
839 
840  return bsuccess;
841 }
842 
843 //-----------------------------------------------------------------------------
844 // Function : NOISE::resetACLinearSystem_
845 // Purpose :
846 // Special Notes :
847 // Scope : public
848 // Creator : Eric Keiter, SNL
849 // Creation Date : 12/8/2014
850 //-----------------------------------------------------------------------------
852 {
853  double omega = 2.0 * M_PI * currentFreq_;
854 
855  ACMatrix_->block( 0, 1).put( 0.0);
856  ACMatrix_->block( 0, 1).add(*C_);
857  ACMatrix_->block( 0, 1).scale(-omega);
858 
859  ACMatrix_->block(1, 0).put( 0.0);
860  ACMatrix_->block(1, 0).add(*C_);
861  ACMatrix_->block(1, 0).scale(omega);
862 
863  // Copy the values loaded into the blocks into the global matrix for the solve.
864  ACMatrix_->assembleGlobalMatrix();
865 
866  ACMatrix_->setUseTranspose (false);
867  blockSolver_->SetUseTranspose(false);
868 
869  // restore the AC RHS
870  B_->putScalar( 0.0 );
871  B_->block( 0 ).addVec( 1.0, *bVecRealPtr);
872  B_->block( 1 ).addVec( 1.0, *bVecImagPtr);
873 
874  // clear out X_
875  X_->putScalar( 0.0 );
876 
877  return true;
878 }
879 
880 //-----------------------------------------------------------------------------
881 // Function : NOISE::solveACLinearSystem_()
882 // Purpose :
883 // Special Notes :
884 // Scope : public
885 // Creator : Eric Keiter, SNL
886 // Creation Date : 12/8/2014
887 //-----------------------------------------------------------------------------
889 {
890  bool bsuccess = true;
891  // Solve the block problem
892 
893  int linearStatus = blockSolver_->SymbolicFactorization();
894  if (linearStatus != 0)
895  {
896  Xyce::dout() << "Amesos symbolic factorization exited with error: " << linearStatus;
897  bsuccess = false;
898  }
899 
900  linearStatus = blockSolver_->NumericFactorization();
901  if (linearStatus != 0)
902  {
903  Xyce::dout() << "Amesos numeric factorization exited with error: " << linearStatus;
904  bsuccess = false;
905  }
906 
907  linearStatus = blockSolver_->Solve();
908  if (linearStatus != 0)
909  {
910  Xyce::dout() << "Amesos solve exited with error: " << linearStatus;
911  bsuccess = false;
912  }
913 
914  return bsuccess;
915 }
916 
917 
918 //-----------------------------------------------------------------------------
919 // Function : NOISE::processOutputNodes
920 // Purpose : determines the GIDs for the nodes specified in the first argument
921 // of the .NOISE line.
922 // Special Notes :
923 // Scope : public
924 // Creator : Eric Keiter, SNL
925 // Creation Date : 12/15/2014
926 //-----------------------------------------------------------------------------
928 {
929  // setup the names:
930  outputVarNames_.clear();
931  outputVarNames_.push_back(outputNode1_);
932  if (!outputNodeSingle_)
933  {
934  outputVarNames_.push_back(outputNode2_);
935  }
936  int numOutVars = outputVarNames_.size();
937 
938  // set up the gid's:
939  int found(0);
940  int found2(0);
941  bool foundLocal(false);
942  bool foundLocal2(false);
943 
944  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
945  N_PDS_Comm & comm = *(pds_manager.getPDSComm());
946  int myPID = comm.procID();
947 
948  outputVarGIDs_.resize( numOutVars, -1 );
949  for (int iout = 0; iout < numOutVars; ++iout)
950  {
951  std::vector<int> svGIDList1, dummyList;
952  char type1;
953  foundLocal = topology_.getNodeSVarGIDs(NodeID(outputVarNames_[iout], Xyce::_VNODE),
954  svGIDList1, dummyList, type1);
955 
956  found = static_cast<int>(foundLocal);
957  Xyce::Parallel::AllReduce(comm.comm(), MPI_LOR, &found, 1);
958 
959  foundLocal2 = false;
960  if (!found)// if looking for this as a voltage node failed, try a "device" (i.e. current) node.
961  {
962  foundLocal2 = topology_.getNodeSVarGIDs(NodeID(outputVarNames_[iout], Xyce::_DNODE),
963  svGIDList1, dummyList, type1);
964  }
965  found2 = static_cast<int>(foundLocal2);
966  Xyce::Parallel::AllReduce(comm.comm(), MPI_LOR, &found2, 1);
967 
968  if (!found && !found2)
969  {
970  Report::UserError() << "Output function variable " << outputVarNames_[iout] << " not found";
971  }
972 
973  if (found || found2)
974  {
975  int tmpGID=-1;
976  if(svGIDList1.size()==1)
977  {
978  tmpGID = svGIDList1.front();
979  }
980  outputVarGIDs_[iout] = tmpGID;
981  }
982  }
983 }
984 
985 //-----------------------------------------------------------------------------
986 // Function : NOISE::solveDirectNOISE_
987 // Purpose : Solves for NOISE using the direct method.
988 // Special Notes : Not practical, implemented only as a test for adjoint.
989 // Scope : public
990 // Creator : Eric Keiter, SNL
991 // Creation Date : 12/15/2014
992 //-----------------------------------------------------------------------------
994 {
995  bool bsuccess = true;
996  // Solve the block problem
997 
998  // get the number of noise sources
999  // int numSources = loader_.getNumNoiseSources();
1000  // for (int isource=0;isource<numSources;++isources)
1001  // {
1002  // // need different BVector and linear solve set up for each noise source
1003  //
1004  // // substitute the noise Bvector into the linear system object
1005  //
1006  // // solve linear problem for dX/dNoise
1007  //
1008  // // perform matvec to get this dOutput/dNoise for this noise source
1009  // }
1010 
1011 
1012  return bsuccess;
1013 }
1014 
1015 //-----------------------------------------------------------------------------
1016 // Function : NOISE::setupAdjointRHS_
1017 // Purpose : Sets up stuff that only needs to be set up once,
1018 // but is unique to the adjoint solve.
1019 // (i.e. is not used by the direct form)
1020 // Special Notes :
1021 // Scope : public
1022 // Creator : Eric Keiter, SNL
1023 // Creation Date : 12/15/2014
1024 //-----------------------------------------------------------------------------
1026 {
1027  // set up the RHS vector of 1's and 0's vector to represent dOutput/dX.
1028  // If thinking of this as the input to the adjoint circuit problem
1029  // (or adjoint operator) this can also be thought of as current sources to
1030  // the adjoint circuit.
1031  //
1032  // For the adjoint problem
1033  // assume that the phase is zero (as this is essentially the input to the
1034  // adjoint operator) and just set 1's on the real part of the block vector.
1035  // For this purpose re-use the B_ vector from the AC problem.
1036 
1037  // replace RHS in linear system. Assume that the phase is zero, so no
1038  // imaginary contribution.
1039 
1040  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
1041  N_PDS_Comm & comm = *(pds_manager.getPDSComm());
1042  int myPID = comm.procID();
1043 
1044 
1045  bNoiseVecRealPtr->putScalar(0.0);
1046  bNoiseVecImagPtr->putScalar(0.0);
1047 
1048  int numOutVars = outputVarNames_.size();
1049  for (int iout=0;iout<numOutVars;++iout)
1050  {
1051  int tmpGID=outputVarGIDs_[iout];
1052  if (tmpGID > -1)
1053  {
1054  double val=1.0;
1055  if (iout>0) val=-1.0;
1056  bNoiseVecRealPtr->setElementByGlobalIndex( tmpGID, val, 0);
1057  }
1058  }
1059  bNoiseVecRealPtr->fillComplete();
1060 }
1061 
1062 //-----------------------------------------------------------------------------
1063 // Function : NOISE::resetAdjointNOISELinearSystem_
1064 // Purpose :
1065 // Special Notes :
1066 // Scope : public
1067 // Creator : Eric Keiter, SNL
1068 // Creation Date : 12/15/2014
1069 //-----------------------------------------------------------------------------
1071 {
1072  // clear out the X_ vector used by the linear solver.
1073  X_->putScalar(0.0);
1074 
1075 
1076  // setup the B_ vector RHS for the adjoint solve:
1077  B_->putScalar( 0.0 );
1078  B_->block( 0 ).addVec( 1.0, *bNoiseVecRealPtr);
1079  B_->block( 1 ).addVec( 1.0, *bNoiseVecImagPtr);
1080 
1081 #if 0
1082  //-------------------------------------------
1083  Xyce::dout()<<"adjoint noise B vector:"<<std::endl;
1084  B_->printPetraObject(Xyce::dout());
1085  //-------------------------------------------
1086 #endif
1087 
1088  // solve transpose (adjoint) system to obtain dOutput/dF. If thinking of this
1089  // as the adjoint circuit problem (or adjoint operator) this can also be
1090  // thought of as the adjoint voltages, or more precisely a transImpedance (gain).
1091 
1092  ACMatrix_->setUseTranspose (true);
1093  blockSolver_->SetUseTranspose(true);
1094 
1095 #if 0
1096  //-------------------------------------------
1097  Xyce::dout()<<"matrix:"<<std::endl;
1098  ACMatrix_->printPetraObject(Xyce::dout());
1099  //-------------------------------------------
1100 #endif
1101 }
1102 
1103 //-----------------------------------------------------------------------------
1104 // Function : NOISE::solveAdjointNOISE_
1105 // Purpose : Solves for NOISE using the adjoint method.
1106 // Special Notes : This is the production solve.
1107 // Scope : public
1108 // Creator : Eric Keiter, SNL
1109 // Creation Date : 12/15/2014
1110 //-----------------------------------------------------------------------------
1112 {
1113  bool bsuccess = true;
1114 
1115  // do the solve of the tranpose system to get dOutput/dF
1116  int linearStatus = blockSolver_->SymbolicFactorization();
1117  if (linearStatus != 0)
1118  {
1119  Xyce::dout() << "Amesos symbolic factorization exited with error: " << linearStatus;
1120  bsuccess = false;
1121  }
1122 
1123  linearStatus = blockSolver_->NumericFactorization();
1124  if (linearStatus != 0)
1125  {
1126  Xyce::dout() << "Amesos numeric factorization exited with error: " << linearStatus;
1127  bsuccess = false;
1128  }
1129 
1130  linearStatus = blockSolver_->Solve();
1131  if (linearStatus != 0)
1132  {
1133  Xyce::dout() << "Amesos solve exited with error: " << linearStatus;
1134  bsuccess = false;
1135  }
1136 
1137  double omega = 2.0 * M_PI * currentFreq_;
1138 
1139  int numNoiseDevices = noiseDataVec_.size();
1140  for (int i=0;i<numNoiseDevices;++i)
1141  {
1142  (noiseDataVec_[i])->omega = omega;
1143  (noiseDataVec_[i])->freq = currentFreq_;
1144  }
1145 
1147 
1148  std::vector< Teuchos::RCP<Linear::Vector> > outputVectors;
1149  outputVectors.push_back( rcp(linearSystem_.builder().createVector()) );
1150  outputVectors.push_back( rcp(linearSystem_.builder().createVector()) );
1151 
1152  copyFromBlockVector( *X_, outputVectors );
1153  Linear::Vector & Xreal = *(outputVectors[0]);
1154  Linear::Vector & Ximag = *(outputVectors[1]);
1155 
1156 #if 0
1157  std::cout << "Xreal: ------------------------------------"<<std::endl;
1158  Xreal.printPetraObject( Xyce::dout() );
1159  std::cout << "Ximag: ------------------------------------"<<std::endl;
1160  Ximag.printPetraObject( Xyce::dout() );
1161 #endif
1162 
1163  N_PDS_Manager &pds_manager = *analysisManager_.getPDSManager();
1164  N_PDS_Comm & comm = *(pds_manager.getPDSComm());
1165  int myPID = comm.procID();
1166 
1167  totalOutputNoiseDens_ = 0.0;
1168  totalInputNoiseDens_ = 0.0;
1169  for (int i=0;i<numNoiseDevices;++i)
1170  {
1171  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
1172 
1173  noiseDataVec_[i]->totalNoise = 0.0;
1174  noiseDataVec_[i]->totalOutputNoise = 0.0;
1175  for (int j=0;j<numNoiseThisDevice;++j)
1176  {
1177  int li_Pos = noiseDataVec_[i]->li_Pos[j];
1178  int li_Neg = noiseDataVec_[i]->li_Neg[j];
1179 
1180  double realVal = Xreal[li_Pos] - Xreal[li_Neg];
1181  double imagVal = Ximag[li_Pos] - Ximag[li_Neg];
1182  double gain = (realVal*realVal) + (imagVal*imagVal);
1183 
1184  noiseDataVec_[i]->totalNoise += noiseDataVec_[i]->noiseDens[j];
1185 
1186  noiseDataVec_[i]->outputNoiseDens[j] = gain * noiseDataVec_[i]->noiseDens[j];
1187 #if 0
1188  std::string namestring = noiseDataVec_[i]->noiseNames[j];
1189  std::cout << std::left << "noise: " << std::setw(20)<< namestring <<std::right << ":";
1190  std::cout.setf(std::ios::scientific);
1191  std::cout << " li_Pos="<<li_Pos<<" li_Neg="<<li_Neg
1192  << " gain="<<gain<< " noiseDens="<<noiseDataVec_[i]->noiseDens[j]
1193  << " onoise="<<noiseDataVec_[i]->outputNoiseDens[j] <<std::endl;
1194 #endif
1195 
1196  noiseDataVec_[i]->lnNoiseDens[j] = std::log(std::max( noiseDataVec_[i]->outputNoiseDens[j],N_MINLOG) );
1197 
1198  noiseDataVec_[i]->inputNoiseDens[j] = noiseDataVec_[i]->outputNoiseDens[j] * GainSqInv_;
1199 
1200  noiseDataVec_[i]->totalOutputNoise += noiseDataVec_[i]->outputNoiseDens[j];
1201  }
1202 #if 0
1203  std::cout << std::endl;
1204 #endif
1205  noiseDataVec_[i]->totalInputNoise = noiseDataVec_[i]->totalOutputNoise * GainSqInv_;
1206 
1207  totalOutputNoiseDens_ += noiseDataVec_[i]->totalOutputNoise;
1208  }
1209  Xyce::Parallel::AllReduce(comm.comm(), MPI_SUM, &totalOutputNoiseDens_, 1);
1210  totalInputNoiseDens_ += totalOutputNoiseDens_ * GainSqInv_;
1211 
1212  if (comm.isSerial() )
1213  {
1214  // FIX: replace this output call!
1216  }
1217 
1218  return bsuccess;
1219 }
1220 
1221 
1222 //-----------------------------------------------------------------------------
1223 // Function : NOISE::hackTecplotOutput
1224 // Purpose : provides an output function until I setup the output
1225 // manager properly for NOISE.
1226 // Author : Eric Keiter
1227 // Date : 1/5/2015
1228 //-----------------------------------------------------------------------------
1230 {
1231  int numNoiseDevices = noiseDataVec_.size();
1232  std::string fileName = analysisManager_.getNetlistFilename() + "_noise.dat";
1233 
1234  std::ofstream output_stream(fileName.c_str(),
1235  !hackOutputCalledBefore_ ? std::ios_base::out : std::ios_base::app);
1236 
1238  {
1239  // header output
1240  output_stream << "TITLE=\"noise output\"\tVARIABLES=\"frequency\" "<<std::endl;
1241  output_stream << "\t\"Re(V(" << outputNode1_ << "))\""<<std::endl;
1242  output_stream << "\t\"Im(V(" << outputNode1_ << "))\""<<std::endl;
1243 
1244  if(!outputNodeSingle_)
1245  {
1246  output_stream << "\t\"Re(V(" << outputNode2_ << "))\""<<std::endl;
1247  output_stream << "\t\"Im(V(" << outputNode2_ << "))\""<<std::endl;
1248  }
1249  output_stream << "\t\"onoise_spectrum \""<<std::endl;
1250  output_stream << "\t\"inoise_spectrum \""<<std::endl;
1251 
1252  if(pts_per_summary_>0)
1253  {
1254  for (int i=0;i<numNoiseDevices;++i)
1255  {
1256  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
1257  for (int j=0;j<numNoiseThisDevice;++j)
1258  {
1259  std::string namestring = noiseDataVec_[i]->noiseNames[j];
1260  std::transform(namestring.begin(), namestring.end(), namestring.begin(), ::tolower);
1261  output_stream << "\t\"" << namestring << "\"";
1262  }
1263 
1264  // spice doesn't output input noise for individual devices, so exclude.
1265  if (numNoiseThisDevice > 1)
1266  {
1267  std::string totalOutputNoiseName = "onoise_" + noiseDataVec_[i]->deviceName;
1268 
1269  std::transform(totalOutputNoiseName.begin(), totalOutputNoiseName.end(), totalOutputNoiseName.begin(), ::tolower);
1270 
1271  output_stream << "\t\""<<totalOutputNoiseName<<"\"";
1272  }
1273  }
1274  }
1275 
1276  output_stream << std::endl;
1277  output_stream << "ZONE F=POINT T=\"Xyce data\""<<std::endl;
1278  hackOutputCalledBefore_ = true;
1279  }
1280 
1281  // data output
1282  output_stream.setf(std::ios::scientific);
1283 
1284  // output the AC solution for the output node(s) (for double checking)
1285  Linear::Vector & Xreal = saved_AC_X_->block( 0 );
1286  Linear::Vector & Ximag = saved_AC_X_->block( 1 );
1287  double v1r = Xreal.getElementByGlobalIndex(outputVarGIDs_[0]);
1288  double v1i = Ximag.getElementByGlobalIndex(outputVarGIDs_[0]);
1289 
1290  output_stream << currentFreq_ << "\t" << v1r << "\t" << v1i;
1291 
1292  if(!outputNodeSingle_)
1293  {
1294  double v2r = 0.0;
1295  double v2i = 0.0;
1296  v2r = Xreal.getElementByGlobalIndex(outputVarGIDs_[1]);
1297  v2i = Ximag.getElementByGlobalIndex(outputVarGIDs_[1]);
1298  output_stream << "\t" << v2r << "\t" << v2i;
1299  }
1300 
1301  output_stream << "\t" << totalOutputNoiseDens_ << "\t" << totalInputNoiseDens_;
1302 
1303  if(pts_per_summary_>0)
1304  {
1305  for (int i=0;i<numNoiseDevices;++i)
1306  {
1307  int numNoiseThisDevice = noiseDataVec_[i]->numSources;
1308  for (int j=0;j<numNoiseThisDevice;++j)
1309  {
1310  output_stream << "\t" << noiseDataVec_[i]->outputNoiseDens[j];
1311  }
1312 
1313  if (numNoiseThisDevice > 1)
1314  {
1315  output_stream << "\t" << noiseDataVec_[i]->totalOutputNoise;
1316  }
1317  //output_stream << std::endl;
1318  }
1319  }
1320  output_stream << std::endl;
1321 }
1322 
1323 //-----------------------------------------------------------------------------
1324 // Function : NOISE::noiseIntegral
1325 // Purpose : based on the spice3 function: Nintegrate.
1326 // This subroutine evaluates the integral of the function
1327 //
1328 // EXPONENT
1329 // NOISE = a * (FREQUENCY)
1330 //
1331 // given two points from the curve. If EXPONENT is relatively close
1332 // to 0, the noise is simply multiplied by the change in frequency.
1333 // If it isn't, a more complicated expression must be used. Note that
1334 // EXPONENT = -1 gives a different equation than EXPONENT <> -1.
1335 // Hence, the reason for the constant 'N_INTUSELOG'.
1336 //
1337 // Special Notes :
1338 // Scope : public
1339 // Creator : Eric Keiter, SNL
1340 // Creation Date : 12/8/2014
1341 //-----------------------------------------------------------------------------
1342 double NOISE::noiseIntegral(double noizDens, double lnNdens, double lnNlstDens,
1343  double delLnFreq, double delFreq, double lnFreq, double lnLastFreq)
1344 {
1345  double exponent;
1346  double a;
1347 
1348  exponent = (lnNdens - lnNlstDens) / delLnFreq;
1349  if ( fabs(exponent) < N_INTFTHRESH )
1350  {
1351  return (noizDens * delFreq);
1352  } else
1353  {
1354  a = std::exp(lnNdens - exponent*lnFreq);
1355  exponent += 1.0;
1356  if (fabs(exponent) < N_INTUSELOG)
1357  {
1358  return (a * (lnFreq - lnLastFreq));
1359  }
1360  else
1361  {
1362  return (a * ((std::exp(exponent * lnFreq) - std::exp(exponent * lnLastFreq)) /
1363  exponent));
1364  }
1365  }
1366 }
1367 
1368 //-----------------------------------------------------------------------------
1369 // Function : NOISE::processSuccessfulStep()
1370 // Purpose :
1371 // Special Notes :
1372 // Scope : public
1373 // Creator : Eric Keiter, SNL
1374 // Creation Date : 12/8/2014
1375 //-----------------------------------------------------------------------------
1377 {
1378  bool bsuccess = true;
1379 
1380  // FIX OUTPUT
1382 
1385 
1386  if ( !firstDoubleDCOPStep() )
1387  {
1388  stepNumber += 1;
1391  }
1392 
1393  // This output call is for device-specific output (like from a PDE device,
1394  // outputting mesh-based tecplot files). It will only work in parallel if on
1395  // a machine where all processors have I/O capability.
1397 
1398  return bsuccess;
1399 }
1400 
1401 //-----------------------------------------------------------------------------
1402 // Function : NOISE::processFailedStep
1403 // Purpose :
1404 // Special Notes :
1405 // Scope : public
1406 // Creator : Eric Keiter, SNL
1407 // Creation Date : 12/8/2014
1408 //-----------------------------------------------------------------------------
1410 {
1411  bool bsuccess = true;
1412 
1413  stepNumber += 1;
1414  noiseSweepFailures_.push_back(stepNumber);
1417 
1418  return bsuccess;
1419 }
1420 
1421 //-----------------------------------------------------------------------------
1422 // Function : NOISE::finish
1423 // Purpose :
1424 // Special Notes :
1425 // Scope : public
1426 // Creator : Eric Keiter, SNL
1427 // Creation Date : 12/8/2014
1428 //-----------------------------------------------------------------------------
1430 {
1431  bool bsuccess = true;
1432 
1433  if (DEBUG_ANALYSIS)
1434  {
1435  Xyce::dout() << "Calling NOISE::doFinish() outputs!" << std::endl;
1436  }
1437 
1438  // FIX OUTPUT
1440 
1441  if (!(noiseSweepFailures_.empty()))
1442  {
1443  bsuccess = false;
1444  }
1445 
1446  return bsuccess;
1447 }
1448 
1449 
1450 //-----------------------------------------------------------------------------
1451 // Function : NOISE::doHandlePredictor
1452 // Purpose :
1453 // Special Notes :
1454 // Scope : private
1455 // Creator : Eric Keiter, SNL
1456 // Creation Date : 12/8/2014
1457 //-----------------------------------------------------------------------------
1459 {
1463 
1464  // In case this is the upper level of a 2-level sim, tell the
1465  // inner solve to do its prediction:
1466  bool beginIntegrationFlag = analysisManager_.getBeginningIntegrationFlag(); // system_state.beginIntegrationFlag;
1467  double nextTimeStep = analysisManager_.getStepErrorControl().currentTimeStep; // system_state.nextTimeStep;
1468  double nextTime = analysisManager_.getStepErrorControl().nextTime; // system_state.nextTime;
1469  int currentOrder = analysisManager_.getWorkingIntegrationMethod().getOrder(); // system_state.currentOrder;
1470 
1471  loader_.startTimeStep(beginIntegrationFlag, nextTimeStep, nextTime, currentOrder);
1472 
1473  return true;
1474 }
1475 
1476 //-----------------------------------------------------------------------------
1477 // Function : NOISE::updateCurrentFreq_(int stepNumber )
1478 // Purpose :
1479 // Special Notes : Used for NOISE analysis classes.
1480 // Scope : public
1481 // Creator : Eric Keiter, SNL.
1482 // Creation Date : 12/8/2014
1483 //-----------------------------------------------------------------------------
1484 bool NOISE::updateCurrentFreq_(int stepNumber)
1485 {
1487  if (type_ == "LIN")
1488  {
1489 
1490  currentFreq_ = fStart_ + static_cast<double>(stepNumber)*fstep_;
1491  }
1492  else if(type_ == "DEC" || type_ == "OCT")
1493  {
1494 
1495  currentFreq_ = fStart_*pow(stepMult_, static_cast<double>(stepNumber) );
1496  }
1497  else
1498  {
1499  Report::DevelFatal().in("NOISE::updateCurrentFreq_")
1500  << "NOISE::updateCurrentFreq_: unsupported STEP type";
1501  }
1502 
1504 
1505  lnFreq_ = std::log(std::max(currentFreq_,N_MINLOG));
1506  lnLastFreq_ = std::log(std::max(lastFreq_,N_MINLOG));
1508 
1509  return true;
1510 }
1511 
1512 //-----------------------------------------------------------------------------
1513 // Function : NOISE::setupSweepParam_
1514 // Purpose : Processes sweep parameters.
1515 // Special Notes : Used for NOISE analysis classes.
1516 // Scope : public
1517 // Creator : Eric Keiter, SNL.
1518 // Creation Date : 12/8/2014
1519 //-----------------------------------------------------------------------------
1521 {
1522  double fstart, fstop;
1523  double fcount = 0.0;
1524 
1525  fstart = fStart_;
1526  fstop = fStop_;
1527 
1528  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
1529  {
1530  Xyce::dout() << std::endl << std::endl;
1531  Xyce::dout() << section_divider << std::endl;
1532  Xyce::dout() << "NOISE::setupSweepParam_" << std::endl;
1533  }
1534 
1535  if (type_ == "LIN")
1536  {
1537  int np = static_cast<int>(np_);
1538 
1539  if ( np == 1)
1540  fstep_ = 0;
1541  else
1542  fstep_ = (fstop - fstart)/(np_ - 1.0);
1543 
1544  fcount = np_;
1545  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
1546  {
1547  Xyce::dout() << "fstep = " << fstep_ << std::endl;
1548  }
1549  }
1550  else if (type_ == "DEC")
1551  {
1552  stepMult_ = std::pow(10.0, 1.0/np_);
1553  fcount = floor(fabs(std::log10(fstart) - std::log10(fstop)) * np_ + 1.0);
1554  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
1555  {
1556  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
1557  }
1558  }
1559  else if (type_ == "OCT")
1560  {
1561  stepMult_ = std::pow(2.0, 1.0/np_);
1562 
1563  // changed to remove dependence on "log2" function, which apparently
1564  // doesn't exist in the math libraries of FreeBSD or the mingw
1565  // cross-compilation suite. Log_2(x)=log_e(x)/log_e(2.0)
1566  double ln2 = std::log(2.0);
1567  fcount = floor(fabs(std::log(fstart) - std::log(fstop))/ln2 * np_ + 1.0);
1568  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
1569  {
1570  Xyce::dout() << "stepMult_ = " << stepMult_ << std::endl;
1571  }
1572  }
1573  else
1574  {
1575  Report::DevelFatal().in("NOISE::setupSweepParam") << "Unsupported type";
1576  }
1577 
1578  // At this point, pinterval equals the total number of steps
1579  // for the step loop.
1580  return static_cast<int> (fcount);
1581 }
1582 
1583 namespace {
1584 
1585 typedef Util::Factory<AnalysisBase, NOISE> NOISEFactoryBase;
1586 
1587 //-----------------------------------------------------------------------------
1588 // Class : NOISEFactory
1589 // Purpose :
1590 // Special Notes :
1591 // Scope : public
1592 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1593 // Creation Date : Thu Jan 29 12:53:02 2015
1594 //-----------------------------------------------------------------------------
1595 ///
1596 /// Factory for parsing NOISE parameters from the netlist and creating NOISE analysis.
1597 ///
1598 class NOISEFactory : public NOISEFactoryBase
1599 {
1600 public:
1601  //-----------------------------------------------------------------------------
1602  // Function : NOISEFactory
1603  // Purpose :
1604  // Special Notes :
1605  // Scope : public
1606  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1607  // Creation Date : Thu Jan 29 12:54:09 2015
1608  //-----------------------------------------------------------------------------
1609  ///
1610  /// Constructs the NOISE analysis factory
1611  ///
1612  /// @invariant Stores the results of parsing, so if more than one of the analysis and
1613  /// associated lines are parsed, the second options simply overwrite the previously parsed
1614  /// values.
1615  ///
1616  /// @invariant The existence of the parameters specified in the constructor cannot
1617  /// change.
1618  ///
1619  /// @param analysis_manager
1620  /// @param linear_system
1621  /// @param nonlinear_manager
1622  /// @param topology
1623  ///
1624  NOISEFactory(
1625  Analysis::AnalysisManager & analysis_manager,
1626  Linear::System & linear_system,
1627  Nonlinear::Manager & nonlinear_manager,
1628  Loader::Loader & loader,
1629  Topo::Topology & topology,
1630  IO::InitialConditionsManager & initial_conditions_manager)
1631  : NOISEFactoryBase(),
1632  analysisManager_(analysis_manager),
1633  linearSystem_(linear_system),
1634  nonlinearManager_(nonlinear_manager),
1635  loader_(loader),
1636  topology_(topology),
1637  initialConditionsManager_(initial_conditions_manager)
1638  {}
1639 
1640  virtual ~NOISEFactory()
1641  {}
1642 
1643  //-----------------------------------------------------------------------------
1644  // Function : create
1645  // Purpose :
1646  // Special Notes :
1647  // Scope : public
1648  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1649  // Creation Date : Thu Jan 29 12:59:00 2015
1650  //-----------------------------------------------------------------------------
1651  ///
1652  /// Create a new NOISE analysis and applies the analysis and time integrator option blocks.
1653  ///
1654  /// @return new NOISE analysis object
1655  ///
1656  NOISE *create() const
1657  {
1658  analysisManager_.setAnalysisMode(ANP_MODE_NOISE);
1660  noise->setAnalysisParams(noiseAnalysisOptionBlock_);
1661  noise->setTimeIntegratorOptions(timeIntegratorOptionBlock_);
1662 
1663  return noise;
1664  }
1665 
1666  //-----------------------------------------------------------------------------
1667  // Function : setNOISEAnalysisOptionBlock
1668  // Purpose :
1669  // Special Notes :
1670  // Scope : public
1671  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1672  // Creation Date : Thu Jan 29 13:00:14 2015
1673  //-----------------------------------------------------------------------------
1674  ///
1675  /// Saves the analysis parsed options block in the factory.
1676  ///
1677  /// @invariant Overwrites any previously specified analysis option block.
1678  ///
1679  /// @param option_block parsed option block
1680  ///
1681  void setNOISEAnalysisOptionBlock(const Util::OptionBlock &option_block)
1682  {
1683  noiseAnalysisOptionBlock_ = option_block;
1684  }
1685 
1686  //-----------------------------------------------------------------------------
1687  // Function : setTimeIntegratorOptionBlock
1688  // Purpose :
1689  // Special Notes :
1690  // Scope : public
1691  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
1692  // Creation Date : Thu Jan 29 13:01:27 2015
1693  //-----------------------------------------------------------------------------
1694  ///
1695  /// Saves the time integrator parsed option block.
1696  ///
1697  /// @invariant Overwrites any previously specified time integrator option block.
1698  ///
1699  /// @param option_block parsed option block
1700  ///
1701  bool setTimeIntegratorOptionBlock(const Util::OptionBlock &option_block)
1702  {
1703  timeIntegratorOptionBlock_ = option_block;
1704 
1705  return true;
1706  }
1707 
1708 public:
1709  AnalysisManager & analysisManager_;
1710  Linear::System & linearSystem_;
1711  Nonlinear::Manager & nonlinearManager_;
1712  Loader::Loader & loader_;
1713  Topo::Topology & topology_;
1714  IO::InitialConditionsManager & initialConditionsManager_;
1715 
1716 private:
1717  Util::OptionBlock noiseAnalysisOptionBlock_;
1718  Util::OptionBlock timeIntegratorOptionBlock_;
1719 };
1720 
1721 // .NOISE
1722 struct NOISEAnalysisReg : public IO::PkgOptionsReg
1723 {
1724  NOISEAnalysisReg(
1725  NOISEFactory & factory )
1726  : factory_(factory)
1727  {}
1728 
1729  bool operator()(const Util::OptionBlock &option_block)
1730  {
1731  factory_.setNOISEAnalysisOptionBlock(option_block);
1732 
1733  factory_.analysisManager_.addAnalysis(&factory_);
1734 
1735  return true;
1736  }
1737 
1738  NOISEFactory & factory_;
1739 };
1740 
1741 //-----------------------------------------------------------------------------
1742 // Function : extractNOISEData
1743 // Purpose : Extract the parameters from a netlist .NOISE line held in
1744 // parsed_line.
1745 // Special Notes : noise specification:
1746 //
1747 // .noise v(output <,ref>) src ( dec | lin | oct ) pts fstart fstop + <pts_per_summary>
1748 //
1749 // for now ignoring the optional points per summary
1750 //
1751 // Scope : public
1752 // Creator : Eric R. Keiter
1753 // Creation Date : 12/8/2014
1754 //-----------------------------------------------------------------------------
1755 bool
1756 extractNOISEData(
1757  IO::PkgOptionsMgr & options_manager,
1758  IO::CircuitBlock & circuit_block,
1759  const std::string & netlist_filename,
1760  const IO::TokenVector & parsed_line)
1761 {
1762  Util::OptionBlock option_block("NOISE", Util::OptionBlock::NO_EXPRESSIONS, netlist_filename, parsed_line[0].lineNumber_);
1763 
1764  int numFields = parsed_line.size();
1765 
1766  // Check that the minimum required number of fields are on the line.
1767  if (numFields < 10)
1768  {
1769  Report::UserError0().at(netlist_filename, parsed_line[0].lineNumber_)
1770  << ".NOISE line has an unexpected number of fields. NumFields = " << numFields;
1771  return false;
1772  }
1773 
1774  int linePosition = 1; // Start of parameters on .param line.
1775 
1776  Util::Param parameter("", "");
1777 
1778  // output node(s):
1779  ExtendedString stringVal("");
1780  std::ostringstream msg;
1781  int p_err=0;
1782  if( parsed_line[linePosition].string_ == "V" || parsed_line[linePosition].string_ == "v")
1783  {
1784  if( parsed_line[linePosition+3].string_ == ")" )
1785  {
1786  stringVal = parsed_line[linePosition].string_;
1787  stringVal.toUpper();
1788  parameter.setTag(stringVal);
1789  parameter.setVal( 1.0 );
1790  option_block.addParam( parameter );
1791 
1792  stringVal = parsed_line[linePosition+2].string_;
1793  stringVal.toUpper();
1794  parameter.setTag( stringVal );
1795  parameter.setVal( 0.0 );
1796  option_block.addParam( parameter );
1797 
1798  linePosition += 4;
1799  }
1800  else if( parsed_line[linePosition+5].string_ == ")" )
1801  {
1802  stringVal = parsed_line[linePosition].string_;
1803  stringVal.toUpper();
1804  parameter.setTag(stringVal);
1805  parameter.setVal( 2.0 );
1806  option_block.addParam( parameter );
1807 
1808  stringVal = parsed_line[linePosition+2].string_;
1809  stringVal.toUpper();
1810  parameter.setTag( stringVal );
1811  parameter.setVal( 0.0 );
1812  option_block.addParam( parameter );
1813 
1814  stringVal = parsed_line[linePosition+4].string_;
1815  stringVal.toUpper();
1816  parameter.setTag( stringVal );
1817  parameter.setVal( 0.0 );
1818  option_block.addParam( parameter );
1819 
1820  linePosition += 6;
1821  }
1822  else
1823  {
1824  msg << "Unrecognized parenthetical specification for NOISE output ";
1825  p_err = linePosition;
1826  }
1827  }
1828  else
1829  {
1830  msg << "Incorrect format for NOISE output.";
1831  p_err = linePosition;
1832  }
1833 
1834  // source is required
1835  stringVal = parsed_line[linePosition].string_;
1836  stringVal.toUpper();
1837  parameter.setTag( "SOURCE" );
1838  parameter.setVal(std::string(stringVal));
1839  option_block.addParam( parameter );
1840 #if 0
1841  std::cout << "Source is at linePosition="<<linePosition<<" source="<<stringVal<<std::endl;
1842 #endif
1843  ++linePosition; // Advance to next parameter.
1844 
1845  // type is required
1846  stringVal = parsed_line[linePosition].string_;
1847  stringVal.toUpper();
1848  parameter.setTag( "TYPE" );
1849  parameter.setVal(std::string(stringVal));
1850  option_block.addParam( parameter );
1851 #if 0
1852  std::cout << "Type is at linePosition="<<linePosition<<" type="<<stringVal<<std::endl;
1853 #endif
1854  ++linePosition; // Advance to next parameter.
1855 
1856  // np is required
1857  parameter.setTag( "NP" );
1858  parameter.setVal( parsed_line[linePosition].string_ );
1859  option_block.addParam( parameter );
1860 #if 0
1861  std::cout << "NP is at linePosition="<<linePosition<<" np="
1862  << parsed_line[linePosition].string_ <<std::endl;
1863 #endif
1864  ++linePosition; // Advance to next parameter.
1865 
1866  // fstart is required
1867  parameter.setTag( "FSTART" );
1868  parameter.setVal( parsed_line[linePosition].string_ );
1869  option_block.addParam( parameter );
1870 #if 0
1871  std::cout << "fstart is at linePosition="<<linePosition<<" fstart="
1872  << parsed_line[linePosition].string_ <<std::endl;
1873 #endif
1874  ++linePosition; // Advance to next parameter.
1875 
1876 
1877  // fstop is required
1878  parameter.setTag( "FSTOP" );
1879  parameter.setVal( parsed_line[linePosition].string_ );
1880  option_block.addParam( parameter );
1881 #if 0
1882  std::cout << "fstop is at linePosition="<<linePosition<<" fstop="
1883  << parsed_line[linePosition].string_ <<std::endl;
1884 #endif
1885 
1886  // pts_per_summary is optional. If value is negative, assume it wasn't set.
1887  parameter.setTag( "PTS_PER_SUMMARY" );
1888  if (numFields >= 11)
1889  {
1890  ++linePosition; // Advance to next parameter.
1891 
1892  parameter.setVal( parsed_line[linePosition].string_ );
1893 
1894 #if 0
1895  std::cout << "pts_per_summary is at linePosition="<<linePosition<<" pts_per_summary="
1896  << parsed_line[linePosition].string_ <<std::endl;
1897 #endif
1898  }
1899  else
1900  {
1901  parameter.setVal( std::string("-1") );
1902 #if 0
1903  std::cout << "pts_per_summary was not specified. It is set to: pts_per_summary=-1" <<std::endl;
1904 #endif
1905  }
1906  option_block.addParam( parameter );
1907 
1908  circuit_block.addOptions(option_block);
1909 
1910  return true;
1911 }
1912 
1913 } // namespace <unnamed>
1914 
1915 //-----------------------------------------------------------------------------
1916 // Function : NOISEFactory::registerFactory
1917 // Purpose :
1918 //-----------------------------------------------------------------------------
1919 bool
1921  FactoryBlock & factory_block)
1922 {
1923  NOISEFactory *factory = new NOISEFactory(factory_block.analysisManager_, factory_block.linearSystem_, factory_block.nonlinearManager_, factory_block.loader_, factory_block.topology_, factory_block.initialConditionsManager_);
1924 
1925  addAnalysisFactory(factory_block, factory);
1926 
1927  factory_block.optionsManager_.addCommandParser(".NOISE", extractNOISEData);
1928 
1929  factory_block.optionsManager_.addCommandProcessor("NOISE", new NOISEAnalysisReg(*factory));
1930 
1931  factory_block.optionsManager_.addOptionsProcessor("TIMEINT", IO::createRegistrationOptions<NOISEFactory>(*factory, &NOISEFactory::setTimeIntegratorOptionBlock));
1932 
1933  return true;
1934 }
1935 
1936 } // namespace Analysis
1937 } // namespace Xyce
Util::OptionBlock noiseAnalysisOptionBlock_
Definition: N_ANP_NOISE.C:1717
Linear::Vector * lastSolutionPtr
unsigned int successfulStepsTaken_
Number of consecutive successful time-integration steps.
std::vector< double > dOdpVec_
Definition: N_ANP_NOISE.h:216
Linear::Matrix * G_
Definition: N_ANP_NOISE.h:201
virtual bool setInitialGuess(Linear::Vector *solVectorPtr)
Definition: N_LOA_Loader.h:232
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_NOISE.h:149
Linear::Vector * lastLeadDeltaVPtr
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_NOISE.C:1711
std::vector< double > scaled_dOdpAdjVec_
Definition: N_ANP_NOISE.h:219
bool setTimeIntegratorOption(const Util::Param &param)
TimeIntg::TIAParams tiaParams_
Definition: N_ANP_NOISE.h:153
Linear::System & linearSystem_
Definition: N_ANP_NOISE.C:1710
void outputAC(double freq, const Linear::Vector &solnVecRealPtr, const Linear::Vector &solnVecImaginaryPtr)
void evaluateStepError(const Loader::Loader &loader, const TIAParams &tia_params)
Pure virtual class to augment a linear system.
#define N_INTUSELOG
Definition: N_ANP_NOISE.C:117
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:122
virtual bool outputPlotFiles() const
Definition: N_LOA_Loader.h:261
virtual int getNumNoiseDevices()
Definition: N_LOA_Loader.h:215
unsigned int stepNumber
Time-integration step number counter.
virtual bool loadBVectorsforAC(Linear::Vector *bVecRealPtr, Linear::Vector *bVecImagPtr)
Definition: N_LOA_Loader.h:203
Linear::Vector * bNoiseVecImagPtr
Definition: N_ANP_NOISE.h:161
Linear::Vector * currStorePtr
Linear::Vector * lastStatePtr
Epetra_LinearProblem * blockProblem_
Definition: N_ANP_NOISE.h:208
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method)
Linear::BlockVector * saved_AC_X_
Definition: N_ANP_NOISE.h:205
Linear::Matrix * C_
Definition: N_ANP_NOISE.h:200
std::vector< double > objectiveVec_
Definition: N_ANP_NOISE.h:215
bool resetAll(const TIAParams &tia_params)
std::string specifiedSource_
Definition: N_ANP_NOISE.h:168
std::vector< int > noiseSweepFailures_
Definition: N_ANP_NOISE.h:171
NOISE(AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Loader::Loader &loader, Topo::Topology &topology, IO::InitialConditionsManager &initial_conditions_manager)
Definition: N_ANP_NOISE.C:176
Linear::Vector * bVecImagPtr
Definition: N_ANP_NOISE.h:157
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()
#define N_MINLOG
Definition: N_ANP_NOISE.C:108
const std::string & getNetlistFilename() const
NonLinearSolver & getNonlinearSolver()
Linear::BlockMatrix * ACMatrix_
Definition: N_ANP_NOISE.h:202
Linear::Vector * daeQVectorPtr
Linear::BlockVector * B_
Definition: N_ANP_NOISE.h:203
AnalysisManager & analysisManager_
Definition: N_ANP_NOISE.h:146
AnalysisManager & analysisManager_
Definition: N_ANP_NOISE.C:1709
Linear::Vector * lastLeadCurrentPtr
virtual bool startTimeStep(bool beginIntegrationFlag, double nextTimeStep, double nextTime, int currentOrder)
Definition: N_LOA_Loader.h:305
void setErrorWtVector(const TIAParams &tia_params)
virtual bool isPDESystem() const
Definition: N_LOA_Loader.h:256
IO::InitialConditionsManager & initialConditionsManager_
Definition: N_ANP_NOISE.h:151
Linear::Vector * daeFVectorPtr
Loader::Loader & loader_
Definition: N_ANP_NOISE.C:1712
The FactoryBlock contains parameters needed by the analysis creation functions.
IO::InitialConditionsManager & initialConditionsManager_
bool getDCOPFlag() const
Definition: N_ANP_NOISE.C:382
NOISEFactory & factory_
Definition: N_ANP_NOISE.C:1738
Linear::Matrix * dFdxMatrixPtr
virtual bool updateSources()
Definition: N_LOA_Loader.h:244
Linear::Vector * nextStatePtr
Linear::Vector * dFdxdVpVectorPtr
bool updateCurrentFreq_(int stepNumber)
Definition: N_ANP_NOISE.C:1484
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:110
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:189
Linear::Vector * currLeadDeltaVPtr
Linear::BlockVector * X_
Definition: N_ANP_NOISE.h:204
void setDoubleDCOPEnabled(bool enable)
Linear::Vector * bNoiseVecRealPtr
Definition: N_ANP_NOISE.h:160
Nonlinear::Manager & nonlinearManager_
std::vector< Xyce::Analysis::NoiseData * > noiseDataVec_
Definition: N_ANP_NOISE.h:213
bool registerNOISEFactory(FactoryBlock &factory_block)
Definition: N_ANP_NOISE.C:1920
Loader::Loader & loader_
Definition: N_ANP_NOISE.h:147
virtual void getNoiseSources(std::vector< Xyce::Analysis::NoiseData * > &noiseDataVec)
Definition: N_LOA_Loader.h:223
#define N_INTFTHRESH
Definition: N_ANP_NOISE.C:113
Linear::Vector * nextSolutionPtr
std::vector< double > scaled_dOdpVec_
Definition: N_ANP_NOISE.h:218
void dcOutput(int dcStepNumber, Linear::Vector &currSolutionPtr, Linear::Vector &stateVecPtr, Linear::Vector &storeVecPtr, Linear::Vector &lead_current_vector, Linear::Vector &junction_voltage_vector, Linear::Vector &lead_current_dqdt_vector, std::vector< double > &objectiveVec_, std::vector< double > &dOdpVec_, std::vector< double > &dOdpAdjVec_, std::vector< double > &scaled_dOdpVec_, std::vector< double > &scaled_dOdpAdjVec_)
#define M_PI
Topo::Topology & topology_
Definition: N_ANP_NOISE.C:1713
void notify(const StepEvent &event)
Definition: N_ANP_NOISE.C:274
virtual void setupNoiseSources(std::vector< Xyce::Analysis::NoiseData * > &noiseDataVec)
Definition: N_LOA_Loader.h:220
Linear::Vector * nextStorePtr
bool setTimeIntegratorOptions(const Util::OptionBlock &option_block)
Definition: N_ANP_NOISE.C:134
void addAnalysisFactory(FactoryBlock &factory_block, Util::Factory< AnalysisBase, void > *factory)
Amesos_BaseSolver * blockSolver_
Definition: N_ANP_NOISE.h:207
Linear::Vector * dQdxdVpVectorPtr
Linear::Vector * bVecRealPtr
Definition: N_ANP_NOISE.h:156
Topo::Topology & topology_
Definition: N_ANP_NOISE.h:150
std::vector< std::string > outputVarNames_
Definition: N_ANP_NOISE.h:210
Linear::Vector * currLeadCurrentPtr
Linear::Vector * lastStorePtr
void setInputOPFlag(bool initial_conditions_loaded)
TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod()
std::string outputNode2_
Definition: N_ANP_NOISE.h:167
std::string outputNode1_
Definition: N_ANP_NOISE.h:166
const IO::CmdParse & getCommandLine() const
std::vector< int > outputVarGIDs_
Definition: N_ANP_NOISE.h:211
bool setAnalysisParams(const Util::OptionBlock &paramsBlock)
Definition: N_ANP_NOISE.C:298
OutputMgrAdapter & outputManagerAdapter_
Definition: N_ANP_NOISE.h:152
Linear::Vector * nextLeadCurrentQDerivPtr
Linear::Vector * currSolutionPtr
TimeIntg::DataStore * getDataStore()
unsigned int baseIntegrationMethod_
Current time-integration method flag.
void resetAdjointNOISELinearSystem_()
Definition: N_ANP_NOISE.C:1070
#define N_MINGAIN
Definition: N_ANP_NOISE.C:109
Linear::Vector * nextStoreLeadCurrQPtr
Util::OptionBlock timeIntegratorOptionBlock_
Definition: N_ANP_NOISE.C:1718
Linear::Vector * nextStateDerivPtr
void outputNoise(double freq, double totalOutputNoiseDens_, double totalInputNoiseDens_, const std::vector< Xyce::Analysis::NoiseData * > &noiseDataVec_)
double noiseIntegral(double noizDens, double lnNdens, double lnNlstDens, double delLnFreq, double delFreq, double lnFreq, double lnLastFreq)
Definition: N_ANP_NOISE.C:1342
Linear::Matrix * dQdxMatrixPtr
Linear::Vector * flagSolutionPtr
std::vector< double > dOdpAdjVec_
Definition: N_ANP_NOISE.h:217
Linear::Vector * daeBVectorPtr
IO::InitialConditionsManager & initialConditionsManager_
Definition: N_ANP_NOISE.C:1714
bool setReturnCodeOption(const Util::Param &param)
Linear::System & linearSystem_
Definition: N_ANP_NOISE.h:148
Linear::Vector * nextLeadCurrentPtr