CONSTANT

From ASCEND
Revision as of 20:04, 14 February 2012 by Jpye (talk | contribs) (Created page with "The '''CONSTANT''' statement is used to declare constant-value 'variable' types that may be used as parameters for reusable parametric MODEL types. Real constants which d...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The CONSTANT statement is used to declare constant-value 'variable' types that may be used as parameters for reusable parametric MODEL types.

Real constants which do not have a default value are usually needed only in libraries of reusable models, such as components.a4l, where the values depend on the end-user’s selection from alternatives in a database. The standard incantation to define a new real constant type is:

CONSTANT critical_pressure_constant
REFINES real_constant DIMENSION M/L/T^2;

It is wasteful to define a CONSTANT type and a compiled object to represent a universal constant. For example, the thermodynamic gas constant, R = 8.314... {J/mole/K}, is frequently needed in modeling chemical systems. The SI value of R does not vary with its application. Neither does the value of <math>\pi</math>. Numeric constants of this sort are better represented as a numeric coefficient and an appropriately defined unit conversion, using the UNITS statement.

Consider the ideal gas law, PV = NRT and the ASCEND unit conversion {GAS_C} which appears in the library ascend4/models/measures.a4l. This equation should be written:

P * V = n * 1.0{GAS_C} * T;

Similarly, area <math>{}= \pi*r^2</math> should be written

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn

The coefficient 1 of {GAS_C} and {PI} in these equations takes of the dimensionality of and is multiplied by the conversion factor implied by the UNITS definition for the part within the braces {}. If we check models/measures.a4l, we find the definition of PI is simply {3.14159...} and the definition of GAS_C is {8.314... J/mole/K} as we ought to expect.

For historical reasons there are a few universal constant definitions in models/atoms.a4l. New modelers should not use them; they are only provided to support outdated models that no one has yet taken the time to update.

See also