[12038] | 1 | #module imports
|
---|
[13101] | 2 | import numpy
|
---|
[12038] | 3 | from fielddisplay import fielddisplay
|
---|
[13101] | 4 | from EnumDefinitions import *
|
---|
| 5 | from checkfield import *
|
---|
| 6 | from WriteData import *
|
---|
| 7 | from MatlabFuncs import *
|
---|
[12038] | 8 |
|
---|
[13101] | 9 | class qmu(object):
|
---|
| 10 | """
|
---|
| 11 | QMU class definition
|
---|
| 12 |
|
---|
| 13 | Usage:
|
---|
| 14 | qmu=qmu();
|
---|
| 15 | """
|
---|
| 16 |
|
---|
[12038] | 17 | #properties
|
---|
| 18 | def __init__(self):
|
---|
| 19 | # {{{ Properties
|
---|
| 20 | self.isdakota = 0
|
---|
| 21 | self.variables = {}
|
---|
| 22 | self.responses = {}
|
---|
| 23 | self.method = {}
|
---|
| 24 | self.params = {}
|
---|
| 25 | self.results = {}
|
---|
| 26 | self.partition = float('NaN')
|
---|
| 27 | self.numberofpartitions = 0
|
---|
| 28 | self.numberofresponses = 0
|
---|
| 29 | self.variabledescriptors = []
|
---|
| 30 | self.responsedescriptors = []
|
---|
| 31 | self.mass_flux_profile_directory = float('NaN')
|
---|
| 32 | self.mass_flux_profiles = float('NaN')
|
---|
| 33 | self.mass_flux_segments = []
|
---|
| 34 | self.adjacency = float('NaN')
|
---|
| 35 | self.vertex_weight = float('NaN')
|
---|
[12123] | 36 |
|
---|
| 37 | #set defaults
|
---|
| 38 | self.setdefaultparameters()
|
---|
| 39 |
|
---|
[12038] | 40 | #}}}
|
---|
[13101] | 41 |
|
---|
| 42 | def setdefaultparameters(self):
|
---|
[12123] | 43 | # {{{setdefaultparameters
|
---|
[13101] | 44 | return self
|
---|
[12123] | 45 | #}}}
|
---|
| 46 |
|
---|
[13101] | 47 | def checkconsistency(self,md,solution,analyses): # {{{
|
---|
| 48 |
|
---|
| 49 | #Early return
|
---|
| 50 | if not md.qmu.isdakota:
|
---|
| 51 | return
|
---|
| 52 |
|
---|
| 53 | if not md.qmu.params.evaluation_concurrency==1:
|
---|
| 54 | md.checkmessage("concurrency should be set to 1 when running dakota in library mode")
|
---|
| 55 | if md.qmu.partition:
|
---|
| 56 | if not numpy.size(md.qmu.partition)==md.mesh.numberofvertices:
|
---|
| 57 | md.checkmessage("user supplied partition for qmu analysis should have size md.mesh.numberofvertices x 1")
|
---|
| 58 | if not min(md.qmu.partition)==0:
|
---|
| 59 | md.checkmessage("partition vector not indexed from 0 on")
|
---|
| 60 | if max(md.qmu.partition)>=md.qmu.numberofpartitions:
|
---|
| 61 | md.checkmessage("for qmu analysis, partitioning vector cannot go over npart, number of partition areas")
|
---|
| 62 |
|
---|
| 63 | if not strcmpi(md.cluster.name,'none'):
|
---|
| 64 | if not md.settings.waitonlock:
|
---|
| 65 | md.checkmessage("waitonlock should be activated when running qmu in parallel mode!")
|
---|
| 66 |
|
---|
| 67 | return md
|
---|
| 68 | # }}}
|
---|
| 69 |
|
---|
| 70 | def __repr__(self): # {{{
|
---|
| 71 | s =' qmu parameters:\n'
|
---|
| 72 |
|
---|
| 73 | s+="%s\n" % fielddisplay(self,'isdakota','is qmu analysis activated?')
|
---|
| 74 | for i,variable in enumerate(self.variables):
|
---|
| 75 | s+=" variables%s: (arrays of each variable class)\n" % \
|
---|
| 76 | string_dim(self.variables,i)
|
---|
| 77 | fnames=vars(variable)
|
---|
| 78 | maxlen=0
|
---|
| 79 | for fname in fnames:
|
---|
| 80 | maxlen=max(maxlen,len(fname))
|
---|
| 81 |
|
---|
| 82 | for fname in fnames:
|
---|
| 83 | s+="' %-*s: [%ix%i] '%s'\n" % \
|
---|
| 84 | (maxlen+1,fname,size(getattr(variable,fname)),type(getattr(variable,fname)))
|
---|
| 85 |
|
---|
| 86 | for i,response in enumerate(self.responses):
|
---|
| 87 | s+=" responses%s: (arrays of each response class)\n" % \
|
---|
| 88 | string_dim(self.responses,i)
|
---|
| 89 | fnames=vars(response)
|
---|
| 90 | maxlen=0
|
---|
| 91 | for fname in fnames:
|
---|
| 92 | maxlen=max(maxlen,len(fname))
|
---|
| 93 |
|
---|
| 94 | for fname in fnames:
|
---|
| 95 | s+=" %-*s: [%ix%i] '%s'\n" % \
|
---|
| 96 | (maxlen+1,fname,size(getattr(response,fname)),type(getattr(response,fname)))
|
---|
| 97 |
|
---|
| 98 | s+="%s\n" % fielddisplay(self,'numberofresponses','number of responses')
|
---|
| 99 |
|
---|
| 100 | for i,method in enumerate(self.method):
|
---|
| 101 | if isinstance(method,'dakota_method'):
|
---|
| 102 | s+=" method%s : '%s'\n" % \
|
---|
| 103 | (string_dim(method,i),method.method)
|
---|
| 104 |
|
---|
| 105 | for i,param in enumerate(self.params):
|
---|
| 106 | s+=" params%s: (array of method-independent parameters)\n" % \
|
---|
| 107 | string_dim(self.params,i)
|
---|
| 108 | fnames=vars(param)
|
---|
| 109 | maxlen=0
|
---|
| 110 | for fname in fnames:
|
---|
| 111 | maxlen=max(maxlen,len(fname))
|
---|
| 112 |
|
---|
| 113 | for fname in fnames:
|
---|
| 114 | s+=" %-*s: %s\n" % \
|
---|
| 115 | (maxlen+1,fname,any2str(getattr(param,fname)))
|
---|
| 116 |
|
---|
| 117 | for i,result in enumerate(self.results):
|
---|
| 118 | s+=" results%s: (information from dakota files)\n" % \
|
---|
| 119 | string_dim(self.results,i)
|
---|
| 120 | fnames=vars(result)
|
---|
| 121 | maxlen=0
|
---|
| 122 | for fname in fnames:
|
---|
| 123 | maxlen=max(maxlen,len(fname))
|
---|
| 124 |
|
---|
| 125 | for fname in fnames:
|
---|
| 126 | s+=" %-*s: [%ix%i] '%s'\n" % \
|
---|
| 127 | (maxlen+1,fname,size(getattr(result,fname)),type(getattr(result,fname)))
|
---|
| 128 |
|
---|
| 129 | s+="%s\n" % fielddisplay(self,'partition','user provided mesh partitioning, defaults to metis if not specified')
|
---|
| 130 | s+="%s\n" % fielddisplay(self,'numberofpartitions','number of partitions for semi-discrete qmu')
|
---|
| 131 | s+="%s\n" % fielddisplay(self,'variabledescriptors','')
|
---|
| 132 | s+="%s\n" % fielddisplay(self,'responsedescriptors','')
|
---|
| 133 | s+="%s\n" % fielddisplay(self,'method','array of dakota_method class')
|
---|
| 134 | s+="%s\n" % fielddisplay(self,'mass_flux_profile_directory','directory for mass flux profiles')
|
---|
| 135 | s+="%s\n" % fielddisplay(self,'mass_flux_profiles','list of mass_flux profiles')
|
---|
| 136 | s+="%s\n" % fielddisplay(self,'mass_flux_segments','')
|
---|
| 137 | s+="%s\n" % fielddisplay(self,'adjacency','')
|
---|
| 138 | s+="%s\n" % fielddisplay(self,'vertex_weight','weight applied to each mesh vertex')
|
---|
| 139 |
|
---|
| 140 | return s
|
---|
| 141 | # }}}
|
---|
| 142 |
|
---|
| 143 | def marshall(self,fid): # {{{
|
---|
| 144 | WriteData(fid,'object',self,'fieldname','isdakota','format','Boolean')
|
---|
| 145 | if not self.isdakota:
|
---|
| 146 | return
|
---|
| 147 | WriteData(fid,'object',self,'fieldname','partition','format','DoubleMat','mattype',2)
|
---|
| 148 | WriteData(fid,'object',self,'fieldname','numberofpartitions','format','Integer')
|
---|
| 149 | WriteData(fid,'object',self,'fieldname','numberofresponses','format','Integer')
|
---|
| 150 | WriteData(fid,'object',self,'fieldname','variabledescriptors','format','StringArray')
|
---|
| 151 | WriteData(fid,'object',self,'fieldname','responsedescriptors','format','StringArray')
|
---|
| 152 | WriteData(fid,'object',self,'fieldname','mass_flux_segments','format','MatArray')
|
---|
| 153 | # }}}
|
---|
| 154 |
|
---|