Skip to content

Class emulator::EmulatorComp

ClassList > emulator > EmulatorComp

Abstract base class for all emulated E3SM components. More...

  • #include <emulator_comp.hpp>

Inherited by the following classes: emulator::EmulatorAtm

Public Functions

Type Name
EmulatorComp (CompType type)
Construct an emulator component of the given type.
MPI_Comm comm () const
Get MPI communicator.
int comp_id () const
Get component ID.
void create_instance (MPI_Comm comm, int comp_id, const char * input_file, int run_type, int start_ymd, int start_tod)
Initialize the component instance.
void finalize ()
Finalize and clean up the component.
void get_cols_area (double * area) const
Get area for local columns.
void get_cols_latlon (double * lat, double * lon) const
Get lat/lon for local columns.
void get_local_col_gids (int * gids) const
Get global IDs for local columns.
int get_num_global_cols () const
Get total number of columns globally.
int get_num_local_cols () const
Get number of columns on this MPI rank.
int get_nx () const
Get number of grid points in x-direction (longitude).
int get_ny () const
Get number of grid points in y-direction (latitude).
void initialize ()
Initialize the component (phase 2).
bool is_root () const
Check if this is the root rank (rank 0).
int rank () const
Get MPI rank within component communicator.
void run (int dt)
Execute one time step.
void set_grid_data (int nx, int ny, int num_local_cols, int num_global_cols, const int * col_gids, const double * lat, const double * lon, const double * area)
Set grid decomposition data from the driver.
void setup_coupling (double * import_data, double * export_data, int num_imports, int num_exports, int field_size)
Set up coupling data buffers.
CompType type () const
Get component type.
virtual ~EmulatorComp () = default

Protected Attributes

Type Name
std::vector< double > m_area
Cell area [km²].
std::vector< int > m_col_gids
Global IDs for local columns.
MPI_Comm m_comm
MPI communicator.
int m_comp_id
Component ID from driver.
int m_current_tod = 0
Current time of day [seconds].
int m_current_ymd = 0
Current date as YYYYMMDD.
double * m_export_data = nullptr
Export buffer pointer (a2x)
int m_field_size = 0
Size per field (should = num_local_cols)
double * m_import_data = nullptr
Import buffer pointer (x2a)
std::string m_input_file
Path to configuration file.
std::vector< double > m_lat
Latitude [radians].
Logger m_logger
Component logger.
std::vector< double > m_lon
Longitude [radians].
int m_nprocs
Number of MPI processes.
int m_num_exports = 0
Number of export fields.
int m_num_global_cols = 0
Global column count.
int m_num_imports = 0
Number of import fields.
int m_num_local_cols = 0
Local column count.
int m_nx = 0
Grid points in x (longitude)
int m_ny = 0
Grid points in y (latitude)
int m_rank
MPI rank within component.
int m_run_type
Run type (startup/continue/branch)
int m_step_count = 0
Number of steps executed.
CompType m_type
Component type enum.

Protected Functions

Type Name
virtual void export_to_coupler ()
Export fields to coupler (override as needed).
virtual void final_impl () = 0
Component-specific finalization.
virtual void import_from_coupler ()
Import fields from coupler (override as needed).
virtual void init_impl () = 0
Component-specific initialization.
virtual void run_impl (int dt) = 0
Component-specific time step execution.
virtual void run_inference (const std::vector< double > & inputs, std::vector< double > & outputs) = 0
Run AI inference on packed input/output vectors.

Detailed Description

Public Functions Documentation

function EmulatorComp

Construct an emulator component of the given type.

explicit emulator::EmulatorComp::EmulatorComp (
    CompType type
) 

Parameters:

  • type Component type (ATM, OCN, ICE, LND)

function comm

Get MPI communicator.

inline MPI_Comm emulator::EmulatorComp::comm () const


function comp_id

Get component ID.

inline int emulator::EmulatorComp::comp_id () const


function create_instance

Initialize the component instance.

void emulator::EmulatorComp::create_instance (
    MPI_Comm comm,
    int comp_id,
    const char * input_file,
    int run_type,
    int start_ymd,
    int start_tod
) 

Initialize the component instance with MPI and metadata.

Sets up MPI communicator, stores component metadata, and prepares for grid data and coupling setup.

Parameters:

  • comm MPI communicator for this component
  • comp_id Component ID assigned by the driver
  • input_file Path to component configuration file
  • run_type Run type (startup, continue, branch)
  • start_ymd Start date as YYYYMMDD
  • start_tod Start time of day in seconds

function finalize

Finalize and clean up the component.

void emulator::EmulatorComp::finalize () 

Finalize the component and release resources.

Releases resources, finalizes inference backend, and performs any necessary cleanup.


function get_cols_area

Get area for local columns.

void emulator::EmulatorComp::get_cols_area (
    double * area
) const

Parameters:

  • area Output area array [km²]

function get_cols_latlon

Get lat/lon for local columns.

void emulator::EmulatorComp::get_cols_latlon (
    double * lat,
    double * lon
) const

Parameters:

  • lat Output latitude array [radians]
  • lon Output longitude array [radians]

function get_local_col_gids

Get global IDs for local columns.

void emulator::EmulatorComp::get_local_col_gids (
    int * gids
) const

Parameters:

  • gids Output array (must be pre-allocated with num_local_cols)

function get_num_global_cols

Get total number of columns globally.

inline int emulator::EmulatorComp::get_num_global_cols () const


function get_num_local_cols

Get number of columns on this MPI rank.

inline int emulator::EmulatorComp::get_num_local_cols () const


function get_nx

Get number of grid points in x-direction (longitude).

inline int emulator::EmulatorComp::get_nx () const


function get_ny

Get number of grid points in y-direction (latitude).

inline int emulator::EmulatorComp::get_ny () const


