wolfhece 2.1.99__py3-none-any.whl → 2.1.101__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. wolfhece/PyDraw.py +220 -29
  2. wolfhece/PyGui.py +1039 -53
  3. wolfhece/PyVertexvectors.py +2 -2
  4. wolfhece/Results2DGPU.py +37 -13
  5. wolfhece/acceptability/Parallels.py +2 -2
  6. wolfhece/acceptability/_add_path.py +23 -0
  7. wolfhece/acceptability/acceptability.py +594 -563
  8. wolfhece/acceptability/acceptability_gui.py +564 -331
  9. wolfhece/acceptability/cli.py +307 -120
  10. wolfhece/acceptability/func.py +1754 -1597
  11. wolfhece/apps/version.py +1 -1
  12. wolfhece/bernoulli/losses.py +76 -23
  13. wolfhece/bernoulli/losses_jax.py +143 -0
  14. wolfhece/bernoulli/pipe.py +7 -2
  15. wolfhece/gpuview.py +4 -1
  16. wolfhece/libs/__init__.py +11 -10
  17. wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
  18. wolfhece/math_parser/__init__.py +4 -4
  19. wolfhece/math_parser/calculator.py +51 -9
  20. wolfhece/mesh2d/bc_manager.py +25 -2
  21. wolfhece/mesh2d/gpu_2d.py +644 -0
  22. wolfhece/mesh2d/simple_2d.py +2817 -0
  23. wolfhece/mesh2d/wolf2dprev.py +5 -2
  24. wolfhece/pidcontroller.py +131 -0
  25. wolfhece/pywalous.py +7 -7
  26. wolfhece/scenario/config_manager.py +98 -21
  27. wolfhece/wolf_array.py +391 -176
  28. wolfhece/wolf_vrt.py +108 -7
  29. wolfhece/wolfresults_2D.py +113 -6
  30. wolfhece/xyz_file.py +91 -51
  31. {wolfhece-2.1.99.dist-info → wolfhece-2.1.101.dist-info}/METADATA +3 -1
  32. {wolfhece-2.1.99.dist-info → wolfhece-2.1.101.dist-info}/RECORD +35 -30
  33. {wolfhece-2.1.99.dist-info → wolfhece-2.1.101.dist-info}/WHEEL +1 -1
  34. {wolfhece-2.1.99.dist-info → wolfhece-2.1.101.dist-info}/entry_points.txt +0 -0
  35. {wolfhece-2.1.99.dist-info → wolfhece-2.1.101.dist-info}/top_level.txt +0 -0
wolfhece/PyGui.py CHANGED
@@ -68,6 +68,9 @@ try:
68
68
  from .picc import Picc_data, Cadaster_data
69
69
  from .wolf_zi_db import ZI_Databse_Elt, PlansTerrier
70
70
  from .CpGrid import CpGrid
71
+ from .mesh2d.gpu_2d import Sim_2D_GPU
72
+ from .mesh2d.wolf2dprev import prev_sim2D
73
+ from .mesh2d.cst_2D_boundary_conditions import BCType_2D, BCType_2D_OO, BCType_2D_GPU, Direction
71
74
  except ImportError as e:
72
75
  print(f"Import Error: {e} - RatingCurve, mesh2d, Results2DGPU, PyGuiHydrology, RatingCurve, hydrology, PyParams, picc, wolf_zi_db, CpGrid")
73
76
  print("Please install the required modules using 'pip install -r requirements.txt'")
@@ -208,44 +211,44 @@ class MapManager(GenMapManager):
208
211
 
209
212
  self.mapviewer.menu_walous()
210
213
 
211
- class GPU2DModel(GenMapManager):
214
+ # class GPU2DModel(GenMapManager):
212
215
 
213
- mydir:str
214
- files_results_array:dict
215
- mybed:WolfArray
216
+ # mydir:str
217
+ # files_results_array:dict
218
+ # mybed:WolfArray
216
219
 
217
- def __init__(self,dir:str='', *args, **kw):
218
- super(GPU2DModel, self).__init__(*args, **kw)
220
+ # def __init__(self,dir:str='', *args, **kw):
221
+ # super(GPU2DModel, self).__init__(*args, **kw)
219
222
 
220
- self.setup_mapviewer(title='Wolf GPU 2D')
223
+ # self.setup_mapviewer(title='Wolf GPU 2D')
221
224
 
222
- if dir=='':
223
- idir=wx.DirDialog(None,"Choose Directory")
224
- if idir.ShowModal() == wx.ID_CANCEL:
225
- return
226
- self.mydir =idir.GetPath()
227
- else:
228
- self.mydir=normpath(dir)
225
+ # if dir=='':
226
+ # idir=wx.DirDialog(None,"Choose Directory")
227
+ # if idir.ShowModal() == wx.ID_CANCEL:
228
+ # return
229
+ # self.mydir =idir.GetPath()
230
+ # else:
231
+ # self.mydir=normpath(dir)
229
232
 
230
- ext=['.top','.frott','.cls_pos','.cls_Z','.hbin','.zbin','.srcq']
231
- for myext in ext:
232
- if exists(self.mydir+'//simul'+myext):
233
+ # ext=['.top','.frott','.cls_pos','.cls_Z','.hbin','.zbin','.srcq']
234
+ # for myext in ext:
235
+ # if exists(self.mydir+'//simul'+myext):
233
236
 
234
- self.mapviewer.add_object(which='array',
235
- filename=self.mydir+'//simul'+myext,
236
- id=myext,
237
- ToCheck=False)
237
+ # self.mapviewer.add_object(which='array',
238
+ # filename=self.mydir+'//simul'+myext,
239
+ # id=myext,
240
+ # ToCheck=False)
238
241
 
239
- self.mybed=WolfArray(self.mydir +'//simul.top')
240
- self.result = wolfres2DGPU(self.mydir,self.mybed,parent=self)
242
+ # self.mybed=WolfArray(self.mydir +'//simul.top')
243
+ # self.result = wolfres2DGPU(self.mydir,self.mybed,parent=self)
241
244
 
242
- self.mapviewer.add_object(which='array',
243
- newobj=self.result,
244
- id='res1',
245
- ToCheck=False)
245
+ # self.mapviewer.add_object(which='array',
246
+ # newobj=self.result,
247
+ # id='res1',
248
+ # ToCheck=False)
246
249
 
247
- self.mapviewer.findminmax(True)
248
- self.mapviewer.Autoscale(False)
250
+ # self.mapviewer.findminmax(True)
251
+ # self.mapviewer.Autoscale(False)
249
252
 
250
253
  class HydrologyModel(GenMapManager):
251
254
 
@@ -451,15 +454,15 @@ class Wolf2DPartArrays():
451
454
 
452
455
  self_btn_addfile = wx.Button(self._panel, label=_("Add file"))
453
456
  self_btn_addfile.Bind(wx.EVT_BUTTON, self.on_addfile)
454
- self_btn_addfile.SetToolTipString(_("Add a file to the selected part array"))
457
+ self_btn_addfile.SetToolTip(_("Add a file to the selected part array"))
455
458
 
456
459
  self_btn_delfile = wx.Button(self._panel, label=_("Delete file"))
457
460
  self_btn_delfile.Bind(wx.EVT_BUTTON, self.on_delfile)
458
- self_btn_delfile.SetToolTipString(_("Delete the selected file from the selected part array"))
461
+ self_btn_delfile.SetToolTip(_("Delete the selected file from the selected part array"))
459
462
 
460
463
  self._btn_apply = wx.Button(self._panel, label=_("Apply"))
461
464
  self._btn_apply.Bind(wx.EVT_BUTTON, self.on_apply)
462
- self._btn_apply.SetToolTipString(_("Apply the values in the grid to the in-memory simulation (without writing to disk)"))
465
+ self._btn_apply.SetToolTip(_("Apply the values in the grid to the in-memory simulation (without writing to disk)"))
463
466
 
