Statistics
| Revision:

root / src / optimize_width.cpp

History | View | Annotate | Download (1.6 kB)

1
#include "optimize_width.h"
2
#include "compute_energy_width.h"
3
#include <nlopt.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <cmath>
7

    
8
void optimize_width(int vertex_number, double *vertices, int edge_number, int *edges_vertices,
9
                   double *lengths, double *rest_lengths, double *edges_width, int *periodizer, double *width, double *height){
10

    
11
nlopt_opt opt;
12
opt=nlopt_create(NLOPT_LN_BOBYQA,edge_number);
13

    
14
nlopt_set_stopval(opt, -HUGE_VAL);
15
nlopt_set_maxeval(opt, -1.);
16
nlopt_set_maxtime(opt, -1.);
17
nlopt_set_xtol_rel(opt, -1.);
18
nlopt_set_xtol_abs1(opt, 1.e-6);
19
nlopt_set_ftol_rel(opt, -1.);
20
nlopt_set_ftol_abs(opt, -1.);
21

    
22
struct parameters_list3 {int vertex_number; double *vertices; int edge_number; int *edges_vertices;
23
                        double *lengths; double *rest_lengths; int *periodizer; double *width; double *height;};
24

    
25
struct parameters_list3 parameters;
26
parameters.vertex_number=vertex_number;
27
parameters.vertices=vertices;
28
parameters.edge_number=edge_number;
29
parameters.edges_vertices=edges_vertices;
30
parameters.lengths=lengths;
31
parameters.rest_lengths=rest_lengths;
32
parameters.periodizer=periodizer;
33
parameters.width=width;
34
parameters.height=height;
35
void* pparameters=&parameters;
36

    
37
double width_optimize[edge_number]; double energy;
38
for (int i=0; i<edge_number;i++){ width_optimize[i]=edges_width[i];}
39

    
40
/// first resolution: find the reference width and height without the anisotropic stress
41
int reso=nlopt_set_min_objective(opt, compute_energy_width, pparameters);
42
nlopt_optimize(opt, width_optimize, &energy);
43
printf("%d\n",reso);
44

    
45
for (int i=0; i<edge_number;i++){edges_width[i]=width_optimize[i];}
46

    
47
nlopt_destroy(opt);
48

    
49
}