version 0.5.0
block_reader.f90
1 !This file is part of Notus 0.5.0
2 
3 !Copyright Bordeaux-INP, Université de Bordeaux, CNRS
4 !
5 !Contributors:
6 !Antoine Lemoine, 19-10-2016, antoine.lemoine@bordeaux-inp.fr
7 
8 !This software is a computer program whose purpose is to simulate fluid flows.
9 
10 !This software is governed by the CeCILL license under French law and
11 !abiding by the rules of distribution of free software. You can use,
12 !modify and/ or redistribute the software under the terms of the CeCILL
13 !license as circulated by CEA, CNRS and INRIA at the following URL
14 !"http://www.cecill.info".
15 
16 !As a counterpart to the access to the source code and rights to copy,
17 !modify and redistribute granted by the license, users are provided only
18 !with a limited warranty and the software's author, the holder of the
19 !economic rights, and the successive licensors have only limited
20 !liability.
21 
22 !In this respect, the user's attention is drawn to the risks associated
23 !with loading, using, modifying and/or developing or reproducing the
24 !software by the user in light of its specific status of free software,
25 !that may mean that it is complicated to manipulate, and that also
26 !therefore means that it is reserved for developers and experienced
27 !professionals having in-depth computer knowledge. Users are therefore
28 !encouraged to load and test the software's suitability as regards their
29 !requirements in conditions enabling the security of their systems and/or
30 !data to be ensured and, more generally, to use and operate it in the
31 !same conditions as regards security.
32 
33 !The fact that you are presently reading this means that you have had
34 !knowledge of the CeCILL license and that you accept its terms.
35 
36 module mod_ui_parse_system
37  use mod_nts_language
38  use mod_nts_parse_block
39  use mod_nts_parse_path
40  use mod_ui_read_solver
41  use mod_ui_system_state
42  implicit none
43 
44 contains
45 
46  logical recursive function ui_parse_system(parser, tok, keyword_id) result(keyword_id_found)
47  use enum_test_case
49  use variables_core
50  use variables_output, only : output_directory, case_directory
51  use variables_test_case, only : test_case, test_case_switch
53 
54  type(t_parser) :: parser
55  type(t_token), intent(in) :: tok
56  integer, intent(in) :: keyword_id
57 
58  type(t_token) :: tok_brace, tok_test_case
59  type(t_token) :: tok_next
60 
61  keyword_id_found = .true.
62 
63  select case(keyword_id)
64  case(kw_output_directory)
65  output_directory = simplify_path(case_directory//'/'//nts_evaluate_string_expression(parser))
66  call nts_expect(parser, tk_semicolon)
67 
68  case(kw_measure_cpu_time)
69  is_cpu_time_measuring = .true.
70  call nts_expect(parser, tk_semicolon)
71 
72  case(kw_measure_time_iteration_cpu_time)
73  is_cpu_time_time_iteration_measuring = .true.
74  call nts_expect(parser, tk_semicolon)
75 
76  case(kw_write_cpu_time)
77  is_cpu_time_writing = .true.
78  call nts_expect(parser, tk_semicolon)
79 
80  case(kw_enable_checkpoint)
81  is_checkpoint = nts_evaluate_boolean_expression(parser)
82  call nts_expect(parser, tk_semicolon)
83 
84  case(kw_checkpoint_frequency)
85  checkpoint_frequency = nts_evaluate_integer_expression(parser)
86  call nts_expect(parser, tk_semicolon)
87 
88  case(kw_checkpoint_metric)
89  call nts_get_keyword(parser, tok_next)
90 
91  select case(tok_next%keyword_id)
92  case(kw_cpu_time)
93  checkpoint_metric = checkpoint_metric_cpu_time
94  case(kw_time_iteration)
95  checkpoint_metric = checkpoint_metric_time_iteration
96  case default
97  call parser%throw_error(tok, "checkpoint_metric expect 'checkpoint_metric_cpu_time' or 'checkpoint_metric_time_iteration'")
98  end select
99 
100  case(kw_enable_initial_conditions_checkpoint)
101  is_initial_conditions_checkpoint = nts_evaluate_boolean_expression(parser)
102  call nts_expect(parser, tk_semicolon)
103 
104  case(kw_enable_last_iteration_checkpoint)
105  is_last_iteration_checkpoint = nts_evaluate_boolean_expression(parser)
106  call nts_expect(parser, tk_semicolon)
107 
108  case(kw_checkpoint_max_files)
109  checkpoint_n_files = nts_evaluate_integer_expression(parser)
110  call nts_expect(parser, tk_semicolon)
111 
112  if (checkpoint_n_files < 2) call parser%throw_error(tok, "'checkpoint_max_files' must be ≥ 2")
113 
114  case(kw_checkpoint_name)
115  checkpoint_filename = nts_evaluate_string_expression(parser)
116  call nts_expect(parser, tk_semicolon)
117 
118  ui_is_checkpoint_file_read = .true.
119 
120  case(kw_restart)
121  restart_filename = nts_parse_path(parser)
122  call nts_expect(parser, tk_semicolon)
123 
124  is_restart = .true.
125 
126  case(kw_test_case)
127  call nts_peek(parser, tok_test_case)
128 
129  if (.not. nts_next_token(parser, tk_keyword)) then
130  call parser%throw_error(tok, "test case keyword expected (ie. tc_poiseuille) but got a '"// &
131  trim(token_id_to_string(tok_test_case%kind))//"' instead")
132  end if
133 
134  select case(tok_test_case%keyword_id)
135  case(kw_tc_channel_3d)
136  test_case = test_case_channel_3d
137  case(kw_tc_backward_facing_step_axisymmetric)
138  test_case = test_case_ibm_backward_facing_step_axisymmetric
139  case(kw_tc_lagrangian_particles)
140  test_case = test_case_lagrangian_particles
141  case(kw_tc_linear_system_test)
142  test_case = test_case_linear_system_test
143  call nts_peek(parser, tok_brace)
144  call nts_expect(parser, tk_left_brace)
145  call parser%new_scope(tok_brace)
146  call nts_parse_block(parser, ui_test_case_linear_system_test)
147  case(kw_tc_species_transport)
148  test_case = test_case_species_transport
149  case(kw_tc_plane_turbulent_channel)
150  test_case = test_case_plane_turbulent_channel
151  case(kw_tc_poiseuille_rayleigh_benard)
152  test_case = test_case_poiseuille_rayleigh_benard
153  case(kw_tc_poiseuille_viscosity)
154  test_case = test_case_poiseuille_viscosity
155  case(kw_tc_solitary_wave_periodic)
156  test_case = test_case_solitary_wave_periodic
157  case(kw_tc_solitary_wave_wall)
158  test_case = test_case_solitary_wave_wall
159  case(kw_tc_standing_wave)
160  test_case = test_case_standing_wave
161  case(kw_tc_thermal_contact_resistance)
162  test_case = test_case_thermal_contact_resistance
163  test_case_switch = nts_evaluate_integer_expression(parser)
164  case(kw_tc_bubble_rise)
165  test_case = test_case_bubble_rise
166  case(kw_tc_jet_buckling)
167  test_case = test_case_jet_buckling
168  case default
169  call parser%throw_error(tok_test_case, "keyword '"//ui_keywords(tok_test_case%keyword_id)%name//&
170  "' is not a valid test case keyword")
171  end select
172 
173  call nts_expect(parser, tk_semicolon)
174 
175  is_test_case_mode = .true.
176 
177  case(kw_test_case_switch)
178  test_case_switch = nts_evaluate_integer_expression(parser)
179 
180  case default
181  call parser%throw_error(tok, "invalid keyword '"//parser%lex%keywords(tok%keyword_id)%name//"' in system block")
182  keyword_id_found = .false.
183  end select
184  end function ui_parse_system
185 
186  ! This routine would be preferably be located with the corresponding test case.
187  logical recursive function ui_test_case_linear_system_test(parser, tok, keyword_id) result(keyword_id_found)
188  use variables_test_case_linear_system_test
189 
190  type(t_parser) :: parser
191  type(t_token), intent(in) :: tok
192  integer, intent(in) :: keyword_id
193 
194  character(len=:), allocatable :: stl_type
195 
196  keyword_id_found = .true.
197 
198  select case(keyword_id)
199  case(kw_stencil_type)
200  stl_type = nts_evaluate_string_expression(parser)
201  select case (stl_type)
202  case ("1_star")
203  ls_test_stencil_type = stencil_1_star
204  case ("1_square")
205  ls_test_stencil_type = stencil_1_square
206  case ("2_star")
207  ls_test_stencil_type = stencil_2_star
208  case ("2_square")
209  ls_test_stencil_type = stencil_2_square
210  case default
211  call parser%throw_error(tok, "unknown stencil type: "//stl_type)
212  end select
213  call nts_expect(parser, tk_semicolon)
214 
215  case(kw_solver)
216  call ui_read_solver(parser, ls_test_solver)
217 
218  case default
219  keyword_id_found = .false.
220  end select
221  end function ui_test_case_linear_system_test
222 
223 end module mod_ui_parse_system
Declaration variables associated to checkpoint/restart.
Definition: variables.f90:38
Variables for CPU time measurement in different part of the code.
Definition: variables.f90:39
recursive logical function nts_evaluate_boolean_expression(parser)
Evaluate a boolean expression.
Define variables of the core library.
recursive integer function nts_evaluate_integer_expression(parser)
Evaluate an integer expression.
recursive subroutine nts_parse_block(parser, block_reader)
Read a new block.
Definition: parse_block.f90:72
recursive character(len=:) function, allocatable nts_evaluate_string_expression(parser)
Evaluate a string precision expression.
Define variables associated to outputs.
Define variables associated to test cases setup.
Definition: variables.f90:39
Test case identifiers.
Definition: enum.f90:42