找回密码
 注册
Simdroid-非首页
查看: 57|回复: 0

[基础知识] Adams中振动后台运行

[复制链接]
发表于 2014-7-30 09:42:08 | 显示全部楼层 |阅读模式 来自 中国
Adams中振动后台运行


本文主要说明利用Adams/Vibration模块在频域范围内进行后台分析,在这实际工程中有一定的应用。要完成这一分析流程,需要借助Python编译环境,Python作为一款应用广泛的编程软件,在很多工程仿真软件上都有其拓展应用的身影。
基本步骤:
l  利用Adams创建振动分析用的模型,并以Adm方式保存,还需要有控制仿真过程的脚本文件,即Acf文件;
l  利用Adams与Python的接口功能定义激励信号,输入通道,输出通道;
l  利用Adams与Python的接口功能定义输出,将线性系统的频响特性保存在Xml文件中,同时生成Cmd文件用于Adams后处理;
具体执行过程如下:
第一,启动cmd命令窗口,并将工作路径指定到相关位置:C:\Users\cnzc8469\Desktop\batch。

   点击回车后会产生如下变化,但最关键的是如下文件的生成:


       这里面关键的设置在Python脚本文件中,需要工程师首先熟悉Python的语法格式以及同Adams相关的API,可以参考帮助下的Testing your model章节,又详细地接口函数说明。
frommsc.ADAMS.Vibration.AvActuator import *
frommsc.ADAMS.Vibration.AvOutputChannel import *
frommsc.ADAMS.Vibration.AvInputChannel  import *
frommsc.ADAMS.Vibration.AvLinearize     import *
frommsc.ADAMS.Vibration.AvUtils         import *
fromAvPPTCmdExporter import *
############################################这一部分相当于Include包含文件功能
defmessage_handler(msg, type, data):
  """Message handler forvibration"""
  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 producelinear model check execution display for errors.")
        AvAPI().PopMessageHandler()
      # 检查口令许可
      AvAPI.ReleaseLicense()
    else:
      logFile.write("Could not getADAMS/Vibration Solver license")
  except Exception:
    formatExceptionInfo(logFile)
    最后,可以直接打开Adams后处理界面,将生成的CMD文件导入,查看相关信息,如频响等内容。


您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-9-23 20:16 , Processed in 0.027103 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表