Exemplo n.º 1
0
    def setUpClass(cls):
        nn = 10

        cls.p = Problem(model=Group())

        ivc = cls.p.model.add_subsystem('ivc',
                                        IndepVarComp(),
                                        promotes_outputs=['*'])
        ivc.add_output('r_e2b_I', val=np.ones((nn, 3)))
        ivc.add_output('v_e2b_I', val=np.ones((nn, 3)))
        ivc.add_output('a_pert_I', val=np.ones((nn, 3)))

        cls.p.model.add_subsystem('rmag_comp',
                                  VectorMagnitudeComp(vec_size=nn,
                                                      length=3,
                                                      in_name='r_e2b_I',
                                                      mag_name='rmag_e2b',
                                                      units='km'),
                                  promotes_inputs=['*'],
                                  promotes_outputs=['*'])

        cls.p.model.add_subsystem('orbit_eom_comp',
                                  OrbitEOMComp(num_nodes=nn),
                                  promotes_inputs=['*'],
                                  promotes_outputs=['*'])

        cls.p.setup(check=True, force_alloc_complex=True)

        cls.p['r_e2b_I'] = np.random.rand(nn, 3) * 1000
        cls.p['v_e2b_I'] = np.random.rand(nn, 3) * 10
        cls.p['a_pert_I'] = np.random.rand(nn, 3)

        cls.p.run_model()
Exemplo n.º 2
0
    def test(self):
        """
        An example demonstrating a trivial use case of MuxComp
        """
        import numpy as np
        from openmdao.api import Problem, Group, IndepVarComp, MuxComp, VectorMagnitudeComp
        from openmdao.utils.assert_utils import assert_rel_error

        # The number of elements to be muxed
        n = 3

        # The size of each element to be muxed
        m = 100

        p = Problem(model=Group())

        ivc = IndepVarComp()
        ivc.add_output(name='x', shape=(m, ), units='m')
        ivc.add_output(name='y', shape=(m, ), units='m')
        ivc.add_output(name='z', shape=(m, ), units='m')

        p.model.add_subsystem(name='ivc',
                              subsys=ivc,
                              promotes_outputs=['x', 'y', 'z'])

        mux_comp = p.model.add_subsystem(name='mux',
                                         subsys=MuxComp(vec_size=n))

        mux_comp.add_var('r', shape=(m, ), axis=1, units='m')

        p.model.add_subsystem(name='vec_mag_comp',
                              subsys=VectorMagnitudeComp(vec_size=m,
                                                         length=n,
                                                         in_name='r',
                                                         mag_name='r_mag',
                                                         units='m'))

        p.model.connect('x', 'mux.r_0')
        p.model.connect('y', 'mux.r_1')
        p.model.connect('z', 'mux.r_2')
        p.model.connect('mux.r', 'vec_mag_comp.r')

        p.setup()

        p['x'] = 1 + np.random.rand(m)
        p['y'] = 1 + np.random.rand(m)
        p['z'] = 1 + np.random.rand(m)

        p.run_model()

        # Verify the results against numpy.dot in a for loop.
        for i in range(n):
            r_i = [p['x'][i], p['y'][i], p['z'][i]]
            expected_i = np.sqrt(np.dot(r_i, r_i))
            assert_rel_error(self,
                             p.get_val('vec_mag_comp.r_mag')[i], expected_i)
Exemplo n.º 3
0
    def test(self):
        """
        A simple example to compute the magnitude of 3-vectors at at 100 points simultaneously.
        """
        import numpy as np
        from openmdao.api import Problem, Group, IndepVarComp, VectorMagnitudeComp
        from openmdao.utils.assert_utils import assert_rel_error

        n = 100

        p = Problem(model=Group())

        ivc = IndepVarComp()
        ivc.add_output(name='pos', shape=(n, 3), units='m')

        p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['pos'])

        dp_comp = VectorMagnitudeComp(vec_size=n,
                                      length=3,
                                      in_name='r',
                                      mag_name='r_mag',
                                      units='km')

        p.model.add_subsystem(name='vec_mag_comp', subsys=dp_comp)

        p.model.connect('pos', 'vec_mag_comp.r')

        p.setup()

        p['pos'] = np.random.rand(n, 3)

        p.run_model()

        # Verify the results against numpy.dot in a for loop.
        for i in range(n):
            a_i = p['pos'][i, :]
            expected_i = np.sqrt(np.dot(a_i, a_i)) / 1000.0
            assert_rel_error(self,
                             p.get_val('vec_mag_comp.r_mag')[i], expected_i)
