Using enumerations for categorical data

Using integer values to describe categorical data, e.g. types of elements,types of DOFs, etc. is cumbersome and error prone. It forces developers to remember many 'magic' values.

Contrary to this, enumeration classes provide many advantages. Besides improving code readability they can also prevent many, hard to debug, errors. This is the reason that Nadamak package provides several enum types.

Contents

Enums for DOF types

enumeration mp.FEM.DofType
Enumeration members for class 'mp.FEM.DofType':

    Temperature
    Displacement
    Stress
    Strain

To create enumeration value

dt = mp.FEM.DofType.Temperature
dt = 

    Temperature

To make syntax shorter one can also import the enum class

import mp.FEM.DofType
dt = DofType.Temperature;

Instead of using enum tags one can use conversion from strings

dt = DofType('Temperature')
dt = 

    Temperature

It is also possible to use abreviated names and different cases, as long as the conversion is unique

dt = DofType('temp')
dt = 

    Temperature

To convert enumeration value to string

disp(char(dt))
Temperature

To convert enumeration value to integer

disp(int32(dt))
   0

Enums for finite element types

enumeration mp.FEM.FemType
Enumeration members for class 'mp.FEM.FemType':

    Line2
    Line3
    Triang3
    Triang6
    Triang10
    Quad4
    Quad8
    Quad9
    Hex8

Enums for boundary condition types

enumeration mp.BcType
Enumeration members for class 'mp.BcType':

    NotSet
    Temperature
    HeatFlux
    Insulation
    Displacement
    Fixity
    FixityX
    FixityY
    FixityZ
    FixityXY
    FixityXZ
    FixityYZ
    Pressure
    Traction
    Force

Check if value is an enum or object of given class

dt = DofType('temp');

Check if value is enum type

isenum(dt)
ans =

  logical

   1

Check if value is an object of given class

isa(dt, 'mp.FEM.BcType')
ans =

  logical

   0

Internal management of demo. Do not call if reporducing this demo

mp_manage_demos('report', 'mp_enumerations', true);