43 #include "PanzerAdaptersSTK_config.hpp" 44 #ifdef PANZER_HAVE_TEKO 53 ParameterListCallback::ParameterListCallback(
const std::string & coordFieldName,
54 const std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> > & fps,
55 const Teuchos::RCP<const panzer_stk::STKConnManager> & connManager,
56 const Teuchos::RCP<const panzer::GlobalIndexer> & ugi)
57 : coordFieldName_(coordFieldName), fieldPatterns_(fps), connManager_(connManager), ugi_(ugi), coordinatesBuilt_(false)
60 Teuchos::RCP<Teuchos::ParameterList> ParameterListCallback::request(
const Teko::RequestMesg & rm)
62 TEUCHOS_ASSERT(handlesRequest(rm));
65 Teuchos::RCP<Teuchos::ParameterList> outputPL = rcp(
new Teuchos::ParameterList);
66 Teuchos::RCP<const Teuchos::ParameterList> inputPL = rm.getParameterList();
67 Teuchos::ParameterList::ConstIterator itr;
68 for(itr=inputPL->begin();itr!=inputPL->end();++itr)
69 setFieldByKey(itr->first,*outputPL);
74 bool ParameterListCallback::handlesRequest(
const Teko::RequestMesg & rm)
78 if(rm.getName()==
"Parameter List")
return true;
82 void ParameterListCallback::preRequest(
const Teko::RequestMesg & rm)
84 TEUCHOS_ASSERT(handlesRequest(rm));
91 void ParameterListCallback::setFieldByKey(
const std::string & key,Teuchos::ParameterList & pl)
const 93 TEUCHOS_TEST_FOR_EXCEPTION(!coordinatesBuilt_,std::runtime_error,
94 "ParameterListCallback::setFieldByKey: Coordinates have not been built!");
96 double * x =
const_cast<double *
>(&xcoords_[0]);
97 double * y =
const_cast<double *
>(&ycoords_[0]);
98 double * z =
const_cast<double *
>(&zcoords_[0]);
100 if(key==
"x-coordinates")
101 pl.set<
double*>(key,x);
102 else if(key==
"y-coordinates")
103 pl.set<
double*>(key,y);
104 else if(key==
"z-coordinates")
105 pl.set<
double*>(key,z);
107 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
108 "ParameterListCallback cannot handle key=\"" << key <<
"\"");
111 void ParameterListCallback::buildArrayToVector()
113 if(arrayToVector_==Teuchos::null)
117 void ParameterListCallback::buildCoordinates()
119 TEUCHOS_ASSERT(fieldPatterns_.size()>0);
121 std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
123 std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> >::const_iterator itr;
124 for(itr=fieldPatterns_.begin();itr!=fieldPatterns_.end();++itr) {
125 std::string blockId = itr->first;
126 Teuchos::RCP<const panzer::Intrepid2FieldPattern> fieldPattern = itr->second;
127 std::vector<std::size_t> localCellIds;
130 Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
131 fieldData = Kokkos::DynRankView<double,PHX::Device>(
"fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->numberIds());
133 if(fieldPattern->supportsInterpolatoryCoordinates()) {
135 connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
138 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
139 out.setOutputToRootOnly(-1);
140 out <<
"WARNING: In ParameterListCallback::buildCoordinates(), the Intrepid2::FieldPattern in " 141 <<
"block \"" << blockId <<
"\" does not support interpolatory coordinates. " 142 <<
"This may be fine if coordinates are not actually needed. However if they are then bad things " 143 <<
"will happen. Enjoy!" << std::endl;
145 coordinatesBuilt_ =
true;
150 Teuchos::RCP<Tpetra::MultiVector<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> > resultVec
151 = arrayToVector_->template getDataVector<double>(coordFieldName_,data);
153 switch(resultVec->getNumVectors()) {
155 zcoords_.resize(resultVec->getLocalLength());
156 resultVec->getVector(2)->get1dCopy(Teuchos::arrayViewFromVector(zcoords_));
159 ycoords_.resize(resultVec->getLocalLength());
160 resultVec->getVector(1)->get1dCopy(Teuchos::arrayViewFromVector(ycoords_));
163 xcoords_.resize(resultVec->getLocalLength());
164 resultVec->getVector(0)->get1dCopy(Teuchos::arrayViewFromVector(xcoords_));
167 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
168 "ParameterListCallback::buildCoordinates: Constructed multivector has nonphysical dimensions.");
172 coordinatesBuilt_ =
true;