Changeset 4550


Ignore:
Timestamp:
07/13/10 10:37:05 (15 years ago)
Author:
Mathieu Morlighem
Message:

Added inputs in Matice

Location:
issm/trunk/src/c/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Elements/Tria.cpp

    r4548 r4550  
    3232}
    3333/*}}}*/
     34/*FUNCTION Tria::Tria(int id, int index, IoModel* iomodel,int nummodels){{{1*/
     35Tria::Tria(int tria_id, int index, IoModel* iomodel,int nummodels)
     36
     37        :TriaRef(P1Enum) //P1Enum: interpolation type
     38        ,TriaHook(nummodels,index+1,iomodel->numberofelements+1) //index+1: matice id, iomodel->numberofelements+1: matpar id
     39                                                                  { //i is the element index
     40        /*id: */
     41        this->id=tria_id;
     42
     43        //this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
     44        this->parameters=NULL;
     45
     46        /*intialize inputs and results: */
     47        this->inputs=new Inputs();
     48        this->results=new Results();
     49
     50        /*initialize pointers:*/
     51        this->nodes=NULL;
     52        this->matice=NULL;
     53        this->matpar=NULL;
     54
     55}
     56/*}}}*/
    3457/*FUNCTION Tria::~Tria(){{{1*/
    3558Tria::~Tria(){
     
    3760        delete results;
    3861        this->parameters=NULL;
    39 }
    40 /*}}}*/
    41 /*FUNCTION Tria::Tria(int id, int index, IoModel* iomodel,int nummodels){{{1*/
    42 Tria::Tria(int tria_id, int index, IoModel* iomodel,int nummodels)
    43 
    44         :TriaRef(P1Enum) //P1Enum: interpolation type
    45         ,TriaHook(nummodels,index+1,iomodel->numberofelements+1) //index+1: matice id, iomodel->numberofelements+1: matpar id
    46                                                                   { //i is the element index
    47         /*id: */
    48         this->id=tria_id;
    49 
    50         //this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
    51         this->parameters=NULL;
    52 
    53         /*intialize inputs and results: */
    54         this->inputs=new Inputs();
    55         this->results=new Results();
    56 
    57         /*initialize pointers:*/
    58         this->nodes=NULL;
    59         this->matice=NULL;
    60         this->matpar=NULL;
    61 
    6262}
    6363/*}}}*/
  • issm/trunk/src/c/objects/Materials/Matice.cpp

    r4549 r4550  
    1919/*FUNCTION Matice::Matice(){{{1*/
    2020Matice::Matice(){
     21        this->inputs=NULL;
    2122        return;
    2223}
    2324/*}}}*/
    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*/
     26Matice::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*/
    4338        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*/
    4658        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*/
    4978        else ISSMERROR(" Mesh type not supported yet!");
    5079
    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);
    6680}
    6781/*}}}*/
    6882/*FUNCTION Matice::~Matice(){{{1*/
    6983Matice::~Matice(){
     84        delete inputs;
    7085        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;
    7886}
    7987/*}}}*/
     
    8593        printf("Matice:\n");
    8694        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();
    9097}
    9198/*}}}*/
     
    95102        printf("Matice:\n");
    96103        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();
    100106}               
    101107/*}}}*/
     
    112118void  Matice::Marshall(char** pmarshalled_dataset){
    113119
     120        /*Intermediaries*/
    114121        char* marshalled_dataset=NULL;
    115122        int   enum_type=0;
     123        char* marshalled_inputs=NULL;
     124        int   marshalled_inputs_size;
    116125
    117126        /*recover marshalled_dataset: */
     
    126135        /*marshall Matice data: */
    127136        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;
    130143
    131144        *pmarshalled_dataset=marshalled_dataset;
    132         return;
     145
     146        /*clean up and return*/
     147        xfree((void**)&marshalled_inputs);
    133148}
    134149/*}}}*/
     
    136151int   Matice::MarshallSize(){
    137152
    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
    139156}
    140157/*}}}*/
     
    151168
    152169        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);
    155173
    156174        /*return: */
     
    168186/*FUNCTION Matice::copy {{{1*/
    169187Object* 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;
    171200}
    172201/*}}}*/
     
    175204/*FUNCTION Matice::GetB {{{1*/
    176205double Matice::GetB(){
     206
     207        /*Output*/
     208        double B;
     209
     210        inputs->GetParameterAverage(&B,RheologyBEnum);
    177211        return B;
    178212}
     
    180214/*FUNCTION Matice::GetN {{{1*/
    181215double Matice::GetN(){
     216
     217        /*Output*/
     218        double n;
     219
     220        inputs->GetParameterAverage(&n,RheologyNEnum);
    182221        return n;
    183222}
     
    203242        double exx,eyy,exy;
    204243
    205         /*Intermediary value A and exponent e: */
     244        /*Intermediary: */
    206245        double A,e;
     246        double B,n;
     247
     248        /*Get B and n*/
     249        B=GetB();
     250        n=GetN();
    207251
    208252        if (n==1){
     
    264308        double exx,eyy,exy,exz,eyz;
    265309
    266         /*Intermediary value A and exponent e: */
     310        /*Intermediaries: */
    267311        double A,e;
     312        double B,n;
     313
     314        /*Get B and n*/
     315        B=GetB();
     316        n=GetN();
    268317
    269318        if (n==1){
     
    310359/*FUNCTION Matice::GetViscosity3dStokes {{{1*/
    311360void  Matice::GetViscosity3dStokes(double* pviscosity3d, double* epsilon){
    312 
    313361        /*Return viscosity accounting for steady state power law creep [Thomas and MacAyeal, 1982]:
    314362         *
    315363         *                                 2*B
    316364         * 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]
    318366         *
    319367         *     where mu is the viscotiy, B the flow law parameter , (u,v) the velocity
     
    330378        double exx,eyy,exy,exz,eyz,ezz;
    331379
    332         /*Intermediary value A and exponent e: */
     380        /*Intermediaries: */
    333381        double A,e;
     382        double B,n;
    334383        double eps0;
    335384
     385        /*Get B and n*/
    336386        eps0=pow((double)10,(double)-27);
     387        B=GetB();
     388        n=GetN();
    337389       
    338390        if (n==1){
     
    379431/*FUNCTION Matice::GetViscosityComplement {{{1*/
    380432void  Matice::GetViscosityComplement(double* pviscosity_complement, double* epsilon){
    381 
    382433        /*Return viscosity accounting for steady state power law creep [Thomas and MacAyeal, 1982]:
    383434         *
     
    401452        /*Intermediary value A and exponent e: */
    402453        double A,e;
     454        double B,n;
     455
     456        /*Get B and n*/
     457        B=GetB();
     458        n=GetN();
    403459
    404460        if(epsilon){
     
    432488}
    433489/*}}}*/
    434 /*FUNCTION Matice::SetB {{{1*/
    435 void  Matice::SetB(double B_param){
    436         B=B_param;
    437 }
    438 /*}}}*/
    439490/*FUNCTION Matice::InputUpdateFromVector(double* vector, int name, int type) {{{1*/
    440491void  Matice::InputUpdateFromVector(double* vector, int name, int type){
  • issm/trunk/src/c/objects/Materials/Matice.h

    r4248 r4550  
    1616        private:
    1717                int        mid;
    18                 double B;
    19                 double n;
     18                Inputs*  inputs;
    2019
    2120        public:
     
    2322                /*Matice constructors, destructors: {{{1*/
    2423                Matice();
    25                 Matice(int mid,double B,double n);
    2624                Matice(int mid,int i, IoModel* iomodel);
    27                 void Init(int mid,double B,double n);
    2825                ~Matice();
    2926                /*}}}*/
     
    4946                /*}}}*/
    5047                /*Matice Numerics: {{{1*/
    51                 void   SetB(double B_param);
    5248                void   GetViscosity2d(double* pviscosity, double* pepsilon);
    5349                void   GetViscosity3d(double* pviscosity3d, double* pepsilon);
Note: See TracChangeset for help on using the changeset viewer.