calculate average temperature in mug

This commit is contained in:
jakob.schratter 2026-01-26 09:20:41 +01:00
commit e458b93b28
5 changed files with 5398 additions and 5361 deletions

View file

@ -496,6 +496,34 @@ void Mesh::Visualize_paraview(vector<double> const &v) const
return;
}
double Mesh::AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const
{
assert(2==Ndims());
int const nnode = Nnodes(); // number of vertices in mesh
assert( nnode == static_cast<int>(v.size()) );
double cumulative_element_temp = 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
}
cumulative_element_temp += cumulative_node_temp/_nvert_e;
}
}
return cumulative_element_temp/subdomain_element_counter;
}
vector<int> Mesh::Index_DirichletNodes() const

View file

@ -229,6 +229,9 @@ public:
* Vector _bedges is currently not included in the 3D input file.
*/
[[nodiscard]] virtual std::vector<int> Index_DirichletNodes() const;
[[nodiscard]] double AverageVectorFunction_perSubdomain(std::vector<double> &v, int target_sd) const;
/**

View file

@ -433,7 +433,7 @@ double FEM_Matrix::ThermalConductivity(const int subdomain)
{
// ceramic mug
case 0:
lambda = 3.0; // anything from 1 to 4
lambda = 4.0; // anything from 1 to 4
break;
// water

View file

@ -31,7 +31,7 @@ int main(int argc, char **argv )
// ##########################################
double dt = 1.0; // time step
int steps = 20; // number of time iterations
//int steps = 200; // number of time iterations
double u0_mug = 18.0;
double u0_fluid = 80.0;
@ -76,9 +76,12 @@ int main(int argc, char **argv )
mesh_c.Init_Solution_mult(uv, 1, [u0_fluid](double x, double y) -> double { return u0_fluid; }); // fluid
mesh_c.Init_Solution_mult(uv, 2, [u0_air](double x, double y) -> double { return u0_air; }); // air
//mesh_c.Visualize(uv);
auto t3 = system_clock::now(); // start timer
for (int step = 0; step < steps; ++step)
double average_cup_temperature = u0_mug;
while (average_cup_temperature < 67)
//for (int step = 0; step < steps; ++step)
{
vector<double> G(Mdt.Nrows(), 0.0);
Mdt.Mult(G, uv); // G = M/dt * u_{n}
@ -91,6 +94,9 @@ int main(int argc, char **argv )
JacobiSolve(SK, H, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
// ----- SK ----- ------ H -------
average_cup_temperature = mesh_c.AverageVectorFunction_perSubdomain(uv, 0);
cout << "Average cup temperature: " << average_cup_temperature << endl;
}
auto t4 = system_clock::now(); // stop timer

File diff suppressed because it is too large Load diff