Starting from:

$30

MATH233-Lab 1 Grid2D Solved

1.      Create a new C++ project.

2.      In this new project, create a new class named Grid2D. It will be used to represent 2dimensional grids with N × M points uniformly distributed over [xmin,xmax] × [ymin,ymax]. Nodes will be numbered according to the standard ”z-ordering”. ∆x,∆y will be the spatial resolutions.

3.      In which file should that class be defined? (hint: modularity ......)

4.      In the Grid2D class, define N,M,xmin,xmax,ymin,ymax,∆x,∆y as private variables. What types should they be? Why should they be private?

5.      Implement a constructor Grid2D(N,M,xmin,xmax,ymin,ymax]) that initialize the grid with the prescribed parameters and initialize the resolutions ∆x,∆y.

6.      Write two public functions i fromn(int n) and jfromn(int n) that take the index n of a grid point and return its logical coordinates (i,j) on the grid.

7.      Write the reverse function nfromij(int i,int j).

8.      Write a function xfromn(int n), that take the index of a node and return its position in the direction. Write the same function for the y-direction.

9.      Use the outputVTK.txt file to implement two functions initializeVTKfile and printQuantityinto VTKfile that create a vtk file with the grid information and output the values of a given quantity (defined on that grid) in a specified vtk file.

10.   Install paraview.

11.   Write a main file that

(a)    Create a Grid2D with your choice of parameters

(b)   Create a vector of size N × M representing the function cos(x)cos(y) over the grid.

(c)    Output the grid and the vector into one .vtk file

12.   Open your file in paraview. Does it look right?

(Further reading) what is the difference between a class and a struct

More products