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]);
182 for(std::size_t i=0;i<inDOFs.size();i++) {
183 int srcFieldNum = indexerSrc.
getFieldNum(inDOFs[i]);
184 int dstFieldNum = indexerDest.
getFieldNum(outDOFs[i]);
188 fieldNumberMaps[srcFieldNum] = dstFieldNum;
191 buildSrcToDestMap(elementBlock,
196 this->setName(
"Reorder AD Values");
200 template<
typename TRAITS>
208 for(std::size_t fieldIndex = 0; fieldIndex < inFields_.size(); ++fieldIndex) {
210 const PHX::MDField<const ScalarT>& inField = inFields_[fieldIndex];
211 const PHX::MDField<ScalarT>& outField = outFields_[fieldIndex];
213 if(inField.size()>0) {
215 switch (inFields_[fieldIndex].rank()) {
217 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i) {
218 outField(i).val() = inField(i).val();
219 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
220 outField(i).fastAccessDx(dx) = inField(i).fastAccessDx(dstFromSrcMap_[dx]);
224 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
225 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j) {
226 outField(i,j).val() = inField(i,j).val();
227 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
228 outField(i,j).fastAccessDx(dx) = inField(i,j).fastAccessDx(dstFromSrcMap_[dx]);
232 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
233 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
234 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k) {
235 outField(i,j,k).val() = inField(i,j,k).val();
236 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
237 outField(i,j,k).fastAccessDx(dx) = inField(i,j,k).fastAccessDx(dstFromSrcMap_[dx]);
241 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
242 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
243 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
244 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l) {
245 outField(i,j,k,l).val() = inField(i,j,k,l).val();
246 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
247 outField(i,j,k,l).fastAccessDx(dx) = inField(i,j,k,l).fastAccessDx(dstFromSrcMap_[dx]);
251 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
252 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
253 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
254 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l)
255 for (
typename PHX::MDField<ScalarT>::size_type m = 0; m < inField.extent(4); ++m) {
256 outField(i,j,k,l,m).val() = inField(i,j,k,l,m).val();
257 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
258 outField(i,j,k,l,m).fastAccessDx(dx) = inField(i,j,k,l,m).fastAccessDx(dstFromSrcMap_[dx]);
262 for (
typename PHX::MDField<ScalarT>::size_type i = 0; i < inField.extent(0); ++i)
263 for (
typename PHX::MDField<ScalarT>::size_type j = 0; j < inField.extent(1); ++j)
264 for (
typename PHX::MDField<ScalarT>::size_type k = 0; k < inField.extent(2); ++k)
265 for (
typename PHX::MDField<ScalarT>::size_type l = 0; l < inField.extent(3); ++l)
266 for (
typename PHX::MDField<ScalarT>::size_type m = 0; m < inField.extent(4); ++m)
267 for (
typename PHX::MDField<ScalarT>::size_type n = 0; n < inField.extent(5); ++n) {
268 outField(i,j,k,l,m,n).val() = inField(i,j,k,l,m,n).val();
269 for (
typename PHX::MDField<ScalarT>::size_type dx = 0; dx < Teuchos::as<typename PHX::MDField<ScalarT>::size_type>(dstFromSrcMap_.size()); ++dx)
270 outField(i,j,k,l,m,n).fastAccessDx(dx) = inField(i,j,k,l,m,n).fastAccessDx(dstFromSrcMap_[dx]);
307 template<
typename TRAITS>
322 std::map<int,int> fieldNumberMaps;
323 for(std::size_t i=0;i<dstFieldsNum.size();i++) {
324 std::string fieldName = indexerDest.
getFieldString(dstFieldsNum[i]);
326 int srcFieldNum = indexerSrc.
getFieldNum(fieldName);
328 fieldNumberMaps[srcFieldNum] = dstFieldsNum[i];
330 out <<
"Warning: Reorder AD Values can't find field \"" << fieldName <<
"\"" << std::endl;
333 buildSrcToDestMap(elementBlock,fieldNumberMaps,indexerSrc,indexerDest);
337 template<
typename TRAITS>
340 const std::map<int,int> & fieldNumberMaps,
345 std::map<int,int> offsetMap;
346 for(std::map<int,int>::const_iterator itr=fieldNumberMaps.begin();
347 itr!=fieldNumberMaps.end();++itr) {
348 int srcField = itr->first;
349 int dstField = itr->second;
351 const std::vector<int> & srcOffsets = indexerSrc.
getGIDFieldOffsets(elementBlock,srcField);
352 const std::vector<int> & dstOffsets = indexerDest.
getGIDFieldOffsets(elementBlock,dstField);
356 for(std::size_t i=0;i<srcOffsets.size();i++) {
357 offsetMap[srcOffsets[i]] = dstOffsets[i];
361 maxDest = dstOffsets[i]>maxDest ? dstOffsets[i] : maxDest;
367 dstFromSrcMap_ = std::vector<int>(maxDest+1,-1);
368 for(std::map<int,int>::const_iterator itr=offsetMap.begin();
369 itr!=offsetMap.end();++itr) {
370 dstFromSrcMap_[itr->second] = itr->first;
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.
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 UniqueGlobalIndexerBase &indexerSrc, const UniqueGlobalIndexerBase &indexerDest)
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_
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const =0
Reorders the ad values of a specified field to match a different unique global indexer.
virtual const std::string & getFieldString(int num) const =0
Reverse lookup of the field string from a field number.
#define TEUCHOS_ASSERT(assertion_test)
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.