BIMBase之python建模宝典第十六弹

新知榜官方账号

2023-12-02 02:31:42

BIMBase自从2021年发布以来获得了众多关心国产BIM和业务数字化转型的圈内老法师的关注,除了是国内首款完全自主知识产权的的BIMBase系统,实现建筑信息模型(BIM)关键核心技术自主研发安全可控。同时开创了BIMXPYthon的技术跨界混搭风,得以让建模可以通过快速编程实现。So!BIMBase团队为了在功能和场景上帮助大家了解BIMBase学习建模小技巧开设了技术专栏【BIMBase之python建模宝典】今日分享第十六弹随机骨料模型可用于混凝土细观研究,早在abaqus等软件中可以通过插件或者代码来生成三维随机骨料模型,今天我们用BIMBase-python的参数化方式来打开它吧。

①定义参数

其中参数包括控制指定空间的大小,骨料形状、骨料尺寸及骨料模型的模式等,参数内使用combo属性来控制属性条目,用obvious属性控制参数显隐,group属性将参数归类。

classD_random_aggregate_model(Component):
def__init__(self):
Component.__init__(self)
self['三维随机骨料']=Attr(None,show=True)
self['X限制:min']=Attr(100.0,obvious=True,group='立方体尺寸')
self['X限制:max']=Attr(100.0,obvious=True,group='立方体尺寸')
self['Y限制:min']=Attr(100.0,obvious=True,group='立方体尺寸')
self['Y限制:max']=Attr(100.0,obvious=True,group='立方体尺寸')
self['Z限制:min']=Attr(100.0,obvious=True,group='立方体尺寸')
self['Z限制:max']=Attr(100.0,obvious=True,group='立方体尺寸')
self['长度:min']=Attr(5.0,obvious=False,group='约束条件')
self['长度:max']=Attr(10.0,obvious=False,group='约束条件')
self['数量']=Attr(100,obvious=True,group='约束条件')
self['最小间距']=Attr(0.0,obvious=True,group='约束条件')
self['圆柱半径:min']=Attr(0.5,obvious=False,group='约束条件')
self['圆柱半径:max']=Attr(1.5,obvious=False,group='约束条件')
self['长轴:min']=Attr(2.5,obvious=False,group='约束条件')
self['长轴:max']=Attr(4.5,obvious=False,group='约束条件')
self['短轴:min']=Attr(0.5,obvious=False,group='约束条件')
self['短轴:max']=Attr(1.5,obvious=False,group='约束条件')
self['球体半径:min']=Attr(2.5,obvious=False,group='约束条件')
self['球体半径:max']=Attr(4.5,obvious=False,group='约束条件')
self['形状']=Attr('线条',combo=['线条','圆柱','椭球','球体'],obvious=True,group='骨料')
self['模式']=Attr('嵌入',combo=['嵌入','切割'],obvious=False,group='骨料')
self.replace()

②定义变量,调用参数

使用np.random.rand()函数生成随机数,与骨料尺寸约束条件相乘,生成区间内的随机骨料尺寸数据;与pi弧度相乘再减去pi/2,生成骨料的随机转角数据;把随机数直接作为骨料的随机RGB值。

@export
defreplace(self):
#立方体尺寸
BoxX=(self['X限制:max']-self['X限制:min'])*np.random.rand()+self['X限制:min']
BoxY=(self['Y限制:max']-self['Y限制:min'])*np.random.rand()+self['Y限制:min']
BoxZ=(self['Z限制:max']-self['Z限制:min'])*np.random.rand()+self['Z限制:min']

#约束条件
particleNum=self['数量']
MinDist=self['最小间距']
ConeRadius=(self['圆柱半径:max']-self['圆柱半径:min'])*np.random.rand(particleNum,)+self['圆柱半径:min']
print(ConeRadius)
ARadius=(self['长轴:max']-self['长轴:min'])*np.random.rand(particleNum,)+self['长轴:min']
BRadius=(self['短轴:max']-self['短轴:min'])*np.random.rand(particleNum,)+self['短轴:min']
SphereRadius=(self['球体半径:max']-self['球体半径:min'])*np.random.rand(particleNum,)+self['球体半径:min']
Length=(self['长度:max']-self['长度:min'])*np.random.rand(particleNum,)+self['长度:min']

