1.操作系统: Windows xp 32 位
2.软件版本: Adams 2013 32 位、 Visual Studio 2010 专业版 32 位
3.编译软件: Intel Visual Fortran 11.0
4.环境配置:
在操作系统环境变量 Path 中增加 Adams 启动文件 mdi.bat 的路径,如 D:\MSC.Software\Adams\2013\common\mdi.bat
把 Fortran 安装路径,如
D:\IVF2011\Intel\ComposerXE-2011\compiler\lib\ia32
把 libifcoremd.lib 、libifcoremd.lib 、libmmd.lib 、libifportmd.lib 、libirc.lib 、svml_dispmd.lib 这 6 个库文件复制到 Adams 安装路径下 win32 文件夹下
5.编写用户子程序
Adams 安装程序 D:\MSC.Software\Adams\2013\solver\c_usersubs 文件夹下有 C 语言编写 的常用的用户子程序,其中 slv_c_utils.h 文件是用户子程序的头文件。编写用户子程序时, 在这些程序的基础上进行更改会有事半功倍的效果。
本文以编写 VForce 用户子程序为例,对其编写、编译操作过程进行说明。
复制 vfosub.c 和 slv_c_utils.h 两个文件到个人工作文件夹 Adams_Matlab ,本文直接使用 vfosub.c 的原始代码,其代码为:
#include "slv_c_utils.h"
adams_c_Vfosub Vfosub;
/*
* Note:
* Use mixed case names for the Adams subroutine names when using the C
* style interface. For the default subroutine name capitalize the first
* letter and have the remaining letters lower case; Gfosub for example.
* Doing this insures that Adams Solver correctly distinguishes a C style
* subroutine from Fortran and calls with the appropriate interface.
*
*/
void Vfosub( const struct sAdamsVforce* vfo, double time, int dflag, int iflag, double * result)
{
/* Assign readable variable names to passed parameters */
double c=vfo->PAR[0];
int ipar[3]={( int )vfo->PAR[1], ( int )vfo->PAR[2],( int )vfo->PAR[1]};
/* Local variables */
double vel[3];
int nstates;
int errflg;
/* call SYSARY for translation velocities TVEL */
c_sysary( "TVEL", ipar, 3, vel, &nstates, &errflg);
c_errmes(errflg,"Error calling SYSARY for TVEL", vfo->ID, "STOP");
/* --- Evaluate VFORCE components */
result[0] = -c * vel[0];
result[2] = -c * vel[1];
result[2] = -c * vel[2];
}
注意:因为代码中引用了slv_c_utils.h,复制时必须同时复制slv_c_utils.h文件,否则编
译时会报错。
6■编译操作
(1)在开始菜单下,启动Visual Studio 2010命令提示工具。
D:\Adams_Matlab ,(3)输入指令 D:\MSC.Software\Adams\2013\common\mdi.bat 并按回车,(2)把工作路径设置到用户子程序文件所在路径 输入指令
D:\Adams_Matlab ,
(3)输入指令 D:\MSC.Software\Adams\2013\common\mdi.bat 并按回车,
於 Visual Studio 命令提