Line data Source code
1 : /*
2 : * SPDX-FileCopyrightText: Copyright (c) 2014: G-CSC, Goethe University Frankfurt
3 : * SPDX-License-Identifier: LicenseRef-UG4-LGPL-3.0
4 : *
5 : * Author: Arne Naegel, Andreas Kreienbuehl
6 : *
7 : * This file is part of UG4.
8 : *
9 : * UG4 is free software: you can redistribute it and/or modify it under the
10 : * terms of the GNU Lesser General Public License version 3 (as published by the
11 : * Free Software Foundation) with the following additional attribution
12 : * requirements (according to LGPL/GPL v3 §7):
13 : *
14 : * (1) The following notice must be displayed in the Appropriate Legal Notices
15 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
16 : *
17 : * (2) The following notice must be displayed at a prominent place in the
18 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
19 : *
20 : * (3) The following bibliography is recommended for citation and must be
21 : * preserved in all covered files:
22 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
23 : * parallel geometric multigrid solver on hierarchically distributed grids.
24 : * Computing and visualization in science 16, 4 (2013), 151-164"
25 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
26 : * flexible software system for simulating pde based models on high performance
27 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
28 : *
29 : * This program is distributed in the hope that it will be useful,
30 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 : * GNU Lesser General Public License for more details.
33 : */
34 :
35 : #ifndef __H__LIMEX__SIMPLE_INTEGRATOR_HPP__
36 : #define __H__LIMEX__SIMPLE_INTEGRATOR_HPP__
37 :
38 : #include "lib_algebra/operator/debug_writer.h"
39 :
40 : #include "time_integrator.hpp"
41 :
42 : namespace ug {
43 :
44 : /// Integrate (a non-linear problem) over a given time interval
45 : template<class TDomain, class TAlgebra>
46 : class SimpleTimeIntegrator :
47 : public INonlinearTimeIntegrator<TDomain, TAlgebra>,
48 : public ITimeDiscDependentObject<TAlgebra>,
49 : public DebugWritingObject<TAlgebra>
50 : {
51 : protected:
52 : typedef ITimeDiscDependentObject<TAlgebra> tdisc_dep_type;
53 :
54 : public:
55 : typedef INonlinearTimeIntegrator<TDomain, TAlgebra> base_type;
56 : typedef ITimeDiscretization<TAlgebra> time_disc_type;
57 : typedef typename TAlgebra::vector_type vector_type;
58 : typedef typename base_type::grid_function_type grid_function_type;
59 : typedef IGridFunctionSpace<grid_function_type> grid_function_space_type;
60 : typedef VectorTimeSeries<typename base_type::vector_type> vector_time_series_type;
61 :
62 : // constructor
63 0 : SimpleTimeIntegrator (SmartPtr<time_disc_type> tDisc)
64 : : base_type(), ITimeDiscDependentObject<TAlgebra>(tDisc),
65 0 : m_spBanachSpace(new AlgebraicSpace<grid_function_type>() ),
66 0 : m_spDerivative(SPNULL), m_initial_consistency_error(0.0)
67 :
68 0 : {}
69 :
70 : SimpleTimeIntegrator
71 : (
72 : SmartPtr<time_disc_type> tDisc,
73 : SmartPtr<grid_function_space_type> spSpace
74 : )
75 : : base_type(), ITimeDiscDependentObject<TAlgebra>(tDisc),
76 : m_spBanachSpace(spSpace),
77 : m_spDerivative(SPNULL), m_initial_consistency_error(0.0)
78 : {}
79 :
80 :
81 0 : bool apply
82 : (
83 : SmartPtr<grid_function_type> u1,
84 : number t1,
85 : ConstSmartPtr<grid_function_type> u0,
86 : number t0
87 : )
88 : {
89 : time_disc_type &tdisc = *tdisc_dep_type::m_spTimeDisc;
90 :
91 0 : if (tdisc.num_stages() == 1)
92 0 : return apply_single_stage(u1,t1,u0,t0);
93 : else
94 0 : return apply_multi_stage(u1,t1,u0,t0);
95 : }
96 :
97 : void set_derivative(SmartPtr<grid_function_type> udot)
98 0 : { m_spDerivative = udot; }
99 :
100 : SmartPtr<grid_function_type> get_derivative()
101 : { return m_spDerivative; }
102 :
103 : number get_consistency_error() const
104 0 : { return m_initial_consistency_error; }
105 :
106 : void set_banach_space(SmartPtr<IGridFunctionSpace<grid_function_type> > spSpace)
107 0 : { m_spBanachSpace = spSpace; }
108 :
109 : protected:
110 :
111 : bool apply_single_stage
112 : (
113 : SmartPtr<grid_function_type> u1,
114 : number t1,
115 : ConstSmartPtr<grid_function_type> u0,
116 : number t0
117 : );
118 :
119 : bool apply_multi_stage
120 : (
121 : SmartPtr<grid_function_type> u1,
122 : number t1,
123 : ConstSmartPtr<grid_function_type> u0,
124 : number t0
125 : );
126 :
127 : inline bool hasTerminated(double tCurrent, double tStart, double tFinal) const
128 : {
129 : /*return (! ((tCurrent < tFinal) && (tFinal-tCurrent > base_type::m_precisionBound)));*/
130 0 : return tCurrent >= tFinal || tFinal-tCurrent < (tFinal-tStart)*base_type::m_precisionBound;
131 : }
132 :
133 : /// metric
134 : SmartPtr<IGridFunctionSpace<grid_function_type> > m_spBanachSpace;
135 :
136 : SmartPtr<grid_function_type> m_spDerivative;
137 :
138 : number m_initial_consistency_error;
139 : };
140 :
141 : } // ug
142 :
143 : #include "simple_integrator_impl.hpp"
144 :
145 : #endif // __H__LIMEX__SIMPLE_INTEGRATOR_HPP__
|