Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009 #include "Intrepid_FunctionSpaceTools.hpp"
00010 #include "LCM/evaluators/SetField.hpp"
00011
00012 namespace LCM {
00013
00014 template<typename EvalT, typename Traits>
00015 SetField<EvalT, Traits>::
00016 SetField(const Teuchos::ParameterList& p) :
00017 evaluatedFieldName( p.get<std::string>("Evaluated Field Name") ),
00018 evaluatedField( p.get<std::string>("Evaluated Field Name"), p.get<Teuchos::RCP<PHX::DataLayout> >("Evaluated Field Data Layout") ),
00019 fieldValues( p.get<Teuchos::ArrayRCP<ScalarT> >("Field Values"))
00020 {
00021
00022 p.get<Teuchos::RCP<PHX::DataLayout> >("Evaluated Field Data Layout")->dimensions(evaluatedFieldDimensions);
00023
00024
00025 this->addEvaluatedField(evaluatedField);
00026 this->setName("SetField" + PHX::TypeString<EvalT>::value);
00027 }
00028
00029 template<typename EvalT, typename Traits>
00030 void SetField<EvalT, Traits>::
00031 postRegistrationSetup(typename Traits::SetupData d,
00032 PHX::FieldManager<Traits>& fm)
00033 {
00034 this->utils.setFieldData(evaluatedField, fm);
00035 }
00036
00037 template<typename EvalT, typename Traits>
00038 void SetField<EvalT, Traits>::
00039 evaluateFields(typename Traits::EvalData workset)
00040 {
00041 unsigned int numDimensions = evaluatedFieldDimensions.size();
00042
00043 TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions < 2, "SetField::evaluateFields(), unsupported field type.");
00044 int dim1 = evaluatedFieldDimensions[0];
00045 int dim2 = evaluatedFieldDimensions[1];
00046
00047 if(numDimensions == 2){
00048 TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2, "SetField::evaluateFields(), inconsistent data sizes.");
00049 for(int i=0 ; i<dim1 ; ++i){
00050 for(int j=0 ; j<dim2 ; ++j){
00051 evaluatedField(i,j) = fieldValues[i*dim2 + j];
00052 }
00053 }
00054 }
00055 else if(numDimensions == 3){
00056 int dim3 = evaluatedFieldDimensions[2];
00057 TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3, "SetField::evaluateFields(), inconsistent data sizes.");
00058 for(int i=0 ; i<dim1 ; ++i){
00059 for(int j=0 ; j<dim2 ; ++j){
00060 for(int m=0 ; m<dim3 ; ++m){
00061 evaluatedField(i,j,m) = fieldValues[i*dim2*dim3 + j*dim3 + m];
00062 }
00063 }
00064 }
00065 }
00066 else if(numDimensions == 4){
00067 int dim3 = evaluatedFieldDimensions[2];
00068 int dim4 = evaluatedFieldDimensions[3];
00069 TEUCHOS_TEST_FOR_EXCEPT_MSG(fieldValues.size() != dim1*dim2*dim3*dim4, "SetField::evaluateFields(), inconsistent data sizes.");
00070 for(int i=0 ; i<dim1 ; ++i){
00071 for(int j=0 ; j<dim2 ; ++j){
00072 for(int m=0 ; m<dim3 ; ++m){
00073 for(int n=0 ; n<dim4 ; ++n){
00074 evaluatedField(i,j,m,n) = fieldValues[i*dim2*dim3*dim4 + j*dim3*dim4 + m*dim4 + n];
00075 }
00076 }
00077 }
00078 }
00079 }
00080 else{
00081 TEUCHOS_TEST_FOR_EXCEPT_MSG(numDimensions > 4, "SetField::evaluateFields(), unsupported data type.");
00082 }
00083 }
00084
00085 }
00086