43 #ifndef PANZER_GLOBAL_STATISTICS_IMPL_HPP
44 #define PANZER_GLOBAL_STATISTICS_IMPL_HPP
46 #include "Intrepid2_FunctionSpaceTools.hpp"
52 #include "Phalanx_DataLayout_MDALayout.hpp"
54 #include "Teuchos_CommHelpers.hpp"
60 template<
typename EvalT,
typename Traits>
72 std::string names_string = p.
get<std::string>(
"Names");
73 std::vector<std::string> names;
79 for (
typename std::vector<std::string>::const_iterator name = names.begin(); name != names.end(); ++name)
80 field_values.push_back(PHX::MDField<const ScalarT,Cell,IP>(*name, ir->
dl_scalar));
83 volumes = PHX::MDField<ScalarT,Cell>(
"Cell Volumes",cell_dl);
85 tmp = PHX::MDField<ScalarT,Cell>(
"GlobalStatistics:tmp:"+names_string,cell_dl);
86 ones = PHX::MDField<ScalarT,Cell,IP>(
"GlobalStatistics:ones:"+names_string,ir->
dl_scalar);
88 this->addEvaluatedField(volumes);
89 this->addEvaluatedField(tmp);
90 this->addEvaluatedField(ones);
91 for (
typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::const_iterator
field = field_values.begin();
93 this->addDependentField(*
field);
96 averages.resize(field_values.size());
97 maxs.resize(field_values.size());
98 mins.resize(field_values.size());
99 global_maxs.resize(field_values.size());
100 global_mins.resize(field_values.size());
101 global_averages.resize(field_values.size());
105 std::string n =
"GlobalStatistics: " + names_string;
110 template<
typename EvalT,
typename Traits>
118 for (
typename PHX::MDField<ScalarT,Cell,IP>::size_type cell = 0; cell < ones.extent(0); ++cell)
119 for (
typename PHX::MDField<ScalarT,Cell,IP>::size_type ip = 0; ip < ones.extent(1); ++ip)
124 template<
typename EvalT,
typename Traits>
133 Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(volumes.get_view(),
135 (this->wda(workset).int_rules[ir_index])->weighted_measure.get_view());
137 for (index_t cell = 0; cell < workset.
num_cells; ++cell)
138 total_volume += volumes(cell);
140 typename std::vector<PHX::MDField<ScalarT,Cell,IP> >::size_type field_index = 0;
141 for (
typename std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator
field = field_values.begin();
142 field != field_values.end(); ++
field,++field_index) {
144 Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(tmp.get_view(),
146 (this->wda(workset).int_rules[ir_index])->weighted_measure.get_view());
148 for (index_t cell = 0; cell < workset.
num_cells; ++cell) {
149 averages[field_index] += tmp(cell);
151 for (
typename PHX::MDField<ScalarT,Cell,IP>::size_type ip = 0; ip < (
field->extent(1)); ++ip) {
152 maxs[field_index] = std::max( (*
field)(cell,ip), maxs[field_index]);
153 mins[field_index] = std::min( (*
field)(cell,ip), mins[field_index]);
161 template<
typename EvalT,
typename Traits>
169 for (
typename std::vector<ScalarT>::iterator
field = averages.begin();
field != averages.end(); ++
field)
172 for (
typename std::vector<ScalarT>::iterator
field = maxs.begin();
field != maxs.end(); ++
field)
175 for (
typename std::vector<ScalarT>::iterator
field = mins.begin();
field != mins.end(); ++
field)
180 template<
typename EvalT,
typename Traits>
186 this->postprocess(*(global_data->os));
190 template<
typename EvalT,
typename TRAITS>
206 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i)
207 global_averages[i] /= global_total_volume;
209 if (comm->getRank() == 0) {
213 std::size_t precision = 8;
214 os << std::scientific << std::showpoint << std::setprecision(precision) << std::left;
216 std::size_t name_width = 0;
217 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i)
218 name_width = std::max(name_width,field_values[i].fieldTag().name().size());
220 std::size_t value_width = precision + 7;
222 os << std::setw(name_width) <<
"Field"
223 <<
" " << std::setw(value_width) <<
"Average"
224 <<
" " << std::setw(value_width) <<
"Maximum (@IP)"
225 <<
" " << std::setw(value_width) <<
"Minimum (@IP)"
228 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i) {
229 os << std::setw(name_width) << field_values[i].fieldTag().name()
230 <<
" " << std::setw(value_width) << global_averages[i]
231 <<
" " << std::setw(value_width) << global_maxs[i]
232 <<
" " << std::setw(value_width) << global_mins[i] << std::endl;
240 template<
typename EvalT,
typename TRAITS>
243 return tmp.fieldTag();
const PHX::FieldTag & getRequiredFieldTag()
void evaluateFields(typename Traits::EvalData d)
void postprocess(std::ostream &os)
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::vector< std::string >::size_type getIntegrationRuleIndex(int ir_degree, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
GlobalStatistics(const Teuchos::ParameterList &p)
Teuchos::RCP< PHX::DataLayout > dl_scalar
Data layout for scalar fields.
void preEvaluate(typename Traits::PreEvalData d)
void postEvaluate(typename Traits::PostEvalData d)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_