40 #include <Xyce_config.h>
48 #include <N_ERH_Message.h>
49 #include <N_IO_CmdParse.h>
50 #include <N_IO_PkgOptionsMgr.h>
51 #include <N_LAS_BlockMatrix.h>
52 #include <N_LAS_BlockSystemHelpers.h>
53 #include <N_LAS_BlockVector.h>
54 #include <N_LAS_Builder.h>
55 #include <N_LAS_Matrix.h>
56 #include <N_LAS_MultiVector.h>
57 #include <N_LAS_System.h>
64 #include <N_UTL_Diagnostic.h>
65 #include <N_TOP_Topology.h>
66 #include <N_UTL_FeatureTest.h>
67 #include <N_UTL_LogStream.h>
68 #include <N_UTL_Math.h>
69 #include <N_UTL_Timer.h>
71 #include <N_PDS_ParMap.h>
73 #include <Epetra_SerialComm.h>
74 #include <Epetra_Map.h>
75 #include <Epetra_BlockMap.h>
76 #include <Epetra_CrsMatrix.h>
77 #include <Epetra_CrsGraph.h>
78 #include <Epetra_MultiVector.h>
79 #include <Epetra_Vector.h>
80 #include <Epetra_Export.h>
81 #include <Epetra_LinearProblem.h>
84 #include<N_UTL_ExtendedString.h>
85 #include<N_UTL_ExpressionData.h>
88 #include <Teuchos_RCP.hpp>
104 const Util::OptionBlock & option_block)
106 for (Util::ParamList::const_iterator it = option_block.begin(), end = option_block.end(); it != end; ++it)
108 const Util::Param ¶m = *it;
110 if (param.uTag() ==
"DEBUGLEVEL" )
119 Report::UserError() << param.uTag() <<
" is not a recognized time integration option";
136 Linear::System & linear_system,
138 Topo::Topology & topology)
142 loader_(analysis_manager.getLoader()),
146 outputManagerAdapter_(analysis_manager.getOutputManagerAdapter()),
219 const Util::OptionBlock & paramsBlock)
221 for (Util::ParamList::const_iterator it = paramsBlock.begin(), end = paramsBlock.end(); it != end; ++it)
223 if ((*it).uTag() ==
"TYPE")
225 type_ = (*it).stringValue();
227 else if ((*it).uTag() ==
"NP")
229 np_ = (*it).getImmutableValue<
double>();
231 else if ((*it).uTag() ==
"FSTART")
233 fStart_ = (*it).getImmutableValue<
double>();
235 else if ((*it).uTag() ==
"FSTOP")
237 fStop_ = (*it).getImmutableValue<
double>();
241 if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
243 dout() << section_divider << std::endl
244 <<
"AC simulation parameters"
246 <<
"number of points = " <<
np_ << std::endl
247 <<
"starting frequency = " <<
fStart_ << std::endl
248 <<
"stop frequency = " <<
fStop_
291 bool bsuccess =
true;
333 Report::UserError() <<
"Solving for DC operating point failed! Cannot continue AC analysis";
360 Xyce::dout() <<
"bVecReal:" <<std::endl;
362 Xyce::dout() <<
"bVecImag:" <<std::endl;
435 if (DEBUG_TIME && isActive(Diag::TIME_PARAMETERS))
437 Xyce::dout() <<
"dQdxMatrixPtr:" << std::endl;
440 Xyce::dout() <<
"dFdxMatrixPtr:" << std::endl;
443 Xyce::dout() << std::endl;
450 for (
int currentStep = 0; currentStep <
acLoopSize_; ++currentStep)
458 bool stepAttemptStatus;
460 Stats::StatTop _nonlinearStat(
"Nonlinear Solve");
461 Stats::TimeBlock _nonlinearTimer(_nonlinearStat);
467 Xyce::dout()<<
"AC X vector:"<<std::endl;
468 X_->printPetraObject(Xyce::dout());
471 if (stepAttemptStatus)
499 bool bsuccess =
true;
503 RCP<N_PDS_ParMap> baseMap = rcp(pds_manager.getParallelMap( Parallel::SOLUTION ),
false);
504 Epetra_CrsGraph &baseFullGraph = *pds_manager.getMatrixGraph(Parallel::JACOBIAN);
508 RCP<N_PDS_ParMap> blockMap = Linear::createBlockParMap(numBlocks, *baseMap);
512 B_ =
new Linear::BlockVector(numBlocks, blockMap, baseMap);
518 std::vector<std::vector<int> > blockPattern(2);
519 blockPattern[0].resize(2);
520 blockPattern[0][0] = 0; blockPattern[0][1] = 1;
521 blockPattern[1].resize(2);
522 blockPattern[1][0] = 0; blockPattern[1][1] = 1;
524 int offset = Linear::generateOffset( *baseMap );
526 RCP<Epetra_CrsGraph> blockGraph = Linear::createBlockGraph( offset, blockPattern, *blockMap, baseFullGraph);
529 ACMatrix_ =
new Linear::BlockMatrix( numBlocks, offset, blockPattern, *blockGraph, baseFullGraph);
538 B_->putScalar( 0.0 );
542 Amesos amesosFactory;
545 X_ =
new Linear::BlockVector (numBlocks, blockMap, baseMap);
546 X_->putScalar( 0.0 );
552 blockSolver_ = amesosFactory.Create(
"Klu", *
blockProblem_ );
555 Teuchos::ParameterList params;
556 params.set(
"Reindex",
true );
557 blockSolver_->SetParameters( params );
560 int linearStatus = blockSolver_->SymbolicFactorization();
562 if (linearStatus != 0)
564 Xyce::dout() <<
"Amesos symbolic factorization exited with error: " << linearStatus;
595 Xyce::dout()<<
"G matrix:"<<std::endl;
596 G_->printPetraObject(Xyce::dout());
598 Xyce::dout()<<
"C matrix:"<<std::endl;
599 C_->printPetraObject(Xyce::dout());
601 Xyce::dout()<<
"AC matrix:"<<std::endl;
602 ACMatrix_->printPetraObject(Xyce::dout());
604 Xyce::dout()<<
"AC B vector:"<<std::endl;
605 B_->printPetraObject(Xyce::dout());
621 bool bsuccess =
true;
624 int linearStatus =
blockSolver_->NumericFactorization();
626 if (linearStatus != 0)
628 Xyce::dout() <<
"Amesos numeric factorization exited with error: " << linearStatus;
633 if (linearStatus != 0)
635 Xyce::dout() <<
"Amesos solve exited with error: " << linearStatus;
652 bool bsuccess =
true;
683 bool bsuccess =
true;
703 bool bsuccess =
true;
707 Xyce::dout() <<
"Calling AC::doFinish() outputs!" << std::endl;
763 Report::DevelFatal().in(
"AC::updateCurrentFreq_") <<
"AC::updateCurrentFreq_: unsupported STEP type";
767 if (isActive(Diag::TIME_PARAMETERS))
769 Xyce::dout() <<
"currentFreq_ = " <<
currentFreq_ << std::endl;
786 double fstart, fstop;
792 if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
794 Xyce::dout() << std::endl << std::endl;
795 Xyce::dout() << section_divider << std::endl;
796 Xyce::dout() <<
"AC::setupSweepParam_" << std::endl;
801 int np =
static_cast<int>(
np_);
809 if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
811 Xyce::dout() <<
"fstep = " <<
fstep_ << std::endl;
814 else if (
type_ ==
"DEC")
817 fcount = floor(fabs(log10(fstart) - log10(fstop)) *
np_ + 1.0);
818 if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
820 Xyce::dout() <<
"stepMult_ = " <<
stepMult_ << std::endl;
823 else if (
type_ ==
"OCT")
830 double ln2 = log(2.0);
831 fcount = floor(fabs(log(fstart) - log(fstop))/ln2 *
np_ + 1.0);
832 if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
834 Xyce::dout() <<
"stepMult_ = " <<
stepMult_ << std::endl;
839 Report::DevelFatal().in(
"AC::setupSweepParam") <<
"Unsupported type";
844 return static_cast<int> (fcount);
860 class ACFactory :
public Factory<AC>
888 Linear::System & linear_system,
890 Topo::Topology & topology)
939 void setACAnalysisOptionBlock(
const Util::OptionBlock &option_block)
959 void setTimeIntegratorOptionBlock(
const Util::OptionBlock &option_block)
976 struct TimeIntegratorOptionsReg :
public IO::PkgOptionsReg
978 TimeIntegratorOptionsReg(
979 ACFactory & factory )
983 bool operator()(
const Util::OptionBlock &option_block)
985 factory_.setTimeIntegratorOptionBlock(option_block);
994 struct ACAnalysisReg :
public IO::PkgOptionsReg
997 ACFactory & factory )
1001 bool operator()(
const Util::OptionBlock &option_block)
1003 factory_.setACAnalysisOptionBlock(option_block);
1018 const std::string & netlist_filename,
1019 IO::PkgOptionsMgr & options_manager,
1021 Linear::System & linear_system,
1023 Topo::Topology & topology)
1025 ACFactory *factory =
new ACFactory(analysis_manager, linear_system, nonlinear_manager, topology);
1029 options_manager.submitRegistration(
"AC", netlist_filename,
new ACAnalysisReg(*factory));
1030 options_manager.submitRegistration(
"TIMEINT", netlist_filename,
new TimeIntegratorOptionsReg(*factory));
bool doProcessSuccessfulStep()
Linear::Vector * lastSolutionPtr
unsigned int successStepsThisParameter_
bool createLinearSystem_()
unsigned int successfulStepsTaken_
Number of consecutive successful time-integration steps.
int newtonConvergenceStatus
virtual bool setInitialGuess(Linear::Vector *solVectorPtr)
Linear::Vector * lastLeadDeltaVPtr
bool setAnalysisParams(const Util::OptionBlock ¶msBlock)
bool setTimeIntegratorOption(const Util::Param ¶m)
void outputAC(double freq, const Linear::Vector &solnVecRealPtr, const Linear::Vector &solnVecImaginaryPtr)
Pure virtual class to augment a linear system.
TimeIntg::TIAParams tiaParams_
int doubleDCOPStep_
current step in the DCOP loop.
void dcOutput(int dcStepNumber, Linear::Vector &currSolutionPtr, Linear::Vector &stateVecPtr, Linear::Vector &storeVecPtr, Linear::Vector &lead_current_vector, Linear::Vector &junction_voltage_vector, std::vector< double > &objectiveVec_, std::vector< double > &dOdpVec_, std::vector< double > &dOdpAdjVec_, std::vector< double > &scaled_dOdpVec_, std::vector< double > &scaled_dOdpAdjVec_)
Util::OptionBlock timeIntegratorOptionBlock_
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)
bool resetForStepAnalysis()
unsigned int stepNumber
Time-integration step number counter.
virtual bool loadBVectorsforAC(Linear::Vector *bVecRealPtr, Linear::Vector *bVecImagPtr)
bool doProcessFailedStep()
Linear::Vector * currStorePtr
Linear::Vector * lastStatePtr
Topo::Topology & topology_
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method)
bool setupInitialConditions(Linear::Vector &solnVec, Linear::Vector &flagVec)
bool registerACFactory(const std::string &netlist_filename, IO::PkgOptionsMgr &options_manager, AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology)
bool resetAll(const TIAParams &tia_params)
std::vector< int > acSweepFailures_
Util::ListenerAutoSubscribe< StepEvent > StepEventListener
Linear::Vector * nextLeadDeltaVPtr
Linear::Vector * currStatePtr
unsigned int failedStepsAttempted_
Total number of failed time-integration steps.
void obtainCorrectorDeriv()
Parallel::Manager * getPDSManager() const
bool setDCOPOption(const Util::Param ¶m)
TimeIntg::StepErrorControl & getStepErrorControl()
bool setTimeIntegratorOptions(const Util::OptionBlock &option_block)
Linear::Vector * bVecRealPtr
void computeDividedDifferences()
NonLinearSolver & getNonlinearSolver()
std::vector< double > scaled_dOdpVec_
Linear::Vector * daeQVectorPtr
void setConstantHistory()
Linear::Vector * lastLeadCurrentPtr
virtual bool startTimeStep()
void setErrorWtVector(const TIAParams &tia_params)
std::vector< double > dOdpAdjVec_
Amesos_BaseSolver * blockSolver_
Linear::Vector * daeFVectorPtr
Linear::Vector * currLeadCurrentQPtr
Nonlinear::Manager & nonlinearManager_
OutputMgrAdapter & outputManagerAdapter_
bool processSuccessfulStep()
Linear::Matrix * dFdxMatrixPtr
virtual bool updateSources()
Linear::Vector * nextStatePtr
AC(AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology)
Linear::Vector * dFdxdVpVectorPtr
virtual bool loadDAEMatrices(Linear::Vector *tmpSolVectorPtr, Linear::Vector *tmpStaVectorPtr, Linear::Vector *tmpStaDerivVectorPtr, Linear::Vector *tmpStoVectorPtr, Linear::Matrix *tmpdQdxMatrixPtr, Linear::Matrix *tmpdFdxMatrixPtr)
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)
Linear::Vector * currLeadDeltaVPtr
AnalysisManager & analysisManager_
int numberSuccessiveFailures
void addAnalysisFactory(Factory< void > *factory)
bool updateCurrentFreq_(int stepNumber)
std::vector< double > scaled_dOdpAdjVec_
Linear::Vector * nextSolutionPtr
virtual bool getDoubleDCOPFlag() const
Linear::Vector * nextStorePtr
bool updateLinearSystemFreq_()
The analysis factory template defines an interface for analysis type testing and analysis creation...
Linear::Vector * dQdxdVpVectorPtr
Util::OptionBlock acAnalysisOptionBlock_
Linear::Vector * currLeadCurrentPtr
Linear::Vector * lastStorePtr
void setInputOPFlag(bool initial_conditions_loaded)
TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod()
bool firstDoubleDCOPStep()
const IO::CmdParse & getCommandLine() const
void obtainPredictorDeriv()
AnalysisManager & analysisManager_
std::vector< double > objectiveVec_
Linear::Vector * bVecImagPtr
int getIntegrationMethod() const
Linear::Vector * currSolutionPtr
TimeIntg::DataStore * getDataStore()
void evaluateStepError(const TIAParams &tia_params)
Linear::BlockMatrix * ACMatrix_
bool doubleDCOPFlag_
true if doing a double-DCOP is possible.
unsigned int baseIntegrationMethod_
Current time-integration method flag.
Linear::Vector * nextStoreLeadCurrQPtr
Linear::Vector * nextStateDerivPtr
std::vector< double > dOdpVec_
void outputDCOP(const Linear::Vector &solution)
Nonlinear::Manager & nonlinearManager_
Linear::Matrix * dQdxMatrixPtr
bool solveLinearSystem_()
Epetra_LinearProblem * blockProblem_
Linear::Vector * flagSolutionPtr
void notify(const StepEvent &event)
Linear::Vector * daeBVectorPtr
bool setReturnCodeOption(const Util::Param ¶m)
Linear::System & linearSystem_
virtual bool output() const
Linear::Vector * nextLeadCurrentPtr