## Neumann condition for temperature in only one direction

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Neumann condition for temperature in only one direction

Hi,

I am trying to find a way to implement a Neumann boundary condition on the temperature T in the z direction only. Via the GUI, I can use the "prescribed flux (user law)" to define my function but I don't know how I can define my condition. Essentially I am trying to impose the condition dT/dz = some variable quantity that depends on the properties of the liquid inside. I suspect that doing it via the GUI is not possible, maybe by defining a user subroutine might be easier but I have no idea how to do it that way, and I didn't find any satisfactory solution in the documentation either.

Any tips are appreciated,

Best,

Michael

PS : I am using CS 7.0.6
Yvan Fournier
Posts: 4100
Joined: Mon Feb 20, 2012 3:25 pm

### Re: Neumann condition for temperature in only one direction

Hello,

Not only with the GUI, but with the whole of the "legacy" finite volume scheme, Neumann BC's can only be set up relative to the normal direction relative to a boundary.

Using the CDO models it is possible to define a Neumann BC using an arbitrary direction.

In your case, is the z direction normal to the boundary ?

Best regards,

Yvan
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Re: Neumann condition for temperature in only one direction

Hi,

Yes the z direction is normal to my boundary.
Does that mean I can just use the prescribed flux (user law) on this boundary? Since the z-axis is normal to my boundary

Best,

Michael
Yvan Fournier
Posts: 4100
Joined: Mon Feb 20, 2012 3:25 pm

### Re: Neumann condition for temperature in only one direction

Hello,

Yes, you can use the prescribed flux condition in this case.

Best regards,

Yvan
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Re: Neumann condition for temperature in only one direction

Great ! Thank you for your help
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Re: Neumann condition for temperature in only one direction

Hello,

I am trying to use the cs_user_boundary_conditions.c user subroutine. But I am unsure if that should work, and I find the documentation very hard to read. Could you tell me if the following code should work ?

Code: Select all

``````/*============================================================================
* User definition of boundary conditions.
*============================================================================*/

/* code_saturne version 7.0 */

/*
This file is part of Code_Saturne, a general-purpose CFD tool.

Copyright (C) 1998-2021 EDF S.A.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*----------------------------------------------------------------------------*/

#include "cs_defs.h"

/*----------------------------------------------------------------------------
* Standard C library headers
*----------------------------------------------------------------------------*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/

BEGIN_C_DECLS

/*=============================================================================
* Public function definitions
*============================================================================*/

/*----------------------------------------------------------------------------*/
/*!
* \brief User definition of boundary conditions
*
* \param[in]     nvar          total number of variable BC's
* \param[in]     bc_type       boundary face types
* \param[in]     icodcl        boundary face code
*                                - 1  -> Dirichlet
*                                - 2  -> convective outlet
*                                - 3  -> flux density
*                                - 4  -> sliding wall and u.n=0 (velocity)
*                                - 5  -> friction and u.n=0 (velocity)
*                                - 6  -> roughness and u.n=0 (velocity)
*                                - 9  -> free inlet/outlet (velocity)
*                                inflowing possibly blocked
* \param[in]     rcodcl        boundary condition values
*                                rcodcl(3) = flux density value
*                                (negative for gain) in W/m2
*/
/*----------------------------------------------------------------------------*/

void
cs_user_boundary_conditions(int         nvar,
int         bc_type[],
int         icodcl[],
cs_real_t   rcodcl[])
{
const cs_zone_t* z = cs_boundary_zone_by_name("BC_1");
const cs_field_t *f = cs_field_by_name("temperature");
cs_real_t *rcodcl3 = f->bc_coeffs->rcodcl3;
for (cs_lnum_t i = 0; i < z->n_elts; i++) {
cs_lnum_t face_id = z->elt_ids[i];
rcodcl3[face_id] = *my neumann condition expression*;
}
}

/*----------------------------------------------------------------------------*/

END_C_DECLS``````
Yvan Fournier
Posts: 4100
Joined: Mon Feb 20, 2012 3:25 pm

### Re: Neumann condition for temperature in only one direction

Hello,

I did not notice any obvious mistake, so assuming you boundary zone is indeed named "BC_1", and you replace the correct expression for the flux value, it should work.

Note also that if you are using a constant flux value, you can use the GUI. Even with a more complex expression, you can define it with the "user" option in the GUI. In that case, appropriate code will be generated in a "cs_meg_boundary_..." file, in the "src" directory of a code run (RESU/<run_id>/src). This code is generated, so you should never place it in a SRC folder (as it may be overwritten), but looking at the generated code may help provide additional examples taylored to your case (though the zone is selected in a different manner, the loop should be similar).

Best regards,

Yvan
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Re: Neumann condition for temperature in only one direction

Thank you for your fast reply, Yvan.

Unfortunately, I cannot use the GUI because the flux depends on values of the properties of the liquid (such as viscosity, temperature itself, etc.) and are therefore not constant.

I will try it soon.

Best,

Michael
mmagain
Posts: 10
Joined: Mon Jan 15, 2024 9:20 pm

### Re: Neumann condition for temperature in only one direction

Hello,

I have tried running the simulation but bc_coeffs has no attribute rcodcl3. How do I do then to apply the Neumann boundary condition correctly ?

EDIT : After investigation, it seems I should call the attribute af or bf, but I don't know which one I should call.

Here is my code

Best regards,

Michael
cs_user_boundary_conditions.c
Yvan Fournier
Posts: 4100
Joined: Mon Feb 20, 2012 3:25 pm

### Re: Neumann condition for temperature in only one direction

Hello,

Using v7.0, you do not have direct access to "bc_coeffs->rcodcl3[face_id]", as this was added in v8.0 for better readbility.

In v7.0, the equivalent for this is
rcodcl[2 * n_b_faces * nvar + var_id*n_b_faces + face_id] = flux;

(See last example in cs_user_boundary_conditions-notebook.c for a more complete usage example and initialization of var_id, nvar, and n_b_faces above).

I also recommend switchint to v8.0 .

Best regards,

Yvan