• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

TransportResidual_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include <Teuchos_TestForException.hpp>
00008 #include <Phalanx_DataLayout.hpp>
00009 #include <typeinfo>
00010 
00011 namespace LCM {
00012 
00013   //----------------------------------------------------------------------------
00014   template<typename EvalT, typename Traits>
00015   TransportResidual<EvalT, Traits>::
00016   TransportResidual(Teuchos::ParameterList& p,
00017                     const Teuchos::RCP<Albany::Layouts>& dl) :
00018     scalar_     (p.get<std::string>("Scalar Variable Name"), dl->qp_scalar),
00019     scalar_grad_(p.get<std::string>("Scalar Gradient Variable Name"), dl->qp_vector),
00020     weights_    (p.get<std::string>("Weights Name"), dl->qp_scalar),
00021     w_bf_       (p.get<std::string>("Weighted BF Name"), dl->node_qp_scalar),
00022     w_grad_bf_  (p.get<std::string>("Weighted Gradient BF Name"), dl->node_qp_vector),
00023     residual_   (p.get<std::string>("Residual Name"), dl->node_scalar),
00024     have_source_          (p.get<bool>("Have Source", false)),
00025     have_transient_       (p.get<bool>("Have Transient", false)),
00026     have_diffusion_       (p.get<bool>("Have Diffusion", false)),
00027     have_convection_      (p.get<bool>("Have Convection", false)),
00028     have_species_coupling_(p.get<bool>("Have Species Coupling", false)),
00029     have_stabilization_   (p.get<bool>("Have Stabilization", false)),
00030     num_nodes_(0),
00031     num_pts_(0),
00032     num_dims_(0)
00033   {
00034     this->addDependentField(scalar_);
00035     this->addDependentField(scalar_grad_);
00036     this->addDependentField(weights_);
00037     this->addDependentField(w_bf_);
00038     this->addDependentField(w_grad_bf_);
00039 
00040     if (have_source_) {
00041       PHX::MDField<ScalarT,Cell,QuadPoint>
00042         tmp(p.get<std::string>("Source Name"), dl->qp_scalar);
00043       source_ = tmp;
00044       this->addDependentField(source_);
00045     }
00046 
00047     if (have_transient_) {
00048       PHX::MDField<ScalarT,Cell,QuadPoint>
00049         tmp_dot(p.get<std::string>("Scalar Dot Name"), dl->qp_scalar);
00050       scalar_dot_ = tmp_dot;
00051       this->addDependentField(scalar_dot_);
00052 
00053       PHX::MDField<ScalarT,Cell,QuadPoint>
00054         tmp(p.get<std::string>("Transient Coefficient Name"), dl->qp_scalar);
00055       transient_coeff_ = tmp;
00056       this->addDependentField(transient_coeff_);
00057     }
00058 
00059     if (have_diffusion_) {
00060       PHX::MDField<ScalarT,Cell,QuadPoint,Dim,Dim>
00061         tmp(p.get<std::string>("Diffusivity Name"), dl->qp_tensor);
00062       diffusivity_ = tmp;
00063       this->addDependentField(diffusivity_);
00064     }
00065 
00066     if (have_convection_) {
00067       PHX::MDField<ScalarT,Cell,QuadPoint,Dim>
00068         tmp(p.get<std::string>("Convection Vector Name"), dl->qp_vector);
00069       convection_vector_ = tmp;
00070       this->addDependentField(convection_vector_);
00071     }
00072 
00073     if (have_species_coupling_) {
00074       PHX::MDField<ScalarT,Cell,QuadPoint>
00075         tmp(p.get<std::string>("Species Coupling Name"), dl->qp_scalar);
00076       species_coupling_ = tmp;
00077       this->addDependentField(species_coupling_);
00078     }
00079 
00080     if (have_stabilization_) {
00081       PHX::MDField<ScalarT,Cell,QuadPoint>
00082         tmp(p.get<std::string>("Stabilization Name"), dl->qp_scalar);
00083       stabilization_ = tmp;
00084       this->addDependentField(stabilization_);
00085     }
00086 
00087     this->addEvaluatedField(residual_);
00088 
00089     std::vector<PHX::DataLayout::size_type> dims;
00090     dl->node_qp_vector->dimensions(dims);
00091     num_nodes_ = dims[1];
00092     num_pts_   = dims[2];
00093     num_dims_  = dims[3];
00094 
00095     scalar_name_ = p.get<std::string>("Scalar Variable Name")+"_old";
00096 
00097     this->setName("TransportResidual"+PHX::TypeString<EvalT>::value);
00098   }
00099 
00100   //----------------------------------------------------------------------------
00101   template<typename EvalT, typename Traits>
00102   void TransportResidual<EvalT, Traits>::
00103   postRegistrationSetup(typename Traits::SetupData d,
00104                         PHX::FieldManager<Traits>& fm)
00105   {
00106     this->utils.setFieldData(scalar_,fm);
00107     this->utils.setFieldData(scalar_grad_,fm);
00108     this->utils.setFieldData(weights_,fm);
00109     this->utils.setFieldData(w_bf_,fm);
00110     this->utils.setFieldData(w_grad_bf_,fm);
00111 
00112     if (have_source_) {
00113       this->utils.setFieldData(source_,fm);
00114     }
00115 
00116     if (have_transient_) {
00117       this->utils.setFieldData(transient_coeff_,fm);
00118       this->utils.setFieldData(scalar_dot_,fm);
00119     }
00120 
00121     if (have_diffusion_) {
00122       this->utils.setFieldData(diffusivity_,fm);
00123     }
00124 
00125     if (have_convection_) {
00126       this->utils.setFieldData(convection_vector_,fm);
00127     }
00128 
00129     if (have_species_coupling_) {
00130       this->utils.setFieldData(species_coupling_,fm);
00131     }
00132 
00133     if (have_stabilization_) {
00134       this->utils.setFieldData(stabilization_,fm);
00135     }
00136 
00137     this->utils.setFieldData(residual_,fm);
00138   }
00139 
00140   //----------------------------------------------------------------------------
00141   template<typename EvalT, typename Traits>
00142   void TransportResidual<EvalT, Traits>::
00143   evaluateFields(typename Traits::EvalData workset)
00144   {
00145     // zero out residual
00146     for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00147       for (std::size_t node = 0; node < num_nodes_; ++node) {
00148         residual_(cell,node) = 0.0;
00149       }
00150     }
00151 
00152     // transient term
00153     if ( have_transient_ ) {
00154       //if ( dt == 0.0 ) dt = 1.e-15;
00155       // grab old state
00156       //Albany::MDArray scalar_old = (*workset.stateArrayPtr)[scalar_name_];
00157       // compute scalar rate
00158       //ScalarT scalar_dot(0.0);
00159       for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00160         for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00161           //scalar_dot = ( scalar_(cell,pt) - scalar_old(cell,pt) ) / dt;
00162           for (std::size_t node = 0; node < num_nodes_; ++node) {
00163             residual_(cell,node) += transient_coeff_(cell,pt)
00164               * w_bf_(cell,node,pt) * scalar_dot_(cell,pt);
00165           }
00166         }
00167       }
00168     }
00169 
00170     // diffusive term
00171     if ( have_diffusion_ ) {
00172       for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00173         for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00174           for (std::size_t node = 0; node < num_nodes_; ++node) {
00175             for (std::size_t i = 0; i < num_dims_; ++i) {
00176               for (std::size_t j = 0; j < num_dims_; ++j) {
00177                 residual_(cell,node) += w_grad_bf_(cell,node,pt,i) *
00178                   diffusivity_(cell,pt,i,j) * scalar_grad_(cell,pt,j);
00179               }
00180             }
00181           }
00182         }
00183       }
00184     }
00185 
00186     // source term
00187     if ( have_source_ ) {
00188       for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00189         for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00190           for (std::size_t node = 0; node < num_nodes_; ++node) {
00191             residual_(cell,node) -= w_bf_(cell,node,pt) * source_(cell,pt);
00192           }
00193         }
00194       }
00195     }
00196 
00197     // convection term
00198     if ( have_convection_ ) {
00199       for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00200         for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00201           for (std::size_t node = 0; node < num_nodes_; ++node) {
00202             for (std::size_t dim = 0; dim < num_dims_; ++dim) {
00203               residual_(cell,node) += w_bf_(cell,node,pt) *
00204                 convection_vector_(cell,pt,dim) * scalar_grad_(cell,pt,dim);
00205             }
00206           }
00207         }
00208       }
00209     }
00210   }
00211 }
00212 
00213 
00214 

Generated on Wed Mar 26 2014 18:36:46 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1