YetAnotherCoupler 3.2.0_a
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
instance.c File Reference
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utils_core.h"
#include "yac.h"
#include "event.h"
#include "yac_mpi_common.h"
#include "fields.h"
#include "component.h"
#include "config_yaml.h"
Include dependency graph for instance.c:

Go to the source code of this file.

Data Structures

struct  yac_instance
 
struct  comp_grid_config
 
struct  comp_grid_pair_config
 
struct  field_config_event_data
 
struct  src_field_config
 
struct  tgt_field_config
 
struct  field_config
 

Macros

#define CHECK_PHASE(FUNC_NAME, REF_PHASE, NEW_PHASE)
 
#define CHECK_MIN_PHASE(FUNC_NAME, MIN_REF_PHASE)
 
#define CHECK_MAX_PHASE(FUNC_NAME, MAX_REF_PHASE)
 

Enumerations

enum  yac_instance_phase {
  INSTANCE_DEFINITION = 0 , INSTANCE_DEFINITION_COMP = 1 , INSTANCE_DEFINITION_SYNC = 2 , INSTANCE_EXCHANGE = 3 ,
  INSTANCE_UNKNOWN = 4
}
 
enum  field_type { SRC = 1 , TGT = 2 }
 

Functions

static struct yac_basic_gridget_basic_grid (const char *grid_name, char const *component_name, size_t num_fields, struct coupling_field **coupling_fields, int *delete_flag)
 
static int compare_comp_grid_config (const void *a, const void *b)
 
static struct coupling_fieldget_coupling_field (char const *component_name, const char *field_name, const char *grid_name, size_t num_fields, struct coupling_field **coupling_fields)
 
static struct src_field_config get_src_interp_config (struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
 
static struct tgt_field_config get_tgt_interp_config (struct yac_couple_config *couple_config, size_t couple_idx, size_t field_couple_idx)
 
static int compare_field_config_fields (struct coupling_field *a, size_t num_mask_names_a, char const *const *mask_names_a, struct coupling_field *b, size_t num_mask_names_b, char const *const *mask_names_b)
 
static int compare_field_config_field_ids (const void *a, const void *b)
 
static int compare_field_config_interp_method (const void *a, const void *b)
 
static int compare_field_config (const void *a, const void *b)
 
struct field_config_event_data get_event_data (struct yac_instance *instance, int couple_idx, int field_couple_idx, enum field_type field_type)
 
static struct eventgenerate_event (struct field_config_event_data event_data)
 
static void get_field_configuration (struct yac_instance *instance, struct field_config **field_configs_, size_t *count)
 
static int compare_field_config_ids (const void *a, const void *b)
 
static struct yac_interp_weightsgenerate_interp_weights (struct src_field_config src_interp_config, struct yac_interp_grid *interp_grid)
 
static void get_interp_fields_from_coupling_field (struct coupling_field *field, char const *const *mask_names, size_t num_mask_names, struct yac_interp_field **interp_fields, size_t *num_fields, MPI_Comm comm)
 
static void generate_interpolations (struct yac_instance *instance)
 
void yac_instance_sync_def (struct yac_instance *instance)
 
void yac_instance_setup (struct yac_instance *instance)
 
char * yac_instance_setup_and_emit_config (struct yac_instance *instance, int emit_flags)
 
MPI_Comm yac_instance_get_comps_comm (struct yac_instance *instance, char const **comp_names, size_t num_comp_names)
 
int yac_instance_get_comp_size (struct yac_instance *instance, const char *comp_name)
 
int yac_instance_get_comp_rank (struct yac_instance *instance, const char *comp_name)
 
struct yac_instanceyac_instance_new (MPI_Comm comm)
 
void yac_instance_dummy_new (MPI_Comm comm)
 
void yac_instance_delete (struct yac_instance *instance)
 
struct yac_couple_configyac_instance_get_couple_config (struct yac_instance *instance)
 
void yac_instance_set_couple_config (struct yac_instance *instance, struct yac_couple_config *couple_config)
 
void yac_instance_def_datetime (struct yac_instance *instance, const char *start_datetime, const char *end_datetime)
 
char * yac_instance_get_start_datetime (struct yac_instance *instance)
 
char * yac_instance_get_end_datetime (struct yac_instance *instance)
 
void yac_instance_def_components (struct yac_instance *instance, char const **comp_names, size_t num_comps)
 
int yac_instance_components_are_defined (struct yac_instance *instance)
 
struct coupling_fieldyac_instance_add_field (struct yac_instance *instance, char const *field_name, char const *comp_name, struct yac_basic_grid *grid, struct yac_interp_field *interp_fields, size_t num_interp_fields, int collection_size, char const *timestep)
 
void yac_instance_def_couple (struct yac_instance *instance, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_period, int time_reduction, struct yac_interp_stack_config *interp_stack_config, int src_lag, int tgt_lag, const char *weight_file_name, int mapping_on_source, double scale_factor, double scale_summand, size_t num_src_mask_names, char const *const *src_mask_names, char const *tgt_mask_name)
 
struct coupling_fieldyac_instance_get_field (struct yac_instance *instance, const char *comp_name, const char *grid_name, const char *field_name)
 

Variables

static const char * yac_instance_phase_str []
 
static struct field_config_event_data empty_event_data
 

Macro Definition Documentation

◆ CHECK_MAX_PHASE

#define CHECK_MAX_PHASE (   FUNC_NAME,
  MAX_REF_PHASE 
)
Value:
{ \
enum yac_instance_phase ref_max_phase_ = (MAX_REF_PHASE); \
YAC_ASSERT_F( \
instance->phase <= (ref_max_phase_), \
"ERROR(%s): Invalid phase " \
"(current phase: \"%s\" maximum expected phase: \"%s\")", \
#FUNC_NAME, \
MIN(instance->phase,INSTANCE_UNKNOWN)], \
yac_instance_phase_str[(ref_max_phase_)]); \
}
static const char * yac_instance_phase_str[]
Definition instance.c:29
yac_instance_phase
Definition instance.c:21
@ INSTANCE_UNKNOWN
Definition instance.c:26
#define MIN(a, b)

