WIP: Pull Request for a complete Solver package #1
@ -15,7 +15,7 @@ bcRight 3 #
|
|||||||
gx 0.0 # Body forces (e.g. gravity)
|
gx 0.0 # Body forces (e.g. gravity)
|
||||||
gy 0.0 #
|
gy 0.0 #
|
||||||
|
|
||||||
re 36500.0 # Reynolds number
|
re 7500.0 # Reynolds number
|
||||||
|
|
||||||
u_init 1.0 # initial value for velocity in x-direction
|
u_init 1.0 # initial value for velocity in x-direction
|
||||||
v_init 0.0 # initial value for velocity in y-direction
|
v_init 0.0 # initial value for velocity in y-direction
|
||||||
|
@ -17,7 +17,7 @@ gy 0.0 #
|
|||||||
|
|
||||||
re 10.0 # Reynolds number
|
re 10.0 # Reynolds number
|
||||||
|
|
||||||
u_init 0.0 # initial value for velocity in x-direction
|
u_init 1.0 # initial value for velocity in x-direction
|
||||||
v_init 0.0 # initial value for velocity in y-direction
|
v_init 0.0 # initial value for velocity in y-direction
|
||||||
p_init 0.0 # initial value for pressure
|
p_init 0.0 # initial value for pressure
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ gamma 0.9 # upwind differencing factor gamma
|
|||||||
# Particle Tracing Data:
|
# Particle Tracing Data:
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
|
||||||
numberOfParticles 30
|
numberOfParticles 200
|
||||||
startTime 0
|
startTime 0
|
||||||
injectTimePeriod 2.0
|
injectTimePeriod 0.5
|
||||||
writeTimePeriod 0.2
|
writeTimePeriod 0.2
|
||||||
|
|
||||||
x1 0.1
|
x1 0.1
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,9 +8,20 @@
|
|||||||
#define __SOLVER_H_
|
#define __SOLVER_H_
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
|
|
||||||
enum OBJECTBOUNDARY { NONE = 0, TOP, BOTTOM, LEFT, RIGHT, TOPLEFT, BOTTOMLEFT, TOPRIGHT, BOTTOMRIGHT, LOCAL };
|
enum OBJECTBOUNDARY {
|
||||||
|
NONE = 0,
|
||||||
|
TOP,
|
||||||
|
BOTTOM,
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
TOPLEFT,
|
||||||
|
BOTTOMLEFT,
|
||||||
|
TOPRIGHT,
|
||||||
|
BOTTOMRIGHT,
|
||||||
|
LOCAL
|
||||||
|
};
|
||||||
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
||||||
/// @brief
|
/// @brief
|
||||||
enum SHAPE { NOSHAPE = 0, RECT, CIRCLE };
|
enum SHAPE { NOSHAPE = 0, RECT, CIRCLE };
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -22,7 +33,7 @@ typedef struct {
|
|||||||
double *p, *rhs;
|
double *p, *rhs;
|
||||||
double *f, *g;
|
double *f, *g;
|
||||||
double *u, *v;
|
double *u, *v;
|
||||||
int *s;
|
int* s;
|
||||||
/* parameters */
|
/* parameters */
|
||||||
double eps, omega, rho;
|
double eps, omega, rho;
|
||||||
double re, tau, gamma;
|
double re, tau, gamma;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 208 KiB |
@ -1,8 +1,8 @@
|
|||||||
unset border; unset tics; unset key;
|
unset border; unset tics; unset key;
|
||||||
set term gif animate delay 50
|
set term gif animate delay 30
|
||||||
set output "trace.gif"
|
set output "trace.gif"
|
||||||
set xrange [0:7]
|
set xrange [0:1]
|
||||||
set yrange [0:1.5]
|
set yrange [0:1]
|
||||||
|
|
||||||
do for [ts=0:120] {
|
do for [ts=0:120] {
|
||||||
plot "particles_".ts.".dat" with points pointtype 7
|
plot "particles_".ts.".dat" with points pointtype 7
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 478 KiB |
74
BasicSolver/3D-seq/backstep.par
Normal file
74
BasicSolver/3D-seq/backstep.par
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#==============================================================================
|
||||||
|
# Laminar Canal Flow
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
# Problem specific Data:
|
||||||
|
# ---------------------
|
||||||
|
|
||||||
|
name backstep # name of flow setup
|
||||||
|
|
||||||
|
bcTop 1 # flags for boundary conditions
|
||||||
|
bcBottom 1 # 1 = no-slip 3 = outflow
|
||||||
|
bcLeft 3 # 2 = free-slip 4 = periodic
|
||||||
|
bcRight 3 #
|
||||||
|
|
||||||
|
gx 0.0 # Body forces (e.g. gravity)
|
||||||
|
gy 0.0 #
|
||||||
|
|
||||||
|
re 36500.0 # Reynolds number
|
||||||
|
|
||||||
|
u_init 1.0 # initial value for velocity in x-direction
|
||||||
|
v_init 0.0 # initial value for velocity in y-direction
|
||||||
|
p_init 1.0 # initial value for pressure
|
||||||
|
|
||||||
|
# Geometry Data:
|
||||||
|
# -------------
|
||||||
|
|
||||||
|
xlength 7.0 # domain size in x-direction
|
||||||
|
ylength 1.5 # domain size in y-direction
|
||||||
|
imax 210 # number of interior cells in x-direction
|
||||||
|
jmax 45 # number of interior cells in y-direction
|
||||||
|
|
||||||
|
# Time Data:
|
||||||
|
# ---------
|
||||||
|
|
||||||
|
te 60.0 # final time
|
||||||
|
dt 0.02 # time stepsize
|
||||||
|
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||||
|
|
||||||
|
# Pressure Iteration Data:
|
||||||
|
# -----------------------
|
||||||
|
|
||||||
|
itermax 500 # maximal number of pressure iteration in one time step
|
||||||
|
eps 0.0001 # stopping tolerance for pressure iteration
|
||||||
|
rho 0.52
|
||||||
|
omg 1.8 # relaxation parameter for SOR iteration
|
||||||
|
gamma 0.9 # upwind differencing factor gamma
|
||||||
|
|
||||||
|
# Particle Tracing Data:
|
||||||
|
# -----------------------
|
||||||
|
|
||||||
|
numberOfParticles 200
|
||||||
|
startTime 0
|
||||||
|
injectTimePeriod 1.0
|
||||||
|
writeTimePeriod 0.5
|
||||||
|
|
||||||
|
x1 0.0
|
||||||
|
y1 0.5
|
||||||
|
x2 0.0
|
||||||
|
y2 1.5
|
||||||
|
|
||||||
|
# Obstacle Geometry Data:
|
||||||
|
# -----------------------
|
||||||
|
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||||
|
|
||||||
|
shape 1
|
||||||
|
xCenter 0.0
|
||||||
|
yCenter 0.0
|
||||||
|
zCenter 0.0
|
||||||
|
xRectLength 2.0
|
||||||
|
yRectLength 1.0
|
||||||
|
zRectLength 1.0
|
||||||
|
circleRadius 1.0
|
||||||
|
|
||||||
|
#===============================================================================
|
@ -31,14 +31,14 @@ p_init 0.0 # initial value for pressure
|
|||||||
xlength 30.0 # domain size in x-direction
|
xlength 30.0 # domain size in x-direction
|
||||||
ylength 4.0 # domain size in y-direction
|
ylength 4.0 # domain size in y-direction
|
||||||
zlength 4.0 # domain size in z-direction
|
zlength 4.0 # domain size in z-direction
|
||||||
imax 40 # number of interior cells in x-direction
|
imax 100 # number of interior cells in x-direction
|
||||||
jmax 10 # number of interior cells in y-direction
|
jmax 40 # number of interior cells in y-direction
|
||||||
kmax 10 # number of interior cells in z-direction
|
kmax 40 # number of interior cells in z-direction
|
||||||
|
|
||||||
# Time Data:
|
# Time Data:
|
||||||
# ---------
|
# ---------
|
||||||
|
|
||||||
te 100.0 # final time
|
te 60.0 # final time
|
||||||
dt 0.02 # time stepsize
|
dt 0.02 # time stepsize
|
||||||
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||||
|
|
||||||
@ -65,4 +65,17 @@ z1 1.0
|
|||||||
x2 1.0
|
x2 1.0
|
||||||
y2 4.0
|
y2 4.0
|
||||||
z2 1.0
|
z2 1.0
|
||||||
|
|
||||||
|
# Obstacle Geometry Data:
|
||||||
|
# -----------------------
|
||||||
|
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||||
|
|
||||||
|
shape 2
|
||||||
|
xCenter 10.0
|
||||||
|
yCenter 2.0
|
||||||
|
zCenter 2.0
|
||||||
|
xRectLength 8.0
|
||||||
|
yRectLength 2.0
|
||||||
|
zRectLength 2.0
|
||||||
|
circleRadius 1.0
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
@ -65,4 +65,17 @@ z1 1.0
|
|||||||
x2 1.0
|
x2 1.0
|
||||||
y2 4.0
|
y2 4.0
|
||||||
z2 1.0
|
z2 1.0
|
||||||
|
|
||||||
|
# Obstacle Geometry Data:
|
||||||
|
# -----------------------
|
||||||
|
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||||
|
|
||||||
|
shape 1
|
||||||
|
xCenter 10.0
|
||||||
|
yCenter 2.0
|
||||||
|
zCenter 2.0
|
||||||
|
xRectLength 8.0
|
||||||
|
yRectLength 2.0
|
||||||
|
zRectLength 2.0
|
||||||
|
circleRadius 1.0
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
85
BasicSolver/3D-seq/karman.par
Normal file
85
BasicSolver/3D-seq/karman.par
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#==============================================================================
|
||||||
|
# Laminar Canal Flow
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
# Problem specific Data:
|
||||||
|
# ---------------------
|
||||||
|
|
||||||
|
name karman # name of flow setup
|
||||||
|
|
||||||
|
bcTop 1 # flags for boundary conditions
|
||||||
|
bcBottom 1 # 1 = no-slip 3 = outflow
|
||||||
|
bcLeft 3 # 2 = free-slip 4 = periodic
|
||||||
|
bcRight 3 #
|
||||||
|
|
||||||
|
gx 0.0 # Body forces (e.g. gravity)
|
||||||
|
gy 0.0 #
|
||||||
|
|
||||||
|
re 5050.0 # Reynolds number
|
||||||
|
|
||||||
|
u_init 1.0 # initial value for velocity in x-direction
|
||||||
|
v_init 0.0 # initial value for velocity in y-direction
|
||||||
|
p_init 0.0 # initial value for pressure
|
||||||
|
|
||||||
|
# Geometry Data:
|
||||||
|
# -------------
|
||||||
|
|
||||||
|
xlength 30.0 # domain size in x-direction
|
||||||
|
ylength 8.0 # domain size in y-direction
|
||||||
|
imax 400 # number of interior cells in x-direction
|
||||||
|
jmax 200 # number of interior cells in y-direction
|
||||||
|
|
||||||
|
# Time Data:
|
||||||
|
# ---------
|
||||||
|
|
||||||
|
te 150.0 # final time
|
||||||
|
dt 0.02 # time stepsize
|
||||||
|
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||||
|
|
||||||
|
# Pressure Iteration Data:
|
||||||
|
# -----------------------
|
||||||
|
|
||||||
|
itermax 200 # maximal number of pressure iteration in one time step
|
||||||
|
eps 0.001 # stopping tolerance for pressure iteration
|
||||||
|
rho 0.52
|
||||||
|
omg 1.75 # relaxation parameter for SOR iteration
|
||||||
|
gamma 0.9 # upwind differencing factor gamma
|
||||||
|
|
||||||
|
# Particle Tracing Data:
|
||||||
|
# -----------------------
|
||||||
|
|
||||||
|
numberOfParticles 200
|
||||||
|
startTime 50
|
||||||
|
injectTimePeriod 1.0
|
||||||
|
writeTimePeriod 0.5
|
||||||
|
|
||||||
|
x1 0.0
|
||||||
|
y1 3.8
|
||||||
|
x2 0.0
|
||||||
|
y2 4.1
|
||||||
|
|
||||||
|
# Obstacle Geometry Data:
|
||||||
|
# -----------------------
|
||||||
|
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||||
|
|
||||||
|
shape 2
|
||||||
|
xCenter 5.0
|
||||||
|
yCenter 4.0
|
||||||
|
xRectLength 2.0
|
||||||
|
yRectLength 1.0
|
||||||
|
circleRadius 1.0
|
||||||
|
|
||||||
|
# Obstacle Geometry Data:
|
||||||
|
# -----------------------
|
||||||
|
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||||
|
|
||||||
|
shape 1
|
||||||
|
xCenter 10.0
|
||||||
|
yCenter 2.0
|
||||||
|
zCenter 2.0
|
||||||
|
xRectLength 8.0
|
||||||
|
yRectLength 2.0
|
||||||
|
zRectLength 2.0
|
||||||
|
circleRadius 1.0
|
||||||
|
|
||||||
|
#===============================================================================
|
1929
BasicSolver/3D-seq/sample.txt
Normal file
1929
BasicSolver/3D-seq/sample.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,18 +12,16 @@
|
|||||||
|
|
||||||
#include "allocate.h"
|
#include "allocate.h"
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
|
#include "particletracing.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
#include "solver.h"
|
#include "solver.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include "vtkWriter.h"
|
#include "vtkWriter.h"
|
||||||
#include "particletracing.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define G(v, i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
#define G(v, i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
|
|
||||||
enum VARIANT { SOR = 1, RB, RBA };
|
enum VARIANT { SOR = 1, RB, RBA };
|
||||||
|
|
||||||
|
|
||||||
static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, double* wg)
|
static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, double* wg)
|
||||||
{
|
{
|
||||||
int imax = s->grid.imax;
|
int imax = s->grid.imax;
|
||||||
@ -87,8 +85,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
readParameter(¶ms, argv[1]);
|
readParameter(¶ms, argv[1]);
|
||||||
if (argc == 3)
|
if (argc == 3) {
|
||||||
{
|
|
||||||
variant = atoi(argv[2]);
|
variant = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
printParameter(¶ms);
|
printParameter(¶ms);
|
||||||
@ -103,14 +100,19 @@ int main(int argc, char** argv)
|
|||||||
double te = s.te;
|
double te = s.te;
|
||||||
double t = 0.0;
|
double t = 0.0;
|
||||||
|
|
||||||
|
printGrid(&s, s.seg);
|
||||||
|
exit(0);
|
||||||
|
|
||||||
timeStart = getTimeStamp();
|
timeStart = getTimeStamp();
|
||||||
|
|
||||||
void (*solver_generic[])() = {solve, solveRB, solveRBA};
|
void (*solver_generic[])() = { solve, solveRB, solveRBA };
|
||||||
|
|
||||||
while (t <= te) {
|
while (t <= te) {
|
||||||
if (tau > 0.0) computeTimestep(&s);
|
if (tau > 0.0) computeTimestep(&s);
|
||||||
setBoundaryConditions(&s);
|
setBoundaryConditions(&s);
|
||||||
setSpecialBoundaryCondition(&s);
|
setSpecialBoundaryCondition(&s);
|
||||||
|
setObjectBoundaryCondition(&s);
|
||||||
|
|
||||||
computeFG(&s);
|
computeFG(&s);
|
||||||
computeRHS(&s);
|
computeRHS(&s);
|
||||||
solver_generic[variant - 1](&s);
|
solver_generic[variant - 1](&s);
|
||||||
@ -119,7 +121,7 @@ int main(int argc, char** argv)
|
|||||||
trace(&particletracer, s.u, s.v, s.w, t);
|
trace(&particletracer, s.u, s.v, s.w, t);
|
||||||
|
|
||||||
t += s.dt;
|
t += s.dt;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
if (rank == 0) {
|
if (rank == 0) {
|
||||||
printf("TIME %f , TIMESTEP %f\n", t, s.dt);
|
printf("TIME %f , TIMESTEP %f\n", t, s.dt);
|
||||||
|
@ -101,6 +101,15 @@ void readParameter(Parameter* param, const char* filename)
|
|||||||
PARSE_REAL(y2);
|
PARSE_REAL(y2);
|
||||||
PARSE_REAL(z2);
|
PARSE_REAL(z2);
|
||||||
|
|
||||||
|
/* Added obstacle geometry parameters */
|
||||||
|
PARSE_INT(shape);
|
||||||
|
PARSE_REAL(xCenter);
|
||||||
|
PARSE_REAL(yCenter);
|
||||||
|
PARSE_REAL(zCenter);
|
||||||
|
PARSE_REAL(xRectLength);
|
||||||
|
PARSE_REAL(yRectLength);
|
||||||
|
PARSE_REAL(zRectLength);
|
||||||
|
PARSE_REAL(circleRadius);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,12 @@ typedef struct {
|
|||||||
double startTime, injectTimePeriod, writeTimePeriod;
|
double startTime, injectTimePeriod, writeTimePeriod;
|
||||||
|
|
||||||
double x1, y1, z1, x2, y2, z2;
|
double x1, y1, z1, x2, y2, z2;
|
||||||
|
|
||||||
|
int shape;
|
||||||
|
double xCenter, yCenter, zCenter, xRectLength, yRectLength, zRectLength, circleRadius;
|
||||||
} Parameter;
|
} Parameter;
|
||||||
|
|
||||||
void initParameter(Parameter*);
|
extern void initParameter(Parameter*);
|
||||||
void readParameter(Parameter*, const char*);
|
extern void readParameter(Parameter*, const char*);
|
||||||
void printParameter(Parameter*);
|
extern void printParameter(Parameter*);
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,20 +8,20 @@
|
|||||||
#define __PARTICLETRACING_H_
|
#define __PARTICLETRACING_H_
|
||||||
#include "allocate.h"
|
#include "allocate.h"
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
#include "solver.h"
|
|
||||||
#include "particletracing.h"
|
#include "particletracing.h"
|
||||||
|
#include "solver.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef enum COORD { X = 0, Y, NCOORD } COORD;
|
typedef enum COORD { X = 0, Y, NCOORD } COORD;
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
bool flag;
|
bool flag;
|
||||||
} Particle;
|
} Particle;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int numberOfParticles, totalParticles;
|
int numberOfParticles, totalParticles;
|
||||||
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime, lastWriteTime;
|
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime,
|
||||||
|
lastWriteTime;
|
||||||
|
|
||||||
int estimatedNumParticles, activeParticles;
|
int estimatedNumParticles, activeParticles;
|
||||||
|
|
||||||
@ -30,19 +30,19 @@ typedef struct {
|
|||||||
Particle* particlePool;
|
Particle* particlePool;
|
||||||
|
|
||||||
int pointer;
|
int pointer;
|
||||||
|
|
||||||
double imax, jmax, kmax, xlength, ylength, zlength;
|
double imax, jmax, kmax, xlength, ylength, zlength;
|
||||||
|
|
||||||
double x1, y1, x2, y2, z1, z2;
|
double x1, y1, x2, y2, z1, z2;
|
||||||
} ParticleTracer;
|
} ParticleTracer;
|
||||||
|
|
||||||
void initParticleTracer(ParticleTracer*, Parameter*);
|
extern void initParticleTracer(ParticleTracer*, Parameter*);
|
||||||
void injectParticles(ParticleTracer*);
|
extern void injectParticles(ParticleTracer*);
|
||||||
void advanceParticles(ParticleTracer*, double* , double*, double*, double);
|
extern void advanceParticles(ParticleTracer*, double*, double*, double*, double);
|
||||||
void freeParticles(ParticleTracer*);
|
extern void freeParticles(ParticleTracer*);
|
||||||
void writeParticles(ParticleTracer*);
|
extern void writeParticles(ParticleTracer*);
|
||||||
void printParticleTracerParameters(ParticleTracer*);
|
extern void printParticleTracerParameters(ParticleTracer*);
|
||||||
void printParticles(ParticleTracer*);
|
extern void printParticles(ParticleTracer*);
|
||||||
void compress(ParticleTracer*);
|
extern void compress(ParticleTracer*);
|
||||||
void trace(ParticleTracer*, double* , double* , double* , double);
|
extern void trace(ParticleTracer*, double*, double*, double*, double);
|
||||||
#endif
|
#endif
|
@ -22,8 +22,122 @@
|
|||||||
#define U(i, j, k) u[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
#define U(i, j, k) u[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
#define V(i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
#define V(i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
#define W(i, j, k) w[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
#define W(i, j, k) w[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
|
#define S(i, j, k) seg[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
#define RHS(i, j, k) rhs[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
#define RHS(i, j, k) rhs[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||||
|
|
||||||
|
static double distance(
|
||||||
|
double i, double j, double k, double iCenter, double jCenter, double kCenter)
|
||||||
|
{
|
||||||
|
return sqrt(pow(iCenter - i, 2) + pow(jCenter - j, 2) + pow(kCenter - k, 2) * 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printGrid(Solver* solver, int* grid)
|
||||||
|
{
|
||||||
|
int imax = solver->grid.imax;
|
||||||
|
int jmax = solver->grid.jmax;
|
||||||
|
|
||||||
|
for (int k = 0; k < solver->grid.kmax + 2; k++) {
|
||||||
|
printf("K : %02d:\n", k);
|
||||||
|
for (int j = 0; j < solver->grid.jmax + 2; j++) {
|
||||||
|
printf("J : %02d: ", j);
|
||||||
|
for (int i = 0; i < solver->grid.imax + 2; i++) {
|
||||||
|
switch (grid[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]) {
|
||||||
|
case FRONTFACE:
|
||||||
|
printf("FF ");
|
||||||
|
break;
|
||||||
|
case BACKFACE:
|
||||||
|
printf("BF ");
|
||||||
|
break;
|
||||||
|
case LEFTFACE:
|
||||||
|
printf("LF ");
|
||||||
|
break;
|
||||||
|
case RIGHTFACE:
|
||||||
|
printf("RF ");
|
||||||
|
break;
|
||||||
|
case TOPFACE:
|
||||||
|
printf("TF ");
|
||||||
|
break;
|
||||||
|
case BOTTOMFACE:
|
||||||
|
printf("BMF ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FRONTTOPLEFTCORNER:
|
||||||
|
printf("FTLC ");
|
||||||
|
break;
|
||||||
|
case FRONTTOPRIGHTCORNER:
|
||||||
|
printf("FTRC ");
|
||||||
|
break;
|
||||||
|
case FRONTBOTTOMLEFTCORNER:
|
||||||
|
printf("FBLC ");
|
||||||
|
break;
|
||||||
|
case FRONTBOTTOMRIGHTCORNER:
|
||||||
|
printf("FBRC ");
|
||||||
|
break;
|
||||||
|
case BACKTOPLEFTCORNER:
|
||||||
|
printf("BTLC ");
|
||||||
|
break;
|
||||||
|
case BACKTOPRIGHTCORNER:
|
||||||
|
printf("BTRC ");
|
||||||
|
break;
|
||||||
|
case BACKBOTTOMLEFTCORNER:
|
||||||
|
printf("BBLC ");
|
||||||
|
break;
|
||||||
|
case BACKBOTTOMRIGHTCORNER:
|
||||||
|
printf("BBRC ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FRONTTOPLINE:
|
||||||
|
printf("FTL ");
|
||||||
|
break;
|
||||||
|
case FRONTBOTTOMLINE:
|
||||||
|
printf("FBL ");
|
||||||
|
break;
|
||||||
|
case FRONTLEFTLINE:
|
||||||
|
printf("FLL ");
|
||||||
|
break;
|
||||||
|
case FRONTRIGHTLINE:
|
||||||
|
printf("FRL ");
|
||||||
|
break;
|
||||||
|
case MIDTOPLEFTLINE:
|
||||||
|
printf("MTLL ");
|
||||||
|
break;
|
||||||
|
case MIDTOPRIGHTLINE:
|
||||||
|
printf("MTRL ");
|
||||||
|
break;
|
||||||
|
case MIDBOTTOMLEFTLINE:
|
||||||
|
printf("MBTL ");
|
||||||
|
break;
|
||||||
|
case MIDBOTTOMRIGHTLINE:
|
||||||
|
printf("MBRL ");
|
||||||
|
break;
|
||||||
|
case BACKTOPLINE:
|
||||||
|
printf("BTL ");
|
||||||
|
break;
|
||||||
|
case BACKBOTTOMLINE:
|
||||||
|
printf("BBL ");
|
||||||
|
break;
|
||||||
|
case BACKLEFTLINE:
|
||||||
|
printf("BLL ");
|
||||||
|
break;
|
||||||
|
case BACKRIGHTLINE:
|
||||||
|
printf("BRL ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOCAL:
|
||||||
|
printf("L ");
|
||||||
|
break;
|
||||||
|
case NONE:
|
||||||
|
printf("N ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
static void printConfig(Solver* s)
|
static void printConfig(Solver* s)
|
||||||
{
|
{
|
||||||
printf("Parameters for #%s#\n", s->problem);
|
printf("Parameters for #%s#\n", s->problem);
|
||||||
@ -85,7 +199,6 @@ void initSolver(Solver* s, Parameter* params)
|
|||||||
s->gamma = params->gamma;
|
s->gamma = params->gamma;
|
||||||
s->rho = params->rho;
|
s->rho = params->rho;
|
||||||
|
|
||||||
|
|
||||||
int imax = s->grid.imax;
|
int imax = s->grid.imax;
|
||||||
int jmax = s->grid.jmax;
|
int jmax = s->grid.jmax;
|
||||||
int kmax = s->grid.kmax;
|
int kmax = s->grid.kmax;
|
||||||
@ -98,6 +211,7 @@ void initSolver(Solver* s, Parameter* params)
|
|||||||
s->f = allocate(64, bytesize);
|
s->f = allocate(64, bytesize);
|
||||||
s->g = allocate(64, bytesize);
|
s->g = allocate(64, bytesize);
|
||||||
s->h = allocate(64, bytesize);
|
s->h = allocate(64, bytesize);
|
||||||
|
s->seg = allocate(64, bytesize);
|
||||||
|
|
||||||
for (int i = 0; i < (imax + 2) * (jmax + 2) * (kmax + 2); i++) {
|
for (int i = 0; i < (imax + 2) * (jmax + 2) * (kmax + 2); i++) {
|
||||||
s->u[i] = params->u_init;
|
s->u[i] = params->u_init;
|
||||||
@ -108,6 +222,7 @@ void initSolver(Solver* s, Parameter* params)
|
|||||||
s->f[i] = 0.0;
|
s->f[i] = 0.0;
|
||||||
s->g[i] = 0.0;
|
s->g[i] = 0.0;
|
||||||
s->h[i] = 0.0;
|
s->h[i] = 0.0;
|
||||||
|
s->seg[i] = NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
double dx = s->grid.dx;
|
double dx = s->grid.dx;
|
||||||
@ -117,6 +232,194 @@ void initSolver(Solver* s, Parameter* params)
|
|||||||
double invSqrSum = 1.0 / (dx * dx) + 1.0 / (dy * dy) + 1.0 / (dz * dz);
|
double invSqrSum = 1.0 / (dx * dx) + 1.0 / (dy * dy) + 1.0 / (dz * dz);
|
||||||
s->dtBound = 0.5 * s->re * 1.0 / invSqrSum;
|
s->dtBound = 0.5 * s->re * 1.0 / invSqrSum;
|
||||||
|
|
||||||
|
double xCenter = 0, yCenter = 0, zCenter = 0, radius = 0;
|
||||||
|
double x1 = 0, x2 = 0, y1 = 0, y2 = 0, z1 = 0, z2 = 0;
|
||||||
|
|
||||||
|
int* seg = s->seg;
|
||||||
|
|
||||||
|
switch (params->shape) {
|
||||||
|
case NOSHAPE:
|
||||||
|
break;
|
||||||
|
case RECT:
|
||||||
|
x1 = params->xCenter - params->xRectLength / 2;
|
||||||
|
x2 = params->xCenter + params->xRectLength / 2;
|
||||||
|
y1 = params->yCenter - params->yRectLength / 2;
|
||||||
|
y2 = params->yCenter + params->yRectLength / 2;
|
||||||
|
z1 = params->zCenter - params->zRectLength / 2;
|
||||||
|
z2 = params->zCenter + params->zRectLength / 2;
|
||||||
|
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
|
if ((x1 <= (i * dx)) && ((i * dx) <= x2) && (y1 <= (j * dy)) &&
|
||||||
|
((j * dy) <= y2) && ((z1 <= (k * dz)) && ((k * dz) <= z2))) {
|
||||||
|
S(i, j, k) = LOCAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case CIRCLE:
|
||||||
|
xCenter = params->xCenter;
|
||||||
|
yCenter = params->yCenter;
|
||||||
|
zCenter = params->zCenter;
|
||||||
|
radius = params->circleRadius;
|
||||||
|
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
|
if (distance((i * dx),
|
||||||
|
(j * dy),
|
||||||
|
(k * dz),
|
||||||
|
xCenter,
|
||||||
|
yCenter,
|
||||||
|
zCenter) <= radius) {
|
||||||
|
S(i, j, k) = LOCAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
|
|
||||||
|
/* Assigning enum values to Corners */
|
||||||
|
if (S(i - 1, j + 1, k - 1) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j + 1, k) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i + 1, j - 1, k + 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTTOPLEFTCORNER; //
|
||||||
|
}
|
||||||
|
if (S(i + 1, j + 1, k - 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j + 1, k) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i - 1, j - 1, k + 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTTOPRIGHTCORNER; //
|
||||||
|
}
|
||||||
|
if (S(i - 1, j - 1, k - 1) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i + 1, j + 1, k + 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTBOTTOMLEFTCORNER; //
|
||||||
|
}
|
||||||
|
if (S(i + 1, j - 1, k - 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i - 1, j + 1, k + 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTBOTTOMRIGHTCORNER; //
|
||||||
|
}
|
||||||
|
if (S(i - 1, j + 1, k + 1) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j + 1, k) == NONE && S(i, j, k + 1) == NONE &&
|
||||||
|
S(i + 1, j - 1, k - 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKTOPLEFTCORNER; //
|
||||||
|
}
|
||||||
|
if (S(i + 1, j + 1, k + 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j + 1, k) == NONE && S(i, j, k + 1) == NONE &&
|
||||||
|
S(i - 1, j - 1, k - 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKTOPRIGHTCORNER;
|
||||||
|
}
|
||||||
|
if (S(i - 1, j - 1, k + 1) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i, j, k + 1) == NONE &&
|
||||||
|
S(i + 1, j + 1, k - 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKBOTTOMLEFTCORNER;
|
||||||
|
}
|
||||||
|
if (S(i + 1, j - 1, k + 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i, j, k + 1) == NONE &&
|
||||||
|
S(i - 1, j + 1, k - 1) == LOCAL && S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKBOTTOMRIGHTCORNER;
|
||||||
|
}
|
||||||
|
/* Assigning enum values to Lines */
|
||||||
|
if (S(i - 1, j, k - 1) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i - 1, j, k) == NONE && S(i + 1, j, k + 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTLEFTLINE;
|
||||||
|
}
|
||||||
|
if (S(i + 1, j, k - 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j, k - 1) == NONE && S(i - 1, j, k + 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTRIGHTLINE;
|
||||||
|
}
|
||||||
|
if (S(i, j + 1, k - 1) == NONE && S(i, j + 1, k) == NONE &&
|
||||||
|
S(i, j, k - 1) == NONE && S(i, j - 1, k + 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTTOPLINE;
|
||||||
|
}
|
||||||
|
if (S(i, j - 1, k - 1) == NONE && S(i, j, k - 1) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i, j + 1, k + 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTBOTTOMLINE;
|
||||||
|
}
|
||||||
|
if (S(i - 1, j + 1, k) == NONE && S(i, j + 1, k) == NONE &&
|
||||||
|
S(i - 1, j, k) == NONE && S(i + 1, j - 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = MIDTOPLEFTLINE;
|
||||||
|
}
|
||||||
|
if (S(i + 1, j + 1, k) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j + 1, k) == NONE && S(i - 1, j - 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = MIDTOPRIGHTLINE;
|
||||||
|
}
|
||||||
|
if (S(i - 1, j - 1, k) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i + 1, j + 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = MIDBOTTOMLEFTLINE;
|
||||||
|
}
|
||||||
|
if (S(i + 1, j - 1, k) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j - 1, k) == NONE && S(i - 1, j + 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = MIDBOTTOMRIGHTLINE;
|
||||||
|
}
|
||||||
|
if (S(i - 1, j, k + 1) == NONE && S(i - 1, j, k) == NONE &&
|
||||||
|
S(i, j, k + 1) == NONE && S(i + 1, j, k - 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKLEFTLINE;
|
||||||
|
}
|
||||||
|
if (S(i + 1, j, k + 1) == NONE && S(i + 1, j, k) == NONE &&
|
||||||
|
S(i, j, k + 1) == NONE && S(i - 1, j, k - 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKRIGHTLINE;
|
||||||
|
}
|
||||||
|
if (S(i, j + 1, k + 1) == NONE && S(i, j + 1, k) == NONE &&
|
||||||
|
S(i, j, k + 1) == NONE && S(i, j - 1, k - 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKTOPLINE;
|
||||||
|
}
|
||||||
|
if (S(i, j - 1, k + 1) == NONE && S(i, j - 1, k) == NONE &&
|
||||||
|
S(i, j, k + 1) == NONE && S(i, j + 1, k - 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKBOTTOMLINE;
|
||||||
|
}
|
||||||
|
/* Assigning enum values to Faces */
|
||||||
|
if (S(i, j, k - 1) == NONE && S(i, j, k + 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = FRONTFACE; //
|
||||||
|
}
|
||||||
|
if (S(i, j, k + 1) == NONE && S(i, j, k - 1) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BACKFACE; //
|
||||||
|
}
|
||||||
|
if (S(i, j - 1, k) == NONE && S(i, j + 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = BOTTOMFACE; //
|
||||||
|
}
|
||||||
|
if (S(i, j + 1, k) == NONE && S(i, j - 1, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = TOPFACE; //
|
||||||
|
}
|
||||||
|
if (S(i - 1, j, k) == NONE && S(i + 1, j, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = LEFTFACE; //
|
||||||
|
}
|
||||||
|
if (S(i + 1, j, k) == NONE && S(i - 1, j, k) == LOCAL &&
|
||||||
|
S(i, j, k) == LOCAL) {
|
||||||
|
S(i, j, k) = RIGHTFACE; //
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printConfig(s);
|
printConfig(s);
|
||||||
#endif /* VERBOSE */
|
#endif /* VERBOSE */
|
||||||
@ -321,15 +624,14 @@ void solveRBA(Solver* s)
|
|||||||
double idx2 = 1.0 / dx2;
|
double idx2 = 1.0 / dx2;
|
||||||
double idy2 = 1.0 / dy2;
|
double idy2 = 1.0 / dy2;
|
||||||
double idz2 = 1.0 / dz2;
|
double idz2 = 1.0 / dz2;
|
||||||
double factor = 0.5 * (dx2 * dy2 * dz2) /
|
double factor = 0.5 * (dx2 * dy2 * dz2) / (dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
|
||||||
(dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
|
double* p = s->p;
|
||||||
double* p = s->p;
|
double* rhs = s->rhs;
|
||||||
double* rhs = s->rhs;
|
double epssq = eps * eps;
|
||||||
double epssq = eps * eps;
|
|
||||||
double rho = s->rho;
|
double rho = s->rho;
|
||||||
double omega = 1.0;
|
double omega = 1.0;
|
||||||
int it = 0;
|
int it = 0;
|
||||||
double res = 1.0;
|
double res = 1.0;
|
||||||
int pass, ksw, jsw, isw;
|
int pass, ksw, jsw, isw;
|
||||||
|
|
||||||
while ((res >= epssq) && (it < itermax)) {
|
while ((res >= epssq) && (it < itermax)) {
|
||||||
@ -359,7 +661,7 @@ void solveRBA(Solver* s)
|
|||||||
}
|
}
|
||||||
jsw = 3 - jsw;
|
jsw = 3 - jsw;
|
||||||
}
|
}
|
||||||
ksw = 3 - ksw;
|
ksw = 3 - ksw;
|
||||||
omega = (it == 0 && pass == 0 ? 1.0 / (1.0 - 0.5 * rho * rho)
|
omega = (it == 0 && pass == 0 ? 1.0 / (1.0 - 0.5 * rho * rho)
|
||||||
: 1.0 / (1.0 - 0.25 * rho * rho * omega));
|
: 1.0 / (1.0 - 0.25 * rho * rho * omega));
|
||||||
}
|
}
|
||||||
@ -676,6 +978,19 @@ void setSpecialBoundaryCondition(Solver* s)
|
|||||||
U(0, j, k) = y * (ylength - y) * 4.0 / (ylength * ylength);
|
U(0, j, k) = y * (ylength - y) * 4.0 / (ylength * ylength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(s->problem, "karman") == 0) {
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
U(0, j, k) = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (strcmp(s->problem, "backstep") == 0) {
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
|
||||||
|
U(0, j, k) = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,3 +1211,170 @@ void adaptUV(Solver* s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setObjectBoundaryCondition(Solver* s)
|
||||||
|
{
|
||||||
|
int imax = s->grid.imax;
|
||||||
|
int jmax = s->jmax;
|
||||||
|
int kmax = s->kmax;
|
||||||
|
double* u = s->u;
|
||||||
|
double* v = s->v;
|
||||||
|
double* w = s->w;
|
||||||
|
int* seg = s->seg;
|
||||||
|
for (int k = 1; k < kmax + 1; k++) {
|
||||||
|
for (int j = 1; j < jmax + 1; j++) {
|
||||||
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
|
switch (S(i, j, k)) {
|
||||||
|
case TOPFACE:
|
||||||
|
U(i, j, k) = -U(i, j + 1, k);
|
||||||
|
U(i - 1, j, k) = -U(i - 1, j + 1, k);
|
||||||
|
V(i, j, k) = 0.0;
|
||||||
|
W(i, j, k) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOMFACE:
|
||||||
|
U(i, j, k) = -U(i, j - 1, k);
|
||||||
|
U(i - 1, j, k) = -U(i - 1, j - 1, k);
|
||||||
|
V(i, j, k) = 0.0;
|
||||||
|
W(i, j, k) = 0.0;
|
||||||
|
break;
|
||||||
|
case LEFTFACE:
|
||||||
|
U(i - 1, j, k) = 0.0;
|
||||||
|
V(i, j, k) = -V(i - 1, j, k);
|
||||||
|
V(i, j - 1, k) = -V(i - 1, j - 1, k);
|
||||||
|
W(i, j, k) = 0.0;
|
||||||
|
break;
|
||||||
|
case RIGHTFACE:
|
||||||
|
U(i, j, k) = 0.0;
|
||||||
|
V(i, j, k) = -V(i + 1, j, k);
|
||||||
|
V(i, j - 1, k) = -V(i + 1, j - 1, k);
|
||||||
|
W(i, j, k) = 0.0;
|
||||||
|
break;
|
||||||
|
case FRONTFACE:
|
||||||
|
U(i - 1, j, k) = 0.0;
|
||||||
|
V(i, j, k) = 0.0;
|
||||||
|
V(i, j, k) = -V(i - 1, j, k);
|
||||||
|
V(i, j - 1, k) = -V(i - 1, j - 1, k);
|
||||||
|
break;
|
||||||
|
case BACKFACE:
|
||||||
|
U(i, j, k) = 0.0;
|
||||||
|
V(i, j, k) = 0.0;
|
||||||
|
V(i, j, k) = -V(i + 1, j, k);
|
||||||
|
V(i, j - 1, k) = -V(i + 1, j - 1, k);
|
||||||
|
break;
|
||||||
|
case TOPLEFT:
|
||||||
|
U(i, j) = -U(i, j + 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i - 1, j - 1);
|
||||||
|
break;
|
||||||
|
case TOPRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j + 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i + 1, j - 1);
|
||||||
|
break;
|
||||||
|
case BOTTOMLEFT:
|
||||||
|
U(i, j) = -U(i, j - 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = -V(i - 1, j);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOMRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j - 1);
|
||||||
|
V(i, j) = -V(i, j + 1);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
case TOP:
|
||||||
|
U(i, j) = -U(i, j + 1);
|
||||||
|
U(i - 1, j) = -U(i - 1, j + 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOM:
|
||||||
|
U(i, j) = -U(i, j - 1);
|
||||||
|
U(i - 1, j) = -U(i - 1, j - 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
break;
|
||||||
|
case LEFT:
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = -V(i - 1, j);
|
||||||
|
V(i, j - 1) = -V(i - 1, j - 1);
|
||||||
|
break;
|
||||||
|
case RIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
V(i, j) = -V(i + 1, j);
|
||||||
|
V(i, j - 1) = -V(i + 1, j - 1);
|
||||||
|
break;
|
||||||
|
case TOPLEFT:
|
||||||
|
U(i, j) = -U(i, j + 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i - 1, j - 1);
|
||||||
|
break;
|
||||||
|
case TOPRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j + 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i + 1, j - 1);
|
||||||
|
break;
|
||||||
|
case BOTTOMLEFT:
|
||||||
|
U(i, j) = -U(i, j - 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = -V(i - 1, j);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOMRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j - 1);
|
||||||
|
V(i, j) = -V(i, j + 1);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
case TOP:
|
||||||
|
U(i, j) = -U(i, j + 1);
|
||||||
|
U(i - 1, j) = -U(i - 1, j + 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOM:
|
||||||
|
U(i, j) = -U(i, j - 1);
|
||||||
|
U(i - 1, j) = -U(i - 1, j - 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
break;
|
||||||
|
case LEFT:
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = -V(i - 1, j);
|
||||||
|
V(i, j - 1) = -V(i - 1, j - 1);
|
||||||
|
break;
|
||||||
|
case RIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
V(i, j) = -V(i + 1, j);
|
||||||
|
V(i, j - 1) = -V(i + 1, j - 1);
|
||||||
|
break;
|
||||||
|
case TOPLEFT:
|
||||||
|
U(i, j) = -U(i, j + 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i - 1, j - 1);
|
||||||
|
break;
|
||||||
|
case TOPRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j + 1);
|
||||||
|
V(i, j) = 0.0;
|
||||||
|
V(i, j - 1) = -V(i + 1, j - 1);
|
||||||
|
break;
|
||||||
|
case BOTTOMLEFT:
|
||||||
|
U(i, j) = -U(i, j - 1);
|
||||||
|
U(i - 1, j) = 0.0;
|
||||||
|
V(i, j) = -V(i - 1, j);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
case BOTTOMRIGHT:
|
||||||
|
U(i, j) = 0.0;
|
||||||
|
U(i - 1, j) = -U(i - 1, j - 1);
|
||||||
|
V(i, j) = -V(i, j + 1);
|
||||||
|
V(i, j - 1) = 0.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,46 @@
|
|||||||
#include "grid.h"
|
#include "grid.h"
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
|
|
||||||
|
enum OBJECTBOUNDARY {
|
||||||
|
NONE = 0,
|
||||||
|
/* Front Corners */
|
||||||
|
FRONTTOPLEFTCORNER,
|
||||||
|
FRONTTOPRIGHTCORNER,
|
||||||
|
FRONTBOTTOMLEFTCORNER,
|
||||||
|
FRONTBOTTOMRIGHTCORNER,
|
||||||
|
/* Back Corners */
|
||||||
|
BACKTOPLEFTCORNER,
|
||||||
|
BACKTOPRIGHTCORNER,
|
||||||
|
BACKBOTTOMLEFTCORNER,
|
||||||
|
BACKBOTTOMRIGHTCORNER,
|
||||||
|
/* Faces */
|
||||||
|
FRONTFACE,
|
||||||
|
BACKFACE,
|
||||||
|
LEFTFACE,
|
||||||
|
RIGHTFACE,
|
||||||
|
TOPFACE,
|
||||||
|
BOTTOMFACE,
|
||||||
|
/* Front Lines remaining after Corners and Faces */
|
||||||
|
FRONTLEFTLINE,
|
||||||
|
FRONTRIGHTLINE,
|
||||||
|
FRONTTOPLINE,
|
||||||
|
FRONTBOTTOMLINE,
|
||||||
|
/* Bottom Lines remaining after Corners and Faces */
|
||||||
|
BACKLEFTLINE,
|
||||||
|
BACKRIGHTLINE,
|
||||||
|
BACKTOPLINE,
|
||||||
|
BACKBOTTOMLINE,
|
||||||
|
/* Mid Lines remaining after Corners and Faces */
|
||||||
|
MIDTOPLEFTLINE,
|
||||||
|
MIDTOPRIGHTLINE,
|
||||||
|
MIDBOTTOMLEFTLINE,
|
||||||
|
MIDBOTTOMRIGHTLINE,
|
||||||
|
/* Local where its an object but not a boundary */
|
||||||
|
LOCAL
|
||||||
|
};
|
||||||
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
||||||
|
/// @brief
|
||||||
|
enum SHAPE { NOSHAPE = 0, RECT, CIRCLE };
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* geometry and grid information */
|
/* geometry and grid information */
|
||||||
@ -19,6 +58,7 @@ typedef struct {
|
|||||||
double *p, *rhs;
|
double *p, *rhs;
|
||||||
double *f, *g, *h;
|
double *f, *g, *h;
|
||||||
double *u, *v, *w;
|
double *u, *v, *w;
|
||||||
|
int* seg;
|
||||||
/* parameters */
|
/* parameters */
|
||||||
double eps, omega, rho;
|
double eps, omega, rho;
|
||||||
double re, tau, gamma;
|
double re, tau, gamma;
|
||||||
@ -39,8 +79,11 @@ extern void solveRBA(Solver*);
|
|||||||
extern void normalizePressure(Solver*);
|
extern void normalizePressure(Solver*);
|
||||||
extern void computeTimestep(Solver*);
|
extern void computeTimestep(Solver*);
|
||||||
extern void setBoundaryConditions(Solver*);
|
extern void setBoundaryConditions(Solver*);
|
||||||
|
extern void setObjectBoundaryCondition(Solver*);
|
||||||
extern void setSpecialBoundaryCondition(Solver*);
|
extern void setSpecialBoundaryCondition(Solver*);
|
||||||
extern void computeFG(Solver*);
|
extern void computeFG(Solver*);
|
||||||
extern void adaptUV(Solver*);
|
extern void adaptUV(Solver*);
|
||||||
extern void writeResult(Solver*);
|
extern void writeResult(Solver*);
|
||||||
|
extern void printGrid(Solver*, int*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,8 +8,8 @@ name poisson
|
|||||||
|
|
||||||
xlength 1.0 # domain size in x-direction
|
xlength 1.0 # domain size in x-direction
|
||||||
ylength 1.0 # domain size in y-direction
|
ylength 1.0 # domain size in y-direction
|
||||||
imax 200 # number of interior cells in x-direction
|
imax 1000 # number of interior cells in x-direction
|
||||||
jmax 200 # number of interior cells in y-direction
|
jmax 10000 # number of interior cells in y-direction
|
||||||
|
|
||||||
# Pressure Iteration Data:
|
# Pressure Iteration Data:
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
73
PoissonSolver/2D-mpi/result.csv
Normal file
73
PoissonSolver/2D-mpi/result.csv
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
Rank, SOR, RB
|
||||||
|
1, 1138.31, 447.94
|
||||||
|
2, 569.26, 225.46
|
||||||
|
3, 379.59, 150.36
|
||||||
|
4, 284.87, 112.45
|
||||||
|
5, 227.82, 89.36
|
||||||
|
6, 190.25, 75.91
|
||||||
|
7, 163.19, 64.62
|
||||||
|
8, 142.55, 56.34
|
||||||
|
9, 126.80, 49.90
|
||||||
|
10, 114.09, 45.32
|
||||||
|
11, 103.80, 40.71
|
||||||
|
12, 95.28, 37.55
|
||||||
|
13, 87.99, 35.60
|
||||||
|
14, 81.72, 33.19
|
||||||
|
15, 76.30, 30.71
|
||||||
|
16, 71.51, 29.01
|
||||||
|
17, 67.35, 26.94
|
||||||
|
18, 63.69, 25.98
|
||||||
|
19, 60.47, 24.49
|
||||||
|
20, 57.49, 23.21
|
||||||
|
21, 54.81, 22.22
|
||||||
|
22, 52.26, 21.01
|
||||||
|
23, 50.01, 20.81
|
||||||
|
24, 47.93, 19.83
|
||||||
|
25, 46.04, 18.94
|
||||||
|
26, 44.30, 18.01
|
||||||
|
27, 42.68, 17.71
|
||||||
|
28, 41.16, 16.93
|
||||||
|
29, 39.72, 16.33
|
||||||
|
30, 38.51, 16.10
|
||||||
|
31, 37.31, 15.27
|
||||||
|
32, 36.15, 14.86
|
||||||
|
33, 35.11, 14.31
|
||||||
|
34, 34.08, 13.76
|
||||||
|
35, 33.13, 13.50
|
||||||
|
36, 32.22, 13.41
|
||||||
|
37, 31.37, 12.86
|
||||||
|
38, 30.55, 12.65
|
||||||
|
39, 29.83, 12.04
|
||||||
|
40, 29.02, 11.88
|
||||||
|
41, 28.34, 11.45
|
||||||
|
42, 27.75, 11.33
|
||||||
|
43, 27.13, 10.96
|
||||||
|
44, 26.52, 10.69
|
||||||
|
45, 26.02, 10.43
|
||||||
|
46, 25.37, 10.24
|
||||||
|
47, 24.86, 10.07
|
||||||
|
48, 24.42, 9.76
|
||||||
|
49, 23.93, 9.85
|
||||||
|
50, 23.38, 9.44
|
||||||
|
51, 23.11, 9.33
|
||||||
|
52, 22.58, 9.01
|
||||||
|
53, 22.18, 8.95
|
||||||
|
54, 21.82, 8.78
|
||||||
|
55, 21.39, 8.56
|
||||||
|
56, 21.04, 8.45
|
||||||
|
57, 20.71, 8.30
|
||||||
|
58, 20.38, 8.10
|
||||||
|
59, 20.03, 7.99
|
||||||
|
60, 19.78, 7.77
|
||||||
|
61, 19.44, 7.64
|
||||||
|
62, 19.15, 7.55
|
||||||
|
63, 18.83, 7.46
|
||||||
|
64, 18.66, 7.29
|
||||||
|
65, 18.25, 7.19
|
||||||
|
66, 18.07, 7.09
|
||||||
|
67, 17.83, 7.02
|
||||||
|
68, 17.60, 6.90
|
||||||
|
69, 17.48, 6.84
|
||||||
|
70, 17.22, 6.78
|
||||||
|
71, 19.10, 6.74
|
||||||
|
72, 17.46, 6.83
|
|
39
PoissonSolver/2D-mpi/sample.sh
Executable file
39
PoissonSolver/2D-mpi/sample.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash -l
|
||||||
|
#SBATCH --job-name=Sim
|
||||||
|
#SBATCH --output=Sim_Fritz.o%j
|
||||||
|
#SBATCH --partition=singlenode
|
||||||
|
#SBATCH --nodes=1
|
||||||
|
#SBATCH --ntasks-per-node=21
|
||||||
|
#SBATCH --ntasks=21
|
||||||
|
#SBATCH --time=20:00:00
|
||||||
|
#SBATCH --constraint=hwperf
|
||||||
|
#SBATCH --export=NONE
|
||||||
|
#SBATCH --cpu-freq=2400000-2400000:performance
|
||||||
|
|
||||||
|
unset SLURM_EXPORT_ENV
|
||||||
|
|
||||||
|
echo "Starting: $(date)"
|
||||||
|
|
||||||
|
export
|
||||||
|
|
||||||
|
module load python intel/2022.1.0 intelmpi/2021.7.0 itac #likwid/5.2.2
|
||||||
|
module list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cd $SLURM_SUBMIT_DIR
|
||||||
|
|
||||||
|
rm result.csv
|
||||||
|
touch result.csv
|
||||||
|
echo "Rank, SOR, RB" >> result.csv
|
||||||
|
|
||||||
|
for i in $(seq 1 1 72)
|
||||||
|
do
|
||||||
|
time="$i, "
|
||||||
|
|
||||||
|
time+="$(srun --cpu-freq=2200000-2200000:performance -n $i ./exe-ICC poisson.par 1 | grep 'Solution took' | cut -c 15-)"
|
||||||
|
time+=", "
|
||||||
|
time+="$(srun --cpu-freq=2200000-2200000:performance -n $i ./exe-ICC poisson.par 2 | grep 'Solution took' | cut -c 15-)"
|
||||||
|
time=${time//s}
|
||||||
|
echo $time >> result.csv
|
||||||
|
done
|
@ -4,19 +4,20 @@
|
|||||||
* Use of this source code is governed by a MIT-style
|
* Use of this source code is governed by a MIT-style
|
||||||
* license that can be found in the LICENSE file.
|
* license that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
#include "solver.h"
|
#include "solver.h"
|
||||||
|
#include "timing.h"
|
||||||
|
|
||||||
enum VARIANT { SOR = 1, RB, RBA };
|
enum VARIANT { SOR = 1, RB, RBA };
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int rank;
|
int rank;
|
||||||
int variant = RB;
|
int variant = RB;
|
||||||
@ -24,28 +25,30 @@ int main (int argc, char** argv)
|
|||||||
Parameter params;
|
Parameter params;
|
||||||
Solver solver;
|
Solver solver;
|
||||||
|
|
||||||
|
double S, E;
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||||
initParameter(¶ms);
|
initParameter(¶ms);
|
||||||
|
|
||||||
if ( argc < 2 ) {
|
if (argc < 2) {
|
||||||
printf("Usage: %s <configFile>\n",argv[0]);
|
printf("Usage: %s <configFile>\n", argv[0]);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
readParameter(¶ms, argv[1]);
|
readParameter(¶ms, argv[1]);
|
||||||
if (argc == 3)
|
if (argc == 3) {
|
||||||
{
|
|
||||||
variant = atoi(argv[2]);
|
variant = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rank == 0) {
|
||||||
if ( rank == 0 ) {
|
|
||||||
printParameter(¶ms);
|
printParameter(¶ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
initSolver(&solver, ¶ms, 2);
|
initSolver(&solver, ¶ms, 2);
|
||||||
|
|
||||||
|
S = getTimeStamp();
|
||||||
|
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case SOR:
|
case SOR:
|
||||||
printf("Plain SOR\n");
|
printf("Plain SOR\n");
|
||||||
@ -60,7 +63,13 @@ int main (int argc, char** argv)
|
|||||||
solveRBA(&solver);
|
solveRBA(&solver);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//getResult(&solver);
|
// getResult(&solver);
|
||||||
|
|
||||||
|
E = getTimeStamp();
|
||||||
|
|
||||||
|
if (rank == 0) {
|
||||||
|
printf("Solution took %.2fs\n", E - S);
|
||||||
|
}
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -4,49 +4,53 @@
|
|||||||
* Use of this source code is governed by a MIT style
|
* Use of this source code is governed by a MIT style
|
||||||
* license that can be found in the LICENSE file.
|
* license that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "solver.h"
|
|
||||||
#include "parameter.h"
|
|
||||||
#include "allocate.h"
|
#include "allocate.h"
|
||||||
|
#include "parameter.h"
|
||||||
|
#include "solver.h"
|
||||||
|
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
#define P(i,j) p[(j)*(imax+2) + (i)]
|
#define P(i, j) p[(j) * (imax + 2) + (i)]
|
||||||
#define RHS(i,j) rhs[(j)*(imax+2) + (i)]
|
#define RHS(i, j) rhs[(j) * (imax + 2) + (i)]
|
||||||
|
|
||||||
static int sizeOfRank(int rank, int size, int N)
|
static int sizeOfRank(int rank, int size, int N)
|
||||||
{
|
{
|
||||||
return N/size + ((N%size>rank) ? 1 : 0);
|
return N / size + ((N % size > rank) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print(Solver* solver)
|
static void print(Solver* solver)
|
||||||
{
|
{
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
|
|
||||||
printf("### RANK %d #######################################################\n", solver->rank);
|
printf("### RANK %d #######################################################\n",
|
||||||
for( int j=0; j < solver->jmaxLocal+2; j++ ) {
|
solver->rank);
|
||||||
|
for (int j = 0; j < solver->jmaxLocal + 2; j++) {
|
||||||
printf("%02d: ", j);
|
printf("%02d: ", j);
|
||||||
for( int i=0; i < solver->imax+2; i++ ) {
|
for (int i = 0; i < solver->imax + 2; i++) {
|
||||||
printf("%12.8f ", P(i, j));
|
printf("%12.8f ", P(i, j));
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
fflush( stdout );
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exchange(Solver* solver)
|
static void exchange(Solver* solver)
|
||||||
{
|
{
|
||||||
MPI_Request requests[4] = { MPI_REQUEST_NULL, MPI_REQUEST_NULL, MPI_REQUEST_NULL, MPI_REQUEST_NULL };
|
MPI_Request requests[4] = { MPI_REQUEST_NULL,
|
||||||
|
MPI_REQUEST_NULL,
|
||||||
|
MPI_REQUEST_NULL,
|
||||||
|
MPI_REQUEST_NULL };
|
||||||
|
|
||||||
/* exchange ghost cells with top neighbor */
|
/* exchange ghost cells with top neighbor */
|
||||||
if (solver->rank + 1 < solver->size) {
|
if (solver->rank + 1 < solver->size) {
|
||||||
int top = solver->rank + 1;
|
int top = solver->rank + 1;
|
||||||
double* src = solver->p + (solver->jmaxLocal) * (solver->imax+2) + 1;
|
double* src = solver->p + (solver->jmaxLocal) * (solver->imax + 2) + 1;
|
||||||
double* dst = solver->p + (solver->jmaxLocal+1) * (solver->imax+2) + 1;
|
double* dst = solver->p + (solver->jmaxLocal + 1) * (solver->imax + 2) + 1;
|
||||||
|
|
||||||
MPI_Isend(src, solver->imax, MPI_DOUBLE, top, 1, MPI_COMM_WORLD, &requests[0]);
|
MPI_Isend(src, solver->imax, MPI_DOUBLE, top, 1, MPI_COMM_WORLD, &requests[0]);
|
||||||
MPI_Irecv(dst, solver->imax, MPI_DOUBLE, top, 2, MPI_COMM_WORLD, &requests[1]);
|
MPI_Irecv(dst, solver->imax, MPI_DOUBLE, top, 2, MPI_COMM_WORLD, &requests[1]);
|
||||||
@ -54,203 +58,213 @@ static void exchange(Solver* solver)
|
|||||||
|
|
||||||
/* exchange ghost cells with bottom neighbor */
|
/* exchange ghost cells with bottom neighbor */
|
||||||
if (solver->rank > 0) {
|
if (solver->rank > 0) {
|
||||||
int bottom = solver->rank - 1;
|
int bottom = solver->rank - 1;
|
||||||
double* src = solver->p + (solver->imax+2) + 1;
|
double* src = solver->p + (solver->imax + 2) + 1;
|
||||||
double* dst = solver->p + 1;
|
double* dst = solver->p + 1;
|
||||||
|
|
||||||
MPI_Isend(src, solver->imax, MPI_DOUBLE, bottom, 2, MPI_COMM_WORLD, &requests[2]);
|
MPI_Isend(src, solver->imax, MPI_DOUBLE, bottom, 2, MPI_COMM_WORLD, &requests[2]);
|
||||||
MPI_Irecv(dst, solver->imax, MPI_DOUBLE, bottom, 1, MPI_COMM_WORLD, &requests[3]);
|
MPI_Irecv(dst, solver->imax, MPI_DOUBLE, bottom, 1, MPI_COMM_WORLD, &requests[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Waitall(4, requests, MPI_STATUSES_IGNORE);
|
MPI_Waitall(4, requests, MPI_STATUSES_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getResult(Solver *solver)
|
void getResult(Solver* solver)
|
||||||
{
|
{
|
||||||
double* Pall = NULL;
|
double* Pall = NULL;
|
||||||
int *rcvCounts, *displs;
|
int *rcvCounts, *displs;
|
||||||
|
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
Pall = allocate(64, (solver->imax+2) * (solver->jmax+2) * sizeof(double));
|
Pall = allocate(64, (solver->imax + 2) * (solver->jmax + 2) * sizeof(double));
|
||||||
rcvCounts = (int*) malloc(solver->size * sizeof(int));
|
rcvCounts = (int*)malloc(solver->size * sizeof(int));
|
||||||
displs = (int*) malloc(solver->size * sizeof(int));
|
displs = (int*)malloc(solver->size * sizeof(int));
|
||||||
rcvCounts[0] = solver->jmaxLocal * (solver->imax+2);
|
rcvCounts[0] = solver->jmaxLocal * (solver->imax + 2);
|
||||||
displs[0] = 0;
|
displs[0] = 0;
|
||||||
int cursor = rcvCounts[0];
|
int cursor = rcvCounts[0];
|
||||||
|
|
||||||
for ( int i=1; i < solver->size; i++ ) {
|
for (int i = 1; i < solver->size; i++) {
|
||||||
rcvCounts[i] = sizeOfRank(i, solver->size, solver->jmax) * (solver->imax+2);
|
rcvCounts[i] = sizeOfRank(i, solver->size, solver->jmax) * (solver->imax + 2);
|
||||||
displs[i] = cursor;
|
displs[i] = cursor;
|
||||||
cursor += rcvCounts[i];
|
cursor += rcvCounts[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cnt = solver->jmaxLocal*(solver->imax+2);
|
int cnt = solver->jmaxLocal * (solver->imax + 2);
|
||||||
double* sendbuffer = solver->p + (solver->imax+2);
|
double* sendbuffer = solver->p + (solver->imax + 2);
|
||||||
MPI_Gatherv(sendbuffer, cnt, MPI_DOUBLE, Pall,
|
MPI_Gatherv(sendbuffer,
|
||||||
rcvCounts, displs, MPI_DOUBLE, 0, MPI_COMM_WORLD);
|
cnt,
|
||||||
|
MPI_DOUBLE,
|
||||||
|
Pall,
|
||||||
|
rcvCounts,
|
||||||
|
displs,
|
||||||
|
MPI_DOUBLE,
|
||||||
|
0,
|
||||||
|
MPI_COMM_WORLD);
|
||||||
|
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
writeResult(solver, Pall, "p.dat");
|
writeResult(solver, Pall, "p.dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initSolver(Solver *solver, Parameter *params, int problem)
|
void initSolver(Solver* solver, Parameter* params, int problem)
|
||||||
{
|
{
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &(solver->rank));
|
MPI_Comm_rank(MPI_COMM_WORLD, &(solver->rank));
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &(solver->size));
|
MPI_Comm_size(MPI_COMM_WORLD, &(solver->size));
|
||||||
solver->imax = params->imax;
|
solver->imax = params->imax;
|
||||||
solver->jmax = params->jmax;
|
solver->jmax = params->jmax;
|
||||||
solver->jmaxLocal = sizeOfRank(solver->rank, solver->size, solver->jmax);
|
solver->jmaxLocal = sizeOfRank(solver->rank, solver->size, solver->jmax);
|
||||||
printf("RANK %d: imaxLocal : %d, jmaxLocal : %d\n", solver->rank, solver->imax, solver->jmaxLocal);
|
printf("RANK %d: imaxLocal : %d, jmaxLocal : %d\n",
|
||||||
|
solver->rank,
|
||||||
|
solver->imax,
|
||||||
|
solver->jmaxLocal);
|
||||||
|
|
||||||
solver->dx = params->xlength/params->imax;
|
solver->dx = params->xlength / params->imax;
|
||||||
solver->dy = params->ylength/params->jmax;
|
solver->dy = params->ylength / params->jmax;
|
||||||
solver->ys = solver->rank * solver->jmaxLocal * solver->dy;
|
solver->ys = solver->rank * solver->jmaxLocal * solver->dy;
|
||||||
solver->eps = params->eps;
|
solver->eps = params->eps;
|
||||||
solver->omega = params->omg;
|
solver->omega = params->omg;
|
||||||
solver->itermax = params->itermax;
|
solver->itermax = params->itermax;
|
||||||
|
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int jmax = solver->jmax;
|
int jmax = solver->jmax;
|
||||||
int jmaxLocal = solver->jmaxLocal;
|
int jmaxLocal = solver->jmaxLocal;
|
||||||
solver->p = allocate(64, (imax+2) * (jmaxLocal+2) * sizeof(double));
|
solver->p = allocate(64, (imax + 2) * (jmaxLocal + 2) * sizeof(double));
|
||||||
solver->rhs = allocate(64, (imax+2) * (jmax+2) * sizeof(double));
|
solver->rhs = allocate(64, (imax + 2) * (jmax + 2) * sizeof(double));
|
||||||
|
|
||||||
double dx = solver->dx;
|
double dx = solver->dx;
|
||||||
double dy = solver->dy;
|
double dy = solver->dy;
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
double* rhs = solver->rhs;
|
double* rhs = solver->rhs;
|
||||||
|
|
||||||
for( int j=0; j<jmaxLocal+2; j++ ) {
|
for (int j = 0; j < jmaxLocal + 2; j++) {
|
||||||
double y = solver->ys + j * dy;
|
double y = solver->ys + j * dy;
|
||||||
for( int i=0; i<imax+2; i++ ) {
|
for (int i = 0; i < imax + 2; i++) {
|
||||||
P(i,j) = sin(4.0*PI*i*dx)+sin(4.0*PI*y);
|
P(i, j) = sin(4.0 * PI * i * dx) + sin(4.0 * PI * y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(problem == 2) {
|
if (problem == 2) {
|
||||||
for( int j=0; j<jmax+2; j++ ) {
|
for (int j = 0; j < jmax + 2; j++) {
|
||||||
for( int i=0; i<imax+2; i++ ) {
|
for (int i = 0; i < imax + 2; i++) {
|
||||||
RHS(i,j) = sin(2.0*PI*i*dx);
|
RHS(i, j) = sin(2.0 * PI * i * dx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for( int j=0; j<jmax+2; j++ ) {
|
for (int j = 0; j < jmax + 2; j++) {
|
||||||
for( int i=0; i<imax+2; i++ ) {
|
for (int i = 0; i < imax + 2; i++) {
|
||||||
RHS(i,j) = 0.0;
|
RHS(i, j) = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug(Solver *solver)
|
void debug(Solver* solver)
|
||||||
{
|
{
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int rank = solver->rank;
|
int rank = solver->rank;
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
|
|
||||||
/* for( int j=0; j < solver->jmaxLocal+2; j++ ) { */
|
/* for( int j=0; j < solver->jmaxLocal+2; j++ ) { */
|
||||||
/* for( int i=0; i < solver->imax+2; i++ ) { */
|
/* for( int i=0; i < solver->imax+2; i++ ) { */
|
||||||
/* P(i, j) = (double) rank; */
|
/* P(i, j) = (double) rank; */
|
||||||
/* } */
|
/* } */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
/* for ( int i=0; i < solver->size; i++) { */
|
/* for ( int i=0; i < solver->size; i++) { */
|
||||||
/* if ( i == rank ) { */
|
/* if ( i == rank ) { */
|
||||||
/* print(solver); */
|
/* print(solver); */
|
||||||
/* } */
|
/* } */
|
||||||
/* MPI_Barrier(MPI_COMM_WORLD); */
|
/* MPI_Barrier(MPI_COMM_WORLD); */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
/* if ( rank == 0 ) { */
|
/* if ( rank == 0 ) { */
|
||||||
/* printf("##########################################################\n"); */
|
/* printf("##########################################################\n"); */
|
||||||
/* printf("## Exchange ghost layers\n"); */
|
/* printf("## Exchange ghost layers\n"); */
|
||||||
/* printf("##########################################################\n"); */
|
/* printf("##########################################################\n"); */
|
||||||
/* } */
|
/* } */
|
||||||
/* exchange(solver); */
|
/* exchange(solver); */
|
||||||
|
|
||||||
for ( int i=0; i < solver->size; i++) {
|
for (int i = 0; i < solver->size; i++) {
|
||||||
if ( i == rank ) {
|
if (i == rank) {
|
||||||
print(solver);
|
print(solver);
|
||||||
}
|
}
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int solve(Solver *solver)
|
int solve(Solver* solver)
|
||||||
{
|
{
|
||||||
double r;
|
double r;
|
||||||
int it = 0;
|
int it = 0;
|
||||||
double res, res1;
|
double res, res1;
|
||||||
|
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int jmax = solver->jmax;
|
int jmax = solver->jmax;
|
||||||
int jmaxLocal = solver->jmaxLocal;
|
int jmaxLocal = solver->jmaxLocal;
|
||||||
double eps= solver->eps;
|
double eps = solver->eps;
|
||||||
double omega = solver->omega;
|
double omega = solver->omega;
|
||||||
int itermax = solver->itermax;
|
int itermax = solver->itermax;
|
||||||
|
|
||||||
double dx2 = solver->dx * solver->dx;
|
double dx2 = solver->dx * solver->dx;
|
||||||
double dy2 = solver->dy * solver->dy;
|
double dy2 = solver->dy * solver->dy;
|
||||||
double idx2 = 1.0/dx2;
|
double idx2 = 1.0 / dx2;
|
||||||
double idy2 = 1.0/dy2;
|
double idy2 = 1.0 / dy2;
|
||||||
double factor = omega * 0.5 * (dx2*dy2) / (dx2+dy2);
|
double factor = omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
double* rhs = solver->rhs;
|
double* rhs = solver->rhs;
|
||||||
double epssq = eps * eps;
|
double epssq = eps * eps;
|
||||||
|
|
||||||
res = eps + 1.0;
|
res = eps + 1.0;
|
||||||
|
|
||||||
while((res >= epssq) && (it < itermax)) {
|
while ((res >= epssq) && (it < itermax)) {
|
||||||
res = 0.0;
|
res = 0.0;
|
||||||
exchange(solver);
|
exchange(solver);
|
||||||
|
|
||||||
for( int j=1; j<jmaxLocal+1; j++ ) {
|
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||||
for( int i=1; i<imax+1; i++ ) {
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
|
|
||||||
r = RHS(i,j) - ((P(i-1,j) - 2.0 * P(i,j) + P(i+1,j)) * idx2 +
|
r = RHS(i, j) - ((P(i - 1, j) - 2.0 * P(i, j) + P(i + 1, j)) * idx2 +
|
||||||
(P(i,j-1) - 2.0 *P(i,j) + P(i,j+1)) * idy2);
|
(P(i, j - 1) - 2.0 * P(i, j) + P(i, j + 1)) * idy2);
|
||||||
|
|
||||||
P(i,j) -= (factor * r);
|
P(i, j) -= (factor * r);
|
||||||
res += (r * r);
|
res += (r * r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
for( int i=1; i<imax+1; i++ ) {
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
P(i,0) = P(i,1);
|
P(i, 0) = P(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( solver->rank == (solver->size-1) ) {
|
if (solver->rank == (solver->size - 1)) {
|
||||||
for( int i=1; i<imax+1; i++ ) {
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
P(i,jmaxLocal+1) = P(i,jmaxLocal);
|
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int j=1; j<jmaxLocal+1; j++ ) {
|
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||||
P(0,j) = P(1,j);
|
P(0, j) = P(1, j);
|
||||||
P(imax+1, j) = P(imax, j);
|
P(imax + 1, j) = P(imax, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Allreduce(&res, &res1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
MPI_Allreduce(&res, &res1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||||
res = res1;
|
res = res1;
|
||||||
res = sqrt(res / (imax*jmax));
|
res = sqrt(res / (imax * jmax));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
printf("%d Residuum: %e\n",it, res1);
|
printf("%d Residuum: %e\n", it, res1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
printf("Solver took %d iterations\n",it);
|
printf("Solver took %d iterations\n", it);
|
||||||
}
|
}
|
||||||
if( res < eps ){
|
if (res < eps) {
|
||||||
return 1;
|
return 1;
|
||||||
} else{
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,22 +275,22 @@ int solveRB(Solver* solver)
|
|||||||
int it = 0;
|
int it = 0;
|
||||||
double res, res1;
|
double res, res1;
|
||||||
|
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int jmax = solver->jmax;
|
int jmax = solver->jmax;
|
||||||
int jmaxLocal = solver->jmaxLocal;
|
int jmaxLocal = solver->jmaxLocal;
|
||||||
double eps= solver->eps;
|
double eps = solver->eps;
|
||||||
double omega = solver->omega;
|
double omega = solver->omega;
|
||||||
int itermax = solver->itermax;
|
int itermax = solver->itermax;
|
||||||
|
|
||||||
double dx2 = solver->dx * solver->dx;
|
double dx2 = solver->dx * solver->dx;
|
||||||
double dy2 = solver->dy * solver->dy;
|
double dy2 = solver->dy * solver->dy;
|
||||||
double idx2 = 1.0/dx2;
|
double idx2 = 1.0 / dx2;
|
||||||
double idy2 = 1.0/dy2;
|
double idy2 = 1.0 / dy2;
|
||||||
double factor = omega * 0.5 * (dx2*dy2) / (dx2+dy2);
|
double factor = omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
double* rhs = solver->rhs;
|
double* rhs = solver->rhs;
|
||||||
int pass, jsw, isw;
|
int pass, jsw, isw;
|
||||||
double epssq = eps * eps;
|
double epssq = eps * eps;
|
||||||
|
|
||||||
res = eps + 1.0;
|
res = eps + 1.0;
|
||||||
|
|
||||||
@ -304,7 +318,7 @@ int solveRB(Solver* solver)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < imax + 1; i++) {
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
P(i, 0) = P(i, 1);
|
P(i, 0) = P(i, 1);
|
||||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,12 +335,12 @@ int solveRB(Solver* solver)
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( solver->rank == 0 ) {
|
if (solver->rank == 0) {
|
||||||
printf("Solver took %d iterations\n",it);
|
printf("Solver took %d iterations\n", it);
|
||||||
}
|
}
|
||||||
if( res < eps ){
|
if (res < eps) {
|
||||||
return 1;
|
return 1;
|
||||||
} else{
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,24 +351,23 @@ int solveRBA(Solver* solver)
|
|||||||
int it = 0;
|
int it = 0;
|
||||||
double res;
|
double res;
|
||||||
|
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int jmax = solver->jmax;
|
int jmax = solver->jmax;
|
||||||
int jmaxLocal = solver->jmaxLocal;
|
int jmaxLocal = solver->jmaxLocal;
|
||||||
double eps= solver->eps;
|
double eps = solver->eps;
|
||||||
double omega = solver->omega;
|
double omega = solver->omega;
|
||||||
int itermax = solver->itermax;
|
int itermax = solver->itermax;
|
||||||
|
|
||||||
double dx2 = solver->dx * solver->dx;
|
double dx2 = solver->dx * solver->dx;
|
||||||
double dy2 = solver->dy * solver->dy;
|
double dy2 = solver->dy * solver->dy;
|
||||||
double idx2 = 1.0/dx2;
|
double idx2 = 1.0 / dx2;
|
||||||
double idy2 = 1.0/dy2;
|
double idy2 = 1.0 / dy2;
|
||||||
double factor = omega * 0.5 * (dx2*dy2) / (dx2+dy2);
|
double factor = omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
double* rhs = solver->rhs;
|
double* rhs = solver->rhs;
|
||||||
int pass, jsw, isw;
|
int pass, jsw, isw;
|
||||||
double rho = solver->rho;
|
double rho = solver->rho;
|
||||||
double epssq = eps * eps;
|
double epssq = eps * eps;
|
||||||
|
|
||||||
|
|
||||||
res = eps + 1.0;
|
res = eps + 1.0;
|
||||||
|
|
||||||
@ -384,7 +397,7 @@ int solveRBA(Solver* solver)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < imax + 1; i++) {
|
for (int i = 1; i < imax + 1; i++) {
|
||||||
P(i, 0) = P(i, 1);
|
P(i, 0) = P(i, 1);
|
||||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,21 +419,21 @@ int solveRBA(Solver* solver)
|
|||||||
|
|
||||||
void writeResult(Solver* solver, double* m, char* filename)
|
void writeResult(Solver* solver, double* m, char* filename)
|
||||||
{
|
{
|
||||||
int imax = solver->imax;
|
int imax = solver->imax;
|
||||||
int jmax = solver->jmax;
|
int jmax = solver->jmax;
|
||||||
double* p = solver->p;
|
double* p = solver->p;
|
||||||
|
|
||||||
FILE *fp;
|
FILE* fp;
|
||||||
fp= fopen(filename, "w");
|
fp = fopen(filename, "w");
|
||||||
|
|
||||||
if (fp== NULL) {
|
if (fp == NULL) {
|
||||||
printf("Error!\n");
|
printf("Error!\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int j=0; j<jmax+2; j++ ) {
|
for (int j = 0; j < jmax + 2; j++) {
|
||||||
for( int i=0; i<imax+2; i++ ) {
|
for (int i = 0; i < imax + 2; i++) {
|
||||||
fprintf(fp, "%f ", m[j*(imax+2) + i]);
|
fprintf(fp, "%f ", m[j * (imax + 2) + i]);
|
||||||
}
|
}
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ $(BUILD_DIR)/%.o: %.c $(MAKE_DIR)/include_$(TAG).mk
|
|||||||
|
|
||||||
$(BUILD_DIR)/%.s: %.c
|
$(BUILD_DIR)/%.s: %.c
|
||||||
$(info ===> GENERATE ASM $@)
|
$(info ===> GENERATE ASM $@)
|
||||||
$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $@
|
$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
.PHONY: clean distclean tags info asm
|
.PHONY: clean distclean tags info asm
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ OPENMP = -qopenmp
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
VERSION = --version
|
VERSION = --version
|
||||||
CFLAGS = -O3 -xHost -qopt-zmm-usage=high -std=c99 $(OPENMP)
|
CFLAGS = -O3 -xHost -fp-model=precise -qopt-zmm-usage=high -std=c99 $(OPENMP)
|
||||||
LFLAGS = $(OPENMP)
|
LFLAGS = $(OPENMP) -llikwid
|
||||||
DEFINES = -D_GNU_SOURCE
|
DEFINES = -D_GNU_SOURCE -DLIKWID_PERFMON
|
||||||
INCLUDES =
|
INCLUDES = -I/apps/likwid/5.2.2/include
|
||||||
LIBS =
|
LIBS = -L/apps/likwid/5.2.2/lib
|
||||||
|
File diff suppressed because one or more lines are too long
@ -8,8 +8,8 @@ name poisson
|
|||||||
|
|
||||||
xlength 1.0 # domain size in x-direction
|
xlength 1.0 # domain size in x-direction
|
||||||
ylength 1.0 # domain size in y-direction
|
ylength 1.0 # domain size in y-direction
|
||||||
imax 300 # number of interior cells in x-direction
|
imax 1000 # number of interior cells in x-direction
|
||||||
jmax 300 # number of interior cells in y-direction
|
jmax 1000 # number of interior cells in y-direction
|
||||||
|
|
||||||
# Pressure Iteration Data:
|
# Pressure Iteration Data:
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
@ -39,31 +39,29 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
readParameter(¶ms, argv[1]);
|
readParameter(¶ms, argv[1]);
|
||||||
//printParameter(¶ms);
|
// printParameter(¶ms);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
initSolver(&solver, ¶ms, 2);
|
initSolver(&solver, ¶ms, 2);
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
variant = atoi(argv[2]);
|
variant = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case SOR:
|
case SOR:
|
||||||
//printf("Plain SOR\n");
|
// printf("Plain SOR\n");
|
||||||
LIKWID_PROFILE("SOR", solve);
|
LIKWID_PROFILE("SOR", solve);
|
||||||
break;
|
break;
|
||||||
case RB:
|
case RB:
|
||||||
//printf("Red-black SOR\n");
|
// printf("Red-black SOR\n");
|
||||||
LIKWID_PROFILE("RB", solveRB);
|
LIKWID_PROFILE("RB", solveRB);
|
||||||
break;
|
break;
|
||||||
case RBA:
|
case RBA:
|
||||||
//printf("Red-black SOR with acceleration\n");
|
// printf("Red-black SOR with acceleration\n");
|
||||||
LIKWID_PROFILE("RBA", solveRBA);
|
LIKWID_PROFILE("RBA", solveRBA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//printf("Solution took %.2fs\n", endTime - startTime);
|
printf("Solution took %.2fs\n", endTime - startTime);
|
||||||
writeResult(&solver);
|
// writeResult(&solver);
|
||||||
|
|
||||||
LIKWID_MARKER_CLOSE;
|
LIKWID_MARKER_CLOSE;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -108,7 +108,7 @@ void solve(Solver* solver)
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
// printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||||
printf("%d, %f\n", it, solver->omega);
|
printf("%d, %f\n", it, solver->omega);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ void solveRB(Solver* solver)
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
// printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||||
printf("%d, %f\n", it, solver->omega);
|
printf("%d, %f\n", it, solver->omega);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,8 +234,8 @@ void solveRBA(Solver* solver)
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Final omega: %f\n", omega);
|
// printf("Final omega: %f\n", omega);
|
||||||
//printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
// printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||||
printf("%d, %f\n", it, omega);
|
printf("%d, %f\n", it, omega);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
log/All in One.pptx
Normal file
BIN
log/All in One.pptx
Normal file
Binary file not shown.
BIN
log/Enhanced Solver.pptx
Normal file
BIN
log/Enhanced Solver.pptx
Normal file
Binary file not shown.
BIN
log/Particel Tracing.pptx
Normal file
BIN
log/Particel Tracing.pptx
Normal file
Binary file not shown.
BIN
log/Red Black SOR Solver.pptx
Normal file
BIN
log/Red Black SOR Solver.pptx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user