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.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

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