模型的参数操作是 PTK 日常使用频率最高的功能。本文详解 get_value、set_value、get_values 和 set_values 四大核心方法的用法。
单个参数读取:get_value()
读取油嘴的 Bean Size:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
from sixgill.definitions import Parameters
beansize = model.get_value(Name='Choke', parameter=Parameters.Choke.BEANSIZE)使用字符串路径的等价写法:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
beansize = model.get_value('Choke', Parameters.Choke.BEANSIZE)设置单个参数:set_value()
修改油嘴尺寸为 12/64 英寸:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
model.set_value(Name='Choke', parameter=Parameters.Choke.BEANSIZE, value=12)通过高层上下文设置油藏压力——无需指定具体是哪个 Completion:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
model.set_value(
Well='Well_1',
parameter=Parameters.Completion.RESERVOIRPRESSURE,
value='3210')批量获取参数:get_values()
一次获取多个参数:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
result = model.get_values(
Name='Choke',
parameters=[Parameters.Choke.BEANSIZE,
Parameters.Choke.CRITICALPRESSURERATIO])
# 返回: {'Choke': {'BeanSize': 32, 'CriticalPressureRatio': 0.55}}获取所有油嘴的所有参数(不传参数列表即返回全部):文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
all_params = model.get_values(Choke=ALL)批量设置参数:set_values()
使用字典格式批量更新:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
updated = {
'CentComp': {
Parameters.Compressor.HONOURSTONEWALLLIMIT: True,
Parameters.Compressor.EFFICIENCY: 100.0,
Parameters.Compressor.PRESSUREDIFFERENTIAL: 2400.0
}
}
model.set_values(updated)统一赋值:set_all_value()
给所有油嘴设置相同的 Bean Size:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html
model.set_all_value(Choke=ALL, parameter=Parameters.Choke.BEANSIZE, value=2)注意:set_value() 在上下文匹配多个组件时会抛出异常,而 set_all_value() 则会对所有匹配组件执行相同赋值。文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html 文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/pipesim/26888.html






