Usage of user_physical_properties.c

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
senartcon
Posts: 37
Joined: Wed May 08, 2013 6:46 pm

Usage of user_physical_properties.c

Post by senartcon »

Dear users,

I have entered my formulation for spatially varying density inside:

Code: Select all

void
cs_user_physical_properties(const cs_mesh_t             *mesh,
                            const cs_mesh_quantities_t  *mesh_quantities)
{

}
Now how to return the output (density) to the corresponding property variable, as we do in the Fortran subroutine using propce(iel, ipcrom)? Could not find any example.
Thanks.
Yvan Fournier
Posts: 4251
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of user_physical_properties.c

Post by Yvan Fournier »

Hello,

Yes, we are still missing examples here, but examples for postprocessing may be helpful in showing how to access field values and properties.

In the case of pressure:
cs_real_t cvar_rho = CS_F_(rho)->val;
(adding "cs_field_pointer.h" to the includes section if missing)

or
cs_real_t cvar_rho = cs_field_b_name("density")->val;
Should provide access to the cell values array for density. The other examples (postprocessing/extra operations) may help you see how to access other variables you may need to determine density values.

Regards,

Yvan
senartcon
Posts: 37
Joined: Wed May 08, 2013 6:46 pm

Re: Usage of user_physical_properties.c

Post by senartcon »

Hello Yvan,

thanks for your reply. In fact I found that all variable references can be found here:
https://www.code-saturne.org/cms/sites/ ... field.html

However, the variable density is not effected in the simulation., although this subroutine is compiled. I am using CS ver. 5.0.
My code is:

Code: Select all

void
cs_user_physical_properties(const cs_mesh_t             *mesh,
                            const cs_mesh_quantities_t  *mesh_quantities)
{
	cs_real_t *cvar_rho = CS_F_(rho)->val;
	
	for(cs_int_t cell_id=0; cell_id < mesh->n_cells; cell_id++)
	{
		x = mesh_quantities->cell_cen[3*cell_id];
		y = mesh_quantities->cell_cen[3*cell_id+1];
		...
		cvar_rho[cell_id] = f(x, y ...);
	}
	return;
}
Yvan Fournier
Posts: 4251
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of user_physical_properties.c

Post by Yvan Fournier »

Hello,

I don't remember the keyword to activate variable density (maybe irovar), but in the GUI, you can define the density as being variable (so that the field is defined), with a simple (constant) mathematical expression, the use your user function to set the actual values.

Regards,

Yvan
Post Reply