Panzer  Version of the Day
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_ConfigDefs.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,
65  const Teuchos::RCP<const panzer::PureBasis> & basis,
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,
77  const Teuchos::RCP<const panzer::PureBasis> & basis,
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,
88  const Teuchos::RCP<const panzer::PureBasis> & basis,
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] =
107  PHX::MDField<const ScalarT,Cell,NODE>(names[fd],basis->functional);
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,
125 {
126  for (std::size_t fd = 0; fd < scatterFields_.size(); ++fd) {
127  std::string fieldName = scatterFields_[fd].fieldTag().name();
128 
129  // setup the field data object
130  this->utils.setFieldData(scatterFields_[fd],fm);
131  }
132 }
133 
134 template <typename EvalT,typename TraitsT>
136 evaluateFields(typename TraitsT::EvalData d)
137 {
138  TEUCHOS_ASSERT(false);
139 }
140 
141 template < >
144 {
145  // for convenience pull out some objects from workset
146  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
147  std::string blockId = this->wda(workset).block_id;
148 
149  for(std::size_t fieldIndex=0; fieldIndex<scatterFields_.size();fieldIndex++) {
150  // scaline field value only if the scaling parameter is specified, otherwise use 1.0
151  double scaling = (scaling_.size()>0) ? scaling_[fieldIndex] : 1.0;
152 
153  // write field to the STK mesh object
154  if(!cellFields_)
155  mesh_->setSolutionFieldData(scatterFields_[fieldIndex].fieldTag().name(),blockId,
156  localCellIds,scatterFields_[fieldIndex],scaling);
157  else
158  mesh_->setCellFieldData(scatterFields_[fieldIndex].fieldTag().name(),blockId,
159  localCellIds,scatterFields_[fieldIndex],scaling);
160  }
161 }
162 
163 } // end panzer_stk
164 
165 #endif
std::vector< PHX::MDField< const ScalarT, panzer::Cell, panzer::Point > > scatterFields_
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)
void initialize(const Teuchos::RCP< const panzer::PointRule > &pointRule, const Teuchos::RCP< const panzer::PureBasis > &basis, bool derivativesRequired)
Initialization method to unify the constructors.
Teuchos::RCP< STK_Interface > mesh_
void postRegistrationSetup(typename TraitsT::SetupData d, PHX::FieldManager< TraitsT > &fm)
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
ScatterFields(const std::string &scatterName, const Teuchos::RCP< STK_Interface > mesh, const Teuchos::RCP< const panzer::PureBasis > &basis, const std::vector< std::string > &names)
std::vector< double > scaling_
void evaluateFields(typename TraitsT::EvalData d)