diff --git a/Geo/STensor3.h b/Geo/STensor3.h index a039a045fb4884f684c3a77e049f99c4df92a567..3edc3b39809d307b03937b0017f6f55028f66531 100644 --- a/Geo/STensor3.h +++ b/Geo/STensor3.h @@ -92,7 +92,7 @@ class SMetric3 { { return _val[getIndex(i, j)]; } - SMetric3 invert () const + SMetric3 invert() const { fullMatrix<double> m(3, 3); getMat(m); @@ -101,7 +101,7 @@ class SMetric3 { ithis.setMat(m); return ithis; } - double determinant () const + double determinant() const { fullMatrix<double> m(3,3); getMat(m); @@ -185,7 +185,6 @@ SMetric3 interpolation (const SMetric3 &m1, const double w); // concrete class for general 3x3 matrix - class STensor3 { protected: // 00 01 02 10 11 12 20 21 22 @@ -237,7 +236,7 @@ class STensor3 { { return _val[i]; } - STensor3 invert () const + STensor3 invert() const { fullMatrix<double> m(3, 3); getMat(m); @@ -246,7 +245,6 @@ class STensor3 { ithis.setMat(m); return ithis; } - STensor3 operator + (const STensor3 &other) const { STensor3 res(*this); diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp index 29103eef72985603736ee1f033227759fdd0fddc..a8c550b63b3757fcbcc82082afc894b718cd08c3 100644 --- a/Mesh/Field.cpp +++ b/Mesh/Field.cpp @@ -908,11 +908,13 @@ class MathEvalExpressionAniso mathEvaluator *_f[6]; std::set<int> _fields[6]; public: - MathEvalExpressionAniso() { - for (int i=0;i<6;i++)_f[i]=0; + MathEvalExpressionAniso() + { + for(int i = 0; i < 6; i++) _f[i] = 0; } - ~MathEvalExpressionAniso(){ - for (int i=0;i<6;i++)if(_f[i]) delete _f[i]; + ~MathEvalExpressionAniso() + { + for(int i = 0; i < 6; i++) if(_f[i]) delete _f[i]; } bool set_function(int iFunction, const std::string &f) { @@ -955,8 +957,9 @@ class MathEvalExpressionAniso void evaluate (double x, double y, double z, SMetric3 &metr) { const int index[6][2] = {{0,0},{1,1},{2,2},{0,1},{0,2},{1,2}}; - for (int iFunction = 0;iFunction<6;iFunction++){ - if(!_f[iFunction]) metr(index[iFunction][0],index[iFunction][1]) = MAX_LC; + for (int iFunction = 0; iFunction < 6; iFunction++){ + if(!_f[iFunction]) + metr(index[iFunction][0], index[iFunction][1]) = MAX_LC; else{ std::vector<double> values(3 + _fields[iFunction].size()), res(1); values[0] = x; @@ -1015,7 +1018,7 @@ class MathEvalFieldAniso : public Field MathEvalExpressionAniso expr; std::string f[6]; public: - virtual bool isotropic () const {return false;} + virtual bool isotropic () const { return false; } MathEvalFieldAniso() { options["m11"] = new FieldOptionString @@ -1047,21 +1050,21 @@ class MathEvalFieldAniso : public Field } update_needed = false; } - expr.evaluate(x, y, z,metr); + expr.evaluate(x, y, z, metr); } double operator() (double x, double y, double z, GEntity *ge=0) { if(update_needed) { - for (int i=0;i<6;i++){ - if(!expr.set_function(i,f[i])) + for (int i = 0; i < 6; i++){ + if(!expr.set_function(i, f[i])) Msg::Error("Field %i: Invalid matheval expression \"%s\"", this->id, f[i].c_str()); } update_needed = false; } SMetric3 metr; - expr.evaluate(x, y, z,metr); - return metr(0,0); + expr.evaluate(x, y, z, metr); + return metr(0, 0); } const char *getName() { @@ -1123,24 +1126,53 @@ class ParametricField : public Field }; #if defined(HAVE_POST) + class PostViewField : public Field { OctreePost *octree; - public: int view_index; bool crop_negative_values; - double operator() (double x, double y, double z, GEntity *ge=0) + public: + PostViewField() + { + octree = 0; + view_index = 0; + options["IView"] = new FieldOptionInt + (view_index, "Post-processing view index", &update_needed); + crop_negative_values = true; + options["CropNegativeValues"] = new FieldOptionBool + (crop_negative_values, "return LC_MAX instead of a negative value (this " + "option is needed for backward compatibility with the BackgroundMesh option"); + } + ~PostViewField() + { + if(octree) delete octree; + } + PView *getView() const { // we should maybe test the unique view num instead, but that // would be slower - if(view_index < 0 || view_index >= (int)PView::list.size()) - return MAX_LC; + if(view_index < 0 || view_index >= (int)PView::list.size()){ + Msg::Error("View[%d] does not exist", view_index); + return 0; + } PView *v = PView::list[view_index]; if(v->getData()->hasModel(GModel::current())){ - Msg::Error("Cannot use view based on current model for background mesh"); - Msg::Error("Use a list-based view (.pos file) instead?"); - return MAX_LC; + Msg::Error("Cannot use view based on current mesh for background mesh: you might" + " want to use a list-based view (.pos file) instead"); + return 0; } + } + virtual bool isotropic () const + { + PView *v = getView(); + if(v && v->getData()->getNumTensors()) return false; + return true; + } + double operator() (double x, double y, double z, GEntity *ge=0) + { + PView *v = getView(); + if(!v) return MAX_LC; if(update_needed){ if(octree) delete octree; octree = new OctreePost(v); @@ -1150,10 +1182,31 @@ class PostViewField : public Field // use large tolerance (in element reference coordinates) to // maximize chance of finding an element if(!octree->searchScalarWithTol(x, y, z, &l, 0, 0, 1.)) - Msg::Info("No element found containing point (%g,%g,%g)", x, y, z); + Msg::Info("No scalar element found containing point (%g,%g,%g)", x, y, z); if(l <= 0 && crop_negative_values) return MAX_LC; return l; } + void operator() (double x, double y, double z, SMetric3 &metr, GEntity *ge=0) + { + PView *v = getView(); + if(!v) return; + if(update_needed){ + if(octree) delete octree; + octree = new OctreePost(v); + update_needed = false; + } + double l[9]; + if(!octree->searchTensor(x, y, z, l, 0)){ + Msg::Info("No tensor element found containing point (%g,%g,%g)", x, y, z); + return; + } + metr(0, 0) = l[0]; + metr(1, 0) = l[3]; + metr(1, 1) = l[4]; + metr(2, 0) = l[6]; + metr(2, 1) = l[7]; + metr(2, 2) = l[8]; + } const char *getName() { return "PostView"; @@ -1162,22 +1215,8 @@ class PostViewField : public Field { return "Evaluate the post processing view IView."; } - PostViewField() - { - octree = 0; - view_index = 0; - options["IView"] = new FieldOptionInt - (view_index, "Post-processing view index", &update_needed); - crop_negative_values = true; - options["CropNegativeValues"] = new FieldOptionBool - (crop_negative_values, "return LC_MAX instead of a negative value (this " - "option is needed for backward compatibility with the BackgroundMesh option"); - } - ~PostViewField() - { - if(octree) delete octree; - } }; + #endif class MinAnisoField : public Field