@@ -64,36 +64,6 @@ public class SparseSolverTestv1 : NDSimulation
64
64
/// </summary>
65
65
private double cap = 1.0 * 1.0E-2 ;
66
66
/// <summary>
67
- /// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
68
- /// \f[\bar{g}_{K}n^4(V-V_k)\f]
69
- /// where \f$n\f$ is the state variable, and \f$V_k\f$ is the reversal potential.
70
- /// </summary>
71
- private double gk = 5.0 * 1.0E1 ;
72
- /// <summary>
73
- /// [S/m2] sodium conductance per unit area, this is the Sodium conductance per unit area, it is used in this term
74
- /// \f[\bar{g}_{Na}m^3h(V-V_{Na})\f]
75
- /// where \f$m,h\f$ are the state variables, and \f$V_{Na}\f$ is the reversal potential for sodium.
76
- /// </summary>
77
- private double gna = 50.0 * 1.0E1 ;
78
- /// <summary>
79
- /// [S/m2] leak conductance per unit area, this is the leak conductance per unit area, it is used in this term
80
- /// \f[\bar{g}_{l}(V-V_l)\f]
81
- /// \f$V_l\f$ is the leak reversal potential.
82
- /// </summary>
83
- private double gl = 0.0 * 1.0E1 ;
84
- /// <summary>
85
- /// [V] potassium reversal potential
86
- /// </summary>
87
- private double ek = - 90.0 * 1.0E-3 ;
88
- /// <summary>
89
- /// [V] sodium reversal potential
90
- /// </summary>
91
- private double ena = 50.0 * 1.0E-3 ;
92
- /// <summary>
93
- /// [V] leak reversal potential
94
- /// </summary>
95
- private double el = - 70.0 * 1.0E-3 ;
96
- /// <summary>
97
67
/// [] potassium channel state probability, unitless
98
68
/// </summary>
99
69
private double ni = 0.0376969 ;
@@ -380,28 +350,51 @@ protected override void PreSolve()
380
350
if ( ! g . Loading ) InitializeNeuronCell ( ) ;
381
351
else BuildVectors ( g . U , g . M , g . N , g . H , g . Upre , g . Mpre , g . Npre , g . Hpre ) ;
382
352
353
+ else BuildVectors ( g . U , g . M , g . N , g . H , g . Upre , g . Mpre , g . Npre , g . Hpre ) ;
354
+
355
+ ///<c>R</c> this is the reaction vector for the reaction solve
356
+ R = Vector . Build . Dense ( Neuron . nodes . Count ) ;
357
+
358
+ tempState = Vector . Build . Dense ( Neuron . nodes . Count , 0 ) ;
359
+ ///<c>reactConst</c> this is a small list for collecting the conductances and reversal potential which is sent to the reaction solve routine
360
+ // reactConst = new List<double> { gk, gna, gl, ek, ena, el };
361
+
362
+ /// this sets the target time step size
363
+ timeStep = SetTargetTimeStep ( cap , 2 * Neuron . MaxRadius , 2 * Neuron . MinRadius , Neuron . TargetEdgeLength , gna , gk , gl , res , 1.0 ) ;
364
+ ///UnityEngine.Debug.Log("Target Time Step = " + timeStep);
365
+
366
+ ///<c>List<CoordinateStorage<double>> sparse_stencils = makeSparseStencils(Neuron, res, cap, k);</c> Construct sparse RHS and LHS in coordinate storage format, no zeros are stored \n
367
+ /// <c>sparse_stencils</c> this is a list which contains only two matrices the LHS and RHS matrices for the Crank-Nicolson solve
368
+ sparse_stencils = makeSparseStencils ( Neuron , res , cap , timeStep ) ;
369
+ ///<c>CompressedColumnStorage</c> call Compresses the sparse matrices which are stored in <c>sparse_stencils[0]</c> and <c>sparse_stencils[1]</c>
370
+ r_csc = CompressedColumnStorage < double > . OfIndexed ( sparse_stencils [ 0 ] ) ; //null;
371
+ l_csc = CompressedColumnStorage < double > . OfIndexed ( sparse_stencils [ 1 ] ) ; //null;
372
+ ///<c>double [] b</c> we define storage for the diffusion solve part
373
+ b = new double [ Neuron . nodes . Count ] ;
374
+ ///<c>var lu = SparseLU.Create(l_csc, ColumnOrdering.MinimumDegreeAtA, 0.1);</c> this creates the LU decomposition of the HINES matrix which is defined by <c>l_csc</c>
375
+ lu = SparseLU . Create ( l_csc , ColumnOrdering . MinimumDegreeAtA , 0.1 ) ;
383
376
384
- // Define alpha and beta functions for the gating variable (example for potassium channel)
385
- Func < double , double > alpha_n = ( voltage ) => 0.01 * ( voltage + 55 ) / ( 1 - Math . Exp ( - ( voltage + 55 ) / 10 ) ) ;
386
- Func < double , double > beta_n = ( voltage ) => 0.125 * Math . Exp ( - ( voltage + 65 ) / 80 ) ;
377
+ // // Define alpha and beta functions for the gating variable (example for potassium channel)
378
+ // Func<double, double> alpha_n = (voltage) => 0.01 * (voltage + 55) / (1 - Math.Exp(-(voltage + 55) / 10));
379
+ // Func<double, double> beta_n = (voltage) => 0.125 * Math.Exp(-(voltage + 65) / 80);
387
380
388
- // Create a gating variable for potassium channel (n gate)
389
- GatingVariable potassiumGate = new GatingVariable ( "n" , alpha_n , beta_n )
390
- {
391
- Coefficients = new List < double > { 1.0 }
392
- } ;
381
+ // // Create a gating variable for potassium channel (n gate)
382
+ // GatingVariable potassiumGate = new GatingVariable("n", alpha_n, beta_n)
383
+ // {
384
+ // Coefficients = new List<double> { 1.0 }
385
+ // };
393
386
394
- // Create the potassium ion channel
395
- IonChannel potassiumChannel = new IonChannel ( "Potassium" , , ) ;
387
+ // // Create the potassium ion channel
388
+ // IonChannel potassiumChannel = new IonChannel("Potassium", , );
396
389
397
- // Add the gating variable to the potassium channel
398
- potassiumChannel . AddGatingVariable ( potassiumGate ) ;
390
+ // // Add the gating variable to the potassium channel
391
+ // potassiumChannel.AddGatingVariable(potassiumGate);
399
392
400
- // Calculate the current at a certain voltage
401
- double voltage = - 65 ;
402
- double current = potassiumChannel . CalculateCurrent ( voltage ) ;
393
+ // // Calculate the current at a certain voltage
394
+ // double voltage = -65;
395
+ // double current = potassiumChannel.CalculateCurrent(voltage);
403
396
404
- Console . WriteLine ( $ "Potassium channel current at { voltage } mV: { current } A") ;
397
+ // Console.WriteLine($"Potassium channel current at {voltage} mV: {current} A");
405
398
406
399
407
400
@@ -428,6 +421,61 @@ protected override void PreSolve()
428
421
lu = SparseLU . Create ( l_csc , ColumnOrdering . MinimumDegreeAtA , 0.1 ) ;
429
422
}
430
423
424
+ public void InitializeIonChannels ( )
425
+ {
426
+ /// <summary>
427
+ /// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
428
+ /// \f[\bar{g}_{K}n^4(V-V_k)\f]
429
+ /// where \f$n\f$ is the state variable, and \f$V_k\f$ is the reversal potential.
430
+ /// </summary>
431
+ private double gk = 5.0 * 1.0E1 ;
432
+ /// <summary>
433
+ /// [S/m2] sodium conductance per unit area, this is the Sodium conductance per unit area, it is used in this term
434
+ /// \f[\bar{g}_{Na}m^3h(V-V_{Na})\f]
435
+ /// where \f$m,h\f$ are the state variables, and \f$V_{Na}\f$ is the reversal potential for sodium.
436
+ /// </summary>
437
+ private double gna = 50.0 * 1.0E1 ;
438
+ /// <summary>
439
+ /// [S/m2] leak conductance per unit area, this is the leak conductance per unit area, it is used in this term
440
+ /// \f[\bar{g}_{l}(V-V_l)\f]
441
+ /// \f$V_l\f$ is the leak reversal potential.
442
+ /// </summary>
443
+ private double gl = 0.0 * 1.0E1 ;
444
+ /// <summary>
445
+ /// [V] potassium reversal potential
446
+ /// </summary>
447
+ private double ek = - 90.0 * 1.0E-3 ;
448
+ /// <summary>
449
+ /// [V] sodium reversal potential
450
+ /// </summary>
451
+ private double ena = 50.0 * 1.0E-3 ;
452
+ /// <summary>
453
+ /// [V] leak reversal potential
454
+ /// </summary>
455
+ private double el = - 70.0 * 1.0E-3 ;
456
+
457
+ //
458
+ private double n_alphaFunction ;
459
+ private double m_alphaFunction ;
460
+ private double h_alphaFunction ;
461
+ private double n_betaFunction ;
462
+ private double m_betaFunction ;
463
+ private double h_betaFunction ;
464
+
465
+
466
+
467
+ IonChannel potassiumChannel = new IonChannel ( "Potassium Channel" , gk , ek ) ;
468
+ potassiumChannel . AddGatingVariable ( new GatingVariable ( "n" , alpha : n_alphaFunction , beta : n_betaFunction ) ) ;
469
+
470
+ IonChannel sodiumChannel = new IonChannel ( "Sodium Channel" , gna , ena ) ;
471
+ sodiumChannel . AddGatingVariable ( new GatingVariable ( "m" , alpha : m_alphaFunction , beta : m_betaFunction ) ) ;
472
+ sodiumChannel . AddGatingVariable ( new GatingVariable ( "h" , alpha : h_alphaFunction , beta : h_betaFunction ) ) ;
473
+
474
+ IonChannel leakageChannel = new IonChannel ( "Leakage Channel" , gl , el ) ;
475
+ leadChannel . AddGatingVariable ( new GatingVariable ( "n" ) ) ;
476
+
477
+ }
478
+
431
479
/// <summary>
432
480
/// This is the main solver, it is running on it own thread.
433
481
/// The solver using SBDF2 for time steping, the implicit part is used for the diffusion and the explicit
0 commit comments