PlayaIfpackILUOperator.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                 Playa: Programmable Linear Algebra
00005 //                 Copyright 2012 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #include "PlayaIfpackILUOperator.hpp"
00043 #include "Teuchos_Array.hpp"
00044 #include "PlayaMPIComm.hpp"
00045 #include "PlayaEpetraVector.hpp"
00046 
00047 
00048 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00049 #include "PlayaVectorImpl.hpp"
00050 #include "PlayaLinearOperatorImpl.hpp"
00051 #endif
00052 
00053 namespace Playa
00054 {
00055 
00056 using namespace Teuchos;
00057 
00058 IfpackILUOperator::IfpackILUOperator(const EpetraMatrix* A,
00059   int fillLevels,
00060   int overlapFill,
00061   double relaxationValue,
00062   double relativeThreshold,
00063   double absoluteThreshold)
00064   : LinearOpWithSpaces<double>(A->domain(), A->range()),
00065     precondGraph_(),
00066     precond_()
00067 {
00068   const Epetra_CrsMatrix* matrix = A->crsMatrix();
00069 
00070   const Epetra_CrsGraph& matrixGraph = matrix->Graph();
00071       
00072   Ifpack_IlukGraph* precondGraph 
00073     = new Ifpack_IlukGraph(matrixGraph, fillLevels, overlapFill);
00074   precondGraph_ = rcp(precondGraph);
00075 
00076   int ierr = precondGraph->ConstructFilledGraph();
00077 
00078   TEUCHOS_TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00079     "IfpackOperator ctor: "
00080     "precondGraph->ConstructFilledGraph() failed with ierr="
00081     << ierr);
00082 
00083   Ifpack_CrsRiluk* precond = new Ifpack_CrsRiluk(*precondGraph);
00084   precond_ = rcp(precond);
00085 
00086   precond->SetRelaxValue(relaxationValue);
00087   precond->SetRelativeThreshold(relativeThreshold);
00088   precond->SetAbsoluteThreshold(absoluteThreshold);
00089 
00090   ierr = precond->InitValues(*matrix);
00091 
00092   TEUCHOS_TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00093     "IfpackOperator ctor: "
00094     "precond->InitValues() failed with ierr="
00095     << ierr);
00096 
00097   ierr = precond->Factor();
00098 
00099   TEUCHOS_TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00100     "IfpackOperator ctor: "
00101     "precond->Factor() failed with ierr="
00102     << ierr);
00103 }
00104 
00105 void IfpackILUOperator::apply(Teuchos::ETransp transApplyType,
00106   const Vector<double>& in,
00107   Vector<double> out) const
00108 {
00109   /* grab the epetra vector objects underlying the input and output vectors */
00110   const Epetra_Vector& epIn = EpetraVector::getConcrete(in);
00111   Epetra_Vector& epOut = EpetraVector::getConcrete(out);
00112 
00113   /* ifpack's solve is logically const but declared non-const because
00114    *  internal data changes. So, do a const_cast. */
00115   Ifpack_CrsRiluk* p = const_cast<Ifpack_CrsRiluk*>(precond_.get());
00116 
00117   int ierr;
00118 
00119   /* do the solve (or transpose solve) */
00120   if (transApplyType==NO_TRANS)
00121   {
00122     ierr = p->Solve(false, epIn, epOut);
00123   }
00124   else
00125   {
00126     ierr = p->Solve(true, epIn, epOut);
00127   }
00128   TEUCHOS_TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00129            "Playa::IfpackILUOperator apply: "
00130            "p->Solve() (transpose state="
00131            << transApplyType << ") failed with ierr="
00132            << ierr);
00133 }
00134   
00135 }

Site Contact