Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

How to change the dynamic variables in CAM

jie_wong

jie wang
New Member
Hello,

I want to change the dynamic variables, such as temperature or wind, in particular model time. I found that dyn_in and dyn_out are used to contain the dynamic variables, thus dyn_out%t3 represent the temperature field. But after I overwrite/change the values of the dyn_out%t3, it seems make no change to the results of the models. So I am asking is the variable I change is wrong or the way is wrong? If it is, how to change/overwrite the dynamic (which I mean the 3-dimension atmosphere dield) variables?

Thanks.
 

nusbaume

Jesse Nusbaumer
CSEG and Liaisons
Staff member
Hi Jie Wang,

The use of the dyn_out structure is dycore and code location dependent, and so is likely not the best option if you want to modify the model state. Assuming you aren’t trying to experiment with the internal dycore routines or the dynamics-physics coupling itself, then the best location to change the model state is likely in the physics, specifically the physics_state structure, which contains numerous 3-D physics variables listed in this source file:

src/physics/cam/physics_types.F90

Then you could modify that structure either after d_p_coupling is called, which means it is after the dynamics has run, or before p_d_coupling, which is before the dynamics (but after the physics). You can find those coupling calls in the stepon_run routines here:

src/dynamics/<dyn>/stepon.F90

Where <dyn> is the dycore you are using (eul, fv, se, etc.).

Finally, if you are trying to target a specific geographic area (e.g. a lat/lon range) in the phys_state structure, then you can use the get_rlat_p and get_rlon_p routines in phys_grid to check for what that latitude/longitude value is (in radians) for a given physics chunk/column. Also, to get the chunk/column range, you'll just need to pull begchunk and endchunk from ppgrid, and then get the "ncols" from each chunk using get_ncols_p, which is also from phys_grid. So basically something like this:

Code:
use ppgrid, only: begchunk, endchunk
use phys_grid, only: get_ncols_p

do chunk=begchunk, endchunk
   ncols = get_ncols_p(chunk)
   do i=1,ncols
      !Increase column temperature by 5 Kelvin:
       phys_state(chunk)%t(i,:) = phys_state(chunk)%t(i,:) + 5._r8
   end do
end do

Anyways, I hope that helps, and if you are confused by anything I wrote just let me know.

Thanks, and have a great day!

Jesse
 

jie_wong

jie wang
New Member
Hi Jesse,
Thanks for you relpying! I understand what you told me why and how to modift the model state in physic_state. But I am also confused why I modify dyn_out%t3 didn't work. Because in d_p_coupling, the variables in dyn_out are passed to phys_state, so if I change the dyn_out before d_p_coupling the phys_state should be changed either? But it seems like it didn't work, that is my first question.
And my second question is explaining why I want to modify in dyn_out. For example, I want to add a high pressure system in the model in a particular time, if I add it in dyn_out, then I can see clearly how the system varies with model time. But If I modify in phys_state, because phys_state is determined by the dyn_out, so only the moment the system is exist, but there is no real system being added in the dynamic vairables. So maybe modification in phys_state is not right?
I hope I expain my question clearly, If not, please let me know.

Best Wishes!

Jie
 

nusbaume

Jesse Nusbaumer
CSEG and Liaisons
Staff member
Hi Jie,

In response to your two questions:

But I am also confused why I modify dyn_out%t3 didn't work.

I am not really sure without looking at your actual source code, but it could be for all sorts of reasons, and sadly I don’t see anything obvious in the code you have sent so far. However, I want to emphasize that using MPI is generally not a good way to change the model state, especially because the MPI calls you are are using are not scalable (the performance can get worse with an increasing number of processors). I should also note that we generally are only supposed to give a limited amount of support to CESM1 if it is not being used in a paleoclimate context, so I am sadly not sure if we can spend a large amount of time going through your code to find bugs. More information about our support policy can be found here:


But If I modify in phys_state, because phys_state is determined by the dyn_out

The situation you described would be a problem if you changed the phys_state variables just before d_p_coupling. However, if you add your phys_state change after that call then you are overwriting the values from dyn_out, and thus your changes will stay around and be “seen” by the model physics and dynamics. The same goes if you add the phys_state changes before p_d_coupling (then the dynamics will see the change first instead of the physics).

