SundanceFunctionSupportResolver.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_FUNCTION_SUPPORT_RESOLVER_H
00032 #define SUNDANCE_FUNCTION_SUPPORT_RESOLVER_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceExpr.hpp"
00036 #include "SundanceSet.hpp"
00037 #include "SundanceMap.hpp"
00038 #include "SundanceOrderedHandle.hpp"
00039 #include "SundanceCellFilterStub.hpp"
00040 
00041 
00042 namespace Sundance
00043 {
00044 
00045 class SumOfIntegrals;
00046 class SumOfBCs;
00047 class CommonFuncDataStub;
00048 
00049 /** */
00050 class FunctionSupportResolver
00051 {
00052 public:
00053   /** */
00054   FunctionSupportResolver(
00055     const Expr& eqns,
00056     const Expr& bcs,
00057     const Array<Expr>& vars,
00058     const Array<Expr>& unks,
00059     const Expr& unkParams,
00060     const Expr& params,
00061     const Array<Expr>& fixedFields,
00062     bool isVariational);
00063   
00064   
00065   /** \name Getting information about functions */
00066   //@{
00067   /** Returns the number of variational function blocks */
00068   int numVarBlocks() const {return varFuncs_.size();}
00069 
00070   /** Returns the number of unknown function blocks */
00071   int numUnkBlocks() const {return unkFuncs_.size();}
00072 
00073   /** Returns the number of unknown parameters */
00074   int numUnkParams() const {return unkParams_.size();}
00075 
00076   /** Returns the number of fixed parameters */
00077   int numFixedParams() const {return fixedParams_.size();}
00078 
00079   /** Returns the number of variational functions in this block */
00080   int numVars(int block) const {return varFuncs_[block].size();}
00081 
00082   /** Returns the number of unk functions in this block */
00083   int numUnks(int block) const {return unkFuncs_[block].size();}
00084 
00085   /** Returns the number of variational function IDs in this block.
00086    * This will differ from the number of variational functions in cases
00087    * where a vector field uses a single vector-valued basis rather
00088    * than scalar bases for each component. */
00089   int numVarIDs(int block) const {return varFuncData_[block].size();}
00090 
00091   /** Returns the number of unk function IDs in this block.
00092    * This will differ from the number of unknown functions in cases
00093    * where a vector field uses a single vector-valued basis rather
00094    * than scalar bases for each component. */ 
00095   int numUnkIDs(int block) const {return unkFuncData_[block].size();}
00096 
00097   /** Returns the data for the i-th variational function in block b */
00098   RCP<const CommonFuncDataStub> varFuncData(int b, int i) const {return varFuncData_[b][i];}
00099 
00100   /** Returns the data for the i-th unknown function in block b */
00101   RCP<const CommonFuncDataStub> unkFuncData(int b, int i) const {return unkFuncData_[b][i];}
00102 
00103   /** Returns the i-th unknown parameter */
00104   const Expr& unkParam(int i) const {return unkParams_[i];}
00105 
00106   /** Determine whether a given func ID is listed as a 
00107    * variational function in this equation set */
00108   bool hasVarID(int fid) const 
00109     {return varIDToBlockMap_.containsKey(fid);}
00110 
00111   /** Determine whether a given func ID is listed as a unk function 
00112    * in this equation set */
00113   bool hasUnkID(int fid) const 
00114     {return unkIDToBlockMap_.containsKey(fid);}
00115 
00116   /** Determine whether a given func ID is listed as a unk parameter 
00117    * in this equation set */
00118   bool hasUnkParamID(int fid) const 
00119     {return unkParamIDToReducedUnkParamIDMap_.containsKey(fid);}
00120 
00121   /** Determine whether a given func ID is listed as a fixed parameter 
00122    * in this equation set */
00123   bool hasFixedParamID(int fid) const 
00124     {return fixedParamIDToReducedFixedParamIDMap_.containsKey(fid);}
00125 
00126   /** get the block number for the variational function having the
00127    * specified unreduced funcID */
00128   int blockForVarID(int varID) const ;
00129 
00130   /** get the block number for the unknown function having the
00131    * specified unreduced funcID */
00132   int blockForUnkID(int unkID) const ;
00133   //@}
00134 
00135 
00136   /** \name Finding the functions that appear on regions */
00137   //@{
00138   /** Returns the variational functions that appear explicitly
00139    * on the d-th region */
00140   const Set<int>& varsOnRegion(int d) const 
00141     {return varsOnRegions_.get(regions_[d]);}
00142 
00143   /** Returns the unknown functions that appear explicitly on the
00144    * d-th region. */
00145   const Set<int>& unksOnRegion(int d) const 
00146     {return unksOnRegions_.get(regions_[d]);}
00147 
00148   /** Returns the variational functions that 
00149    * appear in BCs on the d-th region.
00150    * We can use this information to tag certain rows as BC rows */
00151   const Set<int>& bcVarsOnRegion(int d) const 
00152     {return bcVarsOnRegions_.get(regions_[d]);}
00153 
00154   /** Returns the unknown functions that appear in BCs on the d-th region.
00155    * We can use this information to tag certain columns as BC
00156    * columns in the event we're doing symmetrized BC application */
00157   const Set<int>& bcUnksOnRegion(int d) const 
00158     {return bcUnksOnRegions_.get(regions_[d]);}
00159 
00160   /** Returns the reduced variational functions that appear explicitly
00161    * on the d-th region */
00162   const Array<Set<int> >& reducedVarsOnRegion(const OrderedHandle<CellFilterStub>& r) const 
00163     {return reducedVarsOnRegions_[indexForRegion(r)];}
00164 
00165   /** Returns the reduced unknown functions that appear explicitly on the
00166    * d-th region. */
00167   const Array<Set<int> >& reducedUnksOnRegion(const OrderedHandle<CellFilterStub>& r) const 
00168     {return reducedUnksOnRegions_[indexForRegion(r)];}
00169   //@}
00170 
00171       
00172 
00173 
00174   /** \name Transforming between unreduced and reduced function IDs */
00175   //@{
00176   /** get the reduced ID for the variational function having the
00177    * specified unreduced funcID */
00178   int reducedVarID(int varID) const ;
00179 
00180   /** get the reduced ID for the unknown 
00181    * function having the given funcID */
00182   int reducedUnkID(int unkID) const ;
00183 
00184   /** get the reduced ID for the unk parameter
00185    * having the given funcID */
00186   int reducedUnkParamID(int unkID) const ;
00187 
00188   /** get the reduced ID for the fixed parameter
00189    * having the given funcID */
00190   int reducedFixedParamID(int unkID) const ;
00191 
00192   /** get the unreduced funcID for a variational function
00193    * as specified by a reduced ID and block index */
00194   int unreducedVarID(int block, int reducedVarID) const 
00195     {return unreducedVarID_[block][reducedVarID];}
00196 
00197   /** get the unreduced funcID for an unknown function
00198    * as specified by a reduced ID and block index */
00199   int unreducedUnkID(int block, int reducedUnkID) const 
00200     {return unreducedUnkID_[block][reducedUnkID];}
00201 
00202   /** get the unreduced funcID for an unknown parameter
00203    * as specified by a reduced ID  */
00204   int unreducedUnkParamID(int reducedUnkParamID) const 
00205     {return unreducedUnkParamID_[reducedUnkParamID];}
00206 
00207   /** get the unreduced funcID for a fixed parameter
00208    * as specified by a reduced ID */
00209   int unreducedFixedParamID(int reducedFixedParamID) const 
00210     {return unreducedFixedParamID_[reducedFixedParamID];}
00211 
00212   /** Return the map from fixed param ID to reduced fixed param ID */
00213   const Map<int, int>& fixedParamIDToReducedFixedParamIDMap() const
00214     {return fixedParamIDToReducedFixedParamIDMap_;}
00215   
00216   //@}
00217 
00218 
00219   /** \name Finding integration regions for the equation set */
00220   //@{
00221   /** Returns the number of regions on which pieces of the equation
00222    * or BCs are defined. */
00223   int numRegions() const {return regions_.size();}
00224       
00225   /** Returns the d-th region for this equation set */
00226   const RCP<CellFilterStub>& region(int d) const 
00227     {return regions_[d].ptr();}
00228 
00229   /** Returns the index of the given region */
00230   int indexForRegion(const OrderedHandle<CellFilterStub>& region) const ;
00231 
00232   /** Whether a region has BCs */
00233   bool isBCRegion(int d) const 
00234     {return bcVarsOnRegions_.containsKey(regions_[d]);}
00235 
00236 
00237   /** Return the set of regions on which the specified 
00238    * test func appears. */
00239   const Set<OrderedHandle<CellFilterStub> >& 
00240   regionsForTestFunc(int unreducedTestID) const ;
00241       
00242   /** Return the set of regions on which the specified 
00243    * unknown func appears */
00244   const Set<OrderedHandle<CellFilterStub> >& 
00245   regionsForUnkFunc(int unreducedUnkID) const ;
00246   //@}
00247 
00248 
00249   /**
00250    * Flatten a spectral expression into a list of its coefficients
00251    */
00252   Expr flattenSpectral(const Expr& input) const ;
00253   /**
00254    * Flatten a spectral expression into a list of its coefficients
00255    */
00256   Array<Expr> flattenSpectral(const Array<Expr>& input) const ;
00257 
00258   /** Whether essential BCs are present */
00259   bool hasBCs() const ;
00260 
00261   /** Access to integrals */
00262   const SumOfIntegrals* integralSum() const {return integralSum_;}
00263 
00264   /** Access to BCs */
00265   const SumOfBCs* bcSum() const {return bcSum_;}
00266 
00267   /** */
00268   const Array<Expr>& unks() const {return unkFuncs_;}
00269 
00270   /** */
00271   const Array<Expr>& vars() const {return varFuncs_;}
00272 
00273   /** */
00274   const Array<Expr>& fixedFields() const {return fixedFields_;}
00275 
00276   /** */
00277   const Expr& fixedParams() const {return fixedParams_;}
00278 
00279   /** */
00280   const Expr& unkParams() const {return unkParams_;}
00281 
00282   /** */
00283   const Set<int>& varFuncSet() const {return varFuncSet_;}
00284   /** */
00285   const Set<int>& unkFuncSet() const {return unkFuncSet_;}
00286   /** */
00287   const Set<int>& unkParamSet() const {return unkParamSet_;}
00288   /** */
00289   const Set<int>& fixedParamSet() const {return fixedParamSet_;}
00290   
00291       
00292 private:
00293 
00294   /** */
00295   Expr eqns_;
00296 
00297   /** */
00298   Expr bcs_;
00299 
00300   /** */
00301   const SumOfIntegrals* integralSum_;
00302 
00303   /** */
00304   const SumOfBCs* bcSum_;
00305 
00306   /** */
00307   Set<int> varFuncSet_;
00308 
00309   /** */
00310   Set<int> unkFuncSet_;
00311 
00312   /** */
00313   Set<int> unkParamSet_;
00314 
00315   /** */
00316   Set<int> fixedParamSet_;
00317 
00318   /** */
00319   Array<OrderedHandle<CellFilterStub> > regions_;
00320 
00321   /** */
00322   Map<OrderedHandle<CellFilterStub>, int> regionToIndexMap_;
00323 
00324   /** */
00325   Map<OrderedHandle<CellFilterStub>, Set<int> > varsOnRegions_;
00326 
00327   /** */
00328   Map<OrderedHandle<CellFilterStub>, Set<int> > unksOnRegions_;
00329 
00330   /** */
00331   Array<Array<Set<int> > > reducedVarsOnRegions_;
00332 
00333   /** */
00334   Array<Array<Set<int> > > reducedUnksOnRegions_;
00335 
00336   /** */
00337   Map<OrderedHandle<CellFilterStub>, Set<int> > bcVarsOnRegions_;
00338 
00339   /** */
00340   Map<OrderedHandle<CellFilterStub>, Set<int> > bcUnksOnRegions_;
00341 
00342   /** */
00343   Map<int, Set<OrderedHandle<CellFilterStub> > > testToRegionsMap_;
00344 
00345   /** */
00346   Map<int, Set<OrderedHandle<CellFilterStub> > > unkToRegionsMap_;
00347 
00348   /** var function data for this equation set */
00349   Array<Array<RCP<const CommonFuncDataStub> > > varFuncData_;
00350 
00351   /** unknown function data for this equation set */
00352   Array<Array<RCP<const CommonFuncDataStub> > > unkFuncData_;
00353 
00354   /** var functions for this equation set */
00355   Array<Expr> varFuncs_;
00356 
00357   /** unknown functions for this equation set */
00358   Array<Expr> unkFuncs_;
00359 
00360   /** fixed functions for this equation set */
00361   Array<Expr> fixedFields_;
00362 
00363   /** The point in function space about which the equations
00364    * are linearized */
00365   Array<Expr> unkLinearizationPts_;
00366 
00367   /** unknown parameters for this equation set */
00368   Expr unkParams_;
00369 
00370   /** fixed parameters for this equation set */
00371   Expr fixedParams_;
00372 
00373   /** map from variational function funcID to that function's
00374    * position in list of var functions */
00375   Array<Map<int, int> > varIDToReducedIDMap_;
00376 
00377   /** map from unknown function funcID to that function's
00378    * position in list of unk functions */
00379   Array<Map<int, int> > unkIDToReducedIDMap_;
00380 
00381   /** map from unknown param funcID to that param's
00382    * position in list of unk params */
00383   Map<int, int> unkParamIDToReducedUnkParamIDMap_;
00384 
00385   /** map from fixed param funcID to that param's
00386    * position in list of fixed params */
00387   Map<int, int> fixedParamIDToReducedFixedParamIDMap_;
00388 
00389   /** map from variational function funcID to that function's
00390    * position in list of var blocks */
00391   Map<int, int> varIDToBlockMap_;
00392 
00393   /** map from unknown function funcID to that function's
00394    * position in list of unk blocks */
00395   Map<int, int> unkIDToBlockMap_;
00396 
00397   /** Map from (block, unreduced var ID) to reduced ID */
00398   Array<Array<int> > reducedVarID_;
00399 
00400   /** Map from (block, unreduced unk ID) to reduced ID */
00401   Array<Array<int> > reducedUnkID_;
00402 
00403   /** Map from unreduced unk ID to reduced ID */
00404   Array<int> reducedUnkParamID_;
00405 
00406   /** Map from unreduced fixed ID to reduced ID */
00407   Array<int> reducedFixedParamID_;
00408 
00409   /** Map from (block, reduced varID) to unreduced varID */
00410   Array<Array<int> > unreducedVarID_;
00411 
00412   /** Map from (block, reduced unkID) to unreduced unkID */
00413   Array<Array<int> > unreducedUnkID_;
00414 
00415   /** Map from reduced unkParamID to unreduced unkParamID */
00416   Array<int> unreducedUnkParamID_;
00417 
00418   /** Map from reduced fixedParamID to unreduced fixedParamID */
00419   Array<int> unreducedFixedParamID_;
00420 
00421   /** Flag indicating whether this equation set is nonlinear */
00422   bool isNonlinear_;
00423       
00424   /** Flag indicating whether this equation set is 
00425    * a variational problem */
00426   bool isVariationalProblem_;
00427 };
00428 
00429 /** */
00430 RCP<const CommonFuncDataStub> getSharedFunctionData(const FuncElementBase* f);
00431 
00432 }
00433  
00434 #endif

Site Contact