本文整理汇总了Python中openmdao.main.api.Assembly类的典型用法代码示例。如果您正苦于以下问题:Python Assembly类的具体用法?Python Assembly怎么用?Python Assembly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assembly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_request
def test_request(self):
logging.debug('')
logging.debug('test_request')
assembly = Assembly()
comp1 = assembly.add('comp1', ExtCode())
comp2 = assembly.add('comp2', ExtCode())
sub = assembly.add('sub', Assembly())
comp3 = sub.add('comp3', ExtCode())
comp1.resources = dict(min_cpus=10,
max_cpus=10,
resource_limits=dict(virtual_memory=100,
cpu_time=120),
rerunnable=True,
accounting_id='frobozz',
queue_name='debug',
job_category='MPI')
comp2.resources = dict(max_cpus=2,
resource_limits=dict(wallclock_time=1000000))
comp3.resources = dict(min_cpus=200,
resource_limits=dict(virtual_memory=20,
cpu_time=1000,
wallclock_time=500),
rerunnable=True,
accounting_id='frobozz',
queue_name='debug',
job_category='MPI')
req = RAM.max_request(assembly)
expected = dict(min_cpus=200,
max_cpus=200,
resource_limits=dict(virtual_memory=100,
cpu_time=1000,
wallclock_time=1000000))
logging.debug('req: %r', req)
logging.debug('exp: %r', expected)
self.assertEqual(req, expected)
req = RAM.total_request(assembly)
expected = dict(min_cpus=200,
max_cpus=200,
resource_limits=dict(virtual_memory=100,
cpu_time=1120,
wallclock_time=1000500),
rerunnable=True,
accounting_id='frobozz',
queue_name='debug',
job_category='MPI')
logging.debug('req: %r', req)
logging.debug('exp: %r', expected)
self.assertEqual(req, expected)
comp3.resources['accounting_id'] = 'xyzzy'
assert_raises(self, 'RAM.total_request(assembly)',
globals(), locals(), ValueError,
"Incompatible settings for 'accounting_id':"
" 'xyzzy' vs. 'frobozz'")
示例2: test_vtree
def test_vtree(self):
top = Assembly()
sub = top.add('sub', Assembly())
sub.add('comp', LoadsComp())
sub.driver.workflow.add('comp')
sub.create_passthrough('comp.loads_in')
sub.create_passthrough('comp.loads_out')
top.driver.workflow.add('sub')
jsonfile = os.path.join(self.tempdir, 'test_vtree.json')
old_json_file = os.path.join(os.path.dirname(__file__), 'vtree.json')
top.recorders = [JSONCaseRecorder(jsonfile)]
loads = Loads()
loads.Fx = [1, 2, 3]
loads.Fy = [4, 5, 6]
loads.Fz = [7, 8, 9]
arr = LoadsArray()
arr.loads = [loads]
top.sub.loads_in = arr
top.run()
cdsnew = CaseDataset(jsonfile, 'json')
cdsold = CaseDataset(old_json_file, 'json')
cdsold.data.vars('sub.comp.loads_out').fetch()[0][0]['loads'][0]['Fx'] == cdsnew.data.vars('sub.comp.loads_out').fetch()[0][0]['loads'][0]['Fx']
cdsold.data.vars('sub.comp.loads_out').fetch()[1][0]['loads'][0]['Fz'] == cdsnew.data.vars('sub.comp.loads_out').fetch()[1][0]['loads'][0]['Fz']
示例3: test_vtree
def test_vtree(self):
top = Assembly()
sub = top.add('sub', Assembly())
sub.add('comp', LoadsComp())
sub.driver.workflow.add('comp')
sub.create_passthrough('comp.loads_in')
sub.create_passthrough('comp.loads_out')
top.driver.workflow.add('sub')
sout = StringIO()
top.recorders = [JSONCaseRecorder(sout)]
loads = Loads()
loads.Fx = [1, 2, 3]
loads.Fy = [4, 5, 6]
loads.Fz = [7, 8, 9]
arr = LoadsArray()
arr.loads = [loads]
top.sub.loads_in = arr
top.run()
# with open('vtree.new', 'w') as out:
# out.write(sout.getvalue())
self.verify(sout, 'vtree.json')
示例4: configure_blade
def configure_blade():
top = Assembly()
configure_bladesurface(top, os.path.join(PATH, 'data/DTU_10MW_RWT_blade_axis_prebend.dat'), planform_nC=6)
# load the planform file
top.blade_length = 86.366
top.span_ni = 5
b = top.blade_surface
# distribute 200 points evenly along the airfoil sections
b.chord_ni = 40
# load the airfoil shapes defining the blade
for f in [os.path.join(PATH, 'data/ffaw3241.dat'),
os.path.join(PATH, 'data/ffaw3301.dat'),
os.path.join(PATH, 'data/ffaw3360.dat'),
os.path.join(PATH, 'data/ffaw3480.dat') ,
os.path.join(PATH, 'data/cylinder.dat')]:
b.base_airfoils.append(np.loadtxt(f))
b.blend_var = np.array([0.241, 0.301, 0.36, 0.48, 1.])
return top
示例5: lofted_blade_shape_example
def lofted_blade_shape_example():
top = Assembly()
configure_bladesurface(top, 'data/DTU_10MW_RWT_blade_axis_prebend.dat', planform_nC=6)
# load the planform file
top.blade_length = 86.366
top.span_ni = 50
print 'planform variables: ', top.pf_splines.pfOut.list_vars()
b = top.blade_surface
# distribute 200 points evenly along the airfoil sections
b.chord_ni = 200
# load the airfoil shapes defining the blade
for f in ['data/ffaw3241.dat',
'data/ffaw3301.dat',
'data/ffaw3360.dat',
'data/ffaw3480.dat' ,
'data/tc72.dat' ,
'data/cylinder.dat']:
b.base_airfoils.append(np.loadtxt(f))
b.blend_var = np.array([0.241, 0.301, 0.36, 0.48, 0.72, 1.])
top.run()
pf = top.pf_splines.pfOut
plt.figure()
plt.title('chord')
plt.plot(pf.s, pf.chord)
plt.savefig('chord.eps')
plt.figure()
plt.title('twist')
plt.plot(pf.s, pf.rot_z)
plt.savefig('twist.eps')
plt.figure()
plt.title('relative thickness')
plt.plot(pf.s, pf.rthick)
plt.savefig('rthick.eps')
plt.figure()
plt.title('pitch axis aft leading edge')
plt.plot(pf.s, pf.p_le)
plt.savefig('p_le.eps')
plt.figure()
plt.axis('equal')
for i in range(b.span_ni):
plt.plot(b.surfout.surface[:, i, 0], b.surfout.surface[:, i, 1])
plt.savefig('lofted_blade.eps')
plt.savefig('lofted_blade.png')
return top
示例6: test_linearGS_simul_element_and_full_connection
def test_linearGS_simul_element_and_full_connection(self):
# Added because of a bug with array slices for Linear GS
top = Assembly()
top.add('comp1', ArrayComp2D())
top.add('comp2', ArrayComp2D())
top.add('driver', SimpleDriver())
top.driver.workflow.add(['comp1', 'comp2'])
top.connect('comp1.y', 'comp2.x')
top.driver.add_parameter('comp1.x[0][0]', low=-10, high=10)
top.driver.add_objective('comp1.y[0][0]')
top.driver.add_constraint('comp2.y[0][1] < 0')
top.driver.gradient_options.lin_solver = 'linear_gs'
top.driver.gradient_options.maxiter = 1
top.run()
J = top.driver.calc_gradient(mode='forward')
assert_rel_error(self, J[0, 0], 2.0, .000001)
assert_rel_error(self, J[1, 0], 39.0, .000001)
J = top.driver.calc_gradient(mode='adjoint')
assert_rel_error(self, J[0, 0], 2.0, .000001)
assert_rel_error(self, J[1, 0], 39.0, .000001)
示例7: test_scaler_array_expression
def test_scaler_array_expression(self):
model = Assembly()
model.add('sub', SubAsmb())
model.driver.workflow.add('sub')
model.run()
J = model.driver.workflow.calc_gradient(inputs=['sub.x', 'sub.y'],
outputs=['sub.z'])
assert_rel_error(self, J[0,0], 10.0, .001)
assert_rel_error(self, J[0,1], 10.0, .001)
assert_rel_error(self, J[0,2], 20.0, .001)
示例8: test_invalid_input
def test_invalid_input(self):
model = Assembly()
model.add("driver", DistributionCaseDriver())
model.add("driven", SimpleComponent())
model.driver.workflow.add("driven")
model.driver.distribution_generator = FiniteDifferenceGenerator(model.driver)
try:
model.driver.add_parameter("driven.invalid", low=-10.0, high=10.0, fd_step=0.1)
except AttributeError as err:
self.assertEqual(str(err), "driver: Can't add parameter 'driven.invalid' because it doesn't exist.")
示例9: GeomTestCase
class GeomTestCase(unittest.TestCase):
def setUp(self):
"""this setup function will be called before each test in this class"""
self.top = Assembly()
self.top.add('g1', GeoSource())
self.top.add('g2', GeoSink())
self.top.connect('g1.g_out', 'g2.g_inp')
self.top.driver.workflow.add(['g1', 'g2'])
def tearDown(self):
"""this teardown function will be called after each test"""
self.top = None
def testGeom(self):
self.top.run()
self.assertEqual(1, self.top.g2.g_inp.get_tessellation())
try:
self.top.g2.g_extra = "hey"
except TypeError as err:
msg = "g2 (1-2): g_extra must provide interface 'IStaticGeometry'"
self.assertEqual(str(err), msg)
else:
self.fail("exception expected")
示例10: test_comp_error
def test_comp_error(self):
a = Assembly()
a.add('m',MetaModel())
a.m.default_surrogate = KrigingSurrogate()
a.m.model = DummyError()
a.m.train_next = True
a.driver.workflow.add('m')
try:
a.run()
except RuntimeError as err:
self.assertEqual("m.model: Test Error",str(err))
else:
self.fail("RuntimeError expected")
示例11: test_invalid_case_outputs
def test_invalid_case_outputs(self):
model = Assembly()
model.add('driver', DistributionCaseDriver())
model.add('driven', SimpleComponent())
model.driver.workflow.add('driven')
model.driver.distribution_generator = FiniteDifferenceGenerator(model.driver)
try:
model.driver.add_response('driven.invalid')
except ValueError as err:
self.assertEqual(str(err), "driver: Can't add response "
"'driven.invalid' because of invalid variables"
" 'driven.invalid'")
else:
self.fail('Expected ValueError')
示例12: setUp
def setUp(self):
""" Called before each test. """
self.model = Assembly()
self.model.add('c1', MyComp())
self.model.add('c2', MyComp())
self.model.driver.workflow = CyclicWorkflow()
self.model.driver.workflow.add(['c1', 'c2'])
示例13: setUp
def setUp(self):
"""this setup function will be called before each test in this class"""
self.top = Assembly()
self.top.add('g1', GeoSource())
self.top.add('g2', GeoSink())
self.top.connect('g1.g_out', 'g2.g_inp')
self.top.driver.workflow.add(['g1', 'g2'])
示例14: test_basic_delegation
def test_basic_delegation(self):
top = Assembly()
top.add('geo', GeomComponent())
# Function not there before we slot
self.assertTrue(not hasattr(top.geo, 'apply_deriv'))
self.assertTrue(not hasattr(top.geo, 'apply_derivT'))
self.assertTrue(not hasattr(top.geo, 'provideJ'))
top.geo.add('parametric_geometry', GeoWithDerivatives())
# Now they should be there.
self.assertTrue(hasattr(top.geo, 'apply_deriv'))
self.assertTrue(hasattr(top.geo, 'apply_derivT'))
self.assertTrue(hasattr(top.geo, 'provideJ'))
示例15: test_invalid_form
def test_invalid_form(self):
model = Assembly()
model.add('driver', DistributionCaseDriver())
model.add('driven', SimpleComponent())
model.driver.workflow.add('driven')
model.driver.distribution_generator = FiniteDifferenceGenerator(model.driver)
model.driver.add_response('driven.y')
model.driver.add_parameter("driven.x", low=-10., high=10., fd_step=0.1)
try:
model.driver.distribution_generator.form = "INVALID_FORM"
except ValueError, err:
msg = ": Variable 'form' must be in ['CENTRAL', 'FORWARD', 'BACKWARD'], " \
"but a value of INVALID_FORM <type 'str'> was specified."
self.assertEqual(str(err), msg)