Exemplo n.º 1
0
    def _create_box(self, cart3d_filename, ID, form, cases, icase, regions):
        stack = True
        dirname = os.path.dirname(os.path.abspath(cart3d_filename))
        input_c3d_filename = os.path.join(dirname, 'input.c3d')
        input_cntl_filename = os.path.join(dirname, 'input.cntl')
        mach = None
        alpha = None
        beta = None
        if os.path.exists(input_cntl_filename):
            cntl = read_input_cntl(input_cntl_filename, log=self.log, debug=self.debug)
            mach, alpha, beta = cntl.get_flow_conditions()
            bcs = cntl.get_boundary_conditions()
            bc_xmin, bc_xmax, bc_ymin, bc_ymax, bc_xmin, bc_xmax, surfbcs = bcs
            #stack = False

            if surfbcs:
                bc_form = [
                    ('Rho', icase, []),
                    ('xVelocity', icase + 1, []),
                    ('yVelocity', icase + 2, []),
                    ('zVelocity', icase + 3, []),
                    ('Mach', icase + 4, []),
                    ('Pressure', icase + 5, []),
                ]
                icase += 5
                nelements = self.nElements
                rho = zeros(nelements, dtype='float32')
                xvel = zeros(nelements, dtype='float32')
                yvel = zeros(nelements, dtype='float32')
                zvel = zeros(nelements, dtype='float32')
                #vel = zeros(nelements, dtype='float32')
                pressure = zeros(nelements, dtype='float32')

                uregions = set(unique(regions))
                surf_bc_regions = set(surfbcs.keys())
                invalid_regions = surf_bc_regions - uregions
                if len(invalid_regions) != 0:
                    assert len(invalid_regions) == 0, invalid_regions

                for bc_id, bc_values in sorted(iteritems(surfbcs)):
                    rhoi, xveli, yveli, zveli, pressi = bc_values
                    i = where(regions == bc_id)[0]
                    rho[i] = rhoi
                    xvel[i] = xveli
                    yvel[i] = yveli
                    zvel[i] = zveli
                    pressure[i] = pressi

                mach = sqrt(xvel ** 2 + yvel ** 2 + zvel ** 2)

                rho_res = GuiResult(ID, header='Rho', title='Rho',
                                    location='centroid', scalar=rho)
                xvel_res = GuiResult(ID, header='xVelocity', title='xVelocity',
                                     location='centroid', scalar=xvel)
                yvel_res = GuiResult(ID, header='yVelocity', title='yVelocity',
                                     location='centroid', scalar=yvel)
                zvel_res = GuiResult(ID, header='zVelocity', title='zVelocity',
                                     location='centroid', scalar=zvel)
                mach_res = GuiResult(ID, header='Mach', title='Mach',
                                     location='centroid', scalar=mach)
                pressure_res = GuiResult(ID, header='Pressure', title='Pressure',
                                         location='centroid', scalar=pressure)

                cases[icase] = (rho_res, (ID, 'Rho'))
                cases[icase + 1] = (xvel_res, (ID, 'xVelocity'))
                cases[icase + 2] = (yvel_res, (ID, 'yVelocity'))
                cases[icase + 3] = (zvel_res, (ID, 'zVelocity'))
                cases[icase + 4] = (mach_res, (ID, 'Mach'))
                cases[icase + 5] = (pressure_res, (ID, 'Pressure'))
                form.append(('Boundary Conditions', None, bc_form))
        else:
            self.log.warning('input_cntl_filename doesnt exist = %s' % input_cntl_filename)


        if os.path.exists(input_c3d_filename):
            nodes, elements = read_input_c3d(input_c3d_filename, stack=stack,
                                             log=self.log, debug=self.debug)

            # Planes
            # ----------
            # xmin, xmax
            # ymin, ymax
            # zmin, zmax

            if stack:
                red = (1., 0., 0.)
                color = red
                self.set_quad_grid('box', nodes, elements, color, line_width=1, opacity=1.)
            else:
                red = (1., 0., 0.)
                inflow_nodes = []
                inflow_elements = []

                green = (0., 1., 0.)
                symmetry_nodes = []
                symmetry_elements = []

                colori = (1., 1., 0.)
                outflow_nodes = []
                outflow_elements = []

                blue = (0., 0., 1.)
                farfield_nodes = []
                farfield_elements = []

                ifarfield = 0
                isymmetry = 0
                iinflow = 0
                ioutflow = 0

                nfarfield_nodes = 0
                nsymmetry_nodes = 0
                ninflow_nodes = 0
                noutflow_nodes = 0
                for bcsi, nodesi, elementsi in zip(bcs, nodes, elements):
                    # 0 = FAR FIELD
                    # 1 = SYMMETRY
                    # 2 = INFLOW  (specify all)
                    # 3 = OUTFLOW (simple extrap)
                    self.log.info('bcsi = %s' % bcsi)
                    nnodes = nodesi.shape[0]
                    bc = bcsi
                    if isinstance(bc, int):
                        if bc == 0:
                            farfield_nodes.append(nodesi)
                            farfield_elements.append(elementsi + nfarfield_nodes)
                            nfarfield_nodes += nnodes
                            ifarfield += 1
                        elif bc == 1:
                            symmetry_nodes.append(nodesi)
                            symmetry_elements.append(elementsi + nsymmetry_nodes)
                            nsymmetry_nodes += nnodes
                            isymmetry += 1
                        elif bc == 2:
                            inflow_nodes.append(nodesi)
                            inflow_elements.append(elementsi + ninflow_nodes)
                            ninflow_nodes += nnodes
                            iinflow += 1
                        elif bc == 3:
                            outflow_nodes.append(nodesi)
                            outflow_elements.append(elementsi + noutflow_nodes)
                            noutflow_nodes += nnodes
                            ioutflow += 1
                        else:
                            msg = 'bc=%s' % str(bc)
                            raise NotImplementedError(msg)
                    elif isinstance(bc, dict):
                        continue
                    else:
                        msg = 'bc=%s' % str(bc)
                        raise NotImplementedError(msg)

                if ifarfield:
                    color = blue
                    nodes = vstack(farfield_nodes)
                    elements = vstack(farfield_elements)
                    self.set_quad_grid('farfield', nodes, elements, color, line_width=1, opacity=1.)

                if isymmetry:
                    color = green
                    nodes = vstack(symmetry_nodes)
                    elements = vstack(symmetry_elements)
                    self.set_quad_grid('symmetry', nodes, elements, color, line_width=1, opacity=1.)

                if iinflow:
                    color = red
                    nodes = vstack(inflow_nodes)
                    elements = vstack(inflow_elements)
                    self.set_quad_grid('inflow', nodes, elements, color, line_width=1, opacity=1.)

                if ioutflow:
                    color = colori
                    nodes = vstack(outflow_nodes)
                    elements = vstack(outflow_elements)
                    self.set_quad_grid('outflow', nodes, elements, color, line_width=1, opacity=1.)

                #i = 0
                #for nodesi, elementsi in zip(nodes, elements):
                    #self.set_quad_grid('box_%i' % i, nodesi, elementsi, color,
                                       #line_width=1, opacity=1.)
                    #i += 1
        else:
            self.log.warning('input_c3d_filename doesnt exist = %s' % input_c3d_filename)
        return mach, alpha, beta
