示例#1
0
        public void defineNodeDirVectors(int[] initial_set, out getFloatValueDelegate getProximaDst, out setFloatValueDelegate setProximaDst)
        {
            float curr_value = 0;
            List <VascularNode> curr_front;

            curr_front = new List <VascularNode>();
            List <VascularNode> tmp_curr_front = new List <VascularNode>();

            foreach (var id in initial_set)
            {
                curr_front.Add(vascular_system[0]);
            }

            getFloatValueDelegate get_del;
            setFloatValueDelegate set_del;

            VascularNode.newFloatValueLayer(out get_del, out set_del);
            foreach (var n in curr_front)
            {
                set_del(n, curr_value);
            }

            while (true)
            {
                foreach (var n in curr_front)
                {
                    foreach (var ng in n.neighbours)
                    {
                        if (get_del(ng) > curr_value)
                        {
                            set_del(ng, curr_value);
                            tmp_curr_front.Add(ng);
                        }
                    }
                }
                if (curr_front.Count == 0)
                {
                    break;
                }

                curr_front = new List <VascularNode>(tmp_curr_front);
                tmp_curr_front.Clear();
                curr_value += 1.0f;
            }

            foreach (var n in vascular_system)
            {
                if (n.neighbours.Count < 3)
                {
                    //Console.WriteLine(n.id);
                    //if (n.id == 1717)
                    //{
                    //    Console.WriteLine("1");
                    //}
                    //Console.WriteLine(get_del(n.neighbours.First()));
                    //Console.WriteLine(get_del(n));
                    if (n.neighbours.Last().position < n.neighbours.First().position)
                    {
                        n.neighbours.Reverse();
                    }
                    n.defDirVector();
                }
            }

            getProximaDst = get_del;
            setProximaDst = set_del;
        }
示例#2
0
        public void setOutletBC(int start_point_id, List <BodyPartInlet> parts, float Q_total, float C_total, float R_total)
        {
            Dictionary <int, List <VascularNode> > outlet_groups = new Dictionary <int, List <VascularNode> >();

            List <VascularNode> reference_points = new List <VascularNode>();

            foreach (var p in parts)
            {
                reference_points.AddRange(p.inlet);
            }

            List <VascularNode> front_0 = new List <VascularNode>();
            List <VascularNode> front_1 = new List <VascularNode>();

            getFloatValueDelegate get_dist;
            setFloatValueDelegate set_dist;

            getFloatValueDelegate get_group;
            setFloatValueDelegate set_group;

            VascularNode.newFloatValueLayer(out get_dist, out set_dist);
            VascularNode.newFloatValueLayer(out get_group, out set_group);

            VascularNode start_point = v_net.vascular_system.Find(x => x.id == start_point_id);

            front_0.Add(start_point);
            set_dist(start_point, 0);

            /*  Q_total = 0;
             * for (int i = 0; i < parts.Count; i++)
             *        Q_total += (float)parts[i].inlet_flux.Sum();*/

            while (true)
            {
                foreach (var n in front_0)
                {
                    if (reference_points.Contains(n) && (!outlet_groups.ContainsKey(n.id)))
                    {
                        outlet_groups.Add(n.id, new List <VascularNode>());
                        set_group(n, n.id);
                    }

                    foreach (var nn in n.neighbours)
                    {
                        if (get_dist(nn) > get_dist(n))
                        {
                            set_dist(nn, get_dist(n) + 1);
                            if (!front_1.Contains(nn))
                            {
                                front_1.Add(nn);
                                set_group(nn, get_group(n));
                                if (outlet_groups.ContainsKey((int)get_group(n)))
                                {
                                    outlet_groups[(int)get_group(n)].Add(nn);
                                }
                            }
                        }
                    }
                }

                front_1 = front_1.Distinct().ToList();
                front_0 = new List <VascularNode>(front_1);
                front_1.Clear();

                if (front_0.Count == 0)
                {
                    break;
                }
            }

            foreach (var part in parts)
            {
                foreach (var root in part.inlet)
                {
                    if (outlet_groups.ContainsKey(root.id))
                    {
                        foreach (var n in outlet_groups[root.id])
                        {
                            if (n.neighbours.Count == 1)
                            {
                                part.outlet.Add(v_net.bounds.Find(x => x.core_node == n));
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < parts.Count; i++)
            {
                double outlet_cube_summ = 0;
                double inlet_cube_summ  = 0;
                foreach (var on in parts[i].outlet)
                {
                    outlet_cube_summ += Math.Pow(on.core_node.radius, 3);
                }

                foreach (var inp_n in parts[i].inlet)
                {
                    inlet_cube_summ += Math.Pow(inp_n.radius, 3);
                }

                Console.WriteLine(parts[i].name + "    inlet/outlet: " + inlet_cube_summ / outlet_cube_summ);
            }

            for (int i = 0; i < parts.Count; i++)
            {
                double a_cube_outlet  = 0;
                double tot_inlet_flux = 0;

                for (int j = 0; j < parts[i].outlet.Count; j++)
                {
                    a_cube_outlet += Math.Pow(parts[i].outlet[j].core_node.radius, 3);
                }


                for (int j = 0; j < parts[i].inlet_flux.Count; j++)
                {
                    tot_inlet_flux += parts[i].inlet_flux[j];
                }

                double R_part = (Q_total / tot_inlet_flux) * R_total;

                foreach (PressureOutletRCR bc in parts[i].outlet)
                {
                    double Rt = a_cube_outlet / Math.Pow(bc.core_node.radius, 3) * R_part;
                    // inv_tot_R += 1.0 / Rt;
                    double R2 = Rt - bc.R1;
                    if (R2 < 0)
                    {
                        R2    = 0.1;
                        bc.R1 = Rt - R2;
                    }

                    bc.R2 = R2;
                    bc.C  = C_total * R_total / Rt;
                }
            }
        }