improved setup for simulation (ii) and (iii)
This commit is contained in:
parent
9392099296
commit
d8fc085d57
4 changed files with 5443 additions and 85 deletions
|
|
@ -637,8 +637,8 @@ void FEM_Matrix::ApplyRobinBC_mult(std::vector<double> &f, const double u_out)
|
|||
int const EdgeNode1 = RobinEdgeNodes[2*i];
|
||||
int const EdgeNode2 = RobinEdgeNodes[2*i + 1];
|
||||
|
||||
cout << "Edge number " << EdgeNumber << ", subdomain: " << subdomain << " ";
|
||||
cout << "Node1: " << EdgeNode1 << " Node2: " << EdgeNode2 << " " << endl;
|
||||
// cout << "Edge number " << EdgeNumber << ", subdomain: " << subdomain << " ";
|
||||
// cout << "Node1: " << EdgeNode1 << " Node2: " << EdgeNode2 << " " << endl;
|
||||
|
||||
double x_1 = Coordinates[2*EdgeNode1];
|
||||
double y_1 = Coordinates[2*EdgeNode1 + 1];
|
||||
|
|
@ -653,7 +653,7 @@ void FEM_Matrix::ApplyRobinBC_mult(std::vector<double> &f, const double u_out)
|
|||
int ij = fetch(EdgeNode1, EdgeNode2);
|
||||
int ji = fetch(EdgeNode2, EdgeNode1);
|
||||
|
||||
cout << "ii: " << ii << ", jj: " << jj << ", ij: " << ij << ", ji: " << ji << endl;
|
||||
//cout << "ii: " << ii << ", jj: " << jj << ", ij: " << ij << ", ji: " << ji << endl;
|
||||
|
||||
_sk[ii] += EdgeLength*alpha/3;
|
||||
_sk[jj] += EdgeLength*alpha/3;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <cassert>
|
||||
#include <chrono> // timing
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <omp.h>
|
||||
using namespace std;
|
||||
|
|
@ -88,8 +89,8 @@ int main(int argc, char **argv )
|
|||
double goal_perc = 60.0;
|
||||
|
||||
double time_count = 0;
|
||||
while (average_cup_temperature < goal_temp)
|
||||
// while (percentage_temp_reached < goal_perc)
|
||||
//while (average_cup_temperature < goal_temp)
|
||||
while (percentage_temp_reached < goal_perc)
|
||||
//for (int step = 0; step < steps; ++step)
|
||||
{
|
||||
vector<double> G(Mdt.Nrows(), 0.0);
|
||||
|
|
@ -119,39 +120,58 @@ int main(int argc, char **argv )
|
|||
|
||||
mesh_c.Visualize(uv);
|
||||
|
||||
// // ################################## SIMULATION (ii) ##################################
|
||||
// double u0_coffee = 85.0;
|
||||
// mesh_c.Init_Solution_mult(uv, 1, [u0_coffee](double x, double y) -> double { return u0_coffee; }); // fluid
|
||||
|
||||
// t3 = system_clock::now(); // start timer
|
||||
// double average_coffee_temperature = u0_coffee;
|
||||
// output vector for simulation (iii)
|
||||
ofstream output_file("../solid-cpp/uv_1.txt");
|
||||
for (double node_value : uv)
|
||||
{
|
||||
output_file << node_value << endl;
|
||||
}
|
||||
output_file.close();
|
||||
|
||||
|
||||
// time_count = 0;
|
||||
// while (average_coffee_temperature > 50.0)
|
||||
// {
|
||||
// vector<double> G(Mdt.Nrows(), 0.0);
|
||||
// Mdt.Mult(G, uv); // G = M/dt * u_{n}
|
||||
// ################################## SIMULATION (ii) ##################################
|
||||
double u0_coffee = 85.0;
|
||||
mesh_c.Init_Solution_mult(uv, 1, [u0_coffee](double x, double y) -> double { return u0_coffee; }); // fluid
|
||||
|
||||
mesh_c.Visualize(uv);
|
||||
|
||||
t3 = system_clock::now(); // start timer
|
||||
double average_coffee_temperature = u0_coffee;
|
||||
goal_temp = 50.0;
|
||||
goal_perc = 60.0;
|
||||
percentage_temp_reached = mesh_c.CheckTemp_mult(uv, 1, goal_temp);
|
||||
|
||||
time_count = 0;
|
||||
//while (average_coffee_temperature > goal_temp)
|
||||
while (percentage_temp_reached > goal_perc)
|
||||
{
|
||||
vector<double> G(Mdt.Nrows(), 0.0);
|
||||
Mdt.Mult(G, uv); // G = M/dt * u_{n}
|
||||
|
||||
// vector<double> H = fv;
|
||||
// for (size_t i = 0; i < Mdt.Nrows(); ++i)
|
||||
// {
|
||||
// H[i] += G[i]; // H = F + G
|
||||
// }
|
||||
vector<double> H = fv;
|
||||
for (int i = 0; i < Mdt.Nrows(); ++i)
|
||||
{
|
||||
H[i] += G[i]; // H = F + G
|
||||
}
|
||||
|
||||
// JacobiSolve(SK, H, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
|
||||
// // ----- SK ----- ------ H -------
|
||||
JacobiSolve(SK, H, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
|
||||
// ----- SK ----- ------ H -------
|
||||
|
||||
// average_coffee_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 1);
|
||||
// cout << "Average coffee temperature: " << average_coffee_temperature << " after " << time_count << " seconds. " << endl;
|
||||
// time_count += dt;
|
||||
// }
|
||||
// t4 = system_clock::now(); // stop timer
|
||||
average_coffee_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 1);
|
||||
percentage_temp_reached = mesh_c.CheckTemp_mult(uv, 1, goal_temp);
|
||||
cout << "Average coffee temperature: " << average_coffee_temperature << " after " << time_count << " seconds. " << endl;
|
||||
cout << "% of elements above temperature " << goal_temp << "ºC: " << percentage_temp_reached << endl;
|
||||
time_count += dt;
|
||||
}
|
||||
t4 = system_clock::now(); // stop timer
|
||||
|
||||
|
||||
// duration = duration_cast<microseconds>(t4 - t3); // duration in microseconds
|
||||
// t_diff = static_cast<double>(duration.count()) / 1e6; // overall duration in seconds
|
||||
// cout << "\n\nJacobiSolve: timing in sec. : " << t_diff << endl;
|
||||
duration = duration_cast<microseconds>(t4 - t3); // duration in microseconds
|
||||
t_diff = static_cast<double>(duration.count()) / 1e6; // overall duration in seconds
|
||||
cout << "\n\nJacobiSolve: timing in sec. : " << t_diff << endl;
|
||||
|
||||
mesh_c.Visualize(uv);
|
||||
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue