SundanceVectorFillingAssemblyKernel.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the 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 Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #include "SundanceOut.hpp"
00043 #include "PlayaTabs.hpp"
00044 #include "SundanceVectorFillingAssemblyKernel.hpp"
00045 #include "Teuchos_Time.hpp"
00046 #include "Teuchos_TimeMonitor.hpp"
00047 
00048 
00049 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00050 #include "PlayaVectorImpl.hpp"
00051 #endif
00052 
00053 using namespace Sundance;
00054 using namespace Sundance;
00055 using namespace Sundance;
00056 using namespace Teuchos;
00057 using namespace Playa;
00058 using std::setw;
00059 using std::endl;
00060       
00061 static Time& vecInsertTimer() 
00062 {
00063   static RCP<Time> rtn 
00064     = TimeMonitor::getNewTimer("vector insertion"); 
00065   return *rtn;
00066 }
00067 
00068 VectorFillingAssemblyKernel::VectorFillingAssemblyKernel(
00069   const Array<RCP<DOFMapBase> >& dofMap,
00070   const Array<RCP<Array<int> > >& isBCIndex,
00071   const Array<int>& lowestLocalIndex,
00072   Array<Vector<double> >& b,
00073   bool partitionBCs,
00074   int verbosity
00075   )
00076   : AssemblyKernelBase(verbosity),
00077     b_(b),
00078     vec_(b.size()),
00079     mapBundle_(dofMap, isBCIndex, lowestLocalIndex, partitionBCs, verbosity)
00080 {
00081   Tabs tab0;
00082 
00083   SUNDANCE_MSG1(verb(), tab0 << "VectorFillingAssemblyKernel ctor");
00084   
00085   int numBlocks = dofMap.size();
00086 
00087   for (int i=0; i<b_.size(); i++)
00088   {
00089     vec_[i].resize(numBlocks);
00090     for (int block=0; block<numBlocks; block++)
00091     {
00092       Tabs tab1;
00093       SUNDANCE_MSG1(verb(), tab1 << "getting vector for block b=" 
00094         << block << " of " << numBlocks);
00095       Vector<double> vecBlock = b[i].getBlock(block);
00096       vec_[i][block] = rcp_dynamic_cast<LoadableVector<double> >(vecBlock.ptr());
00097 
00098       TEUCHOS_TEST_FOR_EXCEPTION(vec_[i][block].get()==0, std::runtime_error,
00099         "vector block " << block << " is not loadable");
00100       vecBlock.zero();
00101     }
00102   }
00103   SUNDANCE_MSG1(verb(), tab0 << "done VectorFillingAssemblyKernel ctor");
00104 }
00105 
00106 
00107 void VectorFillingAssemblyKernel::buildLocalDOFMaps(
00108   const RCP<StdFwkEvalMediator>& mediator,
00109   IntegrationCellSpecifier intCellSpec,
00110   const Array<Set<int> >& requiredFuncs) 
00111 {
00112   mapBundle_.buildLocalDOFMaps(mediator, intCellSpec, requiredFuncs,
00113     verb());
00114 }
00115 
00116 
00117 void VectorFillingAssemblyKernel::insertLocalVectorBatch(
00118   bool isBCRqc,
00119   bool useCofacetCells,
00120   const Array<int>& funcID,  
00121   const Array<int>& funcBlock, 
00122   const Array<int>& mvIndices, 
00123   const Array<double>& localValues) const
00124 {
00125   TimeMonitor timer(vecInsertTimer());
00126   Tabs tab0;
00127 
00128   SUNDANCE_MSG1(verb(), tab0 << "inserting local vector batch");
00129   SUNDANCE_MSG4(verb(), tab0 << "vector values are " << localValues);
00130 
00131   const MapBundle& mb = mapBundle_;
00132   int nCells = mb.nCells();
00133 
00134   for (int i=0; i<funcID.size(); i++)
00135   {
00136     Tabs tab1;
00137     SUNDANCE_MSG2(verb(), tab1 << "function ID = "<< funcID[i] 
00138       << " of " << funcID.size());
00139     SUNDANCE_MSG2(verb(), tab1 << "is BC eqn = " << isBCRqc);
00140     SUNDANCE_MSG2(verb(), tab1 << "num cells = " << nCells);
00141     SUNDANCE_MSG2(verb(), tab1 << "using cofacet cells = " << useCofacetCells);
00142     SUNDANCE_MSG2(verb(), tab1 << "multivector index = " 
00143       << mvIndices[i]);
00144 
00145     /* First, find the block associated with the current function
00146      * so that we can find the appropriate DOF information */
00147     int block = funcBlock[i];
00148 
00149     const RCP<DOFMapBase>& dofMap = mb.dofMap(block);
00150     int lowestLocalRow = mb.lowestLocalIndex(block);
00151 
00152     int chunk = mb.mapStruct(block, useCofacetCells)->chunkForFuncID(funcID[i]);
00153     SUNDANCE_MSG2(verb(), tab1 << "chunk = " << chunk);
00154 
00155     int funcIndex = mb.mapStruct(block, useCofacetCells)->indexForFuncID(funcID[i]);
00156     SUNDANCE_MSG2(verb(), tab1 << "func offset into local DOF map = " 
00157       << funcIndex);
00158 
00159     const Array<int>& dofs = mb.localDOFs(block, useCofacetCells, chunk);
00160     SUNDANCE_MSG4(verb(), tab1 << "local dofs = " << dofs);    
00161 
00162     int nFuncs = mb.mapStruct(block, useCofacetCells)->numFuncs(chunk);
00163     SUNDANCE_MSG2(verb(), tab1 << "num funcs in chunk = " << nFuncs);
00164 
00165     int nNodes = mb.nNodesInChunk(block, useCofacetCells, chunk);
00166     SUNDANCE_MSG2(verb(), tab1 << "num nodes in chunk = " << nNodes);
00167 
00168     const Array<int>& isBCIndex = *(mb.isBCIndex(block));
00169 
00170     /* At this point, we can start to load the elements */
00171     int r=0;
00172     RCP<Playa::LoadableVector<double> > vecBlock 
00173       = vec_[mvIndices[i]][block];
00174 
00175     FancyOStream& os = Out::os();
00176 
00177     for (int c=0; c<nCells; c++)
00178     {
00179       Tabs tab2;
00180       SUNDANCE_MSG2(verb(), tab2 << "cell = " << c << " of " << nCells);
00181       for (int n=0; n<nNodes; n++, r++)
00182       {
00183         Tabs tab3;
00184         int rowIndex = dofs[(c*nFuncs + funcIndex)*nNodes + n];
00185         int localRowIndex = rowIndex - lowestLocalRow;
00186         if (verb() >= 2) os << tab3 << "n=" << setw(4) << n 
00187                             << " G=" << setw(8) << rowIndex 
00188                             << " L=" << setw(8) << localRowIndex;
00189         if (!(dofMap->isLocalDOF(rowIndex))
00190           || isBCRqc!=isBCIndex[localRowIndex]) 
00191         {
00192           if (verb() >= 2)
00193           {
00194             if (!dofMap->isLocalDOF(rowIndex)) 
00195             {
00196               os << " --- skipping (is non-local) ---" << std::endl;
00197             }
00198             else if (!isBCRqc && isBCIndex[localRowIndex])
00199             {
00200               os << " --- skipping (is BC row) ---" << std::endl;
00201             }
00202             else
00203             {
00204               os << " --- skipping (is non-BC row) ---" << std::endl;
00205             }
00206           }
00207         }
00208         else
00209         {
00210           if (verb() >= 2) os << setw(15) << localValues[r] << std::endl;
00211           vecBlock->addToElement(rowIndex, localValues[r]);
00212         }
00213       }
00214     }
00215   }
00216   SUNDANCE_MSG1(verb(), tab0 << "...done vector insertion");
00217 }
00218 
00219 

Site Contact