This file is indexed.

/usr/lib/python2.7/dist-packages/code_saturne/Pages/LagrangianStatisticsView.py is in code-saturne-data 4.3.3+repack-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2016 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.

#-------------------------------------------------------------------------------

"""
This module contains the following classes and function:
- StandardItemModelVolumicNames
- StandardItemModelBoundariesNames
- LagrangianStatisticsView
"""

#-------------------------------------------------------------------------------
# Standard modules
#-------------------------------------------------------------------------------

import logging

#-------------------------------------------------------------------------------
# Third-party modules
#-------------------------------------------------------------------------------

from code_saturne.Base.QtCore    import *
from code_saturne.Base.QtGui     import *
from code_saturne.Base.QtWidgets import *

#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------

from code_saturne.Base.Toolbox import GuiParam
from code_saturne.Base.QtPage import ComboModel, IntValidator, DoubleValidator
from code_saturne.Base.QtPage import from_qvariant, to_text_string
from code_saturne.Pages.LagrangianStatisticsForm import Ui_LagrangianStatisticsForm
from code_saturne.Pages.LagrangianStatisticsModel import LagrangianStatisticsModel
from code_saturne.Pages.LagrangianModel import LagrangianModel


#-------------------------------------------------------------------------------
# log config
#-------------------------------------------------------------------------------


logging.basicConfig()
log = logging.getLogger("LagrangianStatisticsView")
log.setLevel(GuiParam.DEBUG)


#-------------------------------------------------------------------------------
# StandarItemModel for volumic variables names
#-------------------------------------------------------------------------------


class StandardItemModelVolumicNames(QStandardItemModel):
    def __init__(self, model):
        """
        """
        QStandardItemModel.__init__(self)

        self.headers = [self.tr("Variable Name (Mean value)"),
                        self.tr("Variable Name (Variance)"),
                        self.tr("Post-processing")]
        self.setColumnCount(len(self.headers))
        self.model = model
        self.initData()


    def initData(self):

        self.dataVolumicNames = []
        vnames = self.model.getVariablesNamesVolume()
        for vname in vnames:
            if vname == "Part_statis_weight":
                labelv = ""
                postprocessing = self.model.getPostprocessingVolStatusFromName(vname)
                line = [vname, labelv, postprocessing]
            else:
                labelv = "var_" + vname
                postprocessing = self.model.getPostprocessingVolStatusFromName(vname)
                line = [vname, labelv, postprocessing]

            row = self.rowCount()
            self.setRowCount(row+1)
            self.dataVolumicNames.append(line)


    def data(self, index, role):

        if not index.isValid():
            return

        # ToolTips
        if role == Qt.ToolTipRole:
            if index.column() in [0, 1]:
                return self.tr("field label base")

        # Display
        if role == Qt.DisplayRole:
            if index.column() in [0,1]:
                return self.dataVolumicNames[index.row()][index.column()]

        # CheckState
        elif role == Qt.CheckStateRole:
            if index.column() == 2:
                if self.dataVolumicNames[index.row()][index.column()] == 'on':
                    return Qt.Checked
                else:
                    return Qt.Unchecked

        return


    def flags(self, index):
        if not index.isValid():
            return Qt.ItemIsEnabled
        elif index.column() == [0,1]:
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable
        else:
            return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable


    def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.headers[section]
        return


    def setData(self, index, value, role):
        #
        if index.column() == 0:
            self.dataVolumicNames[index.row()][index.column()] = \
                        str(from_qvariant(value, to_text_string))
            vname = self.dataVolumicNames[index.row()][0]

        elif index.column() == 1:
            labelv = str(from_qvariant(value, to_text_string))
            self.dataVolumicNames[index.row()][index.column()] = labelv
            name = self.dataVolumicNames[index.row()][0]

        elif index.column() == 2:
            v = from_qvariant(value, int)
            if v == Qt.Unchecked:
                status = "off"
                self.dataVolumicNames[index.row()][index.column()] = "off"
            else:
                status = "on"
                self.dataVolumicNames[index.row()][index.column()] = "on"

            vname = self.dataVolumicNames[index.row()][0]
            self.model.setPostprocessingVolStatusFromName(vname, status)

        self.dataChanged.emit(index, index)
        return True


#-------------------------------------------------------------------------------
# StandarItemModel for boundaries variables names
#-------------------------------------------------------------------------------


class StandardItemModelBoundariesNames(QStandardItemModel):
    def __init__(self, model):
        """
        """
        QStandardItemModel.__init__(self)

        self.headers = [self.tr("Variable Name"),
                        self.tr("Post-processing")]
        self.setColumnCount(len(self.headers))
        self.model = model
        self.initData()


    def initData(self):

        self.dataBoundariesNames = []
        vnames = self.model.getVariablesNamesBoundary()
        for vname in vnames:
            postprocessing = self.model.getPostprocessingStatusFromName(vname)
            line = [vname, postprocessing]

            row = self.rowCount()
            self.setRowCount(row+1)
            self.dataBoundariesNames.append(line)


    def data(self, index, role):

        self.kwords = [ "IFLMBD",   "INBRBD",   "IANGBD",   "IVITBD",
                        "IENCNBBD", "IENCMABD", "IENCDIBD", "IENCCKBD"]
        if not index.isValid():
            return

        # ToolTips
        if role == Qt.ToolTipRole:
            if index.column() == 0:
                return self.tr("Code_Saturne key word: NOMBRD")
            elif index.column() == 1:
                return self.tr("Code_Saturne key word: " + self.kwords[index.row()])

        # Display
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return self.dataBoundariesNames[index.row()][index.column()]

        # CheckState
        elif role == Qt.CheckStateRole:
            if index.column() ==1:
                if self.dataBoundariesNames[index.row()][index.column()] == 'on':
                    return Qt.Checked
                else:
                    return Qt.Unchecked

        return


    def flags(self, index):
        if not index.isValid():
            return Qt.ItemIsEnabled
        elif index.column() == 0:
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable
        else:
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable


    def headerData(self, section, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.headers[section]
        return


    def setData(self, index, value, role):

        if index.column() == 1:
            v = from_qvariant(value, int)
            if v == Qt.Unchecked:
                status = "off"
                self.dataBoundariesNames[index.row()][index.column()] = "off"
            else:
                status = "on"
                self.dataBoundariesNames[index.row()][index.column()] = "on"

            vname = self.dataBoundariesNames[index.row()][0]
            self.model.setPostprocessingStatusFromName(vname, status)


        self.dataChanged.emit(index, index)
        return True


#-------------------------------------------------------------------------------
# Main class
#-------------------------------------------------------------------------------


class LagrangianStatisticsView(QWidget, Ui_LagrangianStatisticsForm):
    """
    """

    def __init__(self, parent, case):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_LagrangianStatisticsForm.__init__(self)
        self.setupUi(self)

        self.case = case
        self.case.undoStopGlobal()
        self.model = LagrangianStatisticsModel(self.case)

        self.checkBoxISUIST.clicked.connect(self.slotISUIST)
        self.lineEditNBCLST.textChanged[str].connect(self.slotNBCLST)

        self.groupBoxISTALA.clicked.connect(self.slotISTALA)
        self.lineEditIDSTNT.editingFinished.connect(self.slotIDSTNT)
        self.lineEditNSTIST.editingFinished.connect(self.slotNSTIST)

        self.lineEditSEUIL.textChanged[str].connect(self.slotSEUIL)

        self.groupBoxIENSI3.clicked.connect(self.slotIENSI3)

        validatorNBCLST = IntValidator(self.lineEditNBCLST, min=0) # max=100

        validatorIDSTNT = IntValidator(self.lineEditIDSTNT, min=0)
        validatorIDSTNT.setExclusiveMin(True)
        validatorNSTIST = IntValidator(self.lineEditNSTIST, min=0)
        validatorSEUIL = DoubleValidator(self.lineEditSEUIL, min=0.)

        self.lineEditNBCLST.setValidator(validatorNBCLST)
        self.lineEditIDSTNT.setValidator(validatorIDSTNT)
        self.lineEditNSTIST.setValidator(validatorNSTIST)
        self.lineEditSEUIL.setValidator(validatorSEUIL)

        # initialize Widgets
        # FIXME
        # test if restart lagrangian is on
##         mdl.lagr = LagrangianModel()
##         is_restart = mdl_lagr.getRestart()
##         if is_restart == "off":
##             self.lineEditISUIST.setEnabled(False)
##             self.checkBoxISUIST.setEnabled(False)
        status = self.model.getRestartStatisticsStatus()
        if status == "on":
            self.checkBoxISUIST.setChecked(True)
        else:
            self.checkBoxISUIST.setChecked(False)

        nclust = self.model.getGroupOfParticlesValue()
        self.lineEditNBCLST.setText(str(nclust))

        it = self.model.getIterationStart()
        self.lineEditIDSTNT.setText(str(it))

        it = self.model.getIterSteadyStart()
        self.lineEditNSTIST.setText(str(it))

        seuil = self.model.getThresholdValue()
        self.lineEditSEUIL.setText(str(seuil))

        # volume
        status = self.model.getVolumeStatisticsStatus()
        if status == "on":
            self.groupBoxISTALA.setChecked(True)
        else:
            self.groupBoxISTALA.setChecked(False)
        self.slotISTALA()

        # boundary
        status = self.model.getBoundaryStatisticsStatus()
        if status == "on":
            self.groupBoxIENSI3.setChecked(True)
        else:
            self.groupBoxIENSI3.setChecked(False)
        self.slotIENSI3()

        self.case.undoStartGlobal()


    def _initVolumicNames(self):
        """
        Initialize names for volumic statistics.
        """
        self.modelVolumicNames = StandardItemModelVolumicNames(self.model)

        self.tableViewVolumicNames.setModel(self.modelVolumicNames)
        self.tableViewVolumicNames.setAlternatingRowColors(True)
        self.tableViewVolumicNames.setSelectionBehavior(QAbstractItemView.SelectItems)
        self.tableViewVolumicNames.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.tableViewVolumicNames.setEditTriggers(QAbstractItemView.DoubleClicked)
        if QT_API == "PYQT4":
            self.tableViewVolumicNames.horizontalHeader().setResizeMode(QHeaderView.Stretch)
        elif QT_API == "PYQT5":
            self.tableViewVolumicNames.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)


    def _initBoundariesNames(self):
        """
        Initialize names for volumic statistics.
        """
        self.modelBoundariesNames = StandardItemModelBoundariesNames(self.model)

        self.tableViewBoundariesNames.setModel(self.modelBoundariesNames)
        self.tableViewBoundariesNames.setAlternatingRowColors(True)
        self.tableViewBoundariesNames.setSelectionBehavior(QAbstractItemView.SelectItems)
        self.tableViewBoundariesNames.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.tableViewBoundariesNames.setEditTriggers(QAbstractItemView.DoubleClicked)
        if QT_API == "PYQT4":
            self.tableViewBoundariesNames.horizontalHeader().setResizeMode(QHeaderView.Stretch)
        elif QT_API == "PYQT5":
            self.tableViewBoundariesNames.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)


    @pyqtSlot()
    def slotISUIST(self):
        """
        Input ISUIST.
        """
        if self.checkBoxISUIST.isChecked():
            status = "on"
        else:
            status = "off"
        self.model.setRestartStatisticsStatus(status)


    @pyqtSlot(str)
    def slotNBCLST(self, text):
        """
        Input NBCLST.
        """
        if self.lineEditNBCLST.validator().state == QValidator.Acceptable:
            value = from_qvariant(text, int)
            self.model.setGroupOfParticlesValue(value)

    @pyqtSlot()
    def slotISTALA(self):
        """
        Input ISTALA.
        """
        if self.groupBoxISTALA.isChecked():

            self.model.setVolumeStatisticsStatus("on")
            self._initVolumicNames()

        else:

            self.model.setVolumeStatisticsStatus("off")
            if hasattr(self, "modelVolumicNames"):
                del self.modelVolumicNames


    @pyqtSlot()
    def slotIDSTNT(self):
        """
        Input IDSTNT.
        """
        if self.lineEditIDSTNT.validator().state == QValidator.Acceptable:
            text = self.lineEditIDSTNT.text()
            value = from_qvariant(text, int)
            valnds =  self.model.getIterSteadyStart()

            if value > valnds:
                self.lineEditNSTIST.setText(str(value))
                self.model.setIterSteadyStart(value)
            else:
                valndsl = from_qvariant(self.lineEditNSTIST.text(), int)
                self.model.setIterSteadyStart(valndsl)

            self.model.setIterationStart(value)


    @pyqtSlot()
    def slotNSTIST(self):
        """
        Input NSTIST.
        """
        if self.lineEditNSTIST.validator().state == QValidator.Acceptable:
            text = self.lineEditNSTIST.text()
            value = from_qvariant(text, int)
            valids =  self.model.getIterationStart()

            if value < valids:
                self.lineEditIDSTNT.setText(str(value))
                self.model.setIterationStart(value)
            else:
                validsl = from_qvariant(self.lineEditIDSTNT.text(), int)
                self.model.setIterationStart(validsl)

            self.model.setIterSteadyStart(value)


    @pyqtSlot(str)
    def slotSEUIL(self, text):
        """
        Input SEUIL.
        """
        if self.lineEditSEUIL.validator().state == QValidator.Acceptable:
            value = from_qvariant(text, float)
            self.model.setThresholdValue(value)


    @pyqtSlot()
    def slotIENSI3(self):
        """
        Input IENSI3.
        """
        if self.groupBoxIENSI3.isChecked():

            self.model.setBoundaryStatisticsStatus("on")
            self._initBoundariesNames()

        else:

            self.model.setBoundaryStatisticsStatus("off")
            if hasattr(self, "modelBoundariesNames"):
                del self.modelBoundariesNames


    @pyqtSlot(str)
    def slotNSTBOR(self, text):
        """
        Input NSTBOR.
        """
        if self.lineEditNSTBOR.validator().state == QValidator.Acceptable:
            value = from_qvariant(text, int)
            self.model.setIterationStartBoundary(value)


    def tr(self, text):
        """
        Translation
        """
        return text


#-------------------------------------------------------------------------------
# Testing part
#-------------------------------------------------------------------------------


if __name__ == "__main__":
    pass


#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------