| 1 | #move this stuff elsewhere
|
|---|
| 2 | from helpers import *
|
|---|
| 3 |
|
|---|
| 4 | from dakota_in_write import *
|
|---|
| 5 | from dakota_in_params import *
|
|---|
| 6 | from MatlabFuncs import *
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | def dakota_in_data(dmeth, variables, responses, dparams, filei, *args):
|
|---|
| 10 | '''
|
|---|
| 11 | DAKOTA_IN_DATA - define the data to write the dakota .in and .m files.
|
|---|
| 12 |
|
|---|
| 13 | Usage:
|
|---|
| 14 | [] = dakota_in_data(dmeth, variables, responses, dparams, filei, *args)
|
|---|
| 15 |
|
|---|
| 16 | where the required input is:
|
|---|
| 17 | dmeth (dakota_method, method class object)
|
|---|
| 18 | variables (structure array, variable class objects)
|
|---|
| 19 | responses (structure array, response class objects)
|
|---|
| 20 | dparams (structure array, method - independent parameters)
|
|---|
| 21 | filei (character, name of .in and .m files)
|
|---|
| 22 |
|
|---|
| 23 | Params may be empty, in which case defaults will be used.
|
|---|
| 24 |
|
|---|
| 25 | The optional args are passed directly through to the QmuUpdateFunctions
|
|---|
| 26 | brancher to be used by the analysis package. For example, this could be
|
|---|
| 27 | model information.
|
|---|
| 28 |
|
|---|
| 29 | This function defines the data to write the dakota .in and .m files. It is
|
|---|
| 30 | necessary for multiple reasons. First, it collects the parameters and
|
|---|
| 31 | applies some defaults that are unique to the environment. Second, some
|
|---|
| 32 | analysis package ariables and/or responses may be treated differently by
|
|---|
| 33 | Dakota. For example, an analysis package variable may be defined as an
|
|---|
| 34 | array, so the QmuSetupDesign brancher will create Dakota variables for each
|
|---|
| 35 | element of the array. Finally, it calls the functions to write the .in and
|
|---|
| 36 | .m files. this function is independent of the particular analysis package.
|
|---|
| 37 |
|
|---|
| 38 | This data would typically be generated by a MATLAB script for a specific
|
|---|
| 39 | model, using the method, variable, and response class objects.
|
|---|
| 40 | '''
|
|---|
| 41 |
|
|---|
| 42 | # parameters
|
|---|
| 43 | # get default set of parameters
|
|---|
| 44 | params = dakota_in_params(struct())
|
|---|
| 45 | # merge specified parameters into default set, whether or not
|
|---|
| 46 | # they already exist
|
|---|
| 47 | fnames = fieldnames(dparams)
|
|---|
| 48 |
|
|---|
| 49 | for fieldname in fnames:
|
|---|
| 50 | if not isfield(params, fieldname):
|
|---|
| 51 | print('WARNING: dakota_in_data:unknown_param: No parameter {} in default parameter set.'.format(str(fieldname)))
|
|---|
| 52 | exec('params.{} = vars(dparams)[fieldname]'.format(fieldname))
|
|---|
| 53 |
|
|---|
| 54 | # use matlab even though we are running python
|
|---|
| 55 | if params.direct and params.analysis_driver == '':
|
|---|
| 56 | params.analysis_driver = 'matlab'
|
|---|
| 57 |
|
|---|
| 58 | if strcmpi(params.analysis_driver, 'matlab') and params.analysis_components == '':
|
|---|
| 59 | [pathstr, name, ext] = fileparts(filei)
|
|---|
| 60 | params.analysis_components = fullfile(pathstr, name + '.py')
|
|---|
| 61 |
|
|---|
| 62 | # merge method parameters, though they shouldn't be in dparams
|
|---|
| 63 | # dmeth = dmeth_params_merge(dmeth, dparams)
|
|---|
| 64 |
|
|---|
| 65 | # variables
|
|---|
| 66 | fnames = fieldnames(variables)
|
|---|
| 67 |
|
|---|
| 68 | # works like matlab arbitrary structs / classes, remembers order of input attributes
|
|---|
| 69 | dvar = OrderedStruct()
|
|---|
| 70 | dresp = OrderedStruct()
|
|---|
| 71 |
|
|---|
| 72 | for i in range(len(fnames)):
|
|---|
| 73 | # currently all variable types can just be copied
|
|---|
| 74 | exec(('dvar.%s = vars(variables)[fnames[i]]') % (fnames[i]))
|
|---|
| 75 |
|
|---|
| 76 | # responses
|
|---|
| 77 | fnames = fieldnames(responses)
|
|---|
| 78 |
|
|---|
| 79 | for i in range(len(fnames)):
|
|---|
| 80 | # currently all response types can just be copied
|
|---|
| 81 | exec(('dresp.%s = vars(responses)[fnames[i]]') % (fnames[i]))
|
|---|
| 82 |
|
|---|
| 83 | # write files
|
|---|
| 84 | #Write in file
|
|---|
| 85 | dakota_in_write(dmeth, dvar, dresp, params, filei, *args)
|
|---|