Changeset 3301
- Timestamp:
- 03/18/10 14:19:34 (15 years ago)
- Location:
- issm/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/Bamgx.cpp
r3283 r3301 16 16 17 17 /*Bamg options*/ 18 double anisomax;19 18 int maxnbv; 20 double hmin,hmax; 21 double coef,maxsubdiv; 19 double coef; 22 20 int verbosity; 23 21 int NbSmooth; 24 double omega;25 22 26 23 /*intermediary*/ 27 24 int noerr=1; 28 25 int i,j,num; 29 int allquad=0;30 26 double costheta=2; 31 27 double hminaniso=1e-100; … … 35 31 36 32 /*Bamg options*/ 37 anisomax=bamgopts->anisomax;38 33 NbSmooth=bamgopts->NbSmooth; 39 omega=bamgopts->omega;40 34 coef=bamgopts->coef; 41 35 maxnbv=bamgopts->maxnbv; 42 maxsubdiv=bamgopts->maxsubdiv;43 hmin=bamgopts->hmin;44 hmax=bamgopts->hmax;45 36 verbosity=bamgopts->verbose; 46 37 … … 55 46 /*Mesh generation {{{1*/ 56 47 48 //Step1: generate geometry Gh 57 49 if (verbosity>0) printf("Construction of a mesh from a given geometry\n"); 58 50 if (verbosity>1) printf(" Processing geometry...\n"); 59 51 Geometry Gh(bamggeom_in,bamgopts); 60 if (verbosity>10){61 Gh.Echo();62 }63 52 64 53 //get hmin and hmax from geometry to generate the metric 65 hmin = Max(hmin,Gh.MinimalHmin());66 hmax = Min(hmax,Gh.MaximalHmax());67 68 //build metric if not given in input54 bamgopts->hmin = Max(bamgopts->hmin,Gh.MinimalHmin()); 55 bamgopts->hmax = Min(bamgopts->hmax,Gh.MaximalHmax()); 56 57 //build metric using geometry 69 58 if (verbosity>1) printf(" Generating Metric...\n"); 70 59 for(i=0;i<Gh.nbv;i++){ 71 60 Metric M=Gh[i]; 72 61 MatVVP2x2 Vp(M/coef); 73 Vp.Maxh( hmax);74 Vp.Minh( hmin);62 Vp.Maxh(bamgopts->hmax); 63 Vp.Minh(bamgopts->hmin); 75 64 Gh.vertices[i].m = Vp; 76 65 } … … 79 68 if (verbosity>1) printf(" Generating Mesh...\n"); 80 69 Triangles Th(maxnbv,Gh,bamgopts); 70 71 //Split corners if requested 81 72 if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices(); 73 74 //Renumbering 82 75 Th.ReNumberingTheTriangleBySubDomain(); 83 76 … … 101 94 if (verbosity>1) printf(" Processing initial mesh and geometry...\n"); 102 95 Triangles BTh(bamggeom_in,bamgmesh_in,bamgopts); 103 hmin=Max(hmin,BTh.MinimalHmin());104 hmax=Min(hmax,BTh.MaximalHmax());105 96 106 97 //Make Quadtree from background mesh 107 98 BTh.MakeQuadTree(); 108 99 109 //build metric if not given in input 100 //Bound hmin and hmax 101 bamgopts->hmin=Max(bamgopts->hmin,BTh.MinimalHmin()); 102 bamgopts->hmax=Min(bamgopts->hmax,BTh.MaximalHmax()); 103 104 //Generate initial metric 110 105 if (bamgopts->metric){ 111 106 if (verbosity>1) printf(" Processing Metric...\n"); 112 BTh.ReadMetric(bamgopts ,hmin,hmax,coef);107 BTh.ReadMetric(bamgopts); 113 108 } 114 109 else { 115 116 // init with hmax 117 Metric Mhmax(hmax); 110 if (verbosity>1) printf(" Generating initial Metric...\n"); 111 Metric Mhmax(bamgopts->hmax); 118 112 for (int iv=0;iv<BTh.nbv;iv++) BTh[iv].m = Mhmax; 119 // change using hVertices if required 120 if (bamgmesh_in->hVertices){ 121 for (i=0;i<BTh.nbv;i++){ 122 if (!isnan(bamgmesh_in->hVertices[i])){ 123 BTh[i].m=Metric((float)bamgmesh_in->hVertices[i]); 124 } 113 } 114 115 //use present fields to generate metric if present 116 if (bamgopts->field){ 117 if (verbosity>1) printf(" Merge metric with field provided...\n"); 118 BTh.AddMetric(bamgopts); 119 } 120 121 // change using hVertices if provided 122 if (bamgmesh_in->hVertices){ 123 if (verbosity>1) printf(" Merging Metric with hVertices...\n"); 124 for (i=0;i<BTh.nbv;i++){ 125 if (!isnan(bamgmesh_in->hVertices[i])){ 126 BTh[i].m=Metric((float)bamgmesh_in->hVertices[i]); 125 127 } 126 127 } 128 129 //use present fields to generate metric if present 130 if (bamgopts->field){ 131 if (verbosity>1) printf(" Generating Metric from solution field...\n"); 132 BTh.AddMetric(bamgopts); 133 } 134 } 135 136 BTh.AddGeometryMetric(bamgopts); 137 if (verbosity>1) printf(" Smoothing Metric..."); 138 if(bamgopts->gradation) BTh.SmoothMetric(bamgopts->gradation); 139 if (verbosity>1) printf(" done\n"); 140 BTh.MaxSubDivision(maxsubdiv); 141 BTh.BoundAnisotropy(anisomax,hminaniso); 142 143 //Build new mesh Thr 128 } 129 } 130 131 // change using hminVertices if provided 132 if (bamgopts->hminVertices){ 133 if (verbosity>1) printf(" Merging Metric with hminVertices...\n"); 134 for (i=0;i<BTh.nbv;i++){ 135 if (!isnan(bamgopts->hminVertices[i])){ 136 Metric M=BTh.vertices[i].m; 137 MatVVP2x2 Vp(M/coef); 138 Vp.Minh(bamgopts->hminVertices[i]); 139 BTh.vertices[i].m=Vp; 140 } 141 } 142 } 143 144 // change using hmaxVertices if provided 145 if (bamgopts->hmaxVertices){ 146 if (verbosity>1) printf(" Merging Metric with hmaxVertices...\n"); 147 for (i=0;i<BTh.nbv;i++){ 148 if (!isnan(bamgopts->hmaxVertices[i])){ 149 Metric M=BTh.vertices[i].m; 150 MatVVP2x2 Vp(M/coef); 151 Vp.Minh(bamgopts->hmaxVertices[i]); 152 BTh.vertices[i].m=Vp; 153 } 154 } 155 } 156 157 //Add geometry metric if provided 158 if(bamgopts->geometricalmetric) BTh.AddGeometryMetric(bamgopts); 159 160 //Smoothe metric 161 BTh.SmoothMetric(bamgopts->gradation); 162 163 //Control element subdivision 164 BTh.MaxSubDivision(bamgopts->maxsubdiv); 165 166 //Bound anisotropy 167 BTh.BoundAnisotropy(bamgopts->anisomax,hminaniso); 168 169 //Build new mesh 144 170 if (verbosity>1) printf(" Generating Mesh...\n"); 145 171 Thr=&BTh,Thb=0; 146 172 Triangles & Th( *(0 ? new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) : new Triangles(maxnbv,BTh,bamgopts,bamgopts->KeepVertices))); 147 173 if (Thr != &BTh) delete Thr; 174 175 //Make quadrangle if requested 148 176 if(costheta<=1.0) Th.MakeQuadrangles(costheta); 149 if (allquad) Th.SplitElement(allquad==2); 177 //if () Th.SplitElement(2); 178 179 //Split corners if requested 150 180 if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices(); 181 182 //Renumber by subdomain 151 183 Th.ReNumberingTheTriangleBySubDomain(); 152 if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,omega); 184 185 //Smooth vertices 186 if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,bamgopts->omega); 153 187 154 188 //display info -
issm/trunk/src/c/Bamgx/objects/GeometricalEdge.cpp
r3263 r3301 25 25 double dca,dcb,dcta,dctb; 26 26 double ddca,ddcb,ddcta,ddctb; 27 // double t1 = 1 -theta;28 // double t1t1 = t1*t1;29 27 double tt = theta*theta; 30 if ( theta<0){ 31 throw ErrorException(__FUNCT__,exprintf("theta<0")); 28 29 //check theta 30 assert(theta>=0 && theta<=1); 31 32 if (TgA()){ 33 if (TgB()){ 34 // Tangent A and B provided: 35 // interpolation d'hermite 36 dcb = 6*theta*(1-theta); 37 ddcb = 6*(1-2*theta); 38 dca = -dcb; 39 ddca = -ddcb; 40 dcta = (3*theta - 4)*theta + 1; 41 ddcta=6*theta-4; 42 dctb = 3*tt - 2*theta; 43 ddctb = 6*theta-2; 44 } 45 else { 46 //Tangent A provided but tangent B not provided 47 // 1-t*t, t-t*t, t*t 48 double t = theta; 49 dcb = 2*t; 50 ddcb = 2; 51 dca = -dcb; 52 ddca = -2; 53 dcta = 1-dcb; 54 ddcta = -ddcb; 55 dctb=0; 56 ddctb=0; 57 } 32 58 } 33 if ( theta>1){ 34 throw ErrorException(__FUNCT__,exprintf("theta>1")); 59 else{ 60 if (TgB()){ 61 //Tangent B provided but tangent A not provided 62 double t = 1-theta; 63 dca = -2*t; 64 ddca = 2; 65 dcb = -dca; 66 ddcb = -2; 67 dctb = 1+dca; 68 ddctb= ddca; 69 dcta =0; 70 ddcta =0; 71 } 72 else { 73 //Neither thangent A nor tangent B provided 74 // lagrange P1 75 t=B-A; 76 return 0; 77 } 35 78 } 36 if (TgA()) 37 if (TgB()) // interpolation d'hermite 38 { //cb = theta*theta*(3-2*theta); 39 dcb = 6*theta*(1-theta); 40 ddcb = 6*(1-2*theta); 41 //ca = 1-cb; 42 dca = -dcb; 43 ddca = -ddcb; 44 45 // cta = (1-theta)*(1-theta)*theta; 46 dcta = (3*theta - 4)*theta + 1; 47 ddcta=6*theta-4; 48 49 //ctb = (theta-1)*theta*theta ; 50 dctb = 3*tt - 2*theta; 51 ddctb = 6*theta-2; 52 } 53 else { // 1-t*t, t-t*t, t*t 54 double t = theta; 55 // cb = t*t; 56 dcb = 2*t; 57 ddcb = 2; 58 //ca = 1-cb; 59 dca = -dcb; 60 ddca = -2; 61 // cta= t-cb; 62 dcta = 1-dcb; 63 ddcta = -ddcb; 64 // ctb =0; 65 dctb=0; 66 ddctb=0; 67 } 68 else 69 if (TgB()){ 70 double t = 1-theta; 71 //ca = t*t; 72 dca = -2*t; 73 ddca = 2; 74 //cb = 1-ca; 75 dcb = -dca; 76 ddcb = -2; 77 //ctb= -t+ca; 78 dctb = 1+dca; 79 ddctb= ddca; 80 //cta=0; 81 dcta =0; 82 ddcta =0; 83 } 84 else {t=B-A;return 0;} // lagrange P1 85 R2 d = A*dca + B*dcb + tg[0]* dcta + tg[1] * dctb; 86 79 R2 d = A*dca + B*dcb + tg[0]* dcta + tg[1] * dctb; 87 80 R2 dd = A*ddca + B*ddcb + tg[0]* ddcta + tg[1] * ddctb; 88 81 double d2=(d,d); 89 82 double sd2 = sqrt(d2); 90 83 t=d; 91 if(d2>1.0e-20) {t/=sd2;return Abs(Det(d,dd))/(d2*sd2);} 84 if(d2>1.0e-20){ 85 t/=sd2; 86 return Abs(Det(d,dd))/(d2*sd2); 87 } 92 88 else return 0; 93 89 } 94 90 /*}}}1*/ 95 91 /*FUNCTION GeometricalEdge::F{{{1*/ -
issm/trunk/src/c/Bamgx/objects/Geometry.cpp
r3299 r3301 742 742 // generation of all the tangents 743 743 for (i=0;i<nbe;i++) { 744 745 744 //Get AB = vertex1->vertex2 746 745 R2 AB =edges[i].v[1]->r -edges[i].v[0]->r; … … 748 747 double lAB=Norme2(AB); 749 748 //initialize tangent 750 double ltg2[2]; 751 ltg2[0]=0;ltg2[1]=0; 749 double ltg2[2]={0.0}; 752 750 753 751 //loop over the 2 vertices of the edge 754 752 for (jj=0;jj<2;jj++) { 755 R2 tg =edges[i].tg[jj];753 R2 tg =edges[i].tg[jj]; 756 754 double ltg=Norme2(tg); 757 755 … … 760 758 //if the current vertex of the edge is not a corner 761 759 if(!edges[i].v[jj]->Corner()){ 762 tg = edges[i].v[1-jj]->r - edges[i].Adj[jj]->v[1-edges[i].DirAdj[jj]]->r; 763 ltg= Norme2(tg); 764 tg = tg *(lAB/ltg),ltg=lAB; 760 tg = edges[i].v[1-jj]->r - edges[i].Adj[jj]->v[1-edges[i].DirAdj[jj]]->r; //previous point and next point on curve 761 ltg= Norme2(tg); 762 tg = tg *(lAB/ltg); 763 ltg= lAB; 765 764 } 766 765 //else: a Corner with no tangent => nothing to do 767 766 } 768 767 else{ 769 tg = tg *(lAB/ltg),ltg=lAB; 770 } 768 //tangent has already been computed 769 tg = tg*(lAB/ltg),ltg=lAB; 770 } 771 771 772 ltg2[jj] = ltg; 772 if ((tg,AB)<0) tg = -tg; 773 774 if ((tg,AB)<0){ 775 tg = -tg; 776 } 777 773 778 edges[i].tg[jj] = tg; 774 779 } -
issm/trunk/src/c/Bamgx/objects/Triangles.cpp
r3300 r3301 822 822 /*}}}1*/ 823 823 /*FUNCTION Triangles::ReadMetric{{{1*/ 824 void Triangles::ReadMetric(BamgOpts* bamgopts,const double hmin1=1.0e-30,const double hmax1=1.0e30,const double coef=1) { 824 void Triangles::ReadMetric(const BamgOpts* bamgopts) { 825 826 /*Intermediary*/ 825 827 int i,j; 826 828 827 829 if(bamgopts->verbose>3) printf(" processing metric\n"); 828 829 double hm in = Max(hmin1,MinimalHmin());830 double hmax = Min(hmax1,MaximalHmax());830 double hmin = Max(bamgopts->hmin,MinimalHmin()); 831 double hmax = Min(bamgopts->hmax,MaximalHmax()); 832 double coef = bamgopts->coef; 831 833 832 834 //for now we only use j==3 … … 904 906 Gh.ProjectOnCurve(edges[i],ss[j],V,GV); 905 907 906 GeometricalEdge 908 GeometricalEdge* eg = GV; 907 909 double s = GV; 908 910 R2 tg; … … 914 916 } 915 917 double hn=Min(hmax,ht*anisomax); 918 916 919 if (ht<=0 || hn<=0){ 917 920 throw ErrorException(__FUNCT__,exprintf("ht<=0 || hn<=0")); … … 4418 4421 } 4419 4422 } 4420 if (quadtree) {delete quadtree; 4423 if (quadtree){ 4424 delete quadtree; 4421 4425 quadtree = new QuadTree(this); 4422 4426 } 4423 4427 4424 4428 for ( it=0;it<nbv;it++) renu[i]= -renu[i]-1; 4425 printf("end renumbervertex\n");4426 4429 } 4427 4430 /*}}}1*/ -
issm/trunk/src/c/Bamgx/objects/Triangles.h
r3280 r3301 136 136 void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts); 137 137 void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts); 138 void ReadMetric( BamgOpts* bamgopts,const double hmin,const double hmax,const double coef);138 void ReadMetric(const BamgOpts* bamgopts); 139 139 void WriteMetric(BamgOpts* bamgopts); 140 140 void AddMetric(BamgOpts* bamgopts); -
issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
r3263 r3301 11 11 #include "../toolkits/toolkits.h" 12 12 13 /*Bamg: */14 #include <unistd.h>15 #include <stdlib.h>16 #include <stdio.h>17 #include <string.h>18 13 #include "../Bamgx/objects/BamgObjects.h" 19 14 -
issm/trunk/src/c/objects/BamgOpts.cpp
r3279 r3301 19 19 bamgopts->hmin=0; 20 20 bamgopts->hmax=0; 21 bamgopts->hminVertices=NULL; 22 bamgopts->hmaxVertices=NULL; 21 23 bamgopts->gradation=0; 22 24 bamgopts->cutoff=0; 23 25 bamgopts->splitcorners=0; 26 bamgopts->geometricalmetric=0; 24 27 bamgopts->verbose=0; 25 28 bamgopts->err=NULL; … … 43 46 if (bamgopts->errg<0) throw ErrorException(__FUNCT__,exprintf("'errg' option should be >0")); 44 47 if (bamgopts->nbjacobi<=0) throw ErrorException(__FUNCT__,exprintf("'nbjacobi' option should be >0")); 48 if (bamgopts->geometricalmetric!=0 && bamgopts->geometricalmetric!=1) throw ErrorException(__FUNCT__,exprintf("'geometricalmetric' supported options are 0 and 1")); 45 49 if (bamgopts->NbSmooth<=0) throw ErrorException(__FUNCT__,exprintf("'NbSmooth' option should be >0")); 46 50 if (bamgopts->maxnbv<3) throw ErrorException(__FUNCT__,exprintf("'maxnbv' option should be >3")); -
issm/trunk/src/c/objects/BamgOpts.h
r3277 r3301 22 22 double hmin; 23 23 double hmax; 24 double* hminVertices; 25 double* hmaxVertices; 24 26 double gradation; 25 27 double cutoff; 26 28 int splitcorners; 29 int geometricalmetric; 27 30 int verbose; 28 double* 29 double 31 double* err; 32 double errg; 30 33 double coef; 31 34 double* metric; -
issm/trunk/src/m/classes/public/bamg.m
r3293 r3301 4 4 % Available options (for more details see ISSM website http://issm.jpl.nasa.gov/): 5 5 % 6 % - domain : followed by an ARGUS file that prescribes the domain outline (rifts and holes) 7 % - hmin : minimum edge length (default is 10^-100) 8 % - hmax : maximum esge length (default is 10^100) 9 % - hVertices : imposed edge length for each vertex (geometry or mesh) 6 % - domain: followed by an ARGUS file that prescribes the domain outline (rifts and holes) 7 % - hmin : minimum edge length (default is 10^-100) 8 % - hmax : maximum esge length (default is 10^100) 9 % - hVertices : imposed edge length for each vertex (geometry or mesh) 10 % - hminVertices: minimum edge length for each vertex (mesh) 11 % - hmaxVertices: maximum edge length for each vertex (mesh) 10 12 % 11 13 % - anisomax : maximum ration between the smallest and largest edges (default is 10^30) … … 31 33 % - omega : relaxation parameter of the smoothing procedure (default is 1.8) 32 34 % - power : power applied to the metric (default is 1) 33 % - splitcorner : split triangles whuch have 3 vertices on the outline (default is 1) 35 % - splitcorners : split triangles whuch have 3 vertices on the outline (default is 1) 36 % - geometricalmetric : Take the geometry into account to generate the metric (default is 0) 34 37 % - verbose : level of verbosity (default is 1) 35 38 % … … 227 230 bamg_options.hmin=getfieldvalue(options,'hmin',10^-100); 228 231 bamg_options.hmax=getfieldvalue(options,'hmax',10^100); 232 bamg_options.hminVertices=getfieldvalue(options,'hminVertices',[]); 233 bamg_options.hmaxVertices=getfieldvalue(options,'hmaxVertices',[]); 229 234 bamg_options.KeepVertices=getfieldvalue(options,'KeepVertices',1); 230 235 bamg_options.MaximalAngleOfCorner=getfieldvalue(options,'MaximalAngleOfCorner',10); … … 238 243 bamg_options.power=getfieldvalue(options,'power',1); 239 244 bamg_options.splitcorners=getfieldvalue(options,'splitcorners',1); 245 bamg_options.geometricalmetric=getfieldvalue(options,'geometricalmetric',0); 240 246 bamg_options.verbose=getfieldvalue(options,'verbose',1); 241 247 %}}} 242 243 %check bamg options244 fieldsize=size(bamg_options.field);245 if fieldsize(1),246 if fieldsize(1)~=md.numberofgrids,247 error(['bamg error message, ''field'' should have ' num2str(md.numberofgrids) ' lines (numberofgrids)']);248 end249 if (fieldsize(2)~=0 & length(bamg_options.err)~=fieldsize(2)),250 error(['bamg error message, ''err'' should be of length ' num2str(fieldsize(2)) ' (As many as fields)']);251 end252 end253 248 254 249 %call Bamg -
issm/trunk/src/mex/Bamg/Bamg.cpp
r3279 r3301 82 82 FetchData(&bamgopts.verbose,mxGetField(BAMGOPTIONS,0,"verbose")); 83 83 FetchData(&bamgopts.splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners")); 84 FetchData(&bamgopts.geometricalmetric,mxGetField(BAMGOPTIONS,0,"geometricalmetric")); 84 85 FetchData(&bamgopts.MaximalAngleOfCorner,mxGetField(BAMGOPTIONS,0,"MaximalAngleOfCorner")); 86 FetchData(&bamgopts.hminVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hminVertices")); 87 if (bamgopts.hminVertices && (cols!=1 || lines!=bamgmesh_in.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'hminVertices' should be [%i %i]",bamgmesh_in.NumVertices,1));} 88 FetchData(&bamgopts.hmaxVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hmaxVertices")); 89 if (bamgopts.hmaxVertices && (cols!=1 || lines!=bamgmesh_in.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'hmaxVertices' should be [%i %i]",bamgmesh_in.NumVertices,1));} 85 90 FetchData(&bamgopts.metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric")); 86 91 if (bamgopts.metric && (cols!=3 || lines!=bamgmesh_in.NumVertices)){throw ErrorException(__FUNCT__,exprintf("the size of 'metric' should be [%i %i]",bamgmesh_in.NumVertices,3));}
Note:
See TracChangeset
for help on using the changeset viewer.