made better

This commit is contained in:
dino.celebic 2026-01-26 17:56:16 +01:00
commit 1151fb33b2
4 changed files with 56 additions and 14 deletions

View file

@ -496,14 +496,13 @@ void Mesh::Visualize_paraview(vector<double> const &v) const
return; return;
} }
std::tuple<double,double> Mesh::AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const double Mesh::AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const
{ {
assert(2==Ndims()); assert(2==Ndims());
int const nnode = Nnodes(); // number of vertices in mesh int const nnode = Nnodes(); // number of vertices in mesh
assert( nnode == static_cast<int>(v.size()) ); assert( nnode == static_cast<int>(v.size()) );
double cumulative_element_temp = 0.0; double cumulative_element_temp = 0.0;
double elements_temp_reached = 0.0;
int subdomain_element_counter = 0; int subdomain_element_counter = 0;
for (int e = 0; e < Nelems(); ++e) // loop over all elements for (int e = 0; e < Nelems(); ++e) // loop over all elements
{ {
@ -519,16 +518,41 @@ std::tuple<double,double> Mesh::AverageVectorFunction_perSubdomain(std::vector<d
cumulative_node_temp += v[node]; // set function cumulative_node_temp += v[node]; // set function
} }
cumulative_element_temp += cumulative_node_temp/_nvert_e; cumulative_element_temp += cumulative_node_temp/_nvert_e;
}
}
return cumulative_element_temp/subdomain_element_counter;
}
if (cumulative_node_temp/_nvert_e > 67.0) // check if element has reached temp double Mesh::CheckTemp_mult(std::vector<double> &v, int target_sd, double goal_temp) const
{ {
elements_temp_reached++; // add to counter assert(2==Ndims());
int const nnode = Nnodes(); // number of vertices in mesh
assert( nnode == static_cast<int>(v.size()) );
double elements_temp_reached = 0.0;
int subdomain_element_counter = 0;
for (int e = 0; e < Nelems(); ++e) // loop over all elements
{
int sd = ElementSubdomains[e]; // get subdomain of element e
if (sd == target_sd) // if is target subdomain then
{
subdomain_element_counter++;
int base = e * _nvert_e; // get starting index of element in coordinate vector
double cumulative_node_temp = 0.0;
for (int k = 0; k < _nvert_e; ++k) // loop over vertices of element
{
int node = _ia[base + k]; // global index of vertex
cumulative_node_temp += v[node]; // set function
}
if (cumulative_node_temp/_nvert_e > goal_temp)
{
elements_temp_reached++;
} }
} }
} }
// average temperature % of elements reached temperature 67
return std::make_tuple(cumulative_element_temp/subdomain_element_counter, 100 * elements_temp_reached / static_cast<double>(subdomain_element_counter)); return 100 * elements_temp_reached / subdomain_element_counter;
} }

View file

