libsurf
Programmer's Documentation

dnrfregion.h (r6227/r5385)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_DNRFREGION_H
16 #define SURF_DNRFREGION_H
17 
18 #include <vector>
19 #include <genua/svector.h>
20 #include <genua/xmlelement.h>
21 
37 {
38  public:
39 
41  DnRefineRegion(const Vct2 & plo, const Vct2 & phi, Real rf) :
42  rtype(DnRectRegion)
43  {
44  assert(rf > 0.0);
45  rfd[0] = plo[0];
46  rfd[1] = plo[1];
47  rfd[2] = phi[0];
48  rfd[3] = phi[1];
49  rfd[4] = 1.0 / rf;
50  }
51 
53  DnRefineRegion(const Vct2 & ctr, Real ru, Real rv, Real rf) :
54  rtype(DnRadialRegion)
55  {
56  assert(ru > 0.0);
57  assert(rv > 0.0);
58  assert(rf > 0.0);
59  rfd[0] = ctr[0];
60  rfd[1] = ctr[1];
61  rfd[2] = ru;
62  rfd[3] = rv;
63  rfd[4] = 1.0 / rf;
64  }
65 
67  explicit DnRefineRegion(const XmlElement & xe) {fromXml(xe);}
68 
70  inline Real factor(const Vct2 & p) const
71  {
72  if (rtype == DnRadialRegion) {
73  Real usq = sq( (p[0]-rfd[0]) / rfd[2] );
74  Real vsq = sq( (p[1]-rfd[1]) / rfd[3] );
75  if (usq+vsq > 1.0) {
76  return 1.0;
77  } else {
78  // Real t = sqrt(usq + vsq);
79  Real t = usq + vsq;
80  return (1-t)*rfd[4] + t;
81  }
82  } else {
83  if (p[0] < rfd[0] or p[0] > rfd[2])
84  return 1.0;
85  else if (p[1] < rfd[1] or p[1] > rfd[3])
86  return 1.0;
87  else
88  return rfd[4];
89  }
90  }
91 
93  XmlElement toXml() const;
94 
96  void fromXml(const XmlElement & xe);
97 
98  private:
99 
101  Real rfd[5];
102 
104  enum {DnRadialRegion, DnRectRegion} rtype;
105 };
106 
107 typedef std::vector<DnRefineRegion> DnRegionArray;
108 
109 #endif
110 
DnRefineRegion(const Vct2 &plo, const Vct2 &phi, Real rf)
initialize rectangular region
Definition: dnrfregion.h:41
XmlElement toXml() const
generate an xml representation
Definition: dnrfregion.cpp:20
void fromXml(const XmlElement &xe)
recover from xml representation
Definition: dnrfregion.cpp:35
DnRefineRegion(const XmlElement &xe)
initialize from XML representation
Definition: dnrfregion.h:67
Real rfd[5]
region boundaries and refinement factors
Definition: dnrfregion.h:101
Mesh refinement region.
Definition: dnrfregion.h:36
DnRefineRegion(const Vct2 &ctr, Real ru, Real rv, Real rf)
initialize circular region
Definition: dnrfregion.h:53
Real factor(const Vct2 &p) const
compute refinement factor
Definition: dnrfregion.h:70
enum DnRefineRegion::@0 rtype
type switch
Generated on Wed Jan 19 2022 03:03:15 for libsurf by   doxygen 1.8.5