Spatially varying body force

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Spatially varying body force

Post by Yvan Fournier »

Hello,

Reading this on my phone, while commuting, so I may have missed details, but tyour general approach seems good (MEDCoupling fields and code_satirne fields are different objects, so you need to transfer data from the first to the second).

Do you have the error at the first or second time step ? If it is at the second one, it could be due to an outgoing flow at an inlet (that could be caused by the source term). In this case, multiplying the source term by zero (for a test) but leaving the rest of the code as is could confirm this.

Otherwise, you might have an incorrectly defined dimension leading to a memory overwrite. Running under Valgrind would help check this.

Best regards,

Yvan
ywan459
Posts: 20
Joined: Thu Nov 25, 2021 9:13 pm

Re: Spatially varying body force

Post by ywan459 »

Hi Yvan,

Thanks for your time!

After a few trail-error tests and read of reference codes, I moved my field declare to a different routine,

Code: Select all

void
cs_user_model(void)
{   
    cs_parameters_add_variable("VectorFieldonNode", 1);
}
And the error message disappeared, the results seems fine now. Now I have Medcoupling issue - the error message showed

Code: Select all

/home/App/code_saturne/code_saturne-7.0.2/src/base/cs_medcoupling_remapper.cxx:635: Fatal error.

Error: This function cannot be called without MEDCoupling support.
I will try to install MEDcoupling.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Spatially varying body force

Post by Yvan Fournier »

Hello,

The simples way to install MEDCoupling is probably to install a SALOME platform binary. DEpending on the SALOME build, the parallel features of MEDCoupling may be available or not, but in this case, If I recall correctly, only the base features (including MED file I/O) are needed, so a binary from the salome-platfor.org site should do, if your OS in in the list of proposed binaries.

Using the --with-salome =<path> option in the code_saturne configure should then find the contained MEDCoupling paths.

Best regards,

Yvan
ywan459
Posts: 20
Joined: Thu Nov 25, 2021 9:13 pm

Re: Spatially varying body force

Post by ywan459 »

Hi Yvan,
Thanks for the advise!

I have installed salome on my drive. It works fine. My OS is Windows Linux Subsystem with Ubuntu 20.14. This subsystem works well with code_saturne before. I have successfully completed a few regular CFD modelling, and results looks promising.

To configure, I have ran the command line:

Code: Select all

/App/code_saturne/code_saturne-7.0.2$ ./configure --with-salome=/home/App/salome/SALOME-9.8.0-native-UB20.04-SRC/BINARIES-UB20.04
Here is a piece of showed message:

Code: Select all

OpenMP Fortran support: yes
 CUDA support: no
 BLAS (Basic Linear Algebra Subprograms) support: no
 ParMETIS (Parallel Graph Partitioning) support: no
 METIS (Graph Partitioning) support: no
 PT-SCOTCH (Parallel Graph Partitioning) support: no
 SCOTCH (Graph Partitioning) support: no
 CCM support: no
 HDF (Hierarchical Data Format) support: no
 CGNS (CFD General Notation System) support: no
 MED (Model for Exchange of Data) support: no
 [b]MEDCoupling support: no[/b]
 Catalyst (ParaView co-processing) support: no
 Melissa (in-situ statistics) support: no
 EOS support: no
 freesteam support: no
 CoolProp support: no
 PETSc support: no
 MUMPS support: no
 AMGX support: no
 Dynamic loader support: dlopen
 Auto load environment modules: no

 PdfLaTeX (document typesetting) available: no
 Doxygen (document generation) available: yes
   dot (Graphviz) available: yes
   MathJax enabled: no

The package has been configured. Type:
 make
 make install

To generate and install the Code_Saturne kernel
You could see it showed no medcoupling support. Then I just did regular make and install as hits showed:

Code: Select all

make
and

Code: Select all

make install
I have also tried the --enable-medcoupling option in the configure command, it led to the error in make command.


I still have no lucky to run my model. same error message.

Code: Select all

/home/yikun/App/code_saturne/code_saturne-7.0.2/src/base/cs_medcoupling_remapper.cxx:635: Fatal error.

Error: This function cannot be called without MEDCoupling support.
After configure command, what should I do? Thanks in advance.

P.S. the other thing that confused me is the interpolation. I have data at nodes, but code_Saturne requires the data at "cell", how do I suppose to get the interpolated values from nodes to cell? I only see an example: https://www.code-saturne.org/documentat ... er_3d.html This example seems directly take the cell field values. Does medcoupling interpolate values from nodes to cell?

Regards
ywan459
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Spatially varying body force

Post by Yvan Fournier »

Hello,

The MEDCoupling detection (once SALOME is found) might have been broken by changes in SALOME distribution directory structures or environment variables. In this case, search for a file named MEDCoupling.hxx in the SALOME tree, and if you find it, use the part of its path before "include" with the --with-medcoupling=<path> code_saturne configure option.
Hoping this will work. Otherwise, if this fails, you can compile MEDCoupling from sources, using the same MED file support with medCoupling and code_saturne so that files can be read.

Regarding vertex/cells interpolation, I think MEDCoupling should handled that, and there are options to tune the algorimth choice for that.

Best regards,

Yvan
ywan459
Posts: 20
Joined: Thu Nov 25, 2021 9:13 pm

Re: Spatially varying body force

Post by ywan459 »

Hi Yvan,

Thanks!

I have to give up on medcoupling with code_saturne. But I have coded the user subroutine in a different way that reads the txt file of the spatially varying body force and add it to NS equation. I found the way of interpolate the "cell value" from the nodal values through medcoupling in salome environment. Since it is not a variable, but a volumetric condition, I am happy about my current approach of direct export and direct read in.

I have to move on, and will come back to this point at some stage.

Now I have a new issue :D :D :D

I found the my model results (under the z direct universal body force) has a bit of discrepancy compared with the benchmark which the body force was set through GUI. Here is my final source term code:

Code: Select all

void
cs_user_source_terms(cs_domain_t  *domain,
                     int           f_id,
                     cs_real_t    *st_exp,
                     cs_real_t    *st_imp)
{
  /* field structure */
  const cs_field_t  *f = cs_field_by_id(f_id);

  /* mesh quantities */
  const cs_lnum_t  n_cells = domain->mesh->n_cells;
  const cs_real_t  *cell_f_vol = domain->mesh_quantities->cell_vol;
  
  /* Density */
  const cs_real_t  *cpro_rom = CS_F_(rho)->val; 
  
  const cs_real_t ro0  = cs_glob_fluid_properties->ro0;
  
  cs_real_t *cvar_svbf_x = cs_field_by_name("x")->val;
  cs_real_t *cvar_svbf_y = cs_field_by_name("y")->val;
  cs_real_t *cvar_svbf_z = cs_field_by_name("z")->val;
  
  if (strcmp(f->name, "velocity") == 0) {
    cs_real_3_t    *_st_exp = (cs_real_3_t *)st_exp;
    /* apply source terms to all cells */
    for (cs_lnum_t i = 0; i < n_cells; i++) {
      _st_exp[i][0] = cell_f_vol[i] * cvar_svbf_x[i] * cpro_rom[i];
      _st_exp[i][1] = cell_f_vol[i] * cvar_svbf_y[i] * cpro_rom[i];
      _st_exp[i][2] = cell_f_vol[i] * cvar_svbf_z[i] * cpro_rom[i];
    }
  }

}
It reads the x, y and z components of acceleration from fields. In this case, x and y are 0, and z is 9.8 m/s^2. Then calculate the force_x = volume * acc_x * density, force_y = volume * acc_y * density, force_z = volume * acc_z * density.

I have attached the screen cuts of the total pressure. You may see the one subject to the GUI defined body force is higher than the one produced by my user code. Not sure the root cause, I guess the body force was implemented in a very different way ???

REgards
ywan459
Attachments
Capture_S.PNG
Capture_B.PNG
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Spatially varying body force

Post by Yvan Fournier »

Hello,

When defining a source term with the GUI, using a mathematical expression,, that expression is converted into C code in one of the cs_meg_*.c files you can find ind the "src" subfolder of computation run directories, then compiled along with user-defined routines.

It may be interesting to compare the expressions in those files to the one you programmed.

Best regards,

Yvan
Post Reply