43 #include "PanzerAdaptersSTK_config.hpp"
44 #ifdef PANZER_HAVE_TEKO
48 namespace panzer_stk {
53 ParameterListCallbackBlocked::ParameterListCallbackBlocked(
57 : connManager_(connManager), blocked_ugi_(blocked_ugi), aux_blocked_ugi_(aux_blocked_ugi)
61 ParameterListCallbackBlocked::request(
const Teko::RequestMesg & rm)
69 for(itr=inputPL->
begin();itr!=inputPL->
end();++itr) {
70 std::string * str_ptr = 0;
72 setFieldByKey(itr->first,field,*outputPL);
78 bool ParameterListCallbackBlocked::handlesRequest(
const Teko::RequestMesg & rm)
82 if(rm.getName()==
"Parameter List") {
83 bool isHandled =
true;
86 if(pl->
isType<std::string>(
"x-coordinates")) {
87 field = pl->
get<std::string>(
"x-coordinates");
92 if(pl->
isType<std::string>(
"y-coordinates")) {
94 if(field != pl->
get<std::string>(
"y-coordinates")) {
98 if(pl->
isType<std::string>(
"z-coordinates")) {
100 if(field != pl->
get<std::string>(
"z-coordinates")) {
104 if(pl->
isType<std::string>(
"Coordinates")){
105 field = pl->
get<std::string>(
"Coordinates");
107 if(pl->
isType<std::string>(
"Coordinates-Epetra")){
108 field = pl->
get<std::string>(
"Coordinates-Epetra");
116 void ParameterListCallbackBlocked::preRequest(
const Teko::RequestMesg & rm)
120 const std::string&
field(getHandledField(*rm.getParameterList()));
125 std::vector<Teuchos::RCP<panzer::GlobalIndexer>>
126 fieldDOFMngrs = blocked_ugi_->getFieldDOFManagers();
127 for (
int b(0); b < static_cast<int>(fieldDOFMngrs.size()); ++b)
129 for (
int f(0); f < fieldDOFMngrs[b]->getNumFields(); ++f)
131 if (fieldDOFMngrs[b]->getFieldString(f) ==
field)
139 aux_blocked_ugi_->getFieldBlock(aux_blocked_ugi_->getFieldNum(field));
141 block = blocked_ugi_->getFieldBlock(blocked_ugi_->getFieldNum(field));
144 if (rm.getParameterList()->isType<std::string>(
"Coordinates-Epetra")) {
145 buildArrayToVectorEpetra(block, field, useAux);
146 buildCoordinatesEpetra(field, useAux);
148 buildArrayToVectorTpetra(block, field, useAux);
149 buildCoordinatesTpetra(field, useAux);
153 void ParameterListCallbackBlocked::setFieldByKey(
const std::string & key,
const std::string & field,
Teuchos::ParameterList & pl)
const
156 if(key==
"x-coordinates") {
157 double * x =
const_cast<double *
>(&getCoordinateByField(0,field)[0]);
158 pl.
set<
double*>(key,x);
160 else if(key==
"y-coordinates") {
161 double * y =
const_cast<double *
>(&getCoordinateByField(1,field)[0]);
162 pl.
set<
double*>(key,y);
164 else if(key==
"z-coordinates") {
165 double * z =
const_cast<double *
>(&getCoordinateByField(2,field)[0]);
166 pl.
set<
double*>(key,z);
167 }
else if(key ==
"Coordinates") {
169 }
else if(key ==
"Coordinates-Epetra") {
175 "ParameterListCallback cannot handle key=\"" << key <<
"\"");
178 void ParameterListCallbackBlocked::buildArrayToVectorTpetra(
int block,
const std::string & field,
const bool useAux)
180 if(arrayToVectorTpetra_[field]==Teuchos::null) {
183 ugi = aux_blocked_ugi_->getFieldDOFManagers()[block];
185 ugi = blocked_ugi_->getFieldDOFManagers()[block];
190 void ParameterListCallbackBlocked::buildArrayToVectorEpetra(
int block,
const std::string & field,
const bool useAux)
192 if(arrayToVectorEpetra_[field]==Teuchos::null) {
195 ugi = aux_blocked_ugi_->getFieldDOFManagers()[block];
197 ugi = blocked_ugi_->getFieldDOFManagers()[block];
202 void ParameterListCallbackBlocked::buildCoordinatesTpetra(
const std::string & field,
const bool useAux)
204 std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
208 std::vector<std::string> elementBlocks;
210 aux_blocked_ugi_->getElementBlockIds(elementBlocks);
212 blocked_ugi_->getElementBlockIds(elementBlocks);
213 for(std::size_t i=0;i<elementBlocks.size();++i) {
214 std::string blockId = elementBlocks[i];
215 std::vector<std::size_t> localCellIds;
218 Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
219 fieldData = Kokkos::DynRankView<double,PHX::Device>(
"fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->
numberIds());
223 connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
227 out.setOutputToRootOnly(-1);
228 out <<
"WARNING: In ParameterListCallback::buildCoordinates(), the Intrepid2::FieldPattern in "
229 <<
"block \"" << blockId <<
"\" does not support interpolatory coordinates. "
230 <<
"This may be fine if coordinates are not actually needed. However if they are then bad things "
231 <<
"will happen. Enjoy!" << std::endl;
237 coordsVecTp_ = arrayToVectorTpetra_[
field]->template getDataVector<double>(
field,data);
239 switch(coordsVecTp_->getNumVectors()) {
241 zcoords_[
field].resize(coordsVecTp_->getLocalLength());
242 coordsVecTp_->getVector(2)->get1dCopy(Teuchos::arrayViewFromVector(zcoords_[field]));
245 ycoords_[
field].resize(coordsVecTp_->getLocalLength());
246 coordsVecTp_->getVector(1)->get1dCopy(Teuchos::arrayViewFromVector(ycoords_[field]));
249 xcoords_[
field].resize(coordsVecTp_->getLocalLength());
250 coordsVecTp_->getVector(0)->get1dCopy(Teuchos::arrayViewFromVector(xcoords_[field]));
254 "ParameterListCallback::buildCoordinates: Constructed multivector has nonphysical dimensions.");
259 void ParameterListCallbackBlocked::buildCoordinatesEpetra(
const std::string & field,
const bool useAux)
261 std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
265 std::vector<std::string> elementBlocks;
267 aux_blocked_ugi_->getElementBlockIds(elementBlocks);
269 blocked_ugi_->getElementBlockIds(elementBlocks);
270 for(std::size_t i=0;i<elementBlocks.size();++i) {
271 std::string blockId = elementBlocks[i];
272 std::vector<std::size_t> localCellIds;
275 Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
276 fieldData = Kokkos::DynRankView<double,PHX::Device>(
"fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->
numberIds());
280 connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
284 out.setOutputToRootOnly(-1);
285 out <<
"WARNING: In ParameterListCallback::buildCoordinates(), the Intrepid2::FieldPattern in "
286 <<
"block \"" << blockId <<
"\" does not support interpolatory coordinates. "
287 <<
"This may be fine if coordinates are not actually needed. However if they are then bad things "
288 <<
"will happen. Enjoy!" << std::endl;
294 coordsVecEp_ = arrayToVectorEpetra_[
field]->template getDataVector<double>(
field,data);
297 std::string ParameterListCallbackBlocked::
301 if(pl.
isType<std::string>(
"x-coordinates"))
302 return pl.
get<std::string>(
"x-coordinates");
303 else if(pl.
isType<std::string>(
"Coordinates"))
304 return pl.
get<std::string>(
"Coordinates");
305 else if(pl.
isType<std::string>(
"Coordinates-Epetra"))
306 return pl.
get<std::string>(
"Coordinates-Epetra");
308 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Neither x-coordinates nor Coordinates or Coordinates-Epetra field provided.");
312 const std::vector<double> & ParameterListCallbackBlocked::
313 getCoordinateByField(
int dim,
const std::string & field)
const
319 const std::map<std::string,std::vector<double> > * coord =
nullptr;
320 if(dim==0) coord = &xcoords_;
321 else if(dim==1) coord = &ycoords_;
322 else if(dim==2) coord = &zcoords_;
325 "ParameterListCallbackBlocked::getCoordinateByField: dim is not in range of [0,2] for field \""
329 std::map<std::string,std::vector<double> >::const_iterator itr;
330 itr = coord->find(field);
333 "ParameterListCallbackBlocked::getCoordinateByField: Coordinates for field \"" + field +
334 "\" dimension " << dim <<
" have not been built!");
340 ::getFieldPattern(
const std::string & fieldName,
const bool useAux)
const
342 std::vector<std::string> elementBlocks;
344 aux_blocked_ugi_->getElementBlockIds(elementBlocks);
346 blocked_ugi_->getElementBlockIds(elementBlocks);
348 for(std::size_t e=0;e<elementBlocks.size();e++) {
349 std::string blockId = elementBlocks[e];
351 if(blocked_ugi_->fieldInBlock(fieldName,blockId))
352 return Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(blocked_ugi_->getFieldPattern(blockId,fieldName),
true);
354 if(aux_blocked_ugi_->fieldInBlock(fieldName,blockId))
355 return Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(aux_blocked_ugi_->getFieldPattern(blockId,fieldName),
true);
358 return Teuchos::null;
ConstIterator end() const
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T & getValue(T *ptr) const
virtual int numberIds() const
bool supportsInterpolatoryCoordinates() const
Does this field pattern support interpolatory coordinates?
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
params_t::ConstIterator ConstIterator
ConstIterator begin() const
const ParameterEntry & entry(ConstIterator i) const
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
bool isType(const std::string &name) const
#define TEUCHOS_ASSERT(assertion_test)