Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_ParameterListCallback_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifdef PANZER_HAVE_TEKO
44 
45 namespace panzer_stk {
46 
47 using Teuchos::RCP;
48 using Teuchos::rcp;
49 
50 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
51 ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::ParameterListCallback(
52  const std::string & coordFieldName,
53  const std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> > & fps,
54  const Teuchos::RCP<const panzer_stk::STKConnManager<GlobalOrdinalT> > & connManager,
56  : coordFieldName_(coordFieldName), fieldPatterns_(fps), connManager_(connManager), ugi_(ugi), coordinatesBuilt_(false)
57 { }
58 
59 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
60 Teuchos::RCP<Teuchos::ParameterList> ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::request(const Teko::RequestMesg & rm)
61 {
62  TEUCHOS_ASSERT(handlesRequest(rm)); // design by contract
63 
64  // loop over parameter list and set the field by a particular key
66  Teuchos::RCP<const Teuchos::ParameterList> inputPL = rm.getParameterList();
68  for(itr=inputPL->begin();itr!=inputPL->end();++itr)
69  setFieldByKey(itr->first,*outputPL);
70 
71  return outputPL;
72 }
73 
74 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
75 bool ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::handlesRequest(const Teko::RequestMesg & rm)
76 {
77  // check if is a parameter list message, and that the parameter
78  // list contains the right fields
79  if(rm.getName()=="Parameter List") return true;
80  else return false;
81 }
82 
83 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
84 void ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::preRequest(const Teko::RequestMesg & rm)
85 {
86  TEUCHOS_ASSERT(handlesRequest(rm)); // design by contract
87 
88  // empty...nothing to do
89  buildArrayToVector();
90  buildCoordinates();
91 }
92 
93 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
94 void ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::setFieldByKey(const std::string & key,Teuchos::ParameterList & pl) const
95 {
96  TEUCHOS_TEST_FOR_EXCEPTION(!coordinatesBuilt_,std::runtime_error,
97  "ParameterListCallback::setFieldByKey: Coordinates have not been built!");
98 
99  double * x = const_cast<double *>(&xcoords_[0]);
100  double * y = const_cast<double *>(&ycoords_[0]);
101  double * z = const_cast<double *>(&zcoords_[0]);
102 
103  if(key=="x-coordinates")
104  pl.set<double*>(key,x);
105  else if(key=="y-coordinates")
106  pl.set<double*>(key,y);
107  else if(key=="z-coordinates")
108  pl.set<double*>(key,z);
109  else
110  TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,
111  "ParameterListCallback cannot handle key=\"" << key << "\"");
112 }
113 
114 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
115 void ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::buildArrayToVector()
116 {
117  if(arrayToVector_==Teuchos::null)
119 }
120 
121 template <typename LocalOrdinalT,typename GlobalOrdinalT,typename Node>
122 void ParameterListCallback<LocalOrdinalT,GlobalOrdinalT,Node>::buildCoordinates()
123 {
124  TEUCHOS_ASSERT(fieldPatterns_.size()>0); // must be at least one field pattern
125 
126  std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
127 
128  std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> >::const_iterator itr;
129  for(itr=fieldPatterns_.begin();itr!=fieldPatterns_.end();++itr) {
130  std::string blockId = itr->first;
131  Teuchos::RCP<const panzer::Intrepid2FieldPattern> fieldPattern = itr->second;
132  std::vector<std::size_t> localCellIds;
133 
134  // allocate block of data to store coordinates
135  Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
136  fieldData = Kokkos::DynRankView<double,PHX::Device>("fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->numberIds());
137 
138  if(fieldPattern->supportsInterpolatoryCoordinates()) {
139  // get degree of freedom coordiantes
140  connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
141  }
142  else {
143  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
144  out.setOutputToRootOnly(-1);
145  out << "WARNING: In ParameterListCallback::buildCoordinates(), the Intrepid2::FieldPattern in "
146  << "block \"" << blockId << "\" does not support interpolatory coordinates. "
147  << "This may be fine if coordinates are not actually needed. However if they are then bad things "
148  << "will happen. Enjoy!" << std::endl;
149 
150  coordinatesBuilt_ = true;
151  return;
152  }
153  }
154 
156  = arrayToVector_->template getDataVector<double>(coordFieldName_,data);
157 
158  switch(resultVec->getNumVectors()) {
159  case 3:
160  zcoords_.resize(resultVec->getLocalLength());
161  resultVec->getVector(2)->get1dCopy(Teuchos::arrayViewFromVector(zcoords_));
162  // Intentional fall-through.
163  case 2:
164  ycoords_.resize(resultVec->getLocalLength());
165  resultVec->getVector(1)->get1dCopy(Teuchos::arrayViewFromVector(ycoords_));
166  // Intentional fall-through.
167  case 1:
168  xcoords_.resize(resultVec->getLocalLength());
169  resultVec->getVector(0)->get1dCopy(Teuchos::arrayViewFromVector(xcoords_));
170  break;
171  default:
172  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
173  "ParameterListCallback::buildCoordinates: Constructed multivector has nonphysical dimensions.");
174  break;
175  }
176 
177  coordinatesBuilt_ = true;
178 }
179 
180 }
181 
182 #endif
ConstIterator end() const
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)
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
#define TEUCHOS_ASSERT(assertion_test)