Saddle-Point
Loading...
Searching...
No Matches
solution.cc
Go to the documentation of this file.
1
16#include <deal.II/base/quadrature_lib.h>
17#include <deal.II/base/function.h>
18
19#include <deal.II/lac/full_matrix.h>
20#include <deal.II/lac/vector.h>
21#include <deal.II/lac/solver_control.h>
22#include <deal.II/lac/solver_cg.h>
23#include <deal.II/lac/precondition.h>
24#include <deal.II/lac/sparse_matrix.h>
25#include <deal.II/lac/dynamic_sparsity_pattern.h>
26
27#include <deal.II/grid/tria.h>
28#include <deal.II/grid/manifold_lib.h>
29#include <deal.II/grid/grid_generator.h>
30
31#include <deal.II/dofs/dof_handler.h>
32#include <deal.II/dofs/dof_tools.h>
33
34#include <deal.II/fe/fe_q.h>
35#include <deal.II/fe/fe_values.h>
36#include <deal.II/fe/mapping_q.h>
37
38#include <deal.II/numerics/data_out.h>
39#include <deal.II/numerics/vector_tools.h>
40#include <deal.II/numerics/matrix_tools.h>
41
42#include <fstream>
43#include <iostream>
44
45using namespace dealii;
46
47
78template <int dim, int n_equations>
79class Solution : public Function<dim>
80{
81public:
89 : Function<dim>(n_equations)
90 {}
91
102 virtual void vector_value(const Point<dim> &p,
103 Vector<double> &values) const override;
104
115 virtual void vector_gradient(const Point<dim> &p,
116 std::vector< Tensor< 1, dim, double > > & gradients ) const override;
117
118private:
121 int R = 1;
122};
123
124
125// Out-of-line implementation of Solution::vector_value() (see the
126// class declaration for documentation). Several manufactured solutions
127// are coded up here; all but one (test case 2) are commented out. To
128// switch test cases, uncomment the desired block and comment out the
129// others.
130template <int dim, int n_equation>
132 Vector<double> &values) const
133{
134 // ---- test case 1 (commented out) ---------------------------------
135 //double pi = numbers::PI;
136 //values(0) = std::sin(p[0]) * std::sin(p[1]);
137 //values(1) = (- 2) * p[0] * p[1];
138
139 // ---- test case 2 (currently active) ------------------------------
140 values(0) = std::exp(p[0]) * std::cos(p[1]);
141 values(1) = (- 2) * p[0] * p[1];
142
143 // ---- test case 3 (commented out) ---------------------------------
144 //double pi = numbers::PI;
145 //values(0) = std::sin(pi*p[0]) * std::sin(pi*p[1]);
146 //values(1) = (- 2) * p[0] * p[1];
147}
148
149// Out-of-line implementation of Solution::vector_gradient() (see the
150// class declaration for documentation). Returns the analytic gradient
151// of the currently active manufactured solution (test case 2). The
152// function first resizes @p gradients to @p n_equations and then fills
153// it component by component.
154template <int dim, int n_equations>
156 std::vector< Tensor<1, dim, double > > & gradients ) const
157{
158 //double pi = numbers::PI;
159 gradients.resize(n_equations); // Resize the gradients vector
160 //std::vector< Tensor<1, dim, double> > return_value;
161
162 // ---- test case 1 (commented out) ---------------------------------
163 //double pi = numbers::PI;
164 //gradients[0][0] = std::cos(p[0]) * std::sin(p[1]);
165 //gradients[0][1] = std::sin(p[0]) * std::cos(p[1]);
166 //gradients[1][0] = - 2 * p[1];
167 //gradients[1][1] = - 2 * p[0];
168
169 // ---- test case 2 (currently active) ------------------------------
170 gradients[0][0] = std::exp(p[0]) * std::cos(p[1]);
171 gradients[0][1] = std::exp(p[0]) * (-1) * std::sin(p[1]);
172 gradients[1][0] = - 2 * p[1];
173 gradients[1][1] = - 2 * p[0];
174
175 // ---- test case 3 (commented out) ---------------------------------
176 //gradients[0][0] = pi*std::cos(pi*p[0]) * std::sin(pi*p[1]);
177 //gradients[0][1] = pi*std::sin(pi*p[0]) * std::cos(pi*p[1]);
178 //gradients[1][0] = - 2 * p[1];
179 //gradients[1][1] = - 2 * p[0];
180
181 // ---- test case 4 (polar coordinates, commented out) --------------
182 //const auto r = p.norm();
183 //const auto theta = std::atan( p[1]/p[0] );
184 //
185 //gradients[0][0] = 0;
186 //gradients[0][1] = 0;
187 //gradients[1][0] = std::cos( theta / R);
188 //gradients[1][1] = - r * (1/R) * std::sin( theta / R);
189 //return return_value;
190}
Vector-valued manufactured solution used by the saddle-point program.
Definition solution.cc:80
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, double > > &gradients) const override
Evaluate the gradient of every component at a single point.
Definition solution.cc:155
Solution()
Construct a Solution with n_equations components.
Definition solution.cc:88
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
Evaluate the manufactured solution at a single point.
Definition solution.cc:131