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 defined, using gradient reconstruction..
The following example shows how intepolation may be used in the cs_user_postprocess_values function.
First, we define an interpolation function:
static void
_cs_interpolate_from_location_p1(void *input,
int val_dim,
const void *location_vals,
void *point_vals)
{
|| (val_dim != 1 && val_dim != 3 && val_dim != 6)) {
datatype,
val_dim,
n_points,
point_location,
point_coords,
location_vals,
point_vals);
return;
}
&gradient_type,
&halo_type);
if (input != NULL) {
const char *name =
input;
}
switch(val_dim) {
case 1:
{
if (f != NULL)
false,
1,
true,
grad);
else
gradient_type,
halo_type,
1,
true,
100,
0,
0,
0,
0,
-1,
1e-5,
0,
1.5,
NULL,
NULL,
NULL,
c_vals,
NULL,
NULL,
grad);
if (c_id > -1) {
cs_real_t d[3] = {point_coords[i][0] - cell_cen[c_id][0],
point_coords[i][1] - cell_cen[c_id][1],
point_coords[i][2] - cell_cen[c_id][2]};
p_vals[i] = c_vals[c_id] + grad[c_id][0]*d[0]
+ grad[c_id][1]*d[1]
+ grad[c_id][2]*d[2];
}
else
p_vals[i] = 0;
}
}
break;
case 3:
{
if (f != NULL)
false,
1,
grad);
else
gradient_type,
halo_type,
1,
100,
0,
-1,
1e-5,
1.5,
NULL,
NULL,
c_vals,
NULL,
NULL,
grad);
if (c_id > -1) {
cs_real_t d[3] = {point_coords[i][0] - cell_cen[c_id][0],
point_coords[i][1] - cell_cen[c_id][1],
point_coords[i][2] - cell_cen[c_id][2]};
p_vals[i][j] = c_vals[c_id][j] + grad[c_id][j][0]*d[0]
+ grad[c_id][j][1]*d[1]
+ grad[c_id][j][2]*d[2];
}
}
else {
p_vals[i][j] = 0;
}
}
}
break;
case 6:
{
if (f != NULL)
false,
1,
grad);
else
gradient_type,
halo_type,
1,
100,
0,
-1,
1e-5,
1.5,
NULL,
NULL,
c_vals,
grad);
if (c_id > -1) {
cs_real_t d[3] = {point_coords[i][0] - cell_cen[c_id][0],
point_coords[i][1] - cell_cen[c_id][1],
point_coords[i][2] - cell_cen[c_id][2]};
p_vals[i][j] = c_vals[c_id][j] + grad[c_id][j][0]*d[0]
+ grad[c_id][j][1]*d[1]
+ grad[c_id][j][2]*d[2];
}
}
else {
p_vals[i][j] = 0;
}
}
}
break;
default:
assert(0);
}
}
Note the the gradient reconstruction used here assumes ghost cell values are synchronized, which should be the case for field values at this calling stage.
This interpolation function may the be passed to the probe values output function (in cs_user_postprocess_values):
int n_p_fields = 2;
const char *p_field_names[] = {"velocity", "temperature"};
for (int i = 0; i < n_p_fields; i++) {
if (f != NULL) {
char p_name[64];
snprintf(p_name, 63,
"%s_p", f->
name); p_name[63] =
'\0';
(mesh_id,
p_name,
1,
_cs_interpolate_from_location_p1,
ts);
}
}
}
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.