FEI Version of the Day
fei_Factory_Aztec.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // 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 Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #include "fei_trilinos_macros.hpp"
00045 
00046 #include <fei_Factory_Aztec.hpp>
00047 
00048 #include <fei_VectorReducer.hpp>
00049 #include <fei_MatrixReducer.hpp>
00050 
00051 Factory_Aztec::Factory_Aztec(MPI_Comm comm)
00052   : fei::Factory(comm),
00053     comm_(comm),
00054     reducer_(),
00055     blockEntryMatrix_(false),
00056     outputLevel_(0)
00057 {
00058 }
00059 
00060 Factory_Aztec::~Factory_Aztec()
00061 {
00062 }
00063 
00064 int Factory_Aztec::parameters(int numParams,
00065                                   const char* const* paramStrings)
00066 {
00067   std::vector<std::string> stdstrings;
00068   fei::utils::char_ptrs_to_strings(numParams, paramStrings, stdstrings);
00069 
00070   fei::ParameterSet paramset;
00071   fei::utils::parse_strings(stdstrings, " ", paramset);
00072 
00073   parameters(paramset);
00074   return(0);
00075 }
00076 
00077 void Factory_Aztec::parameters(const fei::ParameterSet& parameterset)
00078 {
00079   fei::Factory::parameters(parameterset);
00080 
00081   parameterset.getIntParamValue("outputLevel", outputLevel_);
00082 
00083   bool blkGraph = false;
00084   bool blkMatrix = false;
00085 
00086   parameterset.getBoolParamValue("BLOCK_GRAPH", blkGraph);
00087   parameterset.getBoolParamValue("BLOCK_MATRIX", blkMatrix);
00088 
00089   blockEntryMatrix_ = (blkGraph || blkMatrix);
00090 }
00091 
00092 fei::SharedPtr<fei::MatrixGraph>
00093 Factory_Aztec::createMatrixGraph(fei::SharedPtr<fei::VectorSpace> rowSpace,
00094                       fei::SharedPtr<fei::VectorSpace> colSpace,
00095                       const char* name)
00096 {
00097   static fei::MatrixGraph_Impl2::Factory factory2;
00098   return factory2.createMatrixGraph(rowSpace, colSpace, name);
00099 }
00100 
00101 fei::SharedPtr<fei::Vector>
00102 Factory_Aztec::createVector(fei::SharedPtr<fei::VectorSpace> vecSpace,
00103                                bool isSolutionVector,
00104                                int numVectors)
00105 {
00106   std::vector<int> indices;
00107   int err = 0, localSize = 0;
00108   if (reducer_.get() != NULL) {
00109     indices = reducer_->getLocalReducedEqns();
00110     localSize = indices.size();
00111   }
00112   else {
00113     if (blockEntryMatrix_) {
00114       localSize = vecSpace->getNumBlkIndices_Owned();
00115       indices.resize(localSize*2);
00116       err = vecSpace->getBlkIndices_Owned(localSize, &indices[0], &indices[localSize], localSize);
00117     }
00118     else {
00119       localSize = vecSpace->getNumIndices_Owned();
00120       err = vecSpace->getIndices_Owned(indices);
00121     }
00122   }
00123   if (err != 0) {
00124     throw std::runtime_error("fei::Factory_Aztec: error in vecSpace->getIndices_Owned");
00125   }
00126 
00127   fei::SharedPtr<fei::Vector> feivec, tmpvec;
00128 
00129   if (reducer_.get() != NULL) {
00130     feivec.reset(new fei::VectorReducer(reducer_,
00131                                         tmpvec, isSolutionVector));
00132   }
00133   else {
00134     feivec = tmpvec;
00135   }
00136 
00137   return(feivec);
00138 }
00139 
00140 fei::SharedPtr<fei::Vector>
00141 Factory_Aztec::createVector(fei::SharedPtr<fei::VectorSpace> vecSpace,
00142                                int numVectors)
00143 {
00144   bool isSolnVector = false;
00145   return(createVector(vecSpace, isSolnVector, numVectors));
00146 }
00147 
00148 fei::SharedPtr<fei::Vector>
00149 Factory_Aztec::createVector(fei::SharedPtr<fei::MatrixGraph> matrixGraph,
00150                               int numVectors)
00151 {
00152   bool isSolnVector = false;
00153   return(createVector(matrixGraph, isSolnVector, numVectors));
00154 }
00155 
00156 fei::SharedPtr<fei::Vector>
00157 Factory_Aztec::createVector(fei::SharedPtr<fei::MatrixGraph> matrixGraph,
00158                                bool isSolutionVector,
00159                                int numVectors)
00160 {
00161   int globalNumSlaves = matrixGraph->getGlobalNumSlaveConstraints();
00162 
00163   if (globalNumSlaves > 0 && reducer_.get()==NULL) {
00164     reducer_ = matrixGraph->getReducer();
00165   }
00166 
00167   fei::SharedPtr<fei::Vector> feivec, tmpvec;
00168 
00169   std::vector<int> indices;
00170   int err = 0, localSize;
00171   fei::SharedPtr<fei::VectorSpace> vecSpace = matrixGraph->getRowSpace();
00172   if (reducer_.get() != NULL) {
00173     indices = reducer_->getLocalReducedEqns();
00174     localSize = indices.size();
00175   }
00176   else {
00177     localSize = vecSpace->getNumIndices_Owned();
00178     indices.resize(localSize);
00179     err = vecSpace->getIndices_Owned(indices);
00180   }
00181   if (err != 0) {
00182     throw std::runtime_error("error in vecSpace->getIndices_Owned");
00183   }
00184 
00185   if (reducer_.get() != NULL) {
00186     feivec.reset(new fei::VectorReducer(reducer_, tmpvec, isSolutionVector));
00187   }
00188   else {
00189     feivec = tmpvec;
00190   }
00191 
00192   return(feivec);
00193 }
00194 
00195 fei::SharedPtr<fei::Matrix>
00196 Factory_Aztec::createMatrix(fei::SharedPtr<fei::MatrixGraph> matrixGraph)
00197 {
00198   fei::SharedPtr<fei::Matrix> feimat;
00199   int globalNumSlaves = matrixGraph->getGlobalNumSlaveConstraints();
00200 
00201   if (globalNumSlaves > 0 && reducer_.get()==NULL) {
00202     reducer_ = matrixGraph->getReducer();
00203   }
00204 
00205   return feimat;
00206 }
00207 
00208 fei::SharedPtr<fei::Solver>
00209 Factory_Aztec::createSolver(const char* name)
00210 {
00211   fei::SharedPtr<fei::Solver> solver;
00212   return(solver);
00213 }
00214 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends