1 /* ===========================================================================
2 * Functions to handle the setup of a computational domain
3 *============================================================================*/
4
5 /*
6 This file is part of Code_Saturne, a general-purpose CFD tool.
7
8 Copyright (C) 1998-2021 EDF S.A.
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22 Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25 /*----------------------------------------------------------------------------*/
26
27 #include "cs_defs.h"
28
29 /*----------------------------------------------------------------------------
30 * Standard C library headers
31 *----------------------------------------------------------------------------*/
32
33 #include <assert.h>
34
35 /*----------------------------------------------------------------------------
36 * Local headers
37 *----------------------------------------------------------------------------*/
38
39 #include "bft_mem.h"
40
41 #include "cs_ale.h"
42 #include "cs_boundary_zone.h"
43 #include "cs_cdo_blas.h"
44 #include "cs_evaluate.h"
45 #include "cs_equation.h"
46 #include "cs_equation_assemble.h"
47 #include "cs_equation_common.h"
48 #include "cs_equation_param.h"
49 #include "cs_gwf.h"
50 #include "cs_hodge.h"
51 #include "cs_log.h"
52 #include "cs_log_iteration.h"
53 #include "cs_maxwell.h"
54 #include "cs_mesh_deform.h"
55 #include "cs_mesh_location.h"
56 #include "cs_navsto_system.h"
57 #include "cs_parall.h"
58 #include "cs_prototypes.h"
59 #include "cs_solidification.h"
60 #include "cs_source_term.h"
61 #include "cs_thermal_system.h"
62 #include "cs_time_step.h"
63 #include "cs_walldistance.h"
64
65 /*----------------------------------------------------------------------------
66 * Header for the current file
67 *----------------------------------------------------------------------------*/
68
69 #include "cs_domain_setup.h"
70
71 /*----------------------------------------------------------------------------*/
72
73 BEGIN_C_DECLS
74
75 /*!
76 * \file cs_domain_setup.c
77 *
78 * \brief Functions to handle the setup of a computational domain
79 * High level interface for handling the computation.
80 */
81
82 /*=============================================================================
83 * Local type definitions
84 *============================================================================*/
85
86 /*============================================================================
87 * Global variables
88 *============================================================================*/
89
90 /*! \cond DOXYGEN_SHOULD_SKIP_THIS */
91
92 /*============================================================================
93 * Local static variables
94 *============================================================================*/
95
96 static const char _err_empty_domain[] =
97 " Stop setting an empty cs_domain_t structure.\n"
98 " Please check your settings.\n";
99
100 static const char _err_empty_cdo_context[] =
101 " Stop setting an empty cs_domain_cdo_context_t structure.\n"
102 " Please check your settings.\n";
103
104 /*============================================================================
105 * Prototypes for functions intended for use only by Fortran wrappers.
106 * (descriptions follow, with function bodies).
107 *============================================================================*/
108
109 void
110 cs_f_initialize_cdo_systems(void);
111
112 /*============================================================================
113 * Private function prototypes
114 *============================================================================*/
115
116 /*! (DOXYGEN_SHOULD_SKIP_THIS) \endcond */
117
118 /*----------------------------------------------------------------------------*/
119 /*!
120 * \brief Define the scheme flags for the current computational domain
121 * Requirement: domain->cdo_context is alloctated
122 *
123 * \param[in, out] domain pointer to a cs_domain_t structure
124 */
125 /*----------------------------------------------------------------------------*/
126
127 static void
_set_scheme_flags(cs_domain_t * domain)128 _set_scheme_flags(cs_domain_t *domain)
129 {
130 if (domain == NULL)
131 bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
132 if (domain->cdo_context == NULL)
133 bft_error(__FILE__, __LINE__, 0, _err_empty_cdo_context);
134
135 cs_flag_t quant_flag = 0;
136 cs_domain_cdo_context_t *cc = domain->cdo_context;
137
138 /* Define a scheme flag for the current domain */
139
140 const int n_equations = cs_equation_get_n_equations();
141 for (int eq_id = 0; eq_id < n_equations; eq_id++) {
142
143 cs_equation_t *eq = cs_equation_by_id(eq_id);
144 cs_param_space_scheme_t scheme = cs_equation_get_space_scheme(eq);
145 int vardim = cs_equation_get_var_dim(eq);
146
147 switch (scheme) {
148
149 case CS_SPACE_SCHEME_CDOVB:
150 quant_flag |= CS_CDO_QUANTITIES_VB_SCHEME;
151 cc->vb_scheme_flag |= CS_FLAG_SCHEME_POLY0;
152 if (vardim == 1)
153 cc->vb_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
154 else if (vardim == 3)
155 cc->vb_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
156 else
157 bft_error(__FILE__, __LINE__, 0, "Invalid case");
158 break;
159
160 case CS_SPACE_SCHEME_CDOVCB:
161 quant_flag |= CS_CDO_QUANTITIES_VCB_SCHEME;
162 cc->vcb_scheme_flag |= CS_FLAG_SCHEME_POLY0;
163 if (vardim == 1)
164 cc->vcb_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
165 else if (vardim == 3)
166 cc->vcb_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
167 else
168 bft_error(__FILE__, __LINE__, 0, "Invalid case");
169 break;
170
171 case CS_SPACE_SCHEME_CDOEB:
172 assert(vardim == 3);
173 quant_flag |= CS_CDO_QUANTITIES_EB_SCHEME;
174
175 /* vardim should equal to 3 but each edge is associated to a scalar-valued
176 quantity */
177
178 cc->eb_scheme_flag |= CS_FLAG_SCHEME_POLY0 | CS_FLAG_SCHEME_SCALAR;
179 break;
180
181 case CS_SPACE_SCHEME_CDOFB:
182 quant_flag |= CS_CDO_QUANTITIES_FB_SCHEME;
183 cc->fb_scheme_flag |= CS_FLAG_SCHEME_POLY0;
184
185 /* Always build quantities related to scalar-valued equations (in
186 particular the scalar-valued interface can be useful */
187
188 cc->fb_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
189 if (vardim == 3)
190 cc->fb_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
191 else if (vardim > 3)
192 bft_error(__FILE__, __LINE__, 0, "Invalid case");
193 break;
194
195 case CS_SPACE_SCHEME_HHO_P0:
196 assert(cs_equation_get_space_poly_degree(eq) == 0);
197 quant_flag |= CS_CDO_QUANTITIES_HHO_SCHEME;
198 cc->hho_scheme_flag |= CS_FLAG_SCHEME_POLY0;
199 if (vardim == 1)
200 cc->hho_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
201 else if (vardim == 3)
202 cc->hho_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
203 else
204 bft_error(__FILE__, __LINE__, 0, "Invalid case");
205 break;
206
207 case CS_SPACE_SCHEME_HHO_P1:
208 quant_flag |= CS_CDO_QUANTITIES_HHO_SCHEME;
209 cc->hho_scheme_flag |= CS_FLAG_SCHEME_POLY1;
210 assert(cs_equation_get_space_poly_degree(eq) == 1);
211 if (vardim == 1)
212 cc->hho_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
213 else if (vardim == 3)
214 cc->hho_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
215 else
216 bft_error(__FILE__, __LINE__, 0, "Invalid case");
217 break;
218
219 case CS_SPACE_SCHEME_HHO_P2:
220 quant_flag |= CS_CDO_QUANTITIES_HHO_SCHEME;
221 cc->hho_scheme_flag |= CS_FLAG_SCHEME_POLY2;
222 assert(cs_equation_get_space_poly_degree(eq) == 2);
223 if (vardim == 1)
224 cc->hho_scheme_flag |= CS_FLAG_SCHEME_SCALAR;
225 else if (vardim == 3)
226 cc->hho_scheme_flag |= CS_FLAG_SCHEME_VECTOR;
227 else
228 bft_error(__FILE__, __LINE__, 0, "Invalid case");
229 break;
230
231 default:
232 bft_error(__FILE__, __LINE__, 0,
233 _(" Undefined type of scheme to solve for eq. %s."
234 " Please check your settings."), cs_equation_get_name(eq));
235 }
236
237 } /* Loop on equations */
238
239 /* Navier-Stokes system */
240
241 if (cs_navsto_system_is_activated()) {
242
243 cs_navsto_param_t *nsp = cs_navsto_system_get_param();
244
245 switch (nsp->space_scheme) {
246
247 case CS_SPACE_SCHEME_CDOVB:
248 quant_flag |= CS_CDO_QUANTITIES_VB_SCHEME;
249 cc->vb_scheme_flag |= CS_FLAG_SCHEME_NAVSTO;
250 break;
251
252 case CS_SPACE_SCHEME_CDOVCB:
253 quant_flag |= CS_CDO_QUANTITIES_VCB_SCHEME;
254 cc->vcb_scheme_flag |= CS_FLAG_SCHEME_NAVSTO;
255 break;
256
257 case CS_SPACE_SCHEME_CDOEB:
258 quant_flag |= CS_CDO_QUANTITIES_EB_SCHEME;
259 cc->eb_scheme_flag |= CS_FLAG_SCHEME_NAVSTO;
260 break;
261
262 case CS_SPACE_SCHEME_CDOFB:
263 quant_flag |= CS_CDO_QUANTITIES_FB_SCHEME;
264 cc->fb_scheme_flag |= CS_FLAG_SCHEME_NAVSTO;
265 break;
266
267 case CS_SPACE_SCHEME_HHO_P0:
268 case CS_SPACE_SCHEME_HHO_P1:
269 case CS_SPACE_SCHEME_HHO_P2:
270 quant_flag |= CS_CDO_QUANTITIES_HHO_SCHEME;
271 cc->hho_scheme_flag |= CS_FLAG_SCHEME_NAVSTO;
272 break;
273
274 default:
275 break;
276
277 }
278
279 } /* NavSto is activated */
280
281 /* Update the flag storing which geometrical quantities have to be
282 computed */
283
284 cs_cdo_quantities_set(quant_flag);
285 }
286
287 /*============================================================================
288 * Fortran wrapper function definitions
289 *============================================================================*/
290
291 /*----------------------------------------------------------------------------*/
292 /*!
293 * \brief Initialize CDO systems
294 */
295 /*----------------------------------------------------------------------------*/
296
297 void
cs_f_initialize_cdo_systems(void)298 cs_f_initialize_cdo_systems(void)
299 {
300 assert(cs_glob_domain != NULL);
301 cs_domain_initialize_systems(cs_glob_domain);
302 }
303
304 /*============================================================================
305 * Public function prototypes
306 *============================================================================*/
307
308 /*----------------------------------------------------------------------------*/
309 /*!
310 * \brief Set auxiliary parameters related to the way output is done
311 *
312 * \param[in, out] domain pointer to a cs_domain_t structure
313 * \param[in] nt_interval frequency for the restart process
314 * \param[in] nt_list output frequency into the log
315 * \param[in] verbosity level of information displayed
316 */
317 /*----------------------------------------------------------------------------*/
318
319 void
cs_domain_set_output_param(cs_domain_t * domain,int nt_interval,int nt_list,int verbosity)320 cs_domain_set_output_param(cs_domain_t *domain,
321 int nt_interval,
322 int nt_list,
323 int verbosity)
324 {
325 if (domain == NULL) bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
326
327 domain->restart_nt = nt_interval;
328 domain->output_nt = nt_list;
329 if (domain->output_nt == 0)
330 domain->output_nt = -1;
331
332 domain->verbosity = verbosity;
333 }
334
335 /*----------------------------------------------------------------------------*/
336 /*!
337 * \brief Set parameters for unsteady computations: the max number of time
338 * steps or the final physical time of the simulation
339 *
340 * \param[in, out] domain pointer to a \ref cs_domain_t structure
341 * \param[in] nt_max max. number of time step iterations
342 * \param[in] t_max final physical time of the simulation
343 */
344 /*----------------------------------------------------------------------------*/
345
346 void
cs_domain_set_time_param(cs_domain_t * domain,int nt_max,double t_max)347 cs_domain_set_time_param(cs_domain_t *domain,
348 int nt_max,
349 double t_max)
350 {
351 if (domain == NULL) bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
352
353 domain->time_step->nt_max = nt_max;
354 domain->time_step->t_max = t_max;
355 }
356
357 /*----------------------------------------------------------------------------*/
358 /*!
359 * \brief Set time step parameters for unsteady computations when this is not
360 * already done. This situation should occur when the GUI is used to
361 * set a constant time step.
362 *
363 * \param[in, out] domain pointer to a \ref cs_domain_t structure
364 */
365 /*----------------------------------------------------------------------------*/
366
367 void
cs_domain_automatic_time_step_settings(cs_domain_t * domain)368 cs_domain_automatic_time_step_settings(cs_domain_t *domain)
369 {
370 if (domain == NULL) bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
371
372 cs_time_step_t *ts = domain->time_step;
373
374 if (ts->t_max < 0 && ts->nt_max < 1)
375 bft_error(__FILE__, __LINE__, 0,
376 " %s: Please check your settings.\n"
377 " Unsteady computation but no definition available.\n",
378 __func__);
379 if (ts->dt_ref < 0)
380 bft_error(__FILE__, __LINE__, 0,
381 " %s: Please check your settings.\n"
382 " Unsteady computation but no dt_ref available.\n",
383 __func__);
384
385 cs_domain_set_time_param(domain, ts->nt_max, ts->t_max);
386 cs_domain_def_time_step_by_value(domain, ts->dt_ref);
387 }
388
389 /*----------------------------------------------------------------------------*/
390 /*!
391 * \brief Define the value of the time step thanks to a predefined function
392 *
393 * \param[in, out] domain pointer to a cs_domain_t structure
394 * \param[in] func pointer to a cs_time_func_t function
395 * \param[in] func_input pointer to a structure cast on-the-fly
396 *
397 * \return a pointer to the created definition (\ref cs_xdef_t structure)
398 */
399 /*----------------------------------------------------------------------------*/
400
401 cs_xdef_t *
cs_domain_def_time_step_by_function(cs_domain_t * domain,cs_time_func_t * func,void * func_input)402 cs_domain_def_time_step_by_function(cs_domain_t *domain,
403 cs_time_func_t *func,
404 void *func_input)
405 {
406 if (domain == NULL) bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
407
408 domain->time_step->is_variable = 1; /* not constant time step */
409
410 /* Uniform in space but can change from one time step to the other */
411 domain->time_options.idtvar = CS_TIME_STEP_ADAPTIVE;
412
413 /* Set the property related to the time step if used for building a system */
414 cs_property_t *dt_pty = cs_property_by_name("time_step");
415 if (dt_pty == NULL)
416 dt_pty = cs_property_add("time_step", CS_PROPERTY_ISO);
417
418 cs_property_set_reference_value(dt_pty, domain->time_step->t_max);
419
420 cs_xdef_t *def =
421 cs_property_def_by_time_func(dt_pty,
422 NULL, /* all cells are selected */
423 func,
424 func_input);
425
426 /* Default initialization.
427 To be changed at first call to cs_domain_time_step_increment() */
428
429 domain->time_step->dt[0] = domain->time_step->t_max;
430 domain->time_step->dt[1] = domain->time_step->t_max;
431 domain->time_step->dt[2] = domain->time_step->t_max;
432 domain->time_step->dt_ref = domain->time_step->t_max;
433 domain->time_options.dtmin = domain->time_step->t_max;
434 domain->time_options.dtmax = 0.;
435
436 return def;
437 }
438
439 /*----------------------------------------------------------------------------*/
440 /*!
441 * \brief Define the value of the time step.
442 *
443 * \param[in, out] domain pointer to a cs_domain_t structure
444 * \param[in] dt value of the constant time step
445 */
446 /*----------------------------------------------------------------------------*/
447
448 void
cs_domain_def_time_step_by_value(cs_domain_t * domain,double dt)449 cs_domain_def_time_step_by_value(cs_domain_t *domain,
450 double dt)
451 {
452 if (domain == NULL) bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
453
454 domain->time_step->is_variable = 0; /* constant time step */
455
456 /* Constant time step by default */
457 domain->time_options.idtvar = CS_TIME_STEP_CONSTANT;
458
459 domain->time_step->dt[0] = dt; /* time step n */
460 domain->time_step->dt[1] = dt; /* time step n-1 */
461 domain->time_step->dt[2] = dt; /* time step n-2 */
462 domain->time_step->dt_ref = dt;
463 domain->time_step->dt_next = dt;
464 domain->time_options.dtmin = dt;
465 domain->time_options.dtmax = dt;
466
467 /* Set the property related to the time step if used for building a system */
468 cs_property_t *dt_pty = cs_property_by_name("time_step");
469
470 if (dt_pty == NULL)
471 dt_pty = cs_property_add("time_step", CS_PROPERTY_ISO);
472
473 cs_property_def_constant_value(dt_pty, dt);
474 }
475
476 /*----------------------------------------------------------------------------*/
477 /*!
478 * \brief First setup stage of the cs_domain_t structure
479 * Define extra domain boundaries
480 * Setup predefined equations
481 * Create fields
482 * Define cs_sles_t structures for variable fields
483 *
484 * \param[in, out] domain pointer to a cs_domain_t struct.
485 */
486 /*----------------------------------------------------------------------------*/
487
488 void
cs_domain_initialize_setup(cs_domain_t * domain)489 cs_domain_initialize_setup(cs_domain_t *domain)
490 {
491 /* Setup predefined equations which are activated. At this stage,
492 * no equation is added. Space discretization scheme and the related
493 * numerical parameters are set.
494 */
495
496 /* Wall distance */
497 if (cs_walldistance_is_activated())
498 cs_walldistance_setup();
499
500 /* Mesh deformation */
501 if (cs_mesh_deform_is_activated())
502 cs_mesh_deform_setup(domain);
503
504 /* Thermal module */
505 if (cs_thermal_system_is_activated())
506 cs_thermal_system_init_setup();
507
508 /* Groundwater flow module */
509 if (cs_gwf_is_activated())
510 cs_gwf_init_setup();
511
512 /* ALE mesh velocity */
513 if (cs_ale_is_activated())
514 cs_ale_init_setup(domain);
515
516 /* Maxwell module */
517 if (cs_maxwell_is_activated())
518 cs_maxwell_init_setup();
519
520 /* Navier-Stokes system */
521 if (cs_navsto_system_is_activated()) {
522
523 /* To make more easy the settings for the end-user, one may have to
524 * ensure that the Navier-Stokes system has the sufficient knowledge of
525 * what is requested */
526 if (cs_thermal_system_needs_navsto())
527 cs_navsto_system_update_model(true);
528
529 cs_navsto_system_init_setup();
530
531 }
532 else {
533
534 cs_domain_cdo_context_t *cdo = domain->cdo_context;
535
536 /* Switch off turbulence modelling if in CDO mode only */
537 if (cdo->mode == CS_DOMAIN_CDO_MODE_ONLY) {
538
539 cs_turb_model_t *turb = cs_get_glob_turb_model();
540
541 turb->iturb = CS_TURB_NONE; /* laminar flow */
542 turb->itytur = 0; /* deprecated */
543 turb->hybrid_turb = CS_HYBRID_NONE;
544 turb->type = CS_TURB_NONE;
545
546 }
547
548 }
549
550 if (cs_solidification_is_activated())
551 cs_solidification_init_setup();
552
553 /* Add variables related to user-defined and predefined equations */
554
555 cs_equation_create_fields();
556 cs_advection_field_create_fields();
557
558 /* Set the scheme flag for the computational domain */
559
560 _set_scheme_flags(domain);
561
562 /* Last step: Proceed to the settings of a cs_equation_t structure.
563 * Setup the structure related to cs_sles_*
564 * This should be done after the creation of fields
565 */
566
567 /* Navier-Stokes system */
568 if (cs_navsto_system_is_activated())
569 cs_navsto_system_set_sles();
570
571 /* Set the remaining equations */
572 cs_equation_set_sles();
573 }
574
575 /*----------------------------------------------------------------------------*/
576 /*!
577 * \brief After having read the mesh and the first setup stage build the
578 * connectivities and mesh quantities related to CDO/HHO schemes
579 *
580 * \param[in, out] domain pointer to a cs_domain_t struct.
581 */
582 /*----------------------------------------------------------------------------*/
583
584 void
cs_domain_init_cdo_structures(cs_domain_t * domain)585 cs_domain_init_cdo_structures(cs_domain_t *domain)
586 {
587 if (domain == NULL)
588 bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
589 if (domain->cdo_context == NULL)
590 bft_error(__FILE__, __LINE__, 0, _err_empty_cdo_context);
591
592 /* Manage checkpoint/restart settings
593 * Use the same default values for t_interval and wt_interval as the FV */
594
595 double t_interval = -1.0, wt_interval = -1.0;
596 cs_restart_checkpoint_set_defaults(domain->restart_nt,
597 t_interval,
598 wt_interval);
599
600 /* Build additional connectivity structures
601 Update mesh structure with range set structures */
602
603 cs_domain_cdo_context_t *cc = domain->cdo_context;
604 domain->connect = cs_cdo_connect_init(domain->mesh,
605 cc->eb_scheme_flag,
606 cc->fb_scheme_flag,
607 cc->vb_scheme_flag,
608 cc->vcb_scheme_flag,
609 cc->hho_scheme_flag);
610
611 /* Build additional mesh quantities in a separate structure */
612
613 cs_flag_t cdo_quantities_flag = 0;
614 if (cc->eb_scheme_flag)
615 cdo_quantities_flag |= CS_CDO_QUANTITIES_EB_SCHEME;
616 if (cc->fb_scheme_flag)
617 cdo_quantities_flag |= CS_CDO_QUANTITIES_FB_SCHEME;
618 if (cc->hho_scheme_flag)
619 cdo_quantities_flag |= CS_CDO_QUANTITIES_HHO_SCHEME;
620 if (cc->vb_scheme_flag)
621 cdo_quantities_flag |= CS_CDO_QUANTITIES_VB_SCHEME;
622 if (cc->vcb_scheme_flag)
623 cdo_quantities_flag |= CS_CDO_QUANTITIES_VCB_SCHEME;
624
625 cs_cdo_quantities_set(cdo_quantities_flag);
626
627 domain->cdo_quantities = cs_cdo_quantities_build(domain->mesh,
628 domain->mesh_quantities,
629 domain->connect);
630
631 /* Main generic structures are shared with low-level files.
632 Avoid the declaration of global variables by sharing pointers */
633
634 cs_advection_field_set_shared_pointers(domain->cdo_quantities,
635 domain->connect);
636
637 cs_cdo_blas_set_shared_pointers(domain->cdo_quantities,
638 domain->connect);
639
640 cs_evaluate_set_shared_pointers(domain->cdo_quantities,
641 domain->connect);
642
643 cs_property_set_shared_pointers(domain->cdo_quantities,
644 domain->connect);
645
646 cs_source_term_set_shared_pointers(domain->cdo_quantities,
647 domain->connect);
648
649 /* Allocate common structures for solving equations */
650
651 cs_equation_common_init(domain->connect,
652 domain->cdo_quantities,
653 domain->time_step,
654 cc->eb_scheme_flag,
655 cc->fb_scheme_flag,
656 cc->vb_scheme_flag,
657 cc->vcb_scheme_flag,
658 cc->hho_scheme_flag);
659
660 /* Allocate matrix-related structures for the assembly stage */
661
662 cs_equation_assemble_init(domain->connect,
663 cc->eb_scheme_flag,
664 cc->fb_scheme_flag,
665 cc->vb_scheme_flag,
666 cc->vcb_scheme_flag,
667 cc->hho_scheme_flag);
668
669 /* Set the range set structure for synchronization in parallel computing */
670
671 cs_equation_set_range_set(domain->connect);
672
673 cs_equation_set_shared_structures(domain->connect,
674 domain->cdo_quantities,
675 domain->time_step,
676 cc->eb_scheme_flag,
677 cc->fb_scheme_flag,
678 cc->vb_scheme_flag,
679 cc->vcb_scheme_flag,
680 cc->hho_scheme_flag);
681
682 }
683
684 /*----------------------------------------------------------------------------*/
685 /*!
686 * \brief Last user setup stage of the cs_domain_t structure
687 *
688 * \param[in, out] domain pointer to a cs_domain_t struct.
689 */
690 /*----------------------------------------------------------------------------*/
691
692 void
cs_domain_finalize_user_setup(cs_domain_t * domain)693 cs_domain_finalize_user_setup(cs_domain_t *domain)
694 {
695 if (domain == NULL)
696 bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
697 if (domain->cdo_context == NULL)
698 bft_error(__FILE__, __LINE__, 0, _err_empty_cdo_context);
699
700 /* Groundwater flow module */
701
702 if (cs_gwf_is_activated()) {
703
704 /* Add if needed new terms (as diffusion or reaction) to tracer equations
705 according to the settings */
706
707 cs_gwf_add_tracer_terms();
708
709 }
710
711 /* Allocate all fields created during the setup stage */
712
713 cs_field_allocate_or_map_all();
714
715 /* Set the definition of user-defined properties and/or advection
716 * fields (no more fields are created at this stage)
717 * Last setting stage for equations: Associate properties to activate or not
718 * terms such as:
719 * --> Unsteady terms (link with a property)
720 * --> Diffusion terms (link with a property)
721 * --> Advection term (link with an advection field)
722 * --> Reaction term (link with a property)
723 * --> Source term
724 */
725
726 cs_user_boundary_conditions_setup(domain);
727 cs_user_finalize_setup(domain);
728 }
729
730 /*----------------------------------------------------------------------------*/
731 /*!
732 * \brief Last user setup stage of the cs_domain_t structure
733 *
734 * \param[in, out] domain pointer to a cs_domain_t struct.
735 */
736 /*----------------------------------------------------------------------------*/
737
738 void
cs_domain_finalize_module_setup(cs_domain_t * domain)739 cs_domain_finalize_module_setup(cs_domain_t *domain)
740 {
741 if (domain == NULL)
742 bft_error(__FILE__, __LINE__, 0, _err_empty_domain);
743 if (domain->cdo_context == NULL)
744 bft_error(__FILE__, __LINE__, 0, _err_empty_cdo_context);
745
746 /* Last stage for the settings for each predefined set of equations:
747 - thermal module
748 - groundwater flow module
749 - Maxwell equations
750 - Navier-Stokes system
751 - ALE equation
752 */
753
754 if (cs_thermal_system_is_activated())
755 cs_thermal_system_finalize_setup(domain->connect,
756 domain->cdo_quantities,
757 domain->time_step);
758
759 if (cs_gwf_is_activated())
760 cs_gwf_finalize_setup(domain->connect, domain->cdo_quantities);
761
762 if (cs_maxwell_is_activated())
763 cs_maxwell_finalize_setup(domain->connect, domain->cdo_quantities);
764
765 if (cs_navsto_system_is_activated())
766 cs_navsto_system_finalize_setup(domain->mesh,
767 domain->connect,
768 domain->cdo_quantities,
769 domain->time_step);
770
771 if (cs_ale_is_activated())
772 cs_ale_finalize_setup(domain);
773
774 if (cs_solidification_is_activated())
775 cs_solidification_finalize_setup(domain->connect,
776 domain->cdo_quantities);
777
778 /* Last stage to define properties (when complex definition is requested) */
779 cs_property_finalize_setup();
780
781 /* Last stage to define properties (when complex definition is requested) */
782 cs_advection_field_finalize_setup();
783 }
784
785 /*----------------------------------------------------------------------------*/
786 /*!
787 * \brief Initialize systems of equations and their related field values
788 * according to the user settings
789 *
790 * \param[in, out] domain pointer to a cs_domain_t structure
791 */
792 /*----------------------------------------------------------------------------*/
793
794 void
cs_domain_initialize_systems(cs_domain_t * domain)795 cs_domain_initialize_systems(cs_domain_t *domain)
796 {
797 /* Initialize system before building the linear systems
798 * - create system builder
799 * - initialize field according to initial conditions
800 * - initialize source term
801 * - set the initial condition to all variable fields
802 *
803 * connect can be updated during this initialization step
804 */
805 cs_equation_initialize(domain->mesh,
806 domain->time_step,
807 domain->cdo_quantities,
808 domain->connect);
809
810 /* Set the initial condition for all advection fields */
811 cs_advection_field_update(domain->time_step->t_cur,
812 false); /* operate current to previous ? */
813
814 /* Set the initial state for the thermal module */
815 if (cs_thermal_system_is_activated())
816 cs_thermal_system_update(domain->mesh,
817 domain->connect,
818 domain->cdo_quantities,
819 domain->time_step,
820 false); /* operate current to previous ? */
821
822 /* Set the initial state for the Navier-Stokes system */
823 if (cs_navsto_system_is_activated())
824 cs_navsto_system_initialize(domain->mesh,
825 domain->connect,
826 domain->cdo_quantities,
827 domain->time_step);
828
829 /* Set the initial state for the Maxwell module */
830 if (cs_maxwell_is_activated())
831 cs_maxwell_update(domain->mesh,
832 domain->connect,
833 domain->cdo_quantities,
834 domain->time_step,
835 false); /* operate current to previous ? */
836
837 /* Additional initializations (Navier-Stokes system has already been
838 initialized) */
839 if (cs_solidification_is_activated())
840 cs_solidification_initialize(domain->mesh,
841 domain->connect,
842 domain->cdo_quantities,
843 domain->time_step);
844
845 /* Set the initial state for the groundwater flow module */
846 if (cs_gwf_is_activated())
847 cs_gwf_update(domain->mesh,
848 domain->connect,
849 domain->cdo_quantities,
850 domain->time_step,
851 false); /* operate current to previous ? */
852
853 /* Last word for the user function */
854 int cdo_mode = cs_domain_get_cdo_mode(domain);
855 if (cdo_mode == CS_DOMAIN_CDO_MODE_ONLY)
856 cs_user_initialization(domain);
857 }
858
859 /*----------------------------------------------------------------------------*/
860 /*!
861 * \brief Summary of the main domain settings
862 *
863 * \param[in] domain pointer to the cs_domain_t structure to summarize
864 */
865 /*----------------------------------------------------------------------------*/
866
867 void
cs_domain_setup_log(const cs_domain_t * domain)868 cs_domain_setup_log(const cs_domain_t *domain)
869 {
870 cs_log_printf(CS_LOG_SETUP, "\nSummary of the CDO domain settings\n");
871 cs_log_printf(CS_LOG_SETUP, "%s\n", cs_sep_h1);
872
873 int cdo_mode = cs_domain_get_cdo_mode(domain);
874 switch (cdo_mode) {
875
876 case CS_DOMAIN_CDO_MODE_OFF:
877 cs_log_printf(CS_LOG_SETUP, " * CDO mode: **off**\n");
878 return;
879 case CS_DOMAIN_CDO_MODE_WITH_FV:
880 cs_log_printf(CS_LOG_SETUP, " * CDO mode: **on with legacy FV**\n");
881 break;
882 case CS_DOMAIN_CDO_MODE_ONLY:
883 cs_log_printf(CS_LOG_SETUP, " * CDO mode: **on, stand-alone**\n");
884 break;
885
886 default:
887 break; /* Do nothing */
888 }
889
890 /* CDO main structure count */
891 cs_log_printf(CS_LOG_SETUP, "\n## CDO main structures\n");
892
893 int n_equations, n_predef_equations, n_user_equations;
894 cs_equation_get_count(&n_equations, &n_predef_equations, &n_user_equations);
895
896 cs_log_printf(CS_LOG_SETUP, " **Number of equations** %2d\n",
897 n_equations);
898 cs_log_printf(CS_LOG_SETUP, " **Number of predefined equations** %2d\n",
899 n_predef_equations);
900 cs_log_printf(CS_LOG_SETUP, " **Number of user equations** %2d\n",
901 n_user_equations);
902 cs_log_printf(CS_LOG_SETUP, " **Number of properties** %2d\n",
903 cs_property_get_n_properties());
904 cs_log_printf(CS_LOG_SETUP, " **Number of advection fields** %2d\n",
905 cs_advection_field_get_n_fields());
906
907 cs_domain_cdo_context_t *cc = domain->cdo_context;
908
909 cs_cdo_connect_summary(domain->connect,
910 cc->eb_scheme_flag,
911 cc->vb_scheme_flag,
912 cc->vcb_scheme_flag);
913
914 cs_cdo_quantities_summary(domain->cdo_quantities);
915
916 /* Time step summary */
917 cs_log_printf(CS_LOG_SETUP, "\n## Time step information\n");
918 if (domain->only_steady)
919 cs_log_printf(CS_LOG_SETUP, " * Steady-state computation\n");
920
921 else { /* Time information */
922
923 cs_log_printf(CS_LOG_SETUP, " * Unsteady computation\n");
924
925 if (domain->time_step->t_max > 0.)
926 cs_log_printf(CS_LOG_SETUP, "%-30s %5.3e\n",
927 " * Final simulation time:", domain->time_step->t_max);
928 if (domain->time_step->nt_max > 0)
929 cs_log_printf(CS_LOG_SETUP, "%-30s %9d\n",
930 " * Final time step:", domain->time_step->nt_max);
931
932 if (domain->time_options.idtvar == 0)
933 cs_log_printf(CS_LOG_SETUP, " * Time step **constant**\n\n");
934 else if (domain->time_options.idtvar == 1)
935 cs_log_printf(CS_LOG_SETUP, " * Time step **variable in time**\n\n");
936 else {
937 if (cdo_mode != CS_DOMAIN_CDO_MODE_WITH_FV)
938 bft_error(__FILE__, __LINE__, 0,
939 _(" Invalid idtvar value for the CDO module.\n"));
940 }
941
942 }
943
944 }
945
946
947 /*----------------------------------------------------------------------------*/
948
949 END_C_DECLS
950