Ejemplo n.º 1
0
    def test_fan_in_serial_sets(self):

        prob = Problem(impl=impl)
        prob.root = FanInGrouped()
        prob.root.ln_solver = LinearGaussSeidel()
        prob.root.sub.ln_solver = LinearGaussSeidel()

        # Parallel Groups
        prob.driver.add_param('p1.x1')
        prob.driver.add_param('p2.x2')
        prob.driver.add_objective('comp3.y')

        prob.setup(check=False)
        prob.run()

        param_list = ['p1.x1', 'p2.x2']
        unknown_list = ['comp3.y']

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='rev',
                               return_format='dict')
        assert_rel_error(self, J['comp3.y']['p1.x1'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['comp3.y']['p2.x2'][0][0], 35.0, 1e-6)

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='fwd',
                               return_format='dict')
        assert_rel_error(self, J['comp3.y']['p1.x1'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['comp3.y']['p2.x2'][0][0], 35.0, 1e-6)
Ejemplo n.º 2
0
    def test_fan_out_serial_sets(self):

        prob = Problem(impl=impl)
        prob.root = FanOutGrouped()
        prob.root.ln_solver = LinearGaussSeidel()
        prob.root.sub.ln_solver = LinearGaussSeidel()

        # Parallel Groups
        prob.driver.add_param('p.x')
        prob.driver.add_constraint('c2.y')
        prob.driver.add_constraint('c3.y')

        prob.setup(check=False)
        prob.run()

        unknown_list = ['c2.y', 'c3.y']
        param_list = ['p.x']

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='fwd',
                               return_format='dict')
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='rev',
                               return_format='dict')
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
Ejemplo n.º 3
0
    def test_indices(self):
        asize = 3
        prob = Problem(root=Group(), impl=impl)
        root = prob.root
        root.ln_solver = LinearGaussSeidel()
        root.ln_solver.options['mode'] = 'rev'

        p = root.add('p', ParamComp('x', np.arange(asize, dtype=float) + 1.0))
        G1 = root.add('G1', ParallelGroup())
        G1.ln_solver = LinearGaussSeidel()
        G1.ln_solver.options['mode'] = 'rev'

        c2 = G1.add(
            'c2',
            ExecComp4Test('y = x * 2.0', x=np.zeros(asize), y=np.zeros(asize)))
        c3 = G1.add(
            'c3',
            ExecComp4Test('y = numpy.ones(3).T*x.dot(numpy.arange(3.,6.))',
                          x=np.zeros(asize),
                          y=np.zeros(asize)))
        c4 = root.add(
            'c4',
            ExecComp4Test('y = x * 4.0', x=np.zeros(asize), y=np.zeros(asize)))
        c5 = root.add(
            'c5',
            ExecComp4Test('y = x * 5.0', x=np.zeros(asize), y=np.zeros(asize)))

        prob.driver.add_param('p.x', indices=[1, 2])
        prob.driver.add_constraint('c4.y', indices=[1])
        prob.driver.add_constraint('c5.y', indices=[2])
        prob.driver.parallel_derivs(['c4.y', 'c5.y'])

        root.connect('p.x', 'G1.c2.x')
        root.connect('p.x', 'G1.c3.x')
        root.connect('G1.c2.y', 'c4.x')
        root.connect('G1.c3.y', 'c5.x')

        prob.setup(check=False)
        prob.run()

        J = prob.calc_gradient(['p.x'], ['c4.y', 'c5.y'],
                               mode='fwd',
                               return_format='dict')

        assert_rel_error(self, J['c5.y']['p.x'][0], np.array([20., 25.]), 1e-6)
        assert_rel_error(self, J['c4.y']['p.x'][0], np.array([8., 0.]), 1e-6)

        J = prob.calc_gradient(['p.x'], ['c4.y', 'c5.y'],
                               mode='rev',
                               return_format='dict')

        assert_rel_error(self, J['c5.y']['p.x'][0], np.array([20., 25.]), 1e-6)
        assert_rel_error(self, J['c4.y']['p.x'][0], np.array([8., 0.]), 1e-6)
