我可以在 Gekko 的设计优化过程中使用隐式目标函数吗?这个隐式函数是一个创建数值模型的子程序

2024-03-06

我正在使用 Abaqus 进行抗震结构系统设计的优化。 我打算使用 Gekko 来达到这个目的。但似乎我在写下有关此任务的合适语法时犯了错误。 “Objective”是负责创建Abaqus数值模型、分析模型、处理结果和计算罚函数的子程序的名称。 “目标”返回建筑物成本与要最小化的惩罚函数的总和。 这是错误消息:

@error:数据不足 CSV 读取错误:动态问题的数据行数必须 >= 2 已识别的数据点:1 停止。 。 。

回溯(最近一次调用最后一次): 文件“C:\temp\AK\24-Gekko\opti1.10.3.0.py”,第 721 行,位于 m.solve() 文件“C:\Users\amjad\AppData\Roaming\Python\Python38\site-packages\gekko\gekko.py”,第 2140 行,求解 引发异常(apm_error) 异常:@error:数据不足 CSV 读取错误:动态问题的数据行数必须 >= 2 已识别的数据点:1 停止。 。 。

这是优化过程的主要代码: ''' m = GEKKO(远程=假)

Alfa1  = m.Const(1.25)
Alfa2  = m.Const(0.3)
Alfa3  = m.Const(1.25)
UCS    = m.Const(1000.)    #   $/Ton of steel
UCC    = m.Const(67.)      #   $/m3 of concrete
UCCF   = m.Const(20.)      #   $/m2 of column wood framework
UCBF   = m.Const(28.)      #   $/m2 of beam wood framework
UCWF   = m.Const(20.)      #   $/m2 of wall wood framework
GammaS = m.Const(7850)
GammaC = m.Const(2500)
cover  = m.Const(10.)
f_c    = m.Const(30.)
fy     = m.Const(400.)
Est    = m.Const(200000.)
eu_c   = m.Const(0.003)
bw     = m.Const(700.)
fai    = 6.
#defining material parameters
Mats = {
    "CDP30.0" :("mm",GammaC.value*1.e-12,0.18,0.,[f_c.value,0.0015,0.4,100],[f_c.value/10., 0.001 , 1.0],35,0.1,1.12,0.667,0.1,1.0,0.0),
    "C30.0" :("mm",GammaC.value*1.e-12,0.18,0.,f_c.value),
    "S400.0":("mm",GammaS.value*1.e-12,0.3,0.,fy.value),
    }

#defining section's locations within building members and lengths of members
Sections = {
    "C11":[[("A0-A1","A1-A2","D0-D1","D1-D2"),750.],[],[],[]],
    "C22":[[("A2-A3","A3-A4","A4-A5","D2-D3","D3-D4","D4-D5"),750.],[],[],[]],
    "C33":[[("B0-B1","C0-C1","B1-B2","C1-C2","B2-B3","C2-C3","B3-B4","C3-C4","B4-B5","C4-C5",),750.],[],[],[]],
    "BB1":[[("A1-B1","C1-D1","A2-B2","C2-D2","A3-B3","C3-D3","A4-B4","C4-D4","A5-B5","C5-D5",),700.],[],[]],
    "WW1":[[("B0-C1","B1-C2","B2-C3","B3-C4","B4-C5",),750.],[],[]],
    }
#creating materials of the model
MatText = []
for i in Mats:
    if   i[1:3]=="DP":CDPs(i,Mats[i][0],Mats[i][1],Mats[i][2],Mats[i][3],Mats[i][4],Mats[i][5],Mats[i][6],Mats[i][7],Mats[i][8],Mats[i][9],Mats[i][10],Mats[i][11],Mats[i][12])
    elif i[0]  =="C" :EPPs(i,Mats[i][0],Mats[i][1],Mats[i][2],Mats[i][3],Mats[i][4])
    elif i[0]  =="S" :EPPs(i,Mats[i][0],Mats[i][1],Mats[i][2],Mats[i][3],Mats[i][4])
#objective function initializing
FX = 0.
Vars = []
for i in [x for x in Sections if x[0]=="C"]:
    a      = m.Var(value=125,lb=100,ub=250,integer = False)
    b      = m.Var(value=125,lb=100,ub=250,integer = False)
    Us     = m.Var(value=0.02,lb=0.01,ub=0.045,integer = False)
    rebarS = rectRC(a.value,b.value,Us.value,cover.value,fai,"C")
    Sections[i][1] = [a.value,b.value,Us.value,rebarS]
    As = np.pi*fai**2./4*(4+2*rebarS[1][0]+2*rebarS[2][0])
    #calculating the cost of a Column section
    Sections[i][2] = m.Intermediate(Alfa1*As/(1000**3)*GammaS*UCS+a*b/(1000*1000)*UCC+2*(a+b)/(1000)*UCCF)
    Sections[i][3] = PMinteraction(eu_c.value,cover.value,a.value,b.value,f_c.value,fy.value,Est.value,(2+rebarS[1][0])*np.pi*fai**2/4,(2+rebarS[1][0])*np.pi*fai**2/4)
    FX += len(Sections[i][0][0])*Sections[i][0][1]/1000*Sections[i][2]
    Vars.append((i,Sections[i][1][:3]))

for i in [x for x in Sections if x[0]=="B"]:
    a      = m.Var(value=125,lb=100,ub=250,integer = False)
    b      = m.Var(value=125,lb=100,ub=250,integer = False)
    Us     = m.Var(value=0.02,lb=0.01,ub=0.045)
    rebarS = rectRC(a.value,b.value,Us.value,cover.value,fai,"B")
    Sections[i][1] = [a.value,b.value,Us.value,rebarS]
    As = np.pi*fai**2./4*(4+2*rebarS[1][0]+2*rebarS[2][0])
    #calculating the cost of a Beam section
    Sections[i][2] = m.Intermediate((2*Alfa2*As/(1000**3)+(1-2*Alfa2)*As/(1000**3))*GammaS*UCS+a*b/(1000*1000)*UCC+(a+2*b)/(1000)*UCBF)
    print (Sections[i][2])
    FX += len(Sections[i][0][0])*Sections[i][0][1]/1000*Sections[i][2]
    Vars.append((i,Sections[i][1][:3]))

for i in [x for x in Sections if x[0]=="W"]:
    a      = m.Var(value=125,lb=100,ub=250,integer = False)
    b      = bw.value
    Us     = m.Var(value=0.009,lb=0.007,ub=0.01)
    rebarS = rectRC(a.value,b.value,Us.value,cover.value,fai,"W")
    Sections[i][1] = [a.value,b.value,Us.value,rebarS]
    As = np.pi*fai**2./4*(4+2*rebarS[1][0]+2*rebarS[2][0])
    #calculating the cost of a Wall section
    Sections[i][2] = m.Intermediate(Alfa3*As/(1000**3)*GammaS*UCS+a*b/(1000*1000)*UCC+2*b/(1000)*UCWF)
    print (Sections[i][2])
    FX += len(Sections[i][0][0])*Sections[i][0][1]/1000*Sections[i][2]
    Vars.append((i,Sections[i][1][:3]))

#modifying object function by a reference value
FX = FX/ReferenceFX * 1.

m.Minimize(Objective(Vars))

m.options.SOLVER = 1
m.options.IMODE = 6
m.solve()

'''


Gekko 解决方案模式 https://gekko.readthedocs.io/en/latest/imode.html?highlight=imode#imode-1文档中有更详细的描述。当前模式是IMODE=6应该有微分方程和代数方程。在此模式下,需要定义解决方案的时间点,例如:

m.time=[0,0.1,0.2,0.5,1.0,1.5,2.0]

如果它是稳态解(没有微分方程)那么它应该是IMODE=3用于稳态优化。

m.options.IMODE=3

目前还没有定义PMinteraction。如果这是 Abaqus 模型调用,则需要将其替换为 Gekko 可以编译为字节码的合适模型近似值。一些选项是c 样条线 (1D) https://gekko.readthedocs.io/en/latest/ml.html, B样条线 (2D) https://gekko.readthedocs.io/en/latest/ml.html, or 机器学习模型(高维函数) https://gekko.readthedocs.io/en/latest/ml.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我可以在 Gekko 的设计优化过程中使用隐式目标函数吗?这个隐式函数是一个创建数值模型的子程序 的相关文章

随机推荐