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

- added sigmoid option in threshold field

- don't play tricks in Extend1DMesh & co: always follow the option (so we
  can predictbly mix point/curvature lcs with fields)
parent 4821df4c
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// //
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>. // bugs and problems to <gmsh@geuz.org>.
#ifndef _GMSH_MATRIX_H_ #ifndef _GMSH_MATRIX_H_
#define _GMSH_MATRIX_H_ #define _GMSH_MATRIX_H_
template <class SCALAR> template <class SCALAR>
class Gmsh_Vector class Gmsh_Vector
{ {
......
...@@ -171,13 +171,10 @@ double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double ...@@ -171,13 +171,10 @@ double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double
bool Extend1dMeshIn2dSurfaces() bool Extend1dMeshIn2dSurfaces()
{ {
// don't extend 1d mesh in surfaces if there is a background field
if(GModel::current()->getFields()->background_field != -1) return false;
return CTX.mesh.lc_extend_from_boundary ? true : false; return CTX.mesh.lc_extend_from_boundary ? true : false;
} }
bool Extend2dMeshIn3dVolumes() bool Extend2dMeshIn3dVolumes()
{ {
return Extend1dMeshIn2dSurfaces(); return CTX.mesh.lc_extend_from_boundary ? true : false;
} }
...@@ -35,22 +35,10 @@ class FieldOptionDouble:public FieldOption ...@@ -35,22 +35,10 @@ class FieldOptionDouble:public FieldOption
{ {
public: public:
double &val; double &val;
FieldOptionType get_type() FieldOptionType get_type(){ return FIELD_OPTION_DOUBLE; }
{ FieldOptionDouble(double &_val, bool *_status=0) : FieldOption(_status), val(_val){}
return FIELD_OPTION_DOUBLE; double numerical_value() const { return val; }
}; void numerical_value(double v){ modified(); val = v; }
FieldOptionDouble(double &_val, bool * _status = NULL):FieldOption(_status),
val(_val) {
};
double numerical_value() const
{
return val;
};
void numerical_value(double v)
{
modified();
val = v;
};
void get_text_representation(std::string &v_str) void get_text_representation(std::string &v_str)
{ {
std::ostringstream sstream; std::ostringstream sstream;
...@@ -64,22 +52,10 @@ class FieldOptionInt:public FieldOption ...@@ -64,22 +52,10 @@ class FieldOptionInt:public FieldOption
{ {
public: public:
int &val; int &val;
FieldOptionType get_type() FieldOptionType get_type(){ return FIELD_OPTION_INT; }
{ FieldOptionInt(int &_val, bool *_status=0) : FieldOption(_status), val(_val){}
return FIELD_OPTION_INT; double numerical_value() const { return val; }
}; void numerical_value(double v){ modified(); val = (int)v; }
FieldOptionInt(int &_val, bool * _status = NULL):FieldOption(_status),
val(_val) {
};
double numerical_value() const
{
return val;
};
void numerical_value(double v)
{
modified();
val = (int)v;
};
void get_text_representation(std::string & v_str) void get_text_representation(std::string & v_str)
{ {
std::ostringstream sstream; std::ostringstream sstream;
...@@ -87,27 +63,16 @@ FieldOptionInt(int &_val, bool * _status = NULL):FieldOption(_status), ...@@ -87,27 +63,16 @@ FieldOptionInt(int &_val, bool * _status = NULL):FieldOption(_status),
v_str = sstream.str(); v_str = sstream.str();
} }
}; };
class FieldOptionList : public FieldOption class FieldOptionList : public FieldOption
{ {
public: public:
std::list < int >&val; std::list < int >&val;
FieldOptionType get_type() FieldOptionType get_type(){ return FIELD_OPTION_LIST; }
{ FieldOptionList(std::list<int> &_val, bool *_status=0)
return FIELD_OPTION_LIST; : FieldOption(_status), val(_val) {}
}; std::list<int> &list(){ modified(); return val; }
FieldOptionList(std::list < int >&_val, bool * _status = NULL):FieldOption(_status), const std::list<int>& list() const { return val; }
val(_val)
{
};
std::list < int >&list()
{
modified();
return val;
}
const std::list < int >&list() const
{
return val;
}
void get_text_representation(std::string & v_str) void get_text_representation(std::string & v_str)
{ {
std::ostringstream sstream; std::ostringstream sstream;
...@@ -121,25 +86,16 @@ FieldOptionList(std::list < int >&_val, bool * _status = NULL):FieldOption(_stat ...@@ -121,25 +86,16 @@ FieldOptionList(std::list < int >&_val, bool * _status = NULL):FieldOption(_stat
v_str = sstream.str(); v_str = sstream.str();
} }
}; };
class FieldOptionString:public FieldOption class FieldOptionString:public FieldOption
{ {
public: public:
std::string & val; std::string & val;
virtual FieldOptionType get_type() virtual FieldOptionType get_type(){ return FIELD_OPTION_STRING; }
{ FieldOptionString(std::string &_val, bool *_status=0)
return FIELD_OPTION_STRING; : FieldOption(_status), val(_val) {}
}; std::string &string() { modified(); return val; }
FieldOptionString(std::string & _val, bool * _status = NULL):FieldOption(_status), const std::string &string() const { return val; }
val(_val) {
};
std::string & string() {
modified();
return val;
}
const std::string & string() const
{
return val;
}
void get_text_representation(std::string &v_str) void get_text_representation(std::string &v_str)
{ {
std::ostringstream sstream; std::ostringstream sstream;
...@@ -147,26 +103,16 @@ FieldOptionString(std::string & _val, bool * _status = NULL):FieldOption(_status ...@@ -147,26 +103,16 @@ FieldOptionString(std::string & _val, bool * _status = NULL):FieldOption(_status
v_str = sstream.str(); v_str = sstream.str();
} }
}; };
class FieldOptionBool : public FieldOption class FieldOptionBool : public FieldOption
{ {
public: public:
bool & val; bool & val;
FieldOptionType get_type() FieldOptionType get_type(){ return FIELD_OPTION_BOOL; }
{ FieldOptionBool(bool & _val, bool *_status=0)
return FIELD_OPTION_BOOL; : FieldOption(_status), val(_val) {}
}; double numerical_value() const { return val; }
FieldOptionBool(bool & _val, bool * _status = NULL):FieldOption(_status), void numerical_value(double v){ modified(); val = v; }
val(_val) {
};
double numerical_value() const
{
return val;
};
void numerical_value(double v)
{
modified();
val = v;
};
void get_text_representation(std::string & v_str) void get_text_representation(std::string & v_str)
{ {
std::ostringstream sstream; std::ostringstream sstream;
...@@ -187,7 +133,7 @@ Field *FieldManager::get(int id) ...@@ -187,7 +133,7 @@ Field *FieldManager::get(int id)
{ {
iterator it = find(id); iterator it = find(id);
if(it == end()) { if(it == end()) {
return NULL; return 0;
} }
return it->second; return it->second;
} }
...@@ -196,15 +142,15 @@ Field *FieldManager::new_field(int id, std::string type_name) ...@@ -196,15 +142,15 @@ Field *FieldManager::new_field(int id, std::string type_name)
{ {
if(find(id) != end()) { if(find(id) != end()) {
Msg::Error("Field id %i is already defined.", id); Msg::Error("Field id %i is already defined.", id);
return NULL; return 0;
} }
if(map_type_name.find(type_name) == map_type_name.end()) { if(map_type_name.find(type_name) == map_type_name.end()) {
Msg::Error("Unknown field type \"%s\".", type_name.c_str()); Msg::Error("Unknown field type \"%s\".", type_name.c_str());
return NULL; return 0;
} }
Field *f = (*map_type_name[type_name]) (); Field *f = (*map_type_name[type_name]) ();
if(!f) if(!f)
return NULL; return 0;
f->id = id; f->id = id;
(*this)[id] = f; (*this)[id] = f;
return f; return f;
...@@ -231,6 +177,7 @@ int FieldManager::max_id() ...@@ -231,6 +177,7 @@ int FieldManager::max_id()
else else
return 0; return 0;
} }
void FieldManager::delete_field(int id) void FieldManager::delete_field(int id)
{ {
iterator it = find(id); iterator it = find(id);
...@@ -251,12 +198,13 @@ class StructuredField:public Field ...@@ -251,12 +198,13 @@ class StructuredField:public Field
bool error_status; bool error_status;
bool text_format; bool text_format;
std::string file_name; std::string file_name;
public:StructuredField() public:
StructuredField()
{ {
options["FileName"] = new FieldOptionString(file_name, &update_needed); options["FileName"] = new FieldOptionString(file_name, &update_needed);
text_format = false; text_format = false;
options["TextFormat"] = new FieldOptionBool(text_format, &update_needed); options["TextFormat"] = new FieldOptionBool(text_format, &update_needed);
data = NULL; data = 0;
} }
const char *get_name() const char *get_name()
{ {
...@@ -333,7 +281,7 @@ public:StructuredField() ...@@ -333,7 +281,7 @@ public:StructuredField()
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -416,7 +364,7 @@ public: ...@@ -416,7 +364,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -441,7 +389,7 @@ public: ...@@ -441,7 +389,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -468,7 +416,7 @@ public: ...@@ -468,7 +416,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
double operator() (double x, double y, double z) double operator() (double x, double y, double z)
...@@ -478,11 +426,11 @@ public: ...@@ -478,11 +426,11 @@ public:
} }
}; };
class ThresholdField : public Field class ThresholdField : public Field
{ {
int iField; int iField;
double dmin, dmax, lcmin, lcmax; double dmin, dmax, lcmin, lcmax;
bool sigmoid;
public: public:
const char *get_name() const char *get_name()
{ {
...@@ -495,28 +443,36 @@ public: ...@@ -495,28 +443,36 @@ public:
dmax = 10; dmax = 10;
lcmin = 0.1; lcmin = 0.1;
lcmax = 1; lcmax = 1;
sigmoid = false;
options["IField"] = new FieldOptionInt(iField); options["IField"] = new FieldOptionInt(iField);
options["DistMin"] = new FieldOptionDouble(dmin); options["DistMin"] = new FieldOptionDouble(dmin);
options["DistMax"] = new FieldOptionDouble(dmax); options["DistMax"] = new FieldOptionDouble(dmax);
options["LcMin"] = new FieldOptionDouble(lcmin); options["LcMin"] = new FieldOptionDouble(lcmin);
options["LcMax"] = new FieldOptionDouble(lcmax); options["LcMax"] = new FieldOptionDouble(lcmax);
options["Sigmoid"] = new FieldOptionBool(sigmoid);
} }
double operator() (double x, double y, double z) double operator() (double x, double y, double z)
{ {
Field *field = GModel::current()->getFields()->get(iField); Field *field = GModel::current()->getFields()->get(iField);
double r = ((*field) (x, y, z) - dmin) / (dmax - dmin); double r = ((*field) (x, y, z) - dmin) / (dmax - dmin);
r = std::max(std::min(r, 1.), 0.); r = std::max(std::min(r, 1.), 0.);
double lc = lcmin * (1 - r) + lcmax * r; double lc;
if(sigmoid){
double s = exp(12. * r - 6.) / (1. + exp(12. * r - 6.));
lc = lcmin * (1. - s) + lcmax * s;
}
else{ // linear
lc = lcmin * (1 - r) + lcmax * r;
}
return lc; return lc;
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
class GradientField:public Field class GradientField:public Field
{ {
int iField, kind; int iField, kind;
...@@ -565,10 +521,11 @@ public: ...@@ -565,10 +521,11 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
class CurvatureField:public Field class CurvatureField:public Field
{ {
int iField; int iField;
...@@ -606,10 +563,11 @@ public: ...@@ -606,10 +563,11 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
#if defined(HAVE_GSL) #if defined(HAVE_GSL)
#include <gsl/gsl_math.h> #include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h> #include <gsl/gsl_eigen.h>
...@@ -672,7 +630,7 @@ public: ...@@ -672,7 +630,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -704,7 +662,7 @@ public: ...@@ -704,7 +662,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -737,7 +695,7 @@ public: ...@@ -737,7 +695,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -779,11 +737,12 @@ public: ...@@ -779,11 +737,12 @@ public:
} }
return evaluator_evaluate(eval, nvalues, names, values); return evaluator_evaluate(eval, nvalues, names, values);
} }
MathEvalExpression() { MathEvalExpression()
eval = NULL; {
values = NULL; eval = 0;
c_str_function = NULL; values = 0;
evaluators_id = NULL; c_str_function = 0;
evaluators_id = 0;
} }
bool set_function(const std::string & f) bool set_function(const std::string & f)
{ {
...@@ -853,7 +812,7 @@ public: ...@@ -853,7 +812,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
const char *get_name() const char *get_name()
...@@ -861,6 +820,7 @@ public: ...@@ -861,6 +820,7 @@ public:
return "MathEval"; return "MathEval";
} }
}; };
class ParametricField:public Field class ParametricField:public Field
{ {
MathEvalExpression expr[3]; MathEvalExpression expr[3];
...@@ -890,7 +850,7 @@ public: ...@@ -890,7 +850,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
const char *get_name() const char *get_name()
...@@ -904,7 +864,8 @@ public: ...@@ -904,7 +864,8 @@ public:
class PostViewField : public Field class PostViewField : public Field
{ {
OctreePost *octree; OctreePost *octree;
public:int view_index; public:
int view_index;
double operator() (double x, double y, double z) double operator() (double x, double y, double z)
{ {
// FIXME: should test unique view num instead, but that would be slower // FIXME: should test unique view num instead, but that would be slower
...@@ -949,17 +910,19 @@ public:int view_index; ...@@ -949,17 +910,19 @@ public:int view_index;
{ {
return "PostView"; return "PostView";
} }
PostViewField() { PostViewField()
octree = NULL; {
octree = 0;
options["IView"] = new FieldOptionInt(view_index, &update_needed); options["IView"] = new FieldOptionInt(view_index, &update_needed);
} }
~PostViewField() { ~PostViewField()
{
if(octree) if(octree)
delete octree; delete octree;
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
...@@ -986,7 +949,7 @@ public: ...@@ -986,7 +949,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
const char *get_name() const char *get_name()
...@@ -1016,7 +979,7 @@ public: ...@@ -1016,7 +979,7 @@ public:
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
const char *get_name() const char *get_name()
...@@ -1035,7 +998,8 @@ class AttractorField:public Field ...@@ -1035,7 +998,8 @@ class AttractorField:public Field
std::list < int >nodes_id; std::list < int >nodes_id;
std::list < int >edges_id; std::list < int >edges_id;
int n_nodes_by_edge; int n_nodes_by_edge;
public:AttractorField():kdtree(0), zeronodes(0) public:
AttractorField() : kdtree(0), zeronodes(0)
{ {
index = new ANNidx[1]; index = new ANNidx[1];
dist = new ANNdist[1]; dist = new ANNdist[1];
...@@ -1122,7 +1086,7 @@ public:AttractorField():kdtree(0), zeronodes(0) ...@@ -1122,7 +1086,7 @@ public:AttractorField():kdtree(0), zeronodes(0)
} }
FieldDialogBox *&dialog_box() FieldDialogBox *&dialog_box()
{ {
static FieldDialogBox *dialogBox = NULL; static FieldDialogBox *dialogBox = 0;
return dialogBox; return dialogBox;
} }
}; };
......
...@@ -29,10 +29,7 @@ typedef enum { ...@@ -29,10 +29,7 @@ typedef enum {
class FieldOption { class FieldOption {
protected: protected:
bool *status; bool *status;
inline void modified() inline void modified(){ if(status) *status = true; }
{
if(status) *status = true;
}
public: public:
FieldOption(bool *_status) : status(_status) {} FieldOption(bool *_status) : status(_status) {}
virtual ~FieldOption() {} virtual ~FieldOption() {}
......
l = 1; l = 1;
r1 = 3; r1 = 3;
r2 = 0.5; r2 = 0.5;
n = 3; n = 10;
n2 = n; n2 = n;
progr = 1.4;
// exterior cube // exterior cube
Point(1) = {0,0,0,l}; Point(1) = {0,0,0,l};
...@@ -68,7 +69,7 @@ Line(56) = {109,15}; ...@@ -68,7 +69,7 @@ Line(56) = {109,15};
Line(57) = {104,4}; Line(57) = {104,4};
Line(58) = {103,3}; Line(58) = {103,3};
Line(59) = {106,11}; Line(59) = {106,11};
Transfinite Line{52:59} = n2; Transfinite Line{52:59} = n2 Using Progression progr;
Line Loop(60) = {58,-1,-52,-29};Plane Surface(61) = {60}; Line Loop(60) = {58,-1,-52,-29};Plane Surface(61) = {60};
Line Loop(62) = {58,18,-59,-39};Plane Surface(63) = {62}; Line Loop(62) = {58,18,-59,-39};Plane Surface(63) = {62};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment