Пример #1
0
    def call( self ):
        """In parametric runs, cached data (homogenized coefficients,
        Christoffel acoustic tensor and eigenvalue problem solution) are
        cleared according to 'clear_cache' aplication options.

        Example:

        clear_cache = {'cached_christoffel' : True, 'cached_evp' : True}
        """
        options = self.options

        for key, val in self.app_options.clear_cache.iteritems():
            if val and key.startswith('cached_'):
                setattr(self, key, None)

        if options.phase_velocity:
            # No band gaps in this case.
            return self.compute_phase_velocity()

        evp = self.solve_eigen_problem()

        self.fix_eig_range( evp.eigs.shape[0] )

        if options.detect_band_gaps:
            bg = detect_band_gaps( self.problem, evp.kind,
                                   evp.eigs_rescaled, evp.eig_vectors,
                                   self.app_options, self.conf.funmod )

            if options.plot:
                plot_range, teigs = transform_plot_data( bg.logs.eigs,
                                                         bg.opts.plot_transform,
                                                         self.conf.funmod )

                plot_rsc = bg.opts.plot_rsc
                plot_opts =  bg.opts.plot_options
                plot_labels =  bg.opts.plot_labels
                
                plt.rcParams.update( plot_rsc['params'] )

                fig = plot_gaps( 1, plot_rsc, bg.gaps, bg.kinds,
                                 bg.freq_range_margins, plot_range,
                                 clear = True )
                fig = plot_logs( 1, plot_rsc, plot_labels, bg.logs.freqs, teigs,
                                 bg.valid[bg.eig_range],
                                 bg.freq_range_initial,
                                 plot_range, False,
                                 show_legend = plot_opts['legend'],
                                 new_axes = True )

                fig_name = bg.opts.fig_name
                if fig_name is not None:
                    fig.savefig( fig_name )
                if plot_opts['show']:
                    plt.show()

        elif options.analyze_dispersion:
            christoffel, iw_dir = self.compute_cat(ret_iw_dir=True)

            bg = detect_band_gaps( self.problem, evp.kind,
                                   evp.eigs_rescaled, evp.eig_vectors,
                                   self.app_options, self.conf.funmod,
                                   christoffel = christoffel )

            output( 'computing polarization angles...' )
            pas = compute_polarization_angles( iw_dir, bg.logs.eig_vectors )
            output( '...done' )

            bg.polarization_angles = pas

            output( 'computing phase velocity...' )
            bg.phase_velocity = self.compute_phase_velocity()
            output( '...done' )

            if options.plot:
                plot_rsc = bg.opts.plot_rsc
                plot_opts =  bg.opts.plot_options
                plt.rcParams.update( plot_rsc['params'] )

                aux = transform_plot_data( pas,
                                           bg.opts.plot_transform_angle,
                                           self.conf.funmod )
                plot_range, pas = aux
                
                plot_labels =  bg.opts.plot_labels_angle

                fig = plot_gaps( 1, plot_rsc, bg.gaps, bg.kinds,
                                 bg.freq_range_margins, plot_range,
                                 clear = True )
                fig = plot_logs( 1, plot_rsc, plot_labels, bg.logs.freqs, pas,
                                 bg.valid[bg.eig_range],
                                 bg.freq_range_initial,
                                 plot_range, False,
                                 show_legend = plot_opts['legend'],
                                 new_axes = True )

                fig_name = bg.opts.fig_name_angle
                if fig_name is not None:
                    fig.savefig( fig_name )

                aux = transform_plot_data( bg.logs.eigs,
                                           bg.opts.plot_transform_wave,
                                           self.conf.funmod )
                plot_range, teigs = aux

                plot_labels =  bg.opts.plot_labels_wave

                fig = plot_gaps( 2, plot_rsc, bg.gaps, bg.kinds,
                                 bg.freq_range_margins, plot_range,
                                 clear = True )
                fig = plot_logs( 2, plot_rsc, plot_labels, bg.logs.freqs, teigs,
                                 bg.valid[bg.eig_range],
                                 bg.freq_range_initial,
                                 plot_range, False,
                                 show_legend = plot_opts['legend'],
                                 new_axes = True )

                fig_name = bg.opts.fig_name_wave
                if fig_name is not None:
                    fig.savefig( fig_name )
                if plot_opts['show']:
                    plt.show()

        else:
            bg = None

        return evp, bg