added subdomain support in Mesh class, CalculateLaplaceMult implementation

This commit is contained in:
jakob.schratter 2026-01-22 17:52:23 +01:00
commit 2e887c04bc
13 changed files with 4336 additions and 69057 deletions

View file

@ -23,9 +23,10 @@ int main(int argc, char **argv )
int nrefine = 0;
if (argc > 1) nrefine = atoi(argv[1]);
// generating the mesh
Mesh const mesh_c("../generate_mesh/coffee_cup.txt", "../generate_mesh/coffee_cup_sd.txt");
//Mesh const mesh_c("square_tiny.txt");
Mesh const mesh_c("square_100.txt");
//Mesh const mesh_c("square.txt");
bool ba = mesh_c.checkObtuseAngles();
if (ba) cout << "mesh corrected" << endl;
@ -34,33 +35,36 @@ int main(int argc, char **argv )
//mesh.Debug();
//mesh.DebugEdgeBased();
// Initializing FEM matrix !pattern! (only zero entries now)
FEM_Matrix SK(mesh); // CRS matrix
//SK.writeBinary("sparseMatrix.bin");
//SK.Debug();
vector<double> uv(SK.Nrows(), 0.0); // temperature
// Initialize RHS
vector<double> fv(SK.Nrows(), 0.0); // r.h.s.
SK.CalculateLaplace(fv); // matrix
SK.CalculateRHS(fv, [](double x, double y) { // rhs
return std::sin(M_PI * 2.5 * y) * (M_PI * M_PI * 2.5 * 2.5 * x * x - 2);
}
);
//SK.CheckRowSum();
SK.CheckMatrix();
// Calculate Matrix entries
SK.CalculateLaplaceMult(fv); // matrix
//SK.Debug();
// Two ways to initialize the vector
//mesh.SetValues(uv,f_zero); // user function
//mesh.SetValues(uv, [](double x, double y) -> double {return 0.0*x*y;} ); // lambda function
//mesh.SetValues(uv, [](double x, double y) -> double {return 5e-3*(x+1)*(y+1);} ); // lambda function
//
mesh.SetValues(uv, [](double x, double y) -> double {
return x *x * std::sin(2.5 * M_PI * y);
} );
// Calculate RHS
SK.CalculateRHS(fv, [](double x, double y) { // rhs
return std::sin(M_PI * 2.5 * y) * (M_PI * M_PI * 2.5 * 2.5 * x * x - 2); });
//SK.CheckRowSum();
SK.CheckMatrix();
// Initialize temperature
vector<double> uv(SK.Nrows(), 0.0); // temperature
mesh.SetValues(uv, [](double x, double y) -> double { return 18; } ); // initial temperature of every domain
// Apply BC
SK.ApplyDirichletBC(uv, fv);
// Solve
auto exact_sol(uv);
//SK.Mult(fv,uv);
@ -73,6 +77,8 @@ int main(int argc, char **argv )
double t_diff = static_cast<double>(duration.count()) / 1e6; // overall duration in seconds
cout << "JacobiSolve: timing in sec. : " << t_diff << endl;
// Calculate error and visualize
auto [val, idx] = findLargestAbsError(exact_sol, uv, 1e+6, 100);
//mesh.Visualize(getAbsError(exact_sol, uv));