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; Q_tx_01 = core_node.lumen_sq * core_node.velocity * v_sign[0]; Q_tx_10 = neighbour_node.lumen_sq * neighbour_node.velocity * v_sign[1]; U_tx_10 = neighbour_node.velocity * v_sign[1]; P_tx_01 = core_node.pressure; P_tx_10 = neighbour_node.pressure; double sound_speed = Math.Pow(core_node.lumen_sq, 0.25f) * Math.Sqrt(beta_1 / 2.0f / GlobalDefs.BLOOD_DENSITY); P_tx_11 = (interfunc_dx / sound_speed / dt * P_tx_01 - P_tx_10) / (1 + interfunc_dx / dt / sound_speed); Q_tx_11 = (interfunc_dx / sound_speed / dt * Q_tx_01 - Q_tx_10) / (1 + interfunc_dx / dt / sound_speed); A_tx_10 = neighbour_node.lumen_sq; chrt_frw_left = U_tx_10 + 4 * Math.Pow(A_tx_10, 0.25f) * Math.Sqrt(beta_1 / 2.0f / GlobalDefs.BLOOD_DENSITY); // A_tx_11 = myMath.NewtonSolver(chrt_function, A_tx_10, 1e-9, 1e-10); A_tx_11 = calcLumenSq(P_tx_11); core_node.velocity = Q_tx_11 / A_tx_11 * v_sign[0]; core_node.lumen_sq = A_tx_11; core_node.pressure = P_tx_11; //A_tx_11 = calcLumenSq(P_tx_11); Q_t_0 = Q_t_1; }
public override void doBC(double dt) { if (true) { previous_time = current_time; current_time = current_time + dt; previous_velocity = current_velocity; double flux = flux_on_time(current_time); //Console.WriteLine(flux); double inlet_lumen = myMath.NewtonSolver(flux_function, core_node.lumen_sq, core_node.lumen_sq_0 * 1e-4f, core_node.lumen_sq_0 * 1e-6); double U = flux / inlet_lumen; double dZ = Vector1.Distance(core_node.neighbours.Last().position, core_node.position); double dUdt = (U - previous_velocity) / dt; double dUdZ = (core_node.neighbours.Last().velocity *v_sign[1] - U) / dZ; double visc_term = (double)(GlobalDefs.FRICTION_C * GlobalDefs.BLOOD_VISC * Math.PI * U / GlobalDefs.BLOOD_DENSITY / inlet_lumen); double P = core_node.neighbours.Last().pressure + (dUdt + U * dUdZ + visc_term) * dZ * GlobalDefs.BLOOD_DENSITY; core_node.velocity = U * v_sign[0]; core_node.pressure = P; core_node.lumen_sq = inlet_lumen; //Console.WriteLine(core_node.velocity); chrt_back = core_node.velocity - 4 * Math.Pow(core_node.neighbours.Last().lumen_sq, 0.25f) * Math.Sqrt(beta_1 / 2.0f / GlobalDefs.BLOOD_DENSITY); current_velocity = U; } }
public override void doBCsteady(double dt, double pressure) { 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(R1); //Console.WriteLine(R2); //Console.WriteLine(C); 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/// //double dQdt = (Q_t_1 - Q_t_0) / dt; P_tx_11 = pressure; P_tx_10 = neighbour_node.pressure; U_tx_10 = neighbour_node.velocity * v_sign[1]; A_tx_10 = neighbour_node.lumen_sq; chrt_frw_left = U_tx_01 + 4 * Math.Pow(A_tx_10, 0.25f) * Math.Sqrt(beta_1 / 2.0f / GlobalDefs.BLOOD_DENSITY); 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; }
unsafe public override void calcThread(double dt) { current_time += dt; double dz = 0; curr_dt = dt; int L = nodes.GetLength(0); this.nodes2state(); //if (nodes.Last().id == 13234 || nodes.First().id == 13234) //{ // L = nodes.GetLength(0); //} // lumen_sq_old = (double[])lumen_sq.Clone(); #if FAST unsafe { fixed(double *v_ptr = &velocity[0]) { fixed(double *lum_ptr = &lumen_sq[0]) { fixed(double *p_ptr = &pressure[0]) { thread_solver.calc(v_ptr, lum_ptr, p_ptr, dt); } } } } #endif // this.nodes2state(); #if SAFE double[] velocity_pred = (double[])velocity.Clone(); double[] lumen_sq_pred = (double[])lumen_sq.Clone(); double[] pressure_pred = (double[])pressure.Clone(); for (int i = 1; i < L - 1; i++) { dz = Vector1.Distance(nodes[i].position, nodes[i - 1].position); //dz = 2.5e-3; velocity_pred[i] = velocity[i] - dt / dz * ((velocity[i] * velocity[i] / 2 + pressure[i] / GlobalDefs.BLOOD_DENSITY + g_energy[i]) - (velocity[i - 1] * velocity[i - 1] / 2 + pressure[i - 1] / GlobalDefs.BLOOD_DENSITY + g_energy[i - 1])); velocity_pred[i] = velocity_pred[i] - 1.0 / GlobalDefs.BLOOD_DENSITY / lumen_sq[i] * (GlobalDefs.FRICTION_C * viscosity[i] * Math.PI * velocity_pred[i]) * dt; lumen_sq_pred[i] = lumen_sq[i] - dt / dz * (lumen_sq[i] * velocity[i] - lumen_sq[i - 1] * velocity[i - 1]); pressure_pred[i] = calcPressure(lumen_sq_pred[i], i); //Console.WriteLine(i); } //for(int i=0; i<L;i++) //{ // if (nodes[i].blocked == true) // velocity_pred[i] = 0; //} for (int i = 1; i < L - 1; i++) { dz = Vector1.Distance(nodes[i].position, nodes[i + 1].position); //dz = 2.5e-3; velocity[i] = (velocity[i] + velocity_pred[i]) / 2 - dt / dz / 2 * ((velocity_pred[i + 1] * velocity_pred[i + 1] / 2 + pressure_pred[i + 1] / GlobalDefs.BLOOD_DENSITY + g_energy[i + 1]) - (velocity_pred[i] * velocity_pred[i] / 2 + pressure_pred[i] / GlobalDefs.BLOOD_DENSITY + g_energy[i])); velocity[i] = velocity[i] - 1.0 / 2.0 / GlobalDefs.BLOOD_DENSITY / lumen_sq[i] * (GlobalDefs.FRICTION_C * viscosity[i] * Math.PI * velocity[i]) * dt; lumen_sq[i] = (lumen_sq[i] + lumen_sq_pred[i]) / 2 - dt / dz / 2 * (lumen_sq_pred[i + 1] * velocity_pred[i + 1] - lumen_sq_pred[i] * velocity_pred[i]); pressure[i] = calcPressure(lumen_sq[i], i); } //for (int i = 0; i < L; i++) //{ // if (nodes[i].blocked == true) // velocity[i] = 0; //} if (L == 2) { velocity[0] = (velocity[0] + velocity[1]) / 2; velocity[1] = velocity[0]; pressure[0] = (pressure[0] + pressure[1]) / 2; pressure[1] = pressure[0]; lumen_sq[0] = (lumen_sq[0] + lumen_sq[1]) / 2; lumen_sq[1] = lumen_sq[0]; } if (L > 2) { velocity[L - 1] = velocity[L - 2]; velocity[0] = velocity[1]; pressure[L - 1] = pressure[L - 2]; pressure[0] = pressure[1]; lumen_sq[L - 1] = lumen_sq[L - 2]; lumen_sq[0] = lumen_sq[1]; } #endif this.state2nodes(); }
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; }