forked from Lohittitas/concentricWave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetEtaNvz.c
103 lines (87 loc) · 2.34 KB
/
getEtaNvz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Title: Calculating the jet height and the tip velocity
# v2.0
# Last updated: Sep 26, 2024
# Authors: Vatsal Sanjay, Ayush Dixit, & Aman Bhargava
# Physics of Fluids
*/
#include "navier-stokes/centered.h"
#include "fractions.h"
#include "tag.h"
char filename[80], writefile[80];
scalar f[];
vector u;
double Ymax = 5e-2;
// Structure to hold the result of the tagging function
typedef struct {
int main_phase;
scalar d;
} TagResult;
// Function to tag connected regions and find the largest one
TagResult tag_largest_region(scalar field, double threshold) {
scalar d[];
foreach() {
d[] = (field[] > threshold);
}
int n = tag(d), size[n];
for (int i = 0; i < n; i++) {
size[i] = 0;
}
foreach_leaf() {
if (d[] > 0) {
size[((int) d[]) - 1]++;
}
}
int max_size = 0;
int main_phase = 0;
for (int i = 0; i < n; i++) {
if (size[i] > max_size) {
max_size = size[i];
main_phase = i + 1;
}
}
TagResult result = {main_phase, d};
return result;
}
int main(int argc, char const *argv[]) {
sprintf(filename, "%s", argv[1]);
sprintf(writefile, "%s", argv[2]);
restore(file = filename);
double threshold = 1e-4;
// Tag all liquid parts and find the largest connected region
TagResult liquid_result = tag_largest_region(f, threshold);
int main_phase_liquid = liquid_result.main_phase;
scalar d_liquid = liquid_result.d;
FILE *fp = fopen(writefile, "a");
if (t == 0) {
fprintf(fp, "t,r,eta,vz\n");
}
double Xeta = -HUGE;
double vz = 0;
double rTP = 0;
foreach_boundary(bottom) {
if (f[] > 1e-6 && f[] < 1. - 1e-6 && d_liquid[] == main_phase_liquid) {
// printf("%g %g %g %g\n", x, y, f[], u.x[]);
coord n = interface_normal(point, f);
double alpha = plane_alpha(f[], n);
coord segment[2];
if (facets(n, alpha, segment) == 2) {
double x0 = x + (segment[0].x + segment[1].x) * Delta / 2.;
double y0 = y + (segment[0].y + segment[1].y) * Delta / 2.;
if (y0 < Ymax && x0 > Xeta){
Xeta = x0;
rTP = y0;
vz = interpolate(u.x, x0, 0.0);
}
}
}
}
fprintf(fp, "%5.4f,%5.4e,%5.4e,%5.4e\n", t, rTP, Xeta, vz);
fflush(fp);
fclose(fp);
FILE *fp2 = ferr;
fprintf(fp2, "%5.4e,%5.4e,%5.4e\n", rTP, Xeta, vz);
fflush(fp2);
fclose(fp2);
dump(file="test");
}