$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_FUNCTION_BASE_H 00021 #define LIBMESH_FUNCTION_BASE_H 00022 00023 // Local Includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/dense_vector.h" // required to instantiate a DenseVector<> below 00026 #include "libmesh/auto_ptr.h" 00027 00028 // C++ includes 00029 #include <cstddef> 00030 00031 namespace libMesh 00032 { 00033 00034 00035 00036 // Forward Declarations 00037 class Point; 00038 00039 00062 // ------------------------------------------------------------ 00063 // FunctionBase class definition 00064 template <typename Output=Number> 00065 class FunctionBase 00066 { 00067 protected: 00068 00072 explicit 00073 FunctionBase (const FunctionBase* master = NULL); 00074 00075 public: 00076 00080 virtual ~FunctionBase (); 00081 00085 virtual void init () {} 00086 00090 virtual void clear () {} 00091 00097 virtual UniquePtr<FunctionBase<Output> > clone () const = 0; 00098 00099 00100 // ------------------------------------------------------ 00101 // misc 00108 virtual Output operator() (const Point& p, 00109 const Real time = 0.) = 0; 00110 00116 void operator() (const Point& p, 00117 DenseVector<Output>& output); 00118 00130 virtual void operator() (const Point& p, 00131 const Real time, 00132 DenseVector<Output>& output) = 0; 00133 00144 virtual Output component(unsigned int i, 00145 const Point& p, 00146 Real time=0.); 00147 00148 00153 bool initialized () const; 00154 00155 00156 protected: 00157 00164 const FunctionBase* _master; 00165 00170 bool _initialized; 00171 00172 }; 00173 00174 00175 // ------------------------------------------------------------ 00176 // FunctionBase inline methods 00177 00178 template<typename Output> 00179 inline 00180 FunctionBase<Output>::FunctionBase (const FunctionBase* master) : 00181 _master (master), 00182 _initialized (false) 00183 { 00184 } 00185 00186 00187 00188 template<typename Output> 00189 inline 00190 FunctionBase<Output>::~FunctionBase () 00191 { 00192 } 00193 00194 00195 00196 template <typename Output> 00197 inline 00198 bool FunctionBase<Output>::initialized() const 00199 { 00200 return (this->_initialized); 00201 } 00202 00203 00204 00205 template <typename Output> 00206 inline 00207 Output FunctionBase<Output>::component (unsigned int i, 00208 const Point& p, 00209 Real time) 00210 { 00211 DenseVector<Output> outvec(i+1); 00212 (*this)(p, time, outvec); 00213 return outvec(i); 00214 } 00215 00216 00217 00218 template <typename Output> 00219 inline 00220 void FunctionBase<Output>::operator() (const Point& p, 00221 DenseVector<Output>& output) 00222 { 00223 // Call the time-dependent function with t=0. 00224 this->operator()(p, 0., output); 00225 } 00226 00227 } // namespace libMesh 00228 00229 #endif // LIBMESH_FUNCTION_BASE_H