Hawaii Hybrid
Loading...
Searching...
No Matches
hawaii.h
Go to the documentation of this file.
1#ifndef HAWAII_H_
2#define HAWAII_H_
3
4#include <assert.h>
5#include <errno.h>
6#include <stdarg.h>
7#include <stdbool.h>
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <regex.h>
12#include <time.h>
13#include <unistd.h>
14
15#ifdef USE_MPI
16#include <mpi.h>
17#endif // USE_MPI
18
19#include <gsl/gsl_histogram.h>
20#include <gsl/gsl_blas.h>
21#include <gsl/gsl_vector.h>
22#include <gsl/gsl_linalg.h>
23#include <gsl/gsl_multifit_nlinear.h>
24#include <gsl/gsl_spline.h>
25
26#include <gsl/gsl_fft_real.h>
27#include <gsl/gsl_fft_complex.h>
28#include <gsl/gsl_fft_halfcomplex.h>
29
30#include <gsl/gsl_rng.h>
31#include <gsl/gsl_randist.h>
32
33#define OMPI_SKIP_MPICXX
34
35#ifndef __cplusplus
36#define _GNU_SOURCE
37void sincos(double, double*, double*);
38int syncfs(int);
39#endif
40#include <math.h>
41#include <complex.h>
42
43#ifndef __cplusplus
44#define MT_GENERATE_CODE_IN_HEADER 0
45#endif
46#include "mtwist.h"
47/*
48 * We are using the following functions from mtwist:
49 * double mt_drand(void)
50 * Return a pseudorandom double in [0,1) with 32 bits of randomness
51 *
52 * uint32_t mt_lrand(void);
53 * Generate 32-bit random value
54 */
55
56
57#include <cvode/cvode.h>
58#include <nvector/nvector_serial.h>
59
60#include "array.h"
61#include "constants.h"
62#include "arena.h"
63
64#define IPHI 0
65#define IPPHI 1
66#define ITHETA 2
67#define IPTHETA 3
68#define IR 4
69#define IPR 5
70// used only in Monomer.qp
71#define IPSI 4
72#define IPPSI 5
73
74#define UNUSED(x) (void)(x)
75#define TODO(message) do { fprintf(stderr, "%s:%d: TODO: %s\n", __FILE__, __LINE__, message); abort(); } while(0)
76#define UNREACHABLE(message) do { fprintf(stderr, "%s:%d: UNREACHABLE: %s\n", __FILE__, __LINE__, message); abort(); } while(0)
77
78#define return_defer(value) do { result = (value); goto defer; } while(0)
79
80#define DA_INIT_CAP 256
81#define da_append(da, item) \
82 do { \
83 if ((da)->count >= (da)->capacity) { \
84 (da)->capacity = (da)->capacity == 0 ? DA_INIT_CAP : (da)->capacity*2; \
85 (da)->items = realloc((da)->items, (da)->capacity*sizeof(*(da)->items)); \
86 assert((da)->items != NULL && "ASSERT: not enough memory\n"); \
87 } \
88 \
89 (da)->items[(da)->count++] = (item); \
90 } while (0)
91
92#define da_insert(da, i, item) \
93 do { \
94 if ((i < 0) || ((i) > (da)->count)) { \
95 assert(0 && "ASSERT: index out of bounds\n"); \
96 } \
97 if ((da)->count >= (da)->capacity) { \
98 (da)->capacity = (da)->capacity == 0 ? DA_INIT_CAP : (da)->capacity*2; \
99 (da)->items = realloc((da)->items, (da)->capacity*sizeof(*(da)->items)); \
100 assert((da)->items != NULL && "ASSERT: not enough memory\n"); \
101 } \
102 memmove((da)->items + (i) + 1, (da)->items + (i), ((da)->count - (i))*sizeof(*(da)->items)); \
103 (da)->items[(i)] = (item); \
104 (da)->count++; \
105 } while(0)
106
107#define da_last(da) (da)->items[(da)->count - 1]
108
109extern int _wrank;
110extern int _wsize;
111extern bool _print0_suppress_info;
112extern int _print0_margin;
113
114#ifdef USE_MPI
115#define INIT_WRANK \
116 MPI_Comm_rank(MPI_COMM_WORLD, &_wrank); \
117
118#define INIT_WSIZE \
119 MPI_Comm_size(MPI_COMM_WORLD, &_wsize); \
120
121#define INFO(...) \
122 if ((_wrank == 0) && !_print0_suppress_info) { \
123 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
124 printf("INFO: "); printf(__VA_ARGS__); \
125 }
126
127#define WARNING(...) \
128 if (_wrank == 0) { \
129 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
130 printf("WARNING: "); printf(__VA_ARGS__); \
131 }
132
133#define ERROR(...) \
134 if (_wrank == 0) { \
135 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
136 printf("ERROR: "); printf(__VA_ARGS__); \
137 }
138
139#define PRINT0(...) \
140 if (_wrank == 0) { \
141 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
142 printf(__VA_ARGS__); \
143 }
144
145#else
146#define INIT_WRANK
147#define INIT_WSIZE
148
149#define INFO(...) \
150 if (!_print0_suppress_info) { \
151 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
152 printf(__VA_ARGS__); \
153 }
154
155#define WARNING(...) \
156 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
157 printf("WARNING: "); printf(__VA_ARGS__); \
158
159#define ERROR(...) \
160 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
161 printf("ERROR: "); printf(__VA_ARGS__); \
162
163#define PRINT0(...) \
164 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
165 printf(__VA_ARGS__);
166
167
168#endif
169
170#ifdef __cplusplus
171extern "C" {
172#endif
173
174#define MONOMER_COUNT 6
175#define MODULO_BASE 100
191
193
194// note: gsl_histogram does have fields for nbins and max but I don't want
195// to access them when deciding on what the values should be, so we will have "duplicates"
196// The values of 'nbins' and 'max' are the initial values, and can be updated when
197// the histogram is extended.
198typedef struct {
199 gsl_histogram *h;
200 size_t nbins;
201 double max;
202 char *filename;
203 FILE *fp;
206
256
277typedef struct {
281 double mu;
282
283 size_t Q_SIZE;
284 size_t QP_SIZE;
285
287 double *dVdq;
288
289 size_t seed;
290
291 // time_t: time as the number of seconds since the Epoch (1970-01-01)
295
308
309extern const char *PAIR_STATES[PAIR_STATE_COUNT];
310
321
323
324typedef struct {
327
328 /* sampling */
329 double sampler_Rmin; // a.u.
330 double sampler_Rmax; // a.u.
331 double pesmin; // Hartree
332
333 /* initial spectral moments check */
337
344
345 /* weights to factor in spin statistics */
348
349 /* trajectory */
350 double sampling_time; // a.t.u.
354
355 /* iteration parameters :: applicable to both correlation function AND spectral function calculations */
356 size_t niterations; // the accumulation of the total_trajectories is split into this number of iterations
357 size_t total_trajectories; // the total number of accumulated trajectories (ALL iterations)
358
359 /* correlation function and correlation function array calculations ONLY */
360 const char* cf_filename;
361 double Rcut; // distance at which the trajectory is forcefully stopped, a.u.
363
364 /* pr/mu spectral function calculation ONLY */
365 const char *sf_filename;
367 double R0; // initial distance, a.u.
369
370 /* correlation function array ONLY */
374 const char **cf_filenames;
375} CalcParams;
376
377
378
379typedef enum {
383
384
385typedef struct {
386 double *t;
387 double *data;
388 size_t len; // # of samples in *t, *data
389 size_t capacity; // capacity *t, *data
390 double ntraj; // # of trajectories used for averaging
392 bool normalized; // flag that indicates whether the *data samples are normalized by # of trajectories
393} CFnc;
394
395typedef struct {
397 size_t count;
398 size_t capacity;
399} CFncs;
400
401
402/*
403 * An array of correlation functions for a fixed 'base temperature'
404 * 'base temperature' -- a temperature for which sampling of initial conditions is performed
405 * 'satellite temperature' -- a target temperature for which correlation function is re-weighted
406 */
407typedef struct {
408 double *t;
409 double **data;
410 size_t ntemp;
411 size_t len; // # of samples in *t and elements of *data
412 double *nstar; // array of # effective trajectories
413 size_t ntraj; // # of calculated trajectories
414} CFncArray;
415
416// SFnc may originate from CFnc which itself was derived
417// via multi-temperature reweighting. As a result its 'ntraj'
418// turns out be floating-point value rather than an integer
419typedef struct {
420 double *nu;
421 double *data;
422 size_t len; // # of samples in *nu, *data
423 size_t capacity; // capacity of *nu, *data
424 double ntraj; // # of trajectories used for averaging
427} SFnc;
428
429
430typedef struct {
431 double *nu;
432 double *data;
433 size_t len; // # of samples of *nu, *data
434 size_t capacity; // capacity of *nu, *data
435 double ntraj; // # of trajectories used for averaging
438} Spectrum;
439
440typedef struct {
442 size_t count;
443 size_t capacity;
444} Spectra;
445
446/*
447 * MODEL: Lorentzian function shifted upwards by constant:
448 * y = C + A /(1 + B^2 x^2)
449 */
450typedef struct {
451 double A;
452 double B;
453 double C;
454} WingParams;
455
456typedef struct {
457 size_t n;
458 double* t;
459 double* y;
460} WingData;
461
462typedef struct {
463 double before2;
464 double before;
465 double current;
466
468
469 size_t called;
470 bool ready;
471} Tracker;
472
473
474/* ---------------------------------------------------------------------------------------------------------------- */
475/* -------------------------- User-Supplied Functions: loaded from dynamic libs --------------------------------- */
476/* ---------------------------------------------------------------------------------------------------------------- */
481typedef void (*dipolePtr)(double*, double[3]);
482extern dipolePtr dipole_1;
483extern dipolePtr dipole_2;
484
485typedef void (*dipoleFree)(void);
488
497typedef double (*pesPtr)(double*);
498extern pesPtr pes;
499
508typedef void (*dpesPtr)(double*, double*);
509extern dpesPtr dpes;
510/* ---------------------------------------------------------------------------------------------------------------- */
511
512MoleculeSystem init_ms(double mu, MonomerType t1, MonomerType t2, double *I1, double *I2, size_t seed);
513MoleculeSystem init_ms_from_monomers(double mu, Monomer *m1, Monomer *m2, size_t seed);
514void free_ms(MoleculeSystem *ms);
515
516#ifdef USE_MPI
517CFnc calculate_correlation_and_save(MoleculeSystem *ms, CalcParams *params, double Temperature);
519CFncArray calculate_correlation_array_and_save(MoleculeSystem *ms, CalcParams *params, double base_temperature);
520#endif // USE_MPI
521
522const char* display_monomer_type(MonomerType t);
523
525void get_qp_from_ms(MoleculeSystem *ms, Array *qp);
526
527// this function takes the phase point from MoleculeSystem
528// and packs it into "intermediate_q" field. Then this pointer
529// can be passed to potential energy / its derivatives / dipole function
531
532// this function takes the corresponding components of "ms.dVdq" and writes
533// them into "m.dVdq" vectors for each monomer
535
536// 20.12.2024 NOTE:
537// the MoleculeSystem struct needs to be passed as void* into "rhs" function.
538// Then, the first step is to write the phase point (N_Vector y) into the fields of MoleculeSystem
539// using the method "put_qp_into_ms".
540int rhs(realtype t, N_Vector y, N_Vector ydot, void *data);
541
542Array compute_numerical_derivatives(double (*f)(double *q), double *q, size_t len, size_t order);
543Array compute_numerical_rhs(MoleculeSystem *ms, size_t order);
544gsl_matrix* compute_numerical_jac(void (*transform_angles)(double *qlab, double *qmol), double *qlab, size_t ninput_coordinates, size_t noutput_coordinates, size_t order);
545
547double Hamiltonian(MoleculeSystem *ms);
548
549double generate_normal(double sigma);
550
551void q_generator(MoleculeSystem *ms, CalcParams *params);
552void p_generator(MoleculeSystem *ms, double Temperature);
553bool reject(MoleculeSystem *ms, double Temperature, double pesmin);
554
555void try_applying_requantization_for_monomer(Monomer *m, size_t step_counter);
556void j_monomer(Monomer *m, double j[3]);
557double torque_monomer(Monomer *m);
558double find_closest_integer(double j);
559double find_closest_half_integer(double j);
560
562
563double analytic_full_partition_function_by_V(MoleculeSystem *ms, double Temperature);
564
565// ----------------------------------------------------------
566// Spectral moments calculation
567// ----------------------------------------------------------
568double integrate_composite_simpson(double *x, double *y, size_t len);
569bool compute_Mn_from_cf_using_classical_detailed_balance(CFnc cf, size_t n, double *result);
572void calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
573void compute_dHdp(MoleculeSystem *ms, gsl_matrix* dHdp);
574void calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
575
576#ifdef USE_MPI
577void mpi_calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
578void mpi_calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
579#endif // USE_MPI
580// ----------------------------------------------------------
581
582
583int assert_float_is_equal_to(double estimate, double true_value, double abs_tolerance);
584
585double* linspace(double start, double end, size_t n);
586double* arena_linspace(Arena *a, double start, double end, size_t n);
587size_t* arena_linspace_size_t(Arena *a, size_t start, size_t end, size_t n);
588
589// ----------------------------------------------------------
590// Histogram manipulation
591// ----------------------------------------------------------
592void send_histogram_and_reset(gsl_histogram *h);
593void recv_histogram_and_append(Arena *a, int source, gsl_histogram **h);
594gsl_histogram* gsl_histogram_extend_right(gsl_histogram* h, size_t add_bins);
595int write_histogram_ext(FILE *fp, gsl_histogram *h, int count);
596// ----------------------------------------------------------
597
598// ----------------------------------------------------------
599// String manipulation
600// ----------------------------------------------------------
601/*
602 * This struct represents a resizable buffer designed to build strings
603 * dynamically. It stores characters in a contiguous block of memory,
604 * allowing for manipulation of strings.
605 */
606typedef struct {
607 char *items;
608 size_t count;
609 size_t capacity;
611
612void sb_reserve(String_Builder *sb, size_t n);
613void sb_append(String_Builder *sb, const char *line, size_t n);
615void sb_append_cstring(String_Builder *sb, const char *line);
616void sb_append_format(String_Builder *sb, const char *format, ...);
618void sb_reset(String_Builder *sb);
619void sb_free(String_Builder *sb);
620// ----------------------------------------------------------
621
622// ----------------------------------------------------------
623// Processing the results
624// ----------------------------------------------------------
628
629void normalize_cfnc(CFnc *cf);
630
631void free_cfnc(CFnc cf);
633void free_sfnc(SFnc cf);
634void free_spectrum(Spectrum sp);
635
636bool writetxt(const char *filename, double *x, double *y, size_t len, const char *header);
637
638bool write_correlation_function(const char *filename, CFnc cf);
639int write_correlation_function_ext(FILE *fp, CFnc cf);
640
641bool write_spectral_function(const char *filename, SFnc sf);
642int write_spectral_function_ext(FILE *fp, SFnc sf);
643
644bool write_spectrum(const char *filename, Spectrum sp);
645int write_spectrum_ext(FILE *fp, Spectrum sp);
646
647bool parse_number_of_trajectories_from_header(const char *header, double *ntraj);
648bool parse_temperature_from_header(const char *header, double *Temperature);
649
650bool read_correlation_function(const char *filename, String_Builder *sb, CFnc *cf);
651bool read_spectral_function(const char *filename, String_Builder *sb, SFnc *sf);
652bool read_spectrum(const char *filename, String_Builder *sb, Spectrum *sp);
653
654bool average_correlation_functions(CFnc *average, CFncs cfncs);
655#define average_correlation_functions_ext(average, ...) average_correlation_functions__impl(average, sizeof((CFnc[]){__VA_ARGS__}) / sizeof(CFnc), __VA_ARGS__)
656int average_correlation_functions__impl(CFnc *average, int arg_count, ...);
657
658void connes_apodization(Array a, double sampling_time);
659double *dct(double *v, size_t len);
660double *idct(double *v, size_t len);
663
665
675CFnc egelstaff_time_transform(CFnc cf, bool frommhold_renormalization);
678
679double* pad_to_power_of_two(double* v, size_t len, size_t* padded_len);
680
681extern WingParams INIT_WP;
682double wingmodel(WingParams *wp, double t);
683double wingmodel_image(WingParams *wp, double nu);
684
685int wingmodel_f(const gsl_vector* x, void* data, gsl_vector* f);
686int wingmodel_df(const gsl_vector* x, void* data, gsl_matrix * J);
687
688void gsl_nonlinear_opt(size_t n, double* x, double* y, WingParams *wing_params);
689WingParams fit_baseline(CFnc *cf, size_t EXT_RANGE_MIN);
690
691
692/* Uses bit hack taken from: http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
693static inline bool is_power_of_two(size_t n) {
694 return n && !(n & (n - 1));
695}
696
697static inline unsigned int round_to_next_power_of_two(unsigned int n)
698/*
699 * rounds up to the next highest power of 2 using a clever bit hack
700 * Taken from:
701 * https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
702 *
703 * works on 32-bit numbers
704 */
705{
706 n--;
707 n |= n >> 1;
708 n |= n >> 2;
709 n |= n >> 4;
710 n |= n >> 8;
711 n |= n >> 16;
712 n++;
713
714 return n;
715}
716
717#ifdef __cplusplus
718}
719#endif
720
721#endif // HAWAII_H_
void mpi_calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
mpi_calculate_M0
Definition hawaii.c:1661
WingParams INIT_WP
Definition hawaii.c:5360
CFnc calculate_correlation_and_save(MoleculeSystem *ms, CalcParams *params, double Temperature)
calculate_correlation_and_save
Definition hawaii.c:3014
void mpi_calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
mpi_calculate_M2
Definition hawaii.c:1781
pesPtr pes
Definition hawaii.c:36
int _wsize
Definition hawaii.c:40
int _wrank
Definition hawaii.c:39
const char * CALCULATION_TYPES[CALCULATION_TYPES_COUNT]
Definition hawaii.c:54
dpesPtr dpes
Definition hawaii.c:37
dipolePtr dipole_1
Definition hawaii.c:32
dipolePtr dipole_2
Definition hawaii.c:34
dipoleFree free_dipole_2
Definition hawaii.c:35
SFnc calculate_spectral_function_using_prmu_representation_and_save(MoleculeSystem *ms, CalcParams *params, double Temperature)
calculate_spectral_function_using_prmu_representation_and_save
Definition hawaii.c:3434
MonomerType MONOMER_TYPES[MONOMER_COUNT]
Definition hawaii.c:66
dipoleFree free_dipole_1
Definition hawaii.c:33
const char * PAIR_STATES[PAIR_STATE_COUNT]
Definition hawaii.c:46
bool _print0_suppress_info
Definition hawaii.c:41
int _print0_margin
Definition hawaii.c:42
CFncArray calculate_correlation_array_and_save(MoleculeSystem *ms, CalcParams *params, double base_temperature)
calculate_correlation_array_and_save
Definition hawaii.c:2445
void extract_dVdq_and_write_into_monomers(MoleculeSystem *ms)
Definition hawaii.c:581
double compute_Mn_from_sf_using_quantum_detailed_balance(SFnc sf, size_t n)
Definition hawaii.c:6330
MonomerType
MonomerType enum is used to distinguish between systems of different types and stores the phase point...
Definition hawaii.h:183
@ ROTOR
Represents a rotor with phase point size 6.
Definition hawaii.h:188
@ LINEAR_MOLECULE_REQ_HALFINTEGER
Represents a linear molecule with half-integer angular momentum with phase point size 4.
Definition hawaii.h:187
@ ROTOR_REQUANTIZED_ROTATION
Represents a rotor with requantized rotation with phase point size 6.
Definition hawaii.h:189
@ ATOM
Represents an atom with phase point size 0.
Definition hawaii.h:184
@ LINEAR_MOLECULE
Represents a linear molecule with phase point size 4.
Definition hawaii.h:185
@ LINEAR_MOLECULE_REQ_INTEGER
Represents a linear molecule with integer angular momentum with phase point size 4.
Definition hawaii.h:186
void invert_momenta(MoleculeSystem *ms)
invert_momenta
Definition hawaii.c:1212
SFnc desymmetrize_d1(SFnc sf)
Definition hawaii.c:6066
bool write_correlation_function(const char *filename, CFnc cf)
Definition hawaii.c:4345
double find_closest_integer(double j)
find_closest_integer
Definition hawaii.c:401
void sb_append_seconds_as_datetime_string(String_Builder *sb, int seconds)
Definition hawaii.c:4688
int wingmodel_f(const gsl_vector *x, void *data, gsl_vector *f)
Definition hawaii.c:5375
void get_qp_from_ms(MoleculeSystem *ms, Array *qp)
Definition hawaii.c:1192
SFnc copy_sfnc(SFnc sf)
Definition hawaii.c:6384
bool parse_number_of_trajectories_from_header(const char *header, double *ntraj)
Definition hawaii.c:5117
double * pad_to_power_of_two(double *v, size_t len, size_t *padded_len)
Definition hawaii.c:5774
void sincos(double, double *, double *)
bool read_spectral_function(const char *filename, String_Builder *sb, SFnc *sf)
Definition hawaii.c:4978
#define MONOMER_COUNT
Definition hawaii.h:174
int write_spectral_function_ext(FILE *fp, SFnc sf)
Definition hawaii.c:4441
void normalize_cfnc(CFnc *cf)
Definition hawaii.c:3003
MoleculeSystem init_ms_from_monomers(double mu, Monomer *m1, Monomer *m2, size_t seed)
Function init_ms_from_monomers prepares the MoleculeSystem based on the provided Monomer structs,...
Definition hawaii.c:75
void gsl_nonlinear_opt(size_t n, double *x, double *y, WingParams *wing_params)
Definition hawaii.c:5444
void send_histogram_and_reset(gsl_histogram *h)
Definition hawaii.c:2996
double torque_monomer(Monomer *m)
torque_monomer computes the magnitude of torque (time-derivative of angular momentum) of passed-in mo...
Definition hawaii.c:474
CFnc dct_sf_to_cf(SFnc sf)
Definition hawaii.c:5822
bool writetxt(const char *filename, double *x, double *y, size_t len, const char *header)
Definition hawaii.c:5256
void connes_apodization(Array a, double sampling_time)
Definition hawaii.c:5620
gsl_matrix * compute_numerical_jac(void(*transform_angles)(double *qlab, double *qmol), double *qlab, size_t ninput_coordinates, size_t noutput_coordinates, size_t order)
compute_numerical_jac
Definition hawaii.c:659
Spectrum inv_desymmetrize_d2(Spectrum sp)
Definition hawaii.c:6037
void free_cfnc_array(CFncArray ca)
Definition hawaii.c:5339
bool write_spectrum(const char *filename, Spectrum sp)
Definition hawaii.c:4268
void j_monomer(Monomer *m, double j[3])
j_monomer computes the magnitude of angular momentum of passed-in monomer. Currently,...
Definition hawaii.c:439
double(* pesPtr)(double *)
Definition hawaii.h:497
bool compute_Mn_from_cf_using_classical_detailed_balance(CFnc cf, size_t n, double *result)
Definition hawaii.c:6264
double compute_Mn_from_sf_using_classical_detailed_balance(SFnc sf, size_t n)
Definition hawaii.c:6300
bool write_spectral_function(const char *filename, SFnc sf)
Definition hawaii.c:4425
void extract_q_and_write_into_ms(MoleculeSystem *ms)
Definition hawaii.c:1206
Spectrum copy_spectrum(Spectrum sp)
Definition hawaii.c:6404
double integrate_composite_simpson(double *x, double *y, size_t len)
Definition hawaii.c:6245
void put_qp_into_ms(MoleculeSystem *ms, Array qp)
Definition hawaii.c:1180
CFnc egelstaff_time_transform(CFnc cf, bool frommhold_renormalization)
Definition hawaii.c:6088
void sb_append_cstring(String_Builder *sb, const char *line)
Definition hawaii.c:4628
MoleculeSystem init_ms(double mu, MonomerType t1, MonomerType t2, double *I1, double *I2, size_t seed)
Function init_ms prepares the MoleculeSystem based on the specified monomer types,...
Definition hawaii.c:183
void sb_append_format(String_Builder *sb, const char *format,...)
Definition hawaii.c:4652
double analytic_full_partition_function_by_V(MoleculeSystem *ms, double Temperature)
Definition hawaii.c:5290
double wingmodel_image(WingParams *wp, double nu)
Definition hawaii.c:5370
void free_ms(MoleculeSystem *ms)
Definition hawaii.c:351
bool reject(MoleculeSystem *ms, double Temperature, double pesmin)
reject applies the rejection step to the phase-point that is stored in the MoleculeSystem....
Definition hawaii.c:1423
Spectrum inv_desymmetrize_schofield(Spectrum sp)
Definition hawaii.c:5959
void p_generator(MoleculeSystem *ms, double Temperature)
Function p_generator samples momenta from distribution at given temperature.
Definition hawaii.c:1371
double find_closest_half_integer(double j)
find_closest_half_integer
Definition hawaii.c:412
void q_generator(MoleculeSystem *ms, CalcParams *params)
Function q_generator generates with density in the range [params.sampler_Rmin, params....
Definition hawaii.c:1273
int rhs(realtype t, N_Vector y, N_Vector ydot, void *data)
rhs function is passed to CVode library to propagate the trajectory. First, the phase-point coordinat...
Definition hawaii.c:594
void(* dipoleFree)(void)
Definition hawaii.h:485
int average_correlation_functions__impl(CFnc *average, int arg_count,...)
Definition hawaii.c:4897
#define MODULO_BASE
Definition hawaii.h:175
bool parse_temperature_from_header(const char *header, double *Temperature)
Definition hawaii.c:5075
SFnc desymmetrize_egelstaff_from_cf(CFnc cf)
Definition hawaii.c:6160
void sb_append(String_Builder *sb, const char *line, size_t n)
Definition hawaii.c:4578
int write_histogram_ext(FILE *fp, gsl_histogram *h, int count)
Definition hawaii.c:4497
int syncfs(int)
double kinetic_energy(MoleculeSystem *ms)
Function kinetic_energy computes the kinetic energy at the phase-point stored in MoleculeSystem.
Definition hawaii.c:1082
double * arena_linspace(Arena *a, double start, double end, size_t n)
Definition hawaii.c:4226
double * dct(double *v, size_t len)
Definition hawaii.c:5631
double * linspace(double start, double end, size_t n)
Definition hawaii.c:4205
SFnc desymmetrize_schofield_sf(SFnc sf)
Definition hawaii.c:5915
PairState
PairState is an enumeration representing the possible states of a pair.
Definition hawaii.h:301
@ PAIR_STATE_COUNT
Enum counter value (not a valid state). Used for array sizing.
Definition hawaii.h:306
@ PAIR_STATE_FREE_AND_METASTABLE
Free and metastable states (TODO: automatically separate the contributions based on the number of tur...
Definition hawaii.h:303
@ PAIR_STATE_BOUND
Bound states.
Definition hawaii.h:304
@ PAIR_STATE_NONE
Default/uninitialized state.
Definition hawaii.h:302
@ PAIR_STATE_ALL
Represents the totality of all possible states (aggregate value).
Definition hawaii.h:305
void free_cfnc(CFnc cf)
Definition hawaii.c:5334
void sb_append_null(String_Builder *sb)
Definition hawaii.c:4603
void sb_reset(String_Builder *sb)
Definition hawaii.c:4619
SFnc desymmetrize_d2_sf(SFnc sf)
Definition hawaii.c:5981
SFnc desymmetrize_frommhold(SFnc sf)
Definition hawaii.c:6139
size_t * arena_linspace_size_t(Arena *a, size_t start, size_t end, size_t n)
Definition hawaii.c:4247
void free_sfnc(SFnc cf)
Definition hawaii.c:5350
CFnc copy_cfnc(CFnc cf)
Definition hawaii.c:6364
void calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
calculate_M0 Running mean/variance formulas taken from GSL 1.15 https://github.com/ampl/gsl/blob/mast...
Definition hawaii.c:1464
bool read_spectrum(const char *filename, String_Builder *sb, Spectrum *sp)
Definition hawaii.c:5160
void sb_reserve(String_Builder *sb, size_t n)
Definition hawaii.c:4557
double wingmodel(WingParams *wp, double t)
Definition hawaii.c:5366
void sb_free(String_Builder *sb)
Definition hawaii.c:4710
gsl_histogram * gsl_histogram_extend_right(gsl_histogram *h, size_t add_bins)
Definition hawaii.c:5311
void compute_dHdp(MoleculeSystem *ms, gsl_matrix *dHdp)
compute_dHdp
Definition hawaii.c:1534
void(* dipolePtr)(double *, double[3])
Definition hawaii.h:481
Array compute_numerical_derivatives(double(*f)(double *q), double *q, size_t len, size_t order)
compute_numerical_derivatives
Definition hawaii.c:794
Spectrum desymmetrize_d2_sp(Spectrum sp)
Definition hawaii.c:6009
int wingmodel_df(const gsl_vector *x, void *data, gsl_matrix *J)
Definition hawaii.c:5402
SFnc desymmetrize_egelstaff(SFnc sf)
Definition hawaii.c:6202
double * idct(double *v, size_t len)
Definition hawaii.c:5697
int write_spectrum_ext(FILE *fp, Spectrum sp)
Definition hawaii.c:4284
void free_spectrum(Spectrum sp)
Definition hawaii.c:5355
const char * display_monomer_type(MonomerType t)
Definition hawaii.c:381
void recv_histogram_and_append(Arena *a, int source, gsl_histogram **h)
Definition hawaii.c:3407
void calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
calculate_M2 Running mean/variance formulas taken from GSL 1.15 https://github.com/ampl/gsl/blob/mast...
Definition hawaii.c:1565
int assert_float_is_equal_to(double estimate, double true_value, double abs_tolerance)
Definition hawaii.c:4191
SFnc idct_cf_to_sf(CFnc cf)
Definition hawaii.c:5788
SamplingType
Definition hawaii.h:379
@ MCMC
Definition hawaii.h:381
@ REJECT
Definition hawaii.h:380
CalculationType
Definition hawaii.h:311
@ CALCULATION_NONE
Definition hawaii.h:312
@ CALCULATION_TYPES_COUNT
Definition hawaii.h:319
@ CALCULATION_CORRELATION_ARRAY
Definition hawaii.h:315
@ CALCULATION_CORRELATION_SINGLE
Definition hawaii.h:314
@ CALCULATION_PR_MU
Definition hawaii.h:313
@ CALCULATION_PROCESSING
Definition hawaii.h:316
@ CALCULATION_PHASE_SPACE_M0
Definition hawaii.h:317
@ CALCULATION_PHASE_SPACE_M2
Definition hawaii.h:318
Spectrum compute_alpha(SFnc sf)
Definition hawaii.c:6223
WingParams fit_baseline(CFnc *cf, size_t EXT_RANGE_MIN)
Definition hawaii.c:5544
void try_applying_requantization_for_monomer(Monomer *m, size_t step_counter)
Definition hawaii.c:2157
SFnc desymmetrize_frommhold_from_cf(CFnc cf)
Definition hawaii.c:6181
bool read_correlation_function(const char *filename, String_Builder *sb, CFnc *cf)
Definition hawaii.c:4721
void(* dpesPtr)(double *, double *)
Definition hawaii.h:508
Array compute_numerical_rhs(MoleculeSystem *ms, size_t order)
compute_numerical_rhs Computes the right-hand side of Hamilton's equations of motion using finite-dif...
Definition hawaii.c:882
int write_correlation_function_ext(FILE *fp, CFnc cf)
Definition hawaii.c:4361
Spectrum desymmetrize_schofield_sp(Spectrum sp)
Definition hawaii.c:5937
double generate_normal(double sigma)
Definition hawaii.c:1247
bool average_correlation_functions(CFnc *average, CFncs cfncs)
Definition hawaii.c:4818
double Hamiltonian(MoleculeSystem *ms)
Function Hamiltonian calls kinetic_energy function to compute kinetic energy, assembles a contiguous ...
Definition hawaii.c:1231
Definition arena.h:56
Definition array.h:11
Definition hawaii.h:407
size_t ntemp
Definition hawaii.h:410
size_t ntraj
Definition hawaii.h:413
double * t
Definition hawaii.h:408
size_t len
Definition hawaii.h:411
double ** data
Definition hawaii.h:409
double * nstar
Definition hawaii.h:412
Definition hawaii.h:385
double * data
Definition hawaii.h:387
bool normalized
Definition hawaii.h:392
size_t capacity
Definition hawaii.h:389
size_t len
Definition hawaii.h:388
double * t
Definition hawaii.h:386
double Temperature
Definition hawaii.h:391
double ntraj
Definition hawaii.h:390
Definition hawaii.h:395
size_t capacity
Definition hawaii.h:398
size_t count
Definition hawaii.h:397
CFnc ** items
Definition hawaii.h:396
Definition hawaii.h:324
size_t hep_ppf_niterations
Definition hawaii.h:342
double partial_partition_function_ratio
Definition hawaii.h:336
double ApproximateFrequencyMax
Definition hawaii.h:366
double R0
Definition hawaii.h:367
const char ** cf_filenames
Definition hawaii.h:374
size_t hep_ppf_npoints
Definition hawaii.h:343
const char * sf_filename
Definition hawaii.h:365
size_t hep_m0_npoints
Definition hawaii.h:339
size_t total_trajectories
Definition hawaii.h:357
size_t initialM2_npoints
Definition hawaii.h:335
const char * cf_filename
Definition hawaii.h:360
double sampling_time
Definition hawaii.h:350
bool use_zimmermann_trick
Definition hawaii.h:362
PairState ps
Definition hawaii.h:325
double sampler_Rmax
Definition hawaii.h:330
size_t MaxTrajectoryLength
Definition hawaii.h:351
double pesmin
Definition hawaii.h:331
double even_j_spin_weight
Definition hawaii.h:347
CalculationType calculation_type
Definition hawaii.h:326
double * partial_partition_function_ratios
Definition hawaii.h:371
bool allow_truncating_trajectories_at_length_limit
Definition hawaii.h:352
double Rcut
Definition hawaii.h:361
double * satellite_temperatures
Definition hawaii.h:372
size_t num_satellite_temperatures
Definition hawaii.h:373
size_t niterations
Definition hawaii.h:356
double average_time_between_collisions
Definition hawaii.h:368
double odd_j_spin_weight
Definition hawaii.h:346
size_t hep_m2_npoints
Definition hawaii.h:341
size_t hep_m0_niterations
Definition hawaii.h:338
size_t initialM0_npoints
Definition hawaii.h:334
double sampler_Rmin
Definition hawaii.h:329
size_t hep_m2_niterations
Definition hawaii.h:340
double cvode_tolerance
Definition hawaii.h:353
Angular variables and conjugated momenta are stored within the MoleculeSystem struct in the same orde...
Definition hawaii.h:277
size_t QP_SIZE
Total number of coordinates and momenta for molecular pair (phase point size).
Definition hawaii.h:284
size_t Q_SIZE
Total number of coordinates for molecule pair.
Definition hawaii.h:283
double mu
Reduced mass of molecule pair.
Definition hawaii.h:281
Monomer m2
Second monomer.
Definition hawaii.h:280
double * intermediate_q
Contiguous vector of coordinates.
Definition hawaii.h:286
double intermolecular_qp[6]
Coordinates and conjugated momenta that correspond to the intermolecular motion ( ,...
Definition hawaii.h:278
time_t init_rawtime
Initialization time represented as the number of seconds since Unix Epoch; set in init_ms.
Definition hawaii.h:292
double * dVdq
Contiguous vector of potential energy derivatives.
Definition hawaii.h:287
Monomer m1
First monomer.
Definition hawaii.h:279
size_t seed
Definition hawaii.h:289
time_t temp_rawtime
A temporary time field for the time at which the previous iteration of the iterative algorithm was co...
Definition hawaii.h:293
Monomer represents a monomer in a pair with associated dynamic variables. The order of variables in t...
Definition hawaii.h:223
double jini_histogram_max
Definition hawaii.h:245
double jfin_histogram_max
Definition hawaii.h:251
double torque_limit
Torque limiting values to decide when requantization should be switched on/off.
Definition hawaii.h:236
size_t jfin_histogram_bins
Definition hawaii.h:250
char * jfin_histogram_filename
Definition hawaii.h:252
double DJ
Centrifugal distortion constant.
Definition hawaii.h:227
FILE * fp_jfin_histogram
Definition hawaii.h:254
gsl_histogram * jfin_histogram
Definition hawaii.h:253
MonomerType t
Type identifier for the monomer.
Definition hawaii.h:225
bool apply_requantization
Flag indicating whether requantization should be applied.
Definition hawaii.h:232
FILE * fp_jini_histogram
Definition hawaii.h:248
StoredHistogram nswitch_histogram
Definition hawaii.h:242
gsl_histogram * jini_histogram
Definition hawaii.h:247
size_t jini_histogram_bins
Definition hawaii.h:244
double * qp
Dynamic variables (Euler angles and conjugated momenta).
Definition hawaii.h:229
double * dVdq
Derivatives of potential energy with respect to coordinates pertaining to this monomer (the order of ...
Definition hawaii.h:230
double * torque_cache
Cached torque values.
Definition hawaii.h:237
size_t torque_cache_len
Length of the torque cache array.
Definition hawaii.h:235
double II[3]
Values of inertia tensor.
Definition hawaii.h:226
size_t req_switch_counter
Counter for tracking requantization switching events during the single trajectory.
Definition hawaii.h:234
char * jini_histogram_filename
Definition hawaii.h:246
double initial_j
Definition hawaii.h:239
int index
Index of monomer within the molecule system (1 or 2)
Definition hawaii.h:224
Definition hawaii.h:419
double * nu
Definition hawaii.h:420
size_t capacity
Definition hawaii.h:423
double ntraj
Definition hawaii.h:424
bool normalized
Definition hawaii.h:426
double Temperature
Definition hawaii.h:425
size_t len
Definition hawaii.h:422
double * data
Definition hawaii.h:421
Definition hawaii.h:440
size_t count
Definition hawaii.h:442
size_t capacity
Definition hawaii.h:443
Spectrum ** items
Definition hawaii.h:441
Definition hawaii.h:430
double ntraj
Definition hawaii.h:435
bool normalized
Definition hawaii.h:437
double * nu
Definition hawaii.h:431
double * data
Definition hawaii.h:432
double Temperature
Definition hawaii.h:436
size_t len
Definition hawaii.h:433
size_t capacity
Definition hawaii.h:434
Definition hawaii.h:198
char * filename
Definition hawaii.h:202
FILE * fp
Definition hawaii.h:203
gsl_histogram * h
Definition hawaii.h:199
double max
Definition hawaii.h:201
size_t nbins
Definition hawaii.h:200
bool is_allocated
Definition hawaii.h:204
Definition hawaii.h:606
size_t count
Definition hawaii.h:608
size_t capacity
Definition hawaii.h:609
char * items
Definition hawaii.h:607
Definition hawaii.h:462
double before
Definition hawaii.h:464
double current
Definition hawaii.h:465
size_t turning_points
Definition hawaii.h:467
bool ready
Definition hawaii.h:470
size_t called
Definition hawaii.h:469
double before2
Definition hawaii.h:463
Definition hawaii.h:456
double * y
Definition hawaii.h:459
double * t
Definition hawaii.h:458
size_t n
Definition hawaii.h:457
Definition hawaii.h:450
double B
Definition hawaii.h:452
double A
Definition hawaii.h:451
double C
Definition hawaii.h:453