def __init__(self): super(SimORK, self).__init__() # Input File self.add_param('rocketFile', FileRef('rocket.ork'), binary=True, pass_by_obj=True) self.add_param('WindSpeed', val=0.0) # Output Flight Metrics self.add_output('MaxVelocity', shape=1) self.add_output('MaxAltitude', shape=1) self.add_output('MaxAcceleration', shape=1) self.add_output('MaxMach', shape=1) self.add_output('GroundHitVelocity', shape=1) self.add_output('LaunchRodVelocity', shape=1) self.add_output('FlightTime', shape=1) self.add_output('MaxStability', shape=1) self.add_output('LaunchRodClearanceStability', shape=1) self.add_output('LaunchRodClearanceMass', shape=1) # rocket mass at launch rod clearance self.add_output('BurnoutMass', shape=1) # rocket mass at motor burnout self.add_output('Rocket_Images', FileRef('Rocket_Images.zip'), binary=True, pass_by_obj=True) self.openRocket = None self.imageDirectory = 'Rocket_Images.zip'
def __init__(self, path=''): super(FileSink, self).__init__() self.add_param("ascii_in", FileRef(os.path.join(path, "ascii_final.dat"))) self.add_param("bin_in", FileRef(os.path.join(path, "bin_final.dat")), binary=True)
def __init__(self, path=''): super(FilePass, self).__init__() self.add_param("ascii_in", FileRef(os.path.join(path,"ascii.dat"))) self.add_param("bin_in", FileRef(os.path.join(path,"bin.dat")), binary=True) self.add_output("ascii_out", FileRef(os.path.join(path,"ascii.out"))) self.add_output("bin_out", FileRef(os.path.join(path,"bin.out")), binary=True)
def __init__(self, path='', *args, **kwargs): super(FileProducer, self).__init__(*args, **kwargs) self.add_param('unused', val=0.0) self.add_output('outfile', FileRef(os.path.join(path, 'bin.out')), binary=True)
def __init__(self): super(TestbenchTiming, self).__init__() self.add_param("manifest", val=FileRef("manifest.json"), binary=True, pass_by_obj=True) self.add_output("timing_info", val="[]", pass_by_obj=True) self.add_output("total_time", val=0.0)
def __init__(self): super(ZipProducer, self).__init__() self.add_param("a", val=3.0) self.add_param("b", val=2.0) self.add_output("output_directory_zip", val=FileRef("output_dir.zip"), pass_by_obj=True, binary=True)
def __init__(self, path='', *args, **kwargs): super(FileConsumer, self).__init__(*args, **kwargs) self.add_param('infile', FileRef(os.path.join(path, 'differently_named_bin.dat')), binary=True) self.add_output('checksum', val=0)
def __init__(self): super(ZipConsumer, self).__init__() self.add_param("input_directory_zip", val=FileRef("input_dir.zip"), pass_by_obj=True, binary=True) self.add_output("addition", val=0.0) self.add_output("subtraction", val=0.0) self.add_output("multiplication", val=0.0)
def __init__(self): super(WriteStrToFile, self).__init__() # Note: FileRef("{}_input.txt".format(id(self))) is due to an OpenMDAO idiosyncrasy # whenever you have mutiple Components accepting the same FileRef inputs. # In OpenMDAO, FileRef input that share the same name are implicitly linked # even if they aren't explicitly linked... # https://github.com/OpenMDAO/OpenMDAO1/blob/master/openmdao/core/_checks.py#L38 self.add_param("input_file", val=FileRef("{}_input.txt".format(id(self))), pass_by_obj=True, binary=True) self.add_param("input_str", val=u"", pass_by_obj=True) self.add_output("output_file", val=FileRef("output.txt"), pass_by_obj=True, binary=True) self.add_output("output_str", val=u"", pass_by_obj=True)
def __init__(self): super(GenORK, self).__init__() #Python wrapper inputs self.add_param('payload_mass', val=0.0) self.add_param('coneshape', val=0.0, description='nosecone shape', pass_by_obj=True) self.add_param('noselen_coeff', val=0.0) self.add_param('bodylen_coeff', val=0.0) self.add_param('fintype', val=0.0, description='planform fin shape', pass_by_obj=True) self.add_param('fincount', val=0.0, description='number of fins', pass_by_obj=True) self.add_param('finprofile', val=0.0, description='fin profile', pass_by_obj=True) self.add_param('motorclass', val=0.0, description='class of motor', pass_by_obj=True) self.add_param('material', val=0.0, description='material used', pass_by_obj=True) self.add_param('density', val=0.0, description='density of material [kg/m^3]', pass_by_obj=True) self.add_param('finish', val=0.0, description='finish used', pass_by_obj=True) self.add_param('launchrodlength', val=0.0) # Output: ORK File self.add_output('ORK_File', FileRef('test.ork'), binary=True, pass_by_obj=True)
def __init__(self, name, mdao_config, root, subproblem_output_meta): super(TestBenchComponent, self).__init__() self.name = name self.mdao_config = mdao_config self.__directory = mdao_config['components'][name]['details'][ 'directory'] self.original_testbench_manifest = self._read_testbench_manifest() self.manifest_params = { param['Name']: param for param in self.original_testbench_manifest['Parameters'] } self.manifest_fileinputs = { param['Name']: param for param in self.original_testbench_manifest.get( 'FileInputs', []) } self.manifest_metrics = { param['Name']: param for param in self.original_testbench_manifest['Metrics'] } self.manifest_fileoutputs = { param['Name']: param for param in self.original_testbench_manifest.get( 'FileOutputs', {}) } self.deriv_options['type'] = 'fd' def get_meta(param): units = param.get('units') if units: return {'units': str(units)} else: return {} for param_name, param in six.iteritems( mdao_config['components'][name].get('parameters', {})): pass_by_obj = source_is_not_driver = param.get( 'source', [''])[0] not in mdao_config['drivers'] val = 0.0 manifest_fileinput = self.manifest_fileinputs.get(param_name) if manifest_fileinput is not None: val = FileRef( os.path.join( self.__directory, manifest_fileinput.get('FileName', param_name))) self.add_param(_get_param_name(param_name), val=val, binary=True) continue elif source_is_not_driver and 'source' in param: if len(param['source']) == 1: # TODO: Single-element source must be a ProblemInput problemInput = mdao_config['problemInputs'][param['source'] [0]] if 'innerSource' in problemInput and problemInput[ 'innerSource'][0] in mdao_config['drivers']: source_type = mdao_config['drivers'][ problemInput['innerSource'][0]]['designVariables'][ problemInput['innerSource'][1]].get('type') if source_type == 'enum': val = mdao_config['drivers'][problemInput[ 'innerSource'][0]]['designVariables'][ problemInput['innerSource'][1]]['items'][0] pass_by_obj = True elif source_type == "int": val = 0 else: (val, pass_by_obj) = get_problem_input_value(problemInput) else: if param['source'][0] in mdao_config.get( 'subProblems', {}): # Source is a subproblem output; look up its real path, value, and pass_by_obj-ness source_component = { c.name: c for c in root.components() }[param['source'][0]] output_name = subproblem_output_meta[ param['source'][0]][param['source'][1]] meta = source_component._problem.root.unknowns._dat[ output_name].meta val = meta['val'] pass_by_obj = meta.get('pass_by_obj', False) else: # Source is not a subproblem output; must be a component source_component = { c.name: c for c in root.components() }[param['source'][0]] val = source_component._init_unknowns_dict[ param['source'][-1]]['val'] pass_by_obj = source_component._init_unknowns_dict[ param['source'][-1]].get('pass_by_obj', False) elif 'source' in param: source_type = mdao_config['drivers'][param['source'][0]][ 'designVariables'][param['source'][-1]].get('type') if source_type == 'enum': val = mdao_config['drivers'][param['source'][0]][ 'designVariables'][param['source'][-1]]['items'][0] pass_by_obj = True elif source_type == "int": val = 0 else: manifest_param = self.manifest_params.get(param_name) if manifest_param is not None: val = manifest_param['Value'] pass_by_obj = True else: raise ValueError( 'Could not find parameter or input file named {} in testbench_manifest.json' .format(param_name)) self.add_param(_get_param_name(param_name), val=val, pass_by_obj=pass_by_obj, **get_meta(param)) for metric_name, metric in six.iteritems( mdao_config['components'][name].get('unknowns', {})): manifest_metric = self.manifest_metrics.get(metric_name) if manifest_metric is not None: pass_by_obj = True for driver in mdao_config['drivers'].values(): if driver.get('type') != 'optimizer': continue for objective in driver['objectives'].values(): if objective['source'][0] == name and objective[ 'source'][1] == metric_name: pass_by_obj = False self.add_output(metric_name, val=0.0, pass_by_obj=pass_by_obj, **get_meta(metric)) else: manifest_fileoutput = self.manifest_fileoutputs.get( metric_name) if manifest_fileoutput is None: raise ValueError(metric_name) self.add_output(metric_name, val=FileRef( os.path.join( self.__directory, manifest_fileoutput.get( 'FileName', metric_name))), binary=True) self.add_output('_ret_code', val=0, pass_by_obj=True)
def __init__(self, iname, oname): super(FileMid, self).__init__() self.add_param("fin", FileRef(iname + '.dat')) self.add_output("fout", FileRef(oname + '.out'))
def __init__(self): super(FileBin, self).__init__() self.add_output("fout", FileRef("file.dat"), binary=True)
def __init__(self): super(FileNoBin, self).__init__() self.add_param("fin", FileRef("file.dat"))
def __init__(self, name): super(FileSrc, self).__init__() self.add_output("fout", FileRef(name + '.dat'))
def __init__(self, path=''): super(FileSrc, self).__init__() self.add_output("ascii_dat", FileRef(os.path.join(path,"ascii.dat"))) self.add_output("bin_dat", FileRef(os.path.join(path,"bin.dat")), binary=True)
def __init__(self, name, mdao_config, root, subproblem_output_meta): super(TestBenchComponent, self).__init__() self.name = name self.mdao_config = mdao_config self.__directory = mdao_config['components'][name]['details'][ 'directory'] self.original_testbench_manifest = self._read_testbench_manifest() self.manifest_params = { param['Name']: param for param in self.original_testbench_manifest['Parameters'] } self.manifest_fileinputs = { param['Name']: param for param in self.original_testbench_manifest.get( 'FileInputs', []) } self.manifest_metrics = { param['Name']: param for param in self.original_testbench_manifest['Metrics'] } self.manifest_fileoutputs = { param['Name']: param for param in self.original_testbench_manifest.get( 'FileOutputs', {}) } self.deriv_options['type'] = 'fd' def get_meta(param): units = param.get('units') if units: return {'units': str(units)} else: return {} for param_name, param in six.iteritems( mdao_config['components'][name].get('parameters', {})): pass_by_obj = source_is_not_driver = param.get( 'source', [''])[0] not in mdao_config['drivers'] val = 0.0 manifest_fileinput = self.manifest_fileinputs.get(param_name) if manifest_fileinput is not None: val = FileRef( os.path.join( self.__directory, manifest_fileinput.get('FileName', param_name))) self.add_param(_get_param_name(param_name), val=val, binary=True, pass_by_obj=True) continue elif source_is_not_driver and 'source' in param: if len(param['source']) == 1: # TODO: Single-element source must be a ProblemInput problemInput = mdao_config['problemInputs'][param['source'] [0]] if 'innerSource' in problemInput and problemInput[ 'innerSource'][0] in mdao_config['drivers']: source_type = mdao_config['drivers'][ problemInput['innerSource'][0]]['designVariables'][ problemInput['innerSource'][1]].get('type') if source_type == 'enum': val = mdao_config['drivers'][problemInput[ 'innerSource'][0]]['designVariables'][ problemInput['innerSource'][1]]['items'][0] pass_by_obj = True elif source_type == "int": val = 0 else: (val, pass_by_obj) = get_problem_input_value(problemInput) else: if param['source'][0] in mdao_config.get( 'subProblems', {}): # Source is a subproblem output; look up its real path, value, and pass_by_obj-ness source_component = { c.name: c for c in root.components() }[param['source'][0]] output_name = subproblem_output_meta[ param['source'][0]][param['source'][1]] meta = source_component._problem.root.unknowns._dat[ output_name].meta val = meta['val'] pass_by_obj = meta.get('pass_by_obj', False) else: # Source is not a subproblem output; must be a component source_component = { c.name: c for c in root.components() }[param['source'][0]] val = source_component._init_unknowns_dict[ param['source'][-1]]['val'] pass_by_obj = source_component._init_unknowns_dict[ param['source'][-1]].get('pass_by_obj', False) elif 'source' in param: source_type = mdao_config['drivers'][param['source'][0]][ 'designVariables'][param['source'][-1]].get('type') if source_type == 'enum': val = mdao_config['drivers'][param['source'][0]][ 'designVariables'][param['source'][-1]]['items'][0] pass_by_obj = True elif source_type == "int": val = 0 else: manifest_param = self.manifest_params.get(param_name) if manifest_param is not None: val = manifest_param['Value'] pass_by_obj = True else: raise ValueError( 'Could not find parameter or input file named {} in testbench_manifest.json' .format(param_name)) self.add_param(_get_param_name(param_name), val=val, pass_by_obj=pass_by_obj, **get_meta(param)) for metric_name, metric in six.iteritems( mdao_config['components'][name].get('unknowns', {})): manifest_metric = self.manifest_metrics.get(metric_name) if manifest_metric is not None: pass_by_obj = True for driver in mdao_config['drivers'].values(): if driver.get('type') != 'optimizer': continue for objective in driver['objectives'].values(): if objective['source'][0] == name and objective[ 'source'][1] == metric_name: pass_by_obj = False metric_meta = get_meta(metric) metric_meta['val'] = 0.0 for mdao_component in root.components(): # TODO: metric is possibly connected to a subproblem problemOutput. We should handle this case (root.components() does not contain the desired component, nor is it created yet) destination_component = mdao_config['components'].get( mdao_component.name) if destination_component is None: # TODO: possibly connected to an input to a component in a subproblem. We should handle this case # destination_component should possibly be an IndepVarComp from a ProblemInput. We don't need to handle this case # destination_component should possibly be an IndepVarComp designVariable. We don't need to handle this case continue for parameter_name, parameter in six.iteritems( destination_component['parameters']): if parameter['source'] == [self.name, metric_name]: mdao_parameter = mdao_component._init_params_dict[ _get_param_name( parameter_name, destination_component.get('type'))] for key in ('val', 'shape'): next_val = mdao_parameter.get(key, None) if next_val is not None: metric_meta.pop('val', None) metric_meta[key] = next_val if key == 'val': pass_by_obj = pass_by_obj or not is_differentiable( next_val) break self.add_output(metric_name, pass_by_obj=pass_by_obj, **metric_meta) else: manifest_fileoutput = self.manifest_fileoutputs.get( metric_name) if manifest_fileoutput is None: raise ValueError(metric_name) self.add_output(metric_name, val=FileRef( os.path.join( self.__directory, manifest_fileoutput.get( 'FileName', metric_name))), binary=True, pass_by_obj=True) self.add_output('_ret_code', val=0, pass_by_obj=True)
def __init__(self): super(file_player, self).__init__() self.add_param('Number', val=0.0) self.add_output('File', FileRef('file.txt'), binary=True, pass_by_obj=True)
def __init__(self, name, num_ins): super(FileSink, self).__init__() for i in range(num_ins): self.add_param("fin%d" % i, FileRef(name + '%d.in' % i))