Changeset 4550 for issm/trunk/src/c/objects/Materials/Matice.cpp
- Timestamp:
- 07/13/10 10:37:05 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/objects/Materials/Matice.cpp
r4549 r4550 19 19 /*FUNCTION Matice::Matice(){{{1*/ 20 20 Matice::Matice(){ 21 this->inputs=NULL; 21 22 return; 22 23 } 23 24 /*}}}*/ 24 /*FUNCTION Matice::Matice(int in_mid,double in_B,double in_n){{{1*/ 25 Matice::Matice(int in_mid,double in_B,double in_n){ 26 this->Init(in_mid,in_B,in_n); 27 } 28 /*}}}*/ 29 /*FUNCTION Matice::Matice(int id, int i, IoModel* iomodel, int num_vertices){{{1*/ 30 Matice::Matice(int matice_mid,int i, IoModel* iomodel){ 31 32 int j; 33 34 /*needed for Init routine:*/ 35 double matice_B; 36 double matice_n; 37 int num_vertices; 38 39 /*intermediary: */ 40 double B_avg; 41 42 /*2d or 3d? */ 25 /*FUNCTION Matice::Matice(int id, int index, IoModel* iomodel, int num_vertices){{{1*/ 26 Matice::Matice(int matice_mid,int index, IoModel* iomodel){ 27 28 /*Intermediaries:*/ 29 int i; 30 31 /*Initialize id*/ 32 this->mid=matice_mid; 33 34 /*Initialize inputs*/ 35 this->inputs=new Inputs(); 36 37 /*if 2d*/ 43 38 if(iomodel->dim==2){ 44 num_vertices=3; //tria elements 45 } 39 40 /*Intermediaries*/ 41 const int num_vertices = 3; //Tria has 3 vertices 42 double nodeinputs[num_vertices]; 43 44 /*Get B*/ 45 if (iomodel->rheology_B) { 46 for(i=0;i<num_vertices;i++) nodeinputs[i]=iomodel->rheology_B[int(iomodel->elements[num_vertices*index+i]-1)]; 47 this->inputs->AddInput(new TriaVertexInput(RheologyBEnum,nodeinputs)); 48 } 49 50 /*Get n*/ 51 if (iomodel->rheology_n) { 52 for(i=0;i<num_vertices;i++) nodeinputs[i]=iomodel->rheology_n[int(iomodel->elements[num_vertices*index+i]-1)]; 53 this->inputs->AddInput(new TriaVertexInput(RheologyNEnum,nodeinputs)); 54 } 55 } 56 57 /*if 3d*/ 46 58 else if(iomodel->dim==3){ 47 num_vertices=6; //penta elements 48 } 59 60 /*Intermediaries*/ 61 const int num_vertices = 6; //Penta has 6 vertices 62 double nodeinputs[num_vertices]; 63 64 /*Get B*/ 65 if (iomodel->rheology_B) { 66 for(i=0;i<num_vertices;i++) nodeinputs[i]=iomodel->rheology_B[int(iomodel->elements[num_vertices*index+i]-1)]; 67 this->inputs->AddInput(new PentaVertexInput(RheologyBEnum,nodeinputs)); 68 } 69 70 /*Get n*/ 71 if (iomodel->rheology_n) { 72 for(i=0;i<num_vertices;i++) nodeinputs[i]=iomodel->rheology_n[int(iomodel->elements[num_vertices*index+i]-1)]; 73 this->inputs->AddInput(new PentaVertexInput(RheologyNEnum,nodeinputs)); 74 } 75 } 76 77 /*Else*/ 49 78 else ISSMERROR(" Mesh type not supported yet!"); 50 79 51 /*Compute B on the element if provided*/52 if (iomodel->rheology_B){53 B_avg=0;54 for(j=0;j<num_vertices;j++){55 B_avg+=*(iomodel->rheology_B+((int)*(iomodel->elements+num_vertices*i+j)-1));56 }57 B_avg=B_avg/num_vertices;58 matice_B=B_avg;59 }60 else matice_B=UNDEF;61 62 if (iomodel->rheology_n) matice_n=(double)*(iomodel->rheology_n+i);63 else matice_n=UNDEF;64 65 this->Init(matice_mid,matice_B,matice_n);66 80 } 67 81 /*}}}*/ 68 82 /*FUNCTION Matice::~Matice(){{{1*/ 69 83 Matice::~Matice(){ 84 delete inputs; 70 85 return; 71 }72 /*}}}*/73 /*FUNCTION Matice::Init {{{1*/74 void Matice::Init(int in_mid,double in_B,double in_n){75 this->mid=in_mid;76 this->B=in_B;77 this->n=in_n;78 86 } 79 87 /*}}}*/ … … 85 93 printf("Matice:\n"); 86 94 printf(" mid: %i\n",mid); 87 printf(" B: %g\n",B); 88 printf(" n: %g\n",n); 89 return; 95 printf(" inputs:\n"); 96 inputs->Echo(); 90 97 } 91 98 /*}}}*/ … … 95 102 printf("Matice:\n"); 96 103 printf(" mid: %i\n",mid); 97 printf(" B: %g\n",B); 98 printf(" n: %g\n",n); 99 return; 104 printf(" inputs:\n"); 105 inputs->DeepEcho(); 100 106 } 101 107 /*}}}*/ … … 112 118 void Matice::Marshall(char** pmarshalled_dataset){ 113 119 120 /*Intermediaries*/ 114 121 char* marshalled_dataset=NULL; 115 122 int enum_type=0; 123 char* marshalled_inputs=NULL; 124 int marshalled_inputs_size; 116 125 117 126 /*recover marshalled_dataset: */ … … 126 135 /*marshall Matice data: */ 127 136 memcpy(marshalled_dataset,&mid,sizeof(mid));marshalled_dataset+=sizeof(mid); 128 memcpy(marshalled_dataset,&B,sizeof(B));marshalled_dataset+=sizeof(B); 129 memcpy(marshalled_dataset,&n,sizeof(n));marshalled_dataset+=sizeof(n); 137 138 /*Marshall inputs: */ 139 marshalled_inputs_size=inputs->MarshallSize(); 140 marshalled_inputs=inputs->Marshall(); 141 memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char)); 142 marshalled_dataset+=marshalled_inputs_size; 130 143 131 144 *pmarshalled_dataset=marshalled_dataset; 132 return; 145 146 /*clean up and return*/ 147 xfree((void**)&marshalled_inputs); 133 148 } 134 149 /*}}}*/ … … 136 151 int Matice::MarshallSize(){ 137 152 138 return sizeof(mid)+sizeof(B)+sizeof(n)+sizeof(int); //sizeof(int) for enum type 153 return sizeof(mid) 154 +inputs->MarshallSize() 155 +sizeof(int); //sizeof(int) for enum type 139 156 } 140 157 /*}}}*/ … … 151 168 152 169 memcpy(&mid,marshalled_dataset,sizeof(mid));marshalled_dataset+=sizeof(mid); 153 memcpy(&B,marshalled_dataset,sizeof(B));marshalled_dataset+=sizeof(B); 154 memcpy(&n,marshalled_dataset,sizeof(n));marshalled_dataset+=sizeof(n); 170 171 /*demarshall inputs: */ 172 inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 155 173 156 174 /*return: */ … … 168 186 /*FUNCTION Matice::copy {{{1*/ 169 187 Object* Matice::copy() { 170 return new Matice(*this); 188 189 /*Output*/ 190 Matice* matice=NULL; 191 192 matice->mid=this->mid; 193 if(this->inputs){ 194 matice->inputs=(Inputs*)this->inputs->Copy(); 195 } 196 else{ 197 matice->inputs=new Inputs(); 198 } 199 return matice; 171 200 } 172 201 /*}}}*/ … … 175 204 /*FUNCTION Matice::GetB {{{1*/ 176 205 double Matice::GetB(){ 206 207 /*Output*/ 208 double B; 209 210 inputs->GetParameterAverage(&B,RheologyBEnum); 177 211 return B; 178 212 } … … 180 214 /*FUNCTION Matice::GetN {{{1*/ 181 215 double Matice::GetN(){ 216 217 /*Output*/ 218 double n; 219 220 inputs->GetParameterAverage(&n,RheologyNEnum); 182 221 return n; 183 222 } … … 203 242 double exx,eyy,exy; 204 243 205 /*Intermediary value A and exponent e: */244 /*Intermediary: */ 206 245 double A,e; 246 double B,n; 247 248 /*Get B and n*/ 249 B=GetB(); 250 n=GetN(); 207 251 208 252 if (n==1){ … … 264 308 double exx,eyy,exy,exz,eyz; 265 309 266 /*Intermediar y value A and exponent e: */310 /*Intermediaries: */ 267 311 double A,e; 312 double B,n; 313 314 /*Get B and n*/ 315 B=GetB(); 316 n=GetN(); 268 317 269 318 if (n==1){ … … 310 359 /*FUNCTION Matice::GetViscosity3dStokes {{{1*/ 311 360 void Matice::GetViscosity3dStokes(double* pviscosity3d, double* epsilon){ 312 313 361 /*Return viscosity accounting for steady state power law creep [Thomas and MacAyeal, 1982]: 314 362 * 315 363 * 2*B 316 364 * viscosity3d= ------------------------------------------------------------------- 317 * 2[ exx^2+eyy^2+exx*eyy+exy^2+exz^2+eyz^2 ]^[(n-1)/2n]365 * 2[ exx^2+eyy^2+exx*eyy+exy^2+exz^2+eyz^2 ]^[(n-1)/2n] 318 366 * 319 367 * where mu is the viscotiy, B the flow law parameter , (u,v) the velocity … … 330 378 double exx,eyy,exy,exz,eyz,ezz; 331 379 332 /*Intermediar y value A and exponent e: */380 /*Intermediaries: */ 333 381 double A,e; 382 double B,n; 334 383 double eps0; 335 384 385 /*Get B and n*/ 336 386 eps0=pow((double)10,(double)-27); 387 B=GetB(); 388 n=GetN(); 337 389 338 390 if (n==1){ … … 379 431 /*FUNCTION Matice::GetViscosityComplement {{{1*/ 380 432 void Matice::GetViscosityComplement(double* pviscosity_complement, double* epsilon){ 381 382 433 /*Return viscosity accounting for steady state power law creep [Thomas and MacAyeal, 1982]: 383 434 * … … 401 452 /*Intermediary value A and exponent e: */ 402 453 double A,e; 454 double B,n; 455 456 /*Get B and n*/ 457 B=GetB(); 458 n=GetN(); 403 459 404 460 if(epsilon){ … … 432 488 } 433 489 /*}}}*/ 434 /*FUNCTION Matice::SetB {{{1*/435 void Matice::SetB(double B_param){436 B=B_param;437 }438 /*}}}*/439 490 /*FUNCTION Matice::InputUpdateFromVector(double* vector, int name, int type) {{{1*/ 440 491 void Matice::InputUpdateFromVector(double* vector, int name, int type){
Note:
See TracChangeset
for help on using the changeset viewer.