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                   const int *fieldTypes=NULL);
00071 
00072    int initElemBlock(GlobalID elemBlockID,
00073                      int numElements,
00074                      int numNodesPerElement,
00075                      const int* numFieldsPerNode,
00076                      const int* const* nodalFieldIDs,
00077                      int numElemDofFieldsPerElement,
00078                      const int* elemDOFFieldIDs,
00079                      int interleaveStrategy);
00080 
00081    int initElem(GlobalID elemBlockID,
00082                 GlobalID elemID,
00083                 const GlobalID* elemConn);
00084 
00085    int initSlaveVariable(GlobalID slaveNodeID, 
00086                          int slaveFieldID,
00087                          int offsetIntoSlaveField,
00088                          int numMasterNodes,
00089                          const GlobalID* masterNodeIDs,
00090                          const int* masterFieldIDs,
00091                          const double* weights,
00092                          double rhsValue);
00093 
00094    int deleteMultCRs();
00095 
00096    int initSharedNodes(int numSharedNodes,
00097                        const GlobalID *sharedNodeIDs,  
00098                        const int* numProcsPerNode, 
00099                        const int *const *sharingProcIDs);
00100 
00101    int initCRMult(int numCRNodes,
00102                   const GlobalID* CRNodeIDs,
00103                   const int *CRFieldIDs,
00104                   int& CRID); 
00105 
00106    int initCRPen(int numCRNodes,
00107                  const GlobalID* CRNodeIDs, 
00108                  const int *CRFieldIDs,
00109                  int& CRID); 
00110 
00112    int initComplete();
00113 
00114    int setCurrentMatrix(int matrixID);
00115 
00116    int setCurrentRHS(int rhsID);
00117 
00118    int resetSystem(double s=0.0);
00119 
00120    int resetMatrix(double s=0.0);
00121 
00122    int resetRHSVector(double s=0.0);
00123 
00124   int resetInitialGuess(double s=0.0);
00125 
00126     int loadNodeBCs(int numNodes,
00127                     const GlobalID *nodeIDs,
00128                     int fieldID,
00129                     const int* offsetsIntoField,
00130                     const double* prescribedValues);
00131 
00132     int loadElemBCs(int numElems,
00133                     const GlobalID* elemIDs,  
00134                     int fieldID,
00135                     const double *const *alpha,  
00136                     const double *const *beta,  
00137                     const double *const *gamma);
00138 
00139    int sumInElem(GlobalID elemBlockID,
00140                  GlobalID elemID,
00141                  const GlobalID* elemConn,
00142                  const double* const* elemStiffness,
00143                  const double* elemLoad,
00144                  int elemFormat);
00145 
00146    int sumInElemMatrix(GlobalID elemBlockID,
00147                        GlobalID elemID,
00148                        const GlobalID* elemConn,
00149                        const double* const* elemStiffness,
00150                        int elemFormat);
00151 
00152    int sumInElemRHS(GlobalID elemBlockID,
00153                     GlobalID elemID,
00154                     const GlobalID* elemConn,
00155                     const double* elemLoad);
00156 
00157    int loadCRMult(int CRMultID,
00158                   int numCRNodes,
00159                   const GlobalID* CRNodeIDs,
00160                   const int* CRFieldIDs,
00161                   const double* CRWeights,
00162                   double CRValue);
00163 
00164    int loadCRPen(int CRPenID,
00165                  int numCRNodes,
00166                  const GlobalID* CRNodeIDs,
00167                  const int* CRFieldIDs,
00168                  const double* CRWeights,
00169                  double CRValue,
00170                  double penValue);
00171 
00174    int putIntoRHS(int IDType,
00175                   int fieldID,
00176                   int numIDs,
00177                   const GlobalID* IDs,
00178                   const double* coefficients);
00179 
00182    int sumIntoRHS(int IDType,
00183                   int fieldID,
00184                   int numIDs,
00185                   const GlobalID* IDs,
00186                   const double* coefficients);
00187 
00188    int setMatScalars(int numScalars,
00189                      const int* IDs, 
00190                      const double* scalars);
00191 
00192    int setRHSScalars(int numScalars,
00193                      const int* IDs,
00194                      const double* scalars);
00195 
00196    int loadComplete(bool applyBCs=true,
00197                     bool globalAssemble=true);
00198 
00200    int residualNorm(int whichNorm,
00201                     int numFields,
00202                     int* fieldIDs,
00203                     double* norms);
00204 
00206    int solve(int& status);
00207 
00211    int iterations(int& itersTaken) const;
00212 
00213    int version(const char*& versionString);
00214 
00216    int cumulative_cpu_times(double& initTime,
00217                             double& loadTime,
00218                             double& solveTime,
00219                             double& solnReturnTime);
00220 
00222     int getBlockNodeSolution(GlobalID elemBlockID,  
00223                              int numNodes, 
00224                              const GlobalID *nodeIDs, 
00225                              int *offsets,
00226                              double *results);
00227 
00229     int getNodalSolution(int numNodes,
00230                          const GlobalID* nodeIDs,
00231                          int* offsets,
00232                          double* results);
00233 
00235     int getBlockFieldNodeSolution(GlobalID elemBlockID,
00236                                   int fieldID,
00237                                   int numNodes, 
00238                                   const GlobalID *nodeIDs, 
00239                                   double *results);
00240          
00242     int getBlockElemSolution(GlobalID elemBlockID,  
00243                              int numElems, 
00244                              const GlobalID *elemIDs,
00245                              int& numElemDOFPerElement,
00246                              double *results);
00247 
00249    int getNumCRMultipliers(int& numMultCRs);
00250 
00252    int getCRMultIDList(int numMultCRs, int* multIDs);
00253 
00255    int getCRMultipliers(int numCRs,
00256                         const int* CRIDs,
00257                         double *multipliers);
00258 
00259 // associated "puts" paralleling the solution return services.
00260 // 
00261 // the int sizing parameters are passed for error-checking purposes, so
00262 // that the interface implementation can tell if the passed estimate
00263 // vectors make sense -before- an attempt is made to utilize them as
00264 // initial guesses by unpacking them into the solver's native solution
00265 // vector format (these parameters include lenNodeIDList, lenElemIDList,
00266 // numElemDOF, and numMultCRs -- all other passed params are either 
00267 // vectors or block/constraint-set IDs)
00268 
00270     int putBlockNodeSolution(GlobalID elemBlockID, 
00271                              int numNodes, 
00272                              const GlobalID *nodeIDs, 
00273                              const int *offsets,
00274                              const double *estimates);
00275 
00277     int putBlockFieldNodeSolution(GlobalID elemBlockID, 
00278                                   int fieldID, 
00279                                   int numNodes, 
00280                                   const GlobalID *nodeIDs, 
00281                                   const double *estimates);
00282          
00284     int putBlockElemSolution(GlobalID elemBlockID,  
00285                              int numElems, 
00286                              const GlobalID *elemIDs, 
00287                              int dofPerElem,
00288                              const double *estimates);
00289 
00291     int putCRMultipliers(int numMultCRs, 
00292                          const int* CRIDs,
00293                          const double* multEstimates);
00294 
00295 // utility functions that aid in integrating the FEI calls..............
00296 
00297 // support methods for the "gets" and "puts" of the soln services.
00298 
00299 
00301     int getBlockNodeIDList(GlobalID elemBlockID,
00302                            int numNodes,
00303                            GlobalID *nodeIDs);
00304 
00306    int getBlockElemIDList(GlobalID elemBlockID, 
00307                           int numElems, 
00308                           GlobalID* elemIDs);
00309  
00310 // miscellaneous self-explanatory "read-only" query functions............ 
00311  
00313     int getNumSolnParams(GlobalID nodeID, int& numSolnParams) const;
00314 
00316     int getNumElemBlocks(int& numElemBlocks) const;
00317 
00319     int getNumBlockActNodes(GlobalID blockID, int& numNodes) const;
00320 
00322     int getNumBlockActEqns(GlobalID blockID, int& numEqns) const;
00323 
00326     int getNumNodesPerElement(GlobalID blockID, int& nodesPerElem) const;
00327     
00330     int getNumEqnsPerElement(GlobalID blockID, int& numEqns) const;
00331 
00333     int getNumBlockElements(GlobalID blockID, int& numElems) const;
00334 
00336     int getNumBlockElemDOF(GlobalID blockID, int& DOFPerElem) const;
00337 
00338 
00342     int getParameters(int& numParams, char**& paramStrings);
00343 
00344     //And now a couple of non-FEI query functions that Sandia applications
00345     //need to augment the matrix-access functions. I (Alan Williams) will
00346     //argue to have these included in the FEI 2.1 specification update.
00347 
00352     int getFieldSize(int fieldID, int& numScalars);
00353 
00366     int getEqnNumbers(GlobalID ID,
00367                       int idType, 
00368                       int fieldID,
00369                       int& numEqns,
00370                       int* eqnNumbers);
00371 
00385     int getNodalFieldSolution(int fieldID,
00386                               int numNodes,
00387                               const GlobalID* nodeIDs,
00388                               double* results);
00389 
00395     int getNumLocalNodes(int& numNodes);
00396 
00408     int getLocalNodeIDList(int& numNodes,
00409                            GlobalID* nodeIDs,
00410                            int lenNodeIDs);
00411 
00428     int putNodalFieldData(int fieldID,
00429                           int numNodes,
00430                           const GlobalID* nodeIDs,
00431                           const double* nodeData);
00432 
00433   private: //methods
00434     void basic_initializations();
00435 
00436     int inputRHS(int IDType,
00437                  int fieldID,
00438                  int numIDs,
00439                  const GlobalID* IDs,
00440                  const double* rhsEntries,
00441                  bool sumInto);
00442 
00443     int fillNodeset(int blockID) const;
00444 
00445     int aggregateSystem();
00446 
00447     int aggregateSystem_LinSysCore();
00448 
00449   private: //attributes
00450 
00451     std::vector<fei::SharedPtr<LibraryWrapper> > wrapper_;
00452 
00453     int nodeIDType_;
00454     int elemIDType_;
00455     int constraintIDType_;
00456 
00457     std::vector<fei::SharedPtr<fei::Factory> > factory_;
00458     bool createdFactory_;
00459     fei::SharedPtr<fei::VectorSpace> rowSpace_;
00460     fei::SharedPtr<fei::MatrixGraph> matGraph_;
00461 
00462     fei::SharedPtr<fei::Vector> x_;
00463     std::vector<fei::SharedPtr<fei::Vector> > b_;
00464     std::vector<fei::SharedPtr<fei::Matrix> > A_;
00465     fei::SharedPtr<fei::LinearSystem> linSys_;
00466 
00467     bool newData_;
00468 
00469     Data *soln_fei_matrix_;
00470     Data *soln_fei_vector_;
00471 
00472     MPI_Comm comm_;
00473     int masterRank_;
00474     int localProc_;
00475     int numProcs_;
00476 
00477     int numParams_;
00478     char** paramStrings_;
00479 
00480     std::vector<int> matrixIDs_;
00481     std::vector<int> rhsIDs_;
00482 
00483     std::vector<double> matScalars_;
00484     bool matScalarsSet_;
00485     std::vector<double> rhsScalars_;
00486     bool rhsScalarsSet_;
00487 
00488     int constraintID_;
00489 
00490     int index_soln_;
00491     int index_current_;
00492     int index_current_rhs_row_;
00493 
00494     int solveType_;
00495     int iterations_;
00496 
00497     bool setSolveTypeCalled_;
00498     bool initPhaseIsComplete_;
00499 
00500     bool aggregateSystemFormed_;
00501     int newMatrixDataLoaded_;
00502 
00503     int solveCounter_;
00504 
00505     double initTime_, loadTime_, solveTime_, solnReturnTime_;
00506 
00507     std::vector<int> iwork_;
00508 
00509     mutable std::set<int> nodeset_;
00510     mutable bool nodeset_filled_;
00511     mutable int nodeset_blockid_;
00512 
00513     mutable std::map<int,int> block_dof_per_elem_;
00514     bool any_blocks_have_elem_dof_;
00515   };//class FEI_Impl
00516 
00517 }//namespace fei
00518 
00519 #endif
00520 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:23 2011 for FEI by  doxygen 1.6.3