Exemplo n.º 4
0
    def setup(self):
        nn = self.options['num_nodes']

        self.add_subsystem('rmag_comp',
                           VectorMagnitudeComp(vec_size=nn,
                                               length=3,
                                               in_name='r_e2b_I',
                                               mag_name='rmag_e2b_I',
                                               units='km'),
                           promotes_inputs=['r_e2b_I'],
                           promotes_outputs=['rmag_e2b_I'])

        self.add_subsystem('grav_pert_comp',
                           GravityPerturbationsComp(num_nodes=nn),
                           promotes_inputs=['r_e2b_I', 'rmag_e2b_I'],
                           promotes_outputs=[('a_pert:J2', 'a_pert_I')])

        self.add_subsystem('ori_comp',
                           ORIComp(num_nodes=nn),
                           promotes_inputs=['r_e2b_I', 'v_e2b_I'],
                           promotes_outputs=['O_RI'])

        self.add_subsystem('obr_comp',
                           OBRComp(num_nodes=nn),
                           promotes_inputs=['Gamma'],
                           promotes_outputs=['O_BR'])

        self.add_subsystem('obi_comp',
                           OBIComp(num_nodes=nn),
                           promotes_inputs=['O_BR', 'O_RI'],
                           promotes_outputs=['O_BI'])

        self.add_subsystem(
            'orbit_eom_comp',
            OrbitEOMComp(num_nodes=nn),
            promotes_inputs=['rmag_e2b_I', 'r_e2b_I', 'v_e2b_I', 'a_pert_I'])
Exemplo n.º 5
0
    def setup(self):
        nn = self.options['num_nodes']
        lat_gs = self.options['lat_gs']
        lon_gs = self.options['lon_gs']
        alt_gs = self.options['alt_gs']

        self.add_subsystem('ant_quaternion_comp',
                           CommAntQuaternionComp(num_nodes=nn),
                           promotes_inputs=['antAngle'],
                           promotes_outputs=['q_AB'])

        self.add_subsystem('ant_rotation_matrix_comp',
                           CommAntRotationMatrixComp(num_nodes=nn),
                           promotes_inputs=['q_AB'],
                           promotes_outputs=['O_AB'])

        self.add_subsystem('comm_earth_rotation_quaternion_comp',
                           CommEarthRotationQuaternionComp(num_nodes=nn,
                                                           gha0=0.0),
                           promotes_inputs=['t'],
                           promotes_outputs=['q_IE'])

        self.add_subsystem('comm_earth_rotation_matrix_comp',
                           CommEarthRotationMatrixComp(num_nodes=nn),
                           promotes_inputs=['q_IE'],
                           promotes_outputs=['O_IE'])

        self.add_subsystem('comm_gs_pos_eci_comp',
                           CommGSPosECIComp(num_nodes=nn,
                                            lat=lat_gs,
                                            lon=lon_gs,
                                            alt=alt_gs),
                           promotes_inputs=['O_IE'],
                           promotes_outputs=['r_e2g_I'])

        self.add_subsystem('comm_vector_eci_comp',
                           CommVectorECIComp(num_nodes=nn),
                           promotes_inputs=['r_e2g_I', 'r_e2b_I'],
                           promotes_outputs=['r_b2g_I'])

        self.add_subsystem('comm_vector_body_comp',
                           MatrixVectorProductComp(vec_size=nn,
                                                   A_name='O_BI',
                                                   x_name='r_b2g_I',
                                                   b_name='r_b2g_B',
                                                   x_units='km',
                                                   b_units='km'),
                           promotes_inputs=['O_BI', 'r_b2g_I'],
                           promotes_outputs=['r_b2g_B'])

        self.add_subsystem('comm_vector_ant_comp',
                           MatrixVectorProductComp(vec_size=nn,
                                                   A_name='O_AB',
                                                   x_name='r_b2g_B',
                                                   b_name='r_b2g_A',
                                                   x_units='km',
                                                   b_units='km'),
                           promotes_inputs=['O_AB', 'r_b2g_B'],
                           promotes_outputs=['r_b2g_A'])

        self.add_subsystem('comm_vector_spherical_comp',
                           CommVectorSphericalComp(num_nodes=nn),
                           promotes_inputs=['r_b2g_A'],
                           promotes_outputs=['elevationGS', 'azimuthGS'])

        self.add_subsystem('comm_distance_comp',
                           VectorMagnitudeComp(vec_size=nn,
                                               in_name='r_b2g_A',
                                               mag_name='GSdist',
                                               units='km'),
                           promotes_inputs=['r_b2g_A'],
                           promotes_outputs=['GSdist'])

        self.add_subsystem('comm_gain_pattern_comp',
                           CommGainPatternComp(num_nodes=nn),
                           promotes_inputs=['elevationGS', 'azimuthGS'],
                           promotes_outputs=['gain'])

        self.add_subsystem('comm_los_comp',
                           CommLOSComp(num_nodes=nn),
                           promotes_inputs=['r_b2g_I', 'r_e2g_I'],
                           promotes_outputs=['CommLOS'])

        self.add_subsystem(
            'data_rate_comp',
            CommDataRateComp(num_nodes=nn),
            promotes_inputs=['P_comm', 'gain', 'CommLOS', 'GSdist'],
            promotes_outputs=['dXdt:data'])