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>
79 #include <N_LOA_Loader.h>
80 #include <N_IO_OutputMgr.h>
82 #include <N_IO_CmdParse.h>
83 #include <N_PDS_Manager.h>
84 #include <N_PDS_ParComm.h>
99 nextSolVectorPtrPtr_(0),
100 currSolVectorPtrPtr_(0),
101 tmpSolVectorPtrPtr_(0),
103 jacobianMatrixPtr_(0),
109 petraOptionBlockPtr_(0),
116 netlistFileName_(
""),
117 outputStepNumber_(0),
118 debugTimeFlag_(true),
120 matrixFreeFlag_(false)
210 std::string msg =
"DCOP restart options not supported for this solver. Use nox instead. ";
211 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
225 std::string msg =
".IC options not supported for this nonlinear solver. Use nox instead. ";
226 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
240 std::string msg =
".NODESET options not supported for this nonlinear solver. Use nox instead. ";
241 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
255 std::string msg =
"N_NLS_NonLinearSolver::setLocaOptions - not implemented for this solver. Use nox instead. ";
256 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
270 std::string msg =
"N_NLS_NonLinearSolver::setTwoLevelLocaOptions - not implemented for this solver. Use nox instead.";
271 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
418 tlnPtr_ = tmp_tlnPtr;
419 return (tlnPtr_ != 0);
435 return (nlpMgrPtr_ != 0);
469 bool bsuccess =
true;
482 bsuccess = bsuccess && (rhsVectorPtr_ != 0);
486 bsuccess = bsuccess && (currSolVectorPtrPtr_ != 0);
490 bsuccess = bsuccess && (nextSolVectorPtrPtr_ != 0);
494 bsuccess = bsuccess && (jacobianMatrixPtr_ != 0);
506 bsuccess = bsuccess && (NewtonVectorPtr_ != 0);
511 bsuccess = bsuccess && (solWtVectorPtr_ != 0);
519 Teuchos::RefCountPtr<N_LAS_Vector> NewtonVectorRCPtr = Teuchos::rcp(NewtonVectorPtr_,
false);
520 Teuchos::RefCountPtr<N_LAS_Vector> rhsVectorRCPtr = Teuchos::rcp(rhsVectorPtr_,
false);
524 Teuchos::RefCountPtr<N_LAS_Matrix> jacobianMatrixRCPtr = Teuchos::rcp(jacobianMatrixPtr_,
false);
534 Teuchos::RefCountPtr<N_NLS_NonLinearSolver> NonlinearSolverRCPtr = Teuchos::rcp(
this,
false);
535 Teuchos::RefCountPtr<N_NLS_MatrixFreeEpetraOperator>
537 NonlinearSolverRCPtr,
541 bld_.getSolutionMap()
544 Teuchos::RefCountPtr<Epetra_Operator> epetraOperator = Teuchos::rcp_dynamic_cast<Epetra_Operator>(matFreeOp,
true);
561 Teuchos::RefCountPtr<N_LAS_Preconditioner> precond =
lasPrecPtr_->create( Teuchos::rcp(
lasSysPtr_,
false ) );
565 #ifdef Xyce_DEBUG_NONLINEAR
566 Xyce::dout() <<
"size of solution vector: " <<
lasSysPtr_->getGlobalSolutionSize() << std::endl
567 <<
"size of state vector: " <<
lasSysPtr_->getGlobalStateSize() << std::endl
568 <<
"End of N_NLS_NonLinearSolver::initializeAll\n";
574 #ifdef Xyce_DEBUG_NONLINEAR
587 void N_NLS_NonLinearSolver::debugOutput1
588 (N_LAS_Matrix & jacobian, N_LAS_Vector & rhs)
590 int debugLevel = getDebugLevel();
592 int screenOutput = getScreenOutputFlag ();
598 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
599 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
603 sprintf(filename1,
"matrix_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
605 else if (debugLevel == 2)
611 sprintf(filename1,
"matrix_%03d.txt", newtStep);
614 jacobian.writeToFile(filename1,
false, getMMFormat () );
616 if (screenOutput == 1)
618 Xyce::dout() <<
"\n\t***** Jacobian matrix:" << std::endl;
619 jacobian.printPetraObject(Xyce::dout());
624 sprintf(filename2,
"rhs_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
626 else if (debugLevel == 2)
632 sprintf(filename2,
"rhs_%03d.txt", newtStep);
635 if (screenOutput == 1)
637 Xyce::dout() <<
"\n\t***** RHS vector:" << std::endl;
639 rhs.printPetraObject(Xyce::dout());
642 rhs.writeToFile(filename2);
644 #ifdef Xyce_DEBUG_VOLTLIM
645 debugOutputJDX_VOLTLIM ();
651 #endif // Xyce_DEBUG_NONLINEAR
653 #ifdef Xyce_DEBUG_VOLTLIM
662 void N_NLS_NonLinearSolver::debugOutputJDX_VOLTLIM()
664 int debugLevel = getDebugLevel();
669 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
670 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
671 char filename3[256];
for (
int ich = 0; ich < 256; ++ich) filename3[ich] = 0;
675 sprintf(filename1,
"jdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
676 sprintf(filename2,
"fdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
677 sprintf(filename3,
"qdxVL_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
679 else if (debugLevel == 2)
687 sprintf(filename1,
"jdxVL_%03d.txt", newtStep);
688 sprintf(filename2,
"fdxVL_%03d.txt", newtStep);
689 sprintf(filename3,
"qdxVL_%03d.txt", newtStep);
692 bool Transpose =
false;
694 jdxVLVectorPtr_->putScalar(0.0);
695 fdxVLVectorPtr_->putScalar(0.0);
696 qdxVLVectorPtr_->putScalar(0.0);
698 jacTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *jdxVLVectorPtr_);
699 dFdxTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *fdxVLVectorPtr_);
700 dQdxTestMatrixPtr_->matvec( Transpose , *dxVoltlimVectorPtr_, *qdxVLVectorPtr_);
702 jdxVLVectorPtr_->writeToFile(filename1);
703 fdxVLVectorPtr_->writeToFile(filename2);
704 qdxVLVectorPtr_->writeToFile(filename3);
708 sprintf(filename1,
"jtest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
709 sprintf(filename2,
"ftest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
710 sprintf(filename3,
"qtest_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,newtStep);
712 else if (debugLevel == 2)
720 sprintf(filename1,
"jtest_%03d.txt", newtStep);
721 sprintf(filename2,
"ftest_%03d.txt", newtStep);
722 sprintf(filename3,
"qtest_%03d.txt", newtStep);
725 jacTestMatrixPtr_->writeToFile(filename1);
726 dFdxTestMatrixPtr_->writeToFile(filename2);
727 dQdxTestMatrixPtr_->writeToFile(filename3);
732 #ifdef Xyce_DEBUG_NONLINEAR
741 void N_NLS_NonLinearSolver::debugOutputDAE()
743 int debugLevel = getDebugLevel();
748 char filename1[256];
for (
int ich = 0; ich < 256; ++ich) filename1[ich] = 0;
749 char filename2[256];
for (
int ich = 0; ich < 256; ++ich) filename2[ich] = 0;
751 char filename4[256];
for (
int ich = 0; ich < 256; ++ich) filename4[ich] = 0;
752 char filename6[256];
for (
int ich = 0; ich < 256; ++ich) filename6[ich] = 0;
753 char filename7[256];
for (
int ich = 0; ich < 256; ++ich) filename7[ich] = 0;
754 char filename8[256];
for (
int ich = 0; ich < 256; ++ich) filename8[ich] = 0;
755 char filename9[256];
for (
int ich = 0; ich < 256; ++ich) filename9[ich] = 0;
757 N_LAS_Matrix *dQdx =
lasSysPtr_->getDAEdQdxMatrix ();
758 N_LAS_Matrix *dFdx =
lasSysPtr_->getDAEdFdxMatrix ();
760 N_LAS_Vector *daeQ =
lasSysPtr_->getDAEQVector();
761 N_LAS_Vector *daeF =
lasSysPtr_->getDAEFVector();
763 N_LAS_Vector *daeFlim =
lasSysPtr_->getdFdxdVpVector ();
764 N_LAS_Vector *daeQlim =
lasSysPtr_->getdQdxdVpVector ();
770 sprintf(filename1,
"dQdx_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
771 sprintf(filename2,
"dFdx_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
773 sprintf(filename4,
"daeQ_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
774 sprintf(filename6,
"daeF_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
776 sprintf(filename8,
"daeQlim_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
777 sprintf(filename9,
"daeFlim_%03d_%03d_%03d_%03d.txt" ,
outputStepNumber_,paramNumber,contStep,newtStep);
779 else if (debugLevel >= 2)
792 sprintf(filename1,
"dQdx_%03d.txt" , newtStep);
793 sprintf(filename2,
"dFdx_%03d.txt" , newtStep);
795 sprintf(filename4,
"daeQ_%03d.txt" , newtStep);
796 sprintf(filename6,
"daeF_%03d.txt" , newtStep);
798 sprintf(filename8,
"daeQlim_%03d.txt" , newtStep);
799 sprintf(filename9,
"daeFlim_%03d.txt" , newtStep);
803 dQdx->writeToFile (filename1,
false, getMMFormat () );
804 dFdx->writeToFile (filename2,
false, getMMFormat () );
807 daeQ->writeToFile(filename4);
808 daeF->writeToFile(filename6);
809 daeQlim->writeToFile(filename8);
810 daeFlim->writeToFile(filename9);
812 #endif // Xyce_DEBUG_NONLINEAR
814 #ifdef Xyce_DEBUG_NONLINEAR
827 void N_NLS_NonLinearSolver::debugOutput3
828 (N_LAS_Vector & dxVector, N_LAS_Vector & xVector)
830 int debugLevel = getDebugLevel();
837 char filename[256];
for (
int ich = 0; ich < 256; ++ich) filename[ich] = 0;
841 sprintf(filename,
"update_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,nlStep);
843 else if (debugLevel == 2)
849 sprintf(filename,
"update_%03d.txt", nlStep);
851 dxVector.writeToFile(filename);
854 if (nlParams.getScreenOutputFlag () )
856 Xyce::dout() <<
"\n\t***** Update vector:" << std::endl << std::endl;
858 dxVector.printPetraObject();
865 sprintf(filename,
"solution_%03d_%03d_%03d_%03d.txt",
outputStepNumber_,paramNumber,contStep,nlStep);
873 sprintf(filename,
"solution_%03d.txt", nlStep);
875 xVector.writeToFile(filename);
878 if (nlParams.getScreenOutputFlag () )
880 Xyce::dout() <<
"\n\t***** Solution vector:" << std::endl;
882 xVector.printPetraObject();
1019 N_UTL_Param param(
"Iterations", 0 );
1027 N_UTL_Param param(
"Refactored", 0 );
1033 if( solutionStatus )
return false;
1057 bool transpose =
true;
1106 #ifdef Xyce_DEBUG_NONLINEAR
1115 void N_NLS_NonLinearSolver::setDebugFlags()
1122 (currTime >= getDebugMinTime() &&
1123 currTime <= getDebugMaxTime() ) &&
1134 if (steadyStateFlag ==
true)