FEI Version of the Day
fei_Filter.hpp
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 #ifndef _Filter_hpp_
00044 #define _Filter_hpp_
00045 
00046 
00047 #include <fei_fwd.hpp>
00048 #include <fei_defs.h>
00049 #include <fei_macros.hpp>
00050 #include <fei_iostream.hpp>
00051 
00062 class Filter {
00063 
00064  public:
00066   Filter(SNL_FEI_Structure* probStruct);
00067 
00069   virtual ~Filter();
00070 
00071   virtual int initialize() = 0;
00072 
00073    // set a value (usually zeros) throughout the linear system
00074    virtual int resetSystem(double s) = 0;
00075    virtual int resetMatrix(double s) = 0;
00076    virtual int resetRHSVector(double s) = 0;
00077    virtual int resetInitialGuess(double s) = 0;
00078 
00079    virtual int deleteMultCRs() = 0;
00080 
00081    virtual int loadNodeBCs(int /*numNodes*/,
00082                    const GlobalID* /*nodeIDs*/,
00083                    int /*fieldID*/,
00084                    const int* /*offsetsIntoField*/,
00085                    const double* /*prescribedValues*/)
00086    {
00087       fei::console_out() << "fei ERROR, Filter::loadNodeBCs not overridden."<<FEI_ENDL;
00088       return -1;
00089    }
00090 
00091    virtual int loadElemBCs(int numElems,
00092                    const GlobalID *elemIDs,
00093                    int fieldID,
00094                    const double *const *alpha,  
00095                    const double *const *beta,  
00096                    const double *const *gamma) = 0;
00097 
00098    virtual int sumInElem(GlobalID /*elemBlockID*/,
00099                          GlobalID /*elemID*/,
00100                          const GlobalID* /*elemConn*/,
00101                          const double* const* /*elemStiffness*/,
00102                          const double* /*elemLoad*/,
00103                            int /*elemFormat*/) { return(0); }
00104 
00105    virtual int sumInElemMatrix(GlobalID /*elemBlockID*/,
00106                                GlobalID /*elemID*/,
00107                                const GlobalID* /*elemConn*/,
00108                                const double* const* /*elemStiffness*/,
00109                                int /*elemFormat*/) { return(0); }
00110 
00111    virtual int sumInElemRHS(GlobalID /*elemBlockID*/,
00112                             GlobalID /*elemID*/,
00113                             const GlobalID* /*elemConn*/,
00114                             const double* /*elemLoad*/) { return(0); }
00115 
00116     virtual int loadCRMult(int CRMultID, 
00117                    int numCRNodes,
00118                    const GlobalID* CRNodes, 
00119                    const int* CRFields,
00120                    const double* CRWeights,
00121                    double CRValue) = 0;
00122 
00123     virtual int loadCRPen(int CRPenID, 
00124                   int numCRNodes, 
00125                   const GlobalID* CRNodes,
00126                   const int *CRFields,
00127                   const double* CRWeights,
00128                   double CRValue,
00129                   double penValue) = 0;
00130 
00131    virtual int putIntoRHS(int IDType,
00132                   int fieldID,
00133                           int numIDs,
00134                   const GlobalID* IDs,
00135                   const double* rhsEntries) = 0;
00136 
00137    virtual int sumIntoRHS(int IDType,
00138                   int fieldID,
00139                           int numIDs,
00140                   const GlobalID* IDs,
00141                   const double* rhsEntries) = 0;
00142 
00143    virtual int sumIntoMatrixDiagonal(int /* IDType*/,
00144                                      int /* fieldID*/,
00145                                      int /* numIDs*/,
00146                                      const GlobalID* /* IDs*/,
00147                                      const double* /* coefficients*/)
00148    { return -1; }
00149 
00150    virtual int loadComplete() = 0;
00151 
00152     // set parameters associated with solver choice, etc.
00153     virtual int parameters(int numParams, const char *const* paramStrings);
00154 
00155     //get residual norms
00156     virtual int residualNorm(int whichNorm, int numFields,
00157                      int* fieldIDs, double* norms, double& residTime) = 0;
00158 
00159     // start iterative solution
00160     virtual int solve(int& status, double& sTime) = 0;
00161 
00162     // query function iterations performed.
00163     virtual int iterations() const = 0;
00164 
00165 // Solution return services.......................................
00166  
00167     // return all nodal solution params on a block-by-block basis 
00168     virtual int getBlockNodeSolution(GlobalID elemBlockID,  
00169                              int numNodes, 
00170                              const GlobalID *nodeIDs, 
00171                              int *offsets,
00172                              double *results) = 0;
00173  
00174     virtual int getNodalSolution(int numNodes, 
00175                                  const GlobalID *nodeIDs, 
00176                                  int *offsets,
00177                                  double *results) = 0;
00178 
00179     // return nodal solution for one field on a block-by-block basis 
00180     virtual int getBlockFieldNodeSolution(GlobalID elemBlockID,
00181                                   int fieldID,
00182                                   int numNodes, 
00183                                   const GlobalID *nodeIDs, 
00184                                   double *results) = 0;
00185          
00186     // return element solution params on a block-by-block basis 
00187     virtual int getBlockElemSolution(GlobalID elemBlockID,  
00188                              int numElems, 
00189                              const GlobalID *elemIDs,
00190                              int& numElemDOFPerElement,
00191                              double *results) = 0;
00192 
00193    virtual int getCRMultipliers(int numCRs, const int* CRIDs,
00194                                 double* multipliers) = 0;
00195 
00196 // associated "puts" paralleling the solution return services.
00197 // 
00198 // the int sizing parameters are passed for error-checking purposes, so
00199 // that the interface implementation can tell if the passed estimate
00200 // vectors make sense -before- an attempt is made to utilize them as
00201 // initial guesses by unpacking them into the solver's native solution
00202 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00203 // numElemDOF, and numMultCRs -- all other passed params are either 
00204 // vectors or block/constraint-set IDs)
00205 
00206    // put nodal-based solution guess on a block-by-block basis 
00207    virtual int putBlockNodeSolution(GlobalID elemBlockID,
00208                             int numNodes,
00209                             const GlobalID *nodeIDs, 
00210                             const int *offsets,
00211                             const double *estimates) = 0;
00212 
00213     // put nodal-based guess for one field on a block-by-block basis 
00214     virtual int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00215                                   int fieldID, 
00216                                   int numNodes, 
00217                                   const GlobalID *nodeIDs, 
00218                                   const double *estimates) = 0;
00219   
00220     virtual int putBlockElemSolution(GlobalID elemBlockID,  
00221                                      int numElems, 
00222                                      const GlobalID *elemIDs, 
00223                                      int dofPerElem,
00224                                      const double *estimates) = 0;
00225   
00226     virtual int putCRMultipliers(int numMultCRs, 
00227                          const int* CRIDs,
00228                          const double *multEstimates) = 0;
00229 
00230 //===== a couple of public non-FEI functions... ================================
00231 //These are intended to be used by an 'outer-layer' class like 
00232 //FEI_Implementation.
00233 //
00234   public:
00235 
00236     virtual int getNodalFieldSolution(int fieldID,
00237                               int numNodes,
00238                               const GlobalID* nodeIDs,
00239                               double* results) = 0;
00240 
00241     virtual int putNodalFieldData(int fieldID,
00242                           int numNodes,
00243                           const GlobalID* nodeIDs,
00244                           const double* nodeData) = 0;
00245 
00246     virtual int putNodalFieldSolution(int fieldID,
00247                               int numNodes,
00248                               const GlobalID* nodeIDs,
00249                               const double* nodeData) = 0;
00250 
00251     virtual int unpackSolution() = 0;
00252 
00253     virtual void setEqnCommMgr(EqnCommMgr* eqnCommMgr) = 0;
00254 
00255    virtual EqnCommMgr* getEqnCommMgr() = 0;
00256 
00257    virtual int setNumRHSVectors(int numRHSs, int* rhsIDs) = 0;
00258    virtual int setCurrentRHS(int rhsID) = 0;
00259 
00260    virtual int exchangeRemoteEquations() { return 0; }
00261 
00262    virtual int enforceEssentialBCs(const int* eqns, const double* alpha,
00263                                   const double* gamma, int numEqns) = 0;
00264 
00265    static void copyStiffness(const double* const* elemStiff, int numRows,
00266                              int elemFormat, double** copy);
00267 
00268    void setLogStream(std::ostream* logstrm);
00269    std::ostream* logStream();
00270 
00271  protected:
00272    virtual int generalElemInput(GlobalID /*elemBlockID*/,
00273                                 GlobalID /*elemID*/,
00274                                 const GlobalID* /*elemConn*/,
00275                                 const double* const* /*elemStiffness*/,
00276                                 const double* /*elemLoad*/,
00277                                   int /*elemFormat*/) {return(-1);}
00278 
00279    int generalCoefInput(int /*patternID*/,
00280                         const int* /*rowIDTypes*/,
00281                         const GlobalID* /*rowIDs*/,
00282                         const int* /*colIDTypes*/,
00283                         const GlobalID* /*colIDs*/,
00284                         const double* const* /*matrixEntries*/,
00285                         const double* /*vectorEntries*/,
00286                           int /*numRows*/, int /*numCols*/) {return(-1);}
00287 
00288    int calculateResidualNorms(int whichNorm, int numFields,
00289                               int* fieldIDs, double* norms,
00290                               std::vector<double>& residValues);
00291 
00292    const NodeDescriptor* findNode(GlobalID nodeID) const;
00293    const NodeDescriptor& findNodeDescriptor(GlobalID nodeID) const;
00294 
00295    SNL_FEI_Structure* problemStructure_;
00296 
00297    bool logInput_;
00298    std::ostream* logInputStream_;
00299 
00300    int outputLevel_;
00301 
00302    int numProcs_;
00303    int localRank_;
00304 
00305  private:
00306    Filter(const Filter& /*src*/)
00307      : problemStructure_(NULL), logInput_(false), logInputStream_(NULL),
00308      outputLevel_(0), numProcs_(0), localRank_(0)
00309      {}
00310 
00311    Filter& operator=(const Filter& /*src*/)
00312      {
00313        return(*this);
00314      }
00315 };
00316 
00317 #endif
00318 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends