Skip to content

Working with code examples

Example with lines numbers

turbine_model.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from typing import List

from pydantic import BaseModel, Field


class SoilLayer(BaseModel):
    depth: float = Field(description="Depth from seabed to soil later")
    number_of_elements: int = Field(
        description="Number of elements of this material at this depth"
    )

class TurbineModel(BaseModel):
    soil_layers: List[SoilLayer]
    load_step_num: int = Field(
         default=20, ge=0, description="Number of load steps in cycle"
    )    
    # ... etc. for validation 

Example with highlighted lines

turbine_model.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from pydantic import BaseModel, Field


class SoilLayer(BaseModel):
    depth: float = Field(description="Depth from seabed to soil later")
    number_of_elements: int = Field(
        description="Number of elements of this material at this depth"
    )

class TurbineModel(BaseModel):
    soil_layers: list[SoilLayer]
    load_step_num: int = Field(
         default=20, ge=0, description="Number of load steps in cycle"
    )    
    # ... etc. for validation 

soil_layers = [{"depth": 0, "number_of_elements": 2},{"depth":2, "number_of_elements": 3}]

simulation_steps = 20

turbine_model = TurbineModel(
        soil_layers=soil_layers,
        load_step_num = simulation_steps
    )

print(f"My turbine model: {turbine_model}")