Hermes2D  3.0
discrete_problem_helpers.cpp
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #include "discrete_problem/discrete_problem_helpers.h"
17 #include "forms.h"
18 
19 namespace Hermes
20 {
21  namespace Hermes2D
22  {
23  namespace Mixins
24  {
25  template<typename Scalar>
26  DiscreteProblemRungeKutta<Scalar>::DiscreteProblemRungeKutta() : rungeKutta(false), RK_original_spaces_count(0), force_diagonal_blocks(false), block_weights(nullptr)
27  {
28  }
29 
30  template<typename Scalar>
31  void DiscreteProblemRungeKutta<Scalar>::set_RK(int original_spaces_count, bool force_diagonal_blocks_, Table* block_weights_)
32  {
33  this->rungeKutta = true;
34  this->RK_original_spaces_count = original_spaces_count;
35  this->force_diagonal_blocks = force_diagonal_blocks_;
36  this->block_weights = block_weights_;
37  }
38 
39  template<typename Scalar>
41  {
42  if (block_weights)
43  return block_weights->get_A(form->i / this->RK_original_spaces_count, form->j / this->RK_original_spaces_count);
44  return 1.0;
45  }
46 
47  template<typename Scalar>
48  double DiscreteProblemRungeKutta<Scalar>::block_scaling_coeff(MatrixFormDG<Scalar>* form) const
49  {
50  if (block_weights)
51  return block_weights->get_A(form->i / this->RK_original_spaces_count, form->j / this->RK_original_spaces_count);
52  return 1.0;
53  }
54 
55  template<typename Scalar>
56  DiscreteProblemWeakForm<Scalar>::DiscreteProblemWeakForm(WeakFormSharedPtr<Scalar> wf_) : wf(wf_)
57  {
58  }
59 
60  template<typename Scalar>
61  void DiscreteProblemWeakForm<Scalar>::set_weak_formulation(WeakFormSharedPtr<Scalar> wf_)
62  {
63  if (!wf_)
64  throw Hermes::Exceptions::NullException(0);
65 
66  this->wf = wf_;
67  }
68 
69  template<typename Scalar>
70  WeakFormSharedPtr<Scalar> DiscreteProblemWeakForm<Scalar>::get_weak_formulation() const
71  {
72  return this->wf;
73  }
74 
75  template<typename Scalar>
76  DiscreteProblemMatrixVector<Scalar>::DiscreteProblemMatrixVector() : current_mat(nullptr), current_rhs(nullptr)
77  {
78  }
79 
80  template<typename Scalar>
81  bool DiscreteProblemMatrixVector<Scalar>::set_matrix(SparseMatrix<Scalar>* mat)
82  {
83  this->current_mat = mat;
84  return true;
85  }
86 
87  template<typename Scalar>
88  bool DiscreteProblemMatrixVector<Scalar>::set_rhs(Vector<Scalar>* rhs)
89  {
90  this->current_rhs = rhs;
91  return true;
92  }
93 
94  template class HERMES_API DiscreteProblemRungeKutta < double > ;
95  template class HERMES_API DiscreteProblemRungeKutta < std::complex<double> > ;
96 
97  template class HERMES_API DiscreteProblemWeakForm < double > ;
98  template class HERMES_API DiscreteProblemWeakForm < std::complex<double> > ;
99 
100  template class HERMES_API DiscreteProblemMatrixVector < double > ;
101  template class HERMES_API DiscreteProblemMatrixVector < std::complex<double> > ;
102  }
103 
104  unsigned char init_geometry_points_allocated(RefMap** reference_mapping, unsigned short reference_mapping_count, int order, GeomVol<double>& geometry, double* jacobian_x_weights)
105  {
106  RefMap* rep_reference_mapping = nullptr;
107  for (int i = 0; i < reference_mapping_count; i++)
108  {
109  if (reference_mapping[i])
110  {
111  if (reference_mapping[i]->get_active_element())
112  {
113  rep_reference_mapping = reference_mapping[i];
114  break;
115  }
116  }
117  }
118  return init_geometry_points_allocated(rep_reference_mapping, order, geometry, jacobian_x_weights);
119  }
120 
121  unsigned char init_geometry_points_allocated(RefMap* rep_reference_mapping, int order, GeomVol<double>& geometry, double* jacobian_x_weights)
122  {
123  Element* e = rep_reference_mapping->get_active_element();
124  ElementMode2D mode = e->get_mode();
125  Quad2D* quad = rep_reference_mapping->get_quad_2d();
126 
127  double3* pt = quad->get_points(order, mode);
128  unsigned char np = quad->get_num_points(order, mode);
129 
130  // Init geometry and jacobian*weights.
131  init_geom_vol_allocated(geometry, rep_reference_mapping, order);
132 
133  if (rep_reference_mapping->is_jacobian_const())
134  {
135  double jac = rep_reference_mapping->get_const_jacobian();
136  for (unsigned char i = 0; i < np; i++)
137  jacobian_x_weights[i] = pt[i][2] * jac;
138  }
139  else
140  {
141  double* jac = rep_reference_mapping->get_jacobian(order);
142  for (unsigned char i = 0; i < np; i++)
143  jacobian_x_weights[i] = pt[i][2] * jac[i];
144  }
145  return np;
146  }
147 
148  unsigned char init_surface_geometry_points_allocated(RefMap** reference_mapping, unsigned short reference_mapping_count, int& order, unsigned char isurf, int marker, GeomSurf<double>& geometry, double* jacobian_x_weights)
149  {
150  RefMap* rep_reference_mapping = nullptr;
151  for (int i = 0; i < reference_mapping_count; i++)
152  {
153  if (reference_mapping[i])
154  {
155  if (reference_mapping[i]->get_active_element())
156  {
157  rep_reference_mapping = reference_mapping[i];
158  break;
159  }
160  }
161  }
162  return init_surface_geometry_points_allocated(rep_reference_mapping, order, isurf, marker, geometry, jacobian_x_weights);
163  }
164 
165  unsigned char init_surface_geometry_points_allocated(RefMap* rep_reference_mapping, int& order, unsigned char isurf, int marker, GeomSurf<double>& geometry, double* jacobian_x_weights)
166  {
167  Element* e = rep_reference_mapping->get_active_element();
168  ElementMode2D mode = e->get_mode();
169  Quad2D* quad = rep_reference_mapping->get_quad_2d();
170 
171  int eo = quad->get_edge_points(isurf, order, mode);
172  double3* pt = quad->get_points(eo, mode);
173  unsigned char np = quad->get_num_points(eo, mode);
174 
175  // Init geometry and jacobian*weights.
176  double3* tan;
177  init_geom_surf_allocated(geometry, rep_reference_mapping, isurf, marker, eo, tan);
178  for (unsigned char i = 0; i < np; i++)
179  jacobian_x_weights[i] = pt[i][2] * tan[i][2];
180  order = eo;
181  return np;
182  }
183  }
184 }
Definition: adapt.h:24
HERMES_API void init_geom_surf_allocated(GeomSurf< double > &geom, RefMap *rm, unsigned char isurf, int marker, const int order, double3 *&tan)
Init element geometry for surface integrals.
Definition: forms.cpp:444
HERMES_API void init_geom_vol_allocated(GeomVol< double > &geom, RefMap *rm, const int order)
Init element geometry for volumetric integrals.
Definition: forms.cpp:425
virtual void set_RK(int original_spaces_count, bool force_diagonal_blocks=nullptr, Table *block_weights=nullptr)
Set the special handling of external functions of Runge-Kutta methods, including information how many...
Abstract, base class for matrix form - i.e. a single integral in the bilinear form on the left hand s...
Definition: weakform.h:357
Represents the reference mapping.
Definition: refmap.h:40
DiscreteProblemRungeKutta()
Constructor for multiple components / equations.
Abstract, base class for matrix DG form - i.e. bilinear form, where the integration is with respect t...
Definition: weakform.h:49
HERMES_API unsigned char init_geometry_points_allocated(RefMap **reference_mapping, unsigned short reference_mapping_count, int order, GeomVol< double > &geometry, double *jacobian_x_weights)