Line data Source code
1 : /*
2 : * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Markus Breit
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "common/error.h" // UG_COND_THROW
34 :
35 : namespace ug {
36 :
37 :
38 : template <typename TAlgebra>
39 0 : void CompositeTimeDiscretization<TAlgebra>::
40 : prepare_step(SmartPtr<VectorTimeSeries<vector_type> > prevSol, number dt)
41 : {
42 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
43 0 : m_vTimeDisc[i]->prepare_step(prevSol, dt);
44 0 : }
45 :
46 : template <typename TAlgebra>
47 0 : void CompositeTimeDiscretization<TAlgebra>::prepare_step_elem
48 : (
49 : SmartPtr<VectorTimeSeries<vector_type> > prevSol,
50 : number dt,
51 : const GridLevel& gl
52 : )
53 : {
54 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
55 0 : m_vTimeDisc[i]->prepare_step_elem(prevSol, dt, gl);
56 0 : }
57 :
58 : template <typename TAlgebra>
59 0 : void CompositeTimeDiscretization<TAlgebra>::
60 : finish_step(SmartPtr<VectorTimeSeries<vector_type> > currSol)
61 : {
62 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
63 0 : m_vTimeDisc[i]->finish_step(currSol);
64 0 : }
65 :
66 : template <typename TAlgebra>
67 0 : void CompositeTimeDiscretization<TAlgebra>::finish_step_elem
68 : (
69 : SmartPtr<VectorTimeSeries<vector_type> > currSol,
70 : const GridLevel& gl
71 : )
72 : {
73 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
74 0 : m_vTimeDisc[i]->finish_step_elem(currSol, gl);
75 0 : }
76 :
77 : template <typename TAlgebra>
78 0 : number CompositeTimeDiscretization<TAlgebra>::future_time() const
79 : {
80 0 : if (m_vTimeDisc.size())
81 0 : return m_vTimeDisc[0]->future_time();
82 0 : UG_THROW("At least one time disc must be added to CompositeTimeDiscretization.")
83 : }
84 :
85 : template <typename TAlgebra>
86 0 : size_t CompositeTimeDiscretization<TAlgebra>::num_prev_steps() const
87 : {
88 0 : size_t nSteps = 0;
89 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
90 0 : nSteps = std::max(nSteps, m_vTimeDisc[i]->num_prev_steps());
91 :
92 0 : return nSteps;
93 : }
94 :
95 : template <typename TAlgebra>
96 0 : size_t CompositeTimeDiscretization<TAlgebra>::num_stages() const
97 : {
98 0 : size_t nStages = 0;
99 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
100 0 : nStages = std::max(nStages, m_vTimeDisc[i]->num_stages());
101 :
102 0 : return nStages;
103 : }
104 :
105 : template <typename TAlgebra>
106 0 : void CompositeTimeDiscretization<TAlgebra>::set_stage(size_t stage)
107 : {
108 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
109 0 : m_vTimeDisc[i]->set_stage(stage);
110 0 : }
111 :
112 :
113 : template <typename TAlgebra>
114 0 : void CompositeTimeDiscretization<TAlgebra>::assemble_jacobian
115 : (
116 : matrix_type& J,
117 : const vector_type& u,
118 : const GridLevel& gl
119 : )
120 : {
121 0 : UG_COND_THROW(!m_vTimeDisc.size(),
122 : "At least one time disc must be added to CompositeTimeDiscretization.")
123 :
124 0 : m_vTimeDisc[0]->assemble_jacobian(J, u, gl);
125 0 : for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
126 : {
127 : // avoid clearing of the matrix before assembling
128 0 : m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
129 :
130 0 : m_vTimeDisc[i]->assemble_jacobian(J, u, gl);
131 : }
132 0 : }
133 :
134 : template <typename TAlgebra>
135 0 : void CompositeTimeDiscretization<TAlgebra>::assemble_defect
136 : (
137 : vector_type& d,
138 : const vector_type& u,
139 : const GridLevel& gl
140 : )
141 : {
142 0 : UG_COND_THROW(!m_vTimeDisc.size(),
143 : "At least one time disc must be added to CompositeTimeDiscretization.")
144 :
145 0 : m_vTimeDisc[0]->assemble_defect(d, u, gl);
146 0 : for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
147 : {
148 : // avoid clearing of the matrix before assembling
149 0 : m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
150 :
151 0 : m_vTimeDisc[i]->assemble_defect(d, u, gl);
152 : }
153 0 : }
154 :
155 : template <typename TAlgebra>
156 0 : void CompositeTimeDiscretization<TAlgebra>::assemble_linear
157 : (
158 : matrix_type& A,
159 : vector_type& b,
160 : const GridLevel& gl
161 : )
162 : {
163 0 : UG_COND_THROW(!m_vTimeDisc.size(),
164 : "At least one time disc must be added to CompositeTimeDiscretization.")
165 :
166 0 : m_vTimeDisc[0]->assemble_linear(A, b, gl);
167 0 : for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
168 : {
169 : // avoid clearing of the matrix before assembling
170 0 : m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
171 :
172 0 : m_vTimeDisc[i]->assemble_linear(A, b, gl);
173 : }
174 0 : }
175 :
176 : template <typename TAlgebra>
177 0 : void CompositeTimeDiscretization<TAlgebra>::assemble_rhs
178 : (
179 : vector_type& b,
180 : const vector_type& u,
181 : const GridLevel& gl
182 : )
183 : {
184 0 : UG_COND_THROW(!m_vTimeDisc.size(),
185 : "At least one time disc must be added to CompositeTimeDiscretization.")
186 :
187 0 : m_vTimeDisc[0]->assemble_rhs(b, u, gl);
188 0 : for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
189 : {
190 : // avoid clearing of the matrix before assembling
191 0 : m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
192 :
193 0 : m_vTimeDisc[i]->assemble_rhs(b, u, gl);
194 : }
195 0 : }
196 :
197 : template <typename TAlgebra>
198 0 : void CompositeTimeDiscretization<TAlgebra>::assemble_rhs(vector_type& b, const GridLevel& gl)
199 : {
200 0 : UG_COND_THROW(!m_vTimeDisc.size(),
201 : "At least one time disc must be added to CompositeTimeDiscretization.")
202 :
203 0 : m_vTimeDisc[0]->assemble_rhs(b, gl);
204 0 : for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
205 : {
206 : // avoid clearing of the matrix before assembling
207 0 : m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
208 :
209 0 : m_vTimeDisc[i]->assemble_rhs(b, gl);
210 : }
211 0 : }
212 :
213 : template <typename TAlgebra>
214 0 : void CompositeTimeDiscretization<TAlgebra>::adjust_solution(vector_type& u, const GridLevel& gl)
215 : {
216 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
217 0 : m_vTimeDisc[i]->adjust_solution(u, gl);
218 0 : }
219 :
220 : template <typename TAlgebra>
221 0 : SmartPtr<AssemblingTuner<TAlgebra> > CompositeTimeDiscretization<TAlgebra>::ass_tuner()
222 : {
223 0 : SmartPtr<CompositeAssTuner> sp = make_sp(new CompositeAssTuner());
224 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
225 0 : sp->add_ass_tuner(((IAssemble<TAlgebra>*)m_vTimeDisc[i].get())->ass_tuner());
226 :
227 0 : return sp;
228 : }
229 :
230 : template <typename TAlgebra>
231 0 : ConstSmartPtr<AssemblingTuner<TAlgebra> > CompositeTimeDiscretization<TAlgebra>::ass_tuner() const
232 : {
233 0 : UG_THROW("Unique const AssemblingTuner cannot be provided by CompositeTimeDiscretization.")
234 : }
235 :
236 : template <typename TAlgebra>
237 0 : size_t CompositeTimeDiscretization<TAlgebra>::num_constraints() const
238 : {
239 : size_t n = 0;
240 0 : for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
241 0 : n += m_vTimeDisc[i]->num_constraints();
242 :
243 0 : return n;
244 : }
245 :
246 : template <typename TAlgebra>
247 0 : SmartPtr<IConstraint<TAlgebra> > CompositeTimeDiscretization<TAlgebra>::constraint(size_t i)
248 : {
249 0 : UG_COND_THROW(i >= num_constraints(), "Requested constraint " << i << ", but only "
250 : << num_constraints() << " constraints available.");
251 :
252 : size_t n = 0;
253 : size_t k = 0;
254 :
255 0 : while ((n += m_vTimeDisc[k]->num_constraints()) <= i)
256 0 : ++k;
257 :
258 0 : const size_t indInCurTD = i - (n - m_vTimeDisc[k]->num_constraints());
259 :
260 0 : return m_vTimeDisc[k]->constraint(indInCurTD);
261 : }
262 :
263 : } // end namespace ug
264 :
265 :
|