fei_FEI_Impl.hpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_FEI_Impl_hpp_
00010 #define _fei_FEI_Impl_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_mpi.h>
00014 #include <FEI.hpp>
00015 #include <fei_Factory.hpp>
00016 
00017 #include <set>
00018 #include <vector>
00019 #include <map>
00020 
00021 namespace fei {
00022 
00033   class FEI_Impl : public FEI, private fei::Logger {
00034   public:
00037     FEI_Impl(fei::SharedPtr<LibraryWrapper> wrapper,
00038           MPI_Comm comm,
00039           int masterRank=0);
00040 
00043     FEI_Impl(const fei::Factory* factory,
00044           MPI_Comm comm,
00045           int masterRank=0);
00046 
00049     virtual ~FEI_Impl();
00050 
00055    fei::SharedPtr<fei::LinearSystem> getLinearSystem();
00056 
00057     int parameters(int numParams, 
00058                    const char *const* paramStrings);
00059 
00060    int setIDLists(int numMatrices,
00061                   const int* matrixIDs,
00062                   int numRHSs,
00063                   const int* rhsIDs);
00064 
00065    int setSolveType(int solveType);
00066 
00067    int initFields(int numFields, 
00068                   const int *fieldSizes, 
00069                   const int *fieldIDs);
00070 
00071    int initElemBlock(GlobalID elemBlockID,
00072                      int numElements,
00073                      int numNodesPerElement,
00074                      const int* numFieldsPerNode,
00075                      const int* const* nodalFieldIDs,
00076                      int numElemDofFieldsPerElement,
00077                      const int* elemDOFFieldIDs,
00078                      int interleaveStrategy);
00079 
00080    int initElem(GlobalID elemBlockID,
00081                 GlobalID elemID,
00082                 const GlobalID* elemConn);
00083 
00084    int initSlaveVariable(GlobalID slaveNodeID, 
00085                          int slaveFieldID,
00086                          int offsetIntoSlaveField,
00087                          int numMasterNodes,
00088                          const GlobalID* masterNodeIDs,
00089                          const int* masterFieldIDs,
00090                          const double* weights,
00091                          double rhsValue);
00092 
00093    int deleteMultCRs();
00094 
00095    int initSharedNodes(int numSharedNodes,
00096                        const GlobalID *sharedNodeIDs,  
00097                        const int* numProcsPerNode, 
00098                        const int *const *sharingProcIDs);
00099 
00100    int initCRMult(int numCRNodes,
00101                   const GlobalID* CRNodeIDs,
00102                   const int *CRFieldIDs,
00103                   int& CRID); 
00104 
00105    int initCRPen(int numCRNodes,
00106                  const GlobalID* CRNodeIDs, 
00107                  const int *CRFieldIDs,
00108                  int& CRID); 
00109 
00111    int initComplete();
00112 
00113    int setCurrentMatrix(int matrixID);
00114 
00115    int setCurrentRHS(int rhsID);
00116 
00117    int resetSystem(double s=0.0);
00118 
00119    int resetMatrix(double s=0.0);
00120 
00121    int resetRHSVector(double s=0.0);
00122 
00123   int resetInitialGuess(double s=0.0);
00124 
00125     int loadNodeBCs(int numNodes,
00126                     const GlobalID *nodeIDs,
00127                     int fieldID,
00128                     const int* offsetsIntoField,
00129                     const double* prescribedValues);
00130 
00131     int loadElemBCs(int numElems,
00132                     const GlobalID* elemIDs,  
00133                     int fieldID,
00134                     const double *const *alpha,  
00135                     const double *const *beta,  
00136                     const double *const *gamma);
00137 
00138    int sumInElem(GlobalID elemBlockID,
00139                  GlobalID elemID,
00140                  const GlobalID* elemConn,
00141                  const double* const* elemStiffness,
00142                  const double* elemLoad,
00143                  int elemFormat);
00144 
00145    int sumInElemMatrix(GlobalID elemBlockID,
00146                        GlobalID elemID,
00147                        const GlobalID* elemConn,
00148                        const double* const* elemStiffness,
00149                        int elemFormat);
00150 
00151    int sumInElemRHS(GlobalID elemBlockID,
00152                     GlobalID elemID,
00153                     const GlobalID* elemConn,
00154                     const double* elemLoad);
00155 
00156    int loadCRMult(int CRMultID,
00157                   int numCRNodes,
00158                   const GlobalID* CRNodeIDs,
00159                   const int* CRFieldIDs,
00160                   const double* CRWeights,
00161                   double CRValue);
00162 
00163    int loadCRPen(int CRPenID,
00164                  int numCRNodes,
00165                  const GlobalID* CRNodeIDs,
00166                  const int* CRFieldIDs,
00167                  const double* CRWeights,
00168                  double CRValue,
00169                  double penValue);
00170 
00173    int putIntoRHS(int IDType,
00174                   int fieldID,
00175                   int numIDs,
00176                   const GlobalID* IDs,
00177                   const double* coefficients);
00178 
00181    int sumIntoRHS(int IDType,
00182                   int fieldID,
00183                   int numIDs,
00184                   const GlobalID* IDs,
00185                   const double* coefficients);
00186 
00187    int setMatScalars(int numScalars,
00188                      const int* IDs, 
00189                      const double* scalars);
00190 
00191    int setRHSScalars(int numScalars,
00192                      const int* IDs,
00193                      const double* scalars);
00194 
00195    int loadComplete(bool applyBCs=true,
00196                     bool globalAssemble=true);
00197 
00199    int residualNorm(int whichNorm,
00200                     int numFields,
00201                     int* fieldIDs,
00202                     double* norms);
00203 
00205    int solve(int& status);
00206 
00210    int iterations(int& itersTaken) const;
00211 
00212    int version(const char*& versionString);
00213 
00215    int cumulative_cpu_times(double& initTime,
00216                             double& loadTime,
00217                             double& solveTime,
00218                             double& solnReturnTime);
00219 
00221     int getBlockNodeSolution(GlobalID elemBlockID,  
00222                              int numNodes, 
00223                              const GlobalID *nodeIDs, 
00224                              int *offsets,
00225                              double *results);
00226 
00228     int getNodalSolution(int numNodes,
00229                          const GlobalID* nodeIDs,
00230                          int* offsets,
00231                          double* results);
00232 
00234     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00235                                   int fieldID,
00236                                   int numNodes, 
00237                                   const GlobalID *nodeIDs, 
00238                                   double *results);
00239          
00241     int getBlockElemSolution(GlobalID elemBlockID,  
00242                              int numElems, 
00243                              const GlobalID *elemIDs,
00244                              int& numElemDOFPerElement,
00245                              double *results);
00246 
00248    int getNumCRMultipliers(int& numMultCRs);
00249 
00251    int getCRMultIDList(int numMultCRs, int* multIDs);
00252 
00254    int getCRMultipliers(int numCRs,
00255                         const int* CRIDs,
00256                         double *multipliers);
00257 
00258 // associated "puts" paralleling the solution return services.
00259 // 
00260 // the int sizing parameters are passed for error-checking purposes, so
00261 // that the interface implementation can tell if the passed estimate
00262 // vectors make sense -before- an attempt is made to utilize them as
00263 // initial guesses by unpacking them into the solver's native solution
00264 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00265 // numElemDOF, and numMultCRs -- all other passed params are either 
00266 // vectors or block/constraint-set IDs)
00267 
00269     int putBlockNodeSolution(GlobalID elemBlockID, 
00270                              int numNodes, 
00271                              const GlobalID *nodeIDs, 
00272                              const int *offsets,
00273                              const double *estimates);
00274 
00276     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00277                                   int fieldID, 
00278                                   int numNodes, 
00279                                   const GlobalID *nodeIDs, 
00280                                   const double *estimates);
00281          
00283     int putBlockElemSolution(GlobalID elemBlockID,  
00284                              int numElems, 
00285                              const GlobalID *elemIDs, 
00286                              int dofPerElem,
00287                              const double *estimates);
00288 
00290     int putCRMultipliers(int numMultCRs, 
00291                          const int* CRIDs,
00292                          const double* multEstimates);
00293 
00294 // utility functions that aid in integrating the FEI calls..............
00295 
00296 // support methods for the "gets" and "puts" of the soln services.
00297 
00298 
00300     int getBlockNodeIDList(GlobalID elemBlockID,
00301                            int numNodes,
00302                            GlobalID *nodeIDs);
00303 
00305    int getBlockElemIDList(GlobalID elemBlockID, 
00306                           int numElems, 
00307                           GlobalID* elemIDs);
00308  
00309 // miscellaneous self-explanatory "read-only" query functions............ 
00310  
00312     int getNumSolnParams(GlobalID nodeID, int& numSolnParams) const;
00313 
00315     int getNumElemBlocks(int& numElemBlocks) const;
00316 
00318     int getNumBlockActNodes(GlobalID blockID, int& numNodes) const;
00319 
00321     int getNumBlockActEqns(GlobalID blockID, int& numEqns) const;
00322 
00325     int getNumNodesPerElement(GlobalID blockID, int& nodesPerElem) const;
00326     
00329     int getNumEqnsPerElement(GlobalID blockID, int& numEqns) const;
00330 
00332     int getNumBlockElements(GlobalID blockID, int& numElems) const;
00333 
00335     int getNumBlockElemDOF(GlobalID blockID, int& DOFPerElem) const;
00336 
00337 
00341     int getParameters(int& numParams, char**& paramStrings);
00342 
00343     //And now a couple of non-FEI query functions that Sandia applications
00344     //need to augment the matrix-access functions. I (Alan Williams) will
00345     //argue to have these included in the FEI 2.1 specification update.
00346 
00351     int getFieldSize(int fieldID, int& numScalars);
00352 
00365     int getEqnNumbers(GlobalID ID,
00366                       int idType, 
00367                       int fieldID,
00368                       int& numEqns,
00369                       int* eqnNumbers);
00370 
00384     int getNodalFieldSolution(int fieldID,
00385                               int numNodes,
00386                               const GlobalID* nodeIDs,
00387                               double* results);
00388 
00394     int getNumLocalNodes(int& numNodes);
00395 
00407     int getLocalNodeIDList(int& numNodes,
00408                            GlobalID* nodeIDs,
00409                            int lenNodeIDs);
00410 
00427     int putNodalFieldData(int fieldID,
00428                           int numNodes,
00429                           const GlobalID* nodeIDs,
00430                           const double* nodeData);
00431 
00432   private: //methods
00433     void basic_initializations();
00434 
00435     int inputRHS(int IDType,
00436                  int fieldID,
00437                  int numIDs,
00438                  const GlobalID* IDs,
00439                  const double* rhsEntries,
00440                  bool sumInto);
00441 
00442     int fillNodeset(int blockID) const;
00443 
00444     int aggregateSystem();
00445 
00446     int aggregateSystem_LinSysCore();
00447 
00448   private: //attributes
00449 
00450     std::vector<fei::SharedPtr<LibraryWrapper> > wrapper_;
00451 
00452     int nodeIDType_;
00453     int elemIDType_;
00454     int constraintIDType_;
00455 
00456     std::vector<fei::SharedPtr<fei::Factory> > factory_;
00457     bool createdFactory_;
00458     fei::SharedPtr<fei::VectorSpace> rowSpace_;
00459     fei::SharedPtr<fei::MatrixGraph> matGraph_;
00460 
00461     fei::SharedPtr<fei::Vector> x_;
00462     std::vector<fei::SharedPtr<fei::Vector> > b_;
00463     std::vector<fei::SharedPtr<fei::Matrix> > A_;
00464     fei::SharedPtr<fei::LinearSystem> linSys_;
00465 
00466     bool newData_;
00467 
00468     Data *soln_fei_matrix_;
00469     Data *soln_fei_vector_;
00470 
00471     MPI_Comm comm_;
00472     int masterRank_;
00473     int localProc_;
00474     int numProcs_;
00475 
00476     int numParams_;
00477     char** paramStrings_;
00478 
00479     std::vector<int> matrixIDs_;
00480     std::vector<int> rhsIDs_;
00481 
00482     std::vector<double> matScalars_;
00483     bool matScalarsSet_;
00484     std::vector<double> rhsScalars_;
00485     bool rhsScalarsSet_;
00486 
00487     int constraintID_;
00488 
00489     int index_soln_;
00490     int index_current_;
00491     int index_current_rhs_row_;
00492 
00493     int solveType_;
00494     int iterations_;
00495 
00496     bool setSolveTypeCalled_;
00497     bool initPhaseIsComplete_;
00498 
00499     bool aggregateSystemFormed_;
00500     int newMatrixDataLoaded_;
00501 
00502     int solveCounter_;
00503 
00504     double initTime_, loadTime_, solveTime_, solnReturnTime_;
00505 
00506     std::vector<int> iwork_;
00507 
00508     mutable std::set<int> nodeset_;
00509     mutable bool nodeset_filled_;
00510     mutable int nodeset_blockid_;
00511 
00512     mutable std::map<int,int> block_dof_per_elem_;
00513     bool any_blocks_have_elem_dof_;
00514   };//class FEI_Impl
00515 
00516 }//namespace fei
00517 
00518 #endif
00519 

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