Ejemplo n.º 4
0
    def test_fan_out_parallel_sets(self):

        prob = Problem(impl=impl)
        prob.root = FanOutGrouped()
        prob.root.ln_solver = LinearGaussSeidel()
        prob.root.sub.ln_solver = LinearGaussSeidel()

        # need to set mode to rev before setup. Otherwise the sub-vectors
        # for the parallel set vars won't get allocated.
        prob.root.ln_solver.options['mode'] = 'rev'
        prob.root.sub.ln_solver.options['mode'] = 'rev'

        # Parallel Groups
        prob.driver.add_param('p.x')
        prob.driver.add_constraint('c2.y')
        prob.driver.add_constraint('c3.y')
        prob.driver.parallel_derivs(['c2.y', 'c3.y'])

        self.assertEqual(prob.driver.outputs_of_interest(), [('c2.y', 'c3.y')])
        prob.setup(check=False)
        prob.run()

        unknown_list = ['c2.y', 'c3.y']
        param_list = ['p.x']

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='rev',
                               return_format='dict')
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='fwd',
                               return_format='dict')
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
Ejemplo n.º 5
0
    def test_fan_out_grouped(self):

        prob = Problem(impl=impl)
        prob.root = FanOutGrouped()
        prob.root.ln_solver = LinearGaussSeidel()
        prob.root.sub.ln_solver = LinearGaussSeidel()
        prob.setup(check=False)
        prob.run()

        param_list = ['p.x']
        #unknown_list = ['sub.comp2.y', "sub.comp3.y"]
        unknown_list = ['c2.y', "c3.y"]

        J = prob.calc_gradient(param_list, unknown_list, mode='fwd', return_format='dict')
        #assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6)
        #assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6)
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)

        J = prob.calc_gradient(param_list, unknown_list, mode='rev', return_format='dict')
        #assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6)
        #assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6)
        assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
Ejemplo n.º 6
0
    def test_sellar_derivs_with_Lin_GS(self):

        prob = Problem()
        prob.root = SellarDerivatives()
        prob.root.nl_solver = Newton()
        prob.root.ln_solver = LinearGaussSeidel()

        prob.setup(check=False)
        prob.run()

        assert_rel_error(self, prob['y1'], 25.58830273, .00001)
        assert_rel_error(self, prob['y2'], 12.05848819, .00001)

        # Make sure we aren't iterating like crazy
        self.assertLess(prob.root.nl_solver.iter_count, 8)
Ejemplo n.º 7
0
    model.driver.add_constraint('%s.ConDs'% name, upper=0.0)
    model.driver.add_constraint('%s.ConS0'% name, upper=0.0)
    model.driver.add_constraint('%s.ConS1'% name, upper=0.0)
    model.driver.add_constraint('%s_con5.val'% name, equals=0.0)

# Add Parameter groups
model.driver.add_desvar("bp1.cellInstd", low=0., high=1.0)
model.driver.add_desvar("bp2.finAngle", low=0., high=np.pi/2.)
model.driver.add_desvar("bp3.antAngle", low=-np.pi/4, high=np.pi/4)

# Add objective
model.driver.add_objective('obj.val')

# For Parallel exeuction, we must use KSP or LinearGS
#model.root.ln_solver = PetscKSP()
model.root.ln_solver = LinearGaussSeidel()
model.root.parallel.ln_solver = LinearGaussSeidel()
model.root.parallel.pt0.ln_solver = LinearGaussSeidel()
model.root.parallel.pt1.ln_solver = LinearGaussSeidel()
model.root.parallel.pt2.ln_solver = LinearGaussSeidel()
model.root.parallel.pt3.ln_solver = LinearGaussSeidel()
model.root.parallel.pt4.ln_solver = LinearGaussSeidel()
model.root.parallel.pt5.ln_solver = LinearGaussSeidel()

