Page 1 of 2

Neumann condition for temperature in only one direction

Posted: Wed Apr 17, 2024 12:28 am
by mmagain
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

Re: Neumann condition for temperature in only one direction

Posted: Thu Apr 18, 2024 12:03 am
by Yvan Fournier
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

Re: Neumann condition for temperature in only one direction

Posted: Thu Apr 18, 2024 1:40 am
by mmagain
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

Re: Neumann condition for temperature in only one direction

Posted: Thu Apr 18, 2024 9:15 pm
by Yvan Fournier
Hello,

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

Best regards,

Yvan

Re: Neumann condition for temperature in only one direction

Posted: Fri Apr 19, 2024 3:10 pm
by mmagain
Great ! Thank you for your help

Re: Neumann condition for temperature in only one direction

Posted: Wed Apr 24, 2024 7:53 pm
by mmagain
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>

/*----------------------------------------------------------------------------
 * Local headers
 *----------------------------------------------------------------------------*/

#include "cs_headers.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

Re: Neumann condition for temperature in only one direction

Posted: Thu Apr 25, 2024 7:20 pm
by Yvan Fournier
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

Re: Neumann condition for temperature in only one direction

Posted: Thu Apr 25, 2024 10:19 pm
by mmagain
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

Re: Neumann condition for temperature in only one direction

Posted: Sun Apr 28, 2024 5:38 pm
by mmagain
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
(8.08 KiB) Downloaded 218 times

Re: Neumann condition for temperature in only one direction

Posted: Sun Apr 28, 2024 10:00 pm
by Yvan Fournier
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