FEI Version of the Day
snl_fei_LinearSystem_FEData.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 #include <math.h>
00044 
00045 #include <fei_macros.hpp>
00046 
00047 #include <fei_FiniteElementData.hpp>
00048 
00049 #include <fei_CommUtils.hpp>
00050 #include <snl_fei_LinearSystem_FEData.hpp>
00051 #include <fei_VectorSpace.hpp>
00052 #include <fei_MatrixGraph.hpp>
00053 #include <fei_Matrix_Impl.hpp>
00054 #include <snl_fei_Constraint.hpp>
00055 #include <snl_fei_Utils.hpp>
00056 #include <fei_impl_utils.hpp>
00057 
00058 #include <fei_DirichletBCRecord.hpp>
00059 #include <fei_DirichletBCManager.hpp>
00060 #include <fei_EqnBuffer.hpp>
00061 #include <fei_FEDataFilter.hpp>
00062 
00063 #undef fei_file
00064 #define fei_file "snl_fei_LinearSystem_FEData.cpp"
00065 #include <fei_ErrMacros.hpp>
00066 
00067 //----------------------------------------------------------------------------
00068 snl_fei::LinearSystem_FEData::LinearSystem_FEData(fei::SharedPtr<FiniteElementData>& feData,
00069               fei::SharedPtr<fei::MatrixGraph>& matrixGraph)
00070   : fei::LinearSystem(matrixGraph),
00071     comm_(matrixGraph->getRowSpace()->getCommunicator()),
00072     localProc_(0),
00073     numProcs_(1),
00074     feData_(feData),
00075     lookup_(NULL)
00076 {
00077   localProc_ = fei::localProc(comm_);
00078   numProcs_  = fei::numProcs(comm_);
00079 }
00080 
00081 //----------------------------------------------------------------------------
00082 snl_fei::LinearSystem_FEData::~LinearSystem_FEData()
00083 {
00084 }
00085 
00086 //----------------------------------------------------------------------------
00087 bool snl_fei::LinearSystem_FEData::eqnIsEssentialBC(int globalEqnIndex) const
00088 {
00089   fei::console_out() << "LinearSystem_FEData::eqnIsEssentialBC NOT IMPLEMENTED!!"<<FEI_ENDL;
00090   return(false);
00091 }
00092 
00093 //----------------------------------------------------------------------------
00094 void snl_fei::LinearSystem_FEData::getEssentialBCs(std::vector<int>& bcEqns,
00095                                               std::vector<double>& bcVals) const
00096 {
00097   fei::console_out() << "LinearSystem_FEData::getEssentialBC_Eqns NOT IMPLEMENTED!!"<<FEI_ENDL;
00098 }
00099 
00100 //----------------------------------------------------------------------------
00101 void snl_fei::LinearSystem_FEData::getConstrainedEqns(std::vector<int>& crEqns) const
00102 {
00103   matrixGraph_->getConstrainedIndices(crEqns);
00104 }
00105 
00106 //----------------------------------------------------------------------------
00107 int snl_fei::LinearSystem_FEData::loadComplete(bool applyBCs,
00108                                                bool globalAssemble)
00109 {
00110   if (dbcManager_ == NULL) {
00111     dbcManager_ = new fei::DirichletBCManager(matrixGraph_->getRowSpace());
00112   }
00113 
00114   int err = 0;
00115   if (matrix_.get() != NULL && globalAssemble) {
00116     err = matrix_->gatherFromOverlap();
00117     if (err != 0) {
00118       fei::console_out() << "snl_fei::LinearSystem_FEData::loadComplete, ERROR in matrix."
00119      << "gatherFromOverlap(), data may be incorrect."<<FEI_ENDL;
00120     }
00121   }
00122 
00123   fei::Barrier(comm_);
00124 
00125   if (rhs_.get() != NULL && globalAssemble) {
00126     err = rhs_->gatherFromOverlap();
00127     if (err != 0) {
00128       fei::console_out() << "snl_fei::LinearSystem_FEData::loadComplete, ERROR rhs."
00129         << "gatherFromOverlap(), data may be incorrect."<<FEI_ENDL;
00130     }
00131   }
00132 
00133   fei::Barrier(comm_);
00134 
00135   CHK_ERR( implementBCs(applyBCs) );
00136 
00137   return(feData_->loadComplete());
00138 }
00139 
00140 //----------------------------------------------------------------------------
00141 int snl_fei::LinearSystem_FEData::setBCValuesOnVector(fei::Vector* vector)
00142 {
00143   ERReturn(-1);
00144 }
00145 
00146 //----------------------------------------------------------------------------
00147 int snl_fei::LinearSystem_FEData::implementBCs(bool applyBCs)
00148 {
00149   std::vector<int> essEqns;
00150   std::vector<double> essGamma;
00151 
00152   fei::SharedPtr<fei::FillableMat> localBCeqns(new fei::FillableMat);
00153   fei::SharedPtr<fei::VectorSpace> vecSpace = matrixGraph_->getRowSpace();
00154   int localsize = vecSpace->getNumIndices_Owned();
00155   bool zeroSharedRows = false;
00156   fei::Matrix_Impl<fei::FillableMat> bcEqns(localBCeqns, matrixGraph_, localsize, zeroSharedRows);
00157 
00158   CHK_ERR( dbcManager_->finalizeBCEqns(bcEqns) );
00159 
00160   std::map<int,fei::FillableMat*>& remotes = bcEqns.getRemotelyOwnedMatrices();
00161   std::map<int,fei::FillableMat*>::iterator
00162     it = remotes.begin(),
00163     it_end = remotes.end();
00164   for(; it!=it_end; ++it) {
00165     fei::impl_utils::separate_BC_eqns( *(it->second), essEqns, essGamma);
00166   }
00167 
00168   CHK_ERR( bcEqns.gatherFromOverlap() );
00169 
00170   fei::impl_utils::separate_BC_eqns( *(bcEqns.getMatrix()), essEqns, essGamma);
00171 
00172   int len = essEqns.size();
00173   essEqns.resize(len*3);
00174   int* nodeNumbers = &essEqns[0]+len;
00175   int* dof_ids = nodeNumbers+len;
00176 
00177   if (len > 0) {
00178     int* essEqnsPtr = &essEqns[0];
00179     double* gammaPtr = &essGamma[0];
00180 
00181     for(int i=0; i<len; ++i) {
00182       int eqn = essEqnsPtr[i];
00183       nodeNumbers[i] = lookup_->getAssociatedNodeNumber(eqn);
00184       int fieldID = lookup_->getAssociatedFieldID(eqn);
00185       int base_eqn = lookup_->getEqnNumber(nodeNumbers[i], fieldID);
00186       dof_ids[i]=vecSpace->getFieldDofMap().get_dof_id(fieldID, eqn-base_eqn);
00187     }
00188 
00189     if (applyBCs) {
00190       CHK_ERR( feData_->setDirichletBCs(len, nodeNumbers, dof_ids, gammaPtr) );
00191     }
00192   }
00193 
00194   return(0);
00195 }
00196 
00197 //----------------------------------------------------------------------------
00198 int snl_fei::LinearSystem_FEData::
00199 loadLagrangeConstraint(int constraintID,
00200            const double *weights,
00201            double rhsValue)
00202 {
00203   return(-1);
00204 }
00205 
00206 //----------------------------------------------------------------------------
00207 int snl_fei::LinearSystem_FEData::
00208 loadPenaltyConstraint(int constraintID,
00209           const double *weights,
00210           double penaltyValue,
00211           double rhsValue)
00212 {
00213   return(-1);
00214 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends