WIP: Pull Request for a complete Solver package #1

Closed
AdityaUjeniya wants to merge 51 commits from (deleted):main into main
10 changed files with 3240 additions and 20132 deletions
Showing only changes of commit 413c0918c1 - Show all commits

View File

@ -42,13 +42,19 @@ $(BUILD_DIR)/%.s: %.c
clean:
$(info ===> CLEAN)
@rm -rf $(BUILD_DIR)
@rm -f particle*.dat
@rm -f vtk_files/particle*.vtk
@rm -f vis_files/particle*.dat
@rm -f tags
distclean: clean
$(info ===> DIST CLEAN)
@rm -f $(TARGET)
viz:
$(info ===> REMOVING VIZUALISATION FILES)
@rm -f vtk_files/particle*.vtk
@rm -f vis_files/particle*.dat
info:
$(info $(CFLAGS))
$(Q)$(CC) $(VERSION)

View File

@ -51,10 +51,10 @@ gamma 0.9 # upwind differencing factor gamma
numberOfParticles 30
startTime 0
injectTimePeriod 2.0
writeTimePeriod 2.0
writeTimePeriod 0.5
x1 0.1
y1 0.5
y1 0.9
x2 0.9
y2 0.5
y2 0.9
#===============================================================================

View File

File diff suppressed because it is too large Load Diff

View File

@ -116,10 +116,34 @@ void writeParticles(ParticleTracer* particletracer, Solver* solver)
VtkOptions opts = { .solver = solver, .particletracer = particletracer };
char filename[50];
snprintf(filename, 50, "vtk_files/particles_%d.vtk", ts++);
vtkOpen(&opts, filename);
snprintf(filename, 50, "vtk_files/particles%d.vtk", ts);
vtkOpen(&opts, filename, ts);
vtkParticle(&opts, "particle");
vtkClose(&opts);
FILE* fp;
Particle* particlePool = particletracer->particlePool;
snprintf(filename, 50, "vis_files/particles_%d.dat", ts);
fp = fopen(filename, "w");
if (fp == NULL) {
printf("Error!\n");
exit(EXIT_FAILURE);
}
for (int i = 0; i < particletracer->totalParticles; ++i)
{
if(particlePool[i].flag == true)
{
double x = particlePool[i].x;
double y = particlePool[i].y;
fprintf(fp, "%f %f\n", x, y);
}
}
fclose(fp);
++ts;
}
void initParticleTracer(ParticleTracer* particletracer, Parameter* params)

View File

@ -1,112 +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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vtkWriter.h"
static float floatSwap(float f)
{
union {
float f;
char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
static void writeHeader(VtkOptions* o)
{
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 STRUCTURED_POINTS\n");
fprintf(o->fh, "DIMENSIONS %d %d 0\n", o->solver->imax, o->solver->jmax);
fprintf(o->fh,
"ORIGIN %f %f 0.0\n",
o->solver->dx * 0.5,
o->solver->dy * 0.5);
fprintf(o->fh, "SPACING %f %f 0\n", o->solver->dx, o->solver->dy);
fprintf(o->fh, "POINT_DATA %d\n", o->particletracer->totalParticles);
}
void vtkOpen(VtkOptions* o, char* problem)
{
o->fh = fopen(problem, "w");
writeHeader(o);
printf("Writing VTK output for %s\n", problem);
}
void vtkParticle(VtkOptions* o, char* name)
{
Particle* particlePool = o->particletracer->particlePool;
int imax = o->solver->imax;
int jmax = o->solver->jmax;
if (o->fh == NULL) {
printf("vtkWriter not initialize! Call vtkOpen first!\n");
exit(EXIT_FAILURE);
}
fprintf(o->fh, "VECTORS %s float\n", name);
fprintf(o->fh, "LOOKUP_TABLE default\n");
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
if(particlePool[i].flag == true)
{
double x = particlePool[i].x;
double y = particlePool[i].y;
fprintf(o->fh, "%f %f 0.0\n", x, y);
}
}
/*
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) {
fprintf(o->fh,
"%f %f %f\n",
G(vec.u, i, j, k),
G(vec.v, i, j, k),
G(vec.w, i, j, k));
} else if (o->fmt == BINARY) {
fwrite((float[3]) { floatSwap(G(vec.u, i, j, k)),
floatSwap(G(vec.v, i, j, k)),
floatSwap(G(vec.w, i, j, k)) },
sizeof(float),
3,
o->fh);
}
}
}
}
if (o->fmt == BINARY) fprintf(o->fh, "\n");
*/
}
void vtkClose(VtkOptions* o)
{
fclose(o->fh);
o->fh = NULL;
}

View File

@ -20,7 +20,7 @@ typedef struct VtkOptions {
ParticleTracer* particletracer;
} VtkOptions;
extern void vtkOpen(VtkOptions* opts, char* filename);
extern void vtkOpen(VtkOptions* opts, char* filename, int ts);
extern void vtkParticle(VtkOptions* opts, char* name);
extern void vtkClose(VtkOptions* opts);
#endif // __VTKWRITER_H_

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
unset border; unset tics; unset key;
set term gif animate delay 50
set output "trace.gif"
set xrange [0:30]
set yrange [0:4]
do for [ts=0:48] {
set xrange [0:1]
set yrange [0:1]
do for [ts=0:198] {
plot "particles_".ts.".dat" with points pointtype 7
}
unset output