def setUp(self): self.nn = 5 self.p = Problem(model=Group()) ivc = IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3), units='kg') ivc.add_output(name='b', shape=(self.nn, 3), units='m') ivc.add_output(name='c', shape=(self.nn, 3), units='s ** 2') self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) multi = self.p.model.add_subsystem( name='multiply_divide_comp', subsys=ElementMultiplyDivideComp(complex=True)) multi.add_equation('multdiv_output', ['input_c', 'input_b', 'input_a'], vec_size=self.nn, length=3, input_units=['s**2', 'm', 'kg'], divide=[True, False, False]) self.p.model.connect('a', 'multiply_divide_comp.input_a') self.p.model.connect('b', 'multiply_divide_comp.input_b') self.p.model.connect('c', 'multiply_divide_comp.input_c') self.p.setup(force_alloc_complex=True) self.p['a'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) self.p['b'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) # use uniform 1 - 2 distribution to avoid div zero self.p['c'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) self.p.run_model()
def setUp(self): self.nn = 5 self.p = Problem(model=Group()) ivc = IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) ivc.add_output(name='c', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) multi = self.p.model.add_subsystem(name='multiply_divide_comp', subsys=ElementMultiplyDivideComp()) multi.add_equation('multdiv_output', ['input_a', 'input_b', 'input_c'], vec_size=self.nn, length=3, scaling_factor=2) self.p.model.connect('a', 'multiply_divide_comp.input_a') self.p.model.connect('b', 'multiply_divide_comp.input_b') self.p.model.connect('c', 'multiply_divide_comp.input_c') self.p.setup() self.p['a'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) self.p['b'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) self.p['c'] = np.random.uniform(low=1, high=2, size=(self.nn, 3)) self.p.run_model()
def setUp(self): self.nn = 5 self.p = Problem(model=Group()) ivc = IndepVarComp() ivc.add_output(name='a', shape=(self.nn, )) ivc.add_output(name='b', val=3.0) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b']) multi = self.p.model.add_subsystem(name='multiply_divide_comp', subsys=ElementMultiplyDivideComp()) multi.add_equation('multdiv_output', ['input_a', 'input_b'], vec_size=[self.nn, 1]) self.p.model.connect('a', 'multiply_divide_comp.input_a') self.p.model.connect('b', 'multiply_divide_comp.input_b') self.p.setup() self.p['a'] = np.random.rand(self.nn, ) self.p.run_model()
def setup(self): nn = self.options['num_nodes'] eta_b = self.options['efficiency'] e_b = self.options['specific_energy'] p_b = self.options['specific_power'] cost_inc = self.options['cost_inc'] cost_base = self.options['cost_base'] # defaults = [['SOC_initial', 'batt_SOC_initial', 1, None]] # self.add_subsystem('defaults', DVLabel(defaults), # promotes_inputs=["*"], promotes_outputs=["*"]) self.add_subsystem('batt_base', SimpleBattery(num_nodes=nn, efficiency=eta_b, specific_energy=e_b, specific_power=p_b, cost_inc=cost_inc, cost_base=cost_base), promotes_outputs=['*'], promotes_inputs=['*']) # change in SOC over time is (- elec_load) / max_energy self.add_subsystem('divider', ElementMultiplyDivideComp( output_name='dSOCdt', input_names=['elec_load', 'max_energy'], vec_size=[nn, 1], scaling_factor=-1, divide=[False, True], input_units=['W', 'kJ']), promotes_inputs=['*'], promotes_outputs=['*']) integ = self.add_subsystem('ode_integ', Integrator(num_nodes=nn, method='simpson', diff_units='s', time_setup='duration'), promotes_inputs=['*'], promotes_outputs=['*']) integ.add_integrand('SOC', rate_name='dSOCdt', start_name='SOC_initial', end_name='SOC_final', units=None, val=1.0, start_val=1.0)
def promote_mult(self, source, prom_name, factor, vec_size=1, units=None, length=1, val=1.0, res_units=None, desc='', lower=None, upper=None, ref=1.0, ref0=0.0, res_ref=None, divide=None, input_units=None, tags=None): """Helper function called during setup""" mult_index = self._n_auto_comps self._n_auto_comps += 1 mult = ElementMultiplyDivideComp(output_name=prom_name, input_names=['_temp'], scaling_factor=factor, input_units=[units], vec_size=vec_size, length=length, val=val, res_units=res_units, desc=desc, lower=lower, upper=upper, ref=ref, ref0=ref0, res_ref=res_ref, divide=divide, tags=tags) mult_name = 'mult' + str(mult_index) self.add_subsystem(mult_name, mult, promotes_outputs=['*']) self.connect(source, mult_name + '._temp')
def setUp(self): self.nn = 5 self.p = Problem(model=Group()) ivc = IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) ivc.add_output(name='c', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) multi = self.p.model.add_subsystem(name='multiply_divide_comp', subsys=ElementMultiplyDivideComp()) multi.add_equation('multdiv_output', ['input_a', 'input_b', 'input_c'], vec_size=self.nn, length=3, divide=[False, True]) self.p.model.connect('a', 'multiply_divide_comp.input_a') self.p.model.connect('b', 'multiply_divide_comp.input_b') self.p.model.connect('c', 'multiply_divide_comp.input_c')
def setup(self): nn = self.options['num_nodes'] # Scale the heat transfer by the number of pipes # Used ExecComp here because multiplying vector and scalar inputs self.add_subsystem('heat_divide', ExecComp('q_div = q / n_pipes', q_div={ 'units': 'W', 'shape': (nn, ) }, q={ 'units': 'W', 'shape': (nn, ) }), promotes_inputs=['q', 'n_pipes']) # Maximum heat transfer and weight self.add_subsystem( 'q_max_calc', QMaxHeatPipe( num_nodes=nn, theta=self.options['theta'], yield_stress=self.options['yield_stress'], rho_wall=self.options['rho_wall'], stress_safety_factor=self.options['stress_safety_factor']), # Assume temp in heat pipe is close to evaporator temp promotes_inputs=[ 'inner_diam', 'length', ('design_temp', 'T_design'), ('temp', 'T_evap') ]) # Multiply max heat transfer and weight by number of pipes multiply = ElementMultiplyDivideComp() multiply.add_equation(output_name='weight', input_names=['single_pipe_weight', 'n_pipes'], input_units=['kg', None]) self.add_subsystem('weight_multiplier', multiply, promotes_inputs=['n_pipes'], promotes_outputs=['weight']) self.connect('q_max_calc.heat_pipe_weight', 'weight_multiplier.single_pipe_weight') # Used ExecComp here because multiplying vector and scalar inputs self.add_subsystem('q_max_multiplier', ExecComp('q_max = single_pipe_q_max * n_pipes', q_max={ 'units': 'W', 'shape': (nn, ) }, single_pipe_q_max={ 'units': 'W', 'shape': (nn, ) }), promotes_inputs=['n_pipes'], promotes_outputs=['q_max']) self.connect('q_max_calc.q_max', 'q_max_multiplier.single_pipe_q_max') # Thermal resistance at current operator condition self.add_subsystem( 'ammonia_surrogate', AmmoniaProperties(num_nodes=nn), # Assume temp in heat pipe is close to evaporator temp promotes_inputs=[('temp', 'T_evap')]) self.add_subsystem( 'delta_T_calc', HeatPipeVaporTempDrop(num_nodes=nn), # Assume temp in heat pipe is close to evaporator temp promotes_inputs=[('temp', 'T_evap'), 'inner_diam', 'length']) self.add_subsystem('resistance', HeatPipeThermalResistance( num_nodes=nn, length_evap=self.options['length_evap'], length_cond=self.options['length_cond'], wall_conduct=self.options['wall_conduct'], wick_thickness=self.options['wick_thickness'], wick_conduct=self.options['wick_conduct'], vapor_resistance=True), promotes_inputs=['inner_diam']) self.connect('ammonia_surrogate.rho_vapor', 'delta_T_calc.rho_vapor') self.connect('ammonia_surrogate.vapor_pressure', 'delta_T_calc.vapor_pressure') self.connect('delta_T_calc.delta_T', 'resistance.delta_T') self.connect('q_max_calc.wall_thickness', 'resistance.wall_thickness' ) # use wall thickness from hoop stress calc # Compute condenser temperature self.add_subsystem('cond_temp_calc', ExecComp('T_cond = T_evap - q*R', T_cond={ 'units': 'degC', 'shape': (nn, ) }, T_evap={ 'units': 'degC', 'shape': (nn, ) }, q={ 'units': 'W', 'shape': (nn, ) }, R={ 'units': 'K/W', 'shape': (nn, ) }), promotes_inputs=['T_evap'], promotes_outputs=['T_cond']) self.connect('heat_divide.q_div', ['delta_T_calc.q', 'resistance.q', 'cond_temp_calc.q']) self.connect('resistance.thermal_resistance', 'cond_temp_calc.R') # Warn the user if heat transfer exceeds maximum possible self.add_subsystem('q_max_warning', QMaxWarning(num_nodes=nn, q_max_warn=self.options['q_max_warn']), promotes_inputs=['q', 'q_max'])