def __init__(self): ''' Attributes ---------- initial_time: float end_time: float time_step: float show_time: tuple Two-element tuple, `(bool,float)`, `True` will print to standard output. ''' super().__init__() self.port_names_expected = ['external-flow', 'visualization'] self.initial_time = 0.0 self.end_time = 100 self.time_step = 0.1 self.show_time = (False, 1 * const.minute) self.bounce = True self.slip = True species = list() quantities = list() self.ode_params = dict() # Create a drop with random diameter up within 5 and 8 mm. self.droplet_diameter = (np.random.random(1) * (8 - 5) + 5)[0] * const.milli self.ode_params['droplet-diameter'] = self.droplet_diameter self.ode_params['droplet-xsec-area'] = np.pi * (self.droplet_diameter / 2.0)**2 self.ode_params['gravity'] = const.g # Species in the liquid phase #orig water = Specie(name='water', formula_name='H2O(l)', phase='liquid', \ water = Specie(name='water', formula_name='H2O(l)', \ atoms=['2*H','O']) water.massCC = 0.99965 # [g/cc] water.massCCUnit = 'g/cc' water.molarCCUnit = 'mole/cc' species.append(water) droplet_mass = 4/3 * np.pi * (self.droplet_diameter/2)**3 * water.massCC * \ const.gram / const.centi**3 # [kg] self.ode_params['droplet-mass'] = droplet_mass # Spatial position x_0 = np.zeros(3) position = Quantity(name='position', formalName='Pos.', unit='m', value=x_0) quantities.append(position) # Velocity v_0 = np.zeros(3) velocity = Quantity(name='velocity', formalName='Veloc.', unit='m/s', value=v_0) quantities.append(velocity) # Speed speed = Quantity(name='speed', formalName='Speed', unit='m/s', value=0.0) quantities.append(speed) # Radial position radial_pos = Quantity(name='radial-position', formalName='Radius', unit='m', \ value=np.linalg.norm(x_0[0:2])) quantities.append(radial_pos) # Liquid phase self.liquid_phase = Phase(self.initial_time, time_unit='s', species=species, \ quantities=quantities) #orig self.liquid_phase.SetValue('water', water.massCC, self.initial_time) self.liquid_phase.set_value('water', water.massCC, self.initial_time) # Domain box dimensions: LxLxH m^3 box with given H. # Origin of cartesian coordinate system at the bottom of the box. # z coordinate pointing upwards. -L <= x <= L, -L <= y <= L, self.box_half_length = 250.0 # L [m] self.box_height = 500.0 # H [m] # Random positioning of the droplet constrained to a box sub-region. x_0 = (2 * np.random.random(3) - np.ones(3)) * self.box_half_length / 4.0 x_0[2] = self.box_height #orig self.liquid_phase.SetValue('position', x_0, self.initial_time) self.liquid_phase.set_value('position', x_0, self.initial_time) # Droplet Initial velocity = 0 -> placed still in the flow #orig self.liquid_phase.SetValue('velocity', np.array([0.0,0.0,0.0]), \ self.liquid_phase.set_value('velocity', np.array([0.0,0.0,0.0]), \ self.initial_time) # Default value for the medium surrounding the droplet if data is not passed # through a conneted port. medium_mass_density = 0.1 * const.gram / const.centi**3 # [kg/m^3] self.ode_params['medium-mass-density'] = medium_mass_density medium_displaced_mass = 4/3 * np.pi * (self.droplet_diameter/2)**3 * \ medium_mass_density # [kg] self.ode_params['medium-displaced-mass'] = medium_displaced_mass medium_dyn_viscosity = 1.81e-5 # kg/(m s) self.ode_params['medium-dyn-viscosity'] = medium_dyn_viscosity
ax.set_title(info_str, fontsize=14) if varLegend: ax.legend(loc='best', prop={'size': 7}) ax.grid() # end of: for i_var in range(num_var): fig_name = lead_name + '-' + self.name + '-phase-plot-' + str( i_dash).zfill(2) fig.savefig(fig_name + '.png', dpi=dpi, format='png') #plt.close(fig_num) if show: plt.show() #pickle.dump( fig, open(fig_name+'.pickle','wb') ) return if __name__ == '__main__': tbp_org = Species(name='TBP', formula_name='(C4H9O)_3PO(o)', phase_name='organic', atoms=['12*C', '27*H', '4*O', 'P']) quant = Quantity(name='volume') phase = PhaseNew(name='solvent', species=[tbp_org], quantities=[quant]) print(phase)
def __init__(self, slot_id, input_full_path_file_name, work_dir, ports=list(), cortix_start_time=0.0, cortix_final_time=0.0, cortix_time_unit=None): #................................................................................. # Sanity test assert isinstance( slot_id, int), '-> slot_id type %r is invalid.' % type(slot_id) assert isinstance(ports, list), '-> ports type %r is invalid.' % type(ports) assert len(ports) > 0 assert isinstance(cortix_start_time,float), '-> time type %r is invalid.' % \ type(cortix_start_time) assert isinstance(cortix_final_time, float), '-> time type %r is invalid.' % \ type(cortix_final_time) assert isinstance(cortix_time_unit, str), '-> time unit type %r is invalid.' % \ type(cortix_time_unit) # Logging self.__log = logging.getLogger('launcher-droplet' + str(slot_id) + '.cortix_driver.droplet') self.__log.info('initializing an object of Droplet()') #................................................................................. # Member data self.__slot_id = slot_id self.__ports = ports # Convert Cortix's time unit to Droplet's internal time unit if cortix_time_unit == 'minute': self.__time_unit_scale = 60.0 elif cortix_time_unit == 'second': self.__time_unit_scale = 1.0 elif cortix_time_unit == 'hour': self.__time_unit_scale = 60.0 * 60.0 else: assert False, 'Cortix time_unit: %r not acceptable.' % time_unit self.__cortix_time_unit = cortix_time_unit self.__start_time = cortix_start_time * self.__time_unit_scale # Droplet time unit self.__final_time = cortix_final_time * self.__time_unit_scale # Droplet time unit if work_dir[-1] != '/': work_dir = work_dir + '/' self.__wrkDir = work_dir # Signal to start operation self.__goSignal = True # start operation immediately for port in self.__ports: # if there is a signal port, start operation accordingly (port_name, port_type, this_port_file) = port if port_name == 'go-signal' and port_type == 'use': self.__go_signal = False self.__setup_time = 60.0 # time unit; a delay time before starting to run #................................................................................. # Input ports # Read input information if any #fin = open(input_full_path_file_name,'r') # Configuration member data self.__pyplot_scale = 'linear' # self.__ode_integrator = 'scikits.odes' # or 'scipy.integrate' self.__ode_integrator = 'scipy.integrate' # Domain specific member data gravity = 9.81 # [m/s^2] acceleration of gravity Params = namedtuple('Params', ['gravity']) self.__params = Params(gravity) # Setup the material phase as a liquid species = list() water = Specie(name='water', formulaName='H2O(l)', phase='liquid') water.massCCUnit = 'g/cc' water.molarCCUnit = 'mole/cc' species.append(water) quantities = list() # height height = Quantity(name='height', formalName='Height', unit='m') quantities.append(height) # speed speed = Quantity(name='speed', formalName='Speed', unit='m/s') quantities.append(speed) self.__liquid_phase = Phase(cortix_start_time, species=species, quantities=quantities) # Initialize phase water_mass_cc = 0.99965 # [g/cc] self.__liquid_phase.SetValue('water', water_mass_cc, cortix_start_time) x_0 = 1000.0 # initial height [m] above ground at 0 self.__liquid_phase.SetValue('height', x_0, cortix_start_time) v_0 = 0.0 # initial vertical velocity [m/s] self.__liquid_phase.SetValue('speed', v_0, cortix_start_time)