• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

LameUtils.cpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 #include "LameUtils.hpp"
00007 #include "Teuchos_TestForException.hpp"
00008 #include <string>
00009 #include <algorithm>
00010 
00011 // LAME material models
00012 #ifdef ALBANY_LAME
00013 #include "models/Elastic.h"
00014 #include "models/ElasticNew.h"
00015 #include "models/NeoHookean.h"
00016 #include "models/ElasticFracture.h"
00017 #include "models/ElasticPlastic.h"
00018 #include "models/EPPowerLaw.h"
00019 #include "models/DuctileFracture.h"
00020 #include "models/JohnsonCook.h"
00021 #include "models/PowerLawCreep.h"
00022 #include "models/FoamPlasticity.h"
00023 #include "models/LowDensityFoam.h"
00024 #include "models/StiffElastic.h"
00025 #include "models/FeFp.h"
00026 #include "models/CrystalPlasticity.h"
00027 #endif
00028 
00029 namespace LameUtils {
00030 
00031 Teuchos::RCP<LameMaterial> constructLameMaterialModel(const std::string lameMaterialModelName,
00032                   const Teuchos::ParameterList& lameMaterialParameters){
00033 
00034   // Strings should be all upper case with spaces replaced with underscores
00035   std::string materialModelName = lameMaterialModelName;
00036   std::transform(materialModelName.begin(), materialModelName.end(), materialModelName.begin(), 
00037     (int (*)(int))std::toupper);
00038   std::replace(materialModelName.begin(), materialModelName.end(), ' ', '_');
00039 
00040   LameMatProps props;
00041   parameterListToMatProps(lameMaterialParameters, props);
00042 
00043   Teuchos::RCP<LameMaterial> materialModel;
00044 
00045 #ifdef ALBANY_LAME
00046   if(materialModelName == "ELASTIC")
00047     materialModel = Teuchos::rcp(new lame::Elastic(props));
00048   else if(materialModelName == "ELASTIC_NEW")
00049     materialModel = Teuchos::rcp(new lame::ElasticNew(props));
00050   else if(materialModelName == "NEO_HOOKEAN")
00051     materialModel = Teuchos::rcp(new lame::NeoHookean(props));
00052   else if(materialModelName == "ELASTIC_FRACTURE")
00053     materialModel = Teuchos::rcp(new lame::ElasticFracture(props));
00054   else if(materialModelName == "ELASTIC_PLASTIC")
00055     materialModel = Teuchos::rcp(new lame::ElasticPlastic(props));
00056   else if(materialModelName == "EP_POWER_HARD")
00057     materialModel = Teuchos::rcp(new lame::EPPowerLaw(props));
00058   else if(materialModelName == "DUCTILE_FRACTURE")
00059     materialModel = Teuchos::rcp(new lame::DuctileFracture(props));
00060   else if(materialModelName == "JOHNSON_COOK")
00061     materialModel = Teuchos::rcp(new lame::JohnsonCook(props));
00062   else if(materialModelName == "POWER_LAW_CREEP")
00063     materialModel = Teuchos::rcp(new lame::PowerLawCreep(props));
00064   else if(materialModelName == "FOAM_PLASTICITY")
00065     materialModel = Teuchos::rcp(new lame::FoamPlasticity(props));
00066   else if(materialModelName == "LOW_DENSITY_FOAM")
00067     materialModel = Teuchos::rcp(new lame::LowDensityFoam(props));
00068   else if(materialModelName == "STIFF_ELASTIC")
00069     materialModel = Teuchos::rcp(new lame::StiffElastic(props));
00070   else if(materialModelName == "FEFP")
00071     materialModel = Teuchos::rcp(new lame::FeFp(props));
00072   else if(materialModelName == "CRYSTAL_PLASTICITY")
00073     materialModel = Teuchos::rcp(new lame::CrystalPlasticity(props));
00074   else
00075     TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, " unsupported LAME material model: " + lameMaterialModelName + " (" + materialModelName + ")\n");
00076 #endif
00077 
00078 #ifdef ALBANY_LAMENT
00079   if(materialModelName == "ELASTIC_NEW")
00080     materialModel = Teuchos::rcp(new lament::ElasticNew<double>(props));
00081   else if(materialModelName == "NEOHOOKEAN")
00082     materialModel = Teuchos::rcp(new lament::Neohookean<double>(props));
00083   else{
00084     if(materialModel.is_null())
00085       TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, " unsupported LAMENT material model: " + lameMaterialModelName + " (" + materialModelName + ")\n");
00086   }
00087 #endif
00088 
00089   return materialModel;
00090 }
00091 
00092 std::vector<std::string> getStateVariableNames(const std::string& lameMaterialModelName,
00093                                                const Teuchos::ParameterList& lameMaterialParameters){
00094 
00095   Teuchos::RCP<LameMaterial> materialModel = constructLameMaterialModel(lameMaterialModelName, lameMaterialParameters);
00096 
00097   // Get a list of the state variables, in alphabetical order
00098   std::vector<std::string> lameMaterialModelStateVariables;
00099   std::string tempLameMaterialModelName;
00100   materialModel->getStateVarListAndName(lameMaterialModelStateVariables, tempLameMaterialModelName);
00101 
00102   // Reorder the list to match the order of the variables in the actual state array passed to/from LAME
00103   std::map<int, std::string> variableNamesByIndex;
00104   for(unsigned int i=0 ; i<lameMaterialModelStateVariables.size() ; ++i){
00105     std::string variableName = lameMaterialModelStateVariables[i];
00106     int index = materialModel->getStateVariableIndex(variableName);
00107     variableNamesByIndex[index] = variableName;
00108   }
00109 
00110   std::vector<std::string> sortedVariableNames;
00111   for(unsigned int i=0 ; i<lameMaterialModelStateVariables.size() ; ++i){
00112     sortedVariableNames.push_back(variableNamesByIndex[(int)i]);
00113   }
00114 
00115   return sortedVariableNames;
00116 }
00117 
00118 
00119 std::vector<double> getStateVariableInitialValues(const std::string& lameMaterialModelName,
00120                                                   const Teuchos::ParameterList& lameMaterialParameters){
00121 
00122   Teuchos::RCP<LameMaterial> materialModel = constructLameMaterialModel(lameMaterialModelName, lameMaterialParameters);
00123 
00124   int numStateVariables = materialModel->getNumStateVars();
00125 
00126   // Allocate workset space
00127   std::vector<double> strainRate(6);   // symmetric tensor5
00128   std::vector<double> spin(3);         // skew-symmetric tensor
00129   std::vector<double> leftStretch(6);  // symmetric tensor
00130   std::vector<double> rotation(9);     // full tensor
00131   std::vector<double> stressOld(6);    // symmetric tensor
00132   std::vector<double> stressNew(6);    // symmetric tensor
00133   std::vector<double> stateOld(numStateVariables);  // a single double for each state variable
00134   std::vector<double> stateNew(numStateVariables);  // a single double for each state variable
00135 
00136   // \todo Set up scratch space for material models using getNumScratchVars() and setScratchPtr().
00137 
00138   // Create the matParams structure, which is passed to LAME
00139   Teuchos::RCP<LameMatParams> matp = Teuchos::rcp(new LameMatParams());
00140   matp->nelements = 1;
00141   matp->dt = 0.0;
00142   matp->time = 0.0;
00143   matp->strain_rate = &strainRate[0];
00144   matp->spin = &spin[0];
00145   matp->left_stretch = &leftStretch[0];
00146   matp->rotation = &rotation[0];
00147   matp->state_old = &stateOld[0];
00148   matp->state_new = &stateNew[0];
00149   matp->stress_old = &stressOld[0];
00150   matp->stress_new = &stressNew[0];
00151 
00152   LameMatProps props;
00153   parameterListToMatProps(lameMaterialParameters, props);
00154 
00155   // todo Check with Bill to see if props can be a null pointer (meaning no changes to the material properties).
00156 
00157   materialModel->initialize(matp.get(), &props);
00158 
00159   return stateOld;
00160 }
00161 
00162 }

Generated on Wed Mar 26 2014 18:36:39 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1