Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b38a150
Initial plan
Copilot Feb 10, 2026
7bf169e
Add ActivationFunction class and rename PiecewiseCosineChamber to Lin…
Copilot Feb 10, 2026
980cec7
Refactor ChamberElastanceInductor and LinearElastanceChamber to use A…
Copilot Feb 10, 2026
2f7c593
Add test cases for two hill activation function
Copilot Feb 10, 2026
88e0ad1
Address code review comments: improve readability and documentation
Copilot Feb 10, 2026
0b2ecf0
Add documentation for activation functions
Copilot Feb 10, 2026
b68ffd5
Support string activation_function_type and nested activation_functio…
Copilot Feb 10, 2026
2a7a9d2
Refactor initialize_activation_function to use factory method in Acti…
Copilot Feb 10, 2026
6c18357
Make activation function parameters members of ActivationFunction ins…
Copilot Feb 10, 2026
fbc1dc8
Store cardiac_period as member of ActivationFunction base class
Copilot Feb 10, 2026
0f53d8c
Make PiecewiseCosineChamber an alias to LinearElastanceChamber for ba…
Copilot Feb 10, 2026
7038e2d
Remove backward compatibility code and require activation_type parameter
Copilot Feb 10, 2026
aa4787d
Remove activation function parameters from LinearElastanceChamber and…
Copilot Feb 10, 2026
5d80d12
Remove PiecewiseCosineChamber from factory registration and type checks
Copilot Feb 10, 2026
8031791
Remove PiecewiseCosineChamber completely - no longer needed with acti…
Copilot Feb 10, 2026
0ce3c32
Improve error reporting to list all missing parameters at once
Copilot Feb 11, 2026
3c41770
Fix BlockType enum values to be sequential (piecewise_valve = 17, lin…
Copilot Feb 11, 2026
6d09f57
Fix compilation error: use vector size check instead of non-existent …
Copilot Feb 12, 2026
b0aa76c
Make activation_type a required parameter for ChamberElastanceInductor
Copilot Feb 12, 2026
0a9dc48
Remove backward compatibility for numeric activation_type parameter -…
Copilot Feb 12, 2026
fe33a80
Update chamber_elastance_inductor test case with activation function
aabrown100-git Feb 12, 2026
ffddd68
Update documentation to reflect mandatory string-based activation_fun…
Copilot Feb 12, 2026
28d2faa
Add comprehensive validation for activation_function_type and activat…
Copilot Feb 12, 2026
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
1 change: 1 addition & 0 deletions _codeql_detected_source_root
162 changes: 162 additions & 0 deletions docs/pages/activation_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Activation Functions for Chamber Models

## Overview

Chamber models in svZeroDSolver support different activation functions to model the time-varying elastance of cardiac chambers. The activation function determines how the chamber contracts and relaxes over the cardiac cycle.

## Available Activation Functions

### 1. Half Cosine Activation

A half cosine wave activation function to model contraction:

```
A(t) = -0.5 * cos(2π * t_contract / t_twitch) + 0.5 if t_contract ≤ t_twitch
A(t) = 0 otherwise
```

where `t_contract = max(0, t - t_active)`

**Parameters:**
- `t_active`: Time when activation begins within the cardiac cycle
- `t_twitch`: Duration of the contraction twitch

**Example usage in JSON:**
```json
{
"type": "ChamberElastanceInductor",
"name": "ventricle",
"values": {
"Emax": 1.057,
"Emin": 0.091,
"Vrd": 26.1,
"Vrs": 18.0,
"Impedance": 0.000351787,
"activation_function_type": "half_cosine",
"activation_function_values": {
"t_active": 0.2,
"t_twitch": 0.3
}
}
}
```

### 2. Piecewise Cosine Activation

A piecewise activation function that models separate contraction and relaxation phases:

```
φ(t) = 0.5 * [1 - cos(π * (t - t_C) / T_C)] during contraction
φ(t) = 0.5 * [1 + cos(π * (t - t_R) / T_R)] during relaxation
φ(t) = 0 otherwise
```

**Parameters:**
- `contract_start`: Time when contraction starts
- `relax_start`: Time when relaxation starts
- `contract_duration`: Duration of contraction phase
- `relax_duration`: Duration of relaxation phase

**Example usage in JSON:**
```json
{
"type": "LinearElastanceChamber",
"name": "left_atrium",
"values": {
"Emax": 199.95,
"Epass": 260.59,
"Vrest": 26.24,
"activation_function_type": "piecewise_cosine",
"activation_function_values": {
"contract_start": 0.025,
"relax_start": 0.08625,
"contract_duration": 0.06125,
"relax_duration": 0.18375
}
}
}
```

### 3. Two Hill Activation

A more flexible and physiologically realistic activation function based on the two-hill model. This allows for more precise control over the activation waveform shape.

The activation is computed as:
```
A(t) = C * [g₁(t) / (1 + g₁(t))] * [1 / (1 + g₂(t))]
```

where:
```
g₁(t) = (t_shifted / τ₁)^m₁
g₂(t) = (t_shifted / τ₂)^m₂
t_shifted = (t - t_shift) mod T_cardiac
```

C is a normalization constant ensuring maximum activation is 1.

**Parameters:**
- `t_shift`: Time shift parameter to align activation with cardiac cycle
- `tau_1`: Time constant for first hill (controls rise)
- `tau_2`: Time constant for second hill (controls fall)
- `m1`: Exponent for first hill (controls steepness of rise)
- `m2`: Exponent for second hill (controls steepness of fall)

**Example usage in JSON:**
```json
{
"type": "ChamberElastanceInductor",
"name": "ventricle",
"values": {
"Emax": 1.057,
"Emin": 0.091,
"Vrd": 26.1,
"Vrs": 18.0,
"Impedance": 0.000351787,
"activation_function_type": "two_hill",
"activation_function_values": {
"t_shift": 0.15,
"tau_1": 0.25,
"tau_2": 0.35,
"m1": 1.5,
"m2": 10.0
}
}
}
```

## Switching Between Activation Functions

**Both `ChamberElastanceInductor` and `LinearElastanceChamber` require the `activation_function_type` parameter to be explicitly specified as a string:**

- `activation_function_type: "half_cosine"` - Half Cosine activation
- `activation_function_type: "piecewise_cosine"` - Piecewise Cosine activation
- `activation_function_type: "two_hill"` - Two Hill activation

All activation function-specific parameters must be grouped under `activation_function_values` as a nested dictionary.

### Important Notes

- The `activation_function_type` parameter is **required** for both chamber types
- Only string values are accepted (e.g., "half_cosine", not numeric values)
- Parameters must be specified within the `activation_function_values` nested dictionary

## Elastance Calculation

For all activation functions, the time-varying elastance E(t) is computed as:

**For ChamberElastanceInductor:**
```
E(t) = (Emax - Emin) * A(t) + Emin
Vrest(t) = (1 - A(t)) * (Vrd - Vrs) + Vrs
```

**For LinearElastanceChamber:**
```
E(t) = Epass + Emax * φ(t)
```

## References

The two-hill activation function is described in:
- Kaiser, A. D., et al. (2022). "A design-based model of the aortic valve for fluid-structure interaction." Biomechanics and Modeling in Mechanobiology. https://link.springer.com/article/10.1007/s10439-022-03047-3
Loading
Loading