1 #ifndef __CS_ENFORCEMENT_H__
2 #define __CS_ENFORCEMENT_H__
3 
4 /*============================================================================
5  * Manage the list of solid cells and associated helper functions
6  *============================================================================*/
7 
8 /*
9   This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11   Copyright (C) 1998-2021 EDF S.A.
12 
13   This program is free software; you can redistribute it and/or modify it under
14   the terms of the GNU General Public License as published by the Free Software
15   Foundation; either version 2 of the License, or (at your option) any later
16   version.
17 
18   This program is distributed in the hope that it will be useful, but WITHOUT
19   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21   details.
22 
23   You should have received a copy of the GNU General Public License along with
24   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25   Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------
29  *  Local headers
30  *----------------------------------------------------------------------------*/
31 
32 #include "cs_defs.h"
33 #include "cs_cdo_connect.h"
34 #include "cs_cdo_local.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
38 BEGIN_C_DECLS
39 
40 /*============================================================================
41  * Macro definitions
42  *============================================================================*/
43 
44 /*=============================================================================
45  * Structure and type definitions
46  *============================================================================*/
47 
48 /*! \enum cs_enforcement_selection_t
49  *  \brief Type of entities used to define the selection where the enforcement
50  *         takes place
51  *
52  * Two mechanisms are possible.
53  *
54  * 1) Cell selection: defined a selection of cells and then automatically built
55  *    the related selection of degrees of freedom and assigned a value to each
56  *    selected degrees of freedom
57  *
58  * 2) DoF selection (faces or vertices up to now): defined a selection of
59  *    degrees of freedom (DoFs) and assign a values to a selection of degrees
60  *    of freedom inside
61  */
62 
63 typedef enum {
64 
65   CS_ENFORCEMENT_SELECTION_CELLS,     /*!< List of cell ids */
66   CS_ENFORCEMENT_SELECTION_FACES,     /*!< List of face ids */
67   CS_ENFORCEMENT_SELECTION_EDGES,     /*!< List of edge ids */
68   CS_ENFORCEMENT_SELECTION_VERTICES   /*!< List of vertex ids */
69 
70 } cs_enforcement_selection_t;
71 
72 
73 /*! \enum cs_enforcement_type_t
74  *  \brief Describe the way the values to enforce are defined
75  */
76 
77 typedef enum {
78 
79   CS_ENFORCEMENT_BY_CONSTANT,       /*!< The same constant value for each DoF */
80   CS_ENFORCEMENT_BY_DOF_VALUES      /*!< A prescribed value for each DoF */
81 
82 } cs_enforcement_type_t;
83 
84 
85 /*! \struct cs_enforcement_param_t
86  *  \brief Set of data defining an enforcement
87  */
88 
89 typedef struct {
90 
91   cs_enforcement_selection_t    selection_type;
92   cs_enforcement_type_t         type;
93 
94   cs_lnum_t     n_elts;         /*!< local number of selected entities */
95   cs_lnum_t    *elt_ids;        /*!< local list of selected entities */
96   int           stride;         /*!< number of values by entity */
97   cs_real_t    *values;         /*!< associated values */
98 
99 } cs_enforcement_param_t;
100 
101 /*============================================================================
102  * Public function prototypes
103  *============================================================================*/
104 
105 /*----------------------------------------------------------------------------*/
106 /*!
107  * \brief  Create and define a cs_enforcement_param_t structure
108  *
109  * \param[in] sel_type   type of elements which have been selected
110  * \param[in] type       way to set values for the selected elements
111  * \param[in] stride     number of values to enforce by element
112  * \param[in] n_elts     number of selected elements locally
113  * \param[in] elt_ids    list of element ids
114  * \param[in] values     array of values to enforce
115  *
116  * \return a pointer to a cs_enforcement_param_t structure
117  */
118 /*----------------------------------------------------------------------------*/
119 
120 cs_enforcement_param_t *
121 cs_enforcement_param_create(cs_enforcement_selection_t    sel_type,
122                             cs_enforcement_type_t         type,
123                             int                           stride,
124                             cs_lnum_t                     n_elts,
125                             const cs_lnum_t              *elt_ids,
126                             const cs_real_t              *values);
127 
128 /*----------------------------------------------------------------------------*/
129 /*!
130  * \brief  Copy a cs_enforcement_param_t structure
131  *
132  * \param[in] ref    reference structure to copy
133  *
134  * \return a pointer to a cs_enforcement_param_t structure
135  */
136 /*----------------------------------------------------------------------------*/
137 
138 cs_enforcement_param_t *
139 cs_enforcement_param_copy(const cs_enforcement_param_t   *ref);
140 
141 /*----------------------------------------------------------------------------*/
142 /*!
143  * \brief  Free a cs_enforcement_param_t structure
144  *
145  * \param[in, out] p_efp    double pointer to the structure to free
146  */
147 /*----------------------------------------------------------------------------*/
148 
149 void
150 cs_enforcement_param_free(cs_enforcement_param_t   **p_efp);
151 
152 /*----------------------------------------------------------------------------*/
153 /*!
154  * \brief  Log a cs_enforcement_param_t structure
155  *
156  * \param[in] eqname  name of the related equation
157  * \param[in] efp     pointer to a  cs_enforcement_param_t structure
158  */
159 /*----------------------------------------------------------------------------*/
160 
161 void
162 cs_enforcement_param_log(const char                     *eqname,
163                          const cs_enforcement_param_t   *efp);
164 
165 /*----------------------------------------------------------------------------*/
166 /*!
167  * \brief  Build a cs_enforcement_t structure for vertex-based scheme
168  *
169  * \param[in] connect    pointer to a cs_cdo_connect_t
170  * \param[in] n_params   number of enforcement parameters
171  * \param[in] efp_array  array of parameter structures defining the enforcement
172  *
173  * \return an array with the values to enforce
174  */
175 /*----------------------------------------------------------------------------*/
176 
177 cs_real_t *
178 cs_enforcement_define_at_vertices(const cs_cdo_connect_t     *connect,
179                                   int                         n_params,
180                                   cs_enforcement_param_t    **efp_array);
181 
182 /*----------------------------------------------------------------------------*/
183 /*!
184  * \brief  Build a cs_enforcement_t structure for face-based scheme
185  *
186  * \param[in] connect    pointer to a cs_cdo_connect_t
187  * \param[in] n_params   number of enforcement parameters
188  * \param[in] efp_array  array of parameter structures defining the enforcement
189  *
190  * \return an array with the values to enforce
191  */
192 /*----------------------------------------------------------------------------*/
193 
194 cs_real_t *
195 cs_enforcement_define_at_faces(const cs_cdo_connect_t     *connect,
196                                int                         n_params,
197                                cs_enforcement_param_t    **efp_array);
198 
199 /*----------------------------------------------------------------------------*/
200 /*!
201  * \brief  Build a cs_enforcement_t structure for edge-based scheme
202  *
203  * \param[in] connect    pointer to a cs_cdo_connect_t
204  * \param[in] n_params   number of enforcement parameters
205  * \param[in] efp_array  array of parameter structures defining the enforcement
206  *
207  * \return an array with the values to enforce
208  */
209 /*----------------------------------------------------------------------------*/
210 
211 cs_real_t *
212 cs_enforcement_define_at_edges(const cs_cdo_connect_t     *connect,
213                                int                         n_params,
214                                cs_enforcement_param_t    **efp_array);
215 
216 /*----------------------------------------------------------------------------*/
217 /*!
218  * \brief  Build the cell-wise value to enforce
219  *
220  * \param[in]      forced_values     values to enforce or FLT_MAX
221  * \param[in, out] csys              pointer to a cs_cell_sys_t structure
222  * \param[in, out] cw_forced_values  local values to enforce
223  *
224  * \return true if at least one DoF has to be enforced
225  */
226 /*----------------------------------------------------------------------------*/
227 
228 bool
229 cs_enforcement_dofs_cw(const cs_real_t      *forced_values,
230                        cs_cell_sys_t        *csys,
231                        cs_real_t            *cw_forced_values);
232 
233 /*----------------------------------------------------------------------------*/
234 
235 END_C_DECLS
236 
237 #endif /* __CS_ENFORCEMENT_H__ */
238