MSC Nastran:優(yōu)化設(shè)計基礎(chǔ)教程.Tex.header_第1頁
MSC Nastran:優(yōu)化設(shè)計基礎(chǔ)教程.Tex.header_第2頁
MSC Nastran:優(yōu)化設(shè)計基礎(chǔ)教程.Tex.header_第3頁
MSC Nastran:優(yōu)化設(shè)計基礎(chǔ)教程.Tex.header_第4頁
MSC Nastran:優(yōu)化設(shè)計基礎(chǔ)教程.Tex.header_第5頁
已閱讀5頁,還剩20頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

MSCNastran:優(yōu)化設(shè)計基礎(chǔ)教程1優(yōu)化設(shè)計概述1.11優(yōu)化設(shè)計的基本概念優(yōu)化設(shè)計是一種系統(tǒng)方法,用于在滿足特定約束條件下,尋找最佳的設(shè)計參數(shù),以達到預(yù)定的性能目標(biāo)。在工程設(shè)計中,優(yōu)化設(shè)計可以顯著提高產(chǎn)品的性能,減少材料使用,降低生產(chǎn)成本,同時確保設(shè)計的可靠性和安全性。優(yōu)化設(shè)計通常涉及數(shù)學(xué)建模、數(shù)值分析和計算機輔助設(shè)計(CAD)技術(shù)。1.1.1原理優(yōu)化設(shè)計基于數(shù)學(xué)優(yōu)化理論,通過定義目標(biāo)函數(shù)和約束條件,使用優(yōu)化算法在設(shè)計空間中搜索最優(yōu)解。設(shè)計空間由所有可能的設(shè)計參數(shù)組合構(gòu)成,而目標(biāo)函數(shù)則反映了設(shè)計的性能指標(biāo),如最小化結(jié)構(gòu)重量或最大化結(jié)構(gòu)剛度。約束條件包括設(shè)計的物理限制、材料性能、成本預(yù)算等。1.1.2內(nèi)容目標(biāo)函數(shù):定義設(shè)計的優(yōu)化目標(biāo),如最小化成本、重量或最大化強度、效率。設(shè)計變量:可調(diào)整的設(shè)計參數(shù),如尺寸、形狀、材料選擇等。約束條件:設(shè)計必須滿足的限制,如應(yīng)力、位移、頻率等。優(yōu)化算法:用于搜索最優(yōu)解的數(shù)學(xué)方法,如梯度下降法、遺傳算法、粒子群優(yōu)化等。1.22優(yōu)化設(shè)計在工程中的應(yīng)用優(yōu)化設(shè)計在多個工程領(lǐng)域中有著廣泛的應(yīng)用,包括航空航天、汽車、建筑、機械和電子工程。例如,在航空航天領(lǐng)域,優(yōu)化設(shè)計可以用于減少飛機的重量,提高燃油效率;在汽車工程中,可以用于優(yōu)化車身結(jié)構(gòu),提高碰撞安全性;在建筑領(lǐng)域,可以用于設(shè)計更經(jīng)濟、更安全的結(jié)構(gòu)。1.2.1示例假設(shè)我們正在設(shè)計一個橋梁,目標(biāo)是最小化其總重量,同時確保其在最大風(fēng)力下的穩(wěn)定性。我們可以使用以下步驟進行優(yōu)化設(shè)計:定義目標(biāo)函數(shù):橋梁的總重量。定義設(shè)計變量:橋梁的寬度、厚度、材料類型。定義約束條件:橋梁在最大風(fēng)力下的位移不超過安全閾值。選擇優(yōu)化算法:使用遺傳算法進行優(yōu)化。#Python示例代碼:使用遺傳算法優(yōu)化橋梁設(shè)計

importnumpyasnp

fromdeapimportbase,creator,tools,algorithms

#定義目標(biāo)函數(shù)

defbridge_weight(width,thickness,material):

#假設(shè)的橋梁重量計算公式

returnwidth*thickness*material

#定義約束條件

defbridge_stability(width,thickness,material):

#假設(shè)的橋梁穩(wěn)定性計算公式

stability=width*thickness/material

returnstability>=100#安全閾值

#創(chuàng)建DEAP框架

creator.create("FitnessMin",base.Fitness,weights=(-1.0,))

creator.create("Individual",list,fitness=creator.FitnessMin)

toolbox=base.Toolbox()

toolbox.register("attr_width",np.random.randint,10,20)

toolbox.register("attr_thickness",np.random.randint,5,10)

toolbox.register("attr_material",np.random.randint,1,5)

toolbox.register("individual",tools.initCycle,creator.Individual,

(toolbox.attr_width,toolbox.attr_thickness,toolbox.attr_material),n=1)

toolbox.register("population",tools.initRepeat,list,toolbox.individual)

#定義評估函數(shù)

defevalBridge(individual):

weight=bridge_weight(*individual)

stability=bridge_stability(*individual)

ifnotstability:

weight+=1000#如果穩(wěn)定性不滿足,懲罰重量

returnweight,

toolbox.register("evaluate",evalBridge)

toolbox.register("mate",tools.cxTwoPoint)

toolbox.register("mutate",tools.mutGaussian,mu=0,sigma=1,indpb=0.2)

toolbox.register("select",tools.selTournament,tournsize=3)

#創(chuàng)建初始種群

pop=toolbox.population(n=50)

#進行遺傳算法優(yōu)化

hof=tools.HallOfFame(1)

stats=tools.Statistics(lambdaind:ind.fitness.values)

stats.register("avg",np.mean)

stats.register("std",np.std)

stats.register("min",np.min)

stats.register("max",np.max)

