Hi.
In this segment, we'll begin looking at the coding template for
the second coding assignment which is homework three.
All right?
So, to begin with, let's look at the source file, main.cc.
All right?
Now, I've actually included two sets.
We have a source files and
header files for the 2D problem and for the 3D problem.
Okay?
So, let's look at the 2D problem first.
You can see,
it's basically the same structure as the previous homework assignment.
One difference is that now I'm setting the dimension equal to 2,
which we're then inputting as the template parameter for
our finite element method class.
The other difference is that, when we're generating the mesh,
instead of passing in a single integer, since it's 2D, we're passing in a vector
with two integers that defines the number of elements in each direction.
So here, the name of the vector is num of elements, or num_of_elems.
And for an example, I've set up four elements in the x direction and
eight elements in the y direction.
A four by eight element mesh.
Of course, you can change that as you're doing your programming, but
that's the set up.
Okay?
Other than that, it's pretty much the same.
We have generate mesh, set up system, assemble system, solve and output results.
We aren't calculating the L2-norm of these problems.
It's just you can, you can do it for a 2D problem, if you have the exact solution.
However, for the problems we give you,
we aren't giving you the exact solutions as well.
So, you don't need to bother calculating the L2-norm.
If you did however, you would still be able to look at the rate of convergence as
you increase the number of elements.
Another difference or two other differences are that in this case,
our constructor for problem object for a finite element class.
We don't have any constructor.
We don't have any inputs to the constructor because we are only doing
linear basis function, so we don't have to input the function order.
And since they've already split up the problem into a 2D and
a 3D problem, there aren't any further sub-problems after that.
There's only one 2D problem, and one 3D problem on this homework assignment.
So, there are no inputs to the constructor, okay?
So, let's go over to the template.
This is FEM homework 3a template.
We have the same header files here.
Again, using namespace deal two.
And if we scroll down to the declaration of the functions and
objects, let's look at that.
All right.
You'll notice that I didn't include the function C at node, whatever.
Because since we're doing linear basis functions, it's a lot easier to keep track
of what the value of C is at, whatever node you happen to be at, okay?
So I deleted that.
If it was useful to you, you're free to go ahead and write such a function yourself.
Now let's look at basis function and basis gradient.
There are a couple differences here.
First off, we have more inputs.
We still have the node number, but now we have C1 and C2.
Obviously we have two Coordinates since it's a 2D problem.
Also, with basis gradient instead of returning just a double,
since we are 2D the gradient is a 2D vector.
And so I'm returning the standard vector of doubles.
Okay?
The solution steps however are the same generate mesh to find boundary condition
setup system.
Assemble systems solve an output results.
Except of course that generate mesh accepts as
a vector of integers instead of just the single integer.
The D02 Class objects are the same.
The Gaussian quadrature rule is the same.
All the data structures in solutioning those are all the same in this assignment.
All right, so let's scroll down here, to the constructor.
Again we still have the same method of calling the constructor
of our class variables fe and dof_handler just as before.
But since we don't have problem and order as an input,
we don't need to worry about storing those.
We have the same destructors before as well.
All right?
Moving on to the basis function and the basis gradient.
Again, we talked about the differences in input, where I have node xi_1 and
xi_2 node.
But you'll still do it in the same way.
And probably in this case it wouldn't make sense to do a generalized functional,
though you can certainly go ahead and do that.
Since it's a lot simpler.
Since we're just doing linear basis functions and that end.
So we don't necessarily have so many notes as before.
You can just use a simple if statements.
If the note equals such and such.
Evaluate the basis functions using C1 and C2.
All right?
And then again, you'll return value.
Similar with basis gradient.
You notice here, when I declared this standard vector values,
which is what will be returned, I've already set the length,
or the size of values to be dim.
Of course, dim we've defined in main.cc, we've defined it to be two in this case.
So this creates a vector of length two.
If it initialized the contents to be 0, of course,
they would have been 0 automatically, anyway.
But you will need to go ahead and evaluate the basis gradients at the given nodes for
both components of this gradient vector.
All right?
In some ways, simpler than before because we're only dealing with linear basis
functions or rather, bilinear basis functions I should say, because it's 2D.
But of course since they are in two directions, that is something else for
you to consider.
All right?
At this point I should point out that DL2 again had some different node
numbering from the class.
All right? So let's go to the board here.
In the class, or rather in the lectures.
[SOUND] We went around the nodes, since we're only dealing with bilinear,
we only have nodes that have the vertices here.
But there's something like this, one, two, three, four.
All right?
In deal two, it's a little bit different.
Again as before as with the linear case.
We'll be starting at 0 in our numbering but we're always going left to right.
We go left to right, bottom to top.
So 0, 1 and then up here it's 2, 3.
Okay, so that's something for you to consider in your if statements.
What would've been basis function one according to the lectures is now basis
function zero according to DL2.
What would've been basis function two according
to the lectures is now basis function one according to DL2 and so on.
Okay.
Okay, so in this case remember we need to use the DL2 basis function node numbering.
All right?
Because we are using D02s mesh.
We're using D02s connectivity, matrices, and so on.
So remember to use D02s known numbering as you're creating your basis function and
the gradients of the basis function.
All right.
So moving on to generate mesh.
Again, it's very simple, there's not much for you to do.
You just have to define the limits of your domain, the left and right,
top and bottom.
So x min, x max, y min, y max.
And again, we'll use DL2s functions to create that mesh.
So not a lot for you to edit there.
And now we come to define boundary conditions.
Again, this is defining the Dirichlet boundary conditions.
In this homework,
homework three, you won't have any knowing boundary conditions, and
we actually don't even have a forcing function or a body force at all.
All right, sorry, in this case a forcing function since it's a temperature problem.
And so these Dirichlet boundary conditions are the only Dirichlet,
are the only boundary conditions we're applying.
Of course there are Neumann boundary conditions of zero,
which we don't have to do anything about in our coding.
Now I have, you actually have to create this function yourself but
it's going to be very, very similar to this same function,
to find conditions in the previous homework, alright.
You'll be looping over all of your notes and
you'll have an if statement to check to see what boundary you're on.
Now the difference is, that now you have both x and y coordinates.
And so, you'll need to check.
In order to check your boundary out, you'll have to specify,
are you checking the x value, or the y value?
The other difference comes in that, node locations
whereas before it was a vector, now it's a table.
Let me scroll back up to the top and so
you can see, table is a DL2 function or a DL2 data object.
And the two here just specifies that it's a two dimensional table.
All right?
And it holds doubles, okay?
So let me just sketch out what that would look like.
Two dimensional table, the row index,
is going to be the global degree of the global node number.
So it's just like the index and the vector of node location before.
So this will go up to, just the largest node number, global node number.
Okay?
So that specifies which node you're at.
The column just tells you which component of the position looking at,
you want to know.
Really it's telling you, do you want the x coordinate or the y coordinate.
Okay?
So for example if this is our mesh.
And I'm actually, not exactly sure how DL2 does the global node numbering in 2D.
So I'll just do it this way, but
again, DL2 does it in this, and they do it in a different way, so.
Anytime you want the global node number, you'll actually need to use local DUF
indices to go from a local to a global node number.
But let's say the value here is,
say this coordinate is 0,0 and just for
simplicity I'll make this 1,0, 2,0.
This would be 2,1.
This would be 2,2.
And so on.
Okay, so this table over here would look like this.
At Node zero, the x-coordinate is zero, the y-coordinate is zero.
At Node one, x is one, y is zero.
At Node two, x is two, y is zero again.
If we come down to Node five, for example,
x is still two, the y has a value of one and so on.
Okay.
So if I wanted the x coordinate at node five,
I would use node location.
At node five.
If I wanted the X location I would take 0.
And then that would return to me 2.
Okay?
So again, this is the global node number.
And the second component, the row, or sorry, the column number,
is the component.
Again, essentially X or Y or in the case of the 3D problem that we'll look at, Z.
Okay?
All right.
So with that, you should be able to fill in this defined boundary conditions
function pretty well.
Now, let's stop there in this segment and in the next segment,
we'll move on to looking at setup system and assemble system.