Skip to content

Open-source Revit MCP server: let Claude and other AI assistants read and edit BIM models, with human approval on every change.

Scaffold 4, Tasks 4.2 & 4.3: MEP sizing and clearance validation

sammohammad57858e07f4c135e
diff --git a/packages/model-checker/src/model_checker/mep.py b/packages/model-checker/src/model_checker/mep.py
index 22a2efa..224d852 100644
--- a/packages/model-checker/src/model_checker/mep.py
+++ b/packages/model-checker/src/model_checker/mep.py
@@ -271,3 +271,219 @@ class MEPConnectivityValidator:
Count of issues
"""
return len(self.issues)
+
+
+class MEPSizingValidator:
+ """Validator for MEP duct and pipe sizing."""
+
+ def __init__(self) -> None:
+ """Initialize MEP sizing validator."""
+ self.issues: list[MEPConnectivityIssue] = []
+
+ def validate_duct_sizing(
+ self,
+ ducts: list[dict[str, Any]],
+ max_velocity: float = 10.0, # m/s
+ min_size: float = 100.0, # mm
+ max_size: float = 2000.0, # mm
+ ) -> list[MEPConnectivityIssue]:
+ """Validate duct sizing parameters.
+
+ Args:
+ ducts: List of ducts with 'id', 'width', 'height', 'flow_rate', 'velocity'
+ max_velocity: Maximum allowed velocity in m/s
+ min_size: Minimum duct dimension in mm
+ max_size: Maximum duct dimension in mm
+
+ Returns:
+ List of sizing issues
+ """
+ issues = []
+
+ for duct in ducts:
+ width = duct.get("width", 0)
+ height = duct.get("height", 0)
+ velocity = duct.get("velocity", 0)
+
+ # Check minimum size
+ if width < min_size or height < min_size:
+ issue = MEPConnectivityIssue(
+ element_id=duct["id"],
+ element_type="duct",
+ issue_type="undersized",
+ description=f"Duct size {width}x{height}mm is below minimum {min_size}mm",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ # Check maximum size
+ if width > max_size or height > max_size:
+ issue = MEPConnectivityIssue(
+ element_id=duct["id"],
+ element_type="duct",
+ issue_type="oversized",
+ description=f"Duct size {width}x{height}mm exceeds maximum {max_size}mm",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ # Check velocity
+ if velocity > max_velocity:
+ issue = MEPConnectivityIssue(
+ element_id=duct["id"],
+ element_type="duct",
+ issue_type="excessive_velocity",
+ description=f"Duct velocity {velocity:.1f} m/s exceeds maximum {max_velocity} m/s",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ return issues
+
+ def validate_pipe_sizing(
+ self,
+ pipes: list[dict[str, Any]],
+ max_velocity: float = 3.0, # m/s for pipes
+ min_diameter: float = 15.0, # mm
+ max_diameter: float = 600.0, # mm
+ ) -> list[MEPConnectivityIssue]:
+ """Validate pipe sizing parameters.
+
+ Args:
+ pipes: List of pipes with 'id', 'diameter', 'flow_rate', 'velocity'
+ max_velocity: Maximum allowed velocity in m/s
+ min_diameter: Minimum pipe diameter in mm
+ max_diameter: Maximum pipe diameter in mm
+
+ Returns:
+ List of sizing issues
+ """
+ issues = []
+
+ for pipe in pipes:
+ diameter = pipe.get("diameter", 0)
+ velocity = pipe.get("velocity", 0)
+
+ # Check minimum diameter
+ if diameter < min_diameter:
+ issue = MEPConnectivityIssue(
+ element_id=pipe["id"],
+ element_type="pipe",
+ issue_type="undersized",
+ description=f"Pipe diameter {diameter}mm is below minimum {min_diameter}mm",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ # Check maximum diameter
+ if diameter > max_diameter:
+ issue = MEPConnectivityIssue(
+ element_id=pipe["id"],
+ element_type="pipe",
+ issue_type="oversized",
+ description=f"Pipe diameter {diameter}mm exceeds maximum {max_diameter}mm",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ # Check velocity
+ if velocity > max_velocity:
+ issue = MEPConnectivityIssue(
+ element_id=pipe["id"],
+ element_type="pipe",
+ issue_type="excessive_velocity",
+ description=f"Pipe velocity {velocity:.1f} m/s exceeds maximum {max_velocity} m/s",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ return issues
+
+ def get_issues(self) -> list[MEPConnectivityIssue]:
+ """Get all sizing issues."""
+ return self.issues
+
+ def clear_issues(self) -> None:
+ """Clear all issues."""
+ self.issues = []
+
+
+class MEPClearanceValidator:
+ """Validator for MEP clearance requirements."""
+
+ def __init__(self) -> None:
+ """Initialize clearance validator."""
+ self.issues: list[MEPConnectivityIssue] = []
+
+ def validate_headroom_clearance(
+ self,
+ mep_elements: list[dict[str, Any]],
+ min_clearance: float = 2100.0, # mm from floor
+ ) -> list[MEPConnectivityIssue]:
+ """Validate minimum headroom clearance for MEP elements.
+
+ Args:
+ mep_elements: List of MEP elements with 'id', 'type', 'elevation', 'height'
+ min_clearance: Minimum clearance from floor in mm
+
+ Returns:
+ List of clearance issues
+ """
+ issues = []
+
+ for element in mep_elements:
+ elevation = element.get("elevation", 0)
+ height = element.get("height", 0)
+ bottom = elevation - height / 2 # Assuming height is total height
+
+ if bottom < min_clearance:
+ issue = MEPConnectivityIssue(
+ element_id=element["id"],
+ element_type=element.get("type", "mep_element"),
+ issue_type="insufficient_headroom",
+ description=f"{element.get('type', 'Element')} at {bottom:.0f}mm is below minimum clearance {min_clearance}mm",
+ location={"z": bottom},
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ return issues
+
+ def validate_access_clearance(
+ self,
+ equipment: list[dict[str, Any]],
+ min_access_clearance: float = 600.0, # mm
+ ) -> list[MEPConnectivityIssue]:
+ """Validate access clearance around equipment.
+
+ Args:
+ equipment: List of equipment with 'id', 'type', 'access_clearance'
+ min_access_clearance: Minimum required clearance in mm
+
+ Returns:
+ List of clearance issues
+ """
+ issues = []
+
+ for equip in equipment:
+ clearance = equip.get("access_clearance", 0)
+
+ if clearance < min_access_clearance:
+ issue = MEPConnectivityIssue(
+ element_id=equip["id"],
+ element_type=equip.get("type", "equipment"),
+ issue_type="insufficient_access",
+ description=f"{equip.get('type', 'Equipment')} has only {clearance}mm clearance, needs {min_access_clearance}mm",
+ )
+ issues.append(issue)
+ self.issues.append(issue)
+
+ return issues
+
+ def get_issues(self) -> list[MEPConnectivityIssue]:
+ """Get all clearance issues."""
+ return self.issues
+
+ def clear_issues(self) -> None:
+ """Clear all issues."""
+ self.issues = []
diff --git a/packages/model-checker/tests/test_mep_sizing.py b/packages/model-checker/tests/test_mep_sizing.py
new file mode 100644
index 0000000..7ae3699
--- /dev/null
+++ b/packages/model-checker/tests/test_mep_sizing.py
@@ -0,0 +1,186 @@
+"""Test MEP sizing and clearance validation."""
+
+import pytest
+
+from model_checker.mep import MEPClearanceValidator, MEPSizingValidator
+
+
+# Sizing Tests
+def test_validate_duct_sizing_valid():
+ """Test validating properly sized ducts."""
+ validator = MEPSizingValidator()
+
+ ducts = [
+ {"id": "duct_1", "width": 500, "height": 300, "velocity": 8.0},
+ {"id": "duct_2", "width": 400, "height": 400, "velocity": 9.5},
+ ]
+
+ issues = validator.validate_duct_sizing(ducts, max_velocity=10.0)
+ assert len(issues) == 0
+
+
+def test_validate_duct_undersized():
+ """Test detecting undersized ducts."""
+ validator = MEPSizingValidator()
+
+ ducts = [{"id": "duct_1", "width": 50, "height": 50, "velocity": 5.0}]
+
+ issues = validator.validate_duct_sizing(ducts, min_size=100.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "undersized"
+
+
+def test_validate_duct_oversized():
+ """Test detecting oversized ducts."""
+ validator = MEPSizingValidator()
+
+ ducts = [{"id": "duct_1", "width": 2500, "height": 1500, "velocity": 5.0}]
+
+ issues = validator.validate_duct_sizing(ducts, max_size=2000.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "oversized"
+
+
+def test_validate_duct_excessive_velocity():
+ """Test detecting excessive duct velocity."""
+ validator = MEPSizingValidator()
+
+ ducts = [{"id": "duct_1", "width": 300, "height": 300, "velocity": 15.0}]
+
+ issues = validator.validate_duct_sizing(ducts, max_velocity=10.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "excessive_velocity"
+
+
+def test_validate_pipe_sizing_valid():
+ """Test validating properly sized pipes."""
+ validator = MEPSizingValidator()
+
+ pipes = [
+ {"id": "pipe_1", "diameter": 50, "velocity": 2.0},
+ {"id": "pipe_2", "diameter": 100, "velocity": 2.5},
+ ]
+
+ issues = validator.validate_pipe_sizing(pipes, max_velocity=3.0)
+ assert len(issues) == 0
+
+
+def test_validate_pipe_undersized():
+ """Test detecting undersized pipes."""
+ validator = MEPSizingValidator()
+
+ pipes = [{"id": "pipe_1", "diameter": 10, "velocity": 2.0}]
+
+ issues = validator.validate_pipe_sizing(pipes, min_diameter=15.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "undersized"
+
+
+def test_validate_pipe_oversized():
+ """Test detecting oversized pipes."""
+ validator = MEPSizingValidator()
+
+ pipes = [{"id": "pipe_1", "diameter": 800, "velocity": 1.0}]
+
+ issues = validator.validate_pipe_sizing(pipes, max_diameter=600.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "oversized"
+
+
+def test_validate_pipe_excessive_velocity():
+ """Test detecting excessive pipe velocity."""
+ validator = MEPSizingValidator()
+
+ pipes = [{"id": "pipe_1", "diameter": 25, "velocity": 5.0}]
+
+ issues = validator.validate_pipe_sizing(pipes, max_velocity=3.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "excessive_velocity"
+
+
+# Clearance Tests
+def test_validate_headroom_clearance_valid():
+ """Test validating proper headroom clearance."""
+ validator = MEPClearanceValidator()
+
+ elements = [
+ {"id": "duct_1", "type": "duct", "elevation": 2500, "height": 300},
+ {"id": "pipe_1", "type": "pipe", "elevation": 2400, "height": 100},
+ ]
+
+ issues = validator.validate_headroom_clearance(elements, min_clearance=2100.0)
+ assert len(issues) == 0
+
+
+def test_validate_headroom_insufficient():
+ """Test detecting insufficient headroom."""
+ validator = MEPClearanceValidator()
+
+ elements = [
+ {"id": "duct_1", "type": "duct", "elevation": 2200, "height": 400}
+ ] # Bottom at 2000mm
+
+ issues = validator.validate_headroom_clearance(elements, min_clearance=2100.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "insufficient_headroom"
+
+
+def test_validate_access_clearance_valid():
+ """Test validating proper access clearance."""
+ validator = MEPClearanceValidator()
+
+ equipment = [
+ {"id": "ahu_1", "type": "air_handler", "access_clearance": 800},
+ {"id": "pump_1", "type": "pump", "access_clearance": 1000},
+ ]
+
+ issues = validator.validate_access_clearance(equipment, min_access_clearance=600.0)
+ assert len(issues) == 0
+
+
+def test_validate_access_insufficient():
+ """Test detecting insufficient access clearance."""
+ validator = MEPClearanceValidator()
+
+ equipment = [{"id": "ahu_1", "type": "air_handler", "access_clearance": 400}]
+
+ issues = validator.validate_access_clearance(equipment, min_access_clearance=600.0)
+ assert len(issues) == 1
+ assert issues[0].issue_type == "insufficient_access"
+
+
+def test_complete_mep_sizing_workflow():
+ """Test complete MEP sizing and clearance validation."""
+ sizing_validator = MEPSizingValidator()
+ clearance_validator = MEPClearanceValidator()
+
+ # Validate duct sizing
+ ducts = [
+ {"id": "duct_1", "width": 500, "height": 300, "velocity": 8.0}, # OK
+ {"id": "duct_2", "width": 50, "height": 50, "velocity": 5.0}, # Undersized
+ {"id": "duct_3", "width": 600, "height": 400, "velocity": 12.0}, # Excessive velocity
+ ]
+
+ # Validate pipe sizing
+ pipes = [
+ {"id": "pipe_1", "diameter": 50, "velocity": 2.0}, # OK
+ {"id": "pipe_2", "diameter": 10, "velocity": 1.5}, # Undersized
+ {"id": "pipe_3", "diameter": 100, "velocity": 4.0}, # Excessive velocity
+ ]
+
+ # Validate clearances
+ elements = [
+ {"id": "duct_4", "type": "duct", "elevation": 2200, "height": 400}, # Insufficient headroom
+ ]
+
+ equipment = [
+ {"id": "ahu_1", "type": "air_handler", "access_clearance": 400} # Insufficient access
+ ]
+
+ sizing_validator.validate_duct_sizing(ducts)
+ sizing_validator.validate_pipe_sizing(pipes)
+ clearance_validator.validate_headroom_clearance(elements)
+ clearance_validator.validate_access_clearance(equipment)
+
+ assert len(sizing_validator.get_issues()) == 4 # 2 ducts + 2 pipes
+ assert len(clearance_validator.get_issues()) == 2 # 1 headroom + 1 access