Changeset 25015


Ignore:
Timestamp:
06/11/20 14:59:11 (5 years ago)
Author:
jdquinn
Message:

CHG: Dakota interface changes from MATLAB to Python

Location:
issm/trunk-jpl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/qmu.py

    r25011 r25015  
    158158        fv = fieldnames(self.variables)
    159159        for i in range(len(fv)):
    160             getattr(self.variables, fv[i]).checkconsistency(md, solution, analyses)
     160            variable = getattr(self.variables, fv[i])
     161            if hasattr(variable, 'checkconsistency'):
     162                variable.checkconsistency(md, solution, analyses)
    161163
    162164        return md
  • issm/trunk-jpl/src/m/partition/partitioner.py

    r25014 r25015  
    1616    List of options to partitioner:
    1717
    18     package: 'chaco', 'metis'
    19     npart: number of partitions.
     18    package: 'chaco', 'metis', or 'scotch'
     19    npart: number of partitions
    2020    weighting: 'on' or 'off': default off
    21     section:  1 by defaults(1 = bisection, 2 = quadrisection, 3 = octasection)
    22     recomputeadjacency:  'on' by default (set to 'off' to compute existing one)
     21    section: 1 by defaults(1=bisection, 2=quadrisection, 3=octasection)
     22    recomputeadjacency: 'on' by default (set to 'off' to compute existing one)
    2323    type: 'node' or 'element' partition vector (default to 'node')
    2424    Output: partitionvector: the partition vector
     
    3939    vectortype = options.getfieldvalue('type', 'node')  #default to node
    4040
     41    # Python only: short-circuit
    4142    if vectortype == 'element' and not package == 'linear':
    42         raise RuntimeError('partitioner error message: package ' + str(package) + ' does not allow element partitions.')
     43        raise RuntimeError('partitioner error message: package %s does not allow element partitions.' % package)
    4344
    4445    if(md.mesh.dimension() == 3):
     
    6263
    6364    if package == 'chaco':
    64         #raise RuntimeError('Chaco is not currently supported for this function')
    65         #  default method (from chaco.m)
    66         method = np.array([1, 1, 0, 0, 1, 1, 50, 0, 0.001, 7654321])
    67         method[0] = 3  #  global method (3 = inertial (geometric))
    68         method[2] = 0  #  vertex weights (0 = off, 1 = on)
    69         #specify bisection
    70         method[5] = section  #  ndims (1 = bisection, 2 = quadrisection, 3 = octasection)
     65        if vectortype == 'element':
     66            raise RuntimeError('partitioner error message: package %s does not allow element partitions.' % package)
     67        else:
     68            #  default method (from chaco.m)
     69            method = np.array([1, 1, 0, 0, 1, 1, 50, 0, 0.001, 7654321])
     70            method[0] = 3  #  global method (3 = inertial (geometric))
     71            method[2] = 0  #  vertex weights (0 = off, 1 = on)
    7172
    72         #are we using weights?
    73         if weighting == 'on':
    74             weights = np.floor(md.qmu.vertex_weight / min(md.qmu.vertex_weight))
    75             method[2] = 1
    76         else:
    77             weights = []
     73            #specify bisection
     74            method[5] = section  #  ndims (1 = bisection, 2 = quadrisection, 3 = octasection)
    7875
    79         method = method.reshape(-1, 1)  # transpose to 1x10 instead of 10
    80         #  partition into nparts
    81         if isinstance(md.mesh, mesh2d):
    82             part = np.array(Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, np.zeros((md.mesh.numberofvertices, )), method, npart, np.array([]))).T + 1  #index partitions from 1 up. like metis.
    83         else:
    84             part = np.array(Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, md.mesh.z, method, npart, np.array([]))).T + 1  #index partitions from 1 up. like metis.
     76            #are we using weights?
     77            if weighting == 'on':
     78                weights = np.floor(md.qmu.vertex_weight / min(md.qmu.vertex_weight))
     79                method[2] = 1
     80            else:
     81                weights = []
     82
     83            method = method.reshape(-1, 1)  # transpose to 1x10 instead of 10
     84
     85            #  partition into nparts
     86            if isinstance(md.mesh, mesh2d):
     87                part = np.array(Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, np.zeros((md.mesh.numberofvertices, )), method, npart, np.array([]))).T + 1  #index partitions from 1 up. like metis.
     88            else:
     89                part = np.array(Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, md.mesh.z, method, npart, np.array([]))).T + 1  #index partitions from 1 up. like metis.
    8590
    8691    elif package == 'scotch':
    87         raise RuntimeError('Scotch is not currently supported for this function')
     92        if vectortype == 'element':
     93            raise RuntimeError('partitioner error message: package %s does not allow element partitions.' % package)
     94        else:
     95            #are we using weights?
     96            if m.strcmpi(options.getfieldvalue('weighting'), 'on'):
     97                weights = np.floor(md.qmu.vertex_weight / min(md.qmu.vertex_weight))
     98            else:
     99                weights = []
     100            maptab = Scotch(md.qmu.adjacency, [], weights, [], 'cmplt', [npart])
    88101
    89     #are we using weights?
    90     #if m.strcmpi(options.getfieldvalue('weighting'), 'on'):
    91     #weights = np.floor(md.qmu.vertex_weight / min(md.qmu.vertex_weight))
    92     #else:
    93     #weights = []
    94     #maptab = Scotch(md.qmu.adjacency, [], weights, [], 'cmplt', [npart])
    95     #part = maptab[:, 1] + 1  #index partitions from 1 up. like metis.
     102            part = maptab[:, 1] + 1 #index partitions from 1 up. like metis.
    96103
    97104    elif package == 'linear':
    98 
    99         if (npart == md.mesh.numberofelements) or (md.qmu.numberofpartitions == md.mesh.numberofelements):
     105        if vectortype == 'element':
    100106            part = np.arange(1, 1 + md.mesh.numberofelements, 1)
    101107            print('Linear partitioner requesting partitions on elements')
     
    104110
    105111    elif package == 'metis':
    106         raise RuntimeError('Metis/MeshPartition is not currently supported for this function')
    107     #[element_partitioning, part] = MeshPartition(md, md.qmu.numberofpartitions)
     112        if vectortype == 'element':
     113            raise RuntimeError('partitioner error message: package %s does not allow element partitions.' % package)
     114        else:
     115            [element_partitioning, part] = MeshPartition(md, md.qmu.numberofpartitions)
    108116
    109117    else:
    110         print(help)
    111         raise RuntimeError('partitioner error message: could not find ' + str(package) + ' partitioner')
     118        raise RuntimeError('partitioner error message: could not find %s partitioner' % package)
    112119
    113120    #extrude if we are in 3D:
  • issm/trunk-jpl/src/m/qmu/importancefactors.py

    r24873 r25015  
    11import numpy as np
     2
    23from MatlabFuncs import *
    34
    45
    5 def importancefactors(md, variablename, responsename):
    6     '''IMPORTANCEFACTORS - compute importance factors for a certain variable and response.
     6def importancefactors(md, variablename, responsename, partition):
     7    '''
     8    IMPORTANCEFACTORS - compute importance factors for a certain variable and response.
    79
    8 Usage:
    9     factors = importancefactors(md, variablename, responsename)
     10    Usage:
     11        factors = importancefactors(md, variablename, responsename)
    1012
    1113    Example: factors = importancefactors(md, 'drag', 'max_vel')
    12 '''
     14    '''
    1315
    1416    variablenamelength = len(variablename)
     
    4446        factors = importancefactors
    4547        return factors
    46     elif count == np.max(md.qmu.epartition + 1):
     48    elif count == np.max(partition + 1):
    4749        #distribute importance factor
    48         factors = importancefactors[(md.qmu.epartition.conj().T).flatten().astype(int)]
     50        factors = importancefactors[(partition.conj().T).flatten().astype(int)]
    4951    #md.qmu.partition was created to index "c" style
    5052    else:
    5153        #distribute importance factor
    52         factors = importancefactors[(md.qmu.vpartition.conj().T).flatten().astype(int)]
     54        factors = importancefactors[(partition.conj().T).flatten().astype(int)]
    5355    #md.qmu.partition was created to index "c" style
    5456
  • issm/trunk-jpl/src/m/qmu/preqmu.m

    r24998 r25015  
    8888
    8989%build a MatArray of variable partitions:
    90 variable_fieldnames=fieldnames(md.qmu.variables(ivar));
    9190variablepartitions={};
    9291variablepartitions_npart=[];
     92variable_fieldnames=fieldnames(md.qmu.variables(ivar));
    9393for i=1:length(variable_fieldnames),
    9494        field_name=variable_fieldnames{i};
     
    104104
    105105%build a MatArray of response partitions:
    106 response_fieldnames=fieldnames(md.qmu.responses(ivar));
    107106responsepartitions={};
    108107responsepartitions_npart=[];
     108response_fieldnames=fieldnames(md.qmu.responses(iresp));
    109109for i=1:length(response_fieldnames),
    110110        field_name=response_fieldnames{i};
    111         fieldresponse=md.qmu.responses(ivar).(field_name);
     111        fieldresponse=md.qmu.responses(iresp).(field_name);
    112112        if fieldresponse.isscaled();
    113113                responsepartitions{end+1}=fieldresponse.partition;
  • issm/trunk-jpl/src/m/qmu/preqmu.py

    r25013 r25015  
    77from MatlabFuncs import *
    88from process_qmu_response_data import *
    9 from qmupart2npart import *
     9from qmupart2npart import qmupart2npart
    1010
    1111
    1212def preqmu(md, options):
    13     '''QMU - apply Quantification of Margins and Uncertainties techniques
     13    '''
     14    QMU - apply Quantification of Margins and Uncertainties techniques
    1415    to a solution sequence (like stressbalance.py, progonstic.py, etc ...),
    1516    using the Dakota software from Sandia.
    1617
    17    options come from the solve.py routine. They can include Dakota options:
     18    options come from the solve.py routine. They can include Dakota options:
    1819
    1920    qmufile: input file for Dakota
     
    2425    imethod: same thing for methods
    2526    iparams: same thing for params
    26 '''
     27    '''
    2728
    2829    print('preprocessing dakota inputs')
     
    104105    #fieldresponses = vars(md.qmu.responses[iresp])[field_name]
    105106        fieldresponses = vars(md.qmu.responses)[field_name]
    106         for j in range(np.size(fieldresponses)):
    107             responsedescriptors.append(fieldresponses[j].descriptor)
     107        if type(fieldresponses) in [list, np.ndarray]:
     108            for j in range(np.size(fieldresponses)):
     109                responsedescriptors.append(fieldresponses[j].descriptor)
     110        else:
     111            responsedescriptors.append(fieldresponses.descriptor)
    108112    #}}}
    109113
     
    114118    for i in range(len(variable_fieldnames)):
    115119        field_name = variable_fieldnames[i]
    116         fieldvariable = getattr(md.qmu.variables, field_name)
    117         if fieldvariable.isscaled():
    118             variablepartitions.append(fieldvariable.partition)
    119             variablepartitions_npart.append(qmupart2npart(fieldvariable.partition))
     120        fieldvariable = vars(md.qmu.variables)[field_name]
     121        if type(fieldvariable) in [list, np.ndarray]:
     122            for j in range(np.size(fieldvariable)):
     123                if fieldvariable[j].isscaled():
     124                    variablepartitions.append(fieldvariable[j].partition)
     125                    variablepartitions_npart.append(qmupart2npart(fieldvariable[j].partition))
     126                else:
     127                    variablepartitions.append([])
     128                    variablepartitions_npart.append(0)
    120129        else:
    121             variablepartitions.append([])
    122             variablepartitions_npart.append(0)
     130            if fieldvariable.isscaled():
     131                variablepartitions.append(fieldvariable.partition)
     132                variablepartitions_npart.append(qmupart2npart(fieldvariable.partition))
     133            else:
     134                variablepartitions.append([])
     135                variablepartitions_npart.append(0)
    123136
    124137    # Build a list of response partitions
     
    128141    for i in range(len(response_fieldnames)):
    129142        field_name = response_fieldnames[i]
    130         fieldresponse = getattr(md.qmu.variables, field_name)
    131         if fieldresponse.isscaled():
    132             responsepartitions.append(fieldresponse.partition)
    133             responsepartitions_npart.append(qmupart2npart(fieldresponse.partition))
     143        fieldresponse = vars(md.qmu.responses)[field_name]
     144        if type(fieldresponses) in [list, np.ndarray]:
     145            for j in range(np.size(fieldresponses)):
     146                if fieldresponse[j].isscaled():
     147                    responsepartitions.append(fieldresponse[j].partition)
     148                    responsepartitions_npart.append(qmupart2npart(fieldresponse.partition))
     149                else:
     150                    responsepartitions.append([])
     151                    responsepartitions_npart.append(0)
    134152        else:
    135             responsepartitions.append([])
    136             responsepartitions_npart.append(0)
     153            if fieldresponse.isscaled():
     154                responsepartitions.append(fieldresponse.partition)
     155                responsepartitions_npart.append(qmupart2npart(fieldresponse.partition))
     156            else:
     157                responsepartitions.append([])
     158                responsepartitions_npart.append(0)
    137159
    138160    # register the fields that will be needed by the Qmu model.
  • issm/trunk-jpl/test/NightlyRun/test244.py

    r24870 r25015  
    6868
    6969#partitioning
    70 md.qmu.numberofpartitions = md.mesh.numberofelements
    71 md = partitioner(md, 'package', 'linear', 'type', 'element')
    72 md.qmu.epartition = (md.qmu.epartition - 1)
     70npart = md.mesh.numberofelements
     71partition = partitioner(md, 'package', 'linear', 'type', 'element', 'npart', npart) - 1
    7372
    7473#variables
    7574md.qmu.variables.surface_mass_balance = normal_uncertain.normal_uncertain(
    7675    'descriptor', 'scaled_SmbC',
    77     'mean', np.ones(md.qmu.numberofpartitions),
    78     'stddev', .5 * np.ones(md.qmu.numberofpartitions),
    79     'partition', md.qmu.epartition
     76    'mean', np.ones(md.mesh.numberofelements),
     77    'stddev', .5 * np.ones(md.mesh.numberofelements),
     78    'partition', partition
    8079    )
    8180Tmin = 273.
     
    8382mint_on_partition = telms.flatten()
    8483for pa in range(np.size(mint_on_partition)):
    85     vi = np.where(md.qmu.epartition == pa)
     84    vi = np.where(partition == pa)
    8685    mint = telms[0, vi] * 1.05
    8786    pos = np.where(mint < Tmin)
     
    9291md.qmu.variables.surface_mass_balanceTa = uniform_uncertain.uniform_uncertain(
    9392    'descriptor', 'scaled_SmbTa',
    94     'lower', .95 * np.ones(md.qmu.numberofpartitions),
     93    'lower', .95 * np.ones(md.mesh.numberofelements),
    9594    'upper', np.maximum(np.minimum(np.maximum(1.05, mint_on_partition), 0.9999), 0.0001),
    96     'partition', md.qmu.epartition
     95    'partition', partition
    9796    )
    9897
Note: See TracChangeset for help on using the changeset viewer.