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 HYD {
00013
00014
00015 template<typename EvalT, typename Traits>
00016 HydrideStress<EvalT, Traits>::
00017 HydrideStress(const Teuchos::ParameterList& p) :
00018 strain (p.get<std::string> ("Strain Name"),
00019 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00020 c (p.get<std::string> ("C QP Variable Name"),
00021 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00022 stress (p.get<std::string> ("Stress Name"),
00023 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") )
00024 {
00025
00026 e = p.get<double>("e Value");
00027
00028
00029
00030 Teuchos::RCP<PHX::DataLayout> tensor_dl =
00031 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout");
00032 std::vector<PHX::DataLayout::size_type> dims;
00033 tensor_dl->dimensions(dims);
00034 numQPs = dims[1];
00035 numDims = dims[2];
00036
00037
00038 if(numDims == 2){
00039
00040 ElastTensor.resize(3, 3);
00041
00042 ElastTensor(0, 0) = 2.0;
00043 ElastTensor(0, 1) = 1.0;
00044 ElastTensor(1, 0) = 1.0;
00045 ElastTensor(2, 2) = 10.0;
00046
00047 }
00048 else {
00049
00050 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Hydride only works in 2D presently: "
00051 << "See line " << __LINE__ << " in file " << __FILE__ << std::endl);
00052
00053 ElastTensor.resize(6, 6);
00054
00055 }
00056
00057 this->addDependentField(c);
00058 this->addDependentField(strain);
00059
00060 this->addEvaluatedField(stress);
00061
00062 this->setName("HydrideStress"+PHX::TypeString<EvalT>::value);
00063
00064 }
00065
00066
00067 template<typename EvalT, typename Traits>
00068 void HydrideStress<EvalT, Traits>::
00069 postRegistrationSetup(typename Traits::SetupData d,
00070 PHX::FieldManager<Traits>& fm)
00071 {
00072 this->utils.setFieldData(c,fm);
00073 this->utils.setFieldData(stress,fm);
00074 this->utils.setFieldData(strain,fm);
00075 }
00076
00077
00078 #if 0
00079 template<typename EvalT, typename Traits>
00080 void HydrideStress<EvalT, Traits>::
00081 evaluateFields(typename Traits::EvalData workset)
00082 {
00083 ScalarT lambda, mu;
00084
00085 switch (numDims) {
00086 case 1:
00087 Intrepid::FunctionSpaceTools::tensorMultiplyDataData<ScalarT>(stress, elasticModulus, strain);
00088 break;
00089 case 2:
00090
00091 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00092 for (std::size_t qp=0; qp < numQPs; ++qp) {
00093
00094 lambda = ( elasticModulus(cell,qp) * poissonsRatio(cell,qp) )
00095 / ( ( 1 + poissonsRatio(cell,qp) ) * ( 1 - 2 * poissonsRatio(cell,qp) ) );
00096
00097 mu = elasticModulus(cell,qp) / ( 2 * ( 1 + poissonsRatio(cell,qp) ) );
00098
00099 stress(cell,qp,0,0) = 2.0 * mu * ( strain(cell,qp,0,0) )
00100 + lambda * ( strain(cell,qp,0,0) + strain(cell,qp,1,1) );
00101
00102 stress(cell,qp,1,1) = 2.0 * mu * ( strain(cell,qp,1,1) )
00103 + lambda * ( strain(cell,qp,0,0) + strain(cell,qp,1,1) );
00104
00105 stress(cell,qp,0,1) = 2.0 * mu * ( strain(cell,qp,0,1) );
00106
00107 stress(cell,qp,1,0) = stress(cell,qp,0,1);
00108
00109 }
00110 }
00111 break;
00112
00113 case 3:
00114
00115 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00116 for (std::size_t qp=0; qp < numQPs; ++qp) {
00117
00118 lambda = ( elasticModulus(cell,qp) * poissonsRatio(cell,qp) )
00119 / ( ( 1 + poissonsRatio(cell,qp) ) * ( 1 - 2 * poissonsRatio(cell,qp) ) );
00120
00121 mu = elasticModulus(cell,qp) / ( 2 * ( 1 + poissonsRatio(cell,qp) ) );
00122
00123 stress(cell,qp,0,0) = 2.0 * mu * ( strain(cell,qp,0,0) )
00124 + lambda * ( strain(cell,qp,0,0) + strain(cell,qp,1,1) + strain(cell,qp,2,2) );
00125
00126 stress(cell,qp,1,1) = 2.0 * mu * ( strain(cell,qp,1,1) )
00127 + lambda * ( strain(cell,qp,0,0) + strain(cell,qp,1,1) + strain(cell,qp,2,2) );
00128
00129 stress(cell,qp,2,2) = 2.0 * mu * ( strain(cell,qp,2,2) )
00130 + lambda * ( strain(cell,qp,0,0) + strain(cell,qp,1,1) + strain(cell,qp,2,2) );
00131
00132 stress(cell,qp,0,1) = 2.0 * mu * ( strain(cell,qp,0,1) );
00133
00134 stress(cell,qp,1,2) = 2.0 * mu * ( strain(cell,qp,1,2) );
00135
00136 stress(cell,qp,2,0) = 2.0 * mu * ( strain(cell,qp,2,0) );
00137
00138 stress(cell,qp,1,0) = stress(cell,qp,0,1);
00139
00140 stress(cell,qp,2,1) = stress(cell,qp,1,2);
00141
00142 stress(cell,qp,0,2) = stress(cell,qp,2,0);
00143
00144 }
00145 }
00146 break;
00147 }
00148 }
00149 #endif
00150
00151 template<typename EvalT, typename Traits>
00152 void HydrideStress<EvalT, Traits>::
00153 evaluateFields(typename Traits::EvalData workset)
00154 {
00155
00156 switch (numDims) {
00157 case 1:
00158
00159 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Hydride only works in 2D presently: "
00160 << "See line " << __LINE__ << " in file " << __FILE__ << std::endl);
00161 break;
00162 case 2:
00163
00164 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00165 for (std::size_t qp=0; qp < numQPs; ++qp) {
00166
00167 stress(cell,qp,0,0) = ElastTensor(0,0) * (strain(cell,qp,0,0) - e * c(cell, qp))
00168 + ElastTensor(0, 1) * (strain(cell,qp,1,1) - e * c(cell, qp))
00169 + ElastTensor(0, 2) * 2.0 * strain(cell,qp,0,1);
00170
00171 stress(cell,qp,1,1) = ElastTensor(1,0) * (strain(cell,qp,0,0) - e * c(cell, qp))
00172 + ElastTensor(1, 1) * (strain(cell,qp,1,1) - e * c(cell, qp))
00173 + ElastTensor(1, 2) * 2.0 * strain(cell,qp,0,1);
00174
00175 stress(cell,qp,0,1) = ElastTensor(2,0) * (strain(cell,qp,0,0) - e * c(cell, qp))
00176 + ElastTensor(2, 1) * (strain(cell,qp,1,1) - e * c(cell, qp))
00177 + ElastTensor(2, 2) * 2.0 * strain(cell,qp,0,1);
00178
00179 stress(cell,qp,1,0) = stress(cell,qp,0,1);
00180
00181 }
00182 }
00183 break;
00184
00185 case 3:
00186 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Hydride only works in 2D presently: "
00187 << "See line " << __LINE__ << " in file " << __FILE__ << std::endl);
00188 break;
00189 }
00190 }
00191
00192 template<typename EvalT, typename Traits>
00193 typename HydrideStress<EvalT, Traits>::ScalarT&
00194 HydrideStress<EvalT, Traits>::getValue(const std::string &n) {
00195
00196 if (n == "e")
00197
00198 return e;
00199
00200 else
00201 {
00202 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, std::endl <<
00203 "Error! Logic error in getting parameter " << n <<
00204 " in HydrideStress::getValue()" << std::endl);
00205 return e;
00206 }
00207
00208 }
00209
00210
00211
00212 }
00213