Coverage for pySDC / projects / StroemungsRaum / run_Navier_Stokes_equations_monolithic_FEniCS.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-14 15:19 +0000

1from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI 

2from pySDC.projects.StroemungsRaum.problem_classes.NavierStokes_2D_monolithic_FEniCS import fenics_NSE_2D_Monolithic 

3from pySDC.projects.StroemungsRaum.sweepers.generic_implicit_mass import generic_implicit_mass 

4 

5 

6def setup(t0=0): 

7 """ 

8 Helper routine to set up parameters 

9 

10 Args: 

11 t0: float, 

12 initial time 

13 

14 Returns: 

15 description: dict, 

16 pySDC description dictionary containing problem and method parameters. 

17 controller_params: dict, 

18 Parameters for the pySDC controller. 

19 """ 

20 # time step size 

21 dt = 1 / 100 

22 

23 # initialize level parameters 

24 level_params = dict() 

25 level_params['restol'] = 1e-10 

26 level_params['dt'] = dt 

27 

28 # initialize step parameters 

29 step_params = dict() 

30 step_params['maxiter'] = 10 

31 

32 # initialize sweeper parameters 

33 sweeper_params = dict() 

34 sweeper_params['quad_type'] = 'RADAU-RIGHT' 

35 sweeper_params['num_nodes'] = 2 

36 sweeper_params['QI'] = 'LU' 

37 

38 # initialize problem parameters 

39 problem_params = dict() 

40 problem_params['nu'] = 0.001 

41 problem_params['t0'] = t0 

42 problem_params['order'] = 2 

43 problem_params['Sol_tol'] = 1e-10 

44 

45 # initialize controller parameters 

46 controller_params = dict() 

47 controller_params['logger_level'] = 20 

48 

49 # Fill description dictionary 

50 description = dict() 

51 description['problem_class'] = fenics_NSE_2D_Monolithic 

52 description['sweeper_class'] = generic_implicit_mass 

53 description['problem_params'] = problem_params 

54 description['sweeper_params'] = sweeper_params 

55 description['level_params'] = level_params 

56 description['step_params'] = step_params 

57 

58 return description, controller_params 

59 

60 

61def run_simulation(description, controller_params, Tend): 

62 """ 

63 Run the time integration for the 2D Navier-Stokes equations. 

64 

65 Args: 

66 description: dict, 

67 pySDC problem and method description. 

68 controller_params: dict, 

69 Parameters for the pySDC controller. 

70 Tend: float, 

71 Final simulation time. 

72 

73 Returns: 

74 P: problem instance, 

75 Problem instance containing the final solution and other problem-related information. 

76 stats: dict, 

77 collected runtime statistics, 

78 uend: FEniCS function, 

79 Final solution at time Tend. 

80 """ 

81 # get initial time from description 

82 t0 = description['problem_params']['t0'] 

83 

84 # quickly generate block of steps 

85 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description) 

86 

87 # get initial values on finest level 

88 P = controller.MS[0].levels[0].prob 

89 uinit = P.u_exact(t0) 

90 

91 # call main function to get things done... 

92 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend) 

93 

94 return P, stats, uend 

95 

96 

97if __name__ == "__main__": 

98 

99 t0 = 3.125e-04 # the FEATFLOW data initial time 

100 Tend = 8.0 

101 

102 # run the setup to get description and controller parameters 

103 description, controller_params = setup(t0=t0) 

104 

105 # run the simulation and get the problem, stats and final solution 

106 prob, stats, uend = run_simulation(description, controller_params, Tend)