Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_ParameterListCallback.cpp
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 #include "PanzerAdaptersSTK_config.hpp"
44 #ifdef PANZER_HAVE_TEKO
45 
47 
48 namespace panzer_stk {
49 
50 using Teuchos::RCP;
51 using Teuchos::rcp;
52 
53 ParameterListCallback::ParameterListCallback(const std::string & coordFieldName,
54  const std::map<std::string,Teuchos::RCP<const panzer::Intrepid2FieldPattern> > & fps,
57  : coordFieldName_(coordFieldName), fieldPatterns_(fps), connManager_(connManager), ugi_(ugi), coordinatesBuilt_(false)
58 { }
59 
60 Teuchos::RCP<Teuchos::ParameterList> ParameterListCallback::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 bool ParameterListCallback::handlesRequest(const Teko::RequestMesg & rm)
75 {
76  // check if is a parameter list message, and that the parameter
77  // list contains the right fields
78  if(rm.getName()=="Parameter List") return true;
79  else return false;
80 }
81 
82 void ParameterListCallback::preRequest(const Teko::RequestMesg & rm)
83 {
84  TEUCHOS_ASSERT(handlesRequest(rm)); // design by contract
85 
86  // empty...nothing to do
87  buildArrayToVector();
88  buildCoordinates();
89 }
90 
91 void ParameterListCallback::setFieldByKey(const std::string & key,Teuchos::ParameterList & pl) const
92 {
93  TEUCHOS_TEST_FOR_EXCEPTION(!coordinatesBuilt_,std::runtime_error,
94  "ParameterListCallback::setFieldByKey: Coordinates have not been built!");
95 
96  double * x = const_cast<double *>(&xcoords_[0]);
97  double * y = const_cast<double *>(&ycoords_[0]);
98  double * z = const_cast<double *>(&zcoords_[0]);
99 
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);
106  else
107  TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,
108  "ParameterListCallback cannot handle key=\"" << key << "\"");
109 }
110 
111 void ParameterListCallback::buildArrayToVector()
112 {
113  if(arrayToVector_==Teuchos::null)
114  arrayToVector_ = Teuchos::rcp(new panzer::ArrayToFieldVector(ugi_));
115 }
116 
117 void ParameterListCallback::buildCoordinates()
118 {
119  TEUCHOS_ASSERT(fieldPatterns_.size()>0); // must be at least one field pattern
120 
121  std::map<std::string,Kokkos::DynRankView<double,PHX::Device> > data;
122 
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;
128 
129  // allocate block of data to store coordinates
130  Kokkos::DynRankView<double,PHX::Device> & fieldData = data[blockId];
131  fieldData = Kokkos::DynRankView<double,PHX::Device>("fieldData",connManager_->getElementBlock(blockId).size(),fieldPattern->numberIds());
132 
133  if(fieldPattern->supportsInterpolatoryCoordinates()) {
134  // get degree of freedom coordiantes
135  connManager_->getDofCoords(blockId,*fieldPattern,localCellIds,fieldData);
136  }
137  else {
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;
144 
145  coordinatesBuilt_ = true;
146  return;
147  }
148  }
149 
151  = arrayToVector_->template getDataVector<double>(coordFieldName_,data);
152 
153  switch(resultVec->getNumVectors()) {
154  case 3:
155  zcoords_.resize(resultVec->getLocalLength());
156  resultVec->getVector(2)->get1dCopy(Teuchos::arrayViewFromVector(zcoords_));
157  // Intentional fall-through.
158  case 2:
159  ycoords_.resize(resultVec->getLocalLength());
160  resultVec->getVector(1)->get1dCopy(Teuchos::arrayViewFromVector(ycoords_));
161  // Intentional fall-through.
162  case 1:
163  xcoords_.resize(resultVec->getLocalLength());
164  resultVec->getVector(0)->get1dCopy(Teuchos::arrayViewFromVector(xcoords_));
165  break;
166  default:
167  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
168  "ParameterListCallback::buildCoordinates: Constructed multivector has nonphysical dimensions.");
169  break;
170  }
171 
172  coordinatesBuilt_ = true;
173 }
174 
175 }
176 
177 #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)