7
const char *project_info =
8
R"(//! Project: Laplace equation with Dirichlet BCs, No. 0
18
//! 0 +----------+-----> x
22
//! b1: $u=f1=u_exact$
23
//! b3: $u=f3=u_exact$
24
//! b2: $u=f2=u_exact$
25
//! b4: $u=f4=u_exact$
28
//! $u_{xx}+u_{yy}=4(x^2+y^2+1)e^{x^2+y^2}$
33
//! Boundary discretization method: inward 4-point differencing-scheme (INWARD_DIFF4)
34
//! Linear solver: GSL LU
41
xBoundary b1(1., 0., 1.);
42
xBoundary b2(0., 1., 0.);
43
yBoundary b3(1., 1., 0.);
44
yBoundary b4(0., 0., 1.);
47
mesh.set_boundaries({b3, b2, b4 ,b1});
49
DirichletBC bc1(b1, "f1");
50
DirichletBC bc2(b2, "f2");
51
DirichletBC bc3(b3, "f3");
52
DirichletBC bc4(b4, "f4");
54
// Part 1: declaration of fields and functions
56
Function f("f"), uex("exact_solution"), f1("f1"), f2("f2"), f3("f3"), f4("f4");
58
// Part 2: declaration and customization of PDE
62
// Part 3: set PDE fields, BCs and functions
66
// pde.set_BC(bc3, u);
67
// pde.set_BC(bc4, u);
68
pde.set_BCs({bc1, /*bc2, */bc3, bc4});
69
pde.set_functions({f, f1, f2, f3, f4, uex});
71
// This is the old way
72
pde.get_function("f").implementation = " {return 4*(x*x+y*y+1)*exp(x*x+y*y);}";
73
pde.get_function("f1").implementation = " {return exact_solution(x,y);}";
74
pde.get_function("f2").implementation = " {return exact_solution(x,y);}";
75
pde.get_function("f3").implementation = " {return exact_solution(x,y);}";
76
pde.get_function("f4").implementation = " {return exact_solution(x,y);}";
77
pde.get_function("exact_solution").implementation = " {return exp(x*x+y*y);}";
79
f.set_implementation(" {return 4*(x*x+y*y+1)*exp(x*x+y*y);}");
80
f1.set_implementation("exact_solution(x,y)");
81
f2.set_implementation("exact_solution(x,y)");
82
f3.set_implementation("exact_solution(x,y)");
83
f4.set_implementation("exact_solution(x,y)");
84
uex.set_implementation("exp(x*x+y*y)");
87
// Part 4: set PDE equations
88
pde("Dirichlet") = Dxx[u] + Dyy[u] - f;
91
std::cout << (pde.linear_BCs() ? " has linear BCs" : " has nonlinear BCs") << '\n';
93
std::cout << (pde.linear_eqs() ? " has linear eqs" : " has nonlinear eqs") << '\n';
95
std::cout << (pde.linear() ? " is linear." : " is nonlinear.") << '\n';
97
// Part 5: set methods
98
pde.set_library("gsl");
99
pde.set_matrix_method("LU");
102
pde.executable = "gsl2d_dir_0";
103
pde.compiler = "clang++";
104
pde.project_info = project_info;
105
pde.set_output("code/gsl2d_dir_0");
107
pde.generate_makefile();
109
catch (const std::string& msg)
111
std::cout << msg << std::endl;
114
catch (const char *msg)
116
std::cout << "Caught const char* exception!\n";
117
std::cout << msg << std::endl;