NREL / SOWFA

Other
130 stars 113 forks source link

tool WRFextraction in SOWFA #83

Open gengvic opened 2 years ago

gengvic commented 2 years ago

Hello,

I am interested in the tool WRFextraction in SOWFA. It allows to create the boundary condition files for OpenFOAM from WRF. I am confused about “WRFTOOF expects OpenFOAM boundary definitions in files named “_bc.dat” and “interior.dat”. Where could I find an example of these files? How I could provide these OpenFOAM boundary definitions files? Is there the examples of these boundary definition files? They aren’t In the exampleCases” example.mesoscaleInfluence.SWiFTsiteLubbock.11Nov2013Diurnal”. Thank you,

ewquon commented 2 years ago

Here's an example bc.dat file, with lat/lon/elevation columns:

 33.6105 -102.051 1020.19
 33.7105 -102.051 1020.19
 33.8105 -102.051 1020.19
 33.6105 -102.051 1030.19
 33.7105 -102.051 1030.19
 33.8105 -102.051 1030.19
 33.6105 -102.051 1040.19
 33.7105 -102.051 1040.19
 33.8105 -102.051 1040.19
 33.6105 -102.051 1050.19
 33.7105 -102.051 1050.19
 33.8105 -102.051 1050.19
 33.6105 -102.051 1060.19
 33.7105 -102.051 1060.19
 33.8105 -102.051 1060.19
 33.6105 -102.051 1070.19
 33.7105 -102.051 1070.19
 33.8105 -102.051 1070.19
 33.6105 -102.051 1080.19
 33.7105 -102.051 1080.19
 33.8105 -102.051 1080.19
 33.6105 -102.051 1090.19
 33.7105 -102.051 1090.19
 33.8105 -102.051 1090.19
Zhang-Zhaoyu commented 2 years ago

Here's an example bc.dat file, with lat/lon/elevation columns:

 33.6105 -102.051 1020.19
 33.7105 -102.051 1020.19
 33.8105 -102.051 1020.19
 33.6105 -102.051 1030.19
 33.7105 -102.051 1030.19
 33.8105 -102.051 1030.19
 33.6105 -102.051 1040.19
 33.7105 -102.051 1040.19
 33.8105 -102.051 1040.19
 33.6105 -102.051 1050.19
 33.7105 -102.051 1050.19
 33.8105 -102.051 1050.19
 33.6105 -102.051 1060.19
 33.7105 -102.051 1060.19
 33.8105 -102.051 1060.19
 33.6105 -102.051 1070.19
 33.7105 -102.051 1070.19
 33.8105 -102.051 1070.19
 33.6105 -102.051 1080.19
 33.7105 -102.051 1080.19
 33.8105 -102.051 1080.19
 33.6105 -102.051 1090.19
 33.7105 -102.051 1090.19
 33.8105 -102.051 1090.19

Hi ewquon,

When I tried to run the WRFextraction with ./wrftoof. The result shows like

opening : flnm(i) 1 wrfout_d01_2015-08-05_05_40_00.nc Dimensions: 1 100 1 109 1 88 WRF grid is clockwise rotated approx. -0.00000 deg. from true lat/lon. Compensating. Getting variables from solution file Have heat flux: T Processing body 1 : west_bc.dat Processing body 2 : east_bc.dat Processing body 3 : south_bc.dat Processing body 4 : north_bc.dat Processing body 5 : lower_bc.dat Processing body 6 : upper_bc.dat End.

My question is that I cannot find the output file (such as west_bc.dat) in the folder. Does it run correctly or the result is included in other files?

Thank you very much!

rthedin commented 2 years ago

The files *_bc.dat and interior.dat are inputs to wrttoof. When you give the list of lat/lon/elev, wrftoof will use those coordinates and the nc file and give you U/T/p_rgh interpolated onto those points, for the different times that your nc files refer to. Note that wrftoof also has -startdate as input and that helps you align your SOWFA simulation with a real date (what datetime the time 0 corresponds to).

These are the steps you need to do:

  1. Get your points file for each boundary, containing x,y,z
  2. Converte the x,y,z into lat/lon/elev. These are your *_bc.dat file
  3. Run wrftoof from the same directory where the bc.dat files sit. Give startdate and -offset as needed (see wrftoof readme file)
