summaryrefslogtreecommitdiff
path: root/src/gradget.cpp
blob: 2f8128fa4f5f8c13034b6fcb16e9a37c2e93b404 (plain)
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
/* eigenget.cpp
 *
 * Copyright (C) 2013 Jaron Kent-Dobias
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// A utility which returns a given generalized eigenvector to the user.

#include "domain_energy.h"
#include "domain_eigen.h"

#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>

// GSL includes.
#include <gsl/gsl_sf.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_permute_vector.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_sort_vector.h>


// Initializes the program.
int main(int argc, char *argv[]) {

	int opt;
	unsigned n, m, nn;
	double c, d;
	char *in_filename, *out_filename;
	bool truehessian;

	gsl_vector *z, *grad, *testgrad;

	truehessian = false;

	while ((opt = getopt(argc, argv, "n:m:c:i:o:td:")) != -1) {
		switch (opt) {
			case 'n':
				n = atoi(optarg);
				break;
			case 'm':
				m = atoi(optarg);
				break;
			case 'c':
				c = atof(optarg);
				break;
			case 'd':
				d = atof(optarg);
				break;
			case 'i':
				in_filename = optarg;
				break;
			case 'o':
				out_filename = optarg;
				break;
			case 't':
				truehessian = true;
				break;
			default:
				exit(EXIT_FAILURE);
		}
	}

	if (truehessian) nn = 3 * n + 3;
	else nn = 3 * n + 3;

	z = gsl_vector_alloc(3 * n + 3);
	grad = gsl_vector_alloc(nn);
	testgrad = gsl_vector_alloc(nn);

	FILE *in_file = fopen(in_filename, "r");
	gsl_vector_fscanf(in_file, z);
	fclose(in_file);

	if (truehessian) domain_energy_fixedGradient(grad, n, z, c);
	else domain_energy_fixedGradient(grad, n, z, c);
	domain_energy_fixedGradient(testgrad, n, z, c);

	FILE *out_file = fopen(out_filename, "w");
	for (unsigned i = 0; i < nn; i++) {
		fprintf(out_file, "%e\t", gsl_vector_get(grad, i) - gsl_vector_get(testgrad, i));
	}
	fclose(out_file);
}