Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NodeOpti.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessJac.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Calculate jacobians of elements.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef UTILITIES_NEKMESH_NODEOPTI
37 #define UTILITIES_NEKMESH_NODEOPTI
38 
39 #include <ostream>
40 
42 
43 #include "ProcessVarOpti.h"
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 class NodeOptiJob;
51 
52 class NodeOpti
53 {
54 public:
55  NodeOpti(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
57  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
58  optiType o)
59  : m_node(n), m_res(r), m_derivUtils(d), m_opti(o)
60  {
61  // filter element types within d vector
62  for (int i = 0; i < e.size(); i++)
63  {
64  m_data[e[i]->GetEl()->GetShapeType()].push_back(e[i]);
65  }
66  }
67 
68  virtual ~NodeOpti(){};
69 
70  void CalcMinJac();
71 
72  virtual void Optimise() = 0;
74 
75  template <int DIM>
76  NekDouble GetFunctional(NekDouble &minJacNew, bool gradient = true);
77 
78  template <int DIM> void MinEigen(NekDouble &val);
79 
80 protected:
83  std::map<LibUtilities::ShapeType, std::vector<ElUtilSharedPtr> > m_data;
85 
86  template <int DIM> int IsIndefinite();
87 
90  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> m_derivUtils;
92 
93  static NekDouble c1()
94  {
95  return 1e-3;
96  }
97  static NekDouble gradTol()
98  {
99  return 1e-8;
100  }
102  {
103  return 1e-8;
104  }
105 };
106 
107 typedef boost::shared_ptr<NodeOpti> NodeOptiSharedPtr;
109  int, NodeOpti, NodeSharedPtr, std::vector<ElUtilSharedPtr>,
110  ResidualSharedPtr, std::map<LibUtilities::ShapeType, DerivUtilSharedPtr>,
111  optiType>
113 
115 
116 class NodeOpti3D3D : public NodeOpti // 1D optimsation in 3D space
117 {
118 public:
119  NodeOpti3D3D(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
120  ResidualSharedPtr r,
121  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
122  optiType o)
123  : NodeOpti(n, e, r, d, o)
124  {
125  }
126 
128 
129  void Optimise();
130 
131  static int m_type;
132  static NodeOptiSharedPtr create(
133  NodeSharedPtr n, std::vector<ElUtilSharedPtr> e, ResidualSharedPtr r,
134  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d, optiType o)
135  {
136  return NodeOptiSharedPtr(new NodeOpti3D3D(n, e, r, d, o));
137  }
138 
139 private:
140 };
141 
142 class NodeOpti2D2D : public NodeOpti // 1D optimsation in 3D space
143 {
144 public:
145  NodeOpti2D2D(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
146  ResidualSharedPtr r,
147  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
148  optiType o)
149  : NodeOpti(n, e, r, d, o)
150  {
151  }
152 
154 
155  void Optimise();
156 
157  static int m_type;
158  static NodeOptiSharedPtr create(
159  NodeSharedPtr n, std::vector<ElUtilSharedPtr> e, ResidualSharedPtr r,
160  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d, optiType o)
161  {
162  return NodeOptiSharedPtr(new NodeOpti2D2D(n, e, r, d, o));
163  }
164 
165 private:
166 };
167 
169 {
170 public:
171  NodeOptiJob(NodeOpti *no) : node(no)
172  {
173  }
174 
175  void Run()
176  {
177  node->Optimise();
178  }
179 
180 private:
181  NodeOpti *node;
182 };
183 }
184 }
185 
186 #endif
NodeOptiFactory & GetNodeOptiFactory()
Definition: NodeOpti.cpp:52
int IsIndefinite()
Returns 1 if Hessian matrix is indefinite and 0 otherwise.
Definition: Hessian.hxx:50
static NekDouble alphaTol()
Definition: NodeOpti.h:101
void MinEigen(NekDouble &val)
Calculates minimum eigenvalue of Hessian matrix.
Definition: Hessian.hxx:148
NodeOptiJob * GetJob()
Definition: NodeOpti.cpp:276
LibUtilities::NekFactory< int, NodeOpti, NodeSharedPtr, std::vector< ElUtilSharedPtr >, ResidualSharedPtr, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr >, optiType > NodeOptiFactory
Definition: NodeOpti.h:112
Array< OneD, NekDouble > m_grad
Definition: NodeOpti.h:84
std::map< LibUtilities::ShapeType, std::vector< ElUtilSharedPtr > > m_data
Definition: NodeOpti.h:83
boost::shared_ptr< Residual > ResidualSharedPtr
Definition: ElUtil.h:54
static NekDouble c1()
Definition: NodeOpti.h:93
NodeOpti(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:55
NodeOpti2D2D(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:145
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
boost::shared_ptr< NodeOpti > NodeOptiSharedPtr
Definition: NodeOpti.h:107
NekDouble GetFunctional(NekDouble &minJacNew, bool gradient=true)
Evaluate functional for elements connected to a node.
Definition: Evaluator.hxx:274
static NodeOptiSharedPtr create(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:158
ResidualSharedPtr m_res
Definition: NodeOpti.h:89
virtual void Optimise()=0
Base class for tasks to be sent to the ThreadManager to run.
Definition: Thread.h:99
static NodeOptiSharedPtr create(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:132
NodeOpti3D3D(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:119
static boost::mutex mutex
Definition: Vmath.cpp:134
NodeSharedPtr m_node
Definition: NodeOpti.h:81
static NekDouble gradTol()
Definition: NodeOpti.h:97
std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > m_derivUtils
Definition: NodeOpti.h:90
Provides a generic Factory class.
Definition: NekFactory.hpp:116