8.3
general documentation
Interpolation

Probe set interpolation

By default, probes and profile values are "P0" interpolated, that is their value is that of the containing cell or face, or closest vertex.

For cell-based values, a "P1" piecewise linear interpolation may be used.

The P1 interpolation is based on a local least-squares gradient, so ghost cell values must be synchronized (this is automatically the case for fields, but must be handled by the user in case of auxiliary arrays).

If a field's boundary values (i.e. associated field) are known, they are used in the interpolation. Otherwise, if boundary conditions are defined, they are used. When neither boundary values nor boundary conditions are known (i.e. for a non-solved variable field or values not defined as a field), homogeneous Neumann boundary conditions are assumed. Improved gradient interpolation for stratification and "jumps" is also ignored here, so this may lead to excessively smooth output in areas where this should occur.

Interpolation may be activated in a global manner for all outputs using a given probe set as by setting the set's "interpolate", option to 1, as shown on the following example. The "probes" set configured here is the default probe set defined using the GUI:

{
cs_probe_set_t *pset = cs_probe_set_get("probes");
cs_probe_set_option(pset, "interpolation", "1");
}
void cs_probe_set_option(cs_probe_set_t *pset, const char *keyname, const char *keyval)
Set optional parameters related to the management of a set of probes.
Definition: cs_probe.cpp:1444
cs_probe_set_t * cs_probe_set_get(const char *name)
Retrieve a cs_probe_set_t structure.
Definition: cs_probe.cpp:796
struct _cs_probe_set_t cs_probe_set_t
Definition: cs_probe.h:53

If a finer control is needed, such as applying a different interpolation option to selected fields, or providing a more precice (but usually more costly interpolation, interpolation may also be defined on a case per case basis using the cs_user_postprocess_values function.

The following example shows how this may be done, using the built-in cs_interpolate_from_location_p1 function (which is based on the "P1" interpolation described above) by passing its pointer to the to cs_post_write_probe_values outout function.

int n_p_fields = 2;
const char *p_field_names[] = {"velocity", "temperature"};
for (int i = 0; i < n_p_fields; i++) {
cs_field_t *f = cs_field_by_name_try(p_field_names[i]);
if (f != nullptr) {
/* use different name to avoid conflict with field name in case already
present in probe set through default output */
char f_name[128], p_name[128];
snprintf(f_name, 63, "%s", f->name); f_name[127] = '\0';
snprintf(p_name, 63, "%s_p", f->name); p_name[63] = '\0';
(mesh_id,
CS_POST_WRITER_ALL_ASSOCIATED, /* writer id filter */
p_name, /* var_name */
f->dim, /* var_dim */
1, /* parent location id */
cs_interpolate_from_location_p1, /* P1 interpolation */
f_name, /* interpolation input */
f->val,
ts);
}
}
}
cs_field_t * cs_field_by_name_try(const char *name)
Return a pointer to a field based on its name if present.
Definition: cs_field.cpp:2515
void cs_interpolate_from_location_p1(void *input, cs_datatype_t datatype, int val_dim, cs_lnum_t n_points, const cs_lnum_t point_location[], const cs_real_3_t point_coords[], const void *location_vals, void *point_vals)
Interpolate values defined on a mesh location at a given set of points using a P1 interpolation.
Definition: cs_interpolate.cpp:227
void cs_post_write_probe_values(int mesh_id, int writer_id, const char *var_name, int var_dim, cs_datatype_t datatype, int parent_location_id, cs_interpolate_from_location_t *interpolate_func, void *interpolate_input, const void *vals, const cs_time_step_t *ts)
Output a variable defined at cells or faces of a post-processing mesh using associated writers.
Definition: cs_post.cpp:7003
#define CS_POST_WRITER_ALL_ASSOCIATED
Definition: cs_post.h:67
#define CS_POST_TYPE_cs_real_t
Definition: cs_post.h:98
Field descriptor.
Definition: cs_field.h:131
const char * name
Definition: cs_field.h:133
cs_real_t * val
Definition: cs_field.h:152
int dim
Definition: cs_field.h:138

In this case, selected outputs are named by appending "_p" to the field name to allow combining default probe outputs with interpolated outputs of specific fields.

For simplicity here, values are output to the main probe set and writer, which is assumed to be defined using the GUI in this example.

Note also that interpolation could be also used in some cs_user_extra_operations cases.

If needed, users may also define their own interpolation functions, whose arguments should match cs_interpolate_from_location_t and pass the appropriate pointer to cs_post_write_probe_values.