Changeset 21546


Ignore:
Timestamp:
02/10/17 11:28:06 (8 years ago)
Author:
Mathieu Morlighem
Message:

CHG: use IoModelToConstrain to create spcs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/analyses/EnthalpyAnalysis.cpp

    r21542 r21546  
    1313        int        M,N;
    1414        bool       spcpresent = false;
     15        int        finiteelement;
    1516        IssmDouble heatcapacity;
    1617        IssmDouble referencetemperature;
     
    2425        iomodel->FindConstant(&heatcapacity,"md.materials.heatcapacity");
    2526        iomodel->FindConstant(&referencetemperature,"md.constants.referencetemperature");
     27        iomodel->FindConstant(&finiteelement,"md.thermal.fe");
    2628
    2729        /*return if 2d mesh*/
     
    3133        iomodel->FetchData(&spcvector,&M,&N,"md.thermal.spctemperature");
    3234
    33         //FIX ME: SHOULD USE IOMODELCREATECONSTRAINTS
    34         /*Transient or static?:*/
    35         if(M==iomodel->numberofvertices){
    36                 /*static: just create Constraints objects*/
    37                 count=0;
    38 
    39                 for(int i=0;i<iomodel->numberofvertices;i++){
    40                         /*keep only this partition's nodes:*/
    41                         if((iomodel->my_vertices[i])){
    42 
    43                                 if (!xIsNan<IssmDouble>(spcvector[i])){
    44 
    45                                         constraints->AddObject(new SpcStatic(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,0,heatcapacity*(spcvector[i]-referencetemperature),EnthalpyAnalysisEnum));
    46                                         count++;
    47 
    48                                 }
    49                         }
    50                 }
    51         }
    52         else if (M==(iomodel->numberofvertices+1)){
    53                 /*transient: create transient SpcTransient objects. Same logic, except we need to retrieve
    54                  * various times and values to initialize an SpcTransient object: */
    55                 count=0;
    56 
    57                 /*figure out times: */
    58                 times=xNew<IssmDouble>(N);
    59                 for(int j=0;j<N;j++){
    60                         times[j]=spcvector[(M-1)*N+j];
    61                 }
    62 
    63                 /*Create constraints from x,y,z: */
    64                 for(int i=0;i<iomodel->numberofvertices;i++){
    65 
    66                         /*keep only this partition's nodes:*/
    67                         if((iomodel->my_vertices[i])){
    68 
    69                                 /*figure out times and values: */
    70                                 values=xNew<IssmDouble>(N);
    71                                 spcpresent=false;
    72                                 for(int j=0;j<N;j++){
    73                                         values[j]=heatcapacity*(spcvector[i*N+j]-referencetemperature);
    74                                         if(!xIsNan<IssmDouble>(values[j]))spcpresent=true; //NaN means no spc by default
    75                                 }
    76 
    77                                 if(spcpresent){
    78                                         constraints->AddObject(new SpcTransient(iomodel->constraintcounter+count+1,iomodel->nodecounter+i+1,0,N,times,values,EnthalpyAnalysisEnum));
    79                                         count++;
    80                                 }
    81                                 xDelete<IssmDouble>(values);
    82                         }
    83                 }
    84         }
    85         else{
    86                 _error_("Size of field " << EnumToStringx(ThermalSpctemperatureEnum) << " not supported");
    87         }
     35        /*Convert spcs from temperatures to enthalpy*/
     36        _assert_(N>0); _assert_(M>=iomodel->numberofvertices);
     37        for(int i=0;i<iomodel->numberofvertices;i++){
     38                for(int j=0;i<N;j++){
     39                        spcvector[i*N+j] = heatcapacity*(spcvector[i]-referencetemperature);
     40                }
     41        }
     42        IoModelToConstraintsx(constraints,iomodel,spcvector,M,N,EnthalpyAnalysisEnum,finiteelement,2);
    8843
    8944        /*Free ressources:*/
Note: See TracChangeset for help on using the changeset viewer.