Skip to content
Snippets Groups Projects
Commit 396af080 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

*** empty log message ***

parent c4a1cd8f
No related branches found
No related tags found
No related merge requests found
...@@ -15,8 +15,6 @@ void invert_singular_matrix3x3(double MM[3][3], double II[3][3]); ...@@ -15,8 +15,6 @@ void invert_singular_matrix3x3(double MM[3][3], double II[3][3]);
// the GSL // the GSL
double brent(double ax, double bx, double cx, double brent(double ax, double bx, double cx,
double (*f)(double), double tol, double *xmin); double (*f)(double), double tol, double *xmin);
void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb,
double *fc, double (*func)(double));
void newt(double x[], int n, int *check, void newt(double x[], int n, int *check,
void (*vecfunc)(int, double [], double [])); void (*vecfunc)(int, double [], double []));
void minimize_2 (double (*f) (double, double, void *data), void minimize_2 (double (*f) (double, double, void *data),
......
...@@ -129,87 +129,4 @@ double brent(double ax, double bx, double cx, ...@@ -129,87 +129,4 @@ double brent(double ax, double bx, double cx,
return fn1(b, NULL); return fn1(b, NULL);
} }
// Find an initial bracketting of the minimum of func. Given 2 initial
// points ax and bx, mnbrak checks in which direction func decreases,
// and takes some steps in that direction, until the function
// increases--at cx. mnbrak returns ax and cx (possibly switched),
// bracketting a minimum.
#define MYGOLD_ 1.618034
#define MYLIMIT_ 100.0
#define MYTINY_ 1.0e-20
#define SIGN(a,b)((b) >= 0.0 ? fabs(a) : -fabs(a))
void mnbrak(double *ax, double *bx, double *cx,
double *fa_dummy, double *fb_dummy, double *fc_dummy,
double (*func) (double))
{
double ulim, u, r, q;
volatile double f_a, f_b, f_c, f_u;
f_a = (*func) (*ax);
f_b = (*func) (*bx);
if(f_b > f_a) {
double tmp;
tmp = *ax;
*ax = *bx;
*bx = tmp;
tmp = f_b;
f_b = f_a;
f_a = tmp;
}
*cx = *bx + MYGOLD_ * (*bx - *ax);
f_c = (*func) (*cx);
while(f_b > f_c) {
r = (*bx - *ax) * (f_b - f_c);
q = (*bx - *cx) * (f_b - f_a);
u = (*bx) - ((*bx - *cx) * q - (*bx - *ax) * r) /
(2.0 * SIGN(std::max(fabs(q - r), MYTINY_), q - r));
ulim = *bx + MYLIMIT_ * (*cx - *bx);
if((*bx - u) * (u - *cx) > 0.0) {
f_u = (*func) (u);
if(f_u < f_c) {
*ax = *bx;
*bx = u;
return;
}
else if(f_u > f_b) {
*cx = u;
return;
}
u = *cx + MYGOLD_ * (*cx - *bx);
f_u = (*func) (u);
}
else if((*cx - u) * (u - ulim) > 0.0) {
f_u = (*func) (u);
if(f_u < f_c) {
*bx = *cx;
*cx = u;
u = *cx + MYGOLD_ * (*cx - *bx);
f_b = f_c;
f_c = f_u;
f_u = (*func) (u);
}
}
else if((u - ulim) * (ulim - *cx) >= 0.0) {
u = ulim;
f_u = (*func) (u);
}
else {
u = *cx + MYGOLD_ * (*cx - *bx);
f_u = (*func) (u);
}
*ax = *bx;
*bx = *cx;
*cx = u;
f_a = f_b;
f_b = f_c;
f_c = f_u;
}
}
#endif #endif
This diff is collapsed.
...@@ -288,7 +288,7 @@ ...@@ -288,7 +288,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE
#line 70 "Gmsh.y" #line 71 "Gmsh.y"
{ {
char *c; char *c;
int i; int i;
......
...@@ -43,6 +43,7 @@ char gmsh_yyname[256] = ""; ...@@ -43,6 +43,7 @@ char gmsh_yyname[256] = "";
int gmsh_yyerrorstate = 0; int gmsh_yyerrorstate = 0;
int gmsh_yyviewindex = 0; int gmsh_yyviewindex = 0;
std::map<std::string, std::vector<double> > gmsh_yysymbols; std::map<std::string, std::vector<double> > gmsh_yysymbols;
std::map<std::string, std::string > gmsh_yystringsymbols;
// Static parser variables (accessible only in this file) // Static parser variables (accessible only in this file)
#if !defined(HAVE_NO_POST) #if !defined(HAVE_NO_POST)
...@@ -730,7 +731,9 @@ Affectation : ...@@ -730,7 +731,9 @@ Affectation :
} }
| tSTRING tAFFECT StringExpr tEND | tSTRING tAFFECT StringExpr tEND
{ {
Msg::Warning("Named string expressions not implemented yet"); gmsh_yystringsymbols[$1] = std::string($3);
Free($1);
Free($3);
} }
// Option Strings // Option Strings
...@@ -3140,7 +3143,32 @@ StringExprVar : ...@@ -3140,7 +3143,32 @@ StringExprVar :
} }
| tSTRING | tSTRING
{ {
Msg::Warning("Named string expressions not implemented yet"); if(!gmsh_yystringsymbols.count($1)){
yymsg(0, "Unknown string variable '%s'", $1);
$$ = $1;
}
else{
std::string val = gmsh_yystringsymbols[$1];
$$ = (char *)Malloc((val.size() + 1) * sizeof(char));
strcpy($$, val.c_str());
Free($1);
}
}
| tSTRING '.' tSTRING
{
const char *val = "";
StringOption(GMSH_GET, $1, 0, $3, val);
$$ = (char*)Malloc((strlen(val) + 1) * sizeof(char));
strcpy($$, val);
Free($1); Free($3);
}
| tSTRING '[' FExpr ']' '.' tSTRING
{
const char *val = "";
StringOption(GMSH_GET, $1, (int)$3, $6, val);
$$ = (char*)Malloc((strlen(val) + 1) * sizeof(char));
strcpy($$, val);
Free($1); Free($6);
} }
; ;
...@@ -3151,7 +3179,7 @@ StringExpr : ...@@ -3151,7 +3179,7 @@ StringExpr :
} }
| tToday | tToday
{ {
$$ = (char *)Malloc(32*sizeof(char)); $$ = (char *)Malloc(32 * sizeof(char));
time_t now; time_t now;
time(&now); time(&now);
strcpy($$, ctime(&now)); strcpy($$, ctime(&now));
...@@ -3159,7 +3187,7 @@ StringExpr : ...@@ -3159,7 +3187,7 @@ StringExpr :
} }
| tStrCat '(' StringExprVar ',' StringExprVar ')' | tStrCat '(' StringExprVar ',' StringExprVar ')'
{ {
$$ = (char *)Malloc((strlen($3)+strlen($5)+1)*sizeof(char)); $$ = (char *)Malloc((strlen($3) + strlen($5) + 1) * sizeof(char));
strcpy($$, $3); strcpy($$, $3);
strcat($$, $5); strcat($$, $5);
Free($3); Free($3);
...@@ -3167,7 +3195,7 @@ StringExpr : ...@@ -3167,7 +3195,7 @@ StringExpr :
} }
| tStrPrefix '(' StringExprVar ')' | tStrPrefix '(' StringExprVar ')'
{ {
$$ = (char *)Malloc((strlen($3)+1)*sizeof(char)); $$ = (char *)Malloc((strlen($3) + 1) * sizeof(char));
int i; int i;
for(i = strlen($3) - 1; i >= 0; i--){ for(i = strlen($3) - 1; i >= 0; i--){
if($3[i] == '.'){ if($3[i] == '.'){
...@@ -3181,7 +3209,7 @@ StringExpr : ...@@ -3181,7 +3209,7 @@ StringExpr :
} }
| tStrRelative '(' StringExprVar ')' | tStrRelative '(' StringExprVar ')'
{ {
$$ = (char *)Malloc((strlen($3)+1)*sizeof(char)); $$ = (char *)Malloc((strlen($3) + 1) * sizeof(char));
int i; int i;
for(i = strlen($3) - 1; i >= 0; i--){ for(i = strlen($3) - 1; i >= 0; i--){
if($3[i] == '/' || $3[i] == '\\') if($3[i] == '/' || $3[i] == '\\')
...@@ -3210,28 +3238,12 @@ StringExpr : ...@@ -3210,28 +3238,12 @@ StringExpr :
$$ = $3; $$ = $3;
} }
else{ else{
$$ = (char*)Malloc((strlen(tmpstring)+1)*sizeof(char)); $$ = (char*)Malloc((strlen(tmpstring) + 1) * sizeof(char));
strcpy($$, tmpstring); strcpy($$, tmpstring);
Free($3); Free($3);
} }
List_Delete($5); List_Delete($5);
} }
| tSprintf '(' tSTRING '.' tSTRING ')'
{
const char *val = "";
StringOption(GMSH_GET, $3, 0, $5, val);
$$ = (char*)Malloc((strlen(val) + 1) * sizeof(char));
strcpy($$, val);
Free($3); Free($5);
}
| tSprintf '(' tSTRING '[' FExpr ']' '.' tSTRING ')'
{
const char *val = "";
StringOption(GMSH_GET, $3, (int)$5, $8, val);
$$ = (char*)Malloc((strlen(val) + 1) * sizeof(char));
strcpy($$, val);
Free($3); Free($8);
}
; ;
%% %%
......
...@@ -20,7 +20,6 @@ SRC = brent.cpp\ ...@@ -20,7 +20,6 @@ SRC = brent.cpp\
lnsrch.cpp\ lnsrch.cpp\
lubksb.cpp\ lubksb.cpp\
ludcmp.cpp\ ludcmp.cpp\
mnbrak.cpp\
newt.cpp\ newt.cpp\
nrutil.cpp nrutil.cpp
...@@ -58,6 +57,5 @@ fmin.o: fmin.cpp nrutil.h ...@@ -58,6 +57,5 @@ fmin.o: fmin.cpp nrutil.h
lnsrch.o: lnsrch.cpp nrutil.h lnsrch.o: lnsrch.cpp nrutil.h
lubksb.o: lubksb.cpp lubksb.o: lubksb.cpp
ludcmp.o: ludcmp.cpp nrutil.h ludcmp.o: ludcmp.cpp nrutil.h
mnbrak.o: mnbrak.cpp nrutil.h
newt.o: newt.cpp nrutil.h newt.o: newt.cpp nrutil.h
nrutil.o: nrutil.cpp ../../Common/Message.h nrutil.o: nrutil.cpp ../../Common/Message.h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment