46 #include <Xyce_config.h>
52 #include <N_UTL_Misc.h>
59 #include "N_LAS_Vector.h"
60 #include "N_LAS_Matrix.h"
61 #include "N_LAS_System.h"
62 #include "N_LAS_Builder.h"
63 #include "N_ERH_ErrorMgr.h"
64 #include "N_LOA_Loader.h"
65 #include "N_IO_OutputMgr.h"
69 #include "Teuchos_ParameterList.hpp"
70 #include "NOX_Abstract_Vector.H"
71 #include "LOCA_Parameter_Vector.H"
74 using namespace N_NLS_NOX;
88 LOCA::Abstract::
Group(gd),
95 useAugmentLinSys_(false),
100 #ifdef Xyce_PARALLEL_MPI
103 nonContinuationSolve_(true)
117 N_NLS_NOX::
Group(source, type),
118 LOCA::Abstract::
Group(source, type),
119 loader(source.loader),
120 outputMgr(source.outputMgr),
121 anaInt(source.anaInt),
122 params(source.params),
123 derivUtils(source.derivUtils),
125 scalingVecPtr(source.scalingVecPtr),
126 useAugmentLinSys_(source.useAugmentLinSys_),
127 outputLinear_(source.outputLinear_),
128 serialNumber_(source.serialNumber_),
129 oldSol_(source.oldSol_),
131 allNodes_(source.allNodes_),
132 #ifdef Xyce_PARALLEL_MPI
133 pdsCommPtr_(source.pdsCommPtr_),
135 augmentLSStrategy_(source.augmentLSStrategy_),
136 nonContinuationSolve_(source.nonContinuationSolve_)
162 NOX::Abstract::Group&
165 return operator=(dynamic_cast<const N_NLS_LOCA::Group&>(source));
179 return operator=(dynamic_cast<const N_NLS_LOCA::Group&>(source));
190 LOCA::Abstract::Group&
193 return operator=(dynamic_cast<const N_NLS_LOCA::Group&>(source));
241 Teuchos::RefCountPtr<N_NLS_LOCA::Group> ptr =
242 Teuchos::rcp(
new Group(*
this, type));
260 if (!nonContinuationSolve_)
262 for (
int i = 0; i < params.length(); ++i) {
263 std::string label = params.getLabel(i);
264 loader.setParam(label, params.getValue(i));
266 if (label ==
"GSTEPPING" && useAugmentLinSys_)
267 augmentLSStrategy_->setProgressVariable(params.getValue(i));
274 if (useAugmentLinSys_)
275 augmentLSStrategy_->augmentResidual(xVec_.getNativeVectorPtr(),
276 fVec_.getNativeVectorPtr());
295 if (!nonContinuationSolve_)
297 for (
int i = 0; i < params.length(); ++i) {
298 std::string label = params.getLabel(i);
299 loader.setParam(label, params.getValue(i));
301 if (label ==
"GSTEPPING" && useAugmentLinSys_)
302 augmentLSStrategy_->setProgressVariable(params.getValue(i));
307 NOX::Abstract::Group::ReturnType status =
311 if (useAugmentLinSys_) {
312 N_LAS_Matrix& jacobian =
313 const_cast<N_LAS_Matrix&
>(sharedSystemPtr_->getJacobian());
314 augmentLSStrategy_->augmentJacobian(&jacobian);
319 N_LAS_Matrix& jacobian =
320 const_cast<N_LAS_Matrix&
>(sharedSystemPtr_->getJacobian());
321 Xyce::dout() <<
"After computeJacobian, linear system is:" << std::endl;
322 outputLinearSystem_ (&jacobian, xVec_.getNativeVectorPtr(),
323 fVec_.getNativeVectorPtr());
326 #ifdef Xyce_DEBUG_NONLINEAR
327 N_LAS_Matrix& jacobian =
328 const_cast<N_LAS_Matrix&
>(sharedSystemPtr_->getJacobian());
329 sharedSystemPtr_->debugOutput1( jacobian,
330 (*(fVec_.getNativeVectorPtr())));
345 Xyce::NodeNamePairMap * allNodes
346 #ifdef Xyce_PARALLEL_MPI
347 , N_PDS_Comm * pdsCommPtr)
353 allNodes_ = allNodes;
354 #ifdef Xyce_PARALLEL_MPI
355 pdsCommPtr_ = pdsCommPtr;
357 outputLinear_ =
true;
370 N_LAS_Vector* solPtr_,
371 N_LAS_Vector* resPtr_)
373 Xyce::NodeNamePairMap::iterator op_i;
374 Xyce::NodeNamePairMap::iterator op_end;
375 int i, row, global_row;
377 std::vector<int> col;
378 std::vector<double> val;
379 std::map<int,std::string> rowOut;
385 #ifdef Xyce_PARALLEL_MPI
386 N_PDS_ParMap * pmap_;
387 pmap_ = resPtr_->pmap();
388 int procID = pdsCommPtr_->procID();
390 op_i = allNodes_->begin();
391 op_end = allNodes_->end();
392 for ( ; op_i != op_end ; ++op_i)
394 std::ostringstream s;
395 row = (*op_i).second.first;
396 #ifdef Xyce_PARALLEL_MPI
397 global_row = pmap_->localToGlobalIndex(row);
401 s <<
"Global: " << global_row <<
" : " << (*op_i).first <<
" Row: " << global_row;
402 s <<
" Value: " << (*solPtr_)[row];
403 if (serialNumber_ > 0)
406 s <<
" Delta Value: " << (*solPtr_)[row] - oldSol_[row];
409 oldSol_[row] = (*solPtr_)[row];
410 s <<
" Residual: " << (*resPtr_)[row];
411 #ifdef Xyce_PARALLEL_MPI
412 s <<
" proc: " << procID;
415 rowLen = jacobian->getLocalRowLength(row);
418 jacobian->getRowCopy(global_row, rowLen, rowLen, &val[0], &col[0]);
419 for (i=0 ; i<rowLen ; i++)
421 if (i>1 && i%10 == 0)
424 s <<
" " << GID <<
"(" << val[i] <<
")";
426 rowOut[global_row] = s.str();
429 std::map<int,std::string>::iterator row_i;
430 std::map<int,std::string>::iterator row_end = rowOut.end();
431 row_i = rowOut.begin();
433 #ifdef Xyce_PARALLEL_MPI
442 if (row_i == row_end)
449 str = (*row_i).second;
450 num = (*row_i).first;
452 #ifdef Xyce_PARALLEL_MPI
456 pdsCommPtr_->minAll (&num, &numG, 1);
463 pdsCommPtr_->sumAll (&pos, &posG, 1);
468 pdsCommPtr_->recv(&len, 1, posG);
470 pdsCommPtr_->recv(&buf[0], len, posG);
471 Xyce::dout() << buf << std::endl;
474 Xyce::dout() << str << std::endl;
476 else if (procID == posG)
479 pdsCommPtr_->send(&len, 1, 0);
480 pdsCommPtr_->send(str.c_str(), len, 0);
486 Xyce::dout() << str << std::endl;
532 params.setValue(paramID, value);
546 return params.getValue(paramID);
560 params.setValue(paramID, value);
574 return params.getValue(paramID);
600 if (scalingVecPtr == 0) {
601 const std::string message =
"N_NLS_LOCA::Group::getScaleVec() - scaling vector not set!";
602 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, message);
605 return (*scalingVecPtr);
616 NOX::Abstract::Group::ReturnType
620 N_LAS_Matrix& jacobian =
621 const_cast<N_LAS_Matrix&
>(sharedSystemPtr_->getJacobian());
624 jacobian.scale(conParamValue);
625 jacobian.getDiagonal(*tmpVectorPtr);
626 (*tmpVectorPtr).addScalar(1.0 - conParamValue);
627 jacobian.replaceDiagonal(*tmpVectorPtr);
630 return NOX::Abstract::Group::Ok;
653 anaInt.completeHomotopyStep
654 (params.getNamesVector(),
655 params.getValuesVector(),
656 xVec_.getNativeVectorPtr());
670 const double conParam)
const
685 anaInt.completeHomotopyStep
686 (params.getNamesVector(),
687 params.getValuesVector(),
688 xVec_.getNativeVectorPtr());
703 #ifdef Xyce_DEBUG_NONLINEAR
704 Xyce::dout() <<
"In N_NLS_LOCA::Group::stepFailed" << std::endl;
706 anaInt.failHomotopyStep ();
719 #ifdef Xyce_DEBUG_NONLINEAR
720 Xyce::dout() <<
"In N_NLS_LOCA::Group::stepSucceeded" << std::endl;
722 #ifdef Xyce_UPDATED_LOCA
727 const std::string message =
"N_NLS_LOCA::Group::stepSucceeded is not fully supported yet! Recompile without Xyce_UPDATED_LOCA defined\n";
728 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, message);
741 const Teuchos::RefCountPtr<N_NLS_NOX::AugmentLinSys>& ls)
743 useAugmentLinSys_ = enable_value;
744 augmentLSStrategy_ = ls;
757 nonContinuationSolve_ =
value;
770 return nonContinuationSolve_;