00001 // $Id: LOCA_Solver_Wrapper.C,v 1.12 2007/08/01 20:50:41 rppawlo Exp $ 00002 // $Source: /space/CVS/Trilinos/packages/nox/src-loca/src/LOCA_Solver_Wrapper.C,v $ 00003 00004 //@HEADER 00005 // ************************************************************************ 00006 // 00007 // NOX: An Object-Oriented Nonlinear Solver Package 00008 // Copyright (2002) Sandia Corporation 00009 // 00010 // LOCA: Library of Continuation Algorithms Package 00011 // Copyright (2005) Sandia Corporation 00012 // 00013 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00014 // license for use of this work by or on behalf of the U.S. Government. 00015 // 00016 // This library is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU Lesser General Public License as 00018 // published by the Free Software Foundation; either version 2.1 of the 00019 // License, or (at your option) any later version. 00020 // 00021 // This library is distributed in the hope that it will be useful, but 00022 // WITHOUT ANY WARRANTY; without even the implied warranty of 00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 // Lesser General Public License for more details. 00025 // 00026 // You should have received a copy of the GNU Lesser General Public 00027 // License along with this library; if not, write to the Free Software 00028 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00029 // USA 00030 // 00031 // Questions? Contact Roger Pawlowski (rppawlo@sandia.gov) or 00032 // Eric Phipps (etphipp@sandia.gov), Sandia National Laboratories. 00033 // ************************************************************************ 00034 // CVS Information 00035 // $Source: /space/CVS/Trilinos/packages/nox/src-loca/src/LOCA_Solver_Wrapper.C,v $ 00036 // $Author: rppawlo $ 00037 // $Date: 2007/08/01 20:50:41 $ 00038 // $Revision: 1.12 $ 00039 // ************************************************************************ 00040 //@HEADER 00041 00042 #include "LOCA_Solver_Wrapper.H" // class definition 00043 #include "LOCA_MultiContinuation_AbstractGroup.H" 00044 #include "LOCA_Extended_MultiAbstractGroup.H" 00045 00046 LOCA::Solver::Wrapper:: 00047 Wrapper(const Teuchos::RCP<NOX::Solver::Generic>& solver) : 00048 solverPtr(solver), 00049 constSolverPtr(solver) 00050 { 00051 resetWrapper(); 00052 } 00053 00054 LOCA::Solver::Wrapper:: 00055 Wrapper(const Teuchos::RCP<const NOX::Solver::Generic>& solver) : 00056 solverPtr(Teuchos::null), 00057 constSolverPtr(solver) 00058 { 00059 resetWrapper(); 00060 } 00061 00062 LOCA::Solver::Wrapper::~Wrapper() 00063 { 00064 } 00065 00066 void 00067 LOCA::Solver::Wrapper:: 00068 reset(const NOX::Abstract::Vector& initialGuess, 00069 const Teuchos::RCP<NOX::StatusTest::Generic>& tests) 00070 { 00071 solverPtr->reset(initialGuess, tests); 00072 resetWrapper(); 00073 } 00074 00075 void 00076 LOCA::Solver::Wrapper:: 00077 reset(const NOX::Abstract::Vector& initialGuess) 00078 { 00079 solverPtr->reset(initialGuess); 00080 resetWrapper(); 00081 } 00082 00083 NOX::StatusTest::StatusType 00084 LOCA::Solver::Wrapper::getStatus() 00085 { 00086 return solverPtr->getStatus(); 00087 } 00088 00089 NOX::StatusTest::StatusType 00090 LOCA::Solver::Wrapper::step() 00091 { 00092 NOX::StatusTest::StatusType status = solverPtr->step(); 00093 resetWrapper(); 00094 return status; 00095 } 00096 00097 NOX::StatusTest::StatusType 00098 LOCA::Solver::Wrapper::solve() 00099 { 00100 NOX::StatusTest::StatusType status = solverPtr->solve(); 00101 resetWrapper(); 00102 return status; 00103 } 00104 00105 const NOX::Abstract::Group& 00106 LOCA::Solver::Wrapper::getSolutionGroup() const 00107 { 00108 return *solnGrpPtr; 00109 } 00110 00111 const NOX::Abstract::Group& 00112 LOCA::Solver::Wrapper::getPreviousSolutionGroup() const 00113 { 00114 return *oldSolnGrpPtr; 00115 } 00116 00117 int 00118 LOCA::Solver::Wrapper::getNumIterations() const 00119 { 00120 return constSolverPtr->getNumIterations(); 00121 } 00122 00123 const Teuchos::ParameterList& 00124 LOCA::Solver::Wrapper::getList() const 00125 { 00126 return constSolverPtr->getList(); 00127 } 00128 00129 void 00130 LOCA::Solver::Wrapper::resetWrapper() 00131 { 00132 // Get current and old solution groups 00133 const NOX::Abstract::Group& soln = constSolverPtr->getSolutionGroup(); 00134 const NOX::Abstract::Group& oldSoln = 00135 constSolverPtr->getPreviousSolutionGroup(); 00136 00137 const LOCA::Extended::MultiAbstractGroup* eGrpPtr; 00138 const LOCA::Extended::MultiAbstractGroup* oldEGrpPtr; 00139 00140 // Cast soln group to an extended group 00141 eGrpPtr = dynamic_cast<const LOCA::Extended::MultiAbstractGroup*>(&soln); 00142 00143 if (eGrpPtr == NULL) { 00144 // soln group is not extended, so set points to original groups 00145 solnGrpPtr = Teuchos::rcp(&soln, false); 00146 oldSolnGrpPtr = Teuchos::rcp(&oldSoln, false); 00147 } 00148 00149 else { 00150 // soln group is extended so get underlying groups 00151 oldEGrpPtr = 00152 dynamic_cast<const LOCA::Extended::MultiAbstractGroup*>(&oldSoln); 00153 solnGrpPtr = eGrpPtr->getUnderlyingGroup(); 00154 oldSolnGrpPtr = oldEGrpPtr->getUnderlyingGroup(); 00155 } 00156 00157 return; 00158 }