00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Teuchos_VerboseObject.hpp"
00009 #include "Teuchos_RCP.hpp"
00010 #include "Phalanx_DataLayout.hpp"
00011 #include "Sacado_ParameterRegistration.hpp"
00012
00013 #include "Intrepid_FunctionSpaceTools.hpp"
00014
00015 namespace Aeras {
00016
00017
00018 template<typename EvalT, typename Traits>
00019 ShallowWaterResid<EvalT, Traits>::
00020 ShallowWaterResid(const Teuchos::ParameterList& p,
00021 const Teuchos::RCP<Albany::Layouts>& dl) :
00022 wBF (p.get<std::string> ("Weighted BF Name"), dl->node_qp_scalar),
00023 wGradBF (p.get<std::string> ("Weighted Gradient BF Name"),dl->node_qp_gradient),
00024 U (p.get<std::string> ("QP Variable Name"), dl->qp_vector),
00025 Ugrad (p.get<std::string> ("Gradient QP Variable Name"), dl->qp_vecgradient),
00026 UDot (p.get<std::string> ("QP Time Derivative Variable Name"), dl->qp_vector),
00027 surfHeight (p.get<std::string> ("Aeras Surface Height QP Variable Name"), dl->qp_scalar),
00028 jacobian_inv (p.get<std::string> ("Jacobian Inv Name"), dl->qp_tensor ),
00029 weighted_measure (p.get<std::string> ("Weights Name"), dl->qp_scalar ),
00030 jacobian (p.get<std::string> ("Jacobian Name"), dl->qp_tensor ),
00031 Residual (p.get<std::string> ("Residual Name"), dl->node_vector),
00032 intrepidBasis (p.get<Teuchos::RCP<Intrepid::Basis<RealType, Intrepid::FieldContainer<RealType> > > > ("Intrepid Basis") ),
00033 cubature (p.get<Teuchos::RCP <Intrepid::Cubature<RealType> > >("Cubature")),
00034 spatialDim(p.get<std::size_t>("spatialDim"))
00035
00036 {
00037
00038 Teuchos::ParameterList* shallowWaterList = p.get<Teuchos::ParameterList*>("Shallow Water Problem");
00039
00040 gravity = shallowWaterList->get<double>("Gravity", 1.0);
00041 usePrescribedVelocity = shallowWaterList->get<bool>("Use Prescribed Velocity", false);
00042
00043 this->addDependentField(U);
00044 this->addDependentField(Ugrad);
00045 this->addDependentField(UDot);
00046 this->addDependentField(wBF);
00047 this->addDependentField(wGradBF);
00048 this->addDependentField(surfHeight);
00049
00050
00051 if(3 == spatialDim ) {
00052 this->addDependentField(weighted_measure);
00053 this->addDependentField(jacobian);
00054 this->addDependentField(jacobian_inv);
00055 }
00056 this->addEvaluatedField(Residual);
00057
00058 std::vector<PHX::DataLayout::size_type> dims;
00059 wGradBF.fieldTag().dataLayout().dimensions(dims);
00060 numNodes = dims[1];
00061 numQPs = dims[2];
00062 numDims = dims[3];
00063
00064 refWeights .resize (numQPs);
00065 val_at_cub_points .resize (numNodes, numQPs);
00066 grad_at_cub_points.resize (numNodes, numQPs, 2);
00067 refPoints .resize (numQPs, 2);
00068
00069 cubature->getCubature(refPoints, refWeights);
00070 intrepidBasis->getValues(val_at_cub_points, refPoints, Intrepid::OPERATOR_VALUE);
00071 intrepidBasis->getValues(grad_at_cub_points, refPoints, Intrepid::OPERATOR_GRAD);
00072
00073 this->setName("Aeras::ShallowWaterResid"+PHX::TypeString<EvalT>::value);
00074
00075
00076 U.fieldTag().dataLayout().dimensions(dims);
00077 vecDim = dims[2];
00078
00079 std::vector<PHX::DataLayout::size_type> gradDims;
00080 wGradBF.fieldTag().dataLayout().dimensions(gradDims);
00081 std::cout << "wGradBF has numNodes = " << gradDims[1] << " numQuadPts = " << gradDims[2] << " numSpatialComponents = "
00082 << gradDims[3] << std::endl;
00083
00084
00085 gradDims.clear();
00086 Ugrad.fieldTag().dataLayout().dimensions(gradDims);
00087
00088 std::cout << "Ugrad has numQuadPts = " << gradDims[1] << " numVecDim = "
00089 << gradDims[2] << " numDim = " << gradDims[3] << std::endl;
00090
00091
00092
00093
00094
00095
00096
00097 Teuchos::RCP<ParamLib> paramLib = p.get<Teuchos::RCP<ParamLib> >("Parameter Library");
00098 new Sacado::ParameterRegistration<EvalT, SPL_Traits>("Gravity", this, paramLib);
00099 }
00100
00101
00102 template<typename EvalT, typename Traits>
00103 void ShallowWaterResid<EvalT, Traits>::
00104 postRegistrationSetup(typename Traits::SetupData d,
00105 PHX::FieldManager<Traits>& fm)
00106 {
00107 this->utils.setFieldData(U,fm);
00108 this->utils.setFieldData(Ugrad,fm);
00109 this->utils.setFieldData(UDot,fm);
00110 this->utils.setFieldData(wBF,fm);
00111 this->utils.setFieldData(wGradBF,fm);
00112 this->utils.setFieldData(surfHeight,fm);
00113 if(3 == spatialDim ) {
00114 this->utils.setFieldData(weighted_measure, fm);
00115 this->utils.setFieldData(jacobian, fm);
00116 this->utils.setFieldData(jacobian_inv, fm);
00117 }
00118 this->utils.setFieldData(Residual,fm);
00119 }
00120
00121
00122 template<typename EvalT, typename Traits>
00123 void ShallowWaterResid<EvalT, Traits>::
00124 evaluateFields(typename Traits::EvalData workset)
00125 {
00126
00127
00128
00129
00130
00131
00132 for (std::size_t i=0; i < Residual.size(); ++i) Residual(i)=0.0;
00133
00134 ScalarT v1, v2;
00135 ScalarT workA1, workA2;
00136 ScalarT work1, work2;
00137
00138
00139
00140
00141 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00142
00143 for (std::size_t qp=0; qp < numQPs; ++qp) {
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00162
00163
00164
00165
00166
00167
00168 for (std::size_t node=0; node < numNodes; ++node) {
00169
00170
00171
00172
00173
00174
00175
00176
00177 Residual(cell,node,0) += UDot(cell,qp,0)*wBF(cell,node,qp)
00178 - (U(cell,qp,0)-surfHeight(cell,qp))*( U(cell,qp,1)*wGradBF(cell,node,qp,0)
00179 + U(cell,qp,2)*wGradBF(cell,node,qp,1) );
00180 }
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 }
00199
00200
00201
00202
00203 if (usePrescribedVelocity) {
00204 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00205 for (std::size_t qp=0; qp < numQPs; ++qp) {
00206 for (std::size_t node=0; node < numNodes; ++node) {
00207 Residual(cell,node,1) += UDot(cell,qp,1)*wBF(cell,node,qp);
00208 Residual(cell,node,2) += UDot(cell,qp,2)*wBF(cell,node,qp);
00209 }
00210 }
00211 }
00212 }
00213 else {
00214
00215 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00216 for (std::size_t qp=0; qp < numQPs; ++qp) {
00217 for (std::size_t node=0; node < numNodes; ++node) {
00218 Residual(cell,node,1) += ( UDot(cell,qp,1)
00219 + U(cell,qp,1)*Ugrad(cell,qp,1,0) + U(cell,qp,2)*Ugrad(cell,qp,1,1)
00220 + gravity*Ugrad(cell,qp,0,0)
00221 )*wBF(cell,node,qp);
00222 Residual(cell,node,2) += ( UDot(cell,qp,2)
00223 + U(cell,qp,1)*Ugrad(cell,qp,2,0) + U(cell,qp,2)*Ugrad(cell,qp,2,1)
00224 + gravity*Ugrad(cell,qp,0,1)
00225 )*wBF(cell,node,qp);
00226 }
00227 }
00228 }
00229 }
00230 }
00231
00232
00233
00234 template<typename EvalT,typename Traits>
00235 typename ShallowWaterResid<EvalT,Traits>::ScalarT&
00236 ShallowWaterResid<EvalT,Traits>::getValue(const std::string &n)
00237 {
00238 return gravity;
00239 }
00240
00241 }