feat!: Changes names of classes to make more clear for dipole model and single dipole fixed magnitude model
All checks were successful
gitea-physics/pdme/pipeline/head This commit looks good

This commit is contained in:
2022-04-30 11:44:39 -05:00
parent 0d5508a0b5
commit 7eba3311c7
4 changed files with 37 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
from pdme.model.model import Model
from pdme.model.fixed_magnitude_model import FixedMagnitudeModel
from pdme.model.model import DipoleModel
from pdme.model.fixed_magnitude_model import SingleDipoleFixedMagnitudeModel
__all__ = [
"Model",
"FixedMagnitudeModel",
"DipoleModel",
"SingleDipoleFixedMagnitudeModel",
]

View File

@@ -1,23 +1,20 @@
import numpy
import numpy.random
from pdme.model.model import Model
from pdme.model.model import DipoleModel
from pdme.measurement import (
OscillatingDipole,
OscillatingDipoleArrangement,
)
class FixedMagnitudeModel(Model):
class SingleDipoleFixedMagnitudeModel(DipoleModel):
"""
Model of oscillating dipole with a fixed magnitude, but free rotation.
Model of single oscillating dipole with a fixed magnitude, but free rotation.
Parameters
----------
pfixed : float
The fixed dipole magnitude.
n : int
The number of dipoles to assume.
"""
def __init__(
@@ -42,8 +39,16 @@ class FixedMagnitudeModel(Model):
def __repr__(self) -> str:
return f"FixedMagnitudeModel({self.xmin}, {self.xmax}, {self.ymin}, {self.ymax}, {self.zmin}, {self.zmax}, {self.pfixed})"
def get_dipoles(self, frequency: float) -> OscillatingDipoleArrangement:
theta = numpy.arccos(self.rng.uniform(-1, 1))
def get_dipoles(
self, max_frequency: float, rng_to_use: numpy.random.Generator = None
) -> OscillatingDipoleArrangement:
rng: numpy.random.Generator
if rng_to_use is None:
rng = self.rng
else:
rng = rng_to_use
theta = numpy.arccos(rng.uniform(-1, 1))
phi = self.rng.uniform(0, 2 * numpy.pi)
px = self.pfixed * numpy.sin(theta) * numpy.cos(phi)
py = self.pfixed * numpy.sin(theta) * numpy.sin(phi)
@@ -55,6 +60,7 @@ class FixedMagnitudeModel(Model):
self.rng.uniform(self.zmin, self.zmax),
)
)
frequency = self.rng.uniform(0, max_frequency)
return OscillatingDipoleArrangement(
[OscillatingDipole(numpy.array([px, py, pz]), s_pts, frequency)]
)

View File

@@ -9,15 +9,26 @@ import logging
_logger = logging.getLogger(__name__)
class Model:
class DipoleModel:
"""
Interface for models.
Interface for models based on dipoles.
Some concepts are kept specific for dipole-based models, even though other types of models could be useful later on.
"""
def get_dipoles(self, frequency: float) -> OscillatingDipoleArrangement:
def get_dipoles(
self, max_frequency: float, rng: numpy.random.Generator = None
) -> OscillatingDipoleArrangement:
"""
For a particular maximum frequency, gets a dipole arrangement based on the model that uniformly distributes its choices according to the model.
If no rng is passed in, uses some default, but you might not want that.
Frequencies should be chosen uniformly on range of (0, max_frequency).
"""
raise NotImplementedError
def get_n_single_dipoles(
def get_monte_carlo_dipole_inputs(
self, n: int, max_frequency: float, rng: numpy.random.Generator = None
) -> numpy.ndarray:
"""
For a given DipoleModel, gets a set of dipole collections as a n x whatever numpy array.
"""
raise NotImplementedError