Grid value range

Feb 4, 2019 at 2:44am
Dear friends
In the following code I trying to create a box with 100x100 lines by varying the value of grid. I however could create a box with 50x50 when I used grid=50.
Can some one suggest any solution?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include<stdlib.h>
#include<iostream> 				
#define grid 100
int i,j;
double dx = 1.0/(grid);	// grid size along x axis.
double dy = 1.0/(grid);	// grid size along y axis
using namespace std;
	int main (void)
{	
FILE *fP2;
	fP2= fopen("Box(%dx%d).plt", "w");
	fprintf(fP2, "VARIABLES=x,y \n");
	fprintf(fP2, "ZONE I=%d, J=%d, F=BLOCK, \n\n", grid+1, grid+1);
			//y node point
			for (j=0; j <=(grid); j++)
		{
		for (i=0; i<=(grid) ; i++)
		        {
				fprintf(fP2, "%.7lf", j*dx);
				fprintf(fP2, "\t");
			}
		}
fprintf(fP2, "\n\n\n");
	// x node point
		for (j=0; j <=(grid); j++)
	{
	for (i=0; i<=(grid); i++)
	         {
			fprintf(fP2, "%.7lf", i*dy);
			fprintf(fP2, "\t");
		}
	}
		fprintf(fP2, "\n\n\n");

		fclose(fP2);
cout<<"calculation is complete!!\n";
system("pause");
return (0);
}

Last edited on Feb 4, 2019 at 2:44am
Feb 4, 2019 at 4:07am
for (j=0; j <=(grid); j++)
this is 101 iterations, not 100, is this what you meant?

what exactly does it do wrong?
Feb 4, 2019 at 4:23am
> create a box with 100x100 lines by varying the value of grid.
> I however could create a box with 50x50 when I used grid=50
Yes, the first exercise would be to try it with a box of 5x5

For one thing, you can craft a 5x5 box by hand and post the results here so we have some idea what you're talking about.

And you need to indent your code better.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include<stdlib.h>
#include<iostream>
#define grid 100
int i, j;
double dx = 1.0 / (grid);       // grid size along x axis.
double dy = 1.0 / (grid);       // grid size along y axis
using namespace std;
int main(void)
{
  FILE *fP2;
  fP2 = fopen("Box(%dx%d).plt", "w");
  fprintf(fP2, "VARIABLES=x,y \n");
  fprintf(fP2, "ZONE I=%d, J=%d, F=BLOCK, \n\n", grid + 1, grid + 1);

  //y node point
  for (j = 0; j <= (grid); j++) {
    for (i = 0; i <= (grid); i++) {
      fprintf(fP2, "%.7lf", j * dx);
      fprintf(fP2, "\t");
    }
  }
  fprintf(fP2, "\n\n\n");

  // x node point
  for (j = 0; j <= (grid); j++) {
    for (i = 0; i <= (grid); i++) {
      fprintf(fP2, "%.7lf", i * dy);
      fprintf(fP2, "\t");
    }
  }
  fprintf(fP2, "\n\n\n");

  fclose(fP2);
  cout << "calculation is complete!!\n";
  system("pause");
  return (0);
}


> #define grid 100
It's C++, so
const int grid = 100;

> int i, j;
> double dx = 1.0 / (grid); // grid size along x axis.
> double dy = 1.0 / (grid); // grid size along y axis
There's no reason for these to be global variables.
In fact, your i,j variables should be declared directly in the loops which use them - for ( int i ...


> fopen("Box(%dx%d).plt", "w");
Were you trying to get a filename called Box(50x50).plt by any chance?


Feb 4, 2019 at 4:47am
When grid value is 50 the box is created, however when I change the grid value to 100 the box is not created.
Yes Box(50x50).plt is the file name, I open this in Techplot.
Feb 4, 2019 at 12:42pm
Your code produced a file
Box(%dx%d).plt
for grid=100.

This plotted fine as a Tecplot file in VisIt ( https://wci.llnl.gov/simulation/computer-codes/visit ), so it will almost certainly plot OK in Tecplot.

Check:
- you have the correct name of file;
- you have a legitimate, fully-licensed version of Tecplot (not some under-functioned student version ... or worse)

Feb 4, 2019 at 12:56pm
If you want a proper filename (with the dimensions)

1
2
3
char filename[100];
sprintf(filename,"Box(%dx%d).plt",grid,grid);
fP2 = fopen(filename, "w");
Feb 4, 2019 at 4:14pm
OK, I've just tried Tecplot itself. I'm using the 2014 version. It doesn't like the length of your lines. You may want to reduce the number of records per line. You can reduce that to one item per line if you want. If you replace both \t (tab) with \n (newline) I managed to get the following grid plot:
https://imgur.com/a/GHDA5Iw
Last edited on Feb 4, 2019 at 5:00pm
Feb 5, 2019 at 5:27am
Thanks @lastchance it worked with replacing \t with \n.
Topic archived. No new replies allowed.