Panzer
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
disc-fe
src
evaluators
Panzer_GlobalStatistics_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_GLOBAL_STATISTICS_IMPL_HPP
44
#define PANZER_GLOBAL_STATISTICS_IMPL_HPP
45
46
#include "Intrepid2_FunctionSpaceTools.hpp"
47
#include "
Panzer_IntegrationRule.hpp
"
48
#include "
Panzer_String_Utilities.hpp
"
49
#include "
Panzer_Workset_Utilities.hpp
"
50
#include "
Panzer_GlobalData.hpp
"
51
#include "
Panzer_IosAllSaver.hpp
"
52
#include "Phalanx_DataLayout_MDALayout.hpp"
53
#include "Teuchos_ScalarTraits.hpp"
54
#include "Teuchos_CommHelpers.hpp"
55
#include <iomanip>
56
57
namespace
panzer
{
58
59
//**********************************************************************
60
template
<
typename
EvalT,
typename
Traits>
61
GlobalStatistics<EvalT, Traits>::
62
GlobalStatistics
(
63
const
Teuchos::ParameterList& p)
64
{
65
comm
= p.get< Teuchos::RCP<const Teuchos::Comm<int> > >(
"Comm"
);
66
67
global_data
= p.get<Teuchos::RCP<panzer::GlobalData> >(
"Global Data"
);
68
69
// Expects a string that is a Colon separated list of field names to compute statistics on.
70
// for example the string "UX:UY:UZ:PRESSURE" would be separated into a vector with
71
// four fields, "UX", "UY", "UZ", and "PRESSURE".
72
std::string names_string = p.get<std::string>(
"Names"
);
73
std::vector<std::string> names;
74
panzer::StringTokenizer
(names, names_string);
75
76
Teuchos::RCP<panzer::IntegrationRule> ir = p.get< Teuchos::RCP<panzer::IntegrationRule> >(
"IR"
);
77
78
field_values
.clear();
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));
81
82
Teuchos::RCP<PHX::MDALayout<Cell> > cell_dl = Teuchos::rcp(
new
PHX::MDALayout<Cell>(ir->dl_scalar->extent(0)));
83
volumes
= PHX::MDField<ScalarT,Cell>(
"Cell Volumes"
,cell_dl);
84
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);
87
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();
92
field !=
field_values
.end(); ++field) {
93
this->addDependentField(*field);
94
}
95
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());
102
103
ir_order
= ir->cubature_degree;
104
105
std::string n =
"GlobalStatistics: "
+ names_string;
106
this->setName(n);
107
}
108
109
//**********************************************************************
110
template
<
typename
EvalT,
typename
Traits>
111
void
112
GlobalStatistics<EvalT, Traits>::
113
postRegistrationSetup
(
114
typename
Traits::SetupData
sd,
115
PHX::FieldManager<Traits>
&
/* fm */
)
116
{
117
ir_index
=
panzer::getIntegrationRuleIndex
(
ir_order
,(*sd.
worksets_
)[0], this->wda);
118
auto
l_ones =
ones
.get_static_view();
119
Kokkos::parallel_for(
"GlobalStatistics"
, l_ones.extent(0), KOKKOS_LAMBDA(
int
cell) {
120
for
(std::size_t ip = 0; ip < l_ones.extent(1); ++ip)
121
l_ones(cell,ip) = 1.0;
122
});
123
}
124
125
//**********************************************************************
126
template
<
typename
EvalT,
typename
Traits>
127
void
128
GlobalStatistics<EvalT, Traits>::
129
evaluateFields
(
130
typename
Traits::EvalData
workset)
131
{
132
if
(workset.
num_cells
== 0)
133
return
;
134
135
Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(
volumes
.get_view(),
136
ones
.get_view(),
137
(this->wda(workset).int_rules[
ir_index
])->weighted_measure.get_view());
138
auto
volumes_h = Kokkos::create_mirror_view(as_view(
volumes
));
139
Kokkos::deep_copy(volumes_h, as_view(
volumes
));
140
141
for
(index_t cell = 0; cell < workset.
num_cells
; ++cell)
142
total_volume
+= volumes_h(cell);
143
144
typename
std::vector<PHX::MDField<ScalarT,Cell,IP> >
::size_type
field_index = 0;
145
for
(
typename
std::vector<PHX::MDField<const ScalarT,Cell,IP> >::iterator field =
field_values
.begin();
146
field !=
field_values
.end(); ++field,++field_index) {
147
148
Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::integrate(
tmp
.get_view(),
149
field->get_view(),
150
(this->wda(workset).int_rules[
ir_index
])->weighted_measure.get_view());
151
auto
tmp_h = Kokkos::create_mirror_view(
tmp
.get_static_view());
152
auto
field_h = Kokkos::create_mirror_view( field->get_static_view());
153
Kokkos::deep_copy(tmp_h,
tmp
.get_static_view());
154
Kokkos::deep_copy(field_h, field->get_static_view());
155
156
157
for
(index_t cell = 0; cell < workset.
num_cells
; ++cell) {
158
averages
[field_index] += tmp_h(cell);
159
160
for
(
typename
PHX::MDField<ScalarT,Cell,IP>::size_type ip = 0; ip < (field->extent(1)); ++ip) {
161
maxs
[field_index] = std::max( field_h(cell,ip),
maxs
[field_index]);
162
mins
[field_index] = std::min( field_h(cell,ip),
mins
[field_index]);
163
}
164
}
165
166
}
167
}
168
169
//**********************************************************************
170
template
<
typename
EvalT,
typename
Traits>
171
void
172
GlobalStatistics<EvalT, Traits>::
173
preEvaluate
(
174
typename
Traits::PreEvalData
/* data */
)
175
{
176
total_volume
= Teuchos::ScalarTraits<ScalarT>::zero();
177
178
for
(
typename
std::vector<ScalarT>::iterator field =
averages
.begin(); field !=
averages
.end(); ++field)
179
*field = Teuchos::ScalarTraits<ScalarT>::zero();
180
181
for
(
typename
std::vector<ScalarT>::iterator field =
maxs
.begin(); field !=
maxs
.end(); ++field)
182
*field = Teuchos::ScalarTraits<ScalarT>::rmin();
183
184
for
(
typename
std::vector<ScalarT>::iterator field =
mins
.begin(); field !=
mins
.end(); ++field)
185
*field = Teuchos::ScalarTraits<ScalarT>::rmax();
186
}
187
188
//**********************************************************************
189
template
<
typename
EvalT,
typename
Traits>
190
void
191
GlobalStatistics<EvalT, Traits>::
192
postEvaluate
(
193
typename
Traits::PostEvalData
/* data */
)
194
{
195
this->
postprocess
(*(
global_data
->os));
196
}
197
198
//**********************************************************************
199
template
<
typename
EvalT,
typename
TRAITS>
200
void
GlobalStatistics<EvalT, TRAITS>::postprocess
(std::ostream&
/* os */
)
201
{
202
// throw unless specialized for residual evaluations
203
TEUCHOS_TEST_FOR_EXCEPTION(
true
,std::logic_error,
"SHOULD NEVER BE CALLED!"
);
204
}
205
206
//**********************************************************************
207
template
<>
208
void
GlobalStatistics<panzer::Traits::Residual, panzer::Traits>::postprocess
(std::ostream& os)
209
{
210
Teuchos::reduceAll(*
comm
, Teuchos::REDUCE_SUM,
static_cast<
int
>
(1), &
total_volume
, &
global_total_volume
);
211
Teuchos::reduceAll(*
comm
, Teuchos::REDUCE_SUM,
static_cast<
int
>
(
averages
.size()), &
averages
[0], &
global_averages
[0]);
212
Teuchos::reduceAll(*
comm
, Teuchos::REDUCE_MAX,
static_cast<
int
>
(
maxs
.size()), &
maxs
[0], &
global_maxs
[0]);
213
Teuchos::reduceAll(*
comm
, Teuchos::REDUCE_MIN,
static_cast<
int
>
(
mins
.size()), &
mins
[0], &
global_mins
[0]);
214
215
for
(std::vector<ScalarT>::size_type i = 0; i <
field_values
.size(); ++i)
216
global_averages
[i] /=
global_total_volume
;
217
218
if
(
comm
->getRank() == 0) {
219
220
panzer::ios_all_saver
saver(os);
221
222
std::size_t precision = 8;
223
os << std::scientific << std::showpoint << std::setprecision(precision) << std::left;
224
225
std::size_t name_width = 0;
226
for
(std::vector<ScalarT>::size_type i = 0; i <
field_values
.size(); ++i)
227
name_width = std::max(name_width,
field_values
[i].fieldTag().name().size());
228
229
std::size_t value_width = precision + 7;
230
231
os << std::setw(name_width) <<
"Field"
232
<<
" "
<< std::setw(value_width) <<
"Average"
233
<<
" "
<< std::setw(value_width) <<
"Maximum (@IP)"
234
<<
" "
<< std::setw(value_width) <<
"Minimum (@IP)"
235
<< std::endl;
236
237
for
(std::vector<ScalarT>::size_type i = 0; i <
field_values
.size(); ++i) {
238
os << std::setw(name_width) <<
field_values
[i].fieldTag().name()
239
<<
" "
<< std::setw(value_width) <<
global_averages
[i]
240
<<
" "
<< std::setw(value_width) <<
global_maxs
[i]
241
<<
" "
<< std::setw(value_width) <<
global_mins
[i] << std::endl;
242
}
243
244
}
245
246
}
247
248
//**********************************************************************
249
template
<
typename
EvalT,
typename
TRAITS>
250
const
PHX::FieldTag&
GlobalStatistics<EvalT, TRAITS>::getRequiredFieldTag
()
251
{
252
return
tmp
.fieldTag();
253
}
254
255
256
}
// namespace panzer
257
258
259
260
#endif
261
Panzer_GlobalData.hpp
Panzer_IntegrationRule.hpp
Panzer_IosAllSaver.hpp
Panzer_String_Utilities.hpp
Panzer_Workset_Utilities.hpp
PHX::FieldManager
Definition
Panzer_BCStrategy_Base.hpp:53
panzer::GlobalStatistics::maxs
std::vector< ScalarT > maxs
Definition
Panzer_GlobalStatistics_decl.hpp:102
panzer::GlobalStatistics::mins
std::vector< ScalarT > mins
Definition
Panzer_GlobalStatistics_decl.hpp:103
panzer::GlobalStatistics::GlobalStatistics
GlobalStatistics(const Teuchos::ParameterList &p)
Definition
Panzer_GlobalStatistics_impl.hpp:62
panzer::GlobalStatistics::ir_order
int ir_order
Definition
Panzer_GlobalStatistics_decl.hpp:109
panzer::GlobalStatistics::postprocess
void postprocess(std::ostream &os)
Definition
Panzer_GlobalStatistics_impl.hpp:200
panzer::GlobalStatistics::field_values
std::vector< PHX::MDField< const ScalarT, Cell, IP > > field_values
Definition
Panzer_GlobalStatistics_decl.hpp:98
panzer::GlobalStatistics::postEvaluate
void postEvaluate(typename Traits::PostEvalData d)
Definition
Panzer_GlobalStatistics_impl.hpp:192
panzer::GlobalStatistics::ones
PHX::MDField< ScalarT, Cell, IP > ones
Definition
Panzer_GlobalStatistics_decl.hpp:96
panzer::GlobalStatistics::tmp
PHX::MDField< ScalarT, Cell > tmp
Definition
Panzer_GlobalStatistics_decl.hpp:94
panzer::GlobalStatistics::comm
Teuchos::RCP< const Teuchos::Comm< int > > comm
Definition
Panzer_GlobalStatistics_decl.hpp:112
panzer::GlobalStatistics::global_mins
std::vector< ScalarT > global_mins
Definition
Panzer_GlobalStatistics_decl.hpp:107
panzer::GlobalStatistics::postRegistrationSetup
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Definition
Panzer_GlobalStatistics_impl.hpp:113
panzer::GlobalStatistics::global_data
Teuchos::RCP< panzer::GlobalData > global_data
Definition
Panzer_GlobalStatistics_decl.hpp:114
panzer::GlobalStatistics::global_total_volume
ScalarT global_total_volume
Definition
Panzer_GlobalStatistics_decl.hpp:104
panzer::GlobalStatistics::global_averages
std::vector< ScalarT > global_averages
Definition
Panzer_GlobalStatistics_decl.hpp:105
panzer::GlobalStatistics::ir_index
std::size_t ir_index
Definition
Panzer_GlobalStatistics_decl.hpp:110
panzer::GlobalStatistics::volumes
PHX::MDField< ScalarT, Cell > volumes
Definition
Panzer_GlobalStatistics_decl.hpp:92
panzer::GlobalStatistics::total_volume
ScalarT total_volume
Definition
Panzer_GlobalStatistics_decl.hpp:100
panzer::GlobalStatistics::global_maxs
std::vector< ScalarT > global_maxs
Definition
Panzer_GlobalStatistics_decl.hpp:106
panzer::GlobalStatistics::averages
std::vector< ScalarT > averages
Definition
Panzer_GlobalStatistics_decl.hpp:101
panzer::GlobalStatistics::getRequiredFieldTag
const PHX::FieldTag & getRequiredFieldTag()
Definition
Panzer_GlobalStatistics_impl.hpp:250
panzer::GlobalStatistics::preEvaluate
void preEvaluate(typename Traits::PreEvalData d)
Definition
Panzer_GlobalStatistics_impl.hpp:173
panzer::GlobalStatistics::evaluateFields
void evaluateFields(typename Traits::EvalData d)
Definition
Panzer_GlobalStatistics_impl.hpp:129
panzer::WorksetDetails::num_cells
int num_cells
DEPRECATED - use: numCells().
Definition
Panzer_Workset.hpp:116
panzer
Computes .
Definition
Panzer_BasisValues_Evaluator_decl.hpp:54
panzer::ios_all_saver
basic_ios_all_saver< char > ios_all_saver
Definition
Panzer_IosAllSaver.hpp:70
panzer::StringTokenizer
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.
Definition
Panzer_String_Utilities.cpp:65
panzer::getIntegrationRuleIndex
std::vector< int >::size_type getIntegrationRuleIndex(int ir_degree, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
Definition
Panzer_Workset_Utilities.cpp:97
panzer::size_type
panzer::Traits::SD::worksets_
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_
Definition
Panzer_Traits.hpp:124
panzer::Traits::PreEvalData
const PED & PreEvalData
Definition
Panzer_Traits.hpp:137
panzer::Traits::PostEvalData
void * PostEvalData
Definition
Panzer_Traits.hpp:139
panzer::Traits::EvalData
const panzer::Workset & EvalData
Definition
Panzer_Traits.hpp:129
panzer::Traits::SetupData
const SD & SetupData
Definition
Panzer_Traits.hpp:127
Generated by
1.17.0