Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use separate map functions for different bodies? #84

Closed
KunalGhoshGitHub opened this issue Dec 12, 2023 · 5 comments
Closed

How to use separate map functions for different bodies? #84

KunalGhoshGitHub opened this issue Dec 12, 2023 · 5 comments

Comments

@KunalGhoshGitHub
Copy link

Respected sir,

I am facing an issue while using this code. Actually, I want to use separate map functions for each of the separate bodies. Could you please help me with how to do it or refer me to any other resources for the same?

Thank you for your time and consideration.

Yours sincerely,
Kunal Ghosh

@weymouth
Copy link
Collaborator

What have you tried? You should be able to just define each body with is open map and then add them together...

@KunalGhoshGitHub
Copy link
Author

Firstly, thank you for your time.

Actually, I was experimenting with one of the examples given (TwoD_cylinderVIV.jl).

I tried to define two bars (sdf_1 and sdf_2) but I am unable to figure out how to give two separate map functions to them.

Here is the modified code:

required to keep things global

let
# parameters
amp=π/4
ϵ=0.5
thk=2ϵ+√2
Re = 250; U = 1
p = 5; L = 2^p
radius = L/2

T = 4*radius    # VIV period

# initial condition FSI
p0=radius/3; v0=0.1*L; a0=0; t0=0

# motion function uses global var to adjust
posx(t) = p0 + (t-t0)*v0

function sdf_1(x,t)
    √sum(abs2,(2*L >= x[1] .> L) ? ((1.0*x[2] - L)) : x ) - thk/2
end

function sdf_2(x,t)
    √sum(abs2,(2*L <= x[1] .< 3*L) ? (x[1] .- (2.0*x[2])) : x ) - thk/2
end

sdf_list = [sdf_1,sdf_2]

function map(x,t)
    α = amp*cos(t*U/L); R = SA[cos(α) sin(α); -sin(α) cos(α)]
    R * (x - SA[3L-L*sin(0*t*U/L),4L])
end

body = AutoBody(map) do x,t  # signed distance function
        minimum(sdf_list) do SDF
            SDF(x,t)
        end
    end

# generate sim
sim = Simulation((10L,10L), (U,0), radius; ν=U*radius/Re, body=body)

# get start time
duration=10; step=0.1; t₀=round(sim_time(sim))

@time @gif for tᵢ in range(t₀,t₀+duration;step)

    # update until time tᵢ in the background
    t = sum(sim.flow.Δt[1:end-1])
    while t < tᵢ*sim.L/sim.U

        # measure body
        measure!(sim,t)

        # update flow
        mom_step!(sim.flow,sim.pois)
        
        Δt = sim.flow.Δt[end]
        p0 += Δt*v0 
        t0 = t; t += Δt
    end

    # plot vorticity
    @inside sim.flow.σ[I] = WaterLily.curl(3,I,sim.flow.u)*sim.L/sim.U
    flood(sim.flow.σ; shift=(-0.5,-0.5),clims=(-5,5))
    body_plot!(sim); plot!(title="tU/L $tᵢ")
    
    # print time step
    println("tU/L=",round(tᵢ,digits=4),", Δt=",round(sim.flow.Δt[end],digits=3))
end

end

@weymouth
Copy link
Collaborator

That's not a good example for applying two simple mappings. Take a look at #35. You just need to do something like:

using WaterLily,StaticArrays
function two_circles(n,m;Re=250,U=1)
    body1 = AutoBody((x,t)->√(x'*x) - m/8, map=(x,t)->x .- m/3 - SA_F32[t,0])
    body2 = AutoBody((x,t)->√(x'*x) - m/6, map=(x,t)->x .- 2m/3 + SA_F32[t,0])
    Simulation((n,m), (U,0), radius; ν=U*radius/Re, body=body1+body2)
end

I've created two maps with two different SDFs and maps. Then the body is just the sum of the two.

@weymouth
Copy link
Collaborator

I assume you figured it out...

@KunalGhoshGitHub
Copy link
Author

Respected sir,

Yes, sir, I had figured it out. Thank you for the help.

Thank you for your time and consideration.

Yours sincerely,
Kunal Ghosh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants