vector/matrix access, small optimization in CalcTetBadness

This commit is contained in:
Joachim Schoeberl 2009-06-06 19:33:32 +00:00
parent 35bc5819db
commit 611a53801d
34 changed files with 4191 additions and 4314 deletions

View File

@ -1,4 +1,4 @@
AC_INIT([netgen],[4.9.9],[],[]) AC_INIT([netgen],[4.9.10-dev],[],[])
AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])

View File

@ -587,8 +587,6 @@ Vec<D> SplineSeg3<D> :: GetTangent (const double t) const
template<int D> template<int D>
void SplineSeg3<D> :: GetCoeff (Vector & u) const void SplineSeg3<D> :: GetCoeff (Vector & u) const
{ {
double t;
int i;
Point<D> p; Point<D> p;
DenseMatrix a(6, 6); DenseMatrix a(6, 6);
DenseMatrix ata(6, 6); DenseMatrix ata(6, 6);
@ -598,23 +596,23 @@ void SplineSeg3<D> :: GetCoeff (Vector & u) const
// ata.SetSymmetric(1); // ata.SetSymmetric(1);
t = 0; double t = 0;
for (i = 1; i <= 5; i++, t += 0.25) for (int i = 0; i < 5; i++, t += 0.25)
{ {
p = GetPoint (t); p = GetPoint (t);
a.Elem(i, 1) = p(0) * p(0); a(i, 0) = p(0) * p(0);
a.Elem(i, 2) = p(1) * p(1); a(i, 1) = p(1) * p(1);
a.Elem(i, 3) = p(0) * p(1); a(i, 2) = p(0) * p(1);
a.Elem(i, 4) = p(0); a(i, 3) = p(0);
a.Elem(i, 5) = p(1); a(i, 4) = p(1);
a.Elem(i, 6) = 1; a(i, 5) = 1;
} }
a.Elem(6, 1) = 1; a(5, 0) = 1;
CalcAtA (a, ata); CalcAtA (a, ata);
u = 0; u = 0;
u.Elem(6) = 1; u(5) = 1;
a.MultTrans (u, f); a.MultTrans (u, f);
ata.Solve (f, u); ata.Solve (f, u);
} }

View File

