Peano
Loading...
Searching...
No Matches
ErrorMeasurement.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import exahype2.solvers.ErrorMeasurement
4from exahype2.solvers.ErrorMeasurement import (
5 create_finish_time_step_implementation_for_error_measurement,
6)
7
8from exahype2.solvers.PDETerms import PDETerms
9
10from exahype2.solvers.aderdg.GlobalFixedTimeStep import GlobalFixedTimeStep
11from exahype2.solvers.aderdg.GlobalAdaptiveTimeStep import GlobalAdaptiveTimeStep
12
13from exahype2.solvers.aderdg.actionsets import EmptyPostprocessSolution
14
15
16class ErrorMeasurement(exahype2.solvers.ErrorMeasurement):
18 self,
19 solver,
20 error_measurement_implementation=PDETerms.User_Defined_Implementation,
21 delta_between_database_flushes=0,
22 output_file_name="ADERDGErrorMeasurement",
23 data_delta_between_snapshots="1e+16",
24 time_delta_between_snapshots=0.0,
25 clear_database_after_flush=True,
26 ):
27 super(ErrorMeasurement, self).__init__(
28 solver=solver,
29 error_measurement_implementation=error_measurement_implementation,
30 delta_between_database_flushes=delta_between_database_flushes,
31 output_file_name=output_file_name,
32 data_delta_between_snapshots=data_delta_between_snapshots,
33 time_delta_between_snapshots=time_delta_between_snapshots,
34 clear_database_after_flush=clear_database_after_flush,
35 )
36
37 solver._finish_time_step_implementation += create_finish_time_step_implementation_for_error_measurement(
38 guard="_solverState == SolverState::GridInitialisation or _solverState == SolverState::TimeStep"
39 )
40
41 solver._action_set_postprocess_solution = EmptyPostprocessSolution(
42 solver=solver
43 )
44
45 if isinstance(solver, GlobalAdaptiveTimeStep):
46 solver._action_set_postprocess_solution._compute_kernel += (
48 )
49 elif isinstance(solver, GlobalFixedTimeStep):
50 solver._action_set_postprocess_solution._compute_kernel += (
52 )
53
54 solver._action_set_postprocess_solution.descend_invocation_order = 3
55
56
58 return """
59 if ((
60 repositories::{{SOLVER_INSTANCE}}.getSolverState() == {{SOLVER_NAME}}::SolverState::GridInitialisation
61 or
62 repositories::{{SOLVER_INSTANCE}}.isFirstGridSweepOfTimeStep())
63 and
64 not marker.willBeRefined() and not marker.hasBeenRefined()
65 ) {
66 double errors[3]{};
67
68 kernels::{{SOLVER_NAME}}::cellErrorIntegral(
69 [&](
70 const tarch::la::Vector<Dimensions, double>& x,
71 const double t,
72 const double dt,
73 const {{SOLUTION_STORAGE_PRECISION}}* Q_,
74 double* solution
75 )->void {
76 double Q[{{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}];
77 std::copy_n(Q_, {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}, Q);
78 repositories::{{SOLVER_INSTANCE}}.analyticalSolution(x, t, dt, Q, solution);
79 },
80 marker.x(),
81 marker.h(),
82 fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStamp(),
83 repositories::{{SOLVER_INSTANCE}}.getTimeStepSize(),
84 fineGridCell{{UNKNOWN_IDENTIFIER}}_old.value,
85 errors
86 );
87
88 repositories::{{SOLVER_INSTANCE}}.setError(errors);
89 }
90"""
91
92
94 return """
95 if ((
96 repositories::{{SOLVER_INSTANCE}}.getSolverState() == {{SOLVER_NAME}}::SolverState::GridInitialisation
97 or
98 repositories::{{SOLVER_INSTANCE}}.isFirstGridSweepOfTimeStep())
99 and
100 not marker.willBeRefined() and not marker.hasBeenRefined()
101 ) {
102 double errors[3]{};
103
104 kernels::{{SOLVER_NAME}}::cellErrorIntegral(
105 [&](
106 const tarch::la::Vector<Dimensions, double>& x,
107 const double t,
108 const double dt,
109 const {{SOLUTION_STORAGE_PRECISION}}* Q_,
110 double* solution
111 )->void {
112 double Q[{{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}];
113 std::copy_n(Q_, {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}, Q);
114 repositories::{{SOLVER_INSTANCE}}.analyticalSolution(x, t, dt, Q, solution);
115 },
116 marker.x(),
117 marker.h(),
118 fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStamp(),
119 repositories::{{SOLVER_INSTANCE}}.getAdmissibleTimeStepSize(),
120 fineGridCell{{UNKNOWN_IDENTIFIER}}_old.value,
121 errors
122 );
123
124 repositories::{{SOLVER_INSTANCE}}.setError(errors);
125 }
126"""
__init__(self, solver, error_measurement_implementation=PDETerms.User_Defined_Implementation, delta_between_database_flushes=0, output_file_name="ADERDGErrorMeasurement", data_delta_between_snapshots="1e+16", time_delta_between_snapshots=0.0, clear_database_after_flush=True)
create_postprocessing_kernel_for_error_measurement_for_fixed_timestepping()
create_postprocessing_kernel_for_error_measurement_for_adaptive_timestepping()