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