/*============================================================================ * General-purpose user-defined functions called before time stepping, at * the end of each time step, and after time-stepping. * * These can be used for operations which do not fit naturally in any other * dedicated user function. *============================================================================*/ /* code_saturne version 8.0 */ /* 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 #if defined(HAVE_MPI) #include #endif /*---------------------------------------------------------------------------- * Local headers *----------------------------------------------------------------------------*/ #include "cs_headers.h" /*----------------------------------------------------------------------------*/ BEGIN_C_DECLS /*----------------------------------------------------------------------------*/ /*! * \file cs_user_extra_operations.c * * \brief This function is called at the end of each time step, and has a very * general purpose (i.e. anything that does not have another dedicated * user function) */ /*----------------------------------------------------------------------------*/ static FILE *f_file = NULL; /*============================================================================ * User function definitions *============================================================================*/ /*----------------------------------------------------------------------------*/ /*! * \brief This function is called at the end of each time step. * * It has a very general purpose, although it is recommended to handle * mainly postprocessing or data-extraction type operations. * * \param[in, out] domain pointer to a cs_domain_t structure */ /*----------------------------------------------------------------------------*/ void cs_user_extra_operations(cs_domain_t *domain) { CS_UNUSED(domain); const cs_lnum_t *b_face_cells = domain->mesh->b_face_cells; const cs_real_3_t *forbr = (const cs_real_3_t *)cs_field_by_name("boundary_forces")->val; const cs_real_t *cvar_p = CS_F_(p)->val; const cs_zone_t *z = cs_boundary_zone_by_name("tablier"); const cs_real_3_t *restrict b_face_cog = (const cs_real_3_t *restrict)cs_glob_mesh_quantities->b_face_cog;/* center of gravity*/ double forces[3] = {0, 0, 0}; for (cs_lnum_t i = 0; i < z->n_elts; i++) { cs_lnum_t face_id = z->elt_ids[i]; forces[0] += forbr[face_id][0]; forces[1] += forbr[face_id][2]; forces[2] +=-forbr[face_id][0]*(0-b_face_cog[face_id][2])+forbr[face_id][2]*(0-b_face_cog[face_id][0]); } cs_parall_sum(3, CS_DOUBLE, forces); if (cs_glob_rank_id == 0) { if (f_file == NULL) { f_file = fopen("lift_and_drag.txt", "w"); fprintf(f_file, "# time_step drag lift moment ddrag\n"); } fprintf(f_file, "%d %g %g %g %g\n", domain->time_step->nt_cur, (forces[0]), (forces[1]/1.85), (forces[2]/(1.85*40)),(forces[0]/1.78) ); if (cs_glob_time_step->nt_cur == cs_glob_time_step->nt_max) { fclose(f_file); f_file = NULL; } } } /*! call field_set_n_previous(iflmas,1) dforces[0] += (forces[0]-cs_field_by_name(forces[0],use_previous_t))/cs_glob_time_step; dforces[1] += (forces[0],use_previous_t); dforces[2] +=forbr[face_id][0]; C=0.5*RHO*u_norm^2*B=6.6; bool use_previous_t = false; */ /*----------------------------------------------------------------------------*/ END_C_DECLS