timestepping (not working)

This commit is contained in:
dino.celebic 2026-01-24 23:56:16 +01:00
commit 6a2db786c5
3 changed files with 57 additions and 29 deletions

View file

@ -26,6 +26,18 @@ int main(int argc, char **argv )
//mesh.Debug();
//mesh_c.DebugEdgeBased();
// ##########################################
// Parameteres
// ##########################################
double dt = 1.0; // time step
int steps = 1; // number of time iterations
double u0_mug = 18.0;
double u0_fluid = 80.0;
double u0_air = 18.0;
double u_out = 18.0;
// ##########################################
// Assembling
// ##########################################
@ -33,40 +45,53 @@ int main(int argc, char **argv )
// Initializing FEM matrix !pattern! (only zero entries now)
FEM_Matrix SK(mesh_c); // CRS matrix
//SK.writeBinary("sparseMatrix.bin");
//SK.Debug();
// SK.Debug();
vector<double> fv(SK.Nrows(), 0.0);
SK.CalculateRHS(fv, [](double x, double y) {return 0;}); // r.h.s.
SK.CalculateRHS(fv, [](double x, double y) {return 0;}); // rhs (f=0)
SK.CalculateLaplace_mult(fv); // stiffness matrix
SK.AddMass_mult(fv); // mass matrix
SK.ApplyRobinBC_mult(fv, 18.0); // apply Robin bnd
SK.CalculateLaplace_mult(fv); // stiffness matrix (+K)
SK.AddMass_mult(fv, 1.0/dt); // add mass matrix (+M/dt)
SK.ApplyRobinBC_mult(fv, u_out); // apply Robin-bnd (+C = +F)
// SK = M/dt + K + C = F
// SK.Debug();
// SK.CheckRowSum();
// SK.CheckMatrix();
FEM_Matrix Mdt(mesh_c);
Mdt.AddMass_mult(fv, 1.0/dt); // mass matrix (Mdt = M/dt)
SK.CheckRowSum();
SK.CheckMatrix();
// Mdt.Debug();
// Mdt.CheckRowSum();
// Mdt.CheckMatrix();
// ##########################################
// Timestepping
// Timestepping (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
// ##########################################
double dt = 1.0; // time step
int steps = 100; // number of time iterations
// Initialize temperature
vector<double> uv(SK.Nrows(), 0.0); // temperature
mesh_c.Init_Solution_mult(uv, 0, [](double x, double y) -> double { return 18; }); // mug
mesh_c.Init_Solution_mult(uv, 1, [](double x, double y) -> double { return 80; }); // fluid
mesh_c.Init_Solution_mult(uv, 2, [](double x, double y) -> double { return 18; }); // air
for (int i = 0; i < steps; ++i)
{
// TODO
}
// Initialize temperature u_0
vector<double> uv(SK.Nrows(), 0.0); // temperature
mesh_c.Init_Solution_mult(uv, 0, [u0_mug](double x, double y) -> double { return u0_mug; }); // mug
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
// TODO DINO
auto t3 = system_clock::now(); // start timer
//JacobiSolve(SK, fv, uv ); // solve the system of equations
for (int step = 0; step < steps; ++step)
{
vector<double> G(Mdt.Nrows(), 0.0);
Mdt.Mult(G, uv); // G = M/dt * u_{n}
for (size_t i = 0; i < Mdt.Nrows(); ++i)
{
fv[i] += G[i]; // F + G
}
JacobiSolve(SK, fv, uv); // solve: (M/dt + K + C) * u_{n+1} = F + M/dt * u_{n}
}
auto t4 = system_clock::now(); // stop timer
auto duration = duration_cast<microseconds>(t4 - t3); // duration in microseconds
double t_diff = static_cast<double>(duration.count()) / 1e6; // overall duration in seconds
cout << "JacobiSolve: timing in sec. : " << t_diff << endl;