hcOnel commented 2 years ago

Hi, I have two questions related to the wrftoof code:

  1. I've been modifying the code to extract some additional parameters I need. Please correct me if I'm wrong, but this script seems to be able to interpolate onto angled planes as well (i.e. not aligned with N, S, E or W), say, a north-east aligned plane. The finterp function seems to be capable. If that is the case, I assume that the N, S, E, W construct is purely for the purpose of suiting SOWFA simulations? Or would an angled plane introduce large errors?
  2. I could not manage to extract multiple time steps when a single wrfout file has multiple time records. All I get is a single time folder (I guess the latest time record the wrfout file has?). I've tried setting the -startdate and -offset arguments manually but no luck. Am I missing something, or am I supposed to run WRF with frames_per_outfile set to 1 in the first place?

Thank you

Zhang-Zhaoyu commented 2 years ago

Hi,

I have the same problem with you with the second question. Please let me know if you have a solution. Thank you very much!!

gaoxiangand commented 2 years ago

Hello, I extracted the boundary but the operation always returns an error as follows:

opening : flnm(i) 1 wrfout_d01_2000-01-24_16:00:00

Dimensions: 1 50 1 50 1 50

Reading latitude/longitude from latlong.nc

The WRF grid is blessings approx. -0.00000 deg. From true Lat /lon.

Getting variables from solution file

Have heat flux: T

Processing body 1 : west_bc.dat

Precomputing points for body 1

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:

0 0x7efd5e8952ed in ???

1 0x7efd5e894503 in ???

2 0x7efd5e129f0f in ???

3 0x55754b1f1ab7 in ???

4 0x55754b1e76be in ???

5 0x7efd5e10cc86 in ???

6 0x55754b1e76f9 in ???

7 0xffffffffffffffff in ???

Segmentation fault (core dumped)

I feel like it might be because there's a problem with the _bC.dat I extracted. So I would like to ask how to extract the coordinates x,y,z of each boundary point and convert them into longitude/latitude/altitude. Is there a program that can be provided?

ewquon commented 2 years ago

Hi,

I have the same problem with you with the second question. Please let me know if you have a solution. Thank you very much!!

I have scripted a workaround that you can adapt for your work:

#!/bin/bash
set -e

# TOOF settings
converter="$HOME/SOWFA/tools/WRFextraction/wrftoof"
opts='-rotation 0.0 -qwall'
startdate='2016-11-21_07_00_00' # used to calculate offset (in seconds) for output boundaryData

# meso data description
wrfout='/projects/windsim/MMC/WRF_cut_domain/d02/20161121'
prefix='WFIP2.control.d02.'
suffix='.nc'

# date/time parsing
datefmt='+%Y-%m-%d_%H_%M_%S'
parse_date()
{
    # Converts the datetime string from the file name into the number of
    # seconds since $startdate, to be used as input to TOOF
    name="$1"
    gnucurrent="${name:0:4}/${name:4:2}/${name:6:2} ${name:9:2}:${name:11:2}:${name:13:2}"

    currentsec=`date -d "$gnucurrent" +%s`
    offset=$((currentsec-startsec))
    start=`date -d "$gnucurrent" $datefmt`
    echo "-startdate $start -offset $offset"
}

gnudate()
{
    datestr=`echo $1 | sed 's/-/\//g'`
    datestr=`echo $datestr | sed 's/_/ /'`
    datestr=`echo $datestr | sed 's/_/:/g'`
    echo $datestr
}
gnustart=`gnudate $startdate`
startsec=`date -d "$gnustart" +%s`

