00001
00002
00003
00004
00005
00006 #include <Teuchos_UnitTestHarness.hpp>
00007 #include <Teuchos_ParameterList.hpp>
00008 #include <Epetra_MpiComm.h>
00009 #include <Phalanx.hpp>
00010 #include "PHAL_AlbanyTraits.hpp"
00011 #include "Albany_Utils.hpp"
00012 #include "Albany_StateManager.hpp"
00013 #include "Albany_TmplSTKMeshStruct.hpp"
00014 #include "Albany_STKDiscretization.hpp"
00015 #include "Albany_OrdinarySTKFieldContainer.hpp"
00016 #include "Albany_MultiSTKFieldContainer.hpp"
00017 #include "LCM/evaluators/lame/LameStress.hpp"
00018 #include "LCM/evaluators/SetField.hpp"
00019 #include <Intrepid_MiniTensor.h>
00020
00021 using namespace std;
00022
00023 namespace {
00024
00025 TEUCHOS_UNIT_TEST( LameStress_elastic, Instantiation )
00026 {
00027
00028 const int worksetSize = 1;
00029 const int numQPts = 1;
00030 const int numDim = 3;
00031 Teuchos::RCP<PHX::MDALayout<Cell, QuadPoint> > qp_scalar =
00032 Teuchos::rcp(new PHX::MDALayout<Cell, QuadPoint>(worksetSize, numQPts));
00033 Teuchos::RCP<PHX::MDALayout<Cell, QuadPoint, Dim, Dim> > qp_tensor =
00034 Teuchos::rcp(new PHX::MDALayout<Cell, QuadPoint, Dim, Dim>(worksetSize, numQPts, numDim, numDim));
00035
00036
00037
00038
00039
00040 Teuchos::ArrayRCP<PHAL::AlbanyTraits::Residual::ScalarT> tensorValue(9);
00041 tensorValue[0] = 1.010050167084168;
00042 tensorValue[1] = 0.0;
00043 tensorValue[2] = 0.0;
00044 tensorValue[3] = 0.0;
00045 tensorValue[4] = 0.99750312239746;
00046 tensorValue[5] = 0.0;
00047 tensorValue[6] = 0.0;
00048 tensorValue[7] = 0.0;
00049 tensorValue[8] = 0.99750312239746;
00050
00051
00052 Teuchos::ParameterList setFieldParameterList("SetField");
00053 setFieldParameterList.set<string>("Evaluated Field Name", "Deformation Gradient");
00054 setFieldParameterList.set< Teuchos::RCP<PHX::DataLayout> >("Evaluated Field Data Layout", qp_tensor);
00055 setFieldParameterList.set< Teuchos::ArrayRCP<PHAL::AlbanyTraits::Residual::ScalarT> >("Field Values", tensorValue);
00056 Teuchos::RCP<LCM::SetField<PHAL::AlbanyTraits::Residual, PHAL::AlbanyTraits> > setField =
00057 Teuchos::rcp(new LCM::SetField<PHAL::AlbanyTraits::Residual, PHAL::AlbanyTraits>(setFieldParameterList));
00058
00059
00060 Teuchos::RCP<Teuchos::ParameterList> lameStressParameterList = Teuchos::rcp(new Teuchos::ParameterList("Stress"));
00061 lameStressParameterList->set<string>("DefGrad Name", "Deformation Gradient");
00062 lameStressParameterList->set<string>("Stress Name", "Stress");
00063 lameStressParameterList->set< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout", qp_scalar);
00064 lameStressParameterList->set< Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout", qp_tensor);
00065 lameStressParameterList->set<string>("Lame Material Model", "Elastic_New");
00066 Teuchos::ParameterList& materialModelParametersList = lameStressParameterList->sublist("Lame Material Parameters");
00067 materialModelParametersList.set<double>("Youngs Modulus", 1.0);
00068 materialModelParametersList.set<double>("Poissons Ratio", 0.25);
00069 Teuchos::RCP<LCM::LameStress<PHAL::AlbanyTraits::Residual, PHAL::AlbanyTraits> > lameStress =
00070 Teuchos::rcp(new LCM::LameStress<PHAL::AlbanyTraits::Residual, PHAL::AlbanyTraits>(*lameStressParameterList));
00071
00072
00073 PHX::FieldManager<PHAL::AlbanyTraits> fieldManager;
00074
00075
00076 fieldManager.registerEvaluator<PHAL::AlbanyTraits::Residual>(setField);
00077 fieldManager.registerEvaluator<PHAL::AlbanyTraits::Residual>(lameStress);
00078
00079
00080 for(std::vector<Teuchos::RCP<PHX::FieldTag> >::const_iterator it = lameStress->evaluatedFields().begin() ; it != lameStress->evaluatedFields().end() ; it++)
00081 fieldManager.requireField<PHAL::AlbanyTraits::Residual>(**it);
00082
00083
00084 PHAL::AlbanyTraits::SetupData setupData = "Test String";
00085 fieldManager.postRegistrationSetup(setupData);
00086
00087
00088 Albany::StateManager stateMgr;
00089
00090 stateMgr.registerStateVariable("Stress", qp_tensor, "dummy", "scalar", 0.0, true);
00091 stateMgr.registerStateVariable("Deformation Gradient", qp_tensor, "dummy", "identity", 1.0, true);
00092
00093 string lameMaterialModelName = lameStressParameterList->get<string>("Lame Material Model");
00094 std::vector<std::string> lameMaterialModelStateVariableNames = LameUtils::getStateVariableNames(lameMaterialModelName, materialModelParametersList);
00095 std::vector<double> lameMaterialModelStateVariableInitialValues = LameUtils::getStateVariableInitialValues(lameMaterialModelName, materialModelParametersList);
00096 for(unsigned int i=0 ; i<lameMaterialModelStateVariableNames.size() ; ++i){
00097 stateMgr.registerStateVariable(lameMaterialModelStateVariableNames[i],
00098 qp_scalar,
00099 "dummy",
00100 Albany::doubleToInitString(lameMaterialModelStateVariableInitialValues[i]),
00101 true);
00102 }
00103
00104
00105 Teuchos::RCP<Teuchos::ParameterList> discretizationParameterList
00106 = Teuchos::rcp(new Teuchos::ParameterList("Discretization"));
00107 discretizationParameterList->set<int>("1D Elements", worksetSize);
00108 discretizationParameterList->set<int>("2D Elements", 1);
00109 discretizationParameterList->set<int>("3D Elements", 1);
00110 discretizationParameterList->set<string>("Method", "STK3D");
00111 discretizationParameterList->set<string>("Exodus Output File Name", "unitTestOutput.exo");
00112 Teuchos::RCP<Epetra_Comm> comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
00113 int numberOfEquations = 3;
00114 Albany::AbstractFieldContainer::FieldContainerRequirements req;
00115 Teuchos::RCP<Albany::GenericSTKMeshStruct> stkMeshStruct
00116 = Teuchos::rcp(new Albany::TmplSTKMeshStruct<3>(discretizationParameterList, Teuchos::null, comm));
00117 stkMeshStruct->setFieldAndBulkData(comm,
00118 discretizationParameterList,
00119 numberOfEquations,
00120 req,
00121 stateMgr.getStateInfoStruct(),
00122 stkMeshStruct->getMeshSpecs()[0]->worksetSize);
00123 Teuchos::RCP<Albany::AbstractDiscretization> discretization =
00124 Teuchos::rcp(new Albany::STKDiscretization(stkMeshStruct, comm));
00125
00126
00127 stateMgr.setStateArrays(discretization);
00128
00129
00130 PHAL::Workset workset;
00131 workset.numCells = worksetSize;
00132 workset.stateArrayPtr = &stateMgr.getStateArray(Albany::StateManager::ELEM, 0);
00133
00134
00135 fieldManager.preEvaluate<PHAL::AlbanyTraits::Residual>(workset);
00136 fieldManager.evaluateFields<PHAL::AlbanyTraits::Residual>(workset);
00137 fieldManager.postEvaluate<PHAL::AlbanyTraits::Residual>(workset);
00138
00139
00140 PHX::MDField<PHAL::AlbanyTraits::Residual::ScalarT,Cell,QuadPoint,Dim,Dim> stressField("Stress", qp_tensor);
00141 fieldManager.getFieldData<PHAL::AlbanyTraits::Residual::ScalarT, PHAL::AlbanyTraits::Residual, Cell, QuadPoint, Dim, Dim>(stressField);
00142
00143
00144
00145
00146
00147
00148 Intrepid::Tensor<PHAL::AlbanyTraits::Residual::ScalarT>
00149 expectedStress(materialModelParametersList.get<double>("Youngs Modulus") * 0.01,
00150 0.0,
00151 0.0,
00152 0.0,
00153 0.0,
00154 0.0,
00155 0.0,
00156 0.0,
00157 0.0);
00158
00159
00160 typedef PHX::MDField<PHAL::AlbanyTraits::Residual::ScalarT>::size_type size_type;
00161 for(size_type cell=0; cell<worksetSize; ++cell){
00162 for(size_type qp=0; qp<numQPts; ++qp){
00163
00164 std::cout << "Stress tensor at cell " << cell << ", quadrature point " << qp << ":" << endl;
00165 std::cout << " " << stressField(cell, qp, 0, 0);
00166 std::cout << " " << stressField(cell, qp, 0, 1);
00167 std::cout << " " << stressField(cell, qp, 0, 2) << endl;
00168 std::cout << " " << stressField(cell, qp, 1, 0);
00169 std::cout << " " << stressField(cell, qp, 1, 1);
00170 std::cout << " " << stressField(cell, qp, 1, 2) << endl;
00171 std::cout << " " << stressField(cell, qp, 2, 0);
00172 std::cout << " " << stressField(cell, qp, 2, 1);
00173 std::cout << " " << stressField(cell, qp, 2, 2) << endl;
00174
00175 std::cout << "Expected result:" << endl;
00176 std::cout << " " << expectedStress(0, 0);
00177 std::cout << " " << expectedStress(0, 1);
00178 std::cout << " " << expectedStress(0, 2) << endl;
00179 std::cout << " " << expectedStress(1, 0);
00180 std::cout << " " << expectedStress(1, 1);
00181 std::cout << " " << expectedStress(1, 2) << endl;
00182 std::cout << " " << expectedStress(2, 0);
00183 std::cout << " " << expectedStress(2, 1);
00184 std::cout << " " << expectedStress(2, 2) << endl;
00185
00186 std::cout << endl;
00187
00188 double tolerance = 1.0e-15;
00189 for(size_type i=0 ; i<numDim ; ++i){
00190 for(size_type j=0 ; j<numDim ; ++j){
00191 TEST_COMPARE( fabs(stressField(cell, qp, i, j) - expectedStress(i, j)), <=, tolerance );
00192 }
00193 }
00194
00195 }
00196 }
00197 std::cout << endl;
00198
00199 }
00200
00201 }