@@ -4,7 +4,7 @@ using SolarPosition: Observer, SolarAlgorithm, RefractionAlgorithm, PSA, NoRefra
44using SolarPosition: SolPos, ApparentSolPos, SPASolPos, AbstractApparentSolPos
55using ModelingToolkit: @parameters , @variables , System
66using ModelingToolkit: t_nounits as t
7- using Dates: DateTime, Millisecond
7+ using Dates: Dates, DateTime, Millisecond
88import Symbolics
99
1010import SolarPosition: SolarPositionBlock, solar_position
@@ -23,28 +23,39 @@ get_zenith(pos::SolPos) = pos.zenith
2323get_elevation (pos:: AbstractApparentSolPos ) = pos. apparent_elevation
2424get_zenith (pos:: AbstractApparentSolPos ) = pos. apparent_zenith
2525
26- Symbolics. @register_symbolic seconds_to_datetime (t_sec, t0:: DateTime )
26+ Symbolics. @register_symbolic seconds_to_datetime (t_sec, t0:: DateTime ):: DateTime
2727Symbolics. @register_symbolic solar_position (
2828 observer:: Observer ,
2929 time:: DateTime ,
3030 algorithm:: SolarAlgorithm ,
3131 refraction:: RefractionAlgorithm ,
3232)
3333
34- Symbolics. @register_symbolic get_azimuth (pos)
35- Symbolics. @register_symbolic get_elevation (pos)
36- Symbolics. @register_symbolic get_zenith (pos)
34+ Symbolics. @register_symbolic get_azimuth (pos):: Real
35+ Symbolics. @register_symbolic get_elevation (pos):: Real
36+ Symbolics. @register_symbolic get_zenith (pos):: Real
3737
38- function SolarPositionBlock (; name)
39- @parameters t0:: DateTime [tunable = false ] observer:: Observer [tunable = false ]
40- @parameters algorithm:: SolarAlgorithm = PSA () [tunable = false ]
41- @parameters refraction:: RefractionAlgorithm = NoRefraction () [tunable = false ]
38+ function SolarPositionBlock (;
39+ name,
40+ t0 = Dates. now (),
41+ observer = Observer (0.0 , 0.0 , 0.0 ),
42+ algorithm = PSA (),
43+ refraction = NoRefraction (),
44+ )
45+ @parameters t0:: DateTime = t0 [tunable = false ]
46+ @parameters observer:: Observer = observer [tunable = false ]
47+ @parameters algorithm:: SolarAlgorithm = algorithm [tunable = false ]
48+ @parameters refraction:: RefractionAlgorithm = refraction [tunable = false ]
4249
4350 @variables azimuth (t) [output = true ]
4451 @variables elevation (t) [output = true ]
4552 @variables zenith (t) [output = true ]
4653
47- time_expr = Symbolics. term (seconds_to_datetime, t, t0; type = DateTime)
54+ # Ideally this should be expressed by a symbolic equation
55+ # but because it would involve some amount of type manipulation,
56+ # we can keep it this way for now.
57+ # But this might cause the position to be recalculated thrice (I think)
58+ time_expr = seconds_to_datetime (t, t0)
4859 pos = solar_position (observer, time_expr, algorithm, refraction)
4960
5061 eqs = [
@@ -53,7 +64,13 @@ function SolarPositionBlock(; name)
5364 zenith ~ get_zenith (pos),
5465 ]
5566
56- return System (eqs, t; name = name)
67+ return System (
68+ eqs,
69+ t,
70+ #= vars=# [azimuth, elevation, zenith],
71+ #= params=# [t0, observer, algorithm, refraction];
72+ name = name,
73+ )
5774end
5875
5976end # module SolarPositionModelingToolkitExt
0 commit comments