Skip to content

AtmosSimulation Constructor Refactor #3894

@nefrathenrici

Description

@nefrathenrici

This issue continues the refactoring to improve the user interface for setting up and running simulations. The ultimate goal is to move towards a more composable interface:

using ClimaAtmos
# Define the model, domain, and initial conditions as objects
model = AtmosModel(; moisture = Microphysics1Moment)
domain = SphereDomain(; h_elem = 30)
initial_condition = DryBaroclinicWave()
sim = AtmosSimulation(; model, domain, initial_condition)
solve_atmos!(sim)

The only way to construct an AtmosSimulation is via the monolithic get_simulation function, which requires an AtmosConfig. A new constructor which doesn't require AtmosConfig will be introduced. Responsibilities of get_simulation currently include comms_context setup, model and space creation, diagnostics initialization, and state/cache allocation.

Core Changes

  1. New AtmosSimulation Constructor

    A new, composable AtmosSimulation constructor will be introduced. It will serve as the primary user-facing entry point and will have a signature similar to:

    AtmosSimulation(; model, domain, initial_condition, surface_setup, comms_context, params, dt, start_date, many_more_kwargs...)

    This constructor will be responsible for the final steps of setting up the simulation, including:

    • Initializing diagnostics
    • Allocating the state and the cache
    • Creating the integrator object
  2. AbstractDomain structs

    To replace the use of parsed_args in get_spaces, new AbstractDomains will be added. These structs will store all spatial information currently contained in parsed_args (e.g., x_min, x_elem, z_stretch, nh_poly, dz_bottom). The initial hierarchy matches parsed_args["config"] and will include:

    • SphereDomain
    • ColumnDomain
    • BoxDomain
    • PlaneDomain

Refactoring of parsed_args-Dependent Functions

A significant part of this work involves refactoring the many "type getter" functions that currently depend on the parsed_args. These functions will have new methods that accept types/vals rather than parsed_args. The key functions include:

  • get_spaces: Will be refactored to dispatch on the new AbstractDomain types.
  • get_callbacks: Needs to be adapted to receive configuration (like output frequency) via explicit arguments or structs instead of parsed_args.
  • get_diagnostics: Similar to callbacks, its behavior will need to be configured directly. I expect this and the callbacks will be the biggest obstacle in the refactor, since it will be cumbersome to pass vectors of diagnostics/callbacks so we will need some convenience functions to simplify this aspect of simulation configuration.
  • get_surface_setup: Turned into keyword argument: AtmosSimulation(; surface_setup = ...)
  • get_tracers: Can be determined from the AtmosModel info for now since the only tracers available prescribed aerosols when applicable.
  • get_steady_state_velocity: Will use val or types for topography info.
  • get_state_restart: Will be simplified to take just a file path and comms_ctx.
  • ode_configuration: This will likely take many keyword arguments since it takes many parsed_args at the moment.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions