Changeset 5217


Ignore:
Timestamp:
08/12/10 17:54:04 (15 years ago)
Author:
Eric.Larour
Message:

Fixed some bug in CreateParametersQmu + introduced a new scheme that
makes it impossible to fetch twice the same data. This is needed,
as now, the variables for qmu are expanded before being marshalled, and
we do not get descriptors such as Thickness, Surface, etc ...
but the equivalent variables Thickness1, Thickenss2, Surface1, Surface2, Surface3, etc ...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp

    r5103 r5217  
    2727        char**  variabledescriptors=NULL;
    2828        char*   descriptor=NULL;
     29        char*   root=NULL;
    2930        double* dakota_parameter=NULL;
    3031
     
    5253        int      count;
    5354
     55        /*fetching of parameters: */
     56        int    found=0;
     57        char** strings=NULL;
     58        char*  string=NULL;
     59
    5460        #ifdef _SERIAL_
    5561                mxArray* pfield=NULL;
     
    7783                parameters->AddObject(new   StringParam(QmuErrNameEnum,qmuerrname));
    7884                /*}}}*/
    79                
     85
    8086                /*Deal with variable descriptors: {{{1*/
    8187                variabledescriptors=(char**)xmalloc(iomodel->numberofvariables*sizeof(char*));
     
    95101                #else
    96102                for(i=0;i<iomodel->numberofvariables;i++){
    97                         sprintf(variabledescriptors_tag,"%s%i","variabledescriptor",i);
     103                        sprintf(variabledescriptors_tag,"%s%i","variabledescriptor",i+1);
    98104                        IoModelFetchData(&descriptor,iomodel_handle,variabledescriptors_tag);
    99105                        variabledescriptors[i]=descriptor;
     
    119125                #else
    120126                for(i=0;i<iomodel->numberofresponses;i++){
    121                         sprintf(responsedescriptors_tag,"%s%i","responsedescriptor",i);
     127                        sprintf(responsedescriptors_tag,"%s%i","responsedescriptor",i+1);
    122128                        IoModelFetchData(&descriptor,iomodel_handle,responsedescriptors_tag);
    123129                        responsedescriptors[i]=descriptor;
     
    127133                /*Ok, we have all the response descriptors. Build a parameter with it: */
    128134                parameters->AddObject(new StringArrayParam(ResponseDescriptorsEnum,responsedescriptors,iomodel->numberofresponses));
    129                 /*}}}}*/
     135                /*}}}*/
    130136
    131137                /*Deal with partitioning: {{{1*/
     
    147153
    148154                /*Deal with data needed because of qmu variable inputs: {{{1*/
    149                 for(i=0;i<iomodel->numberofvariables;i++){
    150 
     155               
     156                /*First, build a list of strings, used to make sure we don't deal with the same descriptor twice: */
     157                if(iomodel->numberofvariables){
     158                        strings=(char**)xmalloc(iomodel->numberofvariables*sizeof(char*));
     159                        for(i=0;i<iomodel->numberofvariables;i++)strings[i]=NULL;
     160                }
     161                                       
     162                /*Now, go through all our needed variables, and fetch the corresponding data: */
     163                for(i=0;i<iomodel->numberofvariables;i++){
     164
     165                        /*recover root of descriptor. Descriptors can come in 2 forms: Letters+Number or just letters (ex: Thickness1, RhoIce, Surface3). Strip the number
     166                         * from the descriptor (root), so that we key off of this: */
    151167                        descriptor=variabledescriptors[i];
    152 
    153                         if ((strcmp(descriptor,"Thickness")==0) || (strcmp(descriptor,"DragCoefficient")     ==0) || (strcmp(descriptor,"Surface")     ==0) || (strcmp(descriptor,"Bed")     ==0)
    154 
    155 
    156                                 ){
    157 
    158                                 IoModelFetchData(&dakota_parameter,NULL,NULL,iomodel_handle,EnumToModelField(StringToEnum(descriptor)));
    159                                 parameters->AddObject(new DoubleVecParam(StringToEnum(descriptor),dakota_parameter,iomodel->numberofvertices));
    160                                 xfree((void**)&dakota_parameter);
    161                         }
    162                 }
     168                        if(isdistributed(&root,descriptor)){
     169
     170                                //now, check that this root was not already processed, ie we did not already fetch the corresponding data!
     171                                found=0;
     172                                for(j=0;j<iomodel->numberofvariables;j++){
     173                                        if (strings[j]) if (strcmp(strings[j],root)==0)found=1;
     174                                }
     175
     176                                /*If we did not, fetch data and add it to the parameters: */
     177                                if(!found){
     178
     179                                        /*Recover: */
     180                                        printf("ok1 %s %s %s\n",descriptor,root,EnumToModelField(StringToEnum(root)));
     181
     182                                        IoModelFetchData(&dakota_parameter,NULL,NULL,iomodel_handle,EnumToModelField(StringToEnum(root)));
     183                                       
     184                                        /*Add to parameters: */
     185                                        parameters->AddObject(new DoubleVecParam(StringToEnum(root),dakota_parameter,iomodel->numberofvertices));
     186                               
     187                                        /*Free ressources:*/
     188                                        xfree((void**)&dakota_parameter);
     189
     190                                        /*Ensure we won't process this variable anymore: */
     191                                        string=(char*)xmalloc((strlen(root)+1)*sizeof(char)); strcpy(string,root); strings[i]=string;
     192                                }
     193                        }
     194                        xfree((void**)&root);
     195                }
     196                /*Free strings: not needed anymore */
     197                for(i=0;i<iomodel->numberofvariables;i++){
     198                        string=strings[i];
     199                        xfree((void**)&string);
     200                }
     201                xfree((void**)&strings);
    163202                /*}}}*/
    164203
Note: See TracChangeset for help on using the changeset viewer.