def setUp(self): self.top = set_as_top(Assembly()) self.top.add('c1', GeomComponent()) self.top.c1.add('parametric_geometry', DummyGeometry()) self.top.add('c2', GeomRecieve()) self.top.connect('c1.geom_out', 'c2.geom_in') self.top.driver.workflow.add(['c1', 'c2']) self.top.c1.x = [3.0, 4.0] self.top.c1.y = 10 self.inputs = ['c1.x', 'c1.y'] self.outputs = ['c1.z', 'c2.out']
def test_collision(self): logging.debug('') logging.debug('test_collision') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'hwb.xml') g.vsp_path = VSP_PATH g.generate_cfd_mesh = True g.write_nascart = True msg = ': CFD meshing and NASCART output use the same output filenames' assert_raises(self, 'g.run()', globals(), locals(), Exception, msg)
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'))
def test_ge90(self): logging.debug('') logging.debug('test_ge90') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'GE90.xml') g.vsp_path = VSP_PATH g.comp_geom = True g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 2043.568902, 0.001) assert_rel_error(self, g.theoretical_volume, 1031.974785, 0.0003) assert_rel_error(self, g.wetted_area, 1894.494077, 0.005) assert_rel_error(self, g.wetted_volume, 979.795926, 0.002)
def test_eagle_eye(self): logging.debug('') logging.debug('test_eagle_eye') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'eagle_eye.xml') g.vsp_path = VSP_PATH g.comp_geom = True g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 374.888362, 0.0007) assert_rel_error(self, g.theoretical_volume, 104.646845, 0.002) assert_rel_error(self, g.wetted_area, 277.323347, 0.0006) assert_rel_error(self, g.wetted_volume, 92.116985, 0.002)
def test_m6_singleside(self): logging.debug('') logging.debug('test_m6_singleside') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'm6_singleside.xml') g.vsp_path = VSP_PATH g.comp_geom = False g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 0, 0.0001) assert_rel_error(self, g.theoretical_volume, 0, 0.0001) assert_rel_error(self, g.wetted_area, 0, 0.0001) assert_rel_error(self, g.wetted_volume, 0, 0.0001)
def test_schweizer2_32(self): logging.debug('') logging.debug('test_schweizer2_32777') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'Schweizer2_32.xml') g.vsp_path = VSP_PATH g.comp_geom = True g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 688.442371, 0.0003) assert_rel_error(self, g.theoretical_volume, 177.148284, 0.0009) assert_rel_error(self, g.wetted_area, 590.724803, 0.0003) assert_rel_error(self, g.wetted_volume, 155.390161, 0.0009)
def test_hwb(self): logging.debug('') logging.debug('test_hwb') g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'hwb.xml') g.vsp_path = VSP_PATH g.comp_geom = True g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 647.158638, 0.0001) assert_rel_error(self, g.theoretical_volume, 122.884067, 0.0001) assert_rel_error(self, g.wetted_area, 608.236512, 0.0001) assert_rel_error(self, g.wetted_volume, 121.853274, 0.0001)
def test_cessna182(self): logging.debug('') logging.debug('test_cessna182') logging.debug(os.getcwd()) g = set_as_top(GeomComponent()) g.add("parametric_geometry", VSPParametricGeometry()) g.parametric_geometry.model_file = os.path.join(TESTDIR, 'Cessna182.vsp') g.vsp_path = VSP_PATH g.comp_geom = True g.run() # 'desired' from Linux, 'tolerance' for Mac/Windows. assert_rel_error(self, g.theoretical_area, 849.669075, 0.0005) assert_rel_error(self, g.theoretical_volume, 303.350163, 0.002) assert_rel_error(self, g.wetted_area, 713.083095, 0.0005) assert_rel_error(self, g.wetted_volume, 287.489547, 0.002)
def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() self.base_inputs = set(self.geomcomp.list_inputs()) #need to manually add geom_out here, since it's a special case self.base_outputs = set(self.geomcomp.list_outputs() + ['geom_out'])
def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() comp = Component() self.base_inputs = set(comp.list_inputs()) self.base_outputs = set(comp.list_outputs())
class GeomCompTestCase(unittest.TestCase): def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() comp = Component() self.base_inputs = set(comp.list_inputs()) self.base_outputs = set(comp.list_outputs()) def tearDown(self): shutil.rmtree(self.tdir) def test_with_pygem_diamond(self): try: from pygem_diamond.pygem import GEMParametricGeometry except ImportError: raise SkipTest("pygem_diamond is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) base_ins = set(self.geomcomp.list_inputs()) base_outs = set(self.geomcomp.list_outputs()) gem_outs = ['zcg', 'zmax', 'xcg', 'zmin', 'Ixz', 'Izx', 'Ixx', 'Ixy', 'xmin', 'Izy', 'Izz', 'ymin', 'ibody', 'ymax', 'nnode', 'ycg', 'nface', 'volume', 'Iyy', 'Iyx', 'Iyz', 'area', 'nedge', 'xmax'] csm_input = """ # bottle2 (from OpenCASCADE tutorial) # written by John Dannenhoffer # default design parameters despmtr width 10.00 despmtr depth 4.00 despmtr height 15.00 despmtr neckDiam 2.50 despmtr neckHeight 3.00 despmtr wall 0.20 wall thickness (in neck) despmtr filRad1 0.25 fillet radius on body of bottle despmtr filRad2 0.10 fillet radius between bottle and neck # basic bottle shape (filletted) set baseHt height-neckHeight skbeg -width/2 -depth/4 0 cirarc 0 -depth/2 0 +width/2 -depth/4 0 linseg +width/2 +depth/4 0 cirarc 0 +depth/2 0 -width/2 +depth/4 0 linseg -width/2 -depth/4 0 skend extrude 0 0 baseHt fillet filRad1 # neck cylinder 0 0 baseHt 0 0 height neckDiam/2 # join the neck to the bottle and apply a fillet at the union union fillet filRad2 # hollow out bottle hollow wall 18 end """ model_file = os.path.join(self.tdir, 'bottle.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file # default outputs that OpenCSM calculates for you expected_outs = set(['baseHt']+gem_outs) expected_ins = set(['width', 'depth', 'height', 'neckDiam', 'neckHeight', 'wall', 'filRad1', 'filRad2']) self.assertEquals(set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals(set(self.geomcomp.list_outputs()) - base_outs, expected_outs) # now do a simple box solid with a sphere subtracted out of it csm_input = """ despmtr radius 0.5 despmtr side 2.0 set sph_dist side/2.0 box 0.0 0.0 0.0 side side side sphere sph_dist sph_dist sph_dist radius subtract end """ model_file = os.path.join(self.tdir, 'bool.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file expected_outs = set(['sph_dist']+gem_outs) expected_ins = set(['radius', 'side']) self.assertEquals(set(self.geomcomp.list_inputs())-base_ins, expected_ins) self.assertEquals(set(self.geomcomp.list_outputs())-base_outs, expected_outs) comp = self.geomcomp self.assertEqual(comp.side, 2.0) self.assertEqual(comp.radius, 0.5) self.assertEqual(comp.sph_dist, self.geomcomp.side/2.0) # volume should be box volume - sphere volume self.assertAlmostEqual(comp.volume, comp.side**3.0 - 4./3.*math.pi*comp.radius**3.0) # test a set/rebuild comp.side = 3.0 comp.radius = 0.25 comp.run() self.assertEqual(comp.side, 3.0) self.assertEqual(comp.radius, 0.25) self.assertEqual(comp.sph_dist, self.geomcomp.side/2.0) self.assertAlmostEqual(comp.volume, comp.side**3.0 - 4./3.*math.pi*comp.radius**3.0) def test_with_pygem_quartz(self): try: from pygem_quartz.pygem import GEMParametricGeometry except ImportError: raise SkipTest("pygem_quartz is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) self.geomcomp.parametric_geometry.model_file = self.model_file self.def_outs = []
def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() self.base_inputs = set(self.geomcomp.list_inputs()) #need to manually add geom_out here, since it's a special case self.base_outputs = set(self.geomcomp.list_outputs()+['geom_out'])
class GeomCompTestCase(unittest.TestCase): def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() self.base_inputs = set(self.geomcomp.list_inputs()) #need to manually add geom_out here, since it's a special case self.base_outputs = set(self.geomcomp.list_outputs()+['geom_out']) def tearDown(self): shutil.rmtree(self.tdir, onerror=onerror) def test_auto_run_with_box(self): self.geomcomp.add('parametric_geometry',BoxParametricGeometry()) self.geomcomp.height = 2 self.geomcomp.auto_run = False self.geomcomp.run() self.assertEquals(self.geomcomp.volume,8) self.geomcomp.height = 10 #check that is has not run yet, and that volume has not changed self.assertFalse(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume,8) self.geomcomp.run() self.assertTrue(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume,40) self.geomcomp.auto_run = True self.geomcomp.height = 2 self.assertTrue(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume,8) #make sure setting back to false works self.geomcomp.auto_run = False self.geomcomp.height = 10 self.assertFalse(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume,8) def test_with_pygem_diamond(self): try: from openmdao.lib.geometry.diamond import GEMParametricGeometry except ImportError: raise SkipTest("pygem_diamond is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) base_ins = set(self.geomcomp.list_inputs()) base_outs = set(self.geomcomp.list_outputs()+['geom_out']) gem_outs = ['zcg', 'zmax', 'xcg', 'zmin', 'Ixz', 'Izx', 'Ixx', 'Ixy', 'xmin', 'Izy', 'Izz', 'ymin', 'ibody1', 'ibody2', 'ymax', 'nnode', 'ycg', 'nface', 'volume', 'Iyy', 'Iyx', 'Iyz', 'area', 'nedge', 'xmax', 'iedge', 'length', 'iface', 'inode', 'nbody'] csm_input = """ # bottle2 (from OpenCASCADE tutorial) # written by John Dannenhoffer # default design parameters despmtr width 10.00 despmtr depth 4.00 despmtr height 15.00 despmtr neckDiam 2.50 despmtr neckHeight 3.00 despmtr wall 0.20 wall thickness (in neck) despmtr filRad1 0.25 fillet radius on body of bottle despmtr filRad2 0.10 fillet radius between bottle and neck # basic bottle shape (filletted) set baseHt height-neckHeight skbeg -width/2 -depth/4 0 cirarc 0 -depth/2 0 +width/2 -depth/4 0 linseg +width/2 +depth/4 0 cirarc 0 +depth/2 0 -width/2 +depth/4 0 linseg -width/2 -depth/4 0 skend extrude 0 0 baseHt fillet filRad1 # neck cylinder 0 0 baseHt 0 0 height neckDiam/2 # join the neck to the bottle and apply a fillet at the union union fillet filRad2 # hollow out bottle hollow wall 18 end """ model_file = os.path.join(self.tdir, 'bottle.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file # default outputs that OpenCSM calculates for you expected_outs = set(['baseHt']+gem_outs) expected_ins = set(['width', 'depth', 'height', 'neckDiam', 'neckHeight', 'wall', 'filRad1', 'filRad2']) self.assertEquals(set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals(set(self.geomcomp.list_outputs()) - base_outs, expected_outs) # now do a simple box solid with a sphere subtracted out of it csm_input = """ despmtr radius 0.5 despmtr side 2.0 set sph_dist side/2.0 box 0.0 0.0 0.0 side side side sphere sph_dist sph_dist sph_dist radius subtract end """ model_file = os.path.join(self.tdir, 'bool.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file expected_outs = set(['sph_dist']+gem_outs) expected_ins = set(['radius', 'side']) self.assertEquals(set(self.geomcomp.list_inputs())-base_ins, expected_ins) self.assertEquals(set(self.geomcomp.list_outputs())-base_outs, expected_outs) comp = self.geomcomp self.assertEqual(comp.side, 2.0) self.assertEqual(comp.radius, 0.5) self.assertEqual(comp.sph_dist, self.geomcomp.side/2.0) # volume should be box volume - sphere volume self.assertAlmostEqual(comp.volume, comp.side**3.0 - 4./3.*math.pi*comp.radius**3.0) # test a set/rebuild comp.side = 3.0 comp.radius = 0.25 comp.run() self.assertEqual(comp.side, 3.0) self.assertEqual(comp.radius, 0.25) self.assertEqual(comp.sph_dist, self.geomcomp.side/2.0) self.assertAlmostEqual(comp.volume, comp.side**3.0 - 4./3.*math.pi*comp.radius**3.0) # def test_with_pygem_quartz(self): # try: # from pygem_quartz.pygem import GEMParametricGeometry # except ImportError: # raise SkipTest("pygem_quartz is not installed") # self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) # self.geomcomp.parametric_geometry.model_file = self.model_file # self.def_outs = [] # # add test here... def test_with_box(self): self.geomcomp.add('parametric_geometry', BoxParametricGeometry()) ins = set(self.geomcomp.list_inputs()) - self.base_inputs outs = set(self.geomcomp.list_outputs()) - self.base_outputs print self.base_outputs, self.geomcomp.list_outputs(), outs self.assertEqual(ins, set(['height'])) self.assertEqual(outs, set(['volume'])) height = self.geomcomp.height volume = self.geomcomp.volume self.assertEqual(volume, 2*2*height) self.geomcomp.height = 5 self.geomcomp.run() self.assertEqual(self.geomcomp.volume, 2*2*5.) def test_with_vartrees(self): class VTBoxParametricGeometry(BoxParametricGeometry): def _update_meta(self): newmeta = { 'myvt.f': { 'iotype': 'in', 'value': 3.14, }, 'myvt.subvt.f': { 'iotype': 'in', 'value': 11.1, }, 'myvt.subvt.i': { 'iotype': 'in', 'value': 4, }, 'myvt.subvt.s': { 'iotype': 'in', 'value': "foo", }, 'myvt.subvt.arr': { 'iotype': 'in', 'value': numpy.array([1., 2., 3., 4.]), }, 'myvt.subvt.en': { 'iotype': 'in', 'type': 'enum', 'values': ["yes", "no"], 'value': 'yes', }, 'fproduct': { 'iotype': 'out', 'value': 3.14 * 11.1, }, 'concat': { 'iotype': 'out', 'value': 'fooyes' }, 'bogus': { 'iotype': 'out', 'type': 'flarn', # this should cause a warning and revert trait to a Python trait 'value': object(), } } self.meta.update(newmeta) def regen_model(self): super(VTBoxParametricGeometry, self).regen_model() if 'myvt.f' not in self.meta: self._update_meta() self.meta['fproduct']['value'] = self.meta['myvt.f']['value']*self.meta['myvt.subvt.f']['value'] self.meta['concat']['value'] = self.meta['myvt.subvt.s']['value']+self.meta['myvt.subvt.en']['value'] self.geomcomp.add('parametric_geometry', VTBoxParametricGeometry()) ins = set(self.geomcomp.list_inputs()) - self.base_inputs outs = set(self.geomcomp.list_outputs()) - self.base_outputs # are expected inputs and outputs here? self.assertEqual(ins, set(["height", "myvt"])) self.assertEqual(outs, set(["volume", "fproduct", "concat", "bogus"])) # make sure our VT works topvars = set(self.geomcomp.myvt.list_vars()) self.assertEqual(topvars, set(["f", "subvt"])) topvars = set(self.geomcomp.myvt.subvt.list_vars()) self.assertEqual(topvars, set(["arr", "en", 'i', 'f', 's'])) # check types of stuff self.assertTrue(isinstance(self.geomcomp.myvt, VariableTree)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt, VariableTree)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt.arr, numpy.ndarray)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt.en, basestring)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt.trait('en').trait_type, Enum)) self.assertTrue(isinstance(self.geomcomp.trait('bogus').trait_type, Python)) # set some vartree values and see if they update in the geometry self.geomcomp.myvt.f = 6. self.geomcomp.myvt.subvt.f = 7. self.geomcomp.run() self.assertEqual(self.geomcomp.fproduct, 42.) # see if enum is limited to allowed values try: self.geomcomp.myvt.subvt.en = "foo" except Exception as err: self.assertEqual("myvt.subvt: Variable 'en' must be in ['yes', 'no'], but a value of foo <type 'str'> was specified.", str(err))
class GeomCompTestCase(unittest.TestCase): def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() comp = Component() self.base_inputs = set(comp.list_inputs()) self.base_outputs = set(comp.list_outputs()) def tearDown(self): shutil.rmtree(self.tdir) def test_with_pygem_diamond(self): try: from pygem_diamond.pygem import GEMParametricGeometry except ImportError: raise SkipTest("pygem_diamond is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) base_ins = set(self.geomcomp.list_inputs()) base_outs = set(self.geomcomp.list_outputs()) gem_outs = [ 'zcg', 'zmax', 'xcg', 'zmin', 'Ixz', 'Izx', 'Ixx', 'Ixy', 'xmin', 'Izy', 'Izz', 'ymin', 'ibody', 'ymax', 'nnode', 'ycg', 'nface', 'volume', 'Iyy', 'Iyx', 'Iyz', 'area', 'nedge', 'xmax' ] csm_input = """ # bottle2 (from OpenCASCADE tutorial) # written by John Dannenhoffer # default design parameters despmtr width 10.00 despmtr depth 4.00 despmtr height 15.00 despmtr neckDiam 2.50 despmtr neckHeight 3.00 despmtr wall 0.20 wall thickness (in neck) despmtr filRad1 0.25 fillet radius on body of bottle despmtr filRad2 0.10 fillet radius between bottle and neck # basic bottle shape (filletted) set baseHt height-neckHeight skbeg -width/2 -depth/4 0 cirarc 0 -depth/2 0 +width/2 -depth/4 0 linseg +width/2 +depth/4 0 cirarc 0 +depth/2 0 -width/2 +depth/4 0 linseg -width/2 -depth/4 0 skend extrude 0 0 baseHt fillet filRad1 # neck cylinder 0 0 baseHt 0 0 height neckDiam/2 # join the neck to the bottle and apply a fillet at the union union fillet filRad2 # hollow out bottle hollow wall 18 end """ model_file = os.path.join(self.tdir, 'bottle.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file # default outputs that OpenCSM calculates for you expected_outs = set(['baseHt'] + gem_outs) expected_ins = set([ 'width', 'depth', 'height', 'neckDiam', 'neckHeight', 'wall', 'filRad1', 'filRad2' ]) self.assertEquals( set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals( set(self.geomcomp.list_outputs()) - base_outs, expected_outs) # now do a simple box solid with a sphere subtracted out of it csm_input = """ despmtr radius 0.5 despmtr side 2.0 set sph_dist side/2.0 box 0.0 0.0 0.0 side side side sphere sph_dist sph_dist sph_dist radius subtract end """ model_file = os.path.join(self.tdir, 'bool.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file expected_outs = set(['sph_dist'] + gem_outs) expected_ins = set(['radius', 'side']) self.assertEquals( set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals( set(self.geomcomp.list_outputs()) - base_outs, expected_outs) comp = self.geomcomp self.assertEqual(comp.side, 2.0) self.assertEqual(comp.radius, 0.5) self.assertEqual(comp.sph_dist, self.geomcomp.side / 2.0) # volume should be box volume - sphere volume self.assertAlmostEqual( comp.volume, comp.side**3.0 - 4. / 3. * math.pi * comp.radius**3.0) # test a set/rebuild comp.side = 3.0 comp.radius = 0.25 comp.run() self.assertEqual(comp.side, 3.0) self.assertEqual(comp.radius, 0.25) self.assertEqual(comp.sph_dist, self.geomcomp.side / 2.0) self.assertAlmostEqual( comp.volume, comp.side**3.0 - 4. / 3. * math.pi * comp.radius**3.0) def test_with_pygem_quartz(self): try: from pygem_quartz.pygem import GEMParametricGeometry except ImportError: raise SkipTest("pygem_quartz is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) self.geomcomp.parametric_geometry.model_file = self.model_file self.def_outs = []
class GeomCompTestCase(unittest.TestCase): def setUp(self): self.geomcomp = GeomComponent() self.tdir = tempfile.mkdtemp() self.base_inputs = set(self.geomcomp.list_inputs()) #need to manually add geom_out here, since it's a special case self.base_outputs = set(self.geomcomp.list_outputs() + ['geom_out']) def tearDown(self): shutil.rmtree(self.tdir, onerror=onerror) def test_auto_run_with_box(self): self.geomcomp.add('parametric_geometry', BoxParametricGeometry()) self.geomcomp.height = 2 self.geomcomp.auto_run = False self.geomcomp.run() self.assertEquals(self.geomcomp.volume, 8) self.geomcomp.height = 10 #check that is has not run yet, and that volume has not changed self.assertFalse(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume, 8) self.geomcomp.run() self.assertTrue(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume, 40) self.geomcomp.auto_run = True self.geomcomp.height = 2 self.assertTrue(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume, 8) #make sure setting back to false works self.geomcomp.auto_run = False self.geomcomp.height = 10 self.assertFalse(self.geomcomp.is_valid()) self.assertEquals(self.geomcomp.volume, 8) def test_with_pygem_diamond(self): try: from openmdao.lib.geometry.diamond import GEMParametricGeometry except ImportError: raise SkipTest("pygem_diamond is not installed") self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) base_ins = set(self.geomcomp.list_inputs()) base_outs = set(self.geomcomp.list_outputs() + ['geom_out']) gem_outs = [ 'zcg', 'zmax', 'xcg', 'zmin', 'Ixz', 'Izx', 'Ixx', 'Ixy', 'xmin', 'Izy', 'Izz', 'ymin', 'ibody1', 'ibody2', 'ymax', 'nnode', 'ycg', 'nface', 'volume', 'Iyy', 'Iyx', 'Iyz', 'area', 'nedge', 'xmax', 'iedge', 'length', 'iface', 'inode', 'nbody' ] csm_input = """ # bottle2 (from OpenCASCADE tutorial) # written by John Dannenhoffer # default design parameters despmtr width 10.00 despmtr depth 4.00 despmtr height 15.00 despmtr neckDiam 2.50 despmtr neckHeight 3.00 despmtr wall 0.20 wall thickness (in neck) despmtr filRad1 0.25 fillet radius on body of bottle despmtr filRad2 0.10 fillet radius between bottle and neck # basic bottle shape (filletted) set baseHt height-neckHeight skbeg -width/2 -depth/4 0 cirarc 0 -depth/2 0 +width/2 -depth/4 0 linseg +width/2 +depth/4 0 cirarc 0 +depth/2 0 -width/2 +depth/4 0 linseg -width/2 -depth/4 0 skend extrude 0 0 baseHt fillet filRad1 # neck cylinder 0 0 baseHt 0 0 height neckDiam/2 # join the neck to the bottle and apply a fillet at the union union fillet filRad2 # hollow out bottle hollow wall 18 end """ model_file = os.path.join(self.tdir, 'bottle.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file # default outputs that OpenCSM calculates for you expected_outs = set(['baseHt'] + gem_outs) expected_ins = set([ 'width', 'depth', 'height', 'neckDiam', 'neckHeight', 'wall', 'filRad1', 'filRad2' ]) self.assertEquals( set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals( set(self.geomcomp.list_outputs()) - base_outs, expected_outs) # now do a simple box solid with a sphere subtracted out of it csm_input = """ despmtr radius 0.5 despmtr side 2.0 set sph_dist side/2.0 box 0.0 0.0 0.0 side side side sphere sph_dist sph_dist sph_dist radius subtract end """ model_file = os.path.join(self.tdir, 'bool.csm') with open(model_file, 'w') as f: f.write(csm_input) self.geomcomp.parametric_geometry.model_file = model_file expected_outs = set(['sph_dist'] + gem_outs) expected_ins = set(['radius', 'side']) self.assertEquals( set(self.geomcomp.list_inputs()) - base_ins, expected_ins) self.assertEquals( set(self.geomcomp.list_outputs()) - base_outs, expected_outs) comp = self.geomcomp self.assertEqual(comp.side, 2.0) self.assertEqual(comp.radius, 0.5) self.assertEqual(comp.sph_dist, self.geomcomp.side / 2.0) # volume should be box volume - sphere volume self.assertAlmostEqual( comp.volume, comp.side**3.0 - 4. / 3. * math.pi * comp.radius**3.0) # test a set/rebuild comp.side = 3.0 comp.radius = 0.25 comp.run() self.assertEqual(comp.side, 3.0) self.assertEqual(comp.radius, 0.25) self.assertEqual(comp.sph_dist, self.geomcomp.side / 2.0) self.assertAlmostEqual( comp.volume, comp.side**3.0 - 4. / 3. * math.pi * comp.radius**3.0) # def test_with_pygem_quartz(self): # try: # from pygem_quartz.pygem import GEMParametricGeometry # except ImportError: # raise SkipTest("pygem_quartz is not installed") # self.geomcomp.add('parametric_geometry', GEMParametricGeometry()) # self.geomcomp.parametric_geometry.model_file = self.model_file # self.def_outs = [] # # add test here... def test_with_box(self): self.geomcomp.add('parametric_geometry', BoxParametricGeometry()) ins = set(self.geomcomp.list_inputs()) - self.base_inputs outs = set(self.geomcomp.list_outputs()) - self.base_outputs print self.base_outputs, self.geomcomp.list_outputs(), outs self.assertEqual(ins, set(['height'])) self.assertEqual(outs, set(['volume'])) height = self.geomcomp.height volume = self.geomcomp.volume self.assertEqual(volume, 2 * 2 * height) self.geomcomp.height = 5 self.geomcomp.run() self.assertEqual(self.geomcomp.volume, 2 * 2 * 5.) def test_with_vartrees(self): class VTBoxParametricGeometry(BoxParametricGeometry): def _update_meta(self): newmeta = { 'myvt.f': { 'iotype': 'in', 'value': 3.14, }, 'myvt.subvt.f': { 'iotype': 'in', 'value': 11.1, }, 'myvt.subvt.i': { 'iotype': 'in', 'value': 4, }, 'myvt.subvt.s': { 'iotype': 'in', 'value': "foo", }, 'myvt.subvt.arr': { 'iotype': 'in', 'value': numpy.array([1., 2., 3., 4.]), }, 'myvt.subvt.en': { 'iotype': 'in', 'type': 'enum', 'values': ["yes", "no"], 'value': 'yes', }, 'fproduct': { 'iotype': 'out', 'value': 3.14 * 11.1, }, 'concat': { 'iotype': 'out', 'value': 'fooyes' }, 'bogus': { 'iotype': 'out', 'type': 'flarn', # this should cause a warning and revert trait to a Python trait 'value': object(), } } self.meta.update(newmeta) def regen_model(self): super(VTBoxParametricGeometry, self).regen_model() if 'myvt.f' not in self.meta: self._update_meta() self.meta['fproduct']['value'] = self.meta['myvt.f'][ 'value'] * self.meta['myvt.subvt.f']['value'] self.meta['concat']['value'] = self.meta['myvt.subvt.s'][ 'value'] + self.meta['myvt.subvt.en']['value'] self.geomcomp.add('parametric_geometry', VTBoxParametricGeometry()) ins = set(self.geomcomp.list_inputs()) - self.base_inputs outs = set(self.geomcomp.list_outputs()) - self.base_outputs # are expected inputs and outputs here? self.assertEqual(ins, set(["height", "myvt"])) self.assertEqual(outs, set(["volume", "fproduct", "concat", "bogus"])) # make sure our VT works topvars = set(self.geomcomp.myvt.list_vars()) self.assertEqual(topvars, set(["f", "subvt"])) topvars = set(self.geomcomp.myvt.subvt.list_vars()) self.assertEqual(topvars, set(["arr", "en", 'i', 'f', 's'])) # check types of stuff self.assertTrue(isinstance(self.geomcomp.myvt, VariableTree)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt, VariableTree)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt.arr, numpy.ndarray)) self.assertTrue(isinstance(self.geomcomp.myvt.subvt.en, basestring)) self.assertTrue( isinstance(self.geomcomp.myvt.subvt.trait('en').trait_type, Enum)) self.assertTrue( isinstance(self.geomcomp.trait('bogus').trait_type, Python)) # set some vartree values and see if they update in the geometry self.geomcomp.myvt.f = 6. self.geomcomp.myvt.subvt.f = 7. self.geomcomp.run() self.assertEqual(self.geomcomp.fproduct, 42.) # see if enum is limited to allowed values try: self.geomcomp.myvt.subvt.en = "foo" except Exception as err: self.assertEqual( "myvt.subvt: Variable 'en' must be in ['yes', 'no'], but a value of foo <type 'str'> was specified.", str(err))