Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_ParameterListCallback.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#include "PanzerAdaptersSTK_config.hpp"
12#ifdef PANZER_HAVE_TEKO
13
15
16namespace panzer_stk {
17
18using Teuchos::RCP;
19using Teuchos::rcp;
20
21ParameterListCallback::ParameterListCallback(const std::string & coordFieldName,
22 const std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> > & fps,
23 const Teuchos::RCP<const panzer_stk::STKConnManager> & connManager,
24 const Teuchos::RCP<const panzer::GlobalIndexer> & ugi)
25 : coordFieldName_(coordFieldName), fieldPatterns_(fps), connManager_(connManager), ugi_(ugi), coordinatesBuilt_(false)
26{ }
27
28Teuchos::RCP<Teuchos::ParameterList> ParameterListCallback::request(const Teko::RequestMesg & rm)
29{
30 TEUCHOS_ASSERT(handlesRequest(rm)); // design by contract
31
32 // loop over parameter list and set the field by a particular key
33 Teuchos::RCP<Teuchos::ParameterList> outputPL = rcp(new Teuchos::ParameterList);
34 Teuchos::RCP<const Teuchos::ParameterList> inputPL = rm.getParameterList();
35 Teuchos::ParameterList::ConstIterator itr;
36 for(itr=inputPL->begin();itr!=inputPL->end();++itr)
37 setFieldByKey(itr->first,*outputPL);
38
39 return outputPL;
40}
41
42bool ParameterListCallback::handlesRequest(const Teko::RequestMesg & rm)
43{
44 // check if is a parameter list message, and that the parameter
45 // list contains the right fields
46 if(rm.getName()=="Parameter List") return true;
47 else return false;
48}
49
50void ParameterListCallback::preRequest(const Teko::RequestMesg & rm)
51{
52 TEUCHOS_ASSERT(handlesRequest(rm)); // design by contract
53
54 // empty...nothing to do
55 buildArrayToVector();
56 buildCoordinates();
57}
58
59void ParameterListCallback::setFieldByKey(const std::string & key,Teuchos::ParameterList & pl) const
60{
61 TEUCHOS_TEST_FOR_EXCEPTION(!coordinatesBuilt_,std::runtime_error,
62 "ParameterListCallback::setFieldByKey: Coordinates have not been built!");
63
64 double * x = const_cast<double *>(&xcoords_[0]);
65 double * y = const_cast<double *>(&ycoords_[0]);
66 double * z = const_cast<double *>(&zcoords_[0]);
67
68 if(key=="x-coordinates")
69 pl.set<double*>(key,x);
70 else if(key=="y-coordinates")
71 pl.set<double*>(key,y);
72 else if(key=="z-coordinates")
73 pl.set<double*>(key,z);
74 else
75 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,
76 "ParameterListCallback cannot handle key=\"" << key << "\"");
77}
78
79void ParameterListCallback::buildArrayToVector()
80{
81 if(arrayToVector_==Teuchos::null)
82 arrayToVector_ = Teuchos::rcp(new panzer::ArrayToFieldVector(ugi_));
83}
84
85void ParameterListCallback::buildCoordinates()
86{
87 TEUCHOS_ASSERT(fieldPatterns_.size()>0); // must be at least one field pattern
88
89 std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
90
91 std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> >::const_iterator itr;
92 for(itr=fieldPatterns_.begin();itr!=fieldPatterns_.end();++itr) {
93 std::string blockId = itr->first;
94 Teuchos::RCP<const panzer::Intrepid2FieldPattern> fieldPattern = itr->second;
95 std::vector<std::size_t> localCellIds;
96
97 // allocate block of data to store coordinates
98 Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
99 fieldData = Kokkos::DynRankView<double,PHX::Device>("fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->numberIds());
100
101 if(fieldPattern->supportsInterpolatoryCoordinates()) {
102 // get degree of freedom coordiantes
103 connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
104 }
105 else {
106 Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
107 out.setOutputToRootOnly(-1);
108 out << "WARNING: In ParameterListCallback::buildCoordinates(), the Intrepid2::FieldPattern in "
109 << "block \"" << blockId << "\" does not support interpolatory coordinates. "
110 << "This may be fine if coordinates are not actually needed. However if they are then bad things "
111 << "will happen. Enjoy!" << std::endl;
112
113 coordinatesBuilt_ = true;
114 return;
115 }
116 }
117
118 Teuchos::RCP<Tpetra::MultiVector<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> > resultVec
119 = arrayToVector_->template getDataVector<double>(coordFieldName_,data);
120
121 switch(resultVec->getNumVectors()) {
122 case 3:
123 zcoords_.resize(resultVec->getLocalLength());
124 resultVec->getVector(2)->get1dCopy(Teuchos::arrayViewFromVector(zcoords_));
125 // Intentional fall-through.
126 case 2:
127 ycoords_.resize(resultVec->getLocalLength());
128 resultVec->getVector(1)->get1dCopy(Teuchos::arrayViewFromVector(ycoords_));
129 // Intentional fall-through.
130 case 1:
131 xcoords_.resize(resultVec->getLocalLength());
132 resultVec->getVector(0)->get1dCopy(Teuchos::arrayViewFromVector(xcoords_));
133 break;
134 default:
135 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
136 "ParameterListCallback::buildCoordinates: Constructed multivector has nonphysical dimensions.");
137 break;
138 }
139
140 coordinatesBuilt_ = true;
141}
142
143}
144
145#endif