#骨料的随机转角和颜色
XAngle=pi*np.random.rand(particleNum,)-pi/2
YAngle=pi*np.random.rand(particleNum,)-pi/2
ZAngle=pi*np.random.rand(particleNum,)-pi/2
RColor=np.random.rand(particleNum,)
GColor=np.random.rand(particleNum,)
BColor=np.random.rand(particleNum,)

③设置骨料尺寸参数显隐及定义间距和边距

设置在不同骨料形状时,对应可供修改的参数显示及不对应参数隐藏;定义骨料形状不同时的间距MinDist,边距margin。当骨料形状为线条时,属性表显示的尺寸参数有长度;当骨料形状为圆柱时,属性表显示的尺寸参数有长度和圆柱半径;当骨料形状为椭球时,属性表显示的尺寸参数有长轴和短轴;当骨料形状为球体时,属性表显示的尺寸参数有球体半径。

margin=0
ifself['形状']=='线条':
    MinDist=self['最小间距']+2*self['长度:max']
    self.at('长度:min')['obvious']=True
    self.at('长度:max')['obvious']=True
    self.at('圆柱半径:min')['obvious']=False
    self.at('圆柱半径:max')['obvious']=False
    self.at('长轴:min')['obvious']=False
    self.at('长轴:max')['obvious']=False
    self.at('短轴:min')['obvious']=False
    self.at('短轴:max')['obvious']=False
    self.at('球体半径:min')['obvious']=False
    self.at('球体半径:max')['obvious']=False
    self.at('模式')['obvious']=False
ifself['模式']=='嵌入':
    margin=self['长度:max']
elifself['形状']=='圆柱':
    MinDist=self['最小间距']+2*self['长度:max']
    self.at('长度:min')['obvious']=True
    self.at('长度:max')['obvious']=True
    self.at('圆柱半径:min')['obvious']=True
    self.at('圆柱半径:max')['obvious']=True
    self.at('长轴:min')['obvious']=False
    self.at('长轴:max')['obvious']=False
    self.at('短轴:min')['obvious']=False
    self.at('短轴:max')['obvious']=False
    self.at('球体半径:min')['obvious']=False
    self.at('球体半径:max')['obvious']=False
    self.at('模式')['obvious']=True
ifself['模式']=='嵌入':
    margin=max(self['长度:max'],self['圆柱半径:max'])
elifself['形状']=='椭球':
    MinDist=self['最小间距']+2*self['长轴:max']
    self.at('长度:min')['obvious']=False
    self.at('长度:max')['obvious']=False
    self.at('圆柱半径:min')['obvious']=False
    self.at('圆柱半径:max')['obvious']=False
    self.at('长轴:min')['obvious']=True
    self.at('长轴:max')['obvious']=True
    self.at('短轴:min')['obvious']=True
    self.at('短轴:max')['obvious']=True
    self.at('球体半径:min')['obvious']=False
    self.at('球体半径:max')['obvious']=False
    self.at('模式')['obvious']=True
ifself['模式']=='嵌入':
    margin=max(self['长轴:max'],self['短轴:max'])
elifself['形状']=='球体':
    MinDist=self['最小间距']+2*self['球体半径:max']
    self.at('长度:min')['obvious']=False
    self.at('长度:max')['obvious']=False
    self.at('圆柱半径:min')['obvious']=False
    self.at('圆柱半径:max')['obvious']=False
    self.at('长轴:min')['obvious']=False
    self.at('长轴:max')['obvious']=False
    self.at('短轴:min')['obvious']=False
    self.at('短轴:max')['obvious']=False
    self.at('球体半径:min')['obvious']=True
    self.at('球体半径:max')['obvious']=True
    self.at('模式')['obvious']=True
ifself['模式']=='嵌入':
    margin=self['球体半径:max']

本页网址:https://www.xinzhibang.net/article_detail-21718.html

寻求报道,请 点击这里 微信扫码咨询

关键词

BIMBase 建模 python

分享至微信: 微信扫码阅读

相关工具

相关文章