00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009
00010 #include "Intrepid_FunctionSpaceTools.hpp"
00011 #include "Intrepid_RealSpaceTools.hpp"
00012
00013 #include <typeinfo>
00014
00015 namespace LCM {
00016
00017
00018 template<typename EvalT, typename Traits>
00019 ThermoMechanicalEnergyResidual<EvalT, Traits>::
00020 ThermoMechanicalEnergyResidual(const Teuchos::ParameterList& p) :
00021 wBF (p.get<std::string> ("Weighted BF Name"),
00022 p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Scalar Data Layout") ),
00023 Temperature (p.get<std::string> ("QP Variable Name"),
00024 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00025 ThermalCond (p.get<std::string> ("Thermal Conductivity Name"),
00026 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00027 wGradBF (p.get<std::string> ("Weighted Gradient BF Name"),
00028 p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Vector Data Layout") ),
00029 TGrad (p.get<std::string> ("Gradient QP Variable Name"),
00030 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout") ),
00031 Source (p.get<std::string> ("Source Name"),
00032 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00033 F (p.get<std::string> ("Deformation Gradient Name"),
00034 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00035 mechSource (p.get<std::string> ("Mechanical Source Name"),
00036 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00037 deltaTime (p.get<std::string> ("Delta Time Name"),
00038 p.get<Teuchos::RCP<PHX::DataLayout> >("Workset Scalar Data Layout") ),
00039 density (p.get<RealType>("Density") ),
00040 Cv (p.get<RealType>("Heat Capacity") ),
00041 TResidual (p.get<std::string> ("Residual Name"),
00042 p.get<Teuchos::RCP<PHX::DataLayout> >("Node Scalar Data Layout") ),
00043 haveSource (p.get<bool>("Have Source") )
00044 {
00045 this->addDependentField(wBF);
00046 this->addDependentField(Temperature);
00047 this->addDependentField(ThermalCond);
00048 this->addDependentField(TGrad);
00049 this->addDependentField(wGradBF);
00050 this->addDependentField(F);
00051 this->addDependentField(mechSource);
00052 this->addDependentField(deltaTime);
00053 if (haveSource) this->addDependentField(Source);
00054 this->addEvaluatedField(TResidual);
00055
00056 tempName = p.get<std::string>("QP Variable Name")+"_old";
00057
00058 Teuchos::RCP<PHX::DataLayout> vector_dl =
00059 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
00060 std::vector<PHX::DataLayout::size_type> dims;
00061 vector_dl->dimensions(dims);
00062 worksetSize = dims[0];
00063 numQPs = dims[1];
00064 numDims = dims[2];
00065
00066
00067 flux.resize(dims[0], numQPs, numDims);
00068 C.resize(worksetSize, numQPs, numDims, numDims);
00069 Cinv.resize(worksetSize, numQPs, numDims, numDims);
00070 CinvTgrad.resize(worksetSize, numQPs, numDims);
00071 Tdot.resize(worksetSize, numQPs);
00072
00073 this->setName("ThermoMechanicalEnergyResidual"+PHX::TypeString<EvalT>::value);
00074 }
00075
00076
00077 template<typename EvalT, typename Traits>
00078 void ThermoMechanicalEnergyResidual<EvalT, Traits>::
00079 postRegistrationSetup(typename Traits::SetupData d,
00080 PHX::FieldManager<Traits>& fm)
00081 {
00082 this->utils.setFieldData(wBF,fm);
00083 this->utils.setFieldData(Temperature,fm);
00084 this->utils.setFieldData(ThermalCond,fm);
00085 this->utils.setFieldData(TGrad,fm);
00086 this->utils.setFieldData(wGradBF,fm);
00087 this->utils.setFieldData(F,fm);
00088 this->utils.setFieldData(mechSource,fm);
00089 this->utils.setFieldData(deltaTime,fm);
00090 if (haveSource) this->utils.setFieldData(Source,fm);
00091
00092 this->utils.setFieldData(TResidual,fm);
00093 }
00094
00095
00096 template<typename EvalT, typename Traits>
00097 void ThermoMechanicalEnergyResidual<EvalT, Traits>::
00098 evaluateFields(typename Traits::EvalData workset)
00099 {
00100 bool print = false;
00101
00102
00103
00104 typedef Intrepid::FunctionSpaceTools FST;
00105
00106
00107 Albany::MDArray Temperature_old = (*workset.stateArrayPtr)[tempName];
00108
00109
00110 ScalarT dt = deltaTime(0);
00111
00112
00113 FST::tensorMultiplyDataData<ScalarT> (C, F, F, 'T');
00114 Intrepid::RealSpaceTools<ScalarT>::inverse(Cinv, C);
00115 FST::tensorMultiplyDataData<ScalarT> (CinvTgrad, Cinv, TGrad);
00116 FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, CinvTgrad);
00117
00118 FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid::COMP_CPP, false);
00119
00120 if (haveSource) {
00121 for (int i=0; i<Source.size(); i++) Source[i] *= -1.0;
00122 FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid::COMP_CPP, true);
00123 }
00124
00125 for (int i=0; i<mechSource.size(); i++) mechSource[i] *= -1.0;
00126 FST::integrate<ScalarT>(TResidual, mechSource, wBF, Intrepid::COMP_CPP, true);
00127
00128
00129
00130
00131
00132 ScalarT fac(0.0);
00133 if (dt > 0.0)
00134 fac = ( density * Cv ) / dt;
00135
00136 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00137 for (std::size_t qp=0; qp < numQPs; ++qp)
00138 Tdot(cell,qp) = fac * ( Temperature(cell,qp) - Temperature_old(cell,qp) );
00139
00140 FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid::COMP_CPP, true);
00141
00142 if (print)
00143 {
00144 std::cout << " *** ThermoMechanicalEnergyResidual *** " << std::endl;
00145 std::cout << " ** dt: " << dt << std::endl;
00146 std::cout << " ** rho: " << density << std::endl;
00147 std::cout << " ** Cv: " << Cv << std::endl;
00148 for (unsigned int cell(0); cell < workset.numCells; ++cell)
00149 {
00150 std::cout << " ** Cell: " << cell << std::endl;
00151 for (unsigned int qp(0); qp < numQPs; ++qp)
00152 {
00153 std::cout << " * QP: " << std::endl;
00154 std::cout << " F : ";
00155 for (unsigned int i(0); i < numDims; ++i)
00156 for (unsigned int j(0); j < numDims; ++j)
00157 std::cout << F(cell,qp,i,j) << " ";
00158 std::cout << std::endl;
00159
00160 std::cout << " C : ";
00161 for (unsigned int i(0); i < numDims; ++i)
00162 for (unsigned int j(0); j < numDims; ++j)
00163 std::cout << C(cell,qp,i,j) << " ";
00164 std::cout << std::endl;
00165
00166 std::cout << " T : " << Temperature(cell,qp) << std::endl;
00167 std::cout << " Told: " << Temperature(cell,qp) << std::endl;
00168 std::cout << " k : " << ThermalCond(cell,qp) << std::endl;
00169 }
00170 }
00171 }
00172 }
00173
00174
00175 }