def write_needed_inputs( self, source_file_path: str = None, source_formatter: IVariableIOFormatter = None, ): """ Writes the input file of the problem with unconnected inputs of the problem. .. warning:: :meth:`setup` must have been run on this Problem instance. Written value of each variable will be taken: 1. from input_data if it contains the variable 2. from defined default values in component definitions WARNING: if inputs have already been read, they won't be needed any more and won't be in written file. :param source_file_path: if provided, variable values will be read from it :param source_formatter: the class that defines format of input file. if not provided, expected format will be the default one. """ variables = VariableList.from_unconnected_inputs( self, with_optional_inputs=True) if source_file_path: ref_vars = VariableIO(source_file_path, source_formatter).read() variables.update(ref_vars) for var in variables: var.is_input = True writer = VariableIO(self.input_file_path) writer.write(variables)
def write_needed_inputs(self, source_file_path: str = None, source_formatter: IVariableIOFormatter = None): """ Writes the input file of the problem with unconnected inputs of the configured problem. Written value of each variable will be taken: 1. from input_data if it contains the variable 2. from defined default values in component definitions :param source_file_path: if provided, variable values will be read from it :param source_formatter: the class that defines format of input file. if not provided, expected format will be the default one. """ problem = self.get_problem(read_inputs=False) problem.setup() variables = DataFile(self.input_file_path, load_data=False) variables.update( VariableList.from_unconnected_inputs(problem, with_optional_inputs=True), add_variables=True, ) if source_file_path: ref_vars = DataFile(source_file_path, formatter=source_formatter) variables.update(ref_vars, add_variables=False) for var in variables: var.is_input = True variables.save()
def run_system( component: System, input_vars: om.IndepVarComp, setup_mode="auto", add_solvers=False ): """Runs and returns an OpenMDAO problem with provided component and data""" problem = om.Problem() model = problem.model model.add_subsystem("inputs", input_vars, promotes=["*"]) model.add_subsystem("component", component, promotes=["*"]) if add_solvers: model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False) model.linear_solver = om.DirectSolver() problem.setup(mode=setup_mode) vars = VariableList.from_unconnected_inputs(problem) assert not vars, "These inputs are not provided: %s" % vars.names() problem.run_model() return problem