-
Notifications
You must be signed in to change notification settings - Fork 0
/
average.c
169 lines (142 loc) · 4.94 KB
/
average.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* Copyright (c) 2014, Giuseppe Argentieri <giuseppe.argentieri@ts.infn.it>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
*
*
* Filename: average.c
*
* Description: Integral of the entropy production for the Redfield dynamics
*
* Version: 1.0
* Created: 31/05/2014 15:10:24
* Revision: none
* License: BSD
*
* Author: Giuseppe Argentieri (ga), giuseppe.argentieri@ts.infn.it
* Organization: Università degli Studi di Trieste
*
*
*/
#include <stdlib.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>
#include <string.h>
#include "funcs.h"
#include "initial.h"
/*
* FUNCTION
* Name: entropy_prod_time
* Description: Entropy production as a function of time t
*
*/
double entropy_prod_time ( double t1, void* pars )
{
/* Setting the parameters */
struct ent_pars* p = (struct ent_pars*) pars ;
const gsl_vector* rhoeq = p->rhoeq ;
gsl_matrix* red_m = p->red_m ;
/* Value to be returned */
double ept ;
/*
*
* Initializing the system for Redfield dynamics
*
*/
gsl_odeiv2_system r_sys = { generator, jac, 4, (void*) red_m } ;
/* Choosing the step function type: Runge-Kutta-Fehlberg (4,5) */
/* gsl_odeiv2_step* s = gsl_odeiv2_step_alloc ( gsl_odeiv2_step_rkf45 , 4 ) ; */
/* Choosing the step function type: Runge-Kutta Cash-Karp (4,5) */
gsl_odeiv2_step* r_s = gsl_odeiv2_step_alloc ( gsl_odeiv2_step_rkck , 4 ) ;
/* Setting the step control: abserr=1e-9, relerr=1e-3 */
gsl_odeiv2_control* r_c = gsl_odeiv2_control_standard_new ( 1e-9, 1e-3, 1, 1 ) ;
/* Allocating the space for evolution function */
gsl_odeiv2_evolve* r_e = gsl_odeiv2_evolve_alloc ( 4 ) ;
/* Setting the initial state */
gsl_vector* state = gsl_vector_calloc(4) ;
unsigned int i ; /* counter */
for ( i = 0; i < 4; i++ )
gsl_vector_set(state, i, R[i]) ;
/* Evolving */
double time = 0 ;
while ( time < t1 )
{
evol( time, state, STEP, r_e, r_c, r_s, &r_sys ) ;
time += STEP ;
}
ept = entropy_production( state, rhoeq, red_m ) ;
/* free memory for evolution */
gsl_odeiv2_evolve_free (r_e) ;
gsl_odeiv2_control_free (r_c) ;
gsl_odeiv2_step_free (r_s) ;
return (ept) ;
} /* ----- end of function entropy_prod_time ----- */
/*
* FUNCTION
* Name: entropy_integ
* Description: Integrate entropy production up to time t
*
*/
double entropy_integ ( double t, const gsl_vector* rhoeq, gsl_matrix* red_m )
{
double res, abserr;
/* Parameters to be passed to the integrand */
struct ent_pars params ;
params.rhoeq = rhoeq ;
params.red_m = red_m ;
void* pars = (void*) ¶ms ;
/* Allocating workspace for integration */
gsl_integration_workspace* ent_t = gsl_integration_workspace_alloc(1e6) ;
/* Defining the integration function */
gsl_function Ent ;
Ent.function = &entropy_prod_time ;
Ent.params = pars ;
/* Adaptive integration */
gsl_integration_qag( &Ent, 0, t, 1e-3, 1e-1, 1e6, GSL_INTEG_GAUSS61,
ent_t, &res, &abserr) ;
return (res);
} /* ----- end of function entropy_integ ----- */
/*
* FUNCTION
* Name: main
* Description:
*
*/
int main ( int argc, char *argv[] )
{
gsl_matrix* red_m = gsl_matrix_calloc(4,4) ;
mat_read ( red_m, "REDFIELD_MATRIX" ) ;
gsl_vector* rhoeq = gsl_vector_calloc(4) ;
FILE* f = fopen( "RED_STATIONARY.dat", "r") ;
gsl_vector_fscanf ( f, rhoeq ) ;
if ( f == NULL )
printf("Error: %s.\nFailed to open RED_STATIONARY.dat\n",
strerror(errno)) ;
fclose (f) ;
double INT = entropy_integ ( t_end, rhoeq, red_m ) ;
printf("INTEGRATED ENT.: %g\n", INT) ;
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */