Exemplo n.º 1
0
    def slotFormula(self):
        """
        Run formula editor.
        """
        exp = self.mdl.getFormula()

        exp, req, sca, symb = self.mdl.getFormulaViscComponents()

        if self.mdl.getViscosity() == 'isotrop':
            exa = MobileMeshView.viscosity_iso
        else:
            exa = MobileMeshView.viscosity_ortho

        dialog = QMegEditorView(parent = self,
                                function_type = 'vol',
                                zone_name     = "all_cells",
                                variable_name = "mesh_viscosity",
                                expression    = exp,
                                required      = req,
                                symbols       = symb,
                                known_fields  = [],
                                examples      = exa)
        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaMobileMeshView -> %s" % str(result))
            self.mdl.setFormula(str(result))
            self.pushButtonFormula.setStyleSheet("background-color: green")
            self.pushButtonFormula.setToolTip(result)
Exemplo n.º 2
0
    def slotRichardsFormula(self):
        """
        """
        exa = """#example: """

        exp, req, sym = self.mdl.getRichardsFormulaComponents(self.zone_id)

        zone_name = self.zone.getLabel()

        dialog = QMegEditorView(parent=self,
                                function_type='src',
                                zone_name=zone_name,
                                variable_name="richards",
                                expression=exp,
                                required=req,
                                symbols=sym,
                                examples=exa,
                                source_type='momentum_source_term')

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotRichardsFormula -> %s" % str(result))
            self.mdl.setRichardsFormula(self.zone_id, str(result))
            self.pushButtonRichards.setToolTip(result)
            self.pushButtonRichards.setStyleSheet("background-color: green")
Exemplo n.º 3
0
    def slotThermalFormula(self):
        """
        Input the initial formula of thermal scalar
        """
        exa = """#example: """

        exp, req, sym, knf = self.mdl.getThermalFormulaComponents(
            self.zone_id, self.th_sca_name)
        zone_name = self.zone.getLabel()

        dialog = QMegEditorView(parent=self,
                                function_type='src',
                                zone_name=zone_name,
                                variable_name=self.th_sca_name,
                                expression=exp,
                                required=req,
                                symbols=sym,
                                known_fields=knf,
                                examples=exa,
                                source_type='thermal_source_term')

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaThermal -> %s" % str(result))
            self.mdl.setThermalFormula(self.zone_id, self.th_sca_name,
                                       str(result))
            self.pushButtonThermal.setToolTip(result)
            self.pushButtonThermal.setStyleSheet("background-color: green")
