10 #include <gsl/gsl_errno.h> 11 #include <gsl/gsl_math.h> 12 #include <gsl/gsl_min.h> 23 int sv = (params->sv);
24 int incmax = (params->incmax);
25 int vmax = (params->vmax);
26 double **vert = (params->vert);
27 int **vinc = (params->vinc);
28 int ***smat = (params->smat);
29 bool report = (params->report);
32 for (i = 0; i <
nx; i++)
33 for (j = 0; j <
ny; j++)
34 for (k = 0; k <
nz; k++)
54 int iter = 0, max_iter = 100;
55 const gsl_min_fminimizer_type *T;
56 gsl_min_fminimizer *s;
58 gsl_set_error_handler_off ();
63 T = gsl_min_fminimizer_brent;
64 s = gsl_min_fminimizer_alloc (T);
65 status = gsl_min_fminimizer_set (s, &F, m, a, b);
66 if (status == GSL_EINVAL) {
68 cout <<
"endpoints do not enclose a minimum" << endl;
71 }
else if (status != GSL_SUCCESS) {
72 cout <<
"something is wrong in optim function" << endl;
76 printf (
"using %s method\n", gsl_min_fminimizer_name (s));
77 printf (
"%5s [%9s, %9s] %9s %9s\n",
78 "iter",
"lower",
"upper",
"min",
"err(est)");
79 printf (
"%5d [%.7f, %.7f] %.7f %.7f\n",iter, a, b, m, b - a);
84 status = gsl_min_fminimizer_iterate (s);
86 m = gsl_min_fminimizer_x_minimum (s);
87 a = gsl_min_fminimizer_x_lower (s);
88 b = gsl_min_fminimizer_x_upper (s);
91 = gsl_min_test_interval (a, b, 0.01, 0.0);
93 if (status == GSL_SUCCESS)
95 printf (
"Converged:\n");
96 printf (
"%5d [%.7f, %.7f] %.7f %.7f\n", iter, a, b, m, b - a);
99 while (status == GSL_CONTINUE && iter < max_iter);
101 gsl_min_fminimizer_free (s);
double porosity(int ***amat)
Calculates porosity.
void makeNodeStruts(int ***amat, int sv, int incmax, int vmax, double **vert, int **vinc, bool report)
double dedge
parameter influencing size of struts in cell edges
double fn1(double x, void *p)
Objective function for optimization. We want to have certain strut porosity.
bool createEdges
create struts at cell edges
int optim(void *params, double &m, double &a, double &b, bool report)
GSL minimizer for univariate scalar function.
Defines global variables, macros, templates and namespace.
void makeEdgeStruts(int ***amat, int sv, double **vert, int **vinc, bool report)
m
Bubble Growth Application Recipe.
bool createNodes
create struts at cell vertices
struct for passing paramaters to GSL function
integer nz
spatial discretization
namespace with global variables