Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
[project]
name = "loadbearing-wall"
version = "0.1.0"
description = "Add your description here"
dynamic = ['version', 'description']
readme = "README.md"
authors = [
{ name = "Connor Ferster", email = "connorferster@gmail.com" }
{ name = "Connor Ferster", email = "connor@structuralpython.com" }
]
requires-python = ">=3.11"
dependencies = [
"load-distribution==0.1.4",
"pydantic>=2.0.0",
"safer>=5.1.0",
]

[project.scripts]
loadbearing-wall = "loadbearing_wall:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[dependency-groups]
dev = [
Expand Down
35 changes: 25 additions & 10 deletions src/loadbearing_wall/wall_model.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from dataclasses import dataclass, field
from pydantic import BaseModel, Field
import pathlib
from typing import Optional, Any, Union
import safer

from . import linear_reactions as lr
from . import point_reactions as pr
from . import geom_ops as geom


@dataclass
class LinearWallModel:
class LinearWallModel(BaseModel):
height: float
length: float
vertical_spread_angle: float = 0.0
distributed_loads: dict = field(
default_factory=dict
) # Check no side-effects for multiple instances
point_loads: dict = field(
default_factory=dict
) # Check no side-effects for multiple instances
distributed_loads: dict = Field(default={})
point_loads: dict = Field(default={})
gravity_dir: str = "z"
inplane_dir: str = "x"
out_of_plane_dir: str = "y"
Expand Down Expand Up @@ -57,6 +54,24 @@ class LinearWallModel:
end location
"""

@classmethod
def from_json(self, filepath: str | pathlib.Path):
with safer.open(filepath) as file:
json_data = file.read()
return self.model_validate_json(json_data)

def to_json(self, filepath: str | pathlib.Path, indent=2):
json_data = self.model_dump_json(indent=indent)
with safer.open(filepath, "w") as file:
file.write(json_data)

@classmethod
def from_dict(self, data: dict):
return self.model_validate(data)

def dump_dict(self):
return self.model_dump(mode="json")

def add_dist_load(
self,
magnitude_start: float,
Expand Down Expand Up @@ -203,7 +218,7 @@ def get_reactions(
direction_key: str = "dir",
case_key: str = "case",
):
self.spread_loads()
self.spread_loads() # Populates self._projected_loads
lrs = lr.LinearReactionString.from_projected_loads(
self._projected_loads,
self.magnitude_start_key,
Expand Down
58 changes: 58 additions & 0 deletions tempfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"height": 2.0,
"length": 4.0,
"vertical_spread_angle": 0.0,
"distributed_loads": {
"Fz": {
"D": [
{
"w1": 10.0,
"w2": 10.0,
"x1": 1.0,
"x2": 3.0
}
],
"L": [
{
"w1": 15.0,
"w2": 15.0,
"x1": 0.0,
"x2": 2.0
}
]
}
},
"point_loads": {
"Fz": {
"D": [
{
"w1": 100.0,
"x1": 0.5
}
],
"L": [
{
"w1": 100.0,
"x1": 0.5
}
]
},
"Fx": {
"W": [
{
"w1": 2000,
"x1": 0.0
}
]
}
},
"gravity_dir": "Fz",
"inplane_dir": "Fx",
"out_of_plane_dir": "y",
"apply_spread_angle_gravity": true,
"apply_spread_angle_inplane": true,
"magnitude_start_key": "w1",
"magnitude_end_key": "w2",
"location_start_key": "x1",
"location_end_key": "x2"
}
13 changes: 13 additions & 0 deletions tests/test_wall_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,16 @@ def test_45_spread(WM1):
"x2": 4.0,
},
]


def test_serialization(WM0):
serialized_dict = WM0.dump_dict()
reconstituted = LinearWallModel.from_dict(serialized_dict)
assert reconstituted == WM0

import pathlib

tempfile = pathlib.Path("tempfile.json")
WM0.to_json(tempfile)
recon2 = LinearWallModel.from_json(tempfile)
assert WM0 == recon2
Loading
Loading