[5625] | 1 | /*!\file GaussTria.c
|
---|
| 2 | * \brief: implementation of the GaussTria object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
[12706] | 5 | /*Include files: {{{*/
|
---|
[5625] | 6 | #include "./../objects.h"
|
---|
| 7 | /*}}}*/
|
---|
| 8 |
|
---|
| 9 | /*GaussTria constructors and destructors:*/
|
---|
[12706] | 10 | /*FUNCTION GaussTria::GaussTria() {{{*/
|
---|
[5625] | 11 | GaussTria::GaussTria(){
|
---|
| 12 |
|
---|
| 13 | numgauss=-1;
|
---|
| 14 |
|
---|
| 15 | weights=NULL;
|
---|
| 16 | coords1=NULL;
|
---|
| 17 | coords2=NULL;
|
---|
| 18 | coords3=NULL;
|
---|
| 19 |
|
---|
| 20 | weight=UNDEF;
|
---|
| 21 | coord1=UNDEF;
|
---|
| 22 | coord2=UNDEF;
|
---|
| 23 | coord3=UNDEF;
|
---|
| 24 | }
|
---|
| 25 | /*}}}*/
|
---|
[12706] | 26 | /*FUNCTION GaussTria::GaussTria(int order) {{{*/
|
---|
[5625] | 27 | GaussTria::GaussTria(int order){
|
---|
| 28 |
|
---|
| 29 | /*Get gauss points*/
|
---|
| 30 | GaussLegendreTria(&numgauss,&coords1,&coords2,&coords3,&weights,order);
|
---|
| 31 |
|
---|
| 32 | /*Initialize static fields as undefinite*/
|
---|
| 33 | weight=UNDEF;
|
---|
| 34 | coord1=UNDEF;
|
---|
| 35 | coord2=UNDEF;
|
---|
| 36 | coord3=UNDEF;
|
---|
| 37 |
|
---|
| 38 | }
|
---|
| 39 | /*}}}*/
|
---|
[12706] | 40 | /*FUNCTION GaussTria::GaussTria(int index1,int index2,int order) {{{*/
|
---|
[5719] | 41 | GaussTria::GaussTria(int index1,int index2,int order){
|
---|
| 42 |
|
---|
| 43 | /*Intermediaties*/
|
---|
[12706] | 44 | IssmPDouble *seg_coords = NULL;
|
---|
| 45 | IssmPDouble *seg_weights = NULL;
|
---|
[5719] | 46 | int i,index3;
|
---|
| 47 |
|
---|
| 48 | /*Get Segment gauss points*/
|
---|
| 49 | numgauss=order;
|
---|
| 50 | GaussLegendreLinear(&seg_coords,&seg_weights,numgauss);
|
---|
| 51 |
|
---|
| 52 | /*Allocate GaussTria fields*/
|
---|
[12706] | 53 | coords1=xNew<IssmPDouble>(numgauss);
|
---|
| 54 | coords2=xNew<IssmPDouble>(numgauss);
|
---|
| 55 | coords3=xNew<IssmPDouble>(numgauss);
|
---|
| 56 | weights=xNew<IssmPDouble>(numgauss);
|
---|
[5719] | 57 |
|
---|
[5739] | 58 | /*Reverse index1 and 2 if necessary*/
|
---|
[5719] | 59 | if (index1>index2){
|
---|
| 60 | index3=index1; index1=index2; index2=index3;
|
---|
| 61 | for(i=0;i<numgauss;i++) seg_coords[i]=-seg_coords[i];
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /*Build Triangle Gauss point*/
|
---|
| 65 | if (index1==0 && index2==1){
|
---|
| 66 | for(i=0;i<numgauss;i++) coords1[i]= 0.5*(1-seg_coords[i]);
|
---|
| 67 | for(i=0;i<numgauss;i++) coords2[i]=1-0.5*(1.-seg_coords[i]);
|
---|
| 68 | for(i=0;i<numgauss;i++) coords3[i]=0;
|
---|
| 69 | for(i=0;i<numgauss;i++) weights[i]=seg_weights[i];
|
---|
| 70 | }
|
---|
| 71 | else if (index1==0 && index2==2){
|
---|
| 72 | for(i=0;i<numgauss;i++) coords1[i]= 0.5*(1-seg_coords[i]);
|
---|
[12706] | 73 | for(i=0;i<numgauss;i++) coords2[i]= 0 ;
|
---|
[5719] | 74 | for(i=0;i<numgauss;i++) coords3[i]=1-0.5*(1.-seg_coords[i]);
|
---|
| 75 | for(i=0;i<numgauss;i++) weights[i]=seg_weights[i];
|
---|
| 76 | }
|
---|
| 77 | else if (index1==1 && index2==2){
|
---|
| 78 | for(i=0;i<numgauss;i++) coords1[i]=0;
|
---|
| 79 | for(i=0;i<numgauss;i++) coords2[i]= 0.5*(1-seg_coords[i]);
|
---|
| 80 | for(i=0;i<numgauss;i++) coords3[i]=1-0.5*(1.-seg_coords[i]);
|
---|
| 81 | for(i=0;i<numgauss;i++) weights[i]=seg_weights[i];
|
---|
| 82 | }
|
---|
| 83 | else
|
---|
[12706] | 84 | _error2_("The 2 indices provided are not supported yet (user provided " << index1 << " and " << index2 << ")");
|
---|
[5719] | 85 |
|
---|
| 86 | /*Initialize static fields as undefined*/
|
---|
| 87 | weight=UNDEF;
|
---|
| 88 | coord1=UNDEF;
|
---|
| 89 | coord2=UNDEF;
|
---|
| 90 | coord3=UNDEF;
|
---|
| 91 |
|
---|
| 92 | /*clean up*/
|
---|
[12706] | 93 | xDelete<double>(seg_coords);
|
---|
| 94 | xDelete<double>(seg_weights);
|
---|
[5719] | 95 | }
|
---|
| 96 | /*}}}*/
|
---|
[12706] | 97 | /*FUNCTION GaussTria::~GaussTria(){{{*/
|
---|
[5625] | 98 | GaussTria::~GaussTria(){
|
---|
[12706] | 99 | xDelete<IssmPDouble>(weights);
|
---|
| 100 | xDelete<IssmPDouble>(coords1);
|
---|
| 101 | xDelete<IssmPDouble>(coords2);
|
---|
| 102 | xDelete<IssmPDouble>(coords3);
|
---|
[5625] | 103 | }
|
---|
| 104 | /*}}}*/
|
---|
| 105 |
|
---|
| 106 | /*Methods*/
|
---|
[12706] | 107 | /*FUNCTION GaussTria::Echo{{{*/
|
---|
[5625] | 108 | void GaussTria::Echo(void){
|
---|
| 109 |
|
---|
[12706] | 110 | _printLine_("GaussTria:");
|
---|
| 111 | _printLine_(" numgauss: " << numgauss);
|
---|
[5625] | 112 |
|
---|
| 113 | if (weights){
|
---|
[12706] | 114 | _printString_(" weights = [");
|
---|
| 115 | for(int i=0;i<numgauss;i++) _printLine_(" " << weights[i]);
|
---|
| 116 | _printLine_("]");
|
---|
[5625] | 117 | }
|
---|
[12706] | 118 | else _printLine_("weights = NULL");
|
---|
[5625] | 119 | if (coords1){
|
---|
[12706] | 120 | _printString_(" coords1 = [");
|
---|
| 121 | for(int i=0;i<numgauss;i++) _printLine_(" " << coords1[i]);
|
---|
| 122 | _printLine_("]");
|
---|
[5625] | 123 | }
|
---|
[12706] | 124 | else _printLine_("coords1 = NULL");
|
---|
[5625] | 125 | if (coords2){
|
---|
[12706] | 126 | _printString_(" coords2 = [");
|
---|
| 127 | for(int i=0;i<numgauss;i++) _printLine_(" " << coords2[i]);
|
---|
| 128 | _printLine_("]");
|
---|
[5625] | 129 | }
|
---|
[12706] | 130 | else _printLine_("coords2 = NULL");
|
---|
[5625] | 131 | if (coords3){
|
---|
[12706] | 132 | _printString_(" coords3 = [");
|
---|
| 133 | for(int i=0;i<numgauss;i++) _printLine_(" " << coords3[i]);
|
---|
| 134 | _printLine_("]");
|
---|
[5625] | 135 | }
|
---|
[12706] | 136 | else _printLine_("coords3 = NULL");
|
---|
[5625] | 137 |
|
---|
[12706] | 138 | _printLine_(" weight = " << weight);
|
---|
| 139 | _printLine_(" coord1 = " << coord1);
|
---|
| 140 | _printLine_(" coord2 = " << coord2);
|
---|
| 141 | _printLine_(" coord3 = " << coord3);
|
---|
[5625] | 142 |
|
---|
| 143 | }
|
---|
| 144 | /*}}}*/
|
---|
[12706] | 145 | /*FUNCTION GaussTria::GaussCenter{{{*/
|
---|
[5637] | 146 | void GaussTria::GaussCenter(void){
|
---|
| 147 |
|
---|
| 148 | /*update static arrays*/
|
---|
| 149 | coord1=ONETHIRD;
|
---|
| 150 | coord2=ONETHIRD;
|
---|
| 151 | coord3=ONETHIRD;
|
---|
| 152 |
|
---|
| 153 | }
|
---|
| 154 | /*}}}*/
|
---|
[12706] | 155 | /*FUNCTION GaussTria::GaussEdgeCenter{{{*/
|
---|
[5739] | 156 | void GaussTria::GaussEdgeCenter(int index1,int index2){
|
---|
| 157 |
|
---|
| 158 | int index3;
|
---|
| 159 |
|
---|
| 160 | /*Reverse index1 and 2 if necessary*/
|
---|
| 161 | if (index1>index2){
|
---|
| 162 | index3=index1; index1=index2; index2=index3;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /*update static arrays*/
|
---|
| 166 | if (index1==0 && index2==1){
|
---|
| 167 | coord1=0.5;
|
---|
| 168 | coord2=0.5;
|
---|
| 169 | coord3=0.0;
|
---|
| 170 | }
|
---|
| 171 | else if (index1==0 && index2==2){
|
---|
| 172 | coord1=0.5;
|
---|
| 173 | coord2=0.0;
|
---|
| 174 | coord3=0.5;
|
---|
| 175 | }
|
---|
| 176 | else if (index1==1 && index2==2){
|
---|
| 177 | coord1=0.0;
|
---|
| 178 | coord2=0.5;
|
---|
| 179 | coord3=0.5;
|
---|
| 180 | }
|
---|
| 181 | else
|
---|
[12706] | 182 | _error2_("The 2 indices provided are not supported yet (user provided " << index1 << " and " << index2 << ")");
|
---|
[5739] | 183 |
|
---|
| 184 | }
|
---|
| 185 | /*}}}*/
|
---|
[12706] | 186 | /*FUNCTION GaussTria::GaussPoint{{{*/
|
---|
[5625] | 187 | void GaussTria::GaussPoint(int ig){
|
---|
| 188 |
|
---|
| 189 | /*Check input in debugging mode*/
|
---|
[6412] | 190 | _assert_(ig>=0 && ig< numgauss);
|
---|
[5625] | 191 |
|
---|
| 192 | /*update static arrays*/
|
---|
| 193 | weight=weights[ig];
|
---|
| 194 | coord1=coords1[ig];
|
---|
| 195 | coord2=coords2[ig];
|
---|
| 196 | coord3=coords3[ig];
|
---|
| 197 |
|
---|
| 198 | }
|
---|
| 199 | /*}}}*/
|
---|
[12706] | 200 | /*FUNCTION GaussTria::GaussFromCoords{{{*/
|
---|
| 201 | void GaussTria::GaussFromCoords(IssmPDouble x,IssmPDouble y,IssmPDouble* xyz_list){
|
---|
[5734] | 202 |
|
---|
| 203 | /*Intermediaries*/
|
---|
[12706] | 204 | IssmPDouble area = 0;
|
---|
| 205 | IssmPDouble x1,y1,x2,y2,x3,y3;
|
---|
[5734] | 206 |
|
---|
| 207 | /*in debugging mode: check that the default constructor has been called*/
|
---|
[6412] | 208 | _assert_(numgauss==-1);
|
---|
[5734] | 209 |
|
---|
| 210 | x1=*(xyz_list+3*0+0); y1=*(xyz_list+3*0+1);
|
---|
| 211 | x2=*(xyz_list+3*1+0); y2=*(xyz_list+3*1+1);
|
---|
| 212 | x3=*(xyz_list+3*2+0); y3=*(xyz_list+3*2+1);
|
---|
| 213 |
|
---|
| 214 | area=(x2*y3 - y2*x3 + x1*y2 - y1*x2 + x3*y1 - y3*x1)/2;
|
---|
| 215 |
|
---|
| 216 | /*Get first area coordinate = det(x-x3 x2-x3 ; y-y3 y2-y3)/area*/
|
---|
| 217 | coord1=((x-x3)*(y2-y3)-(x2-x3)*(y-y3))/area;
|
---|
| 218 |
|
---|
| 219 | /*Get second area coordinate = det(x1-x3 x-x3 ; y1-y3 y-y3)/area*/
|
---|
| 220 | coord2=((x1-x3)*(y-y3)-(x-x3)*(y1-y3))/area;
|
---|
| 221 |
|
---|
| 222 | /*Get third area coordinate 1-area1-area2: */
|
---|
| 223 | coord3=1-coord1-coord2;
|
---|
| 224 |
|
---|
| 225 | }
|
---|
| 226 | /*}}}*/
|
---|
[12706] | 227 | /*FUNCTION GaussTria::GaussVertex{{{*/
|
---|
[5630] | 228 | void GaussTria::GaussVertex(int iv){
|
---|
| 229 |
|
---|
| 230 | /*in debugging mode: check that the default constructor has been called*/
|
---|
[6412] | 231 | _assert_(numgauss==-1);
|
---|
[5630] | 232 |
|
---|
| 233 | /*update static arrays*/
|
---|
| 234 | switch(iv){
|
---|
| 235 | case 0:
|
---|
| 236 | coord1=1; coord2=0; coord3=0;
|
---|
| 237 | break;
|
---|
| 238 | case 1:
|
---|
| 239 | coord1=0; coord2=1; coord3=0;
|
---|
| 240 | break;
|
---|
| 241 | case 2:
|
---|
| 242 | coord1=0; coord2=0; coord3=1;
|
---|
| 243 | break;
|
---|
| 244 | default:
|
---|
[12706] | 245 | _error2_("vertex index should be in [0 2]");
|
---|
[5630] | 246 |
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | }
|
---|
| 250 | /*}}}*/
|
---|
[12706] | 251 | /*FUNCTION GaussTria::begin{{{*/
|
---|
[5625] | 252 | int GaussTria::begin(void){
|
---|
| 253 |
|
---|
| 254 | /*Check that this has been initialized*/
|
---|
[6412] | 255 | _assert_(numgauss>0);
|
---|
| 256 | _assert_(weights);
|
---|
| 257 | _assert_(coords1);
|
---|
| 258 | _assert_(coords2);
|
---|
| 259 | _assert_(coords3);
|
---|
[5625] | 260 |
|
---|
| 261 | /*return first gauss index*/
|
---|
| 262 | return 0;
|
---|
| 263 | }
|
---|
| 264 | /*}}}*/
|
---|
[12706] | 265 | /*FUNCTION GaussTria::end{{{*/
|
---|
[5625] | 266 | int GaussTria::end(void){
|
---|
| 267 |
|
---|
| 268 | /*Check that this has been initialized*/
|
---|
[6412] | 269 | _assert_(numgauss>0);
|
---|
| 270 | _assert_(weights);
|
---|
| 271 | _assert_(coords1);
|
---|
| 272 | _assert_(coords2);
|
---|
| 273 | _assert_(coords3);
|
---|
[5625] | 274 |
|
---|
| 275 | /*return last gauss index +1*/
|
---|
| 276 | return numgauss;
|
---|
| 277 | }
|
---|
| 278 | /*}}}*/
|
---|