Path: blob/devel/ElmerGUI/netgen/libsrc/geom2d/splinegeometry.cpp
3206 views
/*122d Spline curve for Mesh generator34*/567#include <mystdlib.h>8#include <csg.hpp>9#include <geometry2d.hpp>10#include "meshing.hpp"1112namespace netgen13{1415//using namespace netgen;1617template<int D>18void SplineGeometry<D> :: LoadDataV2 ( ifstream & infile )19{20PrintMessage (1, "Load 2D Geometry V2");21int nump, leftdom, rightdom;22Point<D> x;23int hi1, hi2, hi3;24double hd;25char buf[50], ch;26int pointnr;2728string keyword;2930ARRAY < GeomPoint<D> > infilepoints (0);31ARRAY <int> pointnrs (0);32nump = 0;33int numdomains = 0;343536TestComment ( infile );37// refinement factor38infile >> elto0;39TestComment ( infile );404142// test if next ch is a letter, i.e. new keyword starts43bool ischar = false;4445while ( infile.good() )46{47infile >> keyword;4849ischar = false;5051if ( keyword == "points" )52{53PrintMessage (3, "load points");54infile.get(ch);55infile.putback(ch);5657// test if ch is a letter58if ( int(ch) >= 65 && int(ch) <=90 )59ischar = true;60if ( int(ch) >= 97 && int(ch) <= 122 )61ischar = true;6263while ( ! ischar )64{65TestComment ( infile );66infile >> pointnr;67// pointnrs 1-based68if ( pointnr > nump ) nump = pointnr;69pointnrs.Append(pointnr);7071for(int j=0; j<D; j++)72infile >> x(j);73// hd is now optional, default 174// infile >> hd;75hd = 1;7677Flags flags;787980// get flags,81ch = 'a';82// infile >> ch;83do84{85infile.get (ch);86// if another int-value, set refinement flag to this value87// (corresponding to old files)88if ( int (ch) >= 48 && int(ch) <= 57 )89{90infile.putback(ch);91infile >> hd;92infile.get(ch);93}94}95while (isspace(ch) && ch != '\n');96while (ch == '-')97{98char flag[100];99flag[0]='-';100infile >> (flag+1);101flags.SetCommandLineFlag (flag);102ch = 'a';103do {104infile.get (ch);105} while (isspace(ch) && ch != '\n');106}107if (infile.good())108infile.putback (ch);109110if ( hd == 1 )111hd = flags.GetNumFlag ( "ref", 1.0);112// geompoints.Append (GeomPoint<D>(x, hd));113114infilepoints.Append ( GeomPoint<D>(x, hd) );115infilepoints.Last().hpref = flags.GetDefineFlag ("hpref");116117TestComment(infile);118infile.get(ch);119infile.putback(ch);120121// test if letter122if ( int(ch) >= 65 && int(ch) <=90 )123ischar = true;124if ( int(ch) >= 97 && int(ch) <= 122 )125ischar = true;126}127128// infile.putback (ch);129130geompoints.SetSize(nump);131for ( int i = 0; i < nump; i++ )132{133geompoints[pointnrs[i] - 1] = infilepoints[i];134geompoints[pointnrs[i] - 1].hpref = infilepoints[i].hpref;135}136TestComment(infile);137}138139else if ( keyword == "segments" )140{141PrintMessage (3, "load segments");142143bcnames.SetSize(0);144infile.get(ch);145infile.putback(ch);146int i = 0;147148// test if ch is a letter149if ( int(ch) >= 65 && int(ch) <=90 )150ischar = true;151if ( int(ch) >= 97 && int(ch) <= 122 )152ischar = true;153154while ( !ischar ) //ch != 'p' && ch != 'm' )155{156i++;157TestComment ( infile );158159SplineSeg<D> * spline = 0;160TestComment ( infile );161162infile >> leftdom >> rightdom;163164if ( leftdom > numdomains ) numdomains = leftdom;165if ( rightdom > numdomains ) numdomains = rightdom;166167168infile >> buf;169// type of spline segement170if (strcmp (buf, "2") == 0)171{ // a line172infile >> hi1 >> hi2;173spline = new LineSeg<D>(geompoints[hi1-1],174geompoints[hi2-1]);175}176else if (strcmp (buf, "3") == 0)177{ // a rational spline178infile >> hi1 >> hi2 >> hi3;179spline = new SplineSeg3<D> (geompoints[hi1-1],180geompoints[hi2-1],181geompoints[hi3-1]);182}183else if (strcmp (buf, "4") == 0)184{ // an arc185infile >> hi1 >> hi2 >> hi3;186spline = new CircleSeg<D> (geompoints[hi1-1],187geompoints[hi2-1],188geompoints[hi3-1]);189break;190}191else if (strcmp (buf, "discretepoints") == 0)192{193int npts;194infile >> npts;195ARRAY< Point<D> > pts(npts);196for (int j = 0; j < npts; j++)197for(int k=0; k<D; k++)198infile >> pts[j](k);199200spline = new DiscretePointsSeg<D> (pts);201}202203// infile >> spline->reffak;204spline -> leftdom = leftdom;205spline -> rightdom = rightdom;206splines.Append (spline);207208209// hd is now optional, default 1210// infile >> hd;211hd = 1;212infile >> ch;213214// get refinement parameter, if it is there215//infile.get (ch);216// if another int-value, set refinement flag to this value217// (corresponding to old files)218219if ( int (ch) >= 48 && int(ch) <= 57 )220{221infile.putback(ch);222infile >> hd;223infile >> ch ;224}225226// get flags,227Flags flags;228while (ch == '-')229{230char flag[100];231flag[0]='-';232infile >> (flag+1);233flags.SetCommandLineFlag (flag);234ch = 'a';235infile >> ch;236}237238if (infile.good())239infile.putback (ch);240241splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));242splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||243int (flags.GetDefineFlag ("hprefleft"));244splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||245int (flags.GetDefineFlag ("hprefright"));246splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));247splines.Last()->reffak = flags.GetNumFlag ("ref", 1 );248if ( hd != 1 )249splines.Last()->reffak = hd;250251if ( flags.StringFlagDefined("bcname") )252{253int mybc = splines.Last()->bc-1;254for ( int ii = bcnames.Size(); ii <= mybc; ii++ )255bcnames.Append ( new string ("default"));256if ( bcnames[mybc] ) delete bcnames[mybc];257bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );258}259260TestComment(infile);261infile.get(ch);262infile.putback(ch);263264// test if ch is a letter265if ( int(ch) >= 65 && int(ch) <=90 )266ischar = true;267if ( int(ch) >= 97 && int(ch) <= 122 )268ischar = true;269270}271272infile.get(ch);273infile.putback(ch);274275276}277else if ( keyword == "materials" )278{279TestComment ( infile );280int domainnr;281char material[100];282283if ( !infile.good() )284return;285286materials.SetSize(numdomains) ;287maxh.SetSize ( numdomains ) ;288for ( int i = 0; i < numdomains; i++)289maxh[i] = 1000;290quadmeshing.SetSize ( numdomains );291quadmeshing = false;292tensormeshing.SetSize ( numdomains );293tensormeshing = false;294295296TestComment ( infile );297298for ( int i=0; i<numdomains; i++)299materials [ i ] = new char[100];300301for ( int i=0; i<numdomains && infile.good(); i++)302{303TestComment ( infile );304infile >> domainnr;305infile >> material;306307strcpy (materials[domainnr-1], material);308309Flags flags;310ch = 'a';311infile >> ch;312while (ch == '-')313{314char flag[100];315flag[0]='-';316infile >> (flag+1);317flags.SetCommandLineFlag (flag);318ch = 'a';319infile >> ch;320}321322if (infile.good())323infile.putback (ch);324325maxh[domainnr-1] = flags.GetNumFlag ( "maxh", 1000);326if (flags.GetDefineFlag("quad")) quadmeshing[domainnr-1] = true;327if (flags.GetDefineFlag("tensor")) tensormeshing[domainnr-1] = true;328}329}330}331return;332}333334335336337338339340// check if comments in a .in2d file...341// template <int D>342// void SplineGeometry<D> :: TestComment ( ifstream & infile )343// {344// bool comment = true;345// char ch;346// infile.get(ch);347// infile.putback(ch);348// int ii = 0;349// while ( comment == true && ii < 100)350// {351// infile.get(ch);352// if ( ch == '#' )353// while ( ch != '\n')354// {355// infile.get(ch);356// comment = false;357// }358// else if ( ch == '\n' )359// {360// comment = true;361// ii ++;362// }363// else364// {365// infile.putback(ch);366// comment = false;367// }368//369// infile.get(ch) ;370// if ( ch == '\n' || ch == '#' )371// {372// comment = true;373// }374// infile.putback(ch);375// if ( !comment ) break;376// }377// cerr << "** comment done" << endl;378// cerr << " * last char was " << ch << endl;379// return;380//381// }382383// herbert: fixed TestComment384template <int D>385void SplineGeometry<D> :: TestComment ( ifstream & infile )386{387bool comment = true;388char ch;389while ( comment == true && !infile.eof() ) {390infile.get(ch);391if ( ch == '#' ) { // skip comments392while ( ch != '\n' && !infile.eof() ) {393infile.get(ch);394}395}396else if ( ch == '\n' ) { // skip empty lines397;398}399else if ( isspace(ch) ) { // skip whitespaces400;401}402else { // end of comment403infile.putback(ch);404comment = false;405}406}407return;408}409410411412template<int D>413SplineGeometry<D> :: ~SplineGeometry()414{415for(int i=0; i<splines.Size(); i++)416{417delete splines[i];418}419splines.DeleteAll();420geompoints.DeleteAll();421for (int i=0; i<materials.Size(); i++)422delete materials[i];423for ( int i = 0; i < bcnames.Size(); i++ )424if ( bcnames[i] ) delete bcnames[i];425}426427428429template<int D>430int SplineGeometry<D> :: Load (const ARRAY<double> & raw_data, const int startpos)431{432int pos = startpos;433if(raw_data[pos] != D)434throw NgException("wrong dimension of spline raw_data");435436pos++;437438elto0 = raw_data[pos]; pos++;439440splines.SetSize(int(raw_data[pos]));441pos++;442443ARRAY< Point<D> > pts(3);444445for(int i=0; i<splines.Size(); i++)446{447int type = int(raw_data[pos]);448pos++;449450for(int j=0; j<type; j++)451for(int k=0; k<D; k++)452{453pts[j](k) = raw_data[pos];454pos++;455}456457if (type == 2)458{459splines[i] = new LineSeg<D>(GeomPoint<D>(pts[0],1),460GeomPoint<D>(pts[1],1));461//(*testout) << "appending line segment "462// << pts[0] << " -- " << pts[1] << endl;463}464else if (type == 3)465{466splines[i] = new SplineSeg3<D>(GeomPoint<D>(pts[0],1),467GeomPoint<D>(pts[1],1),468GeomPoint<D>(pts[2],1));469//(*testout) << "appending spline segment "470// << pts[0] << " -- " << pts[1] << " -- " << pts[2] << endl;471472}473else474throw NgException("something wrong with spline raw data");475476}477return pos;478}479480template<int D>481void SplineGeometry<D> :: GetRawData (ARRAY<double> & raw_data) const482{483raw_data.Append(D);484raw_data.Append(elto0);485486487raw_data.Append(splines.Size());488for(int i=0; i<splines.Size(); i++)489splines[i]->GetRawData(raw_data);490491492}493494template<int D>495void SplineGeometry<D> :: CSGLoad (CSGScanner & scan)496{497double hd;498Point<D> x;499int nump, numseg;500501//scan.ReadNext();502scan >> nump >> ';';503504hd = 1;505geompoints.SetSize(nump);506for(int i = 0; i<nump; i++)507{508if(D==2)509scan >> x(0) >> ',' >> x(1) >> ';';510else if(D==3)511scan >> x(0) >> ',' >> x(1) >> ',' >> x(2) >> ';';512513geompoints[i] = GeomPoint<D>(x,hd);514}515516scan >> numseg;// >> ';';517518splines.SetSize(numseg);519520int pnums,pnum1,pnum2,pnum3;521522523for(int i = 0; i<numseg; i++)524{525scan >> ';' >> pnums >> ',';526if (pnums == 2)527{528scan >> pnum1 >> ',' >> pnum2;// >> ';';529splines[i] = new LineSeg<D>(geompoints[pnum1-1],530geompoints[pnum2-1]);531}532else if (pnums == 3)533{534scan >> pnum1 >> ',' >> pnum2 >> ','535>> pnum3;// >> ';';536splines[i] = new SplineSeg3<D>(geompoints[pnum1-1],537geompoints[pnum2-1],538geompoints[pnum3-1]);539}540else if (pnums == 4)541{542scan >> pnum1 >> ',' >> pnum2 >> ','543>> pnum3;// >> ';';544splines[i] = new CircleSeg<D>(geompoints[pnum1-1],545geompoints[pnum2-1],546geompoints[pnum3-1]);547548}549550}551}552553554555556template<int D>557void SplineGeometry<D> :: Load (const char * filename)558{559560ifstream infile;561Point<D> x;562char buf[50];563564565infile.open (filename);566567if ( ! infile.good() )568throw NgException(string ("Input file '") +569string (filename) +570string ("' not available!"));571572TestComment ( infile );573574infile >> buf; // file recognition575576tensormeshing.SetSize(0);577quadmeshing.SetSize(0);578579TestComment ( infile );580if ( strcmp (buf, "splinecurves2dnew") == 0 )581{582LoadDataNew ( infile );583}584else if ( strcmp (buf, "splinecurves2dv2") == 0 )585{586LoadDataV2 ( infile );587}588else589{590LoadData(infile );591}592infile.close();593}594595596template<int D>597void SplineGeometry<D> :: LoadDataNew ( ifstream & infile )598{599600int nump, numseg, leftdom, rightdom;601Point<D> x;602int hi1, hi2, hi3;603double hd;604char buf[50], ch;605int pointnr;606607608TestComment ( infile );609infile >> elto0;610TestComment ( infile );611612infile >> nump;613geompoints.SetSize(nump);614615for (int i = 0; i < nump; i++)616{617TestComment ( infile );618infile >> pointnr;619if ( pointnr > nump )620{621throw NgException(string ("Point number greater than total number of points") );622}623for(int j=0; j<D; j++)624infile >> x(j);625626627// hd is now optional, default 1628// infile >> hd;629hd = 1;630631Flags flags;632633634// get flags,635ch = 'a';636// infile >> ch;637do638{639640infile.get (ch);641// if another int-value, set refinement flag to this value642// (corresponding to old files)643if ( int (ch) >= 48 && int(ch) <= 57 )644{645infile.putback(ch);646infile >> hd;647infile.get(ch);648}649}650while (isspace(ch) && ch != '\n');651while (ch == '-')652{653char flag[100];654flag[0]='-';655infile >> (flag+1);656flags.SetCommandLineFlag (flag);657ch = 'a';658do {659infile.get (ch);660} while (isspace(ch) && ch != '\n');661}662663if (infile.good())664infile.putback (ch);665666if ( hd == 1 )667hd = flags.GetNumFlag ( "ref", 1.0);668// geompoints.Append (GeomPoint<D>(x, hd));669geompoints[pointnr-1] = GeomPoint<D>(x, hd);670geompoints[pointnr-1].hpref = flags.GetDefineFlag ("hpref");671}672673TestComment ( infile );674675infile >> numseg;676bcnames.SetSize(numseg);677for ( int i = 0; i < numseg; i++ )678bcnames[i] = 0;//new"default";679680SplineSeg<D> * spline = 0;681for (int i = 0; i < numseg; i++)682{683TestComment ( infile );684685infile >> leftdom >> rightdom;686687// cout << "add spline " << i << ", left = " << leftdom << endl;688689infile >> buf;690// type of spline segement691if (strcmp (buf, "2") == 0)692{ // a line693infile >> hi1 >> hi2;694spline = new LineSeg<D> (geompoints[hi1-1],695geompoints[hi2-1]);696}697else if (strcmp (buf, "3") == 0)698{ // a rational spline699infile >> hi1 >> hi2 >> hi3;700spline = new SplineSeg3<D> (geompoints[hi1-1],701geompoints[hi2-1],702geompoints[hi3-1]);703}704else if (strcmp (buf, "4") == 0)705{ // an arc706infile >> hi1 >> hi2 >> hi3;707spline = new CircleSeg<D> (geompoints[hi1-1],708geompoints[hi2-1],709geompoints[hi3-1]);710// break;711}712else if (strcmp (buf, "discretepoints") == 0)713{714int npts;715infile >> npts;716ARRAY< Point<D> > pts(npts);717for (int j = 0; j < npts; j++)718for(int k=0; k<D; k++)719infile >> pts[j](k);720721spline = new DiscretePointsSeg<D> (pts);722}723724// infile >> spline->reffak;725spline -> leftdom = leftdom;726spline -> rightdom = rightdom;727splines.Append (spline);728729// hd is now optional, default 1730// infile >> hd;731hd = 1;732infile >> ch;733734// get refinement parameter, if it is there735// infile.get (ch);736// if another int-value, set refinement flag to this value737// (corresponding to old files)738if ( int (ch) >= 48 && int(ch) <= 57 )739{740infile.putback(ch);741infile >> hd;742infile >> ch ;743}744745Flags flags;746while (ch == '-')747{748char flag[100];749flag[0]='-';750infile >> (flag+1);751flags.SetCommandLineFlag (flag);752ch = 'a';753infile >> ch;754}755756if (infile.good())757infile.putback (ch);758759splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));760splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||761int (flags.GetDefineFlag ("hprefleft"));762splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||763int (flags.GetDefineFlag ("hprefright"));764splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));765splines.Last()->reffak = flags.GetNumFlag ("ref", 1 );766767if ( flags.StringFlagDefined("bcname") )768{769int mybc = splines.Last()->bc-1;770if ( bcnames[mybc] ) delete bcnames[mybc];771bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );772}773774if ( hd != 1 )775splines.Last()->reffak = hd;776}777if ( !infile.good() )778return;779TestComment ( infile );780int numdomains;781int domainnr;782char material[100];783784if ( !infile.good() )785return;786787infile >> numdomains;788materials.SetSize(numdomains) ;789maxh.SetSize ( numdomains ) ;790for ( int i = 0; i < numdomains; i++)791maxh[i] = 1000;792793TestComment ( infile );794795for ( int i=0; i<numdomains; i++)796materials [ i ] = new char (100);797798for ( int i=0; i<numdomains && infile.good(); i++)799{800TestComment ( infile );801infile >> domainnr;802infile >> material;803strcpy(materials[domainnr-1], material);804805Flags flags;806ch = 'a';807infile >> ch;808while (ch == '-')809{810char flag[100];811flag[0]='-';812infile >> (flag+1);813flags.SetCommandLineFlag (flag);814ch = 'a';815infile >> ch;816}817818if (infile.good())819infile.putback (ch);820821maxh[domainnr-1] = flags.GetNumFlag ( "maxh", 1000);822}823return;824}825826827828template<int D>829void SplineGeometry<D> :: LoadData ( ifstream & infile )830{831832int nump, numseg, leftdom, rightdom;833Point<D> x;834int hi1, hi2, hi3;835double hd;836char buf[50], ch;837838materials.SetSize(0);839maxh.SetSize(0);840infile >> elto0;841842TestComment ( infile );843844infile >> nump;845for (int i = 0; i < nump; i++)846{847TestComment ( infile );848for(int j=0; j<D; j++)849infile >> x(j);850infile >> hd;851852Flags flags;853854ch = 'a';855// infile >> ch;856do {857infile.get (ch);858} while (isspace(ch) && ch != '\n');859while (ch == '-')860{861char flag[100];862flag[0]='-';863infile >> (flag+1);864flags.SetCommandLineFlag (flag);865ch = 'a';866do {867infile.get (ch);868} while (isspace(ch) && ch != '\n');869}870871if (infile.good())872infile.putback (ch);873874geompoints.Append (GeomPoint<D>(x, hd));875geompoints.Last().hpref = flags.GetDefineFlag ("hpref");876}877878PrintMessage (3, nump, " points loaded");879TestComment ( infile );880881infile >> numseg;882bcnames.SetSize(numseg);883for ( int i = 0; i < numseg; i++ )884bcnames[i] = 0; // "default";885886SplineSeg<D> * spline = 0;887888PrintMessage (3, numseg, " segments loaded");889for (int i = 0; i < numseg; i++)890{891TestComment ( infile );892893infile >> leftdom >> rightdom;894895// cout << "add spline " << i << ", left = " << leftdom << ", right = " << rightdom << endl;896897infile >> buf;898// type of spline segement899if (strcmp (buf, "2") == 0)900{ // a line901infile >> hi1 >> hi2;902spline = new LineSeg<D>(geompoints[hi1-1],903geompoints[hi2-1]);904}905else if (strcmp (buf, "3") == 0)906{ // a rational spline907infile >> hi1 >> hi2 >> hi3;908spline = new SplineSeg3<D> (geompoints[hi1-1],909geompoints[hi2-1],910geompoints[hi3-1]);911}912else if (strcmp (buf, "4") == 0)913{ // an arc914infile >> hi1 >> hi2 >> hi3;915spline = new CircleSeg<D> (geompoints[hi1-1],916geompoints[hi2-1],917geompoints[hi3-1]);918// break;919}920else if (strcmp (buf, "discretepoints") == 0)921{922int npts;923infile >> npts;924ARRAY< Point<D> > pts(npts);925for (int j = 0; j < npts; j++)926for(int k=0; k<D; k++)927infile >> pts[j](k);928929spline = new DiscretePointsSeg<D> (pts);930}931932infile >> spline->reffak;933spline -> leftdom = leftdom;934spline -> rightdom = rightdom;935splines.Append (spline);936937938Flags flags;939ch = 'a';940infile >> ch;941while (ch == '-')942{943char flag[100];944flag[0]='-';945infile >> (flag+1);946flags.SetCommandLineFlag (flag);947ch = 'a';948infile >> ch;949}950951if (infile.good())952infile.putback (ch);953954splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));955splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||956int (flags.GetDefineFlag ("hprefleft"));957splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||958int (flags.GetDefineFlag ("hprefright"));959splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));960if ( flags.StringFlagDefined("bcname") )961{962int mybc = splines.Last()->bc-1;963if ( bcnames[mybc] ) delete bcnames[mybc];964bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );965}966}967}968969970971template<int D>972void SplineGeometry<D> :: PartitionBoundary (double h, Mesh & mesh2d)973{974Box<D> bbox;975GetBoundingBox (bbox);976double dist = Dist (bbox.PMin(), bbox.PMax());977Point<3> pmin;978Point<3> pmax;979980pmin(2) = -dist; pmax(2) = dist;981for(int j=0;j<D;j++)982{983pmin(j) = bbox.PMin()(j);984pmax(j) = bbox.PMax()(j);985}986987988if (printmessage_importance>0)989cout << "searchtree from " << pmin << " to " << pmax << endl;990Point3dTree searchtree (pmin, pmax);991992for (int i = 0; i < splines.Size(); i++)993if (splines[i]->copyfrom == -1)994{995// astrid - set boundary meshsize to domain meshsize h996// if no domain mesh size is given, the max h value from the bounding box is used997double minimum = min2 ( GetDomainMaxh ( splines[i]->leftdom ), GetDomainMaxh ( splines[i]->rightdom ) );998double maximum = max2 ( GetDomainMaxh ( splines[i]->leftdom ), GetDomainMaxh ( splines[i]->rightdom ) );999minimum = min2 ( minimum, h );1000maximum = min2 ( maximum, h);1001if ( minimum > 0 )1002splines[i]->Partition(minimum, elto0, mesh2d, searchtree, i+1);1003else if ( maximum > 0 )1004splines[i]->Partition(maximum, elto0, mesh2d, searchtree, i+1);1005else1006splines[i]->Partition(h, elto0, mesh2d, searchtree, i+1);1007}1008else1009{1010CopyEdgeMesh (splines[i]->copyfrom, i+1, mesh2d, searchtree);1011}1012}101310141015template<int D>1016void SplineGeometry<D> :: CopyEdgeMesh (int from, int to, Mesh & mesh, Point3dTree & searchtree)1017{1018int i;10191020ARRAY<int, PointIndex::BASE> mappoints (mesh.GetNP());1021ARRAY<double, PointIndex::BASE> param (mesh.GetNP());1022mappoints = -1;1023param = 0;10241025Point3d pmin, pmax;1026mesh.GetBox (pmin, pmax);1027double diam2 = Dist2(pmin, pmax);10281029if (printmessage_importance>0)1030cout << "copy edge, from = " << from << " to " << to << endl;10311032for (i = 1; i <= mesh.GetNSeg(); i++)1033{1034const Segment & seg = mesh.LineSegment(i);1035if (seg.edgenr == from)1036{1037mappoints.Elem(seg.p1) = 1;1038param.Elem(seg.p1) = seg.epgeominfo[0].dist;10391040mappoints.Elem(seg.p2) = 1;1041param.Elem(seg.p2) = seg.epgeominfo[1].dist;1042}1043}10441045bool mapped = false;1046for (i = 1; i <= mappoints.Size(); i++)1047{1048if (mappoints.Get(i) != -1)1049{1050Point<D> newp = splines.Get(to)->GetPoint (param.Get(i));1051Point<3> newp3;1052for(int j=0; j<min2(D,3); j++)1053newp3(j) = newp(j);1054for(int j=min2(D,3); j<3; j++)1055newp3(j) = 0;10561057int npi = -1;10581059for (PointIndex pi = PointIndex::BASE;1060pi < mesh.GetNP()+PointIndex::BASE; pi++)1061if (Dist2 (mesh.Point(pi), newp3) < 1e-12 * diam2)1062npi = pi;10631064if (npi == -1)1065{1066npi = mesh.AddPoint (newp3);1067searchtree.Insert (newp3, npi);1068}10691070mappoints.Elem(i) = npi;10711072mesh.GetIdentifications().Add (i, npi, to);1073mapped = true;1074}1075}1076if(mapped)1077mesh.GetIdentifications().SetType(to,Identifications::PERIODIC);10781079// copy segments1080int oldnseg = mesh.GetNSeg();1081for (i = 1; i <= oldnseg; i++)1082{1083const Segment & seg = mesh.LineSegment(i);1084if (seg.edgenr == from)1085{1086Segment nseg;1087nseg.edgenr = to;1088nseg.si = splines.Get(to)->bc;1089nseg.p1 = mappoints.Get(seg.p1);1090nseg.p2 = mappoints.Get(seg.p2);1091nseg.domin = splines.Get(to)->leftdom;1092nseg.domout = splines.Get(to)->rightdom;10931094nseg.epgeominfo[0].edgenr = to;1095nseg.epgeominfo[0].dist = param.Get(seg.p1);1096nseg.epgeominfo[1].edgenr = to;1097nseg.epgeominfo[1].dist = param.Get(seg.p2);1098mesh.AddSegment (nseg);1099}1100}1101}110211031104template<int D>1105void SplineGeometry<D> :: GetBoundingBox (Box<D> & box) const1106{1107if (!splines.Size())1108{1109Point<D> auxp = 0.;1110box.Set (auxp);1111return;1112}11131114ARRAY<Point<D> > points;1115for (int i = 0; i < splines.Size(); i++)1116{1117splines[i]->GetPoints (20, points);11181119if (i == 0) box.Set(points[0]);1120for (int j = 0; j < points.Size(); j++)1121box.Add (points[j]);1122}1123}11241125template<int D>1126void SplineGeometry<D> :: SetGrading (const double grading)1127{ elto0 = grading;}11281129template<int D>1130void SplineGeometry<D> :: AppendPoint (const double x, const double y, const double reffac, const bool hpref)1131{1132geompoints.Append (GeomPoint<D>(x, y, reffac));1133geompoints.Last().hpref = hpref;1134}11351136template<int D>1137void SplineGeometry<D> :: AppendPoint (const Point<D> & p, const double reffac, const bool hpref)1138{1139geompoints.Append (GeomPoint<D>(p, reffac));1140geompoints.Last().hpref = hpref;1141}11421143114411451146template<int D>1147void SplineGeometry<D> :: AppendSegment(SplineSeg<D> * spline, const int leftdomain, const int rightdomain,1148const int bc,1149const double reffac, const bool hprefleft, const bool hprefright,1150const int copyfrom)1151{1152spline -> leftdom = leftdomain;1153spline -> rightdom = rightdomain;1154spline -> bc = (bc >= 0) ? bc : (splines.Size()+1);1155spline -> reffak = reffac;1156spline -> hpref_left = hprefleft;1157spline -> hpref_right = hprefright;1158spline -> copyfrom = copyfrom;11591160splines.Append(spline);1161}11621163template<int D>1164void SplineGeometry<D> :: AppendLineSegment (const int n1, const int n2, const int leftdomain, const int rightdomain,1165const int bc,1166const double reffac, const bool hprefleft, const bool hprefright,1167const int copyfrom)1168{1169SplineSeg<D> * spline = new LineSeg<D>(geompoints[n1],geompoints[n2]);1170AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);1171}11721173template<int D>1174void SplineGeometry<D> :: AppendSplineSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,1175const int bc,1176const double reffac, const bool hprefleft, const bool hprefright,1177const int copyfrom)1178{1179SplineSeg<D> * spline = new SplineSeg3<D>(geompoints[n1],geompoints[n2],geompoints[n3]);1180AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);1181}11821183template<int D>1184void SplineGeometry<D> :: AppendCircleSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,1185const int bc,1186const double reffac, const bool hprefleft, const bool hprefright,1187const int copyfrom)1188{1189SplineSeg<D> * spline = new CircleSeg<D>(geompoints[n1],geompoints[n2],geompoints[n3]);1190AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);1191}11921193template<int D>1194void SplineGeometry<D> :: AppendDiscretePointsSegment (const ARRAY< Point<D> > & points, const int leftdomain, const int rightdomain,1195const int bc,1196const double reffac, const bool hprefleft, const bool hprefright,1197const int copyfrom)1198{1199SplineSeg<D> * spline = new DiscretePointsSeg<D>(points);1200AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);1201}120212031204template<int D>1205void SplineGeometry<D> :: GetMaterial( const int domnr, char* & material )1206{1207if ( materials.Size() >= domnr)1208material = materials[domnr-1];1209else material = 0;1210return;1211}1212121312141215template<int D>1216double SplineGeometry<D> :: GetDomainMaxh( const int domnr )1217{1218if ( maxh.Size() >= domnr && domnr > 0)1219return maxh[domnr-1];1220else1221return -1;1222}122312241225template<int D>1226string SplineGeometry<D> :: GetBCName( const int bcnr ) const1227{1228string bcname;1229if ( bcnames.Size() >= bcnr)1230if ( bcnames[bcnr-1] )1231bcname = *bcnames[bcnr-1];1232else bcname = "default";1233return bcname;1234}12351236template<int D>1237string * SplineGeometry<D> :: BCNamePtr( const int bcnr )1238{1239if ( bcnr > bcnames.Size() )1240return 0;1241else1242return bcnames[bcnr-1];1243}1244124512461247template class SplineGeometry<2>;1248template class SplineGeometry<3>;1249}12501251125212531254