@ -231,7 +231,9 @@ public:
[[nodiscard]] virtual std::vector<int> Index_DirichletNodes() const; [[nodiscard]] virtual std::vector<int> Index_DirichletNodes() const;
[[nodiscard]] std::tuple<double,double> AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const; [[nodiscard]] double AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const;
[[nodiscard]] double CheckTemp_mult(std::vector<double> &v, int target_sd, double goal_temp) const;
/** /**
* Determines the indices of those vertices with Dirichlet boundary conditions. * Determines the indices of those vertices with Dirichlet boundary conditions.

View file

@ -84,10 +84,12 @@ int main(int argc, char **argv )
auto t3 = system_clock::now(); // start timer auto t3 = system_clock::now(); // start timer
double average_cup_temperature = u0_mug; double average_cup_temperature = u0_mug;
double percentage_temp_reached = 0.0; double percentage_temp_reached = 0.0;
double goal_temp = 67.0;
double goal_perc = 60.0;
double time_count = 0; double time_count = 0;
while (average_cup_temperature < 67.0) while (average_cup_temperature < goal_temp)
// while (percentage_temp_reached < 60.0) // while (percentage_temp_reached < goal_perc)
//for (int step = 0; step < steps; ++step) //for (int step = 0; step < steps; ++step)
{ {
vector<double> G(Mdt.Nrows(), 0.0); vector<double> G(Mdt.Nrows(), 0.0);
@ -102,9 +104,10 @@ int main(int argc, char **argv )
JacobiSolve(SK, H, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n} JacobiSolve(SK, H, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
// ----- SK ----- ------ H ------- // ----- SK ----- ------ H -------
tie(average_cup_temperature, percentage_temp_reached) = mesh_c.AverageVectorFunction_perSubdomain(uv, 0); average_cup_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 0);
percentage_temp_reached = mesh_c.CheckTemp_mult(uv, 0, goal_temp);
cout << "Average cup temperature: " << average_cup_temperature << " after " << time_count << " seconds. " << endl; cout << "Average cup temperature: " << average_cup_temperature << " after " << time_count << " seconds. " << endl;
cout << "% of mug elements reached temperature 67º: " << percentage_temp_reached << endl; cout << "% of elements reached temperature " << goal_temp << "ºC: " << percentage_temp_reached << endl;
time_count += dt; time_count += dt;
} }
auto t4 = system_clock::now(); // stop timer auto t4 = system_clock::now(); // stop timer

View file

@ -88,9 +88,13 @@ int main(int argc, char **argv )
auto t3 = system_clock::now(); // start timer auto t3 = system_clock::now(); // start timer
double average_cup_temperature = u0_mug; double average_cup_temperature = u0_mug;
double percentage_temp_reached = 0.0;
double goal_temp = 67.0;
double goal_perc = 60.0;
double time_count = 0; double time_count = 0;
while (average_cup_temperature < 67.0) while (average_cup_temperature < goal_temp)
// while (percentage_temp_reached < goal_perc)
//for (int step = 0; step < steps; ++step) //for (int step = 0; step < steps; ++step)
{ {
vector<double> G(Mdt.Nrows(), 0.0); vector<double> G(Mdt.Nrows(), 0.0);
@ -106,7 +110,9 @@ int main(int argc, char **argv )
// ----- SK ----- ------ H ------- // ----- SK ----- ------ H -------
average_cup_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 0); average_cup_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 0);
percentage_temp_reached = mesh_c.CheckTemp_mult(uv, 0, goal_temp);
cout << "Average cup temperature: " << average_cup_temperature << " after " << time_count << " seconds. " << endl; cout << "Average cup temperature: " << average_cup_temperature << " after " << time_count << " seconds. " << endl;
cout << "% of elements reached temperature " << goal_temp << "ºC: " << percentage_temp_reached << endl;
time_count += dt; time_count += dt;
} }
auto t4 = system_clock::now(); // stop timer auto t4 = system_clock::now(); // stop timer
@ -124,6 +130,7 @@ int main(int argc, char **argv )
t3 = system_clock::now(); // start timer t3 = system_clock::now(); // start timer
double average_coffee_temperature = u0_coffee; double average_coffee_temperature = u0_coffee;
percentage_temp_reached = 0.0;
// ------------------------ initialize preCICE ------------------------ // ------------------------ initialize preCICE ------------------------
int commRank = 0; int commRank = 0;
@ -162,8 +169,12 @@ int main(int argc, char **argv )
// ------------------------ timestepping ------------------------ // ------------------------ timestepping ------------------------
goal_temp = 50.0;
goal_perc = 60.0;
time_count = 0; time_count = 0;
while (average_coffee_temperature > 50.0) while (average_cup_temperature > goal_temp)
// while (percentage_temp_reached > goal_perc)
{ {
preciceDt = participantSolid.getMaxTimeStepSize(); preciceDt = participantSolid.getMaxTimeStepSize();
solverDt = 1.0; solverDt = 1.0;
@ -190,7 +201,9 @@ int main(int argc, char **argv )
// ----- SK ----- ------ H ------- // ----- SK ----- ------ H -------
average_coffee_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 1); average_coffee_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 1);
percentage_temp_reached = mesh_c.CheckTemp_mult(uv, 0, goal_temp);
cout << "Average coffee temperature: " << average_coffee_temperature << " after " << time_count << " seconds. " << endl; cout << "Average coffee temperature: " << average_coffee_temperature << " after " << time_count << " seconds. " << endl;
cout << "% of elements reached temperature " << goal_temp << "ºC: " << percentage_temp_reached << endl;
// ----- write the heat-flux, so openFOAM can read it // ----- write the heat-flux, so openFOAM can read it
{ {