Definition at line 57 of file instance.c.

◆ CHECK_MIN_PHASE

#define CHECK_MIN_PHASE (   FUNC_NAME,
  MIN_REF_PHASE 
)
Value:
{ \
enum yac_instance_phase ref_min_phase_ = (MIN_REF_PHASE); \
YAC_ASSERT_F( \
instance->phase >= (ref_min_phase_), \
"ERROR(%s): Invalid phase " \
"(current phase: \"%s\" minimum expected phase: \"%s\")", \
#FUNC_NAME, yac_instance_phase_str[instance->phase], \
yac_instance_phase_str[(ref_min_phase_)]); \
}

Definition at line 47 of file instance.c.

◆ CHECK_PHASE

#define CHECK_PHASE (   FUNC_NAME,
  REF_PHASE,
  NEW_PHASE 
)
Value:
{ \
enum yac_instance_phase ref_phase_ = (REF_PHASE); \
YAC_ASSERT_F( \
instance->phase == (ref_phase_), \
"ERROR(%s): Invalid phase " \
"(current phase: \"%s\" expected phase: \"%s\")", \
#FUNC_NAME, yac_instance_phase_str[instance->phase], \
yac_instance_phase_str[(ref_phase_)]); \
instance->phase = (NEW_PHASE); \
}

Definition at line 36 of file instance.c.

Enumeration Type Documentation

◆ field_type

enum field_type
Enumerator
SRC 
TGT 

Definition at line 84 of file instance.c.

◆ yac_instance_phase

Enumerator
INSTANCE_DEFINITION 
INSTANCE_DEFINITION_COMP 
INSTANCE_DEFINITION_SYNC 
INSTANCE_EXCHANGE 
INSTANCE_UNKNOWN 

