-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating Vertical Diffusion Solver #133
Merged
mwaxmonsky
merged 19 commits into
ESCOMP:development
from
mwaxmonsky:vertical-diffusion-solve
Oct 24, 2024
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d9d0e5d
Merge pull request #110 from ESCOMP/development
cacraigucar fd27d14
Change Liceense to Apache 2.0
nusbaume 592fe83
Remove old license file.
nusbaume 03f2251
Initial round of needed files for vertical diffusion solve.
mwaxmonsky 93a1dbf
Merge pull request #121 from ESCOMP/development
jimmielin f8ce60b
Merge pull request #130 from ESCOMP/development
nusbaume f1e03e4
Removing shr_ code.
mwaxmonsky f4231db
Updating module names to avoid conflicts.
mwaxmonsky 88f1dbb
Moving modules back to original names and removing host model copies …
mwaxmonsky 55db37b
Removing atmos_phys module prefix missed in previous commit.
mwaxmonsky 020927c
Merge branch 'main' into vertical-diffusion-solve
mwaxmonsky 3d3fa2a
Removing un-needed save
mwaxmonsky ab9d1cc
Consolidating finalize calls for deallocating local objects.
mwaxmonsky 9ba5be1
Moving code to be converted to new directory name.
mwaxmonsky 8b1bd86
Moving vertical diffusion to similar folder as CAM.
mwaxmonsky 2b03bea
Merge branch 'development' into vertical-diffusion-solve
mwaxmonsky a1e05a5
Reorganizing files per PR comments.
mwaxmonsky 396aaac
Addressing PR comments.
mwaxmonsky 0c91251
Additional formatting changes.
mwaxmonsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
module coords_1d | ||
|
||
! This module defines the Coords1D type, which is intended to to cache | ||
! commonly used information derived from a collection of sets of 1-D | ||
! coordinates. | ||
|
||
use shr_kind_mod, only: r8 => shr_kind_r8 | ||
|
||
implicit none | ||
private | ||
save | ||
|
||
public :: Coords1D | ||
|
||
type :: Coords1D | ||
! Number of sets of coordinates in the object. | ||
integer :: n = 0 | ||
! Number of coordinates in each set. | ||
integer :: d = 0 | ||
|
||
! All fields below will be allocated with first dimension "n". | ||
! The second dimension is d+1 for ifc, d for mid, del, and rdel, and | ||
! d-1 for dst and rdst. | ||
|
||
! Cell interface coordinates. | ||
real(r8), allocatable :: ifc(:,:) | ||
! Coordinates at cell mid-points. | ||
real(r8), allocatable :: mid(:,:) | ||
! Width of cells. | ||
real(r8), allocatable :: del(:,:) | ||
! Distance between cell midpoints. | ||
real(r8), allocatable :: dst(:,:) | ||
! Reciprocals: 1/del and 1/dst. | ||
real(r8), allocatable :: rdel(:,:) | ||
real(r8), allocatable :: rdst(:,:) | ||
contains | ||
procedure :: section | ||
procedure :: finalize | ||
end type Coords1D | ||
|
||
interface Coords1D | ||
module procedure new_Coords1D_from_fields | ||
module procedure new_Coords1D_from_int | ||
end interface | ||
|
||
contains | ||
|
||
! Constructor to create an object from existing data. | ||
function new_Coords1D_from_fields(ifc, mid, del, dst, & | ||
rdel, rdst) result(coords) | ||
real(r8), USE_CONTIGUOUS intent(in) :: ifc(:,:) | ||
real(r8), USE_CONTIGUOUS intent(in) :: mid(:,:) | ||
real(r8), USE_CONTIGUOUS intent(in) :: del(:,:) | ||
real(r8), USE_CONTIGUOUS intent(in) :: dst(:,:) | ||
real(r8), USE_CONTIGUOUS intent(in) :: rdel(:,:) | ||
real(r8), USE_CONTIGUOUS intent(in) :: rdst(:,:) | ||
type(Coords1D) :: coords | ||
|
||
coords = allocate_coords(size(ifc, 1), size(ifc, 2) - 1) | ||
|
||
coords%ifc = ifc | ||
coords%mid = mid | ||
coords%del = del | ||
coords%dst = dst | ||
coords%rdel = rdel | ||
coords%rdst = rdst | ||
|
||
end function new_Coords1D_from_fields | ||
|
||
! Constructor if you only have interface coordinates; derives all the other | ||
! fields. | ||
function new_Coords1D_from_int(ifc) result(coords) | ||
real(r8), USE_CONTIGUOUS intent(in) :: ifc(:,:) | ||
type(Coords1D) :: coords | ||
|
||
coords = allocate_coords(size(ifc, 1), size(ifc, 2) - 1) | ||
|
||
coords%ifc = ifc | ||
coords%mid = 0.5_r8 * (ifc(:,:coords%d)+ifc(:,2:)) | ||
coords%del = coords%ifc(:,2:) - coords%ifc(:,:coords%d) | ||
coords%dst = coords%mid(:,2:) - coords%mid(:,:coords%d-1) | ||
coords%rdel = 1._r8/coords%del | ||
coords%rdst = 1._r8/coords%dst | ||
|
||
end function new_Coords1D_from_int | ||
|
||
! Create a new Coords1D object that is a subsection of some other object, | ||
! e.g. if you want only the first m coordinates, use d_bnds=[1, m]. | ||
! | ||
! Originally this used pointers, but it was found to actually be cheaper | ||
! in practice just to make a copy, especially since pointers can impede | ||
! optimization. | ||
function section(self, n_bnds, d_bnds) | ||
class(Coords1D), intent(in) :: self | ||
integer, intent(in) :: n_bnds(2), d_bnds(2) | ||
type(Coords1D) :: section | ||
|
||
section = allocate_coords(n_bnds(2)-n_bnds(1)+1, d_bnds(2)-d_bnds(1)+1) | ||
|
||
section%ifc = self%ifc(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)+1) | ||
section%mid = self%mid(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)) | ||
section%del = self%del(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)) | ||
section%dst = self%dst(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)-1) | ||
section%rdel = self%rdel(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)) | ||
section%rdst = self%rdst(n_bnds(1):n_bnds(2),d_bnds(1):d_bnds(2)-1) | ||
|
||
end function section | ||
|
||
! Quick utility to get allocate each array with the correct size. | ||
function allocate_coords(n, d) result(coords) | ||
integer, intent(in) :: n, d | ||
type(Coords1D) :: coords | ||
|
||
coords%n = n | ||
coords%d = d | ||
|
||
allocate(coords%ifc(coords%n,coords%d+1)) | ||
allocate(coords%mid(coords%n,coords%d)) | ||
allocate(coords%del(coords%n,coords%d)) | ||
allocate(coords%dst(coords%n,coords%d-1)) | ||
allocate(coords%rdel(coords%n,coords%d)) | ||
allocate(coords%rdst(coords%n,coords%d-1)) | ||
|
||
end function allocate_coords | ||
|
||
! Deallocate and reset to initial state. | ||
subroutine finalize(self) | ||
class(Coords1D), intent(inout) :: self | ||
|
||
self%n = 0 | ||
self%d = 0 | ||
|
||
call guarded_deallocate(self%ifc) | ||
call guarded_deallocate(self%mid) | ||
call guarded_deallocate(self%del) | ||
call guarded_deallocate(self%dst) | ||
call guarded_deallocate(self%rdel) | ||
call guarded_deallocate(self%rdst) | ||
|
||
contains | ||
|
||
subroutine guarded_deallocate(array) | ||
real(r8), allocatable :: array(:,:) | ||
|
||
if (allocated(array)) deallocate(array) | ||
|
||
end subroutine guarded_deallocate | ||
|
||
end subroutine finalize | ||
|
||
end module coords_1d | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming the directory is to be named
to-be-ccpp-ized
orto-be-ccppized
(https://github.com/cacraigucar/atmospheric_physics/tree/atmos_phys_zmcleanup3/to_be_ccppized) since I've seen two variants around!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @jimmielin!
@nusbaume, @cacraigucar, @peverwhee, we might have discussed this previously so my apologies for not taking better notes but do we have a preferred layout/naming convention for these non-ccppized files? Particularly with coords1d and linear_1d_operators being helper files (which might be needed by other files later) and the high level interface in the solver file.
I think having them at separate layers might be best for organization but not too sure on the naming conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing this with @jimmielin and @cacraigucar I believe we decided for the
to_be_ccppized
directory to be completely flat. This was to essentially make that directory ugly on purpose so that future users/developers remain motivated to get everything CCPP-ized. Of course if anyone disagrees with this plan please let me know!@jimmielin @cacraigucar @peverwhee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flattened!