Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <vector>
00008 #include <string>
00009
00010 #include "Teuchos_TestForException.hpp"
00011 #include "Phalanx_DataLayout.hpp"
00012
00013 namespace PHAL {
00014
00015 template<typename EvalT, typename Traits>
00016 SaveStateField<EvalT, Traits>::
00017 SaveStateField(const Teuchos::ParameterList& p)
00018 {
00019
00020 this->setName("Save State Field"+PHX::TypeString<EvalT>::value);
00021 }
00022
00023
00024 template<typename EvalT, typename Traits>
00025 void SaveStateField<EvalT, Traits>::postRegistrationSetup(typename Traits::SetupData d,
00026 PHX::FieldManager<Traits>& fm)
00027 {
00028
00029 }
00030
00031
00032 template<typename EvalT, typename Traits>
00033 void SaveStateField<EvalT, Traits>::evaluateFields(typename Traits::EvalData workset)
00034 {
00035
00036 }
00037
00038
00039 template<typename Traits>
00040 SaveStateField<PHAL::AlbanyTraits::Residual, Traits>::
00041 SaveStateField(const Teuchos::ParameterList& p)
00042 {
00043 fieldName = p.get<std::string>("Field Name");
00044 stateName = p.get<std::string>("State Name");
00045 PHX::MDField<ScalarT> f(fieldName, p.get<Teuchos::RCP<PHX::DataLayout> >("State Field Layout") );
00046 field = f;
00047
00048 savestate_operation = Teuchos::rcp(new PHX::Tag<ScalarT>
00049 (fieldName, p.get< Teuchos::RCP<PHX::DataLayout> >("Dummy Data Layout")));
00050
00051 this->addDependentField(field);
00052 this->addEvaluatedField(*savestate_operation);
00053
00054 this->setName("Save Field " + fieldName +" to State " + stateName
00055 + PHX::TypeString<PHAL::AlbanyTraits::Residual>::value);
00056 }
00057
00058
00059 template<typename Traits>
00060 void SaveStateField<PHAL::AlbanyTraits::Residual, Traits>::
00061 postRegistrationSetup(typename Traits::SetupData d,
00062 PHX::FieldManager<Traits>& fm)
00063 {
00064 this->utils.setFieldData(field,fm);
00065 }
00066
00067 template<typename Traits>
00068 void SaveStateField<PHAL::AlbanyTraits::Residual, Traits>::
00069 evaluateFields(typename Traits::EvalData workset)
00070 {
00071
00072
00073 Albany::StateArray::const_iterator it;
00074 it = workset.stateArrayPtr->find(stateName);
00075
00076 TEUCHOS_TEST_FOR_EXCEPTION((it == workset.stateArrayPtr->end()), std::logic_error,
00077 std::endl << "Error: cannot locate " << stateName << " in PHAL_SaveStateField_Def" << std::endl);
00078
00079 Albany::MDArray sta = it->second;
00080 std::vector<int> dims;
00081 sta.dimensions(dims);
00082 int size = dims.size();
00083
00084 switch (size) {
00085 case 1:
00086 sta(0) = field(0);
00087 break;
00088 case 2:
00089 for (int cell = 0; cell < dims[0]; ++cell)
00090 for (int qp = 0; qp < dims[1]; ++qp)
00091 sta(cell, qp) = field(cell,qp);;
00092 break;
00093 case 3:
00094 for (int cell = 0; cell < dims[0]; ++cell)
00095 for (int qp = 0; qp < dims[1]; ++qp)
00096 for (int i = 0; i < dims[2]; ++i)
00097 sta(cell, qp, i) = field(cell,qp,i);
00098 break;
00099 case 4:
00100 for (int cell = 0; cell < dims[0]; ++cell)
00101 for (int qp = 0; qp < dims[1]; ++qp)
00102 for (int i = 0; i < dims[2]; ++i)
00103 for (int j = 0; j < dims[3]; ++j)
00104 sta(cell, qp, i, j) = field(cell,qp,i,j);
00105 break;
00106 default:
00107 TEUCHOS_TEST_FOR_EXCEPT_MSG(size<1||size>4,
00108 "Unexpected Array dimensions in SaveStateField: " << size);
00109 }
00110 }
00111
00112 }