public override void doBC(double dt) { interfunc_dx = Vector1.Distance(core_node.position, core_node.neighbours.Last().position); interfunc_dt = dt; previous_time = current_time; current_time = current_time + dt; //Console.WriteLine(core_node.position); //if (core_node.id == 13234) //core_node.id = 13234; Q_t_1 = core_node.lumen_sq * core_node.velocity * v_sign[0]; //tx_ij - i - time moment, j - space point, 1 - current moment (core node), 0 -previous moment (previus point)/ // Euler scheme for ODE integration/// if (core_node.nodetype >= 3) { Q_t_1 = 0.0; } double dQdt = (Q_t_1 - Q_t_0) / dt;//Console.WriteLine(dQdt); //////////////////////////////////// // Send flow rate to 1-D steady model // Wait for answer // Set pressure //string flags = " -Qin " + Q_t_1.ToString(); //Process Process = new Process(); //Process.StartInfo.UseShellExecute = false; //Process.StartInfo.FileName = "./steady_network_solver"; //Process.StartInfo.Arguments = flags; //Process.StartInfo.CreateNoWindow = true; //Process.StartInfo.RedirectStandardOutput = true; //Process.Start(); ////q = Process.StandardOutput.ReadLine(); //Process.WaitForExit(); //string Pressure_reading = System.IO.File.ReadAllText("p_in.dat"); //P_tx_11 = Convert.ToDouble(Pressure_reading); P_tx_10 = neighbour_node.pressure; U_tx_10 = neighbour_node.velocity * v_sign[1]; A_tx_10 = neighbour_node.lumen_sq; if (core_node.nodetype >= 3) { P_tx_11 = P_tx_10; } else { P_tx_11 = (Q_t_0 * (1 + R1 / R2) + C * R1 * dQdt + GlobalDefs.OUT_PRESSURE / R2 + P_tx_01 * C / dt) / (C / dt + 1 / R2); } //P_tx_11 = (Q_t_0 * (1 + R1 / R2) + C * R1 * dQdt + GlobalDefs.OUT_PRESSURE / R2 + P_tx_01 * C / dt) / (C / dt + 1 / R2); chrt_frw_left = U_tx_01 + 4 * Math.Pow(A_tx_10, 0.25f) * Math.Sqrt(beta_1 / 2.0f / GlobalDefs.BLOOD_DENSITY); //if (core_node.nodetype >= 3) //{ // A_tx_11 = core_node.lumen_sq_0; //} //else //{ // A_tx_11 = myMath.NewtonSolver(chrt_function, A_tx_10, 1e-9, 1e-10); //} A_tx_11 = myMath.NewtonSolver(chrt_function, A_tx_10, 1e-9, 1e-10); U_tx_11 = Q_t_1 / A_tx_11; core_node.velocity = U_tx_11 * v_sign[0]; core_node.lumen_sq = A_tx_11; core_node.pressure = P_tx_11; /* core_node.neighbours.Last().pressure = core_node.pressure; * core_node.neighbours.Last().velocity = core_node.velocity; * core_node.neighbours.Last().lumen_sq = core_node.lumen_sq;*/ P_tx_01 = P_tx_11; A_tx_01 = A_tx_11; U_tx_01 = U_tx_11; Q_t_0 = Q_t_1; }
static public bool LoadTopologyFromString(string text, out VascularNet r_vnet) { ILoadVascularNet vnet = new VascularNet(); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); string[] readText = text.Split(new[] { '\r', '\n' }); Regex regex = new Regex(@"^name:\s*(\w+)$", RegexOptions.IgnoreCase); int i = 0; while (!regex.IsMatch(readText[i])) { i++; if (i >= readText.Length) { throw new TopReadingException("No correct name of vascular system in found\n"); } } Match name_match = regex.Match(readText[i]); vnet.name = name_match.Groups[1].Value; Regex regex_1 = new Regex(@"^Coordinates:\s*$", RegexOptions.IgnoreCase); Regex regex_2 = new Regex(@"^Bonds:\s*$", RegexOptions.IgnoreCase); List <List <int> > bonds_index = new List <List <int> >(); int node_count = 0; int bond_string_count = 0; while (true) { i++; if (regex_1.IsMatch(readText[i])) { while (true) { i++; if (i >= readText.Length) { break; } //regex = new Regex(@"^\s*(\d+)\s+X:(-*\d+.\d+)\s+Y:(-*\d+.\d+)\s+Z:(-*\d+.\d+)\s+R:(-*\d+.\d+)\s+C:(\d+.\d+)$", RegexOptions.IgnoreCase); regex = new Regex(@"^\s*(\d+)\s+L:(-*\d+.\d+)\s+R:(-*\d+.\d+)\s+E:(-*\d+.\d+)\s+T:(-*\d+)$", RegexOptions.IgnoreCase); Match node_match = regex.Match(readText[i]); if (node_match.Groups.Count < 4) { //regex = new Regex(@"^\s*(\d+)\s+X:(-*\d+.\d+)\s+Y:(-*\d+.\d+)\s+Z:(-*\d+.\d+)\s+R:(-*\d+.\d+)$", RegexOptions.IgnoreCase); regex = new Regex(@"^\s*(\d+)\s+L:(-*\d+.\d+)\s+R:(-*\d+.\d+)$", RegexOptions.IgnoreCase); node_match = regex.Match(readText[i]); if (node_match.Groups.Count < 4) { break; } } int id = int.Parse(node_match.Groups[1].Value); //convert to meter from millimeter Vector1 position = new Vector1(double.Parse(node_match.Groups[2].Value) * 1e-3); double rad = double.Parse(node_match.Groups[3].Value); double elasticity = double.Parse(node_match.Groups[4].Value) * 1e6; int nodetype = int.Parse(node_match.Groups[5].Value); vnet.vascular_system.Add(new VascularNode(id, position, rad * 1e-3, elasticity, nodetype)); node_count++; } } else if (regex_2.IsMatch(readText[i])) { while (true) { i++; if (i >= readText.Length) { break; } regex = new Regex(@"(\d+)\s*", RegexOptions.IgnoreCase); MatchCollection node_match = regex.Matches(readText[i]); if (node_match.Count < 2) { break; } int id = int.Parse(node_match[0].Value); bonds_index.Add(new List <int>()); bonds_index[bonds_index.Count - 1].Add(id); for (int n = 1; n < node_match.Count; n++) { bonds_index[bonds_index.Count - 1].Add(int.Parse(node_match[n].Value)); } bond_string_count++; } } if (i >= readText.Length - 1) { foreach (var str in bonds_index) { VascularNode nd = vnet.vascular_system.Find(x => x.id == str[0]); for (int s = 1; s < str.Count; s++) { nd.addNeighbours(new VascularNode[] { vnet.vascular_system.Find(x => x.id == str[s]) }); } } break; } } r_vnet = (VascularNet)vnet; return(false); }
static public double Dot(Vector1 v1, Vector1 v2) { return(v1.x * v2.x); }
static public double Length(Vector1 v1) { return(Math.Sqrt((v1.x * v1.x))); }
static public double Distance(Vector1 v1, Vector1 v2) { return((double)Math.Abs(v1.x - v2.x)); }