-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocate.cpp
73 lines (59 loc) · 1.6 KB
/
allocate.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
#include "structures.h"
int switchCase(int Case) {
int n;
switch (Case)
{
case 0: // уравнение переноса
n = 1;
break;
case 1: // классическая гидродинамика
n = 3;
break;
case 2:
n = 3;
break;
default:
break;
}
return n;
}
void makeArray (double** &A, unsigned int N, unsigned int cases) {
unsigned int nEq; // количество уравнений (строк в вектор-столбце)
nEq = switchCase(cases);
A = new double * [nEq];
for (int i = 0; i < nEq; i++) {
A[i] = new double [N];
}
}
void deleteArray (double** &A, unsigned int N, unsigned int cases) {
unsigned int nEq; // количество уравнений (строк в вектор-столбце)
nEq = switchCase(cases);
for (int i = 0; i < nEq; i++) {
delete [] A[i];
}
delete [] A;
}
void allocateStruct(parameters &var, int N, int cases) {
if (cases == 0)
{
var.velocity = new double [N];
}
if (cases == 1) {
var.velocity = new double [N];
var.pressure = new double [N];
var.energy = new double [N];
var.gamma = new double;
}
}
void deleteStruct(parameters &var, int N, int cases) {
if (cases == 0)
{
delete [] var.velocity;
}
if (cases == 1) {
delete [] var.velocity;
delete [] var.pressure;
delete [] var.energy;
delete var.gamma;
}
}