Ejemplo n.º 1
0
    def writeOutput(self):
        if self.ui.checkBoxMesh.isChecked():
            fh.writeT3S(self.mesh.nodMesh, self.mesh.mesh, self.ui.lineEditMesh.text())
        if self.ui.checkBoxIP.isChecked():
            fh.writeI3S(self.mesh.nodInterp, self.mesh.proInterp, self.ui.lineEditIP.text())
        if self.ui.checkBoxLE.isChecked():
            LE = {1:mc.getNodeIDsLeft(self.mesh.proMesh)}
            fh.writeI3S(self.mesh.nodMesh, LE, self.ui.lineEditLE.text())
        if self.ui.checkBoxRE.isChecked():
            RE = {1:mc.getNodeIDsRight(self.mesh.proMesh)}
            fh.writeI3S(self.mesh.nodMesh, RE, self.ui.lineEditRE.text())
        if self.ui.checkBoxOL.isChecked():
            OL = {1:mc.getNodeIDsOutline(self.mesh.proMesh)}
            fh.writeI3S(self.mesh.nodMesh, OL, self.ui.lineEditOL.text())

        if self.ui.checkBoxWS.isChecked():
            view = """"""
            counter = -1
            content = """"""

            content += ws.lineSet.format(self.getDim(self.ui.lineEditProfiles), self.getPath(self.ui.lineEditProfiles), "0xff0000", "raw profiles")
            counter += 1
            view += ":ObjectView {0} 0\n".format(counter)

            content += ws.lineSet.format(self.getDim(self.ui.lineEditReach), self.getPath(self.ui.lineEditReach), "0xffff00", "channel reach")
            counter += 1
            view += ":ObjectView {0} 0\n".format(counter)

            if self.ui.checkBoxLBL.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditLBL), self.getPath(self.ui.lineEditLBL), "0x00ff00", "left breakline")
                counter += 1
                view += ":ObjectView {0} 0\n".format(counter)

            if self.ui.checkBoxRBL.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditRBL), self.getPath(self.ui.lineEditRBL), "0x00ff00", "right breakline")
                counter += 1
                view += ":ObjectView {0} 0\n".format(counter)

            if self.ui.checkBoxLBO.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditLBO), self.getPath(self.ui.lineEditLBO), "0x0000ff", "left boundary")
                counter += 1
                view += ":ObjectView {0} 0\n".format(counter)

            if self.ui.checkBoxRBO.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditRBO), self.getPath(self.ui.lineEditRBO), "0x0000ff", "right boundary")
                counter += 1
                view += ":ObjectView {0} 0\n".format(counter)

            content += ws.meshScalar.format(self.getPath(self.ui.lineEditMesh), "0xc0c0c0", "mesh")
            counter += 1
            view += ":ObjectView {0} 0\n".format(counter)


            if self.ui.checkBoxIP.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditIP), self.getPath(self.ui.lineEditIP), "0x8000ff", "interpolated profiles")
                counter += 1
                view += ":ObjectView {0} 1\n".format(counter)

            if self.ui.checkBoxLE.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditLE), self.getPath(self.ui.lineEditLE), "0x0080ff", "left edge")
                counter += 1
                view += ":ObjectView {0} 1\n".format(counter)

            if self.ui.checkBoxRE.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditRE), self.getPath(self.ui.lineEditRE), "0x0080ff", "right edge")
                counter += 1
                view += ":ObjectView {0} 1\n".format(counter)

            if self.ui.checkBoxOL.isChecked():
                content += ws.lineSet.format(self.getDim(self.ui.lineEditOL), self.getPath(self.ui.lineEditOL), "0x800080", "outline")
                counter += 1
                view += ":ObjectView {0} 1\n".format(counter)

            content += ws.meshScalar.format(self.getPath(self.ui.lineEditMesh), "0x808080", "mesh")
            counter += 1
            view += ":ObjectView {0} 1\n".format(counter)

            fh.writeEWS(content, view, self.ui.lineEditWS.text())
Ejemplo n.º 2
0
    def create(self):

#        try:
        SMS_elements, \
            SMS_nodes,\
            SMS_strings,\
            SMS_materials,\
            SMS_bc_nodes,\
            SMS_bc_strings_1,\
            SMS_bc_strings_2,\
            SMS_bc_strings_3,\
            SMS_bc_strings_4,\
            SMS_bc_strings_5,\
            SMS_bc_strings_6,\
            SMS_bc_strings_7 = fh.read2DM(self.ui.lineEditInput.text())