Exemplo n.º 4
0
    def slotFormula(self):
        """
        """
        exp = self.mdl.getFormula(self.label_select)
        exa = """#example: a line segment between (x0, y0, z0) and (x1, y1, z1)
#(s, the parameter is always between 0 and 1)
x0 = 3.2;
x1 = 2;
y0 = 2;
y1 = 2;
z0 = 5;
z1 = -0.5;
x = x1*s + x0*(1.-s);
y = y1*s + y0*(1.-s);
z = z1*s + z0*(1.-s);"""
        req = [('x', "x formula"), ('y', "y formula"), ('z', "z formula")]
        sym = [('s', 'parameter')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(self,
                                function_type='pfl',
                                zone_name=self.label_select,
                                variable_name='coords',
                                expression=exp,
                                required=req,
                                symbols=sym,
                                examples=exa)
        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotLineFormula -> %s" % str(result))
            self.mdl.setFormula(self.label_select, str(result))
            self.pushButtonFormula.setToolTip(result)
            self.pushButtonFormula.setStyleSheet("background-color: green")
Exemplo n.º 5
0
    def slotSpeciesGroundWaterFormula(self):
        """
        """
        exa = """#example: """

        exp, req, sym, knf = self.mdl.getGroundWaterSpeciesFormulaComponents(
            self.zone_id, self.scalar)
        zone_name = self.zone.getLabel()

        dialog = QMegEditorView(parent=self,
                                function_type='src',
                                zone_name=zone_name,
                                variable_name=self.scalar,
                                expression=exp,
                                required=req,
                                symbols=sym,
                                known_fields=knf,
                                examples=exa,
                                source_type='scalar_source_term')

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotSpeciesGroundWaterFormula -> %s" % str(result))
            self.mdl.setGroundWaterSpeciesFormula(self.zone_id, self.scalar,
                                                  str(result))
            self.pushButtonSpecies2.setToolTip(result)
            self.pushButtonSpecies2.setStyleSheet("background-color: green")
Exemplo n.º 6
0
    def slotExplicitFormula(self):
        """
        Explicit formula for variable porosity
        """

        objId = self.current_obj

        exp, req, sym = self.ibm.getIBMFormulaComponents(objId-1)
        exa = """if (x < 0.5)
                   indicator = 0;
                 else
                   indicator = 1;"""

        name = self.ibm.getObjectName(objId)

        dialog = QMegEditorView(parent        = self,
                                function_type = 'ibm',
                                zone_name     = name,
                                variable_name = 'porosity',
                                expression    = exp,
                                required      = req,
                                symbols       = sym,
                                known_fields  = [],
                                examples      = exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotExplicitFormula -> %s" % str(result))
            self.ibm.setObjectFormula(objId-1, result)
            self.pushButtonExplicit.setStyleSheet("background-color: green")
            self.pushButtonExplicit.setToolTip(exp)
Exemplo n.º 7
0
    def slotHydraulicHeadFormula(self):
        """
        """
        exp = self.__boundary.getHydraulicHeadFormula()
        exa = """#example: """
        req = [("H", "hydraulic head")]

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name='hydraulic_head',
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition='dirichlet_formula',
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotHydraulicHeadFormula -> %s" % str(result))
            self.__boundary.setHydraulicHeadFormula(str(result))
            self.pushButtonHydraulicHead.setStyleSheet(
                "background-color: green")
            self.pushButtonHydraulicHead.setToolTip(result)
    def slotFormula(self, name):
        """
        User formula for a given saturation property.
        """

        exp, req, sca, symbols = self.mdl.getFormulaComponents(
            'none', name, zone=self.zone_id)

        if not exp:
            exp = self.mdl.getDefaultFormula('none', name)

        exa = self.mdl.getExampleFormula('none', name)

        dialog = QMegEditorView(parent=self,
                                function_type='vol',
                                zone_name=self.zone_name,
                                variable_name=name,
                                expression=exp,
                                required=req,
                                symbols=symbols,
                                known_fields=sca,
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            _k = self.sat_ppts[name]
            _button = getattr(self, "pushButton" + _k)
            log.debug("slotFormula%s -> %s" % (_k, str(result)))
            self.mdl.setFormula('none', name, result, zone=self.zone_id)
            _button.setStyleSheet(_ok_str)
            _button.setToolTip(result)
    def __slotDirectionFormula(self):
        """
        """
        exp = self.__boundary.getDirection(self.__currentField, 'direction_formula')

        req = [('dir_x', 'Direction of the flow along X'),
               ('dir_y', 'Direction of the flow along Y'),
               ('dir_z', 'Direction of the flow along Z')]

        exa = "dir_x = 3.0;\ndir_y = 1.0;\ndir_z = 0.0;\n"

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"),
               ('dt', 'time step'),
               ('t', 'current time'),
               ('iter', 'number of iteration')]

        dialog = QMegEditorView(parent        = self,
                                function_type = "bnd",
                                zone_name     = self.__boundary._label,
                                variable_name = "direction_"+str(self.__currentField),
                                expression    = exp,
                                required      = req,
                                symbols       = sym,
                                condition     = "formula",
                                examples      = exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaDirection -> %s" % str(result))
            self.__boundary.setDirection(self.__currentField, 'direction_formula', result)
            self.pushButtonDirectionFormula.setToolTip(result)
            self.pushButtonDirectionFormula.setStyleSheet("background-color: green")
Exemplo n.º 10
0
    def slotMomentumFormula(self):
        """
        Set momentumFormula of the source term
        """
        exa = """#example:\n
tau = 10.; # relaxation time (s)\n
vel_x_imp = 1.5; #target velocity (m/s)\n
Su = rho * (vel_x_imp - u) / tau;\n
dSudu = - rho / tau; # Jacobian of the source term"""

        exp, req, sym = self.mdl.getMomentumFormulaComponents(self.zone_id)
        knf = [('rho', 'density')]
        zone_name = self.zone.getLabel()

        dialog = QMegEditorView(parent=self,
                                function_type='src',
                                zone_name=zone_name,
                                variable_name="momentum",
                                expression=exp,
                                required=req,
                                symbols=sym,
                                known_fields=knf,
                                examples=exa,
                                source_type='momentum_source_term')

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaVelocity -> %s" % str(result))
            self.mdl.setMomentumFormula(self.zone_id, str(result))
            self.pushButtonMomentum.setToolTip(result)
            self.pushButtonMomentum.setStyleSheet("background-color: green")
Exemplo n.º 11
0
    def __slotFormula(self):
        """
        Run formula editor.
        """
        exp = self.__boundary.getALEFormula()
        c = self.__boundary.getALEChoice()

        if c == "fixed_velocity":
            if not exp:
                exp = 'mesh_velocity[0] = 0.;\nmesh_velocity[1] = 0.;\nmesh_velocity[2] = 0.;'
            req = [('mesh_velocity[0]', 'Fixed velocity of the mesh'),
                   ('mesh_velocity[1]', 'Fixed velocity of the mesh'),
                   ('mesh_velocity[2]', 'Fixed velocity of the mesh')]
            exa = 'mesh_velocity[0] = 0.;\nmesh_velocity[1] = 0.;\nmesh_velocity[2] = 1.;'
        elif c == "fixed_displacement":
            if not exp:
                exp = 'mesh_displacement[0] = 0.;\nmesh_displacement[1] = 0.;\nmesh_displacement[2] = 0.;'
            req = [('mesh_displacement[0]', 'Fixed displacement of the mesh'),
                   ('mesh_displacement[1]', 'Fixed displacement of the mesh'),
                   ('mesh_displacement[2]', 'Fixed displacement of the mesh')]
            exa = 'mesh_displacement[0] = 0.;\nmesh_displacement[1] = 0.;\nmesh_displacement[2] = 1.;'

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name='mesh_velocity',
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition=c,
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaMobileMeshBoundary -> %s" % str(result))
            self.__boundary.setFormula(str(result))
            self.pushButtonMobilBoundary.setStyleSheet(
                "background-color: green")
            self.pushButtonMobilBoundary.setToolTip(result)
    def __slotVelocityFormula(self):
        """
        """
        exp = self.__boundary.getVelocity(self.__currentField)
        c = self.__boundary.getVelocityChoice(self.__currentField)
        if c == 'norm_formula':
            req = [('u_norm', 'Norm of the velocity')]
            exa = "u_norm = 1.0;"
        elif c == 'flow1_formula':
            req = [('q_m', 'Mass flow rate')]
            exa = "q_m = 1.0;"

        if c == 'norm_formula':
            sym = [('x', "X face's gravity center"),
                   ('y', "Y face's gravity center"),
                   ('z', "Z face's gravity center"),
                   ('dt', 'time step'),
                   ('t', 'current time'),
                   ('iter', 'number of iteration'),
                   ('surface', 'Boundary zone surface')]

        elif c == 'flow1_formula':
            sym = [('dt', 'time step'),
                   ('t', 'current time'),
                   ('iter', 'number of iteration'),
                   ('surface', 'Boundary zone surface')]

        for (name, val) in self.notebook.getNotebookList():
            sym.append((name, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(parent        = self,
                                function_type = "bnd",
                                zone_name     = self.__boundary._label,
                                variable_name = "velocity_"+str(self.__currentField),
                                expression    = exp,
                                required      = req,
                                symbols       = sym,
                                condition     = c,
                                examples      = exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaVelocity -> %s" % str(result))
            self.__boundary.setVelocity(self.__currentField, result)
            self.pushButtonVelocityFormula.setToolTip(result)
            self.pushButtonVelocityFormula.setStyleSheet("background-color: green")
    def slotPotVectorFormula(self):
        """
        """
        exp = self.__b.getElecScalarFormula(self.potVect, self.potVec_type)
        exa = """#example: """

        if not exp:
            exp = self.potVect + "[0] = 0;\n" + \
                  self.potVect + "[1] = 0;\n" + \
                  self.potVect + "[2] = 0;\n"

        req = [(self.potVect + "[0]", 'vector potential X'),
               (self.potVect + "[1]", 'vector potential Y'),
               (self.potVect + "[2]", 'vector potential Z')]

        sym = [('x', "X cell's gravity center"),
               ('y', "Y cell's gravity center"),
               ('z', "Z cell's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        c = self.__b.getElecScalarChoice(self.potVect)

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name=self.potVect,
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition=c,
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotPotVectorFormula -> %s" % str(result))
            self.__b.setElecScalarFormula(self.potVect, self.potVec_type,
                                          str(result))
            self.pushButtonPotVectorFormula.setToolTip(result)
            self.pushButtonPotVectorFormula.setStyleSheet(
                "background-color: green")
    def getScalarFormula(self, variable_name, exp_type, exp):
        """
        """
        result = None

        exa = """#example: """
        if exp_type == 'dirichlet_formula':
            req = [(variable_name, str(variable_name))]
        elif exp_type == 'neumann_formula':
            req = [("flux", "flux")]
        elif exp_type == 'exchange_coefficient_formula':
            req = [(variable_name, str(variable_name)),
                   ("hc", "heat coefficient")]

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        c = self.__boundary.getScalarChoice(variable_name)
        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name=variable_name,
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition=c,
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotSpeciesFormula -> %s" % str(result))
            self.__b.setElecScalarFormula(variable_name, exp_type, str(result))

        return result
    def __slotDirectionFormula(self):
        """
        """
        exp = self.__boundary.getDirection('direction_formula')

        req = [('dir_x', 'Direction of the flow along X'),
               ('dir_y', 'Direction of the flow along Y'),
               ('dir_z', 'Direction of the flow along Z')]

        exa = "dir_x = 3.0;\ndir_y = 1.0;\ndir_z = 0.0;\n"

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name='direction',
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition='formula',
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaDirection -> %s" % str(result))
            self.__boundary.setDirection('direction_formula', str(result))
            self.pushButtonDirectionFormula.setToolTip(result)
            self.pushButtonDirectionFormula.setStyleSheet(
                "background-color: green")
Exemplo n.º 16
0
    def slotHeadLossesFormula(self):
        """
        """
        exp = self.__boundary.getHeadLossesFormula()
        if not exp:
            exp = "K = 0.;"

        req = [('K', 'External head losses')]

        exa = "K = 0.;"

        sym = [('x', "X face's gravity center"),
               ('y', "Y face's gravity center"),
               ('z', "Z face's gravity center"), ('dt', 'time step'),
               ('t', 'current time'), ('iter', 'number of iteration'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name='head_loss',
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition='formula',
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaDirection -> %s" % str(result))
            self.__boundary.setHeadLossesFormula(str(result))
            self.pushButtonHeadLossesFormula.setStyleSheet(
                "background-color: green")
            self.pushButtonHeadLossesFormula.setToolTip(result)
    def __slotFormula(self, checked):
        """
        Run formula editor.
        """
        # Read current expression
        name = str(self.getBoundaryName())
        exp = self.getBoundaryDefinedValue()

        if not exp:
            exp = self.__default

        # run the editor
        dialog = QMegEditorView(self.parent,
                                function_type='fsi',
                                zone_name=name,
                                variable_name=self.object_type,
                                expression=exp,
                                required=self.__required,
                                symbols=self.__symbols,
                                examples=self.__examples)
        if dialog.exec_():
            result = dialog.get_result()
            log.debug("FormulaCoupling -> %s" % str(result))
            self.setBoundaryDefinedValue(result)
Exemplo n.º 18
0
    def __slotTurbulenceFormula(self):
        """
        INPUT user formula
        """
        sym = [('x','cell center coordinate'),
               ('y','cell center coordinate'),
               ('z','cell center coordinate'),
               ('t','time'),
               ('dt','time step'),
               ('iter','number of time step'),
               ('surface', 'Boundary zone surface')]

        for (nme, val) in self.notebook.getNotebookList():
            sym.append((nme, 'value (notebook) = ' + str(val)))

        exa_base = """#example:
uref2 = 10.;
dh = 0.2;
rho0 = 1.17862;
mu0 = 1.83e-05;

re = sqrt(uref2)*dh*rho0/mu0;

if (re < 2000) {
  # in this case u*^2 is directly calculated to
  # avoid a problem with xlmbda=64/Re when Re->0
  ustar2 = 8.*mu0*sqrt(uref2)/rho0/dh;
}
else if (re < 4000) {
  xlmbda = 0.021377 + 5.3115e-6*re;
  ustar2 = uref2*xlmbda/8.;
}
else {
  xlmbda = 1/( 1.8*log(re)/log(10.)-1.64)^2;
  ustar2 = uref2*xlmbda/8.;
}
cmu = 0.09;
kappa = 0.42;
"""

        turb_model = TurbulenceModel(self.case).getTurbulenceModel()
        if turb_model in ('k-epsilon', 'k-epsilon-PL'):

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = exa_base + """

k = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);"""

            req = [('k', "turbulent energy"),
                   ('epsilon', "turbulent dissipation")]

            dialog = QMegEditorView(parent        = self,
                                    function_type = 'bnd',
                                    zone_name     = self.__boundary._label,
                                    variable_name = 'turbulence_ke',
                                    expression    = exp,
                                    required      = req,
                                    symbols       = sym,
                                    condition     = 'formula',
                                    examples      = exa)


            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)

        elif turb_model in ('Rij-epsilon', 'Rij-SSG'):

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)

            exa = exa_base + """
d2s3 = 2/3;

k = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);
r11 = d2s3*k;
r22 = d2s3*k;
r33 = d2s3*k;
r12 = 0;
r13 = 0;
r23 = 0;
"""

            req = [('r11', "Reynolds stress R11"),
                   ('r22', "Reynolds stress R22"),
                   ('r33', "Reynolds stress R33"),
                   ('r12', "Reynolds stress R12"),
                   ('r23', "Reynolds stress R13"),
                   ('r13', "Reynolds stress R23"),
                   ('epsilon', "turbulent dissipation")]

            dialog = QMegEditorView(parent        = self,
                                    function_type = 'bnd',
                                    zone_name     = self.__boundary._label,
                                    variable_name = 'turbulence_rije',
                                    expression    = exp,
                                    required      = req,
                                    symbols       = sym,
                                    examples      = exa)

            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)

        elif turb_model == 'Rij-EBRSM':

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)

            exa = exa_base + """
d2s3 = 2/3;

k = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);
r11 = d2s3*k;
r22 = d2s3*k;
r33 = d2s3*k;
r12 = 0;
r13 = 0;
r23 = 0;
alpha =  1.;
"""

            req = [('r11', "Reynolds stress R11"),
                   ('r22', "Reynolds stress R22"),
                   ('r33', "Reynolds stress R33"),
                   ('r12', "Reynolds stress R12"),
                   ('r23', "Reynolds stress R13"),
                   ('r13', "Reynolds stress R23"),
                   ('epsilon', "turbulent dissipation"),
                   ('alpha', "alpha")]

            dialog = QMegEditorView(parent        = self,
                                    function_type = 'bnd',
                                    zone_name     = self.__boundary._label,
                                    variable_name = 'turbulence_rij_ebrsm',
                                    expression    = exp,
                                    required      = req,
                                    symbols       = sym,
                                    examples      = exa)

            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)

        elif turb_model == 'v2f-BL-v2/k':

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)

            exa = exa_base + """
d2s3 = 2/3;

k   = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);
phi = d2s3;
alpha = 0;"""

            req = [('k', "turbulent energy"),
                   ('epsilon', "turbulent dissipation"),
                   ('phi', "variable phi in v2f model"),
                   ('alpha', "variable alpha in v2f model")]

            dialog = QMegEditorView(parent = self,
                                    function_type = 'bnd',
                                    zone_name = self.__boundary._label,
                                    variable_name = 'turbulence_v2f',
                                    expression = exp,
                                    required = req,
                                    symbols = sym,
                                    condition = 'formula',
                                    examples = exa)

            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)

        elif turb_model == 'k-omega-SST':

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)

            exa = exa_base + """

k = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);
omega = epsilon/(cmu * k);"""

            req = [('k', "turbulent energy"),
                   ('omega', "specific dissipation rate")]

            dialog = QMegEditorView(parent        = self,
                                    function_type = 'bnd',
                                    zone_name     = self.__boundary._label,
                                    variable_name = 'turbulence_kw',
                                    expression    = exp,
                                    required      = req,
                                    symbols       = sym,
                                    condition     = 'formula',
                                    examples      = exa)

            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)

        elif turb_model == 'Spalart-Allmaras':

            exp = self.__boundary.getTurbFormula()
            if not exp:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)

            exa = exa_base + """

k = ustar2/sqrt(cmu);
epsilon = ustar2^1.5/(kappa*dh*0.1);

nu_tilda = _epsilon/(cmu * _k);"""

            req = [('nu_tilda', "nu_tilda")]

            dialog = QMegEditorView(parent        = self,
                                    function_type = 'bnd',
                                    zone_name     = self.__boundary._label,
                                    variable_name = 'turbulence_spalart',
                                    expression    = exp,
                                    required      = req,
                                    symbols       = sym,
                                    condition     = 'formula',
                                    examples      = exa)

            if dialog.exec_():
                result = dialog.get_result()
                log.debug("slotFormulaTurb -> %s" % str(result))
                self.__boundary.setTurbFormula(str(result))
                self.pushButtonTurb.setStyleSheet("background-color: green")
                self.pushButtonTurb.setToolTip(result)
    def __slotTurbulenceFormula(self):
        """
        User formula for turbulence
        """
        turb_model = TurbulenceModel(self.case).getTurbulenceModel(
            self.__currentField)

        exp, req, sym = \
            self.__boundary.getTurbFormulaComponents(self.__currentField,
                                                     turb_model)

        # Set model name and specific examples
        if turb_model in ('k-epsilon', 'k-epsilon_linear_production'):
            if exp in _empty_exps:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = """#example :
uref2 = 10.;
dh = 0.2;
re = sqrt(uref2)*dh*rho0/mu0;

if (re < 2000){
#     in this case u*^2 is directly calculated to not have a problem with
#     xlmbda=64/Re when Re->0

  ustar2 = 8.*mu0*sqrt(uref2)/rho0/dh;}

else if (re<4000){

  xlmbda = 0.021377 + 5.3115e-6*re;
  ustar2 = uref2*xlmbda/8.;}

else {

  xlmbda = 1/( 1.8*log(re)/log(10.)-1.64)^2;
  ustar2 = uref2*xlmbda/8.;}

cmu = 0.09;
kappa = 0.42;
k   = ustar2/sqrt(cmu);
eps = ustar2^1.5/(kappa*dh*0.1);"""

            name = 'turbulence_ke_%s' % (self.__currentField)

        elif turb_model in ('rij-epsilon_ssg', 'rij-epsilon_ebrsm'):
            if exp in _empty_exps:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = """#exemple :
uref2 = 10.;
dh = 0.2;
re = sqrt(uref2)*dh*rho0/mu0;

if (re < 2000){
#     in this case u*^2 is directly calculated to not have a problem with
#     xlmbda=64/Re when Re->0

  ustar2 = 8.*mu0*sqrt(uref2)/rho0/dh;}

else if (re<4000){

  xlmbda = 0.021377 + 5.3115e-6*re;
  ustar2 = uref2*xlmbda/8.;}

else {

  xlmbda = 1/( 1.8*log(re)/log(10.)-1.64)^2;
  ustar2 = uref2*xlmbda/8.;}

cmu = 0.09;
kappa = 0.42;
k   = ustar2/sqrt(cmu);
eps = ustar2^1.5/(kappa*dh*0.1);
d2s3 = 2/3;
R11 = d2s3*k;
R22 = d2s3*k;
R33 = d2s3*k;
R12 = 0;
R13 = 0;
R23 = 0;
"""
            name = 'turbulence_rije_%s' % (self.__currentField)

        elif turb_model in ('tchen', 'q2-q12'):
            name = 'turbulence_tchen_%s' % (self.__currentField)
            if exp in _empty_exps:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = """#example :
q2 = 5.e-05;
q12 = 0.0001;"""

        elif turb_model in ('r2-q12'):
            name = 'turbulence_r2q12_%s' % (self.__currentField)
            if exp in _empty_exps:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = """#example :
R11 = 5e-05;
R22 = 5e-05;
R33 = 5e-05;
R12 = 5e-05;
R13 = 5e-05;
R23 = 5e-05;
q12 = 0.0001;"""

        elif turb_model in ('r2-r12-tchen'):
            name = 'turbulence_r2r12_%s' % (self.__currentField)
            if exp in _empty_exps:
                exp = self.__boundary.getDefaultTurbFormula(turb_model)
            exa = """#example :
R11 = 5e-05;
R22 = 5e-05;
R33 = 5e-05;
R12 = 5e-05;
R13 = 5e-05;
R23 = 5e-05;
R12-11 = 5e-05;
R12-22 = 5e-05;
R12-33 = 5e-05;
R12-12 = 5e-05;
R12-13 = 5e-05;
R12-23 = 5e-05;"""

        dialog = QMegEditorView(parent=self,
                                function_type='bnd',
                                zone_name=self.__boundary._label,
                                variable_name=name,
                                expression=exp,
                                required=req,
                                symbols=sym,
                                condition="formula",
                                examples=exa)

        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotFormulaTurb -> %s" % str(result))
            self.__boundary.setTurbFormula(self.__currentField, result)
            self.pushButtonTurb.setToolTip(result)
            self.pushButtonTurb.setStyleSheet("background-color: green")