Ejemplo n.º 1
0
def layout_pos2temp(options: configargparse.Namespace, pos: list,
                    powers: list):
    if options.bcs is None:
        options.bcs = []
    task = get_task(
        geometry_board="s",
        size_board=options.length,
        grid_board=options.nx,
        geometry=len(options.units) * "r",
        size=options.units,
        angle=options.angles,
        intensity=options.powers,
        rad=False,
        method=None,
    )
    layout = task.layout_from_pos(pos, powers)
    temp, xs, ys, zs = run_solver_c(
        ndim=options.ndim,
        length=options.length,
        units=options.units,
        bcs=options.bcs,
        u0=options.u_D,
        powers=powers,
        nx=options.nx - 1,
        F=layout,
    )
    return layout, temp
Ejemplo n.º 2
0
def generate_from_cli(options: configargparse.Namespace):
    """Generate from cli with options.

    Arguments:
        options (configargparse.Namespace): config options
    """
    if options.bcs is None:
        options.bcs = []
    np.random.seed(options.seed)
    seeds = np.random.randint(2**32, size=options.worker)
    print(options.worker)
    print(seeds)
    seeds_q: Queue = Queue()
    for seed in seeds:
        seeds_q.put(seed)

    unit_n = len(options.units)
    geometry = ["r"] * unit_n
    task = get_task(
        geometry_board="s",
        size_board=options.length,
        grid_board=options.nx + 1,
        geometry=geometry,
        size=options.units,
        angle=options.angles,
        intensity=options.powers,
        rad=False,
        method=options.sampler,
    )
    task.warmup()  # warm up, especially for gibbs

    if options.method == "fenics":
        # 创建单参数函数

        method_fenics_p = partial(method_fenics,
                                  options=options,
                                  sampler=task.sample)

        # for i in range(options.sample_n):
        #     method_fenics_p(i)

        # multiprocess support
        with Pool(options.worker, initializer=pool_init,
                  initargs=(seeds_q, )) as pool:
            pool_it = pool.imap(method_fenics_p, range(options.sample_n))
            # for i in pool_it:
            #     print(i)
            for _ in tqdm.tqdm(
                    pool_it,
                    desc=f"{pool._processes} workers's running",
                    total=options.sample_n,
                    ncols=100,
            ):
                pass

    print(f"Generated {options.sample_n} layouts in {options.data_dir}")
Ejemplo n.º 3
0
def generate_from_cli(options: configargparse.Namespace):
    """Generate from cli with options.

    Arguments:
        options (configargparse.Namespace): config options
    """
    if options.bcs is None:
        options.bcs = []
    options.unit_per_row = int(options.length / options.length_unit)
    possible_n = options.unit_per_row**options.ndim
    np.random.seed(options.seed)
    if options.sampler == "uniform":
        sampler = np.random.choice
    powers_all = [
        sampler(options.power, options.unit_n) for _ in range(options.sample_n)
    ]  # 每个样本
    layout_pos_lists = [
        sampler(possible_n, options.unit_n, replace=False)
        for _ in range(options.sample_n)
    ]
    # # 叠加原理
    # if options.method == 'fenics_additive':
    #     u_basis = []
    #     for layout_pos in tqdm.trange(possible_n):
    #         u = run_solver(options.length, options.length_unit, options.bcs,
    #                          layout_pos,
    #                        0, [1.], options.nx, options.ny, False)
    #         u_basis.append(u)
    #     for i in tqdm.trange(options.sample_n):
    #         layout_pos_list = sorted(
    #             sampler(possible_n, options.unit_n, replace=False))
    #         u_elt = (powers[i] * u_basis[pos]
    #                  for i, pos in enumerate(layout_pos_list))
    #         U = reduce(np.add, u_elt) / options.unit_n + options.u_D
    #         F = io.layout2matrix(options.nx, options.ny,
    #                              unit_per_row, powers, layout_pos_list)
    #         xs, ys = get_mesh_grid(options.length, options.nx, options.ny)
    #         io.save(options, i, U, xs, ys, F, layout_pos_list)
    # 无叠加原理
    if options.method == "fenics":
        # 创建单参数函数
        method_fenics_p = partial(
            method_fenics,
            options=options,
            sampler=sampler,
            powers_all=powers_all,
            layout_pos_lists=layout_pos_lists,
        )

        # for i in range(options.sample_n):
        #     method_fenics_p(i)

        # multiprocess support
        with Pool(options.worker) as pool:
            pool_it = pool.imap_unordered(method_fenics_p,
                                          range(options.sample_n))
            for _ in tqdm.tqdm(
                    pool_it,
                    desc=f"{pool._processes} workers's running",
                    total=options.sample_n,
                    ncols=100,
            ):
                pass

    print(f"Generated {options.sample_n} layouts in {options.data_dir}")
Ejemplo n.º 4
0
def generate_from_cli(options: configargparse.Namespace):
    """Generate from cli with options.

    Arguments:
        options (configargparse.Namespace): config options
    """
    if options.bcs is None:
        options.bcs = []
    np.random.seed(options.seed)
    seeds = np.random.randint(2**32, size=options.worker)
    print(options.worker)
    print(seeds)
    seeds_q: Queue = Queue()
    for seed in seeds:
        seeds_q.put(seed)

    unit_n = len(options.units)
    geometry = ["r"] * unit_n

    positions = np.array([k for k in options.positions])
    if options.positions_type == "coord":
        pass
    elif options.positions_type == "grid":
        positions = positions / (options.nx + 1) * options.length
    else:
        raise LookupError(f"Type {options.positions_type} is not supported!")

    task = get_task_powers_sampling(
        geometry_board="s",
        size_board=options.length,
        grid_board=options.nx + 1,
        geometry=geometry,
        size=options.units,
        angle=options.angles,
        intensity=options.powers,
        rad=False,
        position=positions,
    )
    task.warmup()  # warm up, especially for gibbs

    observation = False
    if options.observation_points is not None:
        observation = True
    # print(options)

    if options.method == "fenics":
        # 创建单参数函数

        method_fenics_p = partial(
            method_fenics,
            options=options,
            sampler=task.sample,
            task=task,
            observation=observation,
        )

        # for i in range(options.sample_n):
        #     method_fenics_p(i)

        # multiprocess support
        with Pool(options.worker, initializer=pool_init,
                  initargs=(seeds_q, )) as pool:
            pool_it = pool.imap(method_fenics_p, range(options.sample_n))
            # for i in pool_it:
            #     print(i)
            for _ in tqdm.tqdm(
                    pool_it,
                    desc=f"{pool._processes} workers's running",
                    total=options.sample_n,
                    ncols=100,
            ):
                pass

    print(f"Generated {options.sample_n} layouts in {options.data_dir}")