FEI Version of the Day
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   int* nodeNumbers = &essEqns[0]+len;
00136   int* dof_ids = nodeNumbers+len;
00137 
00138   if (len > 0) {
00139     int* essEqnsPtr = &essEqns[0];
00140     double* gammaPtr = &essGamma[0];
00141 
00142     for(int i=0; i<len; ++i) {
00143       int eqn = essEqnsPtr[i];
00144       nodeNumbers[i] = lookup_->getAssociatedNodeNumber(eqn);
00145       int fieldID = lookup_->getAssociatedFieldID(eqn);
00146       int base_eqn = lookup_->getEqnNumber(nodeNumbers[i], fieldID);
00147       dof_ids[i]=vecSpace->getFieldDofMap().get_dof_id(fieldID, eqn-base_eqn);
00148     }
00149 
00150     if (applyBCs) {
00151       CHK_ERR( feData_->setDirichletBCs(len, nodeNumbers, dof_ids, gammaPtr) );
00152     }
00153   }
00154 
00155   return(0);
00156 }
00157 
00158 //----------------------------------------------------------------------------
00159 int snl_fei::LinearSystem_FEData::
00160 loadLagrangeConstraint(int constraintID,
00161            const double *weights,
00162            double rhsValue)
00163 {
00164   return(-1);
00165 }
00166 
00167 //----------------------------------------------------------------------------
00168 int snl_fei::LinearSystem_FEData::
00169 loadPenaltyConstraint(int constraintID,
00170           const double *weights,
00171           double penaltyValue,
00172           double rhsValue)
00173 {
00174   return(-1);
00175 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends