MFEM  v3.4 Finite element discretization library
fe.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11
12 // Finite Element classes
13
14 #include "fe.hpp"
15 #include "fe_coll.hpp"
16 #include "../mesh/nurbs.hpp"
17 #include "bilininteg.hpp"
18 #include <cmath>
19
20 namespace mfem
21 {
22
23 using namespace std;
24
25 FiniteElement::FiniteElement(int D, int G, int Do, int O, int F)
26  : Nodes(Do)
27 {
28  Dim = D ; GeomType = G ; Dof = Do ; Order = O ; FuncSpace = F;
29  RangeType = SCALAR;
30  MapType = VALUE;
31  DerivType = NONE;
34  for (int i = 0; i < Geometry::MaxDim; i++) { Orders[i] = -1; }
37 #endif
38 }
39
41  const IntegrationPoint &ip, DenseMatrix &shape) const
42 {
43  mfem_error ("FiniteElement::CalcVShape (ip, ...)\n"
44  " is not implemented for this class!");
45 }
46
49 {
50  mfem_error ("FiniteElement::CalcVShape (trans, ...)\n"
51  " is not implemented for this class!");
52 }
53
55  const IntegrationPoint &ip, Vector &divshape) const
56 {
57  mfem_error ("FiniteElement::CalcDivShape (ip, ...)\n"
58  " is not implemented for this class!");
59 }
60
62  ElementTransformation &Trans, Vector &div_shape) const
63 {
64  CalcDivShape(Trans.GetIntPoint(), div_shape);
65  div_shape *= (1.0 / Trans.Weight());
66 }
67
69  DenseMatrix &curl_shape) const
70 {
71  mfem_error ("FiniteElement::CalcCurlShape (ip, ...)\n"
72  " is not implemented for this class!");
73 }
74
76  DenseMatrix &curl_shape) const
77 {
78  switch (Dim)
79  {
80  case 3:
81  {
84 #endif
86  MultABt(vshape, Trans.Jacobian(), curl_shape);
87  curl_shape *= (1.0 / Trans.Weight());
88  break;
89  }
90  case 2:
91  // This is valid for both 2x2 and 3x2 Jacobians
92  CalcCurlShape(Trans.GetIntPoint(), curl_shape);
93  curl_shape *= (1.0 / Trans.Weight());
94  break;
95  default:
96  MFEM_ABORT("Invalid dimension, Dim = " << Dim);
97  }
98 }
99
100 void FiniteElement::GetFaceDofs(int face, int **dofs, int *ndofs) const
101 {
102  mfem_error ("FiniteElement::GetFaceDofs (...)");
103 }
104
106  DenseMatrix &h) const
107 {
108  mfem_error ("FiniteElement::CalcHessian (...) is not overloaded !");
109 }
110
112  DenseMatrix &I) const
113 {
114  mfem_error ("GetLocalInterpolation (...) is not overloaded !");
115 }
116
119  DenseMatrix &I) const
120 {
121  MFEM_ABORT("method is not overloaded !");
122 }
123
125  Coefficient &coeff, ElementTransformation &Trans, Vector &dofs) const
126 {
127  mfem_error ("FiniteElement::Project (...) is not overloaded !");
128 }
129
132 {
133  mfem_error ("FiniteElement::Project (...) (vector) is not overloaded !");
134 }
135
137  MatrixCoefficient &mc, ElementTransformation &T, Vector &dofs) const
138 {
139  mfem_error("FiniteElement::ProjectMatrixCoefficient() is not overloaded !");
140 }
141
142 void FiniteElement::ProjectDelta(int vertex, Vector &dofs) const
143 {
144  mfem_error("FiniteElement::ProjectDelta(...) is not implemented for "
145  "this element!");
146 }
147
150 {
151  mfem_error("FiniteElement::Project(...) (fe version) is not implemented "
152  "for this element!");
153 }
154
157  DenseMatrix &grad) const
158 {
159  mfem_error("FiniteElement::ProjectGrad(...) is not implemented for "
160  "this element!");
161 }
162
165  DenseMatrix &curl) const
166 {
167  mfem_error("FiniteElement::ProjectCurl(...) is not implemented for "
168  "this element!");
169 }
170
173  DenseMatrix &div) const
174 {
175  mfem_error("FiniteElement::ProjectDiv(...) is not implemented for "
176  "this element!");
177 }
178
180  Vector &shape) const
181 {
182  CalcShape(Trans.GetIntPoint(), shape);
183  if (MapType == INTEGRAL)
184  {
185  shape /= Trans.Weight();
186  }
187 }
188
190  DenseMatrix &dshape) const
191 {
192  MFEM_ASSERT(MapType == VALUE, "");
195 #endif
196  CalcDShape(Trans.GetIntPoint(), vshape);
197  Mult(vshape, Trans.InverseJacobian(), dshape);
198 }
199
200
203  const ScalarFiniteElement &fine_fe) const
204 {
205  double v[Geometry::MaxDim];
206  Vector vv (v, Dim);
207  IntegrationPoint f_ip;
208
210  Vector c_shape(Dof);
211 #endif
212
213  MFEM_ASSERT(MapType == fine_fe.GetMapType(), "");
214
215  I.SetSize(fine_fe.Dof, Dof);
216  for (int i = 0; i < fine_fe.Dof; i++)
217  {
218  Trans.Transform(fine_fe.Nodes.IntPoint(i), vv);
219  f_ip.Set(v, Dim);
220  CalcShape(f_ip, c_shape);
221  for (int j = 0; j < Dof; j++)
222  if (fabs(I(i,j) = c_shape(j)) < 1.0e-12)
223  {
224  I(i,j) = 0.0;
225  }
226  }
227  if (MapType == INTEGRAL)
228  {
229  // assuming Trans is linear; this should be ok for all refinement types
231  I *= Trans.Weight();
232  }
233 }
234
237  const ScalarFiniteElement &fine_fe) const
238 {
239  // General "interpolation", defined by L2 projection
240
241  double v[Geometry::MaxDim];
242  Vector vv (v, Dim);
243  IntegrationPoint f_ip;
244
245  const int fs = fine_fe.GetDof(), cs = this->GetDof();
246  I.SetSize(fs, cs);
247  Vector fine_shape(fs), coarse_shape(cs);
248  DenseMatrix fine_mass(fs), fine_coarse_mass(fs, cs); // initialized with 0
249  const int ir_order = GetOrder() + fine_fe.GetOrder();
250  const IntegrationRule &ir = IntRules.Get(fine_fe.GetGeomType(), ir_order);
251
252  for (int i = 0; i < ir.GetNPoints(); i++)
253  {
254  const IntegrationPoint &ip = ir.IntPoint(i);
255  fine_fe.CalcShape(ip, fine_shape);
256  Trans.Transform(ip, vv);
257  f_ip.Set(v, Dim);
258  this->CalcShape(f_ip, coarse_shape);
259
260  AddMult_a_VVt(ip.weight, fine_shape, fine_mass);
261  AddMult_a_VWt(ip.weight, fine_shape, coarse_shape, fine_coarse_mass);
262  }
263
264  DenseMatrixInverse fine_mass_inv(fine_mass);
265  fine_mass_inv.Mult(fine_coarse_mass, I);
266
267  if (MapType == INTEGRAL)
268  {
269  // assuming Trans is linear; this should be ok for all refinement types
271  I *= Trans.Weight();
272  }
273 }
274
275
278  DenseMatrix &curl) const
279 {
280  MFEM_ASSERT(GetMapType() == FiniteElement::INTEGRAL, "");
281
282  DenseMatrix curl_shape(fe.GetDof(), 1);
283
284  curl.SetSize(Dof, fe.GetDof());
285  for (int i = 0; i < Dof; i++)
286  {
287  fe.CalcCurlShape(Nodes.IntPoint(i), curl_shape);
288  for (int j = 0; j < fe.GetDof(); j++)
289  {
290  curl(i,j) = curl_shape(j,0);
291  }
292  }
293 }
294
296  Coefficient &coeff, ElementTransformation &Trans, Vector &dofs) const
297 {
298  for (int i = 0; i < Dof; i++)
299  {
300  const IntegrationPoint &ip = Nodes.IntPoint(i);
301  // some coefficients expect that Trans.IntPoint is the same
302  // as the second argument of Eval
303  Trans.SetIntPoint(&ip);
304  dofs(i) = coeff.Eval (Trans, ip);
305  if (MapType == INTEGRAL)
306  {
307  dofs(i) *= Trans.Weight();
308  }
309  }
310 }
311
314 {
315  MFEM_ASSERT(dofs.Size() == vc.GetVDim()*Dof, "");
316  Vector x(vc.GetVDim());
317
318  for (int i = 0; i < Dof; i++)
319  {
320  const IntegrationPoint &ip = Nodes.IntPoint(i);
321  Trans.SetIntPoint(&ip);
322  vc.Eval (x, Trans, ip);
323  if (MapType == INTEGRAL)
324  {
325  x *= Trans.Weight();
326  }
327  for (int j = 0; j < x.Size(); j++)
328  {
329  dofs(Dof*j+i) = x(j);
330  }
331  }
332 }
333
335  MatrixCoefficient &mc, ElementTransformation &T, Vector &dofs) const
336 {
337  // (mc.height x mc.width) @ DOFs -> (Dof x mc.width x mc.height) in dofs
338  MFEM_ASSERT(dofs.Size() == mc.GetHeight()*mc.GetWidth()*Dof, "");
339  DenseMatrix MQ(mc.GetHeight(), mc.GetWidth());
340
341  for (int k = 0; k < Dof; k++)
342  {
343  T.SetIntPoint(&Nodes.IntPoint(k));
344  mc.Eval(MQ, T, Nodes.IntPoint(k));
345  if (MapType == INTEGRAL) { MQ *= T.Weight(); }
346  for (int r = 0; r < MQ.Height(); r++)
347  {
348  for (int d = 0; d < MQ.Width(); d++)
349  {
350  dofs(k+Dof*(d+MQ.Width()*r)) = MQ(r,d);
351  }
352  }
353  }
354 }
355
358 {
359  if (fe.GetRangeType() == SCALAR)
360  {
361  MFEM_ASSERT(MapType == fe.GetMapType(), "");
362
363  Vector shape(fe.GetDof());
364
365  I.SetSize(Dof, fe.GetDof());
366  for (int k = 0; k < Dof; k++)
367  {
368  fe.CalcShape(Nodes.IntPoint(k), shape);
369  for (int j = 0; j < shape.Size(); j++)
370  {
371  I(k,j) = (fabs(shape(j)) < 1e-12) ? 0.0 : shape(j);
372  }
373  }
374  }
375  else
376  {
377  DenseMatrix vshape(fe.GetDof(), Trans.GetSpaceDim());
378
379  I.SetSize(vshape.Width()*Dof, fe.GetDof());
380  for (int k = 0; k < Dof; k++)
381  {
382  Trans.SetIntPoint(&Nodes.IntPoint(k));
383  fe.CalcVShape(Trans, vshape);
384  if (MapType == INTEGRAL)
385  {
386  vshape *= Trans.Weight();
387  }
388  for (int j = 0; j < vshape.Height(); j++)
389  for (int d = 0; d < vshape.Width(); d++)
390  {
391  I(k+d*Dof,j) = vshape(j,d);
392  }
393  }
394  }
395 }
396
399  DenseMatrix &grad) const
400 {
401  MFEM_ASSERT(fe.GetMapType() == VALUE, "");
402  MFEM_ASSERT(Trans.GetSpaceDim() == Dim, "")
403
404  DenseMatrix dshape(fe.GetDof(), Dim), grad_k(fe.GetDof(), Dim), Jinv(Dim);
405
407  for (int k = 0; k < Dof; k++)
408  {
409  const IntegrationPoint &ip = Nodes.IntPoint(k);
410  fe.CalcDShape(ip, dshape);
411  Trans.SetIntPoint(&ip);
412  CalcInverse(Trans.Jacobian(), Jinv);
413  Mult(dshape, Jinv, grad_k);
414  if (MapType == INTEGRAL)
415  {
416  grad_k *= Trans.Weight();
417  }
418  for (int j = 0; j < grad_k.Height(); j++)
419  for (int d = 0; d < Dim; d++)
420  {
422  }
423  }
424 }
425
428  DenseMatrix &div) const
429 {
430  double detJ;
431  Vector div_shape(fe.GetDof());
432
433  div.SetSize(Dof, fe.GetDof());
434  for (int k = 0; k < Dof; k++)
435  {
436  const IntegrationPoint &ip = Nodes.IntPoint(k);
437  fe.CalcDivShape(ip, div_shape);
438  if (MapType == VALUE)
439  {
440  Trans.SetIntPoint(&ip);
441  detJ = Trans.Weight();
442  for (int j = 0; j < div_shape.Size(); j++)
443  {
444  div(k,j) = (fabs(div_shape(j)) < 1e-12) ? 0.0 : div_shape(j)/detJ;
445  }
446  }
447  else
448  {
449  for (int j = 0; j < div_shape.Size(); j++)
450  {
451  div(k,j) = (fabs(div_shape(j)) < 1e-12) ? 0.0 : div_shape(j);
452  }
453  }
454  }
455 }
456
457
459  Coefficient &coeff, ElementTransformation &Trans, Vector &dofs) const
460 {
461  for (int i = 0; i < Dof; i++)
462  {
463  const IntegrationPoint &ip = Nodes.IntPoint(i);
464  Trans.SetIntPoint(&ip);
465  dofs(i) = coeff.Eval(Trans, ip);
466  }
467 }
468
471 {
472  const NodalFiniteElement *nfe =
473  dynamic_cast<const NodalFiniteElement *>(&fe);
474
475  if (nfe && Dof == nfe->GetDof())
476  {
477  nfe->Project(*this, Trans, I);
478  I.Invert();
479  }
480  else
481  {
482  // local L2 projection
483  DenseMatrix pos_mass, mixed_mass;
484  MassIntegrator mass_integ;
485
486  mass_integ.AssembleElementMatrix(*this, Trans, pos_mass);
487  mass_integ.AssembleElementMatrix2(fe, *this, Trans, mixed_mass);
488
489  DenseMatrixInverse pos_mass_inv(pos_mass);
490  I.SetSize(Dof, fe.GetDof());
491  pos_mass_inv.Mult(mixed_mass, I);
492  }
493 }
494
495
496 void VectorFiniteElement::CalcShape (
497  const IntegrationPoint &ip, Vector &shape ) const
498 {
499  mfem_error ("Error: Cannot use scalar CalcShape(...) function with\n"
500  " VectorFiniteElements!");
501 }
502
503 void VectorFiniteElement::CalcDShape (
504  const IntegrationPoint &ip, DenseMatrix &dshape ) const
505 {
506  mfem_error ("Error: Cannot use scalar CalcDShape(...) function with\n"
507  " VectorFiniteElements!");
508 }
509
511 {
512  switch (MapType)
513  {
514  case H_DIV:
515  DerivType = DIV;
518  break;
519  case H_CURL:
520  switch (Dim)
521  {
522  case 3: // curl: 3D H_CURL -> 3D H_DIV
523  DerivType = CURL;
526  break;
527  case 2:
528  // curl: 2D H_CURL -> INTEGRAL
529  DerivType = CURL;
532  break;
533  case 1:
534  DerivType = NONE;
537  break;
538  default:
539  MFEM_ABORT("Invalid dimension, Dim = " << Dim);
540  }
541  break;
542  default:
543  MFEM_ABORT("Invalid MapType = " << MapType);
544  }
545 }
546
548  ElementTransformation &Trans, DenseMatrix &shape) const
549 {
550  MFEM_ASSERT(MapType == H_DIV, "");
553 #endif
554  CalcVShape(Trans.GetIntPoint(), vshape);
555  MultABt(vshape, Trans.Jacobian(), shape);
556  shape *= (1.0 / Trans.Weight());
557 }
558
560  ElementTransformation &Trans, DenseMatrix &shape) const
561 {
562  MFEM_ASSERT(MapType == H_CURL, "");
565 #endif
566  CalcVShape(Trans.GetIntPoint(), vshape);
567  Mult(vshape, Trans.InverseJacobian(), shape);
568 }
569
571  const double *nk, const Array<int> &d2n,
573 {
574  double vk[Geometry::MaxDim];
575  const int sdim = Trans.GetSpaceDim();
576  MFEM_ASSERT(vc.GetVDim() == sdim, "");
577  Vector xk(vk, sdim);
578  const bool square_J = (Dim == sdim);
579
580  for (int k = 0; k < Dof; k++)
581  {
582  Trans.SetIntPoint(&Nodes.IntPoint(k));
583  vc.Eval(xk, Trans, Nodes.IntPoint(k));
584  // dof_k = nk^t adj(J) xk
585  dofs(k) = Trans.AdjugateJacobian().InnerProduct(vk, nk + d2n[k]*Dim);
586  if (!square_J) { dofs(k) /= Trans.Weight(); }
587  }
588 }
589
591  const double *nk, const Array<int> &d2n,
592  MatrixCoefficient &mc, ElementTransformation &T, Vector &dofs) const
593 {
594  // project the rows of the matrix coefficient in an RT space
595
596  const int sdim = T.GetSpaceDim();
597  MFEM_ASSERT(mc.GetWidth() == sdim, "");
598  const bool square_J = (Dim == sdim);
599  DenseMatrix MQ(mc.GetHeight(), mc.GetWidth());
600  Vector nk_phys(sdim), dofs_k(MQ.Height());
601  MFEM_ASSERT(dofs.Size() == Dof*MQ.Height(), "");
602
603  for (int k = 0; k < Dof; k++)
604  {
605  T.SetIntPoint(&Nodes.IntPoint(k));
606  mc.Eval(MQ, T, Nodes.IntPoint(k));
607  // nk_phys = adj(J)^t nk
608  T.AdjugateJacobian().MultTranspose(nk + d2n[k]*Dim, nk_phys);
609  if (!square_J) { nk_phys /= T.Weight(); }
610  MQ.Mult(nk_phys, dofs_k);
611  for (int r = 0; r < MQ.Height(); r++)
612  {
613  dofs(k+Dof*r) = dofs_k(r);
614  }
615  }
616 }
617
619  const double *nk, const Array<int> &d2n, const FiniteElement &fe,
621 {
622  if (fe.GetRangeType() == SCALAR)
623  {
624  double vk[Geometry::MaxDim];
625  Vector shape(fe.GetDof());
626  int sdim = Trans.GetSpaceDim();
627
628  I.SetSize(Dof, sdim*fe.GetDof());
629  for (int k = 0; k < Dof; k++)
630  {
631  const IntegrationPoint &ip = Nodes.IntPoint(k);
632
633  fe.CalcShape(ip, shape);
634  Trans.SetIntPoint(&ip);
635  Trans.AdjugateJacobian().MultTranspose(nk + d2n[k]*Dim, vk);
636  if (fe.GetMapType() == INTEGRAL)
637  {
638  double w = 1.0/Trans.Weight();
639  for (int d = 0; d < Dim; d++)
640  {
641  vk[d] *= w;
642  }
643  }
644
645  for (int j = 0; j < shape.Size(); j++)
646  {
647  double s = shape(j);
648  if (fabs(s) < 1e-12)
649  {
650  s = 0.0;
651  }
652  for (int d = 0; d < sdim; d++)
653  {
654  I(k,j+d*shape.Size()) = s*vk[d];
655  }
656  }
657  }
658  }
659  else
660  {
661  mfem_error("VectorFiniteElement::Project_RT (fe version)");
662  }
663 }
664
666  const double *nk, const Array<int> &d2n, const FiniteElement &fe,
668 {
669  if (Dim != 2)
670  {
671  mfem_error("VectorFiniteElement::ProjectGrad_RT works only in 2D!");
672  }
673
674  DenseMatrix dshape(fe.GetDof(), fe.GetDim());
676  double tk[2];
677
679  for (int k = 0; k < Dof; k++)
680  {
681  fe.CalcDShape(Nodes.IntPoint(k), dshape);
682  tk[0] = nk[d2n[k]*Dim+1];
683  tk[1] = -nk[d2n[k]*Dim];
685  for (int j = 0; j < grad_k.Size(); j++)
686  {
687  grad(k,j) = (fabs(grad_k(j)) < 1e-12) ? 0.0 : grad_k(j);
688  }
689  }
690 }
691
693  const double *tk, const Array<int> &d2t, const FiniteElement &fe,
695 {
699  DenseMatrix J(Dim, Dim);
700 #else
701  curlshape.SetSize(fe.GetDof(), Dim);
702  curlshape_J.SetSize(fe.GetDof(), Dim);
703  J.SetSize(Dim, Dim);
704 #endif
705
706  Vector curl_k(fe.GetDof());
707
708  curl.SetSize(Dof, fe.GetDof());
709  for (int k = 0; k < Dof; k++)
710  {
711  const IntegrationPoint &ip = Nodes.IntPoint(k);
712
713  // calculate J^t * J / |J|
714  Trans.SetIntPoint(&ip);
715  MultAtB(Trans.Jacobian(), Trans.Jacobian(), J);
716  J *= 1.0 / Trans.Weight();
717
718  // transform curl of shapes (rows) by J^t * J / |J|
719  fe.CalcCurlShape(ip, curlshape);
721
722  curlshape_J.Mult(tk + d2t[k]*Dim, curl_k);
723  for (int j = 0; j < curl_k.Size(); j++)
724  {
725  curl(k,j) = (fabs(curl_k(j)) < 1e-12) ? 0.0 : curl_k(j);
726  }
727  }
728 }
729
731  const double *nk, const Array<int> &d2n, const FiniteElement &fe,
733 {
734  DenseMatrix curl_shape(fe.GetDof(), Dim);
735  Vector curl_k(fe.GetDof());
736
737  curl.SetSize(Dof, fe.GetDof());
738  for (int k = 0; k < Dof; k++)
739  {
740  fe.CalcCurlShape(Nodes.IntPoint(k), curl_shape);
741  curl_shape.Mult(nk + d2n[k]*Dim, curl_k);
742  for (int j = 0; j < curl_k.Size(); j++)
743  {
744  curl(k,j) = (fabs(curl_k(j)) < 1e-12) ? 0.0 : curl_k(j);
745  }
746  }
747 }
748
750  const double *tk, const Array<int> &d2t,
752 {
753  double vk[Geometry::MaxDim];
754  Vector xk(vk, vc.GetVDim());
755
756  for (int k = 0; k < Dof; k++)
757  {
758  Trans.SetIntPoint(&Nodes.IntPoint(k));
759
760  vc.Eval(xk, Trans, Nodes.IntPoint(k));
761  // dof_k = xk^t J tk
762  dofs(k) = Trans.Jacobian().InnerProduct(tk + d2t[k]*Dim, vk);
763  }
764 }
765
767  const double *tk, const Array<int> &d2t,
768  MatrixCoefficient &mc, ElementTransformation &T, Vector &dofs) const
769 {
770  // project the rows of the matrix coefficient in an ND space
771
772  const int sdim = T.GetSpaceDim();
773  MFEM_ASSERT(mc.GetWidth() == sdim, "");
774  DenseMatrix MQ(mc.GetHeight(), mc.GetWidth());
775  Vector tk_phys(sdim), dofs_k(MQ.Height());
776  MFEM_ASSERT(dofs.Size() == Dof*MQ.Height(), "");
777
778  for (int k = 0; k < Dof; k++)
779  {
780  T.SetIntPoint(&Nodes.IntPoint(k));
781  mc.Eval(MQ, T, Nodes.IntPoint(k));
782  // tk_phys = J tk
783  T.Jacobian().Mult(tk + d2t[k]*Dim, tk_phys);
784  MQ.Mult(tk_phys, dofs_k);
785  for (int r = 0; r < MQ.Height(); r++)
786  {
787  dofs(k+Dof*r) = dofs_k(r);
788  }
789  }
790 }
791
793  const double *tk, const Array<int> &d2t, const FiniteElement &fe,
795 {
796  if (fe.GetRangeType() == SCALAR)
797  {
798  int sdim = Trans.GetSpaceDim();
799  double vk[Geometry::MaxDim];
800  Vector shape(fe.GetDof());
801
802  I.SetSize(Dof, sdim*fe.GetDof());
803  for (int k = 0; k < Dof; k++)
804  {
805  const IntegrationPoint &ip = Nodes.IntPoint(k);
806
807  fe.CalcShape(ip, shape);
808  Trans.SetIntPoint(&ip);
809  Trans.Jacobian().Mult(tk + d2t[k]*Dim, vk);
810  if (fe.GetMapType() == INTEGRAL)
811  {
812  double w = 1.0/Trans.Weight();
813  for (int d = 0; d < sdim; d++)
814  {
815  vk[d] *= w;
816  }
817  }
818
819  for (int j = 0; j < shape.Size(); j++)
820  {
821  double s = shape(j);
822  if (fabs(s) < 1e-12)
823  {
824  s = 0.0;
825  }
826  for (int d = 0; d < sdim; d++)
827  {
828  I(k, j + d*shape.Size()) = s*vk[d];
829  }
830  }
831  }
832  }
833  else
834  {
835  mfem_error("VectorFiniteElement::Project_ND (fe version)");
836  }
837 }
838
840  const double *tk, const Array<int> &d2t, const FiniteElement &fe,
842 {
843  MFEM_ASSERT(fe.GetMapType() == VALUE, "");
844
845  DenseMatrix dshape(fe.GetDof(), fe.GetDim());
847
849  for (int k = 0; k < Dof; k++)
850  {
851  fe.CalcDShape(Nodes.IntPoint(k), dshape);
852  dshape.Mult(tk + d2t[k]*Dim, grad_k);
853  for (int j = 0; j < grad_k.Size(); j++)
854  {
855  grad(k,j) = (fabs(grad_k(j)) < 1e-12) ? 0.0 : grad_k(j);
856  }
857  }
858 }
859
861  const VectorFiniteElement &cfe, const double *nk, const Array<int> &d2n,
863 {
864  MFEM_ASSERT(MapType == cfe.GetMapType(), "");
865
866  double vk[Geometry::MaxDim];
867  Vector xk(vk, Dim);
868  IntegrationPoint ip;
870  DenseMatrix vshape(cfe.GetDof(), cfe.GetDim());
871 #else
872  DenseMatrix vshape(cfe.vshape.Data(), cfe.GetDof(), cfe.GetDim());
873 #endif
874  I.SetSize(Dof, vshape.Height());
875
876  // assuming Trans is linear; this should be ok for all refinement types
879  for (int k = 0; k < Dof; k++)
880  {
881  Trans.Transform(Nodes.IntPoint(k), xk);
882  ip.Set3(vk);
883  cfe.CalcVShape(ip, vshape);
884  // xk = |J| J^{-t} n_k
885  adjJ.MultTranspose(nk + d2n[k]*Dim, vk);
886  // I_k = vshape_k.adj(J)^t.n_k, k=1,...,Dof
887  for (int j = 0; j < vshape.Height(); j++)
888  {
889  double Ikj = 0.;
890  for (int i = 0; i < Dim; i++)
891  {
892  Ikj += vshape(j, i) * vk[i];
893  }
894  I(k, j) = (fabs(Ikj) < 1e-12) ? 0.0 : Ikj;
895  }
896  }
897 }
898
900  const VectorFiniteElement &cfe, const double *tk, const Array<int> &d2t,
902 {
903  double vk[Geometry::MaxDim];
904  Vector xk(vk, Dim);
905  IntegrationPoint ip;
907  DenseMatrix vshape(cfe.GetDof(), cfe.GetDim());
908 #else
909  DenseMatrix vshape(cfe.vshape.Data(), cfe.GetDof(), cfe.GetDim());
910 #endif
911  I.SetSize(Dof, vshape.Height());
912
913  // assuming Trans is linear; this should be ok for all refinement types
915  const DenseMatrix &J = Trans.Jacobian();
916  for (int k = 0; k < Dof; k++)
917  {
918  Trans.Transform(Nodes.IntPoint(k), xk);
919  ip.Set3(vk);
920  cfe.CalcVShape(ip, vshape);
921  // xk = J t_k
922  J.Mult(tk + d2t[k]*Dim, vk);
923  // I_k = vshape_k.J.t_k, k=1,...,Dof
924  for (int j = 0; j < vshape.Height(); j++)
925  {
926  double Ikj = 0.;
927  for (int i = 0; i < Dim; i++)
928  {
929  Ikj += vshape(j, i) * vk[i];
930  }
931  I(k, j) = (fabs(Ikj) < 1e-12) ? 0.0 : Ikj;
932  }
933  }
934 }
935
936
938  : NodalFiniteElement(0, Geometry::POINT, 1, 0)
939 {
940  Nodes.IntPoint(0).x = 0.0;
941 }
942
944  Vector &shape) const
945 {
946  shape(0) = 1.;
947 }
948
950  DenseMatrix &dshape) const
951 {
952  // dshape is (1 x 0) - nothing to compute
953 }
954
956  : NodalFiniteElement(1, Geometry::SEGMENT, 2, 1)
957 {
958  Nodes.IntPoint(0).x = 0.0;
959  Nodes.IntPoint(1).x = 1.0;
960 }
961
963  Vector &shape) const
964 {
965  shape(0) = 1. - ip.x;
966  shape(1) = ip.x;
967 }
968
970  DenseMatrix &dshape) const
971 {
972  dshape(0,0) = -1.;
973  dshape(1,0) = 1.;
974 }
975
977  : NodalFiniteElement(2, Geometry::TRIANGLE, 3, 1)
978 {
979  Nodes.IntPoint(0).x = 0.0;
980  Nodes.IntPoint(0).y = 0.0;
981  Nodes.IntPoint(1).x = 1.0;
982  Nodes.IntPoint(1).y = 0.0;
983  Nodes.IntPoint(2).x = 0.0;
984  Nodes.IntPoint(2).y = 1.0;
985 }
986
988  Vector &shape) const
989 {
990  shape(0) = 1. - ip.x - ip.y;
991  shape(1) = ip.x;
992  shape(2) = ip.y;
993 }
994
996  DenseMatrix &dshape) const
997 {
998  dshape(0,0) = -1.; dshape(0,1) = -1.;
999  dshape(1,0) = 1.; dshape(1,1) = 0.;
1000  dshape(2,0) = 0.; dshape(2,1) = 1.;
1001 }
1002
1004  : NodalFiniteElement(2, Geometry::SQUARE, 4, 1, FunctionSpace::Qk)
1005 {
1006  Nodes.IntPoint(0).x = 0.0;
1007  Nodes.IntPoint(0).y = 0.0;
1008  Nodes.IntPoint(1).x = 1.0;
1009  Nodes.IntPoint(1).y = 0.0;
1010  Nodes.IntPoint(2).x = 1.0;
1011  Nodes.IntPoint(2).y = 1.0;
1012  Nodes.IntPoint(3).x = 0.0;
1013  Nodes.IntPoint(3).y = 1.0;
1014 }
1015
1017  Vector &shape) const
1018 {
1019  shape(0) = (1. - ip.x) * (1. - ip.y) ;
1020  shape(1) = ip.x * (1. - ip.y) ;
1021  shape(2) = ip.x * ip.y ;
1022  shape(3) = (1. - ip.x) * ip.y ;
1023 }
1024
1026  DenseMatrix &dshape) const
1027 {
1028  dshape(0,0) = -1. + ip.y; dshape(0,1) = -1. + ip.x ;
1029  dshape(1,0) = 1. - ip.y; dshape(1,1) = -ip.x ;
1030  dshape(2,0) = ip.y ; dshape(2,1) = ip.x ;
1031  dshape(3,0) = -ip.y ; dshape(3,1) = 1. - ip.x ;
1032 }
1033
1035  const IntegrationPoint &ip, DenseMatrix &h) const
1036 {
1037  h(0,0) = 0.; h(0,1) = 1.; h(0,2) = 0.;
1038  h(1,0) = 0.; h(1,1) = -1.; h(1,2) = 0.;
1039  h(2,0) = 0.; h(2,1) = 1.; h(2,2) = 0.;
1040  h(3,0) = 0.; h(3,1) = -1.; h(3,2) = 0.;
1041 }
1042
1043
1045  : NodalFiniteElement(2, Geometry::TRIANGLE, 3, 1, FunctionSpace::Pk)
1046 {
1047  Nodes.IntPoint(0).x = 1./6.;
1048  Nodes.IntPoint(0).y = 1./6.;
1049  Nodes.IntPoint(1).x = 2./3.;
1050  Nodes.IntPoint(1).y = 1./6.;
1051  Nodes.IntPoint(2).x = 1./6.;
1052  Nodes.IntPoint(2).y = 2./3.;
1053 }
1054
1056  Vector &shape) const
1057 {
1058  const double x = ip.x, y = ip.y;
1059
1060  shape(0) = 5./3. - 2. * (x + y);
1061  shape(1) = 2. * (x - 1./6.);
1062  shape(2) = 2. * (y - 1./6.);
1063 }
1064
1066  DenseMatrix &dshape) const
1067 {
1068  dshape(0,0) = -2.; dshape(0,1) = -2.;
1069  dshape(1,0) = 2.; dshape(1,1) = 0.;
1070  dshape(2,0) = 0.; dshape(2,1) = 2.;
1071 }
1072
1074 {
1075  dofs(vertex) = 2./3.;
1076  dofs((vertex+1)%3) = 1./6.;
1077  dofs((vertex+2)%3) = 1./6.;
1078 }
1079
1080
1081 // 0.5-0.5/sqrt(3) and 0.5+0.5/sqrt(3)
1082 const double GaussBiLinear2DFiniteElement::p[] =
1083 { 0.2113248654051871177454256, 0.7886751345948128822545744 };
1084
1086  : NodalFiniteElement(2, Geometry::SQUARE, 4, 1, FunctionSpace::Qk)
1087 {
1088  Nodes.IntPoint(0).x = p[0];
1089  Nodes.IntPoint(0).y = p[0];
1090  Nodes.IntPoint(1).x = p[1];
1091  Nodes.IntPoint(1).y = p[0];
1092  Nodes.IntPoint(2).x = p[1];
1093  Nodes.IntPoint(2).y = p[1];
1094  Nodes.IntPoint(3).x = p[0];
1095  Nodes.IntPoint(3).y = p[1];
1096 }
1097
1099  Vector &shape) const
1100 {
1101  const double x = ip.x, y = ip.y;
1102
1103  shape(0) = 3. * (p[1] - x) * (p[1] - y);
1104  shape(1) = 3. * (x - p[0]) * (p[1] - y);
1105  shape(2) = 3. * (x - p[0]) * (y - p[0]);
1106  shape(3) = 3. * (p[1] - x) * (y - p[0]);
1107 }
1108
1110  DenseMatrix &dshape) const
1111 {
1112  const double x = ip.x, y = ip.y;
1113
1114  dshape(0,0) = 3. * (y - p[1]); dshape(0,1) = 3. * (x - p[1]);
1115  dshape(1,0) = 3. * (p[1] - y); dshape(1,1) = 3. * (p[0] - x);
1116  dshape(2,0) = 3. * (y - p[0]); dshape(2,1) = 3. * (x - p[0]);
1117  dshape(3,0) = 3. * (p[0] - y); dshape(3,1) = 3. * (p[1] - x);
1118 }
1119
1121 {
1122 #if 1
1123  dofs(vertex) = p[1]*p[1];
1124  dofs((vertex+1)%4) = p[0]*p[1];
1125  dofs((vertex+2)%4) = p[0]*p[0];
1126  dofs((vertex+3)%4) = p[0]*p[1];
1127 #else
1128  dofs = 1.0;
1129 #endif
1130 }
1131
1132
1134  : NodalFiniteElement(2, Geometry::SQUARE, 3, 1, FunctionSpace::Qk)
1135 {
1136  Nodes.IntPoint(0).x = 0.0;
1137  Nodes.IntPoint(0).y = 0.0;
1138  Nodes.IntPoint(1).x = 1.0;
1139  Nodes.IntPoint(1).y = 0.0;
1140  Nodes.IntPoint(2).x = 0.0;
1141  Nodes.IntPoint(2).y = 1.0;
1142 }
1143
1145  Vector &shape) const
1146 {
1147  shape(0) = 1. - ip.x - ip.y;
1148  shape(1) = ip.x;
1149  shape(2) = ip.y;
1150 }
1151
1153  DenseMatrix &dshape) const
1154 {
1155  dshape(0,0) = -1.; dshape(0,1) = -1.;
1156  dshape(1,0) = 1.; dshape(1,1) = 0.;
1157  dshape(2,0) = 0.; dshape(2,1) = 1.;
1158 }
1159
1160
1162  : NodalFiniteElement(1, Geometry::SEGMENT, 3, 2)
1163 {
1164  Nodes.IntPoint(0).x = 0.0;
1165  Nodes.IntPoint(1).x = 1.0;
1166  Nodes.IntPoint(2).x = 0.5;
1167 }
1168
1170  Vector &shape) const
1171 {
1172  double x = ip.x;
1173  double l1 = 1.0 - x, l2 = x, l3 = 2. * x - 1.;
1174
1175  shape(0) = l1 * (-l3);
1176  shape(1) = l2 * l3;
1177  shape(2) = 4. * l1 * l2;
1178 }
1179
1181  DenseMatrix &dshape) const
1182 {
1183  double x = ip.x;
1184
1185  dshape(0,0) = 4. * x - 3.;
1186  dshape(1,0) = 4. * x - 1.;
1187  dshape(2,0) = 4. - 8. * x;
1188 }
1189
1190
1192  : PositiveFiniteElement(1, Geometry::SEGMENT, 3, 2)
1193 {
1194  Nodes.IntPoint(0).x = 0.0;
1195  Nodes.IntPoint(1).x = 1.0;
1196  Nodes.IntPoint(2).x = 0.5;
1197 }
1198
1200  Vector &shape) const
1201 {
1202  const double x = ip.x, x1 = 1. - x;
1203
1204  shape(0) = x1 * x1;
1205  shape(1) = x * x;
1206  shape(2) = 2. * x * x1;
1207 }
1208
1210  DenseMatrix &dshape) const
1211 {
1212  const double x = ip.x;
1213
1214  dshape(0,0) = 2. * x - 2.;
1215  dshape(1,0) = 2. * x;
1216  dshape(2,0) = 2. - 4. * x;
1217 }
1218
1220  : NodalFiniteElement(2, Geometry::TRIANGLE, 6, 2)
1221 {
1222  Nodes.IntPoint(0).x = 0.0;
1223  Nodes.IntPoint(0).y = 0.0;
1224  Nodes.IntPoint(1).x = 1.0;
1225  Nodes.IntPoint(1).y = 0.0;
1226  Nodes.IntPoint(2).x = 0.0;
1227  Nodes.IntPoint(2).y = 1.0;
1228  Nodes.IntPoint(3).x = 0.5;
1229  Nodes.IntPoint(3).y = 0.0;
1230  Nodes.IntPoint(4).x = 0.5;
1231  Nodes.IntPoint(4).y = 0.5;
1232  Nodes.IntPoint(5).x = 0.0;
1233  Nodes.IntPoint(5).y = 0.5;
1234 }
1235
1237  Vector &shape) const
1238 {
1239  double x = ip.x, y = ip.y;
1240  double l1 = 1.-x-y, l2 = x, l3 = y;
1241
1242  shape(0) = l1 * (2. * l1 - 1.);
1243  shape(1) = l2 * (2. * l2 - 1.);
1244  shape(2) = l3 * (2. * l3 - 1.);
1245  shape(3) = 4. * l1 * l2;
1246  shape(4) = 4. * l2 * l3;
1247  shape(5) = 4. * l3 * l1;
1248 }
1249
1251  DenseMatrix &dshape) const
1252 {
1253  double x = ip.x, y = ip.y;
1254
1255  dshape(0,0) =
1256  dshape(0,1) = 4. * (x + y) - 3.;
1257
1258  dshape(1,0) = 4. * x - 1.;
1259  dshape(1,1) = 0.;
1260
1261  dshape(2,0) = 0.;
1262  dshape(2,1) = 4. * y - 1.;
1263
1264  dshape(3,0) = -4. * (2. * x + y - 1.);
1265  dshape(3,1) = -4. * x;
1266
1267  dshape(4,0) = 4. * y;
1268  dshape(4,1) = 4. * x;
1269
1270  dshape(5,0) = -4. * y;
1271  dshape(5,1) = -4. * (x + 2. * y - 1.);
1272 }
1273
1275  DenseMatrix &h) const
1276 {
1277  h(0,0) = 4.;
1278  h(0,1) = 4.;
1279  h(0,2) = 4.;
1280
1281  h(1,0) = 4.;
1282  h(1,1) = 0.;
1283  h(1,2) = 0.;
1284
1285  h(2,0) = 0.;
1286  h(2,1) = 0.;
1287  h(2,2) = 4.;
1288
1289  h(3,0) = -8.;
1290  h(3,1) = -4.;
1291  h(3,2) = 0.;
1292
1293  h(4,0) = 0.;
1294  h(4,1) = 4.;
1295  h(4,2) = 0.;
1296
1297  h(5,0) = 0.;
1298  h(5,1) = -4.;
1299  h(5,2) = -8.;
1300 }
1301
1302 void Quad2DFiniteElement::ProjectDelta(int vertex, Vector &dofs) const
1303 {
1304 #if 0
1305  dofs = 1.;
1306 #else
1307  dofs = 0.;
1308  dofs(vertex) = 1.;
1309  switch (vertex)
1310  {
1311  case 0: dofs(3) = 0.25; dofs(5) = 0.25; break;
1312  case 1: dofs(3) = 0.25; dofs(4) = 0.25; break;
1313  case 2: dofs(4) = 0.25; dofs(5) = 0.25; break;
1314  }
1315 #endif
1316 }
1317
1318
1319 const double GaussQuad2DFiniteElement::p[] =
1320 { 0.0915762135097707434595714634022015, 0.445948490915964886318329253883051 };
1321
1323  : NodalFiniteElement(2, Geometry::TRIANGLE, 6, 2), A(6), D(6,2), pol(6)
1324 {
1325  Nodes.IntPoint(0).x = p[0];
1326  Nodes.IntPoint(0).y = p[0];
1327  Nodes.IntPoint(1).x = 1. - 2. * p[0];
1328  Nodes.IntPoint(1).y = p[0];
1329  Nodes.IntPoint(2).x = p[0];
1330  Nodes.IntPoint(2).y = 1. - 2. * p[0];
1331  Nodes.IntPoint(3).x = p[1];
1332  Nodes.IntPoint(3).y = p[1];
1333  Nodes.IntPoint(4).x = 1. - 2. * p[1];
1334  Nodes.IntPoint(4).y = p[1];
1335  Nodes.IntPoint(5).x = p[1];
1336  Nodes.IntPoint(5).y = 1. - 2. * p[1];
1337
1338  for (int i = 0; i < 6; i++)
1339  {
1340  const double x = Nodes.IntPoint(i).x, y = Nodes.IntPoint(i).y;
1341  A(0,i) = 1.;
1342  A(1,i) = x;
1343  A(2,i) = y;
1344  A(3,i) = x * x;
1345  A(4,i) = x * y;
1346  A(5,i) = y * y;
1347  }
1348
1349  A.Invert();
1350 }
1351
1353  Vector &shape) const
1354 {
1355  const double x = ip.x, y = ip.y;
1356  pol(0) = 1.;
1357  pol(1) = x;
1358  pol(2) = y;
1359  pol(3) = x * x;
1360  pol(4) = x * y;
1361  pol(5) = y * y;
1362
1363  A.Mult(pol, shape);
1364 }
1365
1367  DenseMatrix &dshape) const
1368 {
1369  const double x = ip.x, y = ip.y;
1370  D(0,0) = 0.; D(0,1) = 0.;
1371  D(1,0) = 1.; D(1,1) = 0.;
1372  D(2,0) = 0.; D(2,1) = 1.;
1373  D(3,0) = 2. * x; D(3,1) = 0.;
1374  D(4,0) = y; D(4,1) = x;
1375  D(5,0) = 0.; D(5,1) = 2. * y;
1376
1377  Mult(A, D, dshape);
1378 }
1379
1380
1382  : NodalFiniteElement(2, Geometry::SQUARE, 9, 2, FunctionSpace::Qk)
1383 {
1384  Nodes.IntPoint(0).x = 0.0;
1385  Nodes.IntPoint(0).y = 0.0;
1386  Nodes.IntPoint(1).x = 1.0;
1387  Nodes.IntPoint(1).y = 0.0;
1388  Nodes.IntPoint(2).x = 1.0;
1389  Nodes.IntPoint(2).y = 1.0;
1390  Nodes.IntPoint(3).x = 0.0;
1391  Nodes.IntPoint(3).y = 1.0;
1392  Nodes.IntPoint(4).x = 0.5;
1393  Nodes.IntPoint(4).y = 0.0;
1394  Nodes.IntPoint(5).x = 1.0;
1395  Nodes.IntPoint(5).y = 0.5;
1396  Nodes.IntPoint(6).x = 0.5;
1397  Nodes.IntPoint(6).y = 1.0;
1398  Nodes.IntPoint(7).x = 0.0;
1399  Nodes.IntPoint(7).y = 0.5;
1400  Nodes.IntPoint(8).x = 0.5;
1401  Nodes.IntPoint(8).y = 0.5;
1402 }
1403
1405  Vector &shape) const
1406 {
1407  double x = ip.x, y = ip.y;
1408  double l1x, l2x, l3x, l1y, l2y, l3y;
1409
1410  l1x = (x - 1.) * (2. * x - 1);
1411  l2x = 4. * x * (1. - x);
1412  l3x = x * (2. * x - 1.);
1413  l1y = (y - 1.) * (2. * y - 1);
1414  l2y = 4. * y * (1. - y);
1415  l3y = y * (2. * y - 1.);
1416
1417  shape(0) = l1x * l1y;
1418  shape(4) = l2x * l1y;
1419  shape(1) = l3x * l1y;
1420  shape(7) = l1x * l2y;
1421  shape(8) = l2x * l2y;
1422  shape(5) = l3x * l2y;
1423  shape(3) = l1x * l3y;
1424  shape(6) = l2x * l3y;
1425  shape(2) = l3x * l3y;
1426 }
1427
1429  DenseMatrix &dshape) const
1430 {
1431  double x = ip.x, y = ip.y;
1432  double l1x, l2x, l3x, l1y, l2y, l3y;
1433  double d1x, d2x, d3x, d1y, d2y, d3y;
1434
1435  l1x = (x - 1.) * (2. * x - 1);
1436  l2x = 4. * x * (1. - x);
1437  l3x = x * (2. * x - 1.);
1438  l1y = (y - 1.) * (2. * y - 1);
1439  l2y = 4. * y * (1. - y);
1440  l3y = y * (2. * y - 1.);
1441
1442  d1x = 4. * x - 3.;
1443  d2x = 4. - 8. * x;
1444  d3x = 4. * x - 1.;
1445  d1y = 4. * y - 3.;
1446  d2y = 4. - 8. * y;
1447  d3y = 4. * y - 1.;
1448
1449  dshape(0,0) = d1x * l1y;
1450  dshape(0,1) = l1x * d1y;
1451
1452  dshape(4,0) = d2x * l1y;
1453  dshape(4,1) = l2x * d1y;
1454
1455  dshape(1,0) = d3x * l1y;
1456  dshape(1,1) = l3x * d1y;
1457
1458  dshape(7,0) = d1x * l2y;
1459  dshape(7,1) = l1x * d2y;
1460
1461  dshape(8,0) = d2x * l2y;
1462  dshape(8,1) = l2x * d2y;
1463
1464  dshape(5,0) = d3x * l2y;
1465  dshape(5,1) = l3x * d2y;
1466
1467  dshape(3,0) = d1x * l3y;
1468  dshape(3,1) = l1x * d3y;
1469
1470  dshape(6,0) = d2x * l3y;
1471  dshape(6,1) = l2x * d3y;
1472
1473  dshape(2,0) = d3x * l3y;
1474  dshape(2,1) = l3x * d3y;
1475 }
1476
1477 void BiQuad2DFiniteElement::ProjectDelta(int vertex, Vector &dofs) const
1478 {
1479 #if 0
1480  dofs = 1.;
1481 #else
1482  dofs = 0.;
1483  dofs(vertex) = 1.;
1484  switch (vertex)
1485  {
1486  case 0: dofs(4) = 0.25; dofs(7) = 0.25; break;
1487  case 1: dofs(4) = 0.25; dofs(5) = 0.25; break;
1488  case 2: dofs(5) = 0.25; dofs(6) = 0.25; break;
1489  case 3: dofs(6) = 0.25; dofs(7) = 0.25; break;
1490  }
1491  dofs(8) = 1./16.;
1492 #endif
1493 }
1494
1496  : PositiveFiniteElement(2, Geometry::SQUARE, 9, 2, FunctionSpace::Qk)
1497 {
1498  Nodes.IntPoint(0).x = 0.0;
1499  Nodes.IntPoint(0).y = 0.0;
1500  Nodes.IntPoint(1).x = 1.0;
1501  Nodes.IntPoint(1).y = 0.0;
1502  Nodes.IntPoint(2).x = 1.0;
1503  Nodes.IntPoint(2).y = 1.0;
1504  Nodes.IntPoint(3).x = 0.0;
1505  Nodes.IntPoint(3).y = 1.0;
1506  Nodes.IntPoint(4).x = 0.5;
1507  Nodes.IntPoint(4).y = 0.0;
1508  Nodes.IntPoint(5).x = 1.0;
1509  Nodes.IntPoint(5).y = 0.5;
1510  Nodes.IntPoint(6).x = 0.5;
1511  Nodes.IntPoint(6).y = 1.0;
1512  Nodes.IntPoint(7).x = 0.0;
1513  Nodes.IntPoint(7).y = 0.5;
1514  Nodes.IntPoint(8).x = 0.5;
1515  Nodes.IntPoint(8).y = 0.5;
1516 }
1517
1519  Vector &shape) const
1520 {
1521  double x = ip.x, y = ip.y;
1522  double l1x, l2x, l3x, l1y, l2y, l3y;
1523
1524  l1x = (1. - x) * (1. - x);
1525  l2x = 2. * x * (1. - x);
1526  l3x = x * x;
1527  l1y = (1. - y) * (1. - y);
1528  l2y = 2. * y * (1. - y);
1529  l3y = y * y;
1530
1531  shape(0) = l1x * l1y;
1532  shape(4) = l2x * l1y;
1533  shape(1) = l3x * l1y;
1534  shape(7) = l1x * l2y;
1535  shape(8) = l2x * l2y;
1536  shape(5) = l3x * l2y;
1537  shape(3) = l1x * l3y;
1538  shape(6) = l2x * l3y;
1539  shape(2) = l3x * l3y;
1540 }
1541
1543  DenseMatrix &dshape) const
1544 {
1545  double x = ip.x, y = ip.y;
1546  double l1x, l2x, l3x, l1y, l2y, l3y;
1547  double d1x, d2x, d3x, d1y, d2y, d3y;
1548
1549  l1x = (1. - x) * (1. - x);
1550  l2x = 2. * x * (1. - x);
1551  l3x = x * x;
1552  l1y = (1. - y) * (1. - y);
1553  l2y = 2. * y * (1. - y);
1554  l3y = y * y;
1555
1556  d1x = 2. * x - 2.;
1557  d2x = 2. - 4. * x;
1558  d3x = 2. * x;
1559  d1y = 2. * y - 2.;
1560  d2y = 2. - 4. * y;
1561  d3y = 2. * y;
1562
1563  dshape(0,0) = d1x * l1y;
1564  dshape(0,1) = l1x * d1y;
1565
1566  dshape(4,0) = d2x * l1y;
1567  dshape(4,1) = l2x * d1y;
1568
1569  dshape(1,0) = d3x * l1y;
1570  dshape(1,1) = l3x * d1y;
1571
1572  dshape(7,0) = d1x * l2y;
1573  dshape(7,1) = l1x * d2y;
1574
1575  dshape(8,0) = d2x * l2y;
1576  dshape(8,1) = l2x * d2y;
1577
1578  dshape(5,0) = d3x * l2y;
1579  dshape(5,1) = l3x * d2y;
1580
1581  dshape(3,0) = d1x * l3y;
1582  dshape(3,1) = l1x * d3y;
1583
1584  dshape(6,0) = d2x * l3y;
1585  dshape(6,1) = l2x * d3y;
1586
1587  dshape(2,0) = d3x * l3y;
1588  dshape(2,1) = l3x * d3y;
1589 }
1590
1593 {
1594  double s[9];
1595  IntegrationPoint tr_ip;
1596  Vector xx(&tr_ip.x, 2), shape(s, 9);
1597
1598  for (int i = 0; i < 9; i++)
1599  {
1600  Trans.Transform(Nodes.IntPoint(i), xx);
1601  CalcShape(tr_ip, shape);
1602  for (int j = 0; j < 9; j++)
1603  if (fabs(I(i,j) = s[j]) < 1.0e-12)
1604  {
1605  I(i,j) = 0.0;
1606  }
1607  }
1608  for (int i = 0; i < 9; i++)
1609  {
1610  double *d = &I(0,i);
1611  d[4] = 2. * d[4] - 0.5 * (d[0] + d[1]);
1612  d[5] = 2. * d[5] - 0.5 * (d[1] + d[2]);
1613  d[6] = 2. * d[6] - 0.5 * (d[2] + d[3]);
1614  d[7] = 2. * d[7] - 0.5 * (d[3] + d[0]);
1615  d[8] = 4. * d[8] - 0.5 * (d[4] + d[5] + d[6] + d[7]) -
1616  0.25 * (d[0] + d[1] + d[2] + d[3]);
1617  }
1618 }
1619
1621  Coefficient &coeff, ElementTransformation &Trans, Vector &dofs) const
1622 {
1623  double *d = dofs;
1624
1625  for (int i = 0; i < 9; i++)
1626  {
1627  const IntegrationPoint &ip = Nodes.IntPoint(i);
1628  Trans.SetIntPoint(&ip);
1629  d[i] = coeff.Eval(Trans, ip);
1630  }
1631  d[4] = 2. * d[4] - 0.5 * (d[0] + d[1]);
1632  d[5] = 2. * d[5] - 0.5 * (d[1] + d[2]);
1633  d[6] = 2. * d[6] - 0.5 * (d[2] + d[3]);
1634  d[7] = 2. * d[7] - 0.5 * (d[3] + d[0]);
1635  d[8] = 4. * d[8] - 0.5 * (d[4] + d[5] + d[6] + d[7]) -
1636  0.25 * (d[0] + d[1] + d[2] + d[3]);
1637 }
1638
1641  Vector &dofs) const
1642 {
1643  double v[3];
1644  Vector x (v, vc.GetVDim());
1645
1646  for (int i = 0; i < 9; i++)
1647  {
1648  const IntegrationPoint &ip = Nodes.IntPoint(i);
1649  Trans.SetIntPoint(&ip);
1650  vc.Eval (x, Trans, ip);
1651  for (int j = 0; j < x.Size(); j++)
1652  {
1653  dofs(9*j+i) = v[j];
1654  }
1655  }
1656  for (int j = 0; j < x.Size(); j++)
1657  {
1658  double *d = &dofs(9*j);
1659
1660  d[4] = 2. * d[4] - 0.5 * (d[0] + d[1]);
1661  d[5] = 2. * d[5] - 0.5 * (d[1] + d[2]);
1662  d[6] = 2. * d[6] - 0.5 * (d[2] + d[3]);
1663  d[7] = 2. * d[7] - 0.5 * (d[3] + d[0]);
1664  d[8] = 4. * d[8] - 0.5 * (d[4] + d[5] + d[6] + d[7]) -
1665  0.25 * (d[0] + d[1] + d[2] + d[3]);
1666  }
1667 }
1668
1669
1671  : NodalFiniteElement(2, Geometry::SQUARE, 9, 2, FunctionSpace::Qk)
1672 {
1673  const double p1 = 0.5*(1.-sqrt(3./5.));
1674
1675  Nodes.IntPoint(0).x = p1;
1676  Nodes.IntPoint(0).y = p1;
1677  Nodes.IntPoint(4).x = 0.5;
1678  Nodes.IntPoint(4).y = p1;
1679  Nodes.IntPoint(1).x = 1.-p1;
1680  Nodes.IntPoint(1).y = p1;
1681  Nodes.IntPoint(7).x = p1;
1682  Nodes.IntPoint(7).y = 0.5;
1683  Nodes.IntPoint(8).x = 0.5;
1684  Nodes.IntPoint(8).y = 0.5;
1685  Nodes.IntPoint(5).x = 1.-p1;
1686  Nodes.IntPoint(5).y = 0.5;
1687  Nodes.IntPoint(3).x = p1;
1688  Nodes.IntPoint(3).y = 1.-p1;
1689  Nodes.IntPoint(6).x = 0.5;
1690  Nodes.IntPoint(6).y = 1.-p1;
1691  Nodes.IntPoint(2).x = 1.-p1;
1692  Nodes.IntPoint(2).y = 1.-p1;
1693 }
1694
1696  Vector &shape) const
1697 {
1698  const double a = sqrt(5./3.);
1699  const double p1 = 0.5*(1.-sqrt(3./5.));
1700
1701  double x = a*(ip.x-p1), y = a*(ip.y-p1);
1702  double l1x, l2x, l3x, l1y, l2y, l3y;
1703
1704  l1x = (x - 1.) * (2. * x - 1);
1705  l2x = 4. * x * (1. - x);
1706  l3x = x * (2. * x - 1.);
1707  l1y = (y - 1.) * (2. * y - 1);
1708  l2y = 4. * y * (1. - y);
1709  l3y = y * (2. * y - 1.);
1710
1711  shape(0) = l1x * l1y;
1712  shape(4) = l2x * l1y;
1713  shape(1) = l3x * l1y;
1714  shape(7) = l1x * l2y;
1715  shape(8) = l2x * l2y;
1716  shape(5) = l3x * l2y;
1717  shape(3) = l1x * l3y;
1718  shape(6) = l2x * l3y;
1719  shape(2) = l3x * l3y;
1720 }
1721
1723  DenseMatrix &dshape) const
1724 {
1725  const double a = sqrt(5./3.);
1726  const double p1 = 0.5*(1.-sqrt(3./5.));
1727
1728  double x = a*(ip.x-p1), y = a*(ip.y-p1);
1729  double l1x, l2x, l3x, l1y, l2y, l3y;
1730  double d1x, d2x, d3x, d1y, d2y, d3y;
1731
1732  l1x = (x - 1.) * (2. * x - 1);
1733  l2x = 4. * x * (1. - x);
1734  l3x = x * (2. * x - 1.);
1735  l1y = (y - 1.) * (2. * y - 1);
1736  l2y = 4. * y * (1. - y);
1737  l3y = y * (2. * y - 1.);
1738
1739  d1x = a * (4. * x - 3.);
1740  d2x = a * (4. - 8. * x);
1741  d3x = a * (4. * x - 1.);
1742  d1y = a * (4. * y - 3.);
1743  d2y = a * (4. - 8. * y);
1744  d3y = a * (4. * y - 1.);
1745
1746  dshape(0,0) = d1x * l1y;
1747  dshape(0,1) = l1x * d1y;
1748
1749  dshape(4,0) = d2x * l1y;
1750  dshape(4,1) = l2x * d1y;
1751
1752  dshape(1,0) = d3x * l1y;
1753  dshape(1,1) = l3x * d1y;
1754
1755  dshape(7,0) = d1x * l2y;
1756  dshape(7,1) = l1x * d2y;
1757
1758  dshape(8,0) = d2x * l2y;
1759  dshape(8,1) = l2x * d2y;
1760
1761  dshape(5,0) = d3x * l2y;
1762  dshape(5,1) = l3x * d2y;
1763
1764  dshape(3,0) = d1x * l3y;
1765  dshape(3,1) = l1x * d3y;
1766
1767  dshape(6,0) = d2x * l3y;
1768  dshape(6,1) = l2x * d3y;
1769
1770  dshape(2,0) = d3x * l3y;
1771  dshape(2,1) = l3x * d3y;
1772 }
1773
1775  : NodalFiniteElement (2, Geometry::SQUARE, 16, 3, FunctionSpace::Qk)
1776 {
1777  Nodes.IntPoint(0).x = 0.;
1778  Nodes.IntPoint(0).y = 0.;
1779  Nodes.IntPoint(1).x = 1.;
1780  Nodes.IntPoint(1).y = 0.;
1781  Nodes.IntPoint(2).x = 1.;
1782  Nodes.IntPoint(2).y = 1.;
1783  Nodes.IntPoint(3).x = 0.;
1784  Nodes.IntPoint(3).y = 1.;
1785  Nodes.IntPoint(4).x = 1./3.;
1786  Nodes.IntPoint(4).y = 0.;
1787  Nodes.IntPoint(5).x = 2./3.;
1788  Nodes.IntPoint(5).y = 0.;
1789  Nodes.IntPoint(6).x = 1.;
1790  Nodes.IntPoint(6).y = 1./3.;
1791  Nodes.IntPoint(7).x = 1.;
1792  Nodes.IntPoint(7).y = 2./3.;
1793  Nodes.IntPoint(8).x = 2./3.;
1794  Nodes.IntPoint(8).y = 1.;
1795  Nodes.IntPoint(9).x = 1./3.;
1796  Nodes.IntPoint(9).y = 1.;
1797  Nodes.IntPoint(10).x = 0.;
1798  Nodes.IntPoint(10).y = 2./3.;
1799  Nodes.IntPoint(11).x = 0.;
1800  Nodes.IntPoint(11).y = 1./3.;
1801  Nodes.IntPoint(12).x = 1./3.;
1802  Nodes.IntPoint(12).y = 1./3.;
1803  Nodes.IntPoint(13).x = 2./3.;
1804  Nodes.IntPoint(13).y = 1./3.;
1805  Nodes.IntPoint(14).x = 1./3.;
1806  Nodes.IntPoint(14).y = 2./3.;
1807  Nodes.IntPoint(15).x = 2./3.;
1808  Nodes.IntPoint(15).y = 2./3.;
1809 }
1810
1812  const IntegrationPoint &ip, Vector &shape) const
1813 {
1814  double x = ip.x, y = ip.y;
1815
1816  double w1x, w2x, w3x, w1y, w2y, w3y;
1817  double l0x, l1x, l2x, l3x, l0y, l1y, l2y, l3y;
1818
1819  w1x = x - 1./3.; w2x = x - 2./3.; w3x = x - 1.;
1820  w1y = y - 1./3.; w2y = y - 2./3.; w3y = y - 1.;
1821
1822  l0x = (- 4.5) * w1x * w2x * w3x;
1823  l1x = ( 13.5) * x * w2x * w3x;
1824  l2x = (-13.5) * x * w1x * w3x;
1825  l3x = ( 4.5) * x * w1x * w2x;
1826
1827  l0y = (- 4.5) * w1y * w2y * w3y;
1828  l1y = ( 13.5) * y * w2y * w3y;
1829  l2y = (-13.5) * y * w1y * w3y;
1830  l3y = ( 4.5) * y * w1y * w2y;
1831
1832  shape(0) = l0x * l0y;
1833  shape(1) = l3x * l0y;
1834  shape(2) = l3x * l3y;
1835  shape(3) = l0x * l3y;
1836  shape(4) = l1x * l0y;
1837  shape(5) = l2x * l0y;
1838  shape(6) = l3x * l1y;
1839  shape(7) = l3x * l2y;
1840  shape(8) = l2x * l3y;
1841  shape(9) = l1x * l3y;
1842  shape(10) = l0x * l2y;
1843  shape(11) = l0x * l1y;
1844  shape(12) = l1x * l1y;
1845  shape(13) = l2x * l1y;
1846  shape(14) = l1x * l2y;
1847  shape(15) = l2x * l2y;
1848 }
1849
1851  const IntegrationPoint &ip, DenseMatrix &dshape) const
1852 {
1853  double x = ip.x, y = ip.y;
1854
1855  double w1x, w2x, w3x, w1y, w2y, w3y;
1856  double l0x, l1x, l2x, l3x, l0y, l1y, l2y, l3y;
1857  double d0x, d1x, d2x, d3x, d0y, d1y, d2y, d3y;
1858
1859  w1x = x - 1./3.; w2x = x - 2./3.; w3x = x - 1.;
1860  w1y = y - 1./3.; w2y = y - 2./3.; w3y = y - 1.;
1861
1862  l0x = (- 4.5) * w1x * w2x * w3x;
1863  l1x = ( 13.5) * x * w2x * w3x;
1864  l2x = (-13.5) * x * w1x * w3x;
1865  l3x = ( 4.5) * x * w1x * w2x;
1866
1867  l0y = (- 4.5) * w1y * w2y * w3y;
1868  l1y = ( 13.5) * y * w2y * w3y;
1869  l2y = (-13.5) * y * w1y * w3y;
1870  l3y = ( 4.5) * y * w1y * w2y;
1871
1872  d0x = -5.5 + ( 18. - 13.5 * x) * x;
1873  d1x = 9. + (-45. + 40.5 * x) * x;
1874  d2x = -4.5 + ( 36. - 40.5 * x) * x;
1875  d3x = 1. + (- 9. + 13.5 * x) * x;
1876
1877  d0y = -5.5 + ( 18. - 13.5 * y) * y;
1878  d1y = 9. + (-45. + 40.5 * y) * y;
1879  d2y = -4.5 + ( 36. - 40.5 * y) * y;
1880  d3y = 1. + (- 9. + 13.5 * y) * y;
1881
1882  dshape( 0,0) = d0x * l0y; dshape( 0,1) = l0x * d0y;
1883  dshape( 1,0) = d3x * l0y; dshape( 1,1) = l3x * d0y;
1884  dshape( 2,0) = d3x * l3y; dshape( 2,1) = l3x * d3y;
1885  dshape( 3,0) = d0x * l3y; dshape( 3,1) = l0x * d3y;
1886  dshape( 4,0) = d1x * l0y; dshape( 4,1) = l1x * d0y;
1887  dshape( 5,0) = d2x * l0y; dshape( 5,1) = l2x * d0y;
1888  dshape( 6,0) = d3x * l1y; dshape( 6,1) = l3x * d1y;
1889  dshape( 7,0) = d3x * l2y; dshape( 7,1) = l3x * d2y;
1890  dshape( 8,0) = d2x * l3y; dshape( 8,1) = l2x * d3y;
1891  dshape( 9,0) = d1x * l3y; dshape( 9,1) = l1x * d3y;
1892  dshape(10,0) = d0x * l2y; dshape(10,1) = l0x * d2y;
1893  dshape(11,0) = d0x * l1y; dshape(11,1) = l0x * d1y;
1894  dshape(12,0) = d1x * l1y; dshape(12,1) = l1x * d1y;
1895  dshape(13,0) = d2x * l1y; dshape(13,1) = l2x * d1y;
1896  dshape(14,0) = d1x * l2y; dshape(14,1) = l1x * d2y;
1897  dshape(15,0) = d2x * l2y; dshape(15,1) = l2x * d2y;
1898 }
1899
1901  const IntegrationPoint &ip, DenseMatrix &h) const
1902 {
1903  double x = ip.x, y = ip.y;
1904
1905  double w1x, w2x, w3x, w1y, w2y, w3y;
1906  double l0x, l1x, l2x, l3x, l0y, l1y, l2y, l3y;
1907  double d0x, d1x, d2x, d3x, d0y, d1y, d2y, d3y;
1908  double h0x, h1x, h2x, h3x, h0y, h1y, h2y, h3y;
1909
1910  w1x = x - 1./3.; w2x = x - 2./3.; w3x = x - 1.;
1911  w1y = y - 1./3.; w2y = y - 2./3.; w3y = y - 1.;
1912
1913  l0x = (- 4.5) * w1x * w2x * w3x;
1914  l1x = ( 13.5) * x * w2x * w3x;
1915  l2x = (-13.5) * x * w1x * w3x;
1916  l3x = ( 4.5) * x * w1x * w2x;
1917
1918  l0y = (- 4.5) * w1y * w2y * w3y;
1919  l1y = ( 13.5) * y * w2y * w3y;
1920  l2y = (-13.5) * y * w1y * w3y;
1921  l3y = ( 4.5) * y * w1y * w2y;
1922
1923  d0x = -5.5 + ( 18. - 13.5 * x) * x;
1924  d1x = 9. + (-45. + 40.5 * x) * x;
1925  d2x = -4.5 + ( 36. - 40.5 * x) * x;
1926  d3x = 1. + (- 9. + 13.5 * x) * x;
1927
1928  d0y = -5.5 + ( 18. - 13.5 * y) * y;
1929  d1y = 9. + (-45. + 40.5 * y) * y;
1930  d2y = -4.5 + ( 36. - 40.5 * y) * y;
1931  d3y = 1. + (- 9. + 13.5 * y) * y;
1932
1933  h0x = -27. * x + 18.;
1934  h1x = 81. * x - 45.;
1935  h2x = -81. * x + 36.;
1936  h3x = 27. * x - 9.;
1937
1938  h0y = -27. * y + 18.;
1939  h1y = 81. * y - 45.;
1940  h2y = -81. * y + 36.;
1941  h3y = 27. * y - 9.;
1942
1943  h( 0,0) = h0x * l0y; h( 0,1) = d0x * d0y; h( 0,2) = l0x * h0y;
1944  h( 1,0) = h3x * l0y; h( 1,1) = d3x * d0y; h( 1,2) = l3x * h0y;
1945  h( 2,0) = h3x * l3y; h( 2,1) = d3x * d3y; h( 2,2) = l3x * h3y;
1946  h( 3,0) = h0x * l3y; h( 3,1) = d0x * d3y; h( 3,2) = l0x * h3y;
1947  h( 4,0) = h1x * l0y; h( 4,1) = d1x * d0y; h( 4,2) = l1x * h0y;
1948  h( 5,0) = h2x * l0y; h( 5,1) = d2x * d0y; h( 5,2) = l2x * h0y;
1949  h( 6,0) = h3x * l1y; h( 6,1) = d3x * d1y; h( 6,2) = l3x * h1y;
1950  h( 7,0) = h3x * l2y; h( 7,1) = d3x * d2y; h( 7,2) = l3x * h2y;
1951  h( 8,0) = h2x * l3y; h( 8,1) = d2x * d3y; h( 8,2) = l2x * h3y;
1952  h( 9,0) = h1x * l3y; h( 9,1) = d1x * d3y; h( 9,2) = l1x * h3y;
1953  h(10,0) = h0x * l2y; h(10,1) = d0x * d2y; h(10,2) = l0x * h2y;
1954  h(11,0) = h0x * l1y; h(11,1) = d0x * d1y; h(11,2) = l0x * h1y;
1955  h(12,0) = h1x * l1y; h(12,1) = d1x * d1y; h(12,2) = l1x * h1y;
1956  h(13,0) = h2x * l1y; h(13,1) = d2x * d1y; h(13,2) = l2x * h1y;
1957  h(14,0) = h1x * l2y; h(14,1) = d1x * d2y; h(14,2) = l1x * h2y;
1958  h(15,0) = h2x * l2y; h(15,1) = d2x * d2y; h(15,2) = l2x * h2y;
1959 }
1960
1961
1963  : NodalFiniteElement(1, Geometry::SEGMENT, 4, 3)
1964 {
1965  Nodes.IntPoint(0).x = 0.0;
1966  Nodes.IntPoint(1).x = 1.0;
1967  Nodes.IntPoint(2).x = 0.33333333333333333333;
1968  Nodes.IntPoint(3).x = 0.66666666666666666667;
1969 }
1970
1972  Vector &shape) const
1973 {
1974  double x = ip.x;
1975  double l1 = x,
1976  l2 = (1.0-x),
1977  l3 = (0.33333333333333333333-x),
1978  l4 = (0.66666666666666666667-x);
1979
1980  shape(0) = 4.5 * l2 * l3 * l4;
1981  shape(1) = 4.5 * l1 * l3 * l4;
1982  shape(2) = 13.5 * l1 * l2 * l4;
1983  shape(3) = -13.5 * l1 * l2 * l3;
1984 }
1985
1987  DenseMatrix &dshape) const
1988 {
1989  double x = ip.x;
1990
1991  dshape(0,0) = -5.5 + x * (18. - 13.5 * x);
1992  dshape(1,0) = 1. - x * (9. - 13.5 * x);
1993  dshape(2,0) = 9. - x * (45. - 40.5 * x);
1994  dshape(3,0) = -4.5 + x * (36. - 40.5 * x);
1995 }
1996
1997
1999  : NodalFiniteElement(2, Geometry::TRIANGLE, 10, 3)
2000 {
2001  Nodes.IntPoint(0).x = 0.0;
2002  Nodes.IntPoint(0).y = 0.0;
2003  Nodes.IntPoint(1).x = 1.0;
2004  Nodes.IntPoint(1).y = 0.0;
2005  Nodes.IntPoint(2).x = 0.0;
2006  Nodes.IntPoint(2).y = 1.0;
2007  Nodes.IntPoint(3).x = 0.33333333333333333333;
2008  Nodes.IntPoint(3).y = 0.0;
2009  Nodes.IntPoint(4).x = 0.66666666666666666667;
2010  Nodes.IntPoint(4).y = 0.0;
2011  Nodes.IntPoint(5).x = 0.66666666666666666667;
2012  Nodes.IntPoint(5).y = 0.33333333333333333333;
2013  Nodes.IntPoint(6).x = 0.33333333333333333333;
2014  Nodes.IntPoint(6).y = 0.66666666666666666667;
2015  Nodes.IntPoint(7).x = 0.0;
2016  Nodes.IntPoint(7).y = 0.66666666666666666667;
2017  Nodes.IntPoint(8).x = 0.0;
2018  Nodes.IntPoint(8).y = 0.33333333333333333333;
2019  Nodes.IntPoint(9).x = 0.33333333333333333333;
2020  Nodes.IntPoint(9).y = 0.33333333333333333333;
2021 }
2022
2024  Vector &shape) const
2025 {
2026  double x = ip.x, y = ip.y;
2027  double l1 = (-1. + x + y),
2028  lx = (-1. + 3.*x),
2029  ly = (-1. + 3.*y);
2030
2031  shape(0) = -0.5*l1*(3.*l1 + 1.)*(3.*l1 + 2.);
2032  shape(1) = 0.5*x*(lx - 1.)*lx;
2033  shape(2) = 0.5*y*(-1. + ly)*ly;
2034  shape(3) = 4.5*x*l1*(3.*l1 + 1.);
2035  shape(4) = -4.5*x*lx*l1;
2036  shape(5) = 4.5*x*lx*y;
2037  shape(6) = 4.5*x*y*ly;
2038  shape(7) = -4.5*y*l1*ly;
2039  shape(8) = 4.5*y*l1*(1. + 3.*l1);
2040  shape(9) = -27.*x*y*l1;
2041 }
2042
2044  DenseMatrix &dshape) const
2045 {
2046  double x = ip.x, y = ip.y;
2047
2048  dshape(0,0) = 0.5*(-11. + 36.*y - 9.*(x*(-4. + 3.*x) + 6.*x*y + 3.*y*y));
2049  dshape(1,0) = 1. + 4.5*x*(-2. + 3.*x);
2050  dshape(2,0) = 0.;
2051  dshape(3,0) = 4.5*(2. + 9.*x*x - 5.*y + 3.*y*y + 2.*x*(-5. + 6.*y));
2052  dshape(4,0) = -4.5*(1. - 1.*y + x*(-8. + 9.*x + 6.*y));
2053  dshape(5,0) = 4.5*(-1. + 6.*x)*y;
2054  dshape(6,0) = 4.5*y*(-1. + 3.*y);
2055  dshape(7,0) = 4.5*(1. - 3.*y)*y;
2056  dshape(8,0) = 4.5*y*(-5. + 6.*x + 6.*y);
2057  dshape(9,0) = -27.*y*(-1. + 2.*x + y);
2058
2059  dshape(0,1) = 0.5*(-11. + 36.*y - 9.*(x*(-4. + 3.*x) + 6.*x*y + 3.*y*y));
2060  dshape(1,1) = 0.;
2061  dshape(2,1) = 1. + 4.5*y*(-2. + 3.*y);
2062  dshape(3,1) = 4.5*x*(-5. + 6.*x + 6.*y);
2063  dshape(4,1) = 4.5*(1. - 3.*x)*x;
2064  dshape(5,1) = 4.5*x*(-1. + 3.*x);
2065  dshape(6,1) = 4.5*x*(-1. + 6.*y);
2066  dshape(7,1) = -4.5*(1. + x*(-1. + 6.*y) + y*(-8. + 9.*y));
2067  dshape(8,1) = 4.5*(2. + 3.*x*x + y*(-10. + 9.*y) + x*(-5. + 12.*y));
2068  dshape(9,1) = -27.*x*(-1. + x + 2.*y);
2069 }
2070
2072  DenseMatrix &h) const
2073 {
2074  double x = ip.x, y = ip.y;
2075
2076  h(0,0) = 18.-27.*(x+y);
2077  h(0,1) = 18.-27.*(x+y);
2078  h(0,2) = 18.-27.*(x+y);
2079
2080  h(1,0) = -9.+27.*x;
2081  h(1,1) = 0.;
2082  h(1,2) = 0.;
2083
2084  h(2,0) = 0.;
2085  h(2,1) = 0.;
2086  h(2,2) = -9.+27.*y;
2087
2088  h(3,0) = -45.+81.*x+54.*y;
2089  h(3,1) = -22.5+54.*x+27.*y;
2090  h(3,2) = 27.*x;
2091
2092  h(4,0) = 36.-81.*x-27.*y;
2093  h(4,1) = 4.5-27.*x;
2094  h(4,2) = 0.;
2095
2096  h(5,0) = 27.*y;
2097  h(5,1) = -4.5+27.*x;
2098  h(5,2) = 0.;
2099
2100  h(6,0) = 0.;
2101  h(6,1) = -4.5+27.*y;
2102  h(6,2) = 27.*x;
2103
2104  h(7,0) = 0.;
2105  h(7,1) = 4.5-27.*y;
2106  h(7,2) = 36.-27.*x-81.*y;
2107
2108  h(8,0) = 27.*y;
2109  h(8,1) = -22.5+27.*x+54.*y;
2110  h(8,2) = -45.+54.*x+81.*y;
2111
2112  h(9,0) = -54.*y;
2113  h(9,1) = 27.-54.*(x+y);
2114  h(9,2) = -54.*x;
2115 }
2116
2117
2119  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 20, 3)
2120 {
2121  Nodes.IntPoint(0).x = 0;
2122  Nodes.IntPoint(0).y = 0;
2123  Nodes.IntPoint(0).z = 0;
2124  Nodes.IntPoint(1).x = 1.;
2125  Nodes.IntPoint(1).y = 0;
2126  Nodes.IntPoint(1).z = 0;
2127  Nodes.IntPoint(2).x = 0;
2128  Nodes.IntPoint(2).y = 1.;
2129  Nodes.IntPoint(2).z = 0;
2130  Nodes.IntPoint(3).x = 0;
2131  Nodes.IntPoint(3).y = 0;
2132  Nodes.IntPoint(3).z = 1.;
2133  Nodes.IntPoint(4).x = 0.3333333333333333333333333333;
2134  Nodes.IntPoint(4).y = 0;
2135  Nodes.IntPoint(4).z = 0;
2136  Nodes.IntPoint(5).x = 0.6666666666666666666666666667;
2137  Nodes.IntPoint(5).y = 0;
2138  Nodes.IntPoint(5).z = 0;
2139  Nodes.IntPoint(6).x = 0;
2140  Nodes.IntPoint(6).y = 0.3333333333333333333333333333;
2141  Nodes.IntPoint(6).z = 0;
2142  Nodes.IntPoint(7).x = 0;
2143  Nodes.IntPoint(7).y = 0.6666666666666666666666666667;
2144  Nodes.IntPoint(7).z = 0;
2145  Nodes.IntPoint(8).x = 0;
2146  Nodes.IntPoint(8).y = 0;
2147  Nodes.IntPoint(8).z = 0.3333333333333333333333333333;
2148  Nodes.IntPoint(9).x = 0;
2149  Nodes.IntPoint(9).y = 0;
2150  Nodes.IntPoint(9).z = 0.6666666666666666666666666667;
2151  Nodes.IntPoint(10).x = 0.6666666666666666666666666667;
2152  Nodes.IntPoint(10).y = 0.3333333333333333333333333333;
2153  Nodes.IntPoint(10).z = 0;
2154  Nodes.IntPoint(11).x = 0.3333333333333333333333333333;
2155  Nodes.IntPoint(11).y = 0.6666666666666666666666666667;
2156  Nodes.IntPoint(11).z = 0;
2157  Nodes.IntPoint(12).x = 0.6666666666666666666666666667;
2158  Nodes.IntPoint(12).y = 0;
2159  Nodes.IntPoint(12).z = 0.3333333333333333333333333333;
2160  Nodes.IntPoint(13).x = 0.3333333333333333333333333333;
2161  Nodes.IntPoint(13).y = 0;
2162  Nodes.IntPoint(13).z = 0.6666666666666666666666666667;
2163  Nodes.IntPoint(14).x = 0;
2164  Nodes.IntPoint(14).y = 0.6666666666666666666666666667;
2165  Nodes.IntPoint(14).z = 0.3333333333333333333333333333;
2166  Nodes.IntPoint(15).x = 0;
2167  Nodes.IntPoint(15).y = 0.3333333333333333333333333333;
2168  Nodes.IntPoint(15).z = 0.6666666666666666666666666667;
2169  Nodes.IntPoint(16).x = 0.3333333333333333333333333333;
2170  Nodes.IntPoint(16).y = 0.3333333333333333333333333333;
2171  Nodes.IntPoint(16).z = 0.3333333333333333333333333333;
2172  Nodes.IntPoint(17).x = 0;
2173  Nodes.IntPoint(17).y = 0.3333333333333333333333333333;
2174  Nodes.IntPoint(17).z = 0.3333333333333333333333333333;
2175  Nodes.IntPoint(18).x = 0.3333333333333333333333333333;
2176  Nodes.IntPoint(18).y = 0;
2177  Nodes.IntPoint(18).z = 0.3333333333333333333333333333;
2178  Nodes.IntPoint(19).x = 0.3333333333333333333333333333;
2179  Nodes.IntPoint(19).y = 0.3333333333333333333333333333;
2180  Nodes.IntPoint(19).z = 0;
2181 }
2182
2184  Vector &shape) const
2185 {
2186  double x = ip.x, y = ip.y, z = ip.z;
2187
2188  shape(0) = -((-1 + x + y + z)*(-2 + 3*x + 3*y + 3*z)*
2189  (-1 + 3*x + 3*y + 3*z))/2.;
2190  shape(4) = (9*x*(-1 + x + y + z)*(-2 + 3*x + 3*y + 3*z))/2.;
2191  shape(5) = (-9*x*(-1 + 3*x)*(-1 + x + y + z))/2.;
2192  shape(1) = (x*(2 + 9*(-1 + x)*x))/2.;
2193  shape(6) = (9*y*(-1 + x + y + z)*(-2 + 3*x + 3*y + 3*z))/2.;
2194  shape(19) = -27*x*y*(-1 + x + y + z);
2195  shape(10) = (9*x*(-1 + 3*x)*y)/2.;
2196  shape(7) = (-9*y*(-1 + 3*y)*(-1 + x + y + z))/2.;
2197  shape(11) = (9*x*y*(-1 + 3*y))/2.;
2198  shape(2) = (y*(2 + 9*(-1 + y)*y))/2.;
2199  shape(8) = (9*z*(-1 + x + y + z)*(-2 + 3*x + 3*y + 3*z))/2.;
2200  shape(18) = -27*x*z*(-1 + x + y + z);
2201  shape(12) = (9*x*(-1 + 3*x)*z)/2.;
2202  shape(17) = -27*y*z*(-1 + x + y + z);
2203  shape(16) = 27*x*y*z;
2204  shape(14) = (9*y*(-1 + 3*y)*z)/2.;
2205  shape(9) = (-9*z*(-1 + x + y + z)*(-1 + 3*z))/2.;
2206  shape(13) = (9*x*z*(-1 + 3*z))/2.;
2207  shape(15) = (9*y*z*(-1 + 3*z))/2.;
2208  shape(3) = (z*(2 + 9*(-1 + z)*z))/2.;
2209 }
2210
2212  DenseMatrix &dshape) const
2213 {
2214  double x = ip.x, y = ip.y, z = ip.z;
2215
2216  dshape(0,0) = (-11 + 36*y + 36*z - 9*(3*pow(x,2) + 3*pow(y + z,2) +
2217  x*(-4 + 6*y + 6*z)))/2.;
2218  dshape(0,1) = (-11 + 36*y + 36*z - 9*(3*pow(x,2) + 3*pow(y + z,2) +
2219  x*(-4 + 6*y + 6*z)))/2.;
2220  dshape(0,2) = (-11 + 36*y + 36*z - 9*(3*pow(x,2) + 3*pow(y + z,2) +
2221  x*(-4 + 6*y + 6*z)))/2.;
2222  dshape(4,0) = (9*(9*pow(x,2) + (-1 + y + z)*(-2 + 3*y + 3*z) +
2223  2*x*(-5 + 6*y + 6*z)))/2.;
2224  dshape(4,1) = (9*x*(-5 + 6*x + 6*y + 6*z))/2.;
2225  dshape(4,2) = (9*x*(-5 + 6*x + 6*y + 6*z))/2.;
2226  dshape(5,0) = (-9*(1 - y - z + x*(-8 + 9*x + 6*y + 6*z)))/2.;
2227  dshape(5,1) = (9*(1 - 3*x)*x)/2.;
2228  dshape(5,2) = (9*(1 - 3*x)*x)/2.;
2229  dshape(1,0) = 1 + (9*x*(-2 + 3*x))/2.;
2230  dshape(1,1) = 0;
2231  dshape(1,2) = 0;
2232  dshape(6,0) = (9*y*(-5 + 6*x + 6*y + 6*z))/2.;
2233  dshape(6,1) = (9*(2 + 3*pow(x,2) - 10*y - 5*z + 3*(y + z)*(3*y + z) +
2234  x*(-5 + 12*y + 6*z)))/2.;
2235  dshape(6,2) = (9*y*(-5 + 6*x + 6*y + 6*z))/2.;
2236  dshape(19,0) = -27*y*(-1 + 2*x + y + z);
2237  dshape(19,1) = -27*x*(-1 + x + 2*y + z);
2238  dshape(19,2) = -27*x*y;
2239  dshape(10,0) = (9*(-1 + 6*x)*y)/2.;
2240  dshape(10,1) = (9*x*(-1 + 3*x))/2.;
2241  dshape(10,2) = 0;
2242  dshape(7,0) = (9*(1 - 3*y)*y)/2.;
2243  dshape(7,1) = (-9*(1 + x*(-1 + 6*y) - z + y*(-8 + 9*y + 6*z)))/2.;
2244  dshape(7,2) = (9*(1 - 3*y)*y)/2.;
2245  dshape(11,0) = (9*y*(-1 + 3*y))/2.;
2246  dshape(11,1) = (9*x*(-1 + 6*y))/2.;
2247  dshape(11,2) = 0;
2248  dshape(2,0) = 0;
2249  dshape(2,1) = 1 + (9*y*(-2 + 3*y))/2.;
2250  dshape(2,2) = 0;
2251  dshape(8,0) = (9*z*(-5 + 6*x + 6*y + 6*z))/2.;
2252  dshape(8,1) = (9*z*(-5 + 6*x + 6*y + 6*z))/2.;
2253  dshape(8,2) = (9*(2 + 3*pow(x,2) - 5*y - 10*z + 3*(y + z)*(y + 3*z) +
2254  x*(-5 + 6*y + 12*z)))/2.;
2255  dshape(18,0) = -27*z*(-1 + 2*x + y + z);
2256  dshape(18,1) = -27*x*z;
2257  dshape(18,2) = -27*x*(-1 + x + y + 2*z);
2258  dshape(12,0) = (9*(-1 + 6*x)*z)/2.;
2259  dshape(12,1) = 0;
2260  dshape(12,2) = (9*x*(-1 + 3*x))/2.;
2261  dshape(17,0) = -27*y*z;
2262  dshape(17,1) = -27*z*(-1 + x + 2*y + z);
2263  dshape(17,2) = -27*y*(-1 + x + y + 2*z);
2264  dshape(16,0) = 27*y*z;
2265  dshape(16,1) = 27*x*z;
2266  dshape(16,2) = 27*x*y;
2267  dshape(14,0) = 0;
2268  dshape(14,1) = (9*(-1 + 6*y)*z)/2.;
2269  dshape(14,2) = (9*y*(-1 + 3*y))/2.;
2270  dshape(9,0) = (9*(1 - 3*z)*z)/2.;
2271  dshape(9,1) = (9*(1 - 3*z)*z)/2.;
2272  dshape(9,2) = (9*(-1 + x + y + 8*z - 6*(x + y)*z - 9*pow(z,2)))/2.;
2273  dshape(13,0) = (9*z*(-1 + 3*z))/2.;
2274  dshape(13,1) = 0;
2275  dshape(13,2) = (9*x*(-1 + 6*z))/2.;
2276  dshape(15,0) = 0;
2277  dshape(15,1) = (9*z*(-1 + 3*z))/2.;
2278  dshape(15,2) = (9*y*(-1 + 6*z))/2.;
2279  dshape(3,0) = 0;
2280  dshape(3,1) = 0;
2281  dshape(3,2) = 1 + (9*z*(-2 + 3*z))/2.;
2282 }
2283
2284
2286  : NodalFiniteElement(2, Geometry::TRIANGLE, 1, 0)
2287 {
2288  Nodes.IntPoint(0).x = 0.333333333333333333;
2289  Nodes.IntPoint(0).y = 0.333333333333333333;
2290 }
2291
2293  Vector &shape) const
2294 {
2295  shape(0) = 1.0;
2296 }
2297
2299  DenseMatrix &dshape) const
2300 {
2301  dshape(0,0) = 0.0;
2302  dshape(0,1) = 0.0;
2303 }
2304
2305
2307  : NodalFiniteElement(2, Geometry::SQUARE, 1, 0, FunctionSpace::Qk)
2308 {
2309  Nodes.IntPoint(0).x = 0.5;
2310  Nodes.IntPoint(0).y = 0.5;
2311 }
2312
2314  Vector &shape) const
2315 {
2316  shape(0) = 1.0;
2317 }
2318
2320  DenseMatrix &dshape) const
2321 {
2322  dshape(0,0) = 0.0;
2323  dshape(0,1) = 0.0;
2324 }
2325
2326
2328  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 4, 1)
2329 {
2330  Nodes.IntPoint(0).x = 0.0;
2331  Nodes.IntPoint(0).y = 0.0;
2332  Nodes.IntPoint(0).z = 0.0;
2333  Nodes.IntPoint(1).x = 1.0;
2334  Nodes.IntPoint(1).y = 0.0;
2335  Nodes.IntPoint(1).z = 0.0;
2336  Nodes.IntPoint(2).x = 0.0;
2337  Nodes.IntPoint(2).y = 1.0;
2338  Nodes.IntPoint(2).z = 0.0;
2339  Nodes.IntPoint(3).x = 0.0;
2340  Nodes.IntPoint(3).y = 0.0;
2341  Nodes.IntPoint(3).z = 1.0;
2342 }
2343
2345  Vector &shape) const
2346 {
2347  shape(0) = 1. - ip.x - ip.y - ip.z;
2348  shape(1) = ip.x;
2349  shape(2) = ip.y;
2350  shape(3) = ip.z;
2351 }
2352
2354  DenseMatrix &dshape) const
2355 {
2356  if (dshape.Height() == 4)
2357  {
2358  double *A = &dshape(0,0);
2359  A[0] = -1.; A[4] = -1.; A[8] = -1.;
2360  A[1] = 1.; A[5] = 0.; A[9] = 0.;
2361  A[2] = 0.; A[6] = 1.; A[10] = 0.;
2362  A[3] = 0.; A[7] = 0.; A[11] = 1.;
2363  }
2364  else
2365  {
2366  dshape(0,0) = -1.; dshape(0,1) = -1.; dshape(0,2) = -1.;
2367  dshape(1,0) = 1.; dshape(1,1) = 0.; dshape(1,2) = 0.;
2368  dshape(2,0) = 0.; dshape(2,1) = 1.; dshape(2,2) = 0.;
2369  dshape(3,0) = 0.; dshape(3,1) = 0.; dshape(3,2) = 1.;
2370  }
2371 }
2372
2373 void Linear3DFiniteElement::GetFaceDofs (int face, int **dofs, int *ndofs)
2374 const
2375 {
2376  static int face_dofs[4][3] = {{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}};
2377
2378  *ndofs = 3;
2379  *dofs = face_dofs[face];
2380 }
2381
2382
2384  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 10, 2)
2385 {
2386  Nodes.IntPoint(0).x = 0.0;
2387  Nodes.IntPoint(0).y = 0.0;
2388  Nodes.IntPoint(0).z = 0.0;
2389  Nodes.IntPoint(1).x = 1.0;
2390  Nodes.IntPoint(1).y = 0.0;
2391  Nodes.IntPoint(1).z = 0.0;
2392  Nodes.IntPoint(2).x = 0.0;
2393  Nodes.IntPoint(2).y = 1.0;
2394  Nodes.IntPoint(2).z = 0.0;
2395  Nodes.IntPoint(3).x = 0.0;
2396  Nodes.IntPoint(3).y = 0.0;
2397  Nodes.IntPoint(3).z = 1.0;
2398  Nodes.IntPoint(4).x = 0.5;
2399  Nodes.IntPoint(4).y = 0.0;
2400  Nodes.IntPoint(4).z = 0.0;
2401  Nodes.IntPoint(5).x = 0.0;
2402  Nodes.IntPoint(5).y = 0.5;
2403  Nodes.IntPoint(5).z = 0.0;
2404  Nodes.IntPoint(6).x = 0.0;
2405  Nodes.IntPoint(6).y = 0.0;
2406  Nodes.IntPoint(6).z = 0.5;
2407  Nodes.IntPoint(7).x = 0.5;
2408  Nodes.IntPoint(7).y = 0.5;
2409  Nodes.IntPoint(7).z = 0.0;
2410  Nodes.IntPoint(8).x = 0.5;
2411  Nodes.IntPoint(8).y = 0.0;
2412  Nodes.IntPoint(8).z = 0.5;
2413  Nodes.IntPoint(9).x = 0.0;
2414  Nodes.IntPoint(9).y = 0.5;
2415  Nodes.IntPoint(9).z = 0.5;
2416 }
2417
2419  Vector &shape) const
2420 {
2421  double L0, L1, L2, L3;
2422
2423  L0 = 1. - ip.x - ip.y - ip.z;
2424  L1 = ip.x;
2425  L2 = ip.y;
2426  L3 = ip.z;
2427
2428  shape(0) = L0 * ( 2.0 * L0 - 1.0 );
2429  shape(1) = L1 * ( 2.0 * L1 - 1.0 );
2430  shape(2) = L2 * ( 2.0 * L2 - 1.0 );
2431  shape(3) = L3 * ( 2.0 * L3 - 1.0 );
2432  shape(4) = 4.0 * L0 * L1;
2433  shape(5) = 4.0 * L0 * L2;
2434  shape(6) = 4.0 * L0 * L3;
2435  shape(7) = 4.0 * L1 * L2;
2436  shape(8) = 4.0 * L1 * L3;
2437  shape(9) = 4.0 * L2 * L3;
2438 }
2439
2441  DenseMatrix &dshape) const
2442 {
2443  double x, y, z, L0;
2444
2445  x = ip.x;
2446  y = ip.y;
2447  z = ip.z;
2448  L0 = 1.0 - x - y - z;
2449
2450  dshape(0,0) = dshape(0,1) = dshape(0,2) = 1.0 - 4.0 * L0;
2451  dshape(1,0) = -1.0 + 4.0 * x; dshape(1,1) = 0.0; dshape(1,2) = 0.0;
2452  dshape(2,0) = 0.0; dshape(2,1) = -1.0 + 4.0 * y; dshape(2,2) = 0.0;
2453  dshape(3,0) = dshape(3,1) = 0.0; dshape(3,2) = -1.0 + 4.0 * z;
2454  dshape(4,0) = 4.0 * (L0 - x); dshape(4,1) = dshape(4,2) = -4.0 * x;
2455  dshape(5,0) = dshape(5,2) = -4.0 * y; dshape(5,1) = 4.0 * (L0 - y);
2456  dshape(6,0) = dshape(6,1) = -4.0 * z; dshape(6,2) = 4.0 * (L0 - z);
2457  dshape(7,0) = 4.0 * y; dshape(7,1) = 4.0 * x; dshape(7,2) = 0.0;
2458  dshape(8,0) = 4.0 * z; dshape(8,1) = 0.0; dshape(8,2) = 4.0 * x;
2459  dshape(9,0) = 0.0; dshape(9,1) = 4.0 * z; dshape(9,2) = 4.0 * y;
2460 }
2461
2463  : NodalFiniteElement(3, Geometry::CUBE, 8, 1, FunctionSpace::Qk)
2464 {
2465  Nodes.IntPoint(0).x = 0.0;
2466  Nodes.IntPoint(0).y = 0.0;
2467  Nodes.IntPoint(0).z = 0.0;
2468
2469  Nodes.IntPoint(1).x = 1.0;
2470  Nodes.IntPoint(1).y = 0.0;
2471  Nodes.IntPoint(1).z = 0.0;
2472
2473  Nodes.IntPoint(2).x = 1.0;
2474  Nodes.IntPoint(2).y = 1.0;
2475  Nodes.IntPoint(2).z = 0.0;
2476
2477  Nodes.IntPoint(3).x = 0.0;
2478  Nodes.IntPoint(3).y = 1.0;
2479  Nodes.IntPoint(3).z = 0.0;
2480
2481  Nodes.IntPoint(4).x = 0.0;
2482  Nodes.IntPoint(4).y = 0.0;
2483  Nodes.IntPoint(4).z = 1.0;
2484
2485  Nodes.IntPoint(5).x = 1.0;
2486  Nodes.IntPoint(5).y = 0.0;
2487  Nodes.IntPoint(5).z = 1.0;
2488
2489  Nodes.IntPoint(6).x = 1.0;
2490  Nodes.IntPoint(6).y = 1.0;
2491  Nodes.IntPoint(6).z = 1.0;
2492
2493  Nodes.IntPoint(7).x = 0.0;
2494  Nodes.IntPoint(7).y = 1.0;
2495  Nodes.IntPoint(7).z = 1.0;
2496 }
2497
2499  Vector &shape) const
2500 {
2501  double x = ip.x, y = ip.y, z = ip.z;
2502  double ox = 1.-x, oy = 1.-y, oz = 1.-z;
2503
2504  shape(0) = ox * oy * oz;
2505  shape(1) = x * oy * oz;
2506  shape(2) = x * y * oz;
2507  shape(3) = ox * y * oz;
2508  shape(4) = ox * oy * z;
2509  shape(5) = x * oy * z;
2510  shape(6) = x * y * z;
2511  shape(7) = ox * y * z;
2512 }
2513
2515  DenseMatrix &dshape) const
2516 {
2517  double x = ip.x, y = ip.y, z = ip.z;
2518  double ox = 1.-x, oy = 1.-y, oz = 1.-z;
2519
2520  dshape(0,0) = - oy * oz;
2521  dshape(0,1) = - ox * oz;
2522  dshape(0,2) = - ox * oy;
2523
2524  dshape(1,0) = oy * oz;
2525  dshape(1,1) = - x * oz;
2526  dshape(1,2) = - x * oy;
2527
2528  dshape(2,0) = y * oz;
2529  dshape(2,1) = x * oz;
2530  dshape(2,2) = - x * y;
2531
2532  dshape(3,0) = - y * oz;
2533  dshape(3,1) = ox * oz;
2534  dshape(3,2) = - ox * y;
2535
2536  dshape(4,0) = - oy * z;
2537  dshape(4,1) = - ox * z;
2538  dshape(4,2) = ox * oy;
2539
2540  dshape(5,0) = oy * z;
2541  dshape(5,1) = - x * z;
2542  dshape(5,2) = x * oy;
2543
2544  dshape(6,0) = y * z;
2545  dshape(6,1) = x * z;
2546  dshape(6,2) = x * y;
2547
2548  dshape(7,0) = - y * z;
2549  dshape(7,1) = ox * z;
2550  dshape(7,2) = ox * y;
2551 }
2552
2554  : NodalFiniteElement(1, Geometry::SEGMENT, 1, Ord) // defaul Ord = 0
2555 {
2556  Nodes.IntPoint(0).x = 0.5;
2557 }
2558
2560  Vector &shape) const
2561 {
2562  shape(0) = 1.0;
2563 }
2564
2566  DenseMatrix &dshape) const
2567 {
2568  dshape(0,0) = 0.0;
2569 }
2570
2572  : NodalFiniteElement(2, Geometry::TRIANGLE, 3, 1)
2573 {
2574  Nodes.IntPoint(0).x = 0.5;
2575  Nodes.IntPoint(0).y = 0.0;
2576  Nodes.IntPoint(1).x = 0.5;
2577  Nodes.IntPoint(1).y = 0.5;
2578  Nodes.IntPoint(2).x = 0.0;
2579  Nodes.IntPoint(2).y = 0.5;
2580 }
2581
2583  Vector &shape) const
2584 {
2585  shape(0) = 1.0 - 2.0 * ip.y;
2586  shape(1) = -1.0 + 2.0 * ( ip.x + ip.y );
2587  shape(2) = 1.0 - 2.0 * ip.x;
2588 }
2589
2591  DenseMatrix &dshape) const
2592 {
2593  dshape(0,0) = 0.0; dshape(0,1) = -2.0;
2594  dshape(1,0) = 2.0; dshape(1,1) = 2.0;
2595  dshape(2,0) = -2.0; dshape(2,1) = 0.0;
2596 }
2597
2599 // the FunctionSpace should be rotated (45 degrees) Q_1
2600 // i.e. the span of { 1, x, y, x^2 - y^2 }
2601  : NodalFiniteElement(2, Geometry::SQUARE, 4, 2, FunctionSpace::Qk)
2602 {
2603  Nodes.IntPoint(0).x = 0.5;
2604  Nodes.IntPoint(0).y = 0.0;
2605  Nodes.IntPoint(1).x = 1.0;
2606  Nodes.IntPoint(1).y = 0.5;
2607  Nodes.IntPoint(2).x = 0.5;
2608  Nodes.IntPoint(2).y = 1.0;
2609  Nodes.IntPoint(3).x = 0.0;
2610  Nodes.IntPoint(3).y = 0.5;
2611 }
2612
2614  Vector &shape) const
2615 {
2616  const double l1 = ip.x+ip.y-0.5, l2 = 1.-l1, l3 = ip.x-ip.y+0.5, l4 = 1.-l3;
2617
2618  shape(0) = l2 * l3;
2619  shape(1) = l1 * l3;
2620  shape(2) = l1 * l4;
2621  shape(3) = l2 * l4;
2622 }
2623
2625  DenseMatrix &dshape) const
2626 {
2627  const double x2 = 2.*ip.x, y2 = 2.*ip.y;
2628
2629  dshape(0,0) = 1. - x2; dshape(0,1) = -2. + y2;
2630  dshape(1,0) = x2; dshape(1,1) = 1. - y2;
2631  dshape(2,0) = 1. - x2; dshape(2,1) = y2;
2632  dshape(3,0) = -2. + x2; dshape(3,1) = 1. - y2;
2633 }
2634
2635
2637  : VectorFiniteElement(2, Geometry::TRIANGLE, 3, 1, H_DIV)
2638 {
2639  Nodes.IntPoint(0).x = 0.5;
2640  Nodes.IntPoint(0).y = 0.0;
2641  Nodes.IntPoint(1).x = 0.5;
2642  Nodes.IntPoint(1).y = 0.5;
2643  Nodes.IntPoint(2).x = 0.0;
2644  Nodes.IntPoint(2).y = 0.5;
2645 }
2646
2648  DenseMatrix &shape) const
2649 {
2650  double x = ip.x, y = ip.y;
2651
2652  shape(0,0) = x;
2653  shape(0,1) = y - 1.;
2654  shape(1,0) = x;
2655  shape(1,1) = y;
2656  shape(2,0) = x - 1.;
2657  shape(2,1) = y;
2658 }
2659
2661  Vector &divshape) const
2662 {
2663  divshape(0) = 2.;
2664  divshape(1) = 2.;
2665  divshape(2) = 2.;
2666 }
2667
2668 const double RT0TriangleFiniteElement::nk[3][2] =
2669 { {0, -1}, {1, 1}, {-1, 0} };
2670
2673 {
2674  int k, j;
2677  DenseMatrix Jinv(Dim);
2678 #endif
2679
2680 #ifdef MFEM_DEBUG
2681  for (k = 0; k < 3; k++)
2682  {
2684  for (j = 0; j < 3; j++)
2685  {
2686  double d = vshape(j,0)*nk[k][0]+vshape(j,1)*nk[k][1];
2687  if (j == k) { d -= 1.0; }
2688  if (fabs(d) > 1.0e-12)
2689  {
2690  mfem::err << "RT0TriangleFiniteElement::GetLocalInterpolation (...)\n"
2691  " k = " << k << ", j = " << j << ", d = " << d << endl;
2692  mfem_error();
2693  }
2694  }
2695  }
2696 #endif
2697
2698  IntegrationPoint ip;
2699  ip.x = ip.y = 0.0;
2700  Trans.SetIntPoint (&ip);
2701  // Trans must be linear
2702  // set Jinv = |J| J^{-t} = adj(J)^t
2703  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2704  double vk[2];
2705  Vector xk (vk, 2);
2706
2707  for (k = 0; k < 3; k++)
2708  {
2709  Trans.Transform (Nodes.IntPoint (k), xk);
2710  ip.x = vk[0]; ip.y = vk[1];
2711  CalcVShape (ip, vshape);
2712  // vk = |J| J^{-t} nk
2713  vk[0] = Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1];
2714  vk[1] = Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1];
2715  for (j = 0; j < 3; j++)
2716  if (fabs (I(k,j) = vshape(j,0)*vk[0]+vshape(j,1)*vk[1]) < 1.0e-12)
2717  {
2718  I(k,j) = 0.0;
2719  }
2720  }
2721 }
2722
2725  Vector &dofs) const
2726 {
2727  double vk[2];
2728  Vector xk (vk, 2);
2730  DenseMatrix Jinv(Dim);
2731 #endif
2732
2733  for (int k = 0; k < 3; k++)
2734  {
2735  Trans.SetIntPoint (&Nodes.IntPoint (k));
2736  // set Jinv = |J| J^{-t} = adj(J)^t
2737  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2738
2739  vc.Eval (xk, Trans, Nodes.IntPoint (k));
2740  // xk^t |J| J^{-t} nk
2741  dofs(k) = (vk[0] * ( Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1] ) +
2742  vk[1] * ( Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1] ));
2743  }
2744 }
2745
2747  : VectorFiniteElement(2, Geometry::SQUARE, 4, 1, H_DIV, FunctionSpace::Qk)
2748 {
2749  Nodes.IntPoint(0).x = 0.5;
2750  Nodes.IntPoint(0).y = 0.0;
2751  Nodes.IntPoint(1).x = 1.0;
2752  Nodes.IntPoint(1).y = 0.5;
2753  Nodes.IntPoint(2).x = 0.5;
2754  Nodes.IntPoint(2).y = 1.0;
2755  Nodes.IntPoint(3).x = 0.0;
2756  Nodes.IntPoint(3).y = 0.5;
2757 }
2758
2760  DenseMatrix &shape) const
2761 {
2762  double x = ip.x, y = ip.y;
2763
2764  shape(0,0) = 0;
2765  shape(0,1) = y - 1.;
2766  shape(1,0) = x;
2767  shape(1,1) = 0;
2768  shape(2,0) = 0;
2769  shape(2,1) = y;
2770  shape(3,0) = x - 1.;
2771  shape(3,1) = 0;
2772 }
2773
2775  Vector &divshape) const
2776 {
2777  divshape(0) = 1.;
2778  divshape(1) = 1.;
2779  divshape(2) = 1.;
2780  divshape(3) = 1.;
2781 }
2782
2783 const double RT0QuadFiniteElement::nk[4][2] =
2784 { {0, -1}, {1, 0}, {0, 1}, {-1, 0} };
2785
2788 {
2789  int k, j;
2792  DenseMatrix Jinv(Dim);
2793 #endif
2794
2795 #ifdef MFEM_DEBUG
2796  for (k = 0; k < 4; k++)
2797  {
2799  for (j = 0; j < 4; j++)
2800  {
2801  double d = vshape(j,0)*nk[k][0]+vshape(j,1)*nk[k][1];
2802  if (j == k) { d -= 1.0; }
2803  if (fabs(d) > 1.0e-12)
2804  {
2805  mfem::err << "RT0QuadFiniteElement::GetLocalInterpolation (...)\n"
2806  " k = " << k << ", j = " << j << ", d = " << d << endl;
2807  mfem_error();
2808  }
2809  }
2810  }
2811 #endif
2812
2813  IntegrationPoint ip;
2814  ip.x = ip.y = 0.0;
2815  Trans.SetIntPoint (&ip);
2816  // Trans must be linear (more to have embedding?)
2817  // set Jinv = |J| J^{-t} = adj(J)^t
2818  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2819  double vk[2];
2820  Vector xk (vk, 2);
2821
2822  for (k = 0; k < 4; k++)
2823  {
2824  Trans.Transform (Nodes.IntPoint (k), xk);
2825  ip.x = vk[0]; ip.y = vk[1];
2826  CalcVShape (ip, vshape);
2827  // vk = |J| J^{-t} nk
2828  vk[0] = Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1];
2829  vk[1] = Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1];
2830  for (j = 0; j < 4; j++)
2831  if (fabs (I(k,j) = vshape(j,0)*vk[0]+vshape(j,1)*vk[1]) < 1.0e-12)
2832  {
2833  I(k,j) = 0.0;
2834  }
2835  }
2836 }
2837
2840  Vector &dofs) const
2841 {
2842  double vk[2];
2843  Vector xk (vk, 2);
2845  DenseMatrix Jinv(Dim);
2846 #endif
2847
2848  for (int k = 0; k < 4; k++)
2849  {
2850  Trans.SetIntPoint (&Nodes.IntPoint (k));
2851  // set Jinv = |J| J^{-t} = adj(J)^t
2852  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2853
2854  vc.Eval (xk, Trans, Nodes.IntPoint (k));
2855  // xk^t |J| J^{-t} nk
2856  dofs(k) = (vk[0] * ( Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1] ) +
2857  vk[1] * ( Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1] ));
2858  }
2859 }
2860
2862  : VectorFiniteElement(2, Geometry::TRIANGLE, 8, 2, H_DIV)
2863 {
2864  Nodes.IntPoint(0).x = 0.33333333333333333333;
2865  Nodes.IntPoint(0).y = 0.0;
2866  Nodes.IntPoint(1).x = 0.66666666666666666667;
2867  Nodes.IntPoint(1).y = 0.0;
2868  Nodes.IntPoint(2).x = 0.66666666666666666667;
2869  Nodes.IntPoint(2).y = 0.33333333333333333333;
2870  Nodes.IntPoint(3).x = 0.33333333333333333333;
2871  Nodes.IntPoint(3).y = 0.66666666666666666667;
2872  Nodes.IntPoint(4).x = 0.0;
2873  Nodes.IntPoint(4).y = 0.66666666666666666667;
2874  Nodes.IntPoint(5).x = 0.0;
2875  Nodes.IntPoint(5).y = 0.33333333333333333333;
2876  Nodes.IntPoint(6).x = 0.33333333333333333333;
2877  Nodes.IntPoint(6).y = 0.33333333333333333333;
2878  Nodes.IntPoint(7).x = 0.33333333333333333333;
2879  Nodes.IntPoint(7).y = 0.33333333333333333333;
2880 }
2881
2883  DenseMatrix &shape) const
2884 {
2885  double x = ip.x, y = ip.y;
2886
2887  shape(0,0) = -2 * x * (-1 + x + 2 * y);
2888  shape(0,1) = -2 * (-1 + y) * (-1 + x + 2 * y);
2889  shape(1,0) = 2 * x * (x - y);
2890  shape(1,1) = 2 * (x - y) * (-1 + y);
2891  shape(2,0) = 2 * x * (-1 + 2 * x + y);
2892  shape(2,1) = 2 * y * (-1 + 2 * x + y);
2893  shape(3,0) = 2 * x * (-1 + x + 2 * y);
2894  shape(3,1) = 2 * y * (-1 + x + 2 * y);
2895  shape(4,0) = -2 * (-1 + x) * (x - y);
2896  shape(4,1) = 2 * y * (-x + y);
2897  shape(5,0) = -2 * (-1 + x) * (-1 + 2 * x + y);
2898  shape(5,1) = -2 * y * (-1 + 2 * x + y);
2899  shape(6,0) = -3 * x * (-2 + 2 * x + y);
2900  shape(6,1) = -3 * y * (-1 + 2 * x + y);
2901  shape(7,0) = -3 * x * (-1 + x + 2 * y);
2902  shape(7,1) = -3 * y * (-2 + x + 2 * y);
2903 }
2904
2906  Vector &divshape) const
2907 {
2908  double x = ip.x, y = ip.y;
2909
2910  divshape(0) = -2 * (-4 + 3 * x + 6 * y);
2911  divshape(1) = 2 + 6 * x - 6 * y;
2912  divshape(2) = -4 + 12 * x + 6 * y;
2913  divshape(3) = -4 + 6 * x + 12 * y;
2914  divshape(4) = 2 - 6 * x + 6 * y;
2915  divshape(5) = -2 * (-4 + 6 * x + 3 * y);
2916  divshape(6) = -9 * (-1 + 2 * x + y);
2917  divshape(7) = -9 * (-1 + x + 2 * y);
2918 }
2919
2920 const double RT1TriangleFiniteElement::nk[8][2] =
2921 {
2922  { 0,-1}, { 0,-1},
2923  { 1, 1}, { 1, 1},
2924  {-1, 0}, {-1, 0},
2925  { 1, 0}, { 0, 1}
2926 };
2927
2930 {
2931  int k, j;
2934  DenseMatrix Jinv(Dim);
2935 #endif
2936
2937 #ifdef MFEM_DEBUG
2938  for (k = 0; k < 8; k++)
2939  {
2941  for (j = 0; j < 8; j++)
2942  {
2943  double d = vshape(j,0)*nk[k][0]+vshape(j,1)*nk[k][1];
2944  if (j == k) { d -= 1.0; }
2945  if (fabs(d) > 1.0e-12)
2946  {
2947  mfem::err << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n"
2948  " k = " << k << ", j = " << j << ", d = " << d << endl;
2949  mfem_error();
2950  }
2951  }
2952  }
2953 #endif
2954
2955  IntegrationPoint ip;
2956  ip.x = ip.y = 0.0;
2957  Trans.SetIntPoint (&ip);
2958  // Trans must be linear (more to have embedding?)
2959  // set Jinv = |J| J^{-t} = adj(J)^t
2960  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2961  double vk[2];
2962  Vector xk (vk, 2);
2963
2964  for (k = 0; k < 8; k++)
2965  {
2966  Trans.Transform (Nodes.IntPoint (k), xk);
2967  ip.x = vk[0]; ip.y = vk[1];
2968  CalcVShape (ip, vshape);
2969  // vk = |J| J^{-t} nk
2970  vk[0] = Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1];
2971  vk[1] = Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1];
2972  for (j = 0; j < 8; j++)
2973  if (fabs (I(k,j) = vshape(j,0)*vk[0]+vshape(j,1)*vk[1]) < 1.0e-12)
2974  {
2975  I(k,j) = 0.0;
2976  }
2977  }
2978 }
2979
2982 {
2983  double vk[2];
2984  Vector xk (vk, 2);
2986  DenseMatrix Jinv(Dim);
2987 #endif
2988
2989  for (int k = 0; k < 8; k++)
2990  {
2991  Trans.SetIntPoint (&Nodes.IntPoint (k));
2992  // set Jinv = |J| J^{-t} = adj(J)^t
2993  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
2994
2995  vc.Eval (xk, Trans, Nodes.IntPoint (k));
2996  // xk^t |J| J^{-t} nk
2997  dofs(k) = (vk[0] * ( Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1] ) +
2998  vk[1] * ( Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1] ));
2999  dofs(k) *= 0.5;
3000  }
3001 }
3002
3004  : VectorFiniteElement(2, Geometry::SQUARE, 12, 2, H_DIV, FunctionSpace::Qk)
3005 {
3006  // y = 0
3007  Nodes.IntPoint(0).x = 1./3.;
3008  Nodes.IntPoint(0).y = 0.0;
3009  Nodes.IntPoint(1).x = 2./3.;
3010  Nodes.IntPoint(1).y = 0.0;
3011  // x = 1
3012  Nodes.IntPoint(2).x = 1.0;
3013  Nodes.IntPoint(2).y = 1./3.;
3014  Nodes.IntPoint(3).x = 1.0;
3015  Nodes.IntPoint(3).y = 2./3.;
3016  // y = 1
3017  Nodes.IntPoint(4).x = 2./3.;
3018  Nodes.IntPoint(4).y = 1.0;
3019  Nodes.IntPoint(5).x = 1./3.;
3020  Nodes.IntPoint(5).y = 1.0;
3021  // x = 0
3022  Nodes.IntPoint(6).x = 0.0;
3023  Nodes.IntPoint(6).y = 2./3.;
3024  Nodes.IntPoint(7).x = 0.0;
3025  Nodes.IntPoint(7).y = 1./3.;
3026  // x = 0.5 (interior)
3027  Nodes.IntPoint(8).x = 0.5;
3028  Nodes.IntPoint(8).y = 1./3.;
3029  Nodes.IntPoint(9).x = 0.5;
3030  Nodes.IntPoint(9).y = 2./3.;
3031  // y = 0.5 (interior)
3032  Nodes.IntPoint(10).x = 1./3.;
3033  Nodes.IntPoint(10).y = 0.5;
3034  Nodes.IntPoint(11).x = 2./3.;
3035  Nodes.IntPoint(11).y = 0.5;
3036 }
3037
3039  DenseMatrix &shape) const
3040 {
3041  double x = ip.x, y = ip.y;
3042
3043  // y = 0
3044  shape(0,0) = 0;
3045  shape(0,1) = -( 1. - 3.*y + 2.*y*y)*( 2. - 3.*x);
3046  shape(1,0) = 0;
3047  shape(1,1) = -( 1. - 3.*y + 2.*y*y)*(-1. + 3.*x);
3048  // x = 1
3049  shape(2,0) = (-x + 2.*x*x)*( 2. - 3.*y);
3050  shape(2,1) = 0;
3051  shape(3,0) = (-x + 2.*x*x)*(-1. + 3.*y);
3052  shape(3,1) = 0;
3053  // y = 1
3054  shape(4,0) = 0;
3055  shape(4,1) = (-y + 2.*y*y)*(-1. + 3.*x);
3056  shape(5,0) = 0;
3057  shape(5,1) = (-y + 2.*y*y)*( 2. - 3.*x);
3058  // x = 0
3059  shape(6,0) = -(1. - 3.*x + 2.*x*x)*(-1. + 3.*y);
3060  shape(6,1) = 0;
3061  shape(7,0) = -(1. - 3.*x + 2.*x*x)*( 2. - 3.*y);
3062  shape(7,1) = 0;
3063  // x = 0.5 (interior)
3064  shape(8,0) = (4.*x - 4.*x*x)*( 2. - 3.*y);
3065  shape(8,1) = 0;
3066  shape(9,0) = (4.*x - 4.*x*x)*(-1. + 3.*y);
3067  shape(9,1) = 0;
3068  // y = 0.5 (interior)
3069  shape(10,0) = 0;
3070  shape(10,1) = (4.*y - 4.*y*y)*( 2. - 3.*x);
3071  shape(11,0) = 0;
3072  shape(11,1) = (4.*y - 4.*y*y)*(-1. + 3.*x);
3073 }
3074
3076  Vector &divshape) const
3077 {
3078  double x = ip.x, y = ip.y;
3079
3080  divshape(0) = -(-3. + 4.*y)*( 2. - 3.*x);
3081  divshape(1) = -(-3. + 4.*y)*(-1. + 3.*x);
3082  divshape(2) = (-1. + 4.*x)*( 2. - 3.*y);
3083  divshape(3) = (-1. + 4.*x)*(-1. + 3.*y);
3084  divshape(4) = (-1. + 4.*y)*(-1. + 3.*x);
3085  divshape(5) = (-1. + 4.*y)*( 2. - 3.*x);
3086  divshape(6) = -(-3. + 4.*x)*(-1. + 3.*y);
3087  divshape(7) = -(-3. + 4.*x)*( 2. - 3.*y);
3088  divshape(8) = ( 4. - 8.*x)*( 2. - 3.*y);
3089  divshape(9) = ( 4. - 8.*x)*(-1. + 3.*y);
3090  divshape(10) = ( 4. - 8.*y)*( 2. - 3.*x);
3091  divshape(11) = ( 4. - 8.*y)*(-1. + 3.*x);
3092 }
3093
3094 const double RT1QuadFiniteElement::nk[12][2] =
3095 {
3096  // y = 0
3097  {0,-1}, {0,-1},
3098  // X = 1
3099  {1, 0}, {1, 0},
3100  // y = 1
3101  {0, 1}, {0, 1},
3102  // x = 0
3103  {-1,0}, {-1,0},
3104  // x = 0.5 (interior)
3105  {1, 0}, {1, 0},
3106  // y = 0.5 (interior)
3107  {0, 1}, {0, 1}
3108 };
3109
3112 {
3113  int k, j;
3116  DenseMatrix Jinv(Dim);
3117 #endif
3118
3119 #ifdef MFEM_DEBUG
3120  for (k = 0; k < 12; k++)
3121  {
3123  for (j = 0; j < 12; j++)
3124  {
3125  double d = vshape(j,0)*nk[k][0]+vshape(j,1)*nk[k][1];
3126  if (j == k) { d -= 1.0; }
3127  if (fabs(d) > 1.0e-12)
3128  {
3129  mfem::err << "RT1QuadFiniteElement::GetLocalInterpolation (...)\n"
3130  " k = " << k << ", j = " << j << ", d = " << d << endl;
3131  mfem_error();
3132  }
3133  }
3134  }
3135 #endif
3136
3137  IntegrationPoint ip;
3138  ip.x = ip.y = 0.0;
3139  Trans.SetIntPoint (&ip);
3140  // Trans must be linear (more to have embedding?)
3141  // set Jinv = |J| J^{-t} = adj(J)^t
3142  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
3143  double vk[2];
3144  Vector xk (vk, 2);
3145
3146  for (k = 0; k < 12; k++)
3147  {
3148  Trans.Transform (Nodes.IntPoint (k), xk);
3149  ip.x = vk[0]; ip.y = vk[1];
3150  CalcVShape (ip, vshape);
3151  // vk = |J| J^{-t} nk
3152  vk[0] = Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1];
3153  vk[1] = Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1];
3154  for (j = 0; j < 12; j++)
3155  if (fabs (I(k,j) = vshape(j,0)*vk[0]+vshape(j,1)*vk[1]) < 1.0e-12)
3156  {
3157  I(k,j) = 0.0;
3158  }
3159  }
3160 }
3161
3164 {
3165  double vk[2];
3166  Vector xk (vk, 2);
3168  DenseMatrix Jinv(Dim);
3169 #endif
3170
3171  for (int k = 0; k < 12; k++)
3172  {
3173  Trans.SetIntPoint (&Nodes.IntPoint (k));
3174  // set Jinv = |J| J^{-t} = adj(J)^t
3175  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
3176
3177  vc.Eval (xk, Trans, Nodes.IntPoint (k));
3178  // xk^t |J| J^{-t} nk
3179  dofs(k) = (vk[0] * ( Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1] ) +
3180  vk[1] * ( Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1] ));
3181  }
3182 }
3183
3184 const double RT2TriangleFiniteElement::M[15][15] =
3185 {
3186  {
3187  0, -5.3237900077244501311, 5.3237900077244501311, 16.647580015448900262,
3188  0, 24.442740046346700787, -16.647580015448900262, -12.,
3189  -19.118950038622250656, -47.237900077244501311, 0, -34.414110069520051180,
3190  12., 30.590320061795601049, 15.295160030897800524
3191  },
3192  {
3193  0, 1.5, -1.5, -15., 0, 2.625, 15., 15., -4.125, 30., 0, -14.625, -15.,
3194  -15., 10.5
3195  },
3196  {
3197  0, -0.67620999227554986889, 0.67620999227554986889, 7.3524199845510997378,
3198  0, -3.4427400463467007866, -7.3524199845510997378, -12.,
3199  4.1189500386222506555, -0.76209992275549868892, 0, 7.4141100695200511800,
3200  12., -6.5903200617956010489, -3.2951600308978005244
3201  },
3202  {
3203  0, 0, 1.5, 0, 0, 1.5, -11.471370023173350393, 0, 2.4713700231733503933,
3204  -11.471370023173350393, 0, 2.4713700231733503933, 15.295160030897800524,
3205  0, -3.2951600308978005244
3206  },
3207  {
3208  0, 0, 4.875, 0, 0, 4.875, -16.875, 0, -16.875, -16.875, 0, -16.875, 10.5,
3209  36., 10.5
3210  },
3211  {
3212  0, 0, 1.5, 0, 0, 1.5, 2.4713700231733503933, 0, -11.471370023173350393,
3213  2.4713700231733503933, 0, -11.471370023173350393, -3.2951600308978005244,
3214  0, 15.295160030897800524
3215  },
3216  {
3217  -0.67620999227554986889, 0, -3.4427400463467007866, 0,
3218  7.3524199845510997378, 0.67620999227554986889, 7.4141100695200511800, 0,
3219  -0.76209992275549868892, 4.1189500386222506555, -12.,
3220  -7.3524199845510997378, -3.2951600308978005244, -6.5903200617956010489,
3221  12.
3222  },
3223  {
3224  1.5, 0, 2.625, 0, -15., -1.5, -14.625, 0, 30., -4.125, 15., 15., 10.5,
3225  -15., -15.
3226  },
3227  {
3228  -5.3237900077244501311, 0, 24.442740046346700787, 0, 16.647580015448900262,
3229  5.3237900077244501311, -34.414110069520051180, 0, -47.237900077244501311,
3230  -19.118950038622250656, -12., -16.647580015448900262, 15.295160030897800524,
3231  30.590320061795601049, 12.
3232  },
3233  { 0, 0, 18., 0, 0, 6., -42., 0, -30., -26., 0, -14., 24., 32., 8.},
3234  { 0, 0, 6., 0, 0, 18., -14., 0, -26., -30., 0, -42., 8., 32., 24.},
3235  { 0, 0, -6., 0, 0, -4., 30., 0, 4., 22., 0, 4., -24., -16., 0},
3236  { 0, 0, -4., 0, 0, -8., 20., 0, 8., 36., 0, 8., -16., -32., 0},
3237  { 0, 0, -8., 0, 0, -4., 8., 0, 36., 8., 0, 20., 0, -32., -16.},
3238  { 0, 0, -4., 0, 0, -6., 4., 0, 22., 4., 0, 30., 0, -16., -24.}
3239 };
3240
3242  : VectorFiniteElement(2, Geometry::TRIANGLE, 15, 3, H_DIV)
3243 {
3244  const double p = 0.11270166537925831148;
3245
3246  Nodes.IntPoint(0).x = p;
3247  Nodes.IntPoint(0).y = 0.0;
3248  Nodes.IntPoint(1).x = 0.5;
3249  Nodes.IntPoint(1).y = 0.0;
3250  Nodes.IntPoint(2).x = 1.-p;
3251  Nodes.IntPoint(2).y = 0.0;
3252  Nodes.IntPoint(3).x = 1.-p;
3253  Nodes.IntPoint(3).y = p;
3254  Nodes.IntPoint(4).x = 0.5;
3255  Nodes.IntPoint(4).y = 0.5;
3256  Nodes.IntPoint(5).x = p;
3257  Nodes.IntPoint(5).y = 1.-p;
3258  Nodes.IntPoint(6).x = 0.0;
3259  Nodes.IntPoint(6).y = 1.-p;
3260  Nodes.IntPoint(7).x = 0.0;
3261  Nodes.IntPoint(7).y = 0.5;
3262  Nodes.IntPoint(8).x = 0.0;
3263  Nodes.IntPoint(8).y = p;
3264  Nodes.IntPoint(9).x = 0.25;
3265  Nodes.IntPoint(9).y = 0.25;
3266  Nodes.IntPoint(10).x = 0.25;
3267  Nodes.IntPoint(10).y = 0.25;
3268  Nodes.IntPoint(11).x = 0.5;
3269  Nodes.IntPoint(11).y = 0.25;
3270  Nodes.IntPoint(12).x = 0.5;
3271  Nodes.IntPoint(12).y = 0.25;
3272  Nodes.IntPoint(13).x = 0.25;
3273  Nodes.IntPoint(13).y = 0.5;
3274  Nodes.IntPoint(14).x = 0.25;
3275  Nodes.IntPoint(14).y = 0.5;
3276 }
3277
3279  DenseMatrix &shape) const
3280 {
3281  double x = ip.x, y = ip.y;
3282
3283  double Bx[15] = {1., 0., x, 0., y, 0., x*x, 0., x*y, 0., y*y, 0., x*x*x,
3284  x*x*y, x*y*y
3285  };
3286  double By[15] = {0., 1., 0., x, 0., y, 0., x*x, 0., x*y, 0., y*y,
3287  x*x*y, x*y*y, y*y*y
3288  };
3289
3290  for (int i = 0; i < 15; i++)
3291  {
3292  double cx = 0.0, cy = 0.0;
3293  for (int j = 0; j < 15; j++)
3294  {
3295  cx += M[i][j] * Bx[j];
3296  cy += M[i][j] * By[j];
3297  }
3298  shape(i,0) = cx;
3299  shape(i,1) = cy;
3300  }
3301 }
3302
3304  Vector &divshape) const
3305 {
3306  double x = ip.x, y = ip.y;
3307
3308  double DivB[15] = {0., 0., 1., 0., 0., 1., 2.*x, 0., y, x, 0., 2.*y,
3309  4.*x*x, 4.*x*y, 4.*y*y
3310  };
3311
3312  for (int i = 0; i < 15; i++)
3313  {
3314  double div = 0.0;
3315  for (int j = 0; j < 15; j++)
3316  {
3317  div += M[i][j] * DivB[j];
3318  }
3319  divshape(i) = div;
3320  }
3321 }
3322
3323 const double RT2QuadFiniteElement::pt[4] = {0.,1./3.,2./3.,1.};
3324
3325 const double RT2QuadFiniteElement::dpt[3] = {0.25,0.5,0.75};
3326
3328  : VectorFiniteElement(2, Geometry::SQUARE, 24, 3, H_DIV, FunctionSpace::Qk)
3329 {
3330  // y = 0 (pt[0])
3331  Nodes.IntPoint(0).x = dpt[0]; Nodes.IntPoint(0).y = pt[0];
3332  Nodes.IntPoint(1).x = dpt[1]; Nodes.IntPoint(1).y = pt[0];
3333  Nodes.IntPoint(2).x = dpt[2]; Nodes.IntPoint(2).y = pt[0];
3334  // x = 1 (pt[3])
3335  Nodes.IntPoint(3).x = pt[3]; Nodes.IntPoint(3).y = dpt[0];
3336  Nodes.IntPoint(4).x = pt[3]; Nodes.IntPoint(4).y = dpt[1];
3337  Nodes.IntPoint(5).x = pt[3]; Nodes.IntPoint(5).y = dpt[2];
3338  // y = 1 (pt[3])
3339  Nodes.IntPoint(6).x = dpt[2]; Nodes.IntPoint(6).y = pt[3];
3340  Nodes.IntPoint(7).x = dpt[1]; Nodes.IntPoint(7).y = pt[3];
3341  Nodes.IntPoint(8).x = dpt[0]; Nodes.IntPoint(8).y = pt[3];
3342  // x = 0 (pt[0])
3343  Nodes.IntPoint(9).x = pt[0]; Nodes.IntPoint(9).y = dpt[2];
3344  Nodes.IntPoint(10).x = pt[0]; Nodes.IntPoint(10).y = dpt[1];
3345  Nodes.IntPoint(11).x = pt[0]; Nodes.IntPoint(11).y = dpt[0];
3346  // x = pt[1] (interior)
3347  Nodes.IntPoint(12).x = pt[1]; Nodes.IntPoint(12).y = dpt[0];
3348  Nodes.IntPoint(13).x = pt[1]; Nodes.IntPoint(13).y = dpt[1];
3349  Nodes.IntPoint(14).x = pt[1]; Nodes.IntPoint(14).y = dpt[2];
3350  // x = pt[2] (interior)
3351  Nodes.IntPoint(15).x = pt[2]; Nodes.IntPoint(15).y = dpt[0];
3352  Nodes.IntPoint(16).x = pt[2]; Nodes.IntPoint(16).y = dpt[1];
3353  Nodes.IntPoint(17).x = pt[2]; Nodes.IntPoint(17).y = dpt[2];
3354  // y = pt[1] (interior)
3355  Nodes.IntPoint(18).x = dpt[0]; Nodes.IntPoint(18).y = pt[1];
3356  Nodes.IntPoint(19).x = dpt[1]; Nodes.IntPoint(19).y = pt[1];
3357  Nodes.IntPoint(20).x = dpt[2]; Nodes.IntPoint(20).y = pt[1];
3358  // y = pt[2] (interior)
3359  Nodes.IntPoint(21).x = dpt[0]; Nodes.IntPoint(21).y = pt[2];
3360  Nodes.IntPoint(22).x = dpt[1]; Nodes.IntPoint(22).y = pt[2];
3361  Nodes.IntPoint(23).x = dpt[2]; Nodes.IntPoint(23).y = pt[2];
3362 }
3363
3365  DenseMatrix &shape) const
3366 {
3367  double x = ip.x, y = ip.y;
3368
3369  double ax0 = pt[0] - x;
3370  double ax1 = pt[1] - x;
3371  double ax2 = pt[2] - x;
3372  double ax3 = pt[3] - x;
3373
3374  double by0 = dpt[0] - y;
3375  double by1 = dpt[1] - y;
3376  double by2 = dpt[2] - y;
3377
3378  double ay0 = pt[0] - y;
3379  double ay1 = pt[1] - y;
3380  double ay2 = pt[2] - y;
3381  double ay3 = pt[3] - y;
3382
3383  double bx0 = dpt[0] - x;
3384  double bx1 = dpt[1] - x;
3385  double bx2 = dpt[2] - x;
3386
3387  double A01 = pt[0] - pt[1];
3388  double A02 = pt[0] - pt[2];
3389  double A12 = pt[1] - pt[2];
3390  double A03 = pt[0] - pt[3];
3391  double A13 = pt[1] - pt[3];
3392  double A23 = pt[2] - pt[3];
3393
3394  double B01 = dpt[0] - dpt[1];
3395  double B02 = dpt[0] - dpt[2];
3396  double B12 = dpt[1] - dpt[2];
3397
3398  double tx0 = (bx1*bx2)/(B01*B02);
3399  double tx1 = -(bx0*bx2)/(B01*B12);
3400  double tx2 = (bx0*bx1)/(B02*B12);
3401
3402  double ty0 = (by1*by2)/(B01*B02);
3403  double ty1 = -(by0*by2)/(B01*B12);
3404  double ty2 = (by0*by1)/(B02*B12);
3405
3406  // y = 0 (p[0])
3407  shape(0, 0) = 0;
3408  shape(0, 1) = (ay1*ay2*ay3)/(A01*A02*A03)*tx0;
3409  shape(1, 0) = 0;
3410  shape(1, 1) = (ay1*ay2*ay3)/(A01*A02*A03)*tx1;
3411  shape(2, 0) = 0;
3412  shape(2, 1) = (ay1*ay2*ay3)/(A01*A02*A03)*tx2;
3413  // x = 1 (p[3])
3414  shape(3, 0) = (ax0*ax1*ax2)/(A03*A13*A23)*ty0;
3415  shape(3, 1) = 0;
3416  shape(4, 0) = (ax0*ax1*ax2)/(A03*A13*A23)*ty1;
3417  shape(4, 1) = 0;
3418  shape(5, 0) = (ax0*ax1*ax2)/(A03*A13*A23)*ty2;
3419  shape(5, 1) = 0;
3420  // y = 1 (p[3])
3421  shape(6, 0) = 0;
3422  shape(6, 1) = (ay0*ay1*ay2)/(A03*A13*A23)*tx2;
3423  shape(7, 0) = 0;
3424  shape(7, 1) = (ay0*ay1*ay2)/(A03*A13*A23)*tx1;
3425  shape(8, 0) = 0;
3426  shape(8, 1) = (ay0*ay1*ay2)/(A03*A13*A23)*tx0;
3427  // x = 0 (p[0])
3428  shape(9, 0) = (ax1*ax2*ax3)/(A01*A02*A03)*ty2;
3429  shape(9, 1) = 0;
3430  shape(10, 0) = (ax1*ax2*ax3)/(A01*A02*A03)*ty1;
3431  shape(10, 1) = 0;
3432  shape(11, 0) = (ax1*ax2*ax3)/(A01*A02*A03)*ty0;
3433  shape(11, 1) = 0;
3434  // x = p[1] (interior)
3435  shape(12, 0) = (ax0*ax2*ax3)/(A01*A12*A13)*ty0;
3436  shape(12, 1) = 0;
3437  shape(13, 0) = (ax0*ax2*ax3)/(A01*A12*A13)*ty1;
3438  shape(13, 1) = 0;
3439  shape(14, 0) = (ax0*ax2*ax3)/(A01*A12*A13)*ty2;
3440  shape(14, 1) = 0;
3441  // x = p[2] (interior)
3442  shape(15, 0) = -(ax0*ax1*ax3)/(A02*A12*A23)*ty0;
3443  shape(15, 1) = 0;
3444  shape(16, 0) = -(ax0*ax1*ax3)/(A02*A12*A23)*ty1;
3445  shape(16, 1) = 0;
3446  shape(17, 0) = -(ax0*ax1*ax3)/(A02*A12*A23)*ty2;
3447  shape(17, 1) = 0;
3448  // y = p[1] (interior)
3449  shape(18, 0) = 0;
3450  shape(18, 1) = (ay0*ay2*ay3)/(A01*A12*A13)*tx0;
3451  shape(19, 0) = 0;
3452  shape(19, 1) = (ay0*ay2*ay3)/(A01*A12*A13)*tx1;
3453  shape(20, 0) = 0;
3454  shape(20, 1) = (ay0*ay2*ay3)/(A01*A12*A13)*tx2;
3455  // y = p[2] (interior)
3456  shape(21, 0) = 0;
3457  shape(21, 1) = -(ay0*ay1*ay3)/(A02*A12*A23)*tx0;
3458  shape(22, 0) = 0;
3459  shape(22, 1) = -(ay0*ay1*ay3)/(A02*A12*A23)*tx1;
3460  shape(23, 0) = 0;
3461  shape(23, 1) = -(ay0*ay1*ay3)/(A02*A12*A23)*tx2;
3462 }
3463
3465  Vector &divshape) const
3466 {
3467  double x = ip.x, y = ip.y;
3468
3469  double a01 = pt[0]*pt[1];
3470  double a02 = pt[0]*pt[2];
3471  double a12 = pt[1]*pt[2];
3472  double a03 = pt[0]*pt[3];
3473  double a13 = pt[1]*pt[3];
3474  double a23 = pt[2]*pt[3];
3475
3476  double bx0 = dpt[0] - x;
3477  double bx1 = dpt[1] - x;
3478  double bx2 = dpt[2] - x;
3479
3480  double by0 = dpt[0] - y;
3481  double by1 = dpt[1] - y;
3482  double by2 = dpt[2] - y;
3483
3484  double A01 = pt[0] - pt[1];
3485  double A02 = pt[0] - pt[2];
3486  double A12 = pt[1] - pt[2];
3487  double A03 = pt[0] - pt[3];
3488  double A13 = pt[1] - pt[3];
3489  double A23 = pt[2] - pt[3];
3490
3491  double A012 = pt[0] + pt[1] + pt[2];
3492  double A013 = pt[0] + pt[1] + pt[3];
3493  double A023 = pt[0] + pt[2] + pt[3];
3494  double A123 = pt[1] + pt[2] + pt[3];
3495
3496  double B01 = dpt[0] - dpt[1];
3497  double B02 = dpt[0] - dpt[2];
3498  double B12 = dpt[1] - dpt[2];
3499
3500  double tx0 = (bx1*bx2)/(B01*B02);
3501  double tx1 = -(bx0*bx2)/(B01*B12);
3502  double tx2 = (bx0*bx1)/(B02*B12);
3503
3504  double ty0 = (by1*by2)/(B01*B02);
3505  double ty1 = -(by0*by2)/(B01*B12);
3506  double ty2 = (by0*by1)/(B02*B12);
3507
3508  // y = 0 (p[0])
3509  divshape(0) = -(a12 + a13 + a23 - 2.*A123*y + 3.*y*y)/(A01*A02*A03)*tx0;
3510  divshape(1) = -(a12 + a13 + a23 - 2.*A123*y + 3.*y*y)/(A01*A02*A03)*tx1;
3511  divshape(2) = -(a12 + a13 + a23 - 2.*A123*y + 3.*y*y)/(A01*A02*A03)*tx2;
3512  // x = 1 (p[3])
3513  divshape(3) = -(a01 + a02 + a12 - 2.*A012*x + 3.*x*x)/(A03*A13*A23)*ty0;
3514  divshape(4) = -(a01 + a02 + a12 - 2.*A012*x + 3.*x*x)/(A03*A13*A23)*ty1;
3515  divshape(5) = -(a01 + a02 + a12 - 2.*A012*x + 3.*x*x)/(A03*A13*A23)*ty2;
3516  // y = 1 (p[3])
3517  divshape(6) = -(a01 + a02 + a12 - 2.*A012*y + 3.*y*y)/(A03*A13*A23)*tx2;
3518  divshape(7) = -(a01 + a02 + a12 - 2.*A012*y + 3.*y*y)/(A03*A13*A23)*tx1;
3519  divshape(8) = -(a01 + a02 + a12 - 2.*A012*y + 3.*y*y)/(A03*A13*A23)*tx0;
3520  // x = 0 (p[0])
3521  divshape(9) = -(a12 + a13 + a23 - 2.*A123*x + 3.*x*x)/(A01*A02*A03)*ty2;
3522  divshape(10) = -(a12 + a13 + a23 - 2.*A123*x + 3.*x*x)/(A01*A02*A03)*ty1;
3523  divshape(11) = -(a12 + a13 + a23 - 2.*A123*x + 3.*x*x)/(A01*A02*A03)*ty0;
3524  // x = p[1] (interior)
3525  divshape(12) = -(a02 + a03 + a23 - 2.*A023*x + 3.*x*x)/(A01*A12*A13)*ty0;
3526  divshape(13) = -(a02 + a03 + a23 - 2.*A023*x + 3.*x*x)/(A01*A12*A13)*ty1;
3527  divshape(14) = -(a02 + a03 + a23 - 2.*A023*x + 3.*x*x)/(A01*A12*A13)*ty2;
3528  // x = p[2] (interior)
3529  divshape(15) = (a01 + a03 + a13 - 2.*A013*x + 3.*x*x)/(A02*A12*A23)*ty0;
3530  divshape(16) = (a01 + a03 + a13 - 2.*A013*x + 3.*x*x)/(A02*A12*A23)*ty1;
3531  divshape(17) = (a01 + a03 + a13 - 2.*A013*x + 3.*x*x)/(A02*A12*A23)*ty2;
3532  // y = p[1] (interior)
3533  divshape(18) = -(a02 + a03 + a23 - 2.*A023*y + 3.*y*y)/(A01*A12*A13)*tx0;
3534  divshape(19) = -(a02 + a03 + a23 - 2.*A023*y + 3.*y*y)/(A01*A12*A13)*tx1;
3535  divshape(20) = -(a02 + a03 + a23 - 2.*A023*y + 3.*y*y)/(A01*A12*A13)*tx2;
3536  // y = p[2] (interior)
3537  divshape(21) = (a01 + a03 + a13 - 2.*A013*y + 3.*y*y)/(A02*A12*A23)*tx0;
3538  divshape(22) = (a01 + a03 + a13 - 2.*A013*y + 3.*y*y)/(A02*A12*A23)*tx1;
3539  divshape(23) = (a01 + a03 + a13 - 2.*A013*y + 3.*y*y)/(A02*A12*A23)*tx2;
3540 }
3541
3542 const double RT2QuadFiniteElement::nk[24][2] =
3543 {
3544  // y = 0
3545  {0,-1}, {0,-1}, {0,-1},
3546  // x = 1
3547  {1, 0}, {1, 0}, {1, 0},
3548  // y = 1
3549  {0, 1}, {0, 1}, {0, 1},
3550  // x = 0
3551  {-1,0}, {-1,0}, {-1,0},
3552  // x = p[1] (interior)
3553  {1, 0}, {1, 0}, {1, 0},
3554  // x = p[2] (interior)
3555  {1, 0}, {1, 0}, {1, 0},
3556  // y = p[1] (interior)
3557  {0, 1}, {0, 1}, {0, 1},
3558  // y = p[1] (interior)
3559  {0, 1}, {0, 1}, {0, 1}
3560 };
3561
3564 {
3565  int k, j;
3568  DenseMatrix Jinv(Dim);
3569 #endif
3570
3571 #ifdef MFEM_DEBUG
3572  for (k = 0; k < 24; k++)
3573  {
3575  for (j = 0; j < 24; j++)
3576  {
3577  double d = vshape(j,0)*nk[k][0]+vshape(j,1)*nk[k][1];
3578  if (j == k) { d -= 1.0; }
3579  if (fabs(d) > 1.0e-12)
3580  {
3581  mfem::err << "RT2QuadFiniteElement::GetLocalInterpolation (...)\n"
3582  " k = " << k << ", j = " << j << ", d = " << d << endl;
3583  mfem_error();
3584  }
3585  }
3586  }
3587 #endif
3588
3589  IntegrationPoint ip;
3590  ip.x = ip.y = 0.0;
3591  Trans.SetIntPoint (&ip);
3592  // Trans must be linear (more to have embedding?)
3593  // set Jinv = |J| J^{-t} = adj(J)^t
3594  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
3595  double vk[2];
3596  Vector xk (vk, 2);
3597
3598  for (k = 0; k < 24; k++)
3599  {
3600  Trans.Transform (Nodes.IntPoint (k), xk);
3601  ip.x = vk[0]; ip.y = vk[1];
3602  CalcVShape (ip, vshape);
3603  // vk = |J| J^{-t} nk
3604  vk[0] = Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1];
3605  vk[1] = Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1];
3606  for (j = 0; j < 24; j++)
3607  if (fabs (I(k,j) = vshape(j,0)*vk[0]+vshape(j,1)*vk[1]) < 1.0e-12)
3608  {
3609  I(k,j) = 0.0;
3610  }
3611  }
3612 }
3613
3616 {
3617  double vk[2];
3618  Vector xk (vk, 2);
3620  DenseMatrix Jinv(Dim);
3621 #endif
3622
3623  for (int k = 0; k < 24; k++)
3624  {
3625  Trans.SetIntPoint (&Nodes.IntPoint (k));
3626  // set Jinv = |J| J^{-t} = adj(J)^t
3627  CalcAdjugateTranspose (Trans.Jacobian(), Jinv);
3628
3629  vc.Eval (xk, Trans, Nodes.IntPoint (k));
3630  // xk^t |J| J^{-t} nk
3631  dofs(k) = (vk[0] * ( Jinv(0,0)*nk[k][0]+Jinv(0,1)*nk[k][1] ) +
3632  vk[1] * ( Jinv(1,0)*nk[k][0]+Jinv(1,1)*nk[k][1] ));
3633  }
3634 }
3635
3637  : NodalFiniteElement(1, Geometry::SEGMENT, 2, 1)
3638 {
3639  Nodes.IntPoint(0).x = 0.33333333333333333333;
3640  Nodes.IntPoint(1).x = 0.66666666666666666667;
3641 }
3642
3644  Vector &shape) const
3645 {
3646  double x = ip.x;
3647
3648  shape(0) = 2. - 3. * x;
3649  shape(1) = 3. * x - 1.;
3650 }
3651
3653  DenseMatrix &dshape) const
3654 {
3655  dshape(0,0) = -3.;
3656  dshape(1,0) = 3.;
3657 }
3658
3659
3661  : NodalFiniteElement(1, Geometry::SEGMENT, 3, 2)
3662 {
3663  const double p = 0.11270166537925831148;
3664
3665  Nodes.IntPoint(0).x = p;
3666  Nodes.IntPoint(1).x = 0.5;
3667  Nodes.IntPoint(2).x = 1.-p;
3668 }
3669
3671  Vector &shape) const
3672 {
3673  const double p = 0.11270166537925831148;
3674  const double w = 1./((1-2*p)*(1-2*p));
3675  double x = ip.x;
3676
3677  shape(0) = (2*x-1)*(x-1+p)*w;
3678  shape(1) = 4*(x-1+p)*(p-x)*w;
3679  shape(2) = (2*x-1)*(x-p)*w;
3680 }
3681
3683  DenseMatrix &dshape) const
3684 {
3685  const double p = 0.11270166537925831148;
3686  const double w = 1./((1-2*p)*(1-2*p));
3687  double x = ip.x;
3688
3689  dshape(0,0) = (-3+4*x+2*p)*w;
3690  dshape(1,0) = (4-8*x)*w;
3691  dshape(2,0) = (-1+4*x-2*p)*w;
3692 }
3693
3694
3696  : NodalFiniteElement(1, Geometry::SEGMENT, degree+1, degree)
3697 {
3698  int i, m = degree;
3699
3700  Nodes.IntPoint(0).x = 0.0;
3701  Nodes.IntPoint(1).x = 1.0;
3702  for (i = 1; i < m; i++)
3703  {
3704  Nodes.IntPoint(i+1).x = double(i) / m;
3705  }
3706
3707  rwk.SetSize(degree+1);
3709  rxxk.SetSize(degree+1);
3710 #endif
3711
3712  rwk(0) = 1.0;
3713  for (i = 1; i <= m; i++)
3714  {
3715  rwk(i) = rwk(i-1) * ( (double)(m) / (double)(i) );
3716  }
3717  for (i = 0; i < m/2+1; i++)
3718  {
3719  rwk(m-i) = ( rwk(i) *= rwk(m-i) );
3720  }
3721  for (i = m-1; i >= 0; i -= 2)
3722  {
3723  rwk(i) = -rwk(i);
3724  }
3725 }
3726
3728  Vector &shape) const
3729 {
3730  double w, wk, x = ip.x;
3731  int i, k, m = GetOrder();
3732
3734  Vector rxxk(m+1);
3735 #endif
3736
3737  k = (int) floor ( m * x + 0.5 );
3738  k = k > m ? m : k < 0 ? 0 : k; // clamp k to [0,m]
3739
3740  wk = 1.0;
3741  for (i = 0; i <= m; i++)
3742  if (i != k)
3743  {
3744  wk *= ( rxxk(i) = x - (double)(i) / m );
3745  }
3746  w = wk * ( rxxk(k) = x - (double)(k) / m );
3747
3748  if (k != 0)
3749  {
3750  shape(0) = w * rwk(0) / rxxk(0);
3751  }
3752  else
3753  {
3754  shape(0) = wk * rwk(0);
3755  }
3756  if (k != m)
3757  {
3758  shape(1) = w * rwk(m) / rxxk(m);
3759  }
3760  else
3761  {
3762  shape(1) = wk * rwk(k);
3763  }
3764  for (i = 1; i < m; i++)
3765  if (i != k)
3766  {
3767  shape(i+1) = w * rwk(i) / rxxk(i);
3768  }
3769  else
3770  {
3771  shape(k+1) = wk * rwk(k);
3772  }
3773 }
3774
3776  DenseMatrix &dshape) const
3777 {
3778  double s, srx, w, wk, x = ip.x;
3779  int i, k, m = GetOrder();
3780
3782  Vector rxxk(m+1);
3783 #endif
3784
3785  k = (int) floor ( m * x + 0.5 );
3786  k = k > m ? m : k < 0 ? 0 : k; // clamp k to [0,m]
3787
3788  wk = 1.0;
3789  for (i = 0; i <= m; i++)
3790  if (i != k)
3791  {
3792  wk *= ( rxxk(i) = x - (double)(i) / m );
3793  }
3794  w = wk * ( rxxk(k) = x - (double)(k) / m );
3795
3796  for (i = 0; i <= m; i++)
3797  {
3798  rxxk(i) = 1.0 / rxxk(i);
3799  }
3800  srx = 0.0;
3801  for (i = 0; i <= m; i++)
3802  if (i != k)
3803  {
3804  srx += rxxk(i);
3805  }
3806  s = w * srx + wk;
3807
3808  if (k != 0)
3809  {
3810  dshape(0,0) = (s - w * rxxk(0)) * rwk(0) * rxxk(0);
3811  }
3812  else
3813  {
3814  dshape(0,0) = wk * srx * rwk(0);
3815  }
3816  if (k != m)
3817  {
3818  dshape(1,0) = (s - w * rxxk(m)) * rwk(m) * rxxk(m);
3819  }
3820  else
3821  {
3822  dshape(1,0) = wk * srx * rwk(k);
3823  }
3824  for (i = 1; i < m; i++)
3825  if (i != k)
3826  {
3827  dshape(i+1,0) = (s - w * rxxk(i)) * rwk(i) * rxxk(i);
3828  }
3829  else
3830  {
3831  dshape(k+1,0) = wk * srx * rwk(k);
3832  }
3833 }
3834
3835
3837  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 4, 1)
3838 {
3839  Nodes.IntPoint(0).x = 0.33333333333333333333;
3840  Nodes.IntPoint(0).y = 0.33333333333333333333;
3841  Nodes.IntPoint(0).z = 0.33333333333333333333;
3842
3843  Nodes.IntPoint(1).x = 0.0;
3844  Nodes.IntPoint(1).y = 0.33333333333333333333;
3845  Nodes.IntPoint(1).z = 0.33333333333333333333;
3846
3847  Nodes.IntPoint(2).x = 0.33333333333333333333;
3848  Nodes.IntPoint(2).y = 0.0;
3849  Nodes.IntPoint(2).z = 0.33333333333333333333;
3850
3851  Nodes.IntPoint(3).x = 0.33333333333333333333;
3852  Nodes.IntPoint(3).y = 0.33333333333333333333;
3853  Nodes.IntPoint(3).z = 0.0;
3854
3855 }
3856
3858  Vector &shape) const
3859 {
3860  double L0, L1, L2, L3;
3861
3862  L1 = ip.x; L2 = ip.y; L3 = ip.z; L0 = 1.0 - L1 - L2 - L3;
3863  shape(0) = 1.0 - 3.0 * L0;
3864  shape(1) = 1.0 - 3.0 * L1;
3865  shape(2) = 1.0 - 3.0 * L2;
3866  shape(3) = 1.0 - 3.0 * L3;
3867 }
3868
3870  DenseMatrix &dshape) const
3871 {
3872  dshape(0,0) = 3.0; dshape(0,1) = 3.0; dshape(0,2) = 3.0;
3873  dshape(1,0) = -3.0; dshape(1,1) = 0.0; dshape(1,2) = 0.0;
3874  dshape(2,0) = 0.0; dshape(2,1) = -3.0; dshape(2,2) = 0.0;
3875  dshape(3,0) = 0.0; dshape(3,1) = 0.0; dshape(3,2) = -3.0;
3876 }
3877
3878
3880  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 1, 0)
3881 {
3882  Nodes.IntPoint(0).x = 0.25;
3883  Nodes.IntPoint(0).y = 0.25;
3884  Nodes.IntPoint(0).z = 0.25;
3885 }
3886
3888  Vector &shape) const
3889 {
3890  shape(0) = 1.0;
3891 }
3892
3894  DenseMatrix &dshape) const
3895 {
3896  dshape(0,0) = 0.0; dshape(0,1) = 0.0; dshape(0,2) = 0.0;
3897 }
3898
3899
3901  : NodalFiniteElement(3, Geometry::CUBE, 1, 0, FunctionSpace::Qk)
3902 {
3903  Nodes.IntPoint(0).x = 0.5;
3904  Nodes.IntPoint(0).y = 0.5;
3905  Nodes.IntPoint(0).z = 0.5;
3906 }
3907
3909  Vector &shape) const
3910 {
3911  shape(0) = 1.0;
3912 }
3913
3915  DenseMatrix &dshape) const
3916 {
3917  dshape(0,0) = 0.0; dshape(0,1) = 0.0; dshape(0,2) = 0.0;
3918 }
3919
3920
3922  : NodalFiniteElement(3, Geometry::CUBE, (degree+1)*(degree+1)*(degree+1),
3923  degree, FunctionSpace::Qk)
3924 {
3925  if (degree == 2)
3926  {
3927  I = new int[Dof];
3928  J = new int[Dof];
3929  K = new int[Dof];
3930  // nodes
3931  I[ 0] = 0; J[ 0] = 0; K[ 0] = 0;
3932  I[ 1] = 1; J[ 1] = 0; K[ 1] = 0;
3933  I[ 2] = 1; J[ 2] = 1; K[ 2] = 0;
3934  I[ 3] = 0; J[ 3] = 1; K[ 3] = 0;
3935  I[ 4] = 0; J[ 4] = 0; K[ 4] = 1;
3936  I[ 5] = 1; J[ 5] = 0; K[ 5] = 1;
3937  I[ 6] = 1; J[ 6] = 1; K[ 6] = 1;
3938  I[ 7] = 0; J[ 7] = 1; K[ 7] = 1;
3939  // edges
3940  I[ 8] = 2; J[ 8] = 0; K[ 8] = 0;
3941  I[ 9] = 1; J[ 9] = 2; K[ 9] = 0;
3942  I[10] = 2; J[10] = 1; K[10] = 0;
3943  I[11] = 0; J[11] = 2; K[11] = 0;
3944  I[12] = 2; J[12] = 0; K[12] = 1;
3945  I[13] = 1; J[13] = 2; K[13] = 1;
3946  I[14] = 2; J[14] = 1; K[14] = 1;
3947  I[15] = 0; J[15] = 2; K[15] = 1;
3948  I[16] = 0; J[16] = 0; K[16] = 2;
3949  I[17] = 1; J[17] = 0; K[17] = 2;
3950  I[18] = 1; J[18] = 1; K[18] = 2;
3951  I[19] = 0; J[19] = 1; K[19] = 2;
3952  // faces
3953  I[20] = 2; J[20] = 2; K[20] = 0;
3954  I[21] = 2; J[21] = 0; K[21] = 2;
3955  I[22] = 1; J[22] = 2; K[22] = 2;
3956  I[23] = 2; J[23] = 1; K[23] = 2;
3957  I[24] = 0; J[24] = 2; K[24] = 2;
3958  I[25] = 2; J[25] = 2; K[25] = 1;
3959  // element
3960  I[26] = 2; J[26] = 2; K[26] = 2;
3961  }
3962  else if (degree == 3)
3963  {
3964  I = new int[Dof];
3965  J = new int[Dof];
3966  K = new int[Dof];
3967  // nodes
3968  I[ 0] = 0; J[ 0] = 0; K[ 0] = 0;
3969  I[ 1] = 1; J[ 1] = 0; K[ 1] = 0;
3970  I[ 2] = 1; J[ 2] = 1; K[ 2] = 0;
3971  I[ 3] = 0; J[ 3] = 1; K[ 3] = 0;
3972  I[ 4] = 0; J[ 4] = 0; K[ 4] = 1;
3973  I[ 5] = 1; J[ 5] = 0; K[ 5] = 1;
3974  I[ 6] = 1; J[ 6] = 1; K[ 6] = 1;
3975  I[ 7] = 0; J[ 7] = 1; K[ 7] = 1;
3976  // edges
3977  I[ 8] = 2; J[ 8] = 0; K[ 8] = 0;
3978  I[ 9] = 3; J[ 9] = 0; K[ 9] = 0;
3979  I[10] = 1; J[10] = 2; K[10] = 0;
3980  I[11] = 1; J[11] = 3; K[11] = 0;
3981  I[12] = 2; J[12] = 1; K[12] = 0;
3982  I[13] = 3; J[13] = 1; K[13] = 0;
3983  I[14] = 0; J[14] = 2; K[14] = 0;
3984  I[15] = 0; J[15] = 3; K[15] = 0;
3985  I[16] = 2; J[16] = 0; K[16] = 1;
3986  I[17] = 3; J[17] = 0; K[17] = 1;
3987  I[18] = 1; J[18] = 2; K[18] = 1;
3988  I[19] = 1; J[19] = 3; K[19] = 1;
3989  I[20] = 2; J[20] = 1; K[20] = 1;
3990  I[21] = 3; J[21] = 1; K[21] = 1;
3991  I[22] = 0; J[22] = 2; K[22] = 1;
3992  I[23] = 0; J[23] = 3; K[23] = 1;
3993  I[24] = 0; J[24] = 0; K[24] = 2;
3994  I[25] = 0; J[25] = 0; K[25] = 3;
3995  I[26] = 1; J[26] = 0; K[26] = 2;
3996  I[27] = 1; J[27] = 0; K[27] = 3;
3997  I[28] = 1; J[28] = 1; K[28] = 2;
3998  I[29] = 1; J[29] = 1; K[29] = 3;
3999  I[30] = 0; J[30] = 1; K[30] = 2;
4000  I[31] = 0; J[31] = 1; K[31] = 3;
4001  // faces
4002  I[32] = 2; J[32] = 3; K[32] = 0;
4003  I[33] = 3; J[33] = 3; K[33] = 0;
4004  I[34] = 2; J[34] = 2; K[34] = 0;
4005  I[35] = 3; J[35] = 2; K[35] = 0;
4006  I[36] = 2; J[36] = 0; K[36] = 2;
4007  I[37] = 3; J[37] = 0; K[37] = 2;
4008  I[38] = 2; J[38] = 0; K[38] = 3;
4009  I[39] = 3; J[39] = 0; K[39] = 3;
4010  I[40] = 1; J[40] = 2; K[40] = 2;
4011  I[41] = 1; J[41] = 3; K[41] = 2;
4012  I[42] = 1; J[42] = 2; K[42] = 3;
4013  I[43] = 1; J[43] = 3; K[43] = 3;
4014  I[44] = 3; J[44] = 1; K[44] = 2;
4015  I[45] = 2; J[45] = 1; K[45] = 2;
4016  I[46] = 3; J[46] = 1; K[46] = 3;
4017  I[47] = 2; J[47] = 1; K[47] = 3;
4018  I[48] = 0; J[48] = 3; K[48] = 2;
4019  I[49] = 0; J[49] = 2; K[49] = 2;
4020  I[50] = 0; J[50] = 3; K[50] = 3;
4021  I[51] = 0; J[51] = 2; K[51] = 3;
4022  I[52] = 2; J[52] = 2; K[52] = 1;
4023  I[53] = 3; J[53] = 2; K[53] = 1;
4024  I[54] = 2; J[54] = 3; K[54] = 1;
4025  I[55] = 3; J[55] = 3; K[55] = 1;
4026  // element
4027  I[56] = 2; J[56] = 2; K[56] = 2;
4028  I[57] = 3; J[57] = 2; K[57] = 2;
4029  I[58] = 3; J[58] = 3; K[58] = 2;
4030  I[59] = 2; J[59] = 3; K[59] = 2;
4031  I[60] = 2; J[60] = 2; K[60] = 3;
4032  I[61] = 3; J[61] = 2; K[61] = 3;
4033  I[62] = 3; J[62] = 3; K[62] = 3;
4034  I[63] = 2; J[63] = 3; K[63] = 3;
4035  }
4036  else
4037  {
4038  mfem_error ("LagrangeHexFiniteElement::LagrangeHexFiniteElement");
4039  }
4040
4041  fe1d = new Lagrange1DFiniteElement(degree);
4042  dof1d = fe1d -> GetDof();
4043
4045  shape1dx.SetSize(dof1d);
4046  shape1dy.SetSize(dof1d);
4047  shape1dz.SetSize(dof1d);
4048
4049  dshape1dx.SetSize(dof1d,1);
4050  dshape1dy.SetSize(dof1d,1);
4051  dshape1dz.SetSize(dof1d,1);
4052 #endif
4053
4054  for (int n = 0; n < Dof; n++)
4055  {
4056  Nodes.IntPoint(n).x = fe1d -> GetNodes().IntPoint(I[n]).x;
4057  Nodes.IntPoint(n).y = fe1d -> GetNodes().IntPoint(J[n]).x;
4058  Nodes.IntPoint(n).z = fe1d -> GetNodes().IntPoint(K[n]).x;
4059  }
4060 }
4061
4063  Vector &shape) const
4064 {
4065  IntegrationPoint ipy, ipz;
4066  ipy.x = ip.y;
4067  ipz.x = ip.z;
4068
4070  Vector shape1dx(dof1d), shape1dy(dof1d), shape1dz(dof1d);
4071 #endif
4072
4073  fe1d -> CalcShape(ip, shape1dx);
4074  fe1d -> CalcShape(ipy, shape1dy);
4075  fe1d -> CalcShape(ipz, shape1dz);
4076
4077  for (int n = 0; n < Dof; n++)
4078  {
4079  shape(n) = shape1dx(I[n]) * shape1dy(J[n]) * shape1dz(K[n]);
4080  }
4081 }
4082
4084  DenseMatrix &dshape) const
4085 {
4086  IntegrationPoint ipy, ipz;
4087  ipy.x = ip.y;
4088  ipz.x = ip.z;
4089
4091  Vector shape1dx(dof1d), shape1dy(dof1d), shape1dz(dof1d);
4092  DenseMatrix dshape1dx(dof1d,1), dshape1dy(dof1d,1), dshape1dz(dof1d,1);
4093 #endif
4094
4095  fe1d -> CalcShape(ip, shape1dx);
4096  fe1d -> CalcShape(ipy, shape1dy);
4097  fe1d -> CalcShape(ipz, shape1dz);
4098
4099  fe1d -> CalcDShape(ip, dshape1dx);
4100  fe1d -> CalcDShape(ipy, dshape1dy);
4101  fe1d -> CalcDShape(ipz, dshape1dz);
4102
4103  for (int n = 0; n < Dof; n++)
4104  {
4105  dshape(n,0) = dshape1dx(I[n],0) * shape1dy(J[n]) * shape1dz(K[n]);
4106  dshape(n,1) = shape1dx(I[n]) * dshape1dy(J[n],0) * shape1dz(K[n]);
4107  dshape(n,2) = shape1dx(I[n]) * shape1dy(J[n]) * dshape1dz(K[n],0);
4108  }
4109 }
4110
4112 {
4113  delete fe1d;
4114
4115  delete [] I;
4116  delete [] J;
4117  delete [] K;
4118 }
4119
4120
4122  : NodalFiniteElement(1, Geometry::SEGMENT, 3, 4)
4123 {
4124  Nodes.IntPoint(0).x = 0.0;
4125  Nodes.IntPoint(1).x = 1.0;
4126  Nodes.IntPoint(2).x = 0.5;
4127 }
4128
4130  Vector &shape) const
4131 {
4132  double x = ip.x;
4133
4134  if (x <= 0.5)
4135  {
4136  shape(0) = 1.0 - 2.0 * x;
4137  shape(1) = 0.0;
4138  shape(2) = 2.0 * x;
4139  }
4140  else
4141  {
4142  shape(0) = 0.0;
4143  shape(1) = 2.0 * x - 1.0;
4144  shape(2) = 2.0 - 2.0 * x;
4145  }
4146 }
4147
4149  DenseMatrix &dshape) const
4150 {
4151  double x = ip.x;
4152
4153  if (x <= 0.5)
4154  {
4155  dshape(0,0) = - 2.0;
4156  dshape(1,0) = 0.0;
4157  dshape(2,0) = 2.0;
4158  }
4159  else
4160  {
4161  dshape(0,0) = 0.0;
4162  dshape(1,0) = 2.0;
4163  dshape(2,0) = - 2.0;
4164  }
4165 }
4166
4168  : NodalFiniteElement(2, Geometry::TRIANGLE, 6, 5)
4169 {
4170  Nodes.IntPoint(0).x = 0.0;
4171  Nodes.IntPoint(0).y = 0.0;
4172  Nodes.IntPoint(1).x = 1.0;
4173  Nodes.IntPoint(1).y = 0.0;
4174  Nodes.IntPoint(2).x = 0.0;
4175  Nodes.IntPoint(2).y = 1.0;
4176  Nodes.IntPoint(3).x = 0.5;
4177  Nodes.IntPoint(3).y = 0.0;
4178  Nodes.IntPoint(4).x = 0.5;
4179  Nodes.IntPoint(4).y = 0.5;
4180  Nodes.IntPoint(5).x = 0.0;
4181  Nodes.IntPoint(5).y = 0.5;
4182 }
4183
4185  Vector &shape) const
4186 {
4187  int i;
4188
4189  double L0, L1, L2;
4190  L0 = 2.0 * ( 1. - ip.x - ip.y );
4191  L1 = 2.0 * ( ip.x );
4192  L2 = 2.0 * ( ip.y );
4193
4194  // The reference triangle is split in 4 triangles as follows:
4195  //
4196  // T0 - 0,3,5
4197  // T1 - 1,3,4
4198  // T2 - 2,4,5
4199  // T3 - 3,4,5
4200
4201  for (i = 0; i < 6; i++)
4202  {
4203  shape(i) = 0.0;
4204  }
4205
4206  if (L0 >= 1.0) // T0
4207  {
4208  shape(0) = L0 - 1.0;
4209  shape(3) = L1;
4210  shape(5) = L2;
4211  }
4212  else if (L1 >= 1.0) // T1
4213  {
4214  shape(3) = L0;
4215  shape(1) = L1 - 1.0;
4216  shape(4) = L2;
4217  }
4218  else if (L2 >= 1.0) // T2
4219  {
4220  shape(5) = L0;
4221  shape(4) = L1;
4222  shape(2) = L2 - 1.0;
4223  }
4224  else // T3
4225  {
4226  shape(3) = 1.0 - L2;
4227  shape(4) = 1.0 - L0;
4228  shape(5) = 1.0 - L1;
4229  }
4230 }
4231
4233  DenseMatrix &dshape) const
4234 {
4235  int i,j;
4236
4237  double L0, L1, L2;
4238  L0 = 2.0 * ( 1. - ip.x - ip.y );
4239  L1 = 2.0 * ( ip.x );
4240  L2 = 2.0 * ( ip.y );
4241
4242  double DL0[2], DL1[2], DL2[2];
4243  DL0[0] = -2.0; DL0[1] = -2.0;
4244  DL1[0] = 2.0; DL1[1] = 0.0;
4245  DL2[0] = 0.0; DL2[1] = 2.0;
4246
4247  for (i = 0; i < 6; i++)
4248  for (j = 0; j < 2; j++)
4249  {
4250  dshape(i,j) = 0.0;
4251  }
4252
4253  if (L0 >= 1.0) // T0
4254  {
4255  for (j = 0; j < 2; j++)
4256  {
4257  dshape(0,j) = DL0[j];
4258  dshape(3,j) = DL1[j];
4259  dshape(5,j) = DL2[j];
4260  }
4261  }
4262  else if (L1 >= 1.0) // T1
4263  {
4264  for (j = 0; j < 2; j++)
4265  {
4266  dshape(3,j) = DL0[j];
4267  dshape(1,j) = DL1[j];
4268  dshape(4,j) = DL2[j];
4269  }
4270  }
4271  else if (L2 >= 1.0) // T2
4272  {
4273  for (j = 0; j < 2; j++)
4274  {
4275  dshape(5,j) = DL0[j];
4276  dshape(4,j) = DL1[j];
4277  dshape(2,j) = DL2[j];
4278  }
4279  }
4280  else // T3
4281  {
4282  for (j = 0; j < 2; j++)
4283  {
4284  dshape(3,j) = - DL2[j];
4285  dshape(4,j) = - DL0[j];
4286  dshape(5,j) = - DL1[j];
4287  }
4288  }
4289 }
4290
4292  : NodalFiniteElement(3, Geometry::TETRAHEDRON, 10, 4)
4293 {
4294  Nodes.IntPoint(0).x = 0.0;
4295  Nodes.IntPoint(0).y = 0.0;
4296  Nodes.IntPoint(0).z = 0.0;
4297  Nodes.IntPoint(1).x = 1.0;
4298  Nodes.IntPoint(1).y = 0.0;
4299  Nodes.IntPoint(1).z = 0.0;
4300  Nodes.IntPoint(2).x = 0.0;
4301  Nodes.IntPoint(2).y = 1.0;
4302  Nodes.IntPoint(2).z = 0.0;
4303  Nodes.IntPoint(3).x = 0.0;
4304  Nodes.IntPoint(3).y = 0.0;
4305  Nodes.IntPoint(3).z = 1.0;
4306  Nodes.IntPoint(4).x = 0.5;
4307  Nodes.IntPoint(4).y = 0.0;
4308  Nodes.IntPoint(4).z = 0.0;
4309  Nodes.IntPoint(5).x = 0.0;
4310  Nodes.IntPoint(5).y = 0.5;
4311  Nodes.IntPoint(5).z = 0.0;
4312  Nodes.IntPoint(6).x = 0.0;
4313  Nodes.IntPoint(6).y = 0.0;
4314  Nodes.IntPoint(6).z = 0.5;
4315  Nodes.IntPoint(7).x = 0.5;
4316  Nodes.IntPoint(7).y = 0.5;
4317  Nodes.IntPoint(7).z = 0.0;
4318  Nodes.IntPoint(8).x = 0.5;
4319  Nodes.IntPoint(8).y = 0.0;
4320  Nodes.IntPoint(8).z = 0.5;
4321  Nodes.IntPoint(9).x = 0.0;
4322  Nodes.IntPoint(9).y = 0.5;
4323  Nodes.IntPoint(9).z = 0.5;
4324 }
4325
4327  Vector &shape) const
4328 {
4329  int i;
4330
4331  double L0, L1, L2, L3, L4, L5;
4332  L0 = 2.0 * ( 1. - ip.x - ip.y - ip.z );
4333  L1 = 2.0 * ( ip.x );
4334  L2 = 2.0 * ( ip.y );
4335  L3 = 2.0 * ( ip.z );
4336  L4 = 2.0 * ( ip.x + ip.y );
4337  L5 = 2.0 * ( ip.y + ip.z );
4338
4339  // The reference tetrahedron is split in 8 tetrahedra as follows:
4340  //
4341  // T0 - 0,4,5,6
4342  // T1 - 1,4,7,8
4343  // T2 - 2,5,7,9
4344  // T3 - 3,6,8,9
4345  // T4 - 4,5,6,8
4346  // T5 - 4,5,7,8
4347  // T6 - 5,6,8,9
4348  // T7 - 5,7,8,9
4349
4350  for (i = 0; i < 10; i++)
4351  {
4352  shape(i) = 0.0;
4353  }
4354
4355  if (L0 >= 1.0) // T0
4356  {
4357  shape(0) = L0 - 1.0;
4358  shape(4) = L1;
4359  shape(5) = L2;
4360  shape(6) = L3;
4361  }
4362  else if (L1 >= 1.0) // T1
4363  {
4364  shape(4) = L0;
4365  shape(1) = L1 - 1.0;
4366  shape(7) = L2;
4367  shape(8) = L3;
4368  }
4369  else if (L2 >= 1.0) // T2
4370  {
4371  shape(5) = L0;
4372  shape(7) = L1;
4373  shape(2) = L2 - 1.0;
4374  shape(9) = L3;
4375  }
4376  else if (L3 >= 1.0) // T3
4377  {
4378  shape(6) = L0;
4379  shape(8) = L1;
4380  shape(9) = L2;
4381  shape(3) = L3 - 1.0;
4382  }
4383  else if ((L4 <= 1.0) && (L5 <= 1.0)) // T4
4384  {
4385  shape(4) = 1.0 - L5;
4386  shape(5) = L2;
4387  shape(6) = 1.0 - L4;
4388  shape(8) = 1.0 - L0;
4389  }
4390  else if ((L4 >= 1.0) && (L5 <= 1.0)) // T5
4391  {
4392  shape(4) = 1.0 - L5;
4393  shape(5) = 1.0 - L1;
4394  shape(7) = L4 - 1.0;
4395  shape(8) = L3;
4396  }
4397  else if ((L4 <= 1.0) && (L5 >= 1.0)) // T6
4398  {
4399  shape(5) = 1.0 - L3;
4400  shape(6) = 1.0 - L4;
4401  shape(8) = L1;
4402  shape(9) = L5 - 1.0;
4403  }
4404  else if ((L4 >= 1.0) && (L5 >= 1.0)) // T7
4405  {
4406  shape(5) = L0;
4407  shape(7) = L4 - 1.0;
4408  shape(8) = 1.0 - L2;
4409  shape(9) = L5 - 1.0;
4410  }
4411 }
4412
4414  DenseMatrix &dshape) const
4415 {
4416  int i,j;
4417
4418  double L0, L1, L2, L3, L4, L5;
4419  L0 = 2.0 * ( 1. - ip.x - ip.y - ip.z );
4420  L1 = 2.0 * ( ip.x );
4421  L2 = 2.0 * ( ip.y );
4422  L3 = 2.0 * ( ip.z );
4423  L4 = 2.0 * ( ip.x + ip.y );
4424  L5 = 2.0 * ( ip.y + ip.z );
4425
4426  double DL0[3], DL1[3], DL2[3], DL3[3], DL4[3], DL5[3];
4427  DL0[0] = -2.0; DL0[1] = -2.0; DL0[2] = -2.0;
4428  DL1[0] = 2.0; DL1[1] = 0.0; DL1[2] = 0.0;
4429  DL2[0] = 0.0; DL2[1] = 2.0; DL2[2] = 0.0;
4430  DL3[0] = 0.0; DL3[1] = 0.0; DL3[2] = 2.0;
4431  DL4[0] = 2.0; DL4[1] = 2.0; DL4[2] = 0.0;
4432  DL5[0] = 0.0; DL5[1] = 2.0; DL5[2] = 2.0;
4433
4434  for (i = 0; i < 10; i++)
4435  for (j = 0; j < 3; j++)
4436  {
4437  dshape(i,j) = 0.0;
4438  }
4439
4440  if (L0 >= 1.0) // T0
4441  {
4442  for (j = 0; j < 3; j++)
4443  {
4444  dshape(0,j) = DL0[j];
4445  dshape(4,j) = DL1[j];
4446  dshape(5,j) = DL2[j];
4447  dshape(6,j) = DL3[j];
4448  }
4449  }
4450  else if (L1 >= 1.0) // T1
4451  {
4452  for (j = 0; j < 3; j++)
4453  {
4454  dshape(4,j) = DL0[j];
4455  dshape(1,j) = DL1[j];
4456  dshape(7,j) = DL2[j];
4457  dshape(8,j) = DL3[j];
4458  }
4459  }
4460  else if (L2 >= 1.0) // T2
4461  {
4462  for (j = 0; j < 3; j++)
4463  {
4464  dshape(5,j) = DL0[j];
4465  dshape(7,j) = DL1[j];
4466  dshape(2,j) = DL2[j];
4467  dshape(9,j) = DL3[j];
4468  }
4469  }
4470  else if (L3 >= 1.0) // T3
4471  {
4472  for (j = 0; j < 3; j++)
4473  {
4474  dshape(6,j) = DL0[j];
4475  dshape(8,j) = DL1[j];
4476  dshape(9,j) = DL2[j];
4477  dshape(3,j) = DL3[j];
4478  }
4479  }
4480  else if ((L4 <= 1.0) && (L5 <= 1.0)) // T4
4481  {
4482  for (j = 0; j < 3; j++)
4483  {
4484  dshape(4,j) = - DL5[j];
4485  dshape(5,j) = DL2[j];
4486  dshape(6,j) = - DL4[j];
4487  dshape(8,j) = - DL0[j];
4488  }
4489  }
4490  else if ((L4 >= 1.0) && (L5 <= 1.0)) // T5
4491  {
4492  for (j = 0; j < 3; j++)
4493  {
4494  dshape(4,j) = - DL5[j];
4495  dshape(5,j) = - DL1[j];
4496  dshape(7,j) = DL4[j];
4497  dshape(8,j) = DL3[j];
4498  }
4499  }
4500  else if ((L4 <= 1.0) && (L5 >= 1.0)) // T6
4501  {
4502  for (j = 0; j < 3; j++)
4503  {
4504  dshape(5,j) = - DL3[j];
4505  dshape(6,j) = - DL4[j];
4506  dshape(8,j) = DL1[j];
4507  dshape(9,j) = DL5[j];
4508  }
4509  }
4510  else if ((L4 >= 1.0) && (L5 >= 1.0)) // T7
4511  {
4512  for (j = 0; j < 3; j++)
4513  {
4514  dshape(5,j) = DL0[j];
4515  dshape(7,j) = DL4[j];
4516  dshape(8,j) = - DL2[j];
4517  dshape(9,j) = DL5[j];
4518  }
4519  }
4520 }
4521
4522
4524  : NodalFiniteElement(2, Geometry::SQUARE, 9, 1, FunctionSpace::rQk)
4525 {
4526  Nodes.IntPoint(0).x = 0.0;
4527  Nodes.IntPoint(0).y = 0.0;
4528  Nodes.IntPoint(1).x = 1.0;
4529  Nodes.IntPoint(1).y = 0.0;
4530  Nodes.IntPoint(2).x = 1.0;
4531  Nodes.IntPoint(2).y = 1.0;
4532  Nodes.IntPoint(3).x = 0.0;
4533  Nodes.IntPoint(3).y = 1.0;
4534  Nodes.IntPoint(4).x = 0.5;
4535  Nodes.IntPoint(4).y = 0.0;
4536  Nodes.IntPoint(5).x = 1.0;
4537  Nodes.IntPoint(5).y = 0.5;
4538  Nodes.IntPoint(6).x = 0.5;
4539  Nodes.IntPoint(6).y = 1.0;
4540  Nodes.IntPoint(7).x = 0.0;
4541  Nodes.IntPoint(7).y = 0.5;
4542  Nodes.IntPoint(8).x = 0.5;
4543  Nodes.IntPoint(8).y = 0.5;
4544 }
4545
4547  Vector &shape) const
4548 {
4549  int i;
4550  double x = ip.x, y = ip.y;
4551  double Lx, Ly;
4552  Lx = 2.0 * ( 1. - x );
4553  Ly = 2.0 * ( 1. - y );
4554
4555  // The reference square is split in 4 squares as follows:
4556  //
4557  // T0 - 0,4,7,8
4558  // T1 - 1,4,5,8
4559  // T2 - 2,5,6,8
4560  // T3 - 3,6,7,8
4561
4562  for (i = 0; i < 9; i++)
4563  {
4564  shape(i) = 0.0;
4565  }
4566
4567  if ((x <= 0.5) && (y <= 0.5)) // T0
4568  {
4569  shape(0) = (Lx - 1.0) * (Ly - 1.0);
4570  shape(4) = (2.0 - Lx) * (Ly - 1.0);
4571  shape(8) = (2.0 - Lx) * (2.0 - Ly);
4572  shape(7) = (Lx - 1.0) * (2.0 - Ly);
4573  }
4574  else if ((x >= 0.5) && (y <= 0.5)) // T1
4575  {
4576  shape(4) = Lx * (Ly - 1.0);
4577  shape(1) = (1.0 - Lx) * (Ly - 1.0);
4578  shape(5) = (1.0 - Lx) * (2.0 - Ly);
4579  shape(8) = Lx * (2.0 - Ly);
4580  }
4581  else if ((x >= 0.5) && (y >= 0.5)) // T2
4582  {
4583  shape(8) = Lx * Ly ;
4584  shape(5) = (1.0 - Lx) * Ly ;
4585  shape(2) = (1.0 - Lx) * (1.0 - Ly);
4586  shape(6) = Lx * (1.0 - Ly);
4587  }
4588  else if ((x <= 0.5) && (y >= 0.5)) // T3
4589  {
4590  shape(7) = (Lx - 1.0) * Ly ;
4591  shape(8) = (2.0 - Lx) * Ly ;
4592  shape(6) = (2.0 - Lx) * (1.0 - Ly);
4593  shape(3) = (Lx - 1.0) * (1.0 - Ly);
4594  }
4595 }
4596
4598  DenseMatrix &dshape) const
4599 {
4600  int i,j;
4601  double x = ip.x, y = ip.y;
4602  double Lx, Ly;
4603  Lx = 2.0 * ( 1. - x );
4604  Ly = 2.0 * ( 1. - y );
4605
4606  for (i = 0; i < 9; i++)
4607  for (j = 0; j < 2; j++)
4608  {
4609  dshape(i,j) = 0.0;
4610  }
4611
4612  if ((x <= 0.5) && (y <= 0.5)) // T0
4613  {
4614  dshape(0,0) = 2.0 * (1.0 - Ly);
4615  dshape(0,1) = 2.0 * (1.0 - Lx);
4616
4617  dshape(4,0) = 2.0 * (Ly - 1.0);
4618  dshape(4,1) = -2.0 * (2.0 - Lx);
4619
4620  dshape(8,0) = 2.0 * (2.0 - Ly);
4621  dshape(8,1) = 2.0 * (2.0 - Lx);
4622
4623  dshape(7,0) = -2.0 * (2.0 - Ly);
4624  dshape(7,0) = 2.0 * (Lx - 1.0);
4625  }
4626  else if ((x >= 0.5) && (y <= 0.5)) // T1
4627  {
4628  dshape(4,0) = -2.0 * (Ly - 1.0);
4629  dshape(4,1) = -2.0 * Lx;
4630
4631  dshape(1,0) = 2.0 * (Ly - 1.0);
4632  dshape(1,1) = -2.0 * (1.0 - Lx);
4633
4634  dshape(5,0) = 2.0 * (2.0 - Ly);
4635  dshape(5,1) = 2.0 * (1.0 - Lx);
4636
4637  dshape(8,0) = -2.0 * (2.0 - Ly);
4638  dshape(8,1) = 2.0 * Lx;
4639  }
4640  else if ((x >= 0.5) && (y >= 0.5)) // T2
4641  {
4642  dshape(8,0) = -2.0 * Ly;
4643  dshape(8,1) = -2.0 * Lx;
4644
4645  dshape(5,0) = 2.0 * Ly;
4646  dshape(5,1) = -2.0 * (1.0 - Lx);
4647
4648  dshape(2,0) = 2.0 * (1.0 - Ly);
4649  dshape(2,1) = 2.0 * (1.0 - Lx);
4650
4651  dshape(6,0) = -2.0 * (1.0 - Ly);
4652  dshape(6,1) = 2.0 * Lx;
4653  }
4654  else if ((x <= 0.5) && (y >= 0.5)) // T3
4655  {
4656  dshape(7,0) = -2.0 * Ly;
4657  dshape(7,1) = -2.0 * (Lx - 1.0);
4658
4659  dshape(8,0) = 2.0 * Ly ;
4660  dshape(8,1) = -2.0 * (2.0 - Lx);
4661
4662  dshape(6,0) = 2.0 * (1.0 - Ly);
4663  dshape(6,1) = 2.0 * (2.0 - Lx);
4664
4665  dshape(3,0) = -2.0 * (1.0 - Ly);
4666  dshape(3,1) = 2.0 * (Lx - 1.0);
4667  }
4668 }
4669
4671  : NodalFiniteElement(3, Geometry::CUBE, 27, 2, FunctionSpace::rQk)
4672 {
4673  double I[27];
4674  double J[27];
4675  double K[27];
4676  // nodes
4677  I[ 0] = 0.0; J[ 0] = 0.0; K[ 0] = 0.0;
4678  I[ 1] = 1.0; J[ 1] = 0.0; K[ 1] = 0.0;
4679  I[ 2] = 1.0; J[ 2] = 1.0; K[ 2] = 0.0;
4680  I[ 3] = 0.0; J[ 3] = 1.0; K[ 3] = 0.0;
4681  I[ 4] = 0.0; J[ 4] = 0.0; K[ 4] = 1.0;
4682  I[ 5] = 1.0; J[ 5] = 0.0; K[ 5] = 1.0;
4683  I[ 6] = 1.0; J[ 6] = 1.0; K[ 6] = 1.0;
4684  I[ 7] = 0.0; J[ 7] = 1.0; K[ 7] = 1.0;
4685  // edges
4686  I[ 8] = 0.5; J[ 8] = 0.0; K[ 8] = 0.0;
4687  I[ 9] = 1.0; J[ 9] = 0.5; K[ 9] = 0.0;
4688  I[10] = 0.5; J[10] = 1.0; K[10] = 0.0;
4689  I[11] = 0.0; J[11] = 0.5; K[11] = 0.0;
4690  I[12] = 0.5; J[12] = 0.0; K[12] = 1.0;
4691  I[13] = 1.0; J[13] = 0.5; K[13] = 1.0;
4692  I[14] = 0.5; J[14] = 1.0; K[14] = 1.0;
4693  I[15] = 0.0; J[15] = 0.5; K[15] = 1.0;
4694  I[16] = 0.0; J[16] = 0.0; K[16] = 0.5;
4695  I[17] = 1.0; J[17] = 0.0; K[17] = 0.5;
4696  I[18] = 1.0; J[18] = 1.0; K[18] = 0.5;
4697  I[19] = 0.0; J[19] = 1.0; K[19] = 0.5;
4698  // faces
4699  I[20] = 0.5; J[20] = 0.5; K[20] = 0.0;
4700  I[21] = 0.5; J[21] = 0.0; K[21] = 0.5;
4701  I[22] = 1.0; J[22] = 0.5; K[22] = 0.5;
4702  I[23] = 0.5; J[23] = 1.0; K[23] = 0.5;
4703  I[24] = 0.0; J[24] = 0.5; K[24] = 0.5;
4704  I[25] = 0.5; J[25] = 0.5; K[25] = 1.0;
4705  // element
4706  I[26] = 0.5; J[26] = 0.5; K[26] = 0.5;
4707
4708  for (int n = 0; n < 27; n++)
4709  {
4710  Nodes.IntPoint(n).x = I[n];
4711  Nodes.IntPoint(n).y = J[n];
4712  Nodes.IntPoint(n).z = K[n];
4713  }
4714 }
4715
4717  Vector &shape) const
4718 {
4719  int i, N[8];
4720  double Lx, Ly, Lz;
4721  double x = ip.x, y = ip.y, z = ip.z;
4722
4723  for (i = 0; i < 27; i++)
4724  {
4725  shape(i) = 0.0;
4726  }
4727
4728  if ((x <= 0.5) && (y <= 0.5) && (z <= 0.5)) // T0
4729  {
4730  Lx = 1.0 - 2.0 * x;
4731  Ly = 1.0 - 2.0 * y;
4732  Lz = 1.0 - 2.0 * z;
4733
4734  N[0] = 0;
4735  N[1] = 8;
4736  N[2] = 20;
4737  N[3] = 11;
4738  N[4] = 16;
4739  N[5] = 21;
4740  N[6] = 26;
4741  N[7] = 24;
4742  }
4743  else if ((x >= 0.5) && (y <= 0.5) && (z <= 0.5)) // T1
4744  {
4745  Lx = 2.0 - 2.0 * x;
4746  Ly = 1.0 - 2.0 * y;
4747  Lz = 1.0 - 2.0 * z;
4748
4749  N[0] = 8;
4750  N[1] = 1;
4751  N[2] = 9;
4752  N[3] = 20;
4753  N[4] = 21;
4754  N[5] = 17;
4755  N[6] = 22;
4756  N[7] = 26;
4757  }
4758  else if ((x <= 0.5) && (y >= 0.5) && (z <= 0.5)) // T2
4759  {
4760  Lx = 2.0 - 2.0 * x;
4761  Ly = 2.0 - 2.0 * y;
4762  Lz = 1.0 - 2.0 * z;
4763
4764  N[0] = 20;
4765  N[1] = 9;
4766  N[2] = 2;
4767  N[3] = 10;
4768  N[4] = 26;
4769  N[5] = 22;
4770  N[6] = 18;
4771  N[7] = 23;
4772  }
4773  else if ((x >= 0.5) && (y >= 0.5) && (z <= 0.5)) // T3
4774  {
4775  Lx = 1.0 - 2.0 * x;
4776  Ly = 2.0 - 2.0 * y;
4777  Lz = 1.0 - 2.0 * z;
4778
4779  N[0] = 11;
4780  N[1] = 20;
4781  N[2] = 10;
4782  N[3] = 3;
4783  N[4] = 24;
4784  N[5] = 26;
4785  N[6] = 23;
4786  N[7] = 19;
4787  }
4788  else if ((x <= 0.5) && (y <= 0.5) && (z >= 0.5)) // T4
4789  {
4790  Lx = 1.0 - 2.0 * x;
4791  Ly = 1.0 - 2.0 * y;
4792  Lz = 2.0 - 2.0 * z;
4793
4794  N[0] = 16;
4795  N[1] = 21;
4796  N[2] = 26;
4797  N[3] = 24;
4798  N[4] = 4;
4799  N[5] = 12;
4800  N[6] = 25;
4801  N[7] = 15;
4802  }
4803  else if ((x >= 0.5) && (y <= 0.5) && (z >= 0.5)) // T5
4804  {
4805  Lx = 2.0 - 2.0 * x;
4806  Ly = 1.0 - 2.0 * y;
4807  Lz = 2.0 - 2.0 * z;
4808
4809  N[0] = 21;
4810  N[1] = 17;
4811  N[2] = 22;
4812  N[3] = 26;
4813  N[4] = 12;
4814  N[5] = 5;
4815  N[6] = 13;
4816  N[7] = 25;
4817  }
4818  else if ((x <= 0.5) && (y >= 0.5) && (z >= 0.5)) // T6
4819  {
4820  Lx = 2.0 - 2.0 * x;
4821  Ly = 2.0 - 2.0 * y;
4822  Lz = 2.0 - 2.0 * z;
4823
4824  N[0] = 26;
4825  N[1] = 22;
4826  N[2] = 18;
4827  N[3] = 23;
4828  N[4] = 25;
4829  N[5] = 13;
4830  N[6] = 6;
4831  N[7] = 14;
4832  }
4833  else // T7
4834  {
4835  Lx = 1.0 - 2.0 * x;
4836  Ly = 2.0 - 2.0 * y;
4837  Lz = 2.0 - 2.0 * z;
4838
4839  N[0] = 24;
4840  N[1] = 26;
4841  N[2] = 23;
4842  N[3] = 19;
4843  N[4] = 15;
4844  N[5] = 25;
4845  N[6] = 14;
4846  N[7] = 7;
4847  }
4848
4849  shape(N[0]) = Lx * Ly * Lz;
4850  shape(N[1]) = (1 - Lx) * Ly * Lz;
4851  shape(N[2]) = (1 - Lx) * (1 - Ly) * Lz;
4852  shape(N[3]) = Lx * (1 - Ly) * Lz;
4853  shape(N[4]) = Lx * Ly * (1 - Lz);
4854  shape(N[5]) = (1 - Lx) * Ly * (1 - Lz);
4855  shape(N[6]) = (1 - Lx) * (1 - Ly) * (1 - Lz);
4856  shape(N[7]) = Lx * (1 - Ly) * (1 - Lz);
4857 }
4858
4860  DenseMatrix &dshape) const
4861 {
4862  int i, j, N[8];
4863  double Lx, Ly, Lz;
4864  double x = ip.x, y = ip.y, z = ip.z;
4865
4866  for (i = 0; i < 27; i++)
4867  for (j = 0; j < 3; j++)
4868  {
4869  dshape(i,j) = 0.0;
4870  }
4871
4872  if ((x <= 0.5) && (y <= 0.5) && (z <= 0.5)) // T0
4873  {
4874  Lx = 1.0 - 2.0 * x;
4875  Ly = 1.0 - 2.0 * y;
4876  Lz = 1.0 - 2.0 * z;
4877
4878  N[0] = 0;
4879  N[1] = 8;
4880  N[2] = 20;
4881  N[3] = 11;
4882  N[4] = 16;
4883  N[5] = 21;
4884  N[6] = 26;
4885  N[7] = 24;
4886  }
4887  else if ((x >= 0.5) && (y <= 0.5) && (z <= 0.5)) // T1
4888  {
4889  Lx = 2.0 - 2.0 * x;
4890  Ly = 1.0 - 2.0 * y;
4891  Lz = 1.0 - 2.0 * z;
4892
4893  N[0] = 8;
4894  N[1] = 1;
4895  N[2] = 9;
4896  N[3] = 20;
4897  N[4] = 21;
4898  N[5] = 17;
4899  N[6] = 22;
4900  N[7] = 26;
4901  }
4902  else if ((x <= 0.5) && (y >= 0.5) && (z <= 0.5)) // T2
4903  {
4904  Lx = 2.0 - 2.0 * x;
4905  Ly = 2.0 - 2.0 * y;
4906  Lz = 1.0 - 2.0 * z;
4907
4908  N[0] = 20;
4909  N[1] = 9;
4910  N[2] = 2;
4911  N[3] = 10;
4912  N[4] = 26;
4913  N[5] = 22;
4914  N[6] = 18;
4915  N[7] = 23;
4916  }
4917  else if ((x >= 0.5) && (y >= 0.5) && (z <= 0.5)) // T3
4918  {
4919  Lx = 1.0 - 2.0 * x;
4920  Ly = 2.0 - 2.0 * y;
4921  Lz = 1.0 - 2.0 * z;
4922
4923  N[0] = 11;
4924  N[1] = 20;
4925  N[2] = 10;
4926  N[3] = 3;
4927  N[4] = 24;
4928  N[5] = 26;
4929  N[6] = 23;
4930  N[7] = 19;
4931  }
4932  else if ((x <= 0.5) && (y <= 0.5) && (z >= 0.5)) // T4
4933  {
4934  Lx = 1.0 - 2.0 * x;
4935  Ly = 1.0 - 2.0 * y;
4936  Lz = 2.0 - 2.0 * z;
4937
4938  N[0] = 16;
4939  N[1] = 21;
4940  N[2] = 26;
4941  N[3] = 24;
4942  N[4] = 4;
4943  N[5] = 12;
4944  N[6] = 25;
4945  N[7] = 15;
4946  }
4947  else if ((x >= 0.5) && (y <= 0.5) && (z >= 0.5)) // T5
4948  {
4949  Lx = 2.0 - 2.0 * x;
4950  Ly = 1.0 - 2.0 * y;
4951  Lz = 2.0 - 2.0 * z;
4952
4953  N[0] = 21;
4954  N[1] = 17;
4955  N[2] = 22;
4956  N[3] = 26;
4957  N[4] = 12;
4958  N[5] = 5;
4959  N[6] = 13;
4960  N[7] = 25;
4961  }
4962  else if ((x <= 0.5) && (y >= 0.5) && (z >= 0.5)) // T6
4963  {
4964  Lx = 2.0 - 2.0 * x;
4965  Ly = 2.0 - 2.0 * y;
4966  Lz = 2.0 - 2.0 * z;
4967
4968  N[0] = 26;
4969  N[1] = 22;
4970  N[2] = 18;
4971  N[3] = 23;
4972  N[4] = 25;
4973  N[5] = 13;
4974  N[6] = 6;
4975  N[7] = 14;
4976  }
4977  else // T7
4978  {
4979  Lx = 1.0 - 2.0 * x;
4980  Ly = 2.0 - 2.0 * y;
4981  Lz = 2.0 - 2.0 * z;
4982
4983  N[0] = 24;
4984  N[1] = 26;
4985  N[2] = 23;
4986  N[3] = 19;
4987  N[4] = 15;
4988  N[5] = 25;
4989  N[6] = 14;
4990  N[7] = 7;
4991  }
4992
4993  dshape(N[0],0) = -2.0 * Ly * Lz ;
4994  dshape(N[0],1) = -2.0 * Lx * Lz ;
4995  dshape(N[0],2) = -2.0 * Lx * Ly ;
4996
4997  dshape(N[1],0) = 2.0 * Ly * Lz ;
4998  dshape(N[1],1) = -2.0 * (1 - Lx) * Lz ;
4999  dshape(N[1],2) = -2.0 * (1 - Lx) * Ly ;
5000
5001  dshape(N[2],0) = 2.0 * (1 - Ly) * Lz ;
5002  dshape(N[2],1) = 2.0 * (1 - Lx) * Lz ;
5003  dshape(N[2],2) = -2.0 * (1 - Lx) * (1 - Ly);
5004
5005  dshape(N[3],0) = -2.0 * (1 - Ly) * Lz ;
5006  dshape(N[3],1) = 2.0 * Lx * Lz ;
5007  dshape(N[3],2) = -2.0 * Lx * (1 - Ly);
5008
5009  dshape(N[4],0) = -2.0 * Ly * (1 - Lz);
5010  dshape(N[4],1) = -2.0 * Lx * (1 - Lz);
5011  dshape(N[4],2) = 2.0 * Lx * Ly ;
5012
5013  dshape(N[5],0) = 2.0 * Ly * (1 - Lz);
5014  dshape(N[5],1) = -2.0 * (1 - Lx) * (1 - Lz);
5015  dshape(N[5],2) = 2.0 * (1 - Lx) * Ly ;
5016
5017  dshape(N[6],0) = 2.0 * (1 - Ly) * (1 - Lz);
5018  dshape(N[6],1) = 2.0 * (1 - Lx) * (1 - Lz);
5019  dshape(N[6],2) = 2.0 * (1 - Lx) * (1 - Ly);
5020
5021  dshape(N[7],0) = -2.0 * (1 - Ly) * (1 - Lz);
5022  dshape(N[7],1) = 2.0 * Lx * (1 - Lz);
5023  dshape(N[7],2) = 2.0 * Lx * (1 - Ly);
5024 }
5025
5026
5028  : VectorFiniteElement(3, Geometry::CUBE, 12, 1, H_CURL, FunctionSpace::Qk)
5029 {
5030  // not real nodes ...
5031  Nodes.IntPoint(0).x = 0.5;
5032  Nodes.IntPoint(0).y = 0.0;
5033  Nodes.IntPoint(0).z = 0.0;
5034
5035  Nodes.IntPoint(1).x = 1.0;
5036  Nodes.IntPoint(1).y = 0.5;
5037  Nodes.IntPoint(1).z = 0.0;
5038
5039  Nodes.IntPoint(2).x = 0.5;
5040  Nodes.IntPoint(2).y = 1.0;
5041  Nodes.IntPoint(2).z = 0.0;
5042
5043  Nodes.IntPoint(3).x = 0.0;
5044  Nodes.IntPoint(3).y = 0.5;
5045  Nodes.IntPoint(3).z = 0.0;
5046
5047  Nodes.IntPoint(4).x = 0.5;
5048  Nodes.IntPoint(4).y = 0.0;
5049  Nodes.IntPoint(4).z = 1.0;
5050
5051  Nodes.IntPoint(5).x = 1.0;
5052  Nodes.IntPoint(5).y = 0.5;
5053  Nodes.IntPoint(5).z = 1.0;
5054
5055  Nodes.IntPoint(6).x = 0.5;
5056  Nodes.IntPoint(6).y = 1.0;
5057  Nodes.IntPoint(6).z = 1.0;
5058
5059  Nodes.IntPoint(7).x = 0.0;
5060  Nodes.IntPoint(7).y = 0.5;
5061  Nodes.IntPoint(7).z = 1.0;
5062
5063  Nodes.IntPoint(8).x = 0.0;
5064  Nodes.IntPoint(8).y = 0.0;
5065  Nodes.IntPoint(8).z = 0.5;
5066
5067  Nodes.IntPoint(9).x = 1.0;
5068  Nodes.IntPoint(9).y = 0.0;
5069  Nodes.IntPoint(9).z = 0.5;
5070
5071  Nodes.IntPoint(10).x= 1.0;
5072  Nodes.IntPoint(10).y= 1.0;
5073  Nodes.IntPoint(10).z= 0.5;
5074
5075  Nodes.IntPoint(11).x= 0.0;
5076  Nodes.IntPoint(11).y= 1.0;
5077  Nodes.IntPoint(11).z= 0.5;
5078 }
5079
5081  DenseMatrix &shape) const
5082 {
5083  double x = ip.x, y = ip.y, z = ip.z;
5084
5085  shape(0,0) = (1. - y) * (1. - z);
5086  shape(0,1) = 0.;
5087  shape(0,2) = 0.;
5088
5089  shape(2,0) = y * (1. - z);
5090  shape(2,1) = 0.;
5091  shape(2,2) = 0.;
5092
5093  shape(4,0) = z * (1. - y);
5094  shape(4,1) = 0.;
5095  shape(4,2) = 0.;
5096
5097  shape(6,0) = y * z;
5098  shape(6,1) = 0.;
5099  shape(6,2) = 0.;
5100
5101  shape(1,0) = 0.;
5102  shape(1,1) = x * (1. - z);
5103  shape(1,2) = 0.;
5104
5105  shape(3,0) = 0.;
5106  shape(3,1) = (1. - x) * (1. - z);
5107  shape(3,2) = 0.;
5108
5109  shape(5,0) = 0.;
5110  shape(5,1) = x * z;
5111  shape(5,2) = 0.;
5112
5113  shape(7,0) = 0.;
5114  shape(7,1) = (1. - x) * z;
5115  shape(7,2) = 0.;
5116
5117  shape(8,0) = 0.;
5118  shape(8,1) = 0.;
5119  shape(8,2) = (1. - x) * (1. - y);
5120
5121  shape(9,0) = 0.;
5122  shape(9,1) = 0.;
5123  shape(9,2) = x * (1. - y);
5124
5125  shape(10,0) = 0.;
5126  shape(10,1) = 0.;
5127  shape(10,2) = x * y;
5128
5129  shape(11,0) = 0.;
5130  shape(11,1) = 0.;
5131  shape(11,2) = y * (1. - x);
5132
5133 }
5134
5136  DenseMatrix &curl_shape)
5137 const
5138 {
5139  double x = ip.x, y = ip.y, z = ip.z;
5140
5141  curl_shape(0,0) = 0.;
5142  curl_shape(0,1) = y - 1.;
5143  curl_shape(0,2) = 1. - z;
5144
5145  curl_shape(2,0) = 0.;
5146  curl_shape(2,1) = -y;
5147  curl_shape(2,2) = z - 1.;
5148
5149  curl_shape(4,0) = 0;
5150  curl_shape(4,1) = 1. - y;
5151  curl_shape(4,2) = z;
5152
5153  curl_shape(6,0) = 0.;
5154  curl_shape(6,1) = y;
5155  curl_shape(6,2) = -z;
5156
5157  curl_shape(1,0) = x;
5158  curl_shape(1,1) = 0.;
5159  curl_shape(1,2) = 1. - z;
5160
5161  curl_shape(3,0) = 1. - x;
5162  curl_shape(3,1) = 0.;
5163  curl_shape(3,2) = z - 1.;
5164
5165  curl_shape(5,0) = -x;
5166  curl_shape(5,1) = 0.;
5167  curl_shape(5,2) = z;
5168
5169  curl_shape(7,0) = x - 1.;
5170  curl_shape(7,1) = 0.;
5171  curl_shape(7,2) = -z;
5172
5173  curl_shape(8,0) = x - 1.;
5174  curl_shape(8,1) = 1. - y;
5175  curl_shape(8,2) = 0.;
5176
5177  curl_shape(9,0) = -x;
5178  curl_shape(9,1) = y - 1.;
5179  curl_shape(9,2) = 0;
5180
5181  curl_shape(10,0) = x;
5182  curl_shape(10,1) = -y;
5183  curl_shape(10,2) = 0.;
5184
5185  curl_shape(11,0) = 1. - x;
5186  curl_shape(11,1) = y;
5187  curl_shape(11,2) = 0.;
5188 }
5189
5190 const double Nedelec1HexFiniteElement::tk[12][3] =
5191 {
5192  {1,0,0}, {0,1,0}, {1,0,0}, {0,1,0},
5193  {1,0,0}, {0,1,0}, {1,0,0}, {0,1,0},
5194  {0,0,1}, {0,0,1}, {0,0,1}, {0,0,1}
5195 };
5196
5199 {
5200  int k, j;
5203 #endif
5204
5205 #ifdef MFEM_DEBUG
5206  for (k = 0; k < 12; k++)
5207  {
5209  for (j = 0; j < 12; j++)
5210  {
5211  double d = ( vshape(j,0)*tk[k][0] + vshape(j,1)*tk[k][1] +
5212  vshape(j,2)*tk[k][2] );
5213  if (j == k) { d -= 1.0; }
5214  if (fabs(d) > 1.0e-12)
5215  {
5216  mfem::err << "Nedelec1HexFiniteElement::GetLocalInterpolation (...)\n"
5217  " k = " << k << ", j = " << j << ", d = " << d << endl;
5218  mfem_error();
5219  }
5220  }
5221  }
5222 #endif
5223
5224  IntegrationPoint ip;
5225  ip.x = ip.y = ip.z = 0.0;
5226  Trans.SetIntPoint (&ip);
5227  // Trans must be linear (more to have embedding?)
5228  const DenseMatrix &J = Trans.Jacobian();
5229  double vk[3];
5230  Vector xk (vk, 3);
5231
5232  for (k = 0; k < 12; k++)
5233  {
5234  Trans.Transform (Nodes.IntPoint (k), xk);
5235  ip.x = vk[0]; ip.y = vk[1]; ip.z = vk[2];
5236  CalcVShape (ip, vshape);
5237  // vk = J tk
5238  vk[0] = J(0,0)*tk[k][0]+J(0,1)*tk[k][1]+J(0,2)*tk[k][2];
5239  vk[1] = J(1,0)*tk[k][0]+J(1,1)*tk[k][1]+J(1,2)*tk[k][2];
5240  vk[2] = J(2,0)*tk[k][0]+J(2,1)*tk[k][1]+J(2,2)*tk[k][2];
5241  for (j = 0; j < 12; j++)
5242  if (fabs (I(k,j) = (vshape(j,0)*vk[0]+vshape(j,1)*vk[1]+
5243  vshape(j,2)*vk[2])) < 1.0e-12)
5244  {
5245  I(k,j) = 0.0;
5246  }
5247  }
5248 }
5249
5252  Vector &dofs) const
5253 {
5254  double vk[3];
5255  Vector xk (vk, 3);
5256
5257  for (int k = 0; k < 12; k++)
5258  {
5259  Trans.SetIntPoint (&Nodes.IntPoint (k));
5260  const DenseMatrix &J = Trans.Jacobian();
5261
5262  vc.Eval (xk, Trans, Nodes.IntPoint (k));
5263  // xk^t J tk
5264  dofs(k) =
5265  vk[0] * ( J(0,0)*tk[k][0]+J(0,1)*tk[k][1]+J(0,2)*tk[k][2] ) +
5266  vk[1] * ( J(1,0)*tk[k][0]+J(1,1)*tk[k][1]+J(1,2)*tk[k][2] ) +
5267  vk[2] * ( J(2,0)*tk[k][0]+J(2,1)*tk[k][1]+J(2,2)*tk[k][2] );
5268  }
5269 }
5270
5271
5273  : VectorFiniteElement(3, Geometry::TETRAHEDRON, 6, 1, H_CURL)
5274 {
5275  // not real nodes ...
5276  Nodes.IntPoint(0).x = 0.5;
5277  Nodes.IntPoint(0).y = 0.0;
5278  Nodes.IntPoint(0).z = 0.0;
5279
5280  Nodes.IntPoint(1).x = 0.0;
5281  Nodes.IntPoint(1).y = 0.5;
5282  Nodes.IntPoint(1).z = 0.0;
5283
5284  Nodes.IntPoint(2).x = 0.0;
5285  Nodes.IntPoint(2).y = 0.0;
5286  Nodes.IntPoint(2).z = 0.5;
5287
5288  Nodes.IntPoint(3).x = 0.5;
5289  Nodes.IntPoint(3).y = 0.5;
5290  Nodes.IntPoint(3).z = 0.0;
5291
5292  Nodes.IntPoint(4).x = 0.5;
5293  Nodes.IntPoint(4).y = 0.0;
5294  Nodes.IntPoint(4).z = 0.5;
5295
5296  Nodes.IntPoint(5).x = 0.0;
5297  Nodes.IntPoint(5).y = 0.5;
5298  Nodes.IntPoint(5).z = 0.5;
5299 }
5300
5302  DenseMatrix &shape) const
5303 {
5304  double x = ip.x, y = ip.y, z = ip.z;
5305
5306  shape(0,0) = 1. - y - z;
5307  shape(0,1) = x;
5308  shape(0,2) = x;
5309
5310  shape(1,0) = y;
5311  shape(1,1) = 1. - x - z;
5312  shape(1,2) = y;
5313
5314  shape(2,0) = z;
5315  shape(2,1) = z;
5316  shape(2,2) = 1. - x - y;
5317
5318  shape(3,0) = -y;
5319  shape(3,1) = x;
5320  shape(3,2) = 0.;
5321
5322  shape(4,0) = -z;
5323  shape(4,1) = 0.;
5324  shape(4,2) = x;
5325
5326  shape(5,0) = 0.;
5327  shape(5,1) = -z;
5328  shape(5,2) = y;
5329 }
5330
5332  DenseMatrix &curl_shape)
5333 const
5334 {
5335  curl_shape(0,0) = 0.;
5336  curl_shape(0,1) = -2.;
5337  curl_shape(0,2) = 2.;
5338
5339  curl_shape(1,0) = 2.;
5340  curl_shape(1,1) = 0.;
5341  curl_shape(1,2) = -2.;
5342
5343  curl_shape(2,0) = -2.;
5344  curl_shape(2,1) = 2.;
5345  curl_shape(2,2) = 0.;
5346
5347  curl_shape(3,0) = 0.;
5348  curl_shape(3,1) = 0.;
5349  curl_shape(3,2) = 2.;
5350
5351  curl_shape(4,0) = 0.;
5352  curl_shape(4,1) = -2.;
5353  curl_shape(4,2) = 0.;
5354
5355  curl_shape(5,0) = 2.;
5356  curl_shape(5,1) = 0.;
5357  curl_shape(5,2) = 0.;
5358 }
5359
5360 const double Nedelec1TetFiniteElement::tk[6][3] =
5361 {{1,0,0}, {0,1,0}, {0,0,1}, {-1,1,0}, {-1,0,1}, {0,-1,1}};
5362
5365 {
5366  int k, j;
5369 #endif
5370
5371 #ifdef MFEM_DEBUG
5372  for (k = 0; k < 6; k++)
5373  {
5375  for (j = 0; j < 6; j++)
5376  {
5377  double d = ( vshape(j,0)*tk[k][0] + vshape(j,1)*tk[k][1] +
5378  vshape(j,2)*tk[k][2] );
5379  if (j == k) { d -= 1.0; }
5380  if (fabs(d) > 1.0e-12)
5381  {
5382  mfem::err << "Nedelec1TetFiniteElement::GetLocalInterpolation (...)\n"
5383  " k = " << k << ", j = " << j << ", d = " << d << endl;
5384  mfem_error();
5385  }
5386  }
5387  }
5388 #endif
5389
5390  IntegrationPoint ip;
5391  ip.x = ip.y = ip.z = 0.0;
5392  Trans.SetIntPoint (&ip);
5393  // Trans must be linear
5394  const DenseMatrix &J = Trans.Jacobian();
5395  double vk[3];
5396  Vector xk (vk, 3);
5397
5398  for (k = 0; k < 6; k++)
5399  {
5400  Trans.Transform (Nodes.IntPoint (k), xk);
5401  ip.x = vk[0]; ip.y = vk[1]; ip.z = vk[2];
5402  CalcVShape (ip, vshape);
5403  // vk = J tk
5404  vk[0] = J(0,0)*tk[k][0]+J(0,1)*tk[k][1]+J(0,2)*tk[k][2];
5405  vk[1] = J(1,0)*tk[k][0]+J(1,1)*tk[k][1]+J(1,2)*tk[k][2];
5406  vk[2] = J(2,0)*tk[k][0]+J(2,1)*tk[k][1]+J(2,2)*tk[k][2];
5407  for (j = 0; j < 6; j++)
5408  if (fabs (I(k,j) = (vshape(j,0)*vk[0]+vshape(j,1)*vk[1]+
5409  vshape(j,2)*vk[2])) < 1.0e-12)
5410  {
5411  I(k,j) = 0.0;
5412  }
5413  }
5414 }
5415
5418  Vector &dofs) const
5419 {
5420  double vk[3];
5421  Vector xk (vk, 3);
5422
5423  for (int k = 0; k < 6; k++)
5424  {
5425  Trans.SetIntPoint (&Nodes.IntPoint (k));
5426  const DenseMatrix &J = Trans.Jacobian();
5427
5428  vc.Eval (xk, Trans, Nodes.IntPoint (k));
5429  // xk^t J tk
5430  dofs(k) =
5431  vk[0] * ( J(0,0)*tk[k][0]+J(0,1)*tk[k][1]+J(0,2)*tk[k][2] ) +
5432  vk[1] * ( J(1,0)*tk[k][0]+J(1,1)*tk[k][1]+J(1,2)*tk[k][2] ) +
5433  vk[2] * ( J(2,0)*tk[k][0]+J(2,1)*tk[k][1]+J(2,2)*tk[k][2] );
5434  }
5435 }
5436
5438  : VectorFiniteElement(3, Geometry::CUBE, 6, 1, H_DIV, FunctionSpace::Qk)
5439 {
5440  // not real nodes ...
5441  // z = 0, y = 0, x = 1, y = 1, x = 0, z = 1
5442  Nodes.IntPoint(0).x = 0.5;
5443  Nodes.IntPoint(0).y = 0.5;
5444  Nodes.IntPoint(0).z = 0.0;
5445
5446  Nodes.IntPoint(1).x = 0.5;
5447  Nodes.IntPoint(1).y = 0.0;
5448  Nodes.IntPoint(1).z = 0.5;
5449
5450  Nodes.IntPoint(2).x = 1.0;
5451  Nodes.IntPoint(2).y = 0.5;
5452  Nodes.IntPoint(2).z = 0.5;
5453
5454  Nodes.IntPoint(3).x = 0.5;
5455  Nodes.IntPoint(3).y = 1.0;
5456  Nodes.IntPoint(3).z = 0.5;
5457
5458  Nodes.IntPoint(4).x = 0.0;
5459  Nodes.IntPoint(4).y = 0.5;
5460  Nodes.IntPoint(4).z = 0.5;
5461
5462  Nodes.IntPoint(5).x = 0.5;
5463  Nodes.IntPoint(5).y = 0.5;
5464  Nodes.IntPoint(5).z = 1.0;
5465 }
5466