My Project
programmer's documentation
Functions
cs_field.c File Reference
#include "cs_defs.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "cs_log.h"
#include "cs_map.h"
#include "cs_parall.h"
#include "cs_mesh_location.h"
#include "cs_field.h"
Include dependency graph for cs_field.c:

Functions

int cs_field_n_fields (void)
 Return the number of defined fields. More...
 
cs_field_tcs_field_create (const char *name, int type_flag, int location_id, int dim, bool has_previous)
 Create a field descriptor. More...
 
cs_field_tcs_field_find_or_create (const char *name, int type_flag, int location_id, int dim, bool has_previous)
 Return a field matching a given name and attributes, creating it if necessary. More...
 
void cs_field_set_n_time_vals (cs_field_t *f, int n_time_vals)
 Change the number of time values managed by a field. More...
 
void cs_field_allocate_values (cs_field_t *f)
 Allocate arrays for field values. More...
 
void cs_field_map_values (cs_field_t *f, cs_real_t *val, cs_real_t *val_pre)
 Map existing value arrays to field descriptor. More...
 
void cs_field_allocate_bc_coeffs (cs_field_t *f, bool have_flux_bc, bool have_mom_bc, bool have_conv_bc, bool have_exch_bc)
 Allocate boundary condition coefficients arrays. More...
 
void cs_field_init_bc_coeffs (cs_field_t *f)
 Initialize boundary condition coefficients arrays. More...
 
void cs_field_set_values (cs_field_t *f, cs_real_t c)
 Set current field values to the given constant. More...
 
void cs_field_current_to_previous (cs_field_t *f)
 Copy current field values to previous values if applicable. More...
 
void cs_field_destroy_all (void)
 Destroy all defined fields. More...
 
void cs_field_allocate_or_map_all (void)
 Allocate arrays for all defined fields based on their location. More...
 
cs_field_tcs_field_by_id (int id)
 Return a pointer to a field based on its id. More...
 
cs_field_tcs_field_by_name (const char *name)
 Return a pointer to a field based on its name. More...
 
cs_field_tcs_field_by_name_try (const char *name)
 Return a pointer to a field based on its name if present. More...
 
int cs_field_id_by_name (const char *name)
 Return the id of a defined field based on its name. More...
 
void cs_field_component_id_by_name (const char *name, int *f_id, int *c_id)
 Return the id of a defined field and an associated component based on a component name. More...
 
int cs_field_key_id (const char *name)
 Return an id associated with a given key name. More...
 
int cs_field_key_id_try (const char *name)
 Return an id associated with a given key name if present. More...
 
int cs_field_define_key_int (const char *name, int default_value, int type_flag)
 Define a key for an integer value by its name and return an associated id. More...
 
int cs_field_define_key_double (const char *name, double default_value, int type_flag)
 Define a key for an floating point value by its name and return an associated id. More...
 
int cs_field_define_key_str (const char *name, const char *default_value, int type_flag)
 Define a key for a string value by its name and return an associated id. More...
 
int cs_field_define_key_struct (const char *name, const void *default_value, cs_field_log_key_struct_t *log_func, cs_field_log_key_struct_t *log_func_default, size_t size, int type_flag)
 Define a key for a structure value by its name and return an associated id. More...
 
int cs_field_define_sub_key (const char *name, int parent_id)
 Define a sub key. More...
 
void cs_field_destroy_all_keys (void)
 Destroy all defined field keys and associated values. More...
 
int cs_field_key_flag (int key_id)
 Get the type flag associated with a given key id. More...
 
void cs_field_key_disable_setup_log (int key_id)
 Disable logging setup values associated with a given key. More...
 
bool cs_field_is_key_set (const cs_field_t *f, int key_id)
 Query if a given key has been set for a field. More...
 
bool cs_field_is_key_locked (const cs_field_t *f, int key_id)
 Query if a given key has been locked for a field. More...
 
int cs_field_lock_key (cs_field_t *f, int key_id)
 Lock a field relative to a given key. More...
 
int cs_field_set_key_int (cs_field_t *f, int key_id, int value)
 Assign a integer value for a given key to a field. More...
 
int cs_field_get_key_int (const cs_field_t *f, int key_id)
 Return a integer value for a given key associated with a field. More...
 
int cs_field_set_key_int_bits (cs_field_t *f, int key_id, int mask)
 Set integer bits matching a mask to 1 for a given key for a field. More...
 
