From 6e8d69055040b280e7aa2ebf51cd6c10a3463041 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Thu, 4 Jul 2024 16:21:50 -0700 Subject: [PATCH 01/28] First working draft of simplified actuator disk --- Exec/SimpleActuatorDisk/CMakeLists.txt | 12 ++ Exec/SimpleActuatorDisk/GNUmakefile | 37 ++++ Exec/SimpleActuatorDisk/Make.package | 2 + Exec/SimpleActuatorDisk/README | 6 + Exec/SimpleActuatorDisk/inputs_1WT_lat_lon | 106 +++++++++++ Exec/SimpleActuatorDisk/inputs_1WT_x_y | 104 +++++++++++ .../inputs_WindFarm_lat_lon | 85 +++++++++ Exec/SimpleActuatorDisk/inputs_WindFarm_x_y | 83 +++++++++ Exec/SimpleActuatorDisk/plot_profiles.py | 70 ++++++++ Exec/SimpleActuatorDisk/prob.H | 79 +++++++++ Exec/SimpleActuatorDisk/prob.cpp | 167 ++++++++++++++++++ .../windturbines_loc_lat_lon_1WT.txt | 2 + .../windturbines_loc_lat_lon_WindFarm.txt | 97 ++++++++++ .../windturbines_loc_x_y_1WT.txt | 1 + .../windturbines_loc_x_y_WindFarm.txt | 96 ++++++++++ .../windturbines_spec_1WT.tbl | 6 + .../windturbines_spec_WindFarm.tbl | 24 +++ Source/DataStructs/DataStruct.H | 5 +- Source/ERF_make_new_arrays.cpp | 8 +- Source/Initialization/ERF_init_windfarm.cpp | 10 +- .../SimpleActuatorDisk/Advance_SimpleAD.cpp | 132 ++++++++++++++ .../SimpleActuatorDisk/Make.package | 2 + .../SimpleActuatorDisk/SimpleAD.H | 25 +++ Source/WindFarmParametrization/WindFarm.H | 1 + Source/WindFarmParametrization/WindFarm.cpp | 7 +- 25 files changed, 1158 insertions(+), 9 deletions(-) create mode 100644 Exec/SimpleActuatorDisk/CMakeLists.txt create mode 100644 Exec/SimpleActuatorDisk/GNUmakefile create mode 100644 Exec/SimpleActuatorDisk/Make.package create mode 100644 Exec/SimpleActuatorDisk/README create mode 100644 Exec/SimpleActuatorDisk/inputs_1WT_lat_lon create mode 100644 Exec/SimpleActuatorDisk/inputs_1WT_x_y create mode 100644 Exec/SimpleActuatorDisk/inputs_WindFarm_lat_lon create mode 100644 Exec/SimpleActuatorDisk/inputs_WindFarm_x_y create mode 100644 Exec/SimpleActuatorDisk/plot_profiles.py create mode 100644 Exec/SimpleActuatorDisk/prob.H create mode 100644 Exec/SimpleActuatorDisk/prob.cpp create mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_1WT.txt create mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt create mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt create mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt create mode 100644 Exec/SimpleActuatorDisk/windturbines_spec_1WT.tbl create mode 100644 Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl create mode 100644 Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp create mode 100644 Source/WindFarmParametrization/SimpleActuatorDisk/Make.package create mode 100644 Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H diff --git a/Exec/SimpleActuatorDisk/CMakeLists.txt b/Exec/SimpleActuatorDisk/CMakeLists.txt new file mode 100644 index 000000000..2e6da768c --- /dev/null +++ b/Exec/SimpleActuatorDisk/CMakeLists.txt @@ -0,0 +1,12 @@ +set(erf_exe_name erf_fitch) + +add_executable(${erf_exe_name} "") +target_sources(${erf_exe_name} + PRIVATE + prob.cpp +) + +target_include_directories(${erf_exe_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + +include(${CMAKE_SOURCE_DIR}/CMake/BuildERFExe.cmake) +build_erf_exe(${erf_exe_name}) diff --git a/Exec/SimpleActuatorDisk/GNUmakefile b/Exec/SimpleActuatorDisk/GNUmakefile new file mode 100644 index 000000000..53fdb7768 --- /dev/null +++ b/Exec/SimpleActuatorDisk/GNUmakefile @@ -0,0 +1,37 @@ +# AMReX +COMP = gnu +PRECISION = DOUBLE + +# Profiling +PROFILE = FALSE +TINY_PROFILE = TRUE +COMM_PROFILE = FALSE +TRACE_PROFILE = FALSE +MEM_PROFILE = FALSE +USE_GPROF = FALSE + +# Performance +USE_MPI = TRUE +USE_OMP = FALSE + +USE_CUDA = FALSE +USE_HIP = FALSE +USE_SYCL = FALSE + +# Debugging +DEBUG = FALSE + +TEST = TRUE +USE_ASSERTION = TRUE + +USE_WINDFARM = TRUE + + +#USE_POISSON_SOLVE = TRUE + +# GNU Make +Bpack := ./Make.package +Blocs := . +ERF_HOME := ../.. +ERF_PROBLEM_DIR = $(ERF_HOME)/Exec/SimpleActuatorDisk +include $(ERF_HOME)/Exec/Make.ERF diff --git a/Exec/SimpleActuatorDisk/Make.package b/Exec/SimpleActuatorDisk/Make.package new file mode 100644 index 000000000..aeacb72f0 --- /dev/null +++ b/Exec/SimpleActuatorDisk/Make.package @@ -0,0 +1,2 @@ +CEXE_headers += prob.H +CEXE_sources += prob.cpp diff --git a/Exec/SimpleActuatorDisk/README b/Exec/SimpleActuatorDisk/README new file mode 100644 index 000000000..2504f4de7 --- /dev/null +++ b/Exec/SimpleActuatorDisk/README @@ -0,0 +1,6 @@ +This problem setup is for simulation of the Atmospheric Boundary Layer (ABL) +using one of two turbulence schemes (Smagorinsky or Deardorff) and the bottom +boundary condition possibly specified by Monin Obukhov Similarity Theory (MOST). + +This version of the ABL problem initializes the data using a hydrostatic profile +with random perturbations in velocity and potential temperature. diff --git a/Exec/SimpleActuatorDisk/inputs_1WT_lat_lon b/Exec/SimpleActuatorDisk/inputs_1WT_lat_lon new file mode 100644 index 000000000..a5d799cfd --- /dev/null +++ b/Exec/SimpleActuatorDisk/inputs_1WT_lat_lon @@ -0,0 +1,106 @@ +# ------------------ INPUTS TO MAIN PROGRAM ------------------- +max_step = 3000 + +amrex.fpe_trap_invalid = 1 + +fabarray.mfiter_tile_size = 1024 1024 1024 + +# PROBLEM SIZE & GEOMETRY +geometry.prob_extent = 100000.0 100000.0 1000 +amr.n_cell = 50 50 80 + +# WINDFARM PARAMETRIZATION PARAMETERS +erf.windfarm_type = "SimpleActuatorDisk" +erf.windfarm_loc_type = "lat_lon" +erf.latitude_lo = 35.0 +erf.longitude_lo = -100.0 +erf.windfarm_loc_table = "windturbines_loc_lat_lon_1WT.txt" +erf.windfarm_spec_table = "windturbines_spec_1WT.tbl" + +#erf.grid_stretching_ratio = 1.025 +#erf.initial_dz = 16.0 + +geometry.is_periodic = 0 0 0 + +# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) +#zlo.type = "MOST" +#erf.most.z0 = 0.1 +#erf.most.zref = 8.0 + +zlo.type = "SlipWall" +zhi.type = "SlipWall" +xlo.type = "Inflow" +xhi.type = "Outflow" +ylo.type = "Outflow" +yhi.type = "Outflow" + +xlo.velocity = 10. 0. 0. +xlo.density = 1.226 +xlo.theta = 300. + +#erf.sponge_strength = 0.1 +#erf.use_xlo_sponge_damping = true +#erf.xlo_sponge_end = 10000.0 +#erf.use_xhi_sponge_damping = true +#erf.xhi_sponge_start = 90000.0 + +#erf.sponge_density = 1.226 +#erf.sponge_x_velocity = 10.0 +#erf.sponge_y_velocity = 0.0 +#erf.sponge_z_velocity = 0.0 + + +# TIME STEP CONTROL +erf.use_native_mri = 1 +erf.fixed_dt = 3.0 # fixed time step depending on grid resolution +#erf.fixed_fast_dt = 0.0025 + +# DIAGNOSTICS & VERBOSITY +erf.sum_interval = 1 # timesteps between computing mass +erf.v = 1 # verbosity in ERF.cpp +amr.v = 1 # verbosity in Amr.cpp + +# REFINEMENT / REGRIDDING +amr.max_level = 0 # maximum level number allowed + +# CHECKPOINT FILES +erf.check_file = chk # root name of checkpoint file +erf.check_int = 1000 # number of timesteps between checkpoints +#erf.restart = chk02000 + +# PLOTFILES +erf.plot_file_1 = plt # prefix of plotfile name +erf.plot_int_1 = 100 # number of timesteps between plotfiles +erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb vorticity + +# ADVECTION SCHEMES +erf.dycore_horiz_adv_type = "Centered_2nd" +erf.dycore_vert_adv_type = "Centered_2nd" +erf.dryscal_horiz_adv_type = "Centered_2nd" +erf.dryscal_vert_adv_type = "Centered_2nd" +erf.moistscal_horiz_adv_type = "Centered_2nd" +erf.moistscal_vert_adv_type = "Centered_2nd" + +# SOLVER CHOICE +erf.alpha_T = 0.0 +erf.alpha_C = 1.0 +erf.use_gravity = false + +erf.molec_diff_type = "ConstantAlpha" +erf.les_type = "None" +erf.Cs = 1.5 +erf.dynamicViscosity = 10.0 + +erf.pbl_type = "None" + +erf.init_type = "uniform" + + +# PROBLEM PARAMETERS +prob.rho_0 = 1.226 +prob.A_0 = 1.0 + +prob.U_0 = 10.0 +prob.V_0 = 0.0 +prob.W_0 = 0.0 +prob.T_0 = 300.0 diff --git a/Exec/SimpleActuatorDisk/inputs_1WT_x_y b/Exec/SimpleActuatorDisk/inputs_1WT_x_y new file mode 100644 index 000000000..dbfb2dda1 --- /dev/null +++ b/Exec/SimpleActuatorDisk/inputs_1WT_x_y @@ -0,0 +1,104 @@ +# ------------------ INPUTS TO MAIN PROGRAM ------------------- +max_step = 1000 + +amrex.fpe_trap_invalid = 1 + +fabarray.mfiter_tile_size = 1024 1024 1024 + +# PROBLEM SIZE & GEOMETRY +geometry.prob_extent = 1000.0 1000.0 500.0 +amr.n_cell = 100 100 50 + +# WINDFARM PARAMETRIZATION PARAMETERS +erf.windfarm_type = "SimpleActuatorDisk" +erf.windfarm_loc_type = "x_y" +erf.windfarm_loc_table = "windturbines_loc_x_y_1WT.txt" +erf.windfarm_spec_table = "windturbines_spec_1WT.tbl" + +#erf.grid_stretching_ratio = 1.025 +#erf.initial_dz = 16.0 + +geometry.is_periodic = 0 0 0 + +# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) +#zlo.type = "MOST" +#erf.most.z0 = 0.1 +#erf.most.zref = 8.0 + +zlo.type = "SlipWall" +zhi.type = "SlipWall" +xlo.type = "Inflow" +xhi.type = "Outflow" +ylo.type = "Outflow" +yhi.type = "Outflow" + +xlo.velocity = 10. 0. 0. +xlo.density = 1.226 +xlo.theta = 300. + +#erf.sponge_strength = 0.1 +#erf.use_xlo_sponge_damping = true +#erf.xlo_sponge_end = 10000.0 +#erf.use_xhi_sponge_damping = true +#erf.xhi_sponge_start = 90000.0 + +#erf.sponge_density = 1.226 +#erf.sponge_x_velocity = 10.0 +#erf.sponge_y_velocity = 0.0 +#erf.sponge_z_velocity = 0.0 + + +# TIME STEP CONTROL +erf.use_native_mri = 1 +erf.fixed_dt = 0.1 # fixed time step depending on grid resolution +#erf.fixed_fast_dt = 0.0025 + +# DIAGNOSTICS & VERBOSITY +erf.sum_interval = 1 # timesteps between computing mass +erf.v = 1 # verbosity in ERF.cpp +amr.v = 1 # verbosity in Amr.cpp + +# REFINEMENT / REGRIDDING +amr.max_level = 0 # maximum level number allowed + +# CHECKPOINT FILES +erf.check_file = chk # root name of checkpoint file +erf.check_int = 1000 # number of timesteps between checkpoints +#erf.restart = chk02000 + +# PLOTFILES +erf.plot_file_1 = plt # prefix of plotfile name +erf.plot_int_1 = 10 # number of timesteps between plotfiles +erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb vorticity + +# ADVECTION SCHEMES +erf.dycore_horiz_adv_type = "Centered_2nd" +erf.dycore_vert_adv_type = "Centered_2nd" +erf.dryscal_horiz_adv_type = "Centered_2nd" +erf.dryscal_vert_adv_type = "Centered_2nd" +erf.moistscal_horiz_adv_type = "Centered_2nd" +erf.moistscal_vert_adv_type = "Centered_2nd" + +# SOLVER CHOICE +erf.alpha_T = 0.0 +erf.alpha_C = 1.0 +erf.use_gravity = false + +erf.molec_diff_type = "ConstantAlpha" +erf.les_type = "None" +erf.Cs = 1.5 +erf.dynamicViscosity = 10.0 + +erf.pbl_type = "None" + +erf.init_type = "uniform" + + +# PROBLEM PARAMETERS +prob.rho_0 = 1.226 +prob.A_0 = 1.0 + +prob.U_0 = 10.0 +prob.V_0 = 0.0 +prob.W_0 = 0.0 +prob.T_0 = 300.0 diff --git a/Exec/SimpleActuatorDisk/inputs_WindFarm_lat_lon b/Exec/SimpleActuatorDisk/inputs_WindFarm_lat_lon new file mode 100644 index 000000000..e6ebae87b --- /dev/null +++ b/Exec/SimpleActuatorDisk/inputs_WindFarm_lat_lon @@ -0,0 +1,85 @@ +# ------------------ INPUTS TO MAIN PROGRAM ------------------- +max_step = 100000 + +amrex.fpe_trap_invalid = 1 + +fabarray.mfiter_tile_size = 1024 1024 1024 + +# PROBLEM SIZE & GEOMETRY +geometry.prob_extent = 200150 202637 1000 +amr.n_cell = 50 50 40 + +# WINDFARM PARAMETRIZATION PARAMETERS +erf.windfarm_type = "Fitch" +erf.windfarm_loc_type = "lat_lon" +erf.latitude_lo = 35.0 +erf.longitude_lo = -100.0 +erf.windfarm_loc_table = "windturbines_loc_lat_lon_WindFarm.txt" +erf.windfarm_spec_table = "windturbines_spec_WindFarm.tbl" + + +#erf.grid_stretching_ratio = 1.025 +#erf.initial_dz = 16.0 + +geometry.is_periodic = 0 0 0 + +# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) +#zlo.type = "MOST" +#erf.most.z0 = 0.1 +#erf.most.zref = 8.0 + +zlo.type = "SlipWall" +zhi.type = "SlipWall" +xlo.type = "Outflow" +xhi.type = "Outflow" +ylo.type = "Outflow" +yhi.type = "Outflow" + +# TIME STEP CONTROL +erf.use_native_mri = 1 +erf.fixed_dt = 0.25 # fixed time step depending on grid resolution +#erf.fixed_fast_dt = 0.0025 + +# DIAGNOSTICS & VERBOSITY +erf.sum_interval = 1 # timesteps between computing mass +erf.v = 1 # verbosity in ERF.cpp +amr.v = 1 # verbosity in Amr.cpp + +# REFINEMENT / REGRIDDING +amr.max_level = 0 # maximum level number allowed + +# CHECKPOINT FILES +erf.check_file = chk # root name of checkpoint file +erf.check_int = 10000 # number of timesteps between checkpoints +#erf.restart = chk02000 + +# PLOTFILES +erf.plot_file_1 = plt # prefix of plotfile name +erf.plot_int_1 = 1000 # number of timesteps between plotfiles +erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb vorticity + +# SOLVER CHOICE +erf.alpha_T = 0.0 +erf.alpha_C = 1.0 +erf.use_gravity = false + +erf.molec_diff_type = "ConstantAlpha" +erf.les_type = "None" +erf.Cs = 1.5 +erf.dynamicViscosity = 100.0 + +erf.pbl_type = "None" + +erf.init_type = "uniform" + +erf.windfarm_type = "EWP" + +# PROBLEM PARAMETERS +prob.rho_0 = 1.0 +prob.A_0 = 1.0 + +prob.U_0 = 10.0 +prob.V_0 = 10.0 +prob.W_0 = 0.0 +prob.T_0 = 300.0 + diff --git a/Exec/SimpleActuatorDisk/inputs_WindFarm_x_y b/Exec/SimpleActuatorDisk/inputs_WindFarm_x_y new file mode 100644 index 000000000..7fbed1830 --- /dev/null +++ b/Exec/SimpleActuatorDisk/inputs_WindFarm_x_y @@ -0,0 +1,83 @@ +# ------------------ INPUTS TO MAIN PROGRAM ------------------- +max_step = 100000 + +amrex.fpe_trap_invalid = 1 + +fabarray.mfiter_tile_size = 1024 1024 1024 + +# PROBLEM SIZE & GEOMETRY +geometry.prob_extent = 200150 202637 1000 +amr.n_cell = 50 50 40 + +# WINDFARM PARAMETRIZATION PARAMETERS +erf.windfarm_type = "Fitch" +erf.windfarm_loc_type = "x_y" +erf.windfarm_loc_table = "windturbines_loc_x_y_WindFarm.txt" +erf.windfarm_spec_table = "windturbines_spec_WindFarm.tbl" + + +#erf.grid_stretching_ratio = 1.025 +#erf.initial_dz = 16.0 + +geometry.is_periodic = 0 0 0 + +# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) +#zlo.type = "MOST" +#erf.most.z0 = 0.1 +#erf.most.zref = 8.0 + +zlo.type = "SlipWall" +zhi.type = "SlipWall" +xlo.type = "Outflow" +xhi.type = "Outflow" +ylo.type = "Outflow" +yhi.type = "Outflow" + +# TIME STEP CONTROL +erf.use_native_mri = 1 +erf.fixed_dt = 0.25 # fixed time step depending on grid resolution +#erf.fixed_fast_dt = 0.0025 + +# DIAGNOSTICS & VERBOSITY +erf.sum_interval = 1 # timesteps between computing mass +erf.v = 1 # verbosity in ERF.cpp +amr.v = 1 # verbosity in Amr.cpp + +# REFINEMENT / REGRIDDING +amr.max_level = 0 # maximum level number allowed + +# CHECKPOINT FILES +erf.check_file = chk # root name of checkpoint file +erf.check_int = 10000 # number of timesteps between checkpoints +#erf.restart = chk02000 + +# PLOTFILES +erf.plot_file_1 = plt # prefix of plotfile name +erf.plot_int_1 = 1000 # number of timesteps between plotfiles +erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb vorticity + +# SOLVER CHOICE +erf.alpha_T = 0.0 +erf.alpha_C = 1.0 +erf.use_gravity = false + +erf.molec_diff_type = "ConstantAlpha" +erf.les_type = "None" +erf.Cs = 1.5 +erf.dynamicViscosity = 100.0 + +erf.pbl_type = "None" + +erf.init_type = "uniform" + +erf.windfarm_type = "EWP" + +# PROBLEM PARAMETERS +prob.rho_0 = 1.0 +prob.A_0 = 1.0 + +prob.U_0 = 10.0 +prob.V_0 = 10.0 +prob.W_0 = 0.0 +prob.T_0 = 300.0 + diff --git a/Exec/SimpleActuatorDisk/plot_profiles.py b/Exec/SimpleActuatorDisk/plot_profiles.py new file mode 100644 index 000000000..50ab6f76c --- /dev/null +++ b/Exec/SimpleActuatorDisk/plot_profiles.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +import os +import glob +import numpy as np +import matplotlib.pyplot as plt +import yt + +pltfiles = [pltfile for pltfile in glob.glob('plt*') + if os.path.isdir(pltfile) and not ('old' in pltfile)] +nsteps = [int(pltfile[3:]) for pltfile in pltfiles] +latestoutput = pltfiles[np.argmax(nsteps)] +print(latestoutput) + +ds = yt.load(latestoutput) + +soln = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) +zp = np.linspace(ds.domain_left_edge[2], + ds.domain_right_edge[2], + ds.domain_dimensions[2]+1) +z = (zp[1:] + zp[:-1]).value / 2 + +utot = soln['x_velocity'].value +vtot = soln['y_velocity'].value +wtot = soln['z_velocity'].value + +U = np.mean(utot,axis=(0,1)) +V = np.mean(vtot,axis=(0,1)) +W = np.mean(wtot,axis=(0,1)) +u = utot - U[np.newaxis,np.newaxis,:] +v = vtot - V[np.newaxis,np.newaxis,:] +w = wtot - W[np.newaxis,np.newaxis,:] + +uu = np.var(u, axis=(0,1)) +vv = np.var(v, axis=(0,1)) +ww = np.var(w, axis=(0,1)) + +uw = np.mean(u*w, axis=(0,1)) +vw = np.mean(v*w, axis=(0,1)) +uv = np.mean(u*v, axis=(0,1)) + +fig,ax = plt.subplots(nrows=3,ncols=3,sharey=True,figsize=(8.5,11)) +ax[0,0].plot(U,z) +ax[0,1].plot(V,z) +ax[0,2].plot(W,z) +ax[0,0].set_xlabel(r'$\langle U \rangle$ [m/s]') +ax[0,1].set_xlabel(r'$\langle V \rangle$ [m/s]') +ax[0,2].set_xlabel(r'$\langle W \rangle$ [m/s]') +ax[1,0].plot(uu,z) +ax[1,1].plot(vv,z) +ax[1,2].plot(ww,z) +ax[1,0].set_xlabel(r"$\langle u'u' \rangle$ [m/s]") +ax[1,1].set_xlabel(r"$\langle v'v' \rangle$ [m/s]") +ax[1,2].set_xlabel(r"$\langle w'w' \rangle$ [m/s]") +ax[2,0].plot(uw,z) +ax[2,1].plot(vw,z) +ax[2,2].plot(uv,z) +ax[2,0].set_xlabel(r"$\langle u'w' \rangle$ [m/s]") +ax[2,1].set_xlabel(r"$\langle v'w' \rangle$ [m/s]") +ax[2,2].set_xlabel(r"$\langle u'v' \rangle$ [m/s]") +ax[0,0].set_ylabel('$z$ [m]') +ax[1,0].set_ylabel('$z$ [m]') +ax[2,0].set_ylabel('$z$ [m]') +ax[0,0].set_ylim((ds.domain_left_edge[2], ds.domain_right_edge[2])) +for axi in ax.ravel(): + axi.grid() + +fig.savefig('profiles.png',bbox_inches='tight') + +plt.show() + diff --git a/Exec/SimpleActuatorDisk/prob.H b/Exec/SimpleActuatorDisk/prob.H new file mode 100644 index 000000000..aa0c28435 --- /dev/null +++ b/Exec/SimpleActuatorDisk/prob.H @@ -0,0 +1,79 @@ +#ifndef _PROB_H_ +#define _PROB_H_ + +#include + +#include "AMReX_REAL.H" + +#include "prob_common.H" + +struct ProbParm : ProbParmDefaults { + amrex::Real rho_0 = 0.0; + amrex::Real T_0 = 0.0; + amrex::Real A_0 = 1.0; + amrex::Real QKE_0 = 0.1; + + amrex::Real U_0 = 0.0; + amrex::Real V_0 = 0.0; + amrex::Real W_0 = 0.0; + + // random initial perturbations (legacy code) + amrex::Real U_0_Pert_Mag = 0.0; + amrex::Real V_0_Pert_Mag = 0.0; + amrex::Real W_0_Pert_Mag = 0.0; + amrex::Real T_0_Pert_Mag = 0.0; // perturbation to rho*Theta + + // divergence-free initial perturbations + amrex::Real pert_deltaU = 0.0; + amrex::Real pert_deltaV = 0.0; + amrex::Real pert_periods_U = 5.0; + amrex::Real pert_periods_V = 5.0; + amrex::Real pert_ref_height = 100.0; + + // rayleigh damping + amrex::Real dampcoef = 0.2; // inverse time scale [1/s] + amrex::Real zdamp = 500.0; // damping depth [m] from model top + + // helper vars + amrex::Real aval; + amrex::Real bval; + amrex::Real ufac; + amrex::Real vfac; +}; // namespace ProbParm + +class Problem : public ProblemBase +{ +public: + Problem(const amrex::Real* problo, const amrex::Real* probhi); + +#include "Prob/init_constant_density_hse.H" +#include "Prob/init_rayleigh_damping.H" + + void init_custom_pert ( + const amrex::Box& bx, + const amrex::Box& xbx, + const amrex::Box& ybx, + const amrex::Box& zbx, + amrex::Array4 const& state, + amrex::Array4 const& state_pert, + amrex::Array4 const& x_vel_pert, + amrex::Array4 const& y_vel_pert, + amrex::Array4 const& z_vel_pert, + amrex::Array4 const& r_hse, + amrex::Array4 const& p_hse, + amrex::Array4 const& z_nd, + amrex::Array4 const& z_cc, + amrex::GeometryData const& geomdata, + amrex::Array4 const& mf_m, + amrex::Array4 const& mf_u, + amrex::Array4 const& mf_v, + const SolverChoice& sc) override; + +protected: + std::string name() override { return "ABL"; } + +private: + ProbParm parms; +}; + +#endif diff --git a/Exec/SimpleActuatorDisk/prob.cpp b/Exec/SimpleActuatorDisk/prob.cpp new file mode 100644 index 000000000..736211998 --- /dev/null +++ b/Exec/SimpleActuatorDisk/prob.cpp @@ -0,0 +1,167 @@ +#include "prob.H" +#include "AMReX_Random.H" + +using namespace amrex; + +std::unique_ptr +amrex_probinit(const amrex_real* problo, const amrex_real* probhi) +{ + return std::make_unique(problo, probhi); +} + +Problem::Problem(const amrex::Real* problo, const amrex::Real* probhi) +{ + // Parse params + ParmParse pp("prob"); + pp.query("rho_0", parms.rho_0); + pp.query("T_0", parms.T_0); + pp.query("A_0", parms.A_0); + pp.query("QKE_0", parms.QKE_0); + + pp.query("U_0", parms.U_0); + pp.query("V_0", parms.V_0); + pp.query("W_0", parms.W_0); + pp.query("U_0_Pert_Mag", parms.U_0_Pert_Mag); + pp.query("V_0_Pert_Mag", parms.V_0_Pert_Mag); + pp.query("W_0_Pert_Mag", parms.W_0_Pert_Mag); + pp.query("T_0_Pert_Mag", parms.T_0_Pert_Mag); + + pp.query("pert_deltaU", parms.pert_deltaU); + pp.query("pert_deltaV", parms.pert_deltaV); + pp.query("pert_periods_U", parms.pert_periods_U); + pp.query("pert_periods_V", parms.pert_periods_V); + pp.query("pert_ref_height", parms.pert_ref_height); + parms.aval = parms.pert_periods_U * 2.0 * PI / (probhi[1] - problo[1]); + parms.bval = parms.pert_periods_V * 2.0 * PI / (probhi[0] - problo[0]); + parms.ufac = parms.pert_deltaU * std::exp(0.5) / parms.pert_ref_height; + parms.vfac = parms.pert_deltaV * std::exp(0.5) / parms.pert_ref_height; + + pp.query("dampcoef", parms.dampcoef); + pp.query("zdamp", parms.zdamp); + + init_base_parms(parms.rho_0, parms.T_0); +} + +void +Problem::init_custom_pert( + const amrex::Box& bx, + const amrex::Box& xbx, + const amrex::Box& ybx, + const amrex::Box& zbx, + amrex::Array4 const& /*state*/, + amrex::Array4 const& state_pert, + amrex::Array4 const& x_vel_pert, + amrex::Array4 const& y_vel_pert, + amrex::Array4 const& z_vel_pert, + amrex::Array4 const& /*r_hse*/, + amrex::Array4 const& /*p_hse*/, + amrex::Array4 const& /*z_nd*/, + amrex::Array4 const& /*z_cc*/, + amrex::GeometryData const& geomdata, + amrex::Array4 const& /*mf_m*/, + amrex::Array4 const& /*mf_u*/, + amrex::Array4 const& /*mf_v*/, + const SolverChoice& sc) +{ + const bool use_moisture = (sc.moisture_type != MoistureType::None); + + ParallelForRNG(bx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { + // Geometry + const Real* prob_lo = geomdata.ProbLo(); + const Real* prob_hi = geomdata.ProbHi(); + const Real* dx = geomdata.CellSize(); + const Real x = prob_lo[0] + (i + 0.5) * dx[0]; + const Real y = prob_lo[1] + (j + 0.5) * dx[1]; + const Real z = prob_lo[2] + (k + 0.5) * dx[2]; + + // Define a point (xc,yc,zc) at the center of the domain + const Real xc = 0.5 * (prob_lo[0] + prob_hi[0]); + const Real yc = 0.5 * (prob_lo[1] + prob_hi[1]); + const Real zc = 0.5 * (prob_lo[2] + prob_hi[2]); + + const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc)); + + // Add temperature perturbations + if ((z <= parms.pert_ref_height) && (parms.T_0_Pert_Mag != 0.0)) { + Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 + state_pert(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag; + } + + // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain + state_pert(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r); + + // Set an initial value for QKE + state_pert(i, j, k, RhoQKE_comp) = parms.QKE_0; + + if (use_moisture) { + state_pert(i, j, k, RhoQ1_comp) = 0.0; + state_pert(i, j, k, RhoQ2_comp) = 0.0; + } + }); + + // Set the x-velocity + ParallelForRNG(xbx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { + const Real* prob_lo = geomdata.ProbLo(); + const Real* dx = geomdata.CellSize(); + const Real y = prob_lo[1] + (j + 0.5) * dx[1]; + const Real z = prob_lo[2] + (k + 0.5) * dx[2]; + + // Set the x-velocity + x_vel_pert(i, j, k) = parms.U_0; + if ((z <= parms.pert_ref_height) && (parms.U_0_Pert_Mag != 0.0)) + { + Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 + Real x_vel_prime = (rand_double*2.0 - 1.0)*parms.U_0_Pert_Mag; + x_vel_pert(i, j, k) += x_vel_prime; + } + if (parms.pert_deltaU != 0.0) + { + const amrex::Real yl = y - prob_lo[1]; + const amrex::Real zl = z / parms.pert_ref_height; + const amrex::Real damp = std::exp(-0.5 * zl * zl); + x_vel_pert(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl); + } + }); + + // Set the y-velocity + ParallelForRNG(ybx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { + const Real* prob_lo = geomdata.ProbLo(); + const Real* dx = geomdata.CellSize(); + const Real x = prob_lo[0] + (i + 0.5) * dx[0]; + const Real z = prob_lo[2] + (k + 0.5) * dx[2]; + + // Set the y-velocity + y_vel_pert(i, j, k) = parms.V_0; + if ((z <= parms.pert_ref_height) && (parms.V_0_Pert_Mag != 0.0)) + { + Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 + Real y_vel_prime = (rand_double*2.0 - 1.0)*parms.V_0_Pert_Mag; + y_vel_pert(i, j, k) += y_vel_prime; + } + if (parms.pert_deltaV != 0.0) + { + const amrex::Real xl = x - prob_lo[0]; + const amrex::Real zl = z / parms.pert_ref_height; + const amrex::Real damp = std::exp(-0.5 * zl * zl); + y_vel_pert(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl); + } + }); + + // Set the z-velocity + ParallelForRNG(zbx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { + const int dom_lo_z = geomdata.Domain().smallEnd()[2]; + const int dom_hi_z = geomdata.Domain().bigEnd()[2]; + + // Set the z-velocity + if (k == dom_lo_z || k == dom_hi_z+1) + { + z_vel_pert(i, j, k) = 0.0; + } + else if (parms.W_0_Pert_Mag != 0.0) + { + Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 + Real z_vel_prime = (rand_double*2.0 - 1.0)*parms.W_0_Pert_Mag; + z_vel_pert(i, j, k) = parms.W_0 + z_vel_prime; + } + }); +} diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_1WT.txt b/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_1WT.txt new file mode 100644 index 000000000..b78b36903 --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_1WT.txt @@ -0,0 +1,2 @@ +35.45 -99.5 1 + diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt b/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt new file mode 100644 index 000000000..4c68601f6 --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt @@ -0,0 +1,97 @@ +35.7828828829 -99.0168 1 +35.8219219219 -99.0168 1 +35.860960961 -99.0168 1 +35.9 -99.0168 1 +35.939039039 -99.0168 1 +35.9780780781 -99.0168 1 +36.0171171171 -99.0168 1 +35.7828828829 -98.9705333333 1 +35.8219219219 -98.9705333333 1 +35.860960961 -98.9705333333 1 +35.9 -98.9705333333 1 +35.939039039 -98.9705333333 1 +35.9780780781 -98.9705333333 1 +36.0171171171 -98.9705333333 1 +35.7828828829 -98.9242666667 1 +35.8219219219 -98.9242666667 1 +35.860960961 -98.9242666667 1 +35.9 -98.9242666667 1 +35.939039039 -98.9242666667 1 +35.9780780781 -98.9242666667 1 +36.0171171171 -98.9242666667 1 +35.7828828829 -98.878 1 +35.8219219219 -98.878 1 +35.860960961 -98.878 1 +35.9 -98.878 1 +35.939039039 -98.878 1 +35.9780780781 -98.878 1 +36.0171171171 -98.878 1 +35.7828828829 -98.8317333333 1 +35.8219219219 -98.8317333333 1 +35.860960961 -98.8317333333 1 +35.9 -98.8317333333 1 +35.939039039 -98.8317333333 1 +35.9780780781 -98.8317333333 1 +36.0171171171 -98.8317333333 1 +35.7828828829 -98.7854666667 1 +35.8219219219 -98.7854666667 1 +35.860960961 -98.7854666667 1 +35.9 -98.7854666667 1 +35.939039039 -98.7854666667 1 +35.9780780781 -98.7854666667 1 +36.0171171171 -98.7854666667 1 +35.7828828829 -98.7392 1 +35.8219219219 -98.7392 1 +35.860960961 -98.7392 1 +35.9 -98.7392 1 +35.939039039 -98.7392 1 +35.9780780781 -98.7392 1 +36.0171171171 -98.7392 1 +35.463963964 -98.2228 1 +35.487987988 -98.2228 1 +35.512012012 -98.2228 1 +35.536036036 -98.2228 1 +35.463963964 -98.1929333333 1 +35.487987988 -98.1929333333 1 +35.512012012 -98.1929333333 1 +35.536036036 -98.1929333333 1 +35.463963964 -98.1630666667 1 +35.487987988 -98.1630666667 1 +35.512012012 -98.1630666667 1 +35.536036036 -98.1630666667 1 +35.463963964 -98.1332 1 +35.487987988 -98.1332 1 +35.512012012 -98.1332 1 +35.536036036 -98.1332 1 +36.363963964 -99.4228 1 +36.387987988 -99.4228 1 +36.412012012 -99.4228 1 +36.436036036 -99.4228 1 +36.363963964 -99.3929333333 1 +36.387987988 -99.3929333333 1 +36.412012012 -99.3929333333 1 +36.436036036 -99.3929333333 1 +36.363963964 -99.3630666667 1 +36.387987988 -99.3630666667 1 +36.412012012 -99.3630666667 1 +36.436036036 -99.3630666667 1 +36.363963964 -99.3332 1 +36.387987988 -99.3332 1 +36.412012012 -99.3332 1 +36.436036036 -99.3332 1 +35.263963964 -99.5228 1 +35.287987988 -99.5228 1 +35.312012012 -99.5228 1 +35.336036036 -99.5228 1 +35.263963964 -99.4929333333 1 +35.287987988 -99.4929333333 1 +35.312012012 -99.4929333333 1 +35.336036036 -99.4929333333 1 +35.263963964 -99.4630666667 1 +35.287987988 -99.4630666667 1 +35.312012012 -99.4630666667 1 +35.336036036 -99.4630666667 1 +35.263963964 -99.4332 1 +35.287987988 -99.4332 1 +35.312012012 -99.4332 1 +35.336036036 -99.4332 1 diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt new file mode 100644 index 000000000..24c055514 --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt @@ -0,0 +1 @@ +500.0 500.0 diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt new file mode 100644 index 000000000..19fe95746 --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt @@ -0,0 +1,96 @@ +89264.99080053 91233.3333309002 +89259.1966417755 95566.6666710007 +89254.1277665419 99900.0000000001 +89249.7842982733 104233.333329 +89246.1663427532 108566.6666691 +89243.2739881117 112899.9999981 +93458.6633652711 86900.0000019001 +93450.4377452458 91233.3333309002 +93442.9032518779 95566.6666710007 +93436.0600522829 99900.0000000001 +93429.9082982192 104233.333329 +93424.4481261366 108566.6666691 +93419.6796571948 112899.9999981 +97646.3846285663 86900.0000019001 +97636.5111258549 91233.3333309002 +97627.2975408011 95566.6666710007 +97618.7440601867 99900.0000000001 +97610.850857392 104233.333329 +97603.6180924568 108566.6666691 +97597.045912112 112899.9999981 +101834.602975817 86900.0000019001 +101823.132838651 91233.3333309002 +101812.293876018 95566.6666710007 +101802.086289453 99900.0000000001 +101792.510268736 104233.333329 +101783.565991962 108566.6666691 +101775.253625592 112899.9999981 +106023.258628483 86900.0000019001 +106010.237048028 91233.3333309002 +105997.820076828 95566.6666710007 +105986.007927316 99900.0000000001 +105974.800801568 104233.333329 +105964.198891379 108566.6666691 +105954.202378331 112899.9999981 +110212.300853635 86900.0000019001 +110197.767881144 91233.3333309002 +110183.814885453 95566.6666710007 +110170.442086857 99900.0000000001 +110157.64969648 104233.333329 +110145.437916369 108566.6666691 +110133.806939566 112899.9999981 +114401.686336999 86900.0000019001 +114385.677633874 91233.3333309002 +114370.225998194 95566.6666710007 +114355.331655708 99900.0000000001 +114340.994824013 104233.333329 +114327.215712655 108566.6666691 +114313.994523223 112899.9999981 +161442.612044564 51500.0000039998 +161421.662101279 54166.666668 +161400.854802928 56833.3333320002 +161380.190204659 59499.9999960004 +164154.692973227 51500.0000039998 +164133.28852851 54166.666668 +164112.023937775 56833.3333320002 +164090.899255367 59499.9999960004 +166866.785694878 51500.0000039998 +166844.928396839 54166.666668 +166823.208245294 56833.3333320002 +166801.625293788 59499.9999960004 +169578.889421966 51500.0000039998 +169556.58083956 54166.666668 +169534.406775621 56833.3333320002 +169512.367282909 59499.9999960004 +52896.6844501924 151400.000004 +52915.9012759738 154066.666668 +52935.5802920911 156733.333332 +52955.7209832526 159399.999996 +55556.8294903758 151400.000004 +55574.333630956 154066.666668 +55592.2786959773 156733.333332 +55610.6642585664 159399.999996 +58220.3999614163 151400.000004 +58236.3087392296 154066.666668 +58252.6389095071 156733.333332 +58269.390117932 159399.999996 +60886.9461031228 151400.000004 +60901.3618319475 154066.666668 +60916.1809602466 156733.333332 +60931.4031936588 159399.999996 +43430.4219718844 29300.0000039997 +43430.6186514159 31966.666668 +43431.3883478816 34633.3333320001 +43432.7310308126 37299.9999960003 +46144.3886884569 29300.0000039997 +46143.7943466196 31966.666668 +46143.7390225352 34633.3333320001 +46144.2227181378 37299.9999960003 +48858.5817150023 29300.0000039997 +48857.2395489498 31966.666668 +48856.4061323542 34633.3333320001 +48856.0814912463 37299.9999960003 +51572.9651124459 29300.0000039997 +51570.9115091189 31966.666668 +51569.3395333094 34633.3333320001 +51568.2492290571 37299.9999960003 diff --git a/Exec/SimpleActuatorDisk/windturbines_spec_1WT.tbl b/Exec/SimpleActuatorDisk/windturbines_spec_1WT.tbl new file mode 100644 index 000000000..e1abbf4cf --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_spec_1WT.tbl @@ -0,0 +1,6 @@ +4 +119.0 178.0 0.130 2.0 +9 0.805 50.0 +10 0.805 50.0 +11 0.805 50.0 +12 0.805 50.0 diff --git a/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl b/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl new file mode 100644 index 000000000..6d678c3d1 --- /dev/null +++ b/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl @@ -0,0 +1,24 @@ +22 +75. 85. 0.130 2.0 +4. 0.805 50.0 +5. 0.805 150.0 +6. 0.805 280.0 +7. 0.805 460.0 +8. 0.805 700.0 +9. 0.805 990.0 +10. 0.790 1300.0 +11. 0.740 1600.0 +12. 0.700 1850.0 +13. 0.400 1950.0 +14. 0.300 1990.0 +15. 0.250 1995.0 +16. 0.200 2000.0 +17. 0.160 2000.0 +18. 0.140 2000.0 +19. 0.120 2000.0 +20. 0.100 2000.0 +21. 0.080 2000.0 +22. 0.070 2000.0 +23. 0.060 2000.0 +24. 0.055 2000.0 +25. 0.050 2000.0 diff --git a/Source/DataStructs/DataStruct.H b/Source/DataStructs/DataStruct.H index 44a027b15..bc234ed37 100644 --- a/Source/DataStructs/DataStruct.H +++ b/Source/DataStructs/DataStruct.H @@ -38,7 +38,7 @@ enum struct MoistureType { }; enum struct WindFarmType { - Fitch, EWP, None + Fitch, EWP, SimpleAD, None }; enum struct WindFarmLocType{ @@ -331,6 +331,9 @@ struct SolverChoice { else if (windfarm_type_string == "EWP") { windfarm_type = WindFarmType::EWP; } + else if (windfarm_type_string == "SimpleActuatorDisk") { + windfarm_type = WindFarmType::SimpleAD; + } else if (windfarm_type_string != "None") { amrex::Abort("Are you using windfarms? Dont know this windfarm_type. windfarm_type" " has to be Fitch or EWP or None."); diff --git a/Source/ERF_make_new_arrays.cpp b/Source/ERF_make_new_arrays.cpp index 710abb39e..5fef4d5de 100644 --- a/Source/ERF_make_new_arrays.cpp +++ b/Source/ERF_make_new_arrays.cpp @@ -237,11 +237,15 @@ ERF::init_stuff (int lev, const BoxArray& ba, const DistributionMapping& dm, //********************************************************* if (solverChoice.windfarm_type == WindFarmType::Fitch){ vars_windfarm[lev].define(ba, dm, 5, ngrow_state); // V, dVabsdt, dudt, dvdt, dTKEdt - Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell + Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell } if (solverChoice.windfarm_type == WindFarmType::EWP){ vars_windfarm[lev].define(ba, dm, 3, ngrow_state); // dudt, dvdt, dTKEdt - Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell + Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell + } + if (solverChoice.windfarm_type == WindFarmType::SimpleAD) { + vars_windfarm[lev].define(ba, dm, 2, ngrow_state);// dudt, dvdt + Nturb[lev].define(ba, dm, 1, ngrow_state); // Number of turbines in a cell } #endif diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index fdaf02765..80c4327d4 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -13,17 +13,16 @@ using namespace amrex; * * @param lev Integer specifying the current level */ +Vector xloc, yloc; void ERF::init_windfarm (int lev) { - Vector xloc, yloc; if(solverChoice.windfarm_loc_type == WindFarmLocType::lat_lon) { init_windfarm_lat_lon(lev, solverChoice.windfarm_loc_table, xloc, yloc); } else if(solverChoice.windfarm_loc_type == WindFarmLocType::x_y) { init_windfarm_x_y(lev, solverChoice.windfarm_loc_table, xloc, yloc); } - else { amrex::Abort("Are you using windfarms? For windfarm simulations, the inputs need to have an" " entry erf.windfarm_loc_table which should not be None. \n"); @@ -58,8 +57,11 @@ ERF::init_windfarm (int lev) int lj = amrex::min(amrex::max(j, j_lo), j_hi); auto dx = geom[lev].CellSizeArray(); - Real x1 = li*dx[0], x2 = (li+1)*dx[0]; - Real y1 = lj*dx[1], y2 = (lj+1)*dx[1]; + auto ProbLoArr = geom[lev].ProbLoArray(); + Real x1 = ProbLoArr[0] + li*dx[0]; + Real x2 = ProbLoArr[0] + (li+1)*dx[0]; + Real y1 = ProbLoArr[1] + lj*dx[1]; + Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; for(int it=0; it x1 and xloc[it]+1e-12 < x2 and diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp new file mode 100644 index 000000000..5a153e46d --- /dev/null +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include + +using namespace amrex; + +void simpleAD_advance (int lev, + const Geometry& geom, + const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, + MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) + { + simpleAD_source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); + simpleAD_update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); +} + + +void simpleAD_update (const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, + const MultiFab& mf_vars_simpleAD) +{ + + for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { + + Box bx = mfi.tilebox(); + Box tbx = mfi.nodaltilebox(0); + Box tby = mfi.nodaltilebox(1); + + auto cons_array = cons_in.array(mfi); + auto simpleAD_array = mf_vars_simpleAD.array(mfi); + auto u_vel = U_old.array(mfi); + auto v_vel = V_old.array(mfi); + + ParallelFor(tbx, tby, + [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept + { + u_vel(i,j,k) = u_vel(i,j,k) + (simpleAD_array(i-1,j,k,0) + simpleAD_array(i,j,k,0))/2.0*dt_advance; + }, + [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept + { + v_vel(i,j,k) = v_vel(i,j,k) + (simpleAD_array(i,j-1,k,1) + simpleAD_array(i,j,k,1))/2.0*dt_advance; + }); + } +} + +void simpleAD_source_terms_cellcentered (const Geometry& geom, + const MultiFab& cons_in, + const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, + MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) +{ + + auto dx = geom.CellSizeArray(); + auto ProbHiArr = geom.ProbHiArray(); + auto ProbLoArr = geom.ProbLoArray(); + Real d_rotor_rad = rotor_rad; + Real d_hub_height = hub_height; + Real sigma_0 = 1.7*rotor_rad; + + + // Domain valid box + const amrex::Box& domain = geom.Domain(); + int domlo_x = domain.smallEnd(0); + int domhi_x = domain.bigEnd(0) + 1; + int domlo_y = domain.smallEnd(1); + int domhi_y = domain.bigEnd(1) + 1; + int domlo_z = domain.smallEnd(2); + int domhi_z = domain.bigEnd(2) + 1; + + // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt + mf_vars_simpleAD.setVal(0.0); + + for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { + + const Box& bx = mfi.tilebox(); + const Box& gbx = mfi.growntilebox(1); + auto cons_array = cons_in.array(mfi); + auto simpleAD_array = mf_vars_simpleAD.array(mfi); + auto Nturb_array = mf_Nturb.array(mfi); + auto u_vel = U_old.array(mfi); + auto v_vel = V_old.array(mfi); + auto w_vel = W_old.array(mfi); + + amrex::IntVect lo = bx.smallEnd(); + + ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); + int jj = amrex::min(amrex::max(j, domlo_y), domhi_y); + int kk = amrex::min(amrex::max(k, domlo_z), domhi_z); + + Real x1 = ProbLoArr[0] + ii * dx[0]; + Real x2 = ProbLoArr[0] + (ii+1) * dx[0]; + Real y1 = ProbLoArr[1] + jj * dx[1]; + Real y2 = ProbLoArr[1] + (jj+1) * dx[1]; + + Real x = ProbLoArr[0] + (ii+0.5) * dx[0]; + Real y = ProbLoArr[1] + (jj+0.5) * dx[1]; + Real z = ProbLoArr[2] + (kk+0.5) * dx[2]; + + // Compute Simple AD source terms + + Real Vabs = std::pow(u_vel(i,j,k)*u_vel(i,j,k) + + v_vel(i,j,k)*v_vel(i,j,k) + + w_vel(i,j,kk)*w_vel(i,j,kk), 0.5); + + Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction + + + Real fac = 0.0; + int check_int = 0; + for(int it=0;it x1 and xloc[it]+1e-12 < x2) { + if(std::pow((y-yloc[it])*(y-yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { + check_int++; + fac = -2.0*std::pow(u_vel(i,j,k)*std::cos(phi) + v_vel(i,j,k)*std::sin(phi), 2.0)*0.5*(1.0-0.5); + //std::cout << "xcen, ycen, rad " << xcen[0] << " " << ycen[0] << " " << std::pow((x-xcen[0])*(x-xcen[0]) + (y-ycen[0])*(y-ycen[0]),0.5) << "\n"; + //exit(0); + } + } + } + if(check_int > 1){ + std::cout << "Some points are overlapping for two turbines...Exiting.." << "\n"; + exit(0); + } + + simpleAD_array(i,j,k,0) = fac*std::cos(phi); + simpleAD_array(i,j,k,1) = fac*std::sin(phi); + }); + } +} diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package b/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package new file mode 100644 index 000000000..192a21d28 --- /dev/null +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package @@ -0,0 +1,2 @@ +CEXE_sources += Advance_SimpleAD.cpp +CEXE_headers += SimpleAD.H diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H new file mode 100644 index 000000000..95cc5d4ca --- /dev/null +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -0,0 +1,25 @@ +#ifndef SimpleAD_H +#define SimpleAD_H + +#include +#include + +void simpleAD_advance (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + +void simpleAD_source_terms_cellcentered (const amrex::Geometry& geom, + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + +void simpleAD_update (const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp); + +#endif + diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index a0376ae52..203824b9b 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -7,6 +7,7 @@ extern amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; extern amrex::Vector wind_speed, thrust_coeff, power; +extern amrex::Vector xloc, yloc; void read_in_table(std::string windfarm_spec_table); diff --git a/Source/WindFarmParametrization/WindFarm.cpp b/Source/WindFarmParametrization/WindFarm.cpp index 3e54d02c3..90b1595b7 100644 --- a/Source/WindFarmParametrization/WindFarm.cpp +++ b/Source/WindFarmParametrization/WindFarm.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using namespace amrex; amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; @@ -8,7 +9,6 @@ amrex::Vector wind_speed, thrust_coeff, power; void read_in_table(std::string windfarm_spec_table) { - //The first line is the number of pairs entries for the power curve and thrust coefficient. //The second line gives first the height in meters of the turbine hub, second, the diameter in //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of @@ -63,7 +63,10 @@ void advance_windfarm (int lev, fitch_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } else if (solver_choice.windfarm_type == WindFarmType::EWP) { - ewp_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + ewp_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + mf_vars_windfarm, mf_Nturb); + } else if (solver_choice.windfarm_type == WindFarmType::SimpleAD) { + simpleAD_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } } From 3a11281c5fa1f2973df0595eb852218bc3c04642 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Thu, 4 Jul 2024 17:18:26 -0700 Subject: [PATCH 02/28] Correcting checkpoint write --- Exec/SimpleActuatorDisk/inputs_1WT_x_y | 2 +- Source/IO/Checkpoint.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Exec/SimpleActuatorDisk/inputs_1WT_x_y b/Exec/SimpleActuatorDisk/inputs_1WT_x_y index 751046004..71b7ca7d6 100644 --- a/Exec/SimpleActuatorDisk/inputs_1WT_x_y +++ b/Exec/SimpleActuatorDisk/inputs_1WT_x_y @@ -64,7 +64,7 @@ amr.max_level = 0 # maximum level number allowed # CHECKPOINT FILES erf.check_file = chk # root name of checkpoint file erf.check_int = 1000 # number of timesteps between checkpoints -#erf.restart = chk02000 +erf.restart = chk01000 # PLOTFILES erf.plot_file_1 = plt # prefix of plotfile name diff --git a/Source/IO/Checkpoint.cpp b/Source/IO/Checkpoint.cpp index ee4d22564..a95ed6d64 100644 --- a/Source/IO/Checkpoint.cpp +++ b/Source/IO/Checkpoint.cpp @@ -172,7 +172,9 @@ ERF::WriteCheckpointFile () const #if defined(ERF_USE_WINDFARM) - if(solverChoice.windfarm_type == WindFarmType::Fitch or solverChoice.windfarm_type == WindFarmType::EWP){ + if(solverChoice.windfarm_type == WindFarmType::Fitch or + solverChoice.windfarm_type == WindFarmType::EWP or + solverChoice.windfarm_type == WindFarmType::SimpleAD){ ng = Nturb[lev].nGrowVect(); MultiFab mf_Nturb(grids[lev],dmap[lev],1,ng); MultiFab::Copy(mf_Nturb,Nturb[lev],0,0,1,ng); @@ -424,7 +426,9 @@ ERF::ReadCheckpointFile () } #if defined(ERF_USE_WINDFARM) - if(solverChoice.windfarm_type == WindFarmType::Fitch or solverChoice.windfarm_type == WindFarmType::EWP){ + if(solverChoice.windfarm_type == WindFarmType::Fitch or + solverChoice.windfarm_type == WindFarmType::EWP or + solverChoice.windfarm_type == WindFarmType::SimpleAD){ ng = Nturb[lev].nGrowVect(); MultiFab mf_Nturb(grids[lev],dmap[lev],1,ng); VisMF::Read(mf_Nturb, amrex::MultiFabFileFullPrefix(lev, restart_chkfile, "Level_", "NumTurb")); From 0283354e134c7494704fa02d7f1b4299b79ec5cf Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Sun, 7 Jul 2024 12:43:32 -0700 Subject: [PATCH 03/28] Refactoring windfarm routines --- Exec/Make.ERF | 16 +- Exec/SimpleActuatorDisk/inputs_1WT_x_y | 4 +- Source/ERF.H | 19 +- Source/ERF.cpp | 2 +- Source/Initialization/ERF_init_windfarm.cpp | 193 +++------------ .../WindFarmParametrization/InitWindFarm.cpp | 219 ++++++++++++++++++ Source/WindFarmParametrization/Make.package | 1 + .../SimpleActuatorDisk/Advance_SimpleAD.cpp | 22 +- .../SimpleActuatorDisk/SimpleAD.H | 42 ++-- Source/WindFarmParametrization/WindFarm.H | 43 +++- Source/WindFarmParametrization/WindFarm.cpp | 33 +-- 11 files changed, 343 insertions(+), 251 deletions(-) create mode 100644 Source/WindFarmParametrization/InitWindFarm.cpp diff --git a/Exec/Make.ERF b/Exec/Make.ERF index b4d66617e..98e6811b3 100644 --- a/Exec/Make.ERF +++ b/Exec/Make.ERF @@ -142,19 +142,19 @@ INCLUDE_LOCATIONS += $(ERF_MOISTURE_KESSLER_DIR) ifeq ($(USE_WINDFARM), TRUE) DEFINES += -DERF_USE_WINDFARM ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization - ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch - ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP + #ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch + #ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP ERF_WINDFARM_SIMPLEAD_DIR = $(ERF_WINDFARM_DIR)/SimpleActuatorDisk include $(ERF_WINDFARM_DIR)/Make.package - include $(ERF_WINDFARM_FITCH_DIR)/Make.package - include $(ERF_WINDFARM_EWP_DIR)/Make.package + #include $(ERF_WINDFARM_FITCH_DIR)/Make.package + #include $(ERF_WINDFARM_EWP_DIR)/Make.package include $(ERF_WINDFARM_SIMPLEAD_DIR)/Make.package VPATH_LOCATIONS += $(ERF_WINDFARM_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) + #VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) + #INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) + #VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) + #INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) VPATH_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) endif diff --git a/Exec/SimpleActuatorDisk/inputs_1WT_x_y b/Exec/SimpleActuatorDisk/inputs_1WT_x_y index 71b7ca7d6..6a7986956 100644 --- a/Exec/SimpleActuatorDisk/inputs_1WT_x_y +++ b/Exec/SimpleActuatorDisk/inputs_1WT_x_y @@ -1,5 +1,5 @@ # ------------------ INPUTS TO MAIN PROGRAM ------------------- -max_step = 1000 +max_step = 2000 amrex.fpe_trap_invalid = 1 @@ -64,7 +64,7 @@ amr.max_level = 0 # maximum level number allowed # CHECKPOINT FILES erf.check_file = chk # root name of checkpoint file erf.check_int = 1000 # number of timesteps between checkpoints -erf.restart = chk01000 +#erf.restart = chk01000 # PLOTFILES erf.plot_file_1 = plt # prefix of plotfile name diff --git a/Source/ERF.H b/Source/ERF.H index 4ca77a03a..36cd4f61d 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -48,6 +48,10 @@ #include "LagrangianMicrophysics.H" #include "LandSurface.H" +#ifdef ERF_USE_WINDFARM +#include "SimpleAD.H" +#endif + #ifdef ERF_USE_RRTMGP #include "Radiation.H" #endif @@ -372,15 +376,24 @@ public: #endif // ERF_USE_NETCDF #ifdef ERF_USE_WINDFARM - void init_windfarm(int lev); - void init_windfarm_lat_lon(const int lev, + SimpleAD simpleAD; + template + void init_windfarm(int lev, T& windfarm); + void advance_windfarm (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb, + SolverChoice& solver_choice); + /*void init_windfarm_lat_lon(const int lev, const std::string windfarm_loc_table, amrex::Vector& xloc, amrex::Vector& yloc); void init_windfarm_x_y(const int lev, const std::string windfarm_loc_table, amrex::Vector& xloc, - amrex::Vector& yloc); + amrex::Vector& yloc);*/ #endif #ifdef ERF_USE_EB diff --git a/Source/ERF.cpp b/Source/ERF.cpp index fa9eb9ca3..7fedc2a2f 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -1210,7 +1210,7 @@ ERF::init_only (int lev, Real time) // Initialize wind farm #ifdef ERF_USE_WINDFARM - init_windfarm(lev); + init_windfarm(lev, simpleAD); #endif if(solverChoice.spongeChoice.sponge_type == "input_sponge"){ diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 21807145d..40ca27f2a 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -1,9 +1,7 @@ /** * \file ERF_init_windfarm.cpp */ - #include -#include using namespace amrex; @@ -13,176 +11,43 @@ using namespace amrex; * * @param lev Integer specifying the current level */ -Vector xloc, yloc; -void -ERF::init_windfarm (int lev) -{ - if(solverChoice.windfarm_loc_type == WindFarmLocType::lat_lon) { - init_windfarm_lat_lon(lev, solverChoice.windfarm_loc_table, xloc, yloc); - } - else if(solverChoice.windfarm_loc_type == WindFarmLocType::x_y) { - init_windfarm_x_y(lev, solverChoice.windfarm_loc_table, xloc, yloc); - } - else { - amrex::Abort("Are you using windfarms? For windfarm simulations, the inputs need to have an" - " entry erf.windfarm_loc_table which should not be None. \n"); - } - - // Write out a vtk file for turbine locations - if (ParallelDescriptor::IOProcessor()){ - FILE* file_turbloc_vtk; - file_turbloc_vtk = fopen("turbine_locations.vtk","w"); - fprintf(file_turbloc_vtk, "%s\n","# vtk DataFile Version 3.0"); - fprintf(file_turbloc_vtk, "%s\n","Wind turbine locations"); - fprintf(file_turbloc_vtk, "%s\n","ASCII"); - fprintf(file_turbloc_vtk, "%s\n","DATASET POLYDATA"); - fprintf(file_turbloc_vtk, "%s %ld %s\n", "POINTS", xloc.size(), "float"); - for(int it=0; it d_xloc(xloc.size()); - amrex::Gpu::DeviceVector d_yloc(yloc.size()); - amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); - amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); - - Real* d_xloc_ptr = d_xloc.data(); - Real* d_yloc_ptr = d_yloc.data(); - Nturb[lev].setVal(0); +// Explicit instantiation +template void ERF::init_windfarm(int lev, SimpleAD& simpleAD); - int i_lo = geom[lev].Domain().smallEnd(0); int i_hi = geom[lev].Domain().bigEnd(0); - int j_lo = geom[lev].Domain().smallEnd(1); int j_hi = geom[lev].Domain().bigEnd(1); - auto dx = geom[lev].CellSizeArray(); - int num_turb = xloc.size(); - - // Initialize wind farm - for ( MFIter mfi(Nturb[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto Nturb_array = Nturb[lev].array(mfi); - ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int li = amrex::min(amrex::max(i, i_lo), i_hi); - int lj = amrex::min(amrex::max(j, j_lo), j_hi); - - auto dx = geom[lev].CellSizeArray(); - auto ProbLoArr = geom[lev].ProbLoArray(); - Real x1 = ProbLoArr[0] + li*dx[0]; - Real x2 = ProbLoArr[0] + (li+1)*dx[0]; - Real y1 = ProbLoArr[1] + lj*dx[1]; - Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; - - for(int it=0; it x1 and d_xloc_ptr[it]+1e-12 < x2 and - d_yloc_ptr[it]+1e-12 > y1 and d_yloc_ptr[it]+1e-12 < y2){ - Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1; - } - } - }); - } - - read_in_table(solverChoice.windfarm_spec_table); -} - -void -ERF::init_windfarm_lat_lon (const int lev, - const std::string windfarm_loc_table, - Vector& xloc, - Vector& yloc) +template +void ERF::init_windfarm (int lev, T& windfarm) { - - if(solverChoice.latitude_lo == -1e10) { - amrex::Error("Are you using latitude-longitude for wind turbine locations? There needs to be" - " entry for erf.latitude_lo in the inputs for" - " the lower bottom corner of the domain"); - } - - if(solverChoice.longitude_lo == -1e10) { - amrex::Error("Are you using latitude-longitude for wind turbine locations? There needs to be" - " entry erf.longitude_lo in the inputs for" - " the lower bottom corner of the domain"); - } - - if(std::fabs(solverChoice.latitude_lo) > 90.0) { - amrex::Error("The value of erf.latitude_lo in the input file should be within -90 and 90"); - } - - if(std::fabs(solverChoice.longitude_lo) > 180.0) { - amrex::Error("The value of erf.longitude_lo in the input file should be within -180 and 180"); - } - - // Read turbine locations from windturbines.txt - std::ifstream file(windfarm_loc_table); - if (!file.is_open()) { - amrex::Error("Wind turbines location table not found. Either the inputs is missing the" - " erf.windfarm_loc_table entry or the file specified in the entry " + windfarm_loc_table + " is missing."); - } - // Vector of vectors to store the matrix - Vector lat, lon; - Real value1, value2, value3; - - while (file >> value1 >> value2 >> value3) { - - if(std::fabs(value1) > 90.0) { - amrex::Error("The value of latitude for entry " + std::to_string(lat.size() + 1) + - " in " + windfarm_loc_table + " should be within -90 and 90"); - } - - if(std::fabs(value2) > 180.0) { - amrex::Error("The value of longitude for entry " + std::to_string(lat.size() + 1) + - " in " + windfarm_loc_table + " should be within -180 and 180"); - } - - if(std::fabs(solverChoice.longitude_lo) > 180.0) { - amrex::Error("The values of erf.longitude_lo should be within -180 and 180"); - } - lat.push_back(value1); - lon.push_back(value2); - } - file.close(); - - Real rad_earth = 6371.0e3; // Radius of the earth - - Real lat_lo = solverChoice.latitude_lo*M_PI/180.0; - Real lon_lo = solverChoice.longitude_lo*M_PI/180.0; - - // (lat_lo, lon_lo) is mapped to (0,0) - - for(int it=0;it& xloc, - Vector& yloc) +ERF::advance_windfarm (int lev, + const Geometry& geom, + const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, + MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, + SolverChoice& solver_choice) { - // Read turbine locations from windturbines.txt - std::ifstream file(windfarm_loc_table); - if (!file.is_open()) { - amrex::Error("Wind turbines location table not found. Either the inputs is missing the" - " erf.windfarm_loc_table entry or the file specified in the entry " + windfarm_loc_table + " is missing."); - } - // Vector of vectors to store the matrix - Real value1, value2; - while (file >> value1 >> value2) { - xloc.push_back(value1); - yloc.push_back(value2); + if (solver_choice.windfarm_type == WindFarmType::Fitch) { + //fitch_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + // mf_vars_windfarm, mf_Nturb); + } else if (solver_choice.windfarm_type == WindFarmType::EWP) { + //ewp_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + // mf_vars_windfarm, mf_Nturb); + } else if (solver_choice.windfarm_type == WindFarmType::SimpleAD) { + simpleAD.simpleAD_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + mf_vars_windfarm, mf_Nturb); } - file.close(); } diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp new file mode 100644 index 000000000..92813be9b --- /dev/null +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -0,0 +1,219 @@ +/** + * \file ERF_init_windfarm.cpp + */ + +#include + +using namespace amrex; + +/** + * Read in the turbine locations in latitude-longitude from windturbines.txt + * and convert it into x and y coordinates in metres + * + * @param lev Integer specifying the current level + */ +void +WindFarm::init_windfarm (int lev, + std::string windfarm_loc_table, + std::string windfarm_spec_table, + const Geometry& geom, + Vector& Nturb, + bool x_y, bool lat_lon, + const Real latitude_lo, + const Real longitude_lo) +{ + if(x_y) { + init_windfarm_x_y(lev, windfarm_loc_table); + } + else if(lat_lon) { + init_windfarm_lat_lon(lev, windfarm_loc_table, latitude_lo, longitude_lo); + } + else { + amrex::Abort("Are you using windfarms? For windfarm simulations, the inputs need to have an" + " entry erf.windfarm_loc_table which should not be None. \n"); + } + + // Write out a vtk file for turbine locations + if (ParallelDescriptor::IOProcessor()){ + FILE* file_turbloc_vtk; + file_turbloc_vtk = fopen("turbine_locations.vtk","w"); + fprintf(file_turbloc_vtk, "%s\n","# vtk DataFile Version 3.0"); + fprintf(file_turbloc_vtk, "%s\n","Wind turbine locations"); + fprintf(file_turbloc_vtk, "%s\n","ASCII"); + fprintf(file_turbloc_vtk, "%s\n","DATASET POLYDATA"); + fprintf(file_turbloc_vtk, "%s %ld %s\n", "POINTS", xloc.size(), "float"); + for(int it=0; it(xloc.size()*(npts-1)*3)); + for(int it=0; it(2), + static_cast(it*npts+pt), + static_cast(it*npts+pt+1)); + } + } + fclose(file_actuator_disks); + } + + amrex::Gpu::DeviceVector d_xloc(xloc.size()); + amrex::Gpu::DeviceVector d_yloc(yloc.size()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); + amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); + + Real* d_xloc_ptr = d_xloc.data(); + Real* d_yloc_ptr = d_yloc.data(); + + Nturb[lev].setVal(0); + + int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0); + int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1); + auto dx = geom.CellSizeArray(); + int num_turb = xloc.size(); + + // Initialize wind farm + for ( MFIter mfi(Nturb[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { + const Box& bx = mfi.tilebox(); + auto Nturb_array = Nturb[lev].array(mfi); + ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + int li = amrex::min(amrex::max(i, i_lo), i_hi); + int lj = amrex::min(amrex::max(j, j_lo), j_hi); + + auto dx = geom.CellSizeArray(); + auto ProbLoArr = geom.ProbLoArray(); + Real x1 = ProbLoArr[0] + li*dx[0]; + Real x2 = ProbLoArr[0] + (li+1)*dx[0]; + Real y1 = ProbLoArr[1] + lj*dx[1]; + Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; + + for(int it=0; it x1 and d_xloc_ptr[it]+1e-12 < x2 and + d_yloc_ptr[it]+1e-12 > y1 and d_yloc_ptr[it]+1e-12 < y2){ + Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1; + } + } + }); + } + + read_in_table(windfarm_spec_table); +} + +void +WindFarm::init_windfarm_lat_lon (const int lev, + const std::string windfarm_loc_table, + const Real latitude_lo, const Real longitude_lo) +{ + + if(latitude_lo == -1e10) { + amrex::Error("Are you using latitude-longitude for wind turbine locations? There needs to be" + " entry for erf.latitude_lo in the inputs for" + " the lower bottom corner of the domain"); + } + + if(longitude_lo == -1e10) { + amrex::Error("Are you using latitude-longitude for wind turbine locations? There needs to be" + " entry erf.longitude_lo in the inputs for" + " the lower bottom corner of the domain"); + } + + if(std::fabs(latitude_lo) > 90.0) { + amrex::Error("The value of erf.latitude_lo in the input file should be within -90 and 90"); + } + + if(std::fabs(longitude_lo) > 180.0) { + amrex::Error("The value of erf.longitude_lo in the input file should be within -180 and 180"); + } + + // Read turbine locations from windturbines.txt + std::ifstream file(windfarm_loc_table); + if (!file.is_open()) { + amrex::Error("Wind turbines location table not found. Either the inputs is missing the" + " erf.windfarm_loc_table entry or the file specified in the entry " + windfarm_loc_table + " is missing."); + } + // Vector of vectors to store the matrix + Vector lat, lon; + Real value1, value2, value3; + + while (file >> value1 >> value2 >> value3) { + + if(std::fabs(value1) > 90.0) { + amrex::Error("The value of latitude for entry " + std::to_string(lat.size() + 1) + + " in " + windfarm_loc_table + " should be within -90 and 90"); + } + + if(std::fabs(value2) > 180.0) { + amrex::Error("The value of longitude for entry " + std::to_string(lat.size() + 1) + + " in " + windfarm_loc_table + " should be within -180 and 180"); + } + + if(std::fabs(longitude_lo) > 180.0) { + amrex::Error("The values of erf.longitude_lo should be within -180 and 180"); + } + lat.push_back(value1); + lon.push_back(value2); + } + file.close(); + + Real rad_earth = 6371.0e3; // Radius of the earth + + Real lat_lo = latitude_lo*M_PI/180.0; + Real lon_lo = longitude_lo*M_PI/180.0; + + // (lat_lo, lon_lo) is mapped to (0,0) + + for(int it=0;it> value1 >> value2) { + xloc.push_back(value1); + yloc.push_back(value2); + } + file.close(); +} diff --git a/Source/WindFarmParametrization/Make.package b/Source/WindFarmParametrization/Make.package index 1918ac501..ebc021d52 100644 --- a/Source/WindFarmParametrization/Make.package +++ b/Source/WindFarmParametrization/Make.package @@ -1,2 +1,3 @@ CEXE_sources += WindFarm.cpp CEXE_headers += WindFarm.H +CEXE_sources += InitWindFarm.cpp diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp index 5a153e46d..0c2e744fb 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp @@ -1,23 +1,20 @@ -#include -#include #include #include using namespace amrex; -void simpleAD_advance (int lev, +void SimpleAD::simpleAD_advance (int lev, const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) - { +{ simpleAD_source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); simpleAD_update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } - -void simpleAD_update (const Real& dt_advance, +void SimpleAD::simpleAD_update (const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, const MultiFab& mf_vars_simpleAD) @@ -46,7 +43,7 @@ void simpleAD_update (const Real& dt_advance, } } -void simpleAD_source_terms_cellcentered (const Geometry& geom, +void SimpleAD::simpleAD_source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) @@ -57,8 +54,6 @@ void simpleAD_source_terms_cellcentered (const Geometry& geom, auto ProbLoArr = geom.ProbLoArray(); Real d_rotor_rad = rotor_rad; Real d_hub_height = hub_height; - Real sigma_0 = 1.7*rotor_rad; - // Domain valid box const amrex::Box& domain = geom.Domain(); @@ -78,7 +73,6 @@ void simpleAD_source_terms_cellcentered (const Geometry& geom, const Box& gbx = mfi.growntilebox(1); auto cons_array = cons_in.array(mfi); auto simpleAD_array = mf_vars_simpleAD.array(mfi); - auto Nturb_array = mf_Nturb.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); auto w_vel = W_old.array(mfi); @@ -92,8 +86,6 @@ void simpleAD_source_terms_cellcentered (const Geometry& geom, Real x1 = ProbLoArr[0] + ii * dx[0]; Real x2 = ProbLoArr[0] + (ii+1) * dx[0]; - Real y1 = ProbLoArr[1] + jj * dx[1]; - Real y2 = ProbLoArr[1] + (jj+1) * dx[1]; Real x = ProbLoArr[0] + (ii+0.5) * dx[0]; Real y = ProbLoArr[1] + (jj+0.5) * dx[1]; @@ -115,14 +107,12 @@ void simpleAD_source_terms_cellcentered (const Geometry& geom, if(std::pow((y-yloc[it])*(y-yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { check_int++; fac = -2.0*std::pow(u_vel(i,j,k)*std::cos(phi) + v_vel(i,j,k)*std::sin(phi), 2.0)*0.5*(1.0-0.5); - //std::cout << "xcen, ycen, rad " << xcen[0] << " " << ycen[0] << " " << std::pow((x-xcen[0])*(x-xcen[0]) + (y-ycen[0])*(y-ycen[0]),0.5) << "\n"; - //exit(0); } } } if(check_int > 1){ - std::cout << "Some points are overlapping for two turbines...Exiting.." << "\n"; - exit(0); + amrex::Error("Actuator disks are overlapping. Visualize actuator_disks.vtk " + "and check the windturbine locations input file. Exiting.."); } simpleAD_array(i,j,k,0) = fac*std::cos(phi); diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 95cc5d4ca..b9949f68d 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -1,25 +1,31 @@ -#ifndef SimpleAD_H -#define SimpleAD_H +#ifndef SIMPLEAD_H +#define SIMPLEAD_H +#include "WindFarm.H" #include #include -void simpleAD_advance (int lev, - const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); - -void simpleAD_source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); - -void simpleAD_update (const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp); +class SimpleAD : public WindFarm { + +public: + + void simpleAD_advance (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + + void simpleAD_source_terms_cellcentered (const amrex::Geometry& geom, + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + + void simpleAD_update (const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp); +}; #endif diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 1f3b77f6d..57f1e5a83 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -6,19 +6,40 @@ #include #include -extern amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; -extern amrex::Vector wind_speed, thrust_coeff, power; -extern amrex::Vector xloc, yloc; -extern amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; +class WindFarm { -void read_in_table(std::string windfarm_spec_table); +public: -void advance_windfarm (int lev, + WindFarm(){} + + void init_windfarm(int lev, + std::string windfarm_loc_table, + std::string windfarm_spec_table, const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb, - SolverChoice& solver_choice); + amrex::Vector& Nturb, + bool x_y, bool lat_lon, + const amrex::Real latitude_lo=0.0, + const amrex::Real longitude_lo=0.0); + + void init_windfarm_lat_lon(const int lev, + const std::string windfarm_loc_table, + const amrex::Real latitude_lo, + const amrex::Real longitude_lo); + + void init_windfarm_x_y(const int lev, + const std::string windfarm_loc_table); + + void read_in_table(std::string windfarm_spec_table); + +protected: + + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + +}; + + #endif diff --git a/Source/WindFarmParametrization/WindFarm.cpp b/Source/WindFarmParametrization/WindFarm.cpp index 7523198fe..158eb271a 100644 --- a/Source/WindFarmParametrization/WindFarm.cpp +++ b/Source/WindFarmParametrization/WindFarm.cpp @@ -1,14 +1,12 @@ #include -#include -#include -#include using namespace amrex; -Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; -Vector wind_speed, thrust_coeff, power; -Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; +//Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; +//Vector wind_speed, thrust_coeff, power; +//Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; -void read_in_table(std::string windfarm_spec_table) +void +WindFarm::read_in_table(std::string windfarm_spec_table) { //The first line is the number of pairs entries for the power curve and thrust coefficient. //The second line gives first the height in meters of the turbine hub, second, the diameter in @@ -58,24 +56,3 @@ void read_in_table(std::string windfarm_spec_table) Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); } - - -void advance_windfarm (int lev, - const Geometry& geom, - const Real& dt_advance, - MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, - SolverChoice& solver_choice) -{ - if (solver_choice.windfarm_type == WindFarmType::Fitch) { - fitch_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); - } else if (solver_choice.windfarm_type == WindFarmType::EWP) { - ewp_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); - } else if (solver_choice.windfarm_type == WindFarmType::SimpleAD) { - simpleAD_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); - } -} From 682be3cbf383ced4574c1f3dbadc927d4c7d4ce5 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Sun, 7 Jul 2024 14:46:31 -0700 Subject: [PATCH 04/28] WIP:Refactoring for wind farm models --- .../windturbines_loc_lat_lon_WindFarm.txt | 97 ----------- .../windturbines_loc_x_y_1WT.txt | 3 +- .../windturbines_loc_x_y_WindFarm.txt | 96 ----------- .../windturbines_spec_WindFarm.tbl | 24 --- Source/Initialization/ERF_init_windfarm.cpp | 6 + .../WindFarmParametrization/InitWindFarm.cpp | 158 ++++++++++++------ Source/WindFarmParametrization/Make.package | 1 - Source/WindFarmParametrization/WindFarm.H | 7 +- Source/WindFarmParametrization/WindFarm.cpp | 58 ------- 9 files changed, 125 insertions(+), 325 deletions(-) delete mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt delete mode 100644 Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt delete mode 100644 Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl delete mode 100644 Source/WindFarmParametrization/WindFarm.cpp diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt b/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt deleted file mode 100644 index 4c68601f6..000000000 --- a/Exec/SimpleActuatorDisk/windturbines_loc_lat_lon_WindFarm.txt +++ /dev/null @@ -1,97 +0,0 @@ -35.7828828829 -99.0168 1 -35.8219219219 -99.0168 1 -35.860960961 -99.0168 1 -35.9 -99.0168 1 -35.939039039 -99.0168 1 -35.9780780781 -99.0168 1 -36.0171171171 -99.0168 1 -35.7828828829 -98.9705333333 1 -35.8219219219 -98.9705333333 1 -35.860960961 -98.9705333333 1 -35.9 -98.9705333333 1 -35.939039039 -98.9705333333 1 -35.9780780781 -98.9705333333 1 -36.0171171171 -98.9705333333 1 -35.7828828829 -98.9242666667 1 -35.8219219219 -98.9242666667 1 -35.860960961 -98.9242666667 1 -35.9 -98.9242666667 1 -35.939039039 -98.9242666667 1 -35.9780780781 -98.9242666667 1 -36.0171171171 -98.9242666667 1 -35.7828828829 -98.878 1 -35.8219219219 -98.878 1 -35.860960961 -98.878 1 -35.9 -98.878 1 -35.939039039 -98.878 1 -35.9780780781 -98.878 1 -36.0171171171 -98.878 1 -35.7828828829 -98.8317333333 1 -35.8219219219 -98.8317333333 1 -35.860960961 -98.8317333333 1 -35.9 -98.8317333333 1 -35.939039039 -98.8317333333 1 -35.9780780781 -98.8317333333 1 -36.0171171171 -98.8317333333 1 -35.7828828829 -98.7854666667 1 -35.8219219219 -98.7854666667 1 -35.860960961 -98.7854666667 1 -35.9 -98.7854666667 1 -35.939039039 -98.7854666667 1 -35.9780780781 -98.7854666667 1 -36.0171171171 -98.7854666667 1 -35.7828828829 -98.7392 1 -35.8219219219 -98.7392 1 -35.860960961 -98.7392 1 -35.9 -98.7392 1 -35.939039039 -98.7392 1 -35.9780780781 -98.7392 1 -36.0171171171 -98.7392 1 -35.463963964 -98.2228 1 -35.487987988 -98.2228 1 -35.512012012 -98.2228 1 -35.536036036 -98.2228 1 -35.463963964 -98.1929333333 1 -35.487987988 -98.1929333333 1 -35.512012012 -98.1929333333 1 -35.536036036 -98.1929333333 1 -35.463963964 -98.1630666667 1 -35.487987988 -98.1630666667 1 -35.512012012 -98.1630666667 1 -35.536036036 -98.1630666667 1 -35.463963964 -98.1332 1 -35.487987988 -98.1332 1 -35.512012012 -98.1332 1 -35.536036036 -98.1332 1 -36.363963964 -99.4228 1 -36.387987988 -99.4228 1 -36.412012012 -99.4228 1 -36.436036036 -99.4228 1 -36.363963964 -99.3929333333 1 -36.387987988 -99.3929333333 1 -36.412012012 -99.3929333333 1 -36.436036036 -99.3929333333 1 -36.363963964 -99.3630666667 1 -36.387987988 -99.3630666667 1 -36.412012012 -99.3630666667 1 -36.436036036 -99.3630666667 1 -36.363963964 -99.3332 1 -36.387987988 -99.3332 1 -36.412012012 -99.3332 1 -36.436036036 -99.3332 1 -35.263963964 -99.5228 1 -35.287987988 -99.5228 1 -35.312012012 -99.5228 1 -35.336036036 -99.5228 1 -35.263963964 -99.4929333333 1 -35.287987988 -99.4929333333 1 -35.312012012 -99.4929333333 1 -35.336036036 -99.4929333333 1 -35.263963964 -99.4630666667 1 -35.287987988 -99.4630666667 1 -35.312012012 -99.4630666667 1 -35.336036036 -99.4630666667 1 -35.263963964 -99.4332 1 -35.287987988 -99.4332 1 -35.312012012 -99.4332 1 -35.336036036 -99.4332 1 diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt index 24c055514..b552d30b0 100644 --- a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt +++ b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt @@ -1 +1,2 @@ -500.0 500.0 +300.0 300.0 +700.0 700.0 diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt deleted file mode 100644 index 19fe95746..000000000 --- a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_WindFarm.txt +++ /dev/null @@ -1,96 +0,0 @@ -89264.99080053 91233.3333309002 -89259.1966417755 95566.6666710007 -89254.1277665419 99900.0000000001 -89249.7842982733 104233.333329 -89246.1663427532 108566.6666691 -89243.2739881117 112899.9999981 -93458.6633652711 86900.0000019001 -93450.4377452458 91233.3333309002 -93442.9032518779 95566.6666710007 -93436.0600522829 99900.0000000001 -93429.9082982192 104233.333329 -93424.4481261366 108566.6666691 -93419.6796571948 112899.9999981 -97646.3846285663 86900.0000019001 -97636.5111258549 91233.3333309002 -97627.2975408011 95566.6666710007 -97618.7440601867 99900.0000000001 -97610.850857392 104233.333329 -97603.6180924568 108566.6666691 -97597.045912112 112899.9999981 -101834.602975817 86900.0000019001 -101823.132838651 91233.3333309002 -101812.293876018 95566.6666710007 -101802.086289453 99900.0000000001 -101792.510268736 104233.333329 -101783.565991962 108566.6666691 -101775.253625592 112899.9999981 -106023.258628483 86900.0000019001 -106010.237048028 91233.3333309002 -105997.820076828 95566.6666710007 -105986.007927316 99900.0000000001 -105974.800801568 104233.333329 -105964.198891379 108566.6666691 -105954.202378331 112899.9999981 -110212.300853635 86900.0000019001 -110197.767881144 91233.3333309002 -110183.814885453 95566.6666710007 -110170.442086857 99900.0000000001 -110157.64969648 104233.333329 -110145.437916369 108566.6666691 -110133.806939566 112899.9999981 -114401.686336999 86900.0000019001 -114385.677633874 91233.3333309002 -114370.225998194 95566.6666710007 -114355.331655708 99900.0000000001 -114340.994824013 104233.333329 -114327.215712655 108566.6666691 -114313.994523223 112899.9999981 -161442.612044564 51500.0000039998 -161421.662101279 54166.666668 -161400.854802928 56833.3333320002 -161380.190204659 59499.9999960004 -164154.692973227 51500.0000039998 -164133.28852851 54166.666668 -164112.023937775 56833.3333320002 -164090.899255367 59499.9999960004 -166866.785694878 51500.0000039998 -166844.928396839 54166.666668 -166823.208245294 56833.3333320002 -166801.625293788 59499.9999960004 -169578.889421966 51500.0000039998 -169556.58083956 54166.666668 -169534.406775621 56833.3333320002 -169512.367282909 59499.9999960004 -52896.6844501924 151400.000004 -52915.9012759738 154066.666668 -52935.5802920911 156733.333332 -52955.7209832526 159399.999996 -55556.8294903758 151400.000004 -55574.333630956 154066.666668 -55592.2786959773 156733.333332 -55610.6642585664 159399.999996 -58220.3999614163 151400.000004 -58236.3087392296 154066.666668 -58252.6389095071 156733.333332 -58269.390117932 159399.999996 -60886.9461031228 151400.000004 -60901.3618319475 154066.666668 -60916.1809602466 156733.333332 -60931.4031936588 159399.999996 -43430.4219718844 29300.0000039997 -43430.6186514159 31966.666668 -43431.3883478816 34633.3333320001 -43432.7310308126 37299.9999960003 -46144.3886884569 29300.0000039997 -46143.7943466196 31966.666668 -46143.7390225352 34633.3333320001 -46144.2227181378 37299.9999960003 -48858.5817150023 29300.0000039997 -48857.2395489498 31966.666668 -48856.4061323542 34633.3333320001 -48856.0814912463 37299.9999960003 -51572.9651124459 29300.0000039997 -51570.9115091189 31966.666668 -51569.3395333094 34633.3333320001 -51568.2492290571 37299.9999960003 diff --git a/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl b/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl deleted file mode 100644 index 6d678c3d1..000000000 --- a/Exec/SimpleActuatorDisk/windturbines_spec_WindFarm.tbl +++ /dev/null @@ -1,24 +0,0 @@ -22 -75. 85. 0.130 2.0 -4. 0.805 50.0 -5. 0.805 150.0 -6. 0.805 280.0 -7. 0.805 460.0 -8. 0.805 700.0 -9. 0.805 990.0 -10. 0.790 1300.0 -11. 0.740 1600.0 -12. 0.700 1850.0 -13. 0.400 1950.0 -14. 0.300 1990.0 -15. 0.250 1995.0 -16. 0.200 2000.0 -17. 0.160 2000.0 -18. 0.140 2000.0 -19. 0.120 2000.0 -20. 0.100 2000.0 -21. 0.080 2000.0 -22. 0.070 2000.0 -23. 0.060 2000.0 -24. 0.055 2000.0 -25. 0.050 2000.0 diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 40ca27f2a..0a7d2efca 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -28,6 +28,12 @@ void ERF::init_windfarm (int lev, T& windfarm) solverChoice.windfarm_spec_table, geom[lev], Nturb, true, false); } + + windfarm.write_turbine_locations_vtk(); + + if(solverChoice.windfarm_type == WindFarmType::SimpleAD) { + windfarm.write_actuator_disks_vtk(); + } } void diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index 92813be9b..41b78567e 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -22,6 +22,7 @@ WindFarm::init_windfarm (int lev, const Real latitude_lo, const Real longitude_lo) { + if(x_y) { init_windfarm_x_y(lev, windfarm_loc_table); } @@ -33,52 +34,8 @@ WindFarm::init_windfarm (int lev, " entry erf.windfarm_loc_table which should not be None. \n"); } - // Write out a vtk file for turbine locations - if (ParallelDescriptor::IOProcessor()){ - FILE* file_turbloc_vtk; - file_turbloc_vtk = fopen("turbine_locations.vtk","w"); - fprintf(file_turbloc_vtk, "%s\n","# vtk DataFile Version 3.0"); - fprintf(file_turbloc_vtk, "%s\n","Wind turbine locations"); - fprintf(file_turbloc_vtk, "%s\n","ASCII"); - fprintf(file_turbloc_vtk, "%s\n","DATASET POLYDATA"); - fprintf(file_turbloc_vtk, "%s %ld %s\n", "POINTS", xloc.size(), "float"); - for(int it=0; it(xloc.size()*(npts-1)*3)); - for(int it=0; it(2), - static_cast(it*npts+pt), - static_cast(it*npts+pt+1)); - } - } - fclose(file_actuator_disks); - } - - amrex::Gpu::DeviceVector d_xloc(xloc.size()); - amrex::Gpu::DeviceVector d_yloc(yloc.size()); + d_xloc.resize(xloc.size()); + d_yloc.resize(yloc.size()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); @@ -116,7 +73,7 @@ WindFarm::init_windfarm (int lev, }); } - read_in_table(windfarm_spec_table); + read_in_windfarm_spec_table(windfarm_spec_table); } void @@ -217,3 +174,110 @@ WindFarm::init_windfarm_x_y (const int lev, } file.close(); } + +void +WindFarm::write_turbine_locations_vtk() +{ + if (ParallelDescriptor::IOProcessor()){ + FILE* file_turbloc_vtk; + file_turbloc_vtk = fopen("turbine_locations.vtk","w"); + fprintf(file_turbloc_vtk, "%s\n","# vtk DataFile Version 3.0"); + fprintf(file_turbloc_vtk, "%s\n","Wind turbine locations"); + fprintf(file_turbloc_vtk, "%s\n","ASCII"); + fprintf(file_turbloc_vtk, "%s\n","DATASET POLYDATA"); + fprintf(file_turbloc_vtk, "%s %ld %s\n", "POINTS", xloc.size(), "float"); + for(int it=0; it(xloc.size()*(npts-1)*3)); + for(int it=0; it(2), + static_cast(it*npts+pt), + static_cast(it*npts+pt+1)); + } + } + fclose(file_actuator_disks); + } +} + +void +WindFarm::read_in_windfarm_spec_table(std::string windfarm_spec_table) +{ + //The first line is the number of pairs entries for the power curve and thrust coefficient. + //The second line gives first the height in meters of the turbine hub, second, the diameter in + //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of + //the turbine in MW. + //The remaining lines contain the three values of: wind speed, thrust coefficient, and power production in kW. + + // Read turbine data from wind-turbine-1.tbl + std::ifstream file_turb_table(windfarm_spec_table); + if (!file_turb_table.is_open()) { + Error("Wind farm specifications table not found. Either the inputs is missing the " + "erf.windfarm_spec_table entry or the file specified in the entry - " + windfarm_spec_table + " is missing."); + } + else { + Print() << "Reading in wind farm specifications table: " << windfarm_spec_table << "\n"; + } + + int nlines; + file_turb_table >> nlines; + wind_speed.resize(nlines); + thrust_coeff.resize(nlines); + power.resize(nlines); + + d_wind_speed.resize(nlines); + d_thrust_coeff.resize(nlines); + d_power.resize(nlines); + + Real rotor_dia; + file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power; + rotor_rad = rotor_dia*0.5; + if(rotor_rad > hub_height) { + Abort("The blade length is more than the hub height. Check the second line in wind-turbine-1.tbl. Aborting....."); + } + if(thrust_coeff_standing > 1.0) { + Abort("The standing thrust coefficient is greater than 1. Check the second line in wind-turbine-1.tbl. Aborting....."); + } + + for(int iline=0;iline> wind_speed[iline] >> thrust_coeff[iline] >> power[iline]; + if(thrust_coeff[iline] > 1.0) { + Abort("The thrust coefficient is greater than 1. Check wind-turbine-1.tbl. Aborting....."); + } + } + file_turb_table.close(); + + Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); + Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); + Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); +} + diff --git a/Source/WindFarmParametrization/Make.package b/Source/WindFarmParametrization/Make.package index ebc021d52..ebe5c58cb 100644 --- a/Source/WindFarmParametrization/Make.package +++ b/Source/WindFarmParametrization/Make.package @@ -1,3 +1,2 @@ -CEXE_sources += WindFarm.cpp CEXE_headers += WindFarm.H CEXE_sources += InitWindFarm.cpp diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 57f1e5a83..69ce7e877 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -29,7 +29,11 @@ public: void init_windfarm_x_y(const int lev, const std::string windfarm_loc_table); - void read_in_table(std::string windfarm_spec_table); + void read_in_windfarm_spec_table(std::string windfarm_spec_table); + + void write_turbine_locations_vtk(); + + void write_actuator_disks_vtk(); protected: @@ -37,6 +41,7 @@ protected: amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; amrex::Vector wind_speed, thrust_coeff, power; amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; }; diff --git a/Source/WindFarmParametrization/WindFarm.cpp b/Source/WindFarmParametrization/WindFarm.cpp deleted file mode 100644 index 158eb271a..000000000 --- a/Source/WindFarmParametrization/WindFarm.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -using namespace amrex; - -//Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; -//Vector wind_speed, thrust_coeff, power; -//Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - -void -WindFarm::read_in_table(std::string windfarm_spec_table) -{ - //The first line is the number of pairs entries for the power curve and thrust coefficient. - //The second line gives first the height in meters of the turbine hub, second, the diameter in - //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of - //the turbine in MW. - //The remaining lines contain the three values of: wind speed, thrust coefficient, and power production in kW. - - // Read turbine data from wind-turbine-1.tbl - std::ifstream file_turb_table(windfarm_spec_table); - if (!file_turb_table.is_open()) { - Error("Wind farm specifications table not found. Either the inputs is missing the " - "erf.windfarm_spec_table entry or the file specified in the entry - " + windfarm_spec_table + " is missing."); - } - else { - Print() << "Reading in wind farm specifications table: " << windfarm_spec_table << "\n"; - } - - int nlines; - file_turb_table >> nlines; - wind_speed.resize(nlines); - thrust_coeff.resize(nlines); - power.resize(nlines); - - d_wind_speed.resize(nlines); - d_thrust_coeff.resize(nlines); - d_power.resize(nlines); - - Real rotor_dia; - file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power; - rotor_rad = rotor_dia*0.5; - if(rotor_rad > hub_height) { - Abort("The blade length is more than the hub height. Check the second line in wind-turbine-1.tbl. Aborting....."); - } - if(thrust_coeff_standing > 1.0) { - Abort("The standing thrust coefficient is greater than 1. Check the second line in wind-turbine-1.tbl. Aborting....."); - } - - for(int iline=0;iline> wind_speed[iline] >> thrust_coeff[iline] >> power[iline]; - if(thrust_coeff[iline] > 1.0) { - Abort("The thrust coefficient is greater than 1. Check wind-turbine-1.tbl. Aborting....."); - } - } - file_turb_table.close(); - - Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); - Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); - Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); -} From 5d215f4a96fea819d6eeaf8d5dba87f020623f3f Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Sun, 7 Jul 2024 14:48:59 -0700 Subject: [PATCH 05/28] Updating README --- Exec/SimpleActuatorDisk/README | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Exec/SimpleActuatorDisk/README b/Exec/SimpleActuatorDisk/README index 2504f4de7..f3779afc9 100644 --- a/Exec/SimpleActuatorDisk/README +++ b/Exec/SimpleActuatorDisk/README @@ -1,6 +1,2 @@ -This problem setup is for simulation of the Atmospheric Boundary Layer (ABL) -using one of two turbulence schemes (Smagorinsky or Deardorff) and the bottom -boundary condition possibly specified by Monin Obukhov Similarity Theory (MOST). - -This version of the ABL problem initializes the data using a hydrostatic profile -with random perturbations in velocity and potential temperature. +This problem setup is for simulation of wind turbines using a +simplified actuator disk model. From 5999a0bc4b194a2b42e50e0f09d00f9c03efe587 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Tue, 9 Jul 2024 11:10:34 -0700 Subject: [PATCH 06/28] More refactor --- .../windturbines_loc_x_y_1WT.txt | 1 + Source/Initialization/ERF_init_windfarm.cpp | 16 +- .../WindFarmParametrization/InitWindFarm.cpp | 215 ++++++++++-------- Source/WindFarmParametrization/WindFarm.H | 22 +- 4 files changed, 137 insertions(+), 117 deletions(-) diff --git a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt index b552d30b0..21d1873e5 100644 --- a/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt +++ b/Exec/SimpleActuatorDisk/windturbines_loc_x_y_1WT.txt @@ -1,2 +1,3 @@ 300.0 300.0 700.0 700.0 +1200.0 500.0 diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 0a7d2efca..034d07452 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -19,16 +19,18 @@ template void ERF::init_windfarm (int lev, T& windfarm) { if(solverChoice.windfarm_loc_type == WindFarmLocType::lat_lon) { - windfarm.init_windfarm(lev, solverChoice.windfarm_loc_table, - solverChoice.windfarm_spec_table, geom[lev], Nturb, - false, true, - solverChoice.latitude_lo, solverChoice.longitude_lo); + windfarm.read_tables(solverChoice.windfarm_loc_table, + solverChoice.windfarm_spec_table, + false, true, + solverChoice.latitude_lo, solverChoice.longitude_lo); } else if(solverChoice.windfarm_loc_type == WindFarmLocType::x_y) { - windfarm.init_windfarm(lev, solverChoice.windfarm_loc_table, - solverChoice.windfarm_spec_table, geom[lev], - Nturb, true, false); + windfarm.read_tables(solverChoice.windfarm_loc_table, + solverChoice.windfarm_spec_table, + true, false); } + windfarm.fill_Nturb_multifab(geom[lev], Nturb[lev]); + windfarm.write_turbine_locations_vtk(); if(solverChoice.windfarm_type == WindFarmType::SimpleAD) { diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index 41b78567e..507c8f06a 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -13,21 +13,31 @@ using namespace amrex; * @param lev Integer specifying the current level */ void -WindFarm::init_windfarm (int lev, - std::string windfarm_loc_table, +WindFarm::read_tables (std::string windfarm_loc_table, std::string windfarm_spec_table, - const Geometry& geom, - Vector& Nturb, bool x_y, bool lat_lon, const Real latitude_lo, const Real longitude_lo) { - if(x_y) { - init_windfarm_x_y(lev, windfarm_loc_table); + read_windfarm_locations_table(windfarm_loc_table, + x_y, lat_lon, + latitude_lo,longitude_lo); + + read_windfarm_spec_table(windfarm_spec_table); +} + +void +WindFarm::read_windfarm_locations_table(const std::string windfarm_loc_table, + bool x_y, bool lat_lon, + const Real latitude_lo, + const Real longitude_lo) +{ + if(x_y) { + init_windfarm_x_y(windfarm_loc_table); } else if(lat_lon) { - init_windfarm_lat_lon(lev, windfarm_loc_table, latitude_lo, longitude_lo); + init_windfarm_lat_lon(windfarm_loc_table, latitude_lo, longitude_lo); } else { amrex::Abort("Are you using windfarms? For windfarm simulations, the inputs need to have an" @@ -38,47 +48,11 @@ WindFarm::init_windfarm (int lev, d_yloc.resize(yloc.size()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); - - Real* d_xloc_ptr = d_xloc.data(); - Real* d_yloc_ptr = d_yloc.data(); - - Nturb[lev].setVal(0); - - int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0); - int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1); - auto dx = geom.CellSizeArray(); - int num_turb = xloc.size(); - - // Initialize wind farm - for ( MFIter mfi(Nturb[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); - auto Nturb_array = Nturb[lev].array(mfi); - ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int li = amrex::min(amrex::max(i, i_lo), i_hi); - int lj = amrex::min(amrex::max(j, j_lo), j_hi); - - auto dx = geom.CellSizeArray(); - auto ProbLoArr = geom.ProbLoArray(); - Real x1 = ProbLoArr[0] + li*dx[0]; - Real x2 = ProbLoArr[0] + (li+1)*dx[0]; - Real y1 = ProbLoArr[1] + lj*dx[1]; - Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; - - for(int it=0; it x1 and d_xloc_ptr[it]+1e-12 < x2 and - d_yloc_ptr[it]+1e-12 > y1 and d_yloc_ptr[it]+1e-12 < y2){ - Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1; - } - } - }); - } - - read_in_windfarm_spec_table(windfarm_spec_table); } + void -WindFarm::init_windfarm_lat_lon (const int lev, - const std::string windfarm_loc_table, +WindFarm::init_windfarm_lat_lon (const std::string windfarm_loc_table, const Real latitude_lo, const Real longitude_lo) { @@ -156,8 +130,7 @@ WindFarm::init_windfarm_lat_lon (const int lev, } void -WindFarm::init_windfarm_x_y (const int lev, - const std::string windfarm_loc_table) +WindFarm::init_windfarm_x_y (const std::string windfarm_loc_table) { // Read turbine locations from windturbines.txt std::ifstream file(windfarm_loc_table); @@ -175,6 +148,99 @@ WindFarm::init_windfarm_x_y (const int lev, file.close(); } + +void +WindFarm::read_windfarm_spec_table(const std::string windfarm_spec_table) +{ + //The first line is the number of pairs entries for the power curve and thrust coefficient. + //The second line gives first the height in meters of the turbine hub, second, the diameter in + //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of + //the turbine in MW. + //The remaining lines contain the three values of: wind speed, thrust coefficient, and power production in kW. + + // Read turbine data from wind-turbine-1.tbl + std::ifstream file_turb_table(windfarm_spec_table); + if (!file_turb_table.is_open()) { + Error("Wind farm specifications table not found. Either the inputs is missing the " + "erf.windfarm_spec_table entry or the file specified in the entry - " + windfarm_spec_table + " is missing."); + } + else { + Print() << "Reading in wind farm specifications table: " << windfarm_spec_table << "\n"; + } + + int nlines; + file_turb_table >> nlines; + wind_speed.resize(nlines); + thrust_coeff.resize(nlines); + power.resize(nlines); + + d_wind_speed.resize(nlines); + d_thrust_coeff.resize(nlines); + d_power.resize(nlines); + + Real rotor_dia; + file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power; + rotor_rad = rotor_dia*0.5; + if(rotor_rad > hub_height) { + Abort("The blade length is more than the hub height. Check the second line in wind-turbine-1.tbl. Aborting....."); + } + if(thrust_coeff_standing > 1.0) { + Abort("The standing thrust coefficient is greater than 1. Check the second line in wind-turbine-1.tbl. Aborting....."); + } + + for(int iline=0;iline> wind_speed[iline] >> thrust_coeff[iline] >> power[iline]; + if(thrust_coeff[iline] > 1.0) { + Abort("The thrust coefficient is greater than 1. Check wind-turbine-1.tbl. Aborting....."); + } + } + file_turb_table.close(); + + Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); + Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); + Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); +} + +void +WindFarm::fill_Nturb_multifab(const Geometry& geom, + MultiFab& mf_Nturb) +{ + Real* d_xloc_ptr = d_xloc.data(); + Real* d_yloc_ptr = d_yloc.data(); + + mf_Nturb.setVal(0); + + int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0); + int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1); + auto dx = geom.CellSizeArray(); + int num_turb = xloc.size(); + + // Initialize wind farm + for ( MFIter mfi(mf_Nturb,TilingIfNotGPU()); mfi.isValid(); ++mfi) { + const Box& bx = mfi.tilebox(); + auto Nturb_array = mf_Nturb.array(mfi); + ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + int li = amrex::min(amrex::max(i, i_lo), i_hi); + int lj = amrex::min(amrex::max(j, j_lo), j_hi); + + auto dx = geom.CellSizeArray(); + auto ProbLoArr = geom.ProbLoArray(); + Real x1 = ProbLoArr[0] + li*dx[0]; + Real x2 = ProbLoArr[0] + (li+1)*dx[0]; + Real y1 = ProbLoArr[1] + lj*dx[1]; + Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; + + for(int it=0; it x1 and d_xloc_ptr[it]+1e-12 < x2 and + d_yloc_ptr[it]+1e-12 > y1 and d_yloc_ptr[it]+1e-12 < y2){ + Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1; + } + } + }); + } +} + + void WindFarm::write_turbine_locations_vtk() { @@ -211,8 +277,8 @@ WindFarm::write_actuator_disks_vtk() Real x, y, z; Real theta = 2.0*M_PI/npts*pt; x = xloc[it]+1e-12; - y = yloc[it]+85.0*cos(theta); - z = 119.0+85.0*sin(theta); + y = yloc[it]+rotor_rad*cos(theta); + z = hub_height+rotor_rad*sin(theta); fprintf(file_actuator_disks, "%0.15g %0.15g %0.15g\n", x, y, z); } } @@ -229,55 +295,4 @@ WindFarm::write_actuator_disks_vtk() } } -void -WindFarm::read_in_windfarm_spec_table(std::string windfarm_spec_table) -{ - //The first line is the number of pairs entries for the power curve and thrust coefficient. - //The second line gives first the height in meters of the turbine hub, second, the diameter in - //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of - //the turbine in MW. - //The remaining lines contain the three values of: wind speed, thrust coefficient, and power production in kW. - - // Read turbine data from wind-turbine-1.tbl - std::ifstream file_turb_table(windfarm_spec_table); - if (!file_turb_table.is_open()) { - Error("Wind farm specifications table not found. Either the inputs is missing the " - "erf.windfarm_spec_table entry or the file specified in the entry - " + windfarm_spec_table + " is missing."); - } - else { - Print() << "Reading in wind farm specifications table: " << windfarm_spec_table << "\n"; - } - - int nlines; - file_turb_table >> nlines; - wind_speed.resize(nlines); - thrust_coeff.resize(nlines); - power.resize(nlines); - - d_wind_speed.resize(nlines); - d_thrust_coeff.resize(nlines); - d_power.resize(nlines); - - Real rotor_dia; - file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power; - rotor_rad = rotor_dia*0.5; - if(rotor_rad > hub_height) { - Abort("The blade length is more than the hub height. Check the second line in wind-turbine-1.tbl. Aborting....."); - } - if(thrust_coeff_standing > 1.0) { - Abort("The standing thrust coefficient is greater than 1. Check the second line in wind-turbine-1.tbl. Aborting....."); - } - - for(int iline=0;iline> wind_speed[iline] >> thrust_coeff[iline] >> power[iline]; - if(thrust_coeff[iline] > 1.0) { - Abort("The thrust coefficient is greater than 1. Check wind-turbine-1.tbl. Aborting....."); - } - } - file_turb_table.close(); - - Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); - Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); - Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); -} diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 69ce7e877..364e2b00c 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -12,24 +12,26 @@ public: WindFarm(){} - void init_windfarm(int lev, - std::string windfarm_loc_table, + void read_tables (std::string windfarm_loc_table, std::string windfarm_spec_table, - const amrex::Geometry& geom, - amrex::Vector& Nturb, bool x_y, bool lat_lon, const amrex::Real latitude_lo=0.0, const amrex::Real longitude_lo=0.0); - void init_windfarm_lat_lon(const int lev, - const std::string windfarm_loc_table, + void init_windfarm_lat_lon(const std::string windfarm_loc_table, const amrex::Real latitude_lo, - const amrex::Real longitude_lo); + const amrex::Real longitude_lo); - void init_windfarm_x_y(const int lev, - const std::string windfarm_loc_table); + void init_windfarm_x_y(const std::string windfarm_loc_table); - void read_in_windfarm_spec_table(std::string windfarm_spec_table); + void read_windfarm_locations_table(const std::string windfarm_loc_table, + bool x_y, bool lat_lon, + const amrex::Real latitude_lo=0.0, + const amrex::Real longitude_lo=0.0); + + void read_windfarm_spec_table(const std::string windfarm_spec_table); + + void fill_Nturb_multifab(const amrex::Geometry& geom, amrex::MultiFab& mf_Nturb); void write_turbine_locations_vtk(); From e759f366854c7201ac237e63b21a5557b840bb07 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Sun, 14 Jul 2024 13:56:39 -0700 Subject: [PATCH 07/28] Some more refactoring --- Source/ERF.H | 10 +-- Source/ERF.cpp | 11 +++- Source/Initialization/ERF_init_windfarm.cpp | 26 +++----- Source/TimeIntegration/ERF_Advance.cpp | 1 + .../WindFarmParametrization/InitWindFarm.cpp | 2 +- .../WindFarmParametrization/Null/Make.package | 1 + .../Null/NullWindFarm.H | 47 ++++++++++++++ .../SimpleActuatorDisk/Advance_SimpleAD.cpp | 21 ++++--- .../SimpleActuatorDisk/SimpleAD.H | 12 ++-- Source/WindFarmParametrization/WindFarm.H | 62 ++++++++++++++++--- 10 files changed, 148 insertions(+), 45 deletions(-) create mode 100644 Source/WindFarmParametrization/Null/Make.package create mode 100644 Source/WindFarmParametrization/Null/NullWindFarm.H diff --git a/Source/ERF.H b/Source/ERF.H index 36cd4f61d..587cac2d4 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -49,7 +49,7 @@ #include "LandSurface.H" #ifdef ERF_USE_WINDFARM -#include "SimpleAD.H" +#include "WindFarm.H" #endif #ifdef ERF_USE_RRTMGP @@ -376,9 +376,7 @@ public: #endif // ERF_USE_NETCDF #ifdef ERF_USE_WINDFARM - SimpleAD simpleAD; - template - void init_windfarm(int lev, T& windfarm); + void init_windfarm(int lev); void advance_windfarm (int lev, const amrex::Geometry& geom, const amrex::Real& dt_advance, @@ -452,6 +450,9 @@ private: // Initialize the microphysics object void initializeMicrophysics (const int&); + // Initialize the windfarm object + void initializeWindFarm (const int&); + // Compute a vector of new MultiFabs by copying from valid region and filling ghost cells // // NOTE: FillPatch takes in an empty MF, and returns cell-centered + velocities (not momenta) @@ -665,6 +666,7 @@ private: // Variables for wind farm parametrization models + std::unique_ptr windfarm; amrex::Vector Nturb; amrex::Vector vars_windfarm; // Fitch: Vabs, Vabsdt, dudt, dvdt, dTKEdt // EWP: dudt, dvdt, dTKEdt diff --git a/Source/ERF.cpp b/Source/ERF.cpp index 7fedc2a2f..6fbb425a8 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -136,6 +136,8 @@ ERF::ERF () ReadParameters(); initializeMicrophysics(nlevs_max); + initializeWindFarm(nlevs_max); + const std::string& pv1 = "plot_vars_1"; setPlotVariables(pv1,plot_var_names_1); const std::string& pv2 = "plot_vars_2"; setPlotVariables(pv2,plot_var_names_2); @@ -1108,6 +1110,13 @@ ERF::initializeMicrophysics (const int& a_nlevsmax /*!< number of AMR levels */) return; } + +void +ERF::initializeWindFarm(const int& a_nlevsmax/*!< number of AMR levels */ ) +{ + windfarm = std::make_unique(a_nlevsmax, solverChoice.windfarm_type); +} + void ERF::restart () { @@ -1210,7 +1219,7 @@ ERF::init_only (int lev, Real time) // Initialize wind farm #ifdef ERF_USE_WINDFARM - init_windfarm(lev, simpleAD); + init_windfarm(lev); #endif if(solverChoice.spongeChoice.sponge_type == "input_sponge"){ diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 034d07452..ba573348d 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -13,28 +13,27 @@ using namespace amrex; */ // Explicit instantiation -template void ERF::init_windfarm(int lev, SimpleAD& simpleAD); -template -void ERF::init_windfarm (int lev, T& windfarm) +void +ERF::init_windfarm (int lev) { if(solverChoice.windfarm_loc_type == WindFarmLocType::lat_lon) { - windfarm.read_tables(solverChoice.windfarm_loc_table, + windfarm->read_tables(solverChoice.windfarm_loc_table, solverChoice.windfarm_spec_table, false, true, solverChoice.latitude_lo, solverChoice.longitude_lo); } else if(solverChoice.windfarm_loc_type == WindFarmLocType::x_y) { - windfarm.read_tables(solverChoice.windfarm_loc_table, + windfarm->read_tables(solverChoice.windfarm_loc_table, solverChoice.windfarm_spec_table, true, false); } - windfarm.fill_Nturb_multifab(geom[lev], Nturb[lev]); + windfarm->fill_Nturb_multifab(geom[lev], Nturb[lev]); - windfarm.write_turbine_locations_vtk(); + windfarm->write_turbine_locations_vtk(); if(solverChoice.windfarm_type == WindFarmType::SimpleAD) { - windfarm.write_actuator_disks_vtk(); + windfarm->write_actuator_disks_vtk(); } } @@ -47,15 +46,6 @@ ERF::advance_windfarm (int lev, MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, SolverChoice& solver_choice) { - - if (solver_choice.windfarm_type == WindFarmType::Fitch) { - //fitch_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - // mf_vars_windfarm, mf_Nturb); - } else if (solver_choice.windfarm_type == WindFarmType::EWP) { - //ewp_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - // mf_vars_windfarm, mf_Nturb); - } else if (solver_choice.windfarm_type == WindFarmType::SimpleAD) { - simpleAD.simpleAD_advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + windfarm->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); - } } diff --git a/Source/TimeIntegration/ERF_Advance.cpp b/Source/TimeIntegration/ERF_Advance.cpp index 02448f2bf..f9850e9f6 100644 --- a/Source/TimeIntegration/ERF_Advance.cpp +++ b/Source/TimeIntegration/ERF_Advance.cpp @@ -76,6 +76,7 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/) if (qmoist[lev].size() > 0) FillPatchMoistVars(lev, *(qmoist[lev][0])); } + #if defined(ERF_USE_WINDFARM) if (solverChoice.windfarm_type != WindFarmType::None) { advance_windfarm(lev, Geom(lev), dt_lev, S_old, diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index 507c8f06a..b19c0bf25 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -19,7 +19,7 @@ WindFarm::read_tables (std::string windfarm_loc_table, const Real latitude_lo, const Real longitude_lo) { - + std::cout << "Reading tables " << "\n"; read_windfarm_locations_table(windfarm_loc_table, x_y, lat_lon, latitude_lo,longitude_lo); diff --git a/Source/WindFarmParametrization/Null/Make.package b/Source/WindFarmParametrization/Null/Make.package new file mode 100644 index 000000000..571b0c2b8 --- /dev/null +++ b/Source/WindFarmParametrization/Null/Make.package @@ -0,0 +1 @@ +CEXE_headers += NullWindFarm.H diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H new file mode 100644 index 000000000..5fa943dd6 --- /dev/null +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -0,0 +1,47 @@ +#ifndef NULLWINDFARM_H +#define NULLWINDFARM_H + +#include +#include +#include +#include + +class NullWindFarm { + +public: + + NullWindFarm() + { + rotor_rad = 10000.0; + } + + virtual void advance (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0; + + /*virtual void source_terms_cellcentered (const amrex::Geometry& geom, + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0; + + virtual void update (const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp) = 0;*/ + + +protected: + + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; +}; + + +#endif + diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp index 0c2e744fb..f7c88c6f4 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp @@ -3,18 +3,23 @@ using namespace amrex; -void SimpleAD::simpleAD_advance (int lev, +void SimpleAD::advance (int lev, const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) { - simpleAD_source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); - simpleAD_update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); + + std::cout << "Values of " << this->rotor_rad << " " << this->hub_height << "\n"; + + exit(0); + + source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); + update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } -void SimpleAD::simpleAD_update (const Real& dt_advance, +void SimpleAD::update (const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, const MultiFab& mf_vars_simpleAD) @@ -43,10 +48,10 @@ void SimpleAD::simpleAD_update (const Real& dt_advance, } } -void SimpleAD::simpleAD_source_terms_cellcentered (const Geometry& geom, - const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) +void SimpleAD::source_terms_cellcentered (const Geometry& geom, + const MultiFab& cons_in, + const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, + MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) { auto dx = geom.CellSizeArray(); diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index b9949f68d..2fc7afbe2 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -1,27 +1,27 @@ #ifndef SIMPLEAD_H #define SIMPLEAD_H -#include "WindFarm.H" +#include "NullWindFarm.H" #include #include -class SimpleAD : public WindFarm { +class SimpleAD : public NullWindFarm { public: - void simpleAD_advance (int lev, + void advance (int lev, const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override; - void simpleAD_source_terms_cellcentered (const amrex::Geometry& geom, + void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); - void simpleAD_update (const amrex::Real& dt_advance, + void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars_ewp); diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 364e2b00c..f22a3b7a8 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -1,17 +1,31 @@ #ifndef WINDFARM_H #define WINDFARM_H +#include "NullWindFarm.H" +#include "SimpleAD.H" #include #include #include #include -class WindFarm { +class WindFarm : public NullWindFarm { public: WindFarm(){} + WindFarm (int nlev, + const WindFarmType& a_windfarm_type) + { + m_windfarm_model.resize(nlev); + if (a_windfarm_type == WindFarmType::SimpleAD) { + SetModel(); + amrex::Print() << "Simple actuator disk windfarm model!\n"; + } else { + amrex::Abort("WindFarm: Dont know this windfarm_type!") ; + } + } + void read_tables (std::string windfarm_loc_table, std::string windfarm_spec_table, bool x_y, bool lat_lon, @@ -37,16 +51,50 @@ public: void write_actuator_disks_vtk(); + void advance (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override + { + m_windfarm_model[lev]->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + mf_vars_windfarm, mf_Nturb); + } + + /*void source_terms_cellcentered (const amrex::Geometry& geom, + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) + { + m_windfarm_model[lev]->source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); + } + + void update (const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp) + { + m_windfarm_model[lev]->update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); + }*/ + + protected: - amrex::Vector xloc, yloc; - amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; - amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; + /*! \brief Create and set the specified windfarm model */ + template + void SetModel () + { + std::cout << "Setting the wind farm model with " << m_windfarm_model.size() << " levels " << "\n"; + for (int lev(0); lev(); + } + } -}; +private: + amrex::Vector> m_windfarm_model; /*!< windfarm model */ +}; #endif From b391ffcf9be31e29d721be6926bf645aa7914ec6 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Sun, 14 Jul 2024 13:56:58 -0700 Subject: [PATCH 08/28] Some more refactoring --- Exec/Make.ERF | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Exec/Make.ERF b/Exec/Make.ERF index 98e6811b3..7e14093dc 100644 --- a/Exec/Make.ERF +++ b/Exec/Make.ERF @@ -141,20 +141,31 @@ INCLUDE_LOCATIONS += $(ERF_MOISTURE_KESSLER_DIR) # at runtime from the inputs ifeq ($(USE_WINDFARM), TRUE) DEFINES += -DERF_USE_WINDFARM - ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization + + ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization + ERF_WINDFARM_NULL_DIR = $(ERF_WINDFARM_DIR)/Null #ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch #ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP ERF_WINDFARM_SIMPLEAD_DIR = $(ERF_WINDFARM_DIR)/SimpleActuatorDisk + include $(ERF_WINDFARM_DIR)/Make.package + include $(ERF_WINDFARM_NULL_DIR)/Make.package #include $(ERF_WINDFARM_FITCH_DIR)/Make.package #include $(ERF_WINDFARM_EWP_DIR)/Make.package include $(ERF_WINDFARM_SIMPLEAD_DIR)/Make.package + VPATH_LOCATIONS += $(ERF_WINDFARM_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_DIR) + + VPATH_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) + INCLUDE_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) + #VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) #INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) + #VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) #INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) + VPATH_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) endif From 7056cfe0405ee8fa298615882d9b6c43f2b1c725 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 17:28:16 -0700 Subject: [PATCH 09/28] Refactoring almost done --- Exec/EWP/inputs_WindFarm_lat_lon | 2 -- Exec/EWP/inputs_WindFarm_x_y | 4 +--- Exec/Make.ERF | 16 ++++++++-------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Exec/EWP/inputs_WindFarm_lat_lon b/Exec/EWP/inputs_WindFarm_lat_lon index e6ebae87b..b3a549ceb 100644 --- a/Exec/EWP/inputs_WindFarm_lat_lon +++ b/Exec/EWP/inputs_WindFarm_lat_lon @@ -72,8 +72,6 @@ erf.pbl_type = "None" erf.init_type = "uniform" -erf.windfarm_type = "EWP" - # PROBLEM PARAMETERS prob.rho_0 = 1.0 prob.A_0 = 1.0 diff --git a/Exec/EWP/inputs_WindFarm_x_y b/Exec/EWP/inputs_WindFarm_x_y index 7fbed1830..19b931695 100644 --- a/Exec/EWP/inputs_WindFarm_x_y +++ b/Exec/EWP/inputs_WindFarm_x_y @@ -10,7 +10,7 @@ geometry.prob_extent = 200150 202637 1000 amr.n_cell = 50 50 40 # WINDFARM PARAMETRIZATION PARAMETERS -erf.windfarm_type = "Fitch" +erf.windfarm_type = "EWP" erf.windfarm_loc_type = "x_y" erf.windfarm_loc_table = "windturbines_loc_x_y_WindFarm.txt" erf.windfarm_spec_table = "windturbines_spec_WindFarm.tbl" @@ -70,8 +70,6 @@ erf.pbl_type = "None" erf.init_type = "uniform" -erf.windfarm_type = "EWP" - # PROBLEM PARAMETERS prob.rho_0 = 1.0 prob.A_0 = 1.0 diff --git a/Exec/Make.ERF b/Exec/Make.ERF index 7e14093dc..672767acd 100644 --- a/Exec/Make.ERF +++ b/Exec/Make.ERF @@ -144,14 +144,14 @@ ifeq ($(USE_WINDFARM), TRUE) ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization ERF_WINDFARM_NULL_DIR = $(ERF_WINDFARM_DIR)/Null - #ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch - #ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP + ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch + ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP ERF_WINDFARM_SIMPLEAD_DIR = $(ERF_WINDFARM_DIR)/SimpleActuatorDisk include $(ERF_WINDFARM_DIR)/Make.package include $(ERF_WINDFARM_NULL_DIR)/Make.package - #include $(ERF_WINDFARM_FITCH_DIR)/Make.package - #include $(ERF_WINDFARM_EWP_DIR)/Make.package + include $(ERF_WINDFARM_FITCH_DIR)/Make.package + include $(ERF_WINDFARM_EWP_DIR)/Make.package include $(ERF_WINDFARM_SIMPLEAD_DIR)/Make.package VPATH_LOCATIONS += $(ERF_WINDFARM_DIR) @@ -160,11 +160,11 @@ ifeq ($(USE_WINDFARM), TRUE) VPATH_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) - #VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - #INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) + VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) + INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - #VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) - #INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) + VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) + INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) VPATH_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) INCLUDE_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) From 2ce4ec26f3a55da3053d2db10ff21b659948f08a Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 17:33:00 -0700 Subject: [PATCH 10/28] Refactoring almost complete --- Source/ERF.H | 2 +- Source/ERF.cpp | 3 +- Source/Initialization/ERF_init_windfarm.cpp | 10 +-- Source/TimeIntegration/ERF_Advance.cpp | 2 +- .../EWP/AdvanceEWP.cpp | 38 +++++---- Source/WindFarmParametrization/EWP/EWP.H | 42 ++++++---- .../Fitch/AdvanceFitch.cpp | 28 ++++--- Source/WindFarmParametrization/Fitch/Fitch.H | 18 +++- .../WindFarmParametrization/InitWindFarm.cpp | 26 +++--- .../Null/NullWindFarm.H | 61 ++++++++++---- .../SimpleActuatorDisk/Advance_SimpleAD.cpp | 49 +++++------ .../SimpleActuatorDisk/SimpleAD.H | 10 ++- Source/WindFarmParametrization/WindFarm.H | 83 +++++++++++-------- 13 files changed, 231 insertions(+), 141 deletions(-) diff --git a/Source/ERF.H b/Source/ERF.H index 587cac2d4..c63343fff 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -450,7 +450,7 @@ private: // Initialize the microphysics object void initializeMicrophysics (const int&); - // Initialize the windfarm object + // Initialize the windfarm object void initializeWindFarm (const int&); // Compute a vector of new MultiFabs by copying from valid region and filling ghost cells diff --git a/Source/ERF.cpp b/Source/ERF.cpp index 6fbb425a8..f6502faa0 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -1114,7 +1114,8 @@ ERF::initializeMicrophysics (const int& a_nlevsmax /*!< number of AMR levels */) void ERF::initializeWindFarm(const int& a_nlevsmax/*!< number of AMR levels */ ) { - windfarm = std::make_unique(a_nlevsmax, solverChoice.windfarm_type); + //std::cout << "Solver choice windfarm is " << solverChoice.windfarm_type << "\n"; + windfarm = std::make_unique(a_nlevsmax, solverChoice.windfarm_type); } void diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index ba573348d..e1683c6dc 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -14,7 +14,7 @@ using namespace amrex; // Explicit instantiation -void +void ERF::init_windfarm (int lev) { if(solverChoice.windfarm_loc_type == WindFarmLocType::lat_lon) { @@ -24,11 +24,11 @@ ERF::init_windfarm (int lev) solverChoice.latitude_lo, solverChoice.longitude_lo); } else if(solverChoice.windfarm_loc_type == WindFarmLocType::x_y) { windfarm->read_tables(solverChoice.windfarm_loc_table, - solverChoice.windfarm_spec_table, - true, false); + solverChoice.windfarm_spec_table, + true, false); } - windfarm->fill_Nturb_multifab(geom[lev], Nturb[lev]); + windfarm->fill_Nturb_multifab(geom[lev], Nturb[lev]); windfarm->write_turbine_locations_vtk(); @@ -46,6 +46,6 @@ ERF::advance_windfarm (int lev, MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, SolverChoice& solver_choice) { - windfarm->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + windfarm->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } diff --git a/Source/TimeIntegration/ERF_Advance.cpp b/Source/TimeIntegration/ERF_Advance.cpp index f9850e9f6..7b358797a 100644 --- a/Source/TimeIntegration/ERF_Advance.cpp +++ b/Source/TimeIntegration/ERF_Advance.cpp @@ -76,7 +76,7 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/) if (qmoist[lev].size() > 0) FillPatchMoistVars(lev, *(qmoist[lev][0])); } - + #if defined(ERF_USE_WINDFARM) if (solverChoice.windfarm_type != WindFarmType::None) { advance_windfarm(lev, Geom(lev), dt_lev, S_old, diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index 098868367..304e1f93d 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -6,22 +6,24 @@ using namespace amrex; -void ewp_advance (int lev, - const Geometry& geom, - const Real& dt_advance, - MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) +void +EWP::advance (int lev, + const Geometry& geom, + const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, + MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) { - ewp_source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_ewp, mf_Nturb); - ewp_update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp); + source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_ewp, mf_Nturb); + update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp); } -void ewp_update (const Real& dt_advance, - MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, - const MultiFab& mf_vars_ewp) +void +EWP::update (const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, + const MultiFab& mf_vars_ewp) { for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { @@ -51,12 +53,16 @@ void ewp_update (const Real& dt_advance, } } -void ewp_source_terms_cellcentered (const Geometry& geom, - const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) +void +EWP::source_terms_cellcentered (const Geometry& geom, + const MultiFab& cons_in, + const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, + MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) { + get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + d_wind_speed, d_thrust_coeff, d_power); + auto dx = geom.CellSizeArray(); auto ProbHiArr = geom.ProbHiArray(); auto ProbLoArr = geom.ProbLoArray(); diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index 7bd5db3cf..584fe6ec0 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -4,22 +4,34 @@ #include #include -void ewp_advance (int lev, - const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); - -void ewp_source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); - -void ewp_update (const amrex::Real& dt_advance, +#include "NullWindFarm.H" + +class EWP : public NullWindFarm { + + void advance (int lev, + const amrex::Geometry& geom, + const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp); + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + + void source_terms_cellcentered (const amrex::Geometry& geom, + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + + void update (const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp); + +protected: + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; +}; #endif diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index 56a1a50a2..bfd23eb47 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -44,22 +44,24 @@ Real compute_Aijk(const Real z_k, } -void fitch_advance (int lev, +void +Fitch::advance (int lev, const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb) { - fitch_source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_fitch, mf_Nturb); - fitch_update(dt_advance, cons_in, U_old, V_old, mf_vars_fitch); + source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_fitch, mf_Nturb); + update(dt_advance, cons_in, U_old, V_old, mf_vars_fitch); } -void fitch_update (const Real& dt_advance, - MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, - const MultiFab& mf_vars_fitch) +void +Fitch::update (const Real& dt_advance, + MultiFab& cons_in, + MultiFab& U_old, MultiFab& V_old, + const MultiFab& mf_vars_fitch) { for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { @@ -89,12 +91,16 @@ void fitch_update (const Real& dt_advance, } } -void fitch_source_terms_cellcentered (const Geometry& geom, - const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb) +void +Fitch::source_terms_cellcentered (const Geometry& geom, + const MultiFab& cons_in, + const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, + MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb) { + get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + d_wind_speed, d_thrust_coeff, d_power); + auto dx = geom.CellSizeArray(); auto ProbHiArr = geom.ProbHiArray(); auto ProbLoArr = geom.ProbLoArray(); diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index 59e0f0542..7ea5d094d 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -4,22 +4,34 @@ #include #include -void fitch_advance (int lev, +#include "NullWindFarm.H" + +class Fitch : public NullWindFarm { + +void advance (int lev, const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); -void fitch_source_terms_cellcentered (const amrex::Geometry& geom, +void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); -void fitch_update (const amrex::Real& dt_advance, +void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars_fitch); +protected: + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; +}; + #endif diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index b19c0bf25..f0653ddc4 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -19,21 +19,21 @@ WindFarm::read_tables (std::string windfarm_loc_table, const Real latitude_lo, const Real longitude_lo) { - std::cout << "Reading tables " << "\n"; - read_windfarm_locations_table(windfarm_loc_table, - x_y, lat_lon, - latitude_lo,longitude_lo); + std::cout << "Reading tables " << "\n"; + read_windfarm_locations_table(windfarm_loc_table, + x_y, lat_lon, + latitude_lo,longitude_lo); read_windfarm_spec_table(windfarm_spec_table); } -void +void WindFarm::read_windfarm_locations_table(const std::string windfarm_loc_table, - bool x_y, bool lat_lon, - const Real latitude_lo, - const Real longitude_lo) + bool x_y, bool lat_lon, + const Real latitude_lo, + const Real longitude_lo) { - if(x_y) { + if(x_y) { init_windfarm_x_y(windfarm_loc_table); } else if(lat_lon) { @@ -48,6 +48,8 @@ WindFarm::read_windfarm_locations_table(const std::string windfarm_loc_table, d_yloc.resize(yloc.size()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); + + set_turb_loc(d_xloc, d_yloc); } @@ -199,11 +201,15 @@ WindFarm::read_windfarm_spec_table(const std::string windfarm_spec_table) Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); + + set_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + d_wind_speed, d_thrust_coeff, d_power); + } void WindFarm::fill_Nturb_multifab(const Geometry& geom, - MultiFab& mf_Nturb) + MultiFab& mf_Nturb) { Real* d_xloc_ptr = d_xloc.data(); Real* d_yloc_ptr = d_yloc.data(); diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index 5fa943dd6..7f293327c 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -10,36 +10,61 @@ class NullWindFarm { public: - NullWindFarm() - { - rotor_rad = 10000.0; - } + NullWindFarm() {} - virtual void advance (int lev, + virtual void advance (int lev, const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0; - /*virtual void source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0; + virtual void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, + const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, + const amrex::Gpu::DeviceVector& d_thrust_coeff, + const amrex::Gpu::DeviceVector& d_power) + { + m_rotor_rad = rotor_rad; + m_hub_height = hub_height; + m_thrust_coeff_standing = thrust_coeff_standing; + m_d_wind_speed = d_wind_speed; + m_d_thrust_coeff = d_thrust_coeff; + m_d_power = d_power; + } - virtual void update (const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp) = 0;*/ + virtual void set_turb_loc (const amrex::Gpu::DeviceVector& d_xloc, + const amrex::Gpu::DeviceVector& d_yloc) + { + m_d_xloc = d_xloc; + m_d_yloc = d_yloc; + } + void get_turb_spec (amrex::Real& rotor_rad, amrex::Real& hub_height, + amrex::Real& thrust_coeff_standing, amrex::Gpu::DeviceVector& d_wind_speed, + amrex::Gpu::DeviceVector& d_thrust_coeff, amrex::Gpu::DeviceVector& d_power) + { + rotor_rad = m_rotor_rad; + hub_height = m_hub_height; + thrust_coeff_standing = m_thrust_coeff_standing; + d_wind_speed = m_d_wind_speed; + d_thrust_coeff = m_d_thrust_coeff; + d_power = m_d_power; + } + + void get_turb_loc (amrex::Gpu::DeviceVector& d_xloc, + amrex::Gpu::DeviceVector& d_yloc) + { + d_xloc = m_d_xloc; + d_yloc = m_d_yloc; + } protected: - amrex::Vector xloc, yloc; - amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; - amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; + amrex::Vector m_xloc, m_yloc; + amrex::Real m_hub_height, m_rotor_rad, m_thrust_coeff_standing, m_nominal_power; + amrex::Vector m_wind_speed, m_thrust_coeff, m_power; + amrex::Gpu::DeviceVector m_d_wind_speed, m_d_thrust_coeff, m_d_power; + amrex::Gpu::DeviceVector m_d_xloc, m_d_yloc; }; diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp index f7c88c6f4..83620c839 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp @@ -10,11 +10,6 @@ void SimpleAD::advance (int lev, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) { - - std::cout << "Values of " << this->rotor_rad << " " << this->hub_height << "\n"; - - exit(0); - source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } @@ -54,28 +49,33 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) { - auto dx = geom.CellSizeArray(); - auto ProbHiArr = geom.ProbHiArray(); - auto ProbLoArr = geom.ProbLoArray(); - Real d_rotor_rad = rotor_rad; - Real d_hub_height = hub_height; + get_turb_loc(d_xloc, d_yloc); + get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + d_wind_speed, d_thrust_coeff, d_power); + + + auto dx = geom.CellSizeArray(); + auto ProbHiArr = geom.ProbHiArray(); + auto ProbLoArr = geom.ProbLoArray(); + Real d_rotor_rad = rotor_rad; + Real d_hub_height = hub_height; // Domain valid box - const amrex::Box& domain = geom.Domain(); - int domlo_x = domain.smallEnd(0); - int domhi_x = domain.bigEnd(0) + 1; - int domlo_y = domain.smallEnd(1); - int domhi_y = domain.bigEnd(1) + 1; - int domlo_z = domain.smallEnd(2); - int domhi_z = domain.bigEnd(2) + 1; + const amrex::Box& domain = geom.Domain(); + int domlo_x = domain.smallEnd(0); + int domhi_x = domain.bigEnd(0) + 1; + int domlo_y = domain.smallEnd(1); + int domhi_y = domain.bigEnd(1) + 1; + int domlo_z = domain.smallEnd(2); + int domhi_z = domain.bigEnd(2) + 1; - // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt - mf_vars_simpleAD.setVal(0.0); + // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt + mf_vars_simpleAD.setVal(0.0); - for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { + for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - const Box& gbx = mfi.growntilebox(1); + const Box& gbx = mfi.growntilebox(1); auto cons_array = cons_in.array(mfi); auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); @@ -107,9 +107,10 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, Real fac = 0.0; int check_int = 0; - for(int it=0;it x1 and xloc[it]+1e-12 < x2) { - if(std::pow((y-yloc[it])*(y-yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { + + for(int it=0;it x1 and d_xloc[it]+1e-12 < x2) { + if(std::pow((y-d_yloc[it])*(y-d_yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { check_int++; fac = -2.0*std::pow(u_vel(i,j,k)*std::cos(phi) + v_vel(i,j,k)*std::sin(phi), 2.0)*0.5*(1.0-0.5); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 2fc7afbe2..83f25c56f 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -1,9 +1,9 @@ #ifndef SIMPLEAD_H #define SIMPLEAD_H -#include "NullWindFarm.H" #include #include +#include "NullWindFarm.H" class SimpleAD : public NullWindFarm { @@ -25,6 +25,14 @@ public: amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars_ewp); + +protected: + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; + }; #endif diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index f22a3b7a8..5181f7950 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -1,30 +1,39 @@ #ifndef WINDFARM_H #define WINDFARM_H -#include "NullWindFarm.H" -#include "SimpleAD.H" #include #include #include #include +#include "NullWindFarm.H" +#include "Fitch.H" +#include "EWP.H" +#include "SimpleAD.H" + class WindFarm : public NullWindFarm { public: WindFarm(){} - WindFarm (int nlev, - const WindFarmType& a_windfarm_type) - { - m_windfarm_model.resize(nlev); - if (a_windfarm_type == WindFarmType::SimpleAD) { + WindFarm (int nlev, + const WindFarmType& a_windfarm_type) + { + m_windfarm_model.resize(nlev); + if (a_windfarm_type == WindFarmType::Fitch) { + SetModel(); + } + else if (a_windfarm_type == WindFarmType::EWP) { + SetModel(); + } + else if (a_windfarm_type == WindFarmType::SimpleAD) { SetModel(); amrex::Print() << "Simple actuator disk windfarm model!\n"; } else { amrex::Abort("WindFarm: Dont know this windfarm_type!") ; } - } + } void read_tables (std::string windfarm_loc_table, std::string windfarm_spec_table, @@ -39,61 +48,65 @@ public: void init_windfarm_x_y(const std::string windfarm_loc_table); void read_windfarm_locations_table(const std::string windfarm_loc_table, - bool x_y, bool lat_lon, - const amrex::Real latitude_lo=0.0, - const amrex::Real longitude_lo=0.0); + bool x_y, bool lat_lon, + const amrex::Real latitude_lo=0.0, + const amrex::Real longitude_lo=0.0); void read_windfarm_spec_table(const std::string windfarm_spec_table); - void fill_Nturb_multifab(const amrex::Geometry& geom, amrex::MultiFab& mf_Nturb); + void fill_Nturb_multifab(const amrex::Geometry& geom, amrex::MultiFab& mf_Nturb); void write_turbine_locations_vtk(); void write_actuator_disks_vtk(); - void advance (int lev, + void advance (int lev, const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override - { - m_windfarm_model[lev]->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); - } - - /*void source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) - { - m_windfarm_model[lev]->source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); - } - - void update (const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp) - { - m_windfarm_model[lev]->update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); - }*/ + { + m_windfarm_model[lev]->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + mf_vars_windfarm, mf_Nturb); + } + void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, + const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, + const amrex::Gpu::DeviceVector& d_thrust_coeff, + const amrex::Gpu::DeviceVector& d_power) override + { + m_windfarm_model[0]->set_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + d_wind_speed, d_thrust_coeff, d_power); + } + + void set_turb_loc (const amrex::Gpu::DeviceVector& d_xloc, + const amrex::Gpu::DeviceVector& d_yloc) override + { + m_windfarm_model[0]->set_turb_loc(d_xloc, d_yloc); + } protected: + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; + amrex::Gpu::DeviceVector d_xloc, d_yloc; + /*! \brief Create and set the specified windfarm model */ template void SetModel () { - std::cout << "Setting the wind farm model with " << m_windfarm_model.size() << " levels " << "\n"; + std::cout << "Setting the wind farm model with " << m_windfarm_model.size() << " levels " << "\n"; for (int lev(0); lev(); } } + private: amrex::Vector> m_windfarm_model; /*!< windfarm model */ - }; #endif From 6c29cd567cb005822364d9f63ba3999de3c02454 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 17:38:16 -0700 Subject: [PATCH 11/28] Removing unused dirs and files --- Exec/EWP/plot_profiles.py | 70 --------- Exec/Fitch/CMakeLists.txt | 12 -- Exec/Fitch/GNUmakefile | 37 ----- Exec/Fitch/Make.package | 2 - Exec/Fitch/README | 6 - Exec/Fitch/inputs_Fitch | 74 ---------- Exec/Fitch/inputs_Fitch_LargeDomain | 76 ---------- Exec/Fitch/inputs_Fitch_Testing | 79 ---------- Exec/Fitch/inputs_Fitch_WindFarm | 78 ---------- Exec/Fitch/plot_profiles.py | 70 --------- Exec/Fitch/prob.H | 79 ---------- Exec/Fitch/prob.cpp | 167 ---------------------- Exec/Fitch/wind-turbine-1.tbl | 24 ---- Exec/Fitch/windturbines.txt | 25 ---- Exec/Fitch/windturbines.txt_LargeDomain | 30 ---- Exec/Fitch/windturbines_WindFarm.txt | 97 ------------- Exec/SimpleActuatorDisk/plot_profiles.py | 70 --------- Source/WindFarmParametrization/WindFarm.H | 2 - 18 files changed, 998 deletions(-) delete mode 100644 Exec/EWP/plot_profiles.py delete mode 100644 Exec/Fitch/CMakeLists.txt delete mode 100644 Exec/Fitch/GNUmakefile delete mode 100644 Exec/Fitch/Make.package delete mode 100644 Exec/Fitch/README delete mode 100644 Exec/Fitch/inputs_Fitch delete mode 100644 Exec/Fitch/inputs_Fitch_LargeDomain delete mode 100644 Exec/Fitch/inputs_Fitch_Testing delete mode 100644 Exec/Fitch/inputs_Fitch_WindFarm delete mode 100644 Exec/Fitch/plot_profiles.py delete mode 100644 Exec/Fitch/prob.H delete mode 100644 Exec/Fitch/prob.cpp delete mode 100644 Exec/Fitch/wind-turbine-1.tbl delete mode 100644 Exec/Fitch/windturbines.txt delete mode 100644 Exec/Fitch/windturbines.txt_LargeDomain delete mode 100644 Exec/Fitch/windturbines_WindFarm.txt delete mode 100644 Exec/SimpleActuatorDisk/plot_profiles.py diff --git a/Exec/EWP/plot_profiles.py b/Exec/EWP/plot_profiles.py deleted file mode 100644 index 50ab6f76c..000000000 --- a/Exec/EWP/plot_profiles.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -import os -import glob -import numpy as np -import matplotlib.pyplot as plt -import yt - -pltfiles = [pltfile for pltfile in glob.glob('plt*') - if os.path.isdir(pltfile) and not ('old' in pltfile)] -nsteps = [int(pltfile[3:]) for pltfile in pltfiles] -latestoutput = pltfiles[np.argmax(nsteps)] -print(latestoutput) - -ds = yt.load(latestoutput) - -soln = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -zp = np.linspace(ds.domain_left_edge[2], - ds.domain_right_edge[2], - ds.domain_dimensions[2]+1) -z = (zp[1:] + zp[:-1]).value / 2 - -utot = soln['x_velocity'].value -vtot = soln['y_velocity'].value -wtot = soln['z_velocity'].value - -U = np.mean(utot,axis=(0,1)) -V = np.mean(vtot,axis=(0,1)) -W = np.mean(wtot,axis=(0,1)) -u = utot - U[np.newaxis,np.newaxis,:] -v = vtot - V[np.newaxis,np.newaxis,:] -w = wtot - W[np.newaxis,np.newaxis,:] - -uu = np.var(u, axis=(0,1)) -vv = np.var(v, axis=(0,1)) -ww = np.var(w, axis=(0,1)) - -uw = np.mean(u*w, axis=(0,1)) -vw = np.mean(v*w, axis=(0,1)) -uv = np.mean(u*v, axis=(0,1)) - -fig,ax = plt.subplots(nrows=3,ncols=3,sharey=True,figsize=(8.5,11)) -ax[0,0].plot(U,z) -ax[0,1].plot(V,z) -ax[0,2].plot(W,z) -ax[0,0].set_xlabel(r'$\langle U \rangle$ [m/s]') -ax[0,1].set_xlabel(r'$\langle V \rangle$ [m/s]') -ax[0,2].set_xlabel(r'$\langle W \rangle$ [m/s]') -ax[1,0].plot(uu,z) -ax[1,1].plot(vv,z) -ax[1,2].plot(ww,z) -ax[1,0].set_xlabel(r"$\langle u'u' \rangle$ [m/s]") -ax[1,1].set_xlabel(r"$\langle v'v' \rangle$ [m/s]") -ax[1,2].set_xlabel(r"$\langle w'w' \rangle$ [m/s]") -ax[2,0].plot(uw,z) -ax[2,1].plot(vw,z) -ax[2,2].plot(uv,z) -ax[2,0].set_xlabel(r"$\langle u'w' \rangle$ [m/s]") -ax[2,1].set_xlabel(r"$\langle v'w' \rangle$ [m/s]") -ax[2,2].set_xlabel(r"$\langle u'v' \rangle$ [m/s]") -ax[0,0].set_ylabel('$z$ [m]') -ax[1,0].set_ylabel('$z$ [m]') -ax[2,0].set_ylabel('$z$ [m]') -ax[0,0].set_ylim((ds.domain_left_edge[2], ds.domain_right_edge[2])) -for axi in ax.ravel(): - axi.grid() - -fig.savefig('profiles.png',bbox_inches='tight') - -plt.show() - diff --git a/Exec/Fitch/CMakeLists.txt b/Exec/Fitch/CMakeLists.txt deleted file mode 100644 index 2e6da768c..000000000 --- a/Exec/Fitch/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(erf_exe_name erf_fitch) - -add_executable(${erf_exe_name} "") -target_sources(${erf_exe_name} - PRIVATE - prob.cpp -) - -target_include_directories(${erf_exe_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -include(${CMAKE_SOURCE_DIR}/CMake/BuildERFExe.cmake) -build_erf_exe(${erf_exe_name}) diff --git a/Exec/Fitch/GNUmakefile b/Exec/Fitch/GNUmakefile deleted file mode 100644 index 64c279f6a..000000000 --- a/Exec/Fitch/GNUmakefile +++ /dev/null @@ -1,37 +0,0 @@ -# AMReX -COMP = gnu -PRECISION = DOUBLE - -# Profiling -PROFILE = FALSE -TINY_PROFILE = TRUE -COMM_PROFILE = FALSE -TRACE_PROFILE = FALSE -MEM_PROFILE = FALSE -USE_GPROF = FALSE - -# Performance -USE_MPI = TRUE -USE_OMP = FALSE - -USE_CUDA = FALSE -USE_HIP = FALSE -USE_SYCL = FALSE - -# Debugging -DEBUG = FALSE - -TEST = TRUE -USE_ASSERTION = TRUE - -USE_WINDFARM = TRUE - - -#USE_POISSON_SOLVE = TRUE - -# GNU Make -Bpack := ./Make.package -Blocs := . -ERF_HOME := ../.. -ERF_PROBLEM_DIR = $(ERF_HOME)/Exec/Fitch -include $(ERF_HOME)/Exec/Make.ERF diff --git a/Exec/Fitch/Make.package b/Exec/Fitch/Make.package deleted file mode 100644 index aeacb72f0..000000000 --- a/Exec/Fitch/Make.package +++ /dev/null @@ -1,2 +0,0 @@ -CEXE_headers += prob.H -CEXE_sources += prob.cpp diff --git a/Exec/Fitch/README b/Exec/Fitch/README deleted file mode 100644 index 2504f4de7..000000000 --- a/Exec/Fitch/README +++ /dev/null @@ -1,6 +0,0 @@ -This problem setup is for simulation of the Atmospheric Boundary Layer (ABL) -using one of two turbulence schemes (Smagorinsky or Deardorff) and the bottom -boundary condition possibly specified by Monin Obukhov Similarity Theory (MOST). - -This version of the ABL problem initializes the data using a hydrostatic profile -with random perturbations in velocity and potential temperature. diff --git a/Exec/Fitch/inputs_Fitch b/Exec/Fitch/inputs_Fitch deleted file mode 100644 index 9d59f4298..000000000 --- a/Exec/Fitch/inputs_Fitch +++ /dev/null @@ -1,74 +0,0 @@ -# ------------------ INPUTS TO MAIN PROGRAM ------------------- -max_step = 1800000 - -amrex.fpe_trap_invalid = 1 - -fabarray.mfiter_tile_size = 1024 1024 1024 - -# PROBLEM SIZE & GEOMETRY -geometry.prob_extent = 18000 18000 1000 -amr.n_cell = 32 32 64 - -#erf.grid_stretching_ratio = 1.025 -#erf.initial_dz = 16.0 - -geometry.is_periodic = 0 0 0 - -# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) -#zlo.type = "MOST" -#erf.most.z0 = 0.1 -#erf.most.zref = 8.0 - -zlo.type = "SlipWall" -zhi.type = "SlipWall" - -xlo.type = "Outflow" -xhi.type = "Outflow" -ylo.type = "Outflow" -yhi.type = "Outflow" - -# TIME STEP CONTROL -erf.fixed_dt = 0.005 # fixed time step depending on grid resolution - -# DIAGNOSTICS & VERBOSITY -erf.sum_interval = 1 # timesteps between computing mass -erf.v = 1 # verbosity in ERF.cpp -amr.v = 1 # verbosity in Amr.cpp - -# REFINEMENT / REGRIDDING -amr.max_level = 0 # maximum level number allowed - -# CHECKPOINT FILES -erf.check_file = chk # root name of checkpoint file -erf.check_int = -1 # number of timesteps between checkpoints - -# PLOTFILES -erf.plot_file_1 = plt # prefix of plotfile name -erf.plot_int_1 = 1000 # number of timesteps between plotfiles -erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE - -# SOLVER CHOICE -erf.alpha_T = 0.0 -erf.alpha_C = 1.0 -erf.use_gravity = false - -erf.molec_diff_type = "None" -erf.les_type = "None" -erf.Cs = 1.5 -erf.dynamicViscosity = 0.0 - -erf.pbl_type = "None" - -erf.init_type = "uniform" - -erf.windfarm_type = "Fitch" - -# PROBLEM PARAMETERS -prob.rho_0 = 1.0 -prob.A_0 = 1.0 - -prob.U_0 = 10.0 -prob.V_0 = 10.0 -prob.W_0 = 0.0 -prob.T_0 = 300.0 - diff --git a/Exec/Fitch/inputs_Fitch_LargeDomain b/Exec/Fitch/inputs_Fitch_LargeDomain deleted file mode 100644 index fc27a8b05..000000000 --- a/Exec/Fitch/inputs_Fitch_LargeDomain +++ /dev/null @@ -1,76 +0,0 @@ -# ------------------ INPUTS TO MAIN PROGRAM ------------------- -max_step = 10 - -amrex.fpe_trap_invalid = 1 - -fabarray.mfiter_tile_size = 1024 1024 1024 - -# PROBLEM SIZE & GEOMETRY -erf.windfarm_type = "Fitch" -erf.latitude_lo = 35.0 -erf.longitude_lo = -100.0 -geometry.prob_extent = 534000 389000 20000 -amr.n_cell = 32 32 64 - -#erf.grid_stretching_ratio = 1.025 -#erf.initial_dz = 16.0 - -geometry.is_periodic = 0 0 0 - -# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) -#zlo.type = "MOST" -#erf.most.z0 = 0.1 -#erf.most.zref = 8.0 - -zlo.type = "SlipWall" -zhi.type = "SlipWall" - -xlo.type = "Outflow" -xhi.type = "Outflow" -ylo.type = "Outflow" -yhi.type = "Outflow" - -# TIME STEP CONTROL -erf.fixed_dt = 0.005 # fixed time step depending on grid resolution - -# DIAGNOSTICS & VERBOSITY -erf.sum_interval = 1 # timesteps between computing mass -erf.v = 1 # verbosity in ERF.cpp -amr.v = 1 # verbosity in Amr.cpp - -# REFINEMENT / REGRIDDING -amr.max_level = 0 # maximum level number allowed - -# CHECKPOINT FILES -erf.check_file = chk # root name of checkpoint file -erf.check_int = -1 # number of timesteps between checkpoints - -# PLOTFILES -erf.plot_file_1 = plt # prefix of plotfile name -erf.plot_int_1 = 1000 # number of timesteps between plotfiles -erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb - -# SOLVER CHOICE -erf.alpha_T = 0.0 -erf.alpha_C = 1.0 -erf.use_gravity = false - -erf.molec_diff_type = "None" -erf.les_type = "None" -erf.Cs = 1.5 -erf.dynamicViscosity = 0.0 - -erf.pbl_type = "None" - -erf.init_type = "uniform" - - -# PROBLEM PARAMETERS -prob.rho_0 = 1.0 -prob.A_0 = 1.0 - -prob.U_0 = 10.0 -prob.V_0 = 10.0 -prob.W_0 = 0.0 -prob.T_0 = 300.0 - diff --git a/Exec/Fitch/inputs_Fitch_Testing b/Exec/Fitch/inputs_Fitch_Testing deleted file mode 100644 index 8514c9cb7..000000000 --- a/Exec/Fitch/inputs_Fitch_Testing +++ /dev/null @@ -1,79 +0,0 @@ -# ------------------ INPUTS TO MAIN PROGRAM ------------------- -max_step = 200 - -amrex.fpe_trap_invalid = 1 - -fabarray.mfiter_tile_size = 1024 1024 1024 - -# PROBLEM SIZE & GEOMETRY -erf.latitude_lo = 35.0 -erf.longitude_lo = -100.0 -geometry.prob_extent = 200150 202637 1000 -amr.n_cell = 50 50 40 - -#erf.grid_stretching_ratio = 1.025 -#erf.initial_dz = 16.0 - -geometry.is_periodic = 0 0 0 - -# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) -#zlo.type = "MOST" -#erf.most.z0 = 0.1 -#erf.most.zref = 8.0 - -zlo.type = "SlipWall" -zhi.type = "SlipWall" - -xlo.type = "Outflow" -xhi.type = "Outflow" -ylo.type = "Outflow" -yhi.type = "Outflow" - -# TIME STEP CONTROL -erf.use_native_mri = 1 -erf.fixed_dt = 0.0025 # fixed time step depending on grid resolution -#erf.fixed_fast_dt = 0.0025 - -# DIAGNOSTICS & VERBOSITY -erf.sum_interval = 1 # timesteps between computing mass -erf.v = 1 # verbosity in ERF.cpp -amr.v = 1 # verbosity in Amr.cpp - -# REFINEMENT / REGRIDDING -amr.max_level = 0 # maximum level number allowed - -# CHECKPOINT FILES -erf.check_file = chk # root name of checkpoint file -erf.check_int = 100 # number of timesteps between checkpoints -#erf.restart = chk00100 - -# PLOTFILES -erf.plot_file_1 = plt # prefix of plotfile name -erf.plot_int_1 = 10000 # number of timesteps between plotfiles -erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE - -# SOLVER CHOICE -erf.alpha_T = 0.0 -erf.alpha_C = 1.0 -erf.use_gravity = false - -erf.molec_diff_type = "None" -erf.les_type = "None" -erf.Cs = 1.5 -erf.dynamicViscosity = 0.0 - -erf.pbl_type = "None" - -erf.init_type = "uniform" - -erf.windfarm_type = "Fitch" - -# PROBLEM PARAMETERS -prob.rho_0 = 1.0 -prob.A_0 = 1.0 - -prob.U_0 = 10.0 -prob.V_0 = 10.0 -prob.W_0 = 0.0 -prob.T_0 = 300.0 - diff --git a/Exec/Fitch/inputs_Fitch_WindFarm b/Exec/Fitch/inputs_Fitch_WindFarm deleted file mode 100644 index e901933cb..000000000 --- a/Exec/Fitch/inputs_Fitch_WindFarm +++ /dev/null @@ -1,78 +0,0 @@ -# ------------------ INPUTS TO MAIN PROGRAM ------------------- -max_step = 100000 - -amrex.fpe_trap_invalid = 1 - -fabarray.mfiter_tile_size = 1024 1024 1024 - -# PROBLEM SIZE & GEOMETRY -erf.latitude_lo = 35.0 -erf.longitude_lo = -100.0 -geometry.prob_extent = 200150 202637 1000 -amr.n_cell = 50 50 40 - -#erf.grid_stretching_ratio = 1.025 -#erf.initial_dz = 16.0 - -geometry.is_periodic = 0 0 0 - -# MOST BOUNDARY (DEFAULT IS ADIABATIC FOR THETA) -#zlo.type = "MOST" -#erf.most.z0 = 0.1 -#erf.most.zref = 8.0 - -zlo.type = "SlipWall" -zhi.type = "SlipWall" -xlo.type = "Outflow" -xhi.type = "Outflow" -ylo.type = "Outflow" -yhi.type = "Outflow" - -# TIME STEP CONTROL -erf.use_native_mri = 1 -erf.fixed_dt = 0.25 # fixed time step depending on grid resolution -#erf.fixed_fast_dt = 0.0025 - -# DIAGNOSTICS & VERBOSITY -erf.sum_interval = 1 # timesteps between computing mass -erf.v = 1 # verbosity in ERF.cpp -amr.v = 1 # verbosity in Amr.cpp - -# REFINEMENT / REGRIDDING -amr.max_level = 0 # maximum level number allowed - -# CHECKPOINT FILES -erf.check_file = chk # root name of checkpoint file -erf.check_int = 10000 # number of timesteps between checkpoints -#erf.restart = chk02000 - -# PLOTFILES -erf.plot_file_1 = plt # prefix of plotfile name -erf.plot_int_1 = 1000 # number of timesteps between plotfiles -erf.plot_vars_1 = density rhoadv_0 x_velocity y_velocity z_velocity pressure temp theta QKE num_turb vorticity - -# SOLVER CHOICE -erf.alpha_T = 0.0 -erf.alpha_C = 1.0 -erf.use_gravity = false - -erf.molec_diff_type = "ConstantAlpha" -erf.les_type = "None" -erf.Cs = 1.5 -erf.dynamicViscosity = 100.0 - -erf.pbl_type = "None" - -erf.init_type = "uniform" - -erf.windfarm_type = "Fitch" - -# PROBLEM PARAMETERS -prob.rho_0 = 1.0 -prob.A_0 = 1.0 - -prob.U_0 = 10.0 -prob.V_0 = 10.0 -prob.W_0 = 0.0 -prob.T_0 = 300.0 - diff --git a/Exec/Fitch/plot_profiles.py b/Exec/Fitch/plot_profiles.py deleted file mode 100644 index 50ab6f76c..000000000 --- a/Exec/Fitch/plot_profiles.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -import os -import glob -import numpy as np -import matplotlib.pyplot as plt -import yt - -pltfiles = [pltfile for pltfile in glob.glob('plt*') - if os.path.isdir(pltfile) and not ('old' in pltfile)] -nsteps = [int(pltfile[3:]) for pltfile in pltfiles] -latestoutput = pltfiles[np.argmax(nsteps)] -print(latestoutput) - -ds = yt.load(latestoutput) - -soln = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -zp = np.linspace(ds.domain_left_edge[2], - ds.domain_right_edge[2], - ds.domain_dimensions[2]+1) -z = (zp[1:] + zp[:-1]).value / 2 - -utot = soln['x_velocity'].value -vtot = soln['y_velocity'].value -wtot = soln['z_velocity'].value - -U = np.mean(utot,axis=(0,1)) -V = np.mean(vtot,axis=(0,1)) -W = np.mean(wtot,axis=(0,1)) -u = utot - U[np.newaxis,np.newaxis,:] -v = vtot - V[np.newaxis,np.newaxis,:] -w = wtot - W[np.newaxis,np.newaxis,:] - -uu = np.var(u, axis=(0,1)) -vv = np.var(v, axis=(0,1)) -ww = np.var(w, axis=(0,1)) - -uw = np.mean(u*w, axis=(0,1)) -vw = np.mean(v*w, axis=(0,1)) -uv = np.mean(u*v, axis=(0,1)) - -fig,ax = plt.subplots(nrows=3,ncols=3,sharey=True,figsize=(8.5,11)) -ax[0,0].plot(U,z) -ax[0,1].plot(V,z) -ax[0,2].plot(W,z) -ax[0,0].set_xlabel(r'$\langle U \rangle$ [m/s]') -ax[0,1].set_xlabel(r'$\langle V \rangle$ [m/s]') -ax[0,2].set_xlabel(r'$\langle W \rangle$ [m/s]') -ax[1,0].plot(uu,z) -ax[1,1].plot(vv,z) -ax[1,2].plot(ww,z) -ax[1,0].set_xlabel(r"$\langle u'u' \rangle$ [m/s]") -ax[1,1].set_xlabel(r"$\langle v'v' \rangle$ [m/s]") -ax[1,2].set_xlabel(r"$\langle w'w' \rangle$ [m/s]") -ax[2,0].plot(uw,z) -ax[2,1].plot(vw,z) -ax[2,2].plot(uv,z) -ax[2,0].set_xlabel(r"$\langle u'w' \rangle$ [m/s]") -ax[2,1].set_xlabel(r"$\langle v'w' \rangle$ [m/s]") -ax[2,2].set_xlabel(r"$\langle u'v' \rangle$ [m/s]") -ax[0,0].set_ylabel('$z$ [m]') -ax[1,0].set_ylabel('$z$ [m]') -ax[2,0].set_ylabel('$z$ [m]') -ax[0,0].set_ylim((ds.domain_left_edge[2], ds.domain_right_edge[2])) -for axi in ax.ravel(): - axi.grid() - -fig.savefig('profiles.png',bbox_inches='tight') - -plt.show() - diff --git a/Exec/Fitch/prob.H b/Exec/Fitch/prob.H deleted file mode 100644 index aa0c28435..000000000 --- a/Exec/Fitch/prob.H +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _PROB_H_ -#define _PROB_H_ - -#include - -#include "AMReX_REAL.H" - -#include "prob_common.H" - -struct ProbParm : ProbParmDefaults { - amrex::Real rho_0 = 0.0; - amrex::Real T_0 = 0.0; - amrex::Real A_0 = 1.0; - amrex::Real QKE_0 = 0.1; - - amrex::Real U_0 = 0.0; - amrex::Real V_0 = 0.0; - amrex::Real W_0 = 0.0; - - // random initial perturbations (legacy code) - amrex::Real U_0_Pert_Mag = 0.0; - amrex::Real V_0_Pert_Mag = 0.0; - amrex::Real W_0_Pert_Mag = 0.0; - amrex::Real T_0_Pert_Mag = 0.0; // perturbation to rho*Theta - - // divergence-free initial perturbations - amrex::Real pert_deltaU = 0.0; - amrex::Real pert_deltaV = 0.0; - amrex::Real pert_periods_U = 5.0; - amrex::Real pert_periods_V = 5.0; - amrex::Real pert_ref_height = 100.0; - - // rayleigh damping - amrex::Real dampcoef = 0.2; // inverse time scale [1/s] - amrex::Real zdamp = 500.0; // damping depth [m] from model top - - // helper vars - amrex::Real aval; - amrex::Real bval; - amrex::Real ufac; - amrex::Real vfac; -}; // namespace ProbParm - -class Problem : public ProblemBase -{ -public: - Problem(const amrex::Real* problo, const amrex::Real* probhi); - -#include "Prob/init_constant_density_hse.H" -#include "Prob/init_rayleigh_damping.H" - - void init_custom_pert ( - const amrex::Box& bx, - const amrex::Box& xbx, - const amrex::Box& ybx, - const amrex::Box& zbx, - amrex::Array4 const& state, - amrex::Array4 const& state_pert, - amrex::Array4 const& x_vel_pert, - amrex::Array4 const& y_vel_pert, - amrex::Array4 const& z_vel_pert, - amrex::Array4 const& r_hse, - amrex::Array4 const& p_hse, - amrex::Array4 const& z_nd, - amrex::Array4 const& z_cc, - amrex::GeometryData const& geomdata, - amrex::Array4 const& mf_m, - amrex::Array4 const& mf_u, - amrex::Array4 const& mf_v, - const SolverChoice& sc) override; - -protected: - std::string name() override { return "ABL"; } - -private: - ProbParm parms; -}; - -#endif diff --git a/Exec/Fitch/prob.cpp b/Exec/Fitch/prob.cpp deleted file mode 100644 index 736211998..000000000 --- a/Exec/Fitch/prob.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include "prob.H" -#include "AMReX_Random.H" - -using namespace amrex; - -std::unique_ptr -amrex_probinit(const amrex_real* problo, const amrex_real* probhi) -{ - return std::make_unique(problo, probhi); -} - -Problem::Problem(const amrex::Real* problo, const amrex::Real* probhi) -{ - // Parse params - ParmParse pp("prob"); - pp.query("rho_0", parms.rho_0); - pp.query("T_0", parms.T_0); - pp.query("A_0", parms.A_0); - pp.query("QKE_0", parms.QKE_0); - - pp.query("U_0", parms.U_0); - pp.query("V_0", parms.V_0); - pp.query("W_0", parms.W_0); - pp.query("U_0_Pert_Mag", parms.U_0_Pert_Mag); - pp.query("V_0_Pert_Mag", parms.V_0_Pert_Mag); - pp.query("W_0_Pert_Mag", parms.W_0_Pert_Mag); - pp.query("T_0_Pert_Mag", parms.T_0_Pert_Mag); - - pp.query("pert_deltaU", parms.pert_deltaU); - pp.query("pert_deltaV", parms.pert_deltaV); - pp.query("pert_periods_U", parms.pert_periods_U); - pp.query("pert_periods_V", parms.pert_periods_V); - pp.query("pert_ref_height", parms.pert_ref_height); - parms.aval = parms.pert_periods_U * 2.0 * PI / (probhi[1] - problo[1]); - parms.bval = parms.pert_periods_V * 2.0 * PI / (probhi[0] - problo[0]); - parms.ufac = parms.pert_deltaU * std::exp(0.5) / parms.pert_ref_height; - parms.vfac = parms.pert_deltaV * std::exp(0.5) / parms.pert_ref_height; - - pp.query("dampcoef", parms.dampcoef); - pp.query("zdamp", parms.zdamp); - - init_base_parms(parms.rho_0, parms.T_0); -} - -void -Problem::init_custom_pert( - const amrex::Box& bx, - const amrex::Box& xbx, - const amrex::Box& ybx, - const amrex::Box& zbx, - amrex::Array4 const& /*state*/, - amrex::Array4 const& state_pert, - amrex::Array4 const& x_vel_pert, - amrex::Array4 const& y_vel_pert, - amrex::Array4 const& z_vel_pert, - amrex::Array4 const& /*r_hse*/, - amrex::Array4 const& /*p_hse*/, - amrex::Array4 const& /*z_nd*/, - amrex::Array4 const& /*z_cc*/, - amrex::GeometryData const& geomdata, - amrex::Array4 const& /*mf_m*/, - amrex::Array4 const& /*mf_u*/, - amrex::Array4 const& /*mf_v*/, - const SolverChoice& sc) -{ - const bool use_moisture = (sc.moisture_type != MoistureType::None); - - ParallelForRNG(bx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { - // Geometry - const Real* prob_lo = geomdata.ProbLo(); - const Real* prob_hi = geomdata.ProbHi(); - const Real* dx = geomdata.CellSize(); - const Real x = prob_lo[0] + (i + 0.5) * dx[0]; - const Real y = prob_lo[1] + (j + 0.5) * dx[1]; - const Real z = prob_lo[2] + (k + 0.5) * dx[2]; - - // Define a point (xc,yc,zc) at the center of the domain - const Real xc = 0.5 * (prob_lo[0] + prob_hi[0]); - const Real yc = 0.5 * (prob_lo[1] + prob_hi[1]); - const Real zc = 0.5 * (prob_lo[2] + prob_hi[2]); - - const Real r = std::sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc)); - - // Add temperature perturbations - if ((z <= parms.pert_ref_height) && (parms.T_0_Pert_Mag != 0.0)) { - Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 - state_pert(i, j, k, RhoTheta_comp) = (rand_double*2.0 - 1.0)*parms.T_0_Pert_Mag; - } - - // Set scalar = A_0*exp(-10r^2), where r is distance from center of domain - state_pert(i, j, k, RhoScalar_comp) = parms.A_0 * exp(-10.*r*r); - - // Set an initial value for QKE - state_pert(i, j, k, RhoQKE_comp) = parms.QKE_0; - - if (use_moisture) { - state_pert(i, j, k, RhoQ1_comp) = 0.0; - state_pert(i, j, k, RhoQ2_comp) = 0.0; - } - }); - - // Set the x-velocity - ParallelForRNG(xbx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { - const Real* prob_lo = geomdata.ProbLo(); - const Real* dx = geomdata.CellSize(); - const Real y = prob_lo[1] + (j + 0.5) * dx[1]; - const Real z = prob_lo[2] + (k + 0.5) * dx[2]; - - // Set the x-velocity - x_vel_pert(i, j, k) = parms.U_0; - if ((z <= parms.pert_ref_height) && (parms.U_0_Pert_Mag != 0.0)) - { - Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 - Real x_vel_prime = (rand_double*2.0 - 1.0)*parms.U_0_Pert_Mag; - x_vel_pert(i, j, k) += x_vel_prime; - } - if (parms.pert_deltaU != 0.0) - { - const amrex::Real yl = y - prob_lo[1]; - const amrex::Real zl = z / parms.pert_ref_height; - const amrex::Real damp = std::exp(-0.5 * zl * zl); - x_vel_pert(i, j, k) += parms.ufac * damp * z * std::cos(parms.aval * yl); - } - }); - - // Set the y-velocity - ParallelForRNG(ybx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { - const Real* prob_lo = geomdata.ProbLo(); - const Real* dx = geomdata.CellSize(); - const Real x = prob_lo[0] + (i + 0.5) * dx[0]; - const Real z = prob_lo[2] + (k + 0.5) * dx[2]; - - // Set the y-velocity - y_vel_pert(i, j, k) = parms.V_0; - if ((z <= parms.pert_ref_height) && (parms.V_0_Pert_Mag != 0.0)) - { - Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 - Real y_vel_prime = (rand_double*2.0 - 1.0)*parms.V_0_Pert_Mag; - y_vel_pert(i, j, k) += y_vel_prime; - } - if (parms.pert_deltaV != 0.0) - { - const amrex::Real xl = x - prob_lo[0]; - const amrex::Real zl = z / parms.pert_ref_height; - const amrex::Real damp = std::exp(-0.5 * zl * zl); - y_vel_pert(i, j, k) += parms.vfac * damp * z * std::cos(parms.bval * xl); - } - }); - - // Set the z-velocity - ParallelForRNG(zbx, [=, parms=parms] AMREX_GPU_DEVICE(int i, int j, int k, const amrex::RandomEngine& engine) noexcept { - const int dom_lo_z = geomdata.Domain().smallEnd()[2]; - const int dom_hi_z = geomdata.Domain().bigEnd()[2]; - - // Set the z-velocity - if (k == dom_lo_z || k == dom_hi_z+1) - { - z_vel_pert(i, j, k) = 0.0; - } - else if (parms.W_0_Pert_Mag != 0.0) - { - Real rand_double = amrex::Random(engine); // Between 0.0 and 1.0 - Real z_vel_prime = (rand_double*2.0 - 1.0)*parms.W_0_Pert_Mag; - z_vel_pert(i, j, k) = parms.W_0 + z_vel_prime; - } - }); -} diff --git a/Exec/Fitch/wind-turbine-1.tbl b/Exec/Fitch/wind-turbine-1.tbl deleted file mode 100644 index 6d678c3d1..000000000 --- a/Exec/Fitch/wind-turbine-1.tbl +++ /dev/null @@ -1,24 +0,0 @@ -22 -75. 85. 0.130 2.0 -4. 0.805 50.0 -5. 0.805 150.0 -6. 0.805 280.0 -7. 0.805 460.0 -8. 0.805 700.0 -9. 0.805 990.0 -10. 0.790 1300.0 -11. 0.740 1600.0 -12. 0.700 1850.0 -13. 0.400 1950.0 -14. 0.300 1990.0 -15. 0.250 1995.0 -16. 0.200 2000.0 -17. 0.160 2000.0 -18. 0.140 2000.0 -19. 0.120 2000.0 -20. 0.100 2000.0 -21. 0.080 2000.0 -22. 0.070 2000.0 -23. 0.060 2000.0 -24. 0.055 2000.0 -25. 0.050 2000.0 diff --git a/Exec/Fitch/windturbines.txt b/Exec/Fitch/windturbines.txt deleted file mode 100644 index 85d189cdf..000000000 --- a/Exec/Fitch/windturbines.txt +++ /dev/null @@ -1,25 +0,0 @@ -35.863963964 -98.9228 1 -35.881981982 -98.9228 1 -35.9 -98.9228 1 -35.918018018 -98.9228 1 -35.936036036 -98.9228 1 -35.863963964 -98.9004 1 -35.881981982 -98.9004 1 -35.9 -98.9004 1 -35.918018018 -98.9004 1 -35.936036036 -98.9004 1 -35.863963964 -98.878 1 -35.881981982 -98.878 1 -35.9 -98.878 1 -35.918018018 -98.878 1 -35.936036036 -98.878 1 -35.863963964 -98.8556 1 -35.881981982 -98.8556 1 -35.9 -98.8556 1 -35.918018018 -98.8556 1 -35.936036036 -98.8556 1 -35.863963964 -98.8332 1 -35.881981982 -98.8332 1 -35.9 -98.8332 1 -35.918018018 -98.8332 1 -35.936036036 -98.8332 1 diff --git a/Exec/Fitch/windturbines.txt_LargeDomain b/Exec/Fitch/windturbines.txt_LargeDomain deleted file mode 100644 index 586e94b81..000000000 --- a/Exec/Fitch/windturbines.txt_LargeDomain +++ /dev/null @@ -1,30 +0,0 @@ -36.732 -97.128 1 -36.824 -97.367 1 -36.967 -96.754 1 -36.607 -96.846 1 -36.719 -97.249 1 -36.889 -97.031 1 -36.621 -96.932 1 -36.752 -96.788 1 -36.855 -97.421 1 -36.694 -96.656 1 -36.579 -97.223 1 -36.912 -97.379 1 -36.721 -96.815 1 -36.685 -97.437 1 -36.781 -97.049 1 -36.936 -97.203 1 -36.541 -96.791 1 -36.655 -97.284 1 -36.798 -96.695 1 -36.887 -96.956 1 -36.633 -96.716 1 -36.912 -96.813 1 -36.725 -96.579 1 -36.594 -97.184 1 -36.902 -97.354 1 -36.628 -96.871 1 -36.762 -97.428 1 -36.811 -97.285 1 -36.549 -97.492 1 -36.642 -96.673 1 diff --git a/Exec/Fitch/windturbines_WindFarm.txt b/Exec/Fitch/windturbines_WindFarm.txt deleted file mode 100644 index 4c68601f6..000000000 --- a/Exec/Fitch/windturbines_WindFarm.txt +++ /dev/null @@ -1,97 +0,0 @@ -35.7828828829 -99.0168 1 -35.8219219219 -99.0168 1 -35.860960961 -99.0168 1 -35.9 -99.0168 1 -35.939039039 -99.0168 1 -35.9780780781 -99.0168 1 -36.0171171171 -99.0168 1 -35.7828828829 -98.9705333333 1 -35.8219219219 -98.9705333333 1 -35.860960961 -98.9705333333 1 -35.9 -98.9705333333 1 -35.939039039 -98.9705333333 1 -35.9780780781 -98.9705333333 1 -36.0171171171 -98.9705333333 1 -35.7828828829 -98.9242666667 1 -35.8219219219 -98.9242666667 1 -35.860960961 -98.9242666667 1 -35.9 -98.9242666667 1 -35.939039039 -98.9242666667 1 -35.9780780781 -98.9242666667 1 -36.0171171171 -98.9242666667 1 -35.7828828829 -98.878 1 -35.8219219219 -98.878 1 -35.860960961 -98.878 1 -35.9 -98.878 1 -35.939039039 -98.878 1 -35.9780780781 -98.878 1 -36.0171171171 -98.878 1 -35.7828828829 -98.8317333333 1 -35.8219219219 -98.8317333333 1 -35.860960961 -98.8317333333 1 -35.9 -98.8317333333 1 -35.939039039 -98.8317333333 1 -35.9780780781 -98.8317333333 1 -36.0171171171 -98.8317333333 1 -35.7828828829 -98.7854666667 1 -35.8219219219 -98.7854666667 1 -35.860960961 -98.7854666667 1 -35.9 -98.7854666667 1 -35.939039039 -98.7854666667 1 -35.9780780781 -98.7854666667 1 -36.0171171171 -98.7854666667 1 -35.7828828829 -98.7392 1 -35.8219219219 -98.7392 1 -35.860960961 -98.7392 1 -35.9 -98.7392 1 -35.939039039 -98.7392 1 -35.9780780781 -98.7392 1 -36.0171171171 -98.7392 1 -35.463963964 -98.2228 1 -35.487987988 -98.2228 1 -35.512012012 -98.2228 1 -35.536036036 -98.2228 1 -35.463963964 -98.1929333333 1 -35.487987988 -98.1929333333 1 -35.512012012 -98.1929333333 1 -35.536036036 -98.1929333333 1 -35.463963964 -98.1630666667 1 -35.487987988 -98.1630666667 1 -35.512012012 -98.1630666667 1 -35.536036036 -98.1630666667 1 -35.463963964 -98.1332 1 -35.487987988 -98.1332 1 -35.512012012 -98.1332 1 -35.536036036 -98.1332 1 -36.363963964 -99.4228 1 -36.387987988 -99.4228 1 -36.412012012 -99.4228 1 -36.436036036 -99.4228 1 -36.363963964 -99.3929333333 1 -36.387987988 -99.3929333333 1 -36.412012012 -99.3929333333 1 -36.436036036 -99.3929333333 1 -36.363963964 -99.3630666667 1 -36.387987988 -99.3630666667 1 -36.412012012 -99.3630666667 1 -36.436036036 -99.3630666667 1 -36.363963964 -99.3332 1 -36.387987988 -99.3332 1 -36.412012012 -99.3332 1 -36.436036036 -99.3332 1 -35.263963964 -99.5228 1 -35.287987988 -99.5228 1 -35.312012012 -99.5228 1 -35.336036036 -99.5228 1 -35.263963964 -99.4929333333 1 -35.287987988 -99.4929333333 1 -35.312012012 -99.4929333333 1 -35.336036036 -99.4929333333 1 -35.263963964 -99.4630666667 1 -35.287987988 -99.4630666667 1 -35.312012012 -99.4630666667 1 -35.336036036 -99.4630666667 1 -35.263963964 -99.4332 1 -35.287987988 -99.4332 1 -35.312012012 -99.4332 1 -35.336036036 -99.4332 1 diff --git a/Exec/SimpleActuatorDisk/plot_profiles.py b/Exec/SimpleActuatorDisk/plot_profiles.py deleted file mode 100644 index 50ab6f76c..000000000 --- a/Exec/SimpleActuatorDisk/plot_profiles.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -import os -import glob -import numpy as np -import matplotlib.pyplot as plt -import yt - -pltfiles = [pltfile for pltfile in glob.glob('plt*') - if os.path.isdir(pltfile) and not ('old' in pltfile)] -nsteps = [int(pltfile[3:]) for pltfile in pltfiles] -latestoutput = pltfiles[np.argmax(nsteps)] -print(latestoutput) - -ds = yt.load(latestoutput) - -soln = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions) -zp = np.linspace(ds.domain_left_edge[2], - ds.domain_right_edge[2], - ds.domain_dimensions[2]+1) -z = (zp[1:] + zp[:-1]).value / 2 - -utot = soln['x_velocity'].value -vtot = soln['y_velocity'].value -wtot = soln['z_velocity'].value - -U = np.mean(utot,axis=(0,1)) -V = np.mean(vtot,axis=(0,1)) -W = np.mean(wtot,axis=(0,1)) -u = utot - U[np.newaxis,np.newaxis,:] -v = vtot - V[np.newaxis,np.newaxis,:] -w = wtot - W[np.newaxis,np.newaxis,:] - -uu = np.var(u, axis=(0,1)) -vv = np.var(v, axis=(0,1)) -ww = np.var(w, axis=(0,1)) - -uw = np.mean(u*w, axis=(0,1)) -vw = np.mean(v*w, axis=(0,1)) -uv = np.mean(u*v, axis=(0,1)) - -fig,ax = plt.subplots(nrows=3,ncols=3,sharey=True,figsize=(8.5,11)) -ax[0,0].plot(U,z) -ax[0,1].plot(V,z) -ax[0,2].plot(W,z) -ax[0,0].set_xlabel(r'$\langle U \rangle$ [m/s]') -ax[0,1].set_xlabel(r'$\langle V \rangle$ [m/s]') -ax[0,2].set_xlabel(r'$\langle W \rangle$ [m/s]') -ax[1,0].plot(uu,z) -ax[1,1].plot(vv,z) -ax[1,2].plot(ww,z) -ax[1,0].set_xlabel(r"$\langle u'u' \rangle$ [m/s]") -ax[1,1].set_xlabel(r"$\langle v'v' \rangle$ [m/s]") -ax[1,2].set_xlabel(r"$\langle w'w' \rangle$ [m/s]") -ax[2,0].plot(uw,z) -ax[2,1].plot(vw,z) -ax[2,2].plot(uv,z) -ax[2,0].set_xlabel(r"$\langle u'w' \rangle$ [m/s]") -ax[2,1].set_xlabel(r"$\langle v'w' \rangle$ [m/s]") -ax[2,2].set_xlabel(r"$\langle u'v' \rangle$ [m/s]") -ax[0,0].set_ylabel('$z$ [m]') -ax[1,0].set_ylabel('$z$ [m]') -ax[2,0].set_ylabel('$z$ [m]') -ax[0,0].set_ylim((ds.domain_left_edge[2], ds.domain_right_edge[2])) -for axi in ax.ravel(): - axi.grid() - -fig.savefig('profiles.png',bbox_inches='tight') - -plt.show() - diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 5181f7950..e747dfd0a 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -98,13 +98,11 @@ protected: template void SetModel () { - std::cout << "Setting the wind farm model with " << m_windfarm_model.size() << " levels " << "\n"; for (int lev(0); lev(); } } - private: amrex::Vector> m_windfarm_model; /*!< windfarm model */ }; From c76f1042a84cce57ac52b8e151584f90d2b26245 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 17:44:29 -0700 Subject: [PATCH 12/28] Adding ifdef to correct compilation error --- Source/ERF.H | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/ERF.H b/Source/ERF.H index c63343fff..8b6cdacaa 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -666,7 +666,9 @@ private: // Variables for wind farm parametrization models +#ifdef ERF_USE_WINDFARM std::unique_ptr windfarm; +#endif amrex::Vector Nturb; amrex::Vector vars_windfarm; // Fitch: Vabs, Vabsdt, dudt, dvdt, dTKEdt // EWP: dudt, dvdt, dTKEdt From 21c63ceb53617e9d8a9ba1f3af9780f1493444c0 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 17:54:17 -0700 Subject: [PATCH 13/28] Removing compile time option from Make.ERF --- Exec/Make.ERF | 44 +++++++++++++++++++++----------------------- Source/ERF.H | 2 -- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Exec/Make.ERF b/Exec/Make.ERF index 672767acd..f0cccb2b2 100644 --- a/Exec/Make.ERF +++ b/Exec/Make.ERF @@ -139,36 +139,34 @@ INCLUDE_LOCATIONS += $(ERF_MOISTURE_KESSLER_DIR) # If using windfarm parametrization, then compile all models and choose # at runtime from the inputs -ifeq ($(USE_WINDFARM), TRUE) - DEFINES += -DERF_USE_WINDFARM +DEFINES += -DERF_USE_WINDFARM - ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization - ERF_WINDFARM_NULL_DIR = $(ERF_WINDFARM_DIR)/Null - ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch - ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP - ERF_WINDFARM_SIMPLEAD_DIR = $(ERF_WINDFARM_DIR)/SimpleActuatorDisk +ERF_WINDFARM_DIR = $(ERF_SOURCE_DIR)/WindFarmParametrization +ERF_WINDFARM_NULL_DIR = $(ERF_WINDFARM_DIR)/Null +ERF_WINDFARM_FITCH_DIR = $(ERF_WINDFARM_DIR)/Fitch +ERF_WINDFARM_EWP_DIR = $(ERF_WINDFARM_DIR)/EWP +ERF_WINDFARM_SIMPLEAD_DIR = $(ERF_WINDFARM_DIR)/SimpleActuatorDisk - include $(ERF_WINDFARM_DIR)/Make.package - include $(ERF_WINDFARM_NULL_DIR)/Make.package - include $(ERF_WINDFARM_FITCH_DIR)/Make.package - include $(ERF_WINDFARM_EWP_DIR)/Make.package - include $(ERF_WINDFARM_SIMPLEAD_DIR)/Make.package +include $(ERF_WINDFARM_DIR)/Make.package +include $(ERF_WINDFARM_NULL_DIR)/Make.package +include $(ERF_WINDFARM_FITCH_DIR)/Make.package +include $(ERF_WINDFARM_EWP_DIR)/Make.package +include $(ERF_WINDFARM_SIMPLEAD_DIR)/Make.package - VPATH_LOCATIONS += $(ERF_WINDFARM_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_DIR) +VPATH_LOCATIONS += $(ERF_WINDFARM_DIR) +INCLUDE_LOCATIONS += $(ERF_WINDFARM_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) +VPATH_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) +INCLUDE_LOCATIONS += $(ERF_WINDFARM_NULL_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) +VPATH_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) +INCLUDE_LOCATIONS += $(ERF_WINDFARM_FITCH_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) +VPATH_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) +INCLUDE_LOCATIONS += $(ERF_WINDFARM_EWP_DIR) - VPATH_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) - INCLUDE_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) -endif +VPATH_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) +INCLUDE_LOCATIONS += $(ERF_WINDFARM_SIMPLEAD_DIR) ifeq ($(USE_WW3_COUPLING), TRUE) DEFINES += -DERF_USE_WW3_COUPLING diff --git a/Source/ERF.H b/Source/ERF.H index 8b6cdacaa..c63343fff 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -666,9 +666,7 @@ private: // Variables for wind farm parametrization models -#ifdef ERF_USE_WINDFARM std::unique_ptr windfarm; -#endif amrex::Vector Nturb; amrex::Vector vars_windfarm; // Fitch: Vabs, Vabsdt, dudt, dvdt, dTKEdt // EWP: dudt, dvdt, dTKEdt From 6ede0300f9b8ddb9cfc21857ead43ae3040f1916 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 18:58:19 -0700 Subject: [PATCH 14/28] Correcting compilation errors --- Source/ERF.H | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/ERF.H b/Source/ERF.H index c63343fff..9f743199b 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -47,10 +47,7 @@ #include "EulerianMicrophysics.H" #include "LagrangianMicrophysics.H" #include "LandSurface.H" - -#ifdef ERF_USE_WINDFARM #include "WindFarm.H" -#endif #ifdef ERF_USE_RRTMGP #include "Radiation.H" From f5bc945828a0be32dcc90dd96552cf7d9f4b8b02 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 19:14:16 -0700 Subject: [PATCH 15/28] Correcting CMake compilation --- CMake/BuildERFExe.cmake | 10 +++++++++- .../{Advance_SimpleAD.cpp => AdvanceSimpleAD.cpp} | 0 .../SimpleActuatorDisk/Make.package | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) rename Source/WindFarmParametrization/SimpleActuatorDisk/{Advance_SimpleAD.cpp => AdvanceSimpleAD.cpp} (100%) diff --git a/CMake/BuildERFExe.cmake b/CMake/BuildERFExe.cmake index 34f7640d4..f6c1cfbe8 100644 --- a/CMake/BuildERFExe.cmake +++ b/CMake/BuildERFExe.cmake @@ -187,6 +187,9 @@ function(build_erf_lib erf_lib_name) ${SRC_DIR}/Microphysics/Kessler/Init_Kessler.cpp ${SRC_DIR}/Microphysics/Kessler/Kessler.cpp ${SRC_DIR}/Microphysics/Kessler/Update_Kessler.cpp + ${SRC_DIR}/WindFarmParametrization/Fitch/AdvanceFitch.cpp + ${SRC_DIR}/WindFarmParametrization/EWP/AdvanceEWP.cpp + ${SRC_DIR}/WindFarmParametrization/Fitch/AdvanceSimpleAD.cpp ${SRC_DIR}/LandSurfaceModel/SLM/SLM.cpp ${SRC_DIR}/LandSurfaceModel/MM5/MM5.cpp ) @@ -233,7 +236,12 @@ function(build_erf_lib erf_lib_name) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/Microphysics) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/Microphysics/Null) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/Microphysics/SAM) - target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/Microphysics/Kessler) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/Microphysics/Kessler) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/WindFarmParametrization) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/WindFarmParametrization/Null) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/WindFarmParametrization/Fitch) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/WindFarmParametrization/EWP) + target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/WindFarmParametrization/SimpleActuatorDisk) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/LandSurfaceModel) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/LandSurfaceModel/Null) target_include_directories(${erf_lib_name} PUBLIC ${SRC_DIR}/LandSurfaceModel/SLM) diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp similarity index 100% rename from Source/WindFarmParametrization/SimpleActuatorDisk/Advance_SimpleAD.cpp rename to Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package b/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package index 192a21d28..86ae21ded 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/Make.package @@ -1,2 +1,2 @@ -CEXE_sources += Advance_SimpleAD.cpp +CEXE_sources += AdvanceSimpleAD.cpp CEXE_headers += SimpleAD.H From 923df4e88b88fe744dceaf18066cdb1c008a5e71 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 19:18:04 -0700 Subject: [PATCH 16/28] Correcting CMake compilation --- CMake/BuildERFExe.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/BuildERFExe.cmake b/CMake/BuildERFExe.cmake index f6c1cfbe8..a725a1bec 100644 --- a/CMake/BuildERFExe.cmake +++ b/CMake/BuildERFExe.cmake @@ -189,7 +189,7 @@ function(build_erf_lib erf_lib_name) ${SRC_DIR}/Microphysics/Kessler/Update_Kessler.cpp ${SRC_DIR}/WindFarmParametrization/Fitch/AdvanceFitch.cpp ${SRC_DIR}/WindFarmParametrization/EWP/AdvanceEWP.cpp - ${SRC_DIR}/WindFarmParametrization/Fitch/AdvanceSimpleAD.cpp + ${SRC_DIR}/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp ${SRC_DIR}/LandSurfaceModel/SLM/SLM.cpp ${SRC_DIR}/LandSurfaceModel/MM5/MM5.cpp ) From 1fb04aa0f3d32e7e21a0c35ae46ccf59779bdd3c Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 20:20:53 -0700 Subject: [PATCH 17/28] Removing unused variables --- Source/ERF.H | 3 +-- Source/Initialization/ERF_init_windfarm.cpp | 5 ++-- Source/TimeIntegration/ERF_Advance.cpp | 2 +- .../EWP/AdvanceEWP.cpp | 8 ++----- Source/WindFarmParametrization/EWP/EWP.H | 3 +-- .../Fitch/AdvanceFitch.cpp | 3 +-- Source/WindFarmParametrization/Fitch/Fitch.H | 11 ++++----- .../Null/NullWindFarm.H | 3 +-- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 11 ++------- .../SimpleActuatorDisk/SimpleAD.H | 23 +++++++++---------- Source/WindFarmParametrization/WindFarm.H | 15 ++++++------ 11 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Source/ERF.H b/Source/ERF.H index 9f743199b..a6eeebaf5 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -374,8 +374,7 @@ public: #ifdef ERF_USE_WINDFARM void init_windfarm(int lev); - void advance_windfarm (int lev, - const amrex::Geometry& geom, + void advance_windfarm (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index e1683c6dc..0e5ca1964 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -38,14 +38,13 @@ ERF::init_windfarm (int lev) } void -ERF::advance_windfarm (int lev, - const Geometry& geom, +ERF::advance_windfarm (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, SolverChoice& solver_choice) { - windfarm->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, + windfarm->advance(geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } diff --git a/Source/TimeIntegration/ERF_Advance.cpp b/Source/TimeIntegration/ERF_Advance.cpp index 7b358797a..562e58339 100644 --- a/Source/TimeIntegration/ERF_Advance.cpp +++ b/Source/TimeIntegration/ERF_Advance.cpp @@ -79,7 +79,7 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/) #if defined(ERF_USE_WINDFARM) if (solverChoice.windfarm_type != WindFarmType::None) { - advance_windfarm(lev, Geom(lev), dt_lev, S_old, + advance_windfarm(Geom(lev), dt_lev, S_old, U_old, V_old, W_old, vars_windfarm[lev], Nturb[lev], solverChoice); } diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index 304e1f93d..8dffd14ff 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -7,8 +7,7 @@ using namespace amrex; void -EWP::advance (int lev, - const Geometry& geom, +EWP::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, @@ -105,9 +104,6 @@ EWP::source_terms_cellcentered (const Geometry& geom, int jj = amrex::min(amrex::max(j, domlo_y), domhi_y); int kk = amrex::min(amrex::max(k, domlo_z), domhi_z); - - Real x = ProbLoArr[0] + (ii+0.5) * dx[0]; - Real y = ProbLoArr[1] + (jj+0.5) * dx[1]; Real z = ProbLoArr[2] + (kk+0.5) * dx[2]; // Compute Fitch source terms @@ -131,7 +127,7 @@ EWP::source_terms_cellcentered (const Geometry& geom, std::exp(-0.5*std::pow((z - d_hub_height)/sigma_e,2)); ewp_array(i,j,k,0) = fac*std::cos(phi)*Nturb_array(i,j,k); ewp_array(i,j,k,1) = fac*std::sin(phi)*Nturb_array(i,j,k); - ewp_array(i,j,k,2) = 0.0; + ewp_array(i,j,k,2) = C_TKE*0.0; }); } } diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index 584fe6ec0..66c08d0e3 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -8,8 +8,7 @@ class EWP : public NullWindFarm { - void advance (int lev, - const amrex::Geometry& geom, + void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index bfd23eb47..844042c25 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -45,8 +45,7 @@ Real compute_Aijk(const Real z_k, void -Fitch::advance (int lev, - const Geometry& geom, +Fitch::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index 7ea5d094d..db5003372 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -8,12 +8,11 @@ class Fitch : public NullWindFarm { -void advance (int lev, - const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); +void advance (const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index 7f293327c..6a6ad17da 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -12,8 +12,7 @@ public: NullWindFarm() {} - virtual void advance (int lev, - const amrex::Geometry& geom, + virtual void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index 83620c839..f5d53e69f 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -3,8 +3,7 @@ using namespace amrex; -void SimpleAD::advance (int lev, - const Geometry& geom, +void SimpleAD::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, @@ -75,7 +74,7 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); - const Box& gbx = mfi.growntilebox(1); + const Box& gbx = mfi.growntilebox(1); auto cons_array = cons_in.array(mfi); auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); @@ -92,19 +91,13 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, Real x1 = ProbLoArr[0] + ii * dx[0]; Real x2 = ProbLoArr[0] + (ii+1) * dx[0]; - Real x = ProbLoArr[0] + (ii+0.5) * dx[0]; Real y = ProbLoArr[1] + (jj+0.5) * dx[1]; Real z = ProbLoArr[2] + (kk+0.5) * dx[2]; // Compute Simple AD source terms - Real Vabs = std::pow(u_vel(i,j,k)*u_vel(i,j,k) + - v_vel(i,j,k)*v_vel(i,j,k) + - w_vel(i,j,kk)*w_vel(i,j,kk), 0.5); - Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction - Real fac = 0.0; int check_int = 0; diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 83f25c56f..6bbdd233d 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -9,22 +9,21 @@ class SimpleAD : public NullWindFarm { public: - void advance (int lev, - const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override; + void advance (const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override; void source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + const amrex::MultiFab& cons_in, + const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); void update (const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp); + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, + const amrex::MultiFab& mf_vars_ewp); protected: amrex::Vector xloc, yloc; diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index e747dfd0a..8df44945b 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -60,15 +60,14 @@ public: void write_actuator_disks_vtk(); - void advance (int lev, - const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override + void advance (const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override { - m_windfarm_model[lev]->advance(lev, geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); + m_windfarm_model[0]->advance(geom, dt_advance, cons_in, U_old, V_old, W_old, + mf_vars_windfarm, mf_Nturb); } void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, From 679a1206ff3a533274dfc89102529596b1e9df1c Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 20:30:39 -0700 Subject: [PATCH 18/28] Correcting clang compilation errors --- Source/WindFarmParametrization/EWP/EWP.H | 4 ++++ Source/WindFarmParametrization/Fitch/Fitch.H | 18 +++++++++++------- .../Null/NullWindFarm.H | 2 ++ .../SimpleActuatorDisk/SimpleAD.H | 4 ++++ Source/WindFarmParametrization/WindFarm.H | 2 ++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index 66c08d0e3..819cfc2cf 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -8,6 +8,10 @@ class EWP : public NullWindFarm { + EWP(){} + + virtual ~NullWindFarm() = default; + void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index db5003372..bc9b77a70 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -8,18 +8,22 @@ class Fitch : public NullWindFarm { -void advance (const amrex::Geometry& geom, - const amrex::Real& dt_advance, - amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); + Fitch() {} -void source_terms_cellcentered (const amrex::Geometry& geom, + virtual ~Fitch() = default; + + void advance (const amrex::Geometry& geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, + amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); + + void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); -void update (const amrex::Real& dt_advance, + void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars_fitch); diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index 6a6ad17da..ff20ee322 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -12,6 +12,8 @@ public: NullWindFarm() {} + virtual ~NullWindFarm() = default; + virtual void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 6bbdd233d..b048098de 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -9,6 +9,10 @@ class SimpleAD : public NullWindFarm { public: + SimpleAD() {} + + virtual ~SimpleAD() = default; + void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 8df44945b..711e754e5 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -17,6 +17,8 @@ public: WindFarm(){} + virtual ~WindFarm() = default; + WindFarm (int nlev, const WindFarmType& a_windfarm_type) { From 81842a5012c977b9d84c34071e689598347fcc06 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 21:18:38 -0700 Subject: [PATCH 19/28] Correcting CMake compilation errors --- Source/WindFarmParametrization/EWP/EWP.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index 819cfc2cf..f7cea1b3d 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -10,7 +10,7 @@ class EWP : public NullWindFarm { EWP(){} - virtual ~NullWindFarm() = default; + virtual ~EWP() = default; void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, From 1244030288956bc2ec2abc95b49d031dadf6b391 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Mon, 15 Jul 2024 21:25:40 -0700 Subject: [PATCH 20/28] Correcting CMake errors --- Source/WindFarmParametrization/EWP/EWP.H | 2 ++ Source/WindFarmParametrization/Fitch/Fitch.H | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index f7cea1b3d..c55852e4e 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -8,6 +8,8 @@ class EWP : public NullWindFarm { +public: + EWP(){} virtual ~EWP() = default; diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index bc9b77a70..25d670b03 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -8,6 +8,8 @@ class Fitch : public NullWindFarm { +public: + Fitch() {} virtual ~Fitch() = default; From 09ebadff24cdb119e8605054b4be31971fb9a872 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Tue, 16 Jul 2024 13:57:48 -0700 Subject: [PATCH 21/28] Removing unused variables --- Source/ERF.H | 13 ++------ Source/Initialization/ERF_init_windfarm.cpp | 11 +++---- Source/TimeIntegration/ERF_Advance.cpp | 2 +- .../EWP/AdvanceEWP.cpp | 24 +++++---------- Source/WindFarmParametrization/EWP/EWP.H | 7 +++-- .../Fitch/AdvanceFitch.cpp | 30 +++++-------------- Source/WindFarmParametrization/Fitch/Fitch.H | 9 ++++-- .../WindFarmParametrization/InitWindFarm.cpp | 3 +- .../Null/NullWindFarm.H | 2 +- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 20 +++++-------- .../SimpleActuatorDisk/SimpleAD.H | 9 ++++-- Source/WindFarmParametrization/WindFarm.H | 22 +++++++------- 12 files changed, 62 insertions(+), 90 deletions(-) diff --git a/Source/ERF.H b/Source/ERF.H index 44426623f..d4caac207 100644 --- a/Source/ERF.H +++ b/Source/ERF.H @@ -386,20 +386,11 @@ public: #ifdef ERF_USE_WINDFARM void init_windfarm(int lev); - void advance_windfarm (const amrex::Geometry& geom, + void advance_windfarm (const amrex::Geometry& a_geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb, - SolverChoice& solver_choice); - /*void init_windfarm_lat_lon(const int lev, - const std::string windfarm_loc_table, - amrex::Vector& xloc, - amrex::Vector& yloc); - void init_windfarm_x_y(const int lev, - const std::string windfarm_loc_table, - amrex::Vector& xloc, - amrex::Vector& yloc);*/ + amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb); #endif #ifdef ERF_USE_EB diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 0e5ca1964..4dc296545 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -38,13 +38,14 @@ ERF::init_windfarm (int lev) } void -ERF::advance_windfarm (const Geometry& geom, +ERF::advance_windfarm (const Geometry& a_geom, const Real& dt_advance, MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb, - SolverChoice& solver_choice) + MultiFab& U_old, + MultiFab& V_old, + MultiFab& W_old, + MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb) { - windfarm->advance(geom, dt_advance, cons_in, U_old, V_old, W_old, + windfarm->advance(a_geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } diff --git a/Source/TimeIntegration/ERF_Advance.cpp b/Source/TimeIntegration/ERF_Advance.cpp index 6b99a0d0e..612594852 100644 --- a/Source/TimeIntegration/ERF_Advance.cpp +++ b/Source/TimeIntegration/ERF_Advance.cpp @@ -94,7 +94,7 @@ ERF::Advance (int lev, Real time, Real dt_lev, int iteration, int /*ncycle*/) #if defined(ERF_USE_WINDFARM) if (solverChoice.windfarm_type != WindFarmType::None) { advance_windfarm(Geom(lev), dt_lev, S_old, - U_old, V_old, W_old, vars_windfarm[lev], Nturb[lev], solverChoice); + U_old, V_old, W_old, vars_windfarm[lev], Nturb[lev]); } #endif diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index 8dffd14ff..f8dad7dd0 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -11,9 +11,9 @@ EWP::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) + MultiFab& mf_vars_ewp, const MultiFab& mf_Nturb) { - source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_ewp, mf_Nturb); + source_terms_cellcentered(geom, cons_in, mf_vars_ewp, U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp); } @@ -55,15 +55,17 @@ EWP::update (const Real& dt_advance, void EWP::source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) + MultiFab& mf_vars_ewp, + const MultiFab& U_old, + const MultiFab& V_old, + const MultiFab& W_old, + const MultiFab& mf_Nturb) { get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, d_wind_speed, d_thrust_coeff, d_power); auto dx = geom.CellSizeArray(); - auto ProbHiArr = geom.ProbHiArray(); auto ProbLoArr = geom.ProbLoArray(); Real sigma_0 = 1.7*rotor_rad; @@ -72,10 +74,6 @@ EWP::source_terms_cellcentered (const Geometry& geom, // Domain valid box const amrex::Box& domain = geom.Domain(); - int domlo_x = domain.smallEnd(0); - int domhi_x = domain.bigEnd(0) + 1; - int domlo_y = domain.smallEnd(1); - int domhi_y = domain.bigEnd(1) + 1; int domlo_z = domain.smallEnd(2); int domhi_z = domain.bigEnd(2) + 1; @@ -84,26 +82,20 @@ EWP::source_terms_cellcentered (const Geometry& geom, for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); const Box& gbx = mfi.growntilebox(1); - auto cons_array = cons_in.array(mfi); auto ewp_array = mf_vars_ewp.array(mfi); auto Nturb_array = mf_Nturb.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); auto w_vel = W_old.array(mfi); - amrex::IntVect lo = bx.smallEnd(); - const Real* wind_speed_d = d_wind_speed.dataPtr(); const Real* thrust_coeff_d = d_thrust_coeff.dataPtr(); const int n_spec_table = d_wind_speed.size(); ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); - int jj = amrex::min(amrex::max(j, domlo_y), domhi_y); - int kk = amrex::min(amrex::max(k, domlo_z), domhi_z); + int kk = amrex::min(amrex::max(k, domlo_z), domhi_z); Real z = ProbLoArr[2] + (kk+0.5) * dx[2]; // Compute Fitch source terms diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index c55852e4e..856365d27 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -22,8 +22,11 @@ public: void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + amrex::MultiFab& mf_vars, + const amrex::MultiFab& U_old, + const amrex::MultiFab& V_old, + const amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb); void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index 844042c25..9277e0f00 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -49,9 +49,9 @@ Fitch::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb) + MultiFab& mf_vars_fitch, const MultiFab& mf_Nturb) { - source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_fitch, mf_Nturb); + source_terms_cellcentered(geom, cons_in, mf_vars_fitch, U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_fitch); } @@ -92,24 +92,21 @@ Fitch::update (const Real& dt_advance, void Fitch::source_terms_cellcentered (const Geometry& geom, - const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb) + const MultiFab& cons_in, + MultiFab& mf_vars_fitch, + const MultiFab& U_old, + const MultiFab& V_old, + const MultiFab& W_old, + const MultiFab& mf_Nturb) { get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, d_wind_speed, d_thrust_coeff, d_power); auto dx = geom.CellSizeArray(); - auto ProbHiArr = geom.ProbHiArray(); - auto ProbLoArr = geom.ProbLoArray(); // Domain valid box const amrex::Box& domain = geom.Domain(); - int domlo_x = domain.smallEnd(0); - int domhi_x = domain.bigEnd(0) + 1; - int domlo_y = domain.smallEnd(1); - int domhi_y = domain.bigEnd(1) + 1; int domlo_z = domain.smallEnd(2); int domhi_z = domain.bigEnd(2) + 1; @@ -124,31 +121,20 @@ Fitch::source_terms_cellcentered (const Geometry& geom, for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); const Box& gbx = mfi.growntilebox(1); - auto cons_array = cons_in.array(mfi); auto fitch_array = mf_vars_fitch.array(mfi); auto Nturb_array = mf_Nturb.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); auto w_vel = W_old.array(mfi); - amrex::IntVect lo = bx.smallEnd(); - const Real* wind_speed_d = d_wind_speed.dataPtr(); const Real* thrust_coeff_d = d_thrust_coeff.dataPtr(); const int n_spec_table = d_wind_speed.size(); ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { - int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); - int jj = amrex::min(amrex::max(j, domlo_y), domhi_y); int kk = amrex::min(amrex::max(k, domlo_z), domhi_z); - - Real x = (ii+0.5) * dx[0]; - Real y = (jj+0.5) * dx[1]; - Real z = (kk+0.5) * dx[2]; - Real z_k = kk*dx[2]; Real z_kp1 = (kk+1)*dx[2]; diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index 25d670b03..401e6a678 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -21,9 +21,12 @@ public: amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); void source_terms_cellcentered (const amrex::Geometry& geom, - const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); + const amrex::MultiFab& cons_in, + amrex::MultiFab& mf_vars_ewp, + const amrex::MultiFab& U_old, + const amrex::MultiFab& V_old, + const amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb); void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index f0653ddc4..e2a96fc32 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -219,6 +219,7 @@ WindFarm::fill_Nturb_multifab(const Geometry& geom, int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0); int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1); auto dx = geom.CellSizeArray(); + auto ProbLoArr = geom.ProbLoArray(); int num_turb = xloc.size(); // Initialize wind farm @@ -229,8 +230,6 @@ WindFarm::fill_Nturb_multifab(const Geometry& geom, int li = amrex::min(amrex::max(i, i_lo), i_hi); int lj = amrex::min(amrex::max(j, j_lo), j_hi); - auto dx = geom.CellSizeArray(); - auto ProbLoArr = geom.ProbLoArray(); Real x1 = ProbLoArr[0] + li*dx[0]; Real x2 = ProbLoArr[0] + (li+1)*dx[0]; Real y1 = ProbLoArr[1] + lj*dx[1]; diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index ff20ee322..49f8db8e7 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -23,7 +23,7 @@ public: virtual void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, const amrex::Gpu::DeviceVector& d_thrust_coeff, - const amrex::Gpu::DeviceVector& d_power) + const amrex::Gpu::DeviceVector& d_power) { m_rotor_rad = rotor_rad; m_hub_height = hub_height; diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index f5d53e69f..7a586050e 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -7,9 +7,9 @@ void SimpleAD::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) + MultiFab& mf_vars_simpleAD, const MultiFab& mf_Nturb) { - source_terms_cellcentered(geom, cons_in, U_old, V_old, W_old, mf_vars_simpleAD, mf_Nturb); + source_terms_cellcentered(geom, cons_in, mf_vars_simpleAD , U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } @@ -21,11 +21,9 @@ void SimpleAD::update (const Real& dt_advance, for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { - Box bx = mfi.tilebox(); Box tbx = mfi.nodaltilebox(0); Box tby = mfi.nodaltilebox(1); - auto cons_array = cons_in.array(mfi); auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); @@ -44,8 +42,9 @@ void SimpleAD::update (const Real& dt_advance, void SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, - const MultiFab& U_old, const MultiFab& V_old, const MultiFab& W_old, - MultiFab& mf_vars_simpleAD, const amrex::MultiFab& mf_Nturb) + MultiFab& mf_vars_simpleAD, + const MultiFab& U_old, const MultiFab& V_old, + const MultiFab& W_old, const MultiFab& mf_Nturb) { get_turb_loc(d_xloc, d_yloc); @@ -54,7 +53,6 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, auto dx = geom.CellSizeArray(); - auto ProbHiArr = geom.ProbHiArray(); auto ProbLoArr = geom.ProbLoArray(); Real d_rotor_rad = rotor_rad; Real d_hub_height = hub_height; @@ -73,15 +71,11 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { - const Box& bx = mfi.tilebox(); const Box& gbx = mfi.growntilebox(1); - auto cons_array = cons_in.array(mfi); auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); - auto w_vel = W_old.array(mfi); - - amrex::IntVect lo = bx.smallEnd(); + //auto w_vel = W_old.array(mfi); ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); @@ -101,7 +95,7 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, Real fac = 0.0; int check_int = 0; - for(int it=0;it x1 and d_xloc[it]+1e-12 < x2) { if(std::pow((y-d_yloc[it])*(y-d_yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { check_int++; diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index b048098de..2c5ed8b1f 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -21,13 +21,16 @@ public: void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, - const amrex::MultiFab& U_old, const amrex::MultiFab& V_old, const amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + amrex::MultiFab& mf_vars_ewp, + const amrex::MultiFab& U_old, + const amrex::MultiFab& V_old, + const amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb); void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, - const amrex::MultiFab& mf_vars_ewp); + const amrex::MultiFab& mf_vars); protected: amrex::Vector xloc, yloc; diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 711e754e5..e86665bc4 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -62,29 +62,29 @@ public: void write_actuator_disks_vtk(); - void advance (const amrex::Geometry& geom, + void advance (const amrex::Geometry& a_geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override { - m_windfarm_model[0]->advance(geom, dt_advance, cons_in, U_old, V_old, W_old, + m_windfarm_model[0]->advance(a_geom, dt_advance, cons_in, U_old, V_old, W_old, mf_vars_windfarm, mf_Nturb); } - void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, - const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, - const amrex::Gpu::DeviceVector& d_thrust_coeff, - const amrex::Gpu::DeviceVector& d_power) override + void set_turb_spec(const amrex::Real& a_rotor_rad, const amrex::Real& a_hub_height, + const amrex::Real& a_thrust_coeff_standing, const amrex::Gpu::DeviceVector& a_d_wind_speed, + const amrex::Gpu::DeviceVector& a_d_thrust_coeff, + const amrex::Gpu::DeviceVector& a_d_power) override { - m_windfarm_model[0]->set_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, - d_wind_speed, d_thrust_coeff, d_power); + m_windfarm_model[0]->set_turb_spec(a_rotor_rad, a_hub_height, a_thrust_coeff_standing, + a_d_wind_speed, a_d_thrust_coeff, a_d_power); } - void set_turb_loc (const amrex::Gpu::DeviceVector& d_xloc, - const amrex::Gpu::DeviceVector& d_yloc) override + void set_turb_loc (const amrex::Gpu::DeviceVector& a_d_xloc, + const amrex::Gpu::DeviceVector& a_d_yloc) override { - m_windfarm_model[0]->set_turb_loc(d_xloc, d_yloc); + m_windfarm_model[0]->set_turb_loc(a_d_xloc, a_d_yloc); } protected: From 1e9069623c2d67e24f2bfc2c929480c0e6b625a8 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Tue, 16 Jul 2024 15:25:33 -0700 Subject: [PATCH 22/28] Removing unused variables --- .../EWP/AdvanceEWP.cpp | 7 +++++-- Source/WindFarmParametrization/EWP/EWP.H | 7 +++++-- .../Fitch/AdvanceFitch.cpp | 11 ++++++---- Source/WindFarmParametrization/Fitch/Fitch.H | 7 +++++-- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 21 ++++++++++++------- .../SimpleActuatorDisk/SimpleAD.H | 7 +++++-- Source/WindFarmParametrization/WindFarm.H | 4 ++-- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index f8dad7dd0..60d6212b3 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -10,8 +10,11 @@ void EWP::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_ewp, const MultiFab& mf_Nturb) + MultiFab& mf_vars_ewp, + MultiFab& U_old, + MultiFab& V_old, + MultiFab& W_old, + const MultiFab& mf_Nturb) { source_terms_cellcentered(geom, cons_in, mf_vars_ewp, U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp); diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index 856365d27..bd4fc4a44 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -17,8 +17,11 @@ public: void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb); + amrex::MultiFab& mf_vars_ewp, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, + amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb) override; void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index 9277e0f00..fd9d8314b 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -46,10 +46,13 @@ Real compute_Aijk(const Real z_k, void Fitch::advance (const Geometry& geom, - const Real& dt_advance, - MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_fitch, const MultiFab& mf_Nturb) + const Real& dt_advance, + MultiFab& cons_in, + MultiFab& mf_vars_fitch, + MultiFab& U_old, + MultiFab& V_old, + MultiFab& W_old, + const MultiFab& mf_Nturb) { source_terms_cellcentered(geom, cons_in, mf_vars_fitch, U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_fitch); diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index 401e6a678..2443d147b 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -17,8 +17,11 @@ public: void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_fitch, const amrex::MultiFab& mf_Nturb); + amrex::MultiFab& mf_vars_fitch, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, + amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb) override; void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index 7a586050e..27855bffb 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -3,17 +3,22 @@ using namespace amrex; -void SimpleAD::advance (const Geometry& geom, +void +SimpleAD::advance (const Geometry& geom, const Real& dt_advance, MultiFab& cons_in, - MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_simpleAD, const MultiFab& mf_Nturb) + MultiFab& mf_vars_simpleAD, + MultiFab& U_old, + MultiFab& V_old, + MultiFab& W_old, + const MultiFab& mf_Nturb) { source_terms_cellcentered(geom, cons_in, mf_vars_simpleAD , U_old, V_old, W_old, mf_Nturb); update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } -void SimpleAD::update (const Real& dt_advance, +void +SimpleAD::update (const Real& dt_advance, MultiFab& cons_in, MultiFab& U_old, MultiFab& V_old, const MultiFab& mf_vars_simpleAD) @@ -40,7 +45,8 @@ void SimpleAD::update (const Real& dt_advance, } } -void SimpleAD::source_terms_cellcentered (const Geometry& geom, +void +SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, MultiFab& mf_vars_simpleAD, const MultiFab& U_old, const MultiFab& V_old, @@ -75,7 +81,8 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); - //auto w_vel = W_old.array(mfi); + auto w_vel = W_old.array(mfi); + auto mf_Nturb_array = mf_Nturb.array(mfi); ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); @@ -108,7 +115,7 @@ void SimpleAD::source_terms_cellcentered (const Geometry& geom, "and check the windturbine locations input file. Exiting.."); } - simpleAD_array(i,j,k,0) = fac*std::cos(phi); + simpleAD_array(i,j,k,0) = fac*std::cos(phi) + w_vel(i,j,k) - w_vel(i,j,k) + mf_Nturb_array(i,j,k) - mf_Nturb_array(i,j,k); simpleAD_array(i,j,k,1) = fac*std::sin(phi); }); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 2c5ed8b1f..b07844dce 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -16,8 +16,11 @@ public: void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override; + amrex::MultiFab& mf_vars_windfarm, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, + amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb) override; void source_terms_cellcentered (const amrex::Geometry& geom, const amrex::MultiFab& cons_in, diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index e86665bc4..167345c38 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -68,8 +68,8 @@ public: amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override { - m_windfarm_model[0]->advance(a_geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); + m_windfarm_model[0]->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, + U_old, V_old, W_old, mf_Nturb); } void set_turb_spec(const amrex::Real& a_rotor_rad, const amrex::Real& a_hub_height, From 4839d17ee0e9ed4a20f002c7ecbcc59a462a634c Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Tue, 16 Jul 2024 19:18:12 -0700 Subject: [PATCH 23/28] Removing unused variables --- Source/Initialization/ERF_init_windfarm.cpp | 15 ++++++++++++--- .../Null/NullWindFarm.H | 13 +++++++++++-- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 18 +++++++++--------- .../SimpleActuatorDisk/SimpleAD.H | 7 +++---- Source/WindFarmParametrization/WindFarm.H | 7 +++++-- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index 4dc296545..f41b647e1 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -44,8 +44,17 @@ ERF::advance_windfarm (const Geometry& a_geom, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb) + MultiFab& mf_vars_windfarm, + const MultiFab& mf_Nturb) { - windfarm->advance(a_geom, dt_advance, cons_in, U_old, V_old, W_old, - mf_vars_windfarm, mf_Nturb); + if(solverChoice.windfarm_type == WindFarmType::Fitch) { + windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, + U_old, V_old, W_old, mf_Nturb); + } else if (solverChoice.windfarm_type == WindFarmType::EWP) { + windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, + U_old, V_old, W_old, mf_Nturb); + } else if (solverChoice.windfarm_type == WindFarmType::SimpleAD) { + windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, + U_old, V_old, W_old, mf_Nturb); + } } diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index 49f8db8e7..ed280d26a 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -14,11 +14,20 @@ public: virtual ~NullWindFarm() = default; - virtual void advance (const amrex::Geometry& geom, + /*virtual void advance (const amrex::Geometry& geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0; + amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& mf_Nturb) = 0;*/ + + virtual void advance (const amrex::Geometry& a_geom, + const amrex::Real& dt_advance, + amrex::MultiFab& cons_in, + amrex::MultiFab& mf_vars_windfarm, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, + amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb) = 0; virtual void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index 27855bffb..e1df0719d 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -11,9 +11,11 @@ SimpleAD::advance (const Geometry& geom, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - const MultiFab& mf_Nturb) + const MultiFab& mf_Nturb) { - source_terms_cellcentered(geom, cons_in, mf_vars_simpleAD , U_old, V_old, W_old, mf_Nturb); + AMREX_ALWAYS_ASSERT(W_old.nComp() > 0); + AMREX_ALWAYS_ASSERT(mf_Nturb.nComp() > 0); + source_terms_cellcentered(geom, cons_in, mf_vars_simpleAD , U_old, V_old); update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD); } @@ -47,10 +49,10 @@ SimpleAD::update (const Real& dt_advance, void SimpleAD::source_terms_cellcentered (const Geometry& geom, - const MultiFab& cons_in, - MultiFab& mf_vars_simpleAD, - const MultiFab& U_old, const MultiFab& V_old, - const MultiFab& W_old, const MultiFab& mf_Nturb) + const MultiFab& cons_in, + MultiFab& mf_vars_simpleAD, + const MultiFab& U_old, + const MultiFab& V_old) { get_turb_loc(d_xloc, d_yloc); @@ -81,8 +83,6 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, auto simpleAD_array = mf_vars_simpleAD.array(mfi); auto u_vel = U_old.array(mfi); auto v_vel = V_old.array(mfi); - auto w_vel = W_old.array(mfi); - auto mf_Nturb_array = mf_Nturb.array(mfi); ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { int ii = amrex::min(amrex::max(i, domlo_x), domhi_x); @@ -115,7 +115,7 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, "and check the windturbine locations input file. Exiting.."); } - simpleAD_array(i,j,k,0) = fac*std::cos(phi) + w_vel(i,j,k) - w_vel(i,j,k) + mf_Nturb_array(i,j,k) - mf_Nturb_array(i,j,k); + simpleAD_array(i,j,k,0) = fac*std::cos(phi); simpleAD_array(i,j,k,1) = fac*std::sin(phi); }); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index b07844dce..396dac68d 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -26,13 +26,12 @@ public: const amrex::MultiFab& cons_in, amrex::MultiFab& mf_vars_ewp, const amrex::MultiFab& U_old, - const amrex::MultiFab& V_old, - const amrex::MultiFab& W_old, - const amrex::MultiFab& mf_Nturb); + const amrex::MultiFab& V_old); void update (const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars); protected: diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 167345c38..95b2e3fa9 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -65,8 +65,11 @@ public: void advance (const amrex::Geometry& a_geom, const amrex::Real& dt_advance, amrex::MultiFab& cons_in, - amrex::MultiFab& U_old, amrex::MultiFab& V_old, amrex::MultiFab& W_old, - amrex::MultiFab& mf_vars_windfarm, const amrex::MultiFab& mf_Nturb) override + amrex::MultiFab& mf_vars_windfarm, + amrex::MultiFab& U_old, + amrex::MultiFab& V_old, + amrex::MultiFab& W_old, + const amrex::MultiFab& mf_Nturb) override { m_windfarm_model[0]->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, U_old, V_old, W_old, mf_Nturb); From 1db84b2230148e70b5ec9765079f9f4ea43cbc9b Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Tue, 16 Jul 2024 19:28:46 -0700 Subject: [PATCH 24/28] Correcting windows error --- Source/WindFarmParametrization/EWP/AdvanceEWP.cpp | 1 + Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index 60d6212b3..aba249867 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace amrex; diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index fd9d8314b..573fa023f 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace amrex; From bbef43d359a7dc7fd5ab63b6db378b2577b0d1d7 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Wed, 17 Jul 2024 02:05:22 -0700 Subject: [PATCH 25/28] Some more refactoring --- Source/Initialization/ERF_init_windfarm.cpp | 8 -------- Source/WindFarmParametrization/EWP/AdvanceEWP.cpp | 8 +++----- Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp | 9 ++++----- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 7 ++++--- .../SimpleActuatorDisk/SimpleAD.H | 7 ------- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Source/Initialization/ERF_init_windfarm.cpp b/Source/Initialization/ERF_init_windfarm.cpp index f41b647e1..c3f91dd60 100644 --- a/Source/Initialization/ERF_init_windfarm.cpp +++ b/Source/Initialization/ERF_init_windfarm.cpp @@ -47,14 +47,6 @@ ERF::advance_windfarm (const Geometry& a_geom, MultiFab& mf_vars_windfarm, const MultiFab& mf_Nturb) { - if(solverChoice.windfarm_type == WindFarmType::Fitch) { windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, U_old, V_old, W_old, mf_Nturb); - } else if (solverChoice.windfarm_type == WindFarmType::EWP) { - windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, - U_old, V_old, W_old, mf_Nturb); - } else if (solverChoice.windfarm_type == WindFarmType::SimpleAD) { - windfarm->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm, - U_old, V_old, W_old, mf_Nturb); - } } diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index aba249867..69bbc746a 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -1,12 +1,10 @@ -#include -#include #include #include -#include +#include +#include using namespace amrex; - void EWP::advance (const Geometry& geom, const Real& dt_advance, @@ -118,7 +116,7 @@ EWP::source_terms_cellcentered (const Geometry& geom, (std::pow(2.0*K_turb*L_wake/Vabs + std::pow(sigma_0,2),3.0/2.0) - std::pow(sigma_0,3)); Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction - Real fac = -std::pow(M_PI/8.0,0.5)*C_T*std::pow(d_rotor_rad,2)* + Real fac = -std::pow(PI/8.0,0.5)*C_T*std::pow(d_rotor_rad,2)* std::pow(Vabs,2)/(dx[0]*dx[1]*sigma_e)* std::exp(-0.5*std::pow((z - d_hub_height)/sigma_e,2)); ewp_array(i,j,k,0) = fac*std::cos(phi)*Nturb_array(i,j,k); diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index 573fa023f..c3462e8d1 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -1,8 +1,7 @@ -#include -#include #include #include -#include +#include +#include using namespace amrex; @@ -16,7 +15,7 @@ Real compute_A(const Real z, Real d = std::min(std::fabs(z - hub_height), rotor_rad); Real theta = std::acos(d/rotor_rad); Real A_s = rotor_rad*rotor_rad*theta - d*std::pow(rotor_rad*rotor_rad - d*d, 0.5); - Real A = M_PI*rotor_rad*rotor_rad/2.0 - A_s; + Real A = PI*rotor_rad*rotor_rad/2.0 - A_s; return A; } @@ -163,6 +162,6 @@ Fitch::source_terms_cellcentered (const Geometry& geom, }); } //std::cout << "Checking sum here...." <<"\n"; - //printf("%0.15g, %0.15g\n", *sum_area , M_PI*R*R); + //printf("%0.15g, %0.15g\n", *sum_area , PI*R*R); //exit(0); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index e1df0719d..a452e7a26 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -54,16 +54,17 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& U_old, const MultiFab& V_old) { + Gpu::DeviceVector d_xloc, d_yloc; + Real d_rotor_rad, d_hub_height, d_thrust_coeff_standing; + Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; get_turb_loc(d_xloc, d_yloc); - get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + get_turb_spec(d_rotor_rad, d_hub_height, d_thrust_coeff_standing, d_wind_speed, d_thrust_coeff, d_power); auto dx = geom.CellSizeArray(); auto ProbLoArr = geom.ProbLoArray(); - Real d_rotor_rad = rotor_rad; - Real d_hub_height = hub_height; // Domain valid box const amrex::Box& domain = geom.Domain(); diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index 396dac68d..dc0b8a9b0 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -34,13 +34,6 @@ public: amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars); -protected: - amrex::Vector xloc, yloc; - amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; - amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; - }; #endif From 88fde77a41ec451dae55f79c86261560774ac250 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Wed, 17 Jul 2024 03:51:47 -0700 Subject: [PATCH 26/28] Correcting GPU compilation errors --- .../EWP/AdvanceEWP.cpp | 10 +++- Source/WindFarmParametrization/EWP/EWP.H | 2 - .../Fitch/AdvanceFitch.cpp | 8 ++- Source/WindFarmParametrization/Fitch/Fitch.H | 2 - .../WindFarmParametrization/InitWindFarm.cpp | 25 +++------ .../Null/NullWindFarm.H | 41 +++++++------- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 54 +++++++++++++++---- .../SimpleActuatorDisk/SimpleAD.H | 5 ++ Source/WindFarmParametrization/WindFarm.H | 17 +++--- 9 files changed, 98 insertions(+), 66 deletions(-) diff --git a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp index 69bbc746a..da59c8d03 100644 --- a/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp +++ b/Source/WindFarmParametrization/EWP/AdvanceEWP.cpp @@ -65,7 +65,7 @@ EWP::source_terms_cellcentered (const Geometry& geom, { get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, - d_wind_speed, d_thrust_coeff, d_power); + wind_speed, thrust_coeff, power); auto dx = geom.CellSizeArray(); auto ProbLoArr = geom.ProbLoArray(); @@ -74,6 +74,14 @@ EWP::source_terms_cellcentered (const Geometry& geom, Real d_rotor_rad = rotor_rad; Real d_hub_height = hub_height; + Gpu::DeviceVector d_wind_speed(wind_speed.size()); + Gpu::DeviceVector d_thrust_coeff(thrust_coeff.size()); + + // Copy data from host vectors to device vectors + Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); + Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); + + // Domain valid box const amrex::Box& domain = geom.Domain(); int domlo_z = domain.smallEnd(2); diff --git a/Source/WindFarmParametrization/EWP/EWP.H b/Source/WindFarmParametrization/EWP/EWP.H index bd4fc4a44..031416f00 100644 --- a/Source/WindFarmParametrization/EWP/EWP.H +++ b/Source/WindFarmParametrization/EWP/EWP.H @@ -40,8 +40,6 @@ protected: amrex::Vector xloc, yloc; amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; }; #endif diff --git a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp index c3462e8d1..ce9ef9892 100644 --- a/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp +++ b/Source/WindFarmParametrization/Fitch/AdvanceFitch.cpp @@ -104,7 +104,7 @@ Fitch::source_terms_cellcentered (const Geometry& geom, { get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, - d_wind_speed, d_thrust_coeff, d_power); + wind_speed, thrust_coeff, power); auto dx = geom.CellSizeArray(); @@ -121,6 +121,12 @@ Fitch::source_terms_cellcentered (const Geometry& geom, mf_vars_fitch.setVal(0.0); Real d_hub_height = hub_height; Real d_rotor_rad = rotor_rad; + Gpu::DeviceVector d_wind_speed(wind_speed.size()); + Gpu::DeviceVector d_thrust_coeff(thrust_coeff.size()); + + // Copy data from host vectors to device vectors + Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); + Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { diff --git a/Source/WindFarmParametrization/Fitch/Fitch.H b/Source/WindFarmParametrization/Fitch/Fitch.H index 2443d147b..78bf2b375 100644 --- a/Source/WindFarmParametrization/Fitch/Fitch.H +++ b/Source/WindFarmParametrization/Fitch/Fitch.H @@ -40,8 +40,6 @@ protected: amrex::Vector xloc, yloc; amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; }; #endif diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index e2a96fc32..149e66820 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -44,12 +44,7 @@ WindFarm::read_windfarm_locations_table(const std::string windfarm_loc_table, " entry erf.windfarm_loc_table which should not be None. \n"); } - d_xloc.resize(xloc.size()); - d_yloc.resize(yloc.size()); - amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); - amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); - - set_turb_loc(d_xloc, d_yloc); + set_turb_loc(xloc, yloc); } @@ -176,10 +171,6 @@ WindFarm::read_windfarm_spec_table(const std::string windfarm_spec_table) thrust_coeff.resize(nlines); power.resize(nlines); - d_wind_speed.resize(nlines); - d_thrust_coeff.resize(nlines); - d_power.resize(nlines); - Real rotor_dia; file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power; rotor_rad = rotor_dia*0.5; @@ -198,12 +189,8 @@ WindFarm::read_windfarm_spec_table(const std::string windfarm_spec_table) } file_turb_table.close(); - Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin()); - Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin()); - Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin()); - set_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, - d_wind_speed, d_thrust_coeff, d_power); + wind_speed, thrust_coeff, power); } @@ -211,8 +198,8 @@ void WindFarm::fill_Nturb_multifab(const Geometry& geom, MultiFab& mf_Nturb) { - Real* d_xloc_ptr = d_xloc.data(); - Real* d_yloc_ptr = d_yloc.data(); + Real* xloc_ptr = xloc.data(); + Real* yloc_ptr = yloc.data(); mf_Nturb.setVal(0); @@ -236,8 +223,8 @@ WindFarm::fill_Nturb_multifab(const Geometry& geom, Real y2 = ProbLoArr[1] + (lj+1)*dx[1]; for(int it=0; it x1 and d_xloc_ptr[it]+1e-12 < x2 and - d_yloc_ptr[it]+1e-12 > y1 and d_yloc_ptr[it]+1e-12 < y2){ + if( xloc_ptr[it]+1e-12 > x1 and xloc_ptr[it]+1e-12 < x2 and + yloc_ptr[it]+1e-12 > y1 and yloc_ptr[it]+1e-12 < y2){ Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1; } } diff --git a/Source/WindFarmParametrization/Null/NullWindFarm.H b/Source/WindFarmParametrization/Null/NullWindFarm.H index ed280d26a..4cbdd73c3 100644 --- a/Source/WindFarmParametrization/Null/NullWindFarm.H +++ b/Source/WindFarmParametrization/Null/NullWindFarm.H @@ -4,7 +4,6 @@ #include #include #include -#include class NullWindFarm { @@ -30,42 +29,42 @@ public: const amrex::MultiFab& mf_Nturb) = 0; virtual void set_turb_spec(const amrex::Real& rotor_rad, const amrex::Real& hub_height, - const amrex::Real& thrust_coeff_standing, const amrex::Gpu::DeviceVector& d_wind_speed, - const amrex::Gpu::DeviceVector& d_thrust_coeff, - const amrex::Gpu::DeviceVector& d_power) + const amrex::Real& thrust_coeff_standing, const amrex::Vector& wind_speed, + const amrex::Vector& thrust_coeff, + const amrex::Vector& power) { m_rotor_rad = rotor_rad; m_hub_height = hub_height; m_thrust_coeff_standing = thrust_coeff_standing; - m_d_wind_speed = d_wind_speed; - m_d_thrust_coeff = d_thrust_coeff; - m_d_power = d_power; + m_wind_speed = wind_speed; + m_thrust_coeff = thrust_coeff; + m_power = power; } - virtual void set_turb_loc (const amrex::Gpu::DeviceVector& d_xloc, - const amrex::Gpu::DeviceVector& d_yloc) + virtual void set_turb_loc (const amrex::Vector& xloc, + const amrex::Vector& yloc) { - m_d_xloc = d_xloc; - m_d_yloc = d_yloc; + m_xloc = xloc; + m_yloc = yloc; } void get_turb_spec (amrex::Real& rotor_rad, amrex::Real& hub_height, - amrex::Real& thrust_coeff_standing, amrex::Gpu::DeviceVector& d_wind_speed, - amrex::Gpu::DeviceVector& d_thrust_coeff, amrex::Gpu::DeviceVector& d_power) + amrex::Real& thrust_coeff_standing, amrex::Vector& wind_speed, + amrex::Vector& thrust_coeff, amrex::Vector& power) { rotor_rad = m_rotor_rad; hub_height = m_hub_height; thrust_coeff_standing = m_thrust_coeff_standing; - d_wind_speed = m_d_wind_speed; - d_thrust_coeff = m_d_thrust_coeff; - d_power = m_d_power; + wind_speed = m_wind_speed; + thrust_coeff = m_thrust_coeff; + power = m_power; } - void get_turb_loc (amrex::Gpu::DeviceVector& d_xloc, - amrex::Gpu::DeviceVector& d_yloc) + void get_turb_loc (amrex::Vector& xloc, + amrex::Vector& yloc) { - d_xloc = m_d_xloc; - d_yloc = m_d_yloc; + xloc = m_xloc; + yloc = m_yloc; } protected: @@ -73,8 +72,6 @@ protected: amrex::Vector m_xloc, m_yloc; amrex::Real m_hub_height, m_rotor_rad, m_thrust_coeff_standing, m_nominal_power; amrex::Vector m_wind_speed, m_thrust_coeff, m_power; - amrex::Gpu::DeviceVector m_d_wind_speed, m_d_thrust_coeff, m_d_power; - amrex::Gpu::DeviceVector m_d_xloc, m_d_yloc; }; diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index a452e7a26..a54c97c81 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -47,6 +47,32 @@ SimpleAD::update (const Real& dt_advance, } } +AMREX_FORCE_INLINE +AMREX_GPU_DEVICE +void cell_in_which_act_disk(const Real& y, const Real& z, + const Real* d_xloc, + const Real* d_yloc, + const Real& d_rotor_rad, + const Real& d_hub_height, + const Real& x1, const Real& x2) +{ + //Vector which_act_disk; + /*for(long unsigned int it=0;it x1 and d_xloc[it]+1e-12 < x2) { + if(std::pow((y-d_yloc[it])*(y-d_yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { + //which_act_disk.push_back(it); + } + } + } + if(which_act_disk.size() > 1){ + amrex::Error("Actuator disks are overlapping. Visualize actuator_disks.vtk " + "and check the windturbine locations input file. Exiting.."); + + }*/ + //return which_act_disk; +} + + void SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, @@ -54,14 +80,15 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& U_old, const MultiFab& V_old) { - Gpu::DeviceVector d_xloc, d_yloc; - Real d_rotor_rad, d_hub_height, d_thrust_coeff_standing; - Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - get_turb_loc(d_xloc, d_yloc); - get_turb_spec(d_rotor_rad, d_hub_height, d_thrust_coeff_standing, - d_wind_speed, d_thrust_coeff, d_power); + get_turb_loc(xloc, yloc); + get_turb_spec(rotor_rad, hub_height, thrust_coeff_standing, + wind_speed, thrust_coeff, power); + Gpu::DeviceVector d_xloc(xloc.size()); + Gpu::DeviceVector d_yloc(yloc.size()); + Gpu::copy(Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin()); + Gpu::copy(Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin()); auto dx = geom.CellSizeArray(); auto ProbLoArr = geom.ProbLoArray(); @@ -78,6 +105,14 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt mf_vars_simpleAD.setVal(0.0); + Real d_rotor_rad = rotor_rad; + Real d_hub_height = hub_height; + // Get raw pointers to device vectors + + Real* d_xloc_ptr = d_xloc.data(); + Real* d_yloc_ptr = d_yloc.data(); + long unsigned int nturbs = xloc.size(); + for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) { const Box& gbx = mfi.growntilebox(1); @@ -101,11 +136,12 @@ SimpleAD::source_terms_cellcentered (const Geometry& geom, Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction Real fac = 0.0; + int check_int = 0; - for(long unsigned int it=0;it x1 and d_xloc[it]+1e-12 < x2) { - if(std::pow((y-d_yloc[it])*(y-d_yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { + for(long unsigned int it=0;it x1 and d_xloc_ptr[it]+1e-12 < x2) { + if(std::pow((y-d_yloc_ptr[it])*(y-d_yloc_ptr[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { check_int++; fac = -2.0*std::pow(u_vel(i,j,k)*std::cos(phi) + v_vel(i,j,k)*std::sin(phi), 2.0)*0.5*(1.0-0.5); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H index dc0b8a9b0..ce56c3f79 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/SimpleAD.H @@ -34,6 +34,11 @@ public: amrex::MultiFab& V_old, const amrex::MultiFab& mf_vars); +protected: + amrex::Vector xloc, yloc; + amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; + amrex::Vector wind_speed, thrust_coeff, power; + }; #endif diff --git a/Source/WindFarmParametrization/WindFarm.H b/Source/WindFarmParametrization/WindFarm.H index 95b2e3fa9..6aa24e6c1 100644 --- a/Source/WindFarmParametrization/WindFarm.H +++ b/Source/WindFarmParametrization/WindFarm.H @@ -4,7 +4,6 @@ #include #include #include -#include #include "NullWindFarm.H" #include "Fitch.H" @@ -76,18 +75,18 @@ public: } void set_turb_spec(const amrex::Real& a_rotor_rad, const amrex::Real& a_hub_height, - const amrex::Real& a_thrust_coeff_standing, const amrex::Gpu::DeviceVector& a_d_wind_speed, - const amrex::Gpu::DeviceVector& a_d_thrust_coeff, - const amrex::Gpu::DeviceVector& a_d_power) override + const amrex::Real& a_thrust_coeff_standing, const amrex::Vector& a_wind_speed, + const amrex::Vector& a_thrust_coeff, + const amrex::Vector& a_power) override { m_windfarm_model[0]->set_turb_spec(a_rotor_rad, a_hub_height, a_thrust_coeff_standing, - a_d_wind_speed, a_d_thrust_coeff, a_d_power); + a_wind_speed, a_thrust_coeff, a_power); } - void set_turb_loc (const amrex::Gpu::DeviceVector& a_d_xloc, - const amrex::Gpu::DeviceVector& a_d_yloc) override + void set_turb_loc (const amrex::Vector& a_xloc, + const amrex::Vector& a_yloc) override { - m_windfarm_model[0]->set_turb_loc(a_d_xloc, a_d_yloc); + m_windfarm_model[0]->set_turb_loc(a_xloc, a_yloc); } protected: @@ -95,8 +94,6 @@ protected: amrex::Vector xloc, yloc; amrex::Real hub_height, rotor_rad, thrust_coeff_standing, nominal_power; amrex::Vector wind_speed, thrust_coeff, power; - amrex::Gpu::DeviceVector d_wind_speed, d_thrust_coeff, d_power; - amrex::Gpu::DeviceVector d_xloc, d_yloc; /*! \brief Create and set the specified windfarm model */ template From 92c8c9d90922a1c098f44103081585df5d77098d Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Wed, 17 Jul 2024 09:57:22 -0700 Subject: [PATCH 27/28] All errors resolved --- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index a54c97c81..bc36c63e2 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -47,32 +47,6 @@ SimpleAD::update (const Real& dt_advance, } } -AMREX_FORCE_INLINE -AMREX_GPU_DEVICE -void cell_in_which_act_disk(const Real& y, const Real& z, - const Real* d_xloc, - const Real* d_yloc, - const Real& d_rotor_rad, - const Real& d_hub_height, - const Real& x1, const Real& x2) -{ - //Vector which_act_disk; - /*for(long unsigned int it=0;it x1 and d_xloc[it]+1e-12 < x2) { - if(std::pow((y-d_yloc[it])*(y-d_yloc[it]) + (z-d_hub_height)*(z-d_hub_height),0.5) < d_rotor_rad) { - //which_act_disk.push_back(it); - } - } - } - if(which_act_disk.size() > 1){ - amrex::Error("Actuator disks are overlapping. Visualize actuator_disks.vtk " - "and check the windturbine locations input file. Exiting.."); - - }*/ - //return which_act_disk; -} - - void SimpleAD::source_terms_cellcentered (const Geometry& geom, const MultiFab& cons_in, From fa3c78d02aa66f12a18736ef3ea0cc85bd26a602 Mon Sep 17 00:00:00 2001 From: Mahesh Natarajan Date: Wed, 17 Jul 2024 15:20:20 -0700 Subject: [PATCH 28/28] Removing unwanted lines --- Source/ERF.cpp | 1 - Source/WindFarmParametrization/InitWindFarm.cpp | 5 +++-- .../SimpleActuatorDisk/AdvanceSimpleAD.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/ERF.cpp b/Source/ERF.cpp index 1765c6398..ad914a85a 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -1133,7 +1133,6 @@ ERF::initializeMicrophysics (const int& a_nlevsmax /*!< number of AMR levels */) void ERF::initializeWindFarm(const int& a_nlevsmax/*!< number of AMR levels */ ) { - //std::cout << "Solver choice windfarm is " << solverChoice.windfarm_type << "\n"; windfarm = std::make_unique(a_nlevsmax, solverChoice.windfarm_type); } diff --git a/Source/WindFarmParametrization/InitWindFarm.cpp b/Source/WindFarmParametrization/InitWindFarm.cpp index 149e66820..0d6234fb6 100644 --- a/Source/WindFarmParametrization/InitWindFarm.cpp +++ b/Source/WindFarmParametrization/InitWindFarm.cpp @@ -1,5 +1,5 @@ /** - * \file ERF_init_windfarm.cpp + * \file InitWindFarm.cpp */ #include @@ -19,11 +19,12 @@ WindFarm::read_tables (std::string windfarm_loc_table, const Real latitude_lo, const Real longitude_lo) { - std::cout << "Reading tables " << "\n"; + amrex::Print() << "Reading wind turbine locations table" << "\n"; read_windfarm_locations_table(windfarm_loc_table, x_y, lat_lon, latitude_lo,longitude_lo); + amrex::Print() << "Reading wind turbine specifications table" << "\n"; read_windfarm_spec_table(windfarm_spec_table); } diff --git a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp index bc36c63e2..3f26533ab 100644 --- a/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp +++ b/Source/WindFarmParametrization/SimpleActuatorDisk/AdvanceSimpleAD.cpp @@ -11,7 +11,7 @@ SimpleAD::advance (const Geometry& geom, MultiFab& U_old, MultiFab& V_old, MultiFab& W_old, - const MultiFab& mf_Nturb) + const MultiFab& mf_Nturb) { AMREX_ALWAYS_ASSERT(W_old.nComp() > 0); AMREX_ALWAYS_ASSERT(mf_Nturb.nComp() > 0);