COMSOL WITH MATLAB的用户名设置问题

本人安装了COMSOL软件,同时使用了LIVE LINK WITH MATLAB接口。但是用户名设置那里因为存在字符串单引符号。需要用双引符号,对整个字符串进行括号。因此,将错误和改正方法列出来,以供后面的学习者提供参考。

java.lang.System.setProperty('cs.root','C:\Program Files\COMSOL\COMSOL60\Multiphysics');java.lang.System.setProperty('cs.prefsdir','C:\Users\xiao'wei\.comsol\v60');java.lang.System.setProperty('cs.apiclient','on');import com.comsol.communication.ClientType;import com.comsol.clientapi.engine.APIEngine;APIEngine.setClientType(ClientType.LLMATLAB);java.lang.System.setProperty('org.eclipse.jetty.util.log.class','org.eclipse.jetty.util.log.StdErrLog');java.lang.System.setProperty('org.eclipse.jetty.LEVEL','WARN');com.comsol.model.util.ModelUtil.connect('localhost',2036);import('com.comsol.model.*');import('com.comsol.model.util.*');addpath('C:\Users\xiao'wei\.comsol\v60\llsimulink');addpath('C:\Program Files\COMSOL\COMSOL60\Multiphysics\ext\LiveLink\Simulink\sli');addpath('C:\Program Files\COMSOL\COMSOL60\Multiphysics\mli');run('C:\Users\xiao'wei\.comsol\v60\llmatlab\comsolinit.m');
                                                                                                                                                   ↑
错误: 表达式无效。请检查缺失的乘法运算符、缺失或不对称的分隔符或者其他语法错误。要构造矩阵,请使用方括号而不是圆括号。

如上述英文加粗用户名所示,我们只需要在整个字符串加上双引号就行。

例如,“C:\Users\xiao'wei\.comsol\v60"

addpath(“C:\Users\xiao'wei\.comsol\v60\llsimulink”)

run(“C:\Users\xiao'wei\.comsol\v60\llmatlab\comsolinit.m“)

这样就解决问题了。

成功后,弹出如下提示,这些提示非常有用。

java.lang.System.setProperty('cs.root','C:\Program Files\COMSOL\COMSOL60\Multiphysics');java.lang.System.setProperty('cs.prefsdir',"C:\Users\xiao'wei\.comsol\v60");java.lang.System.setProperty('cs.apiclient','on');import com.comsol.communication.ClientType;import com.comsol.clientapi.engine.APIEngine;APIEngine.setClientType(ClientType.LLMATLAB);java.lang.System.setProperty('org.eclipse.jetty.util.log.class','org.eclipse.jetty.util.log.StdErrLog');java.lang.System.setProperty('org.eclipse.jetty.LEVEL','WARN');com.comsol.model.util.ModelUtil.connect('localhost',2036);import('com.comsol.model.*');import('com.comsol.model.util.*');addpath("C:\Users\xiao'wei\.comsol\v60\llsimulink");addpath('C:\Program Files\COMSOL\COMSOL60\Multiphysics\ext\LiveLink\Simulink\sli');addpath('C:\Program Files\COMSOL\COMSOL60\Multiphysics\mli');run("C:\Users\xiao'wei\.comsol\v60\llmatlab\comsolinit.m");
                                                                       

Starting COMSOL Multiphysics LiveLink(TM) for MATLAB(R) - 6.0.0.318.

Checking for additional startup script (comsolstartup.m)
  in: C:\Users\xiao'wei

Checking for startup script on the MATLAB path


Type help mli and help sli for more information

Type mphapplicationlibraries to open the Application Library

FontPrefs: unable to find font for component Current Folder
  COMSOL Multiphysics - LiveLink for Simulink
  Version 6.0    1-Oct-2021
  Copyright 2010-2021 COMSOL
 
  User interface functions
    mphlaunch       - Launch COMSOL Multiphysics Client and import a model 
                     from the server
    mphload         - Load a COMSOL model MPH-file
    mphsave         - Save a COMSOL model
    mphversion      - Return the version number of COMSOL Multiphysics
    mphsimsettings  - Settings dialog box for LiveLink for Simulink
     mphupdatesystem - Update COMSOL Cosimulation blocks in Simulink systems
 
  Utility functions
    mphreduction    - Return reduced order state space matrices for a model
 
  Model information and navigation
    mphapplicationlibraries - GUI for viewing the Model Library
    mphtags                 - Return tags for model nodes or models on the
                              server

    名为 sli 的文件夹

>> mphcd
错误使用 mphcd
输入参数的数目不足。

COMSOL LIVE LINK WITH MATLAB

将comsol与matlab集成起来

将COMSOL与MATLAB集成起来

  1. 通过MATLAB函数定义模型设定

  2. 通过脚本扩展建模

  3. 在MATLAB工作空间中完成数据计算和后处理

  4. 访问底层模型信息

  5. 模型降阶,并从模型中提取状态空间矩阵

  6. 为在其他仿真工具中计算提供接口

  7. 使用MATLAB图形化用户界面开发工具来创建定制的图形化用户界面

mphnavigator 中的模型对象

图片

图片

函数

界面函数

mphcd:修改到模型所在路径

mphdoc:访问HTML文档

mphload:加载COMSOL模型的MPH-文件

mphopen:打开最近模型文件的GUI

mphsave:保存COMSOL模型

mphstart:连接MATLAB到COMSOL服务器

mphlaunch:启动COSMOL Desktop

mphversion:获取COMSOL的版本号

几何函数

几何函数

mphgeom:在MATLAB图像中绘制几何

mphimage2geom:转换图像为几何

mphviewselection:显示几何实体选择

图片

网格函数

mphmesh:在MATLAB 图像中绘制网格

mphmeshstats:列出网格信息和网格统计

图片

实用函数

mphevaluate:计算模型中的参数表达式

mphgetadj:返回相邻的几何实体

mphgetcoords:返回几何实体的点坐标

mphselectbox:使用橡皮筋/框选择几何实体 

mphselectcoords:使用点坐标选择几何实体

mphquad2tri:转换绘图数据四边形网格为简化网格

mphsurf:从表面数据创建绘图数据

mphreadstl:读取STL文件并以数据结构形式返回数据

mphwritestl:导出绘图数据为STL文件

mphinterpolationfile:通过内插功能保存数据到一个可读文件

mphinputmatrix:增加线性矩阵系统到模型

mphgetu:返回解矢量

mphmatrix:获取模型系统矩阵

mphstate:获取动态系统的状态空间矩阵

mphxmeshinfo:提取扩展网格的信息

mphsolinfo:获得解的信息

mphsolutioninfo:获得解对象和含给定参数的数据集的信息

后处理函数

mpheval:在节点上计算表达式

mphevalglobalmatrix:计算全局矩阵变量

mphevalpointmatrix:计算点上的矩阵变量

mphevalpoint:计算几何顶点上的表达式

mphglobal:计算全局物理量

mphint2:对表达式进行积分

mphinterp:计算任意点上的表达式

mphmax:计算表达式的最大值

mphmean:计算表达式的平均值

mphmin:计算表达式的最小值

mphparticle:计算粒子轨迹上的表达式

mphplot:在图像窗口渲染绘图组

mphtable:获取表格数据

图片

模型信息函数

mphgetproperties:获取模型节点的属性

mphgetexpression:获取模型变量和参数

mphgetselection:获取选择节点的信息

mphmodel:返回模型对象的节点和子节点的标签

mphapplicationlibrary:浏览App库的GUI

mphnavigator:浏览模型对象的GUI

mphsearch:在模型对象中查找表达式的GUI

mphshowerrors:显示模型对象中的错误和警告节点中的信息

图片

流程

使用mphopen命令加载MPH文件

1. 模型文件中包含模型的设置、网格和解

2. 在重新求解前修改模型设置并添加细节,或者使用mphsave命令保存文件

图片

图片

注:此文章后半部分参考了微信公众号相关“COMSOL仿真交流”微信公众号的内容,在此致谢。

最后我用livelink with matlab 调用函数matlabweimod=mphload('c:\tunnel\FD\gaussian_pulse_perfectly_matched_layers.mph');

显示模型

                                           吸收边界几何模型

                                     带吸收边界网格模型,正方形为吸收边界,三角形为介质

mphtable

Get table data.

SYNTAX

info = mphtable(model,tabletag)

DESCRIPTION

info = mphtable(model,tabletag) returns the structure info containing the data with the tabletag tag and its headers.

The returned value info is a structure with the following content

TABLE 6-40: FIELDS IN THE INFO STRUCT

FIELD

CONTENT

headers

Headers of the table

tag

Tag of the table

data

Data of the extracted table

filename

Filename when table exported to file

EXAMPLE  https://doc.comsol.com/5.6/doc/com.comsol.help.llmatlab/llmatlab_ug_ref.9.25.html

Load model_tutorial_llmatlab.mph, add a stationary study and compute the solution for different power values:

model = mphopen('model_tutorial_llmatlab');

std = model.study.create('std');

stat = std.feature.create('stat','Stationary')

stat.setIndex('pname','power',0);

stat.setIndex('plistarr','30 60 90',0);

std.run;

Evaluate the maximum temperature in the model and set the results in a table:

max = model.result.numerical.create('max','MaxVolume');

max.selection.all;

tbl = model.result.table.create('tbl','Table');

tbl.comments('Volume Maximum (T)');

max.set('table','tbl');

max.setResult;

Extract the table data:

str = mphtable(model,'tbl');

tbl_data = str.data

SEE ALSO

mphevalmphevalpointmphglobalmphint2mphinterpmphmaxmphmeanmphmin

EXAMPLE

Evaluate the temperature at given coordinates:

model = mphopen('model_tutorial_llmatlab');

std = model.study.create('std');

std.feature.create('stat','Stationary');

std.run;

coord = [0,0,1e-2;0,0,1e-2;0,1e-2,1e-2];

T = mphinterp(model,'T','coord',coord);

Evaluate both the temperature and the heat flux magnitude:

[T,tfluxMag] = mphinterp(model,{'T','ht.tfluxMag'},...

'coord',coord);

Evaluate the temperature field on a structure grid:

x0 = [0,1e-2,2.5e-2,5e-2]; y0 = x0; z0 = [5e-3,1e-2,1.1e-2];

[x,y,z] = meshgrid(x0,y0,z0); xx = [x(:),y(:),z(:)]';

T = mphinterp(model,'T','coord',xx);

Evaluate the temperature on boundary 7 using global coordinates:

x0 = [0,5e-3,1e-2]; y0 = x0; z0 = [1.1e-2];

[x,y,z] = meshgrid(x0,y0,z0); xx = [x(:),y(:),z(:)]';

T = mphinterp(model,'T','coord',xx,'edim','boundary',...

'selection',7);

Evaluate the temperature and evaluation point global coordinates on boundary 7 using local coordinates:

s10 = [0,0.25,0.5]; s20 = [0,0.25,0.5];

[s1,s2] = meshgrid(s10,s20); ss = [s1(:),s2(:)]';

[x,y,z,T] = mphinterp(model,{'x','y','z','T'},'coord',ss,...

'edim','boundary','selection',7);

Modify the extrapolation distance for point coordinates outside of the geometry:

coord = [5e-2;5e-2;1.1e-2];

T = mphinterp(model,'T','coord',coord)

T = mphinterp(model,'T','coord',coord,'ext',0.5);

Extract data using a cut line dataset. First create the cut line dataset, then evaluate the temperature field along the line:

cln = model.result.dataset.create('cln', 'CutLine3D');

cln.setIndex('genpoints','1e-2',1,0);

cln.setIndex('genpoints','1e-2',0,2);

cln.setIndex('genpoints','5e-2',1,0);

T = mphinterp(model,'T','dataset','cln');

Evaluation including several solution

model = mphopen('model_tutorial_llmatlab');

std = model.study.create('std');

param = std.feature.create('param','Parametric');

time = std.feature.create('time','Transient');

time.set('tlist', 'range(0,1,25)');

param.setIndex('pname','power',0);

param.setIndex('plistarr','30 60 90',0);

std.run;

Evaluate the temperature at every time step computed with power set to 30:

coord = [0 0 1e-2;0 0 1e-2;0 1e-2 1e-2];

T = mphinterp(model,'T','coord',coord,'dataset','dset2');

Evaluate the temperature at the fifth time step:

T = mphinterp(model,'T','coord',coord,'dataset','dset2',...

'solnum',5);

Evaluate the temperature at 10.5 sec:

T = mphinterp(model,'T','coord',coord,'dataset','dset2',...

't',10.5);

Evaluate the temperature at every time step computed with power set to 90:

T = mphinterp(model,'T','coord',coord,'dataset','dset2',...

'outersolnum',3)

mphinterp(weimod,'p_a','coord',[0;0]);%坐标格式[x;y;z]

wei=mphinterp(weimod,'p_a','coord',[zeros(size(-50:50));-50:50]);%选取一条观测线,得到测线地震道数据

wiggle(wei);%调用函数显示波形

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weiyiwen1982

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值