int cs_field_clear_key_int_bits (cs_field_t *f, int key_id, int mask)
 Set integer bits matching a mask to 0 for a given key for a field. More...
 
int cs_field_set_key_double (cs_field_t *f, int key_id, double value)
 Assign a floating point value for a given key to a field. More...
 
double cs_field_get_key_double (const cs_field_t *f, int key_id)
 Return a floating point value for a given key associated with a field. More...
 
int cs_field_set_key_str (cs_field_t *f, int key_id, const char *str)
 Assign a character string for a given key to a field. More...
 
const char * cs_field_get_key_str (const cs_field_t *f, int key_id)
 Return a string for a given key associated with a field. More...
 
int cs_field_set_key_struct (cs_field_t *f, int key_id, void *s)
 Assign a simple structure for a given key to a field. More...
 
const void * cs_field_get_key_struct (const cs_field_t *f, const int key_id, void *s)
 Return a structure for a given key associated with a field. More...
 
void * cs_field_get_key_struct_ptr (cs_field_t *f, int key_id)
 Return a pointer to a simple structure for a given key to a field. More...
 
const void * cs_field_get_key_struct_const_ptr (const cs_field_t *f, int key_id)
 Return a read-only pointer to a simple structure for a given key to a field. More...
 
void cs_field_log_defs (void)
 Print info relative to all field definitions to log file. More...
 
void cs_field_log_info (const cs_field_t *f, int log_keywords)
 Print info relative to a given field to log file. More...
 
void cs_field_log_fields (int log_keywords)
 Print info relative to all defined fields to log file. More...
 
void cs_field_log_key_defs (void)
 Print info relative to all key definitions to log file. More...
 
void cs_field_log_key_vals (int key_id, bool log_defaults)
 Print info relative to a given field key to log file. More...
 
void cs_field_log_all_key_vals (bool log_defaults)
 Print info relative to all given field keys to log file. More...
 
void cs_field_define_keys_base (void)
 Define base keys. More...
 
const char * cs_field_get_label (const cs_field_t *f)
 Return a label associated with a field. More...
 

Detailed Description

Field management.

Function Documentation

◆ cs_field_allocate_bc_coeffs()

void cs_field_allocate_bc_coeffs ( cs_field_t f,
bool  have_flux_bc,
bool  have_mom_bc,
bool  have_conv_bc,
bool  have_exch_bc 
)

Allocate boundary condition coefficients arrays.

For fields on location CS_MESH_LOCATION_CELLS, boundary conditions are located on CS_MESH_LOCATION_BOUNDARY_FACES.

Boundary condition coefficients are not currently supported for other locations (though support could be added by mapping a boundary->location indirection array in the cs_mesh_location_t structure).

For multidimensional fields with coupled components, implicit b and bf coefficient arrays are arrays of block matrices, not vectors, so the number of entries for each boundary face is dim*dim instead of dim.

Parameters
[in,out]fpointer to field structure
[in]have_flux_bcif true, flux bc coefficients (af and bf) are added
[in]have_mom_bcif true, div BC coefficients (ad and bd) are added
[in]have_conv_bcif true, convection BC coefficients (ac and bc) are added
[in]have_exch_bcif true, exchange boundary coefficients (hint and hext) are added

◆ cs_field_allocate_or_map_all()

void cs_field_allocate_or_map_all ( void  )

Allocate arrays for all defined fields based on their location.

Location sized must thus be known.

Fields that do not own their data should all have been mapped at this stage, and are checked.

◆ cs_field_allocate_values()

void cs_field_allocate_values ( cs_field_t f)

Allocate arrays for field values.

Parameters
[in,out]fpointer to field structure

◆ cs_field_by_id()

cs_field_t* cs_field_by_id ( int  id)

Return a pointer to a field based on its id.

This function requires that a field of the given id is defined.

Parameters
[in]idfield id
Returns
pointer to the field structure

◆ cs_field_by_name()

cs_field_t* cs_field_by_name ( const char *  name)

Return a pointer to a field based on its name.

This function requires that a field of the given name is defined.

Parameters
[in]namefield name
Returns
pointer to the field structure

◆ cs_field_by_name_try()

cs_field_t* cs_field_by_name_try ( const char *  name)

Return a pointer to a field based on its name if present.

If no field of the given name is defined, NULL is returned.

Parameters
[in]namefield name
Returns
pointer to the field structure, or NULL

◆ cs_field_clear_key_int_bits()

