00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
00146
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
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