$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_ANALYTIC_FUNCTION_H 00021 #define LIBMESH_ANALYTIC_FUNCTION_H 00022 00023 // Local Includes 00024 #include "libmesh/function_base.h" 00025 00026 // C++ includes 00027 #include <cstddef> 00028 00029 namespace libMesh 00030 { 00031 00032 00033 00034 // Forward Declarations 00035 template <typename T> 00036 class DenseVector; 00037 00038 00047 // ------------------------------------------------------------ 00048 // AnalyticFunction class definition 00049 template <typename Output=Number> 00050 class AnalyticFunction : public FunctionBase<Output> 00051 { 00052 public: 00053 00058 AnalyticFunction (Output fptr(const Point& p, 00059 const Real time)); 00060 00065 AnalyticFunction (void fptr(DenseVector<Output>& output, 00066 const Point& p, 00067 const Real time)); 00071 ~AnalyticFunction (); 00072 00073 00079 Output (* _number_fptr) (const Point& p, 00080 const Real time); 00081 00085 void (* _vector_fptr) (DenseVector<Output>& output, 00086 const Point& p, 00087 const Real time); 00088 00092 void init (); 00093 00097 void clear (); 00098 00102 virtual UniquePtr<FunctionBase<Output> > clone () const; 00103 00108 Output operator() (const Point& p, 00109 const Real time=0.); 00110 00115 void operator() (const Point& p, 00116 const Real time, 00117 DenseVector<Output>& output); 00118 00119 }; 00120 00121 00122 00123 // ------------------------------------------------------------ 00124 // AnalyticFunction inline methods 00125 template <typename Output> 00126 inline 00127 Output AnalyticFunction<Output>::operator() (const Point& p, 00128 const Real time) 00129 { 00130 libmesh_assert (this->initialized()); 00131 return (this->_number_fptr(p, time)); 00132 } 00133 00134 00135 00136 template <typename Output> 00137 inline 00138 void AnalyticFunction<Output>::operator() (const Point& p, 00139 const Real time, 00140 DenseVector<Output>& output) 00141 { 00142 libmesh_assert (this->initialized()); 00143 this->_vector_fptr(output, p, time); 00144 return; 00145 } 00146 00147 00148 00149 template <typename Output> 00150 AnalyticFunction<Output>::AnalyticFunction (Output fptr(const Point& p, 00151 const Real time)) : 00152 FunctionBase<Output> (), 00153 _number_fptr (fptr), 00154 _vector_fptr (NULL) 00155 { 00156 libmesh_assert(fptr); 00157 this->_initialized = true; 00158 } 00159 00160 00161 00162 template <typename Output> 00163 inline 00164 AnalyticFunction<Output>::AnalyticFunction (void fptr(DenseVector<Output>& output, 00165 const Point& p, 00166 const Real time)) : 00167 FunctionBase<Output> (), 00168 _number_fptr (NULL), 00169 _vector_fptr (fptr) 00170 { 00171 libmesh_assert(fptr); 00172 this->_initialized = true; 00173 } 00174 00175 00176 00177 template <typename Output> 00178 inline 00179 AnalyticFunction<Output>::~AnalyticFunction () 00180 { 00181 } 00182 00183 00184 00185 template <typename Output> 00186 void AnalyticFunction<Output>::init () 00187 { 00188 // dumb double-test 00189 libmesh_assert ((_number_fptr != NULL) || (_vector_fptr != NULL)); 00190 00191 // definitely ready 00192 this->_initialized = true; 00193 } 00194 00195 00196 00197 template <typename Output> 00198 inline 00199 void AnalyticFunction<Output>::clear () 00200 { 00201 // We probably need a method to reset these later... 00202 _number_fptr = NULL; 00203 _vector_fptr = NULL; 00204 00205 // definitely not ready 00206 this->_initialized = false; 00207 } 00208 00209 00210 00211 template <typename Output> 00212 inline 00213 UniquePtr<FunctionBase<Output> > 00214 AnalyticFunction<Output>::clone () const 00215 { 00216 return UniquePtr<FunctionBase<Output> > 00217 ( _number_fptr ? 00218 new AnalyticFunction<Output>(_number_fptr) : 00219 new AnalyticFunction<Output>(_vector_fptr) ); 00220 } 00221 00222 00223 } // namespace libMesh 00224 00225 00226 #endif // LIBMESH_ANALYTIC_FUNCTION_H