def test_circuit_recurse(self): # Implicit component is also tested here import openmdao.api as om p = om.Problem() model = p.model model.add_subsystem('ground', om.IndepVarComp('V', 0., units='V')) model.add_subsystem('source', om.IndepVarComp('I', 0.1, units='A')) model.add_subsystem('circuit', Circuit()) model.connect('source.I', 'circuit.I_in') model.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup() # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() om.write_xdsm(p, 'xdsmjs_circuit', out_format='html', quiet=QUIET, show_browser=SHOW, recurse=True) self.assertTrue(os.path.isfile('.'.join(['xdsmjs_circuit', 'html'])))
def test_legend(self): from openmdao.api import Problem, IndepVarComp p = Problem() model = p.model model.add_subsystem('ground', IndepVarComp('V', 0., units='V')) model.add_subsystem('source', IndepVarComp('I', 0.1, units='A')) model.add_subsystem('circuit', Circuit()) model.connect('source.I', 'circuit.I_in') model.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup(check=False) # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() write_xdsm(p, 'xdsmjs_circuit_legend', out_format='html', quiet=QUIET, show_browser=SHOW, recurse=True, legend=True) self.assertTrue(os.path.isfile('.'.join(['xdsmjs_circuit_legend', 'html'])))
def test_legend_and_class_names(self): import openmdao.api as om p = om.Problem() model = p.model model.add_subsystem('ground', om.IndepVarComp('V', 0., units='V')) model.add_subsystem('source', om.IndepVarComp('I', 0.1, units='A')) model.add_subsystem('circuit', Circuit()) model.connect('source.I', 'circuit.I_in') model.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup() # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() write_xdsm(p, 'xdsmjs_circuit_legend', out_format='html', quiet=QUIET, show_browser=SHOW, recurse=True, legend=True) self.assertTrue(os.path.isfile('xdsmjs_circuit_legend' + '.html')) write_xdsm(p, 'xdsmjs_circuit_class_names', out_format='html', quiet=QUIET, show_browser=SHOW, recurse=True, class_names=True) self.assertTrue(os.path.isfile('xdsmjs_circuit_class_names' + '.html'))
def test_model_path_and_recursion(self): from openmdao.api import Problem, IndepVarComp p = Problem() model = p.model group = model.add_subsystem('G1', Group(), promotes=['*']) group2 = model.add_subsystem('G2', Group()) group.add_subsystem('ground', IndepVarComp('V', 0., units='V')) group.add_subsystem('source', IndepVarComp('I', 0.1, units='A')) group2.add_subsystem('source2', IndepVarComp('I', 0.1, units='A')) group.add_subsystem('circuit', Circuit()) group.connect('source.I', 'circuit.I_in') group.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup(check=False) # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() # No model path, no recursion write_xdsm(p, 'xdsm_circuit', out_format=PYXDSM_OUT, quiet=QUIET, show_browser=SHOW, recurse=False) self.assertTrue(os.path.isfile('.'.join(['xdsm_circuit', PYXDSM_OUT]))) # Model path given + recursion write_xdsm(p, 'xdsm_circuit2', out_format=PYXDSM_OUT, quiet=QUIET, show_browser=SHOW, recurse=True, model_path='G2', include_external_outputs=False) self.assertTrue(os.path.isfile('.'.join(['xdsm_circuit2', PYXDSM_OUT]))) # Model path given + no recursion write_xdsm(p, 'xdsm_circuit3', out_format=PYXDSM_OUT, quiet=QUIET, show_browser=SHOW, recurse=False, model_path='G1') self.assertTrue(os.path.isfile('.'.join(['xdsm_circuit3', PYXDSM_OUT]))) # Invalid model path, should raise error with self.assertRaises(ValueError): write_xdsm(p, 'xdsm_circuit4', out_format='tex', quiet=QUIET, show_browser=SHOW, recurse=False, model_path='G3')
def test_circuit_model_path_recurse(self): from openmdao.api import Problem, IndepVarComp p = Problem() model = p.model group = model.add_subsystem('G1', Group(), promotes=['*']) group2 = model.add_subsystem('G2', Group()) group.add_subsystem('ground', IndepVarComp('V', 0., units='V')) group.add_subsystem('source', IndepVarComp('I', 0.1, units='A')) group2.add_subsystem('source2', IndepVarComp('I', 0.1, units='A')) group.add_subsystem('circuit', Circuit()) group.connect('source.I', 'circuit.I_in') group.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup(check=False) # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() write_xdsm(p, 'xdsm_circuit2', out_format='pdf', quiet=QUIET, show_browser=False, recurse=True, model_path='G1', include_external_outputs=False) self.assertTrue(os.path.isfile('.'.join(['xdsm_circuit2', 'tex'])))
def test_invalid_model_path(self): from openmdao.api import Problem, IndepVarComp p = Problem() model = p.model group = model.add_subsystem('G1', Group(), promotes=['*']) group2 = model.add_subsystem('G2', Group()) group.add_subsystem('ground', IndepVarComp('V', 0., units='V')) group.add_subsystem('source', IndepVarComp('I', 0.1, units='A')) group2.add_subsystem('source2', IndepVarComp('I', 0.1, units='A')) group.add_subsystem('circuit', Circuit()) group.connect('source.I', 'circuit.I_in') group.connect('ground.V', 'circuit.Vg') model.add_design_var('ground.V') model.add_design_var('source.I') model.add_objective('circuit.D1.I') p.setup(check=False) # set some initial guesses p['circuit.n1.V'] = 10. p['circuit.n2.V'] = 1. p.run_model() with self.assertRaises(ValueError): write_xdsm(p, 'xdsm_circuit3', out_format='pdf', quiet=QUIET, show_browser=False, recurse=False, model_path='G3')