FEApp_MultiVariateExponentialSourceFunction.hpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #ifndef FEAPP_MULTIVARIATEEXPONENTIALSOURCEFUNCTION_HPP
00033 #define FEAPP_MULTIVARIATEEXPONENTIALSOURCEFUNCTION_HPP
00034 
00035 #include <sstream>
00036 
00037 #include "FEApp_AbstractSourceFunction.hpp"
00038 
00039 #include "Teuchos_RCP.hpp"
00040 #include "Sacado_ScalarParameterLibrary.hpp"
00041 #include "Sacado_ScalarParameterEntry.hpp"
00042 #include "Sacado_Traits.hpp"
00043 
00044 namespace FEApp {
00045 
00046   template <typename EvalT> 
00047   class MultiVariateExponentialNonlinearFactorParameter;
00048 
00052   template <typename EvalT>
00053   class MultiVariateExponentialSourceFunction : 
00054     public FEApp::AbstractSourceFunction<EvalT> {
00055   public:
00056 
00058     typedef typename FEApp::AbstractSourceFunction<EvalT>::ScalarT ScalarT;
00059   
00061     MultiVariateExponentialSourceFunction(
00062          const std::vector<ScalarT>& factor,
00063          const Teuchos::RCP<ParamLib>& paramLib) : 
00064       alpha(factor) 
00065     {
00066       // Add nonlinear factor to parameter library
00067       for (unsigned int i=0; i<factor.size(); i++) {
00068         std::stringstream ss;
00069         ss << "Exponential Source Function Nonlinear Factor " << i;
00070         std::string name = ss.str();
00071         if (!paramLib->isParameter(name))
00072           paramLib->addParameterFamily(name, true, false);
00073         if (!paramLib->template isParameterForType<EvalT>(name)) {
00074           Teuchos::RCP< MultiVariateExponentialNonlinearFactorParameter<EvalT> > tmp = 
00075             Teuchos::rcp(new MultiVariateExponentialNonlinearFactorParameter<EvalT>(Teuchos::rcp(this,false),i));
00076           paramLib->template addEntry<EvalT>(name, tmp);
00077         }
00078       }
00079     };
00080 
00082     virtual ~MultiVariateExponentialSourceFunction() {};
00083 
00085     virtual void
00086     evaluate(const std::vector<ScalarT>& solution,
00087              std::vector<ScalarT>& value) const {
00088       ScalarT a = 0.0;
00089       for (unsigned int j=0; j<alpha.size(); j++)
00090   a += alpha[j];
00091       a /= static_cast<double>(alpha.size());
00092       for (unsigned int i=0; i<solution.size(); i++) {
00093         value[i] = a*std::exp(solution[i]);
00094       }
00095       
00096     }
00097 
00099     void setFactor(unsigned int i, const ScalarT& val, bool mark_constant) { 
00100       alpha[i] = val;
00101       if (mark_constant) Sacado::MarkConstant<ScalarT>::eval(alpha[i]); 
00102     }
00103 
00105     const ScalarT& getFactor(unsigned int i) const { return alpha[i]; }
00106 
00107   private:
00108 
00110     MultiVariateExponentialSourceFunction(const MultiVariateExponentialSourceFunction&);
00111 
00113     MultiVariateExponentialSourceFunction& operator=(const MultiVariateExponentialSourceFunction&);
00114 
00115   protected:
00116   
00118     std::vector<ScalarT> alpha;
00119 
00120   };
00121 
00126   template <typename EvalT>
00127   class MultiVariateExponentialNonlinearFactorParameter : 
00128     public Sacado::ScalarParameterEntry<EvalT,EvaluationTraits> {
00129 
00130   public:
00131 
00133     typedef typename Sacado::ScalarParameterEntry<EvalT,EvaluationTraits>::ScalarT ScalarT;
00134 
00136     MultiVariateExponentialNonlinearFactorParameter(
00137         const Teuchos::RCP< MultiVariateExponentialSourceFunction<EvalT> >& s,
00138         unsigned int i) 
00139       : srcFunc(s), index(i) {}
00140 
00142     virtual ~MultiVariateExponentialNonlinearFactorParameter() {}
00143 
00145     virtual void setRealValue(double value) { 
00146       srcFunc->setFactor(index, value, true); }
00147     
00149     virtual void setValue(const ScalarT& value) { 
00150       srcFunc->setFactor(index, value, false); }
00151 
00153     virtual double getRealValue() const {
00154       return Sacado::ScalarValue<ScalarT>::eval(srcFunc->getFactor(index)); }
00155     
00157     virtual const ScalarT& getValue() const { 
00158       return srcFunc->getFactor(index); }
00159     
00160   protected:  
00161     
00163     Teuchos::RCP< MultiVariateExponentialSourceFunction<EvalT> > srcFunc;
00164 
00166     unsigned int index;
00167 
00168   };
00169 
00170 }
00171 
00172 #endif // FEAPP_MULTIVARIATEEXPONENTIALSOURCEFUNCTION_HPP

Generated on Wed May 12 21:39:33 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7