int cs_field_clear_key_int_bits ( cs_field_t f,
int  key_id,
int  mask 
)

Set integer bits matching a mask to 0 for a given key for a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned. If the data type does not match, CS_FIELD_INVALID_TYPE is returned. If the key value has been locked, CS_FIELD_LOCKED is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]maskmask associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_component_id_by_name()

void cs_field_component_id_by_name ( const char *  name,
int *  f_id,
int *  c_id 
)

Return the id of a defined field and an associated component based on a component name.

If no field with the given name exists, -1 is returned.

Parameters
[in]namefield or field+component name
[out]f_idfield id, or -1 if no match was found
[out]c_idcomponent id, or -1 for all components

◆ cs_field_create()

cs_field_t* cs_field_create ( const char *  name,
int  type_flag,
int  location_id,
int  dim,
bool  has_previous 
)

Create a field descriptor.

Parameters
[in]namefield name
[in]type_flagmask of field property and category values
[in]location_idid of associated location
[in]dimfield dimension (number of components)
[in]has_previousmaintain values at the previous time step ?
Returns
pointer to new field.

◆ cs_field_current_to_previous()

void cs_field_current_to_previous ( cs_field_t f)

Copy current field values to previous values if applicable.

For fields with only one time value, or values not allocated yet, this is a no-op.

Parameters
[in,out]fpointer to field structure

◆ cs_field_define_key_double()

int cs_field_define_key_double ( const char *  name,
double  default_value,
int  type_flag 
)

Define a key for an floating point value by its name and return an associated id.

If the key has already been defined, its previous default value is replaced by the current value, and its id is returned.

Parameters
[in]namekey name
[in]default_valuedefault value associated with key
[in]type_flagmask associated with field types with which the key may be associated, or 0
Returns
id associated with key

◆ cs_field_define_key_int()

int cs_field_define_key_int ( const char *  name,
int  default_value,
int  type_flag 
)

Define a key for an integer value by its name and return an associated id.

If the key has already been defined, its previous default value is replaced by the current value, and its id is returned.

Parameters
[in]namekey name
[in]default_valuedefault value associated with key
[in]type_flagmask associated with field types with which the key may be associated, or 0
Returns
id associated with key

◆ cs_field_define_key_str()

int cs_field_define_key_str ( const char *  name,
const char *  default_value,
int  type_flag 
)

Define a key for a string value by its name and return an associated id.

If the key has already been defined, its previous default value is replaced by the current value, and its id is returned.

Parameters
[in]namekey name
[in]default_valuedefault value associated with key
[in]type_flagmask associated with field types with which the key may be associated, or 0
Returns
id associated with key

◆ cs_field_define_key_struct()

int cs_field_define_key_struct ( const char *  name,
const void *  default_value,
cs_field_log_key_struct_t log_func,
cs_field_log_key_struct_t log_func_default,
size_t  size,
int  type_flag 
)

Define a key for a structure value by its name and return an associated id.

If the key has already been defined, its previous default value is replaced by the current value, and its id is returned.

Parameters
[in]namekey name
[in]default_valuepointer to default value associated with key
[in]log_funcpointer to logging function
[in]log_func_defaultpointer to default logging function
[in]sizesizeof structure
[in]type_flagmask associated with field types with which the key may be associated, or 0
Returns
id associated with key

◆ cs_field_define_keys_base()

void cs_field_define_keys_base ( void  )

Define base keys.

Keys defined by this function are: "label" (string) "log" (integer) "post_vis" (integer) "coupled" (integer, restricted to CS_FIELD_VARIABLE) "moment_id" (integer, restricted to CS_FIELD_ACCUMULATOR | CS_FIELD_POSTPROCESS);

A recommended practice for different submodules would be to use "cs_<module>_key_init() functions to define keys specific to those modules.

◆ cs_field_define_sub_key()

int cs_field_define_sub_key ( const char *  name,
int  parent_id 
)

Define a sub key.

The sub key is the same type as the parent key.

For a given field, when querying a sub key's value and that value has not been set, the query will return the value of the parent key.

Parameters
[in]namekey name
[in]parent_idparent key id
Returns
id associated with key

◆ cs_field_destroy_all()

void cs_field_destroy_all ( void  )

Destroy all defined fields.

◆ cs_field_destroy_all_keys()

void cs_field_destroy_all_keys ( void  )

Destroy all defined field keys and associated values.

◆ cs_field_find_or_create()

