Hermes2D  3.0
ogprojection_nox.h
Go to the documentation of this file.
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/>.
18 #ifndef __H2D_OGPROJECTION_NOX_H
19 #define __H2D_OGPROJECTION_NOX_H
20 
21 #include "../function/solution.h"
22 #include "../forms.h"
23 #include "../weakform/weakform.h"
24 
25 //#include "epetra.h"
26 #if(defined HAVE_NOX && defined HAVE_EPETRA && defined HAVE_TEUCHOS)
27 #include <NOX.H>
28 #ifdef _POSIX_C_SOURCE
29 # undef _POSIX_C_SOURCE // pyconfig.h included by NOX_Epetra defines it
30 #endif
31 #ifdef _XOPEN_SOURCE
32 # undef _XOPEN_SOURCE // pyconfig.h included by NOX_Epetra defines it
33 #endif
34 #include <NOX_Epetra.H>
35 
36 namespace Hermes
37 {
38  namespace Hermes2D
39  {
40  template<typename Scalar>
41  class HERMES_API OGProjectionNOX : public Hermes::Mixins::Loggable
42  {
43  public:
46  static void project_global(SpaceSharedPtr<Scalar> space,
47  MatrixFormVol<Scalar>* custom_projection_jacobian,
48  VectorFormVol<Scalar>* custom_projection_residual,
49  Scalar* target_vec, double newton_tol = 1e-6, int newton_max_iter = 10);
50 
70  static void project_global(SpaceSharedPtr<Scalar> space, MeshFunction<Scalar>* source_meshfn,
71  Scalar* target_vec, NormType proj_norm = HERMES_UNSET_NORM,
72  double newton_tol = 1e-6, int newton_max_iter = 10);
73 
75  static void project_global(SpaceSharedPtr<Scalar> space, MeshFunctionSharedPtr<Scalar> source_meshfn,
76  Scalar* target_vec, NormType proj_norm = HERMES_UNSET_NORM,
77  double newton_tol = 1e-6, int newton_max_iter = 10);
78 
80  static void project_global(SpaceSharedPtr<Scalar> space,
81  MeshFunctionSharedPtr<Scalar> source_sln, MeshFunctionSharedPtr<Scalar> target_sln,
82  NormType proj_norm = HERMES_UNSET_NORM,
83  double newton_tol = 1e-6, int newton_max_iter = 10);
84 
86  static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces, std::vector<MeshFunction<Scalar>* > source_meshfns,
87  Scalar* target_vec, std::vector<NormType> proj_norms = std::vector<NormType>(),
88  double newton_tol = 1e-6, int newton_max_iter = 10);
89 
91  static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces, std::vector<MeshFunctionSharedPtr<Scalar> > source_slns,
92  Scalar* target_vec, std::vector<NormType> proj_norms = std::vector<NormType>(),
93  double newton_tol = 1e-6, int newton_max_iter = 10);
94 
95  static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces,
96  std::vector<MeshFunctionSharedPtr<Scalar> > source_slns, std::vector<MeshFunctionSharedPtr<Scalar> > target_slns,
97  std::vector<NormType> proj_norms = std::vector<NormType>(), bool delete_old_mesh = false,
98  double newton_tol = 1e-6, int newton_max_iter = 10);
99 
100  protected:
106  static void project_internal(SpaceSharedPtr<Scalar> space, WeakForm<Scalar>* proj_wf, Scalar* target_vec,
107  double newton_tol = 1e-6, int newton_max_iter = 10);
108 
110  class ProjectionMatrixFormVol : public MatrixFormVol < Scalar >
111  {
112  public:
113  ProjectionMatrixFormVol(int i, int j, NormType norm_type) : MatrixFormVol<Scalar>(i, j)
114  {
115  this->norm_type = norm_type;
116  }
117 
118  Scalar value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
119  Geom<double> *e, Func<Scalar> **ext) const
120  {
121  switch (norm_type)
122  {
123  case HERMES_L2_NORM:
124  return l2_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
125  case HERMES_H1_NORM:
126  return h1_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
127  case HERMES_H1_SEMINORM:
128  return h1_semi_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
129  case HERMES_HCURL_NORM:
130  return hcurl_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
131  case HERMES_HDIV_NORM:
132  return hdiv_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
133  default:
134  throw Hermes::Exceptions::Exception("Unknown projection type");
135  return 0.0;
136  }
137  }
138 
139  Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
140  Geom<Hermes::Ord> *e, Func<Ord> **ext) const
141  {
142  switch (norm_type)
143  {
144  case HERMES_L2_NORM:
145  return l2_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
146  case HERMES_H1_NORM:
147  return h1_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
148  case HERMES_H1_SEMINORM:
149  return h1_semi_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
150  case HERMES_HCURL_NORM:
151  return hcurl_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
152  case HERMES_HDIV_NORM:
153  return hdiv_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
154  default:
155  throw Hermes::Exceptions::Exception("Unknown projection type");
156  return Hermes::Ord();
157  }
158  }
159 
160  MatrixFormVol<Scalar>* clone()
161  {
162  return new ProjectionMatrixFormVol(*this);
163  }
164 
165  private:
166  NormType norm_type;
167 
168  template<typename TestFunctionDomain, typename SolFunctionDomain>
169  static SolFunctionDomain h1_projection_biform(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
170  Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
171  {
172  SolFunctionDomain result = SolFunctionDomain(0);
173  for (int i = 0; i < n; i++)
174  result += wt[i] * (u->val[i] * v->val[i] + u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
175  return result;
176  }
177 
178  template<typename TestFunctionDomain, typename SolFunctionDomain>
179  static SolFunctionDomain h1_semi_projection_biform(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
180  Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
181  {
182  SolFunctionDomain result = SolFunctionDomain(0);
183  for (int i = 0; i < n; i++)
184  result += wt[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
185  return result;
186  }
187 
188  template<typename TestFunctionDomain, typename SolFunctionDomain>
189  static SolFunctionDomain l2_projection_biform(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
190  Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
191  {
192  SolFunctionDomain result = SolFunctionDomain(0);
193  for (int i = 0; i < n; i++)
194  result += wt[i] * (u->val[i] * v->val[i]);
195  return result;
196  }
197 
198  template<typename TestFunctionDomain, typename SolFunctionDomain>
199  static SolFunctionDomain hcurl_projection_biform(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
200  Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
201  {
202  SolFunctionDomain result = SolFunctionDomain(0);
203  for (int i = 0; i < n; i++) {
204  result += wt[i] * (u->curl[i] * conj(v->curl[i]));
205  result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
206  }
207  return result;
208  }
209 
210  template<typename TestFunctionDomain, typename SolFunctionDomain>
211  static SolFunctionDomain hdiv_projection_biform(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
212  Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
213  {
214  SolFunctionDomain result = SolFunctionDomain(0);
215  for (int i = 0; i < n; i++) {
216  result += wt[i] * (u->div[i] * conj(v->div[i]));
217  result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
218  }
219  return result;
220  }
221  };
222 
224  class ProjectionVectorFormVol : public VectorFormVol < Scalar >
225  {
226  public:
227  ProjectionVectorFormVol(int i, NormType norm_type) : VectorFormVol<Scalar>(i)
228  {
229  this->norm_type = norm_type;
230  }
231 
232  Scalar value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
233  Geom<double> *e, Func<Scalar> **ext) const
234  {
235  switch (norm_type)
236  {
237  case HERMES_L2_NORM:
238  return l2_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
239  case HERMES_H1_NORM:
240  return h1_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
241  case HERMES_H1_SEMINORM:
242  return h1_semi_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
243  case HERMES_HCURL_NORM:
244  return hcurl_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
245  case HERMES_HDIV_NORM:
246  return hdiv_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
247  default:
248  throw Hermes::Exceptions::Exception("Unknown projection type");
249  return 0.0;
250  }
251  }
252 
253  Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *v,
254  Geom<Hermes::Ord> *e, Func<Ord> **ext) const
255  {
256  switch (norm_type)
257  {
258  case HERMES_L2_NORM:
259  return l2_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
260  case HERMES_H1_NORM:
261  return h1_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
262  case HERMES_H1_SEMINORM:
263  return h1_semi_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
264  case HERMES_HCURL_NORM:
265  return hcurl_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
266  case HERMES_HDIV_NORM:
267  return hdiv_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
268  default:
269  throw Hermes::Exceptions::Exception("Unknown projection type");
270  return Hermes::Ord();
271  }
272  }
273 
274  VectorFormVol<Scalar>* clone()
275  {
276  return new ProjectionVectorFormVol(*this);
277  }
278 
279  private:
280  NormType norm_type;
281 
282  template<typename TestFunctionDomain, typename SolFunctionDomain>
283  SolFunctionDomain h1_projection_residual(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
284  Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext) const
285  {
286  SolFunctionDomain result = SolFunctionDomain(0);
287  for (int i = 0; i < n; i++)
288  result += wt[i] * ((u_ext[this->i]->val[i] - ext[0]->val[i]) * v->val[i]
289  + (u_ext[this->i]->dx[i] - ext[0]->dx[i]) * v->dx[i]
290  + (u_ext[this->i]->dy[i] - ext[0]->dy[i]) * v->dy[i]);
291  return result;
292  }
293 
294  template<typename TestFunctionDomain, typename SolFunctionDomain>
295  SolFunctionDomain h1_semi_projection_residual(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
296  Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext) const
297  {
298  SolFunctionDomain result = SolFunctionDomain(0);
299  for (int i = 0; i < n; i++)
300  result += wt[i] * ((u_ext[this->i]->dx[i] - ext[0]->dx[i]) * v->dx[i]
301  + (u_ext[this->i]->dy[i] - ext[0]->dy[i]) * v->dy[i]);
302  return result;
303  }
304 
305  template<typename TestFunctionDomain, typename SolFunctionDomain>
306  SolFunctionDomain l2_projection_residual(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
307  Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext) const
308  {
309  SolFunctionDomain result = SolFunctionDomain(0);
310  for (int i = 0; i < n; i++)
311  result += wt[i] * (u_ext[this->i]->val[i] - ext[0]->val[i]) * v->val[i];
312  return result;
313  }
314 
315  template<typename TestFunctionDomain, typename SolFunctionDomain>
316  SolFunctionDomain hcurl_projection_residual(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
317  Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext) const
318  {
319  SolFunctionDomain result = SolFunctionDomain(0);
320  for (int i = 0; i < n; i++) {
321  result += wt[i] * (u_ext[this->i]->curl[i] - ext[0]->curl[i]) * conj(v->curl[i]);
322  result += wt[i] * ((u_ext[this->i]->val0[i] - ext[0]->val0[i]) * conj(v->val0[i])
323  + (u_ext[this->i]->val1[i] - ext[0]->val1[i]) * conj(v->val1[i]));
324  }
325 
326  return result;
327  }
328 
329  template<typename TestFunctionDomain, typename SolFunctionDomain>
330  SolFunctionDomain hdiv_projection_residual(int n, double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
331  Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext) const
332  {
333  SolFunctionDomain result = SolFunctionDomain(0);
334  for (int i = 0; i < n; i++) {
335  result += wt[i] * (u_ext[this->i]->div[i] - ext[0]->div[i]) * conj(v->div[i]);
336  result += wt[i] * ((u_ext[this->i]->val0[i] - ext[0]->val0[i]) * conj(v->val0[i])
337  + (u_ext[this->i]->val1[i] - ext[0]->val1[i]) * conj(v->val1[i]));
338  }
339 
340  return result;
341  }
342  };
343  };
344  }
345 }
346 #endif
347 #endif
Definition: adapt.h:24