Skip to content

Yasf

YASF

Source code in yasfpy/yasf.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def __init__(
    self,
    path_config: str,
    preprocess: bool = True,
    path_cluster: str = "",
):
    # super().__init__(
    #     path_config=path_config,
    #     preprocess=preprocess,
    #     path_cluster=path_cluster,
    # )
    self.path_config = path_config
    self.config = Config(path_config, preprocess, path_cluster)

    self.particles = Particles(
        self.config.spheres[:, 0:3],
        self.config.spheres[:, 3],
        self.config.spheres[:, 4],
        refractive_index_table=self.config.refractive_index_interpolated,
        # refractive_index_table=self.config.material,
    )
    self.initial_field = InitialField(
        beam_width=self.config.config["initial_field"]["beam_width"],
        focal_point=np.array(self.config.config["initial_field"]["focal_point"]),
        polar_angle=self.config.config["initial_field"]["polar_angle"],
        azimuthal_angle=self.config.config["initial_field"]["azimuthal_angle"],
        polarization=self.config.config["initial_field"]["polarization"],
    )
    self.parameters = Parameters(
        wavelength=self.config.wavelength,
        medium_refractive_index=self.config.medium_refractive_index,
        particles=self.particles,
        initial_field=self.initial_field,
    )
    self.solver = Solver(
        solver_type=self.config.config["solver"]["type"],
        tolerance=self.config.config["solver"]["tolerance"],
        max_iter=self.config.config["solver"]["max_iter"],
        restart=self.config.config["solver"]["restart"],
    )
    self.numerics = Numerics(
        lmax=self.config.config["numerics"]["lmax"],
        sampling_points_number=self.config.config["numerics"]["sampling_points"],
        particle_distance_resolution=self.config.config["numerics"][
            "particle_distance_resolution"
        ],
        gpu=self.config.config["numerics"]["gpu"],
        solver=self.solver,
    )
    self.simulation = Simulation(self.parameters, self.numerics)
    self.optics = Optics(self.simulation)

path_cluster: str instance-attribute

path_config: str = path_config instance-attribute

config: dict = Config(path_config, preprocess, path_cluster) instance-attribute

particles = Particles(self.config.spheres[:, 0:3], self.config.spheres[:, 3], self.config.spheres[:, 4], refractive_index_table=self.config.refractive_index_interpolated) instance-attribute

initial_field = InitialField(beam_width=self.config.config['initial_field']['beam_width'], focal_point=np.array(self.config.config['initial_field']['focal_point']), polar_angle=self.config.config['initial_field']['polar_angle'], azimuthal_angle=self.config.config['initial_field']['azimuthal_angle'], polarization=self.config.config['initial_field']['polarization']) instance-attribute

parameters = Parameters(wavelength=self.config.wavelength, medium_refractive_index=self.config.medium_refractive_index, particles=self.particles, initial_field=self.initial_field) instance-attribute

solver = Solver(solver_type=self.config.config['solver']['type'], tolerance=self.config.config['solver']['tolerance'], max_iter=self.config.config['solver']['max_iter'], restart=self.config.config['solver']['restart']) instance-attribute

numerics = Numerics(lmax=self.config.config['numerics']['lmax'], sampling_points_number=self.config.config['numerics']['sampling_points'], particle_distance_resolution=self.config.config['numerics']['particle_distance_resolution'], gpu=self.config.config['numerics']['gpu'], solver=self.solver) instance-attribute

simulation = Simulation(self.parameters, self.numerics) instance-attribute

optics = Optics(self.simulation) instance-attribute

run

Source code in yasfpy/yasf.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def run(self, points: np.ndarray = None):
    self.particles.compute_volume_equivalent_area()
    self.numerics.compute_spherical_unity_vectors()
    self.numerics.compute_translation_table()
    self.simulation.compute_mie_coefficients()
    self.simulation.compute_initial_field_coefficients()
    self.simulation.compute_right_hand_side()
    self.simulation.compute_scattered_field_coefficients()
    if self.config.config["optics"]:
        self.optics.compute_cross_sections()
        self.optics.compute_efficiencies()
        self.optics.compute_phase_funcition()

    # NOTE: Legacy, needs to be removed
    if points is not None:
        self.optics.simulation.compute_fields(points)

    if "points" in self.config.config:
        points = np.stack(
            (
                self.config.config["points"]["x"],
                self.config.config["points"]["y"],
                self.config.config["points"]["z"],
            ),
            axis=1,
        )
        self.optics.simulation.compute_fields(points)

benchmark staticmethod

Source code in yasfpy/yasf.py
110
111
112
113
114
115
116
117
118
@staticmethod
def benchmark(config_path: str = None, runner: pyperf.Runner = None):
    if config_path is None:
        raise Exception("Plase provide a config file!")
    if runner is None:
        raise Exception("Plase provide a runner for benchmarking!")
    runner.bench_func("yasf_init", lambda: YASF(config_path))
    yasf_instance = YASF(config_path)
    runner.bench_func("yasf_run", lambda: yasf_instance.run())

profiler staticmethod

Source code in yasfpy/yasf.py
120
121
122
123
124
125
126
127
128
129
@staticmethod
def profiler(config_path: str = None, output: str = None):
    if config_path is None:
        raise Exception("Plase provide a config file!")
    with cProfile.Profile() as pr:
        yasf_instance = YASF(config_path)
        yasf_instance.run()
        stats = pstats.Stats(pr).sort_stats(pstats.SortKey.TIME)
        stats.print_stats() if output is None else stats.dump_stats(output)
        return yasf_instance

Comments