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
- Right-click
Job Configurations
and selectSequence
.
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. - Right-click
Sequence
and addsolutions
;
Sequence
下面有各种操作:
-
Job
refers to another sequence that is to be run from this sequence; -
Solution
runs aSolution
node as available under theSolver 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.
-
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.
- To run these operations, select the Sequence node and click Run.
Writing Data to File After Solving in COMSOL Multiphysics®
- Define a derived values under
Results > Derived Values > Global Evaluation
- Create a
Table
under the results node;
- Add the
Results > Evalute Derived Values
option under thesequence 1
and the calculated data will be sent to Table 1 and save to the computer;
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:
添加上述dummy sweep之后会发现job configuration下面自动添加了一个parametric sweep的sequence:
从上图我们可以看出:
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.