14 #define M_SQRT3 1.7320508075688772935274463415058724
17 #define M_SQRT3_2 (M_SQRT3/2)
20 #define M_1_SQRT3 0.57735026918962576450914878050195746
33 typedef enum LatticeDimensionality {
46 LAT_1D_IN_3D_ZONLY = 97,
47 LAT_2D_IN_3D_XYONLY = 162
48 } LatticeDimensionality;
50 inline static bool LatticeDimensionality_checkflags(
51 LatticeDimensionality a, LatticeDimensionality flags_a_has_to_contain) {
52 return ((a & flags_a_has_to_contain) == flags_a_has_to_contain);
59 static inline point2d point2d_fromxy(
const double x,
const double y) {
270 return g->
c->
next(g);
280 r.
point.pol = res.point_pol;
284 r.
point.cart2 = res.point_cart2;
288 r.
point.sph = res.point_sph;
292 r.
point.cart3 = res.point_cart3;
304 return g->
c->
fetch(g, nmemb, target);
309 for (
size_t i = 0; i < nmemb; ++i)
310 target[i].cart3 = t2[i];
316 for (
size_t i = 0; i < nmemb; ++i)
317 target[i].sph = t2[i];
323 for (
size_t i = 0; i < nmemb; ++i)
324 target[i].cart2 = t2[i];
330 for (
size_t i = 0; i < nmemb; ++i)
331 target[i].pol = t2[i];
334 double *t2 = (
double*) ((
char *) target
337 for (
size_t i = 0; i < nmemb; ++i)
343 for (res.generated = 0; res.generated < nmemb;
347 "No method found to generate points. The PGenClassInfo"
348 " %s is apparently broken.", g->
c->name);
350 target[res.generated] = res1.
point;
352 assert(!res.generated || ((res1.
flags & PGEN_COORDS_BITRANGE) == (res.flags & PGEN_COORDS_BITRANGE)));
353 res.flags |= res1.
flags & PGEN_COORDS_BITRANGE;
383 size_t nmemb,
sph_t *target) {
391 tmp, res.flags, res.generated);
401 size_t nmemb,
cart3_t *target) {
409 tmp, res.flags, res.generated);
419 size_t nmemb,
pol_t *target) {
427 tmp, res.flags, res.generated);
437 size_t nmemb,
cart2_t *target) {
445 tmp, res.flags, res.generated);
455 size_t nmemb,
double *target) {
457 return g->
c->
fetch_z(g, nmemb, target);
463 tmp, res.flags, res.generated);
507 return PGenSphDoneVal;
524 return PGenPolDoneVal;
541 return PGenCart3DoneVal;
558 return PGenCart2DoneVal;
566 return g->
c->
fetch(g, n, arr);
605 typedef enum PGen_1D_incrementDirection{
608 PGEN_1D_INC_FROM_ORIGIN,
609 PGEN_1D_INC_TOWARDS_ORIGIN
610 } PGen_1D_incrementDirection;
618 PGen_1D_incrementDirection incdir
623 double minR,
bool inc_minR,
double maxR,
bool inc_maxR);
627 double minR,
bool inc_minR,
double maxR,
bool inc_maxR);
633 double minR,
bool inc_minR,
double maxR,
bool inc_maxR);
635 const cart3_t *offset,
double minR,
bool inc_minR,
double maxR,
bool inc_maxR);
650 #define BASIS_RTOL 1e-13
658 EQUILATERAL_TRIANGULAR = 3,
659 RIGHT_ISOSCELES=SQUARE,
660 PARALLELOGRAMMIC=OBLIQUE,
661 CENTERED_RHOMBIC=RECTANGULAR,
662 RIGHT_TRIANGULAR=RECTANGULAR,
663 CENTERED_RECTANGULAR=RHOMBIC,
664 ISOSCELE_TRIANGULAR=RHOMBIC,
665 RIGHT_ISOSCELE_TRIANGULAR=SQUARE,
666 HEXAGONAL=EQUILATERAL_TRIANGULAR
716 LatticeType2 l2d_classifyLattice(
cart2_t b1,
cart2_t b2,
double rtol);
719 LatticeFlags l2d_detectRightAngles(
cart2_t b1,
cart2_t b2,
double rtol);
720 LatticeFlags l3d_detectRightAngles(
const cart3_t basis[3],
double rtol);
742 double l3d_reciprocalBasis1(
const cart3_t direct_basis[3],
cart3_t reciprocal_basis[3]);
743 double l3d_reciprocalBasis2pi(
const cart3_t direct_basis[3],
cart3_t reciprocal_basis[3]);
767 ptrdiff_t *r_offsets;
778 size_t nmemb,
double rtol,
double atol);
782 point2d shift,
double rtol,
double atol);
798 assert(r_order < ps->nrs);
799 assert(i < (ps->r_offsets[r_order+1] - ps->r_offsets[r_order]));
800 return ps->base[ps->r_offsets[r_order] + i];
804 assert(r_order < ps->nrs);
805 return ps->rs[r_order];
814 double maxr,
bool maxr_inc);
819 double qpms_emptylattice2_mode_nth(
829 void qpms_emptylattice2_modes_maxindex(
830 double target_freqs[],
848 double **target_freqs,
881 TRIANGULAR_HORIZONTAL
882 } TriangularLatticeOrientation;
884 static inline TriangularLatticeOrientation reverseTriangularLatticeOrientation(TriangularLatticeOrientation o){
886 case TRIANGULAR_VERTICAL:
887 return TRIANGULAR_HORIZONTAL;
889 case TRIANGULAR_HORIZONTAL:
890 return TRIANGULAR_VERTICAL;
904 TriangularLatticeOrientation orientation;
908 bool includes_origin;
919 triangular_lattice_gen_t *triangular_lattice_gen_init(
double a, TriangularLatticeOrientation ori,
bool include_origin,
934 TriangularLatticeOrientation orientation;
const PGenClassInfo PGen_FromPoint2DArray
2D point generator that simply iterates over an existing array of Point2d.
Definition: latticegens.c:234
static PGenReturnData PGen_next_nf(struct PGen *g)
Generate a point with any of the next-methods.
Definition: lattices.h:268
static PGenCart3ReturnData PGen_next_cart3(PGen *g)
Generate a point in a 3D real space (cartesian coordinates).
Definition: lattices.h:529
PGen PGen_1D_new_minMaxR(double period, double offset, double minR, bool inc_minR, double maxR, bool inc_maxR, PGen_1D_incrementDirection incdir)
PGen_1D point generator constructor.
Definition: latticegens.c:296
static PGenReturnDataBulk PGen_fetch_z(struct PGen *g, size_t nmemb, double *target)
Generate multiple points in 1D cartesian coordinates.
Definition: lattices.h:454
PGenPointFlags
Definition: lattices.h:127
@ PGEN_METHOD_UNAVAILABLE
Set if no suitable method exists (no point generated).
Definition: lattices.h:149
@ PGEN_DONE
Convenience identifier, not an actual flag.
Definition: lattices.h:150
@ PGEN_SINGLE_R
Definition: lattices.h:146
@ PGEN_NOTDONE
Definition: lattices.h:133
@ PGEN_AT_Z
Set if the point(s) lie(s) at the z-axis (theta is either 0 or M_PI).
Definition: lattices.h:147
@ PGEN_AT_XY
Set if the point(s) lie(s) in the xy-plane (theta is M_PI2).
Definition: lattices.h:148
@ PGEN_OLD_R
Definition: lattices.h:139
struct PGenReturnDataBulk PGenReturnDataBulk
Metadata generated by the fetch*() methods from PGenClassInfo.
static PGenReturnDataBulk PGen_fetch_sph(struct PGen *g, size_t nmemb, sph_t *target)
Generate multiple points in spherical coordinates.
Definition: lattices.h:382
static PGenReturnDataBulk PGen_fetch_cart2(struct PGen *g, size_t nmemb, cart2_t *target)
Generate multiple points in 2D cartesian coordinates.
Definition: lattices.h:436
struct PGenClassInfo PGenClassInfo
PGen class metadata.
struct PGenReturnData PGenReturnData
Generic PGen return type that might contain point represented in any of the supported coordinate syst...
void qpms_emptylattice2_modes_nearest(double target[2], cart2_t b1_rec, cart2_t b2_rec, double rtol, cart2_t k, double wave_speed, double omega)
Gives the frequencies of two empty lattice modes nearest to omega at a given wave vector k.
Definition: lattices2d.c:929
static PGenCart3ReturnData PGenReturnDataConv_sph_cart3(PGenSphReturnData sphdata)
Standard PGen spherical coordinates -> 3d cartesian convertor.
Definition: lattices.h:579
size_t qpms_emptylattice2_modes_maxfreq(double **target_freqs, cart2_t b1_rec, cart2_t b2_rec, double rtol, cart2_t k, double wave_speed, double maxfreq)
Gives the frequencies of empty lattice modes at a given wave vector k up to maxfreq and one more.
Definition: lattices2d.c:886
struct PGen PGen
Generic lattice point generator type.
struct PGenSphReturnData PGenSphReturnData
PGen single-point return data type (3D, spherical coordinates).
int qpms_reduce_lattice_basis(double *b, const size_t bsize, const size_t ndim, double delta)
Lattice basis reduction.
Definition: lll.c:41
static PGenSphReturnData PGen_next_sph(PGen *g)
Generate a point in a 3D real space (spherical coordinates).
Definition: lattices.h:495
static void PGen_destroy(PGen *g)
Deallocate and invalidate a PGen point generator.
Definition: lattices.h:472
struct PGenPolReturnData PGenPolReturnData
PGen single-point return data type (2D, polar coordinates).
struct PGenCart2ReturnData PGenCart2ReturnData
PGen single-point return data type (2D, cartesian coordinates).
static PGenPolReturnData PGen_next_pol(PGen *g)
Generate a point in a 2D real space (polar coordinates).
Definition: lattices.h:512
static PGenReturnDataBulk PGen_fetch_cart3(struct PGen *g, size_t nmemb, cart3_t *target)
Generate multiple points in 3D cartesian coordinates.
Definition: lattices.h:400
struct PGenZReturnData PGenZReturnData
PGen single-point return data type (1D).
size_t PGen_xyWeb_sizecap(cart2_t b1, cart2_t b2, double rtol, cart2_t offset, double minR, bool inc_minR, double maxR, bool inc_maxR)
Returns a number larger or equal than the number of all the points generated by a PGen_xyWeb.
Definition: latticegens.c:591
static PGenReturnDataBulk PGen_fetch_pol(struct PGen *g, size_t nmemb, pol_t *target)
Generate multiple points in polar coordinates.
Definition: lattices.h:418
const PGenClassInfo PGen_1D
1D equidistant point generator.
Definition: latticegens.c:407
const PGenClassInfo PGen_shifted
A metagenerator generating points from another generator shifted by a constant.
Definition: latticegens.c:992
static PGenZReturnData PGen_next_z(PGen *g)
Generate a point in a 1D real space.
Definition: lattices.h:478
static PGenCart2ReturnData PGen_next_cart2(PGen *g)
Generate a point in a 2D real space (cartesian coordinates).
Definition: lattices.h:546
PGen PGen_FromPoints2DArray_new(const point2d *points, size_t len)
PGen_FromPoint2DArray constructor.
static PGenSphReturnData PGenReturnDataConv_cart3_sph(PGenCart3ReturnData c)
Standard PGen 3d cartesian -> spherical coordinates convertor.
Definition: lattices.h:587
static PGenReturnData PGen_next(struct PGen *g)
Generate a point with any of the next-methods or fetch-methods.
Definition: lattices.h:366
struct PGenCart3ReturnData PGenCart3ReturnData
PGen single-point return data type (3D, cartesian coordinates).
static PGenReturnDataBulk PGen_fetch_any(struct PGen *g, size_t nmemb, anycoord_point_t *target)
Generate multiple points with PGen in any coordinate system.
Definition: lattices.h:301
#define QPMS_CRASHING_MALLOC(pointer, size)
Wrapper macro of standard malloc(), crashing on failure.
Definition: qpms_error.h:109
#define QPMS_ENSURE(x, msg,...)
Raises an error if x is not true, with custom error message.
Definition: qpms_error.h:226
@ QPMS_COORDS_CART2
2D cartesian.
Definition: qpms_types.h:244
@ QPMS_COORDS_CART3
Definition: qpms_types.h:245
@ QPMS_COORDS_BITRANGE
Convenience bitmask (not a valid flag!).
Definition: qpms_types.h:247
@ QPMS_COORDS_CART1
1D cartesian (= double).
Definition: qpms_types.h:241
@ QPMS_COORDS_SPH
3D spherical.
Definition: qpms_types.h:243
@ QPMS_COORDS_POL
2D polar.
Definition: qpms_types.h:242
union anycoord_point_t anycoord_point_t
Union type capable to contain various 1D, 2D and 3D coordinates.
PGen single-point return data type (2D, cartesian coordinates).
Definition: lattices.h:192
cart2_t point_cart2
Generated point in cartesian coordinates.
Definition: lattices.h:194
PGenPointFlags flags
Metadata.
Definition: lattices.h:193
PGen single-point return data type (3D, cartesian coordinates).
Definition: lattices.h:198
PGenPointFlags flags
Metadata.
Definition: lattices.h:199
cart3_t point_cart3
Generated point in cartesian coordinates.
Definition: lattices.h:200
PGen class metadata.
Definition: lattices.h:231
PGenReturnDataBulk(* fetch_cart3)(struct PGen *, size_t, cart3_t *)
Generate up to n 3D points in cartesian coordinates.
Definition: lattices.h:259
PGenReturnDataBulk(* fetch)(struct PGen *, size_t, anycoord_point_t *)
Generate up to n points in the native coordinates.
Definition: lattices.h:249
void(* destructor)(struct PGen *)
Destructor.
Definition: lattices.h:264
PGenPointFlags native_point_flags
Info about the generator native coordinate system.
Definition: lattices.h:235
PGenReturnDataBulk(* fetch_z)(struct PGen *, size_t, double *)
Generate up to n 1D points.
Definition: lattices.h:251
PGenReturnDataBulk(* fetch_cart2)(struct PGen *, size_t, cart2_t *)
Generate up to n 2D points in cartesian coordinates.
Definition: lattices.h:257
PGenPolReturnData(* next_pol)(struct PGen *)
Generate a single 2D point in polar coordinates.
Definition: lattices.h:241
PGenCart2ReturnData(* next_cart2)(struct PGen *)
Generate a single 2D point in cartesian coordinates.
Definition: lattices.h:245
PGenSphReturnData(* next_sph)(struct PGen *)
Generate a single 3D point in spherical coordinates.
Definition: lattices.h:243
PGenReturnDataBulk(* fetch_pol)(struct PGen *, size_t, pol_t *)
Generate up to n 2D points in polar coordinates.
Definition: lattices.h:253
PGenZReturnData(* next_z)(struct PGen *)
Generate a single 1D point.
Definition: lattices.h:239
PGenCart3ReturnData(* next_cart3)(struct PGen *)
Generate a single 3D point in cartesian coordinates.
Definition: lattices.h:247
PGenReturnDataBulk(* fetch_sph)(struct PGen *, size_t, sph_t *)
Generate up to n 3D points in spherical coordinates.
Definition: lattices.h:255
PGenReturnData(* next)(struct PGen *)
Generate a single point in the native coordinates.
Definition: lattices.h:237
PGen single-point return data type (2D, polar coordinates).
Definition: lattices.h:180
pol_t point_pol
Generated point in polar coordinates.
Definition: lattices.h:182
PGenPointFlags flags
Metadata.
Definition: lattices.h:181
Metadata generated by the fetch*() methods from PGenClassInfo.
Definition: lattices.h:161
size_t generated
Number of points really generated.
Definition: lattices.h:164
PGenPointFlags flags
Flags describing the returned data.
Definition: lattices.h:163
Generic PGen return type that might contain point represented in any of the supported coordinate syst...
Definition: lattices.h:168
anycoord_point_t point
Generated point in a coordinate system defined by flags.
Definition: lattices.h:170
PGenPointFlags flags
Metadata, must contain valid coordinate system defining flags.
Definition: lattices.h:169
PGen single-point return data type (3D, spherical coordinates).
Definition: lattices.h:186
sph_t point_sph
Generated point in spherical coordinates.
Definition: lattices.h:188
PGenPointFlags flags
Metadata.
Definition: lattices.h:187
PGen single-point return data type (1D).
Definition: lattices.h:174
double point_z
Generated point on a real axis.
Definition: lattices.h:176
PGenPointFlags flags
Medatata.
Definition: lattices.h:175
Generic lattice point generator type.
Definition: lattices.h:120
void * stateData
Pointer to internal state data; shall be NULL if invalid (destroyed);.
Definition: lattices.h:124
const struct PGenClassInfo * c
Pointer to the "class" metadata defining the behaviour of the generator.
Definition: lattices.h:122
2D cartesian coordinates. See also vectors.h.
Definition: qpms_types.h:202
3D cartesian coordinates. See also vectors.h.
Definition: qpms_types.h:186
Definition: lattices.h:931
Definition: lattices.h:763
2D polar coordinates. See also vectors.h.
Definition: qpms_types.h:223
Spherical coordinates. See also vectors.h.
Definition: qpms_types.h:207
Definition: lattices2d.c:258
Definition: lattices.h:901
Union type capable to contain various 1D, 2D and 3D coordinates.
Definition: qpms_types.h:229
double z
1D cartesian coordinate.
Definition: qpms_types.h:230
Coordinate transforms and vector arithmetics.
static pol_t anycoord2pol(anycoord_point_t p, qpms_coord_system_t t)
Conversion from anycoord_point_t to explicitly polar coordinates.
Definition: vectors.h:523
static sph_t cart2sph(const cart3_t cart)
3D cartesian to spherical coordinates conversion. See Coordinate systems and default conversions.
Definition: vectors.h:134
static cart3_t anycoord2cart3(anycoord_point_t p, qpms_coord_system_t t)
Conversion from anycoord_point_t to explicitly 3D cartesian coordinates.
Definition: vectors.h:484
static void anycoord_arr2something(void *dest, qpms_coord_system_t tdest, const anycoord_point_t *src, qpms_coord_system_t tsrc, size_t nmemb)
Coordinate conversion of point arrays (anycoord_point_t to something).
Definition: vectors.h:746
static sph_t anycoord2sph(anycoord_point_t p, qpms_coord_system_t t)
Conversion from anycoord_point_t to explicitly spherical coordinates.
Definition: vectors.h:459
static cart3_t sph2cart(const sph_t sph)
Spherical to 3D cartesian coordinates conversion. See Coordinate systems and default conversions.
Definition: vectors.h:143
static double anycoord2cart1(anycoord_point_t p, qpms_coord_system_t t)
Conversion from anycoord_point_t to explicitly 1D cartesian coordinates.
Definition: vectors.h:573
static cart2_t anycoord2cart2(anycoord_point_t p, qpms_coord_system_t t)
Conversion from anycoord_point_t to explicitly 2D cartesian coordinates.
Definition: vectors.h:548