11 #ifndef PANZER_GLOBAL_STATISTICS_IMPL_HPP
12 #define PANZER_GLOBAL_STATISTICS_IMPL_HPP
14 #include "Intrepid2_FunctionSpaceTools.hpp"
20 #include "Phalanx_DataLayout_MDALayout.hpp"
22 #include "Teuchos_CommHelpers.hpp"
28 template<
typename EvalT,
typename Traits>
40 std::string names_string = p.
get<std::string>(
"Names");
41 std::vector<std::string> names;
47 for (
typename std::vector<std::string>::const_iterator name = names.begin(); name != names.end(); ++name)
56 this->addEvaluatedField(volumes);
57 this->addEvaluatedField(tmp);
58 this->addEvaluatedField(ones);
61 this->addDependentField(*
field);
64 averages.resize(field_values.size());
65 maxs.resize(field_values.size());
66 mins.resize(field_values.size());
67 global_maxs.resize(field_values.size());
68 global_mins.resize(field_values.size());
69 global_averages.resize(field_values.size());
73 std::string n =
"GlobalStatistics: " + names_string;
78 template<
typename EvalT,
typename Traits>
86 auto l_ones = ones.get_static_view();
87 Kokkos::parallel_for(
"GlobalStatistics", l_ones.extent(0), KOKKOS_LAMBDA(
int cell) {
88 for (std::size_t ip = 0; ip < l_ones.extent(1); ++ip)
89 l_ones(cell,ip) = 1.0;
94 template<
typename EvalT,
typename Traits>
103 Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(volumes.get_view(),
105 (this->wda(workset).int_rules[ir_index])->weighted_measure.get_view());
106 auto volumes_h = Kokkos::create_mirror_view(as_view(volumes));
107 Kokkos::deep_copy(volumes_h, as_view(volumes));
109 for (index_t cell = 0; cell < workset.
num_cells; ++cell)
110 total_volume += volumes_h(cell);
112 typename std::vector<PHX::MDField<ScalarT,Cell,IP> >::size_type field_index = 0;
114 field != field_values.end(); ++
field,++field_index) {
116 Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(tmp.get_view(),
118 (this->wda(workset).int_rules[ir_index])->weighted_measure.get_view());
119 auto tmp_h = Kokkos::create_mirror_view(tmp.get_static_view());
121 Kokkos::deep_copy(tmp_h, tmp.get_static_view());
125 for (index_t cell = 0; cell < workset.
num_cells; ++cell) {
126 averages[field_index] += tmp_h(cell);
129 maxs[field_index] = std::max( field_h(cell,ip), maxs[field_index]);
130 mins[field_index] = std::min( field_h(cell,ip), mins[field_index]);
138 template<
typename EvalT,
typename Traits>
146 for (
typename std::vector<ScalarT>::iterator
field = averages.begin();
field != averages.end(); ++
field)
149 for (
typename std::vector<ScalarT>::iterator
field = maxs.begin();
field != maxs.end(); ++
field)
152 for (
typename std::vector<ScalarT>::iterator
field = mins.begin();
field != mins.end(); ++
field)
157 template<
typename EvalT,
typename Traits>
163 this->postprocess(*(global_data->os));
167 template<
typename EvalT,
typename TRAITS>
178 Teuchos::reduceAll(*comm,
Teuchos::REDUCE_SUM, static_cast<int>(1), &total_volume, &global_total_volume);
179 Teuchos::reduceAll(*comm,
Teuchos::REDUCE_SUM, static_cast<int>(averages.size()), &averages[0], &global_averages[0]);
180 Teuchos::reduceAll(*comm,
Teuchos::REDUCE_MAX, static_cast<int>(maxs.size()), &maxs[0], &global_maxs[0]);
181 Teuchos::reduceAll(*comm,
Teuchos::REDUCE_MIN, static_cast<int>(mins.size()), &mins[0], &global_mins[0]);
183 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i)
184 global_averages[i] /= global_total_volume;
186 if (comm->getRank() == 0) {
190 std::size_t precision = 8;
191 os << std::scientific << std::showpoint << std::setprecision(precision) << std::left;
193 std::size_t name_width = 0;
194 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i)
195 name_width = std::max(name_width,field_values[i].fieldTag().name().size());
197 std::size_t value_width = precision + 7;
199 os << std::setw(name_width) <<
"Field"
200 <<
" " << std::setw(value_width) <<
"Average"
201 <<
" " << std::setw(value_width) <<
"Maximum (@IP)"
202 <<
" " << std::setw(value_width) <<
"Minimum (@IP)"
205 for (std::vector<ScalarT>::size_type i = 0; i < field_values.size(); ++i) {
206 os << std::setw(name_width) << field_values[i].fieldTag().name()
207 <<
" " << std::setw(value_width) << global_averages[i]
208 <<
" " << std::setw(value_width) << global_maxs[i]
209 <<
" " << std::setw(value_width) << global_mins[i] << std::endl;
217 template<
typename EvalT,
typename TRAITS>
220 return tmp.fieldTag();
const PHX::FieldTag & getRequiredFieldTag()
int num_cells
DEPRECATED - use: numCells()
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< int >::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)
KOKKOS_FORCEINLINE_FUNCTION array_type get_static_view()
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_