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 LCM {
00013
00014
00015 template<typename EvalT, typename Traits>
00016 DislocationDensity<EvalT, Traits>::
00017 DislocationDensity(const Teuchos::ParameterList& p) :
00018 Fp (p.get<std::string> ("Fp Name"),
00019 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00020 BF (p.get<std::string> ("BF Name"),
00021 p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Scalar Data Layout") ),
00022 GradBF (p.get<std::string> ("Gradient BF Name"),
00023 p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Vector Data Layout") ),
00024 G (p.get<std::string> ("Dislocation Density Name"),
00025 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") )
00026 {
00027 this->addDependentField(Fp);
00028 this->addDependentField(BF);
00029 this->addDependentField(GradBF);
00030 this->addEvaluatedField(G);
00031
00032
00033 Teuchos::RCP<PHX::DataLayout> vector_dl = p.get< Teuchos::RCP<PHX::DataLayout> >("Node QP Vector Data Layout");
00034 std::vector<PHX::DataLayout::size_type> dim;
00035 vector_dl->dimensions(dim);
00036
00037 int containerSize = dim[0];
00038 numNodes = dim[1];
00039 numQPs = dim[2];
00040 numDims = dim[3];
00041
00042
00043 nodalFp.resize(numNodes,numDims,numDims);
00044 curlFp.resize(numQPs,numDims,numDims);
00045
00046 square = (numNodes == numQPs);
00047
00048 TEUCHOS_TEST_FOR_EXCEPTION( square == false, std::runtime_error,
00049 "Dislocation Density Calculation currently needs numNodes == numQPs" );
00050
00051
00052 this->setName("DislocationDensity"+PHX::TypeString<EvalT>::value);
00053 }
00054
00055
00056 template<typename EvalT, typename Traits>
00057 void DislocationDensity<EvalT, Traits>::
00058 postRegistrationSetup(typename Traits::SetupData d,
00059 PHX::FieldManager<Traits>& fm)
00060 {
00061 this->utils.setFieldData(Fp,fm);
00062 this->utils.setFieldData(BF,fm);
00063 this->utils.setFieldData(GradBF,fm);
00064 this->utils.setFieldData(G,fm);
00065 }
00066
00067
00068 template<typename EvalT, typename Traits>
00069 void DislocationDensity<EvalT, Traits>::
00070 evaluateFields(typename Traits::EvalData workset)
00071 {
00072
00073 Teuchos::SerialDenseMatrix<int, double> A;
00074 Teuchos::SerialDenseMatrix<int, double> X;
00075 Teuchos::SerialDenseMatrix<int, double> B;
00076 Teuchos::SerialDenseSolver<int, double> solver;
00077
00078 A.shape(numNodes,numNodes);
00079 X.shape(numNodes,numNodes);
00080 B.shape(numNodes,numNodes);
00081
00082
00083 for (int i = 0; i < numNodes; ++i)
00084 B(i,i) = 1.0;
00085
00086 for (int i=0; i < G.size() ; i++) G[i] = 0.0;
00087
00088
00089 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00090 {
00091 for (std::size_t node=0; node < numNodes; ++node)
00092 for (std::size_t qp=0; qp < numQPs; ++qp)
00093 A(qp,node) = BF(cell,node,qp);
00094
00095 X = 0.0;
00096
00097 solver.setMatrix( Teuchos::rcp( &A, false) );
00098 solver.setVectors( Teuchos::rcp( &X, false ), Teuchos::rcp( &B, false ) );
00099
00100
00101 int status = 0;
00102 status = solver.factor();
00103 status = solver.solve();
00104
00105
00106 nodalFp.initialize(0.0);
00107 for (std::size_t node=0; node < numNodes; ++node)
00108 for (std::size_t qp=0; qp < numQPs; ++qp)
00109 for (std::size_t i=0; i < numDims; ++i)
00110 for (std::size_t j=0; j < numDims; ++j)
00111 nodalFp(node,i,j) += X(node,qp) * Fp(cell,qp,i,j);
00112
00113
00114 curlFp.initialize(0.0);
00115 for (std::size_t node=0; node < numNodes; ++node)
00116 {
00117 for (std::size_t qp=0; qp < numQPs; ++qp)
00118 {
00119 curlFp(qp,0,0) += nodalFp(node,0,2) * GradBF(cell,node,qp,1) - nodalFp(node,0,1) * GradBF(cell,node,qp,2);
00120 curlFp(qp,0,1) += nodalFp(node,1,2) * GradBF(cell,node,qp,1) - nodalFp(node,1,1) * GradBF(cell,node,qp,2);
00121 curlFp(qp,0,2) += nodalFp(node,2,2) * GradBF(cell,node,qp,1) - nodalFp(node,2,1) * GradBF(cell,node,qp,2);
00122
00123 curlFp(qp,1,0) += nodalFp(node,0,0) * GradBF(cell,node,qp,2) - nodalFp(node,0,2) * GradBF(cell,node,qp,0);
00124 curlFp(qp,1,1) += nodalFp(node,1,0) * GradBF(cell,node,qp,2) - nodalFp(node,1,2) * GradBF(cell,node,qp,0);
00125 curlFp(qp,1,2) += nodalFp(node,2,0) * GradBF(cell,node,qp,2) - nodalFp(node,2,2) * GradBF(cell,node,qp,0);
00126
00127 curlFp(qp,2,0) += nodalFp(node,0,1) * GradBF(cell,node,qp,0) - nodalFp(node,0,0) * GradBF(cell,node,qp,1);
00128 curlFp(qp,2,1) += nodalFp(node,1,1) * GradBF(cell,node,qp,0) - nodalFp(node,1,0) * GradBF(cell,node,qp,1);
00129 curlFp(qp,2,2) += nodalFp(node,2,1) * GradBF(cell,node,qp,0) - nodalFp(node,2,0) * GradBF(cell,node,qp,1);
00130 }
00131 }
00132
00133 for (std::size_t qp=0; qp < numQPs; ++qp)
00134 for (std::size_t i=0; i < numDims; ++i)
00135 for (std::size_t j=0; j < numDims; ++j)
00136 for (std::size_t k=0; k < numDims; ++k)
00137 G(cell,qp,i,j) += Fp(cell,qp,i,k) * curlFp(qp,k,j);
00138 }
00139 }
00140
00141
00142 }