MeshKit  1.0
Deform2D.cpp
Go to the documentation of this file.
00001 #include "Deform2D.hpp"
00002 #include <iostream>
00003 #include <math.h>
00004 #include <map>
00005 
00006 
00007 extern "C" void openblas_set_num_threads(int);
00008 
00009 
00010 
00011 namespace MeshKit {
00012 
00013 Deform2D::Deform2D(vector<vector<double> > undeformed_cage_vertices, vector<vector<double> > deformed_cage_vertices)
00014 {
00015     num_vertices = undeformed_cage_vertices.size();
00016     //pass the data
00017         un_cage_vertices.insert(un_cage_vertices.begin(), undeformed_cage_vertices.begin(), undeformed_cage_vertices.end());
00018         cage_vertices.insert(cage_vertices.begin(), deformed_cage_vertices.begin(), deformed_cage_vertices.end());
00019 }
00020 
00021 void Deform2D::SetupInteriorNodes(vector<vector<double> > undeformed_in_nodes)
00022 {
00023     num_interior = undeformed_in_nodes.size();
00024     
00025     un_InnerNodes.insert(un_InnerNodes.begin(), undeformed_in_nodes.begin(), undeformed_in_nodes.end());
00026         InnerNodes.insert(InnerNodes.begin(), undeformed_in_nodes.begin(), undeformed_in_nodes.end());    
00027 }
00028 void Deform2D::GetInteriorNodes(vector<vector<double> > &final_locations)
00029 {
00030    /*
00031    for (unsigned int i = 0; i < InnerNodes.size(); i++){
00032         for (unsigned int j = 0; j < InnerNodes[i].size(); j++){
00033             final_locations[i][j] = InnerNodes[i][j];
00034         }
00035    }
00036    */
00037    final_locations.clear();
00038    final_locations.insert(final_locations.begin(), InnerNodes.begin(), InnerNodes.end());
00039 }
00040 
00041 void Deform2D::Execute()
00042 {
00043     const unsigned int vertex_size = un_cage_vertices.size();
00044     const unsigned int tmp_var = vertex_size + 3;
00045     
00046     mat A = zeros<mat>(vertex_size+3,vertex_size+3);
00047     //mat::fixed<tmp_var,tmp_var> A;
00048     //A.zeros();
00049     /**************************/
00050     /*      |   G       H |      */
00051     /*  A = |             |      */                            
00052     /*      |   H'      0 |      */                            
00053     /*****************************/
00054     //Assign H and H'
00055     for (unsigned int j = 0; j < vertex_size; j++){
00056                 A(j,vertex_size) = 1.0;
00057                     A(j,vertex_size+1) = un_cage_vertices[j][0];
00058                 A(j,vertex_size+2) = un_cage_vertices[j][1];
00059                 A(vertex_size,j) = 1.0;
00060                 A(vertex_size+1,j) = un_cage_vertices[j][0];
00061                 A(vertex_size+2,j) = un_cage_vertices[j][1];
00062     }
00063         
00064     //assign G
00065     for (unsigned int i = 0; i < vertex_size; i++){
00066                 for (unsigned int j = 0; j < vertex_size; j++){
00067                         A(i,j) = TriHarmonicFun(un_cage_vertices[i], un_cage_vertices[j]);
00068                 }
00069     }
00070     //done with the big matrix A
00071     //set up the displacement in x direction
00072     mat b=zeros<mat>(vertex_size+3,2);
00073     
00074     for (unsigned int i = 0; i < vertex_size; i++)
00075                 b(i,0) = cage_vertices[i][0] - un_cage_vertices[i][0];
00076     //set up the displacement in y direction
00077     for (unsigned int i = 0; i < vertex_size; i++)
00078                 b(i,1) = cage_vertices[i][1] - un_cage_vertices[i][1];
00079 
00080     std::cout << "Matrix size is " << vertex_size+3 << "*" << vertex_size+3 << "\n";
00081     openblas_set_num_threads(1);
00082     mat coeffs = solve(A,b);
00083 
00084     //compute the displacement in x and y direction for interior nodes
00085     for (unsigned int i = 0; i < num_interior; i++){
00086                 InnerNodes[i][0] = un_InnerNodes[i][0] + InterpolatedFun(un_InnerNodes[i], coeffs.col(0));
00087                 InnerNodes[i][1] = un_InnerNodes[i][1] + InterpolatedFun(un_InnerNodes[i], coeffs.col(1));
00088     }
00089     
00090 }
00091 
00092 double Deform2D::InterpolatedFun(vector<double> x, vec coeffs)
00093 {
00094     double tmp = 0.0;
00095     double tmp_variable[3] = {1.0, x[0], x[1]};
00096     for (unsigned int i = 0; i < num_vertices; i++)
00097             tmp += coeffs(i,0)*TriHarmonicFun(x, un_cage_vertices[i]);
00098     for (int i = 0; i < 3; i++)
00099             tmp += coeffs(num_vertices+i,0)*tmp_variable[i];
00100 
00101     return tmp;
00102 }
00103 
00104 double Deform2D::TriHarmonicFun(vector<double> xi, vector<double> xj)
00105 {
00106     double value = 0.0;
00107     double delta = sqrt(pow((xi[0] - xj[0]),2) + pow((xi[1] - xj[1]),2));
00108     value = delta*delta*log10(delta);
00109     return value;
00110 }
00111 
00112 Deform2D::~Deform2D()
00113 {
00114         cout << "It is over now in computing 2D deformation" << endl;
00115 }
00116 
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines