Exemple #1
0
        // This prints the general cell and simulation information
        // average edge lengths, spatial step size, time step size, number of time steps
        // the cfl number, time to setup cholesky solver, soma indices
        public void printCell(NeuronCell myCell, double h, double k, double nT, double endTime, double cfl, string strPath, int kSim)
        {
            var cellinfo = new StreamWriter(strPath + @"\cellinfo_" + kSim + ".txt", true);
            var neigbors = new StreamWriter(strPath + @"\nodeNeigbors_" + kSim + ".txt", true);

            cellinfo.Write("aver edgelength = " + myCell.edgeLengths.Average() + "\n");
            cellinfo.Write("max edgelength = " + myCell.edgeLengths.Max() + "\n");
            cellinfo.Write("min edgelength = " + myCell.edgeLengths.Min() + "\n");
            cellinfo.Write("This cell has = " + myCell.vertCount + " nodes." + "\n");
            cellinfo.Write("Time step k = " + k + "\n");
            cellinfo.Write("Spatial step size = " + h + "\n");
            cellinfo.Write("Number of Time steps = " + nT + "\n");
            cellinfo.Write("Soma Indices = " + String.Join(", ", myCell.somaID) + "\n");
            cellinfo.Write("cfl = " + cfl + "\n");
            cellinfo.Close();

            // Print the node neighbors to output file
            for (int p = 0; p < myCell.vertCount; p++)
            {
                for (int q = 0; q < myCell.nodeData[p].neighborIDs.Count; q++)
                {
                    neigbors.Write(myCell.nodeData[p].neighborIDs[q] + ", ");
                }
                neigbors.Write("\n");
            }

            neigbors.Close();
        }
Exemple #2
0
        // This prints the general cell and simulation information
        // average edge lengths, spatial step size, time step size, number of time steps
        // the cfl number, time to setup cholesky solver, soma indices
        public void printCell(NeuronCell myCell, double h, double k, double nT, double endTime, double cfl, string strPath, int kSim)
        {
            var cellinfo   = new StreamWriter(strPath + @"\cellinfo_" + kSim + ".txt", true);
            var neigbors   = new StreamWriter(strPath + @"\nodeNeigbors_" + kSim + ".txt", true);
            var radii      = new StreamWriter(strPath + @"\radii_" + kSim + ".txt", true);
            var somapoints = new StreamWriter(strPath + @"\somapoints_" + kSim + ".txt", true);
            var vertexinfo = new StreamWriter(strPath + @"\vertexinfo_" + kSim + ".txt", true);

            //var brchpoints = new StreamWriter(strPath + @"\brch1_" + kSim + ".txt", true);

            cellinfo.Write("aver edgelength = " + myCell.edgeLengths.Average() + "\n");
            cellinfo.Write("max edgelength = " + myCell.edgeLengths.Max() + "\n");
            cellinfo.Write("min edgelength = " + myCell.edgeLengths.Min() + "\n");
            cellinfo.Write("This cell has = " + myCell.vertCount + " nodes." + "\n");
            cellinfo.Write("Time step k = " + k + "\n");
            cellinfo.Write("Spatial step size = " + h + "\n");
            cellinfo.Write("Number of Time steps = " + nT + "\n");
            cellinfo.Write("Soma Indices = " + String.Join(", ", myCell.somaID) + "\n");
            cellinfo.Write("cfl = " + cfl + "\n");
            cellinfo.Close();

            // Print the node neighbors to output file
            for (int p = 0; p < myCell.vertCount; p++)
            {
                for (int q = 0; q < myCell.nodeData[p].neighborIDs.Count; q++)
                {
                    neigbors.Write(myCell.nodeData[p].neighborIDs[q] + ", ");
                }
                neigbors.Write("\n");

                radii.Write(myCell.nodeData[p].nodeRadius + Environment.NewLine);
                vertexinfo.Write(myCell.nodeData[p].id + " " + myCell.nodeData[p].xcoords + " " + myCell.nodeData[p].ycoords + " " + myCell.nodeData[p].zcoords + " " + Environment.NewLine);
            }

            int sID;

            for (int p = 0; p < myCell.somaID.Count; p++)
            {
                sID = myCell.somaID[p];
                somapoints.Write(sID + " " + myCell.nodeData[sID].xcoords + " " + myCell.nodeData[sID].ycoords + " " + myCell.nodeData[sID].zcoords + Environment.NewLine);
            }

            /*
             * int bID;
             * for (int p=0; p<myCell.brchID.Count; p++)
             * {
             *  bID = myCell.brchID[p];
             *  brchpoints.Write(bID + Environment.NewLine);
             * }
             */
            neigbors.Close();
            radii.Close();
            somapoints.Close();
            //brchpoints.Close();
            vertexinfo.Close();
        }
