24 #ifndef CCORRELATION_OPTICALFLOW_FEM_GRADIENT
25 #define CCORRELATION_OPTICALFLOW_FEM_GRADIENT
42 template<
typename T,
typename Timg>
54 this->class_name =
"Correlation : Optical Flow Finite Element Method using Gradient strategy";
58 virtual void init(CParameterNetCDF &fp)
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";}
71 attribute_name =
"iter_max";
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";}
78 virtual void assignG(
const Cmesh<T,Timg> &oMesh, CImgList<T> &K, CImgList<T> &Ke)
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);
86 virtual void tensors(
const int &thread,
const CImgList<T> &Ve,
const T &residue, CImgList<T> &Ke)
89 cimg_forYZ(Ke[0],modi,dim)
91 Ke[0](0, modi,dim,thread) += Ve[dim][modi] * residue;
96 virtual void assembly(
const int &thread,
const Cmesh<T,Timg> &oMesh,
const int &elem,
const CImgList<T> &Ke, CImgList<T> &K)
99 cimg_forYZ(Ke[0], modi,dim)
103 K[0][oMesh.m_connect[elem][modi]*Ke[0].depth()+dim] += Ke[0](0,modi,dim,thread);
110 virtual void solve(CImgList<T> &K,
const Cmesh<T,Timg> &oMesh, CImgList<T> &solution)
113 double norme = std::sqrt((K[0].get_sqr()).sum())/K[0].height();
115 for (
int node=0; node<oMesh.m_node[0].size(); node++)
117 for (
int dim=0; dim<oMesh.num_var(); dim++)
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]);
125 virtual void test(
const CImgList<T> &solution,
const double &epsilon,
Cfield<T,Timg> &oField, T &previous_res,
int &iter,
int &converged)
128 if (std::abs(oField.m_meanRes.back()-previous_res) >= epsilon and iter<m_iter_max)
131 if (oField.m_meanRes.back()<=previous_res)
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";}
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";
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: Ccorrelation_opticalFlow_fem_gradient.h:43
Definition: Ccorrelation_opticalFlow_fem.h:43