#> Loading required package: floodam.building
library(floodam.building)
# set up a temporary model folder
model_root = file.path(tempdir(), "floodam-generated-model")
model_path = list(
data = file.path(model_root),
output = file.path(model_root, "output")
)
model_dir = file.path(model_path[["data"]], "model", "generated", "generated_model")
# create this directory where you want to create the model
dir.create(model_dir, recursive = TRUE)
Generate a simple building model
2026-06-29
Generate a simple building model
This vignette shows how to generate a simple building layout with generate_model(), inspect the generated geometry, and prepare it for analysis by converting it into a YAML-compatible building structure. The goal is to give you a fast, repeatable way to build test cases and prototype flood vulnerability workflows without starting from an existing input file.
Generate a model
First of all we need to load the package and set up a temporary folder to store the generated model.
The generate_model() function creates a simple building layout with a specified number of rooms and total floor area. You can also specify wall thicknesses (m) for exterior and interior walls.
model_coordinate = generate_model(
n_room = 5,
surface = 80,
thickness_wall_ext = 0.4,
thickness_wall_int = 0.15
)The returned object is a list. The most important components are:
| Name | Type | Description |
|---|---|---|
exterior |
matrix | Exterior building polygon coordinates (closed loop) |
room_1, room_2, … |
matrix | Individual room polygons |
door |
list | Doors connecting rooms and the exterior |
window |
list | Exterior windows for outside-facing rooms |
You can plot the generated layout to visualise rooms, doors and windows to check if the generated model meets your needs.
plot_model_coordinate(model_coordinate)
- The plot shows:
- the building outline in gray,
- each room polygon in white,
- doors as red points,
- windows as blue triangles.
You can compute floor areas for the exterior envelope and the individual rooms.
compute_surface_model(model_coordinate)| exterior | interior |
|---|---|
| 80.00000 | 62.95798 |
| exterior | room_1 | room_2 | room_3 | room_4 | room_5 |
|---|---|---|---|---|---|
| 80.00000 | 7.698704 | 7.698704 | 15.853525 | 15.853525 | 15.853525 |
Convert to a YAML-like structure
As for now, you this object is not a model yet. Therefore you can’t use any of the analysis (analyse_model() and analyse_hydraulic()) functions on it. You need to convert it into a YAML-like structure and save it. You can also generate a furniture CSV file to define the interior layout. The provided function generate_furniture_csv() creates a very simple furniture layout. You can edit the CSV file to customize the furniture placement if needed.
model_structure = convert_model_to_yaml_structure(model_coordinate, thickness_wall_ext = .4, thickness_wall_int = .15)
yaml::write_yaml(model_structure, file.path(model_dir, "building.yaml"))
generate_furniture_csv(model_coordinate, file.path(model_dir, "furniture.csv"))Final model
These files create a complete, loadable building model structure. Once the YAML and furniture files are written, you can use analyse_model() to import the generated building and run the package analysis pipeline.
model = analyse_model(
model = "generated_model",
type = "generated",
stage = c("load", "extract", "damaging", "hydraulic", "display"),
type_building = "yaml",
path = model_path
)
Congratulations! You got you model of your own.You can now use the model object to generate limnigraphs, run hydraulic and damage analysis, and visualize results as needed.