-
Notifications
You must be signed in to change notification settings - Fork 64
IDEAS Style Guide
This page provides a checklist that should be used when contributing to a new class (model, block, function, etc.) to the library.
- Follow the conventions as specified in the Modelica IBSPA library and described in the Modelica Buildings library User's Guide.
- Partial classes and base classes that are not of interest to the user should be stored in a subdirectory called
BaseClasses. - Do not copy sections of code. Use object inheritance.
- Implement new components by extending from the partial classes in the respective
Interfacesdirectories, where possible. - Use the full package names when instantiating a class, i.e. always starting with
IDEAS..
- Class and instance names are written in CamelCase (upper and lower case letters), e.g.,
ElectricCurrent. If possible, only use the first three letters of a compound name, e.g.,EleCur. An underscore is only used at the end of a name to characterise a lower or upper index, e.g.,pin_a. - Class names always start with an upper-case letter.
- Instance names, i.e., names of component instances and variables (except for constants), usually start with a lower case letter,
with only a few exceptions if this is common sense (such as
Tfor a temperature variable). See the table below for examples and exceptions. - Constant names, i.e., names of variables declared with the "constant" prefix, follow the usual naming conventions (= upper and lower case letters) and start usually with an upper case letter, e.g., UniformGravity, SteadyState.
- The two connectors of a domain that have identical declarations and different icons are usually distinguished
by
_a,_bor_p,_n. Examples:Flange_a,Flange_borHeatPort_a,HeatPort_b.
These rules are additions to the basic rules above:
- Variable names start with the symbol. Example:
TSet,T_start,pOut,mFlow_nom(and NOTsetTemperatureoroutletPressureorNomMFlowor something like that) - If possible and clear, abbreviate sequences to 3 letters for instances. For long words, this is strongly encouraged; for short (4 and 5-letter words), this is not necessary, although it is possible. Class names do not have to be abbreviated.
- All variables should be instances of the
Modelica.Units.SIpackage. Examples:Modelica.Units.SI.TemperatureorModelica.Units.SI.MassFlowRate. - The Modelica sign convention denotes: flow INTO component is POSITIVE (for mass flow rates, current, etc.) You can remember this by a simple rule: Modelica components are egoistic: getting something is positive for them. This means for electric power: a positive power at a connection => the object consumes electricity.
- Efficiencies and ratios: no unit, no percentage (1 instead of 100%, also called “base 1”)
- Add a one-line comment to all parameters and variables, including protected ones.
- Provided a detailed explanation of the implemented physics in the
Specificationssection in LaTeX. - Group similar variables using the
groupandtabannotation. - Add model documentation to the
infosection. - Add author information to the
revisionsection. - Run a spell check.
- For complex packages, provide a User's Guide, and reference the
User's Guide in
IDEAS.Buildings.UsersGuide.
- Avoid events where possible.
- Only divide by quantities that cannot take on zero.
- Use SI units in all equations.
- Use the
assertfunction to check for invalid values of parameters or variables. - Use either graphical modelling or textual code. Avoid using both within one class.
- For computational efficiency, equations shall be differentiable and have a continuous first derivative.
- Avoid equations where the first derivative with respect to another variable is zero, except at a single point.
- Do not replace an equation by a constant for a single value, unless the derivative of the original equation is zero for this value.
- Whenever possible, a Modelica tool should not have to do numerical differentiation. For example, in Dymola, if your model translation log shows
Number of numerical Jacobians: 1(or any number other than zero), then enter on the command lineHidden.PrintFailureToDifferentiate = true;Next, translate the model again to see what functions cannot be differentiated symbolically. Then, implement symbolic derivatives for this function. See implementation of function derivatives.
-
Declare variables and final parameters that are not of interest to users as protected.
-
Set default parameter values as follows:
-
If a parameter value can range over a large region, do not provide a default value.
-
If a parameter value does not vary significantly, provide a default by using its start attribute, e.g. use
parameter Real eps(start=0.8, min=0, max=1, unit="1") "Heat exchanger effectiveness";
-
If a parameter value can be precomputed based on other parameters, set its default value to this equation, e.g.
parameter Medium.MassFlowRate mFloSmall(min=0) = 1E-4*mFloNom;
-
If a parameter value should not be changed by a user, use the
finalkeyword.
-
-
For any variable or parameter that may need to be solved numerically, provide a value for the
startand ``nominal``attributes. -
Use types from
Modelica.Units.SIwhere possible.