Definition at line 21 of file instance.c.

Function Documentation

◆ compare_comp_grid_config()

static int compare_comp_grid_config ( const void *  a,
const void *  b 
)
static

Definition at line 179 of file instance.c.

Here is the caller graph for this function:

◆ compare_field_config()

static int compare_field_config ( const void *  a,
const void *  b 
)
static
Examples
test_instance_parallel2.c.

Definition at line 354 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_field_config_field_ids()

static int compare_field_config_field_ids ( const void *  a,
const void *  b 
)
static

Definition at line 323 of file instance.c.

Here is the caller graph for this function:

◆ compare_field_config_fields()

static int compare_field_config_fields ( struct coupling_field a,
size_t  num_mask_names_a,
char const *const *  mask_names_a,
struct coupling_field b,
size_t  num_mask_names_b,
char const *const *  mask_names_b 
)
static

Definition at line 252 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_field_config_ids()

static int compare_field_config_ids ( const void *  a,
const void *  b 
)
static

Definition at line 764 of file instance.c.

Here is the caller graph for this function:

◆ compare_field_config_interp_method()

static int compare_field_config_interp_method ( const void *  a,
const void *  b 
)
static

Definition at line 335 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_event()

static struct event * generate_event ( struct field_config_event_data  event_data)
static

Definition at line 425 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_interp_weights()

static struct yac_interp_weights * generate_interp_weights ( struct src_field_config  src_interp_config,
struct yac_interp_grid interp_grid 
)
static

Definition at line 772 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_interpolations()

static void generate_interpolations ( struct yac_instance instance)
static

Definition at line 910 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_basic_grid()

static struct yac_basic_grid * get_basic_grid ( const char *  grid_name,
char const *  component_name,
size_t  num_fields,
struct coupling_field **  coupling_fields,
int *  delete_flag 
)
static

Definition at line 155 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_coupling_field()

static struct coupling_field * get_coupling_field ( char const *  component_name,
const char *  field_name,
const char *  grid_name,
size_t  num_fields,
struct coupling_field **  coupling_fields 
)
static

Definition at line 189 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_event_data()

struct field_config_event_data get_event_data ( struct yac_instance instance,
int  couple_idx,
int  field_couple_idx,
enum field_type  field_type 
)

Definition at line 383 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_field_configuration()

static void get_field_configuration ( struct yac_instance instance,
struct field_config **  field_configs_,
size_t *  count 
)
static

Definition at line 436 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_interp_fields_from_coupling_field()

static void get_interp_fields_from_coupling_field ( struct coupling_field field,
char const *const *  mask_names,
size_t  num_mask_names,
struct yac_interp_field **  interp_fields,
size_t *  num_fields,
MPI_Comm  comm 
)
static

Definition at line 787 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_src_interp_config()

static struct src_field_config get_src_interp_config ( struct yac_couple_config couple_config,
size_t  couple_idx,
size_t  field_couple_idx 
)
static

Definition at line 207 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tgt_interp_config()

static struct tgt_field_config get_tgt_interp_config ( struct yac_couple_config couple_config,
size_t  couple_idx,
size_t  field_couple_idx 
)
static

Definition at line 236 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_add_field()

struct coupling_field * yac_instance_add_field ( struct yac_instance instance,
char const *  field_name,
char const *  comp_name,
struct yac_basic_grid grid,
struct yac_interp_field interp_fields,
size_t  num_interp_fields,
int  collection_size,
char const *  timestep 
)

Adds a coupling field to a yac instance

Parameters
[in]instanceyac instance
[in]field_namename of the coupling field
[in]comp_namecomponent name
[in]gridgrid
[in]interp_fieldsinterpolation fields
[in]num_interp_fieldsnumber of entries in interp_fields
[in]collection_sizecollection size of field
[in]timesteptimestep at which put/get is called for this field in ISO 8601 format
Returns
pointer to coupling field
Examples
test_instance_parallel1.c, test_instance_parallel2.c, and test_instance_parallel3.c.

