code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
215 stars 80 forks source link

Coupling with code_saturne by PLE library #91

Closed yangzhou-10 closed 1 year ago

yangzhou-10 commented 2 years ago

Hi, I am working with LUMA and Code_saturne coupling by PLE library. This is my previous problems, and got Yvan's feedback, thanks.

[ Problem: Code_saturne send data to PLE library by this function, ple_locator_exchange_point_var(coupling_ent->locator, send_var, NULL, NULL, sizeof(double),2, 0) (from: https://github.com/code-saturne/code\_saturne/blob/master/src/base/cs\_syr\_coupling.c) (1) I want to know every cell's coordinate in the array send_var, so that I can insert data to LUMA in correct coordinate position. (2) Similarly, if I send data array to Code_saturne face, how should I change the array order (based on the coordinates) to allow them insert to Code_saturne corresponding position.

Yvan's answer: Did you already set up the mesh mapping with PLE (ple_locator_set_mesh ?) This is the most essential part.

Assuming this is the case, to send coordinates with ple_locator_exchange_point_var, you need to prepare an array of values to send, using \ple_locator_get_n_dist_points (number of "distant points" located in the local domain you need to send data to, and using \ple_locator_get_dist_locations , you can get the cell (or face) numbers of the local cells in which these points are located. So you can prepare the array to send by filing it with coordinates (for example cell centers) associated with the local cells containing these points.

To send data to code_saturne, the same logic applies. You can use the same functions to determine where points from the code_saturne surface mesh are located in the LUMA mesh, and prepare an array to send using this. ]

yangzhou-10 commented 2 years ago

Hello,

Description: Recently I successfully run Code_Saturne coupling by PLE library, and use the Dirichlet boundary condition. Code_saturne receives velocity data and insert on the face, as shown below.

const cs_field_t fv = cs_field_by_name_try("velocity"); const int var_key_id = cs_field_key_id("variable_id"); int ivarv = cs_field_get_key_int(fv, var_key_id) - 1; for (cs_lnum_t i = 0; i < n_cpl_faces; i++) { cs_lnum_t face_id = f_ids[i]; for (cs_lnum_t ic = 0; ic < 3; ic++) { icodcl[(ivarv + ic) n_b_faces + face_id] = 1; rcodcl[(ivarv + ic) n_b_faces + face_id] = v_luma[3 i + ic]; } }

Question(1): Now, I want Code_Saturne to receive the volume flow rate or mass flow rate, how should I change the above code? and how to define the flow rate direction as shown in GUI. (I try to make icodcl =3, but it doesn't work) image

Question(2): After establishing the mapping between Code_Saturne and other software, I'd like to know if Code_Saturne can calculate the gradient value (i.g. velocity gradient) at the coupling points, and then send the gradient values to other software? For this, the Neumann boundary condition can be applied to the coupling method, which is more accuracy than Dirichlet boundary conditions. Here is Code_Saturne exact the velocity values at coupling points, but doesn't calculate the velocity gradient.

const cs_field_t fv = cs_field_by_name_try("velocity"); const cs_real_t cvar_v = (const cs_real_t )fv->val; for (cs_lnum_t i = 0; i < n_cpl_cells; i++) { cs_lnum_t cid = c_ids[i]; for (cs_lnum_t ic = 0; ic < 3; ic++) v_cs[3 i + ic] = cvar_v[3 * cid + ic]; }

Thanks