Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Add types and unify functions in BalanceLaws #1280

Merged
merged 2 commits into from
Jul 22, 2020
Merged

Add types and unify functions in BalanceLaws #1280

merged 2 commits into from
Jul 22, 2020

Conversation

charleskawczynski
Copy link
Member

@charleskawczynski charleskawczynski commented Jun 23, 2020

Description

  • Adds types to balance law (I have no strong opinions about the names here)
abstract type AbstractStateType end
struct Prognostic <: AbstractStateType end
struct Auxiliary <: AbstractStateType end
struct Gradient <: AbstractStateType end
struct GradientFlux <: AbstractStateType end
struct GradientLaplacian <: AbstractStateType end
struct Hyperdiffusive <: AbstractStateType end
struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end
  • Unifies vars_state (BalanceLaws) into a single function
  • Unifies number_states (BalanceLaws) into a single function
  • Unifies create_state (DGMethods) into a single function
  • Unifies extract_state (Diagnostics) into a single function

This PR also does a replace-all for state_conservative -> state_prognostic.

I have

  • Written and run all necessary tests with CLIMA by including tests/runtests.jl
  • Followed all necessary style guidelines and run julia .dev/climaformat.jl .
  • Updated the documentation to reflect changes from this PR.

For review by CLIMA developers

  • There are no open pull requests for this already
  • CLIMA developers with relevant expertise have been assigned to review this submission
  • The code conforms to the style guidelines and has consistent naming conventions. julia .dev/format.jl has been run in a separate commit.
  • This code does what it is technically intended to do (all numerics make sense physically and/or computationally)

@blallen
Copy link
Contributor

blallen commented Jun 23, 2020

Maybe rename

struct VerticalIntegrals <: AbstractStateType end
struct ReverseVerticalIntegrals <: AbstractStateType end

to

struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end

in order to have more descriptive names? You only know which direction an integral is going based on looking at the kernels.

OTOH, we maybe want to rewrite the integral kernels so you just specify the direction for each variable and don't require a corresponding VerticalIntegral variable for each ReverseVerticalIntegral variable.

More comments coming later.

@blallen
Copy link
Contributor

blallen commented Jun 23, 2020

Why do we need to pass FT as an argument to vars_state()? Isn't @vars just a short cut to various views/elements of an array? Why does it need to know the type of the elements in the array?

On a similar note, could we make vars_state a callable object? That way we could just store FT in the struct and not need to pass it to every function call.

@charleskawczynski
Copy link
Member Author

Why do we need to pass FT as an argument to vars_state()? Isn't @vars just a short cut to various views/elements of an array? Why does it need to know the type of the elements in the array?

Variable templates needs to know the type (I think it may be needed for MArrays) and rank of each variable.

On a similar note, could we make vars_state a callable object? That way we could just store FT in the struct and not need to pass it to every function call.

🤷‍♂️ I think then we'd have to pass vs = vars_state() through the call graph, which doesn't seem desirable. @simonbyrne ?

@charleskawczynski
Copy link
Member Author

struct UpwardIntegrals <: AbstractStateType end, struct DownwardIntegrals <: AbstractStateType end

❤️

@charleskawczynski
Copy link
Member Author

OTOH, we maybe want to rewrite the integral kernels so you just specify the direction for each variable and don't require a corresponding VerticalIntegral variable for each ReverseVerticalIntegral variable.

We could make another supertype :)

@blallen
Copy link
Contributor

blallen commented Jun 23, 2020

OTOH, we maybe want to rewrite the integral kernels so you just specify the direction for each variable and don't require a corresponding VerticalIntegral variable for each ReverseVerticalIntegral variable.

We could make another supertype :)

Sure, but how kernel_reverse_indefinite_stack_integral! works is that it literally flips the sign on an already calculated integral.

