Hermes2D  3.0
weakforms_hcurl.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 "weakforms_hcurl.h"
17 #include "../forms.h"
18 namespace Hermes
19 {
20  namespace Hermes2D
21  {
22  template<typename Real, typename Scalar>
23  static Scalar int_e_f(int n, double *wt, Func<Real> *u, Func<Real> *v)
24  {
25  Scalar result = Scalar(0);
26  for (int i = 0; i < n; i++)
27  result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
28  return result;
29  }
30 
31  template<typename Real, typename Scalar>
32  static Scalar int_curl_e_curl_f(int n, double *wt, Func<Real> *u, Func<Real> *v)
33  {
34  Scalar result = Scalar(0);
35  for (int i = 0; i < n; i++)
36  result += wt[i] * (u->curl[i] * conj(v->curl[i]));
37  return result;
38  }
39 
40  template<typename Real, typename Scalar>
41  static Scalar int_v0(int n, double *wt, Func<Scalar> *v)
42  {
43  Scalar result = Scalar(0);
44  for (int i = 0; i < n; i++)
45  result += wt[i] * v->val0[i];
46  return result;
47  }
48 
49  template<typename Real, typename Scalar>
50  static Scalar int_v1(int n, double *wt, Func<Real> *v)
51  {
52  Scalar result = Scalar(0);
53  for (int i = 0; i < n; i++)
54  result += wt[i] * (v->val1[i]);
55  return result;
56  }
57 
58  template<typename Real, typename Scalar>
59  static Scalar int_F_e_f(int n, double *wt, double(*F)(int marker, Real x, Real y), Func<Real> *u, Func<Real> *v, Geom<Real> *e)
60  {
61  Scalar result = Scalar(0);
62  for (int i = 0; i < n; i++)
63  result += wt[i] * (*F)(e->elem_marker, e->x[i], e->y[i]) * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
64  return result;
65  }
66 
67  template<typename Real, typename Scalar>
68  static Scalar int_e_tau_f_tau(int n, double *wt, Func<Real> *u, Func<Real> *v, GeomSurf<Real> *e)
69  {
70  Scalar result = Scalar(0);
71  for (int i = 0; i < n; i++)
72  result += wt[i] * ((u->val0[i] * e->tx[i] + u->val1[i] * e->ty[i]) *
73  conj(v->val0[i] * e->tx[i] + v->val1[i] * e->ty[i]));
74  return result;
75  }
76 
77  namespace WeakFormsHcurl
78  {
79  template<typename Scalar>
80  DefaultMatrixFormVol<Scalar>::DefaultMatrixFormVol
81  (int i, int j, std::string area, Scalar const_coeff,
82  Hermes2DFunction<Scalar>* f_coeff, SymFlag sym,
83  GeomType gt)
84  : MatrixFormVol<Scalar>(i, j), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
85  {
86  this->set_area(area);
87  this->setSymFlag(sym);
88 
89  // If f_coeff is nullptr, initialize it to be constant 1.0.
90  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
91  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
92  }
93 
94  template<typename Scalar>
95  DefaultMatrixFormVol<Scalar>::DefaultMatrixFormVol
96  (int i, int j, std::vector<std::string> areas, Scalar const_coeff,
97  Hermes2DFunction<Scalar>* f_coeff, SymFlag sym, GeomType gt)
98  : MatrixFormVol<Scalar>(i, j), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
99  {
100  this->set_areas(areas);
101  this->setSymFlag(sym);
102 
103  // If f_coeff is nullptr, initialize it to be constant 1.0.
104  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
105  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
106  }
107 
108  template<typename Scalar>
109  DefaultMatrixFormVol<Scalar>::~DefaultMatrixFormVol()
110  {
111  if (function_coeff == nullptr)
112  delete function_coeff;
113  };
114 
115  template<typename Scalar>
116  Scalar DefaultMatrixFormVol<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u,
117  Func<double> *v, GeomVol<double> *e, Func<Scalar> **ext) const
118  {
119  Scalar result = 0;
120  if (gt == HERMES_PLANAR)
121  {
122  result = const_coeff * int_e_f<double, Scalar>(n, wt, u, v);
123  }
124  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
125 
126  return result;
127  }
128 
129  template<typename Scalar>
130  Ord DefaultMatrixFormVol<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *u, Func<Ord> *v,
131  GeomVol<Ord> *e, Func<Ord> **ext) const
132  {
133  Ord result = Ord(0);
134  if (gt == HERMES_PLANAR)
135  {
136  result = const_coeff * int_e_f<Ord, Ord>(n, wt, u, v);
137  }
138  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
139 
140  return result;
141  }
142 
143  template<typename Scalar>
144  MatrixFormVol<Scalar>* DefaultMatrixFormVol<Scalar>::clone() const
145  {
146  return new DefaultMatrixFormVol<Scalar>(*this);
147  }
148 
149  template<typename Scalar>
150  DefaultJacobianCurlCurl<Scalar>::DefaultJacobianCurlCurl(int i, int j, std::string area, Scalar const_coeff,
151  CubicSpline* c_spline,
152  SymFlag sym, GeomType gt)
153  : MatrixFormVol<Scalar>(i, j),
154  idx_j(j), const_coeff(const_coeff), spline_coeff(c_spline), gt(gt)
155  {
156  this->set_area(area);
157  this->setSymFlag(sym);
158 
159  // If spline is nullptr, initialize it to be constant 1.0.
160  if (c_spline == nullptr) this->spline_coeff = new CubicSpline(1.0);
161  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
162  };
163 
164  template<typename Scalar>
165  DefaultJacobianCurlCurl<Scalar>::DefaultJacobianCurlCurl(int i, int j, std::vector<std::string> areas,
166  Scalar const_coeff, CubicSpline* c_spline,
167  SymFlag sym, GeomType gt)
168  : MatrixFormVol<Scalar>(i, j),
169  idx_j(j), const_coeff(const_coeff), spline_coeff(c_spline), gt(gt)
170  {
171  this->set_areas(areas);
172  this->setSymFlag(sym);
173 
174  // If spline is nullptr, initialize it to be constant 1.0.
175  if (c_spline == nullptr)
176  this->spline_coeff = new CubicSpline(1.0);
177  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
178  }
179 
180  template<typename Scalar>
181  DefaultJacobianCurlCurl<Scalar>::~DefaultJacobianCurlCurl()
182  {
183  if (spline_coeff == nullptr)
184  delete spline_coeff;
185  };
186 
187  template<typename Scalar>
188  Scalar DefaultJacobianCurlCurl<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u,
189  Func<double> *v, GeomVol<double> *e, Func<Scalar> **ext) const
190  {
191  Scalar result = 0;
192  if (gt == HERMES_PLANAR)
193  {
194  result = const_coeff * int_curl_e_curl_f<double, Scalar>(n, wt, u, v);
195  }
196  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
197 
198  return result;
199  }
200 
201  template<typename Scalar>
202  Ord DefaultJacobianCurlCurl<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *u, Func<Ord> *v,
203  GeomVol<Ord> *e, Func<Ord> **ext) const
204  {
205  Ord result = Ord(0);
206  if (gt == HERMES_PLANAR)
207  {
208  result = const_coeff * int_curl_e_curl_f<Ord, Ord>(n, wt, u, v);
209  }
210  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
211 
212  return result;
213  }
214 
215  template<typename Scalar>
216  MatrixFormVol<Scalar>* DefaultJacobianCurlCurl<Scalar>::clone() const
217  {
218  return new DefaultJacobianCurlCurl(*this);
219  }
220 
221  template<typename Scalar>
222  DefaultVectorFormVol<Scalar>::DefaultVectorFormVol(int i, std::string area, Scalar const_coeff0, Scalar const_coeff1,
223  Hermes2DFunction<Scalar>* f_coeff0, Hermes2DFunction<Scalar>* f_coeff1,
224  GeomType gt)
225  : VectorFormVol<Scalar>(i), const_coeff0(const_coeff0), const_coeff1(const_coeff1),
226  function_coeff0(f_coeff0), function_coeff1(f_coeff1), gt(gt)
227  {
228  this->set_area(area);
229 
230  // If f_coeff0 is nullptr, initialize it to be constant 1.0.
231  if (f_coeff0 == nullptr) this->function_coeff0 = new Hermes2DFunction<Scalar>(1.0);
232  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
233  if (f_coeff1 == nullptr) this->function_coeff1 = new Hermes2DFunction<Scalar>(1.0);
234  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
235  }
236 
237  template<typename Scalar>
238  DefaultVectorFormVol<Scalar>::DefaultVectorFormVol(int i, std::vector<std::string> areas,
239  Scalar const_coeff0, Scalar const_coeff1,
240  Hermes2DFunction<Scalar>* f_coeff0, Hermes2DFunction<Scalar>* f_coeff1,
241  GeomType gt)
242  : VectorFormVol<Scalar>(i), const_coeff0(const_coeff0), const_coeff1(const_coeff1),
243  function_coeff0(f_coeff0), function_coeff1(f_coeff1), gt(gt)
244  {
245  this->set_areas(areas);
246 
247  // If f_coeff0 is nullptr, initialize it to be constant 1.0.
248  if (f_coeff0 == nullptr) this->function_coeff0 = new Hermes2DFunction<Scalar>(1.0);
249  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
250  if (f_coeff1 == nullptr) this->function_coeff1 = new Hermes2DFunction<Scalar>(1.0);
251  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
252  }
253 
254  template<typename Scalar>
255  DefaultVectorFormVol<Scalar>::~DefaultVectorFormVol()
256  {
257  if (function_coeff0 == nullptr) delete function_coeff0;
258  if (function_coeff1 == nullptr) delete function_coeff1;
259  };
260 
261  template<typename Scalar>
262  Scalar DefaultVectorFormVol<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
263  GeomVol<double> *e, Func<Scalar> **ext) const
264  {
265  Scalar int_v0 = 0, int_v1 = 0;
266  for (int i = 0; i < n; i++) int_v0 += wt[i] * v->val0[i];
267  for (int i = 0; i < n; i++) int_v1 += wt[i] * v->val1[i];
268  return const_coeff0 * int_v0 + const_coeff1 * int_v1;
269  }
270 
271  template<typename Scalar>
272  Ord DefaultVectorFormVol<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v,
273  GeomVol<Ord> *e, Func<Ord> **ext) const
274  {
275  Ord int_v0 = Ord(0), int_v1 = Ord(0);
276  for (int i = 0; i < n; i++) int_v0 += wt[i] * v->val0[i];
277  for (int i = 0; i < n; i++) int_v1 += wt[i] * v->val1[i];
278  return const_coeff0 * int_v0 + const_coeff1 * int_v1;
279  }
280 
281  template<typename Scalar>
282  VectorFormVol<Scalar>* DefaultVectorFormVol<Scalar>::clone() const
283  {
284  return new DefaultVectorFormVol<Scalar>(*this);
285  }
286 
287  template<typename Scalar>
288  DefaultResidualVol<Scalar>::DefaultResidualVol(int i, std::string area, Scalar const_coeff,
289  Hermes2DFunction<Scalar>* f_coeff,
290  GeomType gt)
291  : VectorFormVol<Scalar>(i),
292  idx_i(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
293  {
294  this->set_area(area);
295 
296  // If f_coeff is nullptr, initialize it to be constant 1.0.
297  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
298  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
299  }
300 
301  template<typename Scalar>
302  DefaultResidualVol<Scalar>::DefaultResidualVol(int i, std::vector<std::string> areas, Scalar const_coeff,
303  Hermes2DFunction<Scalar>* f_coeff,
304  GeomType gt)
305  : VectorFormVol<Scalar>(i),
306  idx_i(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
307  {
308  this->set_areas(areas);
309 
310  // If f_coeff is nullptr, initialize it to be constant 1.0.
311  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
312  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
313  }
314 
315  template<typename Scalar>
316  DefaultResidualVol<Scalar>::~DefaultResidualVol()
317  {
318  if (function_coeff == nullptr) delete function_coeff;
319  };
320 
321  template<typename Scalar>
322  Scalar DefaultResidualVol<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
323  GeomVol<double> *e, Func<Scalar> **ext) const
324  {
325  Scalar result = 0;
326  if (gt == HERMES_PLANAR)
327  {
328  for (int i = 0; i < n; i++)
329  {
330  result += wt[i] * function_coeff->value(e->x[i], e->y[i]) * (u_ext[idx_i]->val0[i] * v->val0[i] +
331  u_ext[idx_i]->val1[i] * v->val1[i]);
332  }
333  }
334  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
335 
336  return const_coeff * result;
337  }
338 
339  template<typename Scalar>
340  Ord DefaultResidualVol<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v,
341  GeomVol<Ord> *e, Func<Ord> **ext) const
342  {
343  Ord result = Ord(0);
344  if (gt == HERMES_PLANAR)
345  {
346  for (int i = 0; i < n; i++)
347  {
348  result += wt[i] * function_coeff->value(e->x[i], e->y[i]) * u_ext[idx_i]->val[i] * v->val[i];
349  }
350  }
351  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
352 
353  return result;
354  }
355 
356  template<typename Scalar>
357  VectorFormVol<Scalar>* DefaultResidualVol<Scalar>::clone() const
358  {
359  return new DefaultResidualVol(*this);
360  }
361 
362  template<typename Scalar>
363  DefaultResidualCurlCurl<Scalar>::DefaultResidualCurlCurl(int i, std::string area, Scalar const_coeff,
364  CubicSpline* c_spline,
365  GeomType gt)
366  : VectorFormVol<Scalar>(i),
367  idx_i(i), const_coeff(const_coeff), spline_coeff(c_spline), gt(gt)
368  {
369  this->set_area(area);
370 
371  // If spline is nullptr, initialize it to be constant 1.0.
372  if (c_spline == nullptr) this->spline_coeff = new CubicSpline(1.0);
373  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
374  };
375 
376  template<typename Scalar>
377  DefaultResidualCurlCurl<Scalar>::DefaultResidualCurlCurl(int i, std::vector<std::string> areas, Scalar const_coeff,
378  CubicSpline* c_spline,
379  GeomType gt)
380  : VectorFormVol<Scalar>(i),
381  idx_i(i), const_coeff(const_coeff), spline_coeff(c_spline), gt(gt)
382  {
383  this->set_areas(areas);
384 
385  // If spline is nullptr, initialize it to be constant 1.0.
386  if (c_spline == nullptr) this->spline_coeff = new CubicSpline(1.0);
387  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
388  }
389 
390  template<typename Scalar>
391  DefaultResidualCurlCurl<Scalar>::~DefaultResidualCurlCurl()
392  {
393  if (spline_coeff == nullptr) delete spline_coeff;
394  };
395 
396  template<typename Scalar>
397  Scalar DefaultResidualCurlCurl<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
398  GeomVol<double> *e, Func<Scalar> **ext) const
399  {
400  Func<Scalar>* u_prev = u_ext[idx_i];
401  Scalar result = 0;
402  if (gt == HERMES_PLANAR)
403  {
404  for (int i = 0; i < n; i++)
405  {
406  double mag0_i = std::abs(u_prev->val0[i]);
407  double mag1_i = std::abs(u_prev->val1[i]);
408  double mag_i = sqrt(sqr(mag0_i) + sqr(mag1_i));
409  result += wt[i] * const_coeff*spline_coeff->value(mag_i)
410  * (u_prev->curl[i] * conj(v->curl[i]));
411  }
412  }
413  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
414 
415  return result;
416  }
417 
418  template<typename Scalar>
419  Ord DefaultResidualCurlCurl<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v,
420  GeomVol<Ord> *e, Func<Ord> **ext) const
421  {
422  Func<Ord>* u_prev = u_ext[idx_i];
423  Ord result = Ord(0);
424  if (gt == HERMES_PLANAR)
425  {
426  for (int i = 0; i < n; i++)
427  {
428  Ord mag0_i = u_prev->val0[i];
429  Ord mag1_i = u_prev->val1[i];
430  Ord mag_i = sqrt(sqr(mag0_i) + sqr(mag1_i));
431  result += wt[i] * const_coeff*spline_coeff->value(mag_i)
432  * (u_prev->curl[i] * conj(v->curl[i]));
433  }
434  }
435  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
436 
437  return result;
438  }
439 
440  template<typename Scalar>
441  VectorFormVol<Scalar>* DefaultResidualCurlCurl<Scalar>::clone() const
442  {
443  return new DefaultResidualCurlCurl(*this);
444  }
445 
446  template<typename Scalar>
447  DefaultMatrixFormSurf<Scalar>::DefaultMatrixFormSurf(int i, int j, std::string area,
448  Scalar const_coeff, Hermes2DFunction<Scalar>* f_coeff,
449  GeomType gt)
450  : MatrixFormSurf<Scalar>(i, j), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
451  {
452  this->set_area(area);
453  // If f_coeff is nullptr, initialize it to be constant 1.0.
454  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
455  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
456  }
457 
458  template<typename Scalar>
459  DefaultMatrixFormSurf<Scalar>::DefaultMatrixFormSurf(int i, int j, std::vector<std::string> areas,
460  Scalar const_coeff, Hermes2DFunction<Scalar>* f_coeff,
461  GeomType gt)
462  : MatrixFormSurf<Scalar>(i, j), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
463  {
464  this->set_areas(areas);
465  // If f_coeff is nullptr, initialize it to be constant 1.0.
466  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
467  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
468  }
469 
470  template<typename Scalar>
471  DefaultMatrixFormSurf<Scalar>::~DefaultMatrixFormSurf()
472  {
473  if (function_coeff == nullptr) delete function_coeff;
474  };
475 
476  template<typename Scalar>
477  Scalar DefaultMatrixFormSurf<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
478  GeomSurf<double> *e, Func<Scalar> **ext) const
479  {
480  Scalar result = 0;
481  if (gt == HERMES_PLANAR)
482  {
483  result = const_coeff * int_e_tau_f_tau<double, Scalar>(n, wt, u, v, e);
484  }
485  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemnted yet.");
486 
487  return result;
488  }
489 
490  template<typename Scalar>
491  Ord DefaultMatrixFormSurf<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *u,
492  Func<Ord> *v, GeomSurf<Ord> *e, Func<Ord> **ext) const
493  {
494  Ord result = Ord(0);
495  if (gt == HERMES_PLANAR)
496  {
497  result = const_coeff * int_e_tau_f_tau<Ord, Ord>(n, wt, u, v, e);
498  }
499  else
500  throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemnted yet.");
501 
502  return result;
503  }
504 
505  template<typename Scalar>
506  MatrixFormSurf<Scalar>* DefaultMatrixFormSurf<Scalar>::clone() const
507  {
508  return new DefaultMatrixFormSurf<Scalar>(*this);
509  }
510 
511  template<typename Scalar>
512  DefaultResidualSurf<Scalar>::DefaultResidualSurf(int i, std::string area,
513  Scalar const_coeff, Hermes2DFunction<Scalar>* f_coeff,
514  GeomType gt)
515  : VectorFormSurf<Scalar>(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
516  {
517  this->set_area(area);
518  // If f_coeff is nullptr, initialize it to be constant 1.0.
519  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
520  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
521  }
522 
523  template<typename Scalar>
524  DefaultResidualSurf<Scalar>::DefaultResidualSurf(int i, std::vector<std::string> areas,
525  Scalar const_coeff, Hermes2DFunction<Scalar>* f_coeff,
526  GeomType gt)
527  : VectorFormSurf<Scalar>(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
528  {
529  // If f_coeff is nullptr, initialize it to be constant 1.0.
530  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
531  else throw Hermes::Exceptions::Exception("Nonconstant functions in Hcurl forms not implemented yet.");
532  }
533 
534  template<typename Scalar>
535  DefaultResidualSurf<Scalar>::~DefaultResidualSurf()
536  {
537  if (function_coeff == nullptr) delete function_coeff;
538  };
539 
540  template<typename Scalar>
541  Scalar DefaultResidualSurf<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
542  GeomSurf<double> *e, Func<Scalar> **ext) const
543  {
544  Scalar result = 0;
545  if (gt == HERMES_PLANAR)
546  {
547  for (int i = 0; i < n; i++)
548  result += wt[i] * ((u_ext[0]->val0[i] * e->tx[i] + u_ext[0]->val1[i] * e->ty[i]) *
549  conj(v->val0[i] * e->tx[i] + v->val1[i] * e->ty[i]));
550  result *= const_coeff;
551  }
552  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemnted yet.");
553 
554  return result;
555  }
556 
557  template<typename Scalar>
558  Ord DefaultResidualSurf<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[],
559  Func<Ord> *v, GeomSurf<Ord> *e, Func<Ord> **ext) const
560  {
561  Ord result = Ord(0);
562  if (gt == HERMES_PLANAR)
563  {
564  for (int i = 0; i < n; i++)
565  result += wt[i] * ((u_ext[0]->val0[i] * e->tx[i] + u_ext[0]->val1[i] * e->ty[i]) *
566  conj(v->val0[i] * e->tx[i] + v->val1[i] * e->ty[i]));
567  }
568  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemnted yet.");
569 
570  return result;
571  }
572 
573  template<typename Scalar>
574  VectorFormSurf<Scalar>* DefaultResidualSurf<Scalar>::clone() const
575  {
576  return new DefaultResidualSurf(*this);
577  }
578 
579  template<typename Scalar>
580  DefaultVectorFormSurf<Scalar>::DefaultVectorFormSurf(int i, std::string area, Scalar const_coeff,
581  Hermes2DFunction<Scalar>* f_coeff,
582  GeomType gt)
583  : VectorFormSurf<Scalar>(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
584  {
585  this->set_area(area);
586  // If f_coeff is nullptr, initialize it to be constant 1.0.
587  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
588  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
589  }
590 
591  template<typename Scalar>
592  DefaultVectorFormSurf<Scalar>::DefaultVectorFormSurf(int i, std::vector<std::string> areas, Scalar const_coeff,
593  Hermes2DFunction<Scalar>* f_coeff,
594  GeomType gt)
595  : VectorFormSurf<Scalar>(i), const_coeff(const_coeff), function_coeff(f_coeff), gt(gt)
596  {
597  this->set_areas(areas);
598  // If f_coeff is nullptr, initialize it to be constant 1.0.
599  if (f_coeff == nullptr) this->function_coeff = new Hermes2DFunction<Scalar>(1.0);
600  else throw Hermes::Exceptions::Exception("Nonconstant coefficients in Hcurl forms not implemented yet.");
601  }
602 
603  template<typename Scalar>
604  DefaultVectorFormSurf<Scalar>::~DefaultVectorFormSurf()
605  {
606  if (function_coeff == nullptr) delete function_coeff;
607  };
608 
609  template<typename Scalar>
610  Scalar DefaultVectorFormSurf<Scalar>::value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
611  GeomSurf<double> *e, Func<Scalar> **ext) const
612  {
613  Scalar result = 0;
614  if (gt == HERMES_PLANAR)
615  {
616  for (int i = 0; i < n; i++)
617  {
618  result += wt[i] * conj(v->val0[i] * e->tx[i] + v->val1[i] * e->ty[i]);
619  }
620  }
621  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
622 
623  return result;
624  }
625 
626  template<typename Scalar>
627  Ord DefaultVectorFormSurf<Scalar>::ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v,
628  GeomSurf<Ord> *e, Func<Ord> **ext) const
629  {
630  Ord result = Ord(0);
631  if (gt == HERMES_PLANAR)
632  {
633  for (int i = 0; i < n; i++)
634  {
635  result += wt[i] * conj(v->val0[i] * e->tx[i] + v->val1[i] * e->ty[i]);
636  }
637  }
638  else throw Hermes::Exceptions::Exception("Axisymmetric Hcurl forms not implemented yet.");
639 
640  return result;
641  }
642 
643  template<typename Scalar>
644  VectorFormSurf<Scalar>* DefaultVectorFormSurf<Scalar>::clone() const
645  {
646  return new DefaultVectorFormSurf<Scalar>(*this);
647  }
648 
649  template class HERMES_API DefaultJacobianCurlCurl < double > ;
650  template class HERMES_API DefaultJacobianCurlCurl < std::complex<double> > ;
651  template class HERMES_API DefaultMatrixFormVol < double > ;
652  template class HERMES_API DefaultMatrixFormVol < std::complex<double> > ;
653  template class HERMES_API DefaultVectorFormVol < double > ;
654  template class HERMES_API DefaultVectorFormVol < std::complex<double> > ;
655  template class HERMES_API DefaultResidualVol < double > ;
656  template class HERMES_API DefaultResidualVol < std::complex<double> > ;
657  template class HERMES_API DefaultResidualCurlCurl < double > ;
658  template class HERMES_API DefaultResidualCurlCurl < std::complex<double> > ;
659  template class HERMES_API DefaultMatrixFormSurf < double > ;
660  template class HERMES_API DefaultMatrixFormSurf < std::complex<double> > ;
661  template class HERMES_API DefaultVectorFormSurf < double > ;
662  template class HERMES_API DefaultVectorFormSurf < std::complex<double> > ;
663  template class HERMES_API DefaultResidualSurf < double > ;
664  template class HERMES_API DefaultResidualSurf < std::complex<double> > ;
665  };
666  }
667 }
Definition: adapt.h:24
SymFlag
Bilinear form symmetry flag, see WeakForm::add_matrix_form.
Definition: global.h:156
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
GeomType
Geometrical type of weak forms.
Definition: global.h:148