@@ -61,7 +61,7 @@ public class SparseSolverTestv1 : NDSimulation
61
61
/// <summary>
62
62
/// [F/m2] capacitance per unit area, this is the plasma membrane capacitance, this a standard value for the capacitance
63
63
/// </summary>
64
- private double cap = 1.0 * 1.0E-2 ;
64
+ private double cap = 1.0 * 1.0E-2 ;
65
65
/// <summary>
66
66
/// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
67
67
/// \f[\bar{g}_{K}n^4(V-V_k)\f]
@@ -157,7 +157,7 @@ public class SparseSolverTestv1 : NDSimulation
157
157
/// </summary>
158
158
private Vector tempState ;
159
159
160
- List < double > reactConst ; //This is for passing the reaction function constants
160
+ // List<double> reactConst; //This is for passing the reaction function constants
161
161
List < CoordinateStorage < double > > sparse_stencils ;
162
162
CompressedColumnStorage < double > r_csc ; //This is for the rhs sparse matrix
163
163
CompressedColumnStorage < double > l_csc ; //This is for the lhs sparse matrix
@@ -396,7 +396,6 @@ protected override void PreSolve()
396
396
Debug . Log ( "Here" ) ;
397
397
InitializeIonChannel ( ) ;
398
398
399
-
400
399
if ( ! g . Loading )
401
400
{
402
401
InitializeNeuronCell ( ) ;
@@ -427,6 +426,7 @@ protected override void PreSolve()
427
426
// Other PreSolve logic (time step, matrices setup, etc.)
428
427
R = Vector . Build . Dense ( Neuron . nodes . Count ) ;
429
428
tempState = Vector . Build . Dense ( Neuron . nodes . Count , 0 ) ;
429
+ timeStep = SetTargetTimeStep ( cap , 2 * Neuron . MaxRadius , 2 * Neuron . MinRadius , Neuron . TargetEdgeLength , ionChannels , res , 1.0 ) ;
430
430
sparse_stencils = makeSparseStencils ( Neuron , res , cap , timeStep ) ;
431
431
r_csc = CompressedColumnStorage < double > . OfIndexed ( sparse_stencils [ 0 ] ) ;
432
432
l_csc = CompressedColumnStorage < double > . OfIndexed ( sparse_stencils [ 1 ] ) ;
@@ -519,7 +519,7 @@ protected override void SolveStep(int t)
519
519
gatingVariable . CurrentState ,
520
520
gatingVariable . PreviousState ,
521
521
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 ) ) ,
523
523
timeStep
524
524
) ;
525
525
@@ -563,12 +563,12 @@ internal override void SetOutputValues()
563
563
/// <param name="cap"></param> this is the capacitance
564
564
/// <param name="maxDiameter"></param> this is the maximum diameter
565
565
/// <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
568
567
/// <param name="res"></param> this is the axial resistance
569
568
/// <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;
570
570
/// <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 )
572
572
{
573
573
/// here we set the minimum time step size and maximum time step size
574
574
/// 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
577
577
//double dtmin = 2e-6;
578
578
double dtmax = 50e-6 ;
579
579
double dt ;
580
+ double scf = 1E-6 ; // to convert to micrometer of edgelengths and radii don't forget this!!!!
580
581
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 ;
585
584
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 ) ) ;
587
598
//double lower_bound = cap * edgeLength*scf * System.Math.Sqrt(res / (gna + gk + gl) * maxDiameter*scf);
588
599
//GameManager.instance.DebugLogSafe("upper_bound = " + upper_bound.ToString());
589
600
590
601
// 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 ) ;
592
603
//GameManager.instance.DebugLogSafe("lower_bound = " + lower_bound.ToString());
593
604
return dt ;
594
605
}
@@ -932,3 +943,4 @@ private void LoadSavedStates(GameManager g)
932
943
}
933
944
}
934
945
}
946
+
0 commit comments