Skip to content

Commit 5959ebf

Browse files
Add files via upload
1 parent 232a7cf commit 5959ebf

File tree

2 files changed

+158
-158
lines changed

2 files changed

+158
-158
lines changed

uRayTracerDemo/uRays/Ray.cs

Lines changed: 157 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,157 @@
1-
using System;
2-
using System.Collections.Generic;
3-
4-
namespace uRayTracerDemo.uRays
5-
{
6-
public class Ray : IReadOnlyList<RayPoint>
7-
{
8-
#region Properties
9-
10-
List<RayPoint> rayPoints;
11-
12-
public double Theta0_rad { get; private set; }
13-
public double Theta_rad { get; private set; }
14-
public double Z0_m { get; private set; }
15-
public double Path_m { get; private set; }
16-
public double ZMax_m { get; private set; }
17-
18-
double prevTheta_deg_valid;
19-
20-
Func<double, double> getSoundSpeed;
21-
22-
public static double EtaSurface = 0.3;
23-
public static double EtaBottom = 0.1;
24-
25-
public double XMax_m
26-
{
27-
get
28-
{
29-
return rayPoints[rayPoints.Count - 1].X_m;
30-
}
31-
}
32-
33-
double cPrev;
34-
double c;
35-
36-
#endregion
37-
38-
#region Constructor
39-
40-
public Ray(double z0_m, double zMax_m, double theta0_deg, Func<double, double> soundSpeedVsZ)
41-
{
42-
if (soundSpeedVsZ == null)
43-
throw new ArgumentNullException("soundSpeedVsZ");
44-
45-
getSoundSpeed = soundSpeedVsZ;
46-
47-
Z0_m = z0_m;
48-
ZMax_m = zMax_m;
49-
Theta0_rad = theta0_deg * Math.PI / 180;
50-
51-
if ((Theta0_rad >= 0) && (Theta0_rad < 0.002))
52-
Theta0_rad = 0.002;
53-
else if ((Theta0_rad <= 0) && (Theta0_rad > -0.002))
54-
Theta0_rad = -0.002;
55-
56-
Theta_rad = Theta0_rad;
57-
prevTheta_deg_valid = Theta_rad;
58-
Path_m = 0;
59-
rayPoints = new List<RayPoint>();
60-
61-
cPrev = getSoundSpeed(z0_m);
62-
63-
rayPoints.Add(new RayPoint(0, Z0_m, 1));
64-
}
65-
66-
#endregion
67-
68-
#region Methods
69-
70-
public RayPoint Step(double dZ)
71-
{
72-
double z = rayPoints[rayPoints.Count - 1].Z_m;
73-
double x = rayPoints[rayPoints.Count - 1].X_m;
74-
double e = rayPoints[rayPoints.Count - 1].E;
75-
76-
double theta_sign = Theta_rad > 0 ? 1 : -1;
77-
z += (dZ * theta_sign);
78-
79-
if (z > ZMax_m)
80-
{
81-
if (z >= ZMax_m)
82-
{
83-
Theta_rad = -Theta_rad;
84-
theta_sign = -theta_sign;
85-
z = ZMax_m * 2 - z;
86-
e *= EtaBottom;
87-
// bottom reflection
88-
}
89-
}
90-
else
91-
{
92-
if (z <= 0)
93-
{
94-
Theta_rad = -Theta_rad;
95-
theta_sign = -theta_sign;
96-
z = -z;
97-
e *= EtaSurface;
98-
// surface reflection
99-
}
100-
}
101-
102-
double rsn = dZ / Math.Abs(Math.Sin(Theta_rad));
103-
double drn = Math.Sqrt(rsn * rsn - dZ * dZ);
104-
Path_m += rsn;
105-
x += drn;
106-
107-
c = getSoundSpeed(z);
108-
109-
double cosTheta = Math.Cos(Theta_rad);
110-
double recipSinTheta = 1.0 / Math.Sin(Theta_rad);
111-
double cncp = cosTheta * c / cPrev;
112-
113-
if ((Math.Abs(cncp) <= 1) && (!double.IsInfinity(recipSinTheta)))
114-
{
115-
prevTheta_deg_valid = Theta_rad;
116-
Theta_rad = theta_sign * Math.Acos(cncp);
117-
}
118-
else
119-
{
120-
Theta_rad = -prevTheta_deg_valid;
121-
}
122-
123-
cPrev = c;
124-
125-
RayPoint newPoint = new RayPoint(x, z, e);
126-
rayPoints.Add(newPoint);
127-
128-
return newPoint;
129-
}
130-
131-
#endregion
132-
133-
#region IReadOnlyList
134-
135-
public RayPoint this[int index]
136-
{
137-
get { return rayPoints[index]; }
138-
}
139-
140-
public int Count
141-
{
142-
get { return rayPoints.Count; }
143-
}
144-
145-
public IEnumerator<RayPoint> GetEnumerator()
146-
{
147-
return rayPoints.GetEnumerator();
148-
}
149-
150-
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
151-
{
152-
return rayPoints.GetEnumerator();
153-
}
154-
155-
#endregion
156-
}
157-
}
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace uRayTracerDemo.uRays
5+
{
6+
public class Ray : IReadOnlyList<RayPoint>
7+
{
8+
#region Properties
9+
10+
List<RayPoint> rayPoints;
11+
12+
public double Theta0_rad { get; private set; }
13+
public double Theta_rad { get; private set; }
14+
public double Z0_m { get; private set; }
15+
public double Path_m { get; private set; }
16+
public double ZMax_m { get; private set; }
17+
18+
double prevTheta_deg_valid;
19+
20+
Func<double, double> getSoundSpeed;
21+
22+
public static double EtaSurface = 0.3;
23+
public static double EtaBottom = 0.1;
24+
25+
public double XMax_m
26+
{
27+
get
28+
{
29+
return rayPoints[rayPoints.Count - 1].X_m;
30+
}
31+
}
32+
33+
double cPrev;
34+
double c;
35+
36+
#endregion
37+
38+
#region Constructor
39+
40+
public Ray(double z0_m, double zMax_m, double theta0_deg, Func<double, double> soundSpeedVsZ)
41+
{
42+
if (soundSpeedVsZ == null)
43+
throw new ArgumentNullException("soundSpeedVsZ");
44+
45+
getSoundSpeed = soundSpeedVsZ;
46+
47+
Z0_m = z0_m;
48+
ZMax_m = zMax_m;
49+
Theta0_rad = theta0_deg * Math.PI / 180;
50+
51+
if ((Theta0_rad >= 0) && (Theta0_rad < 0.002))
52+
Theta0_rad = 0.002;
53+
else if ((Theta0_rad <= 0) && (Theta0_rad > -0.002))
54+
Theta0_rad = -0.002;
55+
56+
Theta_rad = Theta0_rad;
57+
prevTheta_deg_valid = Theta_rad;
58+
Path_m = 0;
59+
rayPoints = new List<RayPoint>();
60+
61+
cPrev = getSoundSpeed(z0_m);
62+
63+
rayPoints.Add(new RayPoint(0, Z0_m, 1));
64+
}
65+
66+
#endregion
67+
68+
#region Methods
69+
70+
public RayPoint Step(double dZ)
71+
{
72+
double z = rayPoints[rayPoints.Count - 1].Z_m;
73+
double x = rayPoints[rayPoints.Count - 1].X_m;
74+
double e = rayPoints[rayPoints.Count - 1].E;
75+
76+
double theta_sign = Theta_rad > 0 ? 1 : -1;
77+
z += (dZ * theta_sign);
78+
79+
if (z > ZMax_m)
80+
{
81+
if (z >= ZMax_m)
82+
{
83+
Theta_rad = -Theta_rad;
84+
theta_sign = -theta_sign;
85+
z = ZMax_m * 2 - z;
86+
e *= EtaBottom;
87+
// bottom reflection
88+
}
89+
}
90+
else
91+
{
92+
if (z <= 0)
93+
{
94+
Theta_rad = -Theta_rad;
95+
theta_sign = -theta_sign;
96+
z = -z;
97+
e *= EtaSurface;
98+
// surface reflection
99+
}
100+
}
101+
102+
double rsn = dZ / Math.Abs(Math.Sin(Theta_rad));
103+
double drn = Math.Sqrt(rsn * rsn - dZ * dZ);
104+
Path_m += Math.Abs(rsn);
105+
x += drn;
106+
107+
c = getSoundSpeed(z);
108+
109+
double cosTheta = Math.Cos(Theta_rad);
110+
double recipSinTheta = 1.0 / Math.Sin(Theta_rad);
111+
double cncp = cosTheta * c / cPrev;
112+
113+
if ((Math.Abs(cncp) <= 1) && (!double.IsInfinity(recipSinTheta)))
114+
{
115+
prevTheta_deg_valid = Theta_rad;
116+
Theta_rad = theta_sign * Math.Acos(cncp);
117+
}
118+
else
119+
{
120+
Theta_rad = -prevTheta_deg_valid;
121+
}
122+
123+
cPrev = c;
124+
125+
RayPoint newPoint = new RayPoint(x, z, e);
126+
rayPoints.Add(newPoint);
127+
128+
return newPoint;
129+
}
130+
131+
#endregion
132+
133+
#region IReadOnlyList
134+
135+
public RayPoint this[int index]
136+
{
137+
get { return rayPoints[index]; }
138+
}
139+
140+
public int Count
141+
{
142+
get { return rayPoints.Count; }
143+
}
144+
145+
public IEnumerator<RayPoint> GetEnumerator()
146+
{
147+
return rayPoints.GetEnumerator();
148+
}
149+
150+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
151+
{
152+
return rayPoints.GetEnumerator();
153+
}
154+
155+
#endregion
156+
}
157+
}

uRayTracerDemo/uRays/Simulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private void BuildVSSP(TSProfilePoint[] tsProfile, double dZ)
116116
v = PHX.Speed_of_sound_UNESCO_calc(t, p, s);
117117
vssp.Add(new VSSPPoint(z, v));
118118

119-
z += dZ;
119+
z += 0.1;
120120
}
121121

122122
vssp_lookup = new Dictionary<double, double>();

0 commit comments

Comments
 (0)