using Unitful
using GeometryBasics
using PeriodicTable
using PhysicalConstants.CODATA2018: g_n

struct Shell
inner
thickness
end

struct Object
shape
material
end

GeometryBasics.volume(s::Sphere) = (4/3)ฯ * s.r^3
GeometryBasics.volume(s::Shell) = volume(Sphere(p0, s.inner.r + s.thickness)) - volume(s.inner)
buoyancy(x::Object) = volume(x.shape) * x.material.density * g_n

p0 = Point(0.0u"m", 0.0u"m", 0.0u"m")
thickness = .0007u"inch"
fluid = elements["helium"]

balloon = Object(Shell(Sphere(p0, radius), thickness), substance)
interior = Object(balloon.shape.inner, fluid)
upreferred.([buoyancy(balloon), buoyancy(interior)])
julia> upreferred.([buoyancy(balloon), buoyancy(interior)])
2-element Array{Quantity{Float64,๐ ๐ ๐^-2,Unitful.FreeUnits{(kg, m, s^-2),๐ ๐ ๐^-2,nothing}},1}:
99.38920184883817 kg m s^-2
58692.24563097477 kg m s^-2

I thought these two numbers would be the net force on the balloon and the contents, respectively, and that they would be similar. What did I do wrong?

3 Likes

Area of the sphere is not proportional to radius cubed is it?

Thatโs a typo yeah, but actually Iโm not using that function. (Edited to delete it.)

Why did you think that they would be similar? The volume of the โballoonโ (i.e. the shell without its interior) could be much smaller than the volume of the interior of the inflated balloon. (A deflated balloon is usually much smaller than half the volume of an inflated balloon.)

You have defined buoyancy(x::Object) but the buoyancy does not only depend on the object, but also on the fluid that surrounds it. (Your function computes the weight.)

2 Likes