%bellowsFill is a function that returns the volume of the bellows for an
%inputted height. Input bellows height in meters

function vol = bellowsFill(h)
    %constants
    ro =5.91*.0254; %m
    ri = 4.72*.0254; %m;
    c=0.89*.0254;%m
    d = 0.08*.0254;%m
    xmax = (c-d)/2;
    vol = 0;
    %assume large diameter sections fill first
    if h < 4*d
        vol = vol+pi*ro^2*h;
    else

        vol=vol+4*d*pi*ro^2;
        %assume all 8 triangle sections fill from largest to smallest
        m = -(ro-ri)/xmax;
        b = ro;
        if h < ((4*d) + xmax*8)
            hLoc = (h-4*d)/8;
            vol = vol + 8*((pi*m^2*hLoc^3)/3 + (2*pi*m*b*hLoc^2)/2 + pi*b^2*hLoc);
        else
            vol = vol + 8*((pi*m^2*xmax^3)/3 + (2*pi*m*b*xmax^2)/2 + pi*b^2*xmax);
            %assume small diameter cylinders fill last
            hLoc = h-4*d-8*xmax;
            vol = vol+pi*ri^2*hLoc;
        end
    end
%     vol = vol*1000; %convert to L
end


