ODE的实现技术研究(jacob)

[color=blue]ODE引擎运行时利用Java并发对象(Java Concurrent Objects,Jacob)来完成过程实例的状态表示和并发性管理。
Jacob提供了应用级的并发机制,它不依赖于线程,这样就降低了系统的开销。

ODE的官方网站提供了一份Jacob的教程,粗略的读了以下,略知一二。
希望有兴趣的朋友一起探讨,或者明白的朋友,不吝赐教。

继续研究中.....[/color][url]http://ode.apache.org/jacob.html[/url]

基本原理
先看一个例子
void process(order) {
billingService.bill(order.billing);
shippingService.ship(order.product, order.shipping, self);
shipping = receive("shipping")
order.customer.send(shipping.details);
}

java 伪代码看起来没什么问题,但是存在缺陷:
1、程序执行过程中出现问题,用户不得不再次发送订单。
2、等待线程过多的时候会导致java虚机down掉。

做如下修改
void process(order) {
billingService.bill(order.billing);
shippingService.ship(order.product, order.shipping, self);
listenOn("shipping", part2);
}
void part2(shipping) {
order.customer.send(shipping.details);
}


看起来会好一些,
but still has a lot of points of failure, where you're not sure if you actually billed the customer and shipped the product or not.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是用ode函数实现三容水箱的仿真的代码: ```python import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # 定义ODE函数 def water_tank(y, t, q_in, A1, A2, A3, Cd12, Cd23, h01, h02, h03): h1, h2, h3 = y # 当前的水位高度 q12 = Cd12 * A1 * np.sqrt(2 * 9.81 * (h1 - h2)) # 1号箱向2号箱流动的流量 q23 = Cd23 * A2 * np.sqrt(2 * 9.81 * (h2 - h3)) # 2号箱向3号箱流动的流量 dh1dt = (q_in - q12) / A1 # 1号箱水位高度变化率 dh2dt = (q12 - q23) / A2 # 2号箱水位高度变化率 dh3dt = q23 / A3 # 3号箱水位高度变化率 return [dh1dt, dh2dt, dh3dt] # 初始条件 y0 = [1, 1, 1] # 三个水箱的初始水位高度 # 参数定义 Cd12 = 0.6 # 1号箱到2号箱的流量系数 Cd23 = 0.5 # 2号箱到3号箱的流量系数 A1 = 1 # 1号箱的底面积 A2 = 2 # 2号箱的底面积 A3 = 3 # 3号箱的底面积 h01 = 1 # 1号箱的初始水位高度 h02 = 1 # 2号箱的初始水位高度 h03 = 1 # 3号箱的初始水位高度 q_in = 0.5 # 1号箱的入流量 # 时间区间定义 t_start = 0 # 起始时间 t_end = 30 # 结束时间 t_step = 0.1 # 时间步长 t = np.arange(t_start, t_end, t_step) # 时间点数组 # 求解ODE方程 sol = odeint(water_tank, y0, t, args=(q_in, A1, A2, A3, Cd12, Cd23, h01, h02, h03)) # 绘制结果图像 plt.plot(t, sol[:, 0], label='Tank 1') plt.plot(t, sol[:, 1], label='Tank 2') plt.plot(t, sol[:, 2], label='Tank 3') plt.xlabel('Time') plt.ylabel('Water level') plt.title('Water Tank Simulation') plt.legend() plt.show() ``` 该代码使用了`scipy.integrate`库中的`odeint`函数求解ODE方程,其中ODE函数`water_tank`计算三个水箱的水位高度变化率,参数包括每个水箱的底面积、流量系数等。最后使用`matplotlib`库绘制出三个水箱的水位高度随时间的变化趋势。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值