Definition at line 1317 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_components_are_defined()

int yac_instance_components_are_defined ( struct yac_instance instance)

Returns true if the components for this instance have already been defined

Parameters
[in]instanceyac instance

Definition at line 1312 of file instance.c.

Here is the caller graph for this function:

◆ yac_instance_def_components()

void yac_instance_def_components ( struct yac_instance instance,
char const **  comp_names,
size_t  num_comps 
)

Defines the components for a yac instance

Parameters
[in]instanceyac instance
[in]comp_namesnames of components
[in]num_compsnumber of entries in comp_names
Examples
test_instance_parallel1.c, test_instance_parallel2.c, test_instance_parallel3.c, and test_instance_parallel4.c.

Definition at line 1290 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_def_couple()

void yac_instance_def_couple ( struct yac_instance instance,
char const *  src_comp_name,
char const *  src_grid_name,
char const *  src_field_name,
char const *  tgt_comp_name,
char const *  tgt_grid_name,
char const *  tgt_field_name,
char const *  coupling_period,
int  time_reduction,
struct yac_interp_stack_config interp_stack_config,
int  src_lag,
int  tgt_lag,
const char *  weight_file_name,
int  mapping_on_source,
double  scale_factor,
double  scale_summand,
size_t  num_src_mask_names,
char const *const *  src_mask_names,
char const *  tgt_mask_name 
)

Defines a couple for a yac instance

Parameters
[in]instanceyac instance
[in]src_comp_namecomponent name of the source component
[in]src_grid_namegrid name of the source grid
[in]src_field_namefield name of the source field
[in]tgt_comp_namecomponent name of the target component
[in]tgt_grid_namegrid name of the target grid
[in]tgt_field_namefield name of the target field
[in]coupling_periodtime step for the coupling
[in]time_reductiontype for reducing multiple timesteps (
See also
YAC_REDUCTION_TIME_NONE etc.)
Parameters
[in]interp_stack_configinterpolation stack config to be used
[in]src_laglag for this couple on the source component
[in]tgt_laglag for this couple on the target component
[in]weight_file_namefile name for the weights file. NULL to disable this feature
[in]mapping_on_sourceside where the mapping is computed. Currently only source = 1 and target = 0 are allowed
[in]scale_factorscale factor
[in]scale_summandscale summand
[in]num_src_mask_namesnumber of source field mask names ("0" if no source field mask names are provided)
[in]src_mask_namesarray of source field mask names ("NULL" if num_src_mask_names == 0)
[in]tgt_mask_nametarget field mask name ("NULL" if no target field mask name is provided)
Examples
test_instance_parallel2.c, and test_instance_parallel3.c.

Definition at line 1376 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_def_datetime()

void yac_instance_def_datetime ( struct yac_instance instance,
const char *  start_datetime,
const char *  end_datetime 
)

Definition of job start and end datetime

Parameters
[in]instanceyac instance
[in]start_datetimecalendar job start datetime
[in]end_datetimecalendar job end datetime
Examples
test_instance_parallel2.c, and test_instance_parallel3.c.

Definition at line 1272 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_delete()

void yac_instance_delete ( struct yac_instance instance)

Destructor for a yac instance

Parameters
[in]instanceyac instance to be deleted
Examples
test_instance_parallel1.c, test_instance_parallel2.c, test_instance_parallel3.c, and test_instance_parallel4.c.

Definition at line 1240 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_dummy_new()

void yac_instance_dummy_new ( MPI_Comm  comm)

Dummy constructor, which can be called instead of yac_instance_new.

Parameters
[in]comm

Definition at line 1234 of file instance.c.

Here is the caller graph for this function:

◆ yac_instance_get_comp_rank()

int yac_instance_get_comp_rank ( struct yac_instance instance,
const char *  comp_name 
)