pop,logbook=algorithms.eaSimple(pop,toolbox,cxpb=0.5,mutpb=0.2,ngen=100,

stats=stats,halloffame=hof,verbose=True)

#輸出最優(yōu)解

print("最優(yōu)解:",hof[0])1.33MSCNastran優(yōu)化設(shè)計模塊介紹MSCNastran是一款廣泛應(yīng)用于工程分析和優(yōu)化的軟件,其優(yōu)化設(shè)計模塊提供了強大的工具,用于結(jié)構(gòu)優(yōu)化、形狀優(yōu)化、拓撲優(yōu)化和多學(xué)科優(yōu)化。通過MSCNastran,工程師可以定義復(fù)雜的設(shè)計問題,包括非線性分析、動態(tài)響應(yīng)和熱效應(yīng),然后使用先進的優(yōu)化算法自動尋找最優(yōu)解。1.3.1功能結(jié)構(gòu)優(yōu)化:通過調(diào)整結(jié)構(gòu)的尺寸和形狀,最小化重量或成本,同時滿足強度和剛度要求。形狀優(yōu)化:優(yōu)化結(jié)構(gòu)的幾何形狀,以提高性能或減少阻力。拓撲優(yōu)化:確定材料在結(jié)構(gòu)中的最優(yōu)分布,以實現(xiàn)輕量化和高性能。多學(xué)科優(yōu)化:同時考慮多個設(shè)計領(lǐng)域(如結(jié)構(gòu)、熱、流體)的優(yōu)化,以實現(xiàn)整體性能的提升。1.3.2使用方法在MSCNastran中進行優(yōu)化設(shè)計,通常需要以下步驟:建立模型:使用MSCNastran的前處理器創(chuàng)建結(jié)構(gòu)模型。定義優(yōu)化問題:設(shè)置目標(biāo)函數(shù)、設(shè)計變量和約束條件。選擇優(yōu)化算法:根據(jù)問題的復(fù)雜性選擇合適的優(yōu)化算法。運行優(yōu)化:使用MSCNastran的求解器進行優(yōu)化計算。分析結(jié)果:使用后處理器分析優(yōu)化結(jié)果,評估設(shè)計性能。1.3.3示例在MSCNastran中,優(yōu)化設(shè)計通常通過編寫輸入文件(.nas文件)來定義。以下是一個簡單的結(jié)構(gòu)優(yōu)化示例,目標(biāo)是最小化結(jié)構(gòu)的重量,同時確保其在特定載荷下的應(yīng)力不超過材料的屈服強度。BEGINBULK

$定義結(jié)構(gòu)模型

GRID,1,0.0,0.0,0.0

GRID,2,1.0,0.0,0.0

GRID,3,1.0,1.0,0.0

GRID,4,0.0,1.0,0.0

CQUAD4,1,1,2,3,4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0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設(shè)計流程

##2.1建立初始模型

在進行優(yōu)化設(shè)計之前,首先需要在MSCNastran中建立一個初始的有限元模型。這個模型應(yīng)該包含所有必要的幾何、材料屬性、網(wǎng)格劃分、邊界條件和載荷。例如,假設(shè)我們正在設(shè)計一個簡單的懸臂梁,其長度為1米,寬度和高度為0.1米,材料為鋼,彈性模量為200GPa,泊松比為0.3。