Anyways, sorry I couldn’t be of more help, but hopefully that helps clarify some things, and helps you get to implementing the changes you want? If you still have concerns about how to move forward with your experiments please let me know.

Thanks, and have a great day!

Jesse
 

jie_wong

jie wang
New Member
Hi Jesse!
Thank you for your patience! It seems your reccomendation of modifying phy_state works, I'll try this way. And another question is the scatter-gather problem using scatter_field_to_chunk. below is part of my modification code. First, I read the 3-d data in ' read_global', and then I try to scatter them to all mpi using 'scatter_field_to_chunk' so that all processes can use to data I read in. And then pass them to phy_state.

if (masterproc)then
write(*,*)'start read in modified file'
open(533,file='/WORK/sio_xmzhang_6/my_cesm/bash_file/phy_change/modift.txt')
read(533,*)(((read_global(i,j,k),i=1,im),j=1,jm),k=1,km)
endif

!! scatter
call scatter_field_to_chunk (1, 1, pver, hdim1, read_global, read_scatter)

write(*,*)'scatter success'

!! pass number to phy_state
do chunk=begchunk, endchunk
ncols = get_ncols_p(chunk)
do i=1,ncols
do k=1,pver
phys_state(chunk)%t(i,k) = read_scatter(i,chunk,k)
end do
end do
end do

But I am little confused with the function 'scatter_field_to_chunk' put in. Am I using it in right way?

As for my first question of my last post about changing the dyn_out didn't work. The code is bellow (which is done after dyn_run):

t3xy => dyn_out%t3
do k=1,km
do j=jfirstxy,jlastxy
do i= ifirstxy,ilastxy
t3xy(i,j,k)=work(i,j,k)
end do
end do
end do


Thanks

Best Wishes
Jie
 

nusbaume

Jesse Nusbaumer
CSEG and Liaisons
Staff member
Hi Jie,

Thanks for the code snippets! Sadly I'll need the entire modified source code file(s) in order to try and debug your issue, as I currently have no idea where exactly you are trying to use MPI, nor do I know how you have declared these variables. So If you can attach your modified files then I might be able to help more.

That all being said, CAM already has methods for reading in files and getting the values distributed, which will probably be better behaved than trying to create your own. I don't know exactly what your text file is like, but in general I would recommend reading it in once during the initialization phase of the model, for example in dyn_init in dyn_comp.F90, or phys_init in physpkg.F90. Then you can save the values in a variable declared in that same module that is then broadcast to the other tasks via mpibcast (assuming you only read the file on the masterproc node). Then whenever you need the values you can just add something like:

Code:
use dyn_comp, only: my_var

to the subroutine you want to use the values in, where my_var is the new variable you created that contains the text file value(s).

Anyways, I hope that helps, and good luck!

Jesse
 

jie_wong

jie wang
New Member
The situation you described would be a problem if you changed the phys_state variables just before d_p_coupling. However, if you add your phys_state change after that call then you are overwriting the values from dyn_out, and thus your changes will stay around and be “seen” by the model physics and dynamics. The same goes if you add the phys_state changes before p_d_coupling (then the dynamics will see the change first instead of the physics).
Hello,
I had problems again. It seems only the temperature modified in phy_state can overwrite the values from dyn_out. Thus, if I want to modify other variables such as u,v, omega or pressure, it seems did not work. So I wonder where is the right place to modify if I want to change U,V,omega or pressure.

Thanks
Jie
 

linlin

New Member
Hello,
I had problems again. It seems only the temperature modified in phy_state can overwrite the values from dyn_out. Thus, if I want to modify other variables such as u,v, omega or pressure, it seems did not work. So I wonder where is the right place to modify if I want to change U,V,omega or pressure.

Thanks
Jie

Hello Jie,

Hope this message finds you well!

If I understand your question correctly, you can also modify u,v,omega or pressure using the same method as how you modify temperature. u,v,omega, pressure and other variables are in the phys_state structure too. phys_state%t, phys_state%u, phys_state%v, phys_state%omega etc.

you can check out what variables are in the physics_state structure, which contains numerous 3-D physics variables listed in this source file:

src/physics/cam/physics_types.F90

Hope this helps.

Best,
Lin
 
Top