Passing and receiving array from function

Hi all,
Would you please guide me about my problem?
The code below is not yet complete and I have to add a lot. BUT
My teacher told me to call the particle velocity array from void function and add it to line 46 (between two for loops). Would you please tell me how to do it?

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  #include <iostream>
#include <cmath>
using namespace std;


int np=100;
int nx=200, ny=200;
int dt=0.1;
double dist;




double euler(double u, double u_previous_time_step){
double a;
	a=(dt/2)*(u_previous_time_step + u);

	return a;
}



void particle_velocity(double **x, double **u, double ***fluid_u){
	int px, py;
    int j,n;

	px=int(x[n][0]);
	py=int(x[n][1]);

	for (j=0; j<2; j++){
	u[n][j] = fluid_u[px][py][j];
	}
}

int main(){
	int n; int i;
	int tmax, t;
	int n1,n2;
	double x[np][2], u[np][2];
	double u_previous_time_step[n][2];

	double fluid_u[nx][ny][2];

	while(t<tmax){
		for (n=0; n<np; n++){
			
			for (i=0; i<2; i++){
				x[n][i]+=euler(u[n][i], u_previous_time_step[n][i]);
				u_previous_time_step[n][i]=u[n][i];
			}
		}
		t=t+dt;
		for(n1=0; n1<np; n1++)
			for(n2=0; n2<np; n2++)
				for (i=0; i<2; i++){
					dist= (x[n2][i])-(x[n1][i]);
			}
	}

	return 0;
}
Last edited on
First look at this snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int np=100;
int nx=200, ny=200;
int dt=0.1;
double dist;

...

int main(){
	int n; int i;
	int tmax, t;
	int n1,n2;
	double x[np][2], u[np][2]; // np must be a compile time const.
	double u_previous_time_step[n][2]; // n must be a compile constant, plus you use n uninitialized here.

	double fluid_u[nx][ny][2];


In C++ array sizes must be compile time constants.

My teacher told me to call the particle velocity array from void function and add it to line 46 (between two for loops). Would you please tell me how to do it?


What have you tried? What exactly don't you understand?

Topic archived. No new replies allowed.