#        except:
#            QMessageBox.critical(self.widget, "Error", "Not able to load file!\nCheck filename or content!")
#            return

        # BK_materials = {BK_node_id: strickler's value}
        BK_materials = {}
        
        # MAP_node_id = {SMS_node_id: BK_node_id}
        MAP_node_id = {}
        
        # BK_nodes = {BK_node_id: [x, y, z]}
        BK_nodes = {}        
        
        # BK_elements = {element_id: [BK_node_id, BK_node_id, BK_node_id (, BK_node_id), SMS_material_id]}
        BK_elements = {}
        
        # map BK nodes to SMS nodes
        i = 0
        for key in SMS_nodes:
            i += 1
            BK_nodes[i] = SMS_nodes[key]
            MAP_node_id[key] = i

        # convert SMS mesh to BK mesh
        i = 0
        impermeableMaterialID = self.ui.spinBoxImpermeable.value()
        material_added = False

        for key in SMS_elements:
            if len(SMS_elements[key]) == 4:
                node_0 = SMS_elements[key][0]
                node_1 = SMS_elements[key][1]
                node_2 = SMS_elements[key][2]
                material = SMS_elements[key][3]
                
                if material_added is False:
                    if material not in SMS_materials:
                        SMS_materials[material] = 0.0
                        material_added = True
                    
                BK_materials[MAP_node_id[node_0]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_1]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_2]] = SMS_materials[material]
                
                if self.ui.checkBoxImpermeable.isChecked():
                    if material != impermeableMaterialID:
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                else:
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                        
            elif len(SMS_elements[key]) == 5:
                node_0 = SMS_elements[key][0]
                node_1 = SMS_elements[key][1]
                node_2 = SMS_elements[key][2]
                node_3 = SMS_elements[key][3]
                material = SMS_elements[key][4]
                
                if material_added is False:
                    if material not in SMS_materials:
                        SMS_materials[material] = 0.0
                        material_added = True
                        
                BK_materials[MAP_node_id[node_0]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_1]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_2]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_3]] = SMS_materials[material]
                
                if self.ui.checkBoxImpermeable.isChecked():
                    if material != impermeableMaterialID:
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_2], MAP_node_id[node_3]]
                else:
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_2], MAP_node_id[node_3]]
                        
        def getStrings(allstrings, strings):
            i = 1
            profiles = {}
            bk_profiles = {}
            for key in strings:
                profiles[i] = allstrings[key]
                bk_profiles[i] = []
                i += 1
            for pID in profiles:
                for nID in profiles[pID]:
                    bk_profiles[pID].append(MAP_node_id[nID])

            return bk_profiles
        
        info = ""
    
        if self.ui.checkBoxBottom.isChecked():
            try:
                fh.writeT3S(BK_nodes, BK_elements, self.ui.lineEditBottom.text())
                info += " - Bottom mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write bottom mesh!\n"

        if self.ui.lineEditInputData.text() != "":
            SMS_wsf = fh.readDAT(self.ui.lineEditInputData.text())
            BK_nodes_wsf = {}
            BK_nodes_dpth = {}
            for key in SMS_nodes:
                wsf = 0.0
                if SMS_wsf[MAP_node_id[key]] <= 0.000001:
                    wsf = SMS_nodes[key][2]
                else:
                    wsf = SMS_wsf[MAP_node_id[key]]
                BK_nodes_wsf[key] = [SMS_nodes[key][0], SMS_nodes[key][1], wsf]    
                BK_nodes_dpth[key] = [SMS_nodes[key][0], SMS_nodes[key][1], wsf-SMS_nodes[key][2]] 
            try:
                fh.writeT3S(BK_nodes_wsf, BK_elements, self.ui.lineEditWaterSurface.text())
                info += " - Water surface mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_wsf), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write water surface mesh!\n"
  
            try:
                fh.writeT3S(BK_nodes_dpth, BK_elements, self.ui.lineEditWaterDepth.text())
                info += " - Water depth mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_dpth), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write water depth mesh!\n"
                  
        if self.ui.checkBoxBottomFriction.isChecked():
            BK_nodes_mat = {}
            for key in BK_nodes:
                if key in BK_materials:
                    BK_nodes_mat[key] = [BK_nodes[key][0], BK_nodes[key][1], BK_materials[key]]
                else:
                    BK_nodes_mat[key] = [BK_nodes[key][0], BK_nodes[key][1], 0.0]                    
            try:
                fh.writeT3S(BK_nodes_mat, BK_elements, self.ui.lineEditBottomFriction.text())
                info += " - Bottom friction mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_mat), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write bottom friction mesh!\n"

        if self.ui.checkBoxCulvertHeight.isChecked():
            # convert SMS boundary condition nodes to BK points
            BK_bcNodes = {}
            for key in SMS_bc_nodes:
                height = SMS_bc_nodes[key] - SMS_nodes[key][2]
                BK_bcNodes[key] = [SMS_nodes[key][0], SMS_nodes[key][1], height]

            try:
                fh.writeXYZ(BK_bcNodes, self.ui.lineEditCulvertHeight.text())
                info += " - Culverts created with {0} nodes.\n".format(len(BK_bcNodes))
            except:
                info += " - ERROR: Not able to write culvert nodes!\n"
                                                                                        
        if self.ui.checkBoxNS1.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_1)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS1.text())
                info += " - Node string 1 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 1!\n"

        if self.ui.checkBoxNS2.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_2)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS2.text())
                info += " - Node string 2 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 2!\n"                               

        if self.ui.checkBoxNS3.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_3)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS3.text())
                info += " - Node string 3 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 3!\n"
                
        if self.ui.checkBoxNS4.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_4)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS4.text())
                info += " - Node string 4 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 4!\n"

        if self.ui.checkBoxNS5.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_5)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS5.text())
                info += " - Node string 5 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 5!\n"
                
        if self.ui.checkBoxNS6.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_6)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS6.text())
                info += " - Node string 6 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 6!\n"
                         
        if self.ui.checkBoxNS7.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_7)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS7.text())
                info += " - Node string 7 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 7!\n"

        QMessageBox.information(self.widget, "Module 2DM2BK", info)