464
467
  self._btn_toviewer = wx.Button(self._panel, label=_("To viewer"))
465
468
  self._btn_toviewer.Bind(wx.EVT_BUTTON, self.on_toviewer)
@@ -628,35 +631,35 @@ class Wolf2DInfiltration():
628
631
  sizer_btns = wx.BoxSizer(wx.HORIZONTAL)
629
632
 
630
633
  self._grid = CpGrid(self._panel,wx.ID_ANY, wx.WANTS_CHARS)
631
- self._grid.CreateGrid(10, 3)
634
+ self._grid.CreateGrid(self.sim.infiltration.nb_steps, self.sim.infiltration.nb_zones)
632
635
 
633
636
  self._btn_apply = wx.Button(self._panel, label=_("Apply"))
634
637
  self._btn_apply.Bind(wx.EVT_BUTTON, self.on_apply)
635
- self._btn_apply.SetToolTipString(_("Apply the values in the grid to the in-memory simulation (without writing to disk)"))
638
+ self._btn_apply.SetToolTip(_("Apply the values in the grid to the in-memory simulation (without writing to disk)"))
636
639
 
637
640
  self._btn_check = wx.Button(self._panel, label=_("Check"))
638
641
  self._btn_check.Bind(wx.EVT_BUTTON, self.on_check)
639
- self._btn_check.SetToolTipString(_("Check the consistency of the in-memory simulation (.fil and .inf files)"))
642
+ self._btn_check.SetToolTip(_("Check the consistency of the in-memory simulation (.fil and .inf files)"))
640
643
 
641
644
  self._btn_reload = wx.Button(self._panel, label=_("Reload"))
642
645
  self._btn_reload.Bind(wx.EVT_BUTTON, self.on_reload)
643
- self._btn_reload.SetToolTipString(_("Reload the values from the in-memory simulation"))
646
+ self._btn_reload.SetToolTip(_("Reload the values from the in-memory simulation"))
644
647
 
645
648
  self._btn_plot = wx.Button(self._panel, label=_("Plot"))
646
649
  self._btn_plot.Bind(wx.EVT_BUTTON, self.on_plot)
647
- self._btn_plot.SetToolTipString(_("Plot the discharges"))
650
+ self._btn_plot.SetToolTip(_("Plot the discharges"))
648
651
 
649
652
  self._btn_plus = wx.Button(self._panel, label="+")
650
653
  self._btn_plus.Bind(wx.EVT_BUTTON, self.on_plus)
651
- self._btn_plus.SetToolTipString(_("Add zone(s) or step(s)"))
654
+ self._btn_plus.SetToolTip(_("Add zone(s) or step(s)"))
652
655
 
653
656
  self._btn_minus = wx.Button(self._panel, label="-")
654
657
  self._btn_minus.Bind(wx.EVT_BUTTON, self.on_minus)
655
- self._btn_minus.SetToolTipString(_("Remove zone(s) or step(s)"))
658
+ self._btn_minus.SetToolTip(_("Remove zone(s) or step(s)"))
656
659
 
657
660
  self._btn_adjust = wx.Button(self._panel, label=_("Adjust"))
658
661
  self._btn_adjust.Bind(wx.EVT_BUTTON, self.on_adjust)
659
- self._btn_adjust.SetToolTipString(_("Adjust the number of rows and columns of the grid"))
662
+ self._btn_adjust.SetToolTip(_("Adjust the number of rows and columns of the grid"))
660
663
 
661
664
  sizer_btns.Add(self._btn_apply, 2, wx.EXPAND | wx.ALL, 2)
662
665
  sizer_btns.Add(self._btn_check, 2, wx.EXPAND | wx.ALL, 2)
@@ -687,15 +690,18 @@ class Wolf2DInfiltration():
687
690
  while self._grid.GetCellValue(0, j_max) != "" and j_max < self._grid.GetNumberCols()-1:
688
691
  j_max += 1
689
692
 
690
- chronos = np.zeros((i_max, j_max), dtype=np.float64)
693
+ chronos = np.zeros((i_max, j_max+1), dtype=np.float64)
691
694
 
692
- for i in range(i_max+1):
693
- for j in range(j_max+1):
694
- chronos[i,j] = self._grid.GetCellValue(i, j)
695
+ try:
696
+ for i in range(i_max):
697
+ for j in range(j_max+1):
698
+ chronos[i,j] = self._grid.GetCellValue(i, j)
699
+ except:
700
+ logging.error("Error converting the grid to Float")
701
+ return
695
702
 
696
703
  self.sim.infiltration.infiltrations_chronology = chronos
697
- self._btn_check(1)
698
-
704
+ self.on_check(1)
699
705
 
700
706
  def _fillgrid(self):
701
707
  """ Fill the CpGrid """
@@ -720,7 +726,7 @@ class Wolf2DInfiltration():
720
726
  grid.ClearGrid()
721
727
 
722
728
  grid.SetColLabelValue(0, _("Time"))
723
- for i in range(1,nb_zones+1):
729
+ for i in range(1,max(nb_zones, grid.GetNumberCols())+1):
724
730
  grid.SetColLabelValue(i, f"Zone {i}")
725
731
 
726
732
  for i in range(nb_steps):
@@ -788,11 +794,11 @@ class Wolf2DInfiltration():
788
794
 
789
795
  dlg.Destroy()
790
796
 
791
- self._fillgrid()
792
-
793
797
  self._grid.DeleteCols(nb_zones)
794
798
  self._grid.DeleteRows(nb_steps)
795
799
 
800
+ self._fillgrid()
801
+
796
802
  self._btn_check.SetBackgroundColour(wx.NullColour)
797
803
 
798
804
  def on_check(self, event):
@@ -958,7 +964,8 @@ class Wolf2DModel(GenMapManager):
958
964
  logging.info(_('Creating GUI'))
959
965
 
960
966
  # Initilisation d'une simulation 2D sur base des fichiers
961
- self.sim:prev_sim2D = prev_sim2D(self.filenamegen)
967
+ self.sim:prev_sim2D
968
+ self.sim = prev_sim2D(self.filenamegen)
962
969
 
963
970
  # Liste des objets à ajouter au GUI
964
971
  self.fines_array=[]
@@ -1177,7 +1184,7 @@ class Wolf2DModel(GenMapManager):
1177
1184
  def mimic_mask(self, source:WolfArray):
1178
1185
  """ Copy the mask of the source array to all arrays in the model. """
1179
1186
 
1180
- self.som.mime_mask(source)
1187
+ self.sim.mimic_mask(source)
1181
1188
 
1182
1189
  def show_properties(self):
