/*============================================================================ * User functions for input of calculation parameters. *============================================================================*/ /* VERS */ /* This file is part of code_saturne, a general-purpose CFD tool. Copyright (C) 1998-2023 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 #include #include #include #if defined(HAVE_MPI) #include #endif #if defined(HAVE_MUMPS) #include #include #endif /*---------------------------------------------------------------------------- * PLE library headers *----------------------------------------------------------------------------*/ #include /*---------------------------------------------------------------------------- * Local headers *----------------------------------------------------------------------------*/ #include "cs_headers.h" #if defined(HAVE_PETSC) #include "cs_sles_petsc.h" #endif #if defined(HAVE_MUMPS) #include "cs_sles_mumps.h" #endif /*----------------------------------------------------------------------------*/ BEGIN_C_DECLS /*----------------------------------------------------------------------------*/ /*! * \file cs_user_parameters-cdo-solidification.c * * \brief User functions for setting a calculation using the solidification * module with CDO schemes * * See \ref parameters for examples. */ /*----------------------------------------------------------------------------*/ /*============================================================================ * Private function prototypes *============================================================================*/ /* Nothing at this time */ /*============================================================================ * User function definitions *============================================================================*/ /*----------------------------------------------------------------------------*/ /*! * \brief Define volume and surface zones. */ /*----------------------------------------------------------------------------*/ void cs_user_zones(void) { cs_boundary_zone_define("base", "base", 0); cs_boundary_zone_define("top", "top", 0); cs_boundary_zone_define("left", "left", 0); cs_boundary_zone_define("right", "right", 0); } /*----------------------------------------------------------------------------*/ /*! * \brief Select physical model options, including user fields. * * This function is called at the earliest stages of the data setup, * so field ids are not available yet. */ /*----------------------------------------------------------------------------*/ void cs_user_model(void) { cs_domain_t *domain = cs_glob_domain; /* ====================== Boundary of the domain ====================== */ cs_boundary_t *bdy = domain->boundaries; /* Choose a boundary by default */ cs_boundary_set_default(bdy, CS_BOUNDARY_SYMMETRY); /* Add new boundaries */ cs_boundary_add(bdy, CS_BOUNDARY_WALL, "base"); cs_boundary_add(bdy, CS_BOUNDARY_WALL, "top"); cs_boundary_add(bdy, CS_BOUNDARY_WALL, "left"); cs_boundary_add(bdy, CS_BOUNDARY_WALL, "right"); /*! [user_model_gravity] */ { cs_physical_constants_t *pc = cs_get_glob_physical_constants(); pc->gravity[0] = 0.; pc->gravity[1] = 0.; pc->gravity[2] = -9.81; /* gravity (m/s2) in the z direction */ } /*! [user_model_gravity] */ /* Activate CDO/HHO module so that main additional structure are built */ cs_param_cdo_mode_set(CS_PARAM_CDO_MODE_ONLY); /* =============================== Define the solidification model =============================== */ /* 1. Activate the solidification module */ /* ------------------------------------- */ /*! [param_cdo_activate_solidification] */ { /* For the solidification module: cs_solidification_activate(solidification_model_type, solid_option_flag, solid_post_flag, boundaries, navsto_model, navsto_model_flag, navsto_coupling_type, navsto_post_flag); If a flag is set to 0, then there is no option to add. To add options to a flag: flag = option1 | option2 | option3 | ... */ cs_flag_t solid_option_flag = 0; cs_flag_t solid_post_flag = CS_SOLIDIFICATION_POST_SOLIDIFICATION_RATE | CS_SOLIDIFICATION_POST_SEGREGATION_INDEX; cs_flag_t navsto_model_flag = CS_NAVSTO_MODEL_BOUSSINESQ; cs_flag_t navsto_post_flag = CS_NAVSTO_POST_VELOCITY_DIVERGENCE | CS_NAVSTO_POST_MASS_DENSITY; /* Activate the solidification module with a binary alloy model (the Navier-Stokes and the thermal modules are also activated in back-end) */ cs_solidification_activate(/* Main solidification model */ CS_SOLIDIFICATION_MODEL_BINARY_ALLOY, /* Solidification options */ solid_option_flag, /* Solidification automatic post options */ solid_post_flag, /* NavSto parameters */ domain->boundaries, CS_NAVSTO_MODEL_INCOMPRESSIBLE_NAVIER_STOKES, navsto_model_flag, CS_NAVSTO_COUPLING_MONOLITHIC, navsto_post_flag); } /*! [param_cdo_activate_solidification] */ /*! [param_cdo_solidification_set_binary_alloy] */ { /* Physical data for the settings of a binary alloy model */ cs_real_t T0 = 1550.0, beta_t = -1.07e-4; cs_real_t conc0 = 1.01, beta_c = -1.4e-2; cs_real_t ml = -62.3, kp = 0.358; cs_real_t t_eutec = 1347.0, t_melt = 1538.0; cs_real_t diff_val = 2e-8; cs_real_t latent_heat = 3.09e5; cs_real_t s_das = 5e-4; /* Set the parameters for the binary alloy model */ cs_solidification_set_binary_alloy_model("C_solute", "C_bulk", /* Boussinesq approximation */ beta_t, T0, beta_c, conc0, /* Phase diagram */ kp, ml, t_eutec, t_melt, /* Solute transport equation */ diff_val, /* Physical constants */ latent_heat, s_das); } /*! [param_cdo_solidification_set_binary_alloy] */ } /*----------------------------------------------------------------------------*/ /*! * \brief Define or modify general numerical and physical user parameters. * * At the calling point of this function, most model-related variables * and other fields have been defined, so specific settings related to those * fields may be set here. */ /*----------------------------------------------------------------------------*/ void cs_user_parameters(cs_domain_t *domain) { CS_UNUSED(domain); /*! [cdo_sles_navsto_full_mumps] */ { /* Parameters related to the Navier-Stokes settings. General strategy. */ cs_navsto_param_t *nsp = cs_navsto_system_get_param(); cs_navsto_param_set(nsp, CS_NSKEY_SLES_STRATEGY, "alu"); //cs_navsto_param_set(nsp, CS_NSKEY_GD_SCALE_COEF, "5e3"); cs_navsto_param_set(nsp, CS_NSKEY_IL_ALGO_RTOL, "1e-8"); cs_navsto_param_set(nsp, CS_NSKEY_IL_ALGO_ATOL, "1e-14"); cs_equation_param_t *mom_eqp = cs_equation_param_by_name("momentum"); /* Linear algebra settings */ cs_equation_param_set(mom_eqp, CS_EQKEY_ADV_STRATEGY, "fully_implicit"); cs_equation_param_set(mom_eqp, CS_EQKEY_SLES_VERBOSITY, "0"); #if defined(HAVE_MUMPS) cs_equation_param_set(mom_eqp, CS_EQKEY_ITSOL, "mumps"); #else bft_error(__FILE__, __LINE__, 0, "%s: MUMPS is not available\n", __func__); #endif cs_equation_param_set(mom_eqp, CS_EQKEY_PRECOND, "mumps"); cs_equation_param_set(mom_eqp, CS_EQKEY_PRECOND_BLOCK_TYPE, "none"); } /*! [cdo_sles_navsto_full_mumps] */ /*! [param_cdo_solidification_set_strategy] */ { cs_solidification_set_strategy(CS_SOLIDIFICATION_STRATEGY_PATH); } /*! [param_cdo_solidification_set_strategy] */ /*! [param_cdo_solidification_binary_advanced] */ { cs_solidification_binary_alloy_t *model_struct = cs_solidification_get_binary_alloy_struct(); int n_iter_max = 10; double delta_eps = 1e-3; /* Drive the convergence of the coupled system (solute transport and thermal * equation) with respect to the following criteria (taken from Voller and * Swaminathan'91) * max_{c\in C} |Temp^(k+1) - Temp^(k)| < delta_tolerance * max_{c\in C} |Cbulk^(k+1) - Cbulk*^(k)| < delta_tolerance * n_iter < n_iter_max */ model_struct->n_iter_max = n_iter_max; model_struct->delta_tolerance = delta_eps; } /*! [param_cdo_solidification_binary_advanced] */ } /*----------------------------------------------------------------------------*/ /*! * \brief Specify the elements such as properties, advection fields, * user-defined equations and modules which have been previously added. * * \param[in, out] domain pointer to a cs_domain_t structure */ /*----------------------------------------------------------------------------*/ void cs_user_finalize_setup(cs_domain_t *domain) { CS_UNUSED(domain); /*! [param_cdo_solidification_properties] */ { /* All the following properties are isotropic and set on all the mesh cells (this implies NULL for the second argument). If the property is piecewise constant, then replace NULL by the name of a volum zone. */ /* Mass density (kg.m^-3) */ cs_property_t *rho = cs_property_by_name(CS_PROPERTY_MASS_DENSITY); cs_real_t rho0_fluid = 7060; cs_property_def_iso_by_value(rho, NULL, rho0_fluid); /* Laminar dynamic viscosity (Pa.s) */ cs_property_t *mu = cs_property_by_name(CS_NAVSTO_LAM_VISCOSITY); cs_real_t mu0_fluid = 4.2e-3; cs_property_def_iso_by_value(mu, NULL, mu0_fluid); /* Thermal heat capacity */ cs_property_t *cp = cs_property_by_name(CS_THERMAL_CP_NAME); cs_real_t cp0_fluid = 500; cs_property_def_iso_by_value(cp, NULL, cp0_fluid); /* Thermal conductivity */ cs_property_t *lambda = cs_property_by_name(CS_THERMAL_LAMBDA_NAME); cs_real_t lambda0_fluid = 30; cs_property_def_iso_by_value(lambda, NULL, lambda0_fluid); } /*! [param_cdo_solidification_properties] */ /*! [param_cdo_solidification_thermal_eq] */ { cs_real_t t_ref_fluid = 1550; cs_equation_param_t *th_eqp = cs_equation_param_by_name(CS_THERMAL_EQNAME); /* Set the initial value for the temperature */ cs_equation_add_ic_by_value(th_eqp, NULL, &t_ref_fluid); /* Set the value of the boundary conditions. * * The other boundary zones are associated to the default boundary (by * default, the thermal equation is associated to a no flux (Homogeneous * Neumann boundary condition) */ } /*! [param_cdo_solidification_thermal_eq] */ /*! [param_cdo_solidification_solute_eq] */ { cs_real_t c_ref = 1.01; /* One assumes that an equation called "C_solute" has been added */ cs_equation_param_t *c_eqp = cs_equation_param_by_name("C_solute"); /* Set the initial value for the solute concentration to the reference value */ cs_equation_add_ic_by_value(c_eqp, NULL, &c_ref); } /*! [param_cdo_solidification_solute_eq] */ } /*----------------------------------------------------------------------------*/ END_C_DECLS