# Parallel Derivative calculation
#for con_name in ['.ConCh','.ConDs','.ConS0','.ConS1','_con5.val']:
#    model.driver.parallel_derivs(['%s%s'%(n,con_name) for n in names])

# Recording
# Some constraints only exit on one process so cannot record everything
recording_includes_options = ['obj.val']
Ejemplo n.º 8
0
    def test_fan_in_parallel_sets(self):

        prob = Problem(impl=impl)
        prob.root = FanInGrouped()
        prob.root.ln_solver = LinearGaussSeidel()
        prob.root.sub.ln_solver = LinearGaussSeidel()

        # auto calculated mode is fwd, so we don't have to set it explicitly
        # in the ln_solvers in order to have our voi subvecs allocated
        # properly.

        # Parallel Groups
        prob.driver.add_param('p1.x1')
        prob.driver.add_param('p2.x2')
        prob.driver.add_objective('comp3.y')

        # make sure we can't mix inputs and outputs in parallel sets
        try:
            prob.driver.parallel_derivs(['p1.x1', 'comp3.y'])
        except Exception as err:
            self.assertEqual(
                str(err),
                "['p1.x1', 'comp3.y'] cannot be grouped because ['p1.x1'] are "
                "params and ['comp3.y'] are not.")
        else:
            self.fail("Exception expected")

        prob.driver.parallel_derivs(['p1.x1', 'p2.x2'])

        self.assertEqual(prob.driver.params_of_interest(),
                         [('p1.x1', 'p2.x2')])

        # make sure we can't add a VOI to multiple groups
        try:
            prob.driver.parallel_derivs(['p1.x1', 'p3.x3'])
        except Exception as err:
            self.assertEqual(
                str(err),
                "'p1.x1' cannot be added to VOI set ('p1.x1', 'p3.x3') "
                "because it already exists in VOI set: ('p1.x1', 'p2.x2')")
        else:
            self.fail("Exception expected")

        prob.setup(check=False)
        prob.run()

        param_list = ['p1.x1', 'p2.x2']
        unknown_list = ['comp3.y']

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='rev',
                               return_format='dict')
        assert_rel_error(self, J['comp3.y']['p1.x1'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['comp3.y']['p2.x2'][0][0], 35.0, 1e-6)

        J = prob.calc_gradient(param_list,
                               unknown_list,
                               mode='fwd',
                               return_format='dict')
        assert_rel_error(self, J['comp3.y']['p1.x1'][0][0], -6.0, 1e-6)
        assert_rel_error(self, J['comp3.y']['p2.x2'][0][0], 35.0, 1e-6)
Ejemplo n.º 9
0
    def __init__(self):
        super(Lift, self).__init__()
        self.ln_solver = LinearGaussSeidel()

        # Pod Inputs
        self.add_param('Br',
                       val=0.64,
                       units='Tesla',
                       desc='residual magnetic flux')  #0.64
        self.add_param('d', val=0.009525, units='m',
                       desc='magnet thickness')  #0.009525 - 0.00635
        self.add_param('N', val=16.0, desc='number magnets')
        self.add_param('M', val=4.0, desc='number magnets per halbach')
        self.add_param('Is',
                       val=3.0,
                       desc='number vertically oriented magnets')

        self.add_param('edge',
                       val=0.1524,
                       units='m',
                       desc='edge length of cube magnets being used')
        self.add_param('mass', val=0.375, units='kg', desc='pod mass')

        # Track Inputs (laminated track)
        self.add_param('delta_c',
                       val=0.0005334,
                       units='m',
                       desc='single layer thickness')
        self.add_param('strip_c',
                       val=0.0105,
                       units='m',
                       desc='center strip spacing')
        self.add_param('Pc', val=0.21, units='m', desc='width of track')
        self.add_param('rc',
                       val=171.3,
                       units='Ohm-m',
                       desc='electric resistivity')
        self.add_param('Nt',
                       val=0.005,
                       units='m',
                       desc='width of conductive strip')
        self.add_param('Ns', val=1, desc='number of laminated sheets')

        # Inductive Loading
        self.add_param('al',
                       val=0.00079 * 8.,
                       units='m',
                       desc='conductor bundle height loaded')
        self.add_param('wf',
                       val=0.0,
                       units='m',
                       desc='total ferrite tile width')

        # Pod/Track Relation
        self.add_param('y1', val=0.01, units='m', desc='rolling clearance')
        self.add_param('veloc', val=10.0, units='m/s', desc='pod velocity')

        self.add_param(
            'dia_out',
            val=0.0406,
            units='m',
            desc='diameter of largest magnet ring. Cenetered on magnets')
        self.add_param('dia_in',
                       val=0.0406,
                       units='m',
                       desc='diameter of smallest magnet ring')
        self.add_param('fill_frac',
                       val=0.8,
                       units='m',
                       desc='fraction of area filled by magnet')
        self.add_param('nr', val=1.0, desc='number of magnet rings')
        self.add_param('rpm', val=10000.0, desc='motor rotations / minute')
        self.add_param('t_plate',
                       val=0.25 * 0.0254,
                       units='m',
                       desc='conductive plate thickness')
        self.add_param('k', val=1., desc='constant for thin sheet')
        self.add_param('rho0',
                       val=2.82E-08,
                       units='Ohm-m',
                       desc='resistivity of aluminum at 20C')
        self.add_param(
            'alpha',
            val=0.0039,
            desc=
            'constant for linear dependence of rho on temperature of aluminum.'
        )
        self.add_param('T',
                       val=26.,
                       units='degC',
                       desc='temperature of aluminum')
        self.add_param('Den',
                       val=2700,
                       units='kg/m^3',
                       desc='density of aluminum')
        self.add_param('mu',
                       val=1.26E-06,
                       units='H/m',
                       desc='magnetic permeability of aluminum')
        self.add_param('halbach',
                       val=1.8,
                       desc='field multiplier for using halbach')
        self.add_param('height',
                       val=0.0051,
                       units='m',
                       desc='rotor lift height')

        # outputs
        # pod outputs
        self.add_output('lambda',
                        val=0.00635 * 4.,
                        units='m',
                        desc='halbach wavelength')
        self.add_output('B0', val=0.9, units='T', desc='halbach peak strength')
        self.add_output('area_mag',
                        val=0.4,
                        units='m',
                        desc='actual magnetized area')
        self.add_output('pforce',
                        val=5.,
                        units='N',
                        desc='required levitation force')
        # system outputs
        self.add_output('l1d',
                        val=5.7E-08,
                        units='Henrys',
                        desc='distributed "1 turn" inductance')
        self.add_output('li',
                        val=0.,
                        units='Henrys',
                        desc='added inductance from loading')
        self.add_output('l1',
                        val=5.7E-08,
                        units='Henrys',
                        desc='one turn inductance')
        self.add_output('r1',
                        val=0.0007,
                        units='Ohm',
                        desc='one turn resistance')
        self.add_output('rl_pole', val=12250, units='rad/s', desc='R/L Pole')
        self.add_output('omegaOsc',
                        val=47.,
                        units='rad/s',
                        desc='Oscillation frequency')
        self.add_output('vOsc',
                        val=0.41,
                        units='m/s',
                        desc='Oscillation velocity')
        # breakpoint analysis
        self.add_output('vb',
                        val=23.,
                        units='m/s',
                        desc='levitation breakpoint')
        self.add_output('sb',
                        val=52.,
                        units='mi/h',
                        desc='levitation breakpoint speed mph')
        self.add_output('omegab',
                        val=2650.,
                        units='rad/s',
                        desc='frequency breakpoint')
        self.add_output('Fxb',
                        val=17.,
                        units='N',
                        desc='drag force at breakpoint')
        self.add_output('l2db', val=0.2, desc='lift to drag at breakpoint')
        # transition analysis
        self.add_output('vt', val=47, units='m/s', desc='transition velocity')
        self.add_output('st',
                        val=52.,
                        units='mi/h',
                        desc='levitation transition speed mph')
        self.add_output('omegat',
                        val=2650.,
                        units='rad/s',
                        desc='frequency transition')
        self.add_output('Fxyt',
                        val=17.,
                        units='N',
                        desc='drag force at transition')
        self.add_output('Lht', val=17., units='m', desc='levitation height')
        self.add_output('l2dt', val=0.2, desc='lift to drag at transition')
        # user specified output point
        self.add_output('omegau', val=2650., units='rad/s', desc='frequency')
        self.add_output('su',
                        val=52.,
                        units='mi/h',
                        desc='levitation speed mph')
        self.add_output('Fyu', val=17., units='N', desc='levitation force')
        self.add_output('Fxu', val=17., units='N', desc='drag force')
        self.add_output('Lhu', val=17., units='m', desc='levitation height')
        self.add_output('Fyuf',
                        val=17.,
                        units='N',
                        desc='fixed levitation force')
        self.add_output('Fxuf', val=17., units='N', desc='fixed drag force')
        self.add_output('l2du', val=0.2, desc='lift to drag')

        self.add_output('rho',
                        val=2.88599E-08,
                        units='Ohm-m',
                        desc='resistivity of aluminum at elevated temps')
        self.add_output('n',
                        val=4.0,
                        desc='number of halbach cycles (4 magnets per cycle)')

        self.add_output('vol_mag',
                        val=0.4,
                        units='m',
                        desc='volume of plate with eddy current')
        self.add_output('omega',
                        val=16.0,
                        units='rad/s',
                        desc='rotation speed')
        self.add_output('area_ring',
                        val=0.0,
                        units='lbm/s',
                        desc='area of ring that contains all magnets')
        self.add_output('B',
                        val=0.172,
                        units='T',
                        desc='magnetic field at plate (Tesla')
        self.add_output('f',
                        val=4.0,
                        units='Hz',
                        desc='magnet rotation frequency')
        self.add_output('P_norm',
                        val=11214.5582,
                        units='W/kg',
                        desc='watts per mass dissipated in aluminum')
        self.add_output('P',
                        val=155.7289266,
                        units='W',
                        desc='watts dissipated in aluminum')
        self.add_output('delta',
                        val=0.003311459,
                        units='m',
                        desc='skin depth equation for good conductors. \
                                                point at which current density has fallen to 0.37 of surface. \
                                                make sure thickness of plate is at least 2*delta'
                        )
Ejemplo n.º 10
0
from openmdao.solvers.ln_gauss_seidel import LinearGaussSeidel
import numpy as np
if MPI:
    from openmdao.core.petsc_impl import PetscImpl as impl
else:
    from openmdao.core.basic_impl import BasicImpl as impl

from hawc2_wrapper.hawc2_inputreader import HAWC2InputReader
from hawc2_wrapper.hawc2_aeroelasticsolver import HAWC2AeroElasticSolver
from hawc2_wrapper.hawc2s_aeroelasticsolver import HAWC2SAeroElasticSolver

H2 = True

top = Problem(impl=impl, root=Group())
root = top.root
root.ln_solver = LinearGaussSeidel()

config = {}

config['with_aero_coeffs'] = True
config['naero_coeffs'] = 6
config['naoa'] = 105

# HAWC2GeometryBuilder
cf = {}
cf['interp_from_htc'] = False
config['HAWC2GeometryBuilder'] = cf

# HAWC2Wrapper
cf = {}
cf['dry_run'] = False