Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "interfaces.h"
- int main(int argc, char** argv) {
- int i = 0, j = 0, k;
- // Storage:
- // All arrays are allocated as two-dimensional arrays. Although they are dynamically
- // allocated, they can be accessed as if they would be allocated statically:
- // int mien_coarse[ne_coarse][NEN];
- int (*mien_coarse)[NEN] = (int(*)[NEN]) malloc(sizeof(int)*nen*ne_coarse);
- double (*mxyz_coarse)[NSD] = (double(*)[NSD]) malloc(sizeof(double)*nsd*nn_coarse);
- double (*data_coarse)[NDF] = (double(*)[NDF]) malloc(sizeof(double)*ndf*nn_coarse);
- double (*mxyz_fine)[NSD] = (double(*)[NSD]) malloc(sizeof(double)*nsd*nn_fine);
- double (*data_fine)[NDF] = (double(*)[NDF]) malloc(sizeof(double)*ndf*nn_fine);
- // Use the following variables for timing
- double start_time; // Write start time to this variable
- double end_time; // Write end time to this variable
- // Read coarse mesh
- read_nodes(&mxyz_coarse[0][0], nn_coarse, nsd, "Data/mxyz.coarse");
- read_connectivity(&mien_coarse[0][0], ne_coarse, nen, "Data/mien.coarse");
- read_data(&data_coarse[0][0], nn_coarse, ndf, "Data/pres.coarse");
- // Read fine mesh
- read_nodes(&mxyz_fine[0][0], nn_fine, nsd, "Data/mxyz.fine");
- check_input(mxyz_coarse, mien_coarse, data_coarse, mxyz_fine, nn_fine, nn_coarse, ne_coarse);
- // TODO: Implement the projection of the coarse grid to the fine nodes. Use the following routine:
- // int check_with_tolerance(xi_eta_zeta, xe, ye, ze, xx, yy, zz, tol);
- // This function should return 1 if the fine node was found in the element and 0 if it was not found.
- // Use the following variables as input and output:
- double xi_eta_zeta[NSD]; // The parametric coordinats (can be computed in the function)
- double xe[NEN]; // The coarse element level x-coordinates
- double ye[NEN]; // The coarse element level y-coordinates
- double ze[NEN]; // The coarse element level z-coordinates
- double xx; // The fine node x-coordinate
- double yy; // The fine node y-coordinate
- double zz; // The fine node z-coordinate
- double tol; // A tolerance which can be used in the function
- // YOUR CODE STARTS HERE
- double xxbar;
- double yybar;
- double zzbar;
- double xbar[4];
- double ybar[4];
- double zbar[4];
- int n1, n2, n3, n4;
- int count;
- tol = 0.001;
- for(i = 0; i < nn_fine; i++){
- xx = mxyz_fine[i][0];
- yy = mxyz_fine[i][1];
- zz = mxyz_fine[i][2];
- for(j = 0; j < ne_coarse; j++){
- //printf("\t[%d]\n", j);
- n1 = mien_coarse[j][0]-1;
- n2 = mien_coarse[j][1]-1;
- n3 = mien_coarse[j][2]-1;
- n4 = mien_coarse[j][3]-1;
- xe[0] = mxyz_coarse[n1][0];
- xe[1] = mxyz_coarse[n2][0];
- xe[2] = mxyz_coarse[n3][0];
- xe[3] = mxyz_coarse[n4][0];
- ye[0] = mxyz_coarse[n1][1];
- ye[1] = mxyz_coarse[n2][1];
- ye[2] = mxyz_coarse[n3][1];
- ye[3] = mxyz_coarse[n4][1];
- ze[0] = mxyz_coarse[n1][2];
- ze[1] = mxyz_coarse[n2][2];
- ze[2] = mxyz_coarse[n3][2];
- ze[3] = mxyz_coarse[n4][2];
- //printf("%lf\n%lf\n%lf", xe[0] ,xe[1], xe[2]);
- if(check_with_tolerance(xi_eta_zeta, xe, ye, ze, xx, yy, zz, tol) == 1){
- for(k = 0; k < ndf; ++k){ // Loop over degrees of freedom and interpolate
- // TODO: Interpolate the data_fine[i][k]. This is the k-th degree of freedom of the i-th node.
- // In this project the number of degrees of freedom is 1. Use for interpolation the function
- double coarse_data[NEN]; // Store the coarse element-level data values in this array
- // YOUR CODE STARTS HERE
- coarse_data[0] = data_coarse[n1][0];
- coarse_data[1] = data_coarse[n2][0];
- coarse_data[2] = data_coarse[n3][0];
- coarse_data[3] = data_coarse[n4][0];
- data_fine[i][k] = interpolate_data(xi_eta_zeta, coarse_data);
- count++;
- }
- break;
- printf("node:%d\tcount:%d\n",i,count);
- // YOUR CODE STARTS HERE
- }
- else{
- //printf("\t\t\t\tno![%d]\n", j);
- continue;
- }
- }
- }
- for(i = 0; i < 11; i++){
- printf("\t\t%lf\n", data_fine[i][k]);
- }
- // DO NOT CHANGE THE FOLLOWING LINES
- // Output
- write_data(&data_fine[0][0], nn_fine, ndf, "Data/pres.fine");
- check_output(data_fine, nn_fine, tol);
- //check_data(&data_fine[0][0], nn_fine, ndf, "Data/pres.fine");
- /*for(i = 0; i < nn_fine; i++){
- printf("%lf\n", data_fine[i][0]);
- }*/
- // Deallocate memory
- free(mien_coarse);
- free(mxyz_coarse);
- free(mxyz_fine);
- free(data_coarse);
- free(data_fine);
- // Timing output
- double dt = end_time - start_time;
- unsigned nn = nn_fine;
- printf("TIMING OUTPUT:\n");
- printf("--------------\n");
- printf(" Needed %e seconds to project %u nodes.\n", dt, nn);
- printf("The tolerance for interpolating all nodes was: %e\n", tol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement