-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSPH_fieldize.cpp
More file actions
56 lines (52 loc) · 1.58 KB
/
SPH_fieldize.cpp
File metadata and controls
56 lines (52 loc) · 1.58 KB
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
#include <cmath>
#ifndef TOP_HAT_KERNEL
/*Compute the SPH weighting for this cell, using the trapezium rule.
* rr is the smoothing length, r0 is the distance of the cell from the center*/
double compute_sph_cell_weight(double rr, double r0)
{
if(r0 > rr){
return 0;
}
double total=0;
double h2 = rr*rr;
//Do the z integration with the trapezium rule.
//Evaluate this at some fixed (well-chosen) abcissae
double zc=0;
if(rr/2 > r0)
zc=sqrt(h2/4-r0*r0);
double zm = sqrt(h2-r0*r0);
double zz[5]={zc,(3*zc+zm)/4.,(zc+zm)/2.,(zc+3*zm)/2,zm};
double kern[5];
double kfac= 8/M_PI/pow(rr,3);
for(int i=0; i< 5;i++){
kern[i] = 2*pow(1-sqrt(zz[i]*zz[i]+r0*r0)/rr,3)*kfac;
}
for(int i=0; i< 4;i++){
//Trapezium rule. Factor of 1/2 goes away because we double the integral
total +=(zz[i+1]-zz[i])*(kern[i+1]+kern[i]);
}
if(rr/2 > r0){
double zz2[9]={0,zc/16.,zc/8.,zc/4.,3*zc/8,zc/2.,5/8.*zc,3*zc/4.,zc};
double kern2[9];
for(int i=0; i< 9;i++){
double r = sqrt(zz2[i]*zz2[i]+r0*r0);
kern2[i] = kfac*(1-6*(r/rr)*r/rr+6*pow(r/rr,3));
}
for(int i=0; i< 8;i++){
//trapezium rule. factor of 1/2 goes away because we double the integral
total +=(zz2[i+1]-zz2[i])*(kern2[i+1]+kern2[i]);
}
}
return total;
}
#else
double compute_sph_cell_weight(double rr, double r0)
{
if(r0 > rr){
return 0;
}
double kfac= 3./4./M_PI/pow(rr,3);
double total = kfac*2*sqrt(rr*rr-r0*r0);
return total;
}
#endif