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  // Typedef for derivative storage, we use boost::multi_array so we can pass
55  // this to functions easily
56  typedef boost::multi_array<NekDouble, 4> DerivArray;
57 
58 public:
59  NodeOpti(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
61  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
62  optiType o, int dim)
63  : m_node(n), m_res(r), m_derivUtils(d), m_opti(o)
64  {
65  // filter element types within d vector
66  for (int i = 0; i < e.size(); i++)
67  {
68  m_data[e[i]->GetEl()->GetShapeType()].push_back(e[i]);
69  }
70 
71  // Set up storage for GetFunctional to avoid reallocation on each call.
72  size_t storageCount = 0;
73  std::map<LibUtilities::ShapeType, std::vector<ElUtilSharedPtr> >
74  ::iterator typeIt;
75  // Count total storage needed.
76  for (typeIt = m_data.begin(); typeIt != m_data.end(); typeIt++)
77  {
78  const int pts = m_derivUtils[typeIt->first]->pts;
79  const int nElmt = typeIt->second.size();
80 
81  storageCount = std::max(storageCount,
82  dim * m_derivUtils[typeIt->first]->ptsStd *
83  typeIt->second.size());
84 
85  m_derivs.insert(std::make_pair(
86  typeIt->first,
87  DerivArray(boost::extents[dim][nElmt][dim][pts])));
88  }
89 
90  m_tmpStore.resize(storageCount);
91  }
92 
93  virtual ~NodeOpti(){};
94 
95  void CalcMinJac();
96 
97  virtual void Optimise() = 0;
99 
100  template <int DIM>
101  NekDouble GetFunctional(NekDouble &minJacNew, bool gradient = true);
102 
103  template <int DIM> void MinEigen(NekDouble &val);
104 
105 protected:
108  std::map<LibUtilities::ShapeType, std::vector<ElUtilSharedPtr> > m_data;
110  std::vector<NekDouble> m_tmpStore;
111  boost::unordered_map<LibUtilities::ShapeType, DerivArray> m_derivs;
112 
113 
114  template <int DIM> int IsIndefinite();
115 
118  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> m_derivUtils;
120 
121  static NekDouble c1()
122  {
123  return 1e-3;
124  }
126  {
127  return 1e-8;
128  }
130  {
131  return 1e-8;
132  }
133 };
134 
135 typedef boost::shared_ptr<NodeOpti> NodeOptiSharedPtr;
137  int, NodeOpti, NodeSharedPtr, std::vector<ElUtilSharedPtr>,
138  ResidualSharedPtr, std::map<LibUtilities::ShapeType, DerivUtilSharedPtr>,
139  optiType>
141 
143 
144 class NodeOpti3D3D : public NodeOpti // 1D optimsation in 3D space
145 {
146 public:
147  NodeOpti3D3D(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
148  ResidualSharedPtr r,
149  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
150  optiType o)
151  : NodeOpti(n, e, r, d, o, 3)
152  {
153  }
154 
156 
157  void Optimise();
158 
159  static int m_type;
160  static NodeOptiSharedPtr create(
161  NodeSharedPtr n, std::vector<ElUtilSharedPtr> e, ResidualSharedPtr r,
162  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d, optiType o)
163  {
164  return NodeOptiSharedPtr(new NodeOpti3D3D(n, e, r, d, o));
165  }
166 
167 private:
168 };
169 
170 class NodeOpti2D2D : public NodeOpti // 1D optimsation in 3D space
171 {
172 public:
173  NodeOpti2D2D(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
174  ResidualSharedPtr r,
175  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d,
176  optiType o)
177  : NodeOpti(n, e, r, d, o, 2)
178  {
179  }
180 
182 
183  void Optimise();
184 
185  static int m_type;
186  static NodeOptiSharedPtr create(
187  NodeSharedPtr n, std::vector<ElUtilSharedPtr> e, ResidualSharedPtr r,
188  std::map<LibUtilities::ShapeType, DerivUtilSharedPtr> d, optiType o)
189  {
190  return NodeOptiSharedPtr(new NodeOpti2D2D(n, e, r, d, o));
191  }
192 
193 private:
194 };
195 
197 {
198 public:
199  NodeOptiJob(NodeOpti *no) : node(no)
200  {
201  }
202 
203  void Run()
204  {
205  node->Optimise();
206  }
207 
208 private:
209  NodeOpti *node;
210 };
211 }
212 }
213 
214 #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:129
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:140
Array< OneD, NekDouble > m_grad
Definition: NodeOpti.h:109
std::map< LibUtilities::ShapeType, std::vector< ElUtilSharedPtr > > m_data
Definition: NodeOpti.h:108
boost::shared_ptr< Residual > ResidualSharedPtr
Definition: ElUtil.h:54
static NekDouble c1()
Definition: NodeOpti.h:121
boost::unordered_map< LibUtilities::ShapeType, DerivArray > m_derivs
Definition: NodeOpti.h:111
std::vector< NekDouble > m_tmpStore
Definition: NodeOpti.h:110
NodeOpti2D2D(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:173
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
boost::multi_array< NekDouble, 4 > DerivArray
Definition: NodeOpti.h:56
double NekDouble
boost::shared_ptr< NodeOpti > NodeOptiSharedPtr
Definition: NodeOpti.h:135
NekDouble GetFunctional(NekDouble &minJacNew, bool gradient=true)
Evaluate functional for elements connected to a node.
Definition: Evaluator.hxx:269
NodeOpti(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o, int dim)
Definition: NodeOpti.h:59
static NodeOptiSharedPtr create(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:186
ResidualSharedPtr m_res
Definition: NodeOpti.h:117
virtual void Optimise()=0
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
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:160
NodeOpti3D3D(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:147
static boost::mutex mutex
Definition: Vmath.cpp:134
static NekDouble gradTol()
Definition: NodeOpti.h:125
std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > m_derivUtils
Definition: NodeOpti.h:118
Provides a generic Factory class.
Definition: NekFactory.hpp:116