COMSOL-Save data to file while solving

COMSOL 可以一边solve一边导出数据到文件,这个在进行长时间的大量数据计算时特别有用,特别是进行parameteric sweep的时候。这个可以通过很多方式来实现。官方的blog有一篇是专门讲这个的:https://www.comsol.com/blogs/how-to-use-job-sequences-to-save-data-after-solving-your-model/
简单来说,他是通过在study node下通过建立了一个programmatic sequence来实现的。

Using Job Sequences to Save Data

  1. Right-click Job Configurations and select Sequence.
    image

    This node is something that you don’t need to worry about during conventional modeling work. It essentially stores low-level information pertaining to the order in which the solution process should be run. Normally, this is controlled indirectly from the top level of a study without the need for enabling Advanced Study Options.
  2. Right-click Sequence and add solutions;
    image

    Sequence下面有各种操作:
  • Job refers to another sequence that is to be run from this sequence;
  • Solution runs a Solution node as available under the Solver Configurations node;
  • Under Other, you can choose External Class, which calls an external Java® class file. Another option, Geometry, builds the Geometry node. This can be used, for example,in combination with a parametric sweep to generate a sequence of MPH-files with different geometry parameters. The Mesh option builds the Mesh node.
  • The default option for a Solution node in a sequence is to run all solution nodes. The Run option in the General section lets you specify which Solution data structures should be computed.
  1. Save Model to File saves the solved model to an MPH-file.
    We would like to save the file when the solver is finished. Right-click the Sequence node and select Save Model to File.


    image
  2. To run these operations, select the Sequence node and click Run.

Writing Data to File After Solving in COMSOL Multiphysics®

  1. Define a derived values under Results > Derived Values > Global Evaluation
image
  1. Create a Table under the results node;
  1. Add the Results > Evalute Derived Values option under the sequence 1 and the calculated data will be sent to Table 1 and save to the computer;
    image

Running Job Sequences from the Command Line

有时候我们需要用command line来运行comsol。注意此时不能用上述方法来建立一个job sequence,因为 The operating system command interface doesn’t let you run any part of a Study node that is not controlled at the top level of the Study node. 也就是说sequence建立在job configuration下,command line无法operate,因为the top-level study step is unaware of your edits under the Job Configuration node。这时候我们需要借助a parametric sweep with a dummy parameter。 因为parameteric sweep是建立在study node的top level下的。

To make the study step at the top of the Study node tree “aware” of your edits under the Job Configurations node, the easiest way is to add a parametric sweep with an arbitrary parameter defined under Global Definitions > Parameters; say, dummy with value 1. Sweeping over this parameter then adds the extra overhead needed to get a handle on the Job Configuration node from the top level of the Study node. Then, you can issue a command-line batch command to run it.

The following picture show the dummy sweep work:


image

添加上述dummy sweep之后会发现job configuration下面自动添加了一个parametric sweep的sequence:


image

从上图我们可以看出:

the Parametric Sweep 1 node is just a special type of Sequence node, the child nodes Solution 1, Save Model to File 1, and Evaluate: Global Evaluation 1 are just as they are in the example above using Sequence.

这时在linux中输入 command line:
comsol batch -inputfile mymodel.mph -study std1
Linux® will now run the sequence of operations that solves, saves the model to file, and finally evaluates the Global Evaluation node.

inner sweep and outer sweep

Note that if you already have a parametric sweep in your model, these can be of two types loosely referred to as “inner sweep” and “outer sweep”. The sweep in the example above using the dummy parameter is an “outer sweep”. The Study node will autodetect which type of sweep to use for best performance, but you can take control manually, if needed. In order to use a job sequence from the command line, your sweep needs to be an “outer sweep”.

More or less all types of sweeps can be changed from being an inner sweep to an outer sweep, but not the other way around. Inner sweeps can be faster, since they will use some of the underlying structure of the computation to speed things up. However, not all types of sweeps can be inner sweeps. For example, a sweep over a geometry parameter always needs to be an outer sweep; again, this is handled automatically by the solver. To make sure the parameter sweep is an outer sweep, change the Use parametric solver to Off in the Parametric Sweep settings, then perform a Show default solver operation and continue from there.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,442评论 0 13
  • 写了一个自定义键盘,使用代理实现的回调,遇到了一个奇葩问题 键盘都是枚举来定义的,每次回调都会返回一个枚举值,其他...
    fortitude1990阅读 357评论 0 0
  • 晚风轻拂面,花香满鼻间。 恰逢人间四月天,傍晚的天气像个格外温柔的少女,树树花开是她特意喷上的属于她的独有的香水气...
    姜归宁阅读 804评论 0 1
  • 啦啦啦!我又来做知识的搬运工啦! 最近好多朋友都在问,血糖参考值是多少?以下就是我为大家搜集的在不同状态下,血糖正...
    lion米儿阅读 353评论 1 1
  • 如果恐龙还在,根据人类的一贯作风,必会驯化一部分,作为农耕家畜、桌上美食、交通工具、战争机器等等。当然,我肯定会说...
    笑无涯阅读 212评论 0 2