YaDICs  V04.14.a
Yet another Digital Image Correlation software: platform dedicated to 2/3D Fluid and Solid kinematics field measurements.
 All Classes Files Functions Variables Pages
Ccorrelation_opticalFlow_fem_gradient.h
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (C) 2012, The YaDICs Project Developers.
3  * See the COPYRIGHT file at the top-level directory of this distribution ./COPYRIGHT.
4  * See ./COPYING file for copying and redistribution conditions.
5  *
6  * This file is part of YaDICs.
7  * YaDICs is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * YaDICs is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with YaDICs. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Information about how to use the software are provided at http://yadic.univ-lille1.fr/
21  **********************************************************************/
22 
23 
24 #ifndef CCORRELATION_OPTICALFLOW_FEM_GRADIENT
25 #define CCORRELATION_OPTICALFLOW_FEM_GRADIENT
26 
27 
39 
40 
41 
42 template<typename T,typename Timg>
44 {
45 
46  public:
47 
48  double m_alpha;
49  int m_iter_max;
50 
52  {// constructor
53 
54  this->class_name = "Correlation : Optical Flow Finite Element Method using Gradient strategy";
55 
56  }
57 
58  virtual void init(CParameterNetCDF &fp)
59  {// init from parameter file
60 
66 
67  std::string attribute_name = "alpha0";
68  int error = fp.loadAttribute(attribute_name,m_alpha);
69  if (this->m_verbose){std::cout<<"\t\t initial coefficient -> "<<m_alpha<<"\n";}
70 
71  attribute_name = "iter_max";
72  m_iter_max = 100;
73  error = fp.loadAttribute(attribute_name,m_iter_max);
74  if (this->m_verbose){std::cout<<"\t\t max number of iteration -> "<<m_iter_max<<"\n";}
75 
76  }
77 
78  virtual void assignG(const Cmesh<T,Timg> &oMesh, CImgList<T> &K, CImgList<T> &Ke)
79  {//assign approriate size for Ke and Fe tensors
80 
81  K.assign(1,1,oMesh.num_node()*oMesh.num_var(),1,1, 0);
82  Ke.assign(1,1,oMesh.num_mod(),oMesh.num_var(),this->m_threadNB, 0);
83 
84  }
85 
86  virtual void tensors(const int &thread, const CImgList<T> &Ve, const T &residue, CImgList<T> &Ke)
87  {//eval stiffness matrix & force vector at element
88 
89  cimg_forYZ(Ke[0],modi,dim)
90  {//for every modes or nodes
91  Ke[0](0, modi,dim,thread) += Ve[dim][modi] * residue;//Fe
92  }
93 
94  }
95 
96  virtual void assembly(const int &thread, const Cmesh<T,Timg> &oMesh, const int &elem, const CImgList<T> &Ke, CImgList<T> &K)
97  {//perform the assembly of K and F
98 
99  cimg_forYZ(Ke[0], modi,dim)
100  {
101  #pragma omp critical
102  {
103  K[0][oMesh.m_connect[elem][modi]*Ke[0].depth()+dim] += Ke[0](0,modi,dim,thread);
104  }
105 
106  }
107 
108  }
109 
110  virtual void solve(CImgList<T> &K, const Cmesh<T,Timg> &oMesh, CImgList<T> &solution)
111  {// K.U = F
112 
113  double norme = std::sqrt((K[0].get_sqr()).sum())/K[0].height();
114 
115  for (int node=0; node<oMesh.m_node[0].size(); node++)
116  {//put solution vector in oField.m_mode[dim][node] framework
117  for (int dim=0; dim<oMesh.num_var(); dim++)
118  {
119  solution[dim][node] += m_alpha*K[0][node*oMesh.num_var()+dim]/(norme*oMesh.m_win[0]*oMesh.m_win[1]*oMesh.m_win[2]);
120  }
121  }
122 
123  }
124 
125  virtual void test(const CImgList<T> &solution, const double &epsilon, Cfield<T,Timg> &oField, T &previous_res, int &iter, int &converged)
126  {//convergency test
127 
128  if (std::abs(oField.m_meanRes.back()-previous_res) >= epsilon and iter<m_iter_max)
129  {
130 
131  if (oField.m_meanRes.back()<=previous_res)
132  {
133  m_alpha*=1.15;
134  }
135  else
136  {
137  m_alpha*=-0.5;
138  }
139 
140  iter++;
141  previous_res = oField.m_meanRes.back();
142  oField.m_mode = solution;
143  if(this->m_verbose){std::cout<<"(iter "<<iter<<") (alpha "<<m_alpha<<"): "<<oField.m_meanRes.back()<<" \%\n\n";}
144 
145  }
146  else
147  {
148  converged = 1;
149  if (oField.m_meanRes.back()>previous_res){printf("Warning : last step has diverged\n");}
150  else{printf("Last step has converged\n");}
151  oField.m_meanRes.back() = previous_res;
152  std::cout<<this->class_name.c_str()<<" -> residue ("<<iter<<" iter) : "<<previous_res<<" \%\n";
153  }
154 
155  }
156 
157 
158 
159 };
160 
161 #endif
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_fem.h:55
It implements optical flow strategy for FEM method.
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_fem_gradient.h:58
Definition: Cmesh.h:61
Definition: Cfield.h:51
Definition: Ccorrelation_opticalFlow_fem_gradient.h:43
Definition: Ccorrelation_opticalFlow_fem.h:43