Skip to content

Commit 6ef9041

Browse files
author
Carlos Eckert
committed
late night
1 parent 9b6cf08 commit 6ef9041

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

Assets/Scripts/C2M2/NeuronalDynamics/Simulation/SparseSolverTestv1.cs

+25-13
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class SparseSolverTestv1 : NDSimulation
6161
/// <summary>
6262
/// [F/m2] capacitance per unit area, this is the plasma membrane capacitance, this a standard value for the capacitance
6363
/// </summary>
64-
private double cap = 1.0 * 1.0E-2;
64+
private double cap = 1.0 * 1.0E-2;
6565
/// <summary>
6666
/// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
6767
/// \f[\bar{g}_{K}n^4(V-V_k)\f]
@@ -157,7 +157,7 @@ public class SparseSolverTestv1 : NDSimulation
157157
/// </summary>
158158
private Vector tempState;
159159

160-
List<double> reactConst; //This is for passing the reaction function constants
160+
// List<double> reactConst; //This is for passing the reaction function constants
161161
List<CoordinateStorage<double>> sparse_stencils;
162162
CompressedColumnStorage<double> r_csc; //This is for the rhs sparse matrix
163163
CompressedColumnStorage<double> l_csc; //This is for the lhs sparse matrix
@@ -396,7 +396,6 @@ protected override void PreSolve()
396396
Debug.Log("Here");
397397
InitializeIonChannel();
398398

399-
400399
if (!g.Loading)
401400
{
402401
InitializeNeuronCell();
@@ -427,6 +426,7 @@ protected override void PreSolve()
427426
// Other PreSolve logic (time step, matrices setup, etc.)
428427
R = Vector.Build.Dense(Neuron.nodes.Count);
429428
tempState = Vector.Build.Dense(Neuron.nodes.Count, 0);
429+
timeStep = SetTargetTimeStep(cap, 2 * Neuron.MaxRadius, 2 * Neuron.MinRadius, Neuron.TargetEdgeLength, ionChannels, res, 1.0);
430430
sparse_stencils = makeSparseStencils(Neuron, res, cap, timeStep);
431431
r_csc = CompressedColumnStorage<double>.OfIndexed(sparse_stencils[0]);
432432
l_csc = CompressedColumnStorage<double>.OfIndexed(sparse_stencils[1]);
@@ -519,7 +519,7 @@ protected override void SolveStep(int t)
519519
gatingVariable.CurrentState,
520520
gatingVariable.PreviousState,
521521
fS(gatingVariable.CurrentState, gatingVariable.Alpha(U_Active), gatingVariable.Beta(U_Active)),
522-
fS(gatingVariable.PreviousState, gatingVariable.Alpha(Upre), gatingVariable.Beta(Upre)),
522+
fS(gatingVariable.PreviousState, gatingVariable.Alpha(Upre), gatingVariable.Beta(Upre)),
523523
timeStep
524524
);
525525

@@ -563,12 +563,12 @@ internal override void SetOutputValues()
563563
/// <param name="cap"></param> this is the capacitance
564564
/// <param name="maxDiameter"></param> this is the maximum diameter
565565
/// <param name="edgeLength"></param> this is the target edge length of the graph geometry
566-
/// <param name="gna"></param> this is the sodium conductance
567-
/// <param name="gk"></param> this is the potassium conductance
566+
/// <param name="ionChannels"></param> this is the list of ionChannels. Used to grather conductance of each channel
568567
/// <param name="res"></param> this is the axial resistance
569568
/// <param name="Rmemscf"></param> this is membrane resistance scale factor, since this is only a fraction of theoretical maximum
569+
/// <param name="cfl"></param> this isn't defined or used in the function but appears to be intended as a safety variable for the time step. Example usage: dt = Math.Min(upper_bound, dtmax) * cfl;
570570
/// <returns></returns>
571-
public static double SetTargetTimeStep(double cap, double maxDiameter, double minDiameter,double edgeLength ,double gna, double gk, double gl, double res, double cfl)
571+
public static double SetTargetTimeStep(double cap, double maxDiameter, double minDiameter, double edgeLength, List<IonChannel> ionChannels, double res, double cfl)
572572
{
573573
/// here we set the minimum time step size and maximum time step size
574574
/// the dtmin is based on prior numerical experiments that revealed that for each refinement level the
@@ -577,18 +577,29 @@ public static double SetTargetTimeStep(double cap, double maxDiameter, double mi
577577
//double dtmin = 2e-6;
578578
double dtmax = 50e-6;
579579
double dt;
580+
double scf = 1E-6; // to convert to micrometer of edgelengths and radii don't forget this!!!!
580581

581-
double gll = gl; double scf = 1E-6; // to convert to micrometer of edgelengths and radii don't forget this!!!!
582-
583-
// what happens if the leak conductance is 0
584-
if (gll == 0.0) { gll = 1.0; }
582+
// Calculate effective conductance based on all ion channels
583+
double effectiveConductance = 0.0;
585584

586-
double upper_bound = cap * edgeLength*scf * System.Math.Sqrt(res / (gll*minDiameter*scf));
585+
foreach (IonChannel channel in ionChannels)
586+
{
587+
effectiveConductance += channel.Conductance;
588+
}
589+
590+
// if effective conductance is 0
591+
if (effectiveConductance == 0.0)
592+
{
593+
effectiveConductance = 1.0; // Set a minimal conductance
594+
}
595+
596+
597+
double upper_bound = cap * edgeLength * scf * System.Math.Sqrt(res / (effectiveConductance * minDiameter * scf));
587598
//double lower_bound = cap * edgeLength*scf * System.Math.Sqrt(res / (gna + gk + gl) * maxDiameter*scf);
588599
//GameManager.instance.DebugLogSafe("upper_bound = " + upper_bound.ToString());
589600

590601
// some cells may have an upper bound that is too large for the solver, so choose the smaller of the two dtmax or upper_bound
591-
dt = System.Math.Min(upper_bound,dtmax);
602+
dt = System.Math.Min(upper_bound, dtmax);
592603
//GameManager.instance.DebugLogSafe("lower_bound = " + lower_bound.ToString());
593604
return dt;
594605
}
@@ -932,3 +943,4 @@ private void LoadSavedStates(GameManager g)
932943
}
933944
}
934945
}
946+

0 commit comments

Comments
 (0)