@ -23,12 +23,12 @@ IntersectTriangleLine (const Point<3> ** tri, const Point<3> ** line)
<< "tri = " << *tri[0] << ", " << *tri[1] << ", " << *tri[2] << endl << "tri = " << *tri[0] << ", " << *tri[1] << ", " << *tri[2] << endl
<< "line = " << *line[0] << ", " << *line[1] << endl; << "line = " << *line[0] << ", " << *line[1] << endl;
*/ */
for (i = 1; i <= 3; i++) for (i = 0; i < 3; i++)
{ {
a.Elem(i, 1) = -vl.X(i); a(i, 0) = -vl.X(i+1);
a.Elem(i, 2) = vt1.X(i); a(i, 1) = vt1.X(i+1);
a.Elem(i, 3) = vt2.X(i); a(i, 2) = vt2.X(i+1);
rs.Elem(i) = vrs.X(i); rs(i) = vrs.X(i+1);
} }
double det = a.Det(); double det = a.Det();
@ -70,12 +70,12 @@ IntersectTriangleLine (const Point<3> ** tri, const Point<3> ** line)
double eps = 1e-6; double eps = 1e-6;
if ( if (
(lami.Get(1) >= -eps && lami.Get(1) <= 1+eps && (lami(0) >= -eps && lami(0) <= 1+eps &&
lami.Get(2) >= -eps && lami.Get(3) >= -eps && lami(1) >= -eps && lami(2) >= -eps &&
lami.Get(2) + lami.Get(3) <= 1+eps) && ! lami(1) + lami(2) <= 1+eps) && !
(lami.Get(1) >= eps && lami.Get(1) <= 1-eps && (lami(0) >= eps && lami(0) <= 1-eps &&
lami.Get(2) >= eps && lami.Get(3) >= eps && lami(1) >= eps && lami(2) >= eps &&
lami.Get(2) + lami.Get(3) <= 1-eps) ) lami(1) + lami(2) <= 1-eps) )
{ {
@ -97,8 +97,8 @@ IntersectTriangleLine (const Point<3> ** tri, const Point<3> ** line)
} }
if (lami.Get(1) >= 0 && lami.Get(1) <= 1 && if (lami(0) >= 0 && lami(0) <= 1 &&
lami.Get(2) >= 0 && lami.Get(3) >= 0 && lami.Get(2) + lami.Get(3) <= 1) lami(1) >= 0 && lami(2) >= 0 && lami(1) + lami(2) <= 1)
{ {
return 1; return 1;
@ -860,12 +860,12 @@ int CalcTriangleCenter (const Point3d ** pts, Point3d & c)
Vec3d v1(*pts[0], *pts[1]); Vec3d v1(*pts[0], *pts[1]);
Vec3d v2(*pts[0], *pts[2]); Vec3d v2(*pts[0], *pts[2]);
rs.Elem(1) = v1 * v1; rs(0) = v1 * v1;
rs.Elem(2) = v2 * v2; rs(1) = v2 * v2;
a.Elem(1,1) = 2 * rs.Get(1); a(0,0) = 2 * rs(0);
a.Elem(1,2) = a.Elem(2,1) = 2 * (v1 * v2); a(0,1) = a(1,0) = 2 * (v1 * v2);
a.Elem(2,2) = 2 * rs.Get(2); a(1,1) = 2 * rs(1);
if (fabs (a.Det()) <= 1e-12 * h * h) if (fabs (a.Det()) <= 1e-12 * h * h)
{ {
@ -877,8 +877,8 @@ int CalcTriangleCenter (const Point3d ** pts, Point3d & c)
inva.Mult (rs, sol); inva.Mult (rs, sol);
c = *pts[0]; c = *pts[0];
v1 *= sol.Get(1); v1 *= sol(0);
v2 *= sol.Get(2); v2 *= sol(1);
c += v1; c += v1;
c += v2; c += v2;

View File

@ -90,21 +90,21 @@ void Transformation3d :: CalcInverse (Transformation3d & inv) const
static Vector b(3), sol(3); static Vector b(3), sol(3);
int i, j; int i, j;
for (i = 1; i <= 3; i++) for (int i = 0; i < 3; i++)
{ {
b.Elem(i) = offset[i-1]; b(i) = offset[i];
for (j = 1; j <= 3; j++) for (j = 0; j < 3; j++)
a.Elem(i, j) = lin[i-1][j-1]; a(i, j) = lin[i][j];
} }
::netgen::CalcInverse (a, inva); ::netgen::CalcInverse (a, inva);
inva.Mult (b, sol); inva.Mult (b, sol);
for (i = 1; i <= 3; i++) for (int i = 0; i < 3; i++)
{ {
inv.offset[i-1] = -sol.Get(i); inv.offset[i] = -sol(i);
for (j = 1; j <= 3; j++) for (j = 0; j < 3; j++)
inv.lin[i-1][j-1] = inva.Elem(i, j); inv.lin[i][j] = inva(i, j);
} }
} }

View File

@ -2,6 +2,8 @@ noinst_HEADERS = densemat.hpp linalg.hpp polynomial.hpp vector.hpp opti.hpp
AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include
METASOURCES = AUTO METASOURCES = AUTO
noinst_LTLIBRARIES = libla.la noinst_LTLIBRARIES = libla.la
libla_la_SOURCES = densemat.cpp polynomial.cpp vector.cpp bfgs.cpp linopt.cpp linsearch.cpp libla_la_SOURCES = densemat.cpp polynomial.cpp bfgs.cpp linopt.cpp linsearch.cpp
# vector.cpp
libla_la_LDFLAGS = -rdynamic libla_la_LDFLAGS = -rdynamic

View File

@ -1,9 +1,9 @@
/***************************************************************************/ /***************************************************************************/
/* */ /* */
/* Vorlesung Optimierung I, Gfrerer, WS94/95 */ /* Vorlesung Optimierung I, Gfrerer, WS94/95 */
/* BFGS-Verfahren zur Lösung freier nichtlinearer Optimierungsprobleme */ /* BFGS-Verfahren zur Lösung freier nichtlinearer Optimierungsprobleme */
/* */ /* */
/* Programmautor: Joachim Schöberl */ /* Programmautor: Joachim Schöberl */
/* Matrikelnummer: 9155284 */ /* Matrikelnummer: 9155284 */
/* */ /* */
/***************************************************************************/ /***************************************************************************/
@ -25,37 +25,36 @@ void Cholesky (const DenseMatrix & a,
double x; double x;
int i, j, k;
int n = a.Height(); int n = a.Height();
// (*testout) << "a = " << a << endl; // (*testout) << "a = " << a << endl;
l = a; l = a;
for (i = 1; i <= n; i++) for (int i = 1; i <= n; i++)
{ {
for (j = i; j <= n; j++) for (int j = i; j <= n; j++)
{ {
x = l.Get(i, j); x = l.Get(i, j);
for (k = 1; k < i; k++) for (int k = 1; k < i; k++)
x -= l.Get(i, k) * l.Get(j, k) * d.Get(k); x -= l.Get(i, k) * l.Get(j, k) * d(k-1);
if (i == j) if (i == j)
{ {
d.Elem(i) = x; d(i-1) = x;
} }
else else
{ {
l.Elem(j, i) = x / d.Get(k); l.Elem(j, i) = x / d(i-1);
} }
} }
} }
for (i = 1; i <= n; i++) for (int i = 1; i <= n; i++)
{ {
l.Elem(i, i) = 1; l.Elem(i, i) = 1;
for (j = i+1; j <= n; j++) for (int j = i+1; j <= n; j++)
l.Elem(i, j) = 0; l.Elem(i, j) = 0;
} }
@ -162,9 +161,7 @@ int LDLtUpdate (DenseMatrix & l, Vector & d, double a, const Vector & u)
// Rueckgabewert: 0 .. D bleibt positiv definit // Rueckgabewert: 0 .. D bleibt positiv definit
// 1 .. sonst // 1 .. sonst
int i, j, n; int n = l.Height();
n = l.Height();
Vector v(n); Vector v(n);
double t, told, xi; double t, told, xi;
@ -172,9 +169,9 @@ int LDLtUpdate (DenseMatrix & l, Vector & d, double a, const Vector & u)
told = 1; told = 1;
v = u; v = u;
for (j = 1; j <= n; j++) for (int j = 1; j <= n; j++)
{ {
t = told + a * sqr (v.Elem(j)) / d.Get(j); t = told + a * sqr (v(j-1)) / d(j-1);
if (t <= 0) if (t <= 0)
{ {
@ -182,14 +179,14 @@ int LDLtUpdate (DenseMatrix & l, Vector & d, double a, const Vector & u)
return 1; return 1;
} }
xi = a * v.Elem(j) / (d.Get(j) * t); xi = a * v(j-1) / (d(j-1) * t);
d.Elem(j) *= t / told; d(j-1) *= t / told;
for (i = j + 1; i <= n; i++) for (int i = j + 1; i <= n; i++)
{ {
v.Elem(i) -= v.Elem(j) * l.Elem(i, j); v(i-1) -= v(j-1) * l.Elem(i, j);
l.Elem(i, j) += xi * v.Elem(i); l.Elem(i, j) += xi * v(i-1);
} }
told = t; told = t;
@ -209,7 +206,7 @@ double BFGS (
{ {
int i, j, n = x.Size(); int n = x.Size();
long it; long it;
char a1crit, a3acrit; char a1crit, a3acrit;
@ -233,14 +230,14 @@ double BFGS (
int ifail; // o: 0 .. Erfolg int ifail; // o: 0 .. Erfolg
// -1 .. Unterschreitung von fmin // -1 .. Unterschreitung von fmin
// 1 .. kein Erfolg bei Liniensuche // 1 .. kein Erfolg bei Liniensuche
// 2 .. Überschreitung von itmax // 2 .. Überschreitung von itmax
typx = par.typx; typx = par.typx;
typf = par.typf; typf = par.typf;
l = 0; l = 0;
for (i = 1; i <= n; i++) for (int i = 1; i <= n; i++)
l.Elem(i, i) = 1; l.Elem(i, i) = 1;
f = fun.FuncGrad (x, g); f = fun.FuncGrad (x, g);
@ -255,10 +252,10 @@ double BFGS (
if (it % (5 * n) == 0) if (it % (5 * n) == 0)
{ {
for (i = 1; i <= n; i++) for (int i = 1; i <= n; i++)
d.Elem(i) = typf/ sqr (typx.Get(i)); // 1; d(i-1) = typf/ sqr (typx(i-1)); // 1;
for (i = 2; i <= n; i++) for (int i = 2; i <= n; i++)
for (j = 1; j < i; j++) for (int j = 1; j < i; j++)
l.Elem(i, j) = 0; l.Elem(i, j) = 0;
/* /*
@ -357,8 +354,8 @@ double BFGS (
hd = eps * max2 (typf, fabs (f)); hd = eps * max2 (typf, fabs (f));
a1crit = 1; a1crit = 1;
for (i = 1; i <= n; i++) for (int i = 1; i <= n; i++)
if ( fabs (g.Elem(i)) * max2 (typx.Elem(i), fabs (x.Elem(i))) > hd) if ( fabs (g(i-1)) * max2 (typx(i-1), fabs (x(i-1))) > hd)
a1crit = 0; a1crit = 0;

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
#define FILE_DENSEMAT #define FILE_DENSEMAT
/**************************************************************************/ /**************************************************************************/
/* File: densemat.hh */ /* File: densemat.hpp */
/* Author: Joachim Schoeberl */ /* Author: Joachim Schoeberl */
/* Date: 01. Oct. 94 */ /* Date: 01. Oct. 94 */
/**************************************************************************/ /**************************************************************************/
@ -12,11 +12,6 @@
*/ */
#include <assert.h>
class DenseMatrix class DenseMatrix
{ {
protected: protected:
@ -67,12 +62,8 @@ public:
#ifdef DEBUG #ifdef DEBUG
if (prod.Size() != height) if (prod.Size() != height)
{ {
cerr << "Mult: wrong vector size " << endl; (*myerr) << "Mult: wrong vector size " << endl;
assert (1);
// prod.SetSize (height);
} }
if (!height) if (!height)
{ {
cout << "DenseMatrix::Mult height = 0" << endl; cout << "DenseMatrix::Mult height = 0" << endl;
@ -94,13 +85,13 @@ public:
#endif #endif
{ {
mp = data; mp = data;
dp = &prod.Elem(1); dp = &prod(0);
for (int i = 1; i <= height; i++) for (int i = 0; i < height; i++)
{ {
sum = 0; sum = 0;
sp = &v.Get(1); sp = &v(0);
for (int j = 1; j <= width; j++) for (int j = 0; j < width; j++)
{ {
// sum += Get(i,j) * v.Get(j); // sum += Get(i,j) * v.Get(j);
sum += *mp * *sp; sum += *mp * *sp;

View File

@ -10,7 +10,6 @@
/* /*
Data types for basic linear algebra Data types for basic linear algebra
more data types are found in linalgl.hpp
The basic concepts include the data types The basic concepts include the data types

View File

@ -37,9 +37,9 @@ void LinearOptimize (const DenseMatrix & a, const Vector & b,
m.Elem(3, j) = a.Get(i3, j); m.Elem(3, j) = a.Get(i3, j);
} }
rs.Elem(1) = b.Get(i1); rs(0) = b(i1-1);
rs.Elem(2) = b.Get(i2); rs(1) = b(i2-1);
rs.Elem(3) = b.Get(i3); rs(2) = b(i3-1);
if (fabs (m.Det()) < 1e-12) continue; if (fabs (m.Det()) < 1e-12) continue;
@ -59,9 +59,9 @@ void LinearOptimize (const DenseMatrix & a, const Vector & b,
*/ */
double rmin = res.Elem(1); double rmin = res(0);
for (int hi = 2; hi <= res.Size(); hi++) for (int hi = 1; hi < res.Size(); hi++)
if (res.Elem(hi) < rmin) rmin = res.Elem(hi); if (res(hi) < rmin) rmin = res(hi);
if ( (f < fmin) && rmin >= -1e-8) if ( (f < fmin) && rmin >= -1e-8)
{ {

View File

@ -2,7 +2,7 @@
/* */ /* */
/* Problem: Liniensuche */ /* Problem: Liniensuche */
/* */ /* */
/* Programmautor: Joachim Schöberl */ /* Programmautor: Joachim Schöberl */
/* Matrikelnummer: 9155284 */ /* Matrikelnummer: 9155284 */
/* */ /* */
/* Algorithmus nach: */ /* Algorithmus nach: */
@ -98,36 +98,36 @@ void MinFunction :: ApproximateHesse (const Vector & x,
double eps = 1e-6; double eps = 1e-6;
double f, f11, f12, f21, f22; double f, f11, f12, f21, f22;
for (i = 1; i <= n; i++) for (i = 0; i < n; i++)
{ {
for (j = 1; j < i; j++) for (j = 0; j < i; j++)
{ {
hx = x; hx = x;
hx.Elem(i) = x.Get(i) + eps; hx(i) = x(i) + eps;
hx.Elem(j) = x.Get(j) + eps; hx(j) = x(j) + eps;
f11 = Func(hx); f11 = Func(hx);
hx.Elem(i) = x.Get(i) + eps; hx(i) = x(i) + eps;
hx.Elem(j) = x.Get(j) - eps; hx(j) = x(j) - eps;
f12 = Func(hx); f12 = Func(hx);
hx.Elem(i) = x.Get(i) - eps; hx(i) = x(i) - eps;
hx.Elem(j) = x.Get(j) + eps; hx(j) = x(j) + eps;
f21 = Func(hx); f21 = Func(hx);
hx.Elem(i) = x.Get(i) - eps; hx(i) = x(i) - eps;
hx.Elem(j) = x.Get(j) - eps; hx(j) = x(j) - eps;
f22 = Func(hx); f22 = Func(hx);
hesse.Elem(i, j) = hesse.Elem(j, i) = hesse(i, j) = hesse(j, i) =
(f11 + f22 - f12 - f21) / (2 * eps * eps); (f11 + f22 - f12 - f21) / (2 * eps * eps);
} }
hx = x; hx = x;
f = Func(x); f = Func(x);
hx.Elem(i) = x.Get(i) + eps; hx(i) = x(i) + eps;
f11 = Func(hx); f11 = Func(hx);
hx.Elem(i) = x.Get(i) - eps; hx(i) = x(i) - eps;
f22 = Func(hx); f22 = Func(hx);
hesse.Elem(i, i) = (f11 + f22 - 2 * f) / (eps * eps); hesse(i, i) = (f11 + f22 - 2 * f) / (eps * eps);
} }
// (*testout) << "hesse = " << hesse << endl; // (*testout) << "hesse = " << hesse << endl;
} }

View File

@ -152,24 +152,6 @@ MaxUnitSquare ()
if (hv > maxv) maxv = hv; if (hv > maxv) maxv = hv;
return maxv; return maxv;
// (*testout) << "maxv = " << maxv << " =~= ";
/*
double x, y;
maxv = -1e8;
double val;
for (x = 0; x <= 1.01; x += 0.1)
for (y = 0; y <= 1.01; y += 0.1)
{
val = Value (x, y);
if (val > maxv)
maxv = val;
}
// (*testout) << maxv << endl;
return maxv;
*/
}; };

File diff suppressed because it is too large Load Diff

View File

@ -35,9 +35,9 @@ public:
double & operator() (int i) { return data[i]; } double & operator() (int i) { return data[i]; }
const double & operator() (int i) const { return data[i]; } const double & operator() (int i) const { return data[i]; }
double & Elem (int i) { return data[i-1]; } // double & Elem (int i) { return data[i-1]; }
const double & Get (int i) const { return data[i-1]; } // const double & Get (int i) const { return data[i-1]; }
void Set (int i, double val) { data[i-1] = val; } // void Set (int i, double val) { data[i-1] = val; }
FlatVector & operator*= (double scal) FlatVector & operator*= (double scal)
{ {
@ -92,7 +92,7 @@ public:
{ delete [] data; } { delete [] data; }
Vector & operator= (const FlatVector & v) Vector & operator= (const FlatVector & v)
{ memcpy (data, &v.Get(1), s*sizeof(double)); return *this; } { memcpy (data, &v(0), s*sizeof(double)); return *this; }
Vector & operator= (double scal) Vector & operator= (double scal)
{ {

View File

@ -793,25 +793,25 @@ bool AdFront3 :: Inside (const Point<3> & p) const
v1 = p2 - p1; v1 = p2 - p1;
v2 = p3 - p1; v2 = p3 - p1;
a.Elem(1, 1) = v1.X(); a(0, 0) = v1.X();
a.Elem(2, 1) = v1.Y(); a(1, 0) = v1.Y();
a.Elem(3, 1) = v1.Z(); a(2, 0) = v1.Z();
a.Elem(1, 2) = v2.X(); a(0, 1) = v2.X();
a.Elem(2, 2) = v2.Y(); a(1, 1) = v2.Y();
a.Elem(3, 2) = v2.Z(); a(2, 1) = v2.Z();
a.Elem(1, 3) = -n.X(); a(0, 2) = -n.X();
a.Elem(2, 3) = -n.Y(); a(1, 2) = -n.Y();
a.Elem(3, 3) = -n.Z(); a(2, 2) = -n.Z();
b.Elem(1) = p(0) - p1(0); b(0) = p(0) - p1(0);
b.Elem(2) = p(1) - p1(1); b(1) = p(1) - p1(1);
b.Elem(3) = p(2) - p1(2); b(2) = p(2) - p1(2);
CalcInverse (a, ainv); CalcInverse (a, ainv);
ainv.Mult (b, u); ainv.Mult (b, u);
if (u.Elem(1) >= 0 && u.Elem(2) >= 0 && u.Elem(1)+u.Elem(2) <= 1 && if (u(0) >= 0 && u(1) >= 0 && u(0)+u(1) <= 1 &&
u.Elem(3) > 0) u(2) > 0)
{ {
cnt++; cnt++;
} }

View File

@ -1091,26 +1091,23 @@ namespace netgen
T_MPRISMS & mprisms, T_MPRISMS & mprisms,
const Mesh & mesh) const Mesh & mesh)
{ {
int i, j, k;
int step;
int marked = 0; int marked = 0;
int np = mesh.GetNP(); int np = mesh.GetNP();
Vector hv(np); Vector hv(np);
for (i = 1; i <= np; i++) for (int i = 0; i < np; i++)
hv.Elem(i) = mesh.GetH (mesh.Point(i)); hv(i) = mesh.GetH (mesh.Point(i+1));
double hfac = 1; double hfac = 1;
for (step = 1; step <= 2; step++) for (int step = 1; step <= 2; step++)
{ {
for (i = 1; i <= mtets.Size(); i++) for (int i = 1; i <= mtets.Size(); i++)
{ {
double h = 0; double h = 0;
for (j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
for (k = j+1; k < 4; k++) for (int k = j+1; k < 4; k++)
{ {
const Point<3> & p1 = mesh.Point (mtets.Get(i).pnums[j]); const Point<3> & p1 = mesh.Point (mtets.Get(i).pnums[j]);
const Point<3> & p2 = mesh.Point (mtets.Get(i).pnums[k]); const Point<3> & p2 = mesh.Point (mtets.Get(i).pnums[k]);
@ -1120,9 +1117,9 @@ namespace netgen
h = sqrt (h); h = sqrt (h);
double hshould = 1e10; double hshould = 1e10;
for (j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
double hi = hv.Get (mtets.Get(i).pnums[j]); double hi = hv (mtets.Get(i).pnums[j]-1);
if (hi < hshould) if (hi < hshould)
hshould = hi; hshould = hi;
} }
@ -1145,12 +1142,12 @@ namespace netgen
} }
} }
for (i = 1; i <= mprisms.Size(); i++) for (int i = 1; i <= mprisms.Size(); i++)
{ {
double h = 0; double h = 0;
for (j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
for (k = j+1; k < 3; k++) for (int k = j+1; k < 3; k++)
{ {
const Point<3> & p1 = mesh.Point (mprisms.Get(i).pnums[j]); const Point<3> & p1 = mesh.Point (mprisms.Get(i).pnums[j]);
const Point<3> & p2 = mesh.Point (mprisms.Get(i).pnums[k]); const Point<3> & p2 = mesh.Point (mprisms.Get(i).pnums[k]);
@ -1160,9 +1157,9 @@ namespace netgen
h = sqrt (h); h = sqrt (h);
double hshould = 1e10; double hshould = 1e10;
for (j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
{ {
double hi = hv.Get (mprisms.Get(i).pnums[j]); double hi = hv (mprisms.Get(i).pnums[j]-1);
if (hi < hshould) if (hi < hshould)
hshould = hi; hshould = hi;
} }

View File

@ -117,7 +117,7 @@ namespace netgen
} }
void HPRefElement :: SetType( HPREF_ELEMENT_TYPE t) void HPRefElement :: SetType (HPREF_ELEMENT_TYPE t)
{ {
type = t; type = t;
switch(type) switch(type)
@ -129,11 +129,17 @@ namespace netgen
case HP_PRISM: np=6; break; case HP_PRISM: np=6; break;
case HP_PYRAMID: np=5; break; case HP_PYRAMID: np=5; break;
case HP_HEX: np=8; break; case HP_HEX: np=8; break;
default:
cerr << "HPRefElement: illegal type " << type << endl;
throw NgException ("HPRefElement::SetType: illegal type");
} }
for(int k=0;k<8;k++)
for(int k = 0; k < 8;k++)
{ {
pnums[k]=0; pnums[k]=0;
for(int l=0;l<3;l++) param[k][l]=0.; for(int l = 0; l < 3; l++)
param[k][l]=0.;
} }
} }
@ -587,6 +593,11 @@ namespace netgen
case PYRAMID: case PYRAMID:
hpel.type = HP_PYRAMID; hpel.type = HP_PYRAMID;
break; break;
default:
cerr << "HPRefElement: illegal elementtype (1) " << mesh[i].GetType() << endl;
throw NgException ("HPRefElement: illegal elementtype (1)");
} }
elements.Append(hpel); elements.Append(hpel);
} }
@ -700,7 +711,7 @@ namespace netgen
HPRef_Struct * hprs = Get_HPRef_Struct (el.type); HPRef_Struct * hprs = Get_HPRef_Struct (el.type);
int newlevel = el.levelx + 1; int newlevel = el.levelx + 1;
int oldnp(0); int oldnp = 0;
switch (hprs->geom) switch (hprs->geom)
{ {
case HP_SEGM: oldnp = 2; break; case HP_SEGM: oldnp = 2; break;
@ -710,6 +721,10 @@ namespace netgen
case HP_PYRAMID: oldnp = 5; break; case HP_PYRAMID: oldnp = 5; break;
case HP_PRISM: oldnp = 6; break; case HP_PRISM: oldnp = 6; break;
case HP_HEX: oldnp = 8; break; case HP_HEX: oldnp = 8; break;
default:
cerr << "HPRefElement: illegal type (3) " << hprs->geom << endl;
throw NgException ("HPRefElement::SetType: illegal type (3)");
} }
@ -830,6 +845,8 @@ namespace netgen
case HP_PRISM: newel.np=6; break; case HP_PRISM: newel.np=6; break;
case HP_TET: newel.np=4; break; case HP_TET: newel.np=4; break;
case HP_PYRAMID: newel.np=5; break; case HP_PYRAMID: newel.np=5; break;
default:
throw NgException (string("hprefinement.cpp: illegal type"));
} }
for (int k = 0; k < newel.np; k++) for (int k = 0; k < newel.np; k++)
@ -915,6 +932,11 @@ namespace netgen
case HP_PRISM: newel.np=6; break; case HP_PRISM: newel.np=6; break;
case HP_TET: newel.np=4; break; case HP_TET: newel.np=4; break;
case HP_PYRAMID: newel.np=5; break; case HP_PYRAMID: newel.np=5; break;
default:
cerr << "HPRefElement: illegal type (4) " << hprsnew->geom << endl;
throw NgException ("HPRefElement: illegal type (4)");
} }
newel.type = hprs->neweltypes[j]; newel.type = hprs->neweltypes[j];
for (int k = 0; k < 8; k++) for (int k = 0; k < 8; k++)
@ -1477,6 +1499,12 @@ namespace netgen
ord_dir[2] = 2; ord_dir[2] = 2;
ned = 8; ned = 8;
break; break;
default:
cerr << "HPRefElement: illegal elementtype (2) " << mesh[i].GetType() << endl;
throw NgException ("HPRefElement: illegal elementtype (2)");
} }
for (int j=0;j<ned;j++) for (int j=0;j<ned;j++)

View File

@ -482,18 +482,18 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh,
pnew = Center (p1, p2); pnew = Center (p1, p2);
Vector px(3); Vector px(3);
px.Elem(1) = pnew.X(); px(0) = pnew.X();
px.Elem(2) = pnew.Y(); px(1) = pnew.Y();
px.Elem(3) = pnew.Z(); px(2) = pnew.Z();
if (elerrs[ei] > 0.1 * badmax) if (elerrs[ei] > 0.1 * badmax)
BFGS (px, pf, par); BFGS (px, pf, par);
bad2 = pf.Func (px); bad2 = pf.Func (px);
pnew.X() = px.Get(1); pnew.X() = px(0);
pnew.Y() = px.Get(2); pnew.Y() = px(1);
pnew.Z() = px.Get(3); pnew.Z() = px(2);
int hpinew = mesh.AddPoint (pnew); int hpinew = mesh.AddPoint (pnew);
@ -584,11 +584,6 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh,
void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
const BitArray * working_elements) const BitArray * working_elements)
{ {
int j, k, l;
ElementIndex ei;
SurfaceElementIndex sei;
PointIndex pi1(0), pi2(0), pi3(0), pi4(0), pi5(0), pi6(0); PointIndex pi1(0), pi2(0), pi3(0), pi4(0), pi5(0), pi6(0);
int cnt = 0; int cnt = 0;
@ -600,7 +595,6 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
int np = mesh.GetNP(); int np = mesh.GetNP();
int ne = mesh.GetNE(); int ne = mesh.GetNE();
//int nse = mesh.GetNSE();
// contains at least all elements at node // contains at least all elements at node
TABLE<ElementIndex,PointIndex::BASE> elementsonnode(np); TABLE<ElementIndex,PointIndex::BASE> elementsonnode(np);
@ -614,16 +608,6 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
multithread.task = "Swap Improve"; multithread.task = "Swap Improve";
// mesh.CalcSurfacesOfNode (); // mesh.CalcSurfacesOfNode ();
/*
for (i = 1; i <= GetNE(); i++)
if (volelements.Get(i).PNum(1))
if (!LegalTet (volelements.Get(i)))
{
cout << "detected illegal tet, 1" << endl;
(*testout) << "detected illegal tet1: " << i << endl;
}
*/
INDEX_3_HASHTABLE<int> faces(mesh.GetNOpenElements()/3 + 2); INDEX_3_HASHTABLE<int> faces(mesh.GetNOpenElements()/3 + 2);
if (goal == OPT_CONFORM) if (goal == OPT_CONFORM)
@ -645,32 +629,15 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
} }
// find elements on node // find elements on node
for (ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
for (j = 0; j < mesh[ei].GetNP(); j++) for (int j = 0; j < mesh[ei].GetNP(); j++)
elementsonnode.Add (mesh[ei][j], ei); elementsonnode.Add (mesh[ei][j], ei);
/*
BitArray illegaltet(GetNE());
MarkIllegalElements();
if (goal == OPT_QUALITY || goal == OPT_LEGAL)
{
int cntill = 0;
for (i = 1; i <= GetNE(); i++)
{
// if (!LegalTet (volelements.Get(i)))
if (VolumeElement(i).flags.illegal)
{
cntill++;
illegaltet.Set (i);
}
}
// (*mycout) << cntill << " illegal tets" << endl;
}
*/
INDEX_2_HASHTABLE<int> edgeused(2 * ne + 5); // INDEX_2_HASHTABLE<int> edgeused(2 * ne + 5);
INDEX_2_CLOSED_HASHTABLE<int> edgeused(12 * ne + 5);
for (ei = 0; ei < ne; ei++)
for (ElementIndex ei = 0; ei < ne; ei++)
{ {
if (multithread.terminate) if (multithread.terminate)
break; break;
@ -695,7 +662,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
// int onlybedges = 1; // int onlybedges = 1;
for (j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
{ {
// loop over edges // loop over edges
@ -726,7 +693,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
edgeused.Set (i2, 1); edgeused.Set (i2, 1);
hasbothpoints.SetSize (0); hasbothpoints.SetSize (0);
for (k = 0; k < elementsonnode[pi1].Size(); k++) for (int k = 0; k < elementsonnode[pi1].Size(); k++)
{ {
bool has1 = 0, has2 = 0; bool has1 = 0, has2 = 0;
ElementIndex elnr = elementsonnode[pi1][k]; ElementIndex elnr = elementsonnode[pi1][k];
@ -734,7 +701,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
if (elem.IsDeleted()) continue; if (elem.IsDeleted()) continue;
for (l = 0; l < elem.GetNP(); l++) for (int l = 0; l < elem.GetNP(); l++)
{ {
if (elem[l] == pi1) has1 = 1; if (elem[l] == pi1) has1 = 1;
if (elem[l] == pi2) has2 = 1; if (elem[l] == pi2) has2 = 1;
@ -742,7 +709,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
if (has1 && has2) if (has1 && has2)
{ // only once { // only once
for (l = 0; l < hasbothpoints.Size(); l++) for (int l = 0; l < hasbothpoints.Size(); l++)
if (hasbothpoints[l] == elnr) if (hasbothpoints[l] == elnr)
has1 = 0; has1 = 0;
@ -752,7 +719,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
} }
bool puretet = 1; bool puretet = 1;
for (k = 0; k < hasbothpoints.Size(); k++) for (int k = 0; k < hasbothpoints.Size(); k++)
if (mesh[hasbothpoints[k]].GetType () != TET) if (mesh[hasbothpoints[k]].GetType () != TET)
puretet = 0; puretet = 0;
if (!puretet) if (!puretet)
@ -763,7 +730,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
if ( nsuround == 3 ) if ( nsuround == 3 )
{ {
Element & elem = mesh[hasbothpoints[0]]; Element & elem = mesh[hasbothpoints[0]];
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] != pi1 && elem[l] != pi2) if (elem[l] != pi1 && elem[l] != pi2)
{ {
pi4 = pi3; pi4 = pi3;
@ -784,16 +751,16 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
} }
pi5 = 0; pi5 = 0;
for (k = 1; k < 3; k++) for (int k = 1; k < 3; k++)
{ {
const Element & elemk = mesh[hasbothpoints[k]]; const Element & elemk = mesh[hasbothpoints[k]];
bool has1 = 0; bool has1 = 0;
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elemk[l] == pi4) if (elemk[l] == pi4)
has1 = 1; has1 = 1;
if (has1) if (has1)
{ {
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elemk[l] != pi1 && elemk[l] != pi2 && elemk[l] != pi4) if (elemk[l] != pi1 && elemk[l] != pi2 && elemk[l] != pi4)
pi5 = elemk[l]; pi5 = elemk[l];
} }
@ -905,21 +872,20 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
el22.flags.illegal_valid = 0; el22.flags.illegal_valid = 0;
mesh[hasbothpoints[0]] = el21; mesh[hasbothpoints[0]] = el21;
mesh[hasbothpoints[1]] = el22; mesh[hasbothpoints[1]] = el22;
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
mesh[hasbothpoints[2]][l] = 0; mesh[hasbothpoints[2]][l] = 0;
mesh[hasbothpoints[2]].Delete(); mesh[hasbothpoints[2]].Delete();
for (k = 0; k < 2; k++) for (int k = 0; k < 2; k++)
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]); elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]);
} }
} }
if (nsuround == 4) if (nsuround == 4)
{ {
const Element & elem1 = mesh[hasbothpoints[0]]; const Element & elem1 = mesh[hasbothpoints[0]];
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem1[l] != pi1 && elem1[l] != pi2) if (elem1[l] != pi1 && elem1[l] != pi2)
{ {
pi4 = pi3; pi4 = pi3;
@ -938,32 +904,32 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
} }
pi5 = 0; pi5 = 0;
for (k = 1; k < 4; k++) for (int k = 1; k < 4; k++)
{ {
const Element & elem = mesh[hasbothpoints[k]]; const Element & elem = mesh[hasbothpoints[k]];
bool has1 = 0; bool has1 = 0;
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] == pi4) if (elem[l] == pi4)
has1 = 1; has1 = 1;
if (has1) if (has1)
{ {
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] != pi1 && elem[l] != pi2 && elem[l] != pi4) if (elem[l] != pi1 && elem[l] != pi2 && elem[l] != pi4)
pi5 = elem[l]; pi5 = elem[l];
} }
} }
pi6 = 0; pi6 = 0;
for (k = 1; k < 4; k++) for (int k = 1; k < 4; k++)
{ {
const Element & elem = mesh[hasbothpoints[k]]; const Element & elem = mesh[hasbothpoints[k]];
bool has1 = 0; bool has1 = 0;
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] == pi3) if (elem[l] == pi3)
has1 = 1; has1 = 1;
if (has1) if (has1)
{ {
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] != pi1 && elem[l] != pi2 && elem[l] != pi3) if (elem[l] != pi1 && elem[l] != pi2 && elem[l] != pi3)
pi6 = elem[l]; pi6 = elem[l];
} }
@ -1183,8 +1149,8 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
mesh[hasbothpoints[2]] = el3; mesh[hasbothpoints[2]] = el3;
mesh[hasbothpoints[3]] = el4; mesh[hasbothpoints[3]] = el4;
for (k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]); elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]);
} }
else if (swap3) else if (swap3)
@ -1216,8 +1182,8 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
mesh[hasbothpoints[3]] = el4b; mesh[hasbothpoints[3]] = el4b;
for (k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]); elementsonnode.Add (mesh[hasbothpoints[k]][l], hasbothpoints[k]);
} }
} }
@ -1231,7 +1197,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
Element & elem = mesh[hasbothpoints[0]]; Element & elem = mesh[hasbothpoints[0]];
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
if (elem[l] != pi1 && elem[l] != pi2) if (elem[l] != pi1 && elem[l] != pi2)
{ {
pi4 = pi3; pi4 = pi3;
@ -1259,12 +1225,12 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
tetused = 0; tetused = 0;
tetused[0] = 1; tetused[0] = 1;
for (l = 2; l < nsuround; l++) for (int l = 2; l < nsuround; l++)
{ {
int oldpi = suroundpts[l-1]; int oldpi = suroundpts[l-1];
int newpi = 0; int newpi = 0;
for (k = 0; k < nsuround && !newpi; k++) for (int k = 0; k < nsuround && !newpi; k++)
if (!tetused[k]) if (!tetused[k])
{ {
const Element & nel = mesh[hasbothpoints[k]]; const Element & nel = mesh[hasbothpoints[k]];
@ -1284,7 +1250,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
bad1 = 0; bad1 = 0;
for (k = 0; k < nsuround; k++) for (int k = 0; k < nsuround; k++)
{ {
hel[0] = pi1; hel[0] = pi1;
hel[1] = pi2; hel[1] = pi2;
@ -1303,11 +1269,11 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
int confedge = -1; int confedge = -1;
double badopt = bad1; double badopt = bad1;
for (l = 0; l < nsuround; l++) for (int l = 0; l < nsuround; l++)
{ {
bad2 = 0; bad2 = 0;
for (k = l+1; k <= nsuround + l - 2; k++) for (int k = l+1; k <= nsuround + l - 2; k++)
{ {
hel[0] = suroundpts[l]; hel[0] = suroundpts[l];
hel[1] = suroundpts[k % nsuround]; hel[1] = suroundpts[k % nsuround];
@ -1344,7 +1310,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
(bad2 <= 100 * bad1 && bad2 <= 1e18) || (bad2 <= 100 * bad1 && bad2 <= 1e18) ||
(bad2 <= 1e8); (bad2 <= 1e8);
for (k = l+1; k <= nsuround + l - 2; k++) for (int k = l+1; k <= nsuround + l - 2; k++)
{ {
INDEX_3 hi3(suroundpts[l], INDEX_3 hi3(suroundpts[l],
suroundpts[k % nsuround], suroundpts[k % nsuround],
@ -1359,7 +1325,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
} }
} }
for (k = l+2; k <= nsuround+l-2; k++) for (int k = l+2; k <= nsuround+l-2; k++)
{ {
if (mesh.BoundaryEdge (suroundpts[l], if (mesh.BoundaryEdge (suroundpts[l],
suroundpts[k % nsuround])) suroundpts[k % nsuround]))
@ -1385,7 +1351,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
// (*mycout) << nsuround << "->" << 2 * (nsuround-2) << " " << flush; // (*mycout) << nsuround << "->" << 2 * (nsuround-2) << " " << flush;
cnt++; cnt++;
for (k = bestl+1; k <= nsuround + bestl - 2; k++) for (int k = bestl+1; k <= nsuround + bestl - 2; k++)
{ {
int k1; int k1;
@ -1420,7 +1386,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
elementsonnode.Add (hel[k1], mesh.GetNE()-1); elementsonnode.Add (hel[k1], mesh.GetNE()-1);
} }
for (k = 0; k < nsuround; k++) for (int k = 0; k < nsuround; k++)
{ {
Element & rel = mesh[hasbothpoints[k]]; Element & rel = mesh[hasbothpoints[k]];
/* /*
@ -1513,8 +1479,6 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal,
} }
} }
ElementIndex ei;
SurfaceElementIndex sei;
PointIndex pi1, pi2, pi3, pi4, pi5, pi6; PointIndex pi1, pi2, pi3, pi4, pi5, pi6;
PointIndex pi1other, pi2other; PointIndex pi1other, pi2other;
@ -1548,11 +1512,11 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal,
// find elements on node // find elements on node
for (ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
for (int j = 0; j < mesh[ei].GetNP(); j++) for (int j = 0; j < mesh[ei].GetNP(); j++)
elementsonnode.Add (mesh[ei][j], ei); elementsonnode.Add (mesh[ei][j], ei);
for (sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
for(int j=0; j<mesh[sei].GetNP(); j++) for(int j=0; j<mesh[sei].GetNP(); j++)
{ {
surfaceelementsonnode.Add(mesh[sei][j], sei); surfaceelementsonnode.Add(mesh[sei][j], sei);
@ -1563,9 +1527,10 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal,
bool periodic; bool periodic;
int idnum(-1); int idnum(-1);
INDEX_2_HASHTABLE<int> edgeused(2 * ne + 5); // INDEX_2_HASHTABLE<int> edgeused(2 * ne + 5);
INDEX_2_CLOSED_HASHTABLE<int> edgeused(12 * ne + 5);
for (ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {
if (multithread.terminate) if (multithread.terminate)
break; break;
@ -2354,18 +2319,12 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal,
*/ */
void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal) void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
{ {
int j, k, l;
ElementIndex ei, eli1, eli2, elnr;
SurfaceElementIndex sei;
PointIndex pi1(0), pi2(0), pi3(0), pi4(0), pi5(0); PointIndex pi1(0), pi2(0), pi3(0), pi4(0), pi5(0);
int cnt = 0;
Element el21(TET), el22(TET), el31(TET), el32(TET), el33(TET); Element el21(TET), el22(TET), el31(TET), el32(TET), el33(TET);
int cnt = 0;
double bad1, bad2; double bad1, bad2;
int np = mesh.GetNP(); int np = mesh.GetNP();
@ -2383,7 +2342,6 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
// TestOk(); // TestOk();
/* /*
CalcSurfacesOfNode (); CalcSurfacesOfNode ();
for (i = 1; i <= GetNE(); i++) for (i = 1; i <= GetNE(); i++)
@ -2404,15 +2362,15 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
// find elements on node // find elements on node
for (ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
for (j = 0; j < mesh[ei].GetNP(); j++) for (int j = 0; j < mesh[ei].GetNP(); j++)
elementsonnode.Add (mesh[ei][j], ei); elementsonnode.Add (mesh[ei][j], ei);
for (sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
for (j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
belementsonnode.Add (mesh[sei][j], sei); belementsonnode.Add (mesh[sei][j], sei);
for (eli1 = 0; eli1 < ne; eli1++) for (ElementIndex eli1 = 0; eli1 < ne; eli1++)
{ {
if (multithread.terminate) if (multithread.terminate)
break; break;
@ -2431,7 +2389,7 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
// cout << "eli = " << eli1 << endl; // cout << "eli = " << eli1 << endl;
// (*testout) << "swapimp2, eli = " << eli1 << "; el = " << mesh[eli1] << endl; // (*testout) << "swapimp2, eli = " << eli1 << "; el = " << mesh[eli1] << endl;
for (j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
// loop over faces // loop over faces
@ -2463,13 +2421,13 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
bool bface = 0; bool bface = 0;
for (k = 0; k < belementsonnode[pi1].Size(); k++) for (int k = 0; k < belementsonnode[pi1].Size(); k++)
{ {
const Element2d & bel = const Element2d & bel =
mesh[belementsonnode[pi1][k]]; mesh[belementsonnode[pi1][k]];
bool bface1 = 1; bool bface1 = 1;
for (l = 0; l < 3; l++) for (int l = 0; l < 3; l++)
if (bel[l] != pi1 && bel[l] != pi2 && bel[l] != pi3) if (bel[l] != pi1 && bel[l] != pi2 && bel[l] != pi3)
{ {
bface1 = 0; bface1 = 0;
@ -2487,9 +2445,9 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
FlatArray<ElementIndex> row = elementsonnode[pi1]; FlatArray<ElementIndex> row = elementsonnode[pi1];
for (k = 0; k < row.Size(); k++) for (int k = 0; k < row.Size(); k++)
{ {
eli2 = row[k]; ElementIndex eli2 = row[k];
// cout << "\rei1 = " << eli1 << ", pi1 = " << pi1 << ", k = " << k << ", ei2 = " << eli2 // cout << "\rei1 = " << eli1 << ", pi1 = " << pi1 << ", k = " << k << ", ei2 = " << eli2
// << ", getne = " << mesh.GetNE(); // << ", getne = " << mesh.GetNE();
@ -2502,7 +2460,7 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
continue; continue;
int comnodes=0; int comnodes=0;
for (l = 1; l <= 4; l++) for (int l = 1; l <= 4; l++)
if (elem2.PNum(l) == pi1 || elem2.PNum(l) == pi2 || if (elem2.PNum(l) == pi1 || elem2.PNum(l) == pi2 ||
elem2.PNum(l) == pi3) elem2.PNum(l) == pi3)
{ {
@ -2586,7 +2544,7 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal)
} }
*/ */
// cout << "neli = " << neli << endl; // cout << "neli = " << neli << endl;
for (l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
{ {
elementsonnode.Add (el31[l], eli1); elementsonnode.Add (el31[l], eli1);
elementsonnode.Add (el32[l], eli2); elementsonnode.Add (el32[l], eli2);

View File

@ -20,8 +20,18 @@ public:
extern double CalcBad (const Mesh::T_POINTS & points, const Element & elem, inline double
double h); CalcBad (const Mesh::T_POINTS & points, const Element & elem,
double h)
{
if (elem.GetType() == TET)
return CalcTetBadness (points[elem[0]], points[elem[1]],
points[elem[2]], points[elem[3]], h);
return 0;
}
extern double CalcTotalBad (const Mesh::T_POINTS & points, extern double CalcTotalBad (const Mesh::T_POINTS & points,
const Mesh::T_VOLELEMENTS & elements); const Mesh::T_VOLELEMENTS & elements);

View File

@ -202,7 +202,7 @@ namespace netgen
Vec3d v2 (p1, p3); Vec3d v2 (p1, p3);
Vec3d v3 (p1, p4); Vec3d v3 (p1, p4);
vol = -Determinant (v1, v2, v3) / 6; vol = Determinant (v1, v2, v3) * (-0.166666666666666);
ll1 = v1.Length2(); ll1 = v1.Length2();
ll2 = v2.Length2(); ll2 = v2.Length2();
@ -276,7 +276,7 @@ namespace netgen
Vec3d v5 (*pp2, *pp4); Vec3d v5 (*pp2, *pp4);
Vec3d v6 (*pp3, *pp4); Vec3d v6 (*pp3, *pp4);
vol = -Determinant (v1, v2, v3) / 6; vol = Determinant (v1, v2, v3) * (-0.166666666666666);
Vec3d gradvol; Vec3d gradvol;
Cross (v5, v4, gradvol); Cross (v5, v4, gradvol);
@ -344,10 +344,8 @@ namespace netgen
graderr += (1/(h*h) - h*h/(ll1*ll1)) * gradll1; graderr += (1/(h*h) - h*h/(ll1*ll1)) * gradll1;
graderr += (1/(h*h) - h*h/(ll2*ll2)) * gradll2; graderr += (1/(h*h) - h*h/(ll2*ll2)) * gradll2;
graderr += (1/(h*h) - h*h/(ll3*ll3)) * gradll3; graderr += (1/(h*h) - h*h/(ll3*ll3)) * gradll3;
cout << "?";
} }
double errpow; double errpow;
if (teterrpow == 2) if (teterrpow == 2)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -128,10 +128,10 @@ int netrule :: IsLineInFreeZone2 (const Point2d & p1, const Point2d & p2) const
{ {
int left, right, allleft, allright; int left, right, allleft, allright;
if (p1.X() > fzmaxx && p2.X() > fzmaxx || if ( (p1.X() > fzmaxx && p2.X() > fzmaxx) ||
p1.X() < fzminx && p2.X() < fzminx || (p1.X() < fzminx && p2.X() < fzminx) ||
p1.Y() > fzmaxy && p2.Y() > fzmaxy || (p1.Y() > fzmaxy && p2.Y() > fzmaxy) ||
p1.Y() < fzminy && p2.Y() < fzminy) return 0; (p1.Y() < fzminy && p2.Y() < fzminy) ) return 0;
for (int i = 1; i <= transfreezone.Size(); i++) for (int i = 1; i <= transfreezone.Size(); i++)
{ {

View File

@ -61,7 +61,7 @@ void vnetrule :: SetFreeZoneTransformation (const Vector & allp, int tolclass)
for (i = 1; i <= 3; i++) for (i = 1; i <= 3; i++)
{ {
for (j = 1; j <= np; j++) for (j = 1; j <= np; j++)
vp.Elem(j) = allp.Get(i+3*j-3); vp(j-1) = allp(i+3*j-3-1);
oldutofreezone->Mult (vp, vfp1); oldutofreezone->Mult (vp, vfp1);
oldutofreezonelimit->Mult (vp, vfp2); oldutofreezonelimit->Mult (vp, vfp2);
@ -70,7 +70,7 @@ void vnetrule :: SetFreeZoneTransformation (const Vector & allp, int tolclass)
vfp1.Add (lam2, vfp2); vfp1.Add (lam2, vfp2);
for (j = 1; j <= nfp; j++) for (j = 1; j <= nfp; j++)
transfreezone.Elem(j).X(i) = vfp1.Elem(j); transfreezone.Elem(j).X(i) = vfp1(j-1);
} }
// MARK(setfz2); // MARK(setfz2);
@ -709,7 +709,7 @@ int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2,
minit = 1000; minit = 1000;
fold = 1E10; fold = 1E10;
while (1) while (1)
{ {
@ -814,7 +814,7 @@ int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2,
if (it > minit) if (it > minit)
(*testout) << "act1,2,3 = " << act1 << act2 << act3 << endl; (*testout) << "act1,2,3 = " << act1 << act2 << act3 << endl;
if (act1 && act2 || act1 && act3 || act2 && act3) return 0; if ( (act1 && act2) || (act1 && act3) || (act2 && act3) ) return 0;
if (act1) if (act1)
{ {

View File

@ -706,13 +706,13 @@ void vnetrule :: LoadRule (istream & ist)
if (quality < 100) if (quality < 100)
{ {
for (i = 1; i <= 3; i++) for (int i = 1; i <= 3; i++)
{ {
for (j = 1; j <= points.Size(); j++) for (int j = 1; j <= points.Size(); j++)
vp.Elem(j) = points.Get(j).X(i); vp(j-1) = points.Get(j).X(i);
oldutofreezone->Mult(vp, vfp); oldutofreezone->Mult(vp, vfp);
for (j = 1; j <= freezone.Size(); j++) for (int j = 1; j <= freezone.Size(); j++)
freezone.Elem(j).X(i) = vfp.Get(j); freezone.Elem(j).X(i) = vfp(j-1);
} }
// for (i = 1; i <= freezone.Size(); i++) // for (i = 1; i <= freezone.Size(); i++)
// (*testout) << "freepoint: " << freezone.Get(i) << endl; // (*testout) << "freepoint: " << freezone.Get(i) << endl;

View File

@ -397,11 +397,11 @@ int Meshing2 ::ApplyRules (Array<Point2d> & lpoints,
{ {
oldu.SetSize (2 * rule->GetNOldP()); oldu.SetSize (2 * rule->GetNOldP());
for (i = 1; i <= rule->GetNOldP(); i++) for (int i = 1; i <= rule->GetNOldP(); i++)
{ {
Vec2d ui(rule->GetPoint(i), lpoints.Get(pmap.Get(i))); Vec2d ui(rule->GetPoint(i), lpoints.Get(pmap.Get(i)));
oldu.Set (2*i-1, ui.X()); oldu (2*i-2) = ui.X();
oldu.Set (2*i , ui.Y()); oldu (2*i-1) = ui.Y();
} }
rule -> SetFreeZoneTransformation (oldu, tolerance); rule -> SetFreeZoneTransformation (oldu, tolerance);
@ -513,8 +513,8 @@ int Meshing2 ::ApplyRules (Array<Point2d> & lpoints,
for (i = oldnp + 1; i <= rule->GetNP(); i++) for (i = oldnp + 1; i <= rule->GetNP(); i++)
{ {
np = rule->GetPoint(i); np = rule->GetPoint(i);
np.X() += newu.Elem (2 * (i-oldnp) - 1); np.X() += newu (2 * (i-oldnp) - 2);
np.Y() += newu.Elem (2 * (i-oldnp)); np.Y() += newu (2 * (i-oldnp) - 1);
pmap.Elem(i) = lpoints.Append (np); pmap.Elem(i) = lpoints.Append (np);
} }

View File

@ -603,13 +603,13 @@ int Meshing3 :: ApplyRules
{ {
const Point3d & lp = lpoints.Get(pmap.Get(i)); const Point3d & lp = lpoints.Get(pmap.Get(i));
const Point3d & rp = rule->GetPoint(i); const Point3d & rp = rule->GetPoint(i);
oldu.Set (3*i-2, lp.X()-rp.X()); oldu (3*i-3) = lp.X()-rp.X();
oldu.Set (3*i-1, lp.Y()-rp.Y()); oldu (3*i-2) = lp.Y()-rp.Y();
oldu.Set (3*i , lp.Z()-rp.Z()); oldu (3*i-1) = lp.Z()-rp.Z();
allp.Set (3*i-2, lp.X()); allp (3*i-3) = lp.X();
allp.Set (3*i-1, lp.Y()); allp (3*i-2) = lp.Y();
allp.Set (3*i , lp.Z()); allp (3*i-1) = lp.Z();
} }
if (rule->GetNP() > rule->GetNOldP()) if (rule->GetNP() > rule->GetNOldP())
@ -623,9 +623,9 @@ int Meshing3 :: ApplyRules
for (i = rule->GetNOldP()+1; i <= rule->GetNP(); i++) for (i = rule->GetNOldP()+1; i <= rule->GetNP(); i++)
{ {
const Point3d & rp = rule->GetPoint(i); const Point3d & rp = rule->GetPoint(i);
allp.Set (3*i-2, rp.X() + newu.Get(3*i-2 - idiff)); allp (3*i-3) = rp.X() + newu(3*i-3 - idiff);
allp.Set (3*i-1, rp.Y() + newu.Get(3*i-1 - idiff)); allp (3*i-2) = rp.Y() + newu(3*i-2 - idiff);
allp.Set (3*i , rp.Z() + newu.Get(3*i - idiff)); allp (3*i-1) = rp.Z() + newu(3*i-1 - idiff);
} }
rule->SetFreeZoneTransformation (allp, rule->SetFreeZoneTransformation (allp,
@ -865,9 +865,9 @@ int Meshing3 :: ApplyRules
for (i = oldnp + 1; i <= rule->GetNP(); i++) for (i = oldnp + 1; i <= rule->GetNP(); i++)
{ {
np = rule->GetPoint(i); np = rule->GetPoint(i);
np.X() += newu.Elem (3 * (i-oldnp) - 2); np.X() += newu (3 * (i-oldnp) - 3);
np.Y() += newu.Elem (3 * (i-oldnp) - 1); np.Y() += newu (3 * (i-oldnp) - 2);
np.Z() += newu.Elem (3 * (i-oldnp)); np.Z() += newu (3 * (i-oldnp) - 1);
pmap.Elem(i) = lpoints.Append (np); pmap.Elem(i) = lpoints.Append (np);
} }

View File

@ -219,9 +219,9 @@ namespace netgen
while (loci <= 5 && !moveisok) while (loci <= 5 && !moveisok)
{ {
loci ++; loci ++;
mesh[pi](0) = origp(0) + x.Get(1)*fact; mesh[pi](0) = origp(0) + x(0)*fact;
mesh[pi](1) = origp(1) + x.Get(2)*fact; mesh[pi](1) = origp(1) + x(1)*fact;
mesh[pi](2) = origp(2) + x.Get(3)*fact; mesh[pi](2) = origp(2) + x(2)*fact;
fact = fact/2.; fact = fact/2.;

View File

@ -441,7 +441,7 @@ namespace netgen
vgrad = 0.0; vgrad = 0.0;
badness = 0; badness = 0;
pp1 = sp1 + x.Get(1) * t1; pp1 = sp1 + x(0) * t1;
meshthis -> ProjectPoint2 (surfi, surfi2, pp1); meshthis -> ProjectPoint2 (surfi, surfi2, pp1);
for (j = 0; j < locelements.Size(); j++) for (j = 0; j < locelements.Size(); j++)
@ -540,7 +540,7 @@ namespace netgen
pts2d.Elem(pi) = Point2d (t1 * (mesh.Point(pi) - sp1), pts2d.Elem(pi) = Point2d (t1 * (mesh.Point(pi) - sp1),
t2 * (mesh.Point(pi) - sp1)); t2 * (mesh.Point(pi) - sp1));
} }
pts2d.Elem(gpi) = Point2d (x.Get(1), x.Get(2)); pts2d.Elem(gpi) = Point2d (x(0), x(1));
for (int k = 1; k <= 2; k++) for (int k = 1; k <= 2; k++)
@ -552,8 +552,8 @@ namespace netgen
hbad = bel. hbad = bel.
CalcJacobianBadnessDirDeriv (pts2d, lpi, vdir, hderiv); CalcJacobianBadnessDirDeriv (pts2d, lpi, vdir, hderiv);
grad.Elem(k) += hderiv; grad(k-1) += hderiv;
if (k == 1) if (k == 1)
badness += hbad; badness += hbad;
} }
@ -590,7 +590,7 @@ namespace netgen
// pp1 = sp1; // pp1 = sp1;
// pp1.Add2 (x.Get(1), t1, x.Get(2), t2); // pp1.Add2 (x.Get(1), t1, x.Get(2), t2);
pp1 = sp1 + x.Get(1) * t1 + x.Get(2) * t2; pp1 = sp1 + x(0) * t1 + x(1) * t2;
static Array<Point2d> pts2d; static Array<Point2d> pts2d;
pts2d.SetSize(mesh.GetNP()); pts2d.SetSize(mesh.GetNP());
@ -611,7 +611,7 @@ namespace netgen
pts2d.Elem(pi) = Point2d (t1 * (mesh.Point(pi) - sp1), pts2d.Elem(pi) = Point2d (t1 * (mesh.Point(pi) - sp1),
t2 * (mesh.Point(pi) - sp1)); t2 * (mesh.Point(pi) - sp1));
} }
pts2d.Elem(gpi) = Point2d (x.Get(1), x.Get(2)); pts2d.Elem(gpi) = Point2d (x(0), x(1));
vdir = Vec2d (dir(0), dir(1)); vdir = Vec2d (dir(0), dir(1));

View File

@ -149,15 +149,15 @@ namespace netgen
static double eps = 1e-6; static double eps = 1e-6;
hx = x; hx = x;
for (int i = 1; i <= 3; i++) for (int i = 0; i < 3; i++)
{ {
hx.Elem(i) = x.Get(i) + eps * h; hx(i) = x(i) + eps * h;
double fr = Func (hx); double fr = Func (hx);
hx.Elem(i) = x.Get(i) - eps * h; hx(i) = x(i) - eps * h;
double fl = Func (hx); double fl = Func (hx);
hx.Elem(i) = x.Get(i); hx(i) = x(i);
g.Elem(i) = (fr - fl) / (2 * eps * h); g(i) = (fr - fl) / (2 * eps * h);
} }
return Func(x); return Func(x);
@ -246,17 +246,17 @@ namespace netgen
static Vector res; static Vector res;
res.SetSize (m.Height()); res.SetSize (m.Height());
for (i = 1;i <= 3; i++) for (i = 0;i < 3; i++)
hv.Elem(i) = vp.Get(i); hv(i) = vp(i);
hv.Elem(4) = 1; hv(3) = 1;
m.Mult (hv, res); m.Mult (hv, res);
for (i = 1; i <= res.Size(); i++) for (i = 1; i <= res.Size(); i++)
{ {
if (res.Get(i) < 1e-10) if (res(i-1) < 1e-10)
badness += 1e24; badness += 1e24;
else else
badness += 1 / res.Get(i); badness += 1 / res(i-1);
} }
return badness; return badness;
@ -269,15 +269,15 @@ namespace netgen
static double eps = 1e-6; static double eps = 1e-6;
hx = x; hx = x;
for (int i = 1; i <= 3; i++) for (int i = 0; i < 3; i++)
{ {
hx.Elem(i) = x.Get(i) + eps * h; hx(i) = x(i) + eps * h;
double fr = Func (hx); double fr = Func (hx);
hx.Elem(i) = x.Get(i) - eps * h; hx(i) = x(i) - eps * h;
double fl = Func (hx); double fl = Func (hx);
hx.Elem(i) = x.Get(i); hx(i) = x(i);
g.Elem(i) = (fr - fl) / (2 * eps * h); g(i) = (fr - fl) / (2 * eps * h);
} }
return Func(x); return Func(x);
@ -374,42 +374,12 @@ namespace netgen
double PointFunction :: PointFunctionValueGrad (const Point<3> & pp, Vec<3> & grad) const double PointFunction :: PointFunctionValueGrad (const Point<3> & pp, Vec<3> & grad) const
{ {
double f;//, delta = h * 1e-6; double f = 0;
// Point<3> hpp; // f = PointFunctionValue (pp);
f = PointFunctionValue (pp);
/*
hpp = pp;
hpp.X() = pp.X() + delta;
fr = PointFunctionValue (hpp);
hpp.X() = pp.X() - delta;
fl = PointFunctionValue (hpp);
grad.Elem(1) = (fr - fl) / (2 * delta);
hpp = pp;
hpp.Y() = pp.Y() + delta;
fr = PointFunctionValue (hpp);
hpp.Y() = pp.Y() - delta;
fl = PointFunctionValue (hpp);
grad.Elem(2) = (fr - fl) / (2 * delta);
hpp = pp;
hpp.Z() = pp.Z() + delta;
fr = PointFunctionValue (hpp);
hpp.Z() = pp.Z() - delta;
fl = PointFunctionValue (hpp);
grad.Elem(3) = (fr - fl) / (2 * delta);
*/
// new gradient calculation
// double badness;
Point<3> hp; Point<3> hp;
Vec<3> vgradi, vgrad(0,0,0); Vec<3> vgradi, vgrad(0,0,0);
// badness = 0;
hp = points[actpind]; hp = points[actpind];
points[actpind] = Point<3> (pp); points[actpind] = Point<3> (pp);
@ -421,10 +391,10 @@ namespace netgen
for (int k = 1; k <= 4; k++) for (int k = 1; k <= 4; k++)
if (el.PNum(k) == actpind) if (el.PNum(k) == actpind)
{ {
CalcTetBadnessGrad (points[el.PNum(1)], f += CalcTetBadnessGrad (points[el.PNum(1)],
points[el.PNum(2)], points[el.PNum(2)],
points[el.PNum(3)], points[el.PNum(3)],
points[el.PNum(4)], -1, k, vgradi); points[el.PNum(4)], -1, k, vgradi);
vgrad += vgradi; vgrad += vgradi;
} }
@ -606,19 +576,19 @@ namespace netgen
static Vector di; static Vector di;
int n = m.Height(); int n = m.Height();
p4.Elem(1) = pp(0); p4(0) = pp(0);
p4.Elem(2) = pp(1); p4(1) = pp(1);
p4.Elem(3) = pp(2); p4(2) = pp(2);
p4.Elem(4) = 1; p4(3) = 1;
di.SetSize (n); di.SetSize (n);
m.Mult (p4, di); m.Mult (p4, di);
double sum = 0; double sum = 0;
for (int i = 1; i <= n; i++) for (int i = 0; i < n; i++)
{ {
if (di.Get(i) > 0) if (di(i) > 0)
sum += 1 / di.Get(i); sum += 1 / di(i);
else else
return 1e16; return 1e16;
} }
@ -635,25 +605,25 @@ namespace netgen
int n = m.Height(); int n = m.Height();
p4.Elem(1) = pp(0); p4(0) = pp(0);
p4.Elem(2) = pp(1); p4(1) = pp(1);
p4.Elem(3) = pp(2); p4(2) = pp(2);
p4.Elem(4) = 1; p4(3) = 1;
di.SetSize (n); di.SetSize (n);
m.Mult (p4, di); m.Mult (p4, di);
double sum = 0; double sum = 0;
grad = 0; grad = 0;
for (int i = 1; i <= n; i++) for (int i = 0; i < n; i++)
{ {
if (di.Get(i) > 0) if (di(i) > 0)
{ {
double idi = 1 / di.Get(i); double idi = 1 / di(i);
sum += idi; sum += idi;
grad(0) -= idi * idi * m.Get(i, 1); grad(0) -= idi * idi * m(i, 0);
grad(1) -= idi * idi * m.Get(i, 2); grad(1) -= idi * idi * m(i, 1);
grad(2) -= idi * idi * m.Get(i, 3); grad(2) -= idi * idi * m(i, 2);
} }
else else
{ {
@ -774,9 +744,9 @@ namespace netgen
} }
hx = x; hx = x;
hx.Elem(i) = x.Get(i) + eps; hx(i-1) = x(i-1) + eps;
f11 = Func(hx); f11 = Func(hx);
hx.Elem(i) = x.Get(i) - eps; hx(i-1) = x(i-1) - eps;
f22 = Func(hx); f22 = Func(hx);
hesse.Elem(i, i) = (f11 + f22 - 2 * f) / (eps * eps) + 1e-12; hesse.Elem(i, i) = (f11 + f22 - 2 * f) / (eps * eps) + 1e-12;
@ -978,17 +948,6 @@ double Opti3EdgeMinFunction :: FuncGrad (const Vector & x, Vector & grad) const
double CalcBad (const Mesh::T_POINTS & points, const Element & elem,
double h)
{
if (elem.GetType() == TET)
return CalcTetBadness (points[elem.PNum(1)],
points[elem.PNum(2)],
points[elem.PNum(3)],
points[elem.PNum(4)], h);
return 0;
}
extern double teterrpow; extern double teterrpow;
double CalcTotalBad (const Mesh::T_POINTS & points, double CalcTotalBad (const Mesh::T_POINTS & points,
@ -1100,10 +1059,10 @@ double JacobianPointFunction :: Func (const Vector & v) const
Point<3> hp = points.Elem(actpind); Point<3> hp = points.Elem(actpind);
points.Elem(actpind) = hp + Vec<3> (v.Get(1), v.Get(2), v.Get(3)); points.Elem(actpind) = hp + Vec<3> (v(0), v(1), v(2));
if(onplane) if(onplane)
points.Elem(actpind) -= (v.Get(1)*nv(0)+v.Get(2)*nv(1)+v.Get(3)*nv(2)) * nv; points.Elem(actpind) -= (v(0)*nv(0)+v(1)*nv(1)+v(2)*nv(2)) * nv;
for (j = 1; j <= elementsonpoint.EntrySize(actpind); j++) for (j = 1; j <= elementsonpoint.EntrySize(actpind); j++)
@ -1129,10 +1088,10 @@ FuncGrad (const Vector & x, Vector & g) const
double badness = 0;//, hbad; double badness = 0;//, hbad;
Point<3> hp = points.Elem(actpind); Point<3> hp = points.Elem(actpind);
points.Elem(actpind) = hp + Vec<3> (x.Get(1), x.Get(2), x.Get(3)); points.Elem(actpind) = hp + Vec<3> (x(0), x(1), x(2));
if(onplane) if(onplane)
points.Elem(actpind) -= (x.Get(1)*nv(0)+x.Get(2)*nv(1)+x.Get(3)*nv(2)) * nv; points.Elem(actpind) -= (x(0)*nv(0)+x(1)*nv(1)+x(2)*nv(2)) * nv;
Vec<3> hderiv; Vec<3> hderiv;
//Vec3d vdir; //Vec3d vdir;
@ -1154,7 +1113,7 @@ FuncGrad (const Vector & x, Vector & g) const
CalcJacobianBadnessGradient (points, lpi, hderiv); CalcJacobianBadnessGradient (points, lpi, hderiv);
for(k=0; k<3; k++) for(k=0; k<3; k++)
g.Elem(k+1) += hderiv(k); g(k) += hderiv(k);
/* /*
for (k = 1; k <= 3; k++) for (k = 1; k <= 3; k++)
@ -1174,10 +1133,10 @@ FuncGrad (const Vector & x, Vector & g) const
if(onplane) if(onplane)
{ {
double scal = nv(0)*g.Get(1) + nv(1)*g.Get(2) + nv(2)*g.Get(3); double scal = nv(0)*g(0) + nv(1)*g(1) + nv(2)*g(2);
g.Elem(1) -= scal*nv(0); g(0) -= scal*nv(0);
g.Elem(2) -= scal*nv(1); g(1) -= scal*nv(1);
g.Elem(3) -= scal*nv(2); g(2) -= scal*nv(2);
} }
//(*testout) << "g = " << g << endl; //(*testout) << "g = " << g << endl;
@ -1197,14 +1156,14 @@ FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const
double badness = 0; double badness = 0;
Point<3> hp = points.Elem(actpind); Point<3> hp = points.Elem(actpind);
points.Elem(actpind) = Point<3> (hp + Vec3d (x.Get(1), x.Get(2), x.Get(3))); points.Elem(actpind) = Point<3> (hp + Vec3d (x(0), x(1), x(2)));
if(onplane) if(onplane)
points.Elem(actpind) -= (Vec3d (x.Get(1), x.Get(2), x.Get(3))*nv) * nv; points.Elem(actpind) -= (Vec3d (x(0), x(1), x(2))*nv) * nv;
double hderiv; double hderiv;
deriv = 0; deriv = 0;
Vec<3> vdir(dir.Get(1), dir.Get(2), dir.Get(3)); Vec<3> vdir(dir(0), dir(1), dir(2));
if(onplane) if(onplane)
{ {
@ -1569,9 +1528,9 @@ void Mesh :: ImproveMesh (OPTIMIZEGOAL goal)
//*testout << "start BFGS, pok" << endl; //*testout << "start BFGS, pok" << endl;
BFGS (x, freeminf, par); BFGS (x, freeminf, par);
//*testout << "BFGS complete, pok" << endl; //*testout << "BFGS complete, pok" << endl;
points[i](0) += x.Get(1); points[i](0) += x(0);
points[i](1) += x.Get(2); points[i](1) += x(1);
points[i](2) += x.Get(3); points[i](2) += x(2);
} }
} }
PrintDot ('\n'); PrintDot ('\n');
@ -1694,9 +1653,9 @@ void Mesh :: ImproveMeshJacobian (OPTIMIZEGOAL goal, const BitArray * usepoint)
//*testout << "start BFGS, Jacobian" << endl; //*testout << "start BFGS, Jacobian" << endl;
BFGS (x, pf, par); BFGS (x, pf, par);
//*testout << "end BFGS, Jacobian" << endl; //*testout << "end BFGS, Jacobian" << endl;
points.Elem(i)(0) += x.Get(1); points.Elem(i)(0) += x(0);
points.Elem(i)(1) += x.Get(2); points.Elem(i)(1) += x(1);
points.Elem(i)(2) += x.Get(3); points.Elem(i)(2) += x(2);
} }
else else
{ {
@ -1873,12 +1832,12 @@ void Mesh :: ImproveMeshJacobianOnSurface (const BitArray & usepoint,
BFGS (x, pf_sum, par); BFGS (x, pf_sum, par);
for(j=1; j<=3; j++) for(j=0; j<3; j++)
points.Elem(i)(j-1) += x.Get(j);// - scal*nv[i-1].X(j); points.Elem(i)(j) += x(j);// - scal*nv[i-1].X(j);
if(brother != -1) if(brother != -1)
for(j=1; j<=3; j++) for(j=0; j<3; j++)
points.Elem(brother)(j-1) += x.Get(j);// - scal*nv[brother-1].X(j); points.Elem(brother)(j) += x(j);// - scal*nv[brother-1].X(j);
} }

View File

@ -183,7 +183,7 @@ void STLGeometry :: SmoothNormals()
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
hv.Elem(k+1) = ngeom(k); hv(k) = ngeom(k);
hm.Mult (hv, hv2); hm.Mult (hv, hv2);
/* /*
@ -230,7 +230,7 @@ void STLGeometry :: SmoothNormals()
} }
for (k = 0; k < 3; k++) for (k = 0; k < 3; k++)
hv.Elem(k+1) = nnb(k); hv(k) = nnb(k);
hm.Mult (hv, hv2); hm.Mult (hv, hv2);
/* /*
@ -245,7 +245,7 @@ void STLGeometry :: SmoothNormals()
} }
m.Solve (rhs, sol); m.Solve (rhs, sol);
Vec3d newn(sol.Get(1), sol.Get(2), sol.Get(3)); Vec3d newn(sol(0), sol(1), sol(2));
newn /= (newn.Length() + 1e-24); newn /= (newn.Length() + 1e-24);
GetTriangle(i).SetNormal(newn); GetTriangle(i).SetNormal(newn);
@ -1562,9 +1562,9 @@ void STLGeometry :: NeighbourAnglesOfSelectedTrig()
for (i = 1; i <= NONeighbourTrigs(st); i++) for (i = 1; i <= NONeighbourTrigs(st); i++)
{ {
PrintMessage(1," triangle ", NeighbourTrig(st,i), ": angle = ", PrintMessage(1," triangle ", NeighbourTrig(st,i), ": angle = ",
180./M_PI*GetAngle(st, NeighbourTrig(st,i)), "°", 180./M_PI*GetAngle(st, NeighbourTrig(st,i)), "°",
", calculated = ", 180./M_PI*Angle(GetTriangle(st).GeomNormal(points), ", calculated = ", 180./M_PI*Angle(GetTriangle(st).GeomNormal(points),
GetTriangle(NeighbourTrig(st,i)).GeomNormal(points)), "°"); GetTriangle(NeighbourTrig(st,i)).GeomNormal(points)), "°");
} }
} }
} }
@ -2601,7 +2601,7 @@ void STLGeometry :: AddFaceEdges()
{ {
PrintFnStart("Add starting edges for faces"); PrintFnStart("Add starting edges for faces");
//für Kugel eine STLLine hinzufügen (Vorteil: verfeinerbar, unabhängig von Auflösung der Geometrie!!!): //für Kugel eine STLLine hinzufügen (Vorteil: verfeinerbar, unabhängig von Auflösung der Geometrie!!!):
//Grenze von 1. gefundener chart //Grenze von 1. gefundener chart
Array<int> edgecnt; Array<int> edgecnt;
@ -2676,7 +2676,7 @@ void STLGeometry :: LinkEdges()
//worked edges //worked edges
Array<int> we(GetNE()); Array<int> we(GetNE());
//setlineendpoints; wenn 180°, dann keine endpunkte //setlineendpoints; wenn 180°, dann keine endpunkte
//nur punkte mit 2 edges kommen in frage, da bei mehr oder weniger punkten ohnehin ein meshpoint hinkommt //nur punkte mit 2 edges kommen in frage, da bei mehr oder weniger punkten ohnehin ein meshpoint hinkommt
Vec3d v1,v2; Vec3d v1,v2;

View File

@ -3,7 +3,6 @@
#include <mystdlib.h> #include <mystdlib.h>
#include <myadt.hpp> #include <myadt.hpp>
#include <meshing.hpp> #include <meshing.hpp>
#include <csg.hpp> #include <csg.hpp>
@ -983,9 +982,9 @@ namespace netgen
for (int i = 1; i <= locms.Size(); i++) for (int i = 1; i <= locms.Size(); i++)
{ {
Point3d p = mesh->Point(i); Point3d p = mesh->Point(i);
locms.Elem(i) = mesh->GetH (p); locms(i-1) = mesh->GetH (p);
if (locms.Elem(i) > maxh) maxh = locms.Elem(i); if (locms(i-1) > maxh) maxh = locms(i-1);
if (locms.Elem(i) < minh) minh = locms.Elem(i); if (locms(i-1) < minh) minh = locms(i-1);
} }
if (!locms.Size()) if (!locms.Size())
{ minh = 1; maxh = 10; } { minh = 1; maxh = 10; }
@ -1145,11 +1144,11 @@ namespace netgen
if (vispar.colormeshsize) if (vispar.colormeshsize)
{ {
SetOpenGlColor (locms.Get(el[0]), minh, maxh, 1); SetOpenGlColor (locms(el[0]-1), minh, maxh, 1);
glVertex3dv (lp0); glVertex3dv (lp0);
SetOpenGlColor (locms.Get(el[1]), minh, maxh, 1); SetOpenGlColor (locms(el[1]-1), minh, maxh, 1);
glVertex3dv (lp1); glVertex3dv (lp1);
SetOpenGlColor (locms.Get(el[2]), minh, maxh, 1); SetOpenGlColor (locms(el[2]-1), minh, maxh, 1);
glVertex3dv (lp2); glVertex3dv (lp2);
} }
else else

View File

@ -149,10 +149,8 @@ using namespace netgen;
void Ng_LoadGeometry (const char * filename) void Ng_LoadGeometry (const char * filename)
{ {
// if (printmessage_importance>0)
// cout << "CALLED NG LOAD GEOMETRY" << endl;
if (printmessage_importance>0)
cout << "CALLED NG LOAD GEOMETRY" << endl;
geometry.Reset (new CSGeometry ()); geometry.Reset (new CSGeometry ());
geometry2d.Reset (); geometry2d.Reset ();
@ -171,6 +169,8 @@ void Ng_LoadGeometry (const char * filename)
if (strcmp(filename,"")==0) if (strcmp(filename,"")==0)
return; return;
PrintMessage (1, "Load geometry from file ", filename);
ifstream infile (filename); ifstream infile (filename);
if ((strcmp (&filename[strlen(filename)-3], "geo") == 0) || if ((strcmp (&filename[strlen(filename)-3], "geo") == 0) ||
@ -1936,8 +1936,6 @@ void Ng_SetSolutionData (Ng_SolutionData * soldata)
// vssolution.ClearSolutionData (); // vssolution.ClearSolutionData ();
VisualSceneSolution::SolData * vss = new VisualSceneSolution::SolData; VisualSceneSolution::SolData * vss = new VisualSceneSolution::SolData;
cout << "Add solution " << soldata->name << ", type = " << soldata->soltype << endl;
vss->name = new char[strlen (soldata->name)+1]; vss->name = new char[strlen (soldata->name)+1];
strcpy (vss->name, soldata->name); strcpy (vss->name, soldata->name);

View File

@ -1,5 +1,7 @@
include_HEADERS = nglib.h include_HEADERS = nglib.h
dist_pkgdata_DATA = cube.surf
AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include $(OCCFLAGS) $(MPI_INCLUDES) AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include $(OCCFLAGS) $(MPI_INCLUDES)
lib_LTLIBRARIES = libnglib.la lib_LTLIBRARIES = libnglib.la

22
nglib/cube.surf Normal file
View File

@ -0,0 +1,22 @@
8
0 0 0
1 0 0
1 1 1
1 0 1
0 1 1
0 0 1
0 1 0
1 1 0
12
2 1 7
8 2 7
6 1 2
4 6 2
4 3 5
5 6 4
8 3 4
8 4 2
5 3 8
7 5 8
1 6 5
7 1 5