本文主要说明利用Adams/Vibration模块在频域范围内进行后台分析,这在实际工程中有一定的应用。要完成这一分析流程,需要借助Python编译环境,Python作为一款应用广泛的编程软件,在很多工程仿真软件上都有其拓展应用的身影。
基本步骤:
1.利用Adams创建振动分析用的模型,并以Adm方式保存,还需要有控制仿真过程的脚本文件,即Acf文件;
2.利用Adams与Python的接口功能定义激励信号,输入通道,输出通道;
3.利用Adams与Python的接口功能定义输出,将线性系统的频响特性保存在Xml文件中,同时生成Cmd文件用于Adams后处理;
具体执行过程如下:
第一,启动cmd命令窗口,并将工作路径指定到相关位置:C:\Users\cnzc8469\Desktop\batch。
点击回车后会产生如下变化,但最关键的是如下文件的生成:
这里面关键的设置在Python脚本文件中,需要工程师首先熟悉Python的语法格式以及同Adams相关的API,可以参考帮助下的Testing your model章节,有详细地接口函数说明。
from msc.ADAMS.Vibration.AvActuator import *
from msc.ADAMS.Vibration.AvOutputChannel import *
from msc.ADAMS.Vibration.AvInputChannel import *
from msc.ADAMS.Vibration.AvLinearize import *
from msc.ADAMS.Vibration.AvUtils import *
from AvPPTCmdExporter import *
############################################这一部分相当于Include包含文件功能
def message_handler(msg, type, data):
"""Message handler for vibration"""
if type[0] == "i":
print "ADAMS/Vibration Info: %s" % (msg)
elif type[0] == "w":
print "ADAMS/Vibration Warn: %s" % (msg)
else :
print "ADAMS/Vibration Error: %s" % (msg)
if __name__ == '__main__':
# open a log file for logging messages
logFile = open("sla_batch.log", "w")
try:
# Check out the vibration license
vib_ok = AvAPI.AcquireLicense()
if vib_ok:
# set message handler
AvAPI().PushMessageHandler(message_handler, [])
# 创建激励信号
act_vert = AvActuatorSweptSine('SS1', 'Displacement', 5, 0)
#创建输入通道,注意相关参数
InChVert = AvInputChannelMarker("PadDispInput", 114, "Translational", "Global", "Z", act_vert)
inList = [InChVert]
# 创建输出通道
CVA= AvOutputChannelPredefined("ChassisVertAccl", 105, "Acceleration", "Z")
# Measure acceleration at steering rack.
TRA= AvOutputChannelPredefined("TieRodAccl", 100, "Acceleration", "X")
outList = [CVA, TRA]
base_name = "sla_batch"
MDI_CPU = os.environ['MDI_CPU']
TOPDIR = os.environ['topdir']
if MDI_CPU == "win32":
if os.path.isdir(TOPDIR) != 0:
TOPDIR = os.environ['SHORT_TOPDIR']
base_path = TOPDIR+'/vibration/examples/python_batch_analysis/'+base_name
model = base_path+".adm"
acFile = base_path+".acf"
#上面两行读取对应模型与脚本控制命令文件
mList = []
# 创建振动仿真分析参数,如模型名称,频域设定等
Model = AvLinearModel(model, inList, outList, acFile, True, base_name, mList)
if Model:
# set the frequencies
f = AvMakeFrequency(0.1, 250, 500, True)
Freq = AvAPI_Matrix(len(f), f)
# 计算频响
FR = Model.FrequencyResponse(Freq)
# 传递函数
TF = Model.TransferFunction(Freq)
# 将计算结果写入到XML文件中
matFile = open(base_name+".xml", "w")
writeXMLHeader(matFile)
writeMatrixXML(matFile, Freq, "Frequency range" )
writeMatrixXML(matFile, FR, "Frequency Response")
writeMatrixXML(matFile, TF, "Transfer Function" )
writeXMLFooter(matFile)
matFile.close()
# 生成CMD文件用于后处理中
amdModel = AvAMD(model)
pptCmdExporter = VibPPTCmdExporter(".sla_basic", base_name+".cmd", amdModel, inList, outList, 0.1, 250.0, 500, True)
pptCmdExporter.writeCmdForPPT(base_name)
else:
logFile.write("Could not produce linear model check execution display for errors.")
AvAPI().PopMessageHandler()
# 检查口令许可
AvAPI.ReleaseLicense()
else:
logFile.write("Could not get ADAMS/Vibration Solver license")
except Exception:
formatExceptionInfo(logFile)
最后,可以直接打开Adams后处理界面,将生成的CMD文件导入,查看相关信息,如频响等内容。