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::console_out() << "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::console_out() << "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::console_out() << "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::console_out() << "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   bool zeroSharedRows = false;
00121   fei::Matrix_Impl<fei::FillableMat> bcEqns(localBCeqns, matrixGraph_, localsize, zeroSharedRows);
00122 
00123   CHK_ERR( dbcManager_->finalizeBCEqns(bcEqns) );
00124 
00125   std::map<int,fei::FillableMat*>& remotes = bcEqns.getRemotelyOwnedMatrices();
00126   std::map<int,fei::FillableMat*>::iterator
00127     it = remotes.begin(),
00128     it_end = remotes.end();
00129   for(; it!=it_end; ++it) {
00130     fei::impl_utils::separate_BC_eqns( *(it->second), essEqns, essGamma);
00131   }
00132 
00133   CHK_ERR( bcEqns.gatherFromOverlap() );
00134 
00135   fei::impl_utils::separate_BC_eqns( *(bcEqns.getMatrix()), essEqns, essGamma);
00136 
00137   int len = essEqns.size();
00138   essEqns.resize(len*3);
00139   int* nodeNumbers = &essEqns[0]+len;
00140   int* dof_ids = nodeNumbers+len;
00141 
00142   if (len > 0) {
00143     int* essEqnsPtr = &essEqns[0];
00144     double* gammaPtr = &essGamma[0];
00145 
00146     for(int i=0; i<len; ++i) {
00147       int eqn = essEqnsPtr[i];
00148       nodeNumbers[i] = lookup_->getAssociatedNodeNumber(eqn);
00149       int fieldID = lookup_->getAssociatedFieldID(eqn);
00150       int base_eqn = lookup_->getEqnNumber(nodeNumbers[i], fieldID);
00151       dof_ids[i]=vecSpace->getFieldDofMap().get_dof_id(fieldID, eqn-base_eqn);
00152     }
00153 
00154     if (applyBCs) {
00155       CHK_ERR( feData_->setDirichletBCs(len, nodeNumbers, dof_ids, gammaPtr) );
00156     }
00157   }
00158 
00159   return(0);
00160 }
00161 
00162 //----------------------------------------------------------------------------
00163 int snl_fei::LinearSystem_FEData::
00164 loadLagrangeConstraint(int constraintID,
00165            const double *weights,
00166            double rhsValue)
00167 {
00168   return(-1);
00169 }
00170 
00171 //----------------------------------------------------------------------------
00172 int snl_fei::LinearSystem_FEData::
00173 loadPenaltyConstraint(int constraintID,
00174           const double *weights,
00175           double penaltyValue,
00176           double rhsValue)
00177 {
00178   return(-1);
00179 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends