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#include <gsl/gsl_sf_bessel.h>
26
27#include <gsl/gsl_fft_real.h>
28#include <gsl/gsl_fft_complex.h>
29#include <gsl/gsl_fft_halfcomplex.h>
30
31#include <gsl/gsl_rng.h>
32#include <gsl/gsl_randist.h>
33
34#define OMPI_SKIP_MPICXX
35
36#ifndef __cplusplus
37#define _GNU_SOURCE
38void sincos(double, double*, double*);
39int syncfs(int);
40#endif
41#include <math.h>
42#include <complex.h>
43
44#ifndef __cplusplus
45#define MT_GENERATE_CODE_IN_HEADER 0
46#endif
47#include "mtwist.h"
48/*
49 * We are using the following functions from mtwist:
50 * double mt_drand(void)
51 * Return a pseudorandom double in [0,1) with 32 bits of randomness
52 *
53 * uint32_t mt_lrand(void);
54 * Generate 32-bit random value
55 */
56
57
58#include <cvode/cvode.h>
59#include <nvector/nvector_serial.h>
60
61#include "array.h"
62#include "constants.h"
63#include "arena.h"
64
65#define IPHI 0
66#define IPPHI 1
67#define ITHETA 2
68#define IPTHETA 3
69#define IR 4
70#define IPR 5
71// used only in Monomer.qp
72#define IPSI 4
73#define IPPSI 5
74
75#define UNUSED(x) (void)(x)
76#define TODO(message) do { fprintf(stderr, "%s:%d: TODO: %s\n", __FILE__, __LINE__, message); abort(); } while(0)
77#define UNREACHABLE(message) do { fprintf(stderr, "%s:%d: UNREACHABLE: %s\n", __FILE__, __LINE__, message); abort(); } while(0)
78
79#define return_defer(value) do { result = (value); goto defer; } while(0)
80
81#define DA_INIT_CAP 256
82#define da_append(da, item) \
83 do { \
84 if ((da)->count >= (da)->capacity) { \
85 (da)->capacity = (da)->capacity == 0 ? DA_INIT_CAP : (da)->capacity*2; \
86 (da)->items = realloc((da)->items, (da)->capacity*sizeof(*(da)->items)); \
87 assert((da)->items != NULL && "ASSERT: not enough memory\n"); \
88 } \
89 \
90 (da)->items[(da)->count++] = (item); \
91 } while (0)
92
93#define da_insert(da, i, item) \
94 do { \
95 if ((i < 0) || ((i) > (da)->count)) { \
96 assert(0 && "ASSERT: index out of bounds\n"); \
97 } \
98 if ((da)->count >= (da)->capacity) { \
99 (da)->capacity = (da)->capacity == 0 ? DA_INIT_CAP : (da)->capacity*2; \
100 (da)->items = realloc((da)->items, (da)->capacity*sizeof(*(da)->items)); \
101 assert((da)->items != NULL && "ASSERT: not enough memory\n"); \
102 } \
103 memmove((da)->items + (i) + 1, (da)->items + (i), ((da)->count - (i))*sizeof(*(da)->items)); \
104 (da)->items[(i)] = (item); \
105 (da)->count++; \
106 } while(0)
107
108#define da_last(da) (da)->items[(da)->count - 1]
109
110extern int _wrank;
111extern int _wsize;
112extern bool _print0_suppress_info;
113extern int _print0_margin;
114
115#ifdef USE_MPI
116#define INIT_WRANK \
117 MPI_Comm_rank(MPI_COMM_WORLD, &_wrank); \
118
119#define INIT_WSIZE \
120 MPI_Comm_size(MPI_COMM_WORLD, &_wsize); \
121
122#define INFO(...) \
123 if ((_wrank == 0) && !_print0_suppress_info) { \
124 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
125 printf("INFO: "); printf(__VA_ARGS__); \
126 }
127
128#define WARNING(...) \
129 if (_wrank == 0) { \
130 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
131 printf("WARNING: "); printf(__VA_ARGS__); \
132 }
133
134#define ERROR(...) \
135 if (_wrank == 0) { \
136 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
137 printf("ERROR: "); printf(__VA_ARGS__); \
138 }
139
140#define PRINT0(...) \
141 if (_wrank == 0) { \
142 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
143 printf(__VA_ARGS__); \
144 }
145
146#else
147#define INIT_WRANK
148#define INIT_WSIZE
149
150#define INFO(...) \
151 if (!_print0_suppress_info) { \
152 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
153 printf(__VA_ARGS__); \
154 }
155
156#define WARNING(...) \
157 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
158 printf("WARNING: "); printf(__VA_ARGS__); \
159
160#define ERROR(...) \
161 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
162 printf("ERROR: "); printf(__VA_ARGS__); \
163
164#define PRINT0(...) \
165 if (_print0_margin > 0) printf("%*s", _print0_margin, " "); \
166 printf(__VA_ARGS__);
167
168
169#endif
170
171#ifdef __cplusplus
172extern "C" {
173#endif
174
175#define MONOMER_COUNT 6
176#define MODULO_BASE 100
192
194
195// note: gsl_histogram does have fields for nbins and max but I don't want
196// to access them when deciding on what the values should be, so we will have "duplicates"
197// The values of 'nbins' and 'max' are the initial values, and can be updated when
198// the histogram is extended.
199typedef struct {
200 gsl_histogram *h;
201 size_t nbins;
202 double max;
203 char *filename;
204 FILE *fp;
207
257
278typedef struct {
282 double mu;
283
284 size_t Q_SIZE;
285 size_t QP_SIZE;
286
288 double *dVdq;
289
290 size_t seed;
291
292 // time_t: time as the number of seconds since the Epoch (1970-01-01)
296
309
310extern const char *PAIR_STATES[PAIR_STATE_COUNT];
311
323
325
326typedef struct {
329
330 /* sampling */
331 double sampler_Rmin; // a.u.
332 double sampler_Rmax; // a.u.
333 double pesmin; // Hartree
334
335 /* initial spectral moments check */
339
346
347 /* weights to factor in spin statistics */
350
351 /* trajectory */
352 double sampling_time; // a.t.u.
356
357 /* iteration parameters :: applicable to both correlation function AND spectral function calculations */
358 size_t niterations; // the accumulation of the total_trajectories is split into this number of iterations
359 size_t total_trajectories; // the total number of accumulated trajectories (ALL iterations)
360
361 /* correlation function and correlation function array calculations ONLY */
362 const char* cf_filename;
363 double Rcut; // distance at which the trajectory is forcefully stopped, a.u.
365
366 /* pr/mu spectral function calculation ONLY */
367 const char *sf_filename;
369 double R0; // initial distance, a.u.
371
372 /* correlation function array ONLY */
376 const char **cf_filenames;
377} CalcParams;
378
379
380
381typedef enum {
385
386
387typedef struct {
388 double *t;
389 double *data;
390 size_t len; // # of samples in *t, *data
391 size_t capacity; // capacity *t, *data
392 double ntraj; // # of trajectories used for averaging
394 bool normalized; // flag that indicates whether the *data samples are normalized by # of trajectories
395} CFnc;
396
397typedef struct {
399 size_t count;
400 size_t capacity;
401} CFncs;
402
403
404/*
405 * An array of correlation functions for a fixed 'base temperature'
406 * 'base temperature' -- a temperature for which sampling of initial conditions is performed
407 * 'satellite temperature' -- a target temperature for which correlation function is re-weighted
408 */
409typedef struct {
410 double *t;
411 double **data;
412 size_t ntemp;
413 size_t len; // # of samples in *t and elements of *data
414 double *nstar; // array of # effective trajectories
415 size_t ntraj; // # of calculated trajectories
416} CFncArray;
417
418// SFnc may originate from CFnc which itself was derived
419// via multi-temperature reweighting. As a result its 'ntraj'
420// turns out be floating-point value rather than an integer
421typedef struct {
422 double *nu;
423 double *data;
424 size_t len; // # of samples in *nu, *data
425 size_t capacity; // capacity of *nu, *data
426 double ntraj; // # of trajectories used for averaging
429} SFnc;
430
431
432typedef struct {
433 double *nu;
434 double *data;
435 size_t len; // # of samples of *nu, *data
436 size_t capacity; // capacity of *nu, *data
437 double ntraj; // # of trajectories used for averaging
440} Spectrum;
441
442typedef struct {
444 size_t count;
445 size_t capacity;
446} Spectra;
447
448/*
449 * MODEL: Lorentzian function shifted upwards by constant:
450 * y = C + A /(1 + B^2 x^2)
451 */
452typedef struct {
453 double A;
454 double B;
455 double C;
456} WingParams;
457
458typedef struct {
459 size_t n;
460 double* t;
461 double* y;
462} WingData;
463
464typedef struct {
465 double before2;
466 double before;
467 double current;
468
470
471 size_t called;
472 bool ready;
473} Tracker;
474
475
476/* ---------------------------------------------------------------------------------------------------------------- */
477/* -------------------------- User-Supplied Functions: loaded from dynamic libs --------------------------------- */
478/* ---------------------------------------------------------------------------------------------------------------- */
483typedef void (*dipolePtr)(double*, double[3]);
484extern dipolePtr dipole_1;
485extern dipolePtr dipole_2;
486
487typedef void (*dipoleFree)(void);
490
499typedef double (*pesPtr)(double*);
500extern pesPtr pes;
501
510typedef void (*dpesPtr)(double*, double*);
511extern dpesPtr dpes;
512/* ---------------------------------------------------------------------------------------------------------------- */
513
514MoleculeSystem init_ms(double mu, MonomerType t1, MonomerType t2, double *I1, double *I2, size_t seed);
515MoleculeSystem init_ms_from_monomers(double mu, Monomer *m1, Monomer *m2, size_t seed);
516void free_ms(MoleculeSystem *ms);
517
518#ifdef USE_MPI
519CFnc calculate_correlation_and_save(MoleculeSystem *ms, CalcParams *params, double Temperature);
520CFnc calculate_correlation_and_save_tests(MoleculeSystem *ms, CalcParams *params, double Temperature);
522CFncArray calculate_correlation_array_and_save(MoleculeSystem *ms, CalcParams *params, double base_temperature);
523#endif // USE_MPI
524
525const char* display_monomer_type(MonomerType t);
526
528void get_qp_from_ms(MoleculeSystem *ms, Array *qp);
529
530// this function takes the phase point from MoleculeSystem
531// and packs it into "intermediate_q" field. Then this pointer
532// can be passed to potential energy / its derivatives / dipole function
534
535// this function takes the corresponding components of "ms.dVdq" and writes
536// them into "m.dVdq" vectors for each monomer
538
539// 20.12.2024 NOTE:
540// the MoleculeSystem struct needs to be passed as void* into "rhs" function.
541// Then, the first step is to write the phase point (N_Vector y) into the fields of MoleculeSystem
542// using the method "put_qp_into_ms".
543int rhs(realtype t, N_Vector y, N_Vector ydot, void *data);
544
545Array compute_numerical_derivatives(double (*f)(double *q), double *q, size_t len, size_t order);
546Array compute_numerical_rhs(MoleculeSystem *ms, size_t order);
547gsl_matrix* compute_numerical_jac(void (*transform_angles)(double *qlab, double *qmol), double *qlab, size_t ninput_coordinates, size_t noutput_coordinates, size_t order);
548
550double Hamiltonian(MoleculeSystem *ms);
551
552double generate_normal(double sigma);
553
554void q_generator(MoleculeSystem *ms, CalcParams *params);
555void p_generator(MoleculeSystem *ms, double Temperature);
556bool reject(MoleculeSystem *ms, double Temperature, double pesmin);
557
559void j_monomer(Monomer *m, double j[3]);
560double torque_monomer(Monomer *m);
561double find_closest_integer(double j);
562double find_closest_half_integer(double j);
563
565
566double analytic_full_partition_function_by_V(MoleculeSystem *ms, double Temperature);
567
568// ----------------------------------------------------------
569// Spectral moments calculation
570// ----------------------------------------------------------
571double integrate_composite_simpson(double *x, double *y, size_t len);
572bool compute_Mn_from_cf_using_classical_detailed_balance(CFnc cf, size_t n, double *result);
575void calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
576void compute_dHdp(MoleculeSystem *ms, gsl_matrix* dHdp);
577void calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
578
579#ifdef USE_MPI
580void mpi_calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
581void mpi_calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q);
582#endif // USE_MPI
583// ----------------------------------------------------------
584
585
586int assert_float_is_equal_to(double estimate, double true_value, double abs_tolerance);
587
588double* linspace(double start, double end, size_t n);
589double* arena_linspace(Arena *a, double start, double end, size_t n);
590size_t* arena_linspace_size_t(Arena *a, size_t start, size_t end, size_t n);
591
592// ----------------------------------------------------------
593// Histogram manipulation
594// ----------------------------------------------------------
595void send_histogram_and_reset(gsl_histogram *h);
596void recv_histogram_and_append(Arena *a, int source, gsl_histogram **h);
597gsl_histogram* gsl_histogram_extend_right(gsl_histogram* h, size_t add_bins);
598int write_histogram_ext(FILE *fp, gsl_histogram *h, int count);
599// ----------------------------------------------------------
600
601// ----------------------------------------------------------
602// String manipulation
603// ----------------------------------------------------------
604/*
605 * This struct represents a resizable buffer designed to build strings
606 * dynamically. It stores characters in a contiguous block of memory,
607 * allowing for manipulation of strings.
608 */
609typedef struct {
610 char *items;
611 size_t count;
612 size_t capacity;
614
615void sb_reserve(String_Builder *sb, size_t n);
616void sb_append(String_Builder *sb, const char *line, size_t n);
618void sb_append_cstring(String_Builder *sb, const char *line);
619void sb_append_format(String_Builder *sb, const char *format, ...);
621void sb_reset(String_Builder *sb);
622void sb_free(String_Builder *sb);
623// ----------------------------------------------------------
624
625// ----------------------------------------------------------
626// Processing the results
627// ----------------------------------------------------------
631
632void normalize_cfnc(CFnc *cf);
633
634void free_cfnc(CFnc cf);
636void free_sfnc(SFnc cf);
637void free_spectrum(Spectrum sp);
638
639bool writetxt(const char *filename, double *x, double *y, size_t len, const char *header);
640
641bool write_correlation_function(const char *filename, CFnc cf);
642int write_correlation_function_ext(FILE *fp, CFnc cf);
643
644bool write_spectral_function(const char *filename, SFnc sf);
645int write_spectral_function_ext(FILE *fp, SFnc sf);
646
647bool write_spectrum(const char *filename, Spectrum sp);
648int write_spectrum_ext(FILE *fp, Spectrum sp);
649
650bool parse_number_of_trajectories_from_header(const char *header, double *ntraj);
651bool parse_temperature_from_header(const char *header, double *Temperature);
652
653bool read_correlation_function(const char *filename, String_Builder *sb, CFnc *cf);
654bool read_spectral_function(const char *filename, String_Builder *sb, SFnc *sf);
655bool read_spectrum(const char *filename, String_Builder *sb, Spectrum *sp);
656
657bool average_correlation_functions(CFnc *average, CFncs cfncs);
658#define average_correlation_functions_ext(average, ...) average_correlation_functions__impl(average, sizeof((CFnc[]){__VA_ARGS__}) / sizeof(CFnc), __VA_ARGS__)
659int average_correlation_functions__impl(CFnc *average, int arg_count, ...);
660
661void kaiser_apodization(Array a, double sampling_time);
662void blackman_apodization(Array a, double sampling_time);
663void connes_apodization(Array a, double sampling_time);
664double *dct(double *v, size_t len);
665double *idct(double *v, size_t len);
668
670
680CFnc egelstaff_time_transform(CFnc cf, bool frommhold_renormalization);
683
684double* pad_to_power_of_two(double* v, size_t len, size_t* padded_len);
685
686extern WingParams INIT_WP;
687double wingmodel(WingParams *wp, double t);
688double wingmodel_image(WingParams *wp, double nu);
689
690int wingmodel_f(const gsl_vector* x, void* data, gsl_vector* f);
691int wingmodel_df(const gsl_vector* x, void* data, gsl_matrix * J);
692
693void gsl_nonlinear_opt(size_t n, double* x, double* y, WingParams *wing_params);
694WingParams fit_baseline(CFnc *cf, size_t EXT_RANGE_MIN);
695
696
697/* Uses bit hack taken from: http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
698static inline bool is_power_of_two(size_t n) {
699 return n && !(n & (n - 1));
700}
701
702static inline unsigned int round_to_next_power_of_two(unsigned int n)
703/*
704 * rounds up to the next highest power of 2 using a clever bit hack
705 * Taken from:
706 * https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
707 *
708 * works on 32-bit numbers
709 */
710{
711 n--;
712 n |= n >> 1;
713 n |= n >> 2;
714 n |= n >> 4;
715 n |= n >> 8;
716 n |= n >> 16;
717 n++;
718
719 return n;
720}
721
722#ifdef __cplusplus
723}
724#endif
725
726#endif // HAWAII_H_
727
728/*
729 * Copyright (C) 2026 A.Finenko & D.Chistikov
730 * Distributed under the GNU General Public License, version 3
731 *
732 * This program is free software: you can redistribute it and/or modify
733 * it under the terms of the GNU General Public License as published by
734 * the Free Software Foundation, either version 3 of the License, or
735 * (at your option) any later version.
736 *
737 * This program is distributed in the hope that it will be useful,
738 * but WITHOUT ANY WARRANTY; without even the implied warranty of
739 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
740 * GNU General Public License for more details.
741 *
742 * You should have received a copy of the GNU General Public License
743 * along with this program. If not, see <http://www.gnu.org/licenses/>.
744 */
745
void mpi_calculate_M0(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
mpi_calculate_M0
Definition hawaii.c:1718
WingParams INIT_WP
Definition hawaii.c:5500
CFnc calculate_correlation_and_save(MoleculeSystem *ms, CalcParams *params, double Temperature)
calculate_correlation_and_save
Definition hawaii.c:3141
void mpi_calculate_M2(MoleculeSystem *ms, CalcParams *params, double Temperature, double *m, double *q)
mpi_calculate_M2
Definition hawaii.c:1838
pesPtr pes
Definition hawaii.c:37
int _wsize
Definition hawaii.c:41
int _wrank
Definition hawaii.c:40
const char * CALCULATION_TYPES[CALCULATION_TYPES_COUNT]
Definition hawaii.c:55
dpesPtr dpes
Definition hawaii.c:38
dipolePtr dipole_1
Definition hawaii.c:33
dipolePtr dipole_2
Definition hawaii.c:35
dipoleFree free_dipole_2
Definition hawaii.c:36
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:3572
MonomerType MONOMER_TYPES[MONOMER_COUNT]
Definition hawaii.c:67
dipoleFree free_dipole_1
Definition hawaii.c:34
const char * PAIR_STATES[PAIR_STATE_COUNT]
Definition hawaii.c:47
bool _print0_suppress_info
Definition hawaii.c:42
int _print0_margin
Definition hawaii.c:43
CFncArray calculate_correlation_array_and_save(MoleculeSystem *ms, CalcParams *params, double base_temperature)
calculate_correlation_array_and_save
Definition hawaii.c:2567
void extract_dVdq_and_write_into_monomers(MoleculeSystem *ms)
Definition hawaii.c:580
double compute_Mn_from_sf_using_quantum_detailed_balance(SFnc sf, size_t n)
Definition hawaii.c:6535
MonomerType
MonomerType enum is used to distinguish between systems of different types and stores the phase point...
Definition hawaii.h:184
@ ROTOR
Represents a rotor with phase point size 6.
Definition hawaii.h:189
@ LINEAR_MOLECULE_REQ_HALFINTEGER
Represents a linear molecule with half-integer angular momentum with phase point size 4.
Definition hawaii.h:188
@ ROTOR_REQUANTIZED_ROTATION
Represents a rotor with requantized rotation with phase point size 6.
Definition hawaii.h:190
@ ATOM
Represents an atom with phase point size 0.
Definition hawaii.h:185
@ LINEAR_MOLECULE
Represents a linear molecule with phase point size 4.
Definition hawaii.h:186
@ LINEAR_MOLECULE_REQ_INTEGER
Represents a linear molecule with integer angular momentum with phase point size 4.
Definition hawaii.h:187
void invert_momenta(MoleculeSystem *ms)
invert_momenta
Definition hawaii.c:1212
SFnc desymmetrize_d1(SFnc sf)
Definition hawaii.c:6271
bool write_correlation_function(const char *filename, CFnc cf)
Definition hawaii.c:4483
double find_closest_integer(double j)
find_closest_integer
Definition hawaii.c:400
void sb_append_seconds_as_datetime_string(String_Builder *sb, int seconds)
Definition hawaii.c:4826
int wingmodel_f(const gsl_vector *x, void *data, gsl_vector *f)
Definition hawaii.c:5515
void get_qp_from_ms(MoleculeSystem *ms, Array *qp)
Definition hawaii.c:1192
SFnc copy_sfnc(SFnc sf)
Definition hawaii.c:6589
bool parse_number_of_trajectories_from_header(const char *header, double *ntraj)
Definition hawaii.c:5255
double * pad_to_power_of_two(double *v, size_t len, size_t *padded_len)
Definition hawaii.c:5979
void sincos(double, double *, double *)
bool read_spectral_function(const char *filename, String_Builder *sb, SFnc *sf)
Definition hawaii.c:5116
#define MONOMER_COUNT
Definition hawaii.h:175
int write_spectral_function_ext(FILE *fp, SFnc sf)
Definition hawaii.c:4579
void normalize_cfnc(CFnc *cf)
Definition hawaii.c:3130
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:76
void gsl_nonlinear_opt(size_t n, double *x, double *y, WingParams *wing_params)
Definition hawaii.c:5584
void send_histogram_and_reset(gsl_histogram *h)
Definition hawaii.c:3123
double torque_monomer(Monomer *m)
torque_monomer computes the magnitude of torque (time-derivative of angular momentum) of passed-in mo...
Definition hawaii.c:473
CFnc dct_sf_to_cf(SFnc sf)
Definition hawaii.c:6027
bool writetxt(const char *filename, double *x, double *y, size_t len, const char *header)
Definition hawaii.c:5394
void connes_apodization(Array a, double sampling_time)
Definition hawaii.c:5825
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:6242
void free_cfnc_array(CFncArray ca)
Definition hawaii.c:5479
bool write_spectrum(const char *filename, Spectrum sp)
Definition hawaii.c:4406
void j_monomer(Monomer *m, double j[3])
j_monomer computes the magnitude of angular momentum of passed-in monomer. Currently,...
Definition hawaii.c:438
double(* pesPtr)(double *)
Definition hawaii.h:499
bool compute_Mn_from_cf_using_classical_detailed_balance(CFnc cf, size_t n, double *result)
Definition hawaii.c:6469
double compute_Mn_from_sf_using_classical_detailed_balance(SFnc sf, size_t n)
Definition hawaii.c:6505
bool write_spectral_function(const char *filename, SFnc sf)
Definition hawaii.c:4563
void extract_q_and_write_into_ms(MoleculeSystem *ms)
Definition hawaii.c:1206
Spectrum copy_spectrum(Spectrum sp)
Definition hawaii.c:6609
double integrate_composite_simpson(double *x, double *y, size_t len)
Definition hawaii.c:6450
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:6293
void sb_append_cstring(String_Builder *sb, const char *line)
Definition hawaii.c:4766
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:182
void sb_append_format(String_Builder *sb, const char *format,...)
Definition hawaii.c:4790
double analytic_full_partition_function_by_V(MoleculeSystem *ms, double Temperature)
Definition hawaii.c:5428
double wingmodel_image(WingParams *wp, double nu)
Definition hawaii.c:5510
void free_ms(MoleculeSystem *ms)
Definition hawaii.c:350
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:1480
Spectrum inv_desymmetrize_schofield(Spectrum sp)
Definition hawaii.c:6164
void p_generator(MoleculeSystem *ms, double Temperature)
Function p_generator samples momenta from distribution at given temperature.
Definition hawaii.c:1428
double find_closest_half_integer(double j)
find_closest_half_integer
Definition hawaii.c:411
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:487
int average_correlation_functions__impl(CFnc *average, int arg_count,...)
Definition hawaii.c:5035
#define MODULO_BASE
Definition hawaii.h:176
bool parse_temperature_from_header(const char *header, double *Temperature)
Definition hawaii.c:5213
SFnc desymmetrize_egelstaff_from_cf(CFnc cf)
Definition hawaii.c:6365
void sb_append(String_Builder *sb, const char *line, size_t n)
Definition hawaii.c:4716
int write_histogram_ext(FILE *fp, gsl_histogram *h, int count)
Definition hawaii.c:4635
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:4364
double * dct(double *v, size_t len)
Definition hawaii.c:5836
double * linspace(double start, double end, size_t n)
Definition hawaii.c:4343
SFnc desymmetrize_schofield_sf(SFnc sf)
Definition hawaii.c:6120
PairState
PairState is an enumeration representing the possible states of a pair.
Definition hawaii.h:302
@ PAIR_STATE_COUNT
Enum counter value (not a valid state). Used for array sizing.
Definition hawaii.h:307
@ PAIR_STATE_FREE_AND_METASTABLE
Free and metastable states (TODO: automatically separate the contributions based on the number of tur...
Definition hawaii.h:304
@ PAIR_STATE_BOUND
Bound states.
Definition hawaii.h:305
@ PAIR_STATE_NONE
Default/uninitialized state.
Definition hawaii.h:303
@ PAIR_STATE_ALL
Represents the totality of all possible states (aggregate value).
Definition hawaii.h:306
void free_cfnc(CFnc cf)
Definition hawaii.c:5474
void sb_append_null(String_Builder *sb)
Definition hawaii.c:4741
void sb_reset(String_Builder *sb)
Definition hawaii.c:4757
SFnc desymmetrize_d2_sf(SFnc sf)
Definition hawaii.c:6186
SFnc desymmetrize_frommhold(SFnc sf)
Definition hawaii.c:6344
size_t * arena_linspace_size_t(Arena *a, size_t start, size_t end, size_t n)
Definition hawaii.c:4385
void free_sfnc(SFnc cf)
Definition hawaii.c:5490
CFnc copy_cfnc(CFnc cf)
Definition hawaii.c:6569
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:1521
bool read_spectrum(const char *filename, String_Builder *sb, Spectrum *sp)
Definition hawaii.c:5298
void sb_reserve(String_Builder *sb, size_t n)
Definition hawaii.c:4695
double wingmodel(WingParams *wp, double t)
Definition hawaii.c:5506
void sb_free(String_Builder *sb)
Definition hawaii.c:4848
gsl_histogram * gsl_histogram_extend_right(gsl_histogram *h, size_t add_bins)
Definition hawaii.c:5451
void check_if_requantization_should_be_applied_to_monomer(Monomer *m, size_t step_counter)
Definition hawaii.c:2287
void compute_dHdp(MoleculeSystem *ms, gsl_matrix *dHdp)
compute_dHdp
Definition hawaii.c:1591
void(* dipolePtr)(double *, double[3])
Definition hawaii.h:483
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:6214
int wingmodel_df(const gsl_vector *x, void *data, gsl_matrix *J)
Definition hawaii.c:5542
SFnc desymmetrize_egelstaff(SFnc sf)
Definition hawaii.c:6407
double * idct(double *v, size_t len)
Definition hawaii.c:5902
int write_spectrum_ext(FILE *fp, Spectrum sp)
Definition hawaii.c:4422
void free_spectrum(Spectrum sp)
Definition hawaii.c:5495
const char * display_monomer_type(MonomerType t)
Definition hawaii.c:380
void recv_histogram_and_append(Arena *a, int source, gsl_histogram **h)
Definition hawaii.c:3535
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:1622
int assert_float_is_equal_to(double estimate, double true_value, double abs_tolerance)
Definition hawaii.c:4329
SFnc idct_cf_to_sf(CFnc cf)
Definition hawaii.c:5993
void kaiser_apodization(Array a, double sampling_time)
Definition hawaii.c:5761
SamplingType
Definition hawaii.h:381
@ MCMC
Definition hawaii.h:383
@ REJECT
Definition hawaii.h:382
CalculationType
Definition hawaii.h:312
@ CALCULATION_NONE
Definition hawaii.h:313
@ CALCULATION_TYPES_COUNT
Definition hawaii.h:320
@ CALCULATION_MANUAL
Definition hawaii.h:321
@ CALCULATION_CORRELATION_ARRAY
Definition hawaii.h:316
@ CALCULATION_CORRELATION_SINGLE
Definition hawaii.h:315
@ CALCULATION_PR_MU
Definition hawaii.h:314
@ CALCULATION_PROCESSING
Definition hawaii.h:317
@ CALCULATION_PHASE_SPACE_M0
Definition hawaii.h:318
@ CALCULATION_PHASE_SPACE_M2
Definition hawaii.h:319
Spectrum compute_alpha(SFnc sf)
Definition hawaii.c:6428
WingParams fit_baseline(CFnc *cf, size_t EXT_RANGE_MIN)
Definition hawaii.c:5684
SFnc desymmetrize_frommhold_from_cf(CFnc cf)
Definition hawaii.c:6386
bool read_correlation_function(const char *filename, String_Builder *sb, CFnc *cf)
Definition hawaii.c:4859
void(* dpesPtr)(double *, double *)
Definition hawaii.h:510
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:4499
Spectrum desymmetrize_schofield_sp(Spectrum sp)
Definition hawaii.c:6142
double generate_normal(double sigma)
Definition hawaii.c:1247
bool average_correlation_functions(CFnc *average, CFncs cfncs)
Definition hawaii.c:4956
double Hamiltonian(MoleculeSystem *ms)
Function Hamiltonian calls kinetic_energy function to compute kinetic energy, assembles a contiguous ...
Definition hawaii.c:1231
void blackman_apodization(Array a, double sampling_time)
Definition hawaii.c:5814
Definition arena.h:56
Definition array.h:11
Definition hawaii.h:409
size_t ntemp
Definition hawaii.h:412
size_t ntraj
Definition hawaii.h:415
double * t
Definition hawaii.h:410
size_t len
Definition hawaii.h:413
double ** data
Definition hawaii.h:411
double * nstar
Definition hawaii.h:414
Definition hawaii.h:387
double * data
Definition hawaii.h:389
bool normalized
Definition hawaii.h:394
size_t capacity
Definition hawaii.h:391
size_t len
Definition hawaii.h:390
double * t
Definition hawaii.h:388
double Temperature
Definition hawaii.h:393
double ntraj
Definition hawaii.h:392
Definition hawaii.h:397
size_t capacity
Definition hawaii.h:400
size_t count
Definition hawaii.h:399
CFnc ** items
Definition hawaii.h:398
Definition hawaii.h:326
size_t hep_ppf_niterations
Definition hawaii.h:344
double partial_partition_function_ratio
Definition hawaii.h:338
double ApproximateFrequencyMax
Definition hawaii.h:368
double R0
Definition hawaii.h:369
bool accelerate_averaging
Definition hawaii.h:364
const char ** cf_filenames
Definition hawaii.h:376
size_t hep_ppf_npoints
Definition hawaii.h:345
const char * sf_filename
Definition hawaii.h:367
size_t hep_m0_npoints
Definition hawaii.h:341
size_t total_trajectories
Definition hawaii.h:359
size_t initialM2_npoints
Definition hawaii.h:337
const char * cf_filename
Definition hawaii.h:362
double sampling_time
Definition hawaii.h:352
PairState ps
Definition hawaii.h:327
double sampler_Rmax
Definition hawaii.h:332
size_t MaxTrajectoryLength
Definition hawaii.h:353
double pesmin
Definition hawaii.h:333
double even_j_spin_weight
Definition hawaii.h:349
CalculationType calculation_type
Definition hawaii.h:328
double * partial_partition_function_ratios
Definition hawaii.h:373
bool allow_truncating_trajectories_at_length_limit
Definition hawaii.h:354
double Rcut
Definition hawaii.h:363
double * satellite_temperatures
Definition hawaii.h:374
size_t num_satellite_temperatures
Definition hawaii.h:375
size_t niterations
Definition hawaii.h:358
double average_time_between_collisions
Definition hawaii.h:370
double odd_j_spin_weight
Definition hawaii.h:348
size_t hep_m2_npoints
Definition hawaii.h:343
size_t hep_m0_niterations
Definition hawaii.h:340
size_t initialM0_npoints
Definition hawaii.h:336
double sampler_Rmin
Definition hawaii.h:331
size_t hep_m2_niterations
Definition hawaii.h:342
double cvode_tolerance
Definition hawaii.h:355
Angular variables and conjugated momenta are stored within the MoleculeSystem struct in the same orde...
Definition hawaii.h:278
size_t QP_SIZE
Total number of coordinates and momenta for molecular pair (phase point size).
Definition hawaii.h:285
size_t Q_SIZE
Total number of coordinates for molecule pair.
Definition hawaii.h:284
double mu
Reduced mass of molecule pair.
Definition hawaii.h:282
Monomer m2
Second monomer.
Definition hawaii.h:281
double * intermediate_q
Contiguous vector of coordinates.
Definition hawaii.h:287
double intermolecular_qp[6]
Coordinates and conjugated momenta that correspond to the intermolecular motion ( ,...
Definition hawaii.h:279
time_t init_rawtime
Initialization time represented as the number of seconds since Unix Epoch; set in init_ms.
Definition hawaii.h:293
double * dVdq
Contiguous vector of potential energy derivatives.
Definition hawaii.h:288
Monomer m1
First monomer.
Definition hawaii.h:280
size_t seed
Definition hawaii.h:290
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:294
Monomer represents a monomer in a pair with associated dynamic variables. The order of variables in t...
Definition hawaii.h:224
double jini_histogram_max
Definition hawaii.h:246
double jfin_histogram_max
Definition hawaii.h:252
double torque_limit
Torque limiting values to decide when requantization should be switched on/off.
Definition hawaii.h:237
size_t jfin_histogram_bins
Definition hawaii.h:251
char * jfin_histogram_filename
Definition hawaii.h:253
double DJ
Centrifugal distortion constant.
Definition hawaii.h:228
FILE * fp_jfin_histogram
Definition hawaii.h:255
gsl_histogram * jfin_histogram
Definition hawaii.h:254
MonomerType t
Type identifier for the monomer.
Definition hawaii.h:226
bool apply_requantization
Flag indicating whether requantization should be applied.
Definition hawaii.h:233
FILE * fp_jini_histogram
Definition hawaii.h:249
StoredHistogram nswitch_histogram
Definition hawaii.h:243
gsl_histogram * jini_histogram
Definition hawaii.h:248
size_t jini_histogram_bins
Definition hawaii.h:245
double * qp
Dynamic variables (Euler angles and conjugated momenta).
Definition hawaii.h:230
double * dVdq
Derivatives of potential energy with respect to coordinates pertaining to this monomer (the order of ...
Definition hawaii.h:231
double * torque_cache
Cached torque values.
Definition hawaii.h:238
size_t torque_cache_len
Length of the torque cache array.
Definition hawaii.h:236
double II[3]
Values of inertia tensor.
Definition hawaii.h:227
size_t req_switch_counter
Counter for tracking requantization switching events during the single trajectory.
Definition hawaii.h:235
char * jini_histogram_filename
Definition hawaii.h:247
double initial_j
Definition hawaii.h:240
int index
Index of monomer within the molecule system (1 or 2)
Definition hawaii.h:225
Definition hawaii.h:421
double * nu
Definition hawaii.h:422
size_t capacity
Definition hawaii.h:425
double ntraj
Definition hawaii.h:426
bool normalized
Definition hawaii.h:428
double Temperature
Definition hawaii.h:427
size_t len
Definition hawaii.h:424
double * data
Definition hawaii.h:423
Definition hawaii.h:442
size_t count
Definition hawaii.h:444
size_t capacity
Definition hawaii.h:445
Spectrum ** items
Definition hawaii.h:443
Definition hawaii.h:432
double ntraj
Definition hawaii.h:437
bool normalized
Definition hawaii.h:439
double * nu
Definition hawaii.h:433
double * data
Definition hawaii.h:434
double Temperature
Definition hawaii.h:438
size_t len
Definition hawaii.h:435
size_t capacity
Definition hawaii.h:436
Definition hawaii.h:199
char * filename
Definition hawaii.h:203
FILE * fp
Definition hawaii.h:204
gsl_histogram * h
Definition hawaii.h:200
double max
Definition hawaii.h:202
size_t nbins
Definition hawaii.h:201
bool is_allocated
Definition hawaii.h:205
Definition hawaii.h:609
size_t count
Definition hawaii.h:611
size_t capacity
Definition hawaii.h:612
char * items
Definition hawaii.h:610
Definition hawaii.h:464
double before
Definition hawaii.h:466
double current
Definition hawaii.h:467
size_t turning_points
Definition hawaii.h:469
bool ready
Definition hawaii.h:472
size_t called
Definition hawaii.h:471
double before2
Definition hawaii.h:465
Definition hawaii.h:458
double * y
Definition hawaii.h:461
double * t
Definition hawaii.h:460
size_t n
Definition hawaii.h:459
Definition hawaii.h:452
double B
Definition hawaii.h:454
double A
Definition hawaii.h:453
double C
Definition hawaii.h:455