FEI Version of the Day
FEI_Implementation.hpp
00001 #ifndef _FEI_Implementation_hpp_
00002 #define _FEI_Implementation_hpp_
00003 
00004 /*--------------------------------------------------------------------*/
00005 /*    Copyright 2005 Sandia Corporation.                              */
00006 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00007 /*    non-exclusive license for use of this work by or on behalf      */
00008 /*    of the U.S. Government.  Export of this program may require     */
00009 /*    a license from the United States Government.                    */
00010 /*--------------------------------------------------------------------*/
00011 
00012 #include <fei_fwd.hpp>
00013 #include <fei_mpi.h>
00014 #include <fei_SharedPtr.hpp>
00015 #include <fei_defs.h>
00016 
00017 #include <FEI.hpp>
00018 
00050 class FEI_Implementation : public FEI {
00051 
00052  public:
00062    FEI_Implementation(fei::SharedPtr<LibraryWrapper> libWrapper,
00063                       MPI_Comm comm,
00064                       int masterRank=0);
00065 
00067    virtual ~FEI_Implementation();
00068 
00069 //public FEI functions:
00070 
00071 
00080    int parameters(int numParams, const char *const* paramStrings);
00081 
00082 //Structural initialization functions.............................
00083 
00099    int setIDLists(int numMatrices,
00100                   const int* matrixIDs,
00101                   int numRHSs,
00102                   const int* rhsIDs);
00103 
00112    int setSolveType(int solveType);
00113 
00128    int initFields(int numFields, 
00129                   const int *fieldSizes, 
00130                   const int *fieldIDs,
00131                   const int *fieldTypes = NULL);
00132 
00154    int initElemBlock(GlobalID elemBlockID,
00155                      int numElements,
00156                      int numNodesPerElement,
00157                      const int* numFieldsPerNode,
00158                      const int* const* nodalFieldIDs,
00159                      int numElemDofFieldsPerElement,
00160                      const int* elemDOFFieldIDs,
00161                      int interleaveStrategy);
00162 
00171   int initElem(GlobalID elemBlockID,
00172                 GlobalID elemID,
00173                 const GlobalID* elemConn);
00174 
00222    int initSlaveVariable(GlobalID slaveNodeID, 
00223                          int slaveFieldID,
00224                          int offsetIntoSlaveField,
00225                          int numMasterNodes,
00226                          const GlobalID* masterNodeIDs,
00227                          const int* masterFieldIDs,
00228                          const double* weights,
00229                          double rhsValue);
00230 
00235    int deleteMultCRs();
00236 
00238    int initSharedNodes(int numSharedNodes,
00239                        const GlobalID *sharedNodeIDs,  
00240                        const int* numProcsPerNode, 
00241                        const int *const *sharingProcIDs);
00242 
00251    int initCRMult(int numCRNodes,
00252                   const GlobalID* CRNodes,
00253                   const int *CRFields,
00254                   int& CRID); 
00255 
00264    int initCRPen(int numCRNodes,
00265                  const GlobalID* CRNodes, 
00266                  const int *CRFields,
00267                  int& CRID); 
00268 
00270    int initComplete();
00271 
00272 // FEI data loading sequence..........................................
00273 
00276    int setCurrentMatrix(int matID);
00277 
00280    int setCurrentRHS(int rhsID);
00281 
00283    int resetSystem(double s=0.0);
00284 
00287    int resetMatrix(double s=0.0);
00288 
00292    int resetRHSVector(double s=0.0);
00293 
00299   int resetInitialGuess(double s=0.0);
00300 
00319     int loadNodeBCs(int numNodes,
00320                     const GlobalID *nodeIDs,
00321                     int fieldID,
00322                     const int* offsetsIntoField,
00323                     const double* prescribedValues);
00324 
00336     int loadElemBCs(int numElems,
00337                     const GlobalID* elemIDs,  
00338                     int fieldID,
00339                     const double *const *alpha,  
00340                     const double *const *beta,  
00341                     const double *const *gamma);
00342 
00358    int sumInElem(GlobalID elemBlockID,
00359                  GlobalID elemID,
00360                  const GlobalID* elemConn,
00361                  const double* const* elemStiffness,
00362                  const double* elemLoad,
00363                  int elemFormat);
00364 
00379    int sumInElemMatrix(GlobalID elemBlockID,
00380                        GlobalID elemID,
00381                        const GlobalID* elemConn,
00382                        const double* const* elemStiffness,
00383                        int elemFormat);
00384 
00393    int sumInElemRHS(GlobalID elemBlockID,
00394                     GlobalID elemID,
00395                     const GlobalID* elemConn,
00396                     const double* elemLoad);
00397 
00407    int loadCRMult(int CRID,
00408                   int numCRNodes,
00409                   const GlobalID* CRNodes,
00410                   const int* CRFields,
00411                   const double* CRWeights,
00412                   double CRValue);
00413 
00424    int loadCRPen(int CRID,
00425                  int numCRNodes,
00426                  const GlobalID* CRNodes,
00427                  const int* CRFields,
00428                  const double* CRWeights,
00429                  double CRValue,
00430                  double penValue);
00431 
00433    int putIntoRHS(int IDType,
00434                   int fieldID,
00435                   int numIDs,
00436                   const GlobalID* IDs,
00437                   const double* rhsEntries);
00438 
00440    int sumIntoRHS(int IDType,
00441                   int fieldID,
00442                   int numIDs,
00443                   const GlobalID* IDs,
00444                   const double* rhsEntries);
00445 
00446    int sumIntoMatrixDiagonal(int IDType,
00447                              int fieldID,
00448                              int numIDs,
00449                              const GlobalID* IDs,
00450                              const double* coefficients);
00451 
00452 // Equation solution services.....................................
00453 
00456    int setMatScalars(int numScalars,
00457                      const int* IDs, 
00458                      const double* scalars);
00459 
00461    int setRHSScalars(int numScalars,
00462                      const int* IDs,
00463                      const double* scalars);
00464 
00467    int loadComplete(bool applyBCs=true,
00468                     bool globalAssemble=true);
00469 
00471    int residualNorm(int whichNorm,
00472                     int numFields,
00473                     int* fieldIDs,
00474                     double* norms);
00475 
00477    int solve(int& status);
00478 
00482    int iterations(int& itersTaken) const;
00483 
00492    int version(const char*& versionString);
00493 
00495    int cumulative_cpu_times(double& initTime,
00496                             double& loadTime,
00497                             double& solveTime,
00498                             double& solnReturnTime);
00499 
00500 // Solution return services.......................................
00501  
00503     int getBlockNodeSolution(GlobalID elemBlockID,  
00504                              int numNodes, 
00505                              const GlobalID *nodeIDs, 
00506                              int *offsets,
00507                              double *results);
00508 
00510     int getNodalSolution(int numNodes,
00511                          const GlobalID* nodeIDs,
00512                          int* offsets,
00513                          double* results);
00514 
00516     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00517                                   int fieldID,
00518                                   int numNodes, 
00519                                   const GlobalID *nodeIDs, 
00520                                   double *results);
00521          
00523     int getBlockElemSolution(GlobalID elemBlockID,  
00524                              int numElems, 
00525                              const GlobalID *elemIDs,
00526                              int& numElemDOFPerElement,
00527                              double *results);
00528 
00530    int getNumCRMultipliers(int& numMultCRs);
00531 
00533    int getCRMultIDList(int numMultCRs, int* multIDs);
00534 
00536    int getCRMultipliers(int numCRs,
00537                         const int* CRIDs,
00538                         double *multipliers);
00539 
00540  
00541 // associated "puts" paralleling the solution return services.
00542 // 
00543 // the int sizing parameters are passed for error-checking purposes, so
00544 // that the interface implementation can tell if the passed estimate
00545 // vectors make sense -before- an attempt is made to utilize them as
00546 // initial guesses by unpacking them into the solver's native solution
00547 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00548 // numElemDOF, and numMultCRs -- all other passed params are either 
00549 // vectors or block/constraint-set IDs)
00550 
00552     int putBlockNodeSolution(GlobalID elemBlockID, 
00553                              int numNodes, 
00554                              const GlobalID *nodeIDs, 
00555                              const int *offsets,
00556                              const double *estimates);
00557 
00559     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00560                                   int fieldID, 
00561                                   int numNodes, 
00562                                   const GlobalID *nodeIDs, 
00563                                   const double *estimates);
00564          
00566     int putBlockElemSolution(GlobalID elemBlockID,  
00567                              int numElems, 
00568                              const GlobalID *elemIDs, 
00569                              int dofPerElem,
00570                              const double *estimates);
00571 
00573     int putCRMultipliers(int numMultCRs, 
00574                          const int* CRIDs,
00575                          const double* multEstimates);
00576 
00577 // utility functions that aid in integrating the FEI calls..............
00578 
00579 // support methods for the "gets" and "puts" of the soln services.
00580 
00581 
00583     int getBlockNodeIDList(GlobalID elemBlockID,
00584                            int numNodes,
00585                            GlobalID *nodeIDs);
00586 
00588    int getBlockElemIDList(GlobalID elemBlockID, 
00589                           int numElems, 
00590                           GlobalID* elemIDs);
00591  
00592 // miscellaneous self-explanatory "read-only" query functions............ 
00593  
00595     int getNumSolnParams(GlobalID nodeID, int& numSolnParams) const;
00596 
00598     int getNumElemBlocks(int& numElemBlocks) const;
00599 
00601     int getNumBlockActNodes(GlobalID blockID, int& numNodes) const;
00602 
00604     int getNumBlockActEqns(GlobalID blockID, int& numEqns) const;
00605 
00608     int getNumNodesPerElement(GlobalID blockID, int& nodesPerElem) const;
00609     
00612     int getNumEqnsPerElement(GlobalID blockID, int& numEqns) const;
00613 
00615     int getNumBlockElements(GlobalID blockID, int& numElems) const;
00616 
00618     int getNumBlockElemDOF(GlobalID blockID, int& DOFPerElem) const;
00619 
00620 
00624     int getParameters(int& numParams, char**& paramStrings);
00625 
00626     //And now a couple of non-FEI query functions that Sandia applications
00627     //need to augment the matrix-access functions. I (Alan Williams) will
00628     //argue to have these included in the FEI 2.1 specification update.
00629 
00634     int getFieldSize(int fieldID, int& numScalars);
00635 
00648     int getEqnNumbers(GlobalID ID,
00649                       int idType, 
00650                       int fieldID,
00651                       int& numEqns,
00652                       int* eqnNumbers);
00653 
00667     int getNodalFieldSolution(int fieldID,
00668                               int numNodes,
00669                               const GlobalID* nodeIDs,
00670                               double* results);
00671 
00677     int getNumLocalNodes(int& numNodes);
00678 
00690     int getLocalNodeIDList(int& numNodes,
00691                            GlobalID* nodeIDs,
00692                            int lenNodeIDs);
00693 
00710     int putNodalFieldData(int fieldID,
00711                           int numNodes,
00712                           const GlobalID* nodeIDs,
00713                           const double* nodeData);
00714 
00715   const SNL_FEI_Structure& getProblemStructure() const
00716   { return *problemStructure_; }
00717 
00718   SNL_FEI_Structure& getProblemStructure()
00719   { return *problemStructure_; }
00720 
00721   //============================================================================
00722   private: //functions
00723 
00724     FEI_Implementation(const FEI_Implementation& src);
00725     FEI_Implementation& operator=(const FEI_Implementation& src);
00726 
00727     void deleteIDs();
00728     void deleteRHSScalars();
00729 
00730     int allocateInternalFEIs();
00731 
00732     void debugOut(const char* msg);
00733     void debugOut(const char* msg, int whichFEI);
00734 
00735     void buildLinearSystem();
00736     int aggregateSystem();
00737 
00738     void messageAbort(const char* msg);
00739     void notAllocatedAbort(const char* name);
00740     void needParametersAbort(const char* name);
00741     void badParametersAbort(const char* name);
00742 
00743     void setDebugOutput(const char* path, const char* name);
00744 
00745   //============================================================================
00746   private: //member variables
00747 
00748     fei::SharedPtr<LibraryWrapper> wrapper_;
00749     fei::SharedPtr<LinearSystemCore> linSysCore_;
00750     std::vector<fei::SharedPtr<LinearSystemCore> > lscArray_;
00751     bool haveLinSysCore_;
00752     bool haveFEData_;
00753     SNL_FEI_Structure* problemStructure_;
00754     Filter** filter_;
00755 
00756     int numInternalFEIs_;
00757     bool internalFEIsAllocated_;
00758 
00759     std::vector<int> matrixIDs_;
00760     std::vector<int> numRHSIDs_;
00761     std::vector<int*> rhsIDs_;
00762 
00763     bool IDsAllocated_;
00764 
00765     std::vector<double> matScalars_;
00766     bool matScalarsSet_;
00767     std::vector<double*> rhsScalars_;
00768     bool rhsScalarsSet_;
00769 
00770     int index_soln_filter_;
00771     int index_current_filter_;
00772     int index_current_rhs_row_;
00773 
00774     int solveType_;
00775 
00776     bool setSolveTypeCalled_;
00777     bool initPhaseIsComplete_;
00778 
00779     bool aggregateSystemFormed_;
00780     int newMatrixDataLoaded_;
00781 
00782     Data *soln_fei_matrix_;
00783     Data *soln_fei_vector_;
00784 
00785     MPI_Comm comm_;
00786 
00787     int masterRank_;
00788     int localRank_;
00789     int numProcs_;
00790 
00791     int outputLevel_;
00792 
00793     int solveCounter_;
00794     int debugOutput_;
00795 #ifdef FEI_HAVE_IOSFWD
00796     std::ostream* dbgOStreamPtr_;
00797 #else
00798     ostream* dbgOStreamPtr_;
00799 #endif
00800     bool dbgFileOpened_;
00801 #ifdef FEI_HAVE_IOSFWD
00802     std::ofstream* dbgFStreamPtr_;
00803 #else
00804     ofstream* dbgFStreamPtr_;
00805 #endif
00806 
00807     double initTime_, loadTime_, solveTime_, solnReturnTime_;
00808 
00809     int numParams_;
00810     char** paramStrings_;
00811 };
00812 
00813 #endif
00814 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends