FEI Version of the Day
fei_FEDataFilter.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 _fei_FEDataFilter_hpp_
00044 #define _fei_FEDataFilter_hpp_
00045 
00046 
00047 #include "fei_fwd.hpp"
00048 #include "fei_defs.h"
00049 #include "fei_Filter.hpp"
00050 
00061 class FEDataFilter : public Filter {
00062 
00063  public:
00064    // Constructor.
00065    FEDataFilter(FEI_Implementation* owner, MPI_Comm comm,
00066                 SNL_FEI_Structure* probStruct,
00067                 LibraryWrapper* wrapper,
00068                 int masterRank=0);
00069 
00070    //Destructor
00071    virtual ~FEDataFilter();
00072 
00073 
00074    // set a value (usually zeros) throughout the linear system
00075    int resetSystem(double s);
00076    int resetMatrix(double s);
00077    int resetRHSVector(double s);
00078    int resetInitialGuess(double s);
00079 
00080    int deleteMultCRs();
00081 
00082    int loadNodeBCs(int numNodes,
00083                    const GlobalID *nodeIDs,
00084                    int fieldID,
00085                    const int* offsetsIntoField,
00086                    const double* prescribedValues);
00087 
00088    int loadElemBCs(int numElems,
00089                    const GlobalID *elemIDs,
00090                    int fieldID,
00091                    const double *const *alpha,  
00092                    const double *const *beta,  
00093                    const double *const *gamma);
00094 
00095    int sumInElem(GlobalID elemBlockID,
00096                  GlobalID elemID,
00097                  const GlobalID* elemConn,
00098                  const double* const* elemStiffness,
00099                  const double* elemLoad,
00100                  int elemFormat);
00101 
00102    int sumInElemMatrix(GlobalID elemBlockID,
00103                        GlobalID elemID,
00104                        const GlobalID* elemConn,
00105                        const double* const* elemStiffness,
00106                        int elemFormat);
00107 
00108    int sumInElemRHS(GlobalID elemBlockID,
00109                     GlobalID elemID,
00110                     const GlobalID* elemConn,
00111                     const double* elemLoad);
00112 
00113     int loadCRMult(int CRMultID, 
00114                    int numCRNodes,
00115                    const GlobalID* CRNodes, 
00116                    const int* CRFields,
00117                    const double* CRWeights,
00118                    double CRValue);
00119 
00120     int loadCRPen(int CRPenID, 
00121                   int numCRNodes, 
00122                   const GlobalID* CRNodes,
00123                   const int *CRFields,
00124                   const double* CRWeights,
00125                   double CRValue,
00126                   double penValue);
00127 
00128    int putIntoRHS(int IDType,
00129                   int fieldID,
00130                           int numIDs,
00131                   const GlobalID* IDs,
00132                   const double* rhsEntries);
00133 
00134    int sumIntoRHS(int IDType,
00135                   int fieldID,
00136                           int numIDs,
00137                   const GlobalID* IDs,
00138                   const double* rhsEntries);
00139 
00140    int sumIntoMatrixDiagonal(int  IDType,
00141                              int  fieldID,
00142                              int  numIDs,
00143                              const GlobalID*  IDs,
00144                              const double*  coefficients);
00145 
00146    int loadComplete();
00147 
00148     // set parameters associated with solver choice, etc.
00149     int parameters(int numParams, const char *const* paramStrings);
00150 
00151     //get residual norms
00152     int residualNorm(int whichNorm, int numFields,
00153                      int* fieldIDs, double* norms, double& residTime);
00154 
00155     // start iterative solution
00156     int solve(int& status, double& sTime);
00157 
00158     // query function iterations performed.
00159     int iterations() const {return(iterations_);};
00160 
00161 // Solution return services.......................................
00162  
00163     // return all nodal solution params on a block-by-block basis 
00164     int getBlockNodeSolution(GlobalID elemBlockID,  
00165                              int numNodes, 
00166                              const GlobalID *nodeIDs, 
00167                              int *offsets,
00168                              double *results);
00169  
00170     int getNodalSolution(int numNodes, 
00171                          const GlobalID *nodeIDs, 
00172                          int *offsets,
00173                          double *results);
00174 
00175     // return nodal solution for one field on a block-by-block basis 
00176     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00177                                   int fieldID,
00178                                   int numNodes, 
00179                                   const GlobalID *nodeIDs, 
00180                                   double *results);
00181          
00182     // return element solution params on a block-by-block basis 
00183     int getBlockElemSolution(GlobalID elemBlockID,  
00184                              int numElems, 
00185                              const GlobalID *elemIDs,
00186                              int& numElemDOFPerElement,
00187                              double *results);
00188 
00189    int getCRMultipliers(int numCRs, const int* CRIDs, double* multipliers);
00190 
00191 // associated "puts" paralleling the solution return services.
00192 // 
00193 // the int sizing parameters are passed for error-checking purposes, so
00194 // that the interface implementation can tell if the passed estimate
00195 // vectors make sense -before- an attempt is made to utilize them as
00196 // initial guesses by unpacking them into the solver's native solution
00197 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00198 // numElemDOF, and numMultCRs -- all other passed params are either 
00199 // vectors or block/constraint-set IDs)
00200 
00201    // put nodal-based solution guess on a block-by-block basis 
00202    int putBlockNodeSolution(GlobalID elemBlockID,
00203                             int numNodes,
00204                             const GlobalID *nodeIDs, 
00205                             const int *offsets,
00206                             const double *estimates);
00207 
00208     // put nodal-based guess for one field on a block-by-block basis 
00209     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00210                                   int fieldID, 
00211                                   int numNodes, 
00212                                   const GlobalID *nodeIDs, 
00213                                   const double *estimates);
00214          
00215     // put element-based solution guess on a block-by-block basis  
00216     int putBlockElemSolution(GlobalID elemBlockID,  
00217                              int numElems, 
00218                              const GlobalID *elemIDs, 
00219                              int dofPerElem,
00220                              const double *estimates);
00221   
00222     int putCRMultipliers(int numMultCRs, 
00223                          const int* CRIDs,
00224                          const double *multEstimates);
00225 
00226 //===== a couple of public non-FEI functions... ================================
00227 //These are intended to be used by an 'outer-layer' class like 
00228 //FEI_Implementation.
00229 //
00230   public:
00231     int getNodalFieldSolution(int fieldID,
00232                               int numNodes,
00233                               const GlobalID* nodeIDs,
00234                               double* results);
00235 
00236     int putNodalFieldData(int fieldID,
00237                           int numNodes,
00238                           const GlobalID* nodeIDs,
00239                           const double* nodeData);
00240 
00241     int putNodalFieldSolution(int fieldID,
00242                               int numNodes,
00243                               const GlobalID* nodeIDs,
00244                               const double* nodeData);
00245 
00246     int unpackSolution();
00247 
00248     void setEqnCommMgr(EqnCommMgr* eqnCommMgr);
00249 
00250    EqnCommMgr* getEqnCommMgr() {return(eqnCommMgr_);};
00251 
00252    int setNumRHSVectors(int numRHSs, int* rhsIDs);
00253    int setCurrentRHS(int rhsID);
00254 
00255    int enforceEssentialBCs(const int* eqns, const double* alpha,
00256                                   const double* gamma, int numEqns);
00257 
00258    int initialize();
00259 
00260 //==============================================================================
00261 //private functions for internal implementation of FEDataFilter.
00262 //==============================================================================
00263   private:
00264    FEDataFilter(const FEDataFilter& src);
00265    FEDataFilter& operator=(const FEDataFilter& src);
00266 
00267    int initLinSysCore();
00268 
00269    int loadFEDataMultCR(int CRID,
00270                         int numCRNodes,
00271                         const GlobalID* CRNodes, 
00272                         const int* CRFields,
00273                         const double* CRWeights,
00274                         double CRValue);
00275 
00276    int loadFEDataPenCR(int CRID,
00277                        int numCRNodes,
00278                        const GlobalID* CRNodes, 
00279                        const int* CRFields,
00280                        const double* CRWeights,
00281                        double CRValue,
00282                        double penValue);
00283 
00284    int generalElemInput(GlobalID elemBlockID,
00285                         GlobalID elemID,
00286                         const double* const* elemStiffness,
00287                         const double* elemLoad,
00288                         int elemFormat);
00289 
00290    int generalElemInput(GlobalID elemBlockID,
00291                         GlobalID elemID,
00292                         const GlobalID* elemConn,
00293                         const double* const* elemStiffness,
00294                         const double* elemLoad,
00295                         int elemFormat);
00296 
00297    void allocElemStuff();
00298 
00299    int giveToMatrix(int numPtRows, const int* ptRows,
00300                     int numPtCols, const int* ptCols,
00301                     const double* const* values,
00302                     int mode);
00303 
00304    int giveToLocalReducedMatrix(int numPtRows, const int* ptRows,
00305                                 int numPtCols, const int* ptCols,
00306                                 const double* const* values,
00307                                 int mode);
00308 
00309    int getFromMatrix(int numPtRows, const int* ptRows,
00310                      const int* rowColOffsets, const int* ptCols,
00311                      int numColsPerRow, double** values);
00312 
00313    int getEqnsFromMatrix(ProcEqns& procEqns, EqnBuffer& eqnData);
00314 
00315    int getEqnsFromRHS(ProcEqns& procEqns, EqnBuffer& eqnData);
00316 
00317    int giveToRHS(int num, const double* values,
00318                  const int* indices, int mode);
00319 
00320    int giveToLocalReducedRHS(int num, const double* values,
00321                              const int* indices, int mode);
00322 
00323    int getFromRHS(int num, double* values, const int* indices);
00324 
00325    int getEqnSolnEntry(int eqnNumber, double& solnValue);
00326 
00327    int getSharedRemoteSolnEntry(int eqnNumber, double& solnValue);
00328 
00329    int getReducedSolnEntry(int eqnNumber, double& solnValue);
00330 
00331    int formResidual(double* residValues, int numLocalEqns);
00332 
00333    int getRemoteSharedEqns(int numPtRows, const int* ptRows,
00334                            ProcEqns& remoteProcEqns);
00335 
00336    int resetTheMatrix(double s);
00337    int resetTheRHSVector(double s);
00338 
00339    int assembleEqns(int numPtRows, 
00340                     int numPtCols,
00341                     const int* rowNumbers,
00342                     const int* colIndices,
00343                     const double* const* coefs,
00344                     bool structurallySymmetric,
00345                     int mode);
00346 
00347    int assembleRHS(int numValues, const int* indices, const double* coefs, int mode);
00348 
00349    void debugOutput(const char* mesg);
00350 
00351    int createEqnCommMgr_put();
00352 
00353 //==============================================================================
00354 //private FEDataFilter variables
00355 //==============================================================================
00356   private:
00357 
00358     LibraryWrapper* wrapper_;
00359     fei::SharedPtr<FiniteElementData> feData_;
00360     bool useLookup_;
00361 
00362     int internalFei_;
00363 
00364     bool newData_;
00365 
00366     int localStartRow_, localEndRow_, numGlobalEqns_;
00367     int reducedStartRow_, reducedEndRow_, numReducedRows_;
00368 
00369     int iterations_;
00370     int numRHSs_;
00371     int currentRHS_;
00372     std::vector<int> rhsIDs_;
00373 
00374     int outputLevel_;
00375 
00376     MPI_Comm comm_;
00377     int masterRank_;
00378 
00379     SNL_FEI_Structure* problemStructure_;
00380 
00381     std::vector<GlobalID> penCRIDs_;
00382 
00383     std::vector<int> rowIndices_;
00384     std::vector<int> rowColOffsets_, colIndices_;
00385 
00386     EqnCommMgr* eqnCommMgr_; //equation communication manager
00387     EqnCommMgr* eqnCommMgr_put_; //only created if users call
00388                                  // the 'put' functions
00389 
00390     int maxElemRows_;
00391 
00392     double** eStiff_;
00393     double* eStiff1D_;
00394     double* eLoad_;
00395 
00396     int numRegularElems_;
00397     std::vector<int> constraintBlocks_;
00398     std::vector<int> constraintNodeOffsets_;
00399     std::vector<int> packedFieldSizes_;
00400 };
00401 
00402 #endif
00403 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends