SundanceAssembler.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_ASSEMBLER_H
00032 #define SUNDANCE_ASSEMBLER_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "PlayaLoadableVector.hpp"
00036 #include "PlayaLoadableMatrix.hpp"
00037 #include "PlayaLinearOperatorDecl.hpp"
00038 #include "PlayaVectorDecl.hpp"
00039 #include "PlayaVectorType.hpp"
00040 #include "Teuchos_HashSet.hpp"
00041 #include "Teuchos_ParameterList.hpp"
00042 #include "PlayaIncrementallyConfigurableMatrixFactory.hpp"
00043 #include "PlayaCollectivelyConfigurableMatrixFactory.hpp"
00044 #include "SundanceRegionQuadCombo.hpp"
00045 #include "SundanceMesh.hpp"
00046 #include "SundanceEvalContext.hpp"
00047 #include "SundanceIntegrationCellSpecifier.hpp"
00048 #include "SundanceComputationType.hpp"
00049 
00050 
00051 namespace Sundance
00052 {
00053 using namespace Teuchos;
00054 using namespace Playa;
00055 
00056 class EquationSet;
00057 class EvaluatableExpr;
00058 class EvalManager;
00059 class EvalVector;
00060 class DiscreteSpace;
00061 class DiscreteFunction;
00062 class CellFilter;
00063 class DOFMapBase;
00064 class IntegralGroup;
00065 class StdFwkEvalMediator;
00066 class AssemblyKernelBase;
00067 
00068 typedef std::set<int> ColSetType;
00069 
00070 /** 
00071  * 
00072  */
00073 class Assembler 
00074 {
00075 public:
00076   /** */
00077   Assembler(
00078     const Mesh& mesh, 
00079     const RCP<EquationSet>& eqn,
00080     const Array<VectorType<double> >& rowVectorType,
00081     const Array<VectorType<double> >& colVectorType,
00082     bool partitionBCs);
00083 
00084 
00085   /** */
00086   Assembler(
00087     const Mesh& mesh, 
00088     const RCP<EquationSet>& eqn);
00089       
00090   /** */
00091   const Array<RCP<DOFMapBase> >& rowMap() const 
00092     {return rowMap_;}
00093 
00094   /** */
00095   const Array<RCP<DOFMapBase> >& colMap() const 
00096     {return colMap_;}
00097 
00098   /** */
00099   const Array<RCP<DiscreteSpace> >& solutionSpace() const 
00100     {return externalColSpace_;}
00101 
00102   /** */
00103   const Array<RCP<DiscreteSpace> >& rowSpace() const 
00104     {return externalRowSpace_;}
00105 
00106   /** */
00107   VectorSpace<double> solnVecSpace() const ;
00108 
00109   /** */
00110   VectorSpace<double> rowVecSpace() const ;
00111 
00112   /** */
00113   const Array<RCP<Set<int> > >& bcRows() const { return bcRows_; }
00114 
00115   /** Allocate, but do not fill, the matrix */
00116   Playa::LinearOperator<double> allocateMatrix() const ;
00117 
00118   /** */
00119   void assemble(Playa::LinearOperator<double>& A,
00120     Array<Vector<double> >& b) const ;
00121 
00122   /** */
00123   void assembleSensitivities(Playa::LinearOperator<double>& A,
00124     Array<Vector<double> >& b) const ;
00125 
00126 
00127   /** */
00128   void assemble(Array<Vector<double> >& b) const ;
00129 
00130   /** */
00131   void evaluate(double& value,
00132     Array<Vector<double> >& gradient) const ;
00133 
00134   /** */
00135   void evaluate(double& value) const ;
00136 
00137   /** */
00138   static int& workSetSize() ;
00139 
00140       
00141   /** */
00142   void getGraph(int br, int bc,
00143     Array<int>& graphData,
00144     Array<int>& rowPtrs,
00145     Array<int>& nnzPerRow) const ;
00146       
00147   /** */
00148   void incrementalGetGraph(int br, int bc, 
00149     IncrementallyConfigurableMatrixFactory* mf) const ;
00150 
00151   /** flushes all configuration , so that it enforces the reassemble of the matrix*/
00152   void flushConfiguration() const;
00153 
00154   /** */
00155   static int& numAssembleCalls() {static int rtn=0; return rtn;}
00156 
00157   /** */
00158   static bool& matrixEliminatesRepeatedCols() {static bool x = false; return x;}
00159 
00160   /** */
00161   const RCP<EquationSet>& eqnSet() const 
00162     {return eqn_;}
00163 
00164   /** */
00165   int maxWatchFlagSetting(const std::string& param) const ;
00166 
00167   /** */
00168   static Time& assemblyTimer() 
00169     {
00170       static RCP<Time> rtn 
00171         = TimeMonitor::getNewTimer("assembly"); 
00172       return *rtn;
00173     }
00174 
00175   /** */
00176   static Time& configTimer() 
00177     {
00178       static RCP<Time> rtn 
00179         = TimeMonitor::getNewTimer("matrix config"); 
00180       return *rtn;
00181     }
00182   
00183   /** */
00184   static Time& fillTimer() 
00185     {
00186       static RCP<Time> rtn 
00187         = TimeMonitor::getNewTimer("matrix/vector fill"); 
00188       return *rtn;
00189     }
00190   
00191 
00192 private:
00193 
00194   /** */
00195   void init(const Mesh& mesh, const RCP<EquationSet>& eqn);
00196 
00197   /** */
00198   bool detectInternalBdry(int cellDim, const CellFilter& filter) const ;
00199 
00200   /** */
00201   void displayEvaluationResults(
00202     const EvalContext& context, 
00203     const EvaluatableExpr* evalExpr, 
00204     const Array<double>& constantCoeffs, 
00205     const Array<RCP<EvalVector> >& vectorCoeffs) const ;
00206 
00207   /** */
00208   void assemblyLoop(const ComputationType& compType,
00209     RCP<AssemblyKernelBase> kernel) const ;
00210 
00211   /** */
00212   bool matNeedsConfiguration() const;
00213 
00214   /** */
00215   void configureMatrix(LinearOperator<double>& A,
00216     Array<Vector<double> >& b) const ;
00217 
00218   /** */
00219   void configureVector(Array<Vector<double> >& b) const ;
00220 
00221   /** */
00222   void configureMatrixBlock(int br, int bc, 
00223     LinearOperator<double>& A) const ;
00224 
00225   /** */
00226   void configureVectorBlock(int br, Vector<double>& b) const ;
00227 
00228   /** */
00229   Array<Array<int> > findNonzeroBlocks() const ;
00230 
00231   /** */
00232   IntegrationCellSpecifier whetherToUseCofacets(
00233     const Array<RCP<IntegralGroup> >& groups,
00234     const EvaluatableExpr* ee,
00235     bool isMaximalCell,
00236     int verb) const ;
00237 
00238   
00239   
00240   /** */
00241   static int defaultWorkSetSize() {static int rtn=100; return rtn;}
00242 
00243   bool partitionBCs_;
00244 
00245   mutable int numConfiguredColumns_;
00246 
00247   Mesh mesh_;
00248 
00249   RCP<EquationSet> eqn_;
00250 
00251   Array<RCP<DOFMapBase> > rowMap_;
00252 
00253   Array<RCP<DOFMapBase> > colMap_;
00254 
00255   Array<RCP<DiscreteSpace> > externalRowSpace_;
00256 
00257   Array<RCP<DiscreteSpace> > externalColSpace_;
00258 
00259   Array<RCP<DiscreteSpace> > privateRowSpace_;
00260 
00261   Array<RCP<DiscreteSpace> > privateColSpace_;
00262 
00263   Array<RCP<Set<int> > > bcRows_;
00264 
00265   Array<RegionQuadCombo> rqc_;
00266 
00267   Map<ComputationType, Array<EvalContext> > contexts_;
00268 
00269   Map<ComputationType, Array<int> > skipRqc_;
00270 
00271   Array<int> isBCRqc_;
00272 
00273   Array<int> isInternalBdry_;
00274 
00275   Map<ComputationType, Array<Array<RCP<IntegralGroup> > > > groups_;
00276 
00277   Array<RCP<StdFwkEvalMediator> > mediators_;
00278 
00279   Map<ComputationType, Array<const EvaluatableExpr*> > evalExprs_;
00280 
00281   RCP<EvalManager> evalMgr_;
00282 
00283   Array<RCP<Array<int> > > isBCRow_;
00284 
00285   Array<RCP<Array<int> > > isBCCol_;
00286 
00287   Array<RCP<std::set<int> > > remoteBCCols_;
00288 
00289   Array<int> lowestRow_;
00290 
00291   Array<int> lowestCol_;
00292 
00293   Array<VectorType<double> > rowVecType_;
00294 
00295   Array<VectorType<double> > colVecType_;
00296 
00297   Map<int, int> testIDToBlockMap_;
00298 
00299   Map<int, int> unkIDToBlockMap_;
00300 
00301   Map<int, int> fixedParamIDToVectorNumber_;
00302 
00303   Map<ComputationType, Array<IntegrationCellSpecifier> > rqcRequiresMaximalCofacets_;
00304 
00305   /** Cached reference to the previously assembled matrix
00306    *  A null value signals that matrix must be assembled */
00307   mutable LinearOperator<double> cachedAssembledMatrix_;
00308 };
00309 
00310 }
00311 
00312 
00313 
00314 #endif

Site Contact