1!------------------------------------------------------------------------------- 2 3! This file is part of Code_Saturne, a general-purpose CFD tool. 4! 5! Copyright (C) 1998-2021 EDF S.A. 6! 7! This program is free software; you can redistribute it and/or modify it under 8! the terms of the GNU General Public License as published by the Free Software 9! Foundation; either version 2 of the License, or (at your option) any later 10! version. 11! 12! This program is distributed in the hope that it will be useful, but WITHOUT 13! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14! FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15! details. 16! 17! You should have received a copy of the GNU General Public License along with 18! this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 19! Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 21!------------------------------------------------------------------------------- 22 23!> \file fldvar.f90 24!> \brief Variables definition initialization, according to calculation type 25!> selected by the user. 26! 27!------------------------------------------------------------------------------ 28! Arguments 29!------------------------------------------------------------------------------ 30! mode name role 31!------------------------------------------------------------------------------ 32!> \param[out] nmodpp number of activated particle physic models 33!______________________________________________________________________________ 34 35subroutine fldvar & 36( nmodpp ) 37 38!=============================================================================== 39! Module files 40!=============================================================================== 41 42use paramx 43use dimens 44use numvar 45use optcal 46use cstphy 47use cstnum 48use entsor 49use albase 50use lagran 51use parall 52use ppppar 53use ppthch 54use coincl 55use cpincl 56use ppincl 57use radiat 58use mesh 59use field 60use cs_c_bindings 61use cfpoin, only:ieos 62 63!=============================================================================== 64 65implicit none 66 67! Arguments 68 69integer nmodpp 70 71! Local variables 72 73integer ipp 74integer iok, keycpl, nmodpp_compatibility, vof_mask 75integer key_lim_id, kscmin, kscmax 76 77type(var_cal_opt) :: vcopt 78 79!=============================================================================== 80! Interfaces 81!=============================================================================== 82 83interface 84 85 ! Interface to C function returning number of user-defined variables 86 87 function cs_parameters_n_added_variables() result(n) & 88 bind(C, name='cs_parameters_n_added_variables') 89 use, intrinsic :: iso_c_binding 90 implicit none 91 integer(c_int) :: n 92 end function cs_parameters_n_added_variables 93 94end interface 95 96!=============================================================================== 97! 0. INITIALISATIONS 98!=============================================================================== 99 100call field_get_key_id('coupled', keycpl) 101 102!=============================================================================== 103! Calcul de nscapp 104! Verification du nombre de scalaires 105! Construction de iscapp 106! Calcul de nscal 107 108! A la sortie de cette section, NSCAL, NSCAUS et NSCAPP sont connus. 109! On en profite aussi pour remplir ITYTUR et ITYTURT puisque ITURB et ITURT 110! viennent d'etre definis. 111!=============================================================================== 112 113! ---> Remplissage de ITYTUR 114itytur = iturb/10 115 116! ---> Coherence modele 117! Rq : ATTENTION il faudrait renforcer le blindage 118 119iok = 0 120nmodpp = 0 121do ipp = 2, nmodmx 122 if (ippmod(ipp).ne.-1) then 123 nmodpp = nmodpp+1 124 if (ippmod(ipp).lt.0 .or. ippmod(ipp).gt.5) then 125 write(nfecra,6001) 126 iok = iok + 1 127 endif 128 endif 129enddo 130 131nmodpp_compatibility = nmodpp 132 133! Compressible module and gas mix are compatible 134if (ippmod(igmix).ne.-1 .and. ippmod(icompf) .ne. -1) then 135 nmodpp_compatibility = nmodpp_compatibility - 1 136endif 137 138! Atmo in humid atmosphere et Couling tower (iaeros) coupling 139if (ippmod(iatmos).eq.2 .and. ippmod(iaeros) .ne. -1) then 140 nmodpp_compatibility = nmodpp_compatibility - 1 141endif 142 143if (nmodpp_compatibility.gt.1) then 144 write(nfecra,6000) 145 iok = iok + 1 146endif 147 148! In case ideal gas mix specific physics was enabled by the user 149! together with the compressible module, the equation of state 150! indicator is reset to the approprate value automatically (ieos=3) 151! and the user is warned. 152if (ippmod(igmix).ge.0.and.ippmod(icompf).ge.0.and.ieos.ne.3) then 153 ieos = 3 154 write(nfecra,6002) 155endif 156 157if (iok.ne.0) then 158 call csexit (1) 159 !========== 160endif 161 162! Set global indicator: ippmod(iphpar) 163! 0: no specific model 164! 1: active specific physical model 165ippmod(iphpar) = 0 166if (nmodpp.gt.0) then 167 ippmod(iphpar) = 1 168 ! Ground water flows model is not considered as a specific physic. 169 if (ippmod(idarcy).gt.-1) ippmod(iphpar) = 0 170endif 171 172! Define main variables 173!====================== 174 175nvar = 0 176 177! Velocity 178 179call add_variable_field('velocity', 'Velocity', 3, iu) 180call field_set_key_int(ivarfl(iu), keycpl, 1) 181 182! All components point to same field 183iv = iu + 1 184iw = iv + 1 185 186! Pressure or hydraulic head for groundwater flow module 187 188if (ippmod(idarcy).eq.-1) then 189 call add_variable_field('pressure', 'Pressure', 1, ipr) 190else 191 call add_variable_field('hydraulic_head', 'Hydraulic head', 1, ipr) 192endif 193 194! Enabled VoF model if free surface or mass transfer modeling enabled 195vof_mask = ior(VOF_FREE_SURFACE, VOF_MERKLE_MASS_TRANSFER) 196if (iand(ivofmt, vof_mask).ne.0) & 197 ivofmt = ior(VOF_ENABLED, ivofmt) 198 199! Mass balance equation options (pressure) 200 201call field_get_key_struct_var_cal_opt(ivarfl(ipr), vcopt) 202 203! elliptic equation 204vcopt%iconv = 0 205 206if (ippmod(icompf).ge.0) then ! compressible algorithm 207 vcopt%istat = 1 208else 209 vcopt%istat = 0 210endif 211 212! VoF algorithm: activate the weighting for the pressure 213if (ivofmt.gt.0) vcopt%iwgrec = 1 214 215call field_set_key_struct_var_cal_opt(ivarfl(ipr), vcopt) 216 217! void fraction (VoF algorithm) 218 219if (ivofmt.gt.0) then 220 call add_variable_field('void_fraction', 'Void Fraction', 1, ivolf2) 221 call field_get_key_struct_var_cal_opt(ivarfl(ivolf2), vcopt) 222 vcopt%idiff = 0 ! pure convection equation 223 224 ! NVD/TVD scheme 225 vcopt%ischcv = 4 226 call field_get_key_id("limiter_choice", key_lim_id) 227 ! (CICSAM limiter) 228 call field_set_key_int(ivarfl(ivolf2), key_lim_id, 11) 229 ! Beta Limiter 230 vcopt%isstpc = 2 231 232 call field_set_key_struct_var_cal_opt(ivarfl(ivolf2), vcopt) 233 ! Bounds for the beta limiter 234 call field_get_key_id("min_scalar", kscmin) 235 call field_get_key_id("max_scalar", kscmax) 236 call field_set_key_double(ivarfl(ivolf2), kscmin, 0.d0) 237 call field_set_key_double(ivarfl(ivolf2), kscmax, 1.d0) 238endif 239 240! Turbulence 241 242if (itytur.eq.2) then 243 call add_variable_field('k', 'Turb Kinetic Energy', 1, ik) 244 call add_variable_field('epsilon', 'Turb Dissipation', 1, iep) 245else if (itytur.eq.3) then 246 call add_variable_field('rij', 'Rij', 6, irij) 247 call field_set_key_int(ivarfl(irij), keycpl, 1) 248 249 ! All rij components point to same field 250 ir11 = irij 251 ir22 = ir11 + 1 252 ir33 = ir22 + 1 253 ir12 = ir33 + 1 254 ir23 = ir12 + 1 255 ir13 = ir23 + 1 256 257 call add_variable_field('epsilon', 'Turb Dissipation', 1, iep) 258 if (iturb.eq.32) then 259 call add_variable_field('alpha', 'Alphap', 1, ial) 260 ! Elliptic equation (no convection, no time term) 261 call field_get_key_struct_var_cal_opt(ivarfl(ial), vcopt) 262 vcopt%istat = 0 263 vcopt%iconv = 0 264 ! For alpha, we always have a diagonal term, so do not shift the diagonal 265 vcopt%idircl = 0 266 call field_set_key_struct_var_cal_opt(ivarfl(ial), vcopt) 267 endif 268else if (itytur.eq.5) then 269 call add_variable_field('k', 'Turb Kinetic Energy', 1, ik) 270 call add_variable_field('epsilon', 'Turb Dissipation', 1, iep) 271 call add_variable_field('phi', 'Phi', 1, iphi) 272 if (iturb.eq.50) then 273 call add_variable_field('f_bar', 'f_bar', 1, ifb) 274 call field_get_key_struct_var_cal_opt(ivarfl(ifb), vcopt) 275 vcopt%istat = 0 276 vcopt%iconv = 0 277 ! For fb, we always have a diagonal term, so do not shift the diagonal 278 vcopt%idircl = 0 279 call field_set_key_struct_var_cal_opt(ivarfl(ifb), vcopt) 280 else if (iturb.eq.51) then 281 call add_variable_field('alpha', 'Alpha', 1, ial) 282 call field_get_key_struct_var_cal_opt(ivarfl(ial), vcopt) 283 vcopt%istat = 0 284 vcopt%iconv = 0 285 ! For alpha, we always have a diagonal term, so do not shift the diagonal 286 vcopt%idircl = 0 287 call field_set_key_struct_var_cal_opt(ivarfl(ial), vcopt) 288 endif 289else if (iturb.eq.60) then 290 call add_variable_field('k', 'Turb Kinetic Energy', 1, ik) 291 call add_variable_field('omega', 'Omega', 1, iomg) 292else if (iturb.eq.70) then 293 call add_variable_field('nu_tilda', 'NuTilda', 1, inusa) 294endif 295 296! Mesh velocity with ALE 297if (iale.ge.1) then 298 299 ! field defined on vertices if CDO-Vb scheme is used 300 if (iale.eq.2) then 301 call add_cdo_variable_field('mesh_velocity', 'Mesh Velocity', & 302 3, MESH_LOCATION_VERTICES, 1, iuma) 303 else 304 call add_variable_field('mesh_velocity', 'Mesh Velocity', 3, iuma) 305 endif 306 307 call field_set_key_int(ivarfl(iuma), keycpl, 1) 308 309 ivma = iuma + 1 310 iwma = ivma + 1 311 312 call field_get_key_struct_var_cal_opt(ivarfl(iuma), vcopt) 313 vcopt%istat = 0 314 vcopt%iconv = 0 315 call field_set_key_struct_var_cal_opt(ivarfl(iuma), vcopt) 316 317endif 318 319! Number of user variables 320 321nscaus = cs_parameters_n_added_variables() 322 323! ---> Lecture donnees thermochimie 324 325call pplecd 326!========== 327 328! ---> Definition des variables 329 330call ppvarp 331!========== 332 333! Thermal model with no specific physics 334 335if (nmodpp.eq.0) then 336 337 if (itherm .eq. 1) then 338 call add_model_scalar_field('temperature', 'Temperature', iscalt) 339 else if (itherm .eq. 2) then 340 call add_model_scalar_field('enthalpy', 'Enthalpy', ihm) 341 iscalt = ihm 342 endif 343 344endif 345 346call add_user_scalar_fields 347 348! Map pointers 349 350call cs_field_pointer_map_base 351call cs_field_pointer_map_boundary 352 353! ---> Verifications 354 355iok = 0 356 357if (nscaus.lt.0) then 358 write(nfecra,6010) nscaus 359 iok = iok + 1 360endif 361 362if (nscaus.gt.0 .or. nscapp.gt.0) then 363 if ((nscaus+nscapp).gt.nscamx) then 364 if (nscapp.le.0) then 365 write(nfecra,6011) nscaus, nscamx, nscamx, nscaus 366 else 367 write(nfecra,6012) nscaus,nscapp,nscamx,nscamx-nscapp,nscaus+nscapp 368 endif 369 iok = iok + 1 370 endif 371endif 372 373if (iok.ne.0) then 374 call csexit (1) 375 !========== 376endif 377 378return 379 380!=============================================================================== 381! 5. FORMATS 382!=============================================================================== 383 384 6000 format( & 385'@ ',/,& 386'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 387'@ ',/,& 388'@ @@ WARNING : STOP AT THE INITIAL DATA VERIFICATION ',/,& 389'@ ========= ',/,& 390'@ SEVERAL INCOMPATIBLE MODELS OF SPECIFIC PHYSICS ARE ',/,& 391'@ ARE ENABLED. ',/,& 392'@ ',/,& 393'@ Only the compressible and gas mix specific physics can be ',/,& 394'@ enabled simultaneously. ',/,& 395'@ ',/,& 396'@ The calculation will not be run. ',/,& 397'@ ',/,& 398'@ Modify the indices of IPPMOD in usppmo. ',/,& 399'@ ',/,& 400'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 401'@ ',/) 402 6001 format( & 403'@ ',/,& 404'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 405'@ ',/,& 406'@ @@ WARNING : STOP AT THE INITIAL DATA VERIFICATION ',/,& 407'@ ========= ',/,& 408'@ WRONG SELLECTION OF THE MODEL FOR SPECIFIC PHYSICS ',/,& 409'@ ',/,& 410'@ The values of the indices of the array IPPMOD are not ',/,& 411'@ admissible ',/,& 412'@ ',/,& 413'@ The calculation will not be run. ',/,& 414'@ ',/,& 415'@ Modify the indices of IPPMOD in usppmo. ',/,& 416'@ ',/,& 417'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 418'@ ',/) 419 6002 format( & 420'@ ',/,& 421'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 422'@ ',/,& 423'@ @@ WARNING : AT THE INITIAL DATA VERIFICATION ',/,& 424'@ ========= ',/,& 425'@ EQUATION OF STATE INCOMPATIBLE WITH SELECTED SPECIFIC ',/,& 426'@ PHYSICS ',/,& 427'@ ',/,& 428'@ The specific physics compressible and gas mix are ',/,& 429'@ simultaneously enabled but the selected equation of ',/,& 430'@ state is not ideal gas mix (ieos different from 3). ',/,& 431'@ ',/,& 432'@ The indicator ieos has been reset to 3 and the calculation',/,& 433'@ will run. ',/,& 434'@ ',/,& 435'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 436'@ ',/) 437 6010 format( & 438'@ ',/,& 439'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 440'@ ',/,& 441'@ @@ WARNING : STOP AT THE INITIAL DATA VERIFICATION ',/,& 442'@ ========= ',/,& 443'@ ERRONEOUS NUMBER OF SCALARS ',/,& 444'@ ',/,& 445'@ The number of users scalars must be an integer either ',/,& 446'@ positive or zero. Here is NSCAUS = ',I10 ,/,& 447'@ ',/,& 448'@ The calculation will not be run. ',/,& 449'@ ',/,& 450'@ Verify parameters. ',/,& 451'@ ',/,& 452'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 453'@ ',/) 454 6011 format( & 455'@ ',/,& 456'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 457'@ ',/,& 458'@ @@ WARNING : STOP AT THE INITIAL DATA VERIFICATION ',/,& 459'@ ========= ',/,& 460'@ NUMBER OF SCALARS TOO LARGE ',/,& 461'@ ',/,& 462'@ The number of users scalars ',/,& 463'@ requested is NSCAUS = ',I10 ,/,& 464'@ The total number of scalars ',/,& 465'@ allowed in paramx is NSCAMX = ',I10 ,/,& 466'@ ',/,& 467'@ The maximmum value allowed of NSCAUS ',/,& 468'@ is in NSCAMX = ',I10 ,/,& 469'@ ',/,& 470'@ The calculation will not be run. ',/,& 471'@ ',/,& 472'@ Verify NSCAUS. ',/,& 473'@ ',/,& 474'@ NSCAMX must be at least ',I10 ,/,& 475'@ ',/,& 476'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 477'@ ',/) 478 6012 format( & 479'@ ',/,& 480'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 481'@ ',/,& 482'@ @@ WARNING : STOP AT THE INITIAL DATA VERIFICATION ',/,& 483'@ ========= ',/,& 484'@ NUMBER OF SCALARS TOO LARGE ',/,& 485'@ ',/,& 486'@ The number of users scalars ',/,& 487'@ requested is NSCAUS = ',I10 ,/,& 488'@ The number of scalars necessary for the specific physics' ,/,& 489'@ with the chosen model is NSCAPP = ',I10 ,/,& 490'@ The total number of scalars ',/,& 491'@ allowed in paramx.h is NSCAMX = ',I10 ,/,& 492'@ ',/,& 493'@ The maximum value allowed for NSCAUS ',/,& 494'@ with the chosen model is NSCAMX-NSCAPP = ',I10 ,/,& 495'@ ',/,& 496'@ The calculation will not be run. ',/,& 497'@ ',/,& 498'@ Verify NSCAUS. ',/,& 499'@ ',/,& 500'@ NSCAMX must be at least ',I10 ,/,& 501'@ ',/,& 502'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 503'@ ',/) 504 505!=============================================================================== 506! 5. FIN 507!=============================================================================== 508 509return 510end subroutine 511 512!=============================================================================== 513! Local functions 514!=============================================================================== 515 516!=============================================================================== 517 518!> \brief add field defining a general solved variable, with default options 519! 520!> It is recommended not to define variable names of more than 16 521!> characters, to get a clear execution log (some advanced writing 522!> levels take into account only the first 16 characters). 523 524!------------------------------------------------------------------------------- 525! Arguments 526!______________________________________________________________________________. 527! mode name role ! 528!______________________________________________________________________________! 529!> \param[in] name field name 530!> \param[in] label field default label, or empty 531!> \param[in] dim field dimension 532!> \param[out] ivar variable number for defined field 533!_______________________________________________________________________________ 534 535subroutine add_variable_field & 536 ( name, label, dim, ivar ) 537 538!=============================================================================== 539! Module files 540!=============================================================================== 541 542use paramx 543use dimens 544use entsor 545use numvar 546use field 547use cs_c_bindings 548 549!=============================================================================== 550 551implicit none 552 553! Arguments 554 555character(len=*), intent(in) :: name, label 556integer, intent(in) :: dim 557integer, intent(out) :: ivar 558 559! Local variables 560 561integer id, ii 562 563integer, save :: keyvar = -1 564 565! Create field 566 567call variable_field_create(name, label, MESH_LOCATION_CELLS, dim, id) 568 569if (keyvar.lt.0) then 570 call field_get_key_id("variable_id", keyvar) 571endif 572 573ivar = nvar + 1 574nvar = nvar + dim 575 576! Check we have enough slots 577call fldvar_check_nvar 578 579ivarfl(ivar) = id 580 581call field_set_key_int(id, keyvar, ivar) 582 583call init_var_cal_opt(id) 584 585if (dim .gt. 1) then 586 do ii = 2, dim 587 ivarfl(ivar + ii - 1) = id 588 enddo 589endif 590 591return 592 593end subroutine add_variable_field 594 595!=============================================================================== 596 597!> \brief Add a field defining a general solved variable, with default options 598!> This variable is solved with a CDO scheme. 599! 600!> It is recommended not to define variable names of more than 16 601!> characters, to get a clear execution log (some advanced writing 602!> levels take into account only the first 16 characters). 603 604!------------------------------------------------------------------------------- 605! Arguments 606!______________________________________________________________________________. 607! mode name role ! 608!______________________________________________________________________________! 609!> \param[in] name field name 610!> \param[in] label field default label, or empty 611!> \param[in] dim field dimension 612!> \param[in] location_id id of the mesh location where the field is defined 613!> \param[in] has_previous if greater than 0 then stores previous state 614!> \param[out] ivar variable number for defined field 615!_______________________________________________________________________________ 616 617subroutine add_cdo_variable_field & 618 ( name, label, dim, location_id, has_previous, ivar ) 619 620!=============================================================================== 621! Module files 622!=============================================================================== 623 624use paramx 625use dimens 626use entsor 627use numvar 628use field 629use cs_c_bindings 630 631!=============================================================================== 632 633implicit none 634 635! Arguments 636 637character(len=*), intent(in) :: name, label 638integer, intent(in) :: dim, location_id, has_previous 639integer, intent(out) :: ivar 640 641! Local variables 642 643integer id, ii 644 645integer, save :: keyvar = -1 646 647! Create field 648 649call variable_cdo_field_create(name, label, location_id, dim, has_previous, id) 650 651if (keyvar.lt.0) then 652 call field_get_key_id("variable_id", keyvar) 653endif 654 655ivar = nvar + 1 656nvar = nvar + dim 657 658! Check we have enough slots 659call fldvar_check_nvar 660 661ivarfl(ivar) = id 662 663call field_set_key_int(id, keyvar, ivar) 664 665call init_var_cal_opt(id) 666 667if (dim .gt. 1) then 668 do ii = 2, dim 669 ivarfl(ivar + ii - 1) = id 670 enddo 671endif 672 673return 674 675end subroutine add_cdo_variable_field 676 677!=============================================================================== 678 679!> \brief add fields defining user solved scalar variables, 680!> with default options 681! 682!------------------------------------------------------------------------------- 683! Arguments 684!______________________________________________________________________________. 685! mode name role ! 686!______________________________________________________________________________! 687!_______________________________________________________________________________ 688 689subroutine add_user_scalar_fields 690 691!=============================================================================== 692! Module files 693!=============================================================================== 694 695use paramx 696use dimens 697use entsor 698use numvar 699use field 700 701!=============================================================================== 702 703implicit none 704 705! Arguments 706 707! Local variables 708 709integer iscal, nfld1, nfld2 710integer dim, id, ii, ivar, keycpl 711 712integer :: keyvar, keysca 713 714!=============================================================================== 715! Interfaces 716!=============================================================================== 717 718interface 719 720 ! Interface to C function building user-defined variables 721 722 subroutine cs_parameters_create_added_variables() & 723 bind(C, name='cs_parameters_create_added_variables') 724 use, intrinsic :: iso_c_binding 725 implicit none 726 end subroutine cs_parameters_create_added_variables 727 728end interface 729 730!=============================================================================== 731 732! Create fields 733 734call field_get_n_fields(nfld1) 735 736call cs_parameters_create_added_variables 737 738call field_get_n_fields(nfld2) 739 740! Now map those fields 741 742iscal = 0 743 744call field_get_key_id('coupled', keycpl) 745call field_get_key_id("scalar_id", keysca) 746call field_get_key_id("variable_id", keyvar) 747 748do id = nfld1, nfld2 - 1 749 750 call field_get_dim(id, dim) 751 752 if (dim.eq.3) then 753 call field_set_key_int(id, keycpl, 1) 754 else if (dim.ne.1) then 755 cycle 756 endif 757 758 iscal = iscal + 1 759 760 ivar = nvar + 1 761 nvar = nvar + dim 762 nscal = nscal + 1 763 764 ! Check we have enough slots 765 call fldvar_check_nvar 766 767 isca(iscal) = ivar 768 ivarfl(ivar) = id 769 770 call field_set_key_int(id, keyvar, ivar) 771 call field_set_key_int(id, keysca, iscal) 772 call init_var_cal_opt(id) 773 774 if (dim .gt. 1) then 775 do ii = 2, dim 776 ivarfl(ivar + ii - 1) = id 777 enddo 778 endif 779 780enddo 781 782return 783 784!--- 785! Formats 786!--- 787 788end subroutine add_user_scalar_fields 789 790!=============================================================================== 791 792!> \brief add field defining a non-user solved scalar variable, 793!> with default options 794! 795!> It is recommended not to define variable names of more than 16 796!> characters, to get a clear execution log (some advanced writing 797!> levels take into account only the first 16 characters). 798! 799!------------------------------------------------------------------------------- 800! Arguments 801!______________________________________________________________________________. 802! mode name role ! 803!______________________________________________________________________________! 804!> \param[in] name field name 805!> \param[in] label field default label, or empty 806!> \param[out] iscal scalar number for defined field 807!_______________________________________________________________________________ 808 809subroutine add_model_scalar_field & 810 ( name, label, iscal ) 811 812!=============================================================================== 813! Module files 814!=============================================================================== 815 816use paramx 817use dimens 818use entsor 819use numvar 820use field 821 822!=============================================================================== 823 824implicit none 825 826! Arguments 827 828character(len=*), intent(in) :: name, label 829integer, intent(out) :: iscal 830 831! Local variables 832 833integer dim 834 835dim = 1 836 837call add_model_field(name, label, dim, iscal) 838 839return 840 841end subroutine add_model_scalar_field 842 843!=============================================================================== 844! 845!> \brief add field defining a non-user solved variable, 846!> with default options 847! 848!> It is recommended not to define variable names of more than 16 849!> characters, to get a clear execution log (some advanced writing 850!> levels take into account only the first 16 characters). 851! 852!------------------------------------------------------------------------------- 853! Arguments 854!______________________________________________________________________________. 855! mode name role ! 856!______________________________________________________________________________! 857!> \param[in] name field name 858!> \param[in] label field default label, or empty 859!> \param[in] dim field dimension 860!> \param[out] iscal variable number for defined field 861!_______________________________________________________________________________ 862 863subroutine add_model_field & 864 ( name, label, dim, iscal ) 865 866!=============================================================================== 867! Module files 868!=============================================================================== 869 870use paramx 871use dimens 872use entsor 873use numvar 874use field 875use cs_c_bindings 876 877!=============================================================================== 878 879implicit none 880 881! Arguments 882 883character(len=*), intent(in) :: name, label 884integer, intent(in) :: dim 885integer, intent(out) :: iscal 886 887! Local variables 888 889integer id 890integer location_id 891 892location_id = 1 ! variables defined on cells 893 894! Create field 895 896call variable_field_create(name, label, location_id, dim, id) 897 898call add_model_field_indexes(id, iscal) 899 900return 901 902end subroutine add_model_field 903 904!=============================================================================== 905! 906!> \brief add field indexes associated with a new non-user solved 907!> scalar variable, with default options 908! 909!------------------------------------------------------------------------------- 910! Arguments 911!______________________________________________________________________________. 912! mode name role ! 913!______________________________________________________________________________! 914!> \param[in] f_id field id 915!> \param[out] iscal variable number for defined field 916!_______________________________________________________________________________ 917 918subroutine add_model_field_indexes & 919 ( f_id, iscal ) 920 921!=============================================================================== 922! Module files 923!=============================================================================== 924 925use paramx 926use dimens 927use entsor 928use numvar 929use field 930 931!=============================================================================== 932 933implicit none 934 935! Arguments 936 937integer, intent(in) :: f_id 938integer, intent(out) :: iscal 939 940! Local variables 941 942integer dim, ivar, ii 943 944integer, save :: keyvar = -1 945integer, save :: keysca = -1 946 947! Get field dimension 948 949call field_get_dim(f_id, dim) 950 951if (keysca.lt.0) then 952 call field_get_key_id("scalar_id", keysca) 953 call field_get_key_id("variable_id", keyvar) 954endif 955 956ivar = nvar + 1 957nvar = nvar + dim 958nscal = nscal + 1 959iscal = nscaus + nscapp + 1 960nscapp = nscapp + 1 961 962! Check we have enough slots 963call fldvar_check_nvar 964call fldvar_check_nscapp 965 966isca(iscal) = ivar 967iscapp(nscapp) = iscal 968 969do ii = 1, dim 970 ivarfl(ivar + ii - 1) = f_id 971enddo 972 973call field_set_key_int(f_id, keyvar, ivar) 974call field_set_key_int(f_id, keysca, iscal) 975call init_var_cal_opt(f_id) 976 977return 978 979end subroutine add_model_field_indexes 980 981!=============================================================================== 982 983!> \brief Check nvarmx is sufficient for the required number of variables. 984 985!------------------------------------------------------------------------------- 986! Arguments 987!______________________________________________________________________________. 988! mode name role ! 989!______________________________________________________________________________! 990!_______________________________________________________________________________ 991 992subroutine fldvar_check_nvar 993 994!=============================================================================== 995! Module files 996!=============================================================================== 997 998use paramx 999use dimens 1000use entsor 1001use numvar 1002 1003!=============================================================================== 1004 1005implicit none 1006 1007! Arguments 1008 1009! Local variables 1010 1011if (nvar .gt. nvarmx) then 1012 write(nfecra,1000) nvar, nvarmx 1013 call csexit (1) 1014endif 1015 1016return 1017 1018!--- 1019! Formats 1020!--- 1021 1022 1000 format( & 1023'@ ',/,& 1024'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 1025'@ ',/,& 1026'@ @@ ERROR: STOP AT THE INITIAL DATA SETUP ',/,& 1027'@ ====== ',/,& 1028'@ NUMBER OF VARIABLES TOO LARGE ',/,& 1029'@ ',/,& 1030'@ The type of calculation defined ',/,& 1031'@ corresponds to a number of variables NVAR >= ', i10 ,/,& 1032'@ The maximum number of variables allowed ',/,& 1033'@ in paramx is NVARMX = ', i10 ,/,& 1034'@ ',/,& 1035'@ The calculation cannot be executed ',/,& 1036'@ ',/,& 1037'@ Verify parameters. ',/,& 1038'@ ',/,& 1039'@ If NVARMX is increased, the code must be reinstalled. ',/,& 1040'@ ',/,& 1041'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 1042'@ ',/) 1043 1044end subroutine fldvar_check_nvar 1045 1046!=============================================================================== 1047 1048!> \brief Initialize the given variable calculation option structure with 1049!> legacy values (iniini) allowing to later test user modification. 1050 1051!------------------------------------------------------------------------------- 1052! Arguments 1053!______________________________________________________________________________. 1054! mode name role ! 1055!______________________________________________________________________________! 1056!_______________________________________________________________________________ 1057 1058subroutine init_var_cal_opt & 1059 ( id ) 1060 1061!=============================================================================== 1062! Module files 1063!=============================================================================== 1064 1065use paramx 1066use dimens 1067use entsor 1068use numvar 1069use cs_c_bindings 1070use field 1071use optcal 1072 1073!=============================================================================== 1074 1075implicit none 1076 1077! Arguments 1078integer id 1079 1080! Local variables 1081type(var_cal_opt) :: vcopt 1082 1083! Most values set by default at in _var_cal_opt default; 1084! see cs_parameters.c 1085 1086call field_get_key_struct_var_cal_opt(id, vcopt) 1087 1088! Undefined values, may be modified by modini 1089vcopt%isstpc = -999 1090vcopt%nswrsm = -1 1091vcopt%imligr = -999 1092vcopt%thetav = -1.d0 1093vcopt%blencv = -1.d0 1094vcopt%epsilo = -1.d0 1095vcopt%epsrsm = -1.d0 1096vcopt%relaxv = -1.d0 1097 1098call field_set_key_struct_var_cal_opt(id, vcopt) 1099 1100return 1101 1102end subroutine init_var_cal_opt 1103 1104!=============================================================================== 1105 1106!> \brief Check nscamx is sufficient for the required number of model scalars. 1107! 1108!------------------------------------------------------------------------------- 1109! Arguments 1110!______________________________________________________________________________. 1111! mode name role ! 1112!______________________________________________________________________________! 1113!_______________________________________________________________________________ 1114 1115subroutine fldvar_check_nscapp 1116 1117!=============================================================================== 1118! Module files 1119!=============================================================================== 1120 1121use paramx 1122use dimens 1123use entsor 1124use numvar 1125 1126!=============================================================================== 1127 1128implicit none 1129 1130! Arguments 1131 1132! Local variables 1133 1134if ((nscaus+nscapp).gt.nscamx) then 1135 write(nfecra,1000) nscaus,nscamx,nscamx-nscaus 1136 call csexit (1) 1137endif 1138 1139return 1140 1141!--- 1142! Formats 1143!--- 1144 1145 1000 format( & 1146'@ ',/,& 1147'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 1148'@ ',/,& 1149'@ @@ ERROR: STOP AT THE INITIAL DATA SETUP ',/,& 1150'@ ====== ',/,& 1151'@ NUMBER OF SCALARS TOO LARGE ',/,& 1152'@ ',/,& 1153'@ The number of users scalars ',/,& 1154'@ requested is NSCAUS = ', i10 ,/,& 1155'@ The total number of scalars ',/,& 1156'@ allowed in paramx.h est NSCAMX = ', i10 ,/,& 1157'@ ',/,& 1158'@ The maximum value possible for NSCAPP ',/,& 1159'@ with the chosen model is NSCAMX-NSCAUS = ', i10 ,/,& 1160'@ ',/,& 1161'@ The calculation will not be run. ',/,& 1162'@ ',/,& 1163'@ Verify NSCAUS. ',/,& 1164'@ ',/,& 1165'@ If NSCAMX is increased, the code must be reinstalled. ',/,& 1166'@ ',/,& 1167'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',/,& 1168'@ ',/) 1169 1170end subroutine fldvar_check_nscapp 1171 1172!=============================================================================== 1173! C bindings (reverse) 1174!=============================================================================== 1175 1176!------------------------------------------------------------------------------- 1177!> \brief add field indexes associated with a new non-user solved 1178!> variable, with default options 1179! 1180!> \param[in] f_id field id 1181 1182!> \result scalar number for defined field 1183!------------------------------------------------------------------------------- 1184 1185function cs_c_add_model_field_indexes(f_id) result(iscal) & 1186 bind(C, name='cs_add_model_field_indexes') 1187 1188 use, intrinsic :: iso_c_binding 1189 use cs_c_bindings 1190 1191 implicit none 1192 1193 ! Arguments 1194 1195 integer(c_int), value :: f_id 1196 integer(c_int) :: iscal 1197 1198 ! Local variables 1199 1200 integer f_id0, iscal0 1201 1202 f_id0 = f_id 1203 1204 call add_model_field_indexes(f_id0, iscal0) 1205 1206 iscal = iscal0 1207 1208end function cs_c_add_model_field_indexes 1209 1210!--------------------------------------------------------------------------- 1211