Reference Guide: Structures - Classes.jl and Core Types
Classes.jl
NOTE: We plan to soon phase out use of Classes.jl for simplicity
Most of the core data structures are defined using the Classes.jl package, which was developed for Mimi, but separated out as a generally useful julia package. The main features of Classes are:
Classes can subclass other classes, thereby inheriting the same list of fields as a starting point, which can then be extended with further fields.
A type hierarchy is defined automatically that allows classes and subclasses to be referenced with a single type. In short, if you define a class
Foo, an abstract type calledAbstractFoois defined, along with the concrete classFoo. If you subclassFoo(say with the classBar), thenAbstractBarwill be a subtype ofAbstractFoo, allowing methods to be defined that operate on both the superclass and subclass. See the Classes.jl documentation for further details.
For example, in Mimi, ModelDef is a subclass of CompositeComponentDef, which in turn is a subclass of ComponentDef. Thus, methods can be written with arguments typed x::ComponentDef to operate on leaf components only, or x::AbstractCompositeComponentDef to operate on composites and ModelDef, or as x::AbstractComponentDef to operate on all three concrete types.
User-facing Classes
Model: TheModelclass contains theModelDef, and after thebuild()function is called, aModelInstancethat can be run. The API forModeldelegates many calls to either its top-levelModeDeforModelInstance, while providing additional functionality including running a Monte Carlo simulation.ComponentReference
[TODO]
VariableReference
[TODO]
Core Types
Several core types are defined in types/core.jl, including the two primary abstract types, MimiStruct and MimiClass.
All structs and classes in Mimi are derived from these abstract types, which allows us to identify Mimi-defined items when writing show() methods. Some of the important structs and classes include:
ComponentIdTo identify components,
@defcompcreates a variable with the name of the component whose value is an instance of this type. The definition is:julia struct ComponentId <: MimiStruct module_obj::Union{Nothing, Module} comp_name::Symbol endComponentPathA
ComponentPathidentifies the path from one or more composites to any component, using anNTupleof symbols. Since component names are unique at the composite level, the sequence of names through a component hierarchy uniquely identifies a component in that hierarchy.julia struct ComponentPath <: MimiStruct names::NTuple{N, Symbol} where N end