cs_field_t* cs_field_find_or_create ( const char *  name,
int  type_flag,
int  location_id,
int  dim,
bool  has_previous 
)

Return a field matching a given name and attributes, creating it if necessary.

If a field with the same name but different attributes is present, this is considered an error.

The default number of time values associated with a field created through this function is 1. To modify it, use cs_field_set_n_time_vals.

Parameters
[in]namefield name
[in]type_flagmask of field property and category values
[in]location_idid of associated location
[in]dimfield dimension (number of components)
[in]has_previousmaintain values at the previous time step ?
Returns
pointer to field

◆ cs_field_get_key_double()

double cs_field_get_key_double ( const cs_field_t f,
int  key_id 
)

Return a floating point value for a given key associated with a field.

If the key id is not valid, or the value type or field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
floating point value associated with the key id for this field

◆ cs_field_get_key_int()

int cs_field_get_key_int ( const cs_field_t f,
int  key_id 
)

Return a integer value for a given key associated with a field.

If the key id is not valid, or the value type or field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
integer value associated with the key id for this field

◆ cs_field_get_key_str()

const char* cs_field_get_key_str ( const cs_field_t f,
int  key_id 
)

Return a string for a given key associated with a field.

If the key id is not valid, or the value type or field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
pointer to character string associated with the key id for this field

◆ cs_field_get_key_struct()

const void* cs_field_get_key_struct ( const cs_field_t f,
const int  key_id,
void *  s 
)

Return a structure for a given key associated with a field.

If the key id is not valid, or the value type or field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[out]sstructure associated with key
Returns
pointer to structure associated with the key id for this field (same as s)

◆ cs_field_get_key_struct_const_ptr()

const void* cs_field_get_key_struct_const_ptr ( const cs_field_t f,
int  key_id 
)

Return a read-only pointer to a simple structure for a given key to a field.

If the key id is not valid, the value type or field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
pointer to key structure in case of success, NULL in case of error

◆ cs_field_get_key_struct_ptr()

void* cs_field_get_key_struct_ptr ( cs_field_t f,
int  key_id 
)

Return a pointer to a simple structure for a given key to a field.

If the key id is not valid, the value type or field category is not compatible, or the structure has been locked, a fatal error is provoked.

Note that using this function marks the field's value for this structure as set, and if no values have been set yet, the structure is set to default values.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
pointer to key structure in case of success, NULL in case of error

◆ cs_field_get_label()

const char* cs_field_get_label ( const cs_field_t f)

Return a label associated with a field.

If the "label" key has been set for this field, its associated string is returned. Otherwise, the field's name is returned.

Parameters
[in]fpointer to field structure
Returns
pointer to character string associated with label for this field

◆ cs_field_id_by_name()

int cs_field_id_by_name ( const char *  name)

Return the id of a defined field based on its name.

If no field with the given name exists, -1 is returned.

Parameters
[in]namekey name
Returns
id of the field, or -1 if not found

◆ cs_field_init_bc_coeffs()

void cs_field_init_bc_coeffs ( cs_field_t f)

Initialize boundary condition coefficients arrays.

For fields on location CS_MESH_LOCATION_CELLS, boundary conditions are located on CS_MESH_LOCATION_BOUNDARY_FACES.

Boundary condition coefficients are not currently supported for other locations (though support could be added by mapping a boundary->location indirection array in the cs_mesh_location_t structure).

For multidimensional fields with coupled components, implicit b and bf coefficient arrays are arrays of block matrices, not vectors, so the number of entries for each boundary face is dim*dim instead of dim.

Parameters
[in,out]fpointer to field structure

◆ cs_field_is_key_locked()

bool cs_field_is_key_locked ( const cs_field_t f,
int  key_id 
)

Query if a given key has been locked for a field.

If the key id is not valid, or the field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
true if the key has been locked for this field, false otherwise

◆ cs_field_is_key_set()

bool cs_field_is_key_set ( const cs_field_t f,
int  key_id 
)

Query if a given key has been set for a field.

If the key id is not valid, or the field category is not compatible, a fatal error is provoked.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
true if the key has been set for this field, false otherwise

◆ cs_field_key_disable_setup_log()

void cs_field_key_disable_setup_log ( int  key_id)

Disable logging setup values associated with a given key.

This is useful when a key is used not for setup purposes, but to track values associated with a field, such as convergence or performance data.

Parameters
[in]key_idid of associated key

◆ cs_field_key_flag()

int cs_field_key_flag ( int  key_id)