Definition at line 1206 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_get_comp_size()

int yac_instance_get_comp_size ( struct yac_instance instance,
const char *  comp_name 
)

Definition at line 1197 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_get_comps_comm()

MPI_Comm yac_instance_get_comps_comm ( struct yac_instance instance,
char const **  comp_names,
size_t  num_comp_names 
)

returns a communicator containing all processes of the provided components

Parameters
[in]instanceyac instance
[in]comp_namescomponent names
[in]num_comp_names
Examples
test_instance_parallel2.c, test_instance_parallel3.c, and test_instance_parallel4.c.

Definition at line 1188 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_get_couple_config()

struct yac_couple_config * yac_instance_get_couple_config ( struct yac_instance instance)

Get the coupling configuration data from a yac instance

Parameters
[in]instanceyac instance
Returns
coupling configuration data
Examples
test_instance_parallel1.c.

Definition at line 1257 of file instance.c.

Here is the caller graph for this function:

◆ yac_instance_get_end_datetime()

char * yac_instance_get_end_datetime ( struct yac_instance instance)

query routine for the end datetime of the job

Parameters
[in]instanceyac instance
Returns
end datetime

Definition at line 1285 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_get_field()

struct coupling_field * yac_instance_get_field ( struct yac_instance instance,
const char *  comp_name,
const char *  grid_name,
const char *  field_name 
)

Definition at line 1397 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_get_start_datetime()

char * yac_instance_get_start_datetime ( struct yac_instance instance)

query routine for the start datetime of the job

Parameters
[in]instanceyac instance
Returns
start datetime

Definition at line 1280 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_new()

struct yac_instance * yac_instance_new ( MPI_Comm  comm)

Constructor for a yac instance.

Parameters
[in]commMPI communicator that contains the processes of all components that will be registered with this yac instance
Returns
yac instance
Remarks
This is collectiv for all processes in comm.
Examples
test_instance_parallel1.c, test_instance_parallel2.c, test_instance_parallel3.c, and test_instance_parallel4.c.

Definition at line 1215 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_set_couple_config()

void yac_instance_set_couple_config ( struct yac_instance instance,
struct yac_couple_config couple_config 
)

Sets the coupling configuration data for a yac instance

Parameters
[in]instanceyac instance
[in]couple_configcoupling configuration data
Examples
test_instance_parallel1.c.

Definition at line 1263 of file instance.c.

Here is the call graph for this function:

◆ yac_instance_setup()

void yac_instance_setup ( struct yac_instance instance)

initiates the generation of all data structures required for interpolation

Parameters
[in]instanceyac instance
Examples
test_instance_parallel1.c, test_instance_parallel2.c, and test_instance_parallel3.c.

Definition at line 1157 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_setup_and_emit_config()

char * yac_instance_setup_and_emit_config ( struct yac_instance instance,
int  emit_flags 
)

initiates the generation of all data structures required for interpolation

Parameters
[in]instanceyac instance
[in]emit_flagsflags for configuring the generated coupling configuration output (YAC_YAML_EMITTER_DEFAULT or YAC_YAML_EMITTER_JSON)
Returns
string containing coupling configuration

Definition at line 1180 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_instance_sync_def()

void yac_instance_sync_def ( struct yac_instance instance)

synchronizes the grid and field definitions

Parameters
[in]instanceyac instance

Definition at line 1149 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ empty_event_data

struct field_config_event_data empty_event_data
static
Initial value:
=
{.timestep = NULL,
.coupling_period = NULL,
.timelag = 0,
.reduction_operation = TIME_NONE,
.start_datetime = NULL,
.end_datetime = NULL}
@ TIME_NONE

◆ yac_instance_phase_str

const char* yac_instance_phase_str[]
static
Initial value:
=
{"definition phase",
"definition phase (after component definition)",
"definition phase (after synchronisation)",
"exchange phase",
"unknown phase"}

Definition at line 29 of file instance.c.