def __init__(self): sf.Application.__init__(self) # Set up the physics world self.world = ode.dWorld() self.world.setGravity(0, -9.81, 0) ssid = ode.dSimpleSpace() self.space = ode.dSimpleSpace(1) # dQuadTreeSpace, dHashSpace self.contactgroup = ode.JointGroup() self.bodyList = []
def sensitivity(self, scenario, value, ranges): self.data.max_P = [] self.data.max_T = [] self.data.max_conversion = [] self.data.max_vent = [] for i in tqdm(ranges): if value == "Rupture Disc Diameter": scenario.D_RD = i elif value == "Rupture Disc Burst Pressure": scenario.P_RD = i elif value == "Backpressure Regulator Set-Point": scenario.P_BPR = i elif value == "Hydrogen Peroxide Concentration": scenario.XH2O2 = i / 100 elif value == "Reactor Charge": scenario.mR = i elif value == "Contamination Factor": scenario.kf = i elif value == "Reaction Temperature": scenario.rxn_temp = i ode = ODE.ODE(scenario) ode.initialize_heatup() ode.integrate() tc = ode.termination_code() # if self.data.RD is True and tc == "Process Finished Successfully (Rupture disc burst)": ode.initialize_vent(integrator='vode') ode.integrate() self.data.max_P.append(ode.max_P()) self.data.max_T.append(ode.max_T()) self.data.max_conversion.append(ode.max_conversion()) self.data.max_vent.append(ode.max_vent())
def _nearcb(self, args, geom1, geom2): """ Create contact joints between colliding geoms. """ body1, body2 = geom1.getBody(), geom2.getBody() if (body1 is None): body1 = ode.environment if (body2 is None): body2 = ode.environment if (ode.areConnected(body1, body2)): return contacts = ode.collide(geom1, geom2) for c in contacts: c.setBounce(0.2) c.setMu(10000) j = ode.ContactJoint(self.world, self._cjoints, c) j.attach(body1, body2)
def main_functions(): inputData = input() m1 = inputData.get('m1') m2 = inputData.get('m2') L1 = inputData.get('L1') L2 = inputData.get('L2') theta1 = inputData.get('theta1') theta2 = inputData.get('theta2') g = inputData.get('g') t = inputData.get('t') temp = ODE(theta1, theta2, m1, m2, L1, L2, g, t) output(temp[0], temp[1], temp[2]) plot(temp[0], temp[1], temp[2])
def run_scenario_menu(self): if None in [self.data.VR, self.data.RD, self.data.kf]: print(' ') print( 'Scenario not fully specified. Update scenario configuration and try again' ) print(' ') input("Press [Enter] to continue...") else: answers = self.setup_plot_rt_q() plot_rt = answers.get("plot_rt") scen = Scenario(self.data.VR, self.data.rxn_temp, self.data.rxn_time, self.data.XH2O2, self.data.mR, self.data.D_RD, self.data.P_RD, self.data.P_BPR, self.data.D_BPR, self.data.BPR_max_Cv, self.data.P0, self.data.kf, self.data.T0, self.data.Ux, self.data.AR, self.data.MAWP, self.data.max_rate, self.data.Kp, self.data.Ki, self.data.Kd, self.data.flow_regime, self.data.BPR, self.data.RD, self.data.cool_time, self.data.TF) ode1 = ODE.ODE(scen) ode1.initialize_heatup() print('Integrating Heatup...') print(' ') ode1.integrate(plot_rt) tc = ode1.termination_code() print(' ') print(tc) print(' ') if self.data.RD is True and ode1.tc == 1: print('Integrating ERS...') print(' ') ode1.initialize_vent(integrator='vode') ode1.integrate(plot_rt) tc = ode1.termination_code() print(' ') print(tc) print(' ') self.data.ode = ode1 self.summary_stats_menu()
def near_callback(self, args, geom1, geom2): # Check if the objects do collide contacts = ode.collide(geom1, geom2) # Create contact joints self.world,self.contactgroup = args for c in contacts: c.setMode(ode.ContactBounce) c.setBounce(0.2) c.setBounceVel(0.15) c.setMu(250.0) j = ode.ContactJoint(self.world, self.contactgroup, c) j.attach(geom1.getBody(), geom2.getBody())
def nearCallback (data, o1, o2): ## exit without doing anything if the two bodies are connected by a joint b1 = ode.dGeomGetBody(o1) b2 = ode.dGeomGetBody(o2) if b1 and b2 and ode.dAreConnected (b1,b2): return ## @@@ it's still more convenient to use the C interface here. contact = ode.dContact() contact.surface.mode = 0 contact.surface.mu = ode.dInfinity if ode.dCollide ( o1,o2,0,contact.geom,sizeof(ode.dContactGeom) ): c = dJointCreateContact (world.id(),contactgroup.id(),&contact) ode.dJointAttach (c,b1,b2)
# Created by: # Felipe Uribe @ MIT, TUM, DTU # ============================================================================= # Version 2020-04 # ============================================================================= import numpy as np import matplotlib import matplotlib.pyplot as plt # import ODE from SuS import SuS #============================================================================ # numerical model: defined in ODE.py dim = 50+1 # RF plus flux: <= 203+1, otherwise increase dim_max in ODE.py u_ODE = lambda theta: ODE.analytical(theta) # LSF u_thres = 2.7 # maximum allowed pressure head g_LSF_single = lambda theta: u_thres - max(u_ODE(theta)) #============================================================================ # SuS method NSIM = int(30) # number of independent simulations N = int(1e3) # total number of samples per level p0 = 0.1 # prescribed level probability # LSF for all samples g_LSF = lambda theta: np.array([ g_LSF_single(theta[:,i]) for i in range(N) ]) #============================================================================
0.70541941, # HypoWCCn 0.03008159, # HyperWCCn 0.08212058, # aWCC 0., # laWCC 0., # vvdm 0., # VVDc 0., # VVDn 0. ]) # WVC frq_ind = 2 period = 21.62451 ##### Below is example solving and plotting frq mRNA for Tseng's model ##### ModTseng = ODE('Tseng\'s Model', frq_ind, Y, p, p_add, dY, Y0, period, findQ=False) tot_time = 100 t_test = np.linspace(0, tot_time, 100 * tot_time) sol_test = ModTseng.solve(ModTseng.lim_cyc_vals, t_test) frq_sol = sol_test[:, frq_ind] plt.plot(t_test, frq_sol)
import matplotlib.pyplot as plt import astropy.units as u import astropy.constants as c import ODE def f2Prime(x,y1,y2): #print(f"{x} {y1} {y2}") return [3*x**2+8*y1-3*y2]*2 def fPrime(x,y): return [5*y+1] solvePoints = [0,1,2,3] #Euler print(ODE.euler(f2Prime,0,[-1,0],solvePoints)) print(ODE.euler(fPrime,0,[-1],solvePoints)) #Heun print(ODE.heun(f2Prime,0,[-1,0],solvePoints)) print(ODE.heun(fPrime,0,[-1],solvePoints)) #RK4 print(ODE.rk4(f2Prime,0,[-1,0],solvePoints)) print(ODE.rk4(fPrime,0,[-1],solvePoints)) #Scipy odeint test def pend(y, t, b, c): theta, omega = y dydt = [omega, -b*omega - c*np.sin(theta)] return dydt
qD = sympy.Symbol('qD') # Parameters as additive pulses p_add = [qA, qB, qC, qD] # Symbolic ODE RHS dA = k3*D**m/(K**m+D**m) - k4*A # frq mRNA dB = k5*A - k6*B + k7*C - k8*B*D # FRQ Protein dC = k8*B*D - k7*C - k9*C # WC-1:FRQ complex dD = k1 - k2*D + k7*C - k8*B*D # WC-1 protein dY = sympy.Matrix([dA, dB, dC, dD]) # Vector ODE RHS # Initial values on the limit cycle at frq mRNA max. Y0 = np.array([0.958658, # A0 0.7892854, # B0 0.3232268, # C0 0.5296776]) # D0 frq_ind = 0 period = 22. ##### Below is example solving and plotting frq mRNA for the simple model ##### ModSimple = ODE('The Simple Model',frq_ind,Y,p,p_add,dY,Y0,period,findQ=False) tot_time=100 t_test = np.linspace(0,tot_time, 100*tot_time) sol_test = ModSimple.solve(ModSimple.lim_cyc_vals, t_test) frq_sol = sol_test[:,frq_ind] plt.plot(t_test, frq_sol)
for index in range(len(collocation_points)): params_eq = { "gravity": 9.81, "density": collocation_points["density"][index], "radius": collocation_points["radius"][index], "mass": collocation_points["mass"][index], "drag_coefficient": collocation_points["drag_coefficient"][index] } param_initial_conditions = { "h": collocation_points["h"][index], "alpha": collocation_points["alpha"][index], "v0": collocation_points["v0"][index], } time, x, y = Solver.solve_object_ODE(delta_t, param_initial_conditions, params_eq) time_vec.append(time) x_vec.append(x) y_vec.append(y) len_max = 0 index_len = 0 for i in range(len(x_vec)): if len(x_vec[i]) > len_max: len_max = len(x_vec[i]) index_len = index print(len_max) print(index_len) x_vec_new = list()
import ODE as ode NUM= 10 ## number of boxes SIDE = 0.2 ## side length of a box MASS= 1.0 ## mass of a box RADIUS =0.1732 ## sphere radius ## dynamics and collision objects body=[] box=[] joint = [] for i in range(NUM): body.append(ode.dBody() ) box.append(ode.dBox() ) joint.append (ode.dBallJoint() ) contactgroup= ode.dJointGroup() space = ode.dSimpleSpace(None) world = ode.dWorld() ## this is called by space.collide when two objects in space are ## potentially colliding. def nearCallback (data, o1, o2): ## exit without doing anything if the two bodies are connected by a joint b1 = ode.dGeomGetBody(o1) b2 = ode.dGeomGetBody(o2) if b1 and b2 and ode.dAreConnected (b1,b2): return
0.0110685024, # Fn0 3.70361114, # Mw0 0.00666226484, # Wc0 0.924361228, # Wn0 0.0820481701, # FWn0 0.05214823, # Mc0 1.93780501 ]) # C0 frq_ind = 0 period = 22.3934820284 ##### Below is example solving and plotting frq mRNA for Dovzhenok's model ##### ModDovzhenok = ODE('The Dovzhenok Model', frq_ind, Y, p, p_add, dY, Y0, period, findQ=False) tot_time = 100 t_test = np.linspace(0, tot_time, 100 * tot_time) sol_test = ModDovzhenok.solve(ModDovzhenok.lim_cyc_vals, t_test) frq_sol = sol_test[:, frq_ind] plt.plot(t_test, frq_sol)