Exemple #1
0
def compute_eigenmomenta( em_equation, u_name, pb, eig_vectors,
                          transform = None, pbar = None ):

    dim = pb.domain.mesh.dim
    n_dof, n_eigs = eig_vectors.shape

    eigenmomenta = nm.empty( (n_eigs, dim), dtype = nm.float64 )

    if pbar is not None:
        pbar.init( n_eigs - 1 )

    for ii in xrange( n_eigs ):
        if pbar is not None:
            pbar.update( ii )
        else:
            if (ii % 100) == 0:
                output( '%d of %d (%f%%)' % (ii, n_eigs,
                                             100. * ii / (n_eigs - 1)) )
            
        if transform is None:
            vec_phi, is_zero = eig_vectors[:,ii], False
        else:
            vec_phi, is_zero = transform( eig_vectors[:,ii], (n_nod, dim) )
           
        if is_zero:
            eigenmomenta[ii,:] = 0.0

        else:
            pb.variables[u_name].data_from_data( vec_phi.copy() )
            val = eval_term_op( None, em_equation, pb )
            eigenmomenta[ii,:] = val

    return eigenmomenta
Exemple #2
0
def compute_density_volume_info( pb, volume_term, region_to_material ):
    """Computes volumes, densities of regions specified in
    `region_to_material`, average density and total volume."""
    average_density = 0.0
    total_volume = 0.0
    volumes = {}
    densities = {}
    for region_name, mat_name in region_to_material.iteritems():
        mat = pb.materials[mat_name]
#        assert_( region_name == mat.region.name )
        vol = eval_term_op( None, volume_term % region_name, pb )
        density = mat.get_data( region_name, mat.igs[0], 'density' )
        output( 'region %s: volume %f, density %f' % (region_name,
                                                      vol, density ) )

        volumes[region_name] = vol
        densities[region_name] = density

        average_density += vol * density
        total_volume += vol
    output( 'total volume:', total_volume )

    average_density /= total_volume

    return Struct( name = 'density_volume_info',
                   average_density = average_density,
                   total_volume = total_volume,
                   volumes = volumes,
                   densities = densities )