Path: blob/devel/ElmerGUI/netgen/libsrc/geom2d/splinegeometry2.cpp
3206 views
1OLD IMPLEMENTATION, NOT USED ANYMORE!2345/*672d Spline curve for Mesh generator89*/1011#include <mystdlib.h>12#include <csg.hpp>13#include <linalg.hpp>14#include <meshing.hpp>151617namespace netgen1819{20using namespace netgen;2122#include "spline2d.hpp"23#include "splinegeometry2.hpp"24252627SplineGeometry2d :: ~SplineGeometry2d()28{29for(int i=0; i<splines.Size(); i++)30{31delete splines[i];32}33splines.DeleteAll();34geompoints.DeleteAll();35}3637void SplineGeometry2d :: CSGLoad (CSGScanner & scan)38{39double x,y,hd;40int nump, numseg;4142//scan.ReadNext();4344scan >> nump >> ';';4546hd = 1;47geompoints.SetSize(nump);48for(int i = 0; i<nump; i++)49{50scan >> x >> ',' >> y >> ';';51geompoints[i] = GeomPoint2d(x,y,hd);52}5354scan >> numseg;// >> ';';5556splines.SetSize(numseg);5758int pnums,pnum1,pnum2,pnum3;596061for(int i = 0; i<numseg; i++)62{63scan >> ';' >> pnums >> ',';64if (pnums == 2)65{66scan >> pnum1 >> ',' >> pnum2;// >> ';';67splines[i] = new LineSegment(geompoints[pnum1-1],68geompoints[pnum2-1]);69}70else if (pnums == 3)71{72scan >> pnum1 >> ',' >> pnum2 >> ','73>> pnum3;// >> ';';74splines[i] = new SplineSegment3(geompoints[pnum1-1],75geompoints[pnum2-1],76geompoints[pnum3-1]);77}78else if (pnums == 4)79{80scan >> pnum1 >> ',' >> pnum2 >> ','81>> pnum3;// >> ';';82splines[i] = new CircleSegment(geompoints[pnum1-1],83geompoints[pnum2-1],84geompoints[pnum3-1]);8586}8788}89909192}939495void SplineGeometry2d :: Load (const char * filename)96{97cout << "load 2d" << endl;98ifstream infile;99int nump, numseg, leftdom, rightdom;100double x, y;101int hi1, hi2, hi3;102double hd;103char buf[50], ch;104105infile.open (filename);106107if (! infile.good() )108throw NgException(string ("2D Input file '") +109string (filename) +110string ("' not available!"));111112infile >> buf; // file recognition113infile >> elto0;114115infile >> nump;116for (int i = 0; i < nump; i++)117{118infile >> x >> y >> hd;119120Flags flags;121122ch = 'a';123// infile >> ch;124do {125infile.get (ch);126} while (isspace(ch) && ch != '\n');127while (ch == '-')128{129char flag[100];130flag[0]='-';131infile >> (flag+1);132flags.SetCommandLineFlag (flag);133ch = 'a';134do {135infile.get (ch);136} while (isspace(ch) && ch != '\n');137}138139if (infile.good())140infile.putback (ch);141142geompoints.Append (GeomPoint2d(x, y, hd));143geompoints.Last().hpref = flags.GetDefineFlag ("hpref");144cout << "point " << x << ", " << y << endl;145}146147infile >> numseg;148SplineSegment * spline = 0;149for (int i = 0; i < numseg; i++)150{151infile >> leftdom >> rightdom;152153// cout << "add spline " << i << ", left = " << leftdom << endl;154155infile >> buf;156// type of spline segement157if (strcmp (buf, "2") == 0)158{ // a line159infile >> hi1 >> hi2;160spline = new LineSegment(geompoints[hi1-1],161geompoints[hi2-1]);162}163else if (strcmp (buf, "3") == 0)164{ // a rational spline165infile >> hi1 >> hi2 >> hi3;166spline = new SplineSegment3 (geompoints[hi1-1],167geompoints[hi2-1],168geompoints[hi3-1]);169}170else if (strcmp (buf, "4") == 0)171{ // an arc172infile >> hi1 >> hi2 >> hi3;173spline = new CircleSegment (geompoints[hi1-1],174geompoints[hi2-1],175geompoints[hi3-1]);176break;177}178else if (strcmp (buf, "discretepoints") == 0)179{180int npts;181infile >> npts;182ARRAY<Point<2> > pts(npts);183for (int j = 0; j < npts; j++)184infile >> pts[j](0) >> pts[j](1);185186spline = new DiscretePointsSegment (pts);187cout << "pts = " << pts << endl;188}189190infile >> spline->reffak;191spline -> leftdom = leftdom;192spline -> rightdom = rightdom;193splines.Append (spline);194195196Flags flags;197ch = 'a';198infile >> ch;199while (ch == '-')200{201char flag[100];202flag[0]='-';203infile >> (flag+1);204flags.SetCommandLineFlag (flag);205ch = 'a';206infile >> ch;207}208209if (infile.good())210infile.putback (ch);211212splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));213splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||214int (flags.GetDefineFlag ("hprefleft"));215splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||216int (flags.GetDefineFlag ("hprefright"));217splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));218}219220cout << "load complete" << endl;221222infile.close();223}224225226227void SplineGeometry2d ::228PartitionBoundary (double h, Mesh & mesh2d)229{230Box<2> bbox;231GetBoundingBox (bbox);232double dist = Dist (bbox.PMin(), bbox.PMax());233Point<3> pmin(bbox.PMin()(0), bbox.PMin()(1), -dist);234Point<3> pmax(bbox.PMax()(0), bbox.PMax()(1), dist);235236cout << "searchtree from " << pmin << " to " << pmax << endl;237Point3dTree searchtree (pmin, pmax);238239for (int i = 0; i < splines.Size(); i++)240if (splines[i]->copyfrom == -1)241splines[i]->Partition(h, elto0, mesh2d, searchtree, i+1);242else243CopyEdgeMesh (splines[i]->copyfrom, i+1, mesh2d, searchtree);244}245246247void SplineGeometry2d :: CopyEdgeMesh (int from, int to, Mesh & mesh, Point3dTree & searchtree)248{249int i, j, k;250251ARRAY<int, PointIndex::BASE> mappoints (mesh.GetNP());252ARRAY<double, PointIndex::BASE> param (mesh.GetNP());253mappoints = -1;254param = 0;255256Point3d pmin, pmax;257mesh.GetBox (pmin, pmax);258double diam2 = Dist2(pmin, pmax);259260cout << "copy edge, from = " << from << " to " << to << endl;261262for (i = 1; i <= mesh.GetNSeg(); i++)263{264const Segment & seg = mesh.LineSegment(i);265if (seg.edgenr == from)266{267mappoints.Elem(seg.p1) = 1;268param.Elem(seg.p1) = seg.epgeominfo[0].dist;269270mappoints.Elem(seg.p2) = 1;271param.Elem(seg.p2) = seg.epgeominfo[1].dist;272}273}274275bool mapped = false;276for (i = 1; i <= mappoints.Size(); i++)277{278if (mappoints.Get(i) != -1)279{280Point<2> newp = splines.Get(to)->GetPoint (param.Get(i));281Point<3> newp3 (newp(0), newp(1), 0);282283int npi = -1;284285for (PointIndex pi = PointIndex::BASE;286pi < mesh.GetNP()+PointIndex::BASE; pi++)287if (Dist2 (mesh.Point(pi), newp3) < 1e-12 * diam2)288npi = pi;289290if (npi == -1)291{292npi = mesh.AddPoint (newp3);293searchtree.Insert (newp3, npi);294}295296mappoints.Elem(i) = npi;297298mesh.GetIdentifications().Add (i, npi, to);299mapped = trueM300}301}302if(mapped)303mesh.GetIdentifications().SetType(to,Identifications::PERIODIC);304305// copy segments306int oldnseg = mesh.GetNSeg();307for (i = 1; i <= oldnseg; i++)308{309const Segment & seg = mesh.LineSegment(i);310if (seg.edgenr == from)311{312Segment nseg;313nseg.edgenr = to;314nseg.si = splines.Get(to)->bc;315nseg.p1 = mappoints.Get(seg.p1);316nseg.p2 = mappoints.Get(seg.p2);317nseg.domin = splines.Get(to)->leftdom;318nseg.domout = splines.Get(to)->rightdom;319320nseg.epgeominfo[0].edgenr = to;321nseg.epgeominfo[0].dist = param.Get(seg.p1);322nseg.epgeominfo[1].edgenr = to;323nseg.epgeominfo[1].dist = param.Get(seg.p2);324mesh.AddSegment (nseg);325}326}327}328329330void SplineGeometry2d ::331GetBoundingBox (Box<2> & box) const332{333if (!splines.Size())334{335box.Set (Point<2> (0,0));336return;337}338339ARRAY<Point<2> > points;340for (int i = 0; i < splines.Size(); i++)341{342splines[i]->GetPoints (20, points);343344if (i == 0) box.Set(points[0]);345for (int j = 0; j < points.Size(); j++)346box.Add (points[j]);347}348}349350void SplineGeometry2d ::351SetGrading (const double grading)352{ elto0 = grading;}353354void SplineGeometry2d ::355AppendPoint (const double x, const double y, const double reffac, const bool hpref)356{357geompoints.Append (GeomPoint2d(x, y, reffac));358geompoints.Last().hpref = hpref;359}360361362void SplineGeometry2d ::363AppendSegment(SplineSegment * spline, const int leftdomain, const int rightdomain,364const int bc,365const double reffac, const bool hprefleft, const bool hprefright,366const int copyfrom)367{368spline -> leftdom = leftdomain;369spline -> rightdom = rightdomain;370spline -> bc = (bc >= 0) ? bc : (splines.Size()+1);371spline -> reffak = reffac;372spline -> hpref_left = hprefleft;373spline -> hpref_right = hprefright;374spline -> copyfrom = copyfrom;375376splines.Append(spline);377}378379void SplineGeometry2d ::380AppendLineSegment (const int n1, const int n2, const int leftdomain, const int rightdomain,381const int bc,382const double reffac, const bool hprefleft, const bool hprefright,383const int copyfrom)384{385SplineSegment * spline = new LineSegment(geompoints[n1],geompoints[n2]);386AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);387}388void SplineGeometry2d ::389AppendSplineSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,390const int bc,391const double reffac, const bool hprefleft, const bool hprefright,392const int copyfrom)393{394SplineSegment * spline = new SplineSegment3(geompoints[n1],geompoints[n2],geompoints[n3]);395AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);396}397void SplineGeometry2d ::398AppendCircleSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,399const int bc,400const double reffac, const bool hprefleft, const bool hprefright,401const int copyfrom)402{403SplineSegment * spline = new CircleSegment(geompoints[n1],geompoints[n2],geompoints[n3]);404AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);405}406void SplineGeometry2d ::407AppendDiscretePointsSegment (const ARRAY< Point<2> > & points, const int leftdomain, const int rightdomain,408const int bc,409const double reffac, const bool hprefleft, const bool hprefright,410const int copyfrom)411{412SplineSegment * spline = new DiscretePointsSegment(points);413AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);414}415416}417418419