网页
综合
更新时间 2026-11-15 00:03:31
Handling Errors in Input Files — Cantera 3.2.0 documentation
自动蜘蛛
cantera.org
正文约 2934 字
During processing of an input file, errors may be encountered. These could be syntax errors, or could be ones that are flagged as errors by Cantera due to some apparent inconsistency in the data—an unphysical value, a species that contains an undeclared element, a reaction that contains an undeclared species, missing species or element definitions, multiple definitions of elements, species, or reactions, and so on. This section is intended to help you understand some causes for these errors and their solutions.
Syntax errors are caught by the YAML parser, and must be corrected before proceeding further. If a syntax error is encountered, Cantera will raise an exception which includes the location of the error. Additional information such as a traceback showing where in the code the input file was being read may be printed as well.
For example, consider the following input file, which is intended to create a gas with the species and reactions of GRI-Mech 3.0, but is missing the colon which is needed after the thermo key:
When this definition is imported into an application, an error message like the following would be printed to the screen, and execution of the program or script would terminate:
The top part of the error message shows the chain of functions that were called before the error was encountered. For the most part, these are internal Cantera functions not of direct concern here. The relevant part of this error message is the part between the lines of asterisks. This message says that the YAML parser ran into a problem on line 4 of gas.yaml. In many cases, including this one, the parser will fail somewhere after the actual problem with the input file, since it must continue parsing until it finds something that cannot possibly be valid YAML syntax. In this case, the problem from the parser’s perspective is that the key which started on line 3 continues across a new line before it finds a colon that can be considered as the separator. Since a key can’t be broken across lines like this, the parser indicates the error at the point where it found the colon. By looking back from the indicated point of the error, we can see that the problem is the missing colon in the previous line.
Now let’s consider the other class of errors, ones that Cantera itself detects. Continuing the example above, suppose that the missing colon is corrected, and the input file processed again. Again an error message results, but this time it is from Cantera:
The problem is that the phase definition specifies that all species are to be imported from the gri30 mechanism, but only the elements H and O are declared. The gri30 mechanism contains species composed of the elements H, O, C, N, and Ar. If the definition is modified to declare these additional elements:
it may be imported successfully.
© Copyright 2001-2025, Cantera Developers.
Created using Sphinx 7.3.7.
Built with the PyData Sphinx Theme 0.15.4.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。