Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_ScatterFields_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 #ifndef PANZER_STK_SCATTER_FIELDS_IMPL_HPP
44 #define PANZER_STK_SCATTER_FIELDS_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 
48 #include "Phalanx_config.hpp"
49 #include "Phalanx_Evaluator_Macros.hpp"
50 #include "Phalanx_MDField.hpp"
51 #include "Phalanx_DataLayout.hpp"
52 #include "Phalanx_DataLayout_MDALayout.hpp"
53 
54 #include "Panzer_BasisIRLayout.hpp"
55 #include "Panzer_Traits.hpp"
56 
57 #include "Teuchos_FancyOStream.hpp"
58 
59 namespace panzer_stk {
60 
61 template <typename EvalT,typename TraitsT>
63 ScatterFields(const std::string & scatterName,
64  const Teuchos::RCP<STK_Interface> mesh,
66  const std::vector<std::string> & names)
67 {
68  std::vector<double> scaling; // empty
69 
70  initialize(scatterName,mesh,basis,names,scaling);
71 }
72 
73 template <typename EvalT,typename TraitsT>
75 ScatterFields(const std::string & scatterName,
76  const Teuchos::RCP<STK_Interface> mesh,
78  const std::vector<std::string> & names,
79  const std::vector<double> & scaling)
80 {
81  initialize(scatterName,mesh,basis,names,scaling);
82 }
83 
84 template <typename EvalT,typename TraitsT>
86 initialize(const std::string & scatterName,
87  const Teuchos::RCP<STK_Interface> mesh,
89  const std::vector<std::string> & names,
90  const std::vector<double> & scaling)
91 {
92  using panzer::Cell;
93  using panzer::NODE;
94 
95  mesh_ = mesh;
96  scaling_ = scaling;
97 
98  bool correctScaling = (names.size()==scaling.size()) || (scaling.size()==0);
99  TEUCHOS_TEST_FOR_EXCEPTION(!correctScaling,std::invalid_argument,
100  "panzer_stk::ScatterFields evaluator requites a consistent number of scaling parameters (equal to the number of field names) "
101  "or an empty \"Field Scaling\" vector");
102 
103  // build dependent fields
104  scatterFields_.resize(names.size());
105  for (std::size_t fd = 0; fd < names.size(); ++fd) {
106  scatterFields_[fd] =
108  this->addDependentField(scatterFields_[fd]);
109  }
110 
111  // determine if this is a cell field or not
112  cellFields_ = basis->getElementSpace()==panzer::PureBasis::CONST;
113 
114  // setup a dummy field to evaluate
115  PHX::Tag<ScalarT> scatterHolder(scatterName,Teuchos::rcp(new PHX::MDALayout<panzer::Dummy>(0)));
116  this->addEvaluatedField(scatterHolder);
117 
118  this->setName(scatterName+": STK-Scatter Fields");
119 }
120 
121 template <typename EvalT,typename TraitsT>
123 postRegistrationSetup(typename TraitsT::SetupData /* d */,
124  PHX::FieldManager<TraitsT>& /* fm */)
125 {
126  for (std::size_t fd = 0; fd < scatterFields_.size(); ++fd)
127  std::string fieldName = scatterFields_[fd].fieldTag().name();
128 }
129 
130 template <typename EvalT,typename TraitsT>
132 evaluateFields(typename TraitsT::EvalData /* d */)
133 {
134  TEUCHOS_ASSERT(false);
135 }
136 
137 template < >
140 {
141  // for convenience pull out some objects from workset
142  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
143  std::string blockId = this->wda(workset).block_id;
144 
145  for(std::size_t fieldIndex=0; fieldIndex<scatterFields_.size();fieldIndex++) {
146  // scaline field value only if the scaling parameter is specified, otherwise use 1.0
147  double scaling = (scaling_.size()>0) ? scaling_[fieldIndex] : 1.0;
148 
149  // write field to the STK mesh object
150  if(!cellFields_)
151  mesh_->setSolutionFieldData(scatterFields_[fieldIndex].fieldTag().name(),blockId,
152  localCellIds,scatterFields_[fieldIndex].get_view(),scaling);
153  else
154  mesh_->setCellFieldData(scatterFields_[fieldIndex].fieldTag().name(),blockId,
155  localCellIds,scatterFields_[fieldIndex].get_view(),scaling);
156  }
157 }
158 
159 } // end panzer_stk
160 
161 #endif
void initialize(const std::string &scatterName, const Teuchos::RCP< STK_Interface > mesh, const Teuchos::RCP< const panzer::PureBasis > &basis, const std::vector< std::string > &names, const std::vector< double > &scaling)
EElementSpace getElementSpace() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void postRegistrationSetup(typename TraitsT::SetupData d, PHX::FieldManager< TraitsT > &fm)
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< PHX::DataLayout > functional
&lt;Cell,Basis&gt; or &lt;Cell,Basis&gt;
ScatterFields(const std::string &scatterName, const Teuchos::RCP< STK_Interface > mesh, const Teuchos::RCP< const panzer::PureBasis > &basis, const std::vector< std::string > &names)
void evaluateFields(typename TraitsT::EvalData d)