class DummyComp(Component): r = Float(iotype='in') r2 = Float(iotype='in') r3 = Float(iotype='in', desc="some random variable", low=-1.0, high=1.0, other_meta_data="test") s = Str(iotype='in') rout = Float(iotype='out', units='ft') r2out = Float(iotype='out') sout = Str(iotype='out') slistout = List(Str, iotype='out') dummy_in = Instance(Component, iotype='in') dummy_out = Instance(Component, iotype='out') dummy_out_no_copy = Instance(Component, iotype='out', copy=None) def __init__(self): super(DummyComp, self).__init__() self.r = 1.0 self.r2 = -1.0 self.rout = 0.0 self.r2out = 0.0 self.s = 'a string' self.sout = '' # make a nested container with input and output ContainerVars self.add('dummy', Multiplier()) self.dummy_in = self.dummy self.dummy_out = self.dummy def execute(self): self.rout = self.r * 1.5 self.r2out = self.r2 + 10.0 self.sout = self.s[::-1] # pylint: disable-msg=E1101 self.dummy.execute()
class TwrGeoOutputs(VariableTree): """Basic Geometric Outputs needed to build Tower of Jacket.""" TwrObj = Instance(Klass=Tube, desc='Object of Class Tube for Tower portion of Jacket') Twr2RNAObj = Instance( Klass=RigidMember, desc='Object of Class RigidMember for Rigid Tower portion') joints = Array(np.array([]), units='m', dtype=np.float, desc='Pile Joint (with legs) Coordinates (3,nlegs=nfaces)') nodes = Array(np.empty((3, 10)), units='m', dtype=np.float, desc='Tower ALL Nodes' ' Coordinates (3,nNodes)') nNodes = Int(0, units=None, desc='Number of Tower Nodes INCLUDING joint at TP') nElems = Int(0, units=None, desc='Number of of elements in the flexible portion of tower') mass = Float(units='kg', desc='Tower Mass') TopMass = Array( np.zeros([10]), dtype=np.float, desc= 'Tower Top mass, Ixx, Iyy, Izz,Ixy,Ixz,Iyz,CMxoff,CMyoff,CMzoff from RNA properties in input' ) TopMass_yaw = Array( np.zeros([10]), dtype=np.float, desc= 'Tower Top mass, Ixx, Iyy, Izz,Ixy,Ixz,Iyz,CMxoff,CMyoff,CMzoff from RNA properties in input including yaw angle w.r.t. Global XYZ' ) TwrlumpedMass = Array( np.zeros([1, 11]), dtype=np.float, desc='Concentrated masses along tower: first column z' 's from base of tower; 2nd through 11th column: mass and Ixx,Iyy,Izz,Ixy,Ixz,Iyz,CMxoff,CMyoff,CMzoff values' ) HH = Float(units='m', desc='Hub-Height') Htwr = Float(units='m', desc='Tower Length') Htwr2 = Float(units='m', desc='Tower at constant cross section Length') Thoff_yaw = Array( np.zeros([3]), units='m', dtype=np.float, desc= 'Tower-top to Hub-center vector in yawed coordinate system (TO BE MOVED SOMEWHERE ELSE at one point)' ) rna_yawedcm = Array( np.zeros([3]), dtype=np.float, desc= 'Tower Top mass CMxoff,CMyoff,CMzoff in yawed coordinate system(TO BE MOVED SOMEWHERE ELSE at one point)' )
class ConnectableDOEdriver(DOEdriverBase): DOEgenerator = Instance(IDOEgenerator, required=True, iotype="in", desc='Iterator supplying normalized DOE values.') case_filter = Instance(ICaseFilter, iotype="in", desc='Selects cases to be run.')
class ConnectableExpectedImprovement(ExpectedImprovementBase): best_case = Instance(CaseSet, iotype="in", desc="CaseSet which contains a single case " "representing the criteria value.") predicted_value = Instance( NormalDistribution, iotype="in", desc="The Normal Distribution of the predicted value " "for some function at some point where you wish to" " calculate the EI.")
class CompWithNestedPythonObjects(Component): cx_nested_in = Instance(ClassWithNestedObjects(ComplexClass(1.0, 2.0), ComplexClass(3.0, 4.0)), iotype="in", desc="nested complex number") cx_nested_out = Instance(ClassWithNestedObjects(ComplexClass(5.0, 6.0), ComplexClass(7.0, 8.0)), iotype="out", desc="nested complex number") def execute(self): self.cx_nested_out = copy.deepcopy(self.cx_nested_in)
class ConnectableMultiObjExpectedImprovement(MultiObjExpectedImprovementBase): best_cases = Instance( CaseSet, iotype="in", desc="CaseIterator which contains only Pareto optimal cases \ according to criteria.") pass
class MyContainer(Container): uncertain = Instance(NormalDistribution, iotype="out") def __init__(self): super(MyContainer, self).__init__() self.uncertain = NormalDistribution() self.add('dyntrait', Float(9., desc='some desc'))
class ConnectableMetaModel(MetaModelBase): """ Same functionality as MetaModelBase but warm_start_data is connectable. """ warm_start_data = Instance(ICaseIterator, iotype="in", desc="CaseIterator containing cases to use as " "initial training data. When this is set, all " "previous training data is cleared and replaced " "with data from this CaseIterator.")
class PGrafComponent(Component): num = Int(iotype='in') # BAN - changed obj to an Instance with iotype defined in order to make obj # visible in the mpi-enabled framework. #obj = Slot(PGrafObject) obj = Instance(PGrafObject, iotype='in') result = Int(iotype='out') def execute(self): self.result = self.num + self.obj.num
class ConnectableParetoFilter(ParetoFilterBase): """ Same functionality as ParetoFilter but without slots. Allows for issuing connections to pareto_set and dominated_set """ criteria = List(Str, iotype="in", desc="List of outputs from the case to consider for " "filtering. Note that only case outputs are allowed as " "criteria.") #case_set = Slot(ICaseIterator, # desc="CaseIterator with the cases to be filtered to " # "Find the pareto optimal subset.") case_sets = List(Instance(ICaseIterator), value=[], iotype="in", desc="CaseSet with the cases to be filtered to " "find the pareto optimal subset.") pareto_set = Instance(CaseSet, iotype="out", desc="Resulting collection of pareto optimal cases.", copy="shallow") dominated_set = Instance(CaseSet, iotype="out", desc="Resulting collection of dominated cases.", copy="shallow")
class Verifier(Component): """ Verifies evaluated cases. """ cases = Instance(ICaseIterator, iotype='in') def execute(self): """ Verify evaluated cases. """ for case in self.cases: i = int(case.label) # Correlation key. self._logger.critical('verifying case %d', i) assert case.msg is None assert case['driven.rosen_suzuki'] == rosen_suzuki( case['driven.x']) assert case['driven.sum_y'] == sum(case['driven.y']) assert case['driven.extra'] == 2.5
class Generator(Component): """ Generates cases to be evaluated. """ cases = Instance(ICaseIterator, iotype='out') def execute(self): """ Generate some cases to be evaluated. """ cases = [] for i in range(10): inputs = [('driven.x', numpy_random.normal(size=4)), ('driven.y', numpy_random.normal(size=10)), ('driven.raise_error', False), ('driven.stop_exec', False)] outputs = ['driven.rosen_suzuki', 'driven.sum_y'] cases.append(Case(inputs, outputs, label=str(i))) self.cases = ListCaseIterator(cases)
class JcktGeoOutputs(VariableTree): """Node Coordinates and Member Connectivity.""" nNodesJckt = Int(units=None, desc='Total Number of nodes in the Jacket, no Tower') nodes = Array(units='m', dtype=np.float, desc='Node' 's coordinates in the Substructure') radii = Array(units='m', dtype=np.float, desc='Node' 's Radii') Reacts = Array( units=None, dtype=int, desc='Node IDs for reactions + Fixity values (1/0)' ) #Fixed for the time being with all fixity (6 dofs per node fixed) nmems = Int(units=None, desc='Total Number of Members in the Jacket, no Tower') mems = Array( units=None, dtype=int, desc='Member Connectivity Node i Node j for every member (i.e.,element)' ) props = Array(dtype=np.float, desc='Jacket Member' 's xsectional and material properties') XnsfM = Array(dtype=np.float, desc='Jacket Member' 's Global to Local DIrection Cosine Matrices [3,3,nelems]') TubeObjs = Instance( Klass=Tube, desc= 'Object of Class Tube for Jacket Elements. Tube Objects, one per element' ) jnt_masses = Array( dtype=np.float, desc= 'Jacket Concentrated Masses at Joints: (joint no, mass, IXX, IYY, IZZ)' ) jnt_masses_yaw = Array( dtype=np.float, desc= 'Jacket Concentrated Masses at Joints: (joint no, mass, IXX, IYY, IZZ) accounting for RNA yaw' )
class ExpectedImprovement(Component): """Expected Improvement calculation for single objective.""" target = Float(0, iotype="in", desc="Current objective minimum.") current = Instance(NormalDistribution, iotype="in", desc="The Normal Distribution of the predicted value " "for some function at some point where you wish to" " calculate the EI.") EI = Float(0.0, iotype="out", desc="The expected improvement of the predicted_value " + \ "in current.") PI = Float(0.0, iotype="out", desc="The probability of improvement of the predicted_value" + \ " in current.") def execute(self): """ Calculates the expected improvement of the model at a given point. """ mu = self.current.mu sigma = self.current.sigma target = self.target try: seterr(divide='raise') self.PI = 0.5 * erfc(-(1. / 2.**.5) * ((target - mu) / sigma)) T1 = (target - mu) * .5 * (erfc(-(target - mu) / (sigma * 2.**.5))) T2 = sigma * ((1. / ((2. * pi)**.5)) * exp(-0.5 * ((target - mu) / sigma)**2.)) self.EI = abs(T1 + T2) except (ValueError, ZeroDivisionError, FloatingPointError): self.EI = 0 self.PI = 0
class ConnectableNeighborhoodDOEdriver(NeighborhoodDOEdriverBase): DOEgenerator = Instance(IDOEgenerator, iotype="in", required=True, desc='Iterator supplying normalized DOE values.')
class TExecComp(ExecComp): data = Instance(iotype='in', desc='Used to check bad JSON data')
def add_region(self, name): self.add(name + '_i', Instance(Region())) self.add(name + '_v', VarTree(Region())) self.add(name + '_f', Float())