SundanceDiscreteFunction.cpp
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 #include "SundanceDiscreteFunction.hpp"
00032 #include "SundanceOut.hpp"
00033 #include "SundanceTabs.hpp"
00034 #include "SundanceMaximalCellFilter.hpp"
00035 #include "SundanceCellFilter.hpp"
00036 #include "SundanceCellSet.hpp"
00037 #include "SundanceSubtypeEvaluator.hpp"
00038 
00039 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00040 #include "TSFVectorImpl.hpp"
00041 #endif
00042 
00043 using namespace Sundance;
00044 using namespace Sundance;
00045 using namespace Sundance;
00046 using namespace Sundance;
00047 using namespace Sundance;
00048 using namespace Teuchos;
00049 
00050 
00051 static Time& getLocalValsTimer() 
00052 {
00053   static RCP<Time> rtn 
00054     = TimeMonitor::getNewTimer("DF getLocalValues"); 
00055   return *rtn;
00056 }
00057 static Time& dfCtorTimer() 
00058 {
00059   static RCP<Time> rtn 
00060     = TimeMonitor::getNewTimer("DF ctor"); 
00061   return *rtn;
00062 }
00063 
00064 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00065                                    const std::string& name)
00066   : DiscreteFunctionStub(tuple(name), space.dimStructure(),
00067                          getRCP(new DiscreteFunctionData(space))), 
00068     FuncWithBasis(space.basis()),
00069     data_()
00070 {
00071   TimeMonitor timer(dfCtorTimer());
00072   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00073 }
00074 
00075 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00076                                    const Array<string>& name)
00077   : DiscreteFunctionStub(name, space.dimStructure(),
00078                          getRCP(new DiscreteFunctionData(space))), 
00079     FuncWithBasis(space.basis()),
00080     data_()
00081 {
00082   TimeMonitor timer(dfCtorTimer());
00083   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00084 }
00085 
00086 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00087                                    const double& constantValue,
00088                                    const std::string& name)
00089   : DiscreteFunctionStub(tuple(name), space.dimStructure(),
00090                          getRCP(new DiscreteFunctionData(space, constantValue))), 
00091     FuncWithBasis(space.basis()),
00092     data_()
00093 {
00094   TimeMonitor timer(dfCtorTimer());
00095   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00096   Vector<double> vec = data_->getVector();
00097   vec.setToConstant(constantValue);
00098   data_->setVector(vec);
00099 }
00100 
00101 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00102                                    const double& constantValue,
00103                                    const Array<string>& name)
00104   : DiscreteFunctionStub(name, space.dimStructure(),
00105                          getRCP(new DiscreteFunctionData(space, constantValue))), 
00106     FuncWithBasis(space.basis()),
00107     data_()
00108 {
00109   TimeMonitor timer(dfCtorTimer());
00110   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00111   Vector<double> vec = data_->getVector();
00112   vec.setToConstant(constantValue);
00113   data_->setVector(vec);
00114 }
00115 
00116 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00117                                    const Vector<double>& vec,
00118                                    const std::string& name)
00119   : DiscreteFunctionStub(tuple(name), space.dimStructure(),
00120                          getRCP(new DiscreteFunctionData(space, vec))), 
00121     FuncWithBasis(space.basis()),
00122     data_()
00123 {
00124   TimeMonitor timer(dfCtorTimer());
00125   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00126 }
00127 
00128 DiscreteFunction::DiscreteFunction(const DiscreteSpace& space, 
00129                                    const Vector<double>& vec,
00130                                    const Array<string>& name)
00131   : DiscreteFunctionStub(name, space.dimStructure(),
00132                          getRCP(new DiscreteFunctionData(space, vec))), 
00133     FuncWithBasis(space.basis()),
00134     data_()
00135 {
00136   TimeMonitor timer(dfCtorTimer());
00137   data_ = rcp_dynamic_cast<DiscreteFunctionData>(dataStub());
00138 }
00139 
00140 void DiscreteFunction::setVector(const Vector<double>& vec) 
00141 {
00142   data_->setVector(vec);
00143 }
00144 
00145 void DiscreteFunction::updateGhosts() const
00146 {
00147   data_->updateGhosts();
00148 }
00149 
00150 
00151 RCP<const MapStructure> DiscreteFunction::getLocalValues(int cellDim, 
00152                                                                  const Array<int>& cellLID,
00153                                                                  Array<Array<double> >& localValues) const 
00154 {
00155   TimeMonitor timer(getLocalValsTimer());
00156   return data_->getLocalValues(cellDim, cellLID, localValues);
00157 }
00158 
00159 
00160 const DiscreteFunction* DiscreteFunction::discFunc(const Expr& expr)
00161 {
00162   const ExprBase* e = expr.ptr().get();
00163   const DiscreteFunction* df 
00164     = dynamic_cast<const DiscreteFunction*>(e);
00165 
00166   TEST_FOR_EXCEPTION(df==0, RuntimeError,
00167     "failed to cast " << expr << " to a discrete function. "
00168     "It appears to be of type " << e->typeName());
00169 
00170   return df;
00171 }
00172 
00173 
00174 
00175 DiscreteFunction* DiscreteFunction::discFunc(Expr& expr)
00176 {
00177   DiscreteFunction* df 
00178     = dynamic_cast<DiscreteFunction*>(expr.ptr().get());
00179 
00180   TEST_FOR_EXCEPTION(df==0, RuntimeError,
00181     "failed to cast " << expr << " to a discrete function. "
00182     "It appears to be of type " << expr.ptr()->typeName());
00183 
00184   return df;
00185 }
00186 
00187 
00188 RCP<DiscreteFuncDataStub> DiscreteFunction::getRCP(DiscreteFunctionData* ptr)
00189 {
00190   return rcp_dynamic_cast<DiscreteFuncDataStub>(rcp(ptr));
00191 }
00192 

Site Contact