COMSOL with matlab---Quick Start

COMSOL 是一个多物理场仿真软件,它的一个最大的问题就是各个版本之间的不兼容问题。解决这个问题的方法就是把COMSOL保存中m文件。m文件实际上是一种录制宏,它保存了你的几乎所有操作,可以用matlab来打开。COMSOL与matlab的连接需要 LiveLink™ for MATLAB®,需要在安装COMSOL时选择安装。具体的安装步骤这里不再赘述。关于COMSOL与matlab的连接可以参考官方的user‘s guide:
https://www.researchgate.net/profile/Mohan_Pradhan/post/Connecting_matlab_with_COMSOL_Livelink/attachment/59d626c079197b807798506e/AS%3A323111042387968%401454047083245/download/LiveLinkForMATLABUsersGuide.pdf
另外官方提供了一个例子教学视频https://cn.comsol.com/blogs/using-matlab-functions-comsol-multiphysics-models/可以供参考。

Quick Start

1. Start COMSOL with matlab

• On Windows® use the COMSOL with MATLAB shortcut icon that is created on the
desktop after the automatic installation. A link is also available in the Windows start
menu under All Programs>COMSOL 43b>COMSOL 4.3b with MATLAB.
• On Mac OS X, use the COMSOL with MATLAB application available in the Application
folder.
• On Linux®, enter the command comsol server matlab at a terminal window

首次启动 会提示输入 username 和 password,这个可以根据个人需要自己填写,之后的启动就不需要了。

启动之后会打开一个matlab的界面以及一个COMSOL with matlab的promt,在matlab中建立合适的工作路径就可以开始工作了。

2. 使用mphload函数导入模型

首先将matlab的工作路径设置到mph文件所在的路径位置。然后使用mphload命令进行导入
model = mphload(‘PATH\Mymodel.mph’)
例如:

  % Load the file model_tutorial_llmatlab.mph:
  model = mphload('model_tutorial_llmatlab')

  % Load the file model_tutorial_llmatlab.mph and set the model name in the COMSOL server to Model2:
  model = mphload('model_tutorial_llmatlab','Model2')

  % Load MyModel.mph with the path specified:
  model = mphload('PATH\MyModel.mph')

  % Load model_tutorial_llmatlab.mph and return the filename:
  [model, filename] = mphload('model_tutorial_llmatlab')

关于mphload函数的更多用法可以用help mphload查看。

模型导入成功后会显示如下内容:

model =

COMSOL Model Object
Name: ML_squareloop.mph
Tag: Model
Identifier: root

3. 使用mphsave函数保存或导出模型

语句如下:
mphsave(model,'/ML_squareloop.m')
导出成功会发现在工作路径下多了一个m文件。

Model Object

While working with the LiveLink™ interface in MATLAB® you work with models
through the model object. Use methods to create, modify, and access models.

Important Notes About the Model Object

  1. All algorithms and data structures for the model are integrated in the model object
  2. The model object and the COMSOL Desktop behavior are virtually identical
  3. The model object includes methods to set up and run sequences of operations to
    create geometry, meshes, and to solve your model.

The Model Object Methods

The model Object 下有大量的methods,他们排列成树型,有点像是COMSOL desktop中Model builder下的构型。

The General Utility Functionality ModelUtil

这个函数可以用来 create or remove a new model object, but also to enable the progress bar or list the model object available in the COMSOL server.

  1. MANAGING THE COMSOL MODEL OBJECT

model = ModelUtil.create('Model')
This command creates a model object Model on the COMSOL server and a MATLAB
object model that is linked to the model object.这个命令在COMSOL server上创建了一个object,同时也创建了一个关联的matlab object。

一个comsol server上可以存在不同的model objects,当想要用matlab来操纵时,需要赋予它不同的matlab variables。对于已经存在的model object,可以创建一个matlab variable来对它连接,例如:
model = ModelUtil.model('Model')
comsol sever上存在一个'Model',用上述命令,我们创建了一个matlab variable model将两者连接起来。

ModelUtil.remove('Model') 从COMSOL server上移除 model object Model

ModelUtil.clear清除COMSOL sever上所有的model objects。

list = ModelUtil.tags列出COMSOL sever上所有的model objects。

  1. ACTIVATING THE PROGRESS BAR
    在默认状态下, matlab不会展示进程信息,通过运行命令:
    ModelUtil.showProgress(true);
    可以activate the progress bar。
    To deactivate the progress bar enter:
    ModelUtil.showProgress(false);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 何以沦落至此?我想我该反思。 是什么?让我混成如今这般模样? 不是我想要的 我想要的又是什么样的? 迷茫... 这...
    亲亲小尤儿阅读 153评论 0 0
  • 近期很多小伙伴在问爱润妍玻尿酸面膜能用吗?真的那么好吗?或许是因为原价298¥一盒的面膜,推广期只要一折29.8元...
    小仙女5200阅读 1,121评论 0 1
  • 整齐排布的书本,逐级递进,可以支持最高的智慧。每天的食物都反复考虑,味道还有营养搭配。外面的世界太黑暗,你就呆在这...
    熔浆曲奇阅读 465评论 0 2
  • 晚饭后一个人在街上晃荡了半天,这样的感觉还是挺赞的。 享受无所事事的轻松。 一个人静下来时常常思考:我到底为啥而活...
    hhzha0阅读 130评论 0 0
  • 绿叶罗裙水澹澹,小池游鱼双双伴,情到深处心无憾。 年少不解蝶恋花,天涯咫尺缱绻暖,花不解语梦又寒。
    夏诺xn阅读 1,745评论 30 64