Line data Source code
1 : // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 : // SPDX-License-Identifier: Apache-2.0
3 :
4 : #ifndef PALACE_FEM_ERROR_INDICATORS_HPP
5 : #define PALACE_FEM_ERROR_INDICATORS_HPP
6 :
7 : #include <array>
8 : #include <vector>
9 : #include "linalg/vector.hpp"
10 : #include "utils/communication.hpp"
11 :
12 : namespace palace
13 : {
14 :
15 : //
16 : // Storage for error estimation results from a simulation which involves one or more solves,
17 : // required in the AMR loop.
18 : //
19 0 : class ErrorIndicator
20 : {
21 : protected:
22 : // Elemental localized error indicators. Used for marking elements for
23 : // refinement and coarsening.
24 : Vector local;
25 :
26 : // Number of samples.
27 : int n;
28 :
29 : public:
30 : ErrorIndicator(Vector &&local) : local(std::move(local)), n(1)
31 : {
32 : this->local.UseDevice(true);
33 : }
34 0 : ErrorIndicator() : n(0) { local.UseDevice(true); }
35 :
36 : // Add an indicator to the running total.
37 : void AddIndicator(const Vector &indicator);
38 :
39 : // Return the local error indicator.
40 0 : const auto &Local() const { return local; }
41 :
42 : // Return the global error indicator.
43 0 : auto Norml2(MPI_Comm comm) const { return linalg::Norml2(comm, local); }
44 :
45 : // Return the largest local error indicator.
46 0 : auto Max(MPI_Comm comm) const
47 : {
48 0 : auto max = local.Max();
49 : Mpi::GlobalMax(1, &max, comm);
50 0 : return max;
51 : }
52 :
53 : // Return the smallest local error indicator.
54 0 : auto Min(MPI_Comm comm) const
55 : {
56 0 : auto min = local.Min();
57 : Mpi::GlobalMin(1, &min, comm);
58 0 : return min;
59 : }
60 :
61 : // Return the mean local error indicator.
62 0 : auto Mean(MPI_Comm comm) const { return linalg::Mean(comm, local); }
63 :
64 : struct SummaryStatistics
65 : {
66 : double norm;
67 : double min;
68 : double max;
69 : double mean;
70 : };
71 :
72 0 : SummaryStatistics GetSummaryStatistics(MPI_Comm comm) const
73 : {
74 0 : return {Norml2(comm), Min(comm), Max(comm), Mean(comm)};
75 : }
76 : };
77 :
78 : } // namespace palace
79 :
80 : #endif // PALACE_FEM_ERROR_INDICATORS_HPP
|