Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::NodeOpti3D3D Class Reference

#include <NodeOpti.h>

Inheritance diagram for Nektar::Utilities::NodeOpti3D3D:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::NodeOpti3D3D:
Collaboration graph
[legend]

Public Member Functions

 NodeOpti3D3D (NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
 
 ~NodeOpti3D3D ()
 
void Optimise ()
 
- Public Member Functions inherited from Nektar::Utilities::NodeOpti
 NodeOpti (NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o, int dim)
 
virtual ~NodeOpti ()
 
void CalcMinJac ()
 
NodeOptiJobGetJob ()
 
template<int DIM>
NekDouble GetFunctional (NekDouble &minJacNew, bool gradient=true)
 Evaluate functional for elements connected to a node. More...
 
template<int DIM>
void MinEigen (NekDouble &val)
 Calculates minimum eigenvalue of Hessian matrix. More...
 
template<>
void MinEigen (NekDouble &val)
 
template<>
void MinEigen (NekDouble &val)
 

Static Public Member Functions

static NodeOptiSharedPtr create (NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
 

Static Public Attributes

static int m_type
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::NodeOpti
template<int DIM>
int IsIndefinite ()
 Returns 1 if Hessian matrix is indefinite and 0 otherwise. More...
 
template<>
int IsIndefinite ()
 
template<>
int IsIndefinite ()
 
- Static Protected Member Functions inherited from Nektar::Utilities::NodeOpti
static NekDouble c1 ()
 
static NekDouble gradTol ()
 
static NekDouble alphaTol ()
 
- Protected Attributes inherited from Nektar::Utilities::NodeOpti
NodeSharedPtr m_node
 
boost::mutex mtx
 
std::map
< LibUtilities::ShapeType,
std::vector< ElUtilSharedPtr > > 
m_data
 
Array< OneD, NekDoublem_grad
 
std::vector< NekDoublem_tmpStore
 
boost::unordered_map
< LibUtilities::ShapeType,
DerivArray
m_derivs
 
NekDouble m_minJac
 
ResidualSharedPtr m_res
 
std::map
< LibUtilities::ShapeType,
DerivUtilSharedPtr
m_derivUtils
 
optiType m_opti
 

Detailed Description

Definition at line 144 of file NodeOpti.h.

Constructor & Destructor Documentation

Nektar::Utilities::NodeOpti3D3D::NodeOpti3D3D ( NodeSharedPtr  n,
std::vector< ElUtilSharedPtr e,
ResidualSharedPtr  r,
std::map< LibUtilities::ShapeType, DerivUtilSharedPtr d,
optiType  o 
)
inline

Definition at line 147 of file NodeOpti.h.

Referenced by create().

151  : NodeOpti(n, e, r, d, o, 3)
152  {
153  }
NodeOpti(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o, int dim)
Definition: NodeOpti.h:59
Nektar::Utilities::NodeOpti3D3D::~NodeOpti3D3D ( )
inline

Definition at line 155 of file NodeOpti.h.

155 {};

Member Function Documentation

static NodeOptiSharedPtr Nektar::Utilities::NodeOpti3D3D::create ( NodeSharedPtr  n,
std::vector< ElUtilSharedPtr e,
ResidualSharedPtr  r,
std::map< LibUtilities::ShapeType, DerivUtilSharedPtr d,
optiType  o 
)
inlinestatic

Definition at line 160 of file NodeOpti.h.

References NodeOpti3D3D().

163  {
164  return NodeOptiSharedPtr(new NodeOpti3D3D(n, e, r, d, o));
165  }
boost::shared_ptr< NodeOpti > NodeOptiSharedPtr
Definition: NodeOpti.h:135
NodeOpti3D3D(NodeSharedPtr n, std::vector< ElUtilSharedPtr > e, ResidualSharedPtr r, std::map< LibUtilities::ShapeType, DerivUtilSharedPtr > d, optiType o)
Definition: NodeOpti.h:147
void Nektar::Utilities::NodeOpti3D3D::Optimise ( )
virtual

Implements Nektar::Utilities::NodeOpti.

Definition at line 165 of file NodeOpti.cpp.

References Nektar::Utilities::mtx.

166 {
167  NekDouble minJacNew;
168  NekDouble currentW = GetFunctional<3>(minJacNew);
169  NekDouble newVal = currentW;
170 
171  if (m_grad[0] * m_grad[0] + m_grad[1] * m_grad[1] + m_grad[2] * m_grad[2] >
172  gradTol())
173  {
174  // needs to optimise
175  NekDouble xc = m_node->m_x;
176  NekDouble yc = m_node->m_y;
177  NekDouble zc = m_node->m_z;
178 
179  Array<OneD, NekDouble> sk(3);
180  NekDouble val;
181 
182  // Calculate minimum eigenvalue
183  MinEigen<3>(val);
184 
185  if (val < 1e-6)
186  {
187  // Add constant identity to Hessian matrix.
188  m_grad[3] += 1e-6 - val;
189  m_grad[6] += 1e-6 - val;
190  m_grad[8] += 1e-6 - val;
191  }
192 
193  // calculate sk
194  NekDouble det =
195  m_grad[3] * (m_grad[6] * m_grad[8] - m_grad[7] * m_grad[7]) -
196  m_grad[4] * (m_grad[4] * m_grad[8] - m_grad[5] * m_grad[7]) +
197  m_grad[5] * (m_grad[4] * m_grad[7] - m_grad[5] * m_grad[6]);
198 
199  sk[0] = m_grad[0] * (m_grad[6] * m_grad[8] - m_grad[7] * m_grad[7]) +
200  m_grad[1] * (m_grad[5] * m_grad[7] - m_grad[4] * m_grad[8]) +
201  m_grad[2] * (m_grad[4] * m_grad[7] - m_grad[3] * m_grad[7]);
202  sk[1] = m_grad[0] * (m_grad[7] * m_grad[5] - m_grad[4] * m_grad[5]) +
203  m_grad[1] * (m_grad[3] * m_grad[8] - m_grad[5] * m_grad[5]) +
204  m_grad[2] * (m_grad[4] * m_grad[5] - m_grad[3] * m_grad[7]);
205  sk[2] = m_grad[0] * (m_grad[4] * m_grad[7] - m_grad[6] * m_grad[5]) +
206  m_grad[1] * (m_grad[4] * m_grad[5] - m_grad[3] * m_grad[7]) +
207  m_grad[2] * (m_grad[3] * m_grad[6] - m_grad[4] * m_grad[4]);
208 
209  sk[0] /= det * -1.0;
210  sk[1] /= det * -1.0;
211  sk[2] /= det * -1.0;
212 
213  bool found = false;
214 
215  NekDouble pg =
216  (m_grad[0] * sk[0] + m_grad[1] * sk[1] + m_grad[2] * sk[2]);
217 
218  // normal gradient line Search
219  NekDouble alpha = 1.0;
220 
221  while (alpha > alphaTol())
222  {
223  // Update node
224  m_node->m_x = xc + alpha * sk[0];
225  m_node->m_y = yc + alpha * sk[1];
226  m_node->m_z = zc + alpha * sk[2];
227 
228  newVal = GetFunctional<3>(minJacNew, false);
229  // dont need the hessian again this function updates G to be the new
230  // location
231  //
232  // Wolfe conditions
233  if (newVal <= currentW + c1() * alpha * pg)
234  {
235  found = true;
236  break;
237  }
238 
239  alpha /= 2.0;
240  }
241 
242  if (!found)
243  {
244  m_node->m_x = xc;
245  m_node->m_y = yc;
246  m_node->m_z = zc;
247 
248  mtx.lock();
249  m_res->nReset[2]++;
250  mtx.unlock();
251  }
252  else
253  {
254  m_minJac = minJacNew;
255 
256  mtx.lock();
257  if (alpha < 1.0)
258  {
259  m_res->alphaI++;
260  }
261  mtx.unlock();
262  }
263 
264  mtx.lock();
265  m_res->val = max(sqrt((m_node->m_x - xc) * (m_node->m_x - xc) +
266  (m_node->m_y - yc) * (m_node->m_y - yc) +
267  (m_node->m_z - zc) * (m_node->m_z - zc)),
268  m_res->val);
269  mtx.unlock();
270  }
271  mtx.lock();
272  m_res->func += newVal;
273  mtx.unlock();
274 }
static NekDouble alphaTol()
Definition: NodeOpti.h:129
Array< OneD, NekDouble > m_grad
Definition: NodeOpti.h:109
static NekDouble c1()
Definition: NodeOpti.h:121
double NekDouble
ResidualSharedPtr m_res
Definition: NodeOpti.h:117
static NekDouble gradTol()
Definition: NodeOpti.h:125

Member Data Documentation

int Nektar::Utilities::NodeOpti3D3D::m_type
static
Initial value:

Definition at line 159 of file NodeOpti.h.