Exemplo n.º 2
0
    def _create_box(self, cart3d_filename, ID, form, cases, icase, regions):
        """creates the bounding box for boundary conditions"""
        dirname = os.path.dirname(os.path.abspath(cart3d_filename))
        input_c3d_filename = os.path.join(dirname, 'input.c3d')
        input_cntl_filename = os.path.join(dirname, 'input.cntl')
        mach = None
        alpha = None
        beta = None
        unused_gamma = None

        bcs = None
        if os.path.exists(input_cntl_filename):
            cntl = read_input_cntl(input_cntl_filename,
                                   log=self.gui.log,
                                   debug=self.gui.debug)
            mach, alpha, beta, unused_gamma = cntl.get_flow_conditions()
            (unused_bc_xmin, unused_bc_xmax, unused_bc_ymin, unused_bc_ymax,
             unused_bc_xmin, unused_bc_xmax,
             surfbcs) = cntl.get_boundary_conditions()
            #stack = False

            if surfbcs:
                bc_form = [
                    ('Rho', icase, []),
                    ('xVelocity', icase + 1, []),
                    ('yVelocity', icase + 2, []),
                    ('zVelocity', icase + 3, []),
                    ('Mach', icase + 4, []),
                    ('Pressure', icase + 5, []),
                ]
                icase += 5
                nelements = self.gui.nelements
                rho = np.full(nelements, np.nan, dtype='float32')
                xvel = np.full(nelements, np.nan, dtype='float32')
                yvel = np.full(nelements, np.nan, dtype='float32')
                zvel = np.full(nelements, np.nan, dtype='float32')
                #vel = np.full(nelements, np.nan, dtype='float32')
                pressure = np.full(nelements, np.nan, dtype='float32')

                uregions = set(unique(regions))
                surf_bc_regions = set(surfbcs.keys())
                invalid_regions = surf_bc_regions - uregions
                if len(invalid_regions) != 0:
                    assert len(invalid_regions) == 0, invalid_regions

                for bc_id, bc_values in sorted(iteritems(surfbcs)):
                    rhoi, xveli, yveli, zveli, pressi = bc_values
                    i = where(regions == bc_id)[0]
                    rho[i] = rhoi
                    xvel[i] = xveli
                    yvel[i] = yveli
                    zvel[i] = zveli
                    pressure[i] = pressi

                inan = np.where(rho == 0.0)
                rho[inan] = np.nan
                xvel[inan] = np.nan
                yvel[inan] = np.nan
                zvel[inan] = np.nan
                #vel[inan] = np.nan
                pressure[inan] = np.nan

                mach = sqrt(xvel**2 + yvel**2 + zvel**2)

                rho_res = GuiResult(ID,
                                    header='Rho',
                                    title='Rho',
                                    location='centroid',
                                    scalar=rho)
                xvel_res = GuiResult(ID,
                                     header='xVelocity',
                                     title='xVelocity',
                                     location='centroid',
                                     scalar=xvel)
                yvel_res = GuiResult(ID,
                                     header='yVelocity',
                                     title='yVelocity',
                                     location='centroid',
                                     scalar=yvel)
                zvel_res = GuiResult(ID,
                                     header='zVelocity',
                                     title='zVelocity',
                                     location='centroid',
                                     scalar=zvel)
                mach_res = GuiResult(ID,
                                     header='Mach',
                                     title='Mach',
                                     location='centroid',
                                     scalar=mach)
                pressure_res = GuiResult(ID,
                                         header='Pressure',
                                         title='Pressure',
                                         location='centroid',
                                         scalar=pressure)

                cases[icase] = (rho_res, (ID, 'Rho'))
                cases[icase + 1] = (xvel_res, (ID, 'xVelocity'))
                cases[icase + 2] = (yvel_res, (ID, 'yVelocity'))
                cases[icase + 3] = (zvel_res, (ID, 'zVelocity'))
                cases[icase + 4] = (mach_res, (ID, 'Mach'))
                cases[icase + 5] = (pressure_res, (ID, 'Pressure'))
                form.append(('Boundary Conditions', None, bc_form))
        else:
            self.gui.log.warning('input_cntl_filename doesnt exist = %s' %
                                 input_cntl_filename)

        if os.path.exists(input_c3d_filename):
            # put in one group

            # Planes
            # ----------
            # xmin, xmax
            # ymin, ymax
            # zmin, zmax
            nodes, elements = read_input_c3d(input_c3d_filename,
                                             stack=True,
                                             log=self.gui.log,
                                             debug=self.gui.debug)

            color = RED_FLOAT
            self.gui.set_quad_grid('box',
                                   nodes,
                                   elements,
                                   color,
                                   line_width=1,
                                   opacity=1.)

            #-------------------------------------------------------------------
            # put in multiple groups
            nodes, elements = read_input_c3d(input_c3d_filename,
                                             stack=False,
                                             log=self.gui.log,
                                             debug=self.gui.debug)

            inflow_nodes = []
            inflow_elements = []

            symmetry_nodes = []
            symmetry_elements = []

            colori = (1., 1., 0.)
            outflow_nodes = []
            outflow_elements = []

            farfield_nodes = []
            farfield_elements = []

            ifarfield = 0
            isymmetry = 0
            iinflow = 0
            ioutflow = 0

            nfarfield_nodes = 0
            nsymmetry_nodes = 0
            ninflow_nodes = 0
            noutflow_nodes = 0
            if bcs is None:
                bcs = [None] * len(nodes)
            for bcsi, nodesi, elementsi in zip(bcs, nodes, elements):
                # 0 = FAR FIELD
                # 1 = SYMMETRY
                # 2 = INFLOW  (specify all)
                # 3 = OUTFLOW (simple extrap)
                self.gui.log.info('bcsi = %s' % bcsi)
                nnodes = nodesi.shape[0]
                bc = bcsi
                if bc is None:  # fake case
                    continue
                elif isinstance(bc, integer_types):
                    if bc == 0:
                        farfield_nodes.append(nodesi)
                        farfield_elements.append(elementsi + nfarfield_nodes)
                        nfarfield_nodes += nnodes
                        ifarfield += 1
                    elif bc == 1:
                        symmetry_nodes.append(nodesi)
                        symmetry_elements.append(elementsi + nsymmetry_nodes)
                        nsymmetry_nodes += nnodes
                        isymmetry += 1
                    elif bc == 2:
                        inflow_nodes.append(nodesi)
                        inflow_elements.append(elementsi + ninflow_nodes)
                        ninflow_nodes += nnodes
                        iinflow += 1
                    elif bc == 3:
                        outflow_nodes.append(nodesi)
                        outflow_elements.append(elementsi + noutflow_nodes)
                        noutflow_nodes += nnodes
                        ioutflow += 1
                    else:
                        msg = 'bc=%s' % str(bc)
                        raise NotImplementedError(msg)
                elif isinstance(bc, dict):  # ???
                    if len(bc) == 0:
                        continue
                    # bc = {
                    #    2: [2.0, 3.0, 0.0, 0.0, 5.0],
                    #    3: [1.0, 1.5, 0.0, 0.0, 0.714285]
                    # }
                    continue
                    #msg = 'bc=%s' % str(bc)
                    #raise NotImplementedError(msg)
                else:
                    msg = 'bc=%s' % str(bc)
                    raise NotImplementedError(msg)

            if ifarfield:
                color = BLUE_FLOAT
                nodes = vstack(farfield_nodes)
                elements = vstack(farfield_elements)
                self.gui.set_quad_grid('farfield',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if isymmetry:
                color = GREEN_FLOAT
                nodes = vstack(symmetry_nodes)
                elements = vstack(symmetry_elements)
                self.gui.set_quad_grid('symmetry',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if iinflow:
                color = RED_FLOAT
                nodes = vstack(inflow_nodes)
                elements = vstack(inflow_elements)
                self.gui.set_quad_grid('inflow',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if ioutflow:
                color = colori
                nodes = vstack(outflow_nodes)
                elements = vstack(outflow_elements)
                self.gui.set_quad_grid('outflow',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            #i = 0
            #for nodesi, elementsi in zip(nodes, elements):
            #self.set_quad_grid('box_%i' % i, nodesi, elementsi, color,
            #line_width=1, opacity=1.)
            #i += 1
        else:
            self.gui.log.warning('input_c3d_filename doesnt exist = %s' %
                                 input_c3d_filename)
        return mach, alpha, beta
Exemplo n.º 3
0
 def test_cart3d_input_c3d(self):
     """tests the input.c3d reading"""
     log = get_logger(level='warning', encoding='utf-8')
     input_c3d_filename = os.path.join(MODEL_PATH, 'input.c3d')
     read_input_c3d(input_c3d_filename, log=log, debug=False, stack=True)
Exemplo n.º 4
0
    def _create_box(self, cart3d_filename, ID, form, cases, icase, regions):
        stack = True
        dirname = os.path.dirname(os.path.abspath(cart3d_filename))
        input_c3d_filename = os.path.join(dirname, 'input.c3d')
        input_cntl_filename = os.path.join(dirname, 'input.cntl')
        mach = None
        alpha = None
        beta = None
        if os.path.exists(input_cntl_filename):
            cntl = read_input_cntl(input_cntl_filename, log=self.log, debug=self.debug)
            mach, alpha, beta = cntl.get_flow_conditions()
            bcs = cntl.get_boundary_conditions()
            bc_xmin, bc_xmax, bc_ymin, bc_ymax, bc_xmin, bc_xmax, surfbcs = bcs
            #stack = False

            if surfbcs:
                bc_form = [
                    ('Rho', icase, []),
                    ('xVelocity', icase + 1, []),
                    ('yVelocity', icase + 2, []),
                    ('zVelocity', icase + 3, []),
                    ('Mach', icase + 4, []),
                    ('Pressure', icase + 5, []),
                ]
                icase += 5
                nelements = self.nElements
                rho = zeros(nelements, dtype='float32')
                xvel = zeros(nelements, dtype='float32')
                yvel = zeros(nelements, dtype='float32')
                zvel = zeros(nelements, dtype='float32')
                vel = zeros(nelements, dtype='float32')
                pressure = zeros(nelements, dtype='float32')

                uregions = set(unique(regions))
                surf_bc_regions = set(surfbcs.keys())
                invalid_regions = surf_bc_regions - uregions
                if len(invalid_regions) != 0:
                    assert len(invalid_regions) == 0, invalid_regions

                for bc_id, bc_values in sorted(iteritems(surfbcs)):
                    rhoi, xveli, yveli, zveli, pressi = bc_values
                    i = where(regions == bc_id)[0]
                    rho[i] = rhoi
                    xvel[i] = xveli
                    yvel[i] = yveli
                    zvel[i] = zveli
                    pressure[i] = pressi

                mach = sqrt(xvel ** 2 + yvel ** 2 + zvel ** 2)

                rho_res = GuiResult(ID, header='Rho', title='Rho',
                                    location='centroid', scalar=rho)
                xvel_res = GuiResult(ID, header='xVelocity', title='xVelocity',
                                     location='centroid', scalar=xvel)
                yvel_res = GuiResult(ID, header='yVelocity', title='yVelocity',
                                     location='centroid', scalar=yvel)
                zvel_res = GuiResult(ID, header='zVelocity', title='zVelocity',
                                     location='centroid', scalar=zvel)
                mach_res = GuiResult(ID, header='Mach', title='Mach',
                                     location='centroid', scalar=mach)
                pressure_res = GuiResult(ID, header='Pressure', title='Pressure',
                                         location='centroid', scalar=pressure)

                cases[icase] = (rho_res, (ID, 'Rho'))
                cases[icase + 1] = (xvel_res, (ID, 'xVelocity'))
                cases[icase + 2] = (yvel_res, (ID, 'yVelocity'))
                cases[icase + 3] = (zvel_res, (ID, 'zVelocity'))
                cases[icase + 4] = (mach_res, (ID, 'Mach'))
                cases[icase + 5] = (pressure_res, (ID, 'Pressure'))
                form.append(('Boundary Conditions', None, bc_form))


        if os.path.exists(input_c3d_filename):
            nodes, elements = read_input_c3d(input_c3d_filename, stack=stack, log=self.log, debug=self.debug)

            # Planes
            # ----------
            # xmin, xmax
            # ymin, ymax
            # zmin, zmax

            if stack:
                red = (1., 0., 0.)
                color = red
                self.set_quad_grid('box', nodes, elements, color, line_width=1, opacity=1.)
            else:
                red = (1., 0., 0.)
                inflow_nodes = []
                inflow_elements = []

                green = (0., 1., 0.)
                symmetry_nodes = []
                symmetry_elements = []

                colori = (1., 1., 0.)
                outflow_nodes = []
                outflow_elements = []

                blue = (0., 0., 1.)
                farfield_nodes = []
                farfield_elements = []

                ifarfield = 0
                isymmetry = 0
                iinflow = 0
                ioutflow = 0

                nfarfield_nodes = 0
                nsymmetry_nodes = 0
                ninflow_nodes = 0
                noutflow_nodes = 0
                for bcsi, nodesi, elementsi in zip(bcs, nodes, elements):
                    # 0 = FAR FIELD
                    # 1 = SYMMETRY
                    # 2 = INFLOW  (specify all)
                    # 3 = OUTFLOW (simple extrap)
                    self.log.info('bcsi = %s' % bcsi)
                    nnodes = nodesi.shape[0]
                    bc = bcsi
                    if isinstance(bc, int):
                        if bc == 0:
                            farfield_nodes.append(nodesi)
                            farfield_elements.append(elementsi + nfarfield_nodes)
                            nfarfield_nodes += nnodes
                            ifarfield += 1
                        elif bc == 1:
                            symmetry_nodes.append(nodesi)
                            symmetry_elements.append(elementsi + nsymmetry_nodes)
                            nsymmetry_nodes += nnodes
                            isymmetry += 1
                        elif bc == 2:
                            inflow_nodes.append(nodesi)
                            inflow_elements.append(elementsi + ninflow_nodes)
                            ninflow_nodes += nnodes
                            iinflow += 1
                        elif bc == 3:
                            outflow_nodes.append(nodesi)
                            outflow_elements.append(elementsi + noutflow_nodes)
                            noutflow_nodes += nnodes
                            ioutflow += 1
                        else:
                            msg = 'bc=%s' % str(bc)
                            raise NotImplementedError(msg)
                    elif isinstance(bc, dict):
                        continue
                    else:
                        msg = 'bc=%s' % str(bc)
                        raise NotImplementedError(msg)

                if ifarfield:
                    color = blue
                    nodes = vstack(farfield_nodes)
                    elements = vstack(farfield_elements)
                    self.set_quad_grid('farfield', nodes, elements, color, line_width=1, opacity=1.)

                if isymmetry:
                    color = green
                    nodes = vstack(symmetry_nodes)
                    elements = vstack(symmetry_elements)
                    self.set_quad_grid('symmetry', nodes, elements, color, line_width=1, opacity=1.)

                if iinflow:
                    color = red
                    nodes = vstack(inflow_nodes)
                    elements = vstack(inflow_elements)
                    self.set_quad_grid('inflow', nodes, elements, color, line_width=1, opacity=1.)

                if ioutflow:
                    color = colori
                    nodes = vstack(outflow_nodes)
                    elements = vstack(outflow_elements)
                    self.set_quad_grid('outflow', nodes, elements, color, line_width=1, opacity=1.)

                #i = 0
                #for nodesi, elementsi in zip(nodes, elements):
                    #self.set_quad_grid('box_%i' % i, nodesi, elementsi, color, line_width=1, opacity=1.)
                    #i += 1
        return mach, alpha, beta
Exemplo n.º 5
0
 def test_cart3d_input_c3d(self):
     """tests the input.c3d reading"""
     from pyNastran.converters.cart3d.input_c3d_reader import read_input_c3d
     input_c3d_filename = os.path.join(test_path, 'input.c3d')
     read_input_c3d(input_c3d_filename, log=None, debug=False, stack=True)
Exemplo n.º 6
0
 def test_cart3d_input_c3d(self):
     """tests the input.c3d reading"""
     from pyNastran.converters.cart3d.input_c3d_reader import read_input_c3d
     input_c3d_filename = os.path.join(test_path, 'input.c3d')
     read_input_c3d(input_c3d_filename, log=None, debug=False, stack=True)