```markdown

###模型參數(shù)

-長度:1米

-寬度:0.1米

-高度:0.1米

-材料:鋼

-彈性模量:200GPa

-泊松比:0.3在MSCNastran中,我們可以通過定義GRID(節(jié)點)、CQUAD4(四邊形殼單元)、MAT1(材料屬性)等卡片來創(chuàng)建這個模型。1.42定義設(shè)計變量設(shè)計變量是優(yōu)化過程中可以改變的參數(shù),它們直接影響結(jié)構(gòu)的性能。在懸臂梁的例子中,我們可以選擇寬度和高度作為設(shè)計變量,以尋找最佳的尺寸配置,同時滿足特定的約束條件。###設(shè)計變量

-寬度(W)

-高度(H)在MSCNastran中,設(shè)計變量通過DESVAR卡片定義。例如:$定義設(shè)計變量

DESVAR,1,W,0.1,0.05,0.2

DESVAR,2,H,0.1,0.05,0.2這里,DESVAR,1,W,0.1,0.05,0.2表示設(shè)計變量1是寬度W,其初始值為0.1米,下限為0.05米,上限為0.2米。1.53設(shè)置目標(biāo)函數(shù)與約束條件目標(biāo)函數(shù)是優(yōu)化過程中的主要目標(biāo),而約束條件則限制了設(shè)計變量的可行范圍。對于懸臂梁,我們可能希望最小化其重量,同時確保其最大位移不超過某個閾值,例如0.01米。###目標(biāo)函數(shù)

-最小化重量

###約束條件

-最大位移不超過0.01米在MSCNastran中,目標(biāo)函數(shù)和約束條件通過OBJFC和OBJFLD卡片定義,約束條件則通過CONM2或SPCADD卡片設(shè)置。例如:$設(shè)置目標(biāo)函數(shù)

OBJFC,1,WEIGHT

$設(shè)置約束條件

CONM2,1,DISPLACEMENT,0.01這里,OBJFC,1,WEIGHT表示目標(biāo)函數(shù)是結(jié)構(gòu)的重量,而CONM2,1,DISPLACEMENT,0.01則定義了一個約束,即最大位移不能超過0.01米。1.64選擇優(yōu)化算法MSCNastran提供了多種優(yōu)化算法,包括梯度法、遺傳算法、模擬退火等。選擇哪種算法取決于問題的復(fù)雜性和所需的優(yōu)化精度。對于懸臂梁的優(yōu)化,我們可能選擇梯度法,因為它在處理連續(xù)設(shè)計變量時效率較高。###優(yōu)化算法

-梯度法在MSCNastran中,優(yōu)化算法通過OPTPRM卡片選擇。例如:$選擇優(yōu)化算法

OPTPRM,GRADIENT,1這里,OPTPRM,GRADIENT,1選擇了梯度法作為優(yōu)化算法。1.75運行優(yōu)化并分析結(jié)果一旦模型、設(shè)計變量、目標(biāo)函數(shù)、約束條件和優(yōu)化算法都已定義,就可以運行優(yōu)化過程了。在MSCNastran中,這通常通過提交一個包含所有必要卡片的輸入文件來完成。###運行優(yōu)化

-提交包含所有卡片的輸入文件優(yōu)化完成后,結(jié)果將包含在輸出文件中,可以使用MSCNastran的后處理器或第三方軟件進行分析。結(jié)果分析應(yīng)關(guān)注設(shè)計變量的最終值、目標(biāo)函數(shù)的最小化程度以及所有約束條件是否得到滿足。###分析結(jié)果

-查看設(shè)計變量的最終值

-確認目標(biāo)函數(shù)是否達到最小

-驗證約束條件是否滿足例如,優(yōu)化結(jié)果可能顯示寬度和高度的最佳值分別為0.12米和0.15米,結(jié)構(gòu)的重量減少了10%,并且最大位移為0.009米,滿足了約束條件。通過以上步驟,可以使用MSCNastran進行結(jié)構(gòu)的優(yōu)化設(shè)計,以找到在滿足特定約束條件下的最佳設(shè)計。2設(shè)計變量與約束條件2.11設(shè)計變量的選擇與定義在結(jié)構(gòu)優(yōu)化設(shè)計中,設(shè)計變量是優(yōu)化過程中的可變參數(shù),它們可以是幾何尺寸、材料屬性、載荷分布等。正確選擇和定義設(shè)計變量是優(yōu)化設(shè)計成功的關(guān)鍵。設(shè)計變量的選擇應(yīng)基于設(shè)計目標(biāo)和結(jié)構(gòu)特性,確保優(yōu)化過程的可行性和效率。2.1.1選擇設(shè)計變量幾何尺寸:如厚度、直徑、長度等,適用于形狀優(yōu)化。材料屬性:如彈性模量、密度等,適用于材料優(yōu)化。載荷分布:如力的大小、方向等,適用于載荷優(yōu)化。2.1.2定義設(shè)計變量在MSCNastran中,設(shè)計變量通過DESVAR卡片定義,格式如下:DESVARIDLABELXINITXLBXUBDXMINDXMAXDMINDMAXNDIMID:設(shè)計變量的唯一標(biāo)識符。LABEL:設(shè)計變量的描述性標(biāo)簽。XINIT:初始設(shè)計變量值。XLB:設(shè)計變量的下限。XUB:設(shè)計變量的上限。DXMIN:設(shè)計變量的最小變化量。DXMAX:設(shè)計變量的最大變化量。DMIN:設(shè)計變量的最小值。DMAX:設(shè)計變量的最大值。NDIM:設(shè)計變量的維度,通常為1。2.1.3示例假設(shè)我們正在優(yōu)化一個梁的厚度,初始厚度為10mm,允許變化范圍為5mm到20mm,最小變化量為0.1mm,最大變化量為5mm。DESVAR1THICKNESS10.05.020.00.15.05.020.012.22約束條件的設(shè)定約束條件限制了設(shè)計變量的可行域,確保設(shè)計滿足特定的性能或規(guī)范要求。在MSCNastran中,約束條件通過DCONSTR、DCONADD、DRESP1、DRESP2等卡片定義。2.2.1DCONSTR卡片用于定義單一的約束條件,格式如下:DCONSTRIDCIDLABELRTYPERIDVALUEID:約束的唯一標(biāo)識符。CID:與設(shè)計變量關(guān)聯(lián)的約束集標(biāo)識符。LABEL:約束的描述性標(biāo)簽。RTYPE:約束類型,如WEIGHT(重量)、DISP(位移)等。RID:響應(yīng)標(biāo)識符,與DRESP1或DRESP2卡片關(guān)聯(lián)。VALUE:約束的閾值。2.2.2示例假設(shè)我們希望梁的重量不超過10kg,可以定義如下約束:DRESP11WEIGHT1

DCONSTR11MAX_WEIGHTWEIGHT110.02.33設(shè)計變量與約束條件的相互作用設(shè)計變量與約束條件之間的相互作用是優(yōu)化設(shè)計的核心。優(yōu)化算法通過調(diào)整設(shè)計變量,尋找滿足所有約束條件的最優(yōu)解。在MSCNastran中,設(shè)計變量和約束條件通過DRESP1、DRESP2、DCONADD等卡片關(guān)聯(lián),形成優(yōu)化問題的數(shù)學(xué)模型。2.3.1DCONADD卡片用于將多個約束條件組合成一個約束集,格式如下:DCONADDCIDCID1CID2...CIDnCID:約束集的標(biāo)識符。CID1,CID2,…,CIDn:要組合的約束條件標(biāo)識符。2.3.2示例假設(shè)我們有以下兩個約束條件:梁的重量不超過10kg。梁的最大位移不超過5mm。我們可以將這兩個約束條件組合成一個約束集:DRESP11WEIGHT1

DRESP12DISP1

DCONSTR11MAX_WEIGHTWEIGHT110.0

DCONSTR22MAX_DISPDISP15.0

DCONADD112在這個例子中,DCONADD卡片將DCONSTR卡片定義的兩個約束條件組合成一個約束集,確保優(yōu)化過程同時滿足重量和位移的約束。通過上述設(shè)計變量和約束條件的定義與組合,我們可以構(gòu)建一個完整的優(yōu)化問題模型,利用MSCNastran的優(yōu)化算法求解,以達到設(shè)計目標(biāo)。3目標(biāo)函數(shù)的設(shè)定3.11目標(biāo)函數(shù)的類型在優(yōu)化設(shè)計中,目標(biāo)函數(shù)是衡量設(shè)計優(yōu)劣的關(guān)鍵指標(biāo)。它反映了設(shè)計目標(biāo)的數(shù)學(xué)表達,可以是單個量或多個量的組合。在MSCNastran中,目標(biāo)函數(shù)的類型主要包括:質(zhì)量最小化:在滿足所有約束條件下,尋找使結(jié)構(gòu)質(zhì)量最小的設(shè)計。剛度最大化:優(yōu)化結(jié)構(gòu)的剛度,使其在給定載荷下變形最小。頻率優(yōu)化:調(diào)整結(jié)構(gòu)的固有頻率,避免與工作環(huán)境中的激勵頻率重合,減少共振風(fēng)險。模態(tài)優(yōu)化:優(yōu)化結(jié)構(gòu)的模態(tài)特性,如模態(tài)質(zhì)量、模態(tài)剛度等。應(yīng)力優(yōu)化:控制結(jié)構(gòu)中的應(yīng)力水平,避免過高的應(yīng)力導(dǎo)致材料疲勞或破壞。位移優(yōu)化:限制結(jié)構(gòu)在特定載荷下的最大位移,確保結(jié)構(gòu)的穩(wěn)定性。3.22目標(biāo)函數(shù)的定義方法在MSCNastran中,目標(biāo)函數(shù)的定義通常通過OptiStruct模塊實現(xiàn)。OptiStruct提供了靈活的接口,允許用戶定義復(fù)雜的目標(biāo)函數(shù)。定義方法包括:3.2.1通過響應(yīng)變量定義響應(yīng)變量(RESPONSE)是OptiStruct中用于定義目標(biāo)函數(shù)和約束的基本單元。例如,定義結(jié)構(gòu)的質(zhì)量最小化目標(biāo)函數(shù),可以使用如下代碼:BEGINBULK

$Definetheresponsevariableformass

SPCADD=1

$Massresponse

RSTADD=1

RESP1,1,RSTADD,MASS,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

#五、優(yōu)化算法的選擇

##5.1優(yōu)化算法的分類

優(yōu)化算法在工程設(shè)計中扮演著關(guān)鍵角色,特別是在使用如MSCNastran這樣的軟件進行結(jié)構(gòu)優(yōu)化時。這些算法可以大致分為兩大類:**確定性算法**和**隨機性算法**。

-**確定性算法**:這類算法在給定相同的初始條件時,每次運行都會得到相同的結(jié)果。它們通?;谔荻刃畔?,如梯度下降法、牛頓法等,適用于目標(biāo)函數(shù)和約束條件可微的情況。

-**隨機性算法**:這類算法引入了隨機性,使得每次運行可能得到不同的結(jié)果。它們適用于目標(biāo)函數(shù)和約束條件不可微或復(fù)雜的情況,如遺傳算法、粒子群優(yōu)化算法等。

##5.2常用優(yōu)化算法介紹

###5.2.1梯度下降法

梯度下降法是一種迭代優(yōu)化算法,用于尋找函數(shù)的局部最小值。它通過計算目標(biāo)函數(shù)的梯度(即導(dǎo)數(shù)),然后沿著梯度的反方向更新參數(shù),以逐步減小函數(shù)值。

**示例代碼**:

```python

