Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <Teuchos_TestForException.hpp>
00008 #include <Phalanx_DataLayout.hpp>
00009 #include <Intrepid_MiniTensor.h>
00010
00011 namespace LCM {
00012
00013
00014 template<typename EvalT, typename Traits>
00015 UnitGradient<EvalT, Traits>::
00016 UnitGradient(const Teuchos::ParameterList& p,
00017 const Teuchos::RCP<Albany::Layouts>& dl) :
00018 scalar_grad_(p.get<std::string>("Gradient QP Variable Name"), dl->qp_vector),
00019 unit_grad_(p.get<std::string>("Unit Gradient QP Variable Name"),dl->qp_vector)
00020 {
00021 this->addDependentField(scalar_grad_);
00022 this->addEvaluatedField(unit_grad_);
00023 this->setName("Unit Gradient QP Variable"+PHX::TypeString<EvalT>::value);
00024
00025 std::vector<PHX::DataLayout::size_type> dims;
00026 dl->qp_vector->dimensions(dims);
00027 num_pts_ = dims[1];
00028 num_dims_ = dims[2];
00029 }
00030
00031
00032 template<typename EvalT, typename Traits>
00033 void UnitGradient<EvalT, Traits>::
00034 postRegistrationSetup(typename Traits::SetupData d,
00035 PHX::FieldManager<Traits>& fm)
00036 {
00037 this->utils.setFieldData(scalar_grad_,fm);
00038 this->utils.setFieldData(unit_grad_,fm);
00039 }
00040
00041
00042 template<typename EvalT, typename Traits>
00043 void UnitGradient<EvalT, Traits>::
00044 evaluateFields(typename Traits::EvalData workset)
00045 {
00046 ScalarT scalar_mag(0.0);
00047 Intrepid::Vector<ScalarT> grad(num_dims_), unit(num_dims_);
00048
00049 for (std::size_t cell(0); cell < workset.numCells; ++cell) {
00050 for (std::size_t pt(0); pt < num_pts_; ++pt) {
00051 grad.fill( &scalar_grad_(cell,pt,0) );
00052 scalar_mag = Intrepid::norm(grad);
00053 if (scalar_mag > 0) {
00054 unit = grad / scalar_mag;
00055 for (std::size_t i(0); i < num_dims_; i++) {
00056 unit_grad_(cell,pt,i) = unit(i);
00057 }
00058 }
00059 else {
00060 for (std::size_t i(0); i < num_dims_; i++){
00061 unit_grad_(cell,pt,i) = 1/std::sqrt(num_dims_);
00062 }
00063 }
00064 }
00065 }
00066 }
00067
00068 }