18 {
"Point",
"Segment",
"Triangle",
"Square",
"Tetrahedron",
"Cube" };
21 { 1.0, 1.0, 0.5, 1.0, 1./6, 1.0 };
114 GeomCenter[
POINT].
x = 0.0;
115 GeomCenter[
POINT].
y = 0.0;
116 GeomCenter[
POINT].
z = 0.0;
134 GeomCenter[
CUBE].
x = 0.5;
135 GeomCenter[
CUBE].
y = 0.5;
136 GeomCenter[
CUBE].
z = 0.5;
138 GeomToPerfGeomJac[
POINT] = NULL;
145 PerfGeomToGeomJac[
POINT] = NULL;
146 PerfGeomToGeomJac[
SEGMENT] = NULL;
148 PerfGeomToGeomJac[
SQUARE] = NULL;
150 PerfGeomToGeomJac[
CUBE] = NULL;
174 GeomToPerfGeomJac[
CUBE]->
Diag(1.0, 3);
179 for (
int i = 0; i <
NumGeom; i++)
181 delete PerfGeomToGeomJac[i];
182 delete GeomToPerfGeomJac[i];
213 ip.
x = double(rand()) / RAND_MAX;
216 ip.
x = double(rand()) / RAND_MAX;
217 ip.
y = double(rand()) / RAND_MAX;
218 if (ip.
x + ip.
y > 1.0)
225 ip.
x = double(rand()) / RAND_MAX;
226 ip.
y = double(rand()) / RAND_MAX;
229 ip.
x = double(rand()) / RAND_MAX;
230 ip.
y = double(rand()) / RAND_MAX;
231 ip.
z = double(rand()) / RAND_MAX;
234 if (ip.
x + ip.
y > 1.0)
241 if (ip.
x + ip.
z > 1.0)
244 ip.
x = ip.
x + ip.
z - 1.0;
249 else if (ip.
x + ip.
y + ip.
z > 1.0)
253 ip.
x = 1.0 - x - ip.
z;
254 ip.
y = 1.0 - x - ip.
y;
260 ip.
x = double(rand()) / RAND_MAX;
261 ip.
y = double(rand()) / RAND_MAX;
262 ip.
z = double(rand()) / RAND_MAX;
265 MFEM_ABORT(
"Unknown type of reference element!");
274 inline bool NearlyEqual(
double x,
double y,
double eps)
276 return std::abs(x-y) <= eps;
281 inline bool FuzzyGT(
double x,
double y,
double eps)
283 return (x > y + eps);
288 inline bool FuzzyLT(
double x,
double y,
double eps)
290 return (x < y - eps);
301 if (ip.
x != 0.0) {
return false; }
304 if (ip.
x < 0.0 || ip.
x > 1.0) {
return false; }
307 if (ip.
x < 0.0 || ip.
y < 0.0 || ip.
x+ip.
y > 1.0) {
return false; }
310 if (ip.
x < 0.0 || ip.
x > 1.0 || ip.
y < 0.0 || ip.
y > 1.0)
314 if (ip.
x < 0.0 || ip.
y < 0.0 || ip.
z < 0.0 ||
315 ip.
x+ip.
y+ip.
z > 1.0) {
return false; }
318 if (ip.
x < 0.0 || ip.
x > 1.0 || ip.
y < 0.0 || ip.
y > 1.0 ||
319 ip.
z < 0.0 || ip.
z > 1.0) {
return false; }
322 MFEM_ABORT(
"Unknown type of reference element!");
332 if (! internal::NearlyEqual(ip.
x, 0.0, eps))
338 if ( internal::FuzzyLT(ip.
x, 0.0, eps)
339 || internal::FuzzyGT(ip.
x, 1.0, eps) )
345 if ( internal::FuzzyLT(ip.
x, 0.0, eps)
346 || internal::FuzzyLT(ip.
y, 0.0, eps)
347 || internal::FuzzyGT(ip.
x+ip.
y, 1.0, eps) )
353 if ( internal::FuzzyLT(ip.
x, 0.0, eps)
354 || internal::FuzzyGT(ip.
x, 1.0, eps)
355 || internal::FuzzyLT(ip.
y, 0.0, eps)
356 || internal::FuzzyGT(ip.
y, 1.0, eps) )
362 if ( internal::FuzzyLT(ip.
x, 0.0, eps)
363 || internal::FuzzyLT(ip.
y, 0.0, eps)
364 || internal::FuzzyLT(ip.
z, 0.0, eps)
365 || internal::FuzzyGT(ip.
x+ip.
y+ip.
z, 1.0, eps) )
371 if ( internal::FuzzyLT(ip.
x, 0.0, eps)
372 || internal::FuzzyGT(ip.
x, 1.0, eps)
373 || internal::FuzzyLT(ip.
y, 0.0, eps)
374 || internal::FuzzyGT(ip.
y, 1.0, eps)
375 || internal::FuzzyLT(ip.
z, 0.0, eps)
376 || internal::FuzzyGT(ip.
z, 1.0, eps) )
382 MFEM_ABORT(
"Unknown type of reference element!");
391 template <
int N,
int dim>
392 inline bool IntersectSegment(
double lbeg[N],
double lend[N],
397 for (
int i = 0; i < N; i++)
399 lbeg[i] = std::max(lbeg[i], 0.0);
403 t = std::min(t, lbeg[i]/(lbeg[i]-lend[i]));
408 if (
dim >= 1) { end.
x = t*lend[0] + (1.0-t)*lbeg[0]; }
409 if (
dim >= 2) { end.
y = t*lend[1] + (1.0-t)*lbeg[1]; }
410 if (
dim >= 3) { end.
z = t*lend[2] + (1.0-t)*lbeg[2]; }
416 inline bool ProjectTriangle(
double &x,
double &y)
421 if (y < 0.0) { y = 0.0; }
422 else if (y > 1.0) { y = 1.0; }
427 if (x > 1.0) { x = 1.0; }
431 const double l3 = 1.0-x-y;
434 if (y - x > 1.0) { x = 0.0; y = 1.0; }
435 else if (y - x < -1.0) { x = 1.0; y = 0.0; }
436 else { x += l3/2; y += l3/2; }
452 if (end.
x != 0.0) { end.
x = 0.0;
return false; }
457 if (end.
x < 0.0) { end.
x = 0.0;
return false; }
458 if (end.
x > 1.0) { end.
x = 1.0;
return false; }
463 double lend[3] = { end.
x, end.
y, 1-end.
x-end.
y };
464 double lbeg[3] = { beg.
x, beg.
y, 1-beg.
x-beg.
y };
465 return internal::IntersectSegment<3,2>(lbeg, lend, end);
469 double lend[4] = { end.
x, end.
y, 1-end.
x, 1.0-end.
y };
470 double lbeg[4] = { beg.
x, beg.
y, 1-beg.
x, 1.0-beg.
y };
471 return internal::IntersectSegment<4,2>(lbeg, lend, end);
475 double lend[4] = { end.
x, end.
y, end.
z, 1.0-end.
x-end.
y-end.
z };
476 double lbeg[4] = { beg.
x, beg.
y, beg.
z, 1.0-beg.
x-beg.
y-beg.
z };
477 return internal::IntersectSegment<4,3>(lbeg, lend, end);
481 double lend[6] = { end.
x, end.
y, end.
z,
482 1.0-end.
x, 1.0-end.
y, 1.0-end.
z
484 double lbeg[6] = { beg.
x, beg.
y, beg.
z,
485 1.0-beg.
x, 1.0-beg.
y, 1.0-beg.
z
487 return internal::IntersectSegment<6,3>(lbeg, lend, end);
490 MFEM_ABORT(
"Unknown type of reference element!");
506 if (ip.
x < 0.0) { ip.
x = 0.0;
return false; }
507 else if (ip.
x > 1.0) { ip.
x = 1.0;
return false; }
513 return internal::ProjectTriangle(ip.
x, ip.
y);
519 if (ip.
x < 0.0) { in_x =
false; ip.
x = 0.0; }
520 else if (ip.
x > 1.0) { in_x =
false; ip.
x = 1.0; }
521 else { in_x =
true; }
522 if (ip.
y < 0.0) { in_y =
false; ip.
y = 0.0; }
523 else if (ip.
y > 1.0) { in_y =
false; ip.
y = 1.0; }
524 else { in_y =
true; }
533 internal::ProjectTriangle(ip.
x, ip.
y);
539 internal::ProjectTriangle(ip.
x, ip.
z);
545 internal::ProjectTriangle(ip.
y, ip.
z);
548 const double l4 = 1.0-ip.
x-ip.
y-ip.
z;
551 const double l4_3 = l4/3;
554 internal::ProjectTriangle(ip.
x, ip.
y);
555 ip.
z = 1.0-ip.
x-ip.
y;
563 bool in_x, in_y, in_z;
564 if (ip.
x < 0.0) { in_x =
false; ip.
x = 0.0; }
565 else if (ip.
x > 1.0) { in_x =
false; ip.
x = 1.0; }
566 else { in_x =
true; }
567 if (ip.
y < 0.0) { in_y =
false; ip.
y = 0.0; }
568 else if (ip.
y > 1.0) { in_y =
false; ip.
y = 1.0; }
569 else { in_y =
true; }
570 if (ip.
z < 0.0) { in_z =
false; ip.
z = 0.0; }
571 else if (ip.
z > 1.0) { in_z =
false; ip.
z = 1.0; }
572 else { in_z =
true; }
573 return in_x && in_y && in_z;
577 MFEM_ABORT(
"Reference element type is not supported!");
597 pm(0,0) = 0.0; pm(1,0) = 0.0;
598 pm(0,1) = 1.0; pm(1,1) = 0.0;
599 pm(0,2) = 0.5; pm(1,2) = 0.86602540378443864676;
606 pm(0,0) = 0.0; pm(1,0) = 0.0;
607 pm(0,1) = 1.0; pm(1,1) = 0.0;
608 pm(0,2) = 1.0; pm(1,2) = 1.0;
609 pm(0,3) = 0.0; pm(1,3) = 1.0;
616 pm(0,0) = 0.0; pm(1,0) = 0.0; pm(2,0) = 0.0;
617 pm(0,1) = 1.0; pm(1,1) = 0.0; pm(2,1) = 0.0;
618 pm(0,2) = 0.5; pm(1,2) = 0.86602540378443864676; pm(2,2) = 0.0;
619 pm(0,3) = 0.5; pm(1,3) = 0.28867513459481288225;
620 pm(2,3) = 0.81649658092772603273;
627 pm(0,0) = 0.0; pm(1,0) = 0.0; pm(2,0) = 0.0;
628 pm(0,1) = 1.0; pm(1,1) = 0.0; pm(2,1) = 0.0;
629 pm(0,2) = 1.0; pm(1,2) = 1.0; pm(2,2) = 0.0;
630 pm(0,3) = 0.0; pm(1,3) = 1.0; pm(2,3) = 0.0;
631 pm(0,4) = 0.0; pm(1,4) = 0.0; pm(2,4) = 1.0;
632 pm(0,5) = 1.0; pm(1,5) = 0.0; pm(2,5) = 1.0;
633 pm(0,6) = 1.0; pm(1,6) = 1.0; pm(2,6) = 1.0;
634 pm(0,7) = 0.0; pm(1,7) = 1.0; pm(2,7) = 1.0;
639 mfem_error (
"Geometry::GetPerfPointMat (...)");
646 if (PerfGeomToGeomJac[GeomType])
648 Mult(J, *PerfGeomToGeomJac[GeomType], PJ);
685 {0, 1, 2}, {1, 0, 2}, {2, 0, 1},
686 {2, 1, 0}, {1, 2, 0}, {0, 2, 1}
697 {{1, 0}, {3, -4}, {2, 1}, {3, 2}};
703 {0, 1, 2, 3}, {0, 3, 2, 1}, {1, 2, 3, 0}, {1, 0, 3, 2},
704 {2, 3, 0, 1}, {2, 1, 0, 3}, {3, 0, 1, 2}, {3, 2, 1, 0}
711 {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}};
720 {{1, 2, 3}, {0, 3, 2}, {0, 1, 3}, {0, 2, 1}};
725 {{1, 0}, {2, 1}, {3, 2}, {2, 3}, {3, 4}, {3, 5}};
730 {0, 1}, {1, 2}, {3, 2}, {0, 3}, {4, 5}, {5, 6},
731 {7, 6}, {4, 7}, {0, 4}, {1, 5}, {2, 6}, {3, 7}
742 {3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
743 {2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}
750 {1, 0}, {3, 3}, {4, 8},
771 for (
int j = 0; j < RGeom[i].Size(); j++) {
delete RGeom[i][j]; }
772 for (
int j = 0; j < IntPts[i].Size(); j++) {
delete IntPts[i][j]; }
776 RefinedGeometry *GeometryRefiner::FindInRGeom(
int Geom,
int Times,
int ETimes,
780 for (
int i = 0; i < RGA.
Size(); i++)
791 IntegrationRule *GeometryRefiner::FindInIntPts(
int Geom,
int NPts)
793 Array<IntegrationRule *> &IPA = IntPts[Geom];
794 for (
int i = 0; i < IPA.Size(); i++)
796 IntegrationRule &ir = *IPA[i];
797 if (ir.GetNPoints() == NPts) {
return &ir; }
806 Times = std::max(Times, 1);
807 ETimes = std::max(ETimes, 1);
811 if (RG) {
return RG; }
821 for (i = 0; i <= Times; i++)
827 for (i = 0; i < Times; i++)
840 3*Times*(ETimes+1), 3*Times);
844 for (k = j = 0; j <= Times; j++)
845 for (i = 0; i <= Times-j; i++, k++)
848 ip.
x = cp[i]/(cp[i] + cp[j] + cp[Times-i-j]);
849 ip.
y = cp[j]/(cp[i] + cp[j] + cp[Times-i-j]);
852 for (l = k = j = 0; j < Times; j++, k++)
853 for (i = 0; i < Times-j; i++, k++)
857 G[l++] = k+Times-j+1;
861 G[l++] = k+Times-j+2;
862 G[l++] = k+Times-j+1;
868 for (k = 0; k < Times; k += Times/ETimes)
870 int < = (k == 0) ? lb : li;
871 j = k*(Times+1)-((k-1)*k)/2;
872 for (i = 0; i < Times-k; i++)
879 for (k = Times; k > 0; k -= Times/ETimes)
881 int < = (k == Times) ? lb : li;
883 for (i = 0; i < k; i++)
885 E[lt++] = j; j += Times-i;
890 for (k = 0; k < Times; k += Times/ETimes)
892 int < = (k == 0) ? lb : li;
894 for (i = 0; i < Times-k; i++)
896 E[lt++] = j; j += Times-i+1;
908 4*(ETimes+1)*Times, 4*Times);
912 for (k = j = 0; j <= Times; j++)
913 for (i = 0; i <= Times; i++, k++)
920 for (l = k = j = 0; j < Times; j++, k++)
921 for (i = 0; i < Times; i++, k++)
931 for (k = 0; k <= Times; k += Times/ETimes)
933 int < = (k == 0 || k == Times) ? lb : li;
934 for (i = 0, j = k*(Times+1); i < Times; i++)
941 for (k = Times; k >= 0; k -= Times/ETimes)
943 int < = (k == Times || k == 0) ? lb : li;
944 for (i = 0, j = k; i < Times; i++)
946 E[lt++] = j; j += Times+1;
958 8*Times*Times*Times, 0);
962 for (l = k = 0; k <= Times; k++)
963 for (j = 0; j <= Times; j++)
964 for (i = 0; i <= Times; i++, l++)
972 for (l = k = 0; k < Times; k++)
973 for (j = 0; j < Times; j++)
974 for (i = 0; i < Times; i++)
976 G[l++] = i+0 + (j+0 + (k+0) * (Times+1)) * (Times+1);
977 G[l++] = i+1 + (j+0 + (k+0) * (Times+1)) * (Times+1);
978 G[l++] = i+1 + (j+1 + (k+0) * (Times+1)) * (Times+1);
979 G[l++] = i+0 + (j+1 + (k+0) * (Times+1)) * (Times+1);
980 G[l++] = i+0 + (j+0 + (k+1) * (Times+1)) * (Times+1);
981 G[l++] = i+1 + (j+0 + (k+1) * (Times+1)) * (Times+1);
982 G[l++] = i+1 + (j+1 + (k+1) * (Times+1)) * (Times+1);
983 G[l++] = i+0 + (j+1 + (k+1) * (Times+1)) * (Times+1);
1005 const int n = Times;
1014 for (k = 0; k <= n; k++)
1015 for (j = 0; j <= k; j++)
1016 for (i = 0; i <= j; i++)
1024 double w = cp[k-j] + cp[i] + cp[j-i] + cp[Times-k];
1028 l = i + (j + k * (n+1)) * (n+1);
1032 if (m != (n+3)*(n+2)*(n+1)/6)
1034 mfem_error(
"GeometryRefiner::Refine() for TETRAHEDRON #1");
1039 for (k = 0; k < n; k++)
1040 for (j = 0; j <= k; j++)
1041 for (i = 0; i <= j; i++)
1051 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1052 G[m++] = vi[i+0 + (j+0 + (k+1) * (n+1)) * (n+1)];
1053 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1054 G[m++] = vi[i+0 + (j+1 + (k+1) * (n+1)) * (n+1)];
1058 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1059 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1060 G[m++] = vi[i+0 + (j+1 + (k+0) * (n+1)) * (n+1)];
1061 G[m++] = vi[i+0 + (j+1 + (k+1) * (n+1)) * (n+1)];
1063 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1064 G[m++] = vi[i+0 + (j+1 + (k+0) * (n+1)) * (n+1)];
1065 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1066 G[m++] = vi[i+1 + (j+1 + (k+0) * (n+1)) * (n+1)];
1071 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1072 G[m++] = vi[i+1 + (j+0 + (k+0) * (n+1)) * (n+1)];
1073 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1074 G[m++] = vi[i+1 + (j+0 + (k+1) * (n+1)) * (n+1)];
1078 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1079 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1080 G[m++] = vi[i+1 + (j+0 + (k+0) * (n+1)) * (n+1)];
1081 G[m++] = vi[i+1 + (j+1 + (k+0) * (n+1)) * (n+1)];
1084 G[m++] = vi[i+0 + (j+0 + (k+0) * (n+1)) * (n+1)];
1085 G[m++] = vi[i+1 + (j+1 + (k+1) * (n+1)) * (n+1)];
1086 G[m++] = vi[i+0 + (j+0 + (k+1) * (n+1)) * (n+1)];
1087 G[m++] = vi[i+1 + (j+0 + (k+1) * (n+1)) * (n+1)];
1092 mfem_error(
"GeometryRefiner::Refine() for TETRAHEDRON #2");
1094 for (i = 0; i < m; i++)
1097 mfem_error(
"GeometryRefiner::Refine() for TETRAHEDRON #3");
1122 ir = FindInIntPts(Geom, Times-1);
1126 for (
int i = 1; i < Times; i++)
1129 ip.
x = double(i) / Times;
1142 ir = FindInIntPts(Geom, ((Times-1)*(Times-2))/2);
1146 for (
int k = 0, j = 1; j < Times-1; j++)
1147 for (
int i = 1; i < Times-j; i++, k++)
1150 ip.
x = double(i) / Times;
1151 ip.
y = double(j) / Times;
1164 ir = FindInIntPts(Geom, (Times-1)*(Times-1));
1168 for (
int k = 0, j = 1; j < Times; j++)
1169 for (
int i = 1; i < Times; i++, k++)
1172 ip.
x = double(i) / Times;
1173 ip.
y = double(j) / Times;
1181 mfem_error(
"GeometryRefiner::RefineInterior(...)");
1184 if (ir) { IntPts[Geom].Append(ir); }
int Size() const
Logical size of the array.
static const int InvOrient[NumOrient]
Class for an integration rule - an Array of IntegrationPoint.
static const int I[NumVert]
static const int J[NumEdges][2]
void JacToPerfJac(int GeomType, const DenseMatrix &J, DenseMatrix &PJ) const
static void GetRandomPoint(int GeomType, IntegrationPoint &ip)
Get a random point in the reference element specified by GeomType.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
static const int J[NumEdges][2]
static const int FaceVert[NumFaces][MaxFaceVert]
RefinedGeometry * Refine(int Geom, int Times, int ETimes=1)
Data type dense matrix using column-major storage.
static const double Volume[NumGeom]
static const int I[NumVert]
static const int NumEdges[NumGeom]
const IntegrationRule * GetVertices(int GeomType)
Return an IntegrationRule consisting of all vertices of the given Geometry::Type, GeomType...
const double * GetPoints(const int p, const int type)
Get the coordinates of the points of the given Quadrature1D type.
static const int NumFaces[NumGeom]
static const int InvOrient[NumOrient]
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
static const int Edges[NumEdges][2]
static const int Dimension[NumGeom]
const IntegrationRule * RefineInterior(int Geom, int Times)
static const int FaceTypes[NumFaces]
static const int NumVerts[NumGeom]
static const int Edges[NumEdges][2]
GeometryRefiner GlobGeometryRefiner
Class for linear FE on tetrahedron.
static const int NumBdrArray[NumGeom]
Class for linear FE on triangle.
static const int InvOrient[NumOrient]
static const int Orient[NumOrient][NumVert]
static const int Edges[NumEdges][2]
static const char * Name[NumGeom]
static const int I[NumVert]
void CalcInverse(const DenseMatrix &a, DenseMatrix &inva)
static const int InvOrient[NumOrient]
static const int Edges[NumEdges][2]
static bool ProjectPoint(int GeomType, const IntegrationPoint &beg, IntegrationPoint &end)
Project a point end, onto the given Geometry::Type, GeomType.
void GetPerfPointMat(int GeomType, DenseMatrix &pm)
void mfem_error(const char *msg)
static const int FaceVert[NumFaces][MaxFaceVert]
static const int J[NumEdges][2]
static const int I[NumVert]
static const int FaceVert[NumFaces][NumVert]
Class for integration point with weight.
void Diag(double c, int n)
Creates n x n diagonal matrix with diagonal elements c.
static const int FaceTypes[NumFaces]
static const int FaceVert[NumFaces][NumVert]
static const int Orient[NumOrient][NumVert]
static const int Edges[NumEdges][2]
static const int Orient[NumOrient][NumVert]
static bool CheckPoint(int GeomType, const IntegrationPoint &ip)
Check if the given point is inside the given reference element.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
static const int Orient[NumOrient][NumVert]
static const int J[NumEdges][2]