// Choose an initial solution, and lock two vertices
void MeshPara::init_slover() 
{
	// Get bbox
	Vec3f bAxis = bbMax - bbMin;

	// Get the Projection dirction
	int d1 ,d2, d3, i;
	d1 = d2 = d3 = 0;
	for (i = 1; i < 3; i++)
	{
		if (bAxis[i] > bAxis[d1])
			d1 = i;
		if (bAxis[i] < bAxis[d3])
			d3 = i;
	}
	for (d2 = 0; d2 < 3; d2++)
	{
		if (d2 != d1 && d2 != d3)
			break;
	}

	// Project vertices
	auto v_end(mesh_.vertices_end());
	float u1 = -1.0e30, u2 = 1.0e30;
	int lock1 = 0, lock2 = 0;
	for (auto v_it = mesh_.vertices_begin(); v_it != v_end; ++v_it)
	{
		float u = mesh_.point(*v_it)[d1];
		float v = mesh_.point(*v_it)[d2];
		int idx =  (*v_it).idx();
		mesh_.set_texcoord2D(*v_it, Vec2f(u, v));

		// set initial solution
		nlSetVariable(2 * idx, u);
		nlSetVariable(2 * idx + 1, v);

		if (u > u1) 
		{
			lock1 = idx;
			u1 = u;
		}
		if (u < u2)
		{
			lock2 = idx;
			u2 = u;
		}
	}

	// set locked variables
	nlLockVariable(2 * lock1);
	nlLockVariable(2 * lock1 + 1);
	nlLockVariable(2 * lock2);
	nlLockVariable(2 * lock2 + 1);
}
Ejemplo n.º 2
0
void leastSquaresSystem::solve(double *vs)
{
 int i;
 Node *n;
 coeffIndexPair *f;

 nlNewContext();
 nlSolverParameteri(NL_SOLVER, NL_PERM_SUPERLU_EXT);
 nlSolverParameteri(NL_NB_VARIABLES, num_variables);
 nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE) ;
 nlSolverParameteri(NL_MAX_ITERATIONS, 1000) ;
 nlSolverParameterd(NL_THRESHOLD, 1e-10) ;

 nlBegin(NL_SYSTEM);

 for (i=0; i<num_variables; i++)
 {
  nlSetVariable(i, vs[i]);
  if (locks[i]) nlLockVariable(i);
 }

 nlBegin(NL_MATRIX);

 for (i=0; i<num_equations; i++)
 {
  nlRowParameterd(NL_RIGHT_HAND_SIDE, known_term[0][i]);
  nlBegin(NL_ROW);
  for (n=rows[i].cips.head(); n!=NULL; n=n->next())
  {
   f = (coeffIndexPair *)n->data;
   nlCoefficient(f->index, f->coeff);
  }  
  nlEnd(NL_ROW);
 }

 nlEnd(NL_MATRIX);
 nlEnd(NL_SYSTEM);
 nlSolve();

 for (i=0; i<num_variables; i++) vs[i] = nlGetVariable(i);

 nlDeleteContext(nlGetCurrent());
}
Ejemplo n.º 3
0
void sparse3System::solve(double *vs)
{
 int i, j;
 Node *n;
 coeffIndexPair *f;

 for (j=0; j<3; j++)
 {
  nlNewContext();
  nlSolverParameteri(NL_SOLVER, NL_PERM_SUPERLU_EXT);
  nlSolverParameteri(NL_NB_VARIABLES, num_variables);
  nlBegin(NL_SYSTEM);

  for (i=0; i<num_variables; i++)
  {
   nlSetVariable(i, vs[i*3 + j]);
   if (locks[i]) nlLockVariable(i);
  }

  nlBegin(NL_MATRIX);

  for (i=0; i<num_equations; i++)
  {
   nlRowParameterd(NL_RIGHT_HAND_SIDE, known_term[j][i]);
   nlBegin(NL_ROW);
   for (n=rows[i].cips.head(); n!=NULL; n=n->next())
   {
    f = (coeffIndexPair *)n->data;
    nlCoefficient(f->index, f->coeff);
   }  
   nlEnd(NL_ROW);
  }

  nlEnd(NL_MATRIX);
  nlEnd(NL_SYSTEM);
  nlSolve();

  for (i=0; i<num_variables; i++) vs[i*3 + j] = nlGetVariable(i);

  nlDeleteContext(nlGetCurrent());
 }
}
Ejemplo n.º 4
0
void laplacian_begin_solve(LaplacianSystem *sys, int index)
{
	int a;

	if (!sys->nlbegun) {
		nlBegin(NL_SYSTEM);

		if(index >= 0) {
			for(a=0; a<sys->totvert; a++) {
				if(sys->vpinned[a]) {
					nlSetVariable(0, a, sys->verts[a][index]);
					nlLockVariable(a);
				}
			}
		}

		nlBegin(NL_MATRIX);
		sys->nlbegun = 1;
	}
}