Cannot convert (double) to (double*)

Joined
Sep 5, 2022
Messages
1
Reaction score
0
Hello, I am new to programming in C and I am trying to program a 2d advection equation that can advance in time. I keep receiving errors about converting types and my solutions thus far have only led to further errors. Could you please explain what is causing this issue and any suggestions for how to begin remedying it. The code is below:

#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <math.h>
#include <omp.h>
#include "hdf5.h"
#include "hdf5_hl.h"
#include "CPyH5_V4.c"

#define RANK 100

void advection2dEq(double U[][RANK], double dt, double dx, double dy, double v_x, double v_y, int LB, int RB, int BB, int TB)
{
// Variables for use in U
int i, j, x, y;
double C_x = v_x * dt / dx;
double C_y = v_y * dt / dy;
double aM1 = C_x / 2 * (C_x + 1);
double a0 = 1 - pow(C_x, 2);
double aP1 = C_x / 2 * (C_x - 1);
double bM1 = C_y / 2 * (C_y + 1);
double b0 = 1 - pow(C_y, 2);
double bP1 = C_y / 2 * (C_y - 1);

// Creating boundary conditions
for (i = 0; i < RANK; i++)
{
U[0] = LB;
U[RANK - 1] = RB;
U[0] = BB;
U[RANK - 1] = TB;
}

// Updating every element in the array using the 2d advection equation with Lax-Wendroff numerical scheme
for (x = 0; x < RANK - 1; ++x)
{
for (y = 0; y < RANK - 1; ++y)
{
U = aM1 * U[x - 1][y] + a0 * U[x][y] + aP1 * U[x + 1][y] + bM1 * U[x][y - 1] + b0 * U[x][y] + bP1 * U[x][y + 1];
}
}
}

void initCond(double sigma, double x0, double y0)
{
double U, x, y, x_0, y_0;
U = exp((-pow((x - x_0), 2) - pow((y - y_0), 2))) / (2 * pow(sigma, 2));
}

int main(void)
{
// variables and setup user inputs
char file[10] = "Lab_01.h5";
double t = 0;
double nt = 121;
double dt = 0.01;
double v_x = 1 / sqrt(2);
double v_y = -(1 / sqrt(2));
double U[RANK][RANK] = {0};
double x0 = 0.5;
double y0 = 0.5;
double sigma = 0.05;

// memory allocation for array of doubles, U
//double **U = (double **)malloc(U[RANK] * U[RANK] * sizeof(double));

// calling functions to set up initial conditions then perform time advance
initCond(sigma, x0, y0);
// advection2dEq(U, dt, dx, dy, v_x, v_y, LB, RB, TB, BB);
}
 
Joined
Oct 15, 2022
Messages
1
Reaction score
0
can't you just get a pointer to your double by putting an & before the variable name and use that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top