File: BoundaryConditionsScalarViewNeptune.py

package info (click to toggle)
code-saturne 7.0.2%2Brepack-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,868 kB
  • sloc: ansic: 395,271; f90: 100,755; python: 86,746; cpp: 6,227; makefile: 4,247; xml: 2,389; sh: 1,091; javascript: 69
file content (200 lines) | stat: -rw-r--r-- 6,642 bytes parent folder | download
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
# -*- coding: utf-8 -*-

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

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2021 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:
- BoundaryConditionsScalarView
"""

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

import string, 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.Pages.BoundaryConditionsScalar import Ui_BoundaryConditionsScalar

from code_saturne.model.Common import GuiParam
from code_saturne.Base.QtPage import DoubleValidator, ComboModel, from_qvariant

from code_saturne.model.SpeciesModel import SpeciesModel

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

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

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

class BoundaryConditionsScalarView(QWidget, Ui_BoundaryConditionsScalar) :
    """
    Boundary condition for non condensable
    """
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_BoundaryConditionsScalar.__init__(self)
        self.setupUi(self)

        # Connections
        self.comboBoxScalar.activated[str].connect(self.__slotChoiceScalar)

        self.__Scalarmodel = ComboModel(self.comboBoxScalar, 1, 1)

        self.comboBoxScalarChoice.activated[str].connect(self.slotScalarTypeChoice)
        self.scalarChoiceModel = ComboModel(self.comboBoxScalarChoice, 1, 1)
        self.scalarChoiceModel.addItem(self.tr("Value"), 'dirichlet')
        self.scalarChoiceModel.addItem(self.tr("Flux"), 'flux')

        self.lineEditScalar.textChanged[str].connect(self.__slotScalar)

        validatorScalar = DoubleValidator(self.lineEditScalar)

        self.lineEditScalar.setValidator(validatorScalar)


    def setup(self, case, fieldId):
        """
        Setup the widget
        """
        self.case = case
        self.__boundary = None
        self.__currentField = fieldId


    def showWidget(self, boundary):
        """
        Show the widget
        """
        self.__boundary = boundary

        # For walls, current field is set to -1, hence the need for the list
        if boundary.getNature() == 'wall':
            fieldList = SpeciesModel(self.case).getFieldIdList(include_none=True)
        else:
            fieldList = [str(self.__currentField)]

        self.__scalarsList = []
        for f_id in fieldList:
            for species in SpeciesModel(self.case).getScalarByFieldId(f_id):
                self.__scalarsList.append((f_id, species))

        if len(self.__scalarsList) > 0 :
            for nb in range(len(self.__Scalarmodel.getItems())):
                self.__Scalarmodel.delItem(0)

            for var in self.__scalarsList :
                name = SpeciesModel(self.case).getScalarLabelByName(var[1])
                self.__Scalarmodel.addItem(self.tr(name), var[1])

            self.__currentScalar = self.__scalarsList[0]

            _f0, _s0 = self.__currentScalar

            self.__Scalarmodel.setItem(str_model=_s0)

            choice0 = self.__boundary.getScalarChoice(_f0, _s0)
            self.scalarChoiceModel.setItem(str_model=choice0)

            val = self.__boundary.getScalarValue(_f0, _s0)
            self.lineEditScalar.setText(str(val))
            self.show()
        else :
            self.hideWidget()


    def hideWidget(self):
        """
        Hide the widget
        """
        self.hide()


    @pyqtSlot(str)
    def __slotChoiceScalar(self, text):
        """
        INPUT choice of non condensable
        """
        for _s in self.__scalarsList:
            if _s[1] == self.__Scalarmodel.dicoV2M[str(text)]:
                self.__currentScalar = _s
                break

        _f_id, _sname = self.__currentScalar

        # Update condition type choice
        scalarModel = self.__boundary.getScalarChoice(_f_id, _sname)
        self.scalarChoiceModel.setItem(str_model=scalarModel)

        # Update value
        val = self.__boundary.getScalarValue(_f_id, _sname)
        self.lineEditScalar.setText(str(val))


    @pyqtSlot(str)
    def slotScalarTypeChoice(self, text):
        """
        INPUT Condition type choice for scalar
        """
        choice = self.scalarChoiceModel.dicoV2M[str(text)]

        _f_id, _sname = self.__currentScalar

        self.__boundary.setScalarChoice(_f_id, _sname, choice)

    @pyqtSlot(str)
    def __slotScalar(self, text):
        """
        INPUT non condensable value
        """
        if self.lineEditScalar.validator().state == QValidator.Acceptable:
            value = from_qvariant(text, float)

            _f_id, _sname = self.__currentScalar
            self.__boundary.setScalarValue(_f_id, _sname, value)


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