FEI Version of the Day
FEI_Implementation.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_Implementation_hpp_
00044 #define _FEI_Implementation_hpp_
00045 
00046 
00047 #include <fei_fwd.hpp>
00048 #include <fei_mpi.h>
00049 #include <fei_SharedPtr.hpp>
00050 #include <fei_defs.h>
00051 
00052 #include <FEI.hpp>
00053 
00085 class FEI_Implementation : public FEI {
00086 
00087  public:
00097    FEI_Implementation(fei::SharedPtr<LibraryWrapper> libWrapper,
00098                       MPI_Comm comm,
00099                       int masterRank=0);
00100 
00102    virtual ~FEI_Implementation();
00103 
00104 //public FEI functions:
00105 
00106 
00115    int parameters(int numParams, const char *const* paramStrings);
00116 
00117 //Structural initialization functions.............................
00118 
00134    int setIDLists(int numMatrices,
00135                   const int* matrixIDs,
00136                   int numRHSs,
00137                   const int* rhsIDs);
00138 
00147    int setSolveType(int solveType);
00148 
00163    int initFields(int numFields, 
00164                   const int *fieldSizes, 
00165                   const int *fieldIDs,
00166                   const int *fieldTypes = NULL);
00167 
00189    int initElemBlock(GlobalID elemBlockID,
00190                      int numElements,
00191                      int numNodesPerElement,
00192                      const int* numFieldsPerNode,
00193                      const int* const* nodalFieldIDs,
00194                      int numElemDofFieldsPerElement,
00195                      const int* elemDOFFieldIDs,
00196                      int interleaveStrategy);
00197 
00206   int initElem(GlobalID elemBlockID,
00207                 GlobalID elemID,
00208                 const GlobalID* elemConn);
00209 
00257    int initSlaveVariable(GlobalID slaveNodeID, 
00258                          int slaveFieldID,
00259                          int offsetIntoSlaveField,
00260                          int numMasterNodes,
00261                          const GlobalID* masterNodeIDs,
00262                          const int* masterFieldIDs,
00263                          const double* weights,
00264                          double rhsValue);
00265 
00270    int deleteMultCRs();
00271 
00273    int initSharedNodes(int numSharedNodes,
00274                        const GlobalID *sharedNodeIDs,  
00275                        const int* numProcsPerNode, 
00276                        const int *const *sharingProcIDs);
00277 
00286    int initCRMult(int numCRNodes,
00287                   const GlobalID* CRNodes,
00288                   const int *CRFields,
00289                   int& CRID); 
00290 
00299    int initCRPen(int numCRNodes,
00300                  const GlobalID* CRNodes, 
00301                  const int *CRFields,
00302                  int& CRID); 
00303 
00305    int initComplete();
00306 
00307 // FEI data loading sequence..........................................
00308 
00311    int setCurrentMatrix(int matID);
00312 
00315    int setCurrentRHS(int rhsID);
00316 
00318    int resetSystem(double s=0.0);
00319 
00322    int resetMatrix(double s=0.0);
00323 
00327    int resetRHSVector(double s=0.0);
00328 
00334   int resetInitialGuess(double s=0.0);
00335 
00354     int loadNodeBCs(int numNodes,
00355                     const GlobalID *nodeIDs,
00356                     int fieldID,
00357                     const int* offsetsIntoField,
00358                     const double* prescribedValues);
00359 
00371     int loadElemBCs(int numElems,
00372                     const GlobalID* elemIDs,  
00373                     int fieldID,
00374                     const double *const *alpha,  
00375                     const double *const *beta,  
00376                     const double *const *gamma);
00377 
00393    int sumInElem(GlobalID elemBlockID,
00394                  GlobalID elemID,
00395                  const GlobalID* elemConn,
00396                  const double* const* elemStiffness,
00397                  const double* elemLoad,
00398                  int elemFormat);
00399 
00414    int sumInElemMatrix(GlobalID elemBlockID,
00415                        GlobalID elemID,
00416                        const GlobalID* elemConn,
00417                        const double* const* elemStiffness,
00418                        int elemFormat);
00419 
00428    int sumInElemRHS(GlobalID elemBlockID,
00429                     GlobalID elemID,
00430                     const GlobalID* elemConn,
00431                     const double* elemLoad);
00432 
00442    int loadCRMult(int CRID,
00443                   int numCRNodes,
00444                   const GlobalID* CRNodes,
00445                   const int* CRFields,
00446                   const double* CRWeights,
00447                   double CRValue);
00448 
00459    int loadCRPen(int CRID,
00460                  int numCRNodes,
00461                  const GlobalID* CRNodes,
00462                  const int* CRFields,
00463                  const double* CRWeights,
00464                  double CRValue,
00465                  double penValue);
00466 
00468    int putIntoRHS(int IDType,
00469                   int fieldID,
00470                   int numIDs,
00471                   const GlobalID* IDs,
00472                   const double* rhsEntries);
00473 
00475    int sumIntoRHS(int IDType,
00476                   int fieldID,
00477                   int numIDs,
00478                   const GlobalID* IDs,
00479                   const double* rhsEntries);
00480 
00481    int sumIntoMatrixDiagonal(int IDType,
00482                              int fieldID,
00483                              int numIDs,
00484                              const GlobalID* IDs,
00485                              const double* coefficients);
00486 
00487 // Equation solution services.....................................
00488 
00491    int setMatScalars(int numScalars,
00492                      const int* IDs, 
00493                      const double* scalars);
00494 
00496    int setRHSScalars(int numScalars,
00497                      const int* IDs,
00498                      const double* scalars);
00499 
00502    int loadComplete(bool applyBCs=true,
00503                     bool globalAssemble=true);
00504 
00506    int residualNorm(int whichNorm,
00507                     int numFields,
00508                     int* fieldIDs,
00509                     double* norms);
00510 
00512    int solve(int& status);
00513 
00517    int iterations(int& itersTaken) const;
00518 
00527    int version(const char*& versionString);
00528 
00530    int cumulative_cpu_times(double& initTime,
00531                             double& loadTime,
00532                             double& solveTime,
00533                             double& solnReturnTime);
00534 
00535 // Solution return services.......................................
00536  
00538     int getBlockNodeSolution(GlobalID elemBlockID,  
00539                              int numNodes, 
00540                              const GlobalID *nodeIDs, 
00541                              int *offsets,
00542                              double *results);
00543 
00545     int getNodalSolution(int numNodes,
00546                          const GlobalID* nodeIDs,
00547                          int* offsets,
00548                          double* results);
00549 
00551     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00552                                   int fieldID,
00553                                   int numNodes, 
00554                                   const GlobalID *nodeIDs, 
00555                                   double *results);
00556          
00558     int getBlockElemSolution(GlobalID elemBlockID,  
00559                              int numElems, 
00560                              const GlobalID *elemIDs,
00561                              int& numElemDOFPerElement,
00562                              double *results);
00563 
00565    int getNumCRMultipliers(int& numMultCRs);
00566 
00568    int getCRMultIDList(int numMultCRs, int* multIDs);
00569 
00571    int getCRMultipliers(int numCRs,
00572                         const int* CRIDs,
00573                         double *multipliers);
00574 
00575  
00576 // associated "puts" paralleling the solution return services.
00577 // 
00578 // the int sizing parameters are passed for error-checking purposes, so
00579 // that the interface implementation can tell if the passed estimate
00580 // vectors make sense -before- an attempt is made to utilize them as
00581 // initial guesses by unpacking them into the solver's native solution
00582 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00583 // numElemDOF, and numMultCRs -- all other passed params are either 
00584 // vectors or block/constraint-set IDs)
00585 
00587     int putBlockNodeSolution(GlobalID elemBlockID, 
00588                              int numNodes, 
00589                              const GlobalID *nodeIDs, 
00590                              const int *offsets,
00591                              const double *estimates);
00592 
00594     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00595                                   int fieldID, 
00596                                   int numNodes, 
00597                                   const GlobalID *nodeIDs, 
00598                                   const double *estimates);
00599          
00601     int putBlockElemSolution(GlobalID elemBlockID,  
00602                              int numElems, 
00603                              const GlobalID *elemIDs, 
00604                              int dofPerElem,
00605                              const double *estimates);
00606 
00608     int putCRMultipliers(int numMultCRs, 
00609                          const int* CRIDs,
00610                          const double* multEstimates);
00611 
00612 // utility functions that aid in integrating the FEI calls..............
00613 
00614 // support methods for the "gets" and "puts" of the soln services.
00615 
00616 
00618     int getBlockNodeIDList(GlobalID elemBlockID,
00619                            int numNodes,
00620                            GlobalID *nodeIDs);
00621 
00623    int getBlockElemIDList(GlobalID elemBlockID, 
00624                           int numElems, 
00625                           GlobalID* elemIDs);
00626  
00627 // miscellaneous self-explanatory "read-only" query functions............ 
00628  
00630     int getNumSolnParams(GlobalID nodeID, int& numSolnParams) const;
00631 
00633     int getNumElemBlocks(int& numElemBlocks) const;
00634 
00636     int getNumBlockActNodes(GlobalID blockID, int& numNodes) const;
00637 
00639     int getNumBlockActEqns(GlobalID blockID, int& numEqns) const;
00640 
00643     int getNumNodesPerElement(GlobalID blockID, int& nodesPerElem) const;
00644     
00647     int getNumEqnsPerElement(GlobalID blockID, int& numEqns) const;
00648 
00650     int getNumBlockElements(GlobalID blockID, int& numElems) const;
00651 
00653     int getNumBlockElemDOF(GlobalID blockID, int& DOFPerElem) const;
00654 
00655 
00659     int getParameters(int& numParams, char**& paramStrings);
00660 
00661     //And now a couple of non-FEI query functions that Sandia applications
00662     //need to augment the matrix-access functions. I (Alan Williams) will
00663     //argue to have these included in the FEI 2.1 specification update.
00664 
00669     int getFieldSize(int fieldID, int& numScalars);
00670 
00683     int getEqnNumbers(GlobalID ID,
00684                       int idType, 
00685                       int fieldID,
00686                       int& numEqns,
00687                       int* eqnNumbers);
00688 
00702     int getNodalFieldSolution(int fieldID,
00703                               int numNodes,
00704                               const GlobalID* nodeIDs,
00705                               double* results);
00706 
00712     int getNumLocalNodes(int& numNodes);
00713 
00725     int getLocalNodeIDList(int& numNodes,
00726                            GlobalID* nodeIDs,
00727                            int lenNodeIDs);
00728 
00745     int putNodalFieldData(int fieldID,
00746                           int numNodes,
00747                           const GlobalID* nodeIDs,
00748                           const double* nodeData);
00749 
00750   const SNL_FEI_Structure& getProblemStructure() const
00751   { return *problemStructure_; }
00752 
00753   SNL_FEI_Structure& getProblemStructure()
00754   { return *problemStructure_; }
00755 
00756   //============================================================================
00757   private: //functions
00758 
00759     FEI_Implementation(const FEI_Implementation& src);
00760     FEI_Implementation& operator=(const FEI_Implementation& src);
00761 
00762     void deleteIDs();
00763     void deleteRHSScalars();
00764 
00765     int allocateInternalFEIs();
00766 
00767     void debugOut(const char* msg);
00768     void debugOut(const char* msg, int whichFEI);
00769 
00770     void buildLinearSystem();
00771     int aggregateSystem();
00772 
00773     void messageAbort(const char* msg);
00774     void notAllocatedAbort(const char* name);
00775     void needParametersAbort(const char* name);
00776     void badParametersAbort(const char* name);
00777 
00778     void setDebugOutput(const char* path, const char* name);
00779 
00780   //============================================================================
00781   private: //member variables
00782 
00783     fei::SharedPtr<LibraryWrapper> wrapper_;
00784     fei::SharedPtr<LinearSystemCore> linSysCore_;
00785     std::vector<fei::SharedPtr<LinearSystemCore> > lscArray_;
00786     bool haveLinSysCore_;
00787     bool haveFEData_;
00788     SNL_FEI_Structure* problemStructure_;
00789     Filter** filter_;
00790 
00791     int numInternalFEIs_;
00792     bool internalFEIsAllocated_;
00793 
00794     std::vector<int> matrixIDs_;
00795     std::vector<int> numRHSIDs_;
00796     std::vector<int*> rhsIDs_;
00797 
00798     bool IDsAllocated_;
00799 
00800     std::vector<double> matScalars_;
00801     bool matScalarsSet_;
00802     std::vector<double*> rhsScalars_;
00803     bool rhsScalarsSet_;
00804 
00805     int index_soln_filter_;
00806     int index_current_filter_;
00807     int index_current_rhs_row_;
00808 
00809     int solveType_;
00810 
00811     bool setSolveTypeCalled_;
00812     bool initPhaseIsComplete_;
00813 
00814     bool aggregateSystemFormed_;
00815     int newMatrixDataLoaded_;
00816 
00817     Data *soln_fei_matrix_;
00818     Data *soln_fei_vector_;
00819 
00820     MPI_Comm comm_;
00821 
00822     int masterRank_;
00823     int localRank_;
00824     int numProcs_;
00825 
00826     int outputLevel_;
00827 
00828     int solveCounter_;
00829     int debugOutput_;
00830 #ifdef FEI_HAVE_IOSFWD
00831     std::ostream* dbgOStreamPtr_;
00832 #else
00833     ostream* dbgOStreamPtr_;
00834 #endif
00835     bool dbgFileOpened_;
00836 #ifdef FEI_HAVE_IOSFWD
00837     std::ofstream* dbgFStreamPtr_;
00838 #else
00839     ofstream* dbgFStreamPtr_;
00840 #endif
00841 
00842     double initTime_, loadTime_, solveTime_, solnReturnTime_;
00843 
00844     int numParams_;
00845     char** paramStrings_;
00846 };
00847 
00848 #endif
00849 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends