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 
00153    int initElemBlock(GlobalID elemBlockID,
00154                      int numElements,
00155                      int numNodesPerElement,
00156                      const int* numFieldsPerNode,
00157                      const int* const* nodalFieldIDs,
00158                      int numElemDofFieldsPerElement,
00159                      const int* elemDOFFieldIDs,
00160                      int interleaveStrategy);
00161 
00170   int initElem(GlobalID elemBlockID,
00171                 GlobalID elemID,
00172                 const GlobalID* elemConn);
00173 
00221    int initSlaveVariable(GlobalID slaveNodeID, 
00222                          int slaveFieldID,
00223                          int offsetIntoSlaveField,
00224                          int numMasterNodes,
00225                          const GlobalID* masterNodeIDs,
00226                          const int* masterFieldIDs,
00227                          const double* weights,
00228                          double rhsValue);
00229 
00234    int deleteMultCRs();
00235 
00237    int initSharedNodes(int numSharedNodes,
00238                        const GlobalID *sharedNodeIDs,  
00239                        const int* numProcsPerNode, 
00240                        const int *const *sharingProcIDs);
00241 
00250    int initCRMult(int numCRNodes,
00251                   const GlobalID* CRNodes,
00252                   const int *CRFields,
00253                   int& CRID); 
00254 
00263    int initCRPen(int numCRNodes,
00264                  const GlobalID* CRNodes, 
00265                  const int *CRFields,
00266                  int& CRID); 
00267 
00269    int initComplete();
00270 
00271 // FEI data loading sequence..........................................
00272 
00275    int setCurrentMatrix(int matID);
00276 
00279    int setCurrentRHS(int rhsID);
00280 
00282    int resetSystem(double s=0.0);
00283 
00286    int resetMatrix(double s=0.0);
00287 
00291    int resetRHSVector(double s=0.0);
00292 
00298   int resetInitialGuess(double s=0.0);
00299 
00318     int loadNodeBCs(int numNodes,
00319                     const GlobalID *nodeIDs,
00320                     int fieldID,
00321                     const int* offsetsIntoField,
00322                     const double* prescribedValues);
00323 
00335     int loadElemBCs(int numElems,
00336                     const GlobalID* elemIDs,  
00337                     int fieldID,
00338                     const double *const *alpha,  
00339                     const double *const *beta,  
00340                     const double *const *gamma);
00341 
00357    int sumInElem(GlobalID elemBlockID,
00358                  GlobalID elemID,
00359                  const GlobalID* elemConn,
00360                  const double* const* elemStiffness,
00361                  const double* elemLoad,
00362                  int elemFormat);
00363 
00378    int sumInElemMatrix(GlobalID elemBlockID,
00379                        GlobalID elemID,
00380                        const GlobalID* elemConn,
00381                        const double* const* elemStiffness,
00382                        int elemFormat);
00383 
00392    int sumInElemRHS(GlobalID elemBlockID,
00393                     GlobalID elemID,
00394                     const GlobalID* elemConn,
00395                     const double* elemLoad);
00396 
00406    int loadCRMult(int CRID,
00407                   int numCRNodes,
00408                   const GlobalID* CRNodes,
00409                   const int* CRFields,
00410                   const double* CRWeights,
00411                   double CRValue);
00412 
00423    int loadCRPen(int CRID,
00424                  int numCRNodes,
00425                  const GlobalID* CRNodes,
00426                  const int* CRFields,
00427                  const double* CRWeights,
00428                  double CRValue,
00429                  double penValue);
00430 
00432    int putIntoRHS(int IDType,
00433                   int fieldID,
00434                   int numIDs,
00435                   const GlobalID* IDs,
00436                   const double* rhsEntries);
00437 
00439    int sumIntoRHS(int IDType,
00440                   int fieldID,
00441                   int numIDs,
00442                   const GlobalID* IDs,
00443                   const double* rhsEntries);
00444 
00445    int sumIntoMatrixDiagonal(int IDType,
00446                              int fieldID,
00447                              int numIDs,
00448                              const GlobalID* IDs,
00449                              const double* coefficients);
00450 
00451 // Equation solution services.....................................
00452 
00455    int setMatScalars(int numScalars,
00456                      const int* IDs, 
00457                      const double* scalars);
00458 
00460    int setRHSScalars(int numScalars,
00461                      const int* IDs,
00462                      const double* scalars);
00463 
00466    int loadComplete(bool applyBCs=true,
00467                     bool globalAssemble=true);
00468 
00470    int residualNorm(int whichNorm,
00471                     int numFields,
00472                     int* fieldIDs,
00473                     double* norms);
00474 
00476    int solve(int& status);
00477 
00481    int iterations(int& itersTaken) const;
00482 
00491    int version(const char*& versionString);
00492 
00494    int cumulative_cpu_times(double& initTime,
00495                             double& loadTime,
00496                             double& solveTime,
00497                             double& solnReturnTime);
00498 
00499 // Solution return services.......................................
00500  
00502     int getBlockNodeSolution(GlobalID elemBlockID,  
00503                              int numNodes, 
00504                              const GlobalID *nodeIDs, 
00505                              int *offsets,
00506                              double *results);
00507 
00509     int getNodalSolution(int numNodes,
00510                          const GlobalID* nodeIDs,
00511                          int* offsets,
00512                          double* results);
00513 
00515     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00516                                   int fieldID,
00517                                   int numNodes, 
00518                                   const GlobalID *nodeIDs, 
00519                                   double *results);
00520          
00522     int getBlockElemSolution(GlobalID elemBlockID,  
00523                              int numElems, 
00524                              const GlobalID *elemIDs,
00525                              int& numElemDOFPerElement,
00526                              double *results);
00527 
00529    int getNumCRMultipliers(int& numMultCRs);
00530 
00532    int getCRMultIDList(int numMultCRs, int* multIDs);
00533 
00535    int getCRMultipliers(int numCRs,
00536                         const int* CRIDs,
00537                         double *multipliers);
00538 
00539  
00540 // associated "puts" paralleling the solution return services.
00541 // 
00542 // the int sizing parameters are passed for error-checking purposes, so
00543 // that the interface implementation can tell if the passed estimate
00544 // vectors make sense -before- an attempt is made to utilize them as
00545 // initial guesses by unpacking them into the solver's native solution
00546 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00547 // numElemDOF, and numMultCRs -- all other passed params are either 
00548 // vectors or block/constraint-set IDs)
00549 
00551     int putBlockNodeSolution(GlobalID elemBlockID, 
00552                              int numNodes, 
00553                              const GlobalID *nodeIDs, 
00554                              const int *offsets,
00555                              const double *estimates);
00556 
00558     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00559                                   int fieldID, 
00560                                   int numNodes, 
00561                                   const GlobalID *nodeIDs, 
00562                                   const double *estimates);
00563          
00565     int putBlockElemSolution(GlobalID elemBlockID,  
00566                              int numElems, 
00567                              const GlobalID *elemIDs, 
00568                              int dofPerElem,
00569                              const double *estimates);
00570 
00572     int putCRMultipliers(int numMultCRs, 
00573                          const int* CRIDs,
00574                          const double* multEstimates);
00575 
00576 // utility functions that aid in integrating the FEI calls..............
00577 
00578 // support methods for the "gets" and "puts" of the soln services.
00579 
00580 
00582     int getBlockNodeIDList(GlobalID elemBlockID,
00583                            int numNodes,
00584                            GlobalID *nodeIDs);
00585 
00587    int getBlockElemIDList(GlobalID elemBlockID, 
00588                           int numElems, 
00589                           GlobalID* elemIDs);
00590  
00591 // miscellaneous self-explanatory "read-only" query functions............ 
00592  
00594     int getNumSolnParams(GlobalID nodeID, int& numSolnParams) const;
00595 
00597     int getNumElemBlocks(int& numElemBlocks) const;
00598 
00600     int getNumBlockActNodes(GlobalID blockID, int& numNodes) const;
00601 
00603     int getNumBlockActEqns(GlobalID blockID, int& numEqns) const;
00604 
00607     int getNumNodesPerElement(GlobalID blockID, int& nodesPerElem) const;
00608     
00611     int getNumEqnsPerElement(GlobalID blockID, int& numEqns) const;
00612 
00614     int getNumBlockElements(GlobalID blockID, int& numElems) const;
00615 
00617     int getNumBlockElemDOF(GlobalID blockID, int& DOFPerElem) const;
00618 
00619 
00623     int getParameters(int& numParams, char**& paramStrings);
00624 
00625     //And now a couple of non-FEI query functions that Sandia applications
00626     //need to augment the matrix-access functions. I (Alan Williams) will
00627     //argue to have these included in the FEI 2.1 specification update.
00628 
00633     int getFieldSize(int fieldID, int& numScalars);
00634 
00647     int getEqnNumbers(GlobalID ID,
00648                       int idType, 
00649                       int fieldID,
00650                       int& numEqns,
00651                       int* eqnNumbers);
00652 
00666     int getNodalFieldSolution(int fieldID,
00667                               int numNodes,
00668                               const GlobalID* nodeIDs,
00669                               double* results);
00670 
00676     int getNumLocalNodes(int& numNodes);
00677 
00689     int getLocalNodeIDList(int& numNodes,
00690                            GlobalID* nodeIDs,
00691                            int lenNodeIDs);
00692 
00709     int putNodalFieldData(int fieldID,
00710                           int numNodes,
00711                           const GlobalID* nodeIDs,
00712                           const double* nodeData);
00713 
00714   const SNL_FEI_Structure& getProblemStructure() const
00715   { return *problemStructure_; }
00716 
00717   SNL_FEI_Structure& getProblemStructure()
00718   { return *problemStructure_; }
00719 
00720   //============================================================================
00721   private: //functions
00722 
00723     FEI_Implementation(const FEI_Implementation& src);
00724     FEI_Implementation& operator=(const FEI_Implementation& src);
00725 
00726     void deleteIDs();
00727     void deleteRHSScalars();
00728 
00729     int allocateInternalFEIs();
00730 
00731     void debugOut(const char* msg);
00732     void debugOut(const char* msg, int whichFEI);
00733 
00734     void buildLinearSystem();
00735     int aggregateSystem();
00736 
00737     void messageAbort(const char* msg);
00738     void notAllocatedAbort(const char* name);
00739     void needParametersAbort(const char* name);
00740     void badParametersAbort(const char* name);
00741 
00742     void setDebugOutput(const char* path, const char* name);
00743 
00744   //============================================================================
00745   private: //member variables
00746 
00747     fei::SharedPtr<LibraryWrapper> wrapper_;
00748     fei::SharedPtr<LinearSystemCore> linSysCore_;
00749     std::vector<fei::SharedPtr<LinearSystemCore> > lscArray_;
00750     bool haveLinSysCore_;
00751     bool haveFEData_;
00752     SNL_FEI_Structure* problemStructure_;
00753     Filter** filter_;
00754 
00755     int numInternalFEIs_;
00756     bool internalFEIsAllocated_;
00757 
00758     std::vector<int> matrixIDs_;
00759     std::vector<int> numRHSIDs_;
00760     std::vector<int*> rhsIDs_;
00761 
00762     bool IDsAllocated_;
00763 
00764     std::vector<double> matScalars_;
00765     bool matScalarsSet_;
00766     std::vector<double*> rhsScalars_;
00767     bool rhsScalarsSet_;
00768 
00769     int index_soln_filter_;
00770     int index_current_filter_;
00771     int index_current_rhs_row_;
00772 
00773     int solveType_;
00774 
00775     bool setSolveTypeCalled_;
00776     bool initPhaseIsComplete_;
00777 
00778     bool aggregateSystemFormed_;
00779     int newMatrixDataLoaded_;
00780 
00781     Data *soln_fei_matrix_;
00782     Data *soln_fei_vector_;
00783 
00784     MPI_Comm comm_;
00785 
00786     int masterRank_;
00787     int localRank_;
00788     int numProcs_;
00789 
00790     int outputLevel_;
00791 
00792     int solveCounter_;
00793     int debugOutput_;
00794 #ifdef FEI_HAVE_IOSFWD
00795     std::ostream* dbgOStreamPtr_;
00796 #else
00797     ostream* dbgOStreamPtr_;
00798 #endif
00799     bool dbgFileOpened_;
00800 #ifdef FEI_HAVE_IOSFWD
00801     std::ofstream* dbgFStreamPtr_;
00802 #else
00803     ofstream* dbgFStreamPtr_;
00804 #endif
00805 
00806     double initTime_, loadTime_, solveTime_, solnReturnTime_;
00807 
00808     int numParams_;
00809     char** paramStrings_;
00810 };
00811 
00812 #endif
00813 

Generated on Wed May 12 21:30:41 2010 for FEI by  doxygen 1.4.7