kernel_indefinite_stack_integral! actually does \int_z1^z (integrand) but kernel_indefinite_stack_integral! does \int_z^z2 (integrand) - \int_z1^z2 (integrand)`. After typing that, I realize links to actual code might be better:

https://github.com/CliMA/ClimateMachine.jl/blob/master/src/Numerics/DGMethods/DGModel_kernels.jl#L1723-L1730
versus
https://github.com/CliMA/ClimateMachine.jl/blob/master/src/Numerics/DGMethods/DGModel_kernels.jl#L1808-L1841

They really aren't equivalent operations at this point.

@charleskawczynski
Copy link
Member Author

charleskawczynski commented Jun 23, 2020

They really aren't equivalent operations at this point.

Ah, I misunderstood your original statement:

maybe want to rewrite the integral kernels so you just specify the direction for each variable and don't require a corresponding VerticalIntegral variable for each ReverseVerticalIntegral variable.

Yes, that seems reasonable. I imagine we could optionally pack this information into VerticalIntegral/ReverseVerticalIntegral, but what your suggesting sounds better I think.

@charleskawczynski
Copy link
Member Author

bors try

@charleskawczynski charleskawczynski force-pushed the ck/refactor_bl branch 3 times, most recently from e87cd66 to a638fa8 Compare June 24, 2020 18:22
bors bot added a commit that referenced this pull request Jun 24, 2020
@bors
Copy link
Contributor

bors bot commented Jun 24, 2020

try

Build failed:

@charleskawczynski charleskawczynski force-pushed the ck/refactor_bl branch 2 times, most recently from 9697159 to 1dbcf7c Compare June 25, 2020 18:31
@charleskawczynski
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Jun 25, 2020
@bors
Copy link
Contributor

bors bot commented Jun 25, 2020

try

Build failed:

@charleskawczynski charleskawczynski force-pushed the ck/refactor_bl branch 6 times, most recently from 066c21d to 74826a8 Compare June 25, 2020 23:52
@charleskawczynski
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jul 21, 2020
1280: Add types and unify functions in BalanceLaws r=charleskawczynski a=charleskawczynski

# Description

 - Adds types to balance law (I have no strong opinions about the names here)

```julia
abstract type AbstractStateType end
struct Prognostic <: AbstractStateType end
struct Auxiliary <: AbstractStateType end
struct Gradient <: AbstractStateType end
struct GradientFlux <: AbstractStateType end
struct GradientLaplacian <: AbstractStateType end
struct Hyperdiffusive <: AbstractStateType end
struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end
```

 - Unifies `vars_state` (BalanceLaws) into a single function
 - Unifies `number_states` (BalanceLaws) into a single function
 - Unifies `create_state` (DGMethods) into a single function
 - Unifies `extract_state` (Diagnostics) into a single function



1315: Add VerticalIntegralModel for integrating flow and tendency r=blallen a=blallen

# Description

This PR adds a VerticalIntegralModel that can be used to integrate both the flow field and flow tendency for use in the split explicit model in #1268. This model is tested for correctness using the 2D and 3D hydrostatic spindown initial states.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
Co-authored-by: Brandon Allen <ballen@mit.edu>
@bors
Copy link
Contributor

bors bot commented Jul 21, 2020

Build failed (retrying...):

bors bot added a commit that referenced this pull request Jul 21, 2020
1280: Add types and unify functions in BalanceLaws r=charleskawczynski a=charleskawczynski

# Description

 - Adds types to balance law (I have no strong opinions about the names here)

```julia
abstract type AbstractStateType end
struct Prognostic <: AbstractStateType end
struct Auxiliary <: AbstractStateType end
struct Gradient <: AbstractStateType end
struct GradientFlux <: AbstractStateType end
struct GradientLaplacian <: AbstractStateType end
struct Hyperdiffusive <: AbstractStateType end
struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end
```

 - Unifies `vars_state` (BalanceLaws) into a single function
 - Unifies `number_states` (BalanceLaws) into a single function
 - Unifies `create_state` (DGMethods) into a single function
 - Unifies `extract_state` (Diagnostics) into a single function



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jul 21, 2020

Build failed:

@charleskawczynski
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jul 21, 2020
1280: Add types and unify functions in BalanceLaws r=charleskawczynski a=charleskawczynski

# Description

 - Adds types to balance law (I have no strong opinions about the names here)

```julia
abstract type AbstractStateType end
struct Prognostic <: AbstractStateType end
struct Auxiliary <: AbstractStateType end
struct Gradient <: AbstractStateType end
struct GradientFlux <: AbstractStateType end
struct GradientLaplacian <: AbstractStateType end
struct Hyperdiffusive <: AbstractStateType end
struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end
```

 - Unifies `vars_state` (BalanceLaws) into a single function
 - Unifies `number_states` (BalanceLaws) into a single function
 - Unifies `create_state` (DGMethods) into a single function
 - Unifies `extract_state` (Diagnostics) into a single function



1321: More pedagogical computation of continuity equation r=blallen a=blallen

# Description

@jm-c pointed out that our current method for computing the continuity equation `∇u = 0` is a little counterintuitive. Here is one possible change we can make to improve the clarity while maintaining computational efficiency at the cost of some extra memory usage.



1359: Yt/boyd vandeven r=thomasgibson a=slifer50

# Description

Addition of the Boyd-Vandeven filter.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
Co-authored-by: Brandon Allen <ballen@mit.edu>
Co-authored-by: yassine <yassinetissaoui@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jul 21, 2020

Build failed (retrying...):

@charleskawczynski
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jul 21, 2020
1280: Add types and unify functions in BalanceLaws r=charleskawczynski a=charleskawczynski

# Description

 - Adds types to balance law (I have no strong opinions about the names here)

```julia
abstract type AbstractStateType end
struct Prognostic <: AbstractStateType end
struct Auxiliary <: AbstractStateType end
struct Gradient <: AbstractStateType end
struct GradientFlux <: AbstractStateType end
struct GradientLaplacian <: AbstractStateType end
struct Hyperdiffusive <: AbstractStateType end
struct UpwardIntegrals <: AbstractStateType end
struct DownwardIntegrals <: AbstractStateType end
```

 - Unifies `vars_state` (BalanceLaws) into a single function
 - Unifies `number_states` (BalanceLaws) into a single function
 - Unifies `create_state` (DGMethods) into a single function
 - Unifies `extract_state` (Diagnostics) into a single function



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
@charleskawczynski
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 22, 2020

@bors bors bot merged commit dcf47cd into master Jul 22, 2020
@bors bors bot deleted the ck/refactor_bl branch July 22, 2020 01:29
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 22, 2020
fill out communication functions and add necessary aux variables

don't statecheck aux while adding new aux variables

turn off restart values for now

remove time averaging over fast mode and add flag for reconciliation

add zero initializations

replace .=- with .-=

rebase fix for `test_vertical_integral_model.jl`

convert `tendency_from_slow_to_fast!` to new reshape&broadcast setup

Update `reconcile_from_fast_to_slow!` with new reshape&broadcast method

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 22, 2020
drive shallow water model by HB model

add coupling traits, use to replace forcing traits in shallow water model

move coupling for SWModel to file in SplitExplicit

add coupling to HBModel, get fully coupled model to converge to analytic solution

Add hydrostatic spindown tests with actual multi-rate happening

remove old integral models

get flow deviation working with new reshape&broadcast setup (on cpu).

Remove stub functions for partial coupling

use Coupling trait for dispatch instead of boolean in SplitExplicitMethod.

use abbreviated model names

Update to new functions from CliMA#1280
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 22, 2020
fill out communication functions and add necessary aux variables

don't statecheck aux while adding new aux variables

turn off restart values for now

remove time averaging over fast mode and add flag for reconciliation

add zero initializations

replace .=- with .-=

rebase fix for `test_vertical_integral_model.jl`

convert `tendency_from_slow_to_fast!` to new reshape&broadcast setup

Update `reconcile_from_fast_to_slow!` with new reshape&broadcast method

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 22, 2020
drive shallow water model by HB model

add coupling traits, use to replace forcing traits in shallow water 
model

move coupling for SWModel to file in SplitExplicit

add coupling to HBModel, get fully coupled model to converge to analytic 
solution

Add hydrostatic spindown tests with actual multi-rate happening

remove old integral models

get flow deviation working with new reshape&broadcast setup (on cpu).

Remove stub functions for partial coupling

use Coupling trait for dispatch instead of boolean in 
SplitExplicitMethod.

use abbreviated model names

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 23, 2020
fill out communication functions and add necessary aux variables

don't statecheck aux while adding new aux variables

turn off restart values for now

remove time averaging over fast mode and add flag for reconciliation

add zero initializations

replace .=- with .-=

rebase fix for `test_vertical_integral_model.jl`

convert `tendency_from_slow_to_fast!` to new reshape&broadcast setup

Update `reconcile_from_fast_to_slow!` with new reshape&broadcast method

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 23, 2020
drive shallow water model by HB model

add coupling traits, use to replace forcing traits in shallow water
model

move coupling for SWModel to file in SplitExplicit

add coupling to HBModel, get fully coupled model to converge to analytic
solution

Add hydrostatic spindown tests with actual multi-rate happening

remove old integral models

get flow deviation working with new reshape&broadcast setup (on cpu).

Remove stub functions for partial coupling

use Coupling trait for dispatch instead of boolean in
SplitExplicitMethod.

use abbreviated model names

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 23, 2020
fill out communication functions and add necessary aux variables

don't statecheck aux while adding new aux variables

turn off restart values for now

remove time averaging over fast mode and add flag for reconciliation

add zero initializations

replace .=- with .-=

rebase fix for `test_vertical_integral_model.jl`

convert `tendency_from_slow_to_fast!` to new reshape&broadcast setup

Update `reconcile_from_fast_to_slow!` with new reshape&broadcast method

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
blallen added a commit to blallen/CLIMA that referenced this pull request Jul 23, 2020
drive shallow water model by HB model

add coupling traits, use to replace forcing traits in shallow water
model

move coupling for SWModel to file in SplitExplicit

add coupling to HBModel, get fully coupled model to converge to analytic
solution

Add hydrostatic spindown tests with actual multi-rate happening

remove old integral models

get flow deviation working with new reshape&broadcast setup (on cpu).

Remove stub functions for partial coupling

use Coupling trait for dispatch instead of boolean in
SplitExplicitMethod.

use abbreviated model names

Update to new functions from CliMA#1280

Co-Authored-By: Jean-Michel Campin <jm-c@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Refactor Non-behavior changing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants