150 likes | 280 Views
Exercises in Computational Mechanics. C.7 Finite Element Programming May 17, 2011. Objectives. Improvement of the basic FEM program of Kikuchi's book To make a FE mesh generation program To visualize results using " gnuplot " To consider inhomogeneous Dirichlet B.C.
E N D
Exercises in Computational Mechanics C.7 Finite Element Programming May 17, 2011
Objectives • Improvement of the basic FEM program of Kikuchi's book • To make a FE mesh generation program • To visualize results using "gnuplot" • To consider inhomogeneous Dirichlet B.C. • To consider inhomogeneous Neumann B.C. B.C.: Boundary Conditions
Mesh generation program for example 7-5 (1/2) - Use the linear triangular element - Divide one edge into m pieces (0, 1) (1, 1) ..... ..... ..... ..... j Number of nodes:(m+1) * (m+1) Number of elements:m * m * 2 ..... ..... ..... ..... Coordinates of nodes ..... ..... ..... ..... ..... ..... y i ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... (0, 0) (1, 0) Node connectivity of elements x n(i+1)(j+1) ni(j+1) eij+1 eij nij n(i+1)j
Mesh generation program for example 7.5 (2/2) G3 Boundary conditions for ex. 7-5 (p.109) (0, 1) (1, 1) ..... ..... G4 G1 ..... ..... Number of B.C.: 4 * m ..... ..... Node list: i +1 ,i=0,...,m i*(m+1) +1 ,i=1,...,m-1 i*(m+1)+m +1 ,i=1,...,m-1 m*(m+1)+i +1 ,i=0,...,m G1 ..... ..... G2 G2 ..... ..... G3 ..... ..... ..... ..... G4 y ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... (0, 0) (1, 0) Download: http://www.s.kyushu-u.ac.jp/~z6om05in/mkdata_e7-5.c Compiling: $ gcc -o mkdata_e7-5 mkdata_e7-5.c Usage: $ ./mkdata_e7-5 m > input.dat (m > 0) x
Improvement of the basic program for using "gnuplot" (1/2) void output4gnuplot(double fm[],double x[], double y[],intnnode) { int m, j; FILE *fp; m = sqrt(nnode); fp = fopen("output.dat", "w"); for (j = 0; j < nnode; j++) { fprintf(fp, "%e %e %e\n", x[j], y[j], fm[j]); if ((j+1)%m == 0) fprintf(fp, "\n"); } fclose(fp); } Download improved program: http://www.s.kyushu-u.ac.jp/~z6om05in/full_FEM.c Compiling: $ gcc -o full_FEMfull_FEM.c -lm Usage: $ ./full_FEM < input.dat
Visualization using "gnuplot" (2/2) $ ./mkdata_e7-5 5 > input.dat $ ./full_FEM < input.dat $ ls input.dat output.dat $ gnuplot gnuplot> set contour gnuplot> splot "output.dat" u 1:2:3 w l (0, 1) (1, 1) y x (0, 0) (1, 0)
Exercise Example 7.6 (p.112) (0, 1) (1, 1) Solving quarter model - G1 is homogeneous Dirichlet B.C. - G2 is homogeneous Neumann B.C. G2 ... (1) Improve "mkdata_e7-5" - making B.C. part (2) Solve a quarter model using "full_FEM" ... ... ... G1 G2 ... (0, 0) (1, 0) G1 y x
A boundary value problem Consider a boundary value problem,
Inhomogeneous Dirichlet boundary conditionsin the input data Boundary conditions in the input data - given as discretized data The basic program - considers homogeneous B.C. only, - requires the node list on Dirichlet boundaries, and - sets the other boundary the homogeneous Neumann boundary. To consider inhomogeneous Dirichlet B.C., - Node numbers and values must be specified in the input data. nbc ibc[1] ibc[2] ibc[3] ... ibc[nbc] nbc ibc[1] vbc[1] ibc[2] vbc[2] ibc[3] vbc[3] ... ibc[nbc] vbc[nbc]
How to consider Inhomogeneous Dirichlet B.C. In Chapter 4 (p.49) - Deletion BC columns/rows from the matrix and the vector Difficult to program!
Sample code for considering inhomogeneous Dirichlet B.C. for (i=0;i<nnode;i++) w[i] = 0.0; for (i=0;i<nbc;i++) w[ibc[i]-1] = - vbc[i]; for (i=0;i<nnode;i++) { for (j=0;j<nnode;j++) fm[i] += am[i][j] * w[j]; } for(i=0;i<nbc;i++) { ii=ibc[i]-1; fm[ii]=vbc[i]; for(j=0;j<nnode;j++) { am[ii][j]=0.0; am[j][ii]=0.0; } am[ii][ii]=1.0; } Download improved program: http://www.s.kyushu-u.ac.jp/~z6om05in/mkdata_p7-1.c http://www.s.kyushu-u.ac.jp/~z6om05in/full_FEM_p7-1.c Compiling: $ gcc -o mkdata_p7-1 mkdata_p7-1.c -lm $ gcc -o full_FEM_p7-1 full_FEM_p7-1.c -lm Usage: $ ./mkdata_p7-1 5 > input.dat $ ./full_FEM_p7-1 < input.dat
Exercise 7.1 (p.119) (1, 1) (0, 1) y x (0, 0) (1, 0)
Inhomogeneous Neumann boundary conditionsin the input data • To consider inhomogeneous Neumann B.C., • Node numbers, local edge numbers and values must be specified in the input data. ndbc idbc[1] vdbc[1] idbc[2] vdbc[2] idbc[3] vdbc[3] ... idbc[ndbc] vdbc[ndbc] nnbc inbc1[1] inbc2[1] vnbc[1] inbc1[2] inbc2[2] vnbc[2] inbc1[3] inbc2[3] vnbc[3] ... inbc1[nnbc] inbc2[nnbc] vnbc[nnbc] li e
Inhomogeneous Neumann B.C. in the program li e Download improved program: http://www.s.kyushu-u.ac.jp/~z6om05in/mkdata_p7-1e.c http://www.s.kyushu-u.ac.jp/~z6om05in/full_FEM_p7-1e.c Compiling: $ gcc -o mkdata_p7-1e mkdata_p7-1e.c -lm $ gcc -o full_FEM_p7-1e full_FEM_p7-1e.c -lm Usage: $ ./mkdata_p7-1e 5 > input.dat $ ./full_FEM_p7-1e < input.dat
Exercise 7.1e (1, 1) (0, 1) y x (0, 0) (1, 0)