importnumpyasnp

defgradient_descent(f,df,x0,learning_rate,num_iters):

"""

梯度下降法優(yōu)化示例

參數(shù):

f:目標(biāo)函數(shù)

df:目標(biāo)函數(shù)的梯度

x0:初始參數(shù)

learning_rate:學(xué)習(xí)率

num_iters:迭代次數(shù)

返回:

x:最終參數(shù)

"""

x=x0

foriinrange(num_iters):

gradient=df(x)

x-=learning_rate*gradient

returnx

#定義目標(biāo)函數(shù)和其梯度

deff(x):

returnx**2+2*x+1

defdf(x):

return2*x+2

#設(shè)置初始參數(shù)和學(xué)習(xí)率

x0=5

learning_rate=0.1

num_iters=100

#運行梯度下降法

x=gradient_descent(f,df,x0,learning_rate,num_iters)

print("最小值點:",x)3.2.22.2遺傳算法遺傳算法是一種基于自然選擇和遺傳學(xué)原理的搜索算法,適用于解決復(fù)雜優(yōu)化問題。它通過模擬生物進化過程,包括選擇、交叉和變異,來尋找最優(yōu)解。示例代碼:importrandom

defgenetic_algorithm(fitness_func,population_size,num_generations,mutation_rate):

"""

遺傳算法優(yōu)化示例

參數(shù):

fitness_func:適應(yīng)度函數(shù)

population_size:種群大小

num_generations:進化代數(shù)

mutation_rate:變異率

返回:

best_individual:最優(yōu)個體

"""

#初始化種群

population=[random.randint(-10,10)for_inrange(population_size)]

for_inrange(num_generations):

#計算適應(yīng)度

fitnesses=[fitness_func(individual)forindividualinpopulation]

#選擇

