/usr/include/gmsh/Field.h is in libgmsh-dev 3.0.6+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | // Gmsh - Copyright (C) 1997-2017 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _FIELD_H_
#define _FIELD_H_
#include <string>
#include <map>
#include <vector>
#include <list>
#include "GmshConfig.h"
#include "STensor3.h"
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <algorithm>
#if defined(HAVE_POST)
class PView;
#endif
class Field;
class GEntity;
typedef enum {
FIELD_OPTION_DOUBLE = 0,
FIELD_OPTION_INT,
FIELD_OPTION_STRING,
FIELD_OPTION_PATH,
FIELD_OPTION_BOOL,
FIELD_OPTION_LIST,
FIELD_OPTION_LIST_DOUBLE
} FieldOptionType;
class FieldCallback {
private:
std::string _help;
public:
virtual void run() = 0;
FieldCallback(const std::string help){ _help = help;}
virtual ~FieldCallback(){};
virtual std::string getDescription(){ return _help; }
};
class FieldOption {
private:
std::string _help;
protected:
bool *status;
inline void modified(){ if(status) *status = true; }
public:
FieldOption(std::string help, bool *_status) : _help(help), status(_status) {}
virtual ~FieldOption() {}
virtual FieldOptionType getType() = 0;
virtual void getTextRepresentation(std::string & v_str) = 0;
virtual std::string getDescription(){ return _help; }
std::string getTypeName(){
switch(getType()){
case FIELD_OPTION_INT: return "integer"; break;
case FIELD_OPTION_DOUBLE: return "float"; break;
case FIELD_OPTION_BOOL: return "boolean"; break;
case FIELD_OPTION_PATH: return "path"; break;
case FIELD_OPTION_STRING: return "string"; break;
case FIELD_OPTION_LIST: return "list"; break;
case FIELD_OPTION_LIST_DOUBLE: return "list_double"; break;
default: return "unknown";
}
}
virtual void numericalValue(double val) {}
virtual double numericalValue() const { return 0.; }
virtual const std::list<int> &list() const
{
static std::list<int> l;
return l;
}
virtual const std::list<double> &listdouble() const
{
static std::list<double> l;
return l;
}
virtual void list(std::list<int> value) { }
virtual void listdouble(std::list<double> value) { }
virtual std::string string() const { return ""; }
virtual void string(const std::string value) { }
};
class Field {
public:
Field() : update_needed(false) {}
virtual ~Field();
virtual void update() {}
int id;
std::map<std::string, FieldOption *> options;
std::map<std::string, FieldCallback*> callbacks;
virtual bool isotropic () const { return true; }
// isotropic
virtual double operator() (double x, double y, double z, GEntity *ge=0) = 0;
// anisotropic
virtual void operator() (double x, double y, double z, SMetric3 &, GEntity *ge=0){}
bool update_needed;
virtual const char *getName() = 0;
#if defined(HAVE_POST)
void putOnView(PView * view, int comp = -1);
#endif
void putOnNewView();
virtual std::string getDescription(){ return ""; }
FieldOption * getOption(const std::string optionName);
};
class FieldFactory {
public:
virtual ~FieldFactory() {}
virtual Field * operator() () = 0;
};
class FieldManager : public std::map<int, Field*> {
private:
int _background_field;
int _boundaryLayer_field;
public:
std::map<std::string, FieldFactory*> map_type_name;
void initialize();
void reset();
Field *get(int id);
Field *newField(int id, std::string type_name);
void deleteField(int id);
int newId();
int maxId();
FieldManager();
~FieldManager();
// compatibility with -bgm
void setBackgroundMesh(int iView);
// set and get background field
void setBackgroundField(Field* BGF);
inline void setBackgroundFieldId(int id){_background_field = id;};
inline void setBoundaryLayerFieldId(int id){_boundaryLayer_field = id;};
inline int getBackgroundField(){return _background_field;}
inline int getBoundaryLayerField(){return _boundaryLayer_field;}
};
// Boundary Layer Field (used both for anisotropic meshing and BL
// extrusion)
#if defined(HAVE_ANN)
class AttractorField;
class BoundaryLayerField : public Field {
private:
std::list<AttractorField *> _att_fields;
std::list<double> hwall_n_nodes;
std::list<int> nodes_id, edges_id;
std::list<int> edges_id_saved, nodes_id_saved, fan_nodes_id;
void operator() (AttractorField *cc, double dist, double x, double y, double z,
SMetric3 &metr, GEntity *ge);
public:
double hwall_n,ratio,hfar,thickness,fan_angle;
double current_distance, tgt_aniso_ratio;
SPoint3 _closest_point;
int iRecombine, iIntersect;
AttractorField *current_closest;
virtual bool isotropic () const {return false;}
virtual const char *getName();
virtual std::string getDescription();
BoundaryLayerField();
~BoundaryLayerField() {removeAttractors();}
virtual double operator() (double x, double y, double z, GEntity *ge=0);
virtual void operator() (double x, double y, double z, SMetric3 &metr, GEntity *ge=0);
bool isEdgeBL (int iE) const
{
return std::find(edges_id.begin(),edges_id.end(),iE) != edges_id.end();
}
bool isEdgeBLSaved (int iE) const
{
return std::find(edges_id_saved.begin(),edges_id_saved.end(),iE)
!= edges_id_saved.end();
}
bool isFanNode (int iV) const
{
return std::find(fan_nodes_id.begin(),fan_nodes_id.end(),iV) != fan_nodes_id.end();
}
bool isEndNode (int iV) const
{
return std::find(nodes_id.begin(),nodes_id.end(),iV) != nodes_id.end();
}
double hwall (int iV){
for (std::list<double>::iterator it = hwall_n_nodes.begin(); it != hwall_n_nodes.end(); ++it){
int i = (int) *it; ++it;
double h = *it;
if (i == iV)return h;
}
return hwall_n;
}
void computeFor1dMesh(double x, double y, double z, SMetric3 &metr);
void setupFor1d(int iE);
void setupFor2d(int iF);
void removeAttractors();
};
#else
class BoundaryLayerField : public Field {
public:
virtual bool isotropic() const { return false; }
virtual const char *getName(){ return ""; }
virtual std::string getDescription(){ return ""; }
BoundaryLayerField()
{
Msg::Error("You must compile with ANN to use BoundaryLayerField");
}
~BoundaryLayerField() {}
virtual double operator() (double x, double y, double z, GEntity *ge=0){ return 0.; }
virtual void operator() (double x, double y, double z, SMetric3 &metr, GEntity *ge=0){}
bool isFaceBL (int iF) const {return false;}
bool isEdgeBL (int iE) const {return false;}
bool isFan (int iE) const {return false;}
bool isVertexBL (int iV) const {return false;}
void computeFor1dMesh(double x, double y, double z, SMetric3 &metr){}
void setupFor2d(int iF){}
void setupFor3d(){}
void removeAttractors(){}
};
#endif
class FieldOptionString : public FieldOption
{
public:
std::string & val;
virtual FieldOptionType getType(){ return FIELD_OPTION_STRING; }
FieldOptionString(std::string &_val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val) {}
void string(const std::string value) { modified(); val = value;}
std::string string() const { return val; }
void getTextRepresentation(std::string &v_str)
{
std::ostringstream sstream;
sstream << "\"" << val << "\"";
v_str = sstream.str();
}
};
class FieldOptionDouble : public FieldOption
{
public:
double &val;
FieldOptionType getType(){ return FIELD_OPTION_DOUBLE; }
FieldOptionDouble(double &_val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val){}
double numericalValue() const { return val; }
void numericalValue(double v){ modified(); val = v; }
void getTextRepresentation(std::string &v_str)
{
std::ostringstream sstream;
sstream.precision(16);
sstream << val;
v_str = sstream.str();
}
};
class FieldOptionInt : public FieldOption
{
public:
int &val;
FieldOptionType getType(){ return FIELD_OPTION_INT; }
FieldOptionInt(int &_val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val){}
double numericalValue() const { return val; }
void numericalValue(double v){ modified(); val = (int)v; }
void getTextRepresentation(std::string & v_str)
{
std::ostringstream sstream;
sstream << val;
v_str = sstream.str();
}
};
class FieldOptionList : public FieldOption
{
public:
std::list<int> &val;
FieldOptionType getType(){ return FIELD_OPTION_LIST; }
FieldOptionList(std::list<int> &_val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val) {}
void list(std::list<int> value){ modified(); val = value; }
const std::list<int>& list() const { return val; }
void getTextRepresentation(std::string & v_str)
{
std::ostringstream sstream;
sstream << "{";
for(std::list<int>::iterator it = val.begin(); it != val.end(); it++) {
if(it != val.begin())
sstream << ", ";
sstream << *it;
}
sstream << "}";
v_str = sstream.str();
}
};
class FieldOptionListDouble : public FieldOption
{
public:
std::list<double> &val;
FieldOptionType getType(){ return FIELD_OPTION_LIST_DOUBLE; }
FieldOptionListDouble(std::list<double> &_val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val) {}
void listdouble(std::list<double> value){ modified(); val = value; }
const std::list<double>& listdouble() const { return val; }
void getTextRepresentation(std::string & v_str)
{
std::ostringstream sstream;
sstream.precision(16);
sstream << "{";
for(std::list<double>::iterator it = val.begin(); it != val.end(); it++) {
if(it != val.begin())
sstream << ", ";
sstream << *it;
}
sstream << "}";
v_str = sstream.str();
}
};
class FieldOptionPath : public FieldOptionString
{
public:
virtual FieldOptionType getType(){ return FIELD_OPTION_PATH; }
FieldOptionPath(std::string &_val, std::string _help, bool *_status=0)
: FieldOptionString(_val, _help, _status) {}
};
class FieldOptionBool : public FieldOption
{
public:
bool & val;
FieldOptionType getType(){ return FIELD_OPTION_BOOL; }
FieldOptionBool(bool & _val, std::string _help, bool *_status=0)
: FieldOption(_help, _status), val(_val) {}
double numericalValue() const { return val; }
void numericalValue(double v){ modified(); val = v; }
void getTextRepresentation(std::string & v_str)
{
std::ostringstream sstream;
sstream << val;
v_str = sstream.str();
}
};
template<class t>
class FieldCallbackGeneric : public FieldCallback {
t * _field;
void (t::*_callback)();
public :
void run()
{
(_field->*_callback)();
}
FieldCallbackGeneric( t *field, void (t::*callback)(), const std::string description)
: FieldCallback(description)
{
_field = field;
_callback = callback;
}
};
template<class F> class FieldFactoryT : public FieldFactory {
public:
Field * operator()() { return new F; }
};
// the class GenericField contains a set of void* functions, which give a mesh size
// All these functions are called when calling operator() ; then, the minimum size is returned.
class GenericField : public Field{
public:
// callback prototypes:
// this callback is called with a void* previously given to the GenericField !
typedef bool (*ptrfunction)(double, double, double, void*, double&);
GenericField();
~GenericField();
using Field::operator();
virtual double operator() (double x, double y, double z, GEntity *ge=0);
virtual const char *getName(){return "GenericField";};
// sets the callbacks
void setCallbackWithData(ptrfunction fct, void *data);
private:
std::vector<ptrfunction> cbs;// the callbacks
std::vector<void*> user_data;// the data to be sent to the callbacks
};
#endif
|