Model section items#
ModelElement subclasses#
Each model section item is represented by one of the following classes, which all inherit from ModelElement,
thus provide the get_generated_element() method to access the associated generated C element. (see Code section items)
Type Definitions
ModelPredefinedType- Predefined typeModelArray- Array type definitionModelStruct- Structure type definitionModelStructField- Field within a structureModelEnum- Enumeration type definitionModelEnumValue- Value within an enumerationModelVariant- Variant type definitionModelVariantConstructor- Constructor within a variantModelNamedType- Named type (user-defined type reference)
Operators and Instances
ModelOperator- Operator declarationModelMonoOperator- Monomorphized operatorModelOperatorInstance- Instance of an operatorModelLoopInstance- Loop instance
Variables and Parameters
ModelVariable- Input/output variableModelVariablesGroup- Group of variablesModelMonoVariable- Monomorphized variableModelTypeParameter- Type parameter for monomorphizationModelSizeParameter- Size parameter for monomorphization
Constants, Sensors, and Probes
ModelConstant- Constant valueModelSensor- Sensor elementModelProbe- Probe elementModelProbesGroup- Group of probes
Model groups#
Some model items can be returned as groups (ModelGroup) of said items.
These items are:
Flows
ModelVariable, found inModelOperatorinputs and outputs, returned asModelVariablesGroupProbes
ModelProbe, found inModelOperator,ModelMonoOperator,ModelLoopInstanceandModelOperatorInstance, returned asModelProbesGroup
These groups possess a common identifier: respectively name and path for variables and probes. Both possess an attribute projections which is a list of all their respective items, represented as projections. A projection is a list of strings or integers which represent the location of the item in the group hierarchy. Integers are used for positional (location in current level) and strings are used for labels (element name or sub-group name).
Groups cannot use the method get_generated_element() (it will return None), they must use get_generated_group_elements() instead.
However, each of a group’s projections can use the method get_generated_element() normally.
Group |
Flows |
Probes |
|---|---|---|
Found in attributes |
inputs and outputs |
probes |
From elements |
|
|
Instead of |
||
Group type |
||
Group attributes |
name (str) |
path (str) and
kind ( |
Group projections |
To get flattened flows and probes instead of groups, ModelOperator.get_flat_inputs(),
ModelOperator.get_flat_outputs() and HasProbesMixin.get_flat_probes() can be used.
API Documentation#
Model module for Swan Code Generator mapping data.
This module implements classes representing elements from the Swan language model. Each model item has a unique integer ID and can reference other model items by their IDs.
- class ansys.scadeone.core.svc.cgmapping.model.HasComputedFlagMixin#
Bases:
objectMixin providing computed flag access methods for elements that carry a
computed_flag.- get_computed_flag() CStructField | None#
Get the computed flag structure for this element. The computed flag is set to true when the value of the element is updated during the cycle.
- Returns:
CStructField|NoneThe computed flag structure (CStructField) if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.HasProbesMixin#
Bases:
objectMixin providing probe access methods for elements that carry a
probeslist.- get_flat_probes() list[ModelProbe]#
Get the probes defined in this element, flattening any groups.
- Returns:
list[ModelProbe]List of all probes, including those expanded from groups.
- get_probes() list[ModelProbe | ModelProbesGroup]#
Get the probes defined in this element, including groups as is.
- Returns:
list[ModelProbe|ModelProbesGroup]List of probes.
- class ansys.scadeone.core.svc.cgmapping.model.ModelArray(id: int, base_type: int, size: int)#
Bases:
ModelElementModel array type definition.
- Parameters:
- class ansys.scadeone.core.svc.cgmapping.model.ModelConstant(id: int, path: str, type: int, external: bool | None = None)#
Bases:
ModelElementModel constant.
- Parameters:
- get_elaborated_function() CFunction | None#
Get the generated function for this constant’s elaboration.
- Returns:
CFunction|NoneThe function if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.ModelElement#
Bases:
objectBase class for all Swan model elements.
This class provides common functionality for all model elements, including access to their generated code elements through the mapping system.
All model elements that inherit from this class must have an ‘id’ attribute.
- get_c_type() CodeElement | None#
Get the generated C type element associated with this model element.
This method first retrieves the generated code elements for this model element, then looks for a code element that has a ‘type’ attribute and retrieves the corresponding C type element.
- Returns:
CodeElement|NoneThe C type element if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_generated_element() CodeElement | None#
Get the generated code element for this model element.
Only the code element associated via a role-less mapping is returned, which guarantees at most one result. Code elements associated through a named role (e.g. CycleMethod, ResetMethod) are not returned here; use the dedicated methods (
get_cycle,get_reset, etc.) instead.- Returns:
CodeElement|NoneThe code element mapped to this model element without a role, or None if no such mapping exists.
- Raises:
AttributeErrorIf this instance has no ‘id’ attribute.
ValueErrorIf no cgmapping is set on this instance.
- get_model_type() ModelElement | None#
Get the model element corresponding to the type of this model element.
This method first checks if this model element has a ‘type’ attribute. If it does, it retrieves the model element with that ID. Otherwise, it gets the generated code element, retrieves its type, and returns the model element associated with that type ID.
- Returns:
ModelElement|NoneThe model element representing the type, None if not found.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.ModelEnum(id: int, values: list[ModelEnumValue])#
Bases:
ModelElementModel enum type definition.
- Parameters:
- id
int Unique identifier for this enum type.
- values
list[ModelEnumValue] List of enum values.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelEnumValue(id: int, path: str, default: bool | None = None)#
Bases:
ModelElementModel enum type value.
- class ansys.scadeone.core.svc.cgmapping.model.ModelGroup(*, projections: list[ModelGroupProjection] = <factory>)#
Bases:
ModelElementBase class for model variable and probe groups.
Subclasses hold a
projectionslist and a shared identifier (namefor variable groups,pathfor probe groups).- get_generated_group_elements() list[CodeElement]#
Get the generated code elements for all projections in this group.
- Returns:
list[CodeElement]List of generated code elements corresponding to each projection in this group.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_group_projection(projection: list[str | int]) ModelGroupProjection | None#
Get the group element corresponding to a specific projection.
- Parameters:
- projection
list[GroupProjection] The exact projection path of element.
- projection
- Returns:
ModelGroupProjection|NoneThe group element corresponding to the given projection, or None if not found.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.ModelGroupProbeProjection(id: int, projection: list[str | int] | None = None)#
Bases:
ModelGroupProjectionProjection of a grouped model probe.
- Parameters:
- id
int Unique identifier for the projected model probe.
- projection
list[GroupProjection] |None Group projection path for the probe.
- id
- get_generated_element() CodeElement | None#
Get the generated code element for this probe projection.
- Returns:
CodeElement|NoneThe code element mapped to this probe projection without a role, or None if no such mapping exists.
- class ansys.scadeone.core.svc.cgmapping.model.ModelGroupProjection(id: int, projection: list[str | int] | None = None)#
Bases:
ModelElementProjection of a group.
- Parameters:
- id
int Unique identifier for the projected model variable.
- projection
list[GroupProjection] |None Group projection path for the variable.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelGroupVariableProjection(id: int, projection: list[str | int] | None = None, _associated_probe: ModelGroupProbeProjection | None = None)#
Bases:
ModelGroupProjectionProjection of a grouped model variable.
- Parameters:
- id
int Unique identifier for the projected model variable.
- projection
list[GroupProjection] |None Group projection path for the variable.
- id
- get_associated_probe() ModelGroupProbeProjection | None#
Get the associated probe for this variable projection if it exists.
- class ansys.scadeone.core.svc.cgmapping.model.ModelLoopInstance(id: int, path: str, bound: int, probes: list[ModelProbe | ModelProbesGroup], instances: list[ModelInstance], kind: LoopKind | None = None, partial: bool | None = None)#
Bases:
HasProbesMixin,HasComputedFlagMixin,ModelElementModel loop instance.
- Parameters:
- id
int Unique identifier for this loop instance.
- path
str Path to the loop instance.
- bound
int Loop bound.
- kind
LoopKind|None Kind of loop (Iterator or Forward).
- partialbool |
None Whether the loop is partial.
- probes
list[ModelProbe|ModelProbesGroup] List of probes in this loop.
- instances
list[ModelInstance] List of nested instances.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelMonoOperator(id: int, path: str, probes: list[ModelProbe | ModelProbesGroup], instances: list[ModelInstance], src: int, type_parameters: list[ModelTypeParameter], size_parameters: list[ModelSizeParameter], inputs: list[ModelMonoVariable], outputs: list[ModelMonoVariable])#
Bases:
OperatorBaseModel operator monomorphization.
- Parameters:
- id
int Unique identifier for this monomorphized operator.
- path
str Path to the operator.
- src
int Reference ID to the source operator.
- type_parameters
list[ModelTypeParameter] List of type parameters.
- size_parameters
list[ModelSizeParameter] List of size parameters.
- inputs
list[ModelMonoVariable] List of monomorphized input variables.
- outputs
list[ModelMonoVariable] List of monomorphized output variables.
- probes
list[ModelProbe|ModelProbesGroup] List of probes.
- instances
list[ModelInstance] List of instances.
- id
- get_flat_inputs() list[ModelMonoVariable]#
Get all monomorphized input variables.
- Returns:
list[ModelMonoVariable]All input variables in order.
- get_flat_outputs() list[ModelMonoVariable]#
Get all monomorphized output variables.
- Returns:
list[ModelMonoVariable]All output variables in order.
- get_input_groups() list[ModelVariablesGroup]#
Always empty: monomorphized operators have no variable groups.
- get_inputs() list[ModelMonoVariable]#
Get monomorphized operator inputs.
- get_output_groups() list[ModelVariablesGroup]#
Always empty: monomorphized operators have no variable groups.
- get_outputs() list[ModelMonoVariable]#
Get monomorphized operator outputs.
- get_src_operator() ModelOperator | None#
Get the source operator for this monomorphized operator.
- Returns:
ModelOperator|NoneThe source operator if found, None if not found or if no cgmapping is set.
- class ansys.scadeone.core.svc.cgmapping.model.ModelMonoVariable(id: int, src: int, _associated_probe: ModelProbe | None = None)#
Bases:
ModelElementModel variable monomorphization.
- Parameters:
- get_associated_probe() ModelProbe | None#
Get the associated probe for this variable.
- class ansys.scadeone.core.svc.cgmapping.model.ModelNamedType(id: int, path: str, definition: int | None = None)#
Bases:
ModelElementModel named type.
- Parameters:
- get_model_type() ModelElement | None#
Get the model element corresponding to the definition of this named type.
- Returns:
ModelElement|NoneThe model element representing the definition, None if not found.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.ModelOperator(id: int, path: str, probes: list[ModelProbe | ModelProbesGroup], instances: list[ModelInstance], inputs: list[ModelVariable | ModelVariablesGroup], outputs: list[ModelVariable | ModelVariablesGroup], root: bool | None = None, external: bool | None = None, expanded: bool | None = None, specialize: int | None = None)#
Bases:
OperatorBaseModel operator.
- Parameters:
- id
int Unique identifier for this operator.
- path
str Path to the operator.
- rootbool |
None Whether this is a root operator.
- externalbool |
None Whether this operator is external.
- expandedbool |
None Whether this operator is expanded.
- specialize
int|None Reference ID to specialization (if any).
- inputs
list[ModelVariable|ModelGroup] List of input variables and groups. A ModelGroup is created only if the variable has a non-None projection attribute.
- outputs
list[ModelVariable|ModelGroup] List of output variables and groups. A ModelGroup is created only if the variable has a non-None projection attribute.
- probes
list[ModelProbe|ModelProbesGroup] List of probes.
- instances
list[ModelInstance] List of instances.
- id
- get_flat_inputs() list[ModelVariable]#
Get all input variables flattened from groups.
- Returns:
list[ModelVariable]All input variables from all groups in order.
- get_flat_outputs() list[ModelVariable]#
Get all output variables flattened from groups.
- Returns:
list[ModelVariable]All output variables from all groups in order.
- get_global_context() CGlobal | None#
Get the generated global context variable.
- Returns:
CGlobal|NoneThe global context variable if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_global_obs_struct() CStruct | None#
Get the generated global observation structure.
- Returns:
CStruct|NoneThe global observation structure if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_input_groups() list[ModelVariablesGroup]#
Get operator input groups only (excluding ungrouped variables).
- get_inputs() list[ModelVariable | ModelVariablesGroup]#
Get operator inputs (variables and groups).
- get_mono_operators() list[ModelMonoOperator]#
Get the monomorphized operators derived from this operator.
- Returns:
list[ModelMonoOperator]List of monomorphized operators that have this operator as their source. Returns empty list if none found or if no cgmapping is set.
- get_output_groups() list[ModelVariablesGroup]#
Get operator output groups only (excluding ungrouped variables).
- get_outputs() list[ModelVariable | ModelVariablesGroup]#
Get operator outputs (variables and groups).
- class ansys.scadeone.core.svc.cgmapping.model.ModelOperatorInstance(id: int, path: str, operator: int, probes: list[ModelProbe | ModelProbesGroup], instances: list[ModelInstance])#
Bases:
HasProbesMixin,HasComputedFlagMixin,ModelElementModel instance of an operator.
- Parameters:
- id
int Unique identifier for this operator instance.
- path
str Path to the operator instance.
- operator
int Reference ID to the operator.
- probes
list[ModelProbe|ModelProbesGroup] List of probes in this instance.
- instances
list[ModelInstance] List of nested instances.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelPredefinedType(id: int, name: str)#
Bases:
ModelElementModel predefined type.
- class ansys.scadeone.core.svc.cgmapping.model.ModelProbe(id: int, path: str, kind: ProbeKind, projection: list[str | int] | None = None)#
Bases:
HasComputedFlagMixin,ModelElementModel element marked as probe.
- Parameters:
- get_generated_element() CodeElement | None#
Get the generated code element for this probe.
- Returns:
CodeElement|NoneThe code element mapped to this probe without a role, or None if no such mapping exists.
- class ansys.scadeone.core.svc.cgmapping.model.ModelProbesGroup(path: str, kind: ProbeKind, *, projections: list[ModelGroupProjection] = <factory>)#
Bases:
ModelGroupGroup of probes sharing the same path.
Each probe in the group has the same
pathandkindand is distinguished by itsprojection(a list of label strings and positional integers).
- class ansys.scadeone.core.svc.cgmapping.model.ModelSensor(id: int, path: str, type: int)#
Bases:
ModelElementModel sensor.
- class ansys.scadeone.core.svc.cgmapping.model.ModelSizeParameter(id: int, name: str, value: int)#
Bases:
ModelElementModel monomorphization operator size parameter.
- class ansys.scadeone.core.svc.cgmapping.model.ModelStruct(id: int, fields: list[ModelStructField])#
Bases:
ModelElementModel structure type definition.
- Parameters:
- id
int Unique identifier for this struct type.
- fields
list[ModelStructField] List of fields in the structure.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelStructField(id: int, name: str, type: int)#
Bases:
ModelElementModel structure field.
- class ansys.scadeone.core.svc.cgmapping.model.ModelTypeParameter(id: int, name: str, type: int)#
Bases:
ModelElementModel monomorphization operator type parameter.
- class ansys.scadeone.core.svc.cgmapping.model.ModelVariable(id: int, name: str, projection: list[str | int] | None = None, _associated_probe: ModelProbe | None = None)#
Bases:
ModelElementModel variable.
- Parameters:
- id
int Unique identifier for this variable.
- name
str Name of the variable.
- projection
list[GroupProjection] |None Group projection for the variable.
- id
- get_associated_probe() ModelProbe | None#
Get the associated probe for this variable.
- class ansys.scadeone.core.svc.cgmapping.model.ModelVariablesGroup(name: str, *, projections: list[ModelGroupProjection] = <factory>)#
Bases:
ModelGroupGroup of model variables.
Each variable of a group shares the same group name and is characterized by its projection, which consists of a list of strings (named) and integers (positional) identifying the variable within the group structure.
- Parameters:
- name
str Shared group name.
- projections
list[ModelGroupProjection] Projected variables that belong to this group.
- name
- class ansys.scadeone.core.svc.cgmapping.model.ModelVariant(id: int, constructors: list[ModelVariantConstructor])#
Bases:
ModelElementModel variant type definition.
- Parameters:
- id
int Unique identifier for this variant type.
- constructors
list[ModelVariantConstructor] List of constructors for the variant.
- id
- class ansys.scadeone.core.svc.cgmapping.model.ModelVariantConstructor(id: int, name: str, type: int | None = None)#
Bases:
ModelElementModel variant type constructor.
- class ansys.scadeone.core.svc.cgmapping.model.OperatorBase(id: int, path: str, probes: list[ModelProbe | ModelProbesGroup], instances: list[ModelInstance])#
Bases:
HasProbesMixin,ModelElementBase class providing common operator methods for ModelOperator and ModelMonoOperator.
- get_context_type() CStruct | None#
Get the generated context type structure.
- Returns:
CStruct|NoneThe context type structure if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_context_typedef() CTypedef | None#
Get the generated context type typedef.
- Returns:
CTypedef|NoneThe context type typedef if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_cycle() CFunction | None#
Get the generated cycle function.
- Returns:
CFunction|NoneThe cycle function if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_function_name() str | None#
Get the generated operator name.
- Returns:
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_generated_element() None#
Model operators are associated to potentially multiple code elements (cycle method, init method, reset method, context struct, etc.) and thus don’t have a single role-less generated element. Consider using the dedicated methods to access the specific associated code elements instead.
- Returns:
NoneOperators do not have a single generated code element.
- get_header_name() str | None#
Get the generated header file name (.h).
- Returns:
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_init() CFunction | None#
Get the generated init function.
- Returns:
CFunction|NoneThe init function if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_input_struct_type() CStruct | None#
Get the generated input structure type.
- Returns:
CStruct|NoneThe input structure type if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_input_struct_typedef() CTypedef | None#
Get the generated input structure typedef.
- Returns:
CTypedef|NoneThe input structure typedef if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_obs_struct_type() CStruct | None#
Get the generated observation structure type.
- Returns:
CStruct|NoneThe observation structure type if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_obs_struct_typedef() CTypedef | None#
Get the generated observation structure typedef.
- Returns:
CTypedef|NoneThe observation structure typedef if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_output_struct_type() CStruct | None#
Get the generated output structure type.
- Returns:
CStruct|NoneThe output structure type if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_output_struct_typedef() CTypedef | None#
Get the generated output structure typedef.
- Returns:
CTypedef|NoneThe output structure typedef if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_reset() CFunction | None#
Get the generated reset function.
- Returns:
CFunction|NoneThe reset function if available, None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_source_name() str | None#
Get the generated source file name (.c).
- Returns:
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- is_function() bool#
Whether the operator is a function. An operator is a function if it is not a node. A function only has an associated cycle method. No init or reset methods.
- Returns:
- bool
True if this operator is a function, False otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- is_node() bool#
Whether the operator is a node. A node has associated init method, reset method and context in addition to a function operator.
- Returns:
- bool
True if this operator is a node, False otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.model.ProbeKind(*values)#
Bases:
EnumKind of probe in the model.
- ansys.scadeone.core.svc.cgmapping.model.load_model_from_json(model_data: list[tuple], registry: _ModelRegistry | None = None) _ModelRegistry#
Load model declarations from JSON data into a registry.
- ansys.scadeone.core.svc.cgmapping.model.parse_model_declaration(data: tuple[str, dict[str, Any]]) ModelDeclaration#
Parse a ModelDeclaration from JSON data.
- Parameters:
- data
tuple JSON data as a tuple [type_name, declaration_data].
- data
- Returns:
ModelDeclarationParsed declaration as a tuple (type_name, declaration_object).
- ansys.scadeone.core.svc.cgmapping.model.parse_model_instance(data: tuple[str, dict[str, Any]]) ModelInstance#
Parse a ModelInstance from JSON data.
- Parameters:
- data
tuple JSON data as a tuple [type_name, instance_data].
- data
- Returns:
ModelInstanceParsed instance as a tuple (type_name, instance_object).
- ansys.scadeone.core.svc.cgmapping.model.parse_model_mono_variable(data: dict) ModelMonoVariable#
Parse a ModelMonoVariable from JSON data.
- Parameters:
- data
dict JSON data for the monomorphized variable.
- data
- Returns:
ModelMonoVariableParsed monomorphized variable object.
- ansys.scadeone.core.svc.cgmapping.model.parse_model_size_parameter(data: dict) ModelSizeParameter#
Parse a ModelSizeParameter from JSON data.
- Parameters:
- data
dict JSON data for the size parameter.
- data
- Returns:
ModelSizeParameterParsed size parameter object.
- ansys.scadeone.core.svc.cgmapping.model.parse_model_type_parameter(data: dict) ModelTypeParameter#
Parse a ModelTypeParameter from JSON data.
- Parameters:
- data
dict JSON data for the type parameter.
- data
- Returns:
ModelTypeParameterParsed type parameter object.
- ansys.scadeone.core.svc.cgmapping.model.parse_model_variable(data: dict) ModelVariable#
Parse a ModelVariable from JSON data.
- Parameters:
- data
dict JSON data for the variable.
- data
- Returns:
ModelVariableParsed variable object.
- ansys.scadeone.core.svc.cgmapping.model.parse_probe(data: dict) ModelProbe#
Parse a Probe from JSON data.
- Parameters:
- data
dict JSON data for the probe.
- data
- Returns:
ProbeParsed probe object.
- ansys.scadeone.core.svc.cgmapping.model.GroupProjection = str | int#
Type alias for group projection
- type ansys.scadeone.core.svc.cgmapping.model.ModelDeclaration = tuple[str, ModelPredefinedType | ModelArray | ModelStruct | ModelEnum | ModelVariant | ModelNamedType | ModelConstant | ModelSensor | ModelOperator | ModelMonoOperator]#
Type alias for model declarations (discriminated union)
- type ansys.scadeone.core.svc.cgmapping.model.ModelInstance = tuple[str, ModelOperatorInstance | ModelLoopInstance]#
Type alias for model instances (discriminated union)