From 4110ca6a01ac1d944eae46be061dc58cec4d2229 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 26 Jun 2004 18:03:24 +0000 Subject: [PATCH] Merged Netgen 4.3.1: a Delaunay/Frontal 2D/3D mesh generator. Thanks a lot to Nicolas Tardieu for this! --- Netgen/libsrc/csg/geometry.h | 48 +++ Netgen/libsrc/csg/geometry.ll | 94 +++++ Netgen/libsrc/csg/geometry.yy | 585 ++++++++++++++++++++++++++ Netgen/libsrc/general/stack.icc | 67 +++ Netgen/libsrc/include/FlexLexer.h | 184 ++++++++ Netgen/libsrc/include/mystdlib.h | 68 +++ Netgen/libsrc/interface/nginterface.h | 222 ++++++++++ Netgen/libsrc/interface/nglib.h | 206 +++++++++ benchmarks/3d/Cube-08.geo | 18 + doc/CREDITS | 6 +- 10 files changed, 1497 insertions(+), 1 deletion(-) create mode 100644 Netgen/libsrc/csg/geometry.h create mode 100644 Netgen/libsrc/csg/geometry.ll create mode 100644 Netgen/libsrc/csg/geometry.yy create mode 100644 Netgen/libsrc/general/stack.icc create mode 100644 Netgen/libsrc/include/FlexLexer.h create mode 100644 Netgen/libsrc/include/mystdlib.h create mode 100644 Netgen/libsrc/interface/nginterface.h create mode 100644 Netgen/libsrc/interface/nglib.h create mode 100644 benchmarks/3d/Cube-08.geo diff --git a/Netgen/libsrc/csg/geometry.h b/Netgen/libsrc/csg/geometry.h new file mode 100644 index 0000000000..d84e8db183 --- /dev/null +++ b/Netgen/libsrc/csg/geometry.h @@ -0,0 +1,48 @@ +#ifndef BISON_GEOMETRY_H +# define BISON_GEOMETRY_H + +#ifndef YYSTYPE +typedef union { +double val; +char * chptr; +Solid * solidtype; +} yystype; +# define YYSTYPE yystype +# define YYSTYPE_IS_TRIVIAL 1 +#endif +# define NUM 257 +# define TOK_SOLID 258 +# define TOK_RECO 259 +# define TOK_TLO 260 +# define TOK_BOUNDINGBOX 261 +# define IDENT 262 +# define IDENTSOLID 263 +# define TOK_SPHERE 264 +# define TOK_CYLINDER 265 +# define TOK_CONE 266 +# define TOK_PLAIN 267 +# define TOK_TUBE 268 +# define TOK_GENCYL 269 +# define TOK_ORTHOBRICK 270 +# define TOK_POLYHEDRON 271 +# define TOK_REVOLUTION 272 +# define TOK_OR 273 +# define TOK_AND 274 +# define TOK_NOT 275 +# define TOK_TRANSLATE 276 +# define TOK_MULTITRANSLATE 277 +# define TOK_ROTATE 278 +# define TOK_MULTIROTATE 279 +# define TOK_SINGULAR 280 +# define TOK_EDGE 281 +# define TOK_POINT 282 +# define TOK_IDENTIFY 283 +# define TOK_CLOSESURFACES 284 +# define TOK_CLOSEEDGES 285 +# define TOK_PERIODIC 286 +# define TOK_BOUNDARYCONDITION 287 + + +extern YYSTYPE yylval; + +#endif /* not BISON_GEOMETRY_H */ diff --git a/Netgen/libsrc/csg/geometry.ll b/Netgen/libsrc/csg/geometry.ll new file mode 100644 index 0000000000..bb2edbc9f5 --- /dev/null +++ b/Netgen/libsrc/csg/geometry.ll @@ -0,0 +1,94 @@ +%{ +#include <mystdlib.h> +#include <myadt.hpp> + +#include <linalg.hpp> +#include <csg.hpp> + + + + +// extern SYMBOLTABLE<Solid*> solids; +namespace netgen { +extern CSGeometry * parsegeom; +} +using namespace netgen; + +#include "geometry.h" + + +ARRAY<char*> parsestrings; +int linenum; +%} + +dig [0-9] +id [a-zA-Z][a-zA-Z0-9]* +num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? +num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? +number {num1}|{num2} +%x incl +%x comment + +%% +algebraic3d { return TOK_RECO; } +solid { return TOK_SOLID; } +tlo { return TOK_TLO; } +and { return TOK_AND; } +or { return TOK_OR; } +not { return TOK_NOT; } +translate { return TOK_TRANSLATE; } +multitranslate { return TOK_MULTITRANSLATE; } +rotate { return TOK_ROTATE; } +multirotate { return TOK_MULTIROTATE; } +sphere { return TOK_SPHERE; } +cylinder { return TOK_CYLINDER; } +cone { return TOK_CONE; } +plain { return TOK_PLAIN; } +plane { return TOK_PLAIN; } +tube { return TOK_TUBE; } +gencyl { return TOK_GENCYL; } +orthobrick { return TOK_ORTHOBRICK; } +polyhedron { return TOK_POLYHEDRON; } +revolution { return TOK_REVOLUTION; } + +singular { return TOK_SINGULAR; } +edge { return TOK_EDGE; } +point { return TOK_POINT; } + +identify { return TOK_IDENTIFY; } +closesurfaces { return TOK_CLOSESURFACES; } +closeedges { return TOK_CLOSEEDGES; } +periodic { return TOK_PERIODIC; } +boundarycondition { return TOK_BOUNDARYCONDITION; } +boundingbox { return TOK_BOUNDINGBOX; } + +{number} { yylval.val = atof (YYText()); return NUM; } +{id}+ { + yylval.chptr = new char [YYLeng()+1]; + parsestrings.Append (yylval.chptr); + strcpy (yylval.chptr, YYText()); + if (parsegeom->GetSolid (yylval.chptr)) + return IDENTSOLID; + else + return IDENT; + } +[ \t] /* eat up ws */ +. { return int(*YYText()); } +\n { linenum++; } +"##".*\n { linenum++; cout << (YYText()+2) ; } /* line comment */ +"#".*\n { linenum++; } /* line comment */ + + +%% + +extern FlexLexer * lexer; + +int yylex () + { + return lexer -> yylex(); + } + +extern "C" int yywrap () + { + return 1; + } diff --git a/Netgen/libsrc/csg/geometry.yy b/Netgen/libsrc/csg/geometry.yy new file mode 100644 index 0000000000..49dd63a53a --- /dev/null +++ b/Netgen/libsrc/csg/geometry.yy @@ -0,0 +1,585 @@ +%{ +//define YYDEBUG 1 + +extern int yylex (); + +#include <mystdlib.h> + +#include <myadt.hpp> + +#include <linalg.hpp> +#include <csg.hpp> + +namespace netgen +{ +netgen::CSGeometry * parsegeom; +} + +using namespace netgen; + +// extern ARRAY<Surface*> surfaces; +// extern SYMBOLTABLE<Solid*> solids; + + +int yyerror (char * s); +splinetube * tube; +spline3d * middlecurve; +Point<3> splinep1; +BSplineCurve2d *bspline; +Flags parseflags; +extern int linenum; +ARRAY<double> doublearray; +ARRAY<char*> stringarray; + +Polyhedra * polyhedron; +// Revolution * revolution; +%} + +%union { +double val; +char * chptr; +Solid * solidtype; +} + +%token <val> NUM +%token TOK_SOLID, TOK_RECO, TOK_TLO, TOK_BOUNDINGBOX +%token <chptr> IDENT IDENTSOLID +%token <solidtype> TOK_SPHERE TOK_CYLINDER TOK_CONE TOK_PLAIN TOK_TUBE TOK_GENCYL TOK_ORTHOBRICK TOK_POLYHEDRON TOK_REVOLUTION +%left <solidtype> TOK_OR TOK_AND TOK_NOT +%token <solidtype> TOK_TRANSLATE TOK_MULTITRANSLATE TOK_ROTATE TOK_MULTIROTATE +%type <solidtype> solid solidprimitive +%type <void> splinesegmentlist splinesegment readbspline bsplinepointlist +%type <chptr> anyident +%token TOK_SINGULAR TOK_EDGE TOK_POINT +%token TOK_IDENTIFY TOK_CLOSESURFACES TOK_CLOSEEDGES TOK_PERIODIC +%token TOK_BOUNDARYCONDITION +%type <void> polyhedronpoints polyhedronfaces polyhedronpoint polyhedronface +%type <void> revolutionpoints revolutionpoint + + +%% +input: + { + linenum = 1; + } + TOK_RECO + recsoliddef + recadddef + + { + int i; + extern ARRAY<char*> parsestrings; + for (i = 0; i < parsestrings.Size(); i++) + delete [] parsestrings[i]; + parsestrings.SetSize(0); + } + ; + + +recsoliddef: + /* empty */ + | recsoliddef soliddef ';' + ; + +soliddef: + TOK_SOLID IDENT '=' solid + { parsegeom->SetSolid($2, new Solid (Solid::ROOT, $4)); + } + flaglist + { + parsegeom->SetFlags($2, parseflags); + } + ; + +solid: + solidprimitive + | IDENTSOLID { $$ = (Solid*)parsegeom->GetSolid($1); } + | solid TOK_OR solid { $$ = new Solid (Solid::UNION, $1, $3); } + | solid TOK_AND solid { $$ = new Solid (Solid::SECTION, $1, $3); } + | TOK_NOT solid { $$ = new Solid (Solid::SUB, $2); } + | '(' solid ')' { $$ = $2; } + ; + +solidprimitive: + TOK_SPHERE '(' NUM ',' NUM ',' NUM ';' + NUM ')' + { + OneSurfacePrimitive * surf = new Sphere (Point<3> ($3, $5, $7), $9); + parsegeom -> AddSurface (surf); + surf->SetSurfaceId (0, parsegeom->GetNSurf()-1); + $$ = new Solid (surf); + } + | TOK_CYLINDER '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ';' + NUM ')' + + { + OneSurfacePrimitive * surf = new Cylinder (Point<3> ($3, $5, $7), + Point<3> ($9, $11, $13), $15); + parsegeom->AddSurface (surf); + surf->SetSurfaceId (0, parsegeom->GetNSurf()-1); + $$ = new Solid (surf); + } + | TOK_CONE '(' NUM ',' NUM ',' NUM ';' + NUM ';' + NUM ',' NUM ',' NUM ';' + NUM ')' + + { + OneSurfacePrimitive * surf = new Cone (Point<3> ($3, $5, $7), + Point<3> ($11, $13, $15), $9, $17); + parsegeom->AddSurface (surf); + surf->SetSurfaceId (0, parsegeom->GetNSurf()-1); + $$ = new Solid (surf); + } + | TOK_PLAIN '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ')' + { + OneSurfacePrimitive * surf = new Plane ( Point<3> ($3, $5, $7), + Vec<3> ($9, $11, $13) ); + parsegeom->AddSurface (surf); + surf->SetSurfaceId (0, parsegeom->GetNSurf()-1); + $$ = new Solid (surf); + } + | TOK_ORTHOBRICK '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ')' + { + Primitive * nprim = new OrthoBrick (Point<3> ($3, $5, $7), + Point<3> ($9, $11, $13)); + for (int j = 0; j < nprim->GetNSurfaces(); j++) + { + parsegeom->AddSurface (&nprim->GetSurface(j)); + nprim->SetSurfaceId (j, parsegeom->GetNSurf()-1); + $$ = new Solid (nprim); + } + } + + + | TOK_POLYHEDRON '(' + { + polyhedron = new Polyhedra (); + } + polyhedronpoints ';' ';' + polyhedronfaces ')' + { + int j; + for (j = 0; j < polyhedron->GetNSurfaces(); j++) + { + parsegeom->AddSurface (&polyhedron->GetSurface(j)); + polyhedron->SetSurfaceId (j, parsegeom->GetNSurf()-1); + $$ = new Solid (polyhedron); + } + } + + +/* + | TOK_REVOLUTION '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ';' + { + revolution = new Revolution (Point<3> ($3, $5, $7), + Point<3> ($9, $11, $13)); + } + revolutionpoints + ')' + { + revolution -> Finish (); + int j; + for (j = 0; j < revolution->GetNSurfaces(); j++) + { + parsegeom->AddSurface (&revolution->GetSurface(j)); + revolution->SetSurfaceId (j, parsegeom->GetNSurf()-1); + $$ = new Solid (revolution); + } + } +*/ + + + | TOK_TRANSLATE '(' NUM ',' NUM ',' NUM ';' solid ')' + { + Solid * nsol = $9 -> Copy(*parsegeom); + Vec<3> v($3, $5, $7); + Transformation<3> trans(v); + nsol -> Transform (trans); + $$ = nsol; + } + + | TOK_MULTITRANSLATE '(' NUM ',' NUM ',' NUM ';' NUM ';' solid ')' + { + int i; + Solid * hsol = $11; + for (i = 1; i <= $9; i++) + { + Solid * nsol = $11 -> Copy(*parsegeom); + Vec<3> v($3, $5, $7); + v *= i; + Transformation<3> trans(v); + nsol -> Transform (trans); + hsol = new Solid (Solid::UNION, hsol, nsol); + } + $$ = hsol; + } + + | TOK_ROTATE '(' NUM ',' NUM ',' NUM ';' NUM ',' NUM ',' NUM ';' solid ')' + { + Solid * nsol = $15 -> Copy(*parsegeom); + Point<3> c($3, $5, $7); + Transformation<3> rot(c, $9, $11, $13); + nsol -> Transform (rot); + $$ = nsol; + } + + | TOK_MULTIROTATE '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ';' + NUM ';' solid ')' + { + int i; + Solid * hsol = $17; + + Point<3> c($3, $5, $7); + Transformation<3> trans(c, $9, $11, $13); + Transformation<3> multi(Vec<3>(0,0,0)); + Transformation<3> ht; + + for (i = 1; i <= $15; i++) + { + Solid * nsol = $17 -> Copy(*parsegeom); + nsol -> Transform (multi); + hsol = new Solid (Solid::UNION, hsol, nsol); + + ht=multi; + multi.Combine (trans, ht); + } + $$ = hsol; + } + + +/* + | TOK_TUBE '(' NUM ',' NUM ',' NUM ',' + { + middlecurve = new spline3d; + splinep1.X() = $3; splinep1.Y() = $5; splinep1.Z() = $7; + } + splinesegmentlist ';' NUM ')' + { + Surface * surf = new splinetube (*middlecurve, $12); + parsegeom->AddSurface (surf); + $$ = new Solid (surf, parsegeom->GetNSurf()); + } + + | TOK_GENCYL '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ';' + readbspline + ')' + { + Surface * surf = new GeneralizedCylinder + (*bspline, Point<3> ($3, $5, $7), Vec<3> ($9, $11, $13), + Vec<3> ($15, $17, $19) ); + parsegeom->AddSurface (surf); + $$ = new Solid (surf, parsegeom->GetNSurf()); + } +*/ + ; + + +polyhedronpoints: + polyhedronpoints ';' polyhedronpoint + | polyhedronpoint + ; +polyhedronfaces: + polyhedronfaces ';' polyhedronface + | polyhedronface + ; +polyhedronpoint: + NUM ',' NUM ',' NUM + { + polyhedron->AddPoint (Point<3> ($1, $3, $5)); + cout << " " << $1 << " " << $3 << " " << $5 << endl; + } + ; +polyhedronface: + NUM ',' NUM ',' NUM + { + polyhedron->AddFace (int($1)-1, int($3)-1, int($5)-1); + cout << $1 << " " << $3 << " " << $5 << endl; + } + | NUM ',' NUM ',' NUM ',' NUM + { + cout << "face, 1 = " << $1 << " " << $3 << " " << $5 << " " << $7 << endl; + polyhedron->AddFace (int($1)-1, int($3)-1, int($5)-1); + polyhedron->AddFace (int($1)-1, int($5)-1, int($7)-1); + cout << $1 << $3 << $5 << $7 << endl; + } + ; + +revolutionpoints: + revolutionpoints ';' revolutionpoint + | revolutionpoint + ; +revolutionpoint: + NUM ',' NUM + { +// revolution->AddPoint (Point<2> ($1, $3)); + cout << " " << $1 << " " << $3 << endl; + } + ; + + + + + +splinesegmentlist: + splinesegment + | splinesegment ',' splinesegmentlist + ; +splinesegment: + NUM ',' NUM ',' NUM ',' + NUM ',' NUM ',' NUM + { + middlecurve->AddSegment (splinep1, Point<3> ($1, $3, $5), Point<3> ($7, $9, $11)); + splinep1(0) = $7; splinep1(1) = $9; splinep1(2) = $11; + } + ; + + +readbspline: + NUM ',' NUM + { + bspline = new BSplineCurve2d; + bspline -> AddPoint (Point<2> ($1, $3)); + cout << "first point" << endl; + } + bsplinepointlist + ; +bsplinepointlist: + /* empty */ { } + | ',' NUM ',' NUM + { + bspline -> AddPoint (Point<2> ($2, $4)); + cout << "Add Point: " << $2 << "-" << $4 << endl; + } + bsplinepointlist + ; + + + + + + + + + +recadddef: + /* empty */ + | recadddef adddef ';' + ; + +adddef: + TOK_SINGULAR TOK_EDGE NUM IDENTSOLID IDENTSOLID + { cout << "singular edge:" << $3 << " between " + << $4 << " and " << $5 << endl; + parsegeom->singedges.Append + (new SingularEdge ($3, parsegeom->GetSolid($4), + parsegeom->GetSolid($5))); + } + | + TOK_SINGULAR TOK_POINT NUM IDENTSOLID IDENTSOLID IDENTSOLID + { cout << "singular point:" << $3 << " between " + << $4 << ", " << $5 << " and " << $6 << endl; + parsegeom->singpoints.Append + (new SingularPoint ($3, parsegeom->GetSolid($4), + parsegeom->GetSolid($5), + parsegeom->GetSolid($6))); + } + | + TOK_IDENTIFY TOK_CLOSESURFACES IDENTSOLID IDENTSOLID flaglist + { + ARRAY<int> si1, si2; + parsegeom->GetSolid($3)->GetSurfaceIndices(si1); + parsegeom->GetSolid($4)->GetSurfaceIndices(si2); + + parsegeom->AddIdentification ( + new CloseSurfaceIdentification ( + parsegeom->GetNIdentifications()+1, + *parsegeom, + parsegeom->GetSurface (si1[0]), + parsegeom->GetSurface (si2[0]), + parseflags)); + } + | + TOK_IDENTIFY TOK_CLOSEEDGES IDENTSOLID IDENTSOLID IDENTSOLID + { + ARRAY<int> si1, si2, si3; + parsegeom->GetSolid($3)->GetSurfaceIndices(si1); + parsegeom->GetSolid($4)->GetSurfaceIndices(si2); + parsegeom->GetSolid($5)->GetSurfaceIndices(si3); + + parsegeom->AddIdentification ( + new CloseEdgesIdentification ( + parsegeom->GetNIdentifications()+1, + *parsegeom, + parsegeom->GetSurface (si1.Get(1)), + parsegeom->GetSurface (si2.Get(1)), + parsegeom->GetSurface (si3.Get(1)))); + } + | + TOK_IDENTIFY TOK_PERIODIC IDENTSOLID IDENTSOLID + { + ARRAY<int> si1, si2; + parsegeom->GetSolid($3)->GetSurfaceIndices(si1); + parsegeom->GetSolid($4)->GetSurfaceIndices(si2); + + parsegeom->AddIdentification ( + new PeriodicIdentification ( + parsegeom->GetNIdentifications()+1, + *parsegeom, + parsegeom->GetSurface (si1.Get(1)), + parsegeom->GetSurface (si2.Get(1)))); + } + | + TOK_TLO IDENTSOLID flaglist + { + int tlonr = + parsegeom->SetTopLevelObject ((Solid*)parsegeom->GetSolid($2)); + TopLevelObject * tlo = parsegeom->GetTopLevelObject (tlonr); + if (parseflags.NumListFlagDefined ("col")) + { + const ARRAY<double> & col = parseflags.GetNumListFlag ("col"); + tlo->SetRGB (col[0], col[1], col[2]); + } + if (parseflags.GetDefineFlag ("transparent")) + tlo->SetTransparent (1); + } + | + TOK_TLO IDENTSOLID IDENTSOLID flaglist + { + ARRAY<int> si; + parsegeom->GetSolid($3)->GetSurfaceIndices(si); + int tlonr = + parsegeom->SetTopLevelObject ((Solid*)parsegeom->GetSolid($2), + (Surface*)parsegeom->GetSurface(si.Get(1))); + TopLevelObject * tlo = parsegeom->GetTopLevelObject (tlonr); + if (parseflags.NumListFlagDefined ("col")) + { + const ARRAY<double> & col = parseflags.GetNumListFlag ("col"); + tlo->SetRGB (col.Get(1), col.Get(2), col.Get(3)); + } + if (parseflags.GetDefineFlag ("transparent")) + tlo->SetTransparent (1); + } + | + TOK_BOUNDINGBOX '(' NUM ',' NUM ',' NUM ';' + NUM ',' NUM ',' NUM ')' + { + parsegeom->SetBoundingBox (Box<3> (Point<3> ($3, $5, $7), + Point<3> ($9, $11, $13))); + } + | + TOK_POINT '(' NUM ',' NUM ',' NUM ')' + { + parsegeom->AddUserPoint (Point<3> ($3, $5, $7)); + } + | + TOK_BOUNDARYCONDITION IDENTSOLID IDENTSOLID NUM + { + CSGeometry::BCModification bcm; + ARRAY<int> si; + + parsegeom->GetSolid($2)->GetSurfaceIndices(si); + + bcm.tlonr = -1; + int i; + for (i = 0; i < parsegeom->GetNTopLevelObjects(); i++) + if (strcmp (parsegeom->GetTopLevelObject(i)->GetSolid()->Name(), $3) == 0) + { + bcm.tlonr = i; + break; + } + + bcm.bcnr = int($4); + for (i = 0; i < si.Size(); i++) + { + bcm.si = si[i]; + parsegeom->bcmodifications.Append (bcm); + } + } + ; + + + + +flaglist: + { parseflags.DeleteFlags (); } + recflaglist + ; + +recflaglist: + /* empty */ + | flag recflaglist + ; + +flag: + '-' anyident + { parseflags.SetFlag ($2); } + | '-' anyident '=' anyident + { parseflags.SetFlag ($2, $4); } + | '-' anyident '=' NUM + { parseflags.SetFlag ($2, $4); } + | '-' anyident '=' numlistbrack + { parseflags.SetFlag ($2, doublearray); } + | '-' anyident '=' stringlistbrack + { parseflags.SetFlag ($2, stringarray); } + ; + + +numlistbrack: + '[' { doublearray.SetSize (0); } + numlist ']' + ; + +numlist: + NUM { doublearray.Append ($1); } + | numlist ',' NUM { doublearray.Append ($3); } + ; + +stringlistbrack: + '[' + { + int i; + for (i = 0; i < stringarray.Size(); i++) + delete stringarray[i]; + stringarray.SetSize (0); + } + stringlist ']' + ; + +stringlist: + anyident + { + stringarray.Append (new char[strlen($1)+1]); + strcpy (stringarray.Last(), $1); + } + + | stringlist ',' anyident + { + stringarray.Append (new char[strlen($3)+1]); + strcpy (stringarray.Last(), $3); + } + ; + + + + + +anyident: + IDENT { $$ = $1; } + | IDENTSOLID { $$ = $1; } +%% + + +int yyerror (char * s) +{ + cerr << s << " in line " << linenum << endl; + return 0; +} + diff --git a/Netgen/libsrc/general/stack.icc b/Netgen/libsrc/general/stack.icc new file mode 100644 index 0000000000..c0182a564b --- /dev/null +++ b/Netgen/libsrc/general/stack.icc @@ -0,0 +1,67 @@ +/*****************************************************************************/ +/* File: stack.hh */ +/* Author: Wolfram Muehlhuber */ +/* Date: September 98 */ +/*****************************************************************************/ + +/* + + Stack class, based on a resizable array + + */ + +template <class T> +inline STACK<T> :: STACK (INDEX asize, INDEX ainc) + : elems(asize, ainc) +{ + size = 0; +} + + +template <class T> +inline STACK<T> :: ~STACK () +{ + ; +} + + +template <class T> +inline void STACK<T> :: Push (const T & el) +{ + if (size < elems.Size()) + elems.Elem(++size) = el; + else + { + elems.Append(el); + size++; + } +} + + +template <class T> +inline T & STACK<T> :: Pop () +{ + return elems.Elem(size--); +} + + +template <class T> +const inline T & STACK<T> :: Top () const +{ + return elems.Get(size); +} + +template <class T> +inline int STACK<T> :: IsEmpty () const +{ + return (size == 0); +} + + +template <class T> +inline void STACK<T> :: MakeEmpty () +{ + size = 0; +} + + diff --git a/Netgen/libsrc/include/FlexLexer.h b/Netgen/libsrc/include/FlexLexer.h new file mode 100644 index 0000000000..abc6b53625 --- /dev/null +++ b/Netgen/libsrc/include/FlexLexer.h @@ -0,0 +1,184 @@ +// $Header: /cvsroot/gmsh/Netgen/libsrc/include/FlexLexer.h,v 1.1 2004-06-26 18:03:24 geuzaine Exp $ + +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex + +// Copyright (c) 1993 The Regents of the University of California. +// All rights reserved. +// +// This code is derived from software contributed to Berkeley by +// Kent Williams and Tom Epperly. +// +// Redistribution and use in source and binary forms are permitted provided +// that: (1) source distributions retain this entire copyright notice and +// comment, and (2) distributions including binaries display the following +// acknowledgement: ``This product includes software developed by the +// University of California, Berkeley and its contributors'' in the +// documentation or other materials provided with the distribution and in +// all advertising materials mentioning features or use of this software. +// Neither the name of the University nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. +// +// If you want to create multiple lexer classes, you use the -P flag +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include <FlexLexer.h> in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include <FlexLexer.h> +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include <FlexLexer.h> +// ... + +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H + + +extern "C++" { +struct yy_buffer_state; +typedef int yy_state_type; + +class FlexLexer { +public: + virtual ~FlexLexer() { } + + const char* YYText() { return yytext; } + int YYLeng() { return yyleng; } + + virtual void + yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; + virtual struct yy_buffer_state* + yy_create_buffer( istream* s, int size ) = 0; + virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; + virtual void yyrestart( istream* s ) = 0; + + virtual int yylex() = 0; + + // Call yylex with new input/output sources. + int yylex( istream* new_in, ostream* new_out = 0 ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( istream* new_in = 0, + ostream* new_out = 0 ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" +}; + +} +#endif + +#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex man page. +#define yyFlexLexerOnce + +class yyFlexLexer : public FlexLexer { +public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ); + + virtual ~yyFlexLexer(); + + void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); + struct yy_buffer_state* yy_create_buffer( istream* s, int size ); + void yy_delete_buffer( struct yy_buffer_state* b ); + void yyrestart( istream* s ); + + virtual int yylex(); + virtual void switch_streams( istream* new_in, ostream* new_out ); + +protected: + virtual int LexerInput( char* buf, int max_size ); + virtual void LexerOutput( const char* buf, int size ); + virtual void LexerError( const char* msg ); + + void yyunput( int c, char* buf_ptr ); + int yyinput(); + + void yy_load_buffer_state(); + void yy_init_buffer( struct yy_buffer_state* b, istream* s ); + void yy_flush_buffer( struct yy_buffer_state* b ); + + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; + + void yy_push_state( int new_state ); + void yy_pop_state(); + int yy_top_state(); + + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans( yy_state_type current_state ); + int yy_get_next_buffer(); + + istream* yyin; // input source for default LexerInput + ostream* yyout; // output sink for default LexerOutput + + struct yy_buffer_state* yy_current_buffer; + + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; + + // Number of characters read into yy_ch_buf. + int yy_n_chars; + + // Points to current character in buffer. + char* yy_c_buf_p; + + int yy_init; // whether we need to initialize + int yy_start; // start state number + + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). + + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; + + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; + + int yy_lp; + int yy_looking_for_trail_begin; + + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; +}; + +#endif diff --git a/Netgen/libsrc/include/mystdlib.h b/Netgen/libsrc/include/mystdlib.h new file mode 100644 index 0000000000..8c5544407c --- /dev/null +++ b/Netgen/libsrc/include/mystdlib.h @@ -0,0 +1,68 @@ +#ifndef FILE_MYSTDLIB +#define FILE_MYSTDLIB + + +#include <iostream> +#include <iomanip> +#include <fstream> +#include <sstream> + +#ifdef OLDCINCLUDE + +// e.g., CC compiler on SGI +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <malloc.h> +#include <ctype.h> +#include <time.h> + +#else + +// new standard +#include <cstdlib> +#include <cstdio> +#include <cmath> +#include <cctype> +#include <ctime> +#endif + + + +#include <new> +#include <string> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + + +/*** Windows headers ***/ +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include <afxwin.h> +#include <afxmt.h> +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN +#include <winnt.h> +#endif /* WIN32 */ + + +/* +extern void* operator new(std::size_t) throw (std::bad_alloc); +extern void* operator new[](std::size_t) throw (std::bad_alloc); +extern void operator delete(void*) throw(); +extern void operator delete[](void*) throw(); +*/ + + +extern int mem_alloc; +extern int mem_total_alloc; +extern int mem_max_alloc; +extern int mem_total_alloc_array; +extern int mem_total_alloc_table; + + +using namespace std; + +#endif diff --git a/Netgen/libsrc/interface/nginterface.h b/Netgen/libsrc/interface/nginterface.h new file mode 100644 index 0000000000..e7949900a0 --- /dev/null +++ b/Netgen/libsrc/interface/nginterface.h @@ -0,0 +1,222 @@ +#ifndef NGINTERFACE +#define NGINTERFACE + +/**************************************************************************/ +/* File: nginterface.hh */ +/* Author: Joachim Schoeberl */ +/* Date: 20. Nov. 99 */ +/**************************************************************************/ + +/* + + Application program interface to Netgen + + + */ + + +// max number of nodes per element +#define NG_ELEMENT_MAXPOINTS 12 + +// max number of nodes per surface element +#define NG_SURFACE_ELEMENT_MAXPOINTS 6 + + + +// implemented element types: +enum NG_ELEMENT_TYPE { + NG_SEGM = 1, NG_SEGM3 = 2, + NG_TRIG = 10, NG_QUAD=11, NG_TRIG6 = 12, NG_QUAD6 = 13, + NG_TET = 20, NG_TET10 = 21, + NG_PYRAMID = 22, NG_PRISM = 23, NG_PRISM12 = 24, + NG_HEX = 25 +}; + +typedef double NG_POINT[3]; // coordinates +typedef int NG_EDGE[2]; // initial point, end point +typedef int NG_FACE[4]; // points, last one is 0 for trig + + +#ifdef __cplusplus +extern "C" { +#endif + + // load geomtry from file + void Ng_LoadGeometry (char * filename); + + // load netgen mesh + void Ng_LoadMesh (char * filename); + + + // space dimension (2 or 3) + int Ng_GetDimension (); + + // number of mesh points + int Ng_GetNP (); + + // number of mesh vertices (differs from GetNP for 2nd order elements) + int Ng_GetNV (); + + // number of mesh elements + int Ng_GetNE (); + + // number of surface triangles + int Ng_GetNSE (); + + // Get Point coordintes, index from 1 .. np + void Ng_GetPoint (int pi, double * p); + + // Get Element Points + NG_ELEMENT_TYPE Ng_GetElement (int ei, int * epi, int * np = 0); + + // Get Element Type + NG_ELEMENT_TYPE Ng_GetElementType (int ei); + + // Get sub-domain of element ei + int Ng_GetElementIndex (int ei); + + // Get Material of element ei + char * Ng_GetElementMaterial (int ei); + + // Get Surface Element Points + NG_ELEMENT_TYPE Ng_GetSurfaceElement (int ei, int * epi, int * np = 0); + + // Get Surface Element Index + int Ng_GetSurfaceElementIndex (int ei); + + // Get normal vector of surface element node + void Ng_GetNormalVector (int sei, int locpi, double * nv); + + + // Find element of point, returns local coordinates + int Ng_FindElementOfPoint (double * p, double * lami); + + + /// Curved Elemens: + /// xi..local coordinates + /// x ..global coordinates + /// dxdxi...D x D Jacobian matrix (row major storage) + void Ng_GetElementTransformation (int ei, const double * xi, + double * x, double * dxdxi); + + /// Curved Elemens: + /// xi..local coordinates + /// x ..global coordinates + /// dxdxi...D x D-1 Jacobian matrix (row major storage) + void Ng_GetSurfaceElementTransformation (int sei, const double * xi, double * x, double * dxdxi); + + + // Mark element for refinement + void Ng_SetRefinementFlag (int ei, int flag); + void Ng_SetSurfaceRefinementFlag (int sei, int flag); + + // Do local refinement + enum NG_REFINEMENT_TYPE { NG_REFINE_H = 0, NG_REFINE_P = 1, NG_REFINE_HP = 2 }; + void Ng_Refine (NG_REFINEMENT_TYPE reftype); + + // Use second order elements + void Ng_SecondOrder (); + void Ng_HighOrder (int order); + void Ng_HPRefinement (int levels); + + + // Topology and coordinate information of master element: + + int Ng_ME_GetNVertices (NG_ELEMENT_TYPE et); + int Ng_ME_GetNEdges (NG_ELEMENT_TYPE et); + int Ng_ME_GetNFaces (NG_ELEMENT_TYPE et); + + const NG_POINT * Ng_ME_GetVertices (NG_ELEMENT_TYPE et); + const NG_EDGE * Ng_ME_GetEdges (NG_ELEMENT_TYPE et); + const NG_FACE * Ng_ME_GetFaces (NG_ELEMENT_TYPE et); + + int Ng_GetNEdges(); + int Ng_GetNFaces(); + + + int Ng_GetElement_Edges (int elnr, int * edges, int * orient = 0); + int Ng_GetElement_Faces (int elnr, int * faces, int * orient = 0); + + int Ng_GetSurfaceElement_Edges (int selnr, int * edges, int * orient = 0); + int Ng_GetSurfaceElement_Face (int selnr, int * orient = 0); + + int Ng_GetFace_Vertices (int fnr, int * vert); + void Ng_GetEdge_Vertices (int ednr, int * vert); + int Ng_GetFace_Edges (int fnr, int * edge); + + int Ng_GetElementOrder (int enr); + + // Multilevel functions: + + // number of levels: + int Ng_GetNLevels (); + // get two parent nodes of node ni + void Ng_GetParentNodes (int ni, int * parents); + + // get parent element (first child has always same number) + int Ng_GetParentElement (int ei); + + // get parent surface element (first child has always same number) + int Ng_GetParentSElement (int ei); + + // representant of anisotropic cluster + int Ng_GetClusterRepVertex (int vi); + int Ng_GetClusterRepEdge (int edi); + int Ng_GetClusterRepFace (int fai); + int Ng_GetClusterRepElement (int eli); + + + void Ng_SurfaceElementTransformation (int eli, double x, double y, + double * p3d, double * jacobian); + +namespace netgen { +#include "../visualization/soldata.hpp" +} + + enum Ng_SolutionType + { NG_SOLUTION_NODAL = 1, + NG_SOLUTION_ELEMENT = 2, + NG_SOLUTION_SURFACE_ELEMENT = 3, + NG_SOLUTION_NONCONTINUOUS = 4, + NG_SOLUTION_SURFACE_NONCONTINUOUS = 5, + NG_SOLUTION_VIRTUAL_FUNCTION = 6, + NG_SOLUTION_MARKED_ELEMENTS = 10, + NG_SOLUTION_ELEMENT_ORDER = 11 + }; + + struct Ng_SolutionData + { + char * name; // name of gridfunction + double * data; // solution values + int components; // relevant (double) components in solution vector + int dist; // # doubles per entry alignment! + int iscomplex; // complex vector ? + bool draw_surface; + bool draw_volume; + int order; // order of elements, only partially supported + Ng_SolutionType soltype; // type of solution function + netgen::SolutionData * solclass; + }; + + // initialize solution data with default arguments + void Ng_InitSolutionData (Ng_SolutionData * soldata); + // set solution data + void Ng_SetSolutionData (Ng_SolutionData * soldata); + // redraw + void Ng_Redraw(); + // + void Ng_SetVisualizationParameter (const char * name, + const char * value); + + + // number of periodic vertices + int Ng_GetNPeriodicVertices (); + // pairs should be an integer array of 2*npairs + void Ng_GetPeriodicVertices (int * pairs); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Netgen/libsrc/interface/nglib.h b/Netgen/libsrc/interface/nglib.h new file mode 100644 index 0000000000..592517c945 --- /dev/null +++ b/Netgen/libsrc/interface/nglib.h @@ -0,0 +1,206 @@ +#ifndef NGLIB +#define NGLIB + +/**************************************************************************/ +/* File: nglib.hh */ +/* Author: Joachim Schoeberl */ +/* Date: 7. May. 2000 */ +/**************************************************************************/ + +/* + + Interface to the netgen meshing kernel + +*/ + + + +/// Data type for NETGEN mesh +typedef void * Ng_Mesh; + +/// Data type for NETGEN CSG geomty +typedef void * Ng_CSG_Geometry; + +/// Data type for NETGEN 2D geomty +typedef void * Ng_Geometry_2D; + +/// Data type for NETGEN STL geomty +typedef void * Ng_STL_Geometry; + + + +// max number of nodes per element +#define NG_VOLUME_ELEMENT_MAXPOINTS 10 + +// implemented element types: +enum Ng_Volume_Element_Type { NG_TET = 1, NG_PYRAMID = 2, NG_PRISM = 3, + NG_TET10 = 4 }; + +// max number of nodes per surface element +#define NG_SURFACE_ELEMENT_MAXPOINTS 6 + +// implemented element types: +enum Ng_Surface_Element_Type { NG_TRIG = 1, NG_QUAD = 2, + NG_TRIG6 = 3 }; + + + +class Ng_Meshing_Parameters +{ + public: + + double maxh; + double fineness; // 0 .. coarse, 1 .. fine + int secondorder; + char * meshsize_filename; + + Ng_Meshing_Parameters(); +}; + + +enum Ng_Result { NG_OK = 0, + NG_SURFACE_INPUT_ERROR = 1, + NG_VOLUME_FAILURE = 2, + NG_STL_INPUT_ERROR = 3, + NG_SURFACE_FAILURE = 4, + NG_FILE_NOT_FOUND = 5 }; + + + + + +#ifdef __cplusplus +extern "C" +{ +#endif + + // initialize, deconstruct Netgen library: + void Ng_Init (); + void Ng_Exit (); + + + // Generates new mesh structure + Ng_Mesh * Ng_NewMesh (); + void Ng_DeleteMesh (Ng_Mesh * mesh); + + // feeds points, surface elements and volume elements to the mesh + void Ng_AddPoint (Ng_Mesh * mesh, double * x); + void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, + int * pi); + void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, + int * pi); + + // ask for number of points, surface and volume elements + int Ng_GetNP (Ng_Mesh * mesh); + int Ng_GetNSE (Ng_Mesh * mesh); + int Ng_GetNE (Ng_Mesh * mesh); + + + // return point coordinates + void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x); + + // return surface and volume element in pi + Ng_Surface_Element_Type + Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi); + + Ng_Volume_Element_Type + Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi); + + + // Defines MeshSize Functions + void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h); + void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h); + void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h); + + // generates volume mesh from surface mesh + Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp); + + void Ng_SaveMesh(Ng_Mesh * mesh, char* filename); + + + + + + // ********************************************************** + // ** 2D Meshing ** + // ********************************************************** + + + // feeds points and boundary to mesh + + void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x); + void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2); + + // ask for number of points, elements and boundary segments + int Ng_GetNP_2D (Ng_Mesh * mesh); + int Ng_GetNE_2D (Ng_Mesh * mesh); + int Ng_GetNSeg_2D (Ng_Mesh * mesh); + + // return point coordinates + void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x); + + // return 2d triangles + void Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); + + // return 2d boundary segment + void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL); + + + // load 2d netgen spline geometry + Ng_Geometry_2D * Ng_LoadGeometry_2D (char * filename); + + // generate 2d mesh, mesh is allocated by function + Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom, + Ng_Mesh ** mesh, + Ng_Meshing_Parameters * mp); + + + + + + + + // ********************************************************** + // ** STL Meshing ** + // ********************************************************** + + + // loads geometry from STL file + Ng_STL_Geometry * Ng_STL_LoadGeometry (char * filename, int binary = 0); + + + // generate new STL Geometry + Ng_STL_Geometry * Ng_STL_NewGeometry (); + + + // fills STL Geometry + // positive orientation + // normal vector may be null-pointer + void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, + double * p1, double * p2, double * p3, + double * nv = NULL); + + // add (optional) edges : + void Ng_STL_AddEdge (Ng_STL_Geometry * geom, + double * p1, double * p2); + + // after adding triangles (and edges) initialize + Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom); + + // automatically generates edges: + Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom, + Ng_Mesh* mesh, + Ng_Meshing_Parameters * mp); + + + // generates mesh, empty mesh must be already created. + Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom, + Ng_Mesh * mesh, + Ng_Meshing_Parameters * mp); + +#ifdef __cplusplus + } +#endif + + +#endif diff --git a/benchmarks/3d/Cube-08.geo b/benchmarks/3d/Cube-08.geo new file mode 100644 index 0000000000..5954091478 --- /dev/null +++ b/benchmarks/3d/Cube-08.geo @@ -0,0 +1,18 @@ +/***************************** +A cube with a hole +*****************************/ + +Point(1) = {0.0,0.0,0.0,.1}; +Extrude Point {1, {1,0.0,0} }; +Extrude Line {1, {0.0,0.0,1} }; +Extrude Surface {5, {0,1,0} }; + +Point(100) = {0.3,0.3,0.3,.1}; +Extrude Point {100, {.4,0.0,0} }; +Extrude Line {28, {0,0.4,0} }; +Extrude Surface {32, {0,0.,0.4} }; + +Surface Loop(55) = {-26,5,-14,-18,-22,-27}; +Surface Loop(56) = {-41,32,-45,-49,-53,-54}; +Volume(57) = {55,56}; +//Volume(57) = {55}; diff --git a/doc/CREDITS b/doc/CREDITS index 3c80db6990..59e13269c8 100644 --- a/doc/CREDITS +++ b/doc/CREDITS @@ -1,4 +1,4 @@ -$Id: CREDITS,v 1.14 2004-06-23 19:53:52 geuzaine Exp $ +$Id: CREDITS,v 1.15 2004-06-26 18:03:24 geuzaine Exp $ Gmsh is copyright (C) 1997-2004 @@ -65,6 +65,10 @@ This version of Gmsh may contain code (in the Triangle subdirectory) copyright (C) 1993, 1995, 1997, 1998, 2002, Jonathan Richard Shewchuk: check the configuration options. +This version of Gmsh may contain code (in the Netgen subdirectory) +copyright (C) 1994-2004, Joachim Sch"oberl: check the configuration +options. + Special thanks to Bill Spitzak <spitzak at users.sourceforge.net>, Michael Sweet <easysw at users.sourceforge.net>, Matthias Melcher <mm at matthiasm.com> and others for the Fast Light Tool Kit on which -- GitLab