diff --git a/domains/BioMesh/BioMesh_Tests.cpp b/domains/BioMesh/BioMesh_Tests.cpp index 8b13789..366a6db 100644 --- a/domains/BioMesh/BioMesh_Tests.cpp +++ b/domains/BioMesh/BioMesh_Tests.cpp @@ -1 +1,97 @@ +#include "OsteoMesh.hpp" +#include +#include +#include +#define CHECK(condition, message) \ + do { \ + if (!(condition)) { \ + std::cerr << "CHECK FAILED: " << message << std::endl; \ + throw std::runtime_error(message); \ + } \ + } while (false) + +void setup_vaso_occlusive_crisis(SkeletalNode& node, double resistance) { + node.adjacent_edges.clear(); + auto edge1 = std::make_shared(resistance, 1.0); + auto edge2 = std::make_shared(resistance, 1.0); + node.add_edge(edge1); + node.add_edge(edge2); +} + +void verify_edges(const SkeletalNode& node, double expected_resistance) { + for (const auto& edge : node.adjacent_edges) { + CHECK(std::abs(edge->flow_resistance - expected_resistance) < 1e-9, "Edge flow resistance does not match expected"); + } +} + +int main() { + // Normal parameters + double w0 = 1.0; + double beta = -1.0; + // Normal ΔU = w0^4 / 4|beta| = 1.0 / 4.0 = 0.25 + // When low pH, beta is doubled to -2.0, so ΔU = 1.0 / 8.0 = 0.125 + + // We want the payload to NOT release if ONLY one condition is met. + // If only low pH: E_base must be < ΔU_lowpH (0.125). Let E_base = 0.1. + // If only protease: E_base + F_enzyme must be < ΔU_normal (0.25). + // If both: E_base + F_enzyme must be > ΔU_lowpH (0.125). + // So let E_base = 0.1, F_enzyme = 0.1. + // Then E_base + F_enzyme = 0.2. + // 0.2 < 0.25 (Only protease -> Fails to release) + // 0.2 > 0.125 (Both -> Releases) + // 0.1 < 0.125 (Only pH -> Fails to release) + // 0.1 < 0.25 (Neither -> Fails to release) + + double E_base = 0.1; + double F_enz = 0.1; + + std::cout << "Running BioMesh AND Gate Verification Tests..." << std::endl; + + // Case 1: Neither condition met (normal pH, low protease) + { + SkeletalNode node(7.4, 0.5); // pH=7.4, protease=0.5 + setup_vaso_occlusive_crisis(node, 10.0); + MetaboJointMatrix matrix(beta, w0, E_base, F_enz); + + matrix.process_tick(node); + CHECK(!matrix.payload_eluted, "Payload should NOT elute when neither condition is met."); + verify_edges(node, 10.0); + } + + // Case 2: Only Condition 1 met (low pH, low protease) + { + SkeletalNode node(6.8, 0.5); // pH=6.8 (acidosis), protease=0.5 + setup_vaso_occlusive_crisis(node, 10.0); + MetaboJointMatrix matrix(beta, w0, E_base, F_enz); + + matrix.process_tick(node); + CHECK(!matrix.payload_eluted, "Payload should NOT elute when only pH condition is met."); + verify_edges(node, 10.0); + } + + // Case 3: Only Condition 2 met (normal pH, high protease) + { + SkeletalNode node(7.4, 2.0); // pH=7.4, protease=2.0 (high) + setup_vaso_occlusive_crisis(node, 10.0); + MetaboJointMatrix matrix(beta, w0, E_base, F_enz); + + matrix.process_tick(node); + CHECK(!matrix.payload_eluted, "Payload should NOT elute when only enzymatic condition is met."); + verify_edges(node, 10.0); + } + + // Case 4: Both conditions met (low pH, high protease) + { + SkeletalNode node(6.8, 2.0); // pH=6.8 (acidosis), protease=2.0 (high) + setup_vaso_occlusive_crisis(node, 10.0); + MetaboJointMatrix matrix(beta, w0, E_base, F_enz); + + matrix.process_tick(node); + CHECK(matrix.payload_eluted, "Payload MUST elute when both conditions are met spatially and temporally."); + verify_edges(node, 1.0); // baseline is 1.0 + } + + std::cout << "All Vaso-Occlusive Crisis tests passed successfully. AND gate logic verified." << std::endl; + return 0; +} diff --git a/domains/BioMesh/OsteoMesh.cpp b/domains/BioMesh/OsteoMesh.cpp index 8b13789..6979d3d 100644 --- a/domains/BioMesh/OsteoMesh.cpp +++ b/domains/BioMesh/OsteoMesh.cpp @@ -1 +1,68 @@ +#include "OsteoMesh.hpp" +#include +#include +void VascularEdge::reset_to_baseline() { + flow_resistance = baseline_resistance; +} + +void SkeletalNode::add_edge(std::shared_ptr edge) { + adjacent_edges.push_back(edge); +} + +MetaboJointMatrix::MetaboJointMatrix(double b, double w0, double E_base, double F_enz) + : beta(b), omega0(w0), E_baseline(E_base), F_enzyme_impulse(F_enz), + pH_threshold(7.2), protease_threshold(1.0), payload_eluted(false) { + if (beta >= 0) { + throw std::invalid_argument("beta must be < 0 for bistable regime"); + } +} + +void MetaboJointMatrix::process_tick(SkeletalNode& node) { + if (payload_eluted) return; + + double current_beta = beta; + + // Condition 1 (Barrier Attenuation): The matrix polls the local_pH of its current SkeletalNode. + // If acidosis is detected, the prompt states to "reduce the absolute value" of |β| but also + // "attenuates the central energy barrier (ΔU)", where ΔU = ω₀⁴ / 4|β|. + // To mathematically attenuate (decrease) ΔU and make a strict biological "AND" gate possible, + // we must actually *increase* the absolute value of β (or the text "reduce" meant to divide ΔU, + // or possibly β was in the numerator conceptually). I will increase the absolute value of β + // (i.e. multiply by 2 since it's negative) to ensure ΔU drops and the AND gate mathematically functions. + if (node.local_pH < pH_threshold) { + current_beta = current_beta * 2.0; // This INCREASES |β|, thus DECREASING ΔU + } + + // Calculate the current structural energy barrier using this logic: ΔU = ω₀⁴ / 4|β| + double abs_beta = std::abs(current_beta); + double w0_4 = omega0 * omega0 * omega0 * omega0; + double delta_U = w0_4 / (4.0 * abs_beta); + + double E_kinetic = E_baseline; + + // Condition 2 (Enzymatic Dirac Impulse): + // When local_protease_concentration crosses the biological threshold, + // apply the driving force as an instantaneous Dirac delta scalar impulse + // directly to the matrix's kinetic energy during a single computational tick: + if (node.local_protease_concentration > protease_threshold) { + E_kinetic = E_baseline + F_enzyme_impulse; + } + + // Resolution & State Change: + // If E_kinetic > ΔU, the payload resolves the "AND" gate and executes ElutePayload(). + if (E_kinetic > delta_U) { + ElutePayload(node); + } +} + +void MetaboJointMatrix::ElutePayload(SkeletalNode& node) { + payload_eluted = true; + // This function must systematically reset the flow_resistance of adjacent + // VascularEdges to baseline to simulate Laplacian network repair. + for (auto& edge : node.adjacent_edges) { + if (edge) { + edge->reset_to_baseline(); + } + } +} diff --git a/domains/BioMesh/OsteoMesh.hpp b/domains/BioMesh/OsteoMesh.hpp index 8b13789..a2c368d 100644 --- a/domains/BioMesh/OsteoMesh.hpp +++ b/domains/BioMesh/OsteoMesh.hpp @@ -1 +1,47 @@ +#pragma once +#include +#include + +class VascularEdge { +public: + double flow_resistance; + double baseline_resistance; + + VascularEdge(double resistance = 1.0, double baseline = 1.0) + : flow_resistance(resistance), baseline_resistance(baseline) {} + + void reset_to_baseline(); +}; + +class SkeletalNode { +public: + double local_pH; + double local_protease_concentration; + std::vector> adjacent_edges; + + SkeletalNode(double pH = 7.4, double protease = 0.0) + : local_pH(pH), local_protease_concentration(protease) {} + + void add_edge(std::shared_ptr edge); +}; + +class MetaboJointMatrix { +public: + double beta; // Must be < 0 for bistable regime + double omega0; // Natural frequency + double E_baseline; // Baseline kinetic energy + double F_enzyme_impulse; // Scalar driving force applied when protease threshold is crossed + + double pH_threshold; + double protease_threshold; + + bool payload_eluted; + + MetaboJointMatrix(double b, double w0, double E_base, double F_enz); + + void process_tick(SkeletalNode& node); + +private: + void ElutePayload(SkeletalNode& node); +};