Merging the new branch
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#=======================================================================================
|
||||
# Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
# Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
# All rights reserved.
|
||||
# Use of this source code is governed by a MIT-style
|
||||
# license that can be found in the LICENSE file.
|
||||
@@ -18,9 +18,10 @@ include $(MAKE_DIR)/include_$(TAG).mk
|
||||
INCLUDES += -I$(SRC_DIR) -I$(BUILD_DIR)
|
||||
|
||||
VPATH = $(SRC_DIR)
|
||||
SRC = $(wildcard $(SRC_DIR)/*.c)
|
||||
SRC = $(filter-out $(wildcard $(SRC_DIR)/*-*.c),$(wildcard $(SRC_DIR)/*.c))
|
||||
ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s, $(SRC))
|
||||
OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC))
|
||||
OBJ += $(BUILD_DIR)/solver-$(SOLVER).o
|
||||
SOURCES = $(SRC) $(wildcard $(SRC_DIR)/*.h)
|
||||
CPPFLAGS := $(CPPFLAGS) $(DEFINES) $(OPTIONS) $(INCLUDES)
|
||||
|
||||
@@ -39,18 +40,16 @@ $(BUILD_DIR)/%.s: %.c
|
||||
|
||||
.PHONY: clean distclean tags info asm format
|
||||
|
||||
clean: vis
|
||||
clean:
|
||||
$(info ===> CLEAN)
|
||||
@rm -rf $(BUILD_DIR)
|
||||
@rm -f tags
|
||||
|
||||
vis:
|
||||
$(info ===> REMOVING VIZUALISATION FILES)
|
||||
@rm -f vtk_files/particle*.vtk
|
||||
|
||||
distclean: clean
|
||||
$(info ===> DIST CLEAN)
|
||||
@rm -f $(TARGET)
|
||||
@rm -f *.dat
|
||||
@rm -f *.png
|
||||
|
||||
info:
|
||||
$(info $(CFLAGS))
|
||||
|
@@ -1,82 +0,0 @@
|
||||
#==============================================================================
|
||||
# Laminar Canal Flow
|
||||
#==============================================================================
|
||||
|
||||
# Problem specific Data:
|
||||
# ---------------------
|
||||
|
||||
name backstep # name of flow setup
|
||||
|
||||
bcLeft 3 # flags for boundary conditions
|
||||
bcRight 3 # 1 = no-slip 3 = outflow
|
||||
bcBottom 1 # 2 = free-slip 4 = periodic
|
||||
bcTop 1 #
|
||||
bcFront 1 #
|
||||
bcBack 1 #
|
||||
|
||||
gx 0.0 # Body forces (e.g. gravity)
|
||||
gy 0.0 #
|
||||
gz 0.0 #
|
||||
|
||||
re 5000.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
|
||||
w_init 0.0 # initial value for velocity in z-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
|
||||
zlength 1.0 # domain size in z-direction
|
||||
imax 70 # number of interior cells in x-direction
|
||||
jmax 15 # number of interior cells in y-direction
|
||||
kmax 10 # number of interior cells in z-direction
|
||||
|
||||
# Time Data:
|
||||
# ---------
|
||||
|
||||
te 100.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.7 # relaxation parameter for SOR iteration
|
||||
gamma 0.9 # upwind differencing factor gamma
|
||||
|
||||
# Particle Tracing Data:
|
||||
# -----------------------
|
||||
|
||||
numberOfParticles 500
|
||||
startTime 30
|
||||
injectTimePeriod 1.0
|
||||
writeTimePeriod 0.2
|
||||
|
||||
x1 0.0
|
||||
y1 0.5
|
||||
z1 0.0
|
||||
x2 0.0
|
||||
y2 1.45
|
||||
z2 1.0
|
||||
|
||||
# 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 2.0
|
||||
circleRadius 1.0
|
||||
|
||||
#===============================================================================
|
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@ gz 0.0 #
|
||||
|
||||
re 100.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
|
||||
w_init 0.0 # initial value for velocity in z-direction
|
||||
p_init 0.0 # initial value for pressure
|
||||
@@ -31,14 +31,14 @@ p_init 0.0 # initial value for pressure
|
||||
xlength 30.0 # domain size in x-direction
|
||||
ylength 4.0 # domain size in y-direction
|
||||
zlength 4.0 # domain size in z-direction
|
||||
imax 100 # number of interior cells in x-direction
|
||||
jmax 40 # number of interior cells in y-direction
|
||||
kmax 40 # number of interior cells in z-direction
|
||||
imax 200 # number of interior cells in x-direction
|
||||
jmax 50 # number of interior cells in y-direction
|
||||
kmax 50 # number of interior cells in z-direction
|
||||
|
||||
# Time Data:
|
||||
# ---------
|
||||
|
||||
te 60.0 # final time
|
||||
te 100.0 # final time
|
||||
dt 0.02 # time stepsize
|
||||
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||
|
||||
@@ -47,35 +47,6 @@ tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||
|
||||
itermax 500 # maximal number of pressure iteration in one time step
|
||||
eps 0.0001 # stopping tolerance for pressure iteration
|
||||
omg 0.52
|
||||
omg 1.7 # relaxation parameter for SOR iteration
|
||||
gamma 0.9 # upwind differencing factor gamma
|
||||
|
||||
# Particle Tracing Data:
|
||||
# -----------------------
|
||||
|
||||
numberOfParticles 200
|
||||
startTime 100
|
||||
injectTimePeriod 2.0
|
||||
writeTimePeriod 1.0
|
||||
|
||||
x1 1.0
|
||||
y1 0.0
|
||||
z1 1.0
|
||||
x2 1.0
|
||||
y2 4.0
|
||||
z2 1.0
|
||||
|
||||
# Obstacle Geometry Data:
|
||||
# -----------------------
|
||||
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||
|
||||
shape 0
|
||||
xCenter 10.0
|
||||
yCenter 2.0
|
||||
zCenter 2.0
|
||||
xRectLength 8.0
|
||||
yRectLength 2.0
|
||||
zRectLength 2.0
|
||||
circleRadius 1.0
|
||||
#===============================================================================
|
||||
|
320011
BasicSolver/3D-seq/canal.vtk
320011
BasicSolver/3D-seq/canal.vtk
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
# Supported: GCC, CLANG, ICC
|
||||
TAG ?= ICC
|
||||
TAG ?= CLANG
|
||||
ENABLE_OPENMP ?= false
|
||||
# Supported: sor, mg
|
||||
SOLVER ?= mg
|
||||
# Run in debug settings
|
||||
DEBUG ?= false
|
||||
|
||||
#Feature options
|
||||
OPTIONS += -DARRAY_ALIGNMENT=64
|
||||
OPTIONS += -DVERBOSE
|
||||
#OPTIONS += -DVERBOSE
|
||||
#OPTIONS += -DDEBUG
|
||||
#OPTIONS += -DBOUNDCHECK
|
||||
#OPTIONS += -DVERBOSE_AFFINITY
|
||||
#OPTIONS += -DVERBOSE_DATASIZE
|
||||
#OPTIONS += -DVERBOSE_TIMER
|
||||
|
@@ -31,14 +31,14 @@ p_init 0.0 # initial value for pressure
|
||||
xlength 1.0 # domain size in x-direction
|
||||
ylength 1.0 # domain size in y-direction
|
||||
zlength 1.0 # domain size in z-direction
|
||||
imax 40 # number of interior cells in x-direction
|
||||
jmax 40 # number of interior cells in y-direction
|
||||
kmax 40 # number of interior cells in z-direction
|
||||
imax 128 # number of interior cells in x-direction
|
||||
jmax 128 # number of interior cells in y-direction
|
||||
kmax 128 # number of interior cells in z-direction
|
||||
|
||||
# Time Data:
|
||||
# ---------
|
||||
|
||||
te 50.0 # final time
|
||||
te 2.0 # final time
|
||||
dt 0.02 # time stepsize
|
||||
tau 0.5 # safety factor for time stepsize control (<0 constant delt)
|
||||
|
||||
@@ -50,32 +50,5 @@ eps 0.001 # stopping tolerance for pressure iteration
|
||||
rho 0.5
|
||||
omg 1.7 # relaxation parameter for SOR iteration
|
||||
gamma 0.9 # upwind differencing factor gamma
|
||||
|
||||
# Particle Tracing Data:
|
||||
# -----------------------
|
||||
|
||||
numberOfParticles 30
|
||||
startTime 10
|
||||
injectTimePeriod 3.0
|
||||
writeTimePeriod 1.0
|
||||
|
||||
x1 0.1
|
||||
y1 0.0
|
||||
z1 1.0
|
||||
x2 1.0
|
||||
y2 4.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
|
||||
levels 5 # Multigrid levels
|
||||
#===============================================================================
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -2,16 +2,18 @@ CC = clang
|
||||
GCC = cc
|
||||
LINKER = $(CC)
|
||||
|
||||
ifeq ($(ENABLE_OPENMP),true)
|
||||
ifeq ($(strip $(ENABLE_OPENMP)),true)
|
||||
OPENMP = -fopenmp
|
||||
#OPENMP = -Xpreprocessor -fopenmp #required on Macos with homebrew libomp
|
||||
LIBS = # -lomp
|
||||
endif
|
||||
ifeq ($(strip $(DEBUG)),true)
|
||||
CFLAGS = -O0 -g -std=c17
|
||||
else
|
||||
CFLAGS = -O3 -std=c17 $(OPENMP)
|
||||
endif
|
||||
|
||||
VERSION = --version
|
||||
# CFLAGS = -O3 -std=c17 $(OPENMP)
|
||||
CFLAGS = -Ofast -std=c17 -Weverything
|
||||
#CFLAGS = -Ofast -fnt-store=aggressive -std=c99 $(OPENMP) #AMD CLANG
|
||||
LFLAGS = $(OPENMP) -lm
|
||||
DEFINES = -D_GNU_SOURCE# -DDEBUG
|
||||
DEFINES = -D_GNU_SOURCE
|
||||
INCLUDES =
|
||||
|
@@ -1,82 +0,0 @@
|
||||
#==============================================================================
|
||||
# Laminar Canal Flow
|
||||
#==============================================================================
|
||||
|
||||
# Problem specific Data:
|
||||
# ---------------------
|
||||
|
||||
name karman # name of flow setup
|
||||
|
||||
bcLeft 3 # flags for boundary conditions
|
||||
bcRight 3 # 1 = no-slip 3 = outflow
|
||||
bcBottom 1 # 2 = free-slip 4 = periodic
|
||||
bcTop 1 #
|
||||
bcFront 1 #
|
||||
bcBack 1 #
|
||||
|
||||
gx 0.0 # Body forces (e.g. gravity)
|
||||
gy 0.0 #
|
||||
gz 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
|
||||
w_init 0.0 # initial value for velocity in z-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
|
||||
zlength 8.0 # domain size in z-direction
|
||||
imax 200 # number of interior cells in x-direction
|
||||
jmax 80 # number of interior cells in y-direction
|
||||
kmax 80 # number of interior cells in z-direction
|
||||
|
||||
# Time Data:
|
||||
# ---------
|
||||
|
||||
te 250.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 4000
|
||||
startTime 50
|
||||
injectTimePeriod 1.0
|
||||
writeTimePeriod 5.0
|
||||
|
||||
x1 0.0
|
||||
y1 3.6
|
||||
z1 3.6
|
||||
x2 0.0
|
||||
y2 4.7
|
||||
z2 4.7
|
||||
|
||||
# Obstacle Geometry Data:
|
||||
# -----------------------
|
||||
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
|
||||
|
||||
shape 2
|
||||
xCenter 5.0
|
||||
yCenter 4.0
|
||||
zCenter 4.0
|
||||
xRectLength 8.0
|
||||
yRectLength 2.0
|
||||
zRectLength 2.0
|
||||
circleRadius 2.0
|
||||
|
||||
#===============================================================================
|
2560011
BasicSolver/3D-seq/karman.vtk
2560011
BasicSolver/3D-seq/karman.vtk
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
639
BasicSolver/3D-seq/src/discretization.c
Normal file
639
BasicSolver/3D-seq/src/discretization.c
Normal file
@@ -0,0 +1,639 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "allocate.h"
|
||||
#include "discretization.h"
|
||||
#include "parameter.h"
|
||||
#include "util.h"
|
||||
|
||||
static void printConfig(Discretization* d)
|
||||
{
|
||||
printf("Parameters for #%s#\n", d->problem);
|
||||
printf("BC Left:%d Right:%d Bottom:%d Top:%d Front:%d Back:%d\n",
|
||||
d->bcLeft,
|
||||
d->bcRight,
|
||||
d->bcBottom,
|
||||
d->bcTop,
|
||||
d->bcFront,
|
||||
d->bcBack);
|
||||
printf("\tReynolds number: %.2f\n", d->re);
|
||||
printf("\tGx Gy: %.2f %.2f %.2f\n", d->gx, d->gy, d->gz);
|
||||
printf("Geometry data:\n");
|
||||
printf("\tDomain box size (x, y, z): %.2f, %.2f, %.2f\n",
|
||||
d->grid.xlength,
|
||||
d->grid.ylength,
|
||||
d->grid.zlength);
|
||||
printf("\tCells (x, y, z): %d, %d, %d\n", d->grid.imax, d->grid.jmax, d->grid.kmax);
|
||||
printf("\tCell size (dx, dy, dz): %f, %f, %f\n", d->grid.dx, d->grid.dy, d->grid.dz);
|
||||
printf("Timestep parameters:\n");
|
||||
printf("\tDefault stepsize: %.2f, Final time %.2f\n", d->dt, d->te);
|
||||
printf("\tdt bound: %.6f\n", d->dtBound);
|
||||
printf("\tTau factor: %.2f\n", d->tau);
|
||||
printf("Iterative parameters:\n");
|
||||
printf("\tepsilon (stopping tolerance) : %f\n", d->eps);
|
||||
printf("\tgamma factor: %f\n", d->gamma);
|
||||
printf("\tomega (SOR relaxation): %f\n", d->omega);
|
||||
}
|
||||
|
||||
void initDiscretization(Discretization* d, Parameter* p)
|
||||
{
|
||||
d->problem = p->name;
|
||||
d->bcLeft = p->bcLeft;
|
||||
d->bcRight = p->bcRight;
|
||||
d->bcBottom = p->bcBottom;
|
||||
d->bcTop = p->bcTop;
|
||||
d->bcFront = p->bcFront;
|
||||
d->bcBack = p->bcBack;
|
||||
|
||||
d->grid.imax = p->imax;
|
||||
d->grid.jmax = p->jmax;
|
||||
d->grid.kmax = p->kmax;
|
||||
d->grid.xlength = p->xlength;
|
||||
d->grid.ylength = p->ylength;
|
||||
d->grid.zlength = p->zlength;
|
||||
d->grid.dx = p->xlength / p->imax;
|
||||
d->grid.dy = p->ylength / p->jmax;
|
||||
d->grid.dz = p->zlength / p->kmax;
|
||||
|
||||
d->eps = p->eps;
|
||||
d->omega = p->omg;
|
||||
d->re = p->re;
|
||||
d->gx = p->gx;
|
||||
d->gy = p->gy;
|
||||
d->gz = p->gz;
|
||||
d->dt = p->dt;
|
||||
d->te = p->te;
|
||||
d->tau = p->tau;
|
||||
d->gamma = p->gamma;
|
||||
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
size_t bytesize = (imax + 2) * (jmax + 2) * (kmax + 2) * sizeof(double);
|
||||
d->u = allocate(64, bytesize);
|
||||
d->v = allocate(64, bytesize);
|
||||
d->w = allocate(64, bytesize);
|
||||
d->p = allocate(64, bytesize);
|
||||
d->rhs = allocate(64, bytesize);
|
||||
d->f = allocate(64, bytesize);
|
||||
d->g = allocate(64, bytesize);
|
||||
d->h = allocate(64, bytesize);
|
||||
|
||||
for (int i = 0; i < (imax + 2) * (jmax + 2) * (kmax + 2); i++) {
|
||||
d->u[i] = p->u_init;
|
||||
d->v[i] = p->v_init;
|
||||
d->w[i] = p->w_init;
|
||||
d->p[i] = p->p_init;
|
||||
d->rhs[i] = 0.0;
|
||||
d->f[i] = 0.0;
|
||||
d->g[i] = 0.0;
|
||||
d->h[i] = 0.0;
|
||||
}
|
||||
|
||||
double dx = d->grid.dx;
|
||||
double dy = d->grid.dy;
|
||||
double dz = d->grid.dz;
|
||||
|
||||
double invSqrSum = 1.0 / (dx * dx) + 1.0 / (dy * dy) + 1.0 / (dz * dz);
|
||||
d->dtBound = 0.5 * d->re * 1.0 / invSqrSum;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printConfig(s);
|
||||
#endif /* VERBOSE */
|
||||
}
|
||||
|
||||
void computeRHS(Discretization* d)
|
||||
{
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
double idx = 1.0 / d->grid.dx;
|
||||
double idy = 1.0 / d->grid.dy;
|
||||
double idz = 1.0 / d->grid.dz;
|
||||
double idt = 1.0 / d->dt;
|
||||
|
||||
double* rhs = d->rhs;
|
||||
double* f = d->f;
|
||||
double* g = d->g;
|
||||
double* h = d->h;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
RHS(i, j, k) = ((F(i, j, k) - F(i - 1, j, k)) * idx +
|
||||
(G(i, j, k) - G(i, j - 1, k)) * idy +
|
||||
(H(i, j, k) - H(i, j, k - 1)) * idz) *
|
||||
idt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double maxElement(Discretization* d, double* m)
|
||||
{
|
||||
int size = (d->grid.imax + 2) * (d->grid.jmax + 2) * (d->grid.kmax + 2);
|
||||
double maxval = DBL_MIN;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
maxval = MAX(maxval, fabs(m[i]));
|
||||
}
|
||||
|
||||
return maxval;
|
||||
}
|
||||
|
||||
void normalizePressure(Discretization* d)
|
||||
{
|
||||
int size = (d->grid.imax + 2) * (d->grid.jmax + 2) * (d->grid.kmax + 2);
|
||||
double* p = d->p;
|
||||
double avgP = 0.0;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
avgP += p[i];
|
||||
}
|
||||
avgP /= size;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
p[i] = p[i] - avgP;
|
||||
}
|
||||
}
|
||||
|
||||
void computeTimestep(Discretization* d)
|
||||
{
|
||||
double dt = d->dtBound;
|
||||
double dx = d->grid.dx;
|
||||
double dy = d->grid.dy;
|
||||
double dz = d->grid.dz;
|
||||
|
||||
double umax = maxElement(d, d->u);
|
||||
double vmax = maxElement(d, d->v);
|
||||
double wmax = maxElement(d, d->w);
|
||||
|
||||
if (umax > 0) {
|
||||
dt = (dt > dx / umax) ? dx / umax : dt;
|
||||
}
|
||||
if (vmax > 0) {
|
||||
dt = (dt > dy / vmax) ? dy / vmax : dt;
|
||||
}
|
||||
if (wmax > 0) {
|
||||
dt = (dt > dz / wmax) ? dz / wmax : dt;
|
||||
}
|
||||
|
||||
d->dt = dt * d->tau;
|
||||
}
|
||||
|
||||
void setBoundaryConditions(Discretization* d)
|
||||
{
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
|
||||
double* u = d->u;
|
||||
double* v = d->v;
|
||||
double* w = d->w;
|
||||
|
||||
switch (d->bcTop) {
|
||||
case NOSLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
V(i, jmax, k) = 0.0;
|
||||
U(i, jmax + 1, k) = -U(i, jmax, k);
|
||||
W(i, jmax + 1, k) = -W(i, jmax, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
V(i, jmax, k) = 0.0;
|
||||
U(i, jmax + 1, k) = U(i, jmax, k);
|
||||
W(i, jmax + 1, k) = W(i, jmax, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, jmax + 1, k) = U(i, jmax, k);
|
||||
V(i, jmax, k) = V(i, jmax - 1, k);
|
||||
W(i, jmax + 1, k) = W(i, jmax, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (d->bcBottom) {
|
||||
case NOSLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
V(i, 0, k) = 0.0;
|
||||
U(i, 0, k) = -U(i, 1, k);
|
||||
W(i, 0, k) = -W(i, 1, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
V(i, 0, k) = 0.0;
|
||||
U(i, 0, k) = U(i, 1, k);
|
||||
W(i, 0, k) = W(i, 1, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, 0, k) = U(i, 1, k);
|
||||
V(i, 0, k) = V(i, 1, k);
|
||||
W(i, 0, k) = W(i, 1, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (d->bcLeft) {
|
||||
case NOSLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(0, j, k) = 0.0;
|
||||
V(0, j, k) = -V(1, j, k);
|
||||
W(0, j, k) = -W(1, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(0, j, k) = 0.0;
|
||||
V(0, j, k) = V(1, j, k);
|
||||
W(0, j, k) = W(1, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(0, j, k) = U(1, j, k);
|
||||
V(0, j, k) = V(1, j, k);
|
||||
W(0, j, k) = W(1, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (d->bcRight) {
|
||||
case NOSLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(imax, j, k) = 0.0;
|
||||
V(imax + 1, j, k) = -V(imax, j, k);
|
||||
W(imax + 1, j, k) = -W(imax, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(imax, j, k) = 0.0;
|
||||
V(imax + 1, j, k) = V(imax, j, k);
|
||||
W(imax + 1, j, k) = W(imax, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
U(imax, j, k) = U(imax - 1, j, k);
|
||||
V(imax + 1, j, k) = V(imax, j, k);
|
||||
W(imax + 1, j, k) = W(imax, j, k);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (d->bcFront) {
|
||||
case NOSLIP:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, 0) = -U(i, j, 1);
|
||||
V(i, j, 0) = -V(i, j, 1);
|
||||
W(i, j, 0) = 0.0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, 0) = U(i, j, 1);
|
||||
V(i, j, 0) = V(i, j, 1);
|
||||
W(i, j, 0) = 0.0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, 0) = U(i, j, 1);
|
||||
V(i, j, 0) = V(i, j, 1);
|
||||
W(i, j, 0) = W(i, j, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (d->bcBack) {
|
||||
case NOSLIP:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, kmax + 1) = -U(i, j, kmax);
|
||||
V(i, j, kmax + 1) = -V(i, j, kmax);
|
||||
W(i, j, kmax + 1) = 0.0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SLIP:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, kmax + 1) = U(i, j, kmax);
|
||||
V(i, j, kmax + 1) = V(i, j, kmax);
|
||||
W(i, j, kmax + 1) = 0.0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OUTFLOW:
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, kmax + 1) = U(i, j, kmax);
|
||||
V(i, j, kmax + 1) = V(i, j, kmax);
|
||||
W(i, j, kmax) = W(i, j, kmax - 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PERIODIC:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setSpecialBoundaryCondition(Discretization* d)
|
||||
{
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
|
||||
double mDy = d->grid.dy;
|
||||
double* u = d->u;
|
||||
|
||||
if (strcmp(d->problem, "dcavity") == 0) {
|
||||
for (int k = 1; k < kmax; k++) {
|
||||
for (int i = 1; i < imax; i++) {
|
||||
U(i, jmax + 1, k) = 2.0 - U(i, jmax, k);
|
||||
}
|
||||
}
|
||||
} else if (strcmp(d->problem, "canal") == 0) {
|
||||
double ylength = d->grid.ylength;
|
||||
double y;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
y = mDy * (j - 0.5);
|
||||
U(0, j, k) = y * (ylength - y) * 4.0 / (ylength * ylength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void computeFG(Discretization* d)
|
||||
{
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
|
||||
double* u = d->u;
|
||||
double* v = d->v;
|
||||
double* w = d->w;
|
||||
double* f = d->f;
|
||||
double* g = d->g;
|
||||
double* h = d->h;
|
||||
|
||||
double gx = d->gx;
|
||||
double gy = d->gy;
|
||||
double gz = d->gz;
|
||||
double dt = d->dt;
|
||||
|
||||
double gamma = d->gamma;
|
||||
double inverseRe = 1.0 / d->re;
|
||||
double inverseDx = 1.0 / d->grid.dx;
|
||||
double inverseDy = 1.0 / d->grid.dy;
|
||||
double inverseDz = 1.0 / d->grid.dz;
|
||||
double du2dx, dv2dy, dw2dz;
|
||||
double duvdx, duwdx, duvdy, dvwdy, duwdz, dvwdz;
|
||||
double du2dx2, du2dy2, du2dz2;
|
||||
double dv2dx2, dv2dy2, dv2dz2;
|
||||
double dw2dx2, dw2dy2, dw2dz2;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
du2dx = inverseDx * 0.25 *
|
||||
((U(i, j, k) + U(i + 1, j, k)) *
|
||||
(U(i, j, k) + U(i + 1, j, k)) -
|
||||
(U(i, j, k) + U(i - 1, j, k)) *
|
||||
(U(i, j, k) + U(i - 1, j, k))) +
|
||||
gamma * inverseDx * 0.25 *
|
||||
(fabs(U(i, j, k) + U(i + 1, j, k)) *
|
||||
(U(i, j, k) - U(i + 1, j, k)) +
|
||||
fabs(U(i, j, k) + U(i - 1, j, k)) *
|
||||
(U(i, j, k) - U(i - 1, j, k)));
|
||||
|
||||
duvdy = inverseDy * 0.25 *
|
||||
((V(i, j, k) + V(i + 1, j, k)) *
|
||||
(U(i, j, k) + U(i, j + 1, k)) -
|
||||
(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
|
||||
(U(i, j, k) + U(i, j - 1, k))) +
|
||||
gamma * inverseDy * 0.25 *
|
||||
(fabs(V(i, j, k) + V(i + 1, j, k)) *
|
||||
(U(i, j, k) - U(i, j + 1, k)) +
|
||||
fabs(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
|
||||
(U(i, j, k) - U(i, j - 1, k)));
|
||||
|
||||
duwdz = inverseDz * 0.25 *
|
||||
((W(i, j, k) + W(i + 1, j, k)) *
|
||||
(U(i, j, k) + U(i, j, k + 1)) -
|
||||
(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
|
||||
(U(i, j, k) + U(i, j, k - 1))) +
|
||||
gamma * inverseDz * 0.25 *
|
||||
(fabs(W(i, j, k) + W(i + 1, j, k)) *
|
||||
(U(i, j, k) - U(i, j, k + 1)) +
|
||||
fabs(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
|
||||
(U(i, j, k) - U(i, j, k - 1)));
|
||||
|
||||
du2dx2 = inverseDx * inverseDx *
|
||||
(U(i + 1, j, k) - 2.0 * U(i, j, k) + U(i - 1, j, k));
|
||||
du2dy2 = inverseDy * inverseDy *
|
||||
(U(i, j + 1, k) - 2.0 * U(i, j, k) + U(i, j - 1, k));
|
||||
du2dz2 = inverseDz * inverseDz *
|
||||
(U(i, j, k + 1) - 2.0 * U(i, j, k) + U(i, j, k - 1));
|
||||
F(i, j, k) = U(i, j, k) + dt * (inverseRe * (du2dx2 + du2dy2 + du2dz2) -
|
||||
du2dx - duvdy - duwdz + gx);
|
||||
|
||||
duvdx = inverseDx * 0.25 *
|
||||
((U(i, j, k) + U(i, j + 1, k)) *
|
||||
(V(i, j, k) + V(i + 1, j, k)) -
|
||||
(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
|
||||
(V(i, j, k) + V(i - 1, j, k))) +
|
||||
gamma * inverseDx * 0.25 *
|
||||
(fabs(U(i, j, k) + U(i, j + 1, k)) *
|
||||
(V(i, j, k) - V(i + 1, j, k)) +
|
||||
fabs(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
|
||||
(V(i, j, k) - V(i - 1, j, k)));
|
||||
|
||||
dv2dy = inverseDy * 0.25 *
|
||||
((V(i, j, k) + V(i, j + 1, k)) *
|
||||
(V(i, j, k) + V(i, j + 1, k)) -
|
||||
(V(i, j, k) + V(i, j - 1, k)) *
|
||||
(V(i, j, k) + V(i, j - 1, k))) +
|
||||
gamma * inverseDy * 0.25 *
|
||||
(fabs(V(i, j, k) + V(i, j + 1, k)) *
|
||||
(V(i, j, k) - V(i, j + 1, k)) +
|
||||
fabs(V(i, j, k) + V(i, j - 1, k)) *
|
||||
(V(i, j, k) - V(i, j - 1, k)));
|
||||
|
||||
dvwdz = inverseDz * 0.25 *
|
||||
((W(i, j, k) + W(i, j + 1, k)) *
|
||||
(V(i, j, k) + V(i, j, k + 1)) -
|
||||
(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
|
||||
(V(i, j, k) + V(i, j, k + 1))) +
|
||||
gamma * inverseDz * 0.25 *
|
||||
(fabs(W(i, j, k) + W(i, j + 1, k)) *
|
||||
(V(i, j, k) - V(i, j, k + 1)) +
|
||||
fabs(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
|
||||
(V(i, j, k) - V(i, j, k + 1)));
|
||||
|
||||
dv2dx2 = inverseDx * inverseDx *
|
||||
(V(i + 1, j, k) - 2.0 * V(i, j, k) + V(i - 1, j, k));
|
||||
dv2dy2 = inverseDy * inverseDy *
|
||||
(V(i, j + 1, k) - 2.0 * V(i, j, k) + V(i, j - 1, k));
|
||||
dv2dz2 = inverseDz * inverseDz *
|
||||
(V(i, j, k + 1) - 2.0 * V(i, j, k) + V(i, j, k - 1));
|
||||
G(i, j, k) = V(i, j, k) + dt * (inverseRe * (dv2dx2 + dv2dy2 + dv2dz2) -
|
||||
duvdx - dv2dy - dvwdz + gy);
|
||||
|
||||
duwdx = inverseDx * 0.25 *
|
||||
((U(i, j, k) + U(i, j, k + 1)) *
|
||||
(W(i, j, k) + W(i + 1, j, k)) -
|
||||
(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
|
||||
(W(i, j, k) + W(i - 1, j, k))) +
|
||||
gamma * inverseDx * 0.25 *
|
||||
(fabs(U(i, j, k) + U(i, j, k + 1)) *
|
||||
(W(i, j, k) - W(i + 1, j, k)) +
|
||||
fabs(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
|
||||
(W(i, j, k) - W(i - 1, j, k)));
|
||||
|
||||
dvwdy = inverseDy * 0.25 *
|
||||
((V(i, j, k) + V(i, j, k + 1)) *
|
||||
(W(i, j, k) + W(i, j + 1, k)) -
|
||||
(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
|
||||
(W(i, j, k) + W(i, j - 1, k))) +
|
||||
gamma * inverseDy * 0.25 *
|
||||
(fabs(V(i, j, k) + V(i, j, k + 1)) *
|
||||
(W(i, j, k) - W(i, j + 1, k)) +
|
||||
fabs(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
|
||||
(W(i, j, k) - W(i, j - 1, k)));
|
||||
|
||||
dw2dz = inverseDz * 0.25 *
|
||||
((W(i, j, k) + W(i, j, k + 1)) *
|
||||
(W(i, j, k) + W(i, j, k + 1)) -
|
||||
(W(i, j, k) + W(i, j, k - 1)) *
|
||||
(W(i, j, k) + W(i, j, k - 1))) +
|
||||
gamma * inverseDz * 0.25 *
|
||||
(fabs(W(i, j, k) + W(i, j, k + 1)) *
|
||||
(W(i, j, k) - W(i, j, k + 1)) +
|
||||
fabs(W(i, j, k) + W(i, j, k - 1)) *
|
||||
(W(i, j, k) - W(i, j, k - 1)));
|
||||
|
||||
dw2dx2 = inverseDx * inverseDx *
|
||||
(W(i + 1, j, k) - 2.0 * W(i, j, k) + W(i - 1, j, k));
|
||||
dw2dy2 = inverseDy * inverseDy *
|
||||
(W(i, j + 1, k) - 2.0 * W(i, j, k) + W(i, j - 1, k));
|
||||
dw2dz2 = inverseDz * inverseDz *
|
||||
(W(i, j, k + 1) - 2.0 * W(i, j, k) + W(i, j, k - 1));
|
||||
H(i, j, k) = W(i, j, k) + dt * (inverseRe * (dw2dx2 + dw2dy2 + dw2dz2) -
|
||||
duwdx - dvwdy - dw2dz + gz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------- boundary of F ---------------------------
|
||||
*/
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
F(0, j, k) = U(0, j, k);
|
||||
F(imax, j, k) = U(imax, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------- boundary of G ---------------------------
|
||||
*/
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
G(i, 0, k) = V(i, 0, k);
|
||||
G(i, jmax, k) = V(i, jmax, k);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------- boundary of G ---------------------------
|
||||
*/
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
H(i, j, 0) = W(i, j, 0);
|
||||
H(i, j, kmax) = W(i, j, kmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void adaptUV(Discretization* d)
|
||||
{
|
||||
int imax = d->grid.imax;
|
||||
int jmax = d->grid.jmax;
|
||||
int kmax = d->grid.kmax;
|
||||
|
||||
double* p = d->p;
|
||||
double* u = d->u;
|
||||
double* v = d->v;
|
||||
double* w = d->w;
|
||||
double* f = d->f;
|
||||
double* g = d->g;
|
||||
double* h = d->h;
|
||||
|
||||
double factorX = d->dt / d->grid.dx;
|
||||
double factorY = d->dt / d->grid.dy;
|
||||
double factorZ = d->dt / d->grid.dz;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
U(i, j, k) = F(i, j, k) - (P(i + 1, j, k) - P(i, j, k)) * factorX;
|
||||
V(i, j, k) = G(i, j, k) - (P(i, j + 1, k) - P(i, j, k)) * factorY;
|
||||
W(i, j, k) = H(i, j, k) - (P(i, j, k + 1) - P(i, j, k)) * factorZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
BasicSolver/3D-seq/src/discretization.h
Normal file
41
BasicSolver/3D-seq/src/discretization.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#ifndef __DISCRETIZATION_H_
|
||||
#define __DISCRETIZATION_H_
|
||||
|
||||
#include "grid.h"
|
||||
#include "parameter.h"
|
||||
|
||||
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
||||
|
||||
typedef struct {
|
||||
/* geometry and grid information */
|
||||
Grid grid;
|
||||
/* arrays */
|
||||
double *p, *rhs;
|
||||
double *f, *g, *h;
|
||||
double *u, *v, *w;
|
||||
/* parameters */
|
||||
double eps, omega;
|
||||
double re, tau, gamma;
|
||||
double gx, gy, gz;
|
||||
/* time stepping */
|
||||
double dt, te;
|
||||
double dtBound;
|
||||
char* problem;
|
||||
int bcLeft, bcRight, bcBottom, bcTop, bcFront, bcBack;
|
||||
} Discretization;
|
||||
|
||||
extern void initDiscretization(Discretization*, Parameter*);
|
||||
extern void computeRHS(Discretization*);
|
||||
extern void normalizePressure(Discretization*);
|
||||
extern void computeTimestep(Discretization*);
|
||||
extern void setBoundaryConditions(Discretization*);
|
||||
extern void setSpecialBoundaryCondition(Discretization*);
|
||||
extern void computeFG(Discretization*);
|
||||
extern void adaptUV(Discretization*);
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
@@ -1,18 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "allocate.h"
|
||||
#include "discretization.h"
|
||||
#include "parameter.h"
|
||||
#include "particletracing.h"
|
||||
#include "progress.h"
|
||||
#include "solver.h"
|
||||
#include "timing.h"
|
||||
@@ -20,9 +18,8 @@
|
||||
|
||||
#define G(v, i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
|
||||
enum VARIANT { SOR = 1, RB, RBA };
|
||||
|
||||
static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, double* wg)
|
||||
static void createBulkArrays(
|
||||
Discretization* s, double* pg, double* ug, double* vg, double* wg)
|
||||
{
|
||||
int imax = s->grid.imax;
|
||||
int jmax = s->grid.jmax;
|
||||
@@ -70,86 +67,72 @@ static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, doub
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int rank;
|
||||
int variant = RB;
|
||||
|
||||
double timeStart, timeStop;
|
||||
Parameter params;
|
||||
Parameter p;
|
||||
Discretization d;
|
||||
Solver s;
|
||||
ParticleTracer particletracer;
|
||||
initParameter(¶ms);
|
||||
initParameter(&p);
|
||||
|
||||
if (argc < 2) {
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3) {
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
printParameter(¶ms);
|
||||
initSolver(&s, ¶ms);
|
||||
initParticleTracer(&particletracer, ¶ms);
|
||||
printParticleTracerParameters(&particletracer);
|
||||
readParameter(&p, argv[1]);
|
||||
printParameter(&p);
|
||||
initDiscretization(&d, &p);
|
||||
initSolver(&s, &d, &p);
|
||||
#ifndef VERBOSE
|
||||
initProgress(s.te);
|
||||
initProgress(d.te);
|
||||
#endif
|
||||
|
||||
double tau = s.tau;
|
||||
double te = s.te;
|
||||
double tau = d.tau;
|
||||
double te = d.te;
|
||||
double t = 0.0;
|
||||
|
||||
// printGrid(&s, s.seg);
|
||||
// exit(0)
|
||||
int nt = 0;
|
||||
|
||||
timeStart = getTimeStamp();
|
||||
|
||||
void (*solver_generic[])() = { solve, solveRB, solveRBA };
|
||||
|
||||
while (t <= te) {
|
||||
if (tau > 0.0) computeTimestep(&s);
|
||||
setBoundaryConditions(&s);
|
||||
setSpecialBoundaryCondition(&s);
|
||||
setObjectBoundaryCondition(&s);
|
||||
|
||||
computeFG(&s);
|
||||
computeRHS(&s);
|
||||
solver_generic[variant - 1](&s);
|
||||
adaptUV(&s);
|
||||
|
||||
trace(&particletracer, s.u, s.v, s.w, s.seg, t);
|
||||
|
||||
t += s.dt;
|
||||
if (tau > 0.0) computeTimestep(&d);
|
||||
setBoundaryConditions(&d);
|
||||
setSpecialBoundaryCondition(&d);
|
||||
computeFG(&d);
|
||||
computeRHS(&d);
|
||||
if (nt % 100 == 0) normalizePressure(&d);
|
||||
solve(&s, d.p, d.rhs);
|
||||
adaptUV(&d);
|
||||
t += d.dt;
|
||||
nt++;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
printf("TIME %f , TIMESTEP %f\n", t, s.dt);
|
||||
}
|
||||
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
|
||||
#else
|
||||
printProgress(t);
|
||||
#endif
|
||||
}
|
||||
timeStop = getTimeStamp();
|
||||
#ifndef VERBOSE
|
||||
stopProgress();
|
||||
#endif
|
||||
printf("Solution took %.2fs\n", timeStop - timeStart);
|
||||
|
||||
timeStart = getTimeStamp();
|
||||
double *pg, *ug, *vg, *wg;
|
||||
|
||||
size_t bytesize = (size_t)(s.grid.imax * s.grid.jmax * s.grid.kmax) * sizeof(double);
|
||||
size_t bytesize = (size_t)(d.grid.imax * d.grid.jmax * d.grid.kmax) * sizeof(double);
|
||||
|
||||
pg = allocate(64, bytesize);
|
||||
ug = allocate(64, bytesize);
|
||||
vg = allocate(64, bytesize);
|
||||
wg = allocate(64, bytesize);
|
||||
|
||||
createBulkArrays(&s, pg, ug, vg, wg);
|
||||
VtkOptions opts = { .grid = s.grid };
|
||||
vtkOpen(&opts, s.problem);
|
||||
createBulkArrays(&d, pg, ug, vg, wg);
|
||||
VtkOptions opts = { .grid = d.grid };
|
||||
vtkOpen(&opts, d.problem);
|
||||
vtkScalar(&opts, "pressure", pg);
|
||||
vtkVector(&opts, "velocity", (VtkVector) { ug, vg, wg });
|
||||
vtkClose(&opts);
|
||||
|
||||
timeStop = getTimeStamp();
|
||||
printf("Result output took %.2fs\n", timeStop - timeStart);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
@@ -26,7 +26,7 @@ void initParameter(Parameter* param)
|
||||
param->re = 100.0;
|
||||
param->gamma = 0.9;
|
||||
param->tau = 0.5;
|
||||
param->rho = 0.99;
|
||||
param->levels = 5;
|
||||
}
|
||||
|
||||
void readParameter(Parameter* param, const char* filename)
|
||||
@@ -66,6 +66,7 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_INT(jmax);
|
||||
PARSE_INT(kmax);
|
||||
PARSE_INT(itermax);
|
||||
PARSE_INT(levels);
|
||||
PARSE_REAL(eps);
|
||||
PARSE_REAL(omg);
|
||||
PARSE_REAL(re);
|
||||
@@ -87,29 +88,6 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_REAL(v_init);
|
||||
PARSE_REAL(w_init);
|
||||
PARSE_REAL(p_init);
|
||||
PARSE_REAL(rho);
|
||||
|
||||
/* Added new particle tracing parameters */
|
||||
PARSE_INT(numberOfParticles);
|
||||
PARSE_REAL(startTime);
|
||||
PARSE_REAL(injectTimePeriod);
|
||||
PARSE_REAL(writeTimePeriod);
|
||||
PARSE_REAL(x1);
|
||||
PARSE_REAL(y1);
|
||||
PARSE_REAL(z1);
|
||||
PARSE_REAL(x2);
|
||||
PARSE_REAL(y2);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,4 +125,5 @@ void printParameter(Parameter* param)
|
||||
printf("\tepsilon (stopping tolerance) : %f\n", param->eps);
|
||||
printf("\tgamma (stopping tolerance) : %f\n", param->gamma);
|
||||
printf("\tomega (SOR relaxation): %f\n", param->omg);
|
||||
printf("\tMultiGrid levels : %d\n", param->levels);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
@@ -10,7 +10,7 @@
|
||||
typedef struct {
|
||||
int imax, jmax, kmax;
|
||||
double xlength, ylength, zlength;
|
||||
int itermax;
|
||||
int itermax, levels;
|
||||
double eps, omg, rho;
|
||||
double re, tau, gamma;
|
||||
double te, dt;
|
||||
@@ -18,17 +18,9 @@ typedef struct {
|
||||
char* name;
|
||||
int bcLeft, bcRight, bcBottom, bcTop, bcFront, bcBack;
|
||||
double u_init, v_init, w_init, p_init;
|
||||
|
||||
int numberOfParticles;
|
||||
double startTime, injectTimePeriod, writeTimePeriod;
|
||||
|
||||
double x1, y1, z1, x2, y2, z2;
|
||||
|
||||
int shape;
|
||||
double xCenter, yCenter, zCenter, xRectLength, yRectLength, zRectLength, circleRadius;
|
||||
} Parameter;
|
||||
|
||||
extern void initParameter(Parameter*);
|
||||
extern void readParameter(Parameter*, const char*);
|
||||
extern void printParameter(Parameter*);
|
||||
void initParameter(Parameter*);
|
||||
void readParameter(Parameter*, const char*);
|
||||
void printParameter(Parameter*);
|
||||
#endif
|
||||
|
@@ -1,325 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vtkWriter.h"
|
||||
|
||||
#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 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)]
|
||||
|
||||
static int ts = 0;
|
||||
unsigned int seed = 32767;
|
||||
void printParticles(ParticleTracer* particletracer)
|
||||
{
|
||||
for (int i = 0; i < particletracer->totalParticles; ++i) {
|
||||
printf("Particle position X : %.2f, Y : %.2f, flag : %d\n",
|
||||
particletracer->particlePool[i].x,
|
||||
particletracer->particlePool[i].y,
|
||||
particletracer->particlePool[i].flag);
|
||||
}
|
||||
}
|
||||
void injectParticles(ParticleTracer* particletracer, int* seg)
|
||||
{
|
||||
|
||||
int imax = particletracer->imax;
|
||||
int jmax = particletracer->jmax;
|
||||
int kmax = particletracer->kmax;
|
||||
|
||||
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
|
||||
|
||||
particletracer->particlePool[particletracer->pointer].x = particletracer->x1;
|
||||
particletracer->particlePool[particletracer->pointer].y = (((double)rand() /
|
||||
RAND_MAX) *
|
||||
(particletracer->y2 - particletracer->y1)) +
|
||||
particletracer->y1;
|
||||
particletracer->particlePool[particletracer->pointer].z = (((double)rand() /
|
||||
RAND_MAX) *
|
||||
(particletracer->z2 - particletracer->z1)) +
|
||||
particletracer->z1;
|
||||
|
||||
int i = particletracer->particlePool[particletracer->pointer].x /
|
||||
particletracer->dx;
|
||||
int j = particletracer->particlePool[particletracer->pointer].y /
|
||||
particletracer->dy;
|
||||
int k = particletracer->particlePool[particletracer->pointer].z /
|
||||
particletracer->dz;
|
||||
|
||||
if(S(i+1, j, k) == NONE)
|
||||
{
|
||||
particletracer->particlePool[particletracer->pointer].flag = true;
|
||||
++(particletracer->pointer);
|
||||
++(particletracer->totalParticles);
|
||||
}
|
||||
else particletracer->particlePool[particletracer->pointer].flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
void advanceParticles(ParticleTracer* particletracer,
|
||||
double* restrict u,
|
||||
double* restrict v,
|
||||
double* restrict w,
|
||||
int* restrict seg,
|
||||
double time)
|
||||
{
|
||||
int imax = particletracer->imax;
|
||||
int jmax = particletracer->jmax;
|
||||
int kmax = particletracer->kmax;
|
||||
|
||||
double dx = particletracer->dx;
|
||||
double dy = particletracer->dy;
|
||||
double dz = particletracer->dz;
|
||||
|
||||
double xlength = particletracer->xlength;
|
||||
double ylength = particletracer->ylength;
|
||||
double zlength = particletracer->zlength;
|
||||
|
||||
for (int i = 0; i < particletracer->totalParticles; ++i) {
|
||||
if (particletracer->particlePool[i].flag == true) {
|
||||
double x = particletracer->particlePool[i].x;
|
||||
double y = particletracer->particlePool[i].y;
|
||||
double z = particletracer->particlePool[i].z;
|
||||
|
||||
int iCoord = (int)(x / dx) + 1;
|
||||
int jCoord = (int)((y + 0.5 * dy) / dy) + 1;
|
||||
int kCoord = (int)((z + 0.5 * dz) / dz) + 1;
|
||||
|
||||
double x1 = (double)(iCoord - 1) * dx;
|
||||
double y1 = ((double)(jCoord - 1) - 0.5) * dy;
|
||||
double z1 = ((double)(kCoord - 1) - 0.5) * dz;
|
||||
|
||||
double x2 = (double)iCoord * dx;
|
||||
double y2 = ((double)jCoord - 0.5) * dy;
|
||||
double z2 = ((double)kCoord - 0.5) * dz;
|
||||
|
||||
double u_n =
|
||||
(1.0 / (dx * dy * dz)) *
|
||||
((x2 - x) * (y2 - y) * (z2 - z) * U(iCoord - 1, jCoord - 1, kCoord - 1) +
|
||||
(x - x1) * (y2 - y) * (z2 - z) * U(iCoord, jCoord - 1, kCoord - 1) +
|
||||
(x2 - x) * (y - y1) * (z2 - z) * U(iCoord - 1, jCoord, kCoord - 1) +
|
||||
(x - x1) * (y - y1) * (z2 - z) * U(iCoord, jCoord, kCoord - 1) +
|
||||
(x2 - x) * (y2 - y) * (z - z1) * U(iCoord - 1, jCoord - 1, kCoord) +
|
||||
(x - x1) * (y2 - y) * (z - z1) * U(iCoord, jCoord - 1, kCoord) +
|
||||
(x2 - x) * (y - y1) * (z - z1) * U(iCoord - 1, jCoord, kCoord) +
|
||||
(x - x1) * (y - y1) * (z - z1) * U(iCoord, jCoord, kCoord));
|
||||
|
||||
double new_x = x + particletracer->dt * u_n;
|
||||
particletracer->particlePool[i].x = new_x;
|
||||
|
||||
iCoord = (int)((x + 0.5 * dx) / dx) + 1;
|
||||
jCoord = (int)(y / dy) + 1;
|
||||
kCoord = (int)((z + 0.5 * dz) / dz) + 1;
|
||||
|
||||
x1 = ((double)(iCoord - 1) - 0.5) * dx;
|
||||
y1 = (double)(jCoord - 1) * dy;
|
||||
z1 = ((double)(kCoord - 1) - 0.5) * dz;
|
||||
|
||||
x2 = ((double)iCoord - 0.5) * dx;
|
||||
y2 = (double)jCoord * dy;
|
||||
z2 = ((double)kCoord - 0.5) * dz;
|
||||
|
||||
double v_n =
|
||||
(1.0 / (dx * dy * dz)) *
|
||||
((x2 - x) * (y2 - y) * (z2 - z) * V(iCoord - 1, jCoord - 1, kCoord - 1) +
|
||||
(x - x1) * (y2 - y) * (z2 - z) * V(iCoord, jCoord - 1, kCoord - 1) +
|
||||
(x2 - x) * (y - y1) * (z2 - z) * V(iCoord - 1, jCoord, kCoord - 1) +
|
||||
(x - x1) * (y - y1) * (z2 - z) * V(iCoord, jCoord, kCoord - 1) +
|
||||
(x2 - x) * (y2 - y) * (z - z1) * V(iCoord - 1, jCoord - 1, kCoord) +
|
||||
(x - x1) * (y2 - y) * (z - z1) * V(iCoord, jCoord - 1, kCoord) +
|
||||
(x2 - x) * (y - y1) * (z - z1) * V(iCoord - 1, jCoord, kCoord) +
|
||||
(x - x1) * (y - y1) * (z - z1) * V(iCoord, jCoord, kCoord));
|
||||
|
||||
double new_y = y + particletracer->dt * v_n;
|
||||
particletracer->particlePool[i].y = new_y;
|
||||
|
||||
iCoord = (int)((x + 0.5 * dx) / dx) + 1;
|
||||
jCoord = (int)((y + 0.5 * dy) / dy) + 1;
|
||||
kCoord = (int)(z / dz) + 1;
|
||||
|
||||
x1 = ((double)(iCoord - 1) - 0.5) * dx;
|
||||
y1 = ((double)(jCoord - 1) - 0.5) * dy;
|
||||
z1 = (double)(kCoord - 1) * dz;
|
||||
|
||||
x2 = ((double)iCoord - 0.5) * dx;
|
||||
y2 = ((double)jCoord - 0.5) * dy;
|
||||
z2 = (double)kCoord * dz;
|
||||
|
||||
double w_n =
|
||||
(1.0 / (dx * dy * dz)) *
|
||||
((x2 - x) * (y2 - y) * (z2 - z) * W(iCoord - 1, jCoord - 1, kCoord - 1) +
|
||||
(x - x1) * (y2 - y) * (z2 - z) * W(iCoord, jCoord - 1, kCoord - 1) +
|
||||
(x2 - x) * (y - y1) * (z2 - z) * W(iCoord - 1, jCoord, kCoord - 1) +
|
||||
(x - x1) * (y - y1) * (z2 - z) * W(iCoord, jCoord, kCoord - 1) +
|
||||
(x2 - x) * (y2 - y) * (z - z1) * W(iCoord - 1, jCoord - 1, kCoord) +
|
||||
(x - x1) * (y2 - y) * (z - z1) * W(iCoord, jCoord - 1, kCoord) +
|
||||
(x2 - x) * (y - y1) * (z - z1) * W(iCoord - 1, jCoord, kCoord) +
|
||||
(x - x1) * (y - y1) * (z - z1) * W(iCoord, jCoord, kCoord));
|
||||
|
||||
double new_z = z + particletracer->dt * w_n;
|
||||
particletracer->particlePool[i].z = new_z;
|
||||
|
||||
// printf("\tOld X : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, New Y :
|
||||
// %.2f, jCoord : %d\n\n", x, new_x, iCoord, y, new_y, jCoord);
|
||||
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f,
|
||||
// U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1,
|
||||
// jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord,
|
||||
// jCoord)); printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1)
|
||||
// : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n",
|
||||
// V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord),
|
||||
// V(iCoord, jCoord)); printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
|
||||
// printf("\t j-1 * (imax + 2) + i-1 = %d with element from U : %.2f", (jCoord
|
||||
// - 1) * (200 + 2) + (iCoord - 1), u[(jCoord - 1) * (imax + 2) + (iCoord -
|
||||
// 1)]); printf("\nimax : %d, jmax : %d\n", imax, jmax);
|
||||
|
||||
if (((new_x < 0.0) || (new_x > xlength) || (new_y < 0.0) ||
|
||||
(new_y > ylength) || (new_z < 0.0) || (new_z > zlength))) {
|
||||
particletracer->particlePool[i].flag = false;
|
||||
}
|
||||
int i_new = new_x / dx, j_new = new_y / dy, k_new = new_z / dz;
|
||||
|
||||
if (S(i_new, j_new, k_new) != NONE) {
|
||||
particletracer->particlePool[i].flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void freeParticles(ParticleTracer* particletracer)
|
||||
{
|
||||
free(particletracer->particlePool);
|
||||
free(particletracer->linSpaceLine);
|
||||
}
|
||||
|
||||
void writeParticles(ParticleTracer* particletracer)
|
||||
{
|
||||
VtkOptions opts = { .particletracer = particletracer };
|
||||
|
||||
char filename[50];
|
||||
snprintf(filename, 50, "vtk_files/particles%d.vtk", ts);
|
||||
vtkOpenPT(&opts, filename, ts);
|
||||
vtkParticle(&opts, "particle");
|
||||
vtkClose(&opts);
|
||||
++ts;
|
||||
}
|
||||
|
||||
void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
|
||||
{
|
||||
particletracer->numberOfParticles = params->numberOfParticles;
|
||||
particletracer->startTime = params->startTime;
|
||||
particletracer->injectTimePeriod = params->injectTimePeriod;
|
||||
particletracer->writeTimePeriod = params->writeTimePeriod;
|
||||
|
||||
particletracer->dt = params->dt;
|
||||
particletracer->dx = params->xlength / params->imax;
|
||||
particletracer->dy = params->ylength / params->jmax;
|
||||
particletracer->dz = params->zlength / params->kmax;
|
||||
|
||||
particletracer->xlength = params->xlength;
|
||||
particletracer->ylength = params->ylength;
|
||||
particletracer->zlength = params->zlength;
|
||||
|
||||
particletracer->x1 = params->x1;
|
||||
particletracer->y1 = params->y1;
|
||||
particletracer->z1 = params->z1;
|
||||
particletracer->x2 = params->x2;
|
||||
particletracer->y2 = params->y2;
|
||||
particletracer->z2 = params->z2;
|
||||
|
||||
particletracer->lastInjectTime = params->startTime;
|
||||
particletracer->lastUpdateTime = params->startTime;
|
||||
particletracer->lastWriteTime = params->startTime;
|
||||
|
||||
particletracer->pointer = 0;
|
||||
particletracer->totalParticles = 0;
|
||||
|
||||
particletracer->imax = params->imax;
|
||||
particletracer->jmax = params->jmax;
|
||||
particletracer->kmax = params->kmax;
|
||||
|
||||
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2) *
|
||||
params->numberOfParticles;
|
||||
|
||||
particletracer->particlePool = malloc(
|
||||
sizeof(Particle) * particletracer->estimatedNumParticles);
|
||||
particletracer->linSpaceLine = malloc(
|
||||
sizeof(Particle) * particletracer->numberOfParticles);
|
||||
}
|
||||
|
||||
void printParticleTracerParameters(ParticleTracer* particletracer)
|
||||
{
|
||||
printf("Particle Tracing data:\n");
|
||||
printf("\tNumber of particles : %d being injected for every period of %.2f\n",
|
||||
particletracer->numberOfParticles,
|
||||
particletracer->injectTimePeriod);
|
||||
printf("\tstartTime : %.2f\n", particletracer->startTime);
|
||||
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : "
|
||||
"%.2f, z1 : %.2f, x2 : %.2f, y2 : %.2f, z2 : %.2f\n",
|
||||
particletracer->x1,
|
||||
particletracer->y1,
|
||||
particletracer->z1,
|
||||
particletracer->x2,
|
||||
particletracer->y2,
|
||||
particletracer->z2);
|
||||
printf("\tPointer : %d, TotalParticles : %d\n",
|
||||
particletracer->pointer,
|
||||
particletracer->totalParticles);
|
||||
printf("\tdt : %.2f, dx : %.2f, dy : %.2f, dz : %.2f\n",
|
||||
particletracer->dt,
|
||||
particletracer->dx,
|
||||
particletracer->dy,
|
||||
particletracer->dz);
|
||||
}
|
||||
|
||||
void trace(ParticleTracer* particletracer,
|
||||
double* u,
|
||||
double* v,
|
||||
double* w,
|
||||
int* seg,
|
||||
double time)
|
||||
{
|
||||
if (time >= particletracer->startTime) {
|
||||
// printParticles(particletracer);
|
||||
if ((time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod) {
|
||||
injectParticles(particletracer, seg);
|
||||
particletracer->lastInjectTime = time;
|
||||
}
|
||||
if ((time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod) {
|
||||
writeParticles(particletracer);
|
||||
particletracer->lastWriteTime = time;
|
||||
}
|
||||
advanceParticles(particletracer, u, v, w, seg, time);
|
||||
compress(particletracer);
|
||||
particletracer->lastUpdateTime = time;
|
||||
}
|
||||
}
|
||||
|
||||
void compress(ParticleTracer* particletracer)
|
||||
{
|
||||
Particle* memPool = particletracer->particlePool;
|
||||
Particle tempPool[particletracer->totalParticles];
|
||||
int totalParticles = 0;
|
||||
|
||||
for (int i = 0; i < particletracer->totalParticles; ++i) {
|
||||
if (memPool[i].flag == 1) {
|
||||
tempPool[totalParticles].x = memPool[i].x;
|
||||
tempPool[totalParticles].y = memPool[i].y;
|
||||
tempPool[totalParticles].z = memPool[i].z;
|
||||
tempPool[totalParticles].flag = memPool[i].flag;
|
||||
++totalParticles;
|
||||
}
|
||||
}
|
||||
|
||||
particletracer->totalParticles = totalParticles;
|
||||
particletracer->pointer = totalParticles + 1;
|
||||
|
||||
memcpy(particletracer->particlePool, tempPool, totalParticles * sizeof(Particle));
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#ifndef __PARTICLETRACING_H_
|
||||
#define __PARTICLETRACING_H_
|
||||
#include "allocate.h"
|
||||
#include "parameter.h"
|
||||
#include "particletracing.h"
|
||||
#include "solver.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum COORD { X = 0, Y, NCOORD } COORD;
|
||||
typedef struct {
|
||||
double x, y, z;
|
||||
bool flag;
|
||||
} Particle;
|
||||
|
||||
typedef struct {
|
||||
int numberOfParticles, totalParticles;
|
||||
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime,
|
||||
lastWriteTime;
|
||||
|
||||
int estimatedNumParticles, activeParticles;
|
||||
|
||||
double dx, dy, dz, dt;
|
||||
Particle* linSpaceLine;
|
||||
Particle* particlePool;
|
||||
|
||||
int pointer;
|
||||
|
||||
double imax, jmax, kmax, xlength, ylength, zlength;
|
||||
|
||||
double x1, y1, x2, y2, z1, z2;
|
||||
} ParticleTracer;
|
||||
|
||||
extern void initParticleTracer(ParticleTracer*, Parameter*);
|
||||
extern void injectParticles(ParticleTracer*, int* seg);
|
||||
extern void advanceParticles(ParticleTracer*, double*, double*, double*, int*, double);
|
||||
extern void freeParticles(ParticleTracer*);
|
||||
extern void writeParticles(ParticleTracer*);
|
||||
extern void printParticleTracerParameters(ParticleTracer*);
|
||||
extern void printParticles(ParticleTracer*);
|
||||
extern void compress(ParticleTracer*);
|
||||
extern void trace(ParticleTracer*, double*, double*, double*, int*, double);
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
250
BasicSolver/3D-seq/src/solver-mg.c
Normal file
250
BasicSolver/3D-seq/src/solver-mg.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "allocate.h"
|
||||
#include "solver.h"
|
||||
#include "util.h"
|
||||
|
||||
#define FINEST_LEVEL 0
|
||||
#define COARSEST_LEVEL (s->levels - 1)
|
||||
#define S(i, j, k) s[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define E(i, j, k) e[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define R(i, j, k) r[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define OLD(i, j, k) old[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
|
||||
static void restrictMG(Solver* s, int level, int imax, int jmax, int kmax)
|
||||
{
|
||||
double* r = s->r[level + 1];
|
||||
double* old = s->r[level];
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; ++i) {
|
||||
R(i, j, k) = (OLD(2 * i - 1, 2 * j - 1, 2 * k) +
|
||||
OLD(2 * i, 2 * j - 1, 2 * k) * 2 +
|
||||
OLD(2 * i + 1, 2 * j - 1, 2 * k) +
|
||||
OLD(2 * i - 1, 2 * j, 2 * k) * 2 +
|
||||
OLD(2 * i, 2 * j, 2 * k) * 8 +
|
||||
OLD(2 * i + 1, 2 * j, 2 * k) * 2 +
|
||||
OLD(2 * i - 1, 2 * j + 1, 2 * k) +
|
||||
OLD(2 * i, 2 * j + 1, 2 * k) * 2 +
|
||||
OLD(2 * i + 1, 2 * j + 1, 2 * k) +
|
||||
|
||||
OLD(2 * i - 1, 2 * j - 1, 2 * k - 1) +
|
||||
OLD(2 * i, 2 * j - 1, 2 * k - 1) * 2 +
|
||||
OLD(2 * i + 1, 2 * j - 1, 2 * k - 1) +
|
||||
OLD(2 * i - 1, 2 * j, 2 * k - 1) * 2 +
|
||||
OLD(2 * i, 2 * j, 2 * k - 1) * 4 +
|
||||
OLD(2 * i + 1, 2 * j, 2 * k - 1) * 2 +
|
||||
OLD(2 * i - 1, 2 * j + 1, 2 * k - 1) +
|
||||
OLD(2 * i, 2 * j + 1, 2 * k - 1) * 2 +
|
||||
OLD(2 * i + 1, 2 * j + 1, 2 * k - 1) +
|
||||
|
||||
OLD(2 * i - 1, 2 * j - 1, 2 * k + 1) +
|
||||
OLD(2 * i, 2 * j - 1, 2 * k + 1) * 2 +
|
||||
OLD(2 * i + 1, 2 * j - 1, 2 * k + 1) +
|
||||
OLD(2 * i - 1, 2 * j, 2 * k + 1) * 2 +
|
||||
OLD(2 * i, 2 * j, 2 * k + 1) * 4 +
|
||||
OLD(2 * i + 1, 2 * j, 2 * k + 1) * 2 +
|
||||
OLD(2 * i - 1, 2 * j + 1, 2 * k + 1) +
|
||||
OLD(2 * i, 2 * j + 1, 2 * k + 1) * 2 +
|
||||
OLD(2 * i + 1, 2 * j + 1, 2 * k + 1)) /
|
||||
64.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void prolongate(Solver* s, int level, int imax, int jmax, int kmax)
|
||||
{
|
||||
double* old = s->r[level + 1];
|
||||
double* e = s->r[level];
|
||||
|
||||
for (int k = 2; k < kmax + 1; k += 2) {
|
||||
for (int j = 2; j < jmax + 1; j += 2) {
|
||||
for (int i = 2; i < imax + 1; i += 2) {
|
||||
E(i, j, k) = OLD(i / 2, j / 2, k / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void correct(Solver* s, double* p, int level, int imax, int jmax, int kmax)
|
||||
{
|
||||
double* e = s->e[level];
|
||||
|
||||
for (int k = 1; k < kmax + 1; ++k) {
|
||||
for (int j = 1; j < jmax + 1; ++j) {
|
||||
for (int i = 1; i < imax + 1; ++i) {
|
||||
P(i, j, k) += E(i, j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setBoundaryCondition(double* p, int imax, int jmax, int kmax)
|
||||
{
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, j, 0) = P(i, j, 1);
|
||||
P(i, j, kmax + 1) = P(i, j, kmax);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, 0, k) = P(i, 1, k);
|
||||
P(i, jmax + 1, k) = P(i, jmax, k);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
P(0, j, k) = P(1, j, k);
|
||||
P(imax + 1, j, k) = P(imax, j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double smooth(
|
||||
Solver* s, double* p, double* rhs, int level, int imax, int jmax, int kmax)
|
||||
{
|
||||
double eps = s->eps;
|
||||
int itermax = s->itermax;
|
||||
double dx2 = s->grid->dx * s->grid->dx;
|
||||
double dy2 = s->grid->dy * s->grid->dy;
|
||||
double dz2 = s->grid->dz * s->grid->dz;
|
||||
double idx2 = 1.0 / dx2;
|
||||
double idy2 = 1.0 / dy2;
|
||||
double idz2 = 1.0 / dz2;
|
||||
double factor = s->omega * 0.5 * (dx2 * dy2 * dz2) /
|
||||
(dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
|
||||
double* r = s->r[level];
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
int pass, ksw, jsw, isw;
|
||||
double res = 1.0;
|
||||
|
||||
ksw = 1;
|
||||
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
jsw = ksw;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
isw = jsw;
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = isw; i < imax + 1; i += 2) {
|
||||
|
||||
R(i, j, k) =
|
||||
RHS(i, j, k) -
|
||||
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
|
||||
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) * idy2 +
|
||||
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) * idz2);
|
||||
|
||||
P(i, j, k) -= (factor * R(i, j, k));
|
||||
res += (R(i, j, k) * R(i, j, k));
|
||||
}
|
||||
isw = 3 - isw;
|
||||
}
|
||||
jsw = 3 - jsw;
|
||||
}
|
||||
ksw = 3 - ksw;
|
||||
}
|
||||
|
||||
res = res / (double)(imax * jmax * kmax);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static double multiGrid(
|
||||
Solver* s, double* p, double* rhs, int level, int imax, int jmax, int kmax)
|
||||
{
|
||||
double res = 0.0;
|
||||
|
||||
// coarsest level TODO: Use direct solver?
|
||||
if (level == COARSEST_LEVEL) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
smooth(s, p, rhs, level, imax, jmax, kmax);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// pre-smoothing TODO: Make smoothing steps configurable?
|
||||
for (int i = 0; i < 5; i++) {
|
||||
smooth(s, p, rhs, level, imax, jmax, kmax);
|
||||
if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
|
||||
}
|
||||
|
||||
// restrict
|
||||
restrictMG(s, level, imax, jmax, kmax);
|
||||
|
||||
// MGSolver on residual and error.
|
||||
// TODO: What if there is a rest?
|
||||
multiGrid(s,
|
||||
s->e[level + 1],
|
||||
s->r[level + 1],
|
||||
level + 1,
|
||||
imax / 2,
|
||||
jmax / 2,
|
||||
kmax / 2);
|
||||
|
||||
// prolongate
|
||||
prolongate(s, level, imax, jmax, kmax);
|
||||
|
||||
// correct p on finer level using residual
|
||||
correct(s, p, level, imax, jmax, kmax);
|
||||
if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
|
||||
|
||||
// post-smoothing
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = smooth(s, p, rhs, level, imax, jmax, kmax);
|
||||
if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void initSolver(Solver* s, Discretization* d, Parameter* p)
|
||||
{
|
||||
s->eps = p->eps;
|
||||
s->omega = p->omg;
|
||||
s->itermax = p->itermax;
|
||||
s->levels = p->levels;
|
||||
s->grid = &d->grid;
|
||||
|
||||
int imax = s->grid->imax;
|
||||
int jmax = s->grid->jmax;
|
||||
int kmax = s->grid->kmax;
|
||||
int levels = s->levels;
|
||||
printf("Using Multigrid solver with %d levels\n", levels);
|
||||
|
||||
s->r = malloc(levels * sizeof(double*));
|
||||
s->e = malloc(levels * sizeof(double*));
|
||||
|
||||
size_t size = (imax + 2) * (jmax + 2) * (kmax + 2);
|
||||
|
||||
for (int j = 0; j < levels; j++) {
|
||||
s->r[j] = allocate(64, size * sizeof(double));
|
||||
s->e[j] = allocate(64, size * sizeof(double));
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
s->r[j][i] = 0.0;
|
||||
s->e[j][i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void solve(Solver* s, double* p, double* rhs)
|
||||
{
|
||||
double res = multiGrid(s, p, rhs, 0, s->grid->imax, s->grid->jmax, s->grid->kmax);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Residuum: %.6f\n", res);
|
||||
#endif
|
||||
}
|
99
BasicSolver/3D-seq/src/solver-sor.c
Normal file
99
BasicSolver/3D-seq/src/solver-sor.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#include "solver.h"
|
||||
#include "util.h"
|
||||
|
||||
void initSolver(Solver* s, Discretization* d, Parameter* p)
|
||||
{
|
||||
s->grid = &d->grid;
|
||||
s->itermax = p->itermax;
|
||||
s->eps = p->eps;
|
||||
s->omega = p->omg;
|
||||
}
|
||||
|
||||
void solve(Solver* s, double* p, double* rhs)
|
||||
{
|
||||
int imax = s->grid->imax;
|
||||
int jmax = s->grid->jmax;
|
||||
int kmax = s->grid->kmax;
|
||||
double eps = s->eps;
|
||||
int itermax = s->itermax;
|
||||
double dx2 = s->grid->dx * s->grid->dx;
|
||||
double dy2 = s->grid->dy * s->grid->dy;
|
||||
double dz2 = s->grid->dz * s->grid->dz;
|
||||
double idx2 = 1.0 / dx2;
|
||||
double idy2 = 1.0 / dy2;
|
||||
double idz2 = 1.0 / dz2;
|
||||
double factor = s->omega * 0.5 * (dx2 * dy2 * dz2) /
|
||||
(dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
int pass, ksw, jsw, isw;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
ksw = 1;
|
||||
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
jsw = ksw;
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
isw = jsw;
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = isw; i < imax + 1; i += 2) {
|
||||
|
||||
double r =
|
||||
RHS(i, j, k) -
|
||||
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
|
||||
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
|
||||
idy2 +
|
||||
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
|
||||
idz2);
|
||||
|
||||
P(i, j, k) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
isw = 3 - isw;
|
||||
}
|
||||
jsw = 3 - jsw;
|
||||
}
|
||||
ksw = 3 - ksw;
|
||||
}
|
||||
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, j, 0) = P(i, j, 1);
|
||||
P(i, j, kmax + 1) = P(i, j, kmax);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, 0, k) = P(i, 1, k);
|
||||
P(i, jmax + 1, k) = P(i, jmax, k);
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 1; k < kmax + 1; k++) {
|
||||
for (int j = 1; j < jmax + 1; j++) {
|
||||
P(0, j, k) = P(1, j, k);
|
||||
P(imax + 1, j, k) = P(imax, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
res = res / (double)(imax * jmax * kmax);
|
||||
#ifdef DEBUG
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
#endif
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,92 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
#ifndef __SOLVER_H_
|
||||
#define __SOLVER_H_
|
||||
|
||||
#include "discretization.h"
|
||||
#include "grid.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,
|
||||
/*Ghost cells boundary */
|
||||
OUTSIDEBOUNDARY
|
||||
};
|
||||
enum BC { NOSLIP = 1, SLIP, OUTFLOW, PERIODIC };
|
||||
/// @brief
|
||||
enum SHAPE { NOSHAPE = 0, RECT, CIRCLE };
|
||||
|
||||
typedef struct {
|
||||
/* geometry and grid information */
|
||||
Grid grid;
|
||||
/* arrays */
|
||||
double *p, *rhs;
|
||||
double *f, *g, *h;
|
||||
double *u, *v, *w;
|
||||
int* seg;
|
||||
Grid* grid;
|
||||
/* parameters */
|
||||
double eps, omega, rho;
|
||||
double re, tau, gamma;
|
||||
double gx, gy, gz;
|
||||
/* time stepping */
|
||||
int itermax;
|
||||
double dt, te;
|
||||
double dtBound;
|
||||
char* problem;
|
||||
int bcLeft, bcRight, bcBottom, bcTop, bcFront, bcBack;
|
||||
int levels;
|
||||
double **r, **e;
|
||||
} Solver;
|
||||
|
||||
extern void initSolver(Solver*, Parameter*);
|
||||
extern void computeRHS(Solver*);
|
||||
extern void solve(Solver*);
|
||||
extern void solveRB(Solver*);
|
||||
extern void solveRBA(Solver*);
|
||||
extern void normalizePressure(Solver*);
|
||||
extern void computeTimestep(Solver*);
|
||||
extern void setBoundaryConditions(Solver*);
|
||||
extern void setObjectBoundaryCondition(Solver*);
|
||||
extern void setObjectPBoundaryCondition(Solver*);
|
||||
extern void setSpecialBoundaryCondition(Solver*);
|
||||
extern void computeFG(Solver*);
|
||||
extern void adaptUV(Solver*);
|
||||
extern void writeResult(Solver*);
|
||||
extern void printGrid(Solver*, int*);
|
||||
extern void initSolver(Solver*, Discretization*, Parameter*);
|
||||
extern void solve(Solver*, double*, double*);
|
||||
|
||||
#endif
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
@@ -19,4 +19,13 @@
|
||||
#define ABS(a) ((a) >= 0 ? (a) : -(a))
|
||||
#endif
|
||||
|
||||
#define P(i, j, k) p[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define F(i, j, k) f[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define G(i, j, k) g[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define H(i, j, k) h[(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 W(i, j, k) w[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
#define RHS(i, j, k) rhs[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
|
||||
|
||||
#endif // __UTIL_H_
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "vtkWriter.h"
|
||||
#define G(v, i, j, k) v[(k) * imax * jmax + (j) * imax + (i)]
|
||||
#define G(v, i, j, k) v[(k)*imax * jmax + (j)*imax + (i)]
|
||||
|
||||
static float floatSwap(float f)
|
||||
{
|
||||
@@ -69,8 +69,7 @@ void vtkScalar(VtkOptions* o, char* name, double* s)
|
||||
printf("vtkWriter not initialize! Call vtkOpen first!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fprintf(o->fh, "SCALARS %s float 1\n", name);
|
||||
fprintf(o->fh, "LOOKUP_TABLE default\n");
|
||||
fprintf(o->fh, "SCALARS %s float\n", name);
|
||||
|
||||
for (int k = 0; k < kmax; k++) {
|
||||
for (int j = 0; j < jmax; j++) {
|
||||
@@ -105,7 +104,7 @@ void vtkVector(VtkOptions* o, char* name, VtkVector vec)
|
||||
for (int k = 0; k < kmax; k++) {
|
||||
for (int j = 0; j < jmax; j++) {
|
||||
for (int i = 0; i < imax; i++) {
|
||||
if (o->fmt == ASCII /*&& k >= 20*/) {
|
||||
if (o->fmt == ASCII) {
|
||||
fprintf(o->fh,
|
||||
"%f %f %f\n",
|
||||
G(vec.u, i, j, k),
|
||||
@@ -130,69 +129,3 @@ void vtkClose(VtkOptions* o)
|
||||
fclose(o->fh);
|
||||
o->fh = NULL;
|
||||
}
|
||||
|
||||
static void writeHeaderPT(VtkOptions* o, int ts)
|
||||
{
|
||||
fprintf(o->fh, "# vtk DataFile Version 3.0\n");
|
||||
fprintf(o->fh, "PAMPI cfd solver particle tracing file\n");
|
||||
if (o->fmt == ASCII) {
|
||||
fprintf(o->fh, "ASCII\n");
|
||||
} else if (o->fmt == BINARY) {
|
||||
fprintf(o->fh, "BINARY\n");
|
||||
}
|
||||
|
||||
fprintf(o->fh, "DATASET UNSTRUCTURED_GRID\n");
|
||||
fprintf(o->fh, "FIELD FieldData 2\n");
|
||||
fprintf(o->fh, "TIME 1 1 double\n");
|
||||
fprintf(o->fh, "%d\n", ts);
|
||||
fprintf(o->fh, "CYCLE 1 1 int\n");
|
||||
fprintf(o->fh, "1\n");
|
||||
}
|
||||
|
||||
void vtkOpenPT(VtkOptions* o, char* problem, int ts)
|
||||
{
|
||||
o->fh = fopen(problem, "w");
|
||||
|
||||
if (o->fh == NULL) {
|
||||
printf("vtkWriter not initialize! Call vtkOpen first!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
writeHeaderPT(o, ts);
|
||||
|
||||
printf("Writing VTK output for %s\n", problem);
|
||||
}
|
||||
|
||||
void vtkParticle(VtkOptions* o, char* name)
|
||||
{
|
||||
Particle* particlePool = o->particletracer->particlePool;
|
||||
|
||||
if (o->fh == NULL) {
|
||||
printf("vtkWriter not initialize! Call vtkOpen first!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fprintf(o->fh, "POINTS %d float\n", o->particletracer->totalParticles);
|
||||
|
||||
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
|
||||
double x = particlePool[i].x;
|
||||
double y = particlePool[i].y;
|
||||
double z = particlePool[i].z;
|
||||
fprintf(o->fh, "%.2f %.2f %.2f\n", x, y, z);
|
||||
}
|
||||
|
||||
fprintf(o->fh,
|
||||
"CELLS %d %d\n",
|
||||
o->particletracer->totalParticles,
|
||||
2 * o->particletracer->totalParticles);
|
||||
|
||||
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
|
||||
fprintf(o->fh, "1 %d\n", i);
|
||||
}
|
||||
|
||||
fprintf(o->fh, "CELL_TYPES %d\n", o->particletracer->totalParticles);
|
||||
|
||||
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
|
||||
fprintf(o->fh, "1\n");
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file.
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef __VTKWRITER_H_
|
||||
#define __VTKWRITER_H_
|
||||
#include <stdio.h>
|
||||
#include "particletracing.h"
|
||||
|
||||
#include "grid.h"
|
||||
|
||||
typedef enum VtkFormat { ASCII = 0, BINARY } VtkFormat;
|
||||
@@ -16,7 +16,6 @@ typedef struct VtkOptions {
|
||||
VtkFormat fmt;
|
||||
Grid grid;
|
||||
FILE* fh;
|
||||
ParticleTracer* particletracer;
|
||||
} VtkOptions;
|
||||
|
||||
typedef struct VtkVector {
|
||||
@@ -27,7 +26,4 @@ extern void vtkOpen(VtkOptions* opts, char* filename);
|
||||
extern void vtkVector(VtkOptions* opts, char* name, VtkVector vec);
|
||||
extern void vtkScalar(VtkOptions* opts, char* name, double* p);
|
||||
extern void vtkClose(VtkOptions* opts);
|
||||
|
||||
extern void vtkOpenPT(VtkOptions* opts, char* filename, int ts);
|
||||
extern void vtkParticle(VtkOptions* opts, char* name);
|
||||
#endif // __VTKWRITER_H_
|
||||
|
Reference in New Issue
Block a user