source: issm/trunk-jpl/src/m/qmu/dakota_in_data.py@ 23716

Last change on this file since 23716 was 23716, checked in by bdef, 6 years ago

CHG: shifting to py3 version of python interface (py2 compatible)

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