Vectors u, bc and bound_f
are initialized from member function get of the instance of
class Prescription:
p.get(BOUNDARY_CONDITION,bc);
p.get(SOURCE,body_f);
p.get(FLUX,bound_f);
|
Note that BOUNDARY_CONDITION, SOURCE and
FLUX are integers defined in an enum variable. They enable selecting the
type of condition to enforce.
Since we deal with a diffusion-convection problem, we have to provide a velocity vector.
We first instantiate the velocity vector, check if the project file contains the flag for
velocity. In this case, we read by using class
IOField the vector
v:
Vect<double> v(ms,2);
if (data.getInteger("v_flag")) {
IOField ff(data.getMeshFile(),data.getString("v_file"),ms,IOField::IN);
ff.get(v);
}
|
We can now declare an equation. We instantiate class DC2DT3 that solves
diffusion-convection equations in 2-D using triangular P1 (3-node) elements.
After instantiation, we transfer to the class various informations: the mesh, the vector
u that will contain solution at nodes, boundary condition vector, source vector,
and velocity vector.
DC2DT3 eq;
eq.setMesh(ms);
eq.setInput(SOLUTION,u);
eq.setInput(BOUNDARY_CONDITION,bc);
eq.setInput(SOURCE,body_f);
eq.setInput(FLUX,bound_f);
eq.setInput(VELOCITY_FIELD,v);
|
With all these data, we can choose some options for the solver. Namely, we define the terms
in the equation (Diffusion and convection) and then choose an iterative solver (Gmres) coupled
with the ILU preconditioner. We then solve the problem by invoking the member function
run:
eq.setTerms(DIFFUSION|CONVECTION);
eq.setSolver(GMRES_SOLVER,ILU_PREC);
int it = eq.run();
|
We end the program by outputting the solution and saving it for plotting purposes:
if (data.getOutput() > 0)
cout << u;
if (data.getPlot()) {
IOField pf(data.getPlotFile(),IOField::OUT);
pf.put(u);
}
|