\(\require{physics}\)

交換密度流

package.cpath = "../fantom_libraries/Release/?.dll;" .. package.cpath
require("fantom")
require("writer")
-- ### utility function
function string_vector(tbl)
  local tmp = fantom.VectorString()
  for i,v in ipairs(tbl) do tmp:push_back(v) end
  return tmp
end
-- basic parameters
case_nme               = "lock"
total_count            = 16001
save_interval          = 100
nx                     = 160
ny                     = 1
dx                     = 0.005
dy                     = 0.005
dt                     = 0.001
limit_depth            = 0.001
fantom.Parameter_THETA = 1.0
z_spacing              = 0.0025
-- z coordinate
dz = fantom.VectorDouble(44)
for i=0, dz:size()-1 do
  dz[i]=0.0025
end
-- creating geometry files
fg  = io.open("geom.txt", "w")
fxr = io.open("xrfm.txt", "w")
fyr = io.open("yrfm.txt", "w")
for i = 0, ny-1 do
  for i = 0, nx-2 do
	fg:write ("0.0\t")
	fxr:write("1\t")
	fyr:write("1\t")
  end
  fg:write ("0.0\n")
  fxr:write("1\n")
  fyr:write("1\n")
end
fg:close()
fxr:close()
fyr:close()
-- creating objects
water_body   = fantom.WaterBody(dx, dy, dz, "geom.txt", "xrfm.txt", "yrfm.txt", limit_depth)
surface      = fantom.SurfaceSolver()
nonhydro     = fantom.NonhydrostaticSolverSurface(1e-8, 2000)
m_advection  = fantom.UltimateQuickest(string_vector({"u", "w"}))
s_advection  = fantom.UltimateQuickestScalar(string_vector({"salinity"}))
baroclinic   = fantom.BaroclinicForce()
txt_writer   = writer.TextWriter(water_body, case_nme)
vtk_writer   = writer.VTKWriter(water_body,  case_nme)
-- variable setting
mean_level = 0.1
	water_body:set_uniform_surface_level(mean_level)
water_body:set_num_threads(4) 
water_body:set_var("u",            0.0)
water_body:set_var("v",            0.0)
water_body:set_var("w",            0.0)
water_body:set_var("temperature",  0.0)
water_body:set_var("salinity",     0.0)
-- initial salinity distribution
for i=0,water_body:box_columns():size()-1 do
  local x = water_body:box_columns()[i]:center().x
  if x < 0.4 then
	local column = water_body:box_columns()[i]
	for k=0, column:original_components():size()-1 do
	  column:set_var_mean_value(k, "salinity", 30.0)
	end
  end
end
-- time marching
for counter = 0, total_count do
  print("----- count = ", counter)
  water_body:construct_box_variables()
  if counter % save_interval == 0 then
	txt_writer:write(dt*counter, counter)
	vtk_writer:write(dt*counter, counter)
  end
  baroclinic :apply(water_body)
  m_advection:apply(water_body, dt)
  water_body :update_explicit_terms(dt)
  nonhydro   :apply(water_body, dt)
  surface    :apply(water_body, dt)
  nonhydro   :correction(water_body, dt)
  water_body :hydrostatic_continuity()
  s_advection:apply(water_body, dt)
  water_body :update_explicit_scalar_advection_terms(dt)  
  water_body :update_wet_components()
  water_body :hydrostatic_continuity()
  collectgarbage()
end