Coverage for C:\src\imod-python\imod\msw\initial_conditions.py: 100%

1 import pathlib

2 import shutil

3

4 from imod.msw.fixed_format import VariableMetaData

5 from imod.msw.pkgbase import MetaSwapPackage

6

7

8 class InitialConditionsEquilibrium(MetaSwapPackage):

9 """

10 Use an equilibrium profile to initialize the model.

11

12 This class is responsible for the file `init_svat.inp`

13 """

14

15 _file_name = "init_svat.inp"

16 _option = "Equilibrium"

17 _metadata_dict: dict = {}

18

19 def __init__(self):

20 super().__init__()

21

22 def _render(self, file, *args):

23 file.write(self._option + "\n")

24

25

26 class InitialConditionsRootzonePressureHead(MetaSwapPackage):

27 """

28 Use the pF-value of the root zone pressure head as initial condition.

29

30 This class is responsible for the file `init_svat.inp`

31

32 Parameters

33 ----------

34 initial_pF: float

35 Initial pF value to be used for all soil columns.

36 """

37

38 _file_name = "init_svat.inp"

39 _option = "Rootzone_pF"

40 _metadata_dict = {

41 "initial_pF": VariableMetaData(6, 0.0, 6.0, float),

42 }

43

44 def __init__(self, initial_pF=2.2):

45 super().__init__()

46 self.dataset["initial_pF"] = initial_pF

47

48 def _render(self, file, *args):

49 file.write(self._option + "\n")

50

51 dataframe = self.dataset.assign_coords(index=[0]).to_dataframe()

52

53 self.write_dataframe_fixed_width(file, dataframe)

54

55

56 class InitialConditionsPercolation(MetaSwapPackage):

57 """

58 The precipitation intensity at the starting time (iybg, tdbg in

59 PARA_SIM.INP) is used for initializing the percolation flux in the profiles.

60 This type of initialization is normally done separately from the actual run,

61 using a specially prepared meteo-input file. After letting the model reach

62 near equilibrium by letting it run for a number of years, the saved state is

63 used for the initialization of subsequent runs.

64

65 This class is responsible for the file `init_svat.inp`

66 """

67

68 _file_name = "init_svat.inp"

69 _option = "MeteoInputP"

70 _metadata_dict: dict = {}

71

72 def __init__(self):

73 super().__init__()

74

75 def _render(self, file, *args):

76 file.write(self._option + "\n")

77

78

79 class InitialConditionsSavedState(MetaSwapPackage):

80 """

81 Use saved state of a previous MetaSWAP run as initial condition.

82

83 This class is responsible for the file `init_svat.inp`

84

85 Parameters

86 ----------

87 saved_state: Path or str

88 Path to a previously saved state. This file will be copied to

89 init_svat.inp.

90

91 """

92

93 _file_name = "init_svat.inp"

94 _option = "Saved_State"

95 _metadata_dict: dict = {}

96

97 def __init__(self, saved_state):

98 super().__init__()

99 self.saved_state = saved_state

100

101 def write(self, directory, *args):

102 directory = pathlib.Path(directory)

103 filename = directory / self._file_name

104

105 shutil.copyfile(self.saved_state, filename)