SundanceAssembler.hpp
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 #ifndef SUNDANCE_ASSEMBLER_H
00043 #define SUNDANCE_ASSEMBLER_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "PlayaLoadableVector.hpp"
00047 #include "PlayaLoadableMatrix.hpp"
00048 #include "PlayaLinearOperatorDecl.hpp"
00049 #include "PlayaVectorDecl.hpp"
00050 #include "PlayaVectorType.hpp"
00051 #include "Teuchos_HashSet.hpp"
00052 #include "Teuchos_ParameterList.hpp"
00053 #include "PlayaIncrementallyConfigurableMatrixFactory.hpp"
00054 #include "PlayaCollectivelyConfigurableMatrixFactory.hpp"
00055 #include "SundanceRegionQuadCombo.hpp"
00056 #include "SundanceMesh.hpp"
00057 #include "SundanceEvalContext.hpp"
00058 #include "SundanceIntegrationCellSpecifier.hpp"
00059 #include "SundanceComputationType.hpp"
00060 
00061 
00062 namespace Sundance
00063 {
00064 using namespace Teuchos;
00065 using namespace Playa;
00066 
00067 class EquationSet;
00068 class EvaluatableExpr;
00069 class EvalManager;
00070 class EvalVector;
00071 class DiscreteSpace;
00072 class DiscreteFunction;
00073 class CellFilter;
00074 class DOFMapBase;
00075 class IntegralGroup;
00076 class StdFwkEvalMediator;
00077 class AssemblyKernelBase;
00078 
00079 typedef std::set<int> ColSetType;
00080 
00081 /** 
00082  * 
00083  */
00084 class Assembler 
00085 {
00086 public:
00087   /** */
00088   Assembler(
00089     const Mesh& mesh, 
00090     const RCP<EquationSet>& eqn,
00091     const Array<VectorType<double> >& rowVectorType,
00092     const Array<VectorType<double> >& colVectorType,
00093     bool partitionBCs);
00094 
00095 
00096   /** */
00097   Assembler(
00098     const Mesh& mesh, 
00099     const RCP<EquationSet>& eqn);
00100       
00101   /** */
00102   const Array<RCP<DOFMapBase> >& rowMap() const 
00103     {return rowMap_;}
00104 
00105   /** */
00106   const Array<RCP<DOFMapBase> >& colMap() const 
00107     {return colMap_;}
00108 
00109   /** */
00110   const Array<RCP<DiscreteSpace> >& solutionSpace() const 
00111     {return externalColSpace_;}
00112 
00113   /** */
00114   const Array<RCP<DiscreteSpace> >& rowSpace() const 
00115     {return externalRowSpace_;}
00116 
00117   /** */
00118   VectorSpace<double> solnVecSpace() const ;
00119 
00120   /** */
00121   VectorSpace<double> rowVecSpace() const ;
00122 
00123   /** */
00124   const Array<RCP<Set<int> > >& bcRows() const { return bcRows_; }
00125 
00126   /** Allocate, but do not fill, the matrix */
00127   Playa::LinearOperator<double> allocateMatrix() const ;
00128 
00129   /** */
00130   void assemble(Playa::LinearOperator<double>& A,
00131     Array<Vector<double> >& b) const ;
00132 
00133   /** */
00134   void assembleSensitivities(Playa::LinearOperator<double>& A,
00135     Array<Vector<double> >& b) const ;
00136 
00137 
00138   /** */
00139   void assemble(Array<Vector<double> >& b) const ;
00140 
00141   /** */
00142   void evaluate(double& value,
00143     Array<Vector<double> >& gradient) const ;
00144 
00145   /** */
00146   void evaluate(double& value) const ;
00147 
00148   /** */
00149   static int& workSetSize() ;
00150 
00151       
00152   /** */
00153   void getGraph(int br, int bc,
00154     Array<int>& graphData,
00155     Array<int>& rowPtrs,
00156     Array<int>& nnzPerRow) const ;
00157       
00158   /** */
00159   void incrementalGetGraph(int br, int bc, 
00160     IncrementallyConfigurableMatrixFactory* mf) const ;
00161 
00162   /** flushes all configuration , so that it enforces the reassemble of the matrix*/
00163   void flushConfiguration() const;
00164 
00165   /** */
00166   static int& numAssembleCalls() {static int rtn=0; return rtn;}
00167 
00168   /** */
00169   static bool& matrixEliminatesRepeatedCols() {static bool x = false; return x;}
00170 
00171   /** */
00172   const RCP<EquationSet>& eqnSet() const 
00173     {return eqn_;}
00174 
00175   /** */
00176   int maxWatchFlagSetting(const std::string& param) const ;
00177 
00178   /** */
00179   static Time& assemblyTimer() 
00180     {
00181       static RCP<Time> rtn 
00182         = TimeMonitor::getNewTimer("assembly"); 
00183       return *rtn;
00184     }
00185 
00186   /** */
00187   static Time& configTimer() 
00188     {
00189       static RCP<Time> rtn 
00190         = TimeMonitor::getNewTimer("matrix config"); 
00191       return *rtn;
00192     }
00193   
00194   /** */
00195   static Time& fillTimer() 
00196     {
00197       static RCP<Time> rtn 
00198         = TimeMonitor::getNewTimer("matrix/vector fill"); 
00199       return *rtn;
00200     }
00201   
00202 
00203 private:
00204 
00205   /** */
00206   void init(const Mesh& mesh, const RCP<EquationSet>& eqn);
00207 
00208   /** */
00209   bool detectInternalBdry(int cellDim, const CellFilter& filter) const ;
00210 
00211   /** */
00212   void displayEvaluationResults(
00213     const EvalContext& context, 
00214     const EvaluatableExpr* evalExpr, 
00215     const Array<double>& constantCoeffs, 
00216     const Array<RCP<EvalVector> >& vectorCoeffs) const ;
00217 
00218   /** */
00219   void assemblyLoop(const ComputationType& compType,
00220     RCP<AssemblyKernelBase> kernel) const ;
00221 
00222   /** */
00223   bool matNeedsConfiguration() const;
00224 
00225   /** */
00226   void configureMatrix(LinearOperator<double>& A,
00227     Array<Vector<double> >& b) const ;
00228 
00229   /** */
00230   void configureVector(Array<Vector<double> >& b) const ;
00231 
00232   /** */
00233   void configureMatrixBlock(int br, int bc, 
00234     LinearOperator<double>& A) const ;
00235 
00236   /** */
00237   void configureVectorBlock(int br, Vector<double>& b) const ;
00238 
00239   /** */
00240   Array<Array<int> > findNonzeroBlocks() const ;
00241 
00242   /** */
00243   IntegrationCellSpecifier whetherToUseCofacets(
00244     const Array<RCP<IntegralGroup> >& groups,
00245     const EvaluatableExpr* ee,
00246     bool isMaximalCell,
00247     int verb) const ;
00248 
00249   
00250   
00251   /** */
00252   static int defaultWorkSetSize() {static int rtn=100; return rtn;}
00253 
00254   bool partitionBCs_;
00255 
00256   mutable int numConfiguredColumns_;
00257 
00258   Mesh mesh_;
00259 
00260   RCP<EquationSet> eqn_;
00261 
00262   Array<RCP<DOFMapBase> > rowMap_;
00263 
00264   Array<RCP<DOFMapBase> > colMap_;
00265 
00266   Array<RCP<DiscreteSpace> > externalRowSpace_;
00267 
00268   Array<RCP<DiscreteSpace> > externalColSpace_;
00269 
00270   Array<RCP<DiscreteSpace> > privateRowSpace_;
00271 
00272   Array<RCP<DiscreteSpace> > privateColSpace_;
00273 
00274   Array<RCP<Set<int> > > bcRows_;
00275 
00276   Array<RegionQuadCombo> rqc_;
00277 
00278   Map<ComputationType, Array<EvalContext> > contexts_;
00279 
00280   Map<ComputationType, Array<int> > skipRqc_;
00281 
00282   Array<int> isBCRqc_;
00283 
00284   Array<int> isInternalBdry_;
00285 
00286   Map<ComputationType, Array<Array<RCP<IntegralGroup> > > > groups_;
00287 
00288   Array<RCP<StdFwkEvalMediator> > mediators_;
00289 
00290   Map<ComputationType, Array<const EvaluatableExpr*> > evalExprs_;
00291 
00292   RCP<EvalManager> evalMgr_;
00293 
00294   Array<RCP<Array<int> > > isBCRow_;
00295 
00296   Array<RCP<Array<int> > > isBCCol_;
00297 
00298   Array<RCP<std::set<int> > > remoteBCCols_;
00299 
00300   Array<int> lowestRow_;
00301 
00302   Array<int> lowestCol_;
00303 
00304   Array<VectorType<double> > rowVecType_;
00305 
00306   Array<VectorType<double> > colVecType_;
00307 
00308   Map<int, int> testIDToBlockMap_;
00309 
00310   Map<int, int> unkIDToBlockMap_;
00311 
00312   Map<int, int> fixedParamIDToVectorNumber_;
00313 
00314   Map<ComputationType, Array<IntegrationCellSpecifier> > rqcRequiresMaximalCofacets_;
00315 
00316   /** Cached reference to the previously assembled matrix
00317    *  A null value signals that matrix must be assembled */
00318   mutable LinearOperator<double> cachedAssembledMatrix_;
00319 };
00320 
00321 }
00322 
00323 
00324 
00325 #endif

Site Contact