def main() -> None: wheel1 = ( ps.Circle(ps.Point(w_1, R), R) .set_fill_color(ps.Style.Color.BLUE) .set_line_width(6) ) wheel2 = wheel1.translate(ps.Point(L, 0)) under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H) under.style.fill_color = ps.Style.Color.RED under.style.line_color = ps.Style.Color.RED over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R, 1.25 * H).set_fill_color( ps.Style.Color.WHITE ) over.style.line_width = 14 over.style.line_color = ps.Style.Color.RED over.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT ground = ps.Wall([ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R) ground.style.fill_pattern = ps.Style.FillPattern.UP_LEFT_TO_RIGHT model = ps.Composition( { "wheel1": wheel1, "wheel2": wheel2, "under": under, "over": over, "ground": ground, } ) fig = ps.Figure( 0, w_1 + 2 * L + 3 * R, -1, 2 * R + 3 * H, backend=MatplotlibBackend ) fig.add(model) fig.show()
def main() -> None: c = ps.Point(w_1, R) wheel1 = ps.Circle(c, R) wheel2 = wheel1.translate(ps.Point(L, 0)) under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H) over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R, 1.25 * H).set_fill_color(ps.Style.Color.WHITE) ground = ps.Wall( [ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R) ground.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT vehicle = ps.Composition({ "wheel1": wheel1, "wheel2": wheel2, "under": under, "over": over, "ground": ground, }) vehicle.style.line_color = ps.Style.Color.RED wheel1_dim = ps.LinearDimension("$w_1$", c + ps.Point(2, 0.25), c) hdp = w_1 + L + 3 * R # horizontal dimension position R_dim = ps.LinearDimension("$R$", ps.Point(hdp, 0), ps.Point(hdp, R)) H_dim = ps.LinearDimension("$H$", ps.Point(hdp, 2 * R), ps.Point(hdp, 2 * R + H)) H2_dim = ps.LinearDimension("$\\frac{5}{4}H$", ps.Point(hdp, 2 * R + H), ps.Point(hdp, 2 * R + (9 / 4) * H)) vdp = 2 * R + H + 3 / 2 * H R2_dim = ps.LinearDimension("$2R$", ps.Point(w_1 - 2 * R, vdp), ps.Point(w_1, vdp)) L_dim = ps.LinearDimension("$L$", ps.Point(w_1, vdp), ps.Point(w_1 + L, vdp)) R3_dim = ps.LinearDimension("$2R$", ps.Point(w_1 + L, vdp), ps.Point(w_1 + L + 2 * R, vdp)) dimensions = ps.Composition({ "wheel1_dim": wheel1_dim, "R_dim": R_dim, "H_dim": H_dim, "H2_dim": H2_dim, "R2_dim": R2_dim, "L_dim": L_dim, "R3_dim": R3_dim, }) model = ps.Composition({"vehicle": vehicle, "dimensions": dimensions}) figure = ps.Figure(0, w_1 + 2 * L + 3 * R, -1, 2 * R + 3 * H, backend=MatplotlibBackend) figure.add(model) figure.show()
def main() -> None: wall = ps.Wall( [ ps.Point(x, gaussian(x)) for x in np.linspace(W + L, 0, 51, endpoint=False) ], 0.3, ) wall.style.line_color = ps.Style.Color.BROWN inlet_profile = ps.VelocityProfile(ps.Point(0, 0), H, velocity_profile, 5) inlet_profile.style.line_color = ps.Style.Color.BLUE symmetry_line = ps.Line(ps.Point(0, H), ps.Point(W + L, H)) symmetry_line.style.line_style = ps.Style.LineStyle.DASHED outlet = ps.Line(ps.Point(W + L, 0), ps.Point(W + L, H)) outlet.style.line_style = ps.Style.LineStyle.DASHED model = ps.Composition({ "bottom": wall, "inlet": inlet_profile, "symmetry line": symmetry_line, "outlet": outlet, }) velocity = velocity_profile(H / 2.0) line = ps.Line(ps.Point(W - 2.5 * sigma, 0), ps.Point(W + 2.5 * sigma, 0)) line.style.line_style = ps.Style.LineStyle.DASHED symbols = { "alpha": ps.LinearDimension(r"$\alpha$", ps.Point(W, 0), ps.Point(W, alpha)), "W": ps.LinearDimension(r"$W$", ps.Point(0, -0.5), ps.Point(W, -0.5)), "L": ps.LinearDimension(r"$L$", ps.Point(W, -0.5), ps.Point(W + L, -0.5)), "v(y)": ps.Text("$v(y)$ ", ps.Point(H / 2.0, velocity.x)), "dashed line": line, } symbols = ps.Composition(symbols) fig = ps.Figure(0, W + L + 1, -2, H + 1, backend=MatplotlibBackend) fig.add(model) fig.add(symbols) fig.show()
def main() -> None: d = make_dashpot(0) s = make_spring(0) M = ps.Rectangle(ps.Point(0, H), 4 * H, 4 * H).set_line_width(4) left_wall = ps.Rectangle(ps.Point(-L, 0), H / 10, L).set_fill_pattern( ps.Style.FillPattern.UP_LEFT_TO_RIGHT) ground = ps.Wall([ps.Point(-L / 2, 0), ps.Point(L, 0)], thickness=-H / 10) wheel1 = ps.Circle(ps.Point(H, H / 2), H / 2) wheel2 = wheel1.translate(ps.Point(2 * H, 0)) fontsize = 24 text_m = ps.Text("$m$", ps.Point(2 * H, H + 2 * H)) text_m.style.font_size = fontsize text_ku = ps.Text("$ku$", ps.Point(-L / 2, H + 4 * H)) text_ku.style.font_size = fontsize text_bv = ps.Text("$bu'$", ps.Point(-L / 2, H)) text_bv.style.font_size = fontsize x_axis = ps.Axis(ps.Point(2 * H, L), H, "$u(t)$") x_axis_start = ps.Line(ps.Point(2 * H, L - H / 4), ps.Point(2 * H, L + H / 4)).set_line_width(4) model = ps.Composition({ "spring": s, "mass": M, "left wall": left_wall, "ground": ground, "wheel1": wheel1, "wheel2": wheel2, "text_m": text_m, "text_ku": text_ku, "x_axis": x_axis, "x_axis_start": x_axis_start, }) fig = ps.Figure(-L, x_max, -1, L + H, backend=MatplotlibBackend) fig.add(model) damping = ps.Composition({"dashpot": d, "text_bv": text_bv}) # or fig = Composition(dict(fig=fig, dashpot=d, text_bv=text_bv)) fig.add(damping) fig.show()
R = 1 # radius of wheel L = 4 # distance between wheels H = 2 # height of vehicle body w_1 = 5 # position of front wheel # TODO : draw grids # drawing_tool.set_grid(True) c = ps.Point(w_1, R) wheel1 = ps.Circle(c, R) wheel2 = wheel1.translate(ps.Point(L, 0)) under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H) over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R, 1.25 * H).set_fill_color(ps.Style.Color.WHITE) ground = ps.Wall([ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R) ground.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT vehicle = ps.Composition({ "wheel1": wheel1, "wheel2": wheel2, "under": under, "over": over, "ground": ground }) vehicle.style.line_color = ps.Style.Color.RED wheel1_dim = ps.ArrowWithText("$w_1$", c + ps.Point(2, 0.25), c) hdp = w_1 + L + 3 * R # horizontal dimension position R_dim = ps.DistanceWithText("$R$", ps.Point(hdp, 0), ps.Point(hdp, R))
def make_spring(x): s_start = ps.Point(-L, 4 * H) s = ps.Spring(start=s_start, length=L + x, bar_length=3 * H / 2) s = s.rotate(-np.pi / 2, s_start) return s d = make_dashpot(0) s = make_spring(0) M = ps.Rectangle(ps.Point(0, H), 4 * H, 4 * H).set_line_width(4) left_wall = ps.Rectangle(ps.Point(-L, 0), H / 10, L).set_fill_pattern( ps.Style.FillPattern.UP_LEFT_TO_RIGHT ) ground = ps.Wall([ps.Point(-L / 2, 0), ps.Point(L, 0)], thickness=-H / 10) wheel1 = ps.Circle(ps.Point(H, H / 2), H / 2) wheel2 = wheel1.translate(ps.Point(2 * H, 0)) fontsize = 24 text_m = ps.Text("$m$", ps.Point(2 * H, H + 2 * H)) text_m.style.font_size = fontsize text_ku = ps.Text("$ku$", ps.Point(-L / 2, H + 4 * H)) text_ku.style.font_size = fontsize text_bv = ps.Text("$bu'$", ps.Point(-L / 2, H)) text_bv.style.font_size = fontsize x_axis = ps.Axis(ps.Point(2 * H, L), H, "$u(t)$", label_spacing=(0.04, -0.01)) x_axis_start = ps.Line( ps.Point(2 * H, L - H / 4), ps.Point(2 * H, L + H / 4) ).set_line_width(4)
logging.basicConfig(level=logging.INFO) W = 5 # upstream area L = 10 # downstream area H = 4 # height sigma = 2 alpha = 2 # Create bottom def gaussian(x: float) -> float: return alpha * np.exp(-((x - W)**2) / (0.5 * sigma**2)) wall = ps.Wall([ ps.Point(x, gaussian(x)) for x in np.linspace(W + L, 0, 51, endpoint=False) ], 0.3) wall.style.line_color = ps.Style.Color.BROWN def velocity_profile(y: float) -> ps.Point: return ps.Point(2 * y * (2 * H - y) / H**2, 0) inlet_profile = ps.VelocityProfile(ps.Point(0, 0), H, velocity_profile, 5) inlet_profile.style.line_color = ps.Style.Color.BLUE symmetry_line = ps.Line(ps.Point(0, H), ps.Point(W + L, H)) symmetry_line.style.line_style = ps.Style.LineStyle.DASHED outlet = ps.Line(ps.Point(W + L, 0), ps.Point(W + L, H))