Exemple #3
0
        // This is for constructing the lhs and rhs of system matrix
        // This will construct a HINES matrix (symmetric), it should be tridiagonal with some off
        // diagonal entries corresponding to a branch location in the neuron graph
        public static List <CoordinateStorage <double> > makeSparseStencils(NeuronCell myCell, double h, double k, double diffConst)
        {
            List <CoordinateStorage <double> > stencils = new List <CoordinateStorage <double> >();

            var rhs = new CoordinateStorage <double>(myCell.vertCount, myCell.vertCount, myCell.vertCount * myCell.vertCount);
            var lhs = new CoordinateStorage <double>(myCell.vertCount, myCell.vertCount, myCell.vertCount * myCell.vertCount);

            // for keeping track of the neighbors of a node
            int nghbrCount;
            int nghbrInd;

            // need cfl coefficient
            double cfl = diffConst * k / h;
            double vRad;//= 1;    // need to use radius data attached to geometry, TODO: move inside the loop and access for each node

            for (int p = 0; p < myCell.vertCount; p++)
            {
                nghbrCount = myCell.nodeData[p].neighborIDs.Count;
                vRad       = myCell.nodeData[p].nodeRadius;
                if (vRad >= 1)
                {
                    vRad = 0.1 * vRad;
                }
                vRad = 0.5 * vRad;

                // set main diagonal entries
                rhs.At(p, p, 1 - ((double)nghbrCount + h * h) * vRad * cfl / (2 * h));
                lhs.At(p, p, 1 + ((double)nghbrCount + h * h) * vRad * cfl / (2 * h));

                // this inner loop is for setting the off diagonal entries which correspond
                // to the neighbors of each node in the branch structure
                for (int q = 0; q < nghbrCount; q++)
                {
                    nghbrInd = myCell.nodeData[p].neighborIDs[q];

                    // should I be using the neighbor radii here or same as main node?
                    //vRad = myCell.nodeData[myCell.nodeData[p].neighborIDs[q]].nodeRadius;

                    // for off diagonal entries
                    rhs.At(p, nghbrInd, vRad * cfl / (2 * h));
                    //rhs.At(nghbrInd, p, vRad * cfl / (2 * h));

                    // for off diagonal entries
                    lhs.At(p, nghbrInd, -vRad * cfl / (2 * h));
                    //lhs.At(nghbrInd, p, -vRad * cfl / (2 * h));
                }
            }
            stencils.Add(rhs);
            stencils.Add(lhs);
            return(stencils);
        }
Exemple #4
0
        // This prints the general cell and simulation information
        // average edge lengths, spatial step size, time step size, number of time steps
        // the cfl number, time to setup cholesky solver, soma indices
        public void printCell(NeuronCell myCell, double h, double k, double nT, double endTime, double cfl, string strPath, DateTime now, DateTime start, DateTime end)
        {
            var cellinfo = new StreamWriter(strPath + @"\cellinfo_" + now.Hour + "_" + now.Minute + "_" + now.Second + ".txt", true);

            cellinfo.Write("aver edgelength = " + myCell.edgeLengths.Average() + "\n");
            cellinfo.Write("max edgelength = " + myCell.edgeLengths.Max() + "\n");
            cellinfo.Write("min edgelength = " + myCell.edgeLengths.Min() + "\n");
            cellinfo.Write("This cell has = " + myCell.vertCount + " nodes." + "\n");
            cellinfo.Write("Time step k = " + k + "\n");
            cellinfo.Write("Spatial step size = " + h + "\n");
            cellinfo.Write("Number of Time steps = " + nT + "\n");
            cellinfo.Write("Soma Indices = " + String.Join(", ", myCell.somaID) + "\n");
            cellinfo.Write("Time to setup CHL sparse solver = " + (end - start).TotalMilliseconds + " (ms).\n");
            cellinfo.Write("cfl = " + cfl + "\n");
            cellinfo.Close();
        }
Exemple #5
0
        // This is for constructing the lhs and rhs of system matrix
        // This will construct a HINES matrix (symmetric), it should be tridiagonal with some off
        // diagonal entries corresponding to a branch location in the neuron graph
        public static List <double[, ]> makeStencils(NeuronCell myCell, double h, double k, double diffConst)
        {
            List <double[, ]> stencils = new List <double[, ]>();

            // preallocate arrays
            double[,] rhsMarray = new double[myCell.vertCount, myCell.vertCount];
            double[,] lhsMarray = new double[myCell.vertCount, myCell.vertCount];

            // for keeping track of the neighbors of a node
            int nghbrCount;
            int nghbrInd;

            // need cfl coefficient
            double cfl  = diffConst * k / h;
            double vRad = 1;    // need to use radius data attached to geometry, TODO: move inside the loop and access for each node

            for (int p = 0; p < myCell.vertCount; p++)
            {
                nghbrCount = myCell.nodeData[p].neighborIDs.Count;

                // set main diagonal entries
                rhsMarray[p, p] = 1 - ((double)nghbrCount) * vRad * cfl / (2 * h);
                lhsMarray[p, p] = 1 + ((double)nghbrCount) * vRad * cfl / (2 * h);

                // this inner loop is for setting the off diagonal entries which correspond
                // to the neighbors of each node in the branch structure
                for (int q = 0; q < nghbrCount; q++)
                {
                    nghbrInd = myCell.nodeData[p].neighborIDs[q];

                    // for off diagonal entries
                    rhsMarray[p, nghbrInd] = vRad * cfl / (2 * h);
                    rhsMarray[nghbrInd, p] = vRad * cfl / (2 * h);

                    // for off diagonal entries
                    lhsMarray[p, nghbrInd] = -vRad * cfl / (2 * h);
                    lhsMarray[nghbrInd, p] = -vRad * cfl / (2 * h);
                }
            }

            // set output
            stencils.Add(rhsMarray);
            stencils.Add(lhsMarray);

            return(stencils);
        }