00001 //@HEADER 00002 // ************************************************************************ 00003 // 00004 // NOX: An Object-Oriented Nonlinear Solver Package 00005 // Copyright (2002) Sandia Corporation 00006 // 00007 // LOCA: Library of Continuation Algorithms Package 00008 // Copyright (2005) Sandia Corporation 00009 // 00010 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00011 // license for use of this work by or on behalf of the U.S. Government. 00012 // 00013 // This library is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU Lesser General Public License as 00015 // published by the Free Software Foundation; either version 2.1 of the 00016 // License, or (at your option) any later version. 00017 // 00018 // This library is distributed in the hope that it will be useful, but 00019 // WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 // Lesser General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU Lesser General Public 00024 // License along with this library; if not, write to the Free Software 00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00026 // USA 00027 // 00028 // Questions? Contact Roger Pawlowski (rppawlo@sandia.gov) or 00029 // Eric Phipps (etphipp@sandia.gov), Sandia National Laboratories. 00030 // ************************************************************************ 00031 // CVS Information 00032 // $Source: /space/CVS/Trilinos/packages/nox/src/NOX_Multiphysics_Group.C,v $ 00033 // $Author: rppawlo $ 00034 // $Date: 2007/08/01 20:50:40 $ 00035 // $Revision: 1.7 $ 00036 // ************************************************************************ 00037 //@HEADER 00038 00039 #include "NOX_Multiphysics_Group.H" 00040 00041 NOX::Multiphysics::Group::Group( 00042 const Teuchos::RCP< vector<Teuchos::RCP<NOX::Solver::Generic> > >& solvers, 00043 const Teuchos::RCP<NOX::StatusTest::Generic>& t, 00044 const Teuchos::RCP<Teuchos::ParameterList>& p) : 00045 solversVecPtr(solvers), 00046 normRHS(0.0) 00047 { 00048 // Create our version of the composite solution vector 00049 vector<const NOX::Abstract::Vector*> vecPtrs; 00050 00051 for( unsigned int i = 0; i < solvers->size(); ++i ) 00052 { 00053 cout << " .. .. .. received solver # " << i << endl; 00054 vecPtrs.push_back( &((*solvers)[i]->getSolutionGroup().getX()) ); 00055 } 00056 00057 resetIsValid(); 00058 } 00059 00060 NOX::Multiphysics::Group::Group( const Group & source, NOX::CopyType type ) 00061 { 00062 switch (type) 00063 { 00064 case DeepCopy: 00065 00066 isValidRHS = source.isValidRHS; 00067 normRHS = source.normRHS; 00068 00069 break; 00070 00071 case ShapeCopy: 00072 resetIsValid(); 00073 break; 00074 00075 default: 00076 cerr << "ERROR: Invalid ConstructorType for group copy constructor." << endl; 00077 throw "NOX Error"; 00078 } 00079 } 00080 00081 NOX::Multiphysics::Group::~Group() 00082 { 00083 } 00084 00085 void 00086 NOX::Multiphysics::Group::resetIsValid() 00087 { 00088 isValidRHS = false; 00089 return; 00090 } 00091 00092 NOX::Abstract::Group & 00093 NOX::Multiphysics::Group::operator=(const NOX::Abstract::Group& source) 00094 { 00095 return operator=(dynamic_cast<const NOX::Multiphysics::Group&> (source)); 00096 } 00097 00098 NOX::Abstract::Group & 00099 NOX::Multiphysics::Group::operator=(const Group& source) 00100 { 00101 return *this; 00102 } 00103 00104 void 00105 NOX::Multiphysics::Group::setX(const NOX::Abstract::Vector& y) 00106 { 00107 resetIsValid(); 00108 } 00109 00110 void 00111 NOX::Multiphysics::Group::computeX(const NOX::Abstract::Group& grp, 00112 const NOX::Abstract::Vector& d, double step) 00113 { 00114 resetIsValid(); 00115 } 00116 00117 NOX::Abstract::Group::ReturnType 00118 NOX::Multiphysics::Group::computeF() 00119 { 00120 NOX::Abstract::Group::ReturnType status; 00121 00122 for( unsigned int i = 0; i < (*solversVecPtr).size(); ++i ) 00123 { 00124 status = const_cast<NOX::Abstract::Group&>((*solversVecPtr)[i]->getSolutionGroup()).computeF(); 00125 if( NOX::Abstract::Group::Ok != status ) 00126 return status; 00127 } 00128 00129 isValidRHS = true; 00130 00131 // Compute the composite normF 00132 normRHS = 0; 00133 00134 for( unsigned int i = 0; i < (*solversVecPtr).size(); ++i ) 00135 normRHS += (*solversVecPtr)[i]->getSolutionGroup().getNormF() * 00136 (*solversVecPtr)[i]->getSolutionGroup().getNormF() ; 00137 normRHS = sqrt(normRHS); 00138 00139 return NOX::Abstract::Group::Ok; 00140 } 00141 00142 bool 00143 NOX::Multiphysics::Group::isF() const 00144 { 00145 return isValidRHS; 00146 } 00147 00148 const NOX::Abstract::Vector& 00149 NOX::Multiphysics::Group::getX() const 00150 { 00151 return (*solversVecPtr)[0]->getSolutionGroup().getX(); 00152 } 00153 00154 const NOX::Abstract::Vector& 00155 NOX::Multiphysics::Group::getF() const 00156 { 00157 return (*solversVecPtr)[0]->getSolutionGroup().getX(); 00158 } 00159 00160 const NOX::Abstract::Vector& 00161 NOX::Multiphysics::Group::getGradient() const 00162 { 00163 return (*solversVecPtr)[0]->getSolutionGroup().getX(); 00164 } 00165 00166 const NOX::Abstract::Vector& 00167 NOX::Multiphysics::Group::getNewton() const 00168 { 00169 return (*solversVecPtr)[0]->getSolutionGroup().getX(); 00170 } 00171 00172 double 00173 NOX::Multiphysics::Group::getNormF() const 00174 { 00175 if (!isF()) { 00176 cerr << "ERROR: NOX::Epetra::Group::getNormF() - invalid RHS" << endl; 00177 throw "NOX Error"; 00178 } 00179 00180 return normRHS; 00181 00182 } 00183 00184 Teuchos::RCP<NOX::Abstract::Group> 00185 NOX::Multiphysics::Group::clone(NOX::CopyType type) const 00186 { 00187 Teuchos::RCP<NOX::Abstract::Group> newgrp = 00188 Teuchos::rcp(new NOX::Multiphysics::Group(*this, type)); 00189 00190 return newgrp; 00191 }