Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009
00010 #include "Intrepid_FunctionSpaceTools.hpp"
00011
00012 namespace PHAL {
00013
00014
00015
00016 template<typename EvalT, typename Traits>
00017 LangevinNoiseTerm<EvalT, Traits>::
00018 LangevinNoiseTerm(const Teuchos::ParameterList& p) :
00019 rho (p.get<std::string> ("Rho QP Variable Name"),
00020 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00021 noiseTerm (p.get<std::string> ("Langevin Noise Term"),
00022 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00023 duration(2),
00024 rng(seedgen())
00025
00026 {
00027
00028 sd = p.get<double>("SD Value");
00029 duration = p.get<Teuchos::Array<int> >("Langevin Noise Time Period");
00030
00031 Teuchos::RCP<PHX::DataLayout> vector_dl =
00032 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
00033 std::vector<PHX::DataLayout::size_type> dims;
00034 vector_dl->dimensions(dims);
00035 numQPs = dims[1];
00036 numDims = dims[2];
00037
00038
00039
00040 nd = Teuchos::rcp(new boost::normal_distribution<double>(0.0,
00041 QCAD::EvaluatorTools<EvalT,Traits>::getDoubleValue(sd)));
00042 var_nor = Teuchos::rcp(new
00043 boost::variate_generator<boost::mt19937&, boost::normal_distribution<double> >(rng, *nd));
00044
00045
00046 this->addDependentField(rho);
00047
00048 this->addEvaluatedField(noiseTerm);
00049
00050 this->setName("LangevinNoiseTerm"+PHX::TypeString<EvalT>::value);
00051
00052 }
00053
00054
00055 template<typename EvalT, typename Traits>
00056 void LangevinNoiseTerm<EvalT, Traits>::
00057 postRegistrationSetup(typename Traits::SetupData d,
00058 PHX::FieldManager<Traits>& fm)
00059 {
00060 this->utils.setFieldData(rho,fm);
00061
00062 this->utils.setFieldData(noiseTerm,fm);
00063 }
00064
00065
00066 template<typename EvalT, typename Traits>
00067 void LangevinNoiseTerm<EvalT, Traits>::
00068 evaluateFields(typename Traits::EvalData workset)
00069 {
00070
00071 if(duration[0] < 0 || (workset.current_time >= duration[0] && workset.current_time < duration[1])){
00072
00073
00074
00075 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00076 for (std::size_t qp=0; qp < numQPs; ++qp)
00077
00078 noiseTerm(cell, qp) = rho(cell, qp) + (*var_nor)();
00079
00080
00081
00082 }
00083
00084 }
00085
00086 template<typename EvalT, typename Traits>
00087 typename LangevinNoiseTerm<EvalT, Traits>::ScalarT&
00088 LangevinNoiseTerm<EvalT, Traits>::getValue(const std::string &n) {
00089
00090 if (n == "sd")
00091
00092 return sd;
00093
00094 else
00095 {
00096 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, std::endl <<
00097 "Error! Logic error in getting parameter " << n <<
00098 " in LangevinNoiseTerm::getValue()" << std::endl);
00099 return sd;
00100 }
00101
00102 }
00103
00104
00105 template<typename EvalT, typename Traits>
00106 long LangevinNoiseTerm<EvalT, Traits>::
00107 seedgen()
00108 {
00109 long seconds, s, seed, pid;
00110
00111 pid = getpid();
00112 s = time ( &seconds );
00113
00114 seed = abs(((s*181)*((pid-83)*359))%104729);
00115 return seed;
00116 }
00117
00118 }
00119