1183
1190
  """
@@ -1188,6 +1195,7 @@ class Wolf2DModel(GenMapManager):
1188
1195
 
1189
1196
  if self._prop_frame is not None:
1190
1197
  self._prop_frame.CenterOnScreen()
1198
+ self._prop_frame.Iconize(False)
1191
1199
  self._prop_frame.Show()
1192
1200
  return
1193
1201
 
@@ -1702,7 +1710,7 @@ class Wolf2DModel(GenMapManager):
1702
1710
 
1703
1711
  wizard_text = self.sim.get_wizard_text()
1704
1712
 
1705
- self.wizard = Wizard(None, -1, _('Wizard Multiblocks simulation'))
1713
+ self.wizard = Wizard(None, -1, _('Wizard GPU simulation'))
1706
1714
 
1707
1715
  self.wizard.SetPageSize((400, 300))
1708
1716
 
@@ -1869,7 +1877,7 @@ class Wolf2DModel(GenMapManager):
1869
1877
  logging.error(_('Invalid fine resolution'))
1870
1878
  return
1871
1879
 
1872
- self.sim.set_mesh_fine_size(float(dx), float(dy))
1880
+ self.sim.set_mesh_fine_size(floatdx, floatdy)
1873
1881
  self._show_glob_properties()
1874
1882
  except:
1875
1883
  logging.error(_('Invalid fine resolution'))
@@ -2753,3 +2761,981 @@ class Wolf2DModel(GenMapManager):
2753
2761
  """Lecture de la matrice nap sur le maillage fin"""
2754
2762
 
2755
2763
  return self.sim.read_fine_array('.napbin')
2764
+
2765
+ class Wolf2DGPUModel(GenMapManager):
2766
+
2767
+ def __init__(self, *args, dir:str='', **kw):
2768
+ """
2769
+ :param dir: directory containing the simulation
2770
+
2771
+ self.wx_exists : If True, then this model will connect itself to the GUI.
2772
+ If False, the model will stand alone (so you can use it outside
2773
+ of the GUI).
2774
+ """
2775
+
2776
+ super(Wolf2DGPUModel, self).__init__(*args, **kw)
2777
+
2778
+ self._wp = None
2779
+ self.dir = ''
2780
+ self._prop_frame = None
2781
+ self._sim:Sim_2D_GPU = None
2782
+
2783
+ # Liste des objets à ajouter au GUI
2784
+ self.arrays={}
2785
+
2786
+ # Gauging stations - SPW
2787
+ self.SPWstations = SPWMIGaugingStations()
2788
+ self.DCENNstations = SPWDCENNGaugingStations()
2789
+
2790
+ if dir != '':
2791
+ # Either a directory or a file "/_/_/_/dir/simul" for example.
2792
+
2793
+ assert exists(dir) or dirname(dir), f"'{dir}' does not exists"
2794
+
2795
+ if dir=='':
2796
+ if self.wx_exists:
2797
+ # Propose a dialog window to choose the directory
2798
+
2799
+ idir=wx.DirDialog(None,"Choose Directory -- Abort for a new model from scratch", style=wx.DD_DEFAULT_STYLE)
2800
+ ret = idir.ShowModal()
2801
+
2802
+ dir =Path(idir.GetPath())
2803
+ if 'simul_gpu_results' in dir.name:
2804
+ dir = dir.parent
2805
+
2806
+ if ret == wx.ID_CANCEL or not (dir / 'parameters.json').exists():
2807
+ self.setup_mapviewer(title='Blank 2D model',wolfparent=self)
2808
+ self.mapviewer.findminmax(True)
2809
+ self.mapviewer.Autoscale(False)
2810
+ self.mapviewer.menu_sim2DGPU()
2811
+ if ret == wx.ID_CANCEL:
2812
+ self._sim = Sim_2D_GPU()
2813
+ else:
2814
+ self._sim = Sim_2D_GPU(idir.GetPath())
2815
+ self.show_properties()
2816
+ if self.wx_exists:
2817
+ self.mapviewer.add_object(which='other',newobj=self.SPWstations,ToCheck=False,id='SPW-MI stations')
2818
+ self.mapviewer.add_object(which='other',newobj=self.DCENNstations,ToCheck=False,id='SPW-DCENN stations')
2819
+ idir.Destroy()
2820
+ return
2821
+ else:
2822
+ return
2823
+
2824
+ self.dir = dir
2825
+ idir.Destroy()
2826
+ else:
2827
+ self.dir=Path(normpath(dir))
2828
+
2829
+ if 'simul_gpu_results' in self.dir:
2830
+ self.dir = self.dir.parent
2831
+
2832
+ try:
2833
+ logging.info(_(f'Simulation directory is : {self.dir}'))
2834
+ logging.info(_('Creating GUI'))
2835
+
2836
+ self._sim = Sim_2D_GPU(self.dir)
2837
+
2838
+ if self.wx_exists:
2839
+
2840
+ self.setup_mapviewer(title='2D GPU model : '+ str(self.dir), wolfparent=self)
2841
+ self.show_properties()
2842
+
2843
+ if self.sim._sim is not None:
2844
+ self._btn_fromarray.Enable(False)
2845
+ self._btn_fromfootprint.Enable(False)
2846
+ self._btn_fromvector.Enable(False)
2847
+ self._btn_magnetic_grid.Enable(False)
2848
+
2849
+ self._btn_add_arrays2viewer.SetLabel(_('Reload arrays'))
2850
+
2851
+ logging.info(_('Treating arrays'))
2852
+
2853
+ self._add_arrays_to_mapviewer()
2854
+ self._add_vectors_to_mapviewer()
2855
+
2856
+ logging.info(_('Zooming'))
2857
+ self.mapviewer.findminmax(True)
2858
+ self.mapviewer.Autoscale(False)
2859
+
2860
+ self.show_properties()
2861
+
2862
+ if self.wx_exists:
2863
+ self.mapviewer.add_object(which='other',newobj=self.SPWstations,ToCheck=False,id='SPW-MI stations')
2864
+ self.mapviewer.add_object(which='other',newobj=self.DCENNstations,ToCheck=False,id='SPW-DCENN stations')
2865
+
2866
+ logging.info(_('Adapting menu'))
2867
+ self.mapviewer.menu_sim2DGPU()
2868
+
2869
+ logging.info(_('Verifying files'))
2870
+ self._sim.verify_files()
2871
+
2872
+ logging.info(_('Model loaded !!'))
2873
+
2874
+ except Exception as ex:
2875
+ logging.error(str(ex), exc_info=True)
2876
+
2877
+ @property
2878
+ def sim(self):
2879
+ """ Alias """
2880
+
2881
+ return self._sim
2882
+
2883
+ def _add_arrays_to_mapviewer(self, force_reload:bool=False):
2884
+ """
2885
+ Add the arrays to the mapviewer
2886
+ """
2887
+
2888
+ logging.info(_('Adding arrays to mapviewer'))
2889
+
2890
+ arrays_in_viewer = self.mapviewer.get_list_objects(draw_type.ARRAYS, checked_state=None)
2891
+
2892
+ if force_reload:
2893
+ self._sim.reload_all()
2894
+ for cur in self.arrays.values():
2895
+ cur.reset_plot()
2896
+ # self.mapviewer.Refresh()
2897
+ else:
2898
+
2899
+ self.arrays = self._sim.get_arraysasdict()
2900
+
2901
+ for array in self.arrays.values():
2902
+ if array.loaded:
2903
+ if array.idx not in [cur.idx for cur in arrays_in_viewer]:
2904
+ self.mapviewer.add_object(which='array', newobj=array, ToCheck=False, id= array.idx)
2905
+
2906
+
2907
+ def _add_vectors_to_mapviewer(self):
2908
+ """
2909
+ Add the vectors to the mapviewer
2910
+ """
2911
+
2912
+ logging.info(_('Adding vectors to mapviewer'))
2913
+ pass
2914
+
2915
+ def show_properties_sim(self):
2916
+ """
2917
+ Show the properties of the model
2918
+ """
2919
+
2920
+ logging.info(_('Opening parameters for simulation {}'.format(self.dir)))
2921
+
2922
+ self._wp:Wolf_Param
2923
+ self._wp = self._sim.sim.to_wolfparam()
2924
+ self._wp.show_in_active_if_default = True
2925
+ self._wp.set_callbacks(self._callbackwp, self._callbackwp_destroy)
2926
+ self._wp._set_gui(title='Parameters for simulation {}'.format(self.dir), toShow=False)
2927
+ self._wp.hide_selected_buttons()
2928
+ self._wp.Show()
2929
+
2930
+ def _callbackwp(self):
2931
+ """ Callback for wolfparam """
2932
+
2933
+ if self._wp is not None:
2934
+ try:
2935
+ if self._wp.Shown:
2936
+ self._sim.sim.from_wolfparam(self._wp)
2937
+ self._sim.sim._save_json()
2938
+ except Exception as e:
2939
+ self._wp = None
2940
+ logging.debug(_('Error while saving parameters for simulation {}'.format(self._sim.sim.path.name)))
2941
+ logging.debug(str(e))
2942
+
2943
+ def _callbackwp_destroy(self):
2944
+ """ Callback for wolfparam """
2945
+
2946
+ if self._wp is not None:
2947
+ try:
2948
+ if self._wp.Shown:
2949
+ self._sim.sim.from_wolfparam(self._wp)
2950
+ self._sim.sim._save_json()
2951
+ except Exception as e:
2952
+ self._wp = None
2953
+ logging.debug(_('Error while saving parameters for simulation {}'.format(self._sim.sim.path.name)))
2954
+ logging.debug(str(e))
2955
+
2956
+ def _set_bc(self, e:wx.EVT_BUTTON):
2957
+ """ Set the boundary conditions """
2958
+
2959
+ from .mesh2d.bc_manager import BcManager, choose_bc_type
2960
+
2961
+ if self._sim is None:
2962
+ logging.error(_('No simulation found'))
2963
+ return
2964
+
2965
+ if 'nap' not in self.arrays:
2966
+ logging.error(_('No nap array found'))
2967
+ return
2968
+
2969
+ if self.mapviewer.active_bc is None:
2970
+
2971
+ newbc = BcManager(self,
2972
+ linked_array=self.arrays['nap'],
2973
+ version = 'gpu',
2974
+ DestroyAtClosing=True,
2975
+ Callback=self.mapviewer.pop_boundary_manager,
2976
+ mapviewer=self.mapviewer,
2977
+ wolfparent = self)
2978
+
2979
+
2980
+ self.mapviewer.mybc.append(newbc)
2981
+
2982
+ self.mapviewer.active_bc = newbc
2983
+
2984
+ self.mapviewer.Refresh()
2985
+
2986
+ else:
2987
+ self.mapviewer.active_bc.Show()
2988
+ # self.mapviewer.active_bc.
2989
+
2990
+ def _set_infiltration(self, e:wx.EVT_BUTTON):
2991
+
2992
+ inf_frame = Wolf2DInfiltration(self._sim)
2993
+ inf_frame.Show()
2994
+
2995
+ def add_boundary_condition(self, i: int, j: int, bc_type:BCType_2D_GPU, bc_value: float, border:Direction):
2996
+ """ alias """
2997
+ from wolfgpu.simple_simulation import BoundaryConditionsTypes, Direction as ss_direction
2998
+
2999
+ def convert_dirhece2gpu(direction:Direction) -> ss_direction:
3000
+ """ Convert the boundary conditions from HECE to GPU """
3001
+ if direction == Direction.LEFT:
3002
+ return ss_direction.LEFT
3003
+ if direction == Direction.BOTTOM:
3004
+ return ss_direction.BOTTOM
3005
+
3006
+ def convert_bchece2gpu(bctype:BCType_2D_GPU) -> BoundaryConditionsTypes:
3007
+ """ Convert the boundary conditions from HECE to GPU """
3008
+ if bctype == BCType_2D_GPU.FROUDE_NORMAL:
3009
+ return BoundaryConditionsTypes.FROUDE_NORMAL
3010
+ if bctype == BCType_2D_GPU.HMOD:
3011
+ return BoundaryConditionsTypes.HMOD
3012
+ if bctype == BCType_2D_GPU.NONE:
3013
+ return BoundaryConditionsTypes.NONE
3014
+ if bctype == BCType_2D_GPU.QX:
3015
+ return BoundaryConditionsTypes.QX
3016
+ if bctype == BCType_2D_GPU.QY:
3017
+ return BoundaryConditionsTypes.QY
3018
+
3019
+ self._sim.sim.add_boundary_condition(i, j, convert_bchece2gpu(bc_type), bc_value, convert_dirhece2gpu(border))
3020
+
3021
+
3022
+ def reset_boundary_conditions(self):
3023
+ """ Reset the boundary conditions """
3024
+
3025
+ self._sim.sim.clear_boundary_conditions()
3026
+
3027
+
3028
+ def _check_errors(self, e:wx.EVT_BUTTON):
3029
+ """ Check the errors in the model """
3030
+
3031
+ ret_warnings = self._sim.sim.check_warnings()
3032
+ ret_errors = self._sim.sim.check_errors()
3033
+ ret_wolfgpu = self._sim.check_environment()
3034
+
3035
+ ret_infil=[]
3036
+ nmax = ma.max(self.arrays['infiltration_zones'].array)
3037
+ nmin = ma.min(self.arrays['infiltration_zones'].array[self.arrays['infiltration_zones'].array > 0])
3038
+ l = ma.unique(self.arrays['infiltration_zones'].array[self.arrays['infiltration_zones'].array > 0]).tolist()
3039
+ chronos = self.sim.sim.infiltrations_chronology
3040
+
3041
+ if nmin !=1:
3042
+ ret_infil.append(_('Infiltration zones index must be strictly positive. the first one is 1.'))
3043
+ if nmax != len(l):
3044
+ ret_infil.append(_('Infiltration zones must be between 1 and N'))
3045
+ ret_infil.append(_('N is the number of infiltration zones'))
3046
+ ret_infil.append(_('You have {} zones in the arrays and the maximum index in the array is {}'.format(len(l), nmax)))
3047
+ if len(chronos[0][1]) != len(l):
3048
+ ret_infil.append(_('Infiltration zones must be between 1 and N'))
3049
+ ret_infil.append(_('N is the number of infiltration zones'))
3050
+ ret_infil.append(_('You have {} zones in the chronology and the maximum index in the array is {}'.format(len(chronos[0][1]), nmax)))
3051
+ ret_infil.append(_('You have {} different zones in the array and the maximum index in the array is {}'.format(len(l), nmax)))
3052
+ ret_infil.append(_('Check the chronology file and the array !'))
3053
+
3054
+
3055
+ if ret_warnings is None:
3056
+ ret_warnings = []
3057
+ if ret_errors is None:
3058
+ ret_errors = []
3059
+
3060
+ self._txt_info.Clear()
3061
+
3062
+ if len(ret_wolfgpu) > 0:
3063
+ self.append_infos(_('Environment :\n'))
3064
+ self.append_infos('\n'.join(ret_wolfgpu))
3065
+ self.append_infos('\n')
3066
+
3067
+ if len(ret_warnings) + len(ret_errors) + len(ret_infil) == 0:
3068
+ self.append_infos(_('No errors found'))
3069
+ self._enable_disable_buttons(False)
3070
+ self._btn_checkerrors.SetBackgroundColour(wx.Colour(0, 255, 0))
3071
+ return
3072
+
3073
+ if len(ret_warnings) > 0:
3074
+ self.append_infos(_('\n**WARNINGS** found :\n\n'))
3075
+ self.append_infos('\n'.join(ret_warnings))
3076
+ self._btn_checkerrors.SetBackgroundColour(wx.Colour(255, 255, 0))
3077
+ self._enable_disable_buttons(False)
3078
+
3079
+ if len(ret_errors) > 0:
3080
+ self.append_infos(_('\n**ERRORS** found :\n\n'))
3081
+ self.append_infos('\n'.join(ret_errors))
3082
+ self._btn_checkerrors.SetBackgroundColour(wx.Colour(255, 0, 0))
3083
+ self._enable_disable_buttons(True)
3084
+
3085
+ if len(ret_infil) > 0:
3086
+ self.append_infos(_('\n**ERRORS** in Infiltration zones :\n\n'))
3087
+ self.append_infos('\n'.join(ret_infil))
3088
+ self._btn_checkerrors.SetBackgroundColour(wx.Colour(255, 0, 0))
3089
+ self._enable_disable_buttons(True)
3090
+
3091
+ def _enable_disable_buttons(self, errors:bool = False):
3092
+ """ Enable or isable buttons"""
3093
+
3094
+ self._btn_write.Enable(not errors)
3095
+ self._btn_run.Enable(not errors)
3096
+
3097
+ self._btn_results.Enable((Path(self.dir) / 'simul_gpu_results').exists())
3098
+ self._btn_rs2ic.Enable((Path(self.dir) / 'simul_gpu_results').exists())
3099
+ self._btn_copy2newdir.Enable((Path(self.dir) / 'simul_gpu_results').exists())
3100
+
3101
+
3102
+ def _write_files(self, e:wx.EVT_BUTTON):
3103
+ """ Write the files to disk """
3104
+
3105
+ if self.dir == '':
3106
+ dlg = wx.DirDialog(None, _('Choose directory to save the simulation'), style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
3107
+ if dlg.ShowModal() == wx.ID_CANCEL:
3108
+ dlg.Destroy()
3109
+ return
3110
+
3111
+ self.dir = dlg.GetPath()
3112
+ dlg.Destroy()
3113
+
3114
+ curdir = Path(self.dir)
3115
+ if not curdir.exists():
3116
+ logging.error(_('Directory does not exist'))
3117
+ return
3118
+
3119
+ if self.mapviewer.active_bc is not None:
3120
+ # Transfer boundary conditions
3121
+ self.mapviewer.active_bc.send_to_wolfparent()
3122
+
3123
+ self._sim.sim.save(Path(self.dir))
3124
+
3125
+
3126
+ def _run(self, e:wx.EVT_BUTTON):
3127
+ """ Run the simulation """
3128
+
3129
+ dlg = wx.MessageDialog(None, _('Do you want to run the simulation in a separate process ?'), _('Run simulation'), wx.YES_NO)
3130
+ if dlg.ShowModal() == wx.ID_NO:
3131
+ dlg.Destroy()
3132
+ return
3133
+
3134
+ dlg.Destroy()
3135
+
3136
+
3137
+ dlg = wx.MessageDialog(None, _("Do you want to limit dryup loops?"), _("Dryup loops"), wx.YES_NO)
3138
+ ret = dlg.ShowModal()
3139
+ if ret == wx.ID_YES:
3140
+ nbloops = wx.GetNumberFromUser(_("Number of dryup loops"), _("Dryup loops"), _("Dryup loops"), 2, 0, 1000)
3141
+ else:
3142
+ nbloops = -1
3143
+
3144
+ dlg.Destroy()
3145
+
3146
+ # Run wolfgpu in a separate command line
3147
+ self._sim.run(limit_dryuploops=nbloops)
3148
+
3149
+
3150
+ def _results(self, e:wx.EVT_BUTTON):
3151
+ """ Display the results """
3152
+
3153
+ self.mapviewer.add_object(which='res2d_gpu',
3154
+ filename=str(self.dir),
3155
+ id=Path(self.dir).name)
3156
+ self.mapviewer.menu_wolf2d()
3157
+ self.mapviewer.Refresh()
3158
+
3159
+ def _results2ic(self, e:wx.EVT_BUTTON):
3160
+ """ Choose one result as initial conditions """
3161
+
3162
+ from .wolfresults_2D import Wolfresults_2D
3163
+ from .Results2DGPU import wolfres2DGPU
3164
+ from datetime import timedelta
3165
+
3166
+ myres = wolfres2DGPU(self.dir, plotted=False)
3167
+
3168
+ times, steps = myres.get_times_steps()
3169
+
3170
+ times_hms = [timedelta(seconds=int(curtime), milliseconds=int(curtime-int(curtime))*1000) for curtime in times]
3171
+
3172
+ choices = [_('Last one')] + ['{:3f} [s] - {} [h:m:s] - {} [step index]'.format(curtime, curtimehms, curstep) for curtime, curtimehms, curstep in zip(times, times_hms, steps)]
3173
+
3174
+ dlg = wx.SingleChoiceDialog(None, _('Choose the time step to set as initial conditions'), _('Results as IC'), choices)
3175
+
3176
+ ret = dlg.ShowModal()
3177
+
3178
+ if ret == wx.ID_CANCEL:
3179
+ logging.info(_('Aborting - No time step selected'))
3180
+ return
3181
+
3182
+ idx = dlg.GetSelection() - 1 # -1 because of the first choice is the last one and it is the convention used in the code
3183
+
3184
+ dlg.Destroy()
3185
+
3186
+ myres.set_hqxqy_as_initial_conditions(idx)
3187
+
3188
+ # update the arrays
3189
+ self._add_arrays_to_mapviewer(force_reload=True)
3190
+
3191
+ def _wizard(self, e:wx.EVT_BUTTON):
3192
+ """ Launch the wizard """
3193
+
3194
+ from wx.adv import Wizard, WizardPageSimple
3195
+
3196
+ wizard_text = self._sim.get_wizard_text()
3197
+
3198
+ self.wizard = Wizard(None, -1, _('Wizard Multiblocks simulation'))
3199
+
3200
+ self.wizard.SetPageSize((400, 300))
3201
+
3202
+ self.wiz_pages:list[WizardPageSimple] = []
3203
+
3204
+ for curpage in wizard_text:
3205
+ self.wiz_pages.append(WizardPageSimple(self.wizard))
3206
+ self.wiz_pages[-1].SetBackgroundColour(wx.Colour(255, 255, 255))
3207
+ self.wiz_pages[-1].SetSizer(wx.BoxSizer(wx.VERTICAL))
3208
+
3209
+ for idx, curpage in enumerate(wizard_text):
3210
+ for curstep in curpage:
3211
+ self.wiz_pages[idx].GetSizer().Add(wx.StaticText(self.wiz_pages[idx], -1, curstep), 0, wx.ALIGN_LEFT)
3212
+
3213
+ for i in range(len(self.wiz_pages)-1):
3214
+ self.wiz_pages[i].Chain(self.wiz_pages[i+1])
3215
+
3216
+
3217
+ ret = self.wizard.RunWizard(self.wiz_pages[0])
3218
+
3219
+ if ret:
3220
+ logging.info(_('Wizard finished'))
3221
+ else:
3222
+ logging.warning(_('Wizard cancelled - Are you sure ?'))
3223
+
3224
+ def _add_arrays2viewer(self, e:wx.EVT_BUTTON):
3225
+ """ Create the fine arrays """
3226
+
3227
+ self._add_arrays_to_mapviewer(force_reload= self._btn_add_arrays2viewer.GetLabel() == _('Reload arrays'))
3228
+
3229
+ def _apply_mask(self, e:wx.EVT_BUTTON):
3230
+ """ Apply the mask """
3231
+
3232
+ if self.mapviewer.active_array is None:
3233
+ logging.error(_('No active array defined - Please select an array'))
3234
+ return
3235
+
3236
+ if self.mapviewer.active_array not in self.arrays.values():
3237
+ logging.error(_("Active array not found in the list of model's arrays"))
3238
+ return
3239
+
3240
+ keys = self.sim._get_description_arrays()
3241
+ self._sim.mimic_mask(self.mapviewer.active_array, [cur for key,cur in zip(keys,self.arrays.values()) if key != self.mapviewer.active_array.idx])
3242
+ for cur in self.arrays.values():
3243
+ cur.reset_plot()
3244
+
3245
+ self.mapviewer.Refresh()
3246
+
3247
+ def _create_from_vector(self, e:wx.EVT_BUTTON):
3248
+ """ Create a simulation from a vector """
3249
+
3250
+ if self._sim.sim is not None:
3251
+ dlg = wx.MessageDialog(None, _('Do you want to erase the current simulation ?'), _('Erase simulation'), wx.YES_NO)
3252
+ if dlg.ShowModal() == wx.ID_NO:
3253
+ dlg.Destroy()
3254
+ return
3255
+
3256
+ dlg.Destroy()
3257
+ self._sim.sim = None
3258
+
3259
+ if self.mapviewer.active_vector is None:
3260
+ logging.error(_('No active vector defined - Please select or create a vector/polygon as external border'))
3261
+ return
3262
+
3263
+ dlg = wx.TextEntryDialog(None, _('Size/Spatial resolution'), _('Spatial resolution'), 'dx, dy')
3264
+ if dlg.ShowModal() == wx.ID_OK:
3265
+
3266
+ try:
3267
+ dx, dy = dlg.GetValue().split(',')
3268
+ self._sim.create_from_vector(self.mapviewer.active_vector, float(dx), float(dy))
3269
+ self.update_wp()
3270
+ self.clear_infos()
3271
+ self.append_infos(str(self._sim.sim))
3272
+ except Exception as e:
3273
+ logging.error(_('Invalid mesh sizes or error {e}'))
3274
+
3275
+ dlg.Destroy()
3276
+
3277
+ self._btn_fromvector.Enable(False)
3278
+ self._btn_fromfootprint.Enable(False)
3279
+ self._btn_fromarray.Enable(False)
3280
+
3281
+ def _create_from_array(self, e:wx.EVT_BUTTON):
3282
+ """ Create a simulation from an array """
3283
+
3284
+ if self._sim.sim is not None:
3285
+ dlg = wx.MessageDialog(None, _('Do you want to erase the current simulation ?'), _('Erase simulation'), wx.YES_NO)
3286
+ if dlg.ShowModal() == wx.ID_NO:
3287
+ dlg.Destroy()
3288
+ return
3289
+
3290
+ dlg.Destroy()
3291
+ self._sim.sim = None
3292
+
3293
+ if self.mapviewer.active_array is None:
3294
+ logging.error(_('No active array defined - Please select or create an array as external border'))
3295
+ return
3296
+
3297
+ self._sim.create_from_array(self.mapviewer.active_array)
3298
+
3299
+ dlg = wx.MessageDialog(None, _('Do you want to use the data from the array as bathymetry?'), _('Use bathymetry'), wx.YES_NO)
3300
+ if dlg.ShowModal() == wx.ID_YES:
3301
+ self._sim.sim._bathymetry[:,:] = self.mapviewer.active_array.array[:,:] # copy the array
3302
+
3303
+ dlg.Destroy()
3304
+
3305
+ self.update_wp()
3306
+ self.clear_infos()
3307
+ self.append_infos(str(self._sim.sim))
3308
+
3309
+ self._btn_fromvector.Enable(False)
3310
+ self._btn_fromfootprint.Enable(False)
3311
+ self._btn_fromarray.Enable(False)
3312
+
3313
+ def _create_from_footprint(self, e:wx.EVT_BUTTON):
3314
+ """ Create a simulation from a footprint """
3315
+
3316
+ if self._sim.sim is not None:
3317
+ dlg = wx.MessageDialog(None, _('Do you want to erase the current simulation ?'), _('Erase simulation'), wx.YES_NO)
3318
+ if dlg.ShowModal() == wx.ID_NO:
3319
+ dlg.Destroy()
3320
+ return
3321
+
3322
+ dlg.Destroy()
3323
+ self._sim.sim = None
3324
+
3325
+ dlg = wx.TextEntryDialog(None, _('Footprint'), _('Footprint'), 'ox, oy, nbx, nby, dx, dy')
3326
+
3327
+ if dlg.ShowModal() == wx.ID_OK:
3328
+ try:
3329
+ ox, oy, nbx, nby, dx, dy = dlg.GetValue().split(',')
3330
+
3331
+ newhead = header_wolf()
3332
+ newhead.nbx = int(nbx)
3333
+ newhead.nby = int(nby)
3334
+ newhead.dx = float(dx)
3335
+ newhead.dy = float(dy)
3336
+ newhead.origx = float(ox)
3337
+ newhead.origy = float(oy)
3338
+
3339
+ self._sim.create_from_header(newhead)
3340
+ self.update_wp()
3341
+ self.clear_infos()
3342
+ self.append_infos(str(self._sim.sim))
3343
+
3344
+ except:
3345
+ logging.error(_('Invalid footprint'))
3346
+
3347
+ dlg.Destroy()
3348
+
3349
+ self._btn_fromvector.Enable(False)
3350
+ self._btn_fromfootprint.Enable(False)
3351
+ self._btn_fromarray.Enable(False)
3352
+
3353
+
3354
+ def _set_magnetic_grid(self, e:wx.EVT_BUTTON):
3355
+ """ Set the magnetic grid """
3356
+
3357
+ dlg = wx.TextEntryDialog(None, _('Magnetic grid'), _('Magnetic grid'), 'ox, oy, dx, dy')
3358
+
3359
+ if dlg.ShowModal() == wx.ID_OK:
3360
+ try:
3361
+ ox, oy, dx, dy = dlg.GetValue().split(',')
3362
+ self._sim.set_magnetic_grid(float(dx), float(dy), float(ox), float(oy))
3363
+ self.update_wp()
3364
+ except:
3365
+ logging.error(_('Invalid magnetic grid'))
3366
+
3367
+ dlg.Destroy()
3368
+
3369
+ def _choose_resolution(self, e:wx.EVT_BUTTON):
3370
+ """ Choose the fine resolution """
3371
+
3372
+ dlg = wx.TextEntryDialog(None, _('Choose the fine resolution'), _('Fine resolution'), 'dx, dy')
3373
+
3374
+ if dlg.ShowModal() == wx.ID_OK:
3375
+ try:
3376
+ dx, dy = dlg.GetValue().split(',')
3377
+
3378
+ try:
3379
+ floatdx = float(dx)
3380
+ floatdy = float(dy)
3381
+ except:
3382
+ logging.error(_('Invalid fine resolution'))
3383
+ return
3384
+
3385
+ self._sim.set_mesh_size(floatdx, floatdy)
3386
+ except:
3387
+ logging.error(_('Invalid fine resolution'))
3388
+
3389
+ dlg.Destroy()
3390
+
3391
+ def _copy2dir(self, e:wx.EVT_BUTTON):
3392
+ """ Copy the simulation to another directory """
3393
+
3394
+ dlg = wx.DirDialog(None, _('Choose the destination directory'))
3395
+
3396
+ if dlg.ShowModal() == wx.ID_OK:
3397
+ newdir = dlg.GetPath()
3398
+ self._sim.copy2dir(newdir)
3399
+
3400
+ dlg.Destroy()
3401
+
3402
+ def _apply_changes(self, e:wx.EVT_BUTTON):
3403
+ """ Apply the changes """
3404
+
3405
+ if self._wp is not None:
3406
+ self._callbackwp()
3407
+
3408
+ def show_properties(self):
3409
+ """
3410
+ Show the properties of the model
3411
+ """
3412
+
3413
+ if self.wx_exists:
3414
+
3415
+ if self._prop_frame is not None:
3416
+ self._prop_frame.CenterOnScreen()
3417
+ self._prop_frame.Iconize(False)
3418
+ self._prop_frame.Show()
3419
+ return
3420
+
3421
+ # Création d'un wx Frame pour les paramètres
3422
+ self._prop_frame = wx.Frame(self,
3423
+ title=_('Parameters') + str(self.dir),
3424
+ size=(650, 800),
3425
+ style = wx.DEFAULT_FRAME_STYLE)
3426
+
3427
+ # add a panel
3428
+ self._panel = wx.Panel(self._prop_frame)
3429
+
3430
+ # Set sizers
3431
+ #
3432
+ # The panel is decomposed in three parts:
3433
+ # - List of toogle buttons + properties
3434
+ # - Buttons to add/remove blocks/update structure
3435
+ # - Information zone (multiline text)
3436
+
3437
+ self._sizer_gen = wx.BoxSizer(wx.HORIZONTAL)
3438
+
3439
+ self._sizer_run_results = wx.BoxSizer(wx.VERTICAL)
3440
+
3441
+ self._sizer_principal = wx.BoxSizer(wx.VERTICAL)
3442
+
3443
+ self._sizer_properties = wx.BoxSizer(wx.HORIZONTAL)
3444
+
3445
+ # self._sizer_btnsblocks = wx.BoxSizer(wx.VERTICAL)
3446
+
3447
+ self._sizer_btnsactions = wx.BoxSizer(wx.HORIZONTAL)
3448
+ self._sizer_btnsactions_left = wx.BoxSizer(wx.VERTICAL)
3449
+ self._sizer_btnsactions_right = wx.BoxSizer(wx.VERTICAL)
3450
+
3451
+ self._sizer_btnsactions.Add(self._sizer_btnsactions_left, 1, wx.EXPAND)
3452
+ self._sizer_btnsactions.Add(self._sizer_btnsactions_right, 1, wx.EXPAND)
3453
+
3454
+ self._sizer_btns_creation = wx.BoxSizer(wx.HORIZONTAL)
3455
+
3456
+ # Buttons
3457
+ # ********
3458
+
3459
+ # Boundary conditions
3460
+ # ---------------------
3461
+
3462
+ self._btn_bc = wx.Button(self._panel, label=_('BCs'))
3463
+ self._btn_bc.SetToolTip(_('Set the boundary conditions'))
3464
+ self._btn_bc.Bind(wx.EVT_BUTTON, self._set_bc)
3465
+
3466
+ self._sizer_run_results.Add(self._btn_bc, 1, wx.EXPAND)
3467
+
3468
+ # Infiltration
3469
+ # --------------
3470
+
3471
+ self._btn_infiltration = wx.Button(self._panel, label=_('Infiltration'))
3472
+ self._btn_infiltration.SetToolTip(_('Set the infiltration'))
3473
+ self._btn_infiltration.Bind(wx.EVT_BUTTON, self._set_infiltration)
3474
+
3475
+ self._sizer_run_results.Add(self._btn_infiltration, 1, wx.EXPAND)
3476
+
3477
+ # Check
3478
+ # -----
3479
+
3480
+ self._btn_checkerrors = wx.Button(self._panel, label=_('Check errors'))
3481
+ self._btn_checkerrors.SetToolTip(_('Check the errors in the model'))
3482
+ self._btn_checkerrors.Bind(wx.EVT_BUTTON, self._check_errors)
3483
+
3484
+ self._sizer_run_results.Add(self._btn_checkerrors, 1, wx.EXPAND)
3485
+
3486
+ # Write files
3487
+ # ------------
3488
+
3489
+ self._btn_write = wx.Button(self._panel, label=_('Write files'))
3490
+ self._btn_write.SetToolTip(_('Write the files to disk'))
3491
+ self._btn_write.Bind(wx.EVT_BUTTON, self._write_files)
3492
+ self._btn_write.Enable(False)
3493
+
3494
+
3495
+ self._sizer_run_results.Add(self._btn_write, 1, wx.EXPAND)
3496
+
3497
+ # Run simulation
3498
+ # ---------------
3499
+
3500
+ self._btn_run = wx.Button(self._panel, label=_('Run'))
3501
+ self._btn_run.SetToolTip(_('Run the simulation - wolfgpu.exe code'))
3502
+ self._btn_run.Bind(wx.EVT_BUTTON, self._run)
3503
+ self._btn_run.Enable(False)
3504
+
3505
+ self._sizer_run_results.Add(self._btn_run, 1, wx.EXPAND)
3506
+
3507
+ # Results
3508
+ # --------
3509
+
3510
+ self._btn_results = wx.Button(self._panel, label=_('Results'))
3511
+ self._btn_results.SetToolTip(_('Display the results of the simulation'))
3512
+ self._btn_results.Bind(wx.EVT_BUTTON, self._results)
3513
+ self._btn_results.Enable(False)
3514
+
3515
+ self._sizer_run_results.Add(self._btn_results, 1, wx.EXPAND)
3516
+
3517
+ # Result as IC
3518
+ # ------------
3519
+
3520
+ self._btn_rs2ic = wx.Button(self._panel, label=_('Results as IC'))
3521
+ self._btn_rs2ic.SetToolTip(_('Set one result as initial conditions'))
3522
+ self._btn_rs2ic.Bind(wx.EVT_BUTTON, self._results2ic)
3523
+ self._btn_rs2ic.Enable(False)
3524
+
3525
+ self._sizer_run_results.Add(self._btn_rs2ic, 1, wx.EXPAND)
3526
+
3527
+ # Copy Simulation
3528
+ # ---------------
3529
+
3530
+ self._btn_copy2newdir = wx.Button(self._panel, label=_('Copy to...'))
3531
+ self._btn_copy2newdir.SetToolTip(_('Copy the simulation to another directory'))
3532
+ self._btn_copy2newdir.Bind(wx.EVT_BUTTON, self._copy2dir)
3533
+ self._btn_copy2newdir.Enable(False)
3534
+
3535
+ self._sizer_run_results.Add(self._btn_copy2newdir, 1, wx.EXPAND)
3536
+
3537
+ # Wizard
3538
+ # ------
3539
+
3540
+ self._btn_wizard = wx.Button(self._panel, label=_('Wizard'))
3541
+ self._btn_wizard.SetToolTip(_('Launch the wizard to create a new model'))
3542
+ self._btn_wizard.Bind(wx.EVT_BUTTON, self._wizard)
3543
+
3544
+ self._sizer_principal.Add(self._btn_wizard, 1, wx.EXPAND)
3545
+
3546
+ self._sizer_magn_res = wx.BoxSizer(wx.HORIZONTAL)
3547
+
3548
+ # Magnetic grid
3549
+ # -------------
3550
+
3551
+ self._btn_magnetic_grid = wx.Button(self._panel, label=_('Magnetic grid'))
3552
+ self._btn_magnetic_grid.SetToolTip(_('Set a magnetic grid for the model'))
3553
+ self._btn_magnetic_grid.Bind(wx.EVT_BUTTON, self._set_magnetic_grid)
3554
+
3555
+ self._sizer_magn_res.Add(self._btn_magnetic_grid, 1, wx.EXPAND)
3556
+
3557
+ # # Resolution
3558
+ # # -----------
3559
+
3560
+ # self._btn_set_fine_res = wx.Button(self._panel, label=_('Set fine resolution'))
3561
+ # self._btn_set_fine_res.SetToolTip(_('Set the fine resolution of the model'))
3562
+ # self._btn_set_fine_res.Bind(wx.EVT_BUTTON, self._choose_resolution)
3563
+
3564
+ # self._sizer_magn_res.Add(self._btn_set_fine_res, 1, wx.EXPAND)
3565
+
3566
+
3567
+ # Chesk Translation
3568
+ # # -----------------
3569
+
3570
+ # self._chk_translation = wx.CheckBox(self._panel, label=_('Shift to (0., 0.)'), style=wx.ALIGN_CENTER)
3571
+ # self._chk_translation.SetToolTip(_('Shift the global coordinates to (0., 0.) and define shifting parameters'))
3572
+ # self._chk_translation.SetValue(True)
3573
+
3574
+ # self._sizer_magn_res.Add(self._chk_translation, 1, wx.EXPAND)
3575
+
3576
+ self._sizer_principal.Add(self._sizer_magn_res, 1, wx.EXPAND)
3577
+
3578
+ self._sizer_add_mesh_create = wx.BoxSizer(wx.HORIZONTAL)
3579
+
3580
+ # Creation
3581
+ # ---------
3582
+
3583
+ self._btn_fromvector = wx.Button(self._panel, label=_('Create From vector'))
3584
+
3585
+ self._btn_fromarray = wx.Button(self._panel, label=_('Create From array'))
3586
+ self._btn_fromfootprint = wx.Button(self._panel, label=_('Create From footprint'))
3587
+
3588
+ self._btn_fromvector.SetToolTip(_('Create a simulation from an existing polygon'))
3589
+ self._btn_fromarray.SetToolTip(_('Create a simulation from the active array'))
3590
+ self._btn_fromfootprint.SetToolTip(_('Create a simulation from the footprint (ox, oy, nbx, nby, dy, dy)'))
3591
+
3592
+ self.Bind(wx.EVT_BUTTON, self._create_from_vector, self._btn_fromvector)
3593
+ self.Bind(wx.EVT_BUTTON, self._create_from_array, self._btn_fromarray)
3594
+ self.Bind(wx.EVT_BUTTON, self._create_from_footprint, self._btn_fromfootprint)
3595
+
3596
+ self._sizer_magn_res.Add(self._btn_fromvector, 1, wx.EXPAND)
3597
+
3598
+ self._sizer_btns_creation.Add(self._btn_fromarray, 1, wx.EXPAND)
3599
+ self._sizer_btns_creation.Add(self._btn_fromfootprint, 1, wx.EXPAND)
3600
+
3601
+ self._sizer_principal.Add(self._sizer_btns_creation, 1, wx.EXPAND)
3602
+
3603
+
3604
+ # Create arrays
3605
+ # -------------
3606
+
3607
+ self._btn_add_arrays2viewer = wx.Button(self._panel, label=_('Add arrays to viewer'))
3608
+ self._btn_add_arrays2viewer.SetToolTip(_('Add all model arrays to the viewer'))
3609
+ self._btn_add_arrays2viewer.Bind(wx.EVT_BUTTON, self._add_arrays2viewer)
3610
+
3611
+ self._btn_apply_mask = wx.Button(self._panel, label=_('Apply mask from active array to all'))
3612
+ self._btn_apply_mask.SetToolTip(_('Apply the mask from the active array to all arrays'))
3613
+ self._btn_apply_mask.Bind(wx.EVT_BUTTON, self._apply_mask)
3614
+
3615
+ self._sizer_add_mesh_create.Add(self._btn_add_arrays2viewer, 1, wx.EXPAND)
3616
+ self._sizer_add_mesh_create.Add(self._btn_apply_mask, 1, wx.EXPAND)
3617
+
3618
+ self._sizer_principal.Add(self._sizer_add_mesh_create, 1, wx.EXPAND)
3619
+
3620
+ # Apply changes
3621
+ # -------------
3622
+ self._btn_apply = wx.Button(self._panel, label=_('Apply changes'))
3623
+ self._btn_apply.SetToolTip(_('Apply the changes to the memory (not saved on disk)'))
3624
+ self._btn_apply.Bind(wx.EVT_BUTTON, self._apply_changes)
3625
+
3626
+ self._panel.SetSizer(self._sizer_gen)
3627
+
3628
+ self._sizer_principal.Add(self._sizer_properties, 4, wx.EXPAND)
3629
+ self._sizer_principal.Add(self._sizer_btnsactions, 1, wx.EXPAND)
3630
+
3631
+ self._txt_info = wx.TextCtrl(self._panel, style=wx.TE_MULTILINE|wx.TE_READONLY)
3632
+
3633
+ self._sizer_principal.Add(self._txt_info, 3, wx.EXPAND)
3634
+
3635
+ self._sizer_gen.Add(self._sizer_principal, 5, wx.EXPAND)
3636
+ self._sizer_gen.Add(self._sizer_run_results, 1, wx.EXPAND)
3637
+
3638
+
3639
+ # Create the local list of parameters
3640
+ # - for global parameters
3641
+ # - for blocks
3642
+
3643
+ # Create the widget PropertyGridManager for the parameters
3644
+ self._wp = Wolf_Param(self._panel, to_read=False, force_even_if_same_default=True, withbuttons=False, init_GUI=False)
3645
+ self._wp.ensure_prop(wxparent = self._panel, show_in_active_if_default= True)
3646
+ self._append_magnetic_grid_to_prop()
3647
+
3648
+ if self._sim.sim is not None:
3649
+ self._sim.sim.add_to_wolfparam(self._wp)
3650
+ self._wp.Populate(sorted_groups=True)
3651
+
3652
+ # add the properties to the sizer
3653
+ self._sizer_properties.Add(self._wp.prop, 5, wx.EXPAND)
3654
+
3655
+ # self._sizer_properties.Add(self._sizer_btnsblocks, 1, wx.EXPAND)
3656
+
3657
+ self._prop_frame.Bind(wx.EVT_CLOSE, self.onclose)
3658
+
3659
+ # Show the frame
3660
+ self._prop_frame.Show()
3661
+
3662
+ else:
3663
+ logging.info(_('No GUI available'))
3664
+
3665
+ def onclose(self, e:wx.EVT_CLOSE):
3666
+ """ Close the properties frame """
3667
+
3668
+ if self._prop_frame is not None:
3669
+ self._prop_frame.Hide()
3670
+
3671
+ def _append_magnetic_grid_to_prop(self):
3672
+ """ Append the magnetic grid to the properties """
3673
+
3674
+ self._wp.add_param(MAGN_GROUP_NAME,
3675
+ 'Dx',
3676
+ 0.,
3677
+ Type_Param.Float,
3678
+ _('Spatial resolution of the magnetic grid along X-axis'),
3679
+ whichdict='All'
3680
+ )
3681
+ self._wp.add_param(MAGN_GROUP_NAME,
3682
+ 'Dy',
3683
+ 0.,
3684
+ Type_Param.Float,
3685
+ _('Spatial resolution of the magnetic grid along Y-axis'),
3686
+ whichdict='All'
3687
+ )
3688
+
3689
+ self._wp.add_param(MAGN_GROUP_NAME,
3690
+ 'Ox',
3691
+ -99999.,
3692
+ Type_Param.Float,
3693
+ _('Origin of the magnetic grid along X-axis'),
3694
+ whichdict='All'
3695
+ )
3696
+
3697
+ self._wp.add_param(MAGN_GROUP_NAME,
3698
+ 'Oy',
3699
+ -99999.,
3700
+ Type_Param.Float,
3701
+ _('Origin of the magnetic grid along Y-axis'),
3702
+ whichdict='All'
3703
+ )
3704
+
3705
+ if self._sim.magnetic_grid is None:
3706
+ self._sim.set_magnetic_grid(1., 1., 0., 0.)
3707
+
3708
+ self._wp[(MAGN_GROUP_NAME, 'Dx')] = self._sim.magnetic_grid.dx
3709
+ self._wp[(MAGN_GROUP_NAME, 'Dy')] = self._sim.magnetic_grid.dy
3710
+
3711
+ self._wp[(MAGN_GROUP_NAME, 'Ox')] = self._sim.magnetic_grid.origx
3712
+ self._wp[(MAGN_GROUP_NAME, 'Oy')] = self._sim.magnetic_grid.origy
3713
+
3714
+ self._wp.Populate(sorted_groups=True)
3715
+
3716
+ def update_wp(self):
3717
+ """ Update the properties """
3718
+
3719
+ if self._wp is not None:
3720
+ self._wp[(MAGN_GROUP_NAME, 'Dx')] = self._sim.magnetic_grid.dx
3721
+ self._wp[(MAGN_GROUP_NAME, 'Dy')] = self._sim.magnetic_grid.dy
3722
+
3723
+ self._wp[(MAGN_GROUP_NAME, 'Ox')] = self._sim.magnetic_grid.origx
3724
+ self._wp[(MAGN_GROUP_NAME, 'Oy')] = self._sim.magnetic_grid.origy
3725
+
3726
+ if self._sim.sim is not None:
3727
+ self._sim.sim.add_to_wolfparam(self._wp)
3728
+
3729
+ self._wp.Populate(sorted_groups=True)
3730
+
3731
+ def clear_infos(self):
3732
+ """ Clear the information zone """
3733
+
3734
+ if self.wx_exists:
3735
+ self._txt_info.Clear()
3736
+
3737
+ def append_infos(self, text):
3738
+ """ Append text to the information zone """
3739
+
3740
+ if self.wx_exists:
3741
+ self._txt_info.AppendText(text)