function initialize

Initialize the component (phase 2).

void emulator::EmulatorComp::initialize () 

Initialize the component by calling the derived class implementation.

Called after grid and coupling setup. Loads AI model, reads initial conditions, and prepares for time stepping.


function is_root

Check if this is the root rank (rank 0).

inline bool emulator::EmulatorComp::is_root () const


function rank

Get MPI rank within component communicator.

inline int emulator::EmulatorComp::rank () const


function run

Execute one time step.

void emulator::EmulatorComp::run (
    int dt
) 

Execute one time step: import → run → export.

Performs the main computational cycle:

  • Import fields from coupler
  • Run AI inference
  • Export fields to coupler

Parameters:

  • dt Time step size in seconds

function set_grid_data

Set grid decomposition data from the driver.

void emulator::EmulatorComp::set_grid_data (
    int nx,
    int ny,
    int num_local_cols,
    int num_global_cols,
    const int * col_gids,
    const double * lat,
    const double * lon,
    const double * area
) 

Override grid data with values from Fortran driver.

Receives the local portion of the global grid as distributed by the E3SM driver's domain decomposition.

Parameters:

  • nx Number of grid points in x-direction (longitude)
  • ny Number of grid points in y-direction (latitude)
  • num_local_cols Number of columns on this MPI rank
  • num_global_cols Total number of columns globally
  • col_gids Global IDs for each local column
  • lat Latitude values for each local column [radians]
  • lon Longitude values for each local column [radians]
  • area Grid cell areas for each local column [km²]

Used when the driver provides grid decomposition directly instead of reading from a file.


function setup_coupling

Set up coupling data buffers.

void emulator::EmulatorComp::setup_coupling (
    double * import_data,
    double * export_data,
    int num_imports,
    int num_exports,
    int field_size
) 

Set up coupling buffer pointers from the MCT layer.

Receives pointers to the MCT attribute vector buffers for data exchange with other components via the coupler.

Parameters:

  • import_data Pointer to import buffer (x2a fields)
  • export_data Pointer to export buffer (a2x fields)
  • num_imports Number of import fields
  • num_exports Number of export fields
  • field_size Size of each field (should equal num_local_cols)

function type

Get component type.

inline CompType emulator::EmulatorComp::type () const


function ~EmulatorComp

virtual emulator::EmulatorComp::~EmulatorComp () = default

Protected Attributes Documentation

variable m_area

Cell area [km²].

std::vector<double> emulator::EmulatorComp::m_area;


variable m_col_gids

Global IDs for local columns.

std::vector<int> emulator::EmulatorComp::m_col_gids;


variable m_comm

MPI communicator.

MPI_Comm emulator::EmulatorComp::m_comm;


variable m_comp_id

Component ID from driver.

int emulator::EmulatorComp::m_comp_id;


variable m_current_tod

Current time of day [seconds].

int emulator::EmulatorComp::m_current_tod;


variable m_current_ymd

Current date as YYYYMMDD.

int emulator::EmulatorComp::m_current_ymd;


variable m_export_data

Export buffer pointer (a2x)

double* emulator::EmulatorComp::m_export_data;


variable m_field_size

Size per field (should = num_local_cols)

int emulator::EmulatorComp::m_field_size;


variable m_import_data

Import buffer pointer (x2a)

double* emulator::EmulatorComp::m_import_data;


variable m_input_file

Path to configuration file.

std::string emulator::EmulatorComp::m_input_file;


variable m_lat

Latitude [radians].

std::vector<double> emulator::EmulatorComp::m_lat;


variable m_logger

Component logger.

Logger emulator::EmulatorComp::m_logger;


variable m_lon

Longitude [radians].

std::vector<double> emulator::EmulatorComp::m_lon;


variable m_nprocs

Number of MPI processes.

int emulator::EmulatorComp::m_nprocs;


variable m_num_exports

Number of export fields.

int emulator::EmulatorComp::m_num_exports;


variable m_num_global_cols

Global column count.

int emulator::EmulatorComp::m_num_global_cols;


variable m_num_imports

Number of import fields.

int emulator::EmulatorComp::m_num_imports;


variable m_num_local_cols

Local column count.

int emulator::EmulatorComp::m_num_local_cols;


variable m_nx

Grid points in x (longitude)

int emulator::EmulatorComp::m_nx;


variable m_ny

Grid points in y (latitude)

int emulator::EmulatorComp::m_ny;


variable m_rank

MPI rank within component.

int emulator::EmulatorComp::m_rank;


variable m_run_type

Run type (startup/continue/branch)

int emulator::EmulatorComp::m_run_type;


variable m_step_count

Number of steps executed.

int emulator::EmulatorComp::m_step_count;


variable m_type

Component type enum.

CompType emulator::EmulatorComp::m_type;


Protected Functions Documentation

function export_to_coupler

Export fields to coupler (override as needed).

inline virtual void emulator::EmulatorComp::export_to_coupler () 


function final_impl

Component-specific finalization.

virtual void emulator::EmulatorComp::final_impl () = 0


function import_from_coupler

Import fields from coupler (override as needed).

inline virtual void emulator::EmulatorComp::import_from_coupler () 


function init_impl

Component-specific initialization.

virtual void emulator::EmulatorComp::init_impl () = 0


function run_impl

Component-specific time step execution.

virtual void emulator::EmulatorComp::run_impl (
    int dt
) = 0


function run_inference

Run AI inference on packed input/output vectors.

virtual void emulator::EmulatorComp::run_inference (
    const std::vector< double > & inputs,
    std::vector< double > & outputs
) = 0

Parameters:

  • inputs Packed input features
  • outputs Packed output features (will be resized as needed)


The documentation for this class was generated from the following file components/emulator_comps/common/src/emulator_comp.hpp