#
# EXECUTION STARTS HERE
#
for soln in $wrfout/$prefix*$suffix; do
    name=${soln#*$prefix}
    name=${name%$suffix}
    echo ''
    echo "Processing $name"
    date_settings=`parse_date $name`
    echo "$converter $soln $date_settings $opts" > log.$name
    time ($converter $soln $date_settings $opts 2>&1 >> log.$name)
done

Hopefully the script makes sense.

ewquon commented 2 years ago

@gaoxiangand You can see the bc file format here: https://github.com/NREL/SOWFA/blob/103832ebbae07b62220858a1e3da4b5e7d6375bd/tools/WRFextraction/module_openfoam_bc.F#L51-L52 The number of lines in the file correspond to the number of boundary points to extract. Each line provides a latitude, longitude, and altitude. Since it's a fortran reader, the delimiter doesn't matter. TOOF doesn't use WRF's HGT terrain map, so a "gotcha" might be that you're specifying a height above ground level rather than above sea level.

gaoxiangand commented 1 year ago

Hello, thank you very much for your answer.

I am interested in the WRF extraction tool in SOWFA. But when I use *_bc.dat input, and (./wrftoof wrfout_d03_2000-01-25_12:00:00 -startdate 2000-01-25_12_00_00-offset 2000) command to extract the speed of each boundary, the reason is all negative, as shown in the following(north/2000/U).

10201

( ( -6.5704446 -5.0668082 -0.0196759) ( -6.5419059 -4.9812737 -0.0197884) ( -6.5419059 -4.9812737 -0.0197884) ( -6.5419059 -4.9812737 -0.0197884) ( -6.5133672 -4.8957396 -0.0199009) ( -6.4757080 -4.8093982 -0.0208689) ( -6.4757080 -4.8093982 -0.0208689) ( -6.4411683 -4.7315555 -0.0218498) ( -6.4411683 -4.7315555 -0.0218498) ( -6.4411683 -4.7315555 -0.0218498) So I want to ask, what could be the cause of this phenomenon?

ewquon commented 1 year ago

If you're sure you're inputing the correct latitude, longitude, and altitude above sea level, then I would check your WRF input data. A few of the points you're showing are repeated, I wonder if you're sampling out of the WRF bounds and it's just giving you the closest point.

gaoxiangand commented 1 year ago

Hello, thank you very much for your answer!

I checked my WRF input data and modified it to ensure sampling within the WRF limits. At present, there are no duplicate points on the output boundary. However, it still appears that the speed is all negative. So I would like to ask if it is because the latitude, longitude and altitude I entered are incorrect? The result I entered is a region I selected myself, as shown below: north_bc.dat:
29.6400 116.2000 100.0000
29.6400 116.2005 100.0000 29.6400 116.2010 100.0000 29.6400 116.2015 100.0000 29.6400 116.2020 100.0000 29.6400 116.2025 100.0000 29.6400 116.2030 100.0000 29.6400 116.2035 100.0000 29.6400 116.2040 100.0000 29.6400 116.2045 100.0000 29.6400 116.2050 100.0000 29.6400 116.2055 100.0000 Here I also want to ask whether my input (* _bc. dat) can select a small region from the WRF results to extract data? However, the altitude of the ground in the WRF simulation results is variable, so should the area (lower_bc. dat) I select be consistent with that in the WRF?

ewquon commented 1 year ago

I'm not sure if I've made it clear or not, but the altitudes are absolute values, not relative to the ground. So if you're sampling at altitudes that are above the ground in WRF, and the bottom of your SOWFA mesh corresponds to the same topography as the WRF region, then TOOF should successfully map the solution from WRF to your SOWFA boundaries. The size of the region to extract from is irrelevant, it can be as big or small as you want.

gaoxiangand commented 1 year ago

hello

Thank you very much for your answer! I have a preliminary understanding of it. But I still have a few questions. For example, the wind speed I extracted is all negative. Is it correct? When I extract (lower and upper, east, west, north and south) boundary data, how do I with OpenFOAM coupling? Is there a similar example?

gaoshijingand commented 1 year ago

hello I have two questions about the wrftoof code:

  1. After successfully extracting data at each boundary using WRFextraction, I find that the extracted velocity U is always negative, as shown in the figure below. I would like to ask whether this phenomenon is normal? 3(PS4E){ J27%QX $9R_E)J

  2. When I use the command./wrftoof wrfout_d03_2000-01-25_12:00:00 -startdate 2000-01-25_12: 00:00-offset 0 I tried to extract data with different offsets, but I found that the data I extracted were all the same. So I would like to ask if a wrfout can only extract the data of one moment in time. With offset you can just change the name of the output folder.

wineallergy commented 10 months ago

Hello.sorrry to bother you. I want to use wrfextraction now. But I am new to these, please forgive me and help me if my question is too stupid. I really need help Firstly: I need to configure the wrtoof tool, right? I read the readme file, do I need to write the location of netCFD in the makefile and then type make? Can someone tell me how to configure it? Second, I know that bc.dat and interior.dat are used as the input of wrtoof, but I do not know at all what procedure they are extracted by. Can someone tell me how to extract it? I really appreciate it for any replies.best wishes.

Here's an example bc.dat file, with lat/lon/elevation columns:

 33.6105 -102.051 1020.19
 33.7105 -102.051 1020.19
 33.8105 -102.051 1020.19
 33.6105 -102.051 1030.19
 33.7105 -102.051 1030.19
 33.8105 -102.051 1030.19
 33.6105 -102.051 1040.19
 33.7105 -102.051 1040.19
 33.8105 -102.051 1040.19
 33.6105 -102.051 1050.19
 33.7105 -102.051 1050.19
 33.8105 -102.051 1050.19
 33.6105 -102.051 1060.19
 33.7105 -102.051 1060.19
 33.8105 -102.051 1060.19
 33.6105 -102.051 1070.19
 33.7105 -102.051 1070.19
 33.8105 -102.051 1070.19
 33.6105 -102.051 1080.19
 33.7105 -102.051 1080.19
 33.8105 -102.051 1080.19
 33.6105 -102.051 1090.19
 33.7105 -102.051 1090.19
 33.8105 -102.051 1090.19
rthedin commented 10 months ago
  1. No. You give the nc file as an argument to the compiled binary.
  2. There is a complete example here
wineallergy commented 10 months ago
  1. 不。您将 nc 文件作为参数提供给已编译的二进制文件。
  2. 这里有一个完整的例子

Thank you very much for your help. I'm sorry for not replying to you in time.I really appreciate for your help. I read this example and example:Biglow Canyon Boundary-coupled looks like a complete wrf-sowfa example with real terrain imported and that's what I want to do. But I still have some problems. (1) I am using sowfa based on Openfoam 2.4.x, do I have to reinstall sowfa6? (2) In the official sowfa example, I saw a case named example.mesoscaleInfluence.SWiFTsiteLubbock.11Nov2013Diurnal where the tendency.py reads the boundary conditions of wrf. But my wrfout file doesn't have some variables that mentioned in the code:'Uadv','Vadv','Thadv','Ug','Vg','Utend','Vtend','Ucor','Vcor','Uphys','Vphys' image image The error came from the above two sentences I looked up the official WRF Users' Guide and it doesn't have some of the variables in the code.So the error occcured: image Is there something wrong with my wrfout file? I really wondered, and it bothered me for a long time. How can I do to figure it out.My code is in the attachment.Can you give me some advice.thank you for reading this.Best wishes to yoy tendencyRead1 .txt

rthedin commented 10 months ago
  1. Yes. SOWFA-2.4 is built on top of OpenFOAM 2.4 and SOWFA-6 is built on top of OpenFOAM 6. You need to first compile OpenFOAM 6 and then compile SOWFA-6.
  2. Tendencies are a different type of mesoscale coupling. If you want to perform such coupling, there is a modified version of WRF developed during the mesoscale-to-microscale coupling project, available here.
wineallergy commented 9 months ago
  1. Yes. SOWFA-2.4 is built on top of OpenFOAM 2.4 and SOWFA-6 is built on top of OpenFOAM 6. You need to first compile OpenFOAM 6 and then compile SOWFA-6.
  2. Tendencies are a different type of mesoscale coupling. If you want to perform such coupling, there is a modified version of WRF developed during the mesoscale-to-microscale coupling project, available here.

Thank you very much for your help. The good news for me is that I have now successfully compiled the wrtoof tool, so I intend to use wrftoof for coupling rather than the tendency offline mmc. In the meantime, I have some questions that I would like to ask for your help. (1) I know that _bc_dat and interor_dat should be input to wrftoof, but the problem is I don't know how to get _bc_dat and interor_dat. I find the 2_wrfPreprocess here https://github.com/a2e-mmc/SOWFA-setups/blob/master/WFIP2/Biglow_boundaryCoupled/2_wrfPreprocess Can I use this program to gengerate get _bc_dat and interor_dat. (2)for the above URL, I have tried to run it, but because I have not successfully installed sowfa6 and slurm, I keep getting errors. So I want to do simple mmc coupling on SOWFA 2.4, I don't plan to add terrain files to it for now. Can I ask you to tell me how to get _bc_dat and interor_dat and then do an mmc coupling? Can you tell me the steps? And please forgive me if my questions are too stupid, but they have really bothered me for a long time. I am really confused.
Best wishes for you.

rthedin commented 9 months ago
  1. You convert it by using this python code starting on this line. See the comment on this very line. One of the code that gets imported there is available here. Later on, the generated *_bc.dat is copied to be used on wrftoof (this line).

    The interior points are obtained here.

  2. I haven't used SOWFA 2.4 in a long time so I am unable to confirm what works and what does not work. You can skip the SLURM stuff and re-write a script that works for you. You can also skip all the terrain stuff with no problem. The workflow is the same-- you should just follow the script and skip the parts that you don't need. I strongly recommend you try on a small problem and go line by line to understand what it is doing.

wineallergy commented 9 months ago
  1. You convert it by using this python code starting on this line. See the comment on this very line. One of the code that gets imported there is available here. Later on, the generated *_bc.dat is copied to be used on wrftoof (this line). The interior points are obtained here.
  2. I haven't used SOWFA 2.4 in a long time so I am unable to confirm what works and what does not work. You can skip the SLURM stuff and re-write a script that works for you. You can also skip all the terrain stuff with no problem. The workflow is the same-- you should just follow the script and skip the parts that you don't need. I strongly recommend you try on a small problem and go line by line to understand what it is doing.
  1. Thankyou very much for your help.
  2. I've now read both steps 1_process and 2_wrf_process, I already have a general understanding of them. but I was wondering do I have to generate the BoundaryData file that contain{north upper,lower,west,east.south} before I run 1_process and 2_wrf_process?I intend to set initializer=none in 1_process, but it seems that this BoundartData file must also be required in 2_wrf_process.
  3. If the file is required, I think the file can be generated by running precursor. I successfully ran an example of sowfa, but it only had north and west in postprocessing/BounaryData using the makeBoundaryDataFiles.north.sh and makeBoundaryDataFiles.west.sh that are given in the sowfa file, but BoundartData/{upper, lower, east, west, south, north} are needed in 2_wrf_process. I do not know what is going to do with it. Can I just try ,Can I modify makeBoundaryDataFiles.north.sh and makeBoundaryDataFiles.west.sh two files to extract information on the other side?Or is there a sloution to this?
  4. I really appreciate it for your reply.It is your reply that has kept me happy in such a difficult situation for me.
rthedin commented 9 months ago
  1. You don't have to have it before running the scripts-- the scripts will generate it for you provided you point to the correct WRF output data (example). That is key. That is why there is a second script dedicated to preparing the wrfout and putting into a format that SOWFA can use. The boundary data is created in the second script-- see constant/boundaryData link being created here. Keep in mind that if you're running an inflow-outflow case (that is, no cyclic boundary conditions on inlet and outlet), you need to provide some sort of BC at the inlet. The case I linked earlier make use of WRF data to couple mesoscale data to the microscale simulation.

    You do not need the initializer on the first script. These scripts are dedicated to a WRF-coupled scenario and the initial conditions will come from your interior point, hence no need to call any sort of initializer.

  2. You could very well generate the boundary data using a precursor. It depends on your goal with the simulation. That is a perfectly fine scenario. The saved boundary data is a reflection of what you asked for. See this example. In short, you probably just asked for the north and west boundaries in your controlDict (likely including sampling/boundaryData or analogous file). The reason all 6 boundaries are requested in the 2_wrf_process is because a larger domain is available and thus sampling at all 6 boundaries is possible. Note that only west/east/north/south are actually used as BCs.

    Note that makdeBoundaryDataFiles.*.sh are scripts specific to SOWFA-2.4. SOWFA 2.4 is an old release and you're encourage to switch to SOWFA-6. I am unable to provide detailed instructions for SOWFA 2.4.