Get the type flag associated with a given key id.

If the key has not been defined previously, -1 is returned.

Parameters
[in]key_idid of associated key
Returns
type flag associated with key, or -1

◆ cs_field_key_id()

int cs_field_key_id ( const char *  name)

Return an id associated with a given key name.

The key must have been defined previously.

Parameters
[in]namekey name
Returns
id associated with key

◆ cs_field_key_id_try()

int cs_field_key_id_try ( const char *  name)

Return an id associated with a given key name if present.

If the key has not been defined previously, -1 is returned.

Parameters
[in]namekey name
Returns
id associated with key, or -1

◆ cs_field_lock_key()

int cs_field_lock_key ( cs_field_t f,
int  key_id 
)

Lock a field relative to a given key.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_log_all_key_vals()

void cs_field_log_all_key_vals ( bool  log_defaults)

Print info relative to all given field keys to log file.

Parameters
[in]log_defaultsif true, log default field values in addition to defined field values

◆ cs_field_log_defs()

void cs_field_log_defs ( void  )

Print info relative to all field definitions to log file.

◆ cs_field_log_fields()

void cs_field_log_fields ( int  log_keywords)

Print info relative to all defined fields to log file.

Parameters
[in]log_keywordslog level for keywords (0: do not log, 1: log non-default values, 2: log all)

◆ cs_field_log_info()

void cs_field_log_info ( const cs_field_t f,
int  log_keywords 
)

Print info relative to a given field to log file.

Parameters
[in]fpointer to field structure
[in]log_keywordslog level for keywords (0: do not log, 1: log non-default values, 2: log all)

◆ cs_field_log_key_defs()

void cs_field_log_key_defs ( void  )

Print info relative to all key definitions to log file.

◆ cs_field_log_key_vals()

void cs_field_log_key_vals ( int  key_id,
bool  log_defaults 
)

Print info relative to a given field key to log file.

Parameters
[in]key_idid of associated key
[in]log_defaultsif true, log default field values in addition to defined field values

◆ cs_field_map_values()

void cs_field_map_values ( cs_field_t f,
cs_real_t val,
cs_real_t val_pre 
)

Map existing value arrays to field descriptor.

Parameters
[in,out]fpointer to field structure
[in]valpointer to array of values
[in]val_prepointer to array of previous values, or NULL

◆ cs_field_n_fields()

int cs_field_n_fields ( void  )

Return the number of defined fields.

Returns
number of defined fields.

◆ cs_field_set_key_double()

int cs_field_set_key_double ( cs_field_t f,
int  key_id,
double  value 
)

Assign a floating point value for a given key to a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]valuevalue associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_set_key_int()

int cs_field_set_key_int ( cs_field_t f,
int  key_id,
int  value 
)

Assign a integer value for a given key to a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned. If the data type does not match, CS_FIELD_INVALID_TYPE is returned. If the key value has been locked, CS_FIELD_LOCKED is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]valuevalue associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_set_key_int_bits()

int cs_field_set_key_int_bits ( cs_field_t f,
int  key_id,
int  mask 
)

Set integer bits matching a mask to 1 for a given key for a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned. If the data type does not match, CS_FIELD_INVALID_TYPE is returned. If the key value has been locked, CS_FIELD_LOCKED is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]maskmask associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_set_key_str()

int cs_field_set_key_str ( cs_field_t f,
int  key_id,
const char *  str 
)

Assign a character string for a given key to a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]strstring associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_set_key_struct()

int cs_field_set_key_struct ( cs_field_t f,
int  key_id,
void *  s 
)

Assign a simple structure for a given key to a field.

If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned. If the field category is not compatible with the key (as defined by its type flag), CS_FIELD_INVALID_CATEGORY is returned.

Parameters
[in]fpointer to field structure
[in]key_idid of associated key
[in]sstructure associated with key
Returns
0 in case of success, > 1 in case of error

◆ cs_field_set_n_time_vals()

void cs_field_set_n_time_vals ( cs_field_t f,
int  n_time_vals 
)

Change the number of time values managed by a field.

The minimum will never be below 1, as the current time is always handled.

Parameters
[in,out]fpointer to field structure
[in]n_time_valsnumber of time values to maintain

◆ cs_field_set_values()

void cs_field_set_values ( cs_field_t f,
cs_real_t  c 
)

Set current field values to the given constant.

Parameters
[in,out]fpointer to field structure
[in]cassigned value