Beispiel #1
0
    def test_same_data_after_compute_totals(self):
        p = om.Problem()

        ivc = om.IndepVarComp()
        ivc.add_output("x", 2.0)
        ivc.add_output("y", 3.0)
        p.model.add_subsystem("ivc", ivc, promotes=["*"])

        comp = make_component(julia.SimpleImplicit(4.0))
        p.model.add_subsystem("square_it_comp", comp, promotes=["*"])

        p.setup()
        p.final_setup(
        )  # Seems like I need this for the id checks to be the same?

        id_x = id(p['x'])
        id_y = id(p['y'])
        id_z1 = id(p['z1'])
        id_z2 = id(p['z2'])

        p.run_model()
        p.compute_totals(of=["z1", "z2"], wrt=["x", "y"])

        id_x_check = id(p['x'])
        id_y_check = id(p['y'])
        id_z1_check = id(p['z1'])
        id_z2_check = id(p['z2'])

        self.assertEqual(id_x, id_x_check)
        self.assertEqual(id_y, id_y_check)
        self.assertEqual(id_z1, id_z1_check)
        self.assertEqual(id_z2, id_z2_check)
Beispiel #2
0
    def test_default_values(self):
        p = om.Problem(model=make_component(julia.SimpleImplicit(2.0)))

        p.setup()

        assert_rel_error(self, p['x'], 2.0)
        assert_rel_error(self, p['y'], 3.0)
        assert_rel_error(self, p['z1'], 2.0)
        assert_rel_error(self, p['z2'], 3.0)
Beispiel #3
0
    def test_same_data_after_run_model(self):
        p = om.Problem(model=make_component(julia.SimpleImplicit(2.0)))

        p.setup()
        p.final_setup(
        )  # Seems like I need this for the id checks to be the same?

        id_x = id(p['x'])
        id_y = id(p['y'])
        id_z1 = id(p['z1'])
        id_z2 = id(p['z2'])

        p.run_model()

        id_x_check = id(p['x'])
        id_y_check = id(p['y'])
        id_z1_check = id(p['z1'])
        id_z2_check = id(p['z2'])

        self.assertEqual(id_x, id_x_check)
        self.assertEqual(id_y, id_y_check)
        self.assertEqual(id_z1, id_z1_check)
        self.assertEqual(id_z2, id_z2_check)
Beispiel #4
0
import openmdao.api as om
from omjl import make_component
import julia.Main as julia

julia.include("components/simple_implicit.jl")

prob = om.Problem()

ivc = om.IndepVarComp()
ivc.add_output("x", 2.0)
ivc.add_output("y", 2.0)
prob.model.add_subsystem("ivc", ivc, promotes=["*"])

comp = make_component(julia.SimpleImplicit(2.0))
comp.linear_solver = om.DirectSolver(assemble_jac=True)
comp.nonlinear_solver = om.NewtonSolver(solve_subsystems=True,
                                        iprint=2,
                                        err_on_non_converge=True)
prob.model.add_subsystem("square_it_comp", comp, promotes=["*"])

prob.setup()
prob.final_setup()
prob.run_model()
print(prob.get_val("z1"))
print(prob.get_val("z2"))
print(prob.compute_totals(of=["z1", "z2"], wrt=["x", "y"]))
def main(a):
    prob = om.Problem()

    ivc = om.IndepVarComp()
    ivc.add_output("x", 2.0)
    ivc.add_output("y", 3.0)
    prob.model.add_subsystem("ivc", ivc, promotes=["*"])

    comp = make_component(julia.SimpleExplicit(a))
    prob.model.add_subsystem("square_it_comp0",
                             comp,
                             promotes_inputs=['x', 'y'],
                             promotes_outputs=[('z1', 'z1_0'), ('z2', 'z2_0')])

    comp = make_component(julia.SimpleExplicit(a + 1))
    prob.model.add_subsystem("square_it_comp1",
                             comp,
                             promotes_inputs=['x', 'y'],
                             promotes_outputs=[('z1', 'z1_1'), ('z2', 'z2_1')])

    comp = make_component(julia.SimpleExplicit(a + 2))
    prob.model.add_subsystem("square_it_comp2",
                             comp,
                             promotes_inputs=['x', 'y'],
                             promotes_outputs=[('z1', 'z1_2'), ('z2', 'z2_2')])

    comp = make_component(julia.SimpleImplicit(a))
    comp.linear_solver = om.DirectSolver(assemble_jac=True)
    comp.nonlinear_solver = om.NewtonSolver(solve_subsystems=True,
                                            iprint=0,
                                            err_on_non_converge=True)
    prob.model.add_subsystem("square_it_comp3",
                             comp,
                             promotes_inputs=["x", "y"],
                             promotes_outputs=[("z1", "z1_3"), ("z2", "z2_3")])

    comp = make_component(julia.SimpleImplicit(a + 1))
    comp.linear_solver = om.DirectSolver(assemble_jac=True)
    comp.nonlinear_solver = om.NewtonSolver(solve_subsystems=True,
                                            iprint=0,
                                            err_on_non_converge=True)
    prob.model.add_subsystem("square_it_comp4",
                             comp,
                             promotes_inputs=["x", "y"],
                             promotes_outputs=[("z1", "z1_4"), ("z2", "z2_4")])

    comp = make_component(julia.SimpleImplicit(a + 2))
    comp.linear_solver = om.DirectSolver(assemble_jac=True)
    comp.nonlinear_solver = om.NewtonSolver(solve_subsystems=True,
                                            iprint=0,
                                            err_on_non_converge=True)
    prob.model.add_subsystem("square_it_comp5",
                             comp,
                             promotes_inputs=["x", "y"],
                             promotes_outputs=[("z1", "z1_5"), ("z2", "z2_5")])

    prob.setup()
    prob.run_model()

    prob.get_val("z1_0")
    prob.get_val("z2_0")
    prob.get_val("z1_1")
    prob.get_val("z2_1")
    prob.get_val("z1_2")
    prob.get_val("z2_2")
    prob.compute_totals(of=["z1_0", "z2_0"], wrt=["x", "y"])
    prob.compute_totals(of=["z1_1", "z2_1"], wrt=["x", "y"])
    prob.compute_totals(of=["z1_2", "z2_2"], wrt=["x", "y"])