diff --git a/utilities/external_code_finalizer.f95 b/utilities/external_code_finalizer.f95 new file mode 100644 index 0000000..fb4d51e --- /dev/null +++ b/utilities/external_code_finalizer.f95 @@ -0,0 +1,61 @@ +subroutine external_code_finalizer +! +! Frees all the memory and terminates Amrex so there are no errors +! at the end of the program +! +! Called by: output_finalize +! Calls: +! External calls: amrex_multifab_destroy,amrex_imultifab_destroy, +! amrex_amrcore_finalize,amrex_finalize +! +use amrex_amr_module +use amrex_base_module +use mpi +use amr_info_holder +use constants +implicit none +integer :: level,ier + +! +! Destroy all the mutlifabs at every level +! +!do level = 0,amrex_max_level +! call amrex_multifab_destroy(mfrho(level)) +! call amrex_multifab_destroy(mfu_vel(level)) +! call amrex_multifab_destroy(mfv_vel(level)) +! call amrex_multifab_destroy(mftemp(level)) +! call amrex_multifab_destroy(mfpress(level)) +! +! call amrex_multifab_destroy(mfchi(level)) +! call amrex_multifab_destroy(mfzeta_x(level)) +! call amrex_multifab_destroy(mfzeta_y(level)) +! call amrex_multifab_destroy(mfpi_xx(level)) +! call amrex_multifab_destroy(mfpi_xy(level)) +! call amrex_multifab_destroy(mfpi_yy(level)) +! call amrex_multifab_destroy(mflambda_x(level)) +! call amrex_multifab_destroy(mflambda_y(level)) +! +! if (dimensions == 3) then +! call amrex_multifab_destroy(mfzeta_z(level) ) +! call amrex_multifab_destroy(mfpi_xz(level) ) +! call amrex_multifab_destroy(mfpi_yz(level) ) +! call amrex_multifab_destroy(mfpi_zz(level) ) +! call amrex_multifab_destroy(mflambda_z(level) ) +! call amrex_multifab_destroy(mfw_vel(level)) +! end if +! +! call amrex_multifab_destroy(mfalpha(level) ) +! call amrex_imultifab_destroy(mfstate(level) ) +! +! call amrex_multifab_destroy(mffi(level)) +! call amrex_multifab_destroy(mffout(level)) +! call amrex_multifab_destroy(mfgi(level)) +! call amrex_multifab_destroy(mfgout(level)) +!end do +! +! Terminate Amrex and MPI along with it. +! +call amrex_amrcore_finalize() +call amrex_finalize() +!call mpi_finalize(ier) +end subroutine diff --git a/utilities/external_code_starter.f90 b/utilities/external_code_starter.f90 new file mode 100644 index 0000000..7271720 --- /dev/null +++ b/utilities/external_code_starter.f90 @@ -0,0 +1,40 @@ +subroutine external_code_starter +! +! +! +! +! Called by: uclbs_main +! Calls: amr_transfer_data_to_amrex +! External calls: mpi_init,amrex_init +! +use mpi +!use cgns +use amrex_base_module +use amrex_amr_module +use amr_processes + +IMPLICIT NONE +integer :: ierr,mpi_ierr + +!call mpi_init( mpi_ierr ) +!if (mpi_ierr /= MPI_SUCCESS) then +! WRITE(*,*) ' Unexpected return from MPI_INIT', ierr +! call error_out +!endif +!write(*,*) 'huh?' +call amrex_init() +!write(*,*) 'bonk?' +call amrex_amrcore_init() +!write(*,*) 'wiggles' +call init_amrex() +call external_data_read + +!WRITE(*,*) 'Initializing from scratch' +CALL amrex_init_from_scratch(0.0D0) +!WRITE(*,*) 'Initialized' + +!call amr_transfer_data_to_amrex + +!call init_things + +end subroutine diff --git a/utilities/external_data_read.f95 b/utilities/external_data_read.f95 new file mode 100644 index 0000000..d578029 --- /dev/null +++ b/utilities/external_data_read.f95 @@ -0,0 +1,61 @@ +subroutine external_data_read +! +! Retrieves useful information that generally goes directly into +! Amrex. This puts it up at the module level to be used later. +! +! Called by: external_code_start +! Calls: +! External calls: amrex_parmparse_build,amrex_parmparse_destroy +! +use constants +use precise +use amrex_base_module +use amrex_amr_module +use amr_info_holder, only: plot_interval,regrid_interval,& + ref_rat,block_factor,max_grid,proper_shell,nodal_domain_limits,fixed_lvl +implicit none +integer :: lvl +type(amrex_parmparse) :: pp + +plot_interval = 400 +regrid_interval = 40 +ref_rat = 2 +block_factor = 8 +max_grid = 64 +!is_period = .false. +proper_shell = 2 +fixed_lvl = 0 + +!write(*,*) 'Reading data from command line inputs file.' + +call amrex_parmparse_build(pp,"amr") +call pp%query("regrid_int",regrid_interval) +call pp%query("plot_int",plot_interval) +call pp%query("ref_ratio",ref_rat) +call pp%query("blocking_factor",block_factor) +call pp%query("max_grid_size",max_grid) +call pp%query("n_proper",proper_shell) +call pp%query("use_fixed_upto_level",fixed_lvl) +call amrex_parmparse_destroy(pp) + +do lvl = 0,amrex_max_level + nodal_domain_limits(1,1,lvl) = 0 + nodal_domain_limits(2,1,lvl) = 0 + nodal_domain_limits(3,1,lvl) = 0 + + nodal_domain_limits(1,2,lvl) = amrex_geom(lvl)%domain%hi(1)+1 + nodal_domain_limits(2,2,lvl) = amrex_geom(lvl)%domain%hi(2)+1 + nodal_domain_limits(3,2,lvl) = amrex_geom(lvl)%domain%hi(3)+1 + + !write(*,*) 'nodal domain',nodal_domain_limits(1:3,1:2,lvl) +end do + + + +!call amrex_parmparse_build(pp,"geometry") +!call pp%query("is_periodic",is_period) +!call amrex_parmparse_build(pp) + +write(*,*) 'Command line input file read.' + +end subroutine diff --git a/utilities/modules/quick_calcs.f95 b/utilities/modules/quick_calcs.f95 new file mode 100644 index 0000000..a7c17fe --- /dev/null +++ b/utilities/modules/quick_calcs.f95 @@ -0,0 +1,223 @@ +module quick_calcs +! +! Putting these in an external procedure for error check and optional arguments +! to be able to work. +! +! +! +! +! +use precise +use constants +implicit none +save +private +public :: quick_sutherlands,quick_therm_cond + + + +contains +! +! +! +! +SUBROUTINE quick_sutherlands(loc_mu,loc_temp,inter_lvl,dim_mu,dim_temp) +! +! A quick Sutherland's Law calculation to find the viscosity at the local node +! +! +! Called by: collision +! Calls: +! +IMPLICIT NONE +REAL(kind=dp),INTENT(IN) :: loc_temp +REAL(kind=dp),INTENT(OUT) :: loc_mu +real(kind=dp),optional :: dim_mu,dim_temp +REAL(kind = dp),parameter :: const_s = 110.15,temp_ref = 273.15,visc_ref = 1.716D-5 +REAL(kind=dp) :: unit_mu,unit_temp +logical,optional :: inter_lvl + + + +unit_temp = loc_temp*t_ref*gama + +unit_mu = visc_ref*((unit_temp/temp_ref)**1.5)*((temp_ref+& + const_s)/(unit_temp+const_s)) + +if (present(inter_lvl)) then + if (inter_lvl) then + loc_mu = (unit_mu*2)/mu_ref + else + loc_mu = unit_mu/mu_ref + end if +else + loc_mu = unit_mu/mu_ref +end if + +if (present(dim_mu)) then + dim_mu = unit_mu +end if +if (present(dim_temp)) then + dim_temp = unit_temp +end if + +END SUBROUTINE +! +! +! +! +! +SUBROUTINE quick_therm_cond(loc_kappa,loc_rho,loc_temp,startup) +! +! This calculates the heat conductivity for a broad range of conditions +! +! +! Called by: collision,basic_fluids_calc +! Calls: error_out +! +IMPLICIT NONE +REAL(kind=dp),INTENT(IN) :: loc_rho,loc_temp +REAL(kind=dp),INTENT(OUT) :: loc_kappa +REAL(kind=dp) :: unit_temp,unit_kappa,unit_rho,unit_p +REAL(kind=dp) :: ak,bk,ck,dk,ek,kek,kappa_bottom +logical,optional :: startup +!INTEGER :: + +!mfp = +!c_bar = 3.0D0*kb*temper/molec_mass_air + +if (present(startup)) then + kappa_bottom = 1.0D0 +else + kappa_bottom = kappa_ref +end if + +unit_temp = loc_temp*t_ref*gama +unit_rho = loc_rho*rho_ref +unit_p = unit_temp*unit_rho*gas_const_R +!write(*,*) 'temps',unit_temp,loc_temp,t_ref,gama + +if (unit_temp <= 500.0D0) then + loc_kappa = kappa_convert*(5.9776D-6 * unit_temp**1.5 / (unit_temp +194.4))/kappa_bottom +else if (unit_temp > 500.0D0 .AND. unit_temp <= 2250.0D0) THEN + unit_rho = loc_rho*rho_ref + + unit_p = unit_rho*gas_const_R*unit_temp/101300.0D0 +! +! Set up the coefficients for the most likely band +! + if (unit_p < 10.0D0 .AND. unit_p > 0.1D0) THEN + ak = 0.334316D0 + bk = 3.28202D0 + ck = 11.9939D0 + dk = 20.0944D0 + ek = 4.62882D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 10.0D0 .AND. unit_p < 100.0D0) then + ak = 0.413573D0 + bk = 3.83393D0 + ck = 13.1885D0 + dk = 20.7305D0 + ek = 4.27728D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 100.0D0 .AND. unit_p < 1000.0D0) then + ak = 0.208749D0 + bk = 1.92122D0 + ck = 6.58813D0 + dk = 10.7630D0 + ek = -1.27699D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 0.10D0 .AND. unit_p < 0.010D0) then + ak = 1.05928D0 + bk = 10.0924D0 + ck = 35.6709D0 + dk = 56.1818D0 + ek = 24.9670D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else + WRITE(*,*) 'Parameters are way out of whack, something went wrong' + write(11,*) 'Parameters are way out of whack, something went wrong' + call error_out + end if +! +! Find the local value of kappa, the thermal conductivity +! + +else if (unit_temp > 2250.0D0 .AND. unit_temp <= 4250.0D0) THEN + + if (unit_p < 10.0D0 .AND. unit_p > 0.1D0) THEN + ak = 10.9992D0 + bk = 387.106D0 + ck = 387.282D0 + dk = 5.48304D0 + ek = -1.20106D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 10.0D0 .AND. unit_p < 100.0D0) then + ak = 82.1184D0 + bk = 308.927D0 + ck = 423.174D0 + dk = 250.668D0 + ek = 47.5889D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 100.0D0 .AND. unit_p < 1000.0D0) then + ak = 38.8677D0 + bk = 123.284D0 + ck = 144.224D0 + dk = 72.8083D0 + ek = 0.684807D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else if (unit_p > 0.10D0 .AND. unit_p < 0.010D0) then + ak = 101.351D0 + bk = 490.653D0 + ck = 868.620D0 + dk = 666.792D0 + ek = 180.596D0 + + kek = LOG(unit_temp/10000.0D0) + unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) + loc_kappa = unit_kappa/kappa_bottom + else + WRITE(*,*) 'Parameters are way out of whack, something went wrong' + write(11,*) 'Parameters are way out of whack, something went wrong' + call error_out + end if +! kek = LOG(unit_temp/10000.0D0) +! unit_kappa = EXP(ak*kek**4 + bk*kek**3 + ck*kek**2 + dk*kek +ek) +! loc_kappa = unit_kappa/kappa_ref +else + WRITE(*,*) 'Temperature diverging, exiting',loc_temp,unit_temp,loc_kappa,loc_rho + CALL error_out +end if + +!write(*,*) 'boing boing' + +END SUBROUTINE + + + + + + + +end module diff --git a/utilities/viscosity_and_timing.f95 b/utilities/viscosity_and_timing.f95 new file mode 100644 index 0000000..bb85913 --- /dev/null +++ b/utilities/viscosity_and_timing.f95 @@ -0,0 +1,127 @@ +SUBROUTINE viscosity_and_timing(characteristic_length) +! +! Basic Sutherland's Law calculations, implemented for air only +! at this point. Later it'll be for more +! +! Called by: background_calcs +! Calls: +! +!USE grid_data, only: rdx +USE freestream_values +USE constants +USE precise +use quick_calcs +USE timing +use amrex_base_module +use amrex_amr_module +!use amr_processes, only: beta_1_calculator,beta_2_calculator +!use amr_info_holder, only : dt,timestep,max_timesteps +IMPLICIT NONE +REAL(KIND=dp) :: sutherlands_const,beta_1_diff,beta_2_diff +REAL(KIND=dp) :: visc_ref,temp_ref +real(kind=dp) :: characteristic_velocity,kappa_base +REAL(KIND=dp) :: characteristic_length,beta_1,beta_2 +logical :: startup +!integer :: lvl + +!write(*,*) 'viscosity assignment' + +sutherlands_const = 110.4 +visc_ref = 1.716E-5 +temp_ref = 273.15 + +viscosity = visc_ref*((t_ref/temp_ref)**1.5)*((temp_ref+& + sutherlands_const)/(t_ref+sutherlands_const)) +nu = viscosity/rho_ref +!mu_ref = viscosity!rho_ref*speed_of_sound*default_char_leng +mu_ref = rho_ref*u_ref*mach*1!characteristic_length +!write(*,*) 'references for visc',mu_ref,viscosity,rho_ref,u_ref*mach,characteristic_length +!mu_inf = 1.0D0 + +characteristic_velocity = v_inf*u_ref +! +! Get the reference thermal conductivity +! +!kappa_ref = gas_const_R*viscosity +startup = .true. + +call quick_therm_cond(kappa_base,rho_inf,temperature,startup) +write(*,*) kappa_ref,rho_ref,gas_const_R,viscosity +!kappa_ref = rho_inf*gas_const_R*viscosity + +kappa_ref = rho_inf*speed_of_sound**3/temperature + +if (characteristic_velocity < 1.0D0) then + characteristic_time = 1.0D0 +else +! characteristic_time = characteristic_length/characteristic_velocity + characteristic_time = 1.0D0!/(characteristic_velocity)!speed_of_sound +end if + +init_beta_1 = 0.5001D0!exp(-mach/6.0D0)-0.01D0 +init_beta_2 = 0.5001D0!exp(-mach/6.0D0)-0.025D0 + +beta_1 = 1.0D0/((2.0D0*viscosity)/(rho_inf*temperature)+1.0D0) +beta_2 = 1.0D0/((2.0D0*kappa_base/kappa_ref)/(rho_inf*const_press*temperature)+1.0D0) + +beta_1_scaling = (beta_1 - init_beta_1)/real(startup_timesteps,kind=dp) +beta_2_scaling = (beta_2 - init_beta_2)/real(startup_timesteps,kind=dp) + +!write(*,*) +!write(*,*) 'beta values',init_beta_1,init_beta_2,beta_1,beta_2,beta_1_scaling,beta_2_scaling +!write(*,*) 'beta pre-calcs values',kappa_base,kappa_ref,viscosity,mu_ref,rho_ref,temperature +reynolds = rho_ref*u_ref*characteristic_length/mu_ref + +write(11,108) reynolds +write(11,109) viscosity +WRITE(11,111) characteristic_time +write(11,112) mu_ref +write(11,113) kappa_ref + + + 108 FORMAT ('Reynolds number = ',F17.4) +! 111 FORMAT ('Lattice Reynolds number = ',F13.4) + 109 FORMAT ('Viscosity = ',F13.11) + 110 FORMAT ('Kinematic Viscosity =', F15.11) + 111 format ('Characteristic time =',F9.7) + 112 format ('Refernce Viscosity, mu = ',F13.11) + 113 format ('Reference Thermal Conductivity, kappa = ',F13.11) + + +END SUBROUTINE + +!kappa_ref = 1.0D0 +!CALL quick_therm_cond(dummy_kappa,rho_inf,temperature) + +!WRITE(*,108) reynolds +!WRITE(*,111) lattice_reynolds +!WRITE(*,109) viscosity +!WRITE(*,110) nu + +!WRITE(11,301) tau +!WRITE(11,100) timestep +!write(11,305) + +! 200 FORMAT ('Value of tau is ', F9.6) +! 301 FORMAT ('Tau = ',F9.7) +! 305 format ('Total number of timesteps at finest level = ',I12) + +!do i = 1,amrex_max_level +! dt(i) = dt(i-1)/2.0D0 +!end do +!! tau = nu/(cs**2.0D0*dt) + 0.5D0 +! tau = nu*dt/(dx**2.0D0 * cs**2.0D0) +.5 +! +! IF (tau < 0.50001) THEN +! +! CALL tau_adjuster(nu) +! +! ELSE IF (tau > 20.0) THEN +! +! CALL tau_adjuster(nu) +! +! ELSE +! WRITE(11,200) tau +! END IF + +!max_ts = CEILING(total_time/dt(amrex_max_level))