Statistics
| Revision:

root / src / optimize_width.cpp

History | View | Annotate | Download (1.6 kB)

1 1 akiss
#include "optimize_width.h"
2 1 akiss
#include "compute_energy_width.h"
3 1 akiss
#include <nlopt.h>
4 1 akiss
#include <stdio.h>
5 1 akiss
#include <stdlib.h>
6 1 akiss
#include <cmath>
7 1 akiss
8 1 akiss
void optimize_width(int vertex_number, double *vertices, int edge_number, int *edges_vertices,
9 1 akiss
                   double *lengths, double *rest_lengths, double *edges_width, int *periodizer, double *width, double *height){
10 1 akiss
11 1 akiss
nlopt_opt opt;
12 1 akiss
opt=nlopt_create(NLOPT_LN_BOBYQA,edge_number);
13 1 akiss
14 1 akiss
nlopt_set_stopval(opt, -HUGE_VAL);
15 1 akiss
nlopt_set_maxeval(opt, -1.);
16 1 akiss
nlopt_set_maxtime(opt, -1.);
17 1 akiss
nlopt_set_xtol_rel(opt, -1.);
18 1 akiss
nlopt_set_xtol_abs1(opt, 1.e-6);
19 1 akiss
nlopt_set_ftol_rel(opt, -1.);
20 1 akiss
nlopt_set_ftol_abs(opt, -1.);
21 1 akiss
22 1 akiss
struct parameters_list3 {int vertex_number; double *vertices; int edge_number; int *edges_vertices;
23 1 akiss
                        double *lengths; double *rest_lengths; int *periodizer; double *width; double *height;};
24 1 akiss
25 1 akiss
struct parameters_list3 parameters;
26 1 akiss
parameters.vertex_number=vertex_number;
27 1 akiss
parameters.vertices=vertices;
28 1 akiss
parameters.edge_number=edge_number;
29 1 akiss
parameters.edges_vertices=edges_vertices;
30 1 akiss
parameters.lengths=lengths;
31 1 akiss
parameters.rest_lengths=rest_lengths;
32 1 akiss
parameters.periodizer=periodizer;
33 1 akiss
parameters.width=width;
34 1 akiss
parameters.height=height;
35 1 akiss
void* pparameters=&parameters;
36 1 akiss
37 1 akiss
double width_optimize[edge_number]; double energy;
38 1 akiss
for (int i=0; i<edge_number;i++){ width_optimize[i]=edges_width[i];}
39 1 akiss
40 1 akiss
/// first resolution: find the reference width and height without the anisotropic stress
41 1 akiss
int reso=nlopt_set_min_objective(opt, compute_energy_width, pparameters);
42 1 akiss
nlopt_optimize(opt, width_optimize, &energy);
43 1 akiss
printf("%d\n",reso);
44 1 akiss
45 1 akiss
for (int i=0; i<edge_number;i++){edges_width[i]=width_optimize[i];}
46 1 akiss
47 1 akiss
nlopt_destroy(opt);
48 1 akiss
49 1 akiss
}