diff --git a/addons/PhysiMeSS/PhysiMeSS.cpp b/addons/PhysiMeSS/PhysiMeSS.cpp index 0201c9b56..effcaad58 100644 --- a/addons/PhysiMeSS/PhysiMeSS.cpp +++ b/addons/PhysiMeSS/PhysiMeSS.cpp @@ -73,6 +73,11 @@ void physimess_update_cell_velocity( Cell* pCell, Phenotype& phenotype, double d } // std::cout << " AGENT " << pCell->type_name << " " << pCell->ID << " has " ; + if (!isFibre(pCell)) { + static_cast(pCell)->fibre_contact_damping = 0.0; + static_cast(pCell)->fibre_contact_orientation.assign(3, 0.0); + } + //add potentials between pCell and its neighbors for (auto* neighbor : static_cast(pCell)->physimess_neighbors) { @@ -102,6 +107,7 @@ void physimess_update_cell_velocity( Cell* pCell, Phenotype& phenotype, double d if (!isFibre(pCell)) { PhysiMeSS_Cell* ppCell = static_cast(pCell); + int stuck_threshold = 10; int unstuck_threshold = 1; @@ -117,13 +123,28 @@ void physimess_update_cell_velocity( Cell* pCell, Phenotype& phenotype, double d << PhysiCell_globals.current_time << std::endl;*/ ppCell->unstuck_counter++; ppCell->force_update_motility_vector(dt); - ppCell->velocity += phenotype.motility.motility_vector; } else { pCell->update_motility_vector(dt); - pCell->velocity += phenotype.motility.motility_vector; } + // Fibre contact damping: scale the motility component perpendicular to the + // most strongly contacting fibre by (1 - c), c = vel_contact*(1 - xi^2) in [0,1]. + // This acts on the active velocity only (not on v_prev or the repulsion), + // so it cannot feed velocity back into itself. + std::vector motility = phenotype.motility.motility_vector; + double c = std::min(1.0, std::max(0.0, ppCell->fibre_contact_damping)); + if (c > 0.0) { + const std::vector& o = ppCell->fibre_contact_orientation; + double m_par = 0.0; + for (int j = 0; j < 3; j++) { m_par += motility[j] * o[j]; } + for (int j = 0; j < 3; j++) { + double par = m_par * o[j]; + motility[j] = par + (1.0 - c) * (motility[j] - par); + } + } + pCell->velocity += motility; + if(ppCell->unstuck_counter == unstuck_threshold+1){ ppCell->unstuck_counter = 0; } diff --git a/addons/PhysiMeSS/PhysiMeSS_cell.cpp b/addons/PhysiMeSS/PhysiMeSS_cell.cpp index 70a67b124..b91bafae4 100644 --- a/addons/PhysiMeSS/PhysiMeSS_cell.cpp +++ b/addons/PhysiMeSS/PhysiMeSS_cell.cpp @@ -5,6 +5,8 @@ PhysiMeSS_Cell::PhysiMeSS_Cell() { stuck_counter = 0; unstuck_counter = 0; + fibre_contact_damping = 0.0; + fibre_contact_orientation.assign(3, 0.0); } @@ -95,13 +97,22 @@ void PhysiMeSS_Cell::add_potentials_from_fibre(PhysiMeSS_Fibre* pFibre) double xip = pow(xi, p_exponent); double xiq = pow((1 - xi * xi), q_exponent); + // Clamp at 0: once |v| > cell_velocity_max the factor would go negative + // and grow with speed, feeding the velocity back into itself. fibre_adhesion = this->custom_data["vel_adhesion"] * xip * - (1 - cell_velocity / this->custom_data["cell_velocity_max"]); + std::max(0.0, 1 - cell_velocity / this->custom_data["cell_velocity_max"]); fibre_repulsion = this->custom_data["vel_contact"] * xiq; axpy(&(velocity), fibre_adhesion, pFibre->state.orientation); - naxpy(&(velocity), fibre_repulsion, previous_velocity); + // Don't subtract previous_velocity here. Feeding v_prev back (once per fibre) + // gives a gain >= ~1 on v_prev, which is unstable with the Adams-Bashforth + // position update. Keep the strongest contact and its fibre orientation; in + // physimess_update_cell_velocity it damps only the motility perpendicular to that fibre. + if (fibre_repulsion > fibre_contact_damping) { + fibre_contact_damping = fibre_repulsion; + fibre_contact_orientation = pFibre->state.orientation; + } degrade_fibre(pFibre); } diff --git a/addons/PhysiMeSS/PhysiMeSS_cell.h b/addons/PhysiMeSS/PhysiMeSS_cell.h index a7be7d8ff..d1bcdd811 100644 --- a/addons/PhysiMeSS/PhysiMeSS_cell.h +++ b/addons/PhysiMeSS/PhysiMeSS_cell.h @@ -13,7 +13,14 @@ class PhysiMeSS_Cell : public PhysiMeSS_Agent int stuck_counter; int unstuck_counter; - + + // Strongest fibre contact damping coefficient seen this mechanics step, and the + // orientation of that fibre. Applied once (not once per fibre) in + // physimess_update_cell_velocity, to the part of the motility vector that is + // perpendicular to the fibre. + double fibre_contact_damping; + std::vector fibre_contact_orientation; + PhysiMeSS_Cell(); ~PhysiMeSS_Cell() {}; diff --git a/config/Cell_Fibre_Mechanics/test_close_fibers.csv b/config/Cell_Fibre_Mechanics/test_close_fibers.csv new file mode 100644 index 000000000..2f6f3fb81 --- /dev/null +++ b/config/Cell_Fibre_Mechanics/test_close_fibers.csv @@ -0,0 +1,4 @@ +-8,0,0,1 +8,0,0,1 +0,0,0,0 +0,-300,0,2 diff --git a/config/Cell_Fibre_Mechanics/test_close_fibers.xml b/config/Cell_Fibre_Mechanics/test_close_fibers.xml new file mode 100644 index 000000000..22e5b41db --- /dev/null +++ b/config/Cell_Fibre_Mechanics/test_close_fibers.xml @@ -0,0 +1,559 @@ + + + + + + config + rules.csv + + + + + + -400.0 + 400.0 + -400.0 + 400.0 + -10.0 + 10.0 + 20.0 + 20.0 + 20.0 + true + + + + 150.0 + min + micron + 0.01 + 0.1 + 6 + + + + 1 + + + + output + + 1 + true + + + 1 + true + + nutrient + + + + + + + false + + + + + false + true + true + 0 + + + + + + 10000.0 + 0.01 + + 0 + 0.0 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + true + true + + ./config/initial.mat + + + ./config/dirichlet.mat + + + + + + + + + + 0.0 + + + 1.0 + 0 + 0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 2 + 1 + 0.7 + + true + true + + true + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0.0 + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 0.0 + 0.01 + 0.0 + 10.0 + 0.05 + 10.0 + 0.0 + 1.0 + 0.0 + 2.0 + 1.0 + 1.0 + 0.0 + 0 + + + + + + + + + 0.0 + + + 0 + 1.0 + 0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0 + 1 + 0 + 0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 1.0 + 200.0 + 0.0 + 2.0 + 0.0 + 1.57 + 0.0 + + + + + + + + + 0.0 + + + 0 + 0 + 1.0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0.2 + 1 + 0 + 0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 1.0 + 200.0 + 0.0 + 2.0 + 0.0 + 1.57 + 0.0 + + + + + + + + + ./config/Cell_Fibre_Mechanics + test_close_fibers.csv + + + + + 0 + 2 + 3 + false + + diff --git a/sample_projects/physimess/config/Cell_Fibre_Mechanics/fibre_rotating.xml b/sample_projects/physimess/config/Cell_Fibre_Mechanics/fibre_rotating.xml new file mode 100644 index 000000000..1330d7447 --- /dev/null +++ b/sample_projects/physimess/config/Cell_Fibre_Mechanics/fibre_rotating.xml @@ -0,0 +1,394 @@ + + + -400 + 400 + -400 + 400 + -10 + 10 + 20 + 20 + 20 + true + + + + 200 + min + micron + + 0.01 + 0.1 + 6 + + + + 2 + + + + output + + + 1 + true + + + + 1 + true + + + + false + + + + + false + true + true + + + + + + 100.0 + 0.1 + + 1 + 0.0 + + + + + true + true + + + ./config/initial.mat + + + + ./config/dirichlet.mat + + + + + + + + + + 0.0 + + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + + 0.4 + 10.0 + 1.25 + + 1.8 + 15.12 + + + + + 2 + 1 + .5 + + true + true + + true + nutrient + 1 + + + + + + + 0.0 + 0.0 + 0.0 + 0.0 + + + + + + + 0.0 + 0.01 + 0.0 + 10.0 + 0.05 + 10.0 + 0.0 + 1.0 + 1.0 + 0.6 + 0.1 + 1.0 + + + + + + + + + 0.0 + + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + + 0.4 + 10.0 + 1.25 + + 1.8 + 15.12 + + + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + + + + + + 0 + 1 + 0 + 0 + + + + + + 1.0 + 40.0 + 0.0 + 2.0 + 0.0 + 1.57 + 0.0 + + + + + + + + 0.0 + + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + + 0.4 + 10.0 + 1.25 + + 1.8 + 15.12 + + + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + + + + + 10.0 + 1 + 0.0 + 0.0 + + + + + + + 1.0 + + + + + + + + ./config/Cell_Fibre_Mechanics + snowplough.csv + + + + + 0 + + 1 + 1000 + false + + + + \ No newline at end of file diff --git a/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.csv b/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.csv new file mode 100644 index 000000000..2f6f3fb81 --- /dev/null +++ b/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.csv @@ -0,0 +1,4 @@ +-8,0,0,1 +8,0,0,1 +0,0,0,0 +0,-300,0,2 diff --git a/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.xml b/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.xml new file mode 100644 index 000000000..9e4dd770a --- /dev/null +++ b/sample_projects/physimess/config/Cell_Fibre_Mechanics/test_2fibres.xml @@ -0,0 +1,559 @@ + + + + + + config + rules.csv + + + + + + -400.0 + 400.0 + -400.0 + 400.0 + -10.0 + 10.0 + 20.0 + 20.0 + 20.0 + true + + + + 150.0 + min + micron + 0.01 + 0.1 + 6 + + + + 1 + + + + output + + 1 + true + + + 1 + true + + nutrient + + + + + + + false + + + + + false + true + true + 0 + + + + + + 10000.0 + 0.01 + + 0 + 0.0 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + true + true + + ./config/initial.mat + + + ./config/dirichlet.mat + + + + + + + + + + 0.0 + + + 1.0 + 0 + 0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 2 + 1 + 0.7 + + true + true + + true + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0.0 + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 0.0 + 0.01 + 0.0 + 10.0 + 0.05 + 10.0 + 0.0 + 1.0 + 0.0 + 2.0 + 1.0 + 1.0 + 0.0 + 0 + + + + + + + + + 0.0 + + + 0 + 1.0 + 0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0 + 1 + 0 + 0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 1.0 + 200.0 + 0.0 + 2.0 + 0.0 + 1.57 + 0.0 + + + + + + + + + 0.0 + + + 0 + 0 + 1.0 + + + + + 0 + + 516 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + 0.0 + + 0 + 0 + + + 0.05 + 0 + 1.66667e-02 + 5.83333e-03 + 0 + 2.0 + + + + + 2494 + 0.75 + 540 + 0.05 + 0.0045 + 0.0055 + 0 + 0 + 2.0 + + + 0.4 + 10.0 + 1.25 + + 1.0 + 1.0 + 1.0 + + + 1.8 + 15.12 + + 0.01 + 0.0 + 0.0 + 12 + + + 0.0 + 0.0 + 0.0 + + false + true + + false + nutrient + 1 + + + false + false + + 0.0 + + + + + + + 0.2 + 1 + 0 + 0 + + + + 0.0 + 0.0 + 0.0 + + 0.0 + 0.0 + 0.0 + + + 0.0 + 0.0 + 0.0 + + 1.0 + 0.1 + + 0.0 + 0.0 + 0.0 + + + + + 0.0 + 0.0 + 0.0 + + + + 0.0 + 0.0 + + + + 1.0 + 200.0 + 0.0 + 2.0 + 0.0 + 1.57 + 0.0 + + + + + + + + + ./config/Cell_Fibre_Mechanics + test_2fibres.csv + + + + + 0 + 2 + 3 + false + + \ No newline at end of file