selected=[random.choices(population,weights=fitnesses,k=2)

for_inrange(population_size//2)]

#交叉

offspring=[]

forparentsinselected:

crossover_point=random.randint(0,len(parents[0]))

offspring.append(parents[0][:crossover_point]+parents[1][crossover_point:])

#變異

forindividualinoffspring:

ifrandom.random()<mutation_rate:

individual[random.randint(0,len(individual)-1)]=random.randint(-10,10)

#更新種群

population=offspring+[max(population,key=fitness_func)]

#返回最優(yōu)個體

best_individual=max(population,key=fitness_func)

returnbest_individual

#定義適應(yīng)度函數(shù)

deffitness_func(x):

return-(x**2+2*x+1)

#設(shè)置遺傳算法參數(shù)

population_size=50

num_generations=100

mutation_rate=0.1

#運行遺傳算法

best_individual=genetic_algorithm(fitness_func,population_size,num_generations,mutation_rate)

print("最優(yōu)解:",best_individual)3.2.32.3粒子群優(yōu)化算法粒子群優(yōu)化算法(PSO)是一種基于群體智能的優(yōu)化算法,模擬了鳥群覓食的行為。每個粒子在搜索空間中尋找最優(yōu)解,通過粒子之間的信息交流來更新自己的位置和速度。示例代碼:importnumpyasnp

defpso(fitness_func,num_particles,num_iterations,search_space):

"""

粒子群優(yōu)化算法示例

參數(shù):

fitness_func:適應(yīng)度函數(shù)

num_particles:粒子數(shù)量

num_iterations:迭代次數(shù)

search_space:搜索空間

返回:

best_position:最優(yōu)位置

"""

#初始化粒子群

positions=np.random.uniform(search_space[0],search_space[1],num_particles)

velocities=np.zeros(num_particles)

personal_best=positions.copy()

global_best=positions[np.argmax([fitness_func(pos)forposinpositions])]

for_inrange(num_iterations):

#更新速度

r1,r2=np.random.rand(),np.random.rand()

velocities=0.5*velocities+2.0*r1*(personal_best-positions)+2.0*r2*(global_best-positions)

#更新位置

positions+=velocities

#更新個人最優(yōu)和全局最優(yōu)

foriinrange(num_particles):

iffitness_func(positions[i])>fitness_func(personal_best[i]):

personal_best[i]=positions[i]

iffitness_func(personal_best[i])>fitness_func(global_best):

global_best=personal_best[i]

returnglobal_best

#定義適應(yīng)度函數(shù)

deffitness_func(x):

return-(x**2+2*x+1)

#設(shè)置PSO參數(shù)

num_particles=50

num_iterations=100

search_space=(-10,10)

#運行PSO

best_position=pso(fitness_func,num_particles,num_iterations,search_space)

print("最優(yōu)位置:",best_position)3.33算法選擇的考量因素選擇優(yōu)化算法時,應(yīng)考慮以下因素:問題的特性:目標(biāo)函數(shù)是否可微?約束條件是否復(fù)雜?問題的維度和規(guī)模如何?計算資源:算法的計算復(fù)雜度和內(nèi)存需求是否在可接受范圍內(nèi)?收斂速度:算法是否能在合理的時間內(nèi)收斂到滿意解?解的穩(wěn)定性:算法是否容易受初始條件影響?是否能穩(wěn)定地找到全局最優(yōu)解或接近最優(yōu)解?可調(diào)參數(shù):算法的參數(shù)是否容易調(diào)整以適應(yīng)特定問題?在實際應(yīng)用中,可能需要嘗試多種算法,結(jié)合問題的具體情況,選擇最適合的優(yōu)化方法。4優(yōu)化設(shè)計案例分析4.11案例一:結(jié)構(gòu)重量最小化在工程設(shè)計中,結(jié)構(gòu)重量最小化是一個常見的優(yōu)化目標(biāo),尤其是在航空航天、汽車和機械工程領(lǐng)域。使用MSCNastran進行結(jié)構(gòu)重量最小化設(shè)計,可以通過調(diào)整設(shè)計變量(如材料厚度、截面尺寸等)來達到在滿足所有約束條件(如應(yīng)力、位移、模態(tài)頻率等)的情況下,使結(jié)構(gòu)重量達到最小的目的。4.1.1原理結(jié)構(gòu)重量最小化設(shè)計通?;谕負鋬?yōu)化、尺寸優(yōu)化或形狀優(yōu)化。在MSCNastran中,可以使用優(yōu)化模塊(如OptiStruct)來實現(xiàn)這一目標(biāo)。OptiStruct采用先進的優(yōu)化算法,如序列二次規(guī)劃(SQP)和遺傳算法(GA),來迭代求解最優(yōu)設(shè)計。4.1.2內(nèi)容定義設(shè)計變量:在Nastran中,設(shè)計變量可以是材料屬性、截面尺寸、厚度等。例如,對于一個由多個板組成的結(jié)構(gòu),設(shè)計變量可以是每個板的厚度。設(shè)定目標(biāo)函數(shù):目標(biāo)函數(shù)是結(jié)構(gòu)重量,通常表示為所有設(shè)計變量的函數(shù)。定義約束條件:約束條件包括應(yīng)力約束、位移約束、模態(tài)頻率約束等。例如,結(jié)構(gòu)在特定載荷下的最大應(yīng)力不能超過材料的許用應(yīng)力。選擇優(yōu)化算法:在Nastran中,可以選擇不同的優(yōu)化算法,如SQP或GA,每種算法都有其適用場景和優(yōu)缺點。執(zhí)行優(yōu)化:通過Nastran的優(yōu)化模塊,設(shè)置好設(shè)計變量、目標(biāo)函數(shù)和約束條件后,運行優(yōu)化求解器,迭代求解最優(yōu)設(shè)計。結(jié)果分析:優(yōu)化完成后,分析優(yōu)化結(jié)果,包括結(jié)構(gòu)重量、應(yīng)力分布、位移情況等,確保優(yōu)化設(shè)計滿足所有工程要求。4.1.3示例假設(shè)我們有一個由多個板組成的結(jié)構(gòu),目標(biāo)是最小化結(jié)構(gòu)重量,同時確保最大應(yīng)力不超過材料的許用應(yīng)力。設(shè)計變量是每個板的厚度,目標(biāo)函數(shù)是所有板的重量之和,約束條件是最大應(yīng)力。#MSCNastran優(yōu)化設(shè)計示例:結(jié)構(gòu)重量最小化

#導(dǎo)入必要的庫

importnumpyasnp

frompyNastran.bdf.bdfimportread_bdf

frompyNastran.op2.op2importread_op2

frompyNastran.optimization.optimizationimportOptimization

#讀取Nastran模型

model=read_bdf('structure.bdf')

#定義設(shè)計變量

design_variables=perties.keys()

#定義目標(biāo)函數(shù):結(jié)構(gòu)重量

defobjective_function(thicknesses):

total_weight=0

fori,propinenumerate(perties.values()):

prop.thickness=thicknesses[i]

total_weight+=prop.material.density*prop.area*prop.length

returntotal_weight

#定義約束條件:最大應(yīng)力

defconstraint_stress(thicknesses):

model.update_properties(thicknesses)

model.run('analysis.nastran')

results=read_op2('analysis.op2')

max_stress=np.max(results.stress)

returnmax_stress-material_yield_strength

#創(chuàng)建優(yōu)化對象

opt=Optimization(model,design_variables,objective_function,constraint_stress)

#設(shè)置優(yōu)化參數(shù)

opt.set_bounds([0.1,0.2,0.3],[0.5,0.6,0.7])

opt.set_initial_guess([0.2,0.3,0.4])

#執(zhí)行優(yōu)化

opt.run()

#輸出優(yōu)化結(jié)果

print('Optimizedthicknesses:',opt.optimized_design)

print('Optimizedweight:',opt.optimized_objective)在上述示例中,我們首先讀取了一個Nastran模型,然后定義了設(shè)計變量(板的厚度)、目標(biāo)函數(shù)(結(jié)構(gòu)重量)和約束條件(最大應(yīng)力)。通過Optimization類,我們設(shè)置了優(yōu)化的上下界和初始猜測值,然后運行優(yōu)化求解器。最后,我們輸出了優(yōu)化后的設(shè)計變量和目標(biāo)函數(shù)值。4.22案例二:模態(tài)頻率優(yōu)化模態(tài)頻率優(yōu)化是調(diào)整結(jié)構(gòu)的動態(tài)特性,以避免共振或提高結(jié)構(gòu)的動態(tài)響應(yīng)。在MSCNastran中,可以通過調(diào)整設(shè)計變量來優(yōu)化模態(tài)頻率,確保結(jié)構(gòu)在特定頻率范圍內(nèi)具有良好的動態(tài)性能。4.2.1原理模態(tài)頻率優(yōu)化通常基于模態(tài)分析,通過調(diào)整設(shè)計變量來改變結(jié)構(gòu)的模態(tài)頻率,使其避開特定的頻率范圍或達到目標(biāo)頻率。在Nastran中,可以使用模態(tài)分析結(jié)果作為約束條件,結(jié)合優(yōu)化算法來求解最優(yōu)設(shè)計。4.2.2內(nèi)容定義設(shè)計變量:設(shè)計變量可以是材料屬性、截面尺寸、厚度等。設(shè)定目標(biāo)函數(shù):目標(biāo)函數(shù)可以是使模態(tài)頻率達到目標(biāo)值或使模態(tài)頻率避開特定頻率范圍。定義約束條件:約束條件包括模態(tài)頻率、結(jié)構(gòu)重量、應(yīng)力等。選擇優(yōu)化算法:選擇適合模態(tài)頻率優(yōu)化的算法,如SQP或GA。執(zhí)行優(yōu)化:設(shè)置好設(shè)計變量、目標(biāo)函數(shù)和約束條件后,運行優(yōu)化求解器。結(jié)果分析:分析優(yōu)化結(jié)果,包括模態(tài)頻率、結(jié)構(gòu)重量、應(yīng)力分布等,確保優(yōu)化設(shè)計滿足所有工程要求。4.2.3示例假設(shè)我們有一個結(jié)構(gòu),目標(biāo)是優(yōu)化其第一階模態(tài)頻率,使其避開特定的頻率范圍(如100Hz至120Hz)。設(shè)計變量是結(jié)構(gòu)的材料密度,目標(biāo)函數(shù)是第一階模態(tài)頻率,約束條件是結(jié)構(gòu)重量。#MSCNastran優(yōu)化設(shè)計示例:模態(tài)頻率優(yōu)化

#導(dǎo)入必要的庫

importnumpyasnp

frompyNastran.bdf.bdfimportread_bdf

frompyNastran.op2.op2importread_op2

frompyNastran.optimization.optimizationimportOptimization

#讀取Nastran模型

model=read_bdf('structure.bdf')

#定義設(shè)計變量

design_variables=model.materials.keys()

#定義目標(biāo)函數(shù):第一階模態(tài)頻率

defobjective_function(densities):

fori,matinenumerate(model.materials.values()):

mat.density=densities[i]

model.run('analysis.nastran')

results=read_op2('analysis.op2')

returnresults.modal_frequencies[0]

#定義約束條件:結(jié)構(gòu)重量

defconstraint_weight(densities):

total_weight=0

fori,matinenumerate(model.materials.values()):

total_weight+=mat.density*mat.volume

returntotal_weight-max_weight

#創(chuàng)建優(yōu)化對象

opt=Optimization(model,design_variables,objective_function,constraint_weight)

#設(shè)置優(yōu)化參數(shù)

opt.set_bounds([2.5e3,2.6e3,2.7e3],[3.0e3,3.1e3,3.2e3])

opt.set_initial_guess([2.8e3,2.9e3,3.0e3])

#執(zhí)行優(yōu)化

opt.run()

#輸出優(yōu)化結(jié)果

print('Optimizeddensities:',opt.optimized_design)

print('Optimizedmodalfrequency:',opt.optimized_objective)在上述示例中,我們定義了設(shè)計變量(材料密度)、目標(biāo)函數(shù)(第一階模態(tài)頻率)和約束條件(結(jié)構(gòu)重量)。通過Optimization類,我們設(shè)置了優(yōu)化的上下界和初始猜測值,然后運行優(yōu)化求解器。最后,我們輸出了優(yōu)化后的設(shè)計變量和目標(biāo)函數(shù)值。4.33案例三:熱應(yīng)力分析優(yōu)化熱應(yīng)力分析優(yōu)化是調(diào)整結(jié)構(gòu)在溫度變化下的應(yīng)力分布,以避免熱應(yīng)力引起的結(jié)構(gòu)損傷。在MSCNastran中,可以通過調(diào)整設(shè)計變量來優(yōu)化熱應(yīng)力,確保結(jié)構(gòu)在溫度變化下具有良好的應(yīng)力分布。4.3.1原理熱應(yīng)力分析優(yōu)化基于熱力學(xué)和結(jié)構(gòu)力學(xué)的結(jié)合,通過調(diào)整設(shè)計變量(如材料熱膨脹系數(shù)、截面尺寸等)來改變結(jié)構(gòu)在溫度變化下的應(yīng)力分布。在Nastran中,可以使用熱應(yīng)力分析結(jié)果作為約束條件,結(jié)合優(yōu)化算法來求解最優(yōu)設(shè)計。4.3.2內(nèi)容定義設(shè)計變量:設(shè)計變量可以是材料熱膨脹系數(shù)、截面尺寸、厚度等。設(shè)定目標(biāo)函數(shù):目標(biāo)函數(shù)可以是使熱應(yīng)力達到最小值或使熱應(yīng)力分布均勻。定義約束條件:約束條件包括熱應(yīng)力、結(jié)構(gòu)重量、模態(tài)頻率等。選擇優(yōu)化算法:選擇適合熱應(yīng)力分析優(yōu)化的算法,如SQP或GA。執(zhí)行優(yōu)化:設(shè)置好設(shè)計變量、目標(biāo)函數(shù)和約束條件后,運行優(yōu)化求解器。結(jié)果分析:分析優(yōu)化結(jié)果,包括熱應(yīng)力、結(jié)構(gòu)重量、模態(tài)頻率等,確保優(yōu)化設(shè)計滿足所有工程要求。4.3.3示例假設(shè)我們有一個結(jié)構(gòu),目標(biāo)是優(yōu)化其在溫度變化下的熱應(yīng)力,使其達到最小值。設(shè)計變量是材料的熱膨脹系數(shù),目標(biāo)函數(shù)是熱應(yīng)力,約束條件是結(jié)構(gòu)重量。#MSCNastran優(yōu)化設(shè)計示例:熱應(yīng)力分析優(yōu)化

#導(dǎo)入必要的庫

importnumpyasnp

frompyNastran.bdf.bdfimportread_bdf

frompyNastran.op2.op2importread_op2

frompyNastran.optimization.optimizationimportOptimization

#讀取Nastran模型

model=read_bdf('structure.bdf')

#定義設(shè)計變量

design_variables=model.materials.keys()

#定義目標(biāo)函數(shù):熱應(yīng)力

defobjective_function(thermal_expansion):

fori,matinenumerate(model.materials.values()):

mat.thermal_expansion=thermal_expansion[i]

model.run('analysis.nastran')

results=read_op2('analysis.op2')

returnnp.max(results.thermal_stress)

#定義約束條件:結(jié)構(gòu)重量

defconstraint_weight(thermal_expansion):

total_weight=0

fori,matinenumerate(model.materials.values()):

total_weight+=mat.density*mat.volume

returntotal_weight-max_weight

#創(chuàng)建優(yōu)化對象

opt=Optimization(model,design_variables,objective_function,constraint_weight)

#設(shè)置優(yōu)化參數(shù)

opt.set_bounds([1.0e-6,1.1e-6,1.2e-6],[1.5e-6,1.6e-6,1.7e-6])

opt.set_initial_guess([1.3e-6,1.4e-6,1.5e-6])

#執(zhí)行優(yōu)化

opt.run()

#輸出優(yōu)化結(jié)果

print('Optimizedthermalexpansioncoefficients:',opt.optimized_design)

print('Optimizedthermalstress:',opt.optimized_objective)在上述示例中,我們定義了設(shè)計變量(材料熱膨脹系數(shù))、目標(biāo)函數(shù)(熱應(yīng)力)和約束條件(結(jié)構(gòu)重量)。通過Optimization類,我們設(shè)置了優(yōu)化的上下界和初始猜測值,然后運行優(yōu)化求解器。最后,我們輸出了優(yōu)化后的設(shè)計變量和目標(biāo)函數(shù)值。5優(yōu)化設(shè)計的高級技巧5.11設(shè)計空間探索設(shè)計空間探索(DesignSpaceExploration,DSE)是優(yōu)化設(shè)計中一個關(guān)鍵步驟,它涉及到對設(shè)計變量的可能組合進行系統(tǒng)性地調(diào)查,以理解設(shè)計空間的特性并識別出潛在的優(yōu)化區(qū)域。在MSCNastran中,DSE可以通過多種方法實現(xiàn),包括但不限于參數(shù)研究、設(shè)計點生成和響應(yīng)面方法。5.1.1參數(shù)研究參數(shù)研究是一種基本的DSE方法,通過改變設(shè)計變量的值,觀察模型響應(yīng)的變化。例如,考慮一個簡單的彈簧模型,其中彈簧的剛度(k)和質(zhì)量(m)是設(shè)計變量,而振動頻率(f)是響應(yīng)。我們可以創(chuàng)建一個參數(shù)研究,改變k和m的值,記錄f的變化,以找到最佳的k和m組合。#Python示例代碼:使用PyNastran進行參數(shù)研究

frompyNastran.bdf.bdfimportBDF

frompyNastran.op2.op2importOP2

importnumpyasnp

#創(chuàng)建BDF模型

model=BDF()

#定義設(shè)計變量

k_values=np.linspace(100,1000,10)

m_values=np.linspace(1,10,10)

#進行參數(shù)研究

forkink_values:

forminm_values:

#更新模型中的彈簧剛度和質(zhì)量

model.update_spring(k)

model.update_mass(m)

#運行分析

model.run_analysis()

#讀取結(jié)果

op2=OP2()

op2.read_op2('output.op2')

f=op2.get_vibration_frequency()

#打印結(jié)果

print(f'k={k},m={m},f={f}')5.1.2設(shè)計點生成設(shè)計點生成是另一種DSE方法,它通過在設(shè)計空間中隨機或系統(tǒng)地生成設(shè)計點,來評估模型的性能。設(shè)計點可以是基于拉丁超立方抽樣(LatinHypercubeSampling,LHS)或全因子設(shè)計(FullFactorialDesign)等方法生成的。5.1.3響應(yīng)面方法響應(yīng)面方法(ResponseSurfaceMethodology,RSM)是一種統(tǒng)計方法,用于構(gòu)建設(shè)計變量與響應(yīng)之間的近似模型。通過在設(shè)計空間中選擇少量的點進行分析,然后使用這些點的數(shù)據(jù)來擬合一個響應(yīng)面,可以快速預(yù)測設(shè)計空間中其他點的響應(yīng)。5.22敏感性分析敏感性分析(SensitivityAnalysis)用于評估設(shè)計變量對模型響應(yīng)的影響程度。在MSCNastran中,可以通過直接求導(dǎo)或使用有限差分方法來計算敏感度。5.2.1直接求導(dǎo)直接求導(dǎo)方法在求解過程中直接計算設(shè)計變量的敏感度,這種方法通常更準(zhǔn)確但計算成本較高。5.2.2有限差分方法有限差分方法通過在設(shè)計變量上施加微小的擾動,然后比較響應(yīng)的變化來估計敏感度。這種方法計算成本較低,但可能受到數(shù)值誤差的影響。#Python示例代碼:使用有限差分方法進行敏感性分析

frompyNastran.bdf.bdfimportBDF

frompyNastran.op2.op2importOP2

importnumpyasnp

#創(chuàng)建BDF模型

model=BDF()

#定義設(shè)計變量和響應(yīng)

k=500

m=5

f=model.get_vibration_frequency()

#定義擾動大小

delta=1e-6

#計算k的敏感度

model.update_spring(k+delta)

f_k_plus=model.get_vibration_frequency()

model.update_spring(k-delta)

f_k_minus=model.get_vibration_frequency()

sensitivity_k=(f_k_plus-f_k_minus)/(2*delta)

#計算m的敏感度

model.update_mass(m+delta)

f_m_plus=model.get_vibration_frequency()

model.update_mass(m-delta)

f_m_minus=model.get_vibration_frequency()

sensitivity_m=(f_m_plus-f_m_minus)/(2*delta)

#打印敏感度結(jié)果

print(f'Sensitivityofk:{sensitivity_k}')

print(f'Sensitivityofm:{sensitivity_m}')5.33多學(xué)科優(yōu)化設(shè)計多學(xué)科優(yōu)化設(shè)計(Multi-DisciplinaryOptimization,MDO)涉及在多個工程學(xué)科之間進行協(xié)調(diào),以找到滿足所有學(xué)科要求的最優(yōu)設(shè)計。在MSCNastran中,MDO可以通過集成不同的分析模塊(如結(jié)構(gòu)、熱、流體等)來實現(xiàn),以確保設(shè)計在所有相關(guān)領(lǐng)域都是最優(yōu)的。5.3.1MDO的策略MDO的策略包括:-獨立學(xué)科和協(xié)同優(yōu)化(IDF):每個學(xué)科獨立優(yōu)化,然后通過迭代來協(xié)調(diào)學(xué)科之間的沖突。-協(xié)同學(xué)科優(yōu)化(CDO):所有學(xué)科同時優(yōu)化,通過一個中心優(yōu)化器來協(xié)調(diào)。-學(xué)科系統(tǒng)協(xié)同(DSA):學(xué)科之間通過系統(tǒng)級的優(yōu)化器進行交互,以找到全局最優(yōu)解。5.3.2MDO的實施在實施MDO時,需要定義每個學(xué)科的模型、目標(biāo)函數(shù)和約束條件。然后,選擇一個合適的MDO策略,并使用優(yōu)化算法來尋找滿足所有學(xué)科要求的最優(yōu)設(shè)計。#Python示例代碼:

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論