Skip to content
Snippets Groups Projects
sfx-esm.cpp 5.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • 数学の武士's avatar
    数学の武士 committed
    #include <iostream>
    
    数学の武士's avatar
    数学の武士 committed
    #include <cmath>
    
    数学の武士's avatar
    数学の武士 committed
    
    
    #include "sfx-esm.h"
    
    数学の武士's avatar
    数学の武士 committed
    #ifdef INCLUDE_CUDA
    
        #include "sfx-memory-processing.cuh"
    
    数学の武士's avatar
    数学の武士 committed
    #endif
    
    
    #include "sfx-memory-processing.h"
    #include "sfx-surface.cuh"
    #include "sfx-model-compute-subfunc.cuh"
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
    template<typename T, MemType memIn, MemType memOut >
    
    数学の武士's avatar
    数学の武士 committed
    void FluxEsm<T, memIn, memOut, MemType::CPU>::compute_flux(const sfx_esm_param_C model, 
                    const sfx_surface_param surface,
                    const sfx_esm_numericsType_C numerics,
                    const sfx_phys_constants phys)
    
    数学の武士's avatar
    数学の武士 committed
    {
    
    数学の武士's avatar
    数学の武士 committed
        T h, U, dT, Tsemi, dQ, z0_m;
        T Re, z0_t, B, h0_m, h0_t, u_dyn0, zeta, Rib, zeta_conv_lim, Rib_conv_lim, f_m_conv_lim, f_h_conv_lim, psi_m, psi_h, phi_m, phi_h, Km, Pr_t_inv, Cm, Ct;
        int surface_type;
        T fval;
    
        for (int step = 0; step < grid_size; step++)
    
    数学の武士's avatar
    数学の武士 committed
        {
    
    数学の武士's avatar
    数学の武士 committed
            U = meteo.U[step];
            Tsemi = meteo.Tsemi[step];
            dT = meteo.dT[step];
            dQ = meteo.dQ[step];
            h = meteo.h[step];
            z0_m = meteo.z0_m[step];
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            surface_type = z0_m < 0.0 ? surface.surface_ocean : surface.surface_land;
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            if (surface_type == surface.surface_ocean)
    
    数学の武士's avatar
    数学の武士 committed
            {
    
    数学の武士's avatar
    数学の武士 committed
                get_charnock_roughness(z0_m, u_dyn0, U, h, surface, numerics.maxiters_charnock);
    
    数学の武士's avatar
    数学の武士 committed
                h0_m = h / z0_m;
            }
    
    数学の武士's avatar
    数学の武士 committed
            if (surface_type == surface.surface_land) 
    
    数学の武士's avatar
    数学の武士 committed
            {
                h0_m = h / z0_m;
    
                u_dyn0 = U * model.kappa / logf(h0_m);
    
    数学の武士's avatar
    数学の武士 committed
            }
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            Re = u_dyn0 * z0_m / phys.nu_air;
            get_thermal_roughness(z0_t, B, z0_m, Re, surface, surface_type);
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            h0_t = h / z0_t;
    
    数学の武士's avatar
    数学の武士 committed
            Rib = (phys.g / Tsemi) * h * (dT + 0.61e0 * Tsemi * dQ) / (U*U);
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            get_convection_lim(zeta_conv_lim, Rib_conv_lim, f_m_conv_lim, f_h_conv_lim, 
                                h0_m, h0_t, B, 
    
    数学の武士's avatar
    数学の武士 committed
                                model);
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
    
            if (Rib > 0.0) 
            {
    
    数学の武士's avatar
    数学の武士 committed
                Rib = std::min(Rib, model.Rib_max);
                get_psi_stable(psi_m, psi_h, zeta, Rib, h0_m, h0_t, B, model);
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
                fval = model.beta_m * zeta;
    
    数学の武士's avatar
    数学の武士 committed
                phi_m = 1.0 + fval;
    
    数学の武士's avatar
    数学の武士 committed
                phi_h = 1.0/model.Pr_t_0_inv + fval;
    
    数学の武士's avatar
    数学の武士 committed
            }
            else if (Rib < Rib_conv_lim) 
            {
    
    数学の武士's avatar
    数学の武士 committed
                get_psi_convection(psi_m, psi_h, zeta, Rib, h0_m, h0_t, B, zeta_conv_lim, f_m_conv_lim, f_h_conv_lim, model, numerics.maxiters_convection);
    
    数学の武士's avatar
    数学の武士 committed
    
    
                fval = powf(zeta_conv_lim / zeta, 1.0/3.0);
    
    数学の武士's avatar
    数学の武士 committed
                phi_m = fval / f_m_conv_lim;
    
    数学の武士's avatar
    数学の武士 committed
                phi_h = fval / (model.Pr_t_0_inv * f_h_conv_lim);
    
    数学の武士's avatar
    数学の武士 committed
            }
            else if (Rib > -0.001) 
            {
    
    数学の武士's avatar
    数学の武士 committed
                get_psi_neutral(psi_m, psi_h, zeta, h0_m, h0_t, B, model);
    
    数学の武士's avatar
    数学の武士 committed
            
                phi_m = 1.0;
    
    数学の武士's avatar
    数学の武士 committed
                phi_h = 1.0 / model.Pr_t_0_inv;
    
    数学の武士's avatar
    数学の武士 committed
            }
            else
            {
    
    数学の武士's avatar
    数学の武士 committed
                get_psi_semi_convection(psi_m, psi_h, zeta, Rib, h0_m, h0_t, B, model, numerics.maxiters_convection);
    
    数学の武士's avatar
    数学の武士 committed
                
    
                phi_m = powf(1.0 - model.alpha_m * zeta, -0.25);
                phi_h = 1.0 / (model.Pr_t_0_inv * sqrtf(1.0 - model.alpha_h_fix * zeta));
    
    数学の武士's avatar
    数学の武士 committed
            Cm = model.kappa / psi_m;
            Ct = model.kappa / psi_h;
    
    数学の武士's avatar
    数学の武士 committed
    
    
    数学の武士's avatar
    数学の武士 committed
            Km = model.kappa * Cm * U * h / phi_m;
    
    数学の武士's avatar
    数学の武士 committed
            Pr_t_inv = phi_m / phi_h;
    
            sfx.zeta[step]         = zeta;
            sfx.Rib[step]          = Rib;
            sfx.Re[step]           = Re;
            sfx.B[step]            = B;
            sfx.z0_m[step]         = z0_m;
            sfx.z0_t[step]         = z0_t;
            sfx.Rib_conv_lim[step] = Rib_conv_lim;
            sfx.Cm[step]           = Cm;
            sfx.Ct[step]           = Ct;
            sfx.Km[step]           = Km;
            sfx.Pr_t_inv[step]     = Pr_t_inv;
        }
    
        if(MemType::CPU != memOut)
    
    数学の武士's avatar
    数学の武士 committed
        {
            const size_t new_size = grid_size * sizeof(T);
    
    数学の武士's avatar
    数学の武士 committed
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->zeta, (void*&)sfx.zeta, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Rib, (void*&)sfx.Rib, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Re, (void*&)sfx.Re, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->B, (void*&)sfx.B, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->z0_m, (void*&)sfx.z0_m, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->z0_t, (void*&)sfx.z0_t, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Rib_conv_lim, (void*&)sfx.Rib_conv_lim, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Cm, (void*&)sfx.Cm, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Ct, (void*&)sfx.Ct, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Km, (void*&)sfx.Km, new_size);
            memproc::memcopy<memOut, MemType::CPU>((void*&)res_sfx->Pr_t_inv, (void*&)sfx.Pr_t_inv, new_size);
    
    数学の武士's avatar
    数学の武士 committed
    template class FluxEsm<float, MemType::CPU, MemType::CPU, MemType::CPU>;
    
    数学の武士's avatar
    数学の武士 committed
    
    #ifdef INCLUDE_CUDA
    
    数学の武士's avatar
    数学の武士 committed
        template class FluxEsm<float, MemType::GPU, MemType::GPU, MemType::GPU>;
        template class FluxEsm<float, MemType::GPU, MemType::GPU, MemType::CPU>;
        template class FluxEsm<float, MemType::GPU, MemType::CPU, MemType::GPU>;
        template class FluxEsm<float, MemType::CPU, MemType::GPU, MemType::GPU>;
        template class FluxEsm<float, MemType::CPU, MemType::CPU, MemType::GPU>;
        template class FluxEsm<float, MemType::CPU, MemType::GPU, MemType::CPU>;
        template class FluxEsm<float, MemType::GPU, MemType::CPU, MemType::CPU>;
    
    数学の武士's avatar
    数学の武士 committed
    #endif