snl_fei_LinearSystem_FEData.cpp

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 #include <math.h>
00009 
00010 #include <fei_macros.hpp>
00011 
00012 #include <fei_FiniteElementData.hpp>
00013 
00014 #include <fei_CommUtils.hpp>
00015 #include <snl_fei_LinearSystem_FEData.hpp>
00016 #include <fei_VectorSpace.hpp>
00017 #include <fei_MatrixGraph.hpp>
00018 #include <fei_Matrix_Impl.hpp>
00019 #include <snl_fei_Constraint.hpp>
00020 #include <snl_fei_Utils.hpp>
00021 #include <fei_impl_utils.hpp>
00022 
00023 #include <fei_DirichletBCRecord.hpp>
00024 #include <fei_DirichletBCManager.hpp>
00025 #include <fei_EqnBuffer.hpp>
00026 #include <fei_FEDataFilter.hpp>
00027 
00028 #undef fei_file
00029 #define fei_file "snl_fei_LinearSystem_FEData.cpp"
00030 #include <fei_ErrMacros.hpp>
00031 
00032 //----------------------------------------------------------------------------
00033 snl_fei::LinearSystem_FEData::LinearSystem_FEData(fei::SharedPtr<FiniteElementData>& feData,
00034               fei::SharedPtr<fei::MatrixGraph>& matrixGraph)
00035   : fei::LinearSystem(matrixGraph),
00036     comm_(matrixGraph->getRowSpace()->getCommunicator()),
00037     localProc_(0),
00038     numProcs_(1),
00039     feData_(feData),
00040     lookup_(NULL)
00041 {
00042   localProc_ = fei::localProc(comm_);
00043   numProcs_  = fei::numProcs(comm_);
00044 }
00045 
00046 //----------------------------------------------------------------------------
00047 snl_fei::LinearSystem_FEData::~LinearSystem_FEData()
00048 {
00049 }
00050 
00051 //----------------------------------------------------------------------------
00052 bool snl_fei::LinearSystem_FEData::eqnIsEssentialBC(int globalEqnIndex) const
00053 {
00054   FEI_CERR << "LinearSystem_FEData::eqnIsEssentialBC NOT IMPLEMENTED!!"<<FEI_ENDL;
00055   return(false);
00056 }
00057 
00058 //----------------------------------------------------------------------------
00059 void snl_fei::LinearSystem_FEData::getEssentialBCs(std::vector<int>& bcEqns,
00060                                               std::vector<double>& bcVals) const
00061 {
00062   FEI_CERR << "LinearSystem_FEData::getEssentialBC_Eqns NOT IMPLEMENTED!!"<<FEI_ENDL;
00063 }
00064 
00065 //----------------------------------------------------------------------------
00066 void snl_fei::LinearSystem_FEData::getConstrainedEqns(std::vector<int>& crEqns) const
00067 {
00068   matrixGraph_->getConstrainedIndices(crEqns);
00069 }
00070 
00071 //----------------------------------------------------------------------------
00072 int snl_fei::LinearSystem_FEData::loadComplete(bool applyBCs,
00073                                                bool globalAssemble)
00074 {
00075   if (dbcManager_ == NULL) {
00076     dbcManager_ = new fei::DirichletBCManager(matrixGraph_->getRowSpace());
00077   }
00078 
00079   int err = 0;
00080   if (matrix_.get() != NULL && globalAssemble) {
00081     err = matrix_->gatherFromOverlap();
00082     if (err != 0) {
00083       FEI_CERR << "snl_fei::LinearSystem_FEData::loadComplete, ERROR in matrix."
00084      << "gatherFromOverlap(), data may be incorrect."<<FEI_ENDL;
00085     }
00086   }
00087 
00088   fei::Barrier(comm_);
00089 
00090   if (rhs_.get() != NULL && globalAssemble) {
00091     err = rhs_->gatherFromOverlap();
00092     if (err != 0) {
00093       FEI_CERR << "snl_fei::LinearSystem_FEData::loadComplete, ERROR rhs."
00094         << "gatherFromOverlap(), data may be incorrect."<<FEI_ENDL;
00095     }
00096   }
00097 
00098   fei::Barrier(comm_);
00099 
00100   CHK_ERR( implementBCs(applyBCs) );
00101 
00102   return(feData_->loadComplete());
00103 }
00104 
00105 //----------------------------------------------------------------------------
00106 int snl_fei::LinearSystem_FEData::setBCValuesOnVector(fei::Vector* vector)
00107 {
00108   ERReturn(-1);
00109 }
00110 
00111 //----------------------------------------------------------------------------
00112 int snl_fei::LinearSystem_FEData::implementBCs(bool applyBCs)
00113 {
00114   std::vector<int> essEqns;
00115   std::vector<double> essGamma;
00116 
00117   fei::SharedPtr<fei::FillableMat> localBCeqns(new fei::FillableMat);
00118   fei::SharedPtr<fei::VectorSpace> vecSpace = matrixGraph_->getRowSpace();
00119   int localsize = vecSpace->getNumIndices_Owned();
00120   fei::Matrix_Impl<fei::FillableMat> bcEqns(localBCeqns, matrixGraph_, localsize);
00121 
00122   CHK_ERR( dbcManager_->finalizeBCEqns(bcEqns) );
00123 
00124   std::vector<fei::FillableMat*>& remote = bcEqns.getRemotelyOwnedMatrix();
00125   for(unsigned p=0; p<remote.size(); ++p) {
00126     fei::impl_utils::separate_BC_eqns( *(remote[p]), essEqns, essGamma);
00127   }
00128 
00129   CHK_ERR( bcEqns.gatherFromOverlap() );
00130 
00131   fei::impl_utils::separate_BC_eqns( *(bcEqns.getMatrix()), essEqns, essGamma);
00132 
00133   int len = essEqns.size();
00134   essEqns.resize(len*3);
00135 
00136   if (len > 0) {
00137     int* essEqnsPtr = &essEqns[0];
00138     double* gammaPtr = &essGamma[0];
00139 
00140     for(int i=0; i<len; ++i) {
00141       int eqn = essEqnsPtr[i];
00142       essEqnsPtr[i+len] = lookup_->getAssociatedNodeNumber(eqn);
00143       essEqnsPtr[i+2*len]=lookup_->getOffsetIntoBlkEqn(essEqnsPtr[i+len], eqn);
00144     }
00145 
00146     if (applyBCs) {
00147       CHK_ERR( feData_->setDirichletBCs(len, essEqnsPtr+len, essEqnsPtr+len*2,
00148                                         gammaPtr) );
00149     }
00150   }
00151 
00152   return(0);
00153 }
00154 
00155 //----------------------------------------------------------------------------
00156 int snl_fei::LinearSystem_FEData::
00157 loadLagrangeConstraint(int constraintID,
00158            const double *weights,
00159            double rhsValue)
00160 {
00161   return(-1);
00162 }
00163 
00164 //----------------------------------------------------------------------------
00165 int snl_fei::LinearSystem_FEData::
00166 loadPenaltyConstraint(int constraintID,
00167           const double *weights,
00168           double penaltyValue,
00169           double rhsValue)
00170 {
00171   return(-1);
00172 }

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