Changeset 24988


Ignore:
Timestamp:
06/08/20 22:58:53 (5 years ago)
Author:
Eric.Larour
Message:

CHG: more integration of partition vectors into variables. Slowly stepping
away from the qmu.vpartition vector paradigm, not yet fully though.

Location:
issm/trunk-jpl/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp

    r24172 r24988  
    1313
    1414        int     i,j,k,l;
    15         int     dummy;
    1615
    1716        int     numberofvertices;
     
    1918        int     nrows;
    2019        int     ncols;
    21         int     npart;
    22         double *qmu_vpart  = NULL;
    23         double *qmu_epart  = NULL;
     20        IssmDouble **variable_partitions         = NULL;
     21        IssmDouble * variable_partition         = NULL;
     22        int          variable_partitions_num;
     23        int         *partitions_m   = NULL;
     24        int         *partitions_n   = NULL;
     25        int          npart;
     26        int          dummy; //should match numvariables
    2427
    2528        double *distributed_values = NULL;
     
    2932
    3033        /*retrieve parameters: */
    31         femmodel->parameters->FindParam(&npart,QmuNumberofpartitionsEnum);
    32         femmodel->parameters->FindParam(&qmu_vpart,NULL,QmuVpartitionEnum);
    33         femmodel->parameters->FindParam(&qmu_epart,NULL,QmuEpartitionEnum);
     34        femmodel->parameters->FindParam(&variable_partitions,&variable_partitions_num,&partitions_m,&partitions_n,QmuVariablePartitionsEnum);
     35       
    3436        numberofvertices=femmodel->vertices->NumberOfVertices();
    3537        numberofelements=femmodel->elements->NumberOfElements();
     
    4446                /*From descriptor, figure out if the variable is scaled, indexed, nodal, or just a simple variable: */
    4547                if (strncmp(descriptor,"scaled_",7)==0){
     48               
     49                        /*recover partition vector: */
     50                        variable_partition=variable_partitions[i];
     51                        //_printf_("variable_partition_M: " << variable_partition_M << " variable_partition_N " << variable_partition_N << "\n");
     52                        npart=partitions_m[i];
    4653
    4754                        /*Variable is scaled. Determine root name of variable (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the
     
    5764                        }
    5865
     66                       
    5967                        /*Now, pick up the parameter corresponding to root: */
    6068                        femmodel->parameters->FindParamInDataset(&parameter,&nrows,&ncols,QmuVariableDescriptorsEnum,StringToEnumx(root));
    6169
    62 
    63                         /*We've got the parameter, we need to update it using qmu_vpart or qmu_epart (depending on whether
    64                          * it is element or vertex distributed), and the distributed_values.
    65                          In addition, the parameter can be either a static or transient (nrows+1) vector. */
     70                        /*We've got the parameter, we need to update it using the partition vector, and the distributed_values.
     71                         In addition, the parameter can be either a static or transient (nrows+1) vector. Finally, the partition vectors can include
     72                         -1 (meaning, don't update). */
    6673                       
    6774                        //_printf_("nrows: " << nrows << " numberofvertices: " << numberofvertices << " numberofelements: " << numberofelements << "\n");
     
    6976                        if (nrows==numberofvertices || nrows==(numberofvertices+1)){
    7077                                for(k=0;k<numberofvertices;k++){
    71                                         for(l=0;l<ncols;l++){
    72                                                 *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)qmu_vpart[k]];
     78                                        if (variable_partition[k]==-1)continue;
     79                                        else{
     80                                                for(l=0;l<ncols;l++){
     81                                                        *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
     82                                                }
    7383                                        }
    7484                                }
     
    7686                        else if (nrows==numberofelements || nrows==(numberofelements+1)){
    7787                                for(k=0;k<numberofelements;k++){
    78                                         for(l=0;l<ncols;l++){
    79                                                 *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)qmu_epart[k]];
     88                                        if (variable_partition[k]==-1)continue;
     89                                        else{
     90                                                for(l=0;l<ncols;l++){
     91                                                        *(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
     92                                                }
    8093                                        }
    8194                                }
     
    108121                        /*increment i to skip the distributed values just collected: */
    109122                        i+=npart-1; //careful, the for loop will add 1.
    110 
     123                       
    111124                        /*Free allocations: */
    112125                        xDelete<double>(parameter);
     
    126139
    127140        /*Free ressources:*/
    128         xDelete<double>(qmu_vpart);
    129         xDelete<double>(qmu_epart);
     141        for(i=0;i<variable_partitions_num;i++){
     142                IssmDouble* matrix=variable_partitions[i];
     143                xDelete<IssmDouble>(matrix);
     144        }
     145        xDelete<int>(partitions_m);
     146        xDelete<int>(partitions_n);
     147        xDelete<IssmDouble*>(variable_partitions);
     148
    130149}
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp

    r24450 r24988  
    1313        /*variable declarations*/
    1414        int          i;
    15         double      *vpart                  = NULL;
    16         double      *epart                  = NULL;
    17         int          npart;
    1815        char       **responsedescriptors    = NULL;
    1916        int          numresponsedescriptors;
     
    3532        int   numberofresponses;
    3633        int   nrows,ncols;
     34
     35        //variable partitions:
     36        IssmDouble **array                      = NULL;
     37        int         *mdims_array                = NULL;
     38        int         *ndims_array                = NULL;
     39        int          num_partitions;
    3740
    3841        /*recover parameters: */
     
    7073                /*Load partitioning vectors (both vertex and element based: */
    7174                parameters->AddObject(iomodel->CopyConstantObject("md.qmu.numberofpartitions",QmuNumberofpartitionsEnum));
    72                 iomodel->FetchData(&vpart,&npart,NULL,"md.qmu.vpartition"); if(!vpart) _error_("md.qmu.vpartition is empty");
    73                 parameters->AddObject(new DoubleVecParam(QmuVpartitionEnum,vpart,npart));
    7475               
    75                 iomodel->FetchData(&epart,&npart,NULL,"md.qmu.epartition"); if(!epart) _error_("md.qmu.epartition is empty");
    76                 parameters->AddObject(new DoubleVecParam(QmuEpartitionEnum,epart,npart));
     76                /*Load partitioning vectors specific to variables:*/
     77                iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.variablepartitions");
     78                parameters->AddObject(new DoubleMatArrayParam(QmuVariablePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
     79
    7780
    7881                /*Deal with data needed because of qmu variables*/
     
    114117                }
    115118                xDelete<char*>(variabledescriptors);
    116                 xDelete<double>(vpart);
    117                 xDelete<double>(epart);
    118119                xDelete<char>(qmuinname);
    119120                xDelete<char>(qmuerrname);
    120121                xDelete<char>(qmuoutname);
     122
     123                for(i=0;i<num_partitions;i++){
     124                        IssmDouble* matrix=array[i];
     125                        xDelete<IssmDouble>(matrix);
     126                }
     127                xDelete<int>(mdims_array);
     128                xDelete<int>(ndims_array);
     129                xDelete<IssmDouble*>(array);
     130
    121131        }
    122132
  • issm/trunk-jpl/src/m/classes/qmu.m

    r24820 r24988  
    1818                numberofresponses           = 0;
    1919                variabledescriptors         = {};
     20                variablepartitions          = {};
    2021                responsedescriptors         = {};
    2122                mass_flux_profile_directory = NaN;
     
    5758        methods
    5859                function self = extrude(self,md) % {{{
    59                         self.vpartition=project3d(md,'vector',self.vpartition','type','node');
    60                         self.epartition=project3d(md,'vector',self.epartition','type','element');
    6160                end % }}}
    6261                function self = qmu(varargin) % {{{
     
    9796                                end
    9897                        end
    99                         if ~isempty(md.qmu.vpartition) & ~any(isnan(md.qmu.vpartition)),
    100                                 if size(md.qmu.vpartition,1)~=md.mesh.numberofvertices
    101                                         md = checkmessage(md,['user supplied vertex partition for qmu analysis should have size md.mesh.numberofvertices x 1']);
    102                                 end
    103                                 if min(md.qmu.vpartition)~=0,
    104                                         md = checkmessage(md,['vertex partition vector not indexed from 0 on']);
    105                                 end
    106                                 if max(md.qmu.vpartition)>=md.qmu.numberofpartitions,
    107                                         md = checkmessage(md,['for qmu analysis, vertex partitioning vector cannot go over npart, number of partition areas']);
    108                                 end
    109                         end
    110                         if ~isempty(md.qmu.epartition) & ~any(isnan(md.qmu.epartition)),
    111                                 if size(md.qmu.epartition,1)~=md.mesh.numberofelements,
    112                                         md = checkmessage(md,['user supplied element partition for qmu analysis should have size md.mesh.numberofelements x 1']);
    113                                 end
    114                                 if min(md.qmu.epartition)~=0,
    115                                         md = checkmessage(md,['element partition vector not indexed from 0 on']);
    116                                 end
    117                                 if max(md.qmu.epartition)>=md.qmu.numberofpartitions,
    118                                         md = checkmessage(md,['for qmu analysis, element partitioning vector cannot go over npart, number of partition areas']);
    119                                 end
    120                         end
    121                         if isempty(md.qmu.vpartition) | any(isnan(md.qmu.vpartition)) | isempty(md.qmu.epartition) | any(isnan(md.qmu.epartition)),
    122                                 md = checkmessage(md,['for qmu analysis, both an element and partitioning vectors need to be supplied with no nan values! One can be defaulted to all zeros.']);
    123                         end
    12498
    12599                        %go through variables and check for consistency:
     
    198172                                end
    199173                        end
    200                         fielddisplay(self,'vpartition','user provided mesh partitioning (vertex based)');
    201                         fielddisplay(self,'epartition','user provided mesh partitioning (element based)');
    202                         fielddisplay(self,'numberofpartitions','number of partitions for semi-discrete qmu')
     174                        fielddisplay(self,'variablepartitions','');
    203175                        fielddisplay(self,'variabledescriptors','');
    204176                        fielddisplay(self,'responsedescriptors','');
     
    223195                        WriteData(fid,prefix,'object',self,'fieldname','numberofresponses','format','Integer');
    224196                        WriteData(fid,prefix,'object',self,'fieldname','variabledescriptors','format','StringArray');
     197                        WriteData(fid,prefix,'object',self,'fieldname','variablepartitions','format','MatArray');
    225198                        WriteData(fid,prefix,'object',self,'fieldname','responsedescriptors','format','StringArray');
    226199                        if ~isempty(self.mass_flux_segments),
  • issm/trunk-jpl/src/m/qmu/preqmu.m

    r24839 r24988  
    8787end
    8888
     89%build a MatArray of variable partitions:
     90variable_fieldnames=fieldnames(md.qmu.variables(ivar));
     91variablepartitions={};
     92for i=1:length(variable_fieldnames),
     93        field_name=variable_fieldnames{i};
     94        fieldvariable=md.qmu.variables(ivar).(field_name);
     95        if fieldvariable.isscaled();
     96                variablepartitions{end+1}=fieldvariable.partition;
     97        else
     98                variablepartitions{end+1}=[];
     99        end
     100end
     101
     102
    89103%register the fields that will be needed by the Qmu model.
    90104md.qmu.numberofresponses=numresponses;
    91105md.qmu.variabledescriptors=variabledescriptors;
     106md.qmu.variablepartitions=variablepartitions;
    92107md.qmu.responsedescriptors=responsedescriptors;
    93108
  • issm/trunk-jpl/src/m/qmu/setupdesign/QmuSetupVariables.m

    r24870 r24988  
    99%ok, key off according to type of descriptor:
    1010if strncmp(descriptor,'scaled_',7),
    11         %we have a scaled variable, expand it over the partition.
     11        %we have a scaled variable, expand it over the partition. First recover the partition:
     12        partition=variables.partition;
     13        %figure out number of partitions:
     14        npart=qmupart2npart(partition)
    1215
    1316        if isa(variables,'uniform_uncertain'),
    14                 if (length(variables.lower)>md.qmu.numberofpartitions || length(variables.upper)>md.qmu.numberofpartitions)
    15                         error('QmuSetupDesign error message: stddev should be either a scalar or a ''npart'' length vector');
     17                nlower=length(variables.lower); nupper=length(variables.upper);
     18                if (nlower ~= npart || nupper ~=npart),
     19                        error('QmuSetupVariables error message: upper and lower fields should be same size as the number of partitions');
    1620                end
    1721        elseif isa(variables,'normal_uncertain'),
    18                 if length(variables.stddev)>md.qmu.numberofpartitions,
    19                         error('QmuSetupDesign error message: stddev should be either a scalar or a ''npart'' length vector');
     22                nstddev=length(variables.stddev);
     23                nmean=length(variables.mean);
     24                if (nstddev ~= npart || nmean ~=npart),
     25                        error('QmuSetupVariables error message: stddev and mean fields should be same size as the number of partitions');
    2026                end
    2127        end
     
    2329        %ok, dealing with semi-discrete distributed variable. Distribute according to how many
    2430        %partitions we want
    25         for j=1:md.qmu.numberofpartitions
     31        for j=1:npart,
    2632                dvar(end+1)           =variables;
    2733                dvar(end  ).descriptor=sprintf('%s_%d',variables.descriptor,j);
    2834                if isa(variables,'uniform_uncertain'),
    29                         if length(variables.lower)>1,
    30                                 dvar(end  ).lower=variables.lower(j);
    31                         end
    32                         if length(variables.upper)>1,
    33                                 dvar(end  ).upper=variables.upper(j);
    34                         end
     35                        dvar(end  ).lower=variables.lower(j);
     36                        dvar(end  ).upper=variables.upper(j);
    3537                elseif isa(variables,'normal_uncertain'),
    36                         if length(variables.stddev)>1,
    37                                 dvar(end  ).stddev=variables.stddev(j);
    38                         end
    39                         if length(variables.mean)>1,
    40                                 dvar(end  ).mean=variables.mean(j);
    41                         end
    42 
     38                        dvar(end  ).stddev=variables.stddev(j);
     39                        dvar(end  ).mean=variables.mean(j);
    4340                end
    4441        end
Note: See TracChangeset for help on using the changeset viewer.