49 #include <Xyce_config.h>
56 #include <N_UTL_fwd.h>
57 #include <N_UTL_OptionBlock.h>
63 #include <N_LAS_Matrix.h>
64 #include <N_LAS_Vector.h>
66 #include <N_LAS_Solver.h>
67 #include <N_LAS_Problem.h>
68 #include <N_LAS_SolverFactory.h>
69 #include <N_LAS_PrecondFactory.h>
71 #include <N_LAS_System.h>
72 #include <N_LAS_Builder.h>
74 #include <N_ERH_ErrorMgr.h>
78 #include <N_LOA_Loader.h>
79 #include <N_IO_OutputMgr.h>
81 #include <N_IO_CmdParse.h>
82 #include <N_PDS_Manager.h>
83 #include <N_PDS_ParComm.h>
103 netlistFileName_(
""),
105 nextSolVectorPtrPtr_(0),
106 currSolVectorPtrPtr_(0),
107 tmpSolVectorPtrPtr_(0),
110 #ifdef Xyce_DEBUG_VOLTLIM
111 jacTestMatrixPtr_(0),
112 dFdxTestMatrixPtr_(0),
113 dQdxTestMatrixPtr_(0),
114 dxVoltlimVectorPtr_(0),
120 jacobianMatrixPtr_(0),
126 petraOptionBlockPtr_(0),
135 numJacobianLoads_(0),
136 numJacobianFactorizations_(0),
138 numFailedLinearSolves_(0),
139 numResidualLoads_(0),
140 totalNumLinearIters_(0),
142 totalLinearSolveTime_(0.0),
143 totalResidualLoadTime_(0.0),
144 totalJacobianLoadTime_(0.0),
146 matrixFreeFlag_(false),
147 outputStepNumber_(0),
148 debugTimeFlag_(true),
239 std::string msg =
"DCOP restart options not supported for this solver. Use nox instead. ";
240 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
254 std::string msg =
".IC options not supported for this nonlinear solver. Use nox instead. ";
255 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
269 std::string msg =
".NODESET options not supported for this nonlinear solver. Use nox instead. ";
270 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
284 std::string msg =
"NonLinearSolver::setLocaOptions - not implemented for this solver. Use nox instead. ";
285 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
299 std::string msg =
"NonLinearSolver::setTwoLevelLocaOptions - not implemented for this solver. Use nox instead.";
300 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
447 tlnPtr_ = tmp_tlnPtr;
448 return (tlnPtr_ != 0);
464 return (nlpMgrPtr_ != 0);
513 bool bsuccess =
true;
526 bsuccess = bsuccess && (rhsVectorPtr_ != 0);
530 bsuccess = bsuccess && (currSolVectorPtrPtr_ != 0);
534 bsuccess = bsuccess && (nextSolVectorPtrPtr_ != 0);
538 bsuccess = bsuccess && (jacobianMatrixPtr_ != 0);
548 bsuccess = bsuccess && (NewtonVectorPtr_ != 0);
552 bsuccess = bsuccess && (solWtVectorPtr_ != 0);
560 Teuchos::RefCountPtr<N_LAS_Vector> NewtonVectorRCPtr = Teuchos::rcp(NewtonVectorPtr_,
false);
561 Teuchos::RefCountPtr<N_LAS_Vector> rhsVectorRCPtr = Teuchos::rcp(rhsVectorPtr_,
false);
565 Teuchos::RefCountPtr<N_LAS_Matrix> jacobianMatrixRCPtr = Teuchos::rcp(jacobianMatrixPtr_,
false);
575 Teuchos::RefCountPtr<NonLinearSolver> NonlinearSolverRCPtr = Teuchos::rcp(
this,
false);
576 Teuchos::RefCountPtr<MatrixFreeEpetraOperator>
578 NonlinearSolverRCPtr,
581 bld_.getSolutionMap()
584 Teuchos::RefCountPtr<Epetra_Operator> epetraOperator = Teuchos::rcp_dynamic_cast<Epetra_Operator>(matFreeOp,
true);
600 Teuchos::RefCountPtr<N_LAS_Preconditioner> precond =
lasPrecPtr_->create( Teuchos::rcp(
lasSysPtr_,
false ) );
604 #ifdef Xyce_DEBUG_NONLINEAR
605 Xyce::dout() <<
"size of solution vector: " <<
lasSysPtr_->getGlobalSolutionSize() << std::endl
606 <<
"size of state vector: " <<
lasSysPtr_->getGlobalStateSize() << std::endl
607 <<
"End of NonLinearSolver::initializeAll\n";
613 #ifdef Xyce_DEBUG_NONLINEAR
626 void NonLinearSolver::debugOutput1
627 (N_LAS_Matrix & jacobian, N_LAS_Vector & rhs)
629 int debugLevel = getDebugLevel();
631 int screenOutput = getScreenOutputFlag ();
637 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
638 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
642 sprintf(filename1,
"matrix_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
644 else if (debugLevel == 2)
650 sprintf(filename1,
"matrix_%03d.txt", newtStep);
653 jacobian.writeToFile(filename1,
false, getMMFormat () );
655 if (screenOutput == 1)
657 Xyce::dout() <<
"\n\t***** Jacobian matrix:" << std::endl;
658 jacobian.printPetraObject(Xyce::dout());
663 sprintf(filename2,
"rhs_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
665 else if (debugLevel == 2)
671 sprintf(filename2,
"rhs_%03d.txt", newtStep);
674 if (screenOutput == 1)
676 Xyce::dout() <<
"\n\t***** RHS vector:" << std::endl;
678 rhs.printPetraObject(Xyce::dout());
681 rhs.writeToFile(filename2);
683 #ifdef Xyce_DEBUG_VOLTLIM
684 debugOutputJDX_VOLTLIM ();
690 #endif // Xyce_DEBUG_NONLINEAR
692 #ifdef Xyce_DEBUG_VOLTLIM
701 void NonLinearSolver::debugOutputJDX_VOLTLIM()
703 int debugLevel = getDebugLevel();
708 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
709 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
710 char filename3[256];
for (
int ich = 0; ich < 256; ++ich) filename3[ich] = 0;
714 sprintf(filename1,
"jdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
715 sprintf(filename2,
"fdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
716 sprintf(filename3,
"qdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
718 else if (debugLevel == 2)
726 sprintf(filename1,
"jdxVL_%03d.txt", newtStep);
727 sprintf(filename2,
"fdxVL_%03d.txt", newtStep);
728 sprintf(filename3,
"qdxVL_%03d.txt", newtStep);
731 bool Transpose =
false;
733 jdxVLVectorPtr_->putScalar(0.0);
734 fdxVLVectorPtr_->putScalar(0.0);
735 qdxVLVectorPtr_->putScalar(0.0);
737 jacTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *jdxVLVectorPtr_);
738 dFdxTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *fdxVLVectorPtr_);
739 dQdxTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *qdxVLVectorPtr_);
741 jdxVLVectorPtr_->writeToFile(filename1);
742 fdxVLVectorPtr_->writeToFile(filename2);
743 qdxVLVectorPtr_->writeToFile(filename3);
747 sprintf(filename1,
"jtest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
748 sprintf(filename2,
"ftest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
749 sprintf(filename3,
"qtest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
751 else if (debugLevel == 2)
759 sprintf(filename1,
"jtest_%03d.txt", newtStep);
760 sprintf(filename2,
"ftest_%03d.txt", newtStep);
761 sprintf(filename3,
"qtest_%03d.txt", newtStep);
764 jacTestMatrixPtr_->writeToFile(filename1);
765 dFdxTestMatrixPtr_->writeToFile(filename2);
766 dQdxTestMatrixPtr_->writeToFile(filename3);
771 #ifdef Xyce_DEBUG_NONLINEAR
780 void NonLinearSolver::debugOutputDAE()
782 int debugLevel = getDebugLevel();
787 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
788 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
790 char filename4[256];
for (
int ich = 0; ich < 256; ++ich) filename4[ich] = 0;
791 char filename6[256];
for (
int ich = 0; ich < 256; ++ich) filename6[ich] = 0;
792 char filename7[256];
for (
int ich = 0; ich < 256; ++ich) filename7[ich] = 0;
793 char filename8[256];
for (
int ich = 0; ich < 256; ++ich) filename8[ich] = 0;
794 char filename9[256];
for (
int ich = 0; ich < 256; ++ich) filename9[ich] = 0;
796 N_LAS_Matrix *dQdx =
lasSysPtr_->getDAEdQdxMatrix ();
797 N_LAS_Matrix *dFdx =
lasSysPtr_->getDAEdFdxMatrix ();
799 N_LAS_Vector *daeQ =
lasSysPtr_->getDAEQVector();
800 N_LAS_Vector *daeF =
lasSysPtr_->getDAEFVector();
802 N_LAS_Vector *daeFlim =
lasSysPtr_->getdFdxdVpVector ();
803 N_LAS_Vector *daeQlim =
lasSysPtr_->getdQdxdVpVector ();
809 sprintf(filename1,
"dQdx_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
810 sprintf(filename2,
"dFdx_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
812 sprintf(filename4,
"daeQ_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
813 sprintf(filename6,
"daeF_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
815 sprintf(filename8,
"daeQlim_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
816 sprintf(filename9,
"daeFlim_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
818 else if (debugLevel >= 2)
831 sprintf(filename1,
"dQdx_%03d.txt" , newtStep);
832 sprintf(filename2,
"dFdx_%03d.txt" , newtStep);
834 sprintf(filename4,
"daeQ_%03d.txt" , newtStep);
835 sprintf(filename6,
"daeF_%03d.txt" , newtStep);
837 sprintf(filename8,
"daeQlim_%03d.txt" , newtStep);
838 sprintf(filename9,
"daeFlim_%03d.txt" , newtStep);
842 dQdx->writeToFile (filename1,
false, getMMFormat () );
843 dFdx->writeToFile (filename2,
false, getMMFormat () );
846 daeQ->writeToFile(filename4);
847 daeF->writeToFile(filename6);
848 daeQlim->writeToFile(filename8);
849 daeFlim->writeToFile(filename9);
851 #endif // Xyce_DEBUG_NONLINEAR
853 #ifdef Xyce_DEBUG_NONLINEAR
866 void NonLinearSolver::debugOutput3
867 (N_LAS_Vector & dxVector, N_LAS_Vector & xVector)
869 int debugLevel = getDebugLevel();
876 char filename[256];
for (
int ich = 0; ich < 256; ++ich) filename[ich] = 0;
880 sprintf(filename,
"update_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,nlStep);
882 else if (debugLevel == 2)
888 sprintf(filename,
"update_%03d.txt", nlStep);
890 dxVector.writeToFile(filename);
893 if (nlParams.getScreenOutputFlag () )
895 Xyce::dout() <<
"\n\t***** Update vector:" << std::endl << std::endl;
897 dxVector.printPetraObject();
904 sprintf(filename,
"solution_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,nlStep);
912 sprintf(filename,
"solution_%03d.txt", nlStep);
914 xVector.writeToFile(filename);
917 if (nlParams.getScreenOutputFlag () )
919 Xyce::dout() <<
"\n\t***** Solution vector:" << std::endl;
921 xVector.printPetraObject();
1058 N_UTL_Param param(
"Iterations", 0 );
1066 N_UTL_Param param(
"Refactored", 0 );
1072 if( solutionStatus )
return false;
1096 bool transpose =
true;
1145 #ifdef Xyce_DEBUG_NONLINEAR
1154 void NonLinearSolver::setDebugFlags()
1161 (currTime >= getDebugMinTime() &&
1162 currTime <= getDebugMaxTime() ) &&
1173 if (dcopFlag ==
true)