00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012
00013 #include <Teuchos_GlobalMPISession.hpp>
00014 #include <Teuchos_CommandLineProcessor.hpp>
00015 #include <Teuchos_RCP.hpp>
00016 #include <Teuchos_ParameterList.hpp>
00017 #include <Teuchos_TestForException.hpp>
00018 #include <Teuchos_as.hpp>
00019 #include <QCAD_MaterialDatabase.hpp>
00020 #include <Phalanx.hpp>
00021
00022 #include <PHAL_AlbanyTraits.hpp>
00023 #include <PHAL_SaveStateField.hpp>
00024 #include <Albany_Utils.hpp>
00025 #include <Albany_StateManager.hpp>
00026 #include <Albany_TmplSTKMeshStruct.hpp>
00027 #include <Albany_STKDiscretization.hpp>
00028 #include <Albany_Layouts.hpp>
00029
00030 #include <Intrepid_MiniTensor.h>
00031
00032 #include "FieldNameMap.hpp"
00033
00034 #include "SetField.hpp"
00035
00036 #include "ConstitutiveModelInterface.hpp"
00037 #include "ConstitutiveModelParameters.hpp"
00038 #include "BifurcationCheck.hpp"
00039
00040 int main(int ac, char* av[])
00041 {
00042
00043 typedef PHX::MDField<PHAL::AlbanyTraits::Residual::ScalarT>::size_type size_type;
00044 typedef PHAL::AlbanyTraits::Residual Residual;
00045 typedef PHAL::AlbanyTraits::Residual::ScalarT ScalarT;
00046 typedef PHAL::AlbanyTraits Traits;
00047 std::cout.precision(15);
00048
00049
00050
00051 Teuchos::CommandLineProcessor command_line_processor;
00052
00053 command_line_processor.setDocString("Material Point Simulator.\n"
00054 "For testing material models in LCM.\n");
00055
00056 std::string input_file = "materials.xml";
00057 command_line_processor.setOption("input", &input_file, "Input File Name");
00058
00059
00060 command_line_processor.recogniseAllOptions(true);
00061
00062
00063 command_line_processor.throwExceptions(false);
00064
00065
00066 Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
00067 command_line_processor.parse(ac, av);
00068
00069 if (parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
00070 return 0;
00071 }
00072
00073 if (parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00074 return 1;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084 Teuchos::GlobalMPISession mpi_session(&ac, &av);
00085 Teuchos::RCP<Epetra_Comm> comm =
00086 Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
00087
00088 Teuchos::RCP<QCAD::MaterialDatabase> material_db;
00089 material_db = Teuchos::rcp(new QCAD::MaterialDatabase(input_file, comm));
00090
00091
00092 std::string element_block_name = "Block0";
00093 std::string material_model_name;
00094 material_model_name = material_db->getElementBlockSublist(element_block_name,
00095 "Material Model").get<std::string>("Model Name");
00096 TEUCHOS_TEST_FOR_EXCEPTION(material_model_name.length()==0,
00097 std::logic_error,
00098 "A material model must be defined for block: "
00099 +element_block_name);
00100
00101
00102
00103
00104
00105
00106
00107 const int workset_size = 1;
00108 const int num_pts = 1;
00109 const int num_dims = 3;
00110 const int num_vertices = 8;
00111 const int num_nodes = 8;
00112 const Teuchos::RCP<Albany::Layouts> dl =
00113 Teuchos::rcp(new Albany::Layouts(workset_size,
00114 num_vertices,
00115 num_nodes,
00116 num_pts,
00117 num_dims));
00118
00119
00120 LCM::FieldNameMap field_name_map(false);
00121 Teuchos::RCP<std::map<std::string, std::string> > fnm =
00122 field_name_map.getMap();
00123
00124
00125
00126 Teuchos::ArrayRCP<ScalarT> def_grad(9);
00127 for (int i(0); i < 9; ++i)
00128 def_grad[i] = 0.0;
00129
00130 def_grad[0] = 1.0;
00131 def_grad[4] = 1.0;
00132 def_grad[8] = 1.0;
00133
00134
00135 Teuchos::ParameterList setDefGradP("SetFieldDefGrad");
00136 setDefGradP.set<std::string>("Evaluated Field Name", "F");
00137 setDefGradP.set<Teuchos::RCP<PHX::DataLayout> >
00138 ("Evaluated Field Data Layout", dl->qp_tensor);
00139 setDefGradP.set<Teuchos::ArrayRCP<ScalarT> >("Field Values", def_grad);
00140 Teuchos::RCP<LCM::SetField<Residual, Traits> > setFieldDefGrad =
00141 Teuchos::rcp(new LCM::SetField<Residual, Traits>(setDefGradP));
00142
00143
00144
00145 Teuchos::ArrayRCP<ScalarT> detdefgrad(1);
00146 detdefgrad[0] = 1.0;
00147
00148
00149 Teuchos::ParameterList setDetDefGradP("SetFieldDetDefGrad");
00150 setDetDefGradP.set<std::string>("Evaluated Field Name", "J");
00151 setDetDefGradP.set<Teuchos::RCP<PHX::DataLayout> >(
00152 "Evaluated Field Data Layout", dl->qp_scalar);
00153 setDetDefGradP.set<Teuchos::ArrayRCP<ScalarT> >("Field Values", detdefgrad);
00154 Teuchos::RCP<LCM::SetField<Residual, Traits> > setFieldDetDefGrad =
00155 Teuchos::rcp(new LCM::SetField<Residual, Traits>(setDetDefGradP));
00156
00157
00158 PHX::FieldManager<Traits> fieldManager;
00159
00160
00161 PHX::FieldManager<Traits> stateFieldManager;
00162
00163
00164 fieldManager.registerEvaluator<Residual>(setFieldDefGrad);
00165 fieldManager.registerEvaluator<Residual>(setFieldDetDefGrad);
00166
00167
00168 stateFieldManager.registerEvaluator<Residual>(setFieldDefGrad);
00169 stateFieldManager.registerEvaluator<Residual>(setFieldDetDefGrad);
00170
00171
00172 Albany::StateManager stateMgr;
00173
00174
00175 std::string matName =
00176 material_db->getElementBlockParam<std::string>(element_block_name,"material");
00177 Teuchos::ParameterList& paramList =
00178 material_db->getElementBlockSublist(element_block_name,matName);
00179
00180
00181 std::string load_case = paramList.get<std::string>("Loading Case Name","uniaxial");
00182 int number_steps = paramList.get<int>("Number of Steps",10);
00183 double step_size = paramList.get<double>("Step Size",1.0e-2);
00184
00185
00186
00187 Teuchos::ParameterList cmpPL;
00188 paramList.set<Teuchos::RCP<std::map<std::string, std::string> > >("Name Map", fnm);
00189 cmpPL.set<Teuchos::ParameterList*>("Material Parameters", ¶mList);
00190 Teuchos::RCP<LCM::ConstitutiveModelParameters<Residual, Traits> > CMP =
00191 Teuchos::rcp(new LCM::ConstitutiveModelParameters<Residual, Traits>(cmpPL,dl));
00192 fieldManager.registerEvaluator<Residual>(CMP);
00193 stateFieldManager.registerEvaluator<Residual>(CMP);
00194
00195
00196
00197 Teuchos::ParameterList cmiPL;
00198 cmiPL.set<Teuchos::ParameterList*>("Material Parameters", ¶mList);
00199 Teuchos::RCP<LCM::ConstitutiveModelInterface<Residual, Traits> > CMI =
00200 Teuchos::rcp(new LCM::ConstitutiveModelInterface<Residual, Traits>(cmiPL,dl));
00201 fieldManager.registerEvaluator<Residual>(CMI);
00202 stateFieldManager.registerEvaluator<Residual>(CMI);
00203
00204
00205 for (std::vector<Teuchos::RCP<PHX::FieldTag> >::const_iterator it =
00206 CMI->evaluatedFields().begin();
00207 it != CMI->evaluatedFields().end(); ++it) {
00208 fieldManager.requireField<Residual>(**it);
00209 }
00210
00211
00212 Teuchos::RCP<Teuchos::ParameterList> p;
00213 Teuchos::RCP<PHX::Evaluator<Traits> > ev;
00214 for (int sv(0); sv < CMI->getNumStateVars(); ++sv) {
00215 CMI->fillStateVariableStruct(sv);
00216 p = stateMgr.registerStateVariable(CMI->getName(),
00217 CMI->getLayout(),
00218 dl->dummy,
00219 element_block_name,
00220 CMI->getInitType(),
00221 CMI->getInitValue(),
00222 CMI->getStateFlag(),
00223 CMI->getOutputFlag());
00224 ev = Teuchos::rcp(new PHAL::SaveStateField<Residual,Traits>(*p));
00225 fieldManager.registerEvaluator<Residual>(ev);
00226 stateFieldManager.registerEvaluator<Residual>(ev);
00227 }
00228
00229
00230
00231
00232
00233 bool check_stability;
00234 check_stability = paramList.get<bool>("Check Stability", false);
00235
00236 if (check_stability) {
00237 Teuchos::ParameterList bcPL;
00238 bcPL.set<Teuchos::ParameterList*>("Material Parameters", ¶mList);
00239 bcPL.set<std::string>("Material Tangent Name", "Material Tangent");
00240 bcPL.set<std::string>("Ellipticity Flag Name", "Ellipticity_Flag");
00241 bcPL.set<std::string>("Bifurcation Direction Name", "Direction");
00242 Teuchos::RCP<LCM::BifurcationCheck<Residual, Traits> > BC =
00243 Teuchos::rcp(new LCM::BifurcationCheck<Residual, Traits>(bcPL,dl));
00244 fieldManager.registerEvaluator<Residual>(BC);
00245 stateFieldManager.registerEvaluator<Residual>(BC);
00246
00247
00248 p = stateMgr.registerStateVariable("Ellipticity_Flag",
00249 dl->qp_scalar,
00250 dl->dummy,
00251 element_block_name,
00252 "scalar",
00253 0.0,
00254 false,
00255 true);
00256 ev = Teuchos::rcp(new PHAL::SaveStateField<Residual,Traits>(*p));
00257 fieldManager.registerEvaluator<Residual>(ev);
00258 stateFieldManager.registerEvaluator<Residual>(ev);
00259
00260
00261 p = stateMgr.registerStateVariable("Direction",
00262 dl->qp_vector,
00263 dl->dummy,
00264 element_block_name,
00265 "scalar",
00266 0.0,
00267 false,
00268 true);
00269 ev = Teuchos::rcp(new PHAL::SaveStateField<Residual,Traits>(*p));
00270 fieldManager.registerEvaluator<Residual>(ev);
00271 stateFieldManager.registerEvaluator<Residual>(ev);
00272 }
00273
00274
00275
00276 p = stateMgr.registerStateVariable("F",
00277 dl->qp_tensor,
00278 dl->dummy,
00279 element_block_name,
00280 "identity",
00281 1.0,
00282 false,
00283 true);
00284 ev = Teuchos::rcp(new PHAL::SaveStateField<Residual,Traits>(*p));
00285 fieldManager.registerEvaluator<Residual>(ev);
00286 stateFieldManager.registerEvaluator<Residual>(ev);
00287
00288
00289 Traits::SetupData setupData = "Test String";
00290 fieldManager.postRegistrationSetup(setupData);
00291
00292
00293 Teuchos::RCP<PHX::DataLayout> dummy =
00294 Teuchos::rcp(new PHX::MDALayout<Dummy>(0));
00295 std::vector<std::string> responseIDs =
00296 stateMgr.getResidResponseIDsToRequire(element_block_name);
00297 std::vector<std::string>::const_iterator it;
00298 for (it = responseIDs.begin(); it != responseIDs.end(); it++) {
00299 const std::string& responseID = *it;
00300 PHX::Tag<PHAL::AlbanyTraits::Residual::ScalarT>
00301 res_response_tag(responseID, dummy);
00302 stateFieldManager.requireField<PHAL::AlbanyTraits::Residual>(res_response_tag);
00303 }
00304 stateFieldManager.postRegistrationSetup("");
00305
00306 std::cout << "Process using 'dot -Tpng -O <name>'\n";
00307 fieldManager.writeGraphvizFile<Residual>("FM", true, true);
00308 stateFieldManager.writeGraphvizFile<Residual>("SFM", true, true);
00309
00310
00311 std::string output_file =
00312 paramList.get<std::string>("Output File Name","output.exo");
00313
00314
00315 Teuchos::RCP<Teuchos::ParameterList> discretizationParameterList =
00316 Teuchos::rcp(new Teuchos::ParameterList("Discretization"));
00317 discretizationParameterList->set<int>("1D Elements", workset_size);
00318 discretizationParameterList->set<int>("2D Elements", 1);
00319 discretizationParameterList->set<int>("3D Elements", 1);
00320 discretizationParameterList->set<std::string>("Method", "STK3D");
00321 discretizationParameterList->set<std::string>("Exodus Output File Name",
00322 output_file);
00323 Epetra_Map map(workset_size*num_dims*num_nodes, 0, *comm);
00324 Epetra_Vector solution_vector(map);
00325
00326 int numberOfEquations = 3;
00327 Albany::AbstractFieldContainer::FieldContainerRequirements req;
00328
00329 Teuchos::RCP<Albany::GenericSTKMeshStruct> stkMeshStruct = Teuchos::rcp(
00330 new Albany::TmplSTKMeshStruct<3>(discretizationParameterList, Teuchos::null, comm));
00331 stkMeshStruct->setFieldAndBulkData(comm, discretizationParameterList,
00332 numberOfEquations, req, stateMgr.getStateInfoStruct(),
00333 stkMeshStruct->getMeshSpecs()[0]->worksetSize);
00334
00335 Teuchos::RCP<Albany::AbstractDiscretization> discretization = Teuchos::rcp(
00336 new Albany::STKDiscretization(stkMeshStruct, comm));
00337
00338
00339 stateMgr.setStateArrays(discretization);
00340
00341
00342 PHAL::Workset workset;
00343 workset.numCells = workset_size;
00344 workset.stateArrayPtr = &stateMgr.getStateArray(Albany::StateManager::ELEM, 0);
00345
00346
00347 PHX::MDField<ScalarT,Cell,QuadPoint,Dim,Dim> stressField("Cauchy_Stress",dl->qp_tensor);
00348
00349
00350
00351
00352 for (int istep(0); istep <= number_steps; ++istep) {
00353
00354 std::cout << "****** in MPS step " << istep << " ****** " << std::endl;
00355
00356
00357 if (load_case == "uniaxial") {
00358 def_grad[0] = 1.0 + istep * step_size;
00359 } else if (load_case == "simple-shear") {
00360 def_grad[1] = istep * step_size;
00361 } else if (load_case == "hydrostatic") {
00362 def_grad[0] = 1.0 + istep * step_size;
00363 def_grad[4] = 1.0 + istep * step_size;
00364 def_grad[8] = 1.0 + istep * step_size;
00365 }
00366
00367
00368 Intrepid::Tensor<ScalarT> Ftensor(3, &def_grad[0]);
00369 detdefgrad[0] = Intrepid::det(Ftensor);
00370
00371
00372
00373 fieldManager.preEvaluate<Residual>(workset);
00374 fieldManager.evaluateFields<Residual>(workset);
00375 fieldManager.postEvaluate<Residual>(workset);
00376
00377 stateFieldManager.getFieldData<ScalarT,Residual,Cell,QuadPoint,Dim,Dim>(stressField);
00378
00379
00380
00381 for (size_type cell = 0; cell < workset_size; ++cell) {
00382 for (size_type qp = 0; qp < num_pts; ++qp) {
00383 std::cout << "in MPS Stress tensor at cell " << cell
00384 << ", quadrature point " << qp << ":" << std::endl;
00385 std::cout << " " << stressField(cell, qp, 0, 0);
00386 std::cout << " " << stressField(cell, qp, 0, 1);
00387 std::cout << " " << stressField(cell, qp, 0, 2) << std::endl;
00388 std::cout << " " << stressField(cell, qp, 1, 0);
00389 std::cout << " " << stressField(cell, qp, 1, 1);
00390 std::cout << " " << stressField(cell, qp, 1, 2) << std::endl;
00391 std::cout << " " << stressField(cell, qp, 2, 0);
00392 std::cout << " " << stressField(cell, qp, 2, 1);
00393 std::cout << " " << stressField(cell, qp, 2, 2) << std::endl;
00394
00395 std::cout << std::endl;
00396
00397 }
00398 }
00399
00400
00401 std::cout << "+++ calling the stateFieldManager\n";
00402 stateFieldManager.preEvaluate<Residual>(workset);
00403 stateFieldManager.evaluateFields<Residual>(workset);
00404 stateFieldManager.postEvaluate<Residual>(workset);
00405
00406 stateMgr.updateStates();
00407
00408
00409 discretization->writeSolution(solution_vector, Teuchos::as<double>(istep));
00410
00411 }
00412
00413 }