43 #ifndef __Panzer_ReorderADValues_Evaluator_impl_hpp__
44 #define __Panzer_ReorderADValues_Evaluator_impl_hpp__
48 #include "Teuchos_Assert.hpp"
49 #include "Teuchos_FancyOStream.hpp"
53 #include "Phalanx_DataLayout.hpp"
55 template<
typename EvalT,
typename TRAITS>
58 const std::vector<std::string> & inFieldNames,
67 for (std::size_t eq = 0; eq < inFieldNames.size(); ++eq) {
68 inFields_.push_back(PHX::MDField<const ScalarT>(inFieldNames[eq],fieldLayouts[eq]));
69 outFields_.push_back(PHX::MDField<ScalarT>(outPrefix+inFieldNames[eq],fieldLayouts[eq]));
72 this->addDependentField(inFields_[eq]);
73 this->addEvaluatedField(outFields_[eq]);
76 this->setName(outPrefix+
" Reorder AD Values");
80 template<
typename EvalT,
typename TRAITS>
83 const std::vector<std::string> & inFieldNames,
84 const std::vector<std::string> & inDOFs,
85 const std::vector<std::string> & outDOFs,
95 for (std::size_t eq = 0; eq < inFieldNames.size(); ++eq) {
96 inFields_.push_back(PHX::MDField<const ScalarT>(inFieldNames[eq],fieldLayouts[eq]));
97 outFields_.push_back(PHX::MDField<ScalarT>(outPrefix+inFieldNames[eq],fieldLayouts[eq]));
100 this->addDependentField(inFields_[eq]);
101 this->addEvaluatedField(outFields_[eq]);
104 this->setName(
"Reorder AD Values");
108 template<
typename EvalT,
typename TRAITS>
116 for(std::size_t i = 0; i < inFields_.size(); ++i)
117 outFields_[i].deep_copy(inFields_[i]);
124 template<
typename TRAITS>
127 const std::vector<std::string> & inFieldNames,
129 const std::string & elementBlock,
138 for (std::size_t eq = 0; eq < inFieldNames.size(); ++eq) {
139 inFields_[eq] = PHX::MDField<const ScalarT>(inFieldNames[eq],fieldLayouts[eq]);
140 outFields_[eq] = PHX::MDField<ScalarT>(outPrefix+inFieldNames[eq],fieldLayouts[eq]);
144 this->addEvaluatedField(outFields_[eq]);
147 buildSrcToDestMap(elementBlock,
151 this->setName(outPrefix+
" Reorder AD Values");
156 template<
typename TRAITS>
159 const std::vector<std::string> & inFieldNames,
160 const std::vector<std::string> & inDOFs,
161 const std::vector<std::string> & outDOFs,
163 const std::string & elementBlock,
171 std::map<int,int> fieldNumberMaps;
172 for (std::size_t eq = 0; eq < inFieldNames.size(); ++eq) {
173 inFields_.push_back(PHX::MDField<const ScalarT>(inFieldNames[eq],fieldLayouts[eq]));
174 outFields_.push_back(PHX::MDField<ScalarT>(outPrefix+inFieldNames[eq],fieldLayouts[eq]));
177 this->addDependentField(inFields_[eq]);
178 this->addEvaluatedField(outFields_[eq]);
180 this->addUnsharedField(outFields_[eq].fieldTag().clone());
184 for(std::size_t i=0;i<inDOFs.size();i++) {
185 int srcFieldNum = indexerSrc.
getFieldNum(inDOFs[i]);
186 int dstFieldNum = indexerDest.
getFieldNum(outDOFs[i]);
190 fieldNumberMaps[srcFieldNum] = dstFieldNum;
193 buildSrcToDestMap(elementBlock,
198 this->setName(
"Reorder AD Values");
202 template<
typename TRAITS>
210 for(std::size_t fieldIndex = 0; fieldIndex < inFields_.size(); ++fieldIndex) {
212 const PHX::MDField<const ScalarT>& inField = inFields_[fieldIndex];
213 const PHX::MDField<ScalarT>& outField = outFields_[fieldIndex];
215 if(inField.size()>0) {
217 switch (inFields_[fieldIndex].rank()) {
219 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i) {
220 outField(i).val() = inField(i).val();
221 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
222 outField(i).fastAccessDx(dx) = inField(i).fastAccessDx(dstFromSrcMap_[dx]);
226 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
227 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j) {
228 outField(i,j).val() = inField(i,j).val();
229 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
230 outField(i,j).fastAccessDx(dx) = inField(i,j).fastAccessDx(dstFromSrcMap_[dx]);
234 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
235 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
236 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k) {
237 outField(i,j,k).val() = inField(i,j,k).val();
238 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
239 outField(i,j,k).fastAccessDx(dx) = inField(i,j,k).fastAccessDx(dstFromSrcMap_[dx]);
243 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
244 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
245 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
246 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l) {
247 outField(i,j,k,l).val() = inField(i,j,k,l).val();
248 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
249 outField(i,j,k,l).fastAccessDx(dx) = inField(i,j,k,l).fastAccessDx(dstFromSrcMap_[dx]);
253 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
254 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
255 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
256 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l)
257 for (
typename PHX::MDField<ScalarT>::size_type m = 0; m < inField.extent(4); ++m) {
258 outField(i,j,k,l,m).val() = inField(i,j,k,l,m).val();
259 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
260 outField(i,j,k,l,m).fastAccessDx(dx) = inField(i,j,k,l,m).fastAccessDx(dstFromSrcMap_[dx]);
264 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
265 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
266 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
267 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l)
268 for (
typename PHX::MDField<ScalarT>::size_type m = 0; m < inField.extent(4); ++m)
269 for (
typename PHX::MDField<ScalarT>::size_type n = 0; n < inField.extent(5); ++n) {
270 outField(i,j,k,l,m,n).val() = inField(i,j,k,l,m,n).val();
271 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
272 outField(i,j,k,l,m,n).fastAccessDx(dx) = inField(i,j,k,l,m,n).fastAccessDx(dstFromSrcMap_[dx]);
309 template<
typename TRAITS>
324 std::map<int,int> fieldNumberMaps;
325 for(std::size_t i=0;i<dstFieldsNum.size();i++) {
326 std::string fieldName = indexerDest.
getFieldString(dstFieldsNum[i]);
328 int srcFieldNum = indexerSrc.
getFieldNum(fieldName);
330 fieldNumberMaps[srcFieldNum] = dstFieldsNum[i];
332 out <<
"Warning: Reorder AD Values can't find field \"" << fieldName <<
"\"" << std::endl;
335 buildSrcToDestMap(elementBlock,fieldNumberMaps,indexerSrc,indexerDest);
339 template<
typename TRAITS>
342 const std::map<int,int> & fieldNumberMaps,
347 std::map<int,int> offsetMap;
348 for(std::map<int,int>::const_iterator itr=fieldNumberMaps.begin();
349 itr!=fieldNumberMaps.end();++itr) {
350 int srcField = itr->first;
351 int dstField = itr->second;
353 const std::vector<int> & srcOffsets = indexerSrc.
getGIDFieldOffsets(elementBlock,srcField);
354 const std::vector<int> & dstOffsets = indexerDest.
getGIDFieldOffsets(elementBlock,dstField);
358 for(std::size_t i=0;i<srcOffsets.size();i++) {
359 offsetMap[srcOffsets[i]] = dstOffsets[i];
363 maxDest = dstOffsets[i]>maxDest ? dstOffsets[i] : maxDest;
369 dstFromSrcMap_ = std::vector<int>(maxDest+1,-1);
370 for(std::map<int,int>::const_iterator itr=offsetMap.begin();
371 itr!=offsetMap.end();++itr) {
372 dstFromSrcMap_[itr->second] = itr->first;
virtual const std::string & getFieldString(int num) const =0
Reverse lookup of the field string from a field number.
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const =0
std::vector< PHX::MDField< ScalarT > > outFields_
void evaluateFields(typename TRAITS::EvalData d)
std::vector< PHX::MDField< const ScalarT > > inFields_
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Reorders the ad values of a specified field to match a different unique global indexer.
virtual const std::vector< int > & getGIDFieldOffsets(const std::string &blockId, int fieldNum) const =0
Use the field pattern so that you can find a particular field in the GIDs array.
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const =0
ReorderADValues_Evaluator(const std::string &outPrefix, const std::vector< std::string > &inFieldNames, const std::vector< Teuchos::RCP< PHX::DataLayout > > &fieldLayouts, const std::string &elementBlock, const GlobalIndexer &indexerSrc, const GlobalIndexer &indexerDest)
#define TEUCHOS_ASSERT(assertion_test)