ug4
composite_time_disc_impl.h
Go to the documentation of this file.
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>
41 {
42  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
43  m_vTimeDisc[i]->prepare_step(prevSol, dt);
44 }
45 
46 template <typename TAlgebra>
48 (
50  number dt,
51  const GridLevel& gl
52 )
53 {
54  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
55  m_vTimeDisc[i]->prepare_step_elem(prevSol, dt, gl);
56 }
57 
58 template <typename TAlgebra>
61 {
62  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
63  m_vTimeDisc[i]->finish_step(currSol);
64 }
65 
66 template <typename TAlgebra>
68 (
70  const GridLevel& gl
71 )
72 {
73  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
74  m_vTimeDisc[i]->finish_step_elem(currSol, gl);
75 }
76 
77 template <typename TAlgebra>
79 {
80  if (m_vTimeDisc.size())
81  return m_vTimeDisc[0]->future_time();
82  UG_THROW("At least one time disc must be added to CompositeTimeDiscretization.")
83 }
84 
85 template <typename TAlgebra>
87 {
88  size_t nSteps = 0;
89  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
90  nSteps = std::max(nSteps, m_vTimeDisc[i]->num_prev_steps());
91 
92  return nSteps;
93 }
94 
95 template <typename TAlgebra>
97 {
98  size_t nStages = 0;
99  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
100  nStages = std::max(nStages, m_vTimeDisc[i]->num_stages());
101 
102  return nStages;
103 }
104 
105 template <typename TAlgebra>
107 {
108  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
109  m_vTimeDisc[i]->set_stage(stage);
110 }
111 
112 
113 template <typename TAlgebra>
115 (
116  matrix_type& J,
117  const vector_type& u,
118  const GridLevel& gl
119 )
120 {
121  UG_COND_THROW(!m_vTimeDisc.size(),
122  "At least one time disc must be added to CompositeTimeDiscretization.")
123 
124  m_vTimeDisc[0]->assemble_jacobian(J, u, gl);
125  for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
126  {
127  // avoid clearing of the matrix before assembling
128  m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
129 
130  m_vTimeDisc[i]->assemble_jacobian(J, u, gl);
131  }
132 }
133 
134 template <typename TAlgebra>
136 (
137  vector_type& d,
138  const vector_type& u,
139  const GridLevel& gl
140 )
141 {
142  UG_COND_THROW(!m_vTimeDisc.size(),
143  "At least one time disc must be added to CompositeTimeDiscretization.")
144 
145  m_vTimeDisc[0]->assemble_defect(d, u, gl);
146  for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
147  {
148  // avoid clearing of the matrix before assembling
149  m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
150 
151  m_vTimeDisc[i]->assemble_defect(d, u, gl);
152  }
153 }
154 
155 template <typename TAlgebra>
157 (
158  matrix_type& A,
159  vector_type& b,
160  const GridLevel& gl
161 )
162 {
163  UG_COND_THROW(!m_vTimeDisc.size(),
164  "At least one time disc must be added to CompositeTimeDiscretization.")
165 
166  m_vTimeDisc[0]->assemble_linear(A, b, gl);
167  for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
168  {
169  // avoid clearing of the matrix before assembling
170  m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
171 
172  m_vTimeDisc[i]->assemble_linear(A, b, gl);
173  }
174 }
175 
176 template <typename TAlgebra>
178 (
179  vector_type& b,
180  const vector_type& u,
181  const GridLevel& gl
182 )
183 {
184  UG_COND_THROW(!m_vTimeDisc.size(),
185  "At least one time disc must be added to CompositeTimeDiscretization.")
186 
187  m_vTimeDisc[0]->assemble_rhs(b, u, gl);
188  for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
189  {
190  // avoid clearing of the matrix before assembling
191  m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
192 
193  m_vTimeDisc[i]->assemble_rhs(b, u, gl);
194  }
195 }
196 
197 template <typename TAlgebra>
199 {
200  UG_COND_THROW(!m_vTimeDisc.size(),
201  "At least one time disc must be added to CompositeTimeDiscretization.")
202 
203  m_vTimeDisc[0]->assemble_rhs(b, gl);
204  for (size_t i = 1; i < m_vTimeDisc.size(); ++i)
205  {
206  // avoid clearing of the matrix before assembling
207  m_vTimeDisc[i]->domain_disc()->ass_tuner()->disable_clear_on_resize();
208 
209  m_vTimeDisc[i]->assemble_rhs(b, gl);
210  }
211 }
212 
213 template <typename TAlgebra>
215 {
216  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
217  m_vTimeDisc[i]->adjust_solution(u, gl);
218 }
219 
220 template <typename TAlgebra>
222 {
224  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
225  sp->add_ass_tuner(((IAssemble<TAlgebra>*)m_vTimeDisc[i].get())->ass_tuner());
226 
227  return sp;
228 }
229 
230 template <typename TAlgebra>
232 {
233  UG_THROW("Unique const AssemblingTuner cannot be provided by CompositeTimeDiscretization.")
234 }
235 
236 template <typename TAlgebra>
238 {
239  size_t n = 0;
240  for (size_t i = 0; i < m_vTimeDisc.size(); ++i)
241  n += m_vTimeDisc[i]->num_constraints();
242 
243  return n;
244 }
245 
246 template <typename TAlgebra>
248 {
249  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  while ((n += m_vTimeDisc[k]->num_constraints()) <= i)
256  ++k;
257 
258  const size_t indInCurTD = i - (n - m_vTimeDisc[k]->num_constraints());
259 
260  return m_vTimeDisc[k]->constraint(indInCurTD);
261 }
262 
263 } // end namespace ug
264 
265 
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
Definition: composite_time_disc.h:70
virtual void prepare_step(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt)
prepares the assembling of Defect/Jacobian for a time step
Definition: composite_time_disc_impl.h:40
virtual number future_time() const
returns the future time point (i.e. the one that will be computed)
Definition: composite_time_disc_impl.h:78
virtual size_t num_constraints() const
returns the number of constraints
Definition: composite_time_disc_impl.h:237
virtual SmartPtr< IConstraint< TAlgebra > > constraint(size_t i)
returns the i'th constraint
Definition: composite_time_disc_impl.h:247
void assemble_rhs(vector_type &b, const vector_type &u, const GridLevel &gl)
Definition: composite_time_disc_impl.h:178
virtual size_t num_stages() const
returns the number of stages
Definition: composite_time_disc_impl.h:96
virtual void finish_step(SmartPtr< VectorTimeSeries< vector_type > > currSol)
Definition: composite_time_disc_impl.h:60
void assemble_jacobian(matrix_type &J, const vector_type &u, const GridLevel &gl)
assembles Jacobian (or Approximation of Jacobian)
Definition: composite_time_disc_impl.h:115
virtual void finish_step_elem(SmartPtr< VectorTimeSeries< vector_type > > currSol, const GridLevel &gl)
Definition: composite_time_disc_impl.h:68
void assemble_defect(vector_type &d, const vector_type &u, const GridLevel &gl)
assembles Defect
Definition: composite_time_disc_impl.h:136
void assemble_linear(matrix_type &A, vector_type &b, const GridLevel &gl)
Assembles Matrix and Right-Hand-Side for a linear problem.
Definition: composite_time_disc_impl.h:157
virtual size_t num_prev_steps() const
returns number of previous time steps needed
Definition: composite_time_disc_impl.h:86
virtual SmartPtr< AssemblingTuner< TAlgebra > > ass_tuner()
Definition: composite_time_disc_impl.h:221
void adjust_solution(vector_type &u, const GridLevel &gl)
sets dirichlet values in solution vector
Definition: composite_time_disc_impl.h:214
virtual void prepare_step_elem(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt, const GridLevel &gl)
prepares the assembling of Defect/Jacobian for a time step
Definition: composite_time_disc_impl.h:48
virtual void set_stage(size_t stage)
sets the stage
Definition: composite_time_disc_impl.h:106
Definition: grid_level.h:42
Interface providing Jacobian and Defect of a discretization.
Definition: assemble_interface.h:110
TAlgebra::vector_type vector_type
Type of algebra vector.
Definition: assemble_interface.h:119
TAlgebra::matrix_type matrix_type
Type of algebra matrix.
Definition: assemble_interface.h:116
time series of solutions and corresponding time point
Definition: solution_time_series.h:59
#define UG_THROW(msg)
Definition: error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
the ug namespace
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836