Exemple #1
0
void PCAMethod(Matriz& matriz, Matriz& res, Matriz& m_ortonormal, int alfa, std::ofstream& filewrite){
  int n = matriz.dimensionFilas();
  int m = matriz.dimensionColumnas();

  Matriz X(n, m);
  calcular_matriz_X(matriz, X);

  Matriz Xt(m, n);
  X.trasponer(Xt);

  Matriz m_covarianza(m, m); //revisar dimensiones

  std::cout << "antes de entrar a multiplicar" << std::endl;
  Xt.multiplicarMatrices(X, m_covarianza); //crear matriz covarianza
  std::cout << "after" << std::endl;

  /* Reducción de la dimensión */
  calcular_base_ortonormal(m_covarianza, m_ortonormal, alfa); //deja en matriz_ortonormal una matriz de alfa filas

  /* Transformación característica */
  Matriz m_ortonormal_traspuesta(m, alfa);
  m_ortonormal.trasponer(m_ortonormal_traspuesta);

  /* Transformación característica */
  matriz.multiplicarMatrices(m_ortonormal_traspuesta, res); // Chequear esto en caso de que no ande
}
Exemple #2
0
void Foam::RBD::joints::Py::jcalc
(
    joint::XSvc& J,
    const rigidBodyModelState& state
) const
{
    J.X = Xt(S_[0].l()*state.q()[qIndex_]);
    J.S1 = S_[0];
    J.v = S_[0]*state.qDot()[qIndex_];
    J.c = Zero;
}
Exemple #3
0
void Foam::RBD::joints::Pz::jcalc
(
    joint::XSvc& J,
    const scalarField& q,
    const scalarField& qDot
) const
{
    J.X = Xt(S_[0].l()*q[qIndex_]);
    J.S1 = S_[0];
    J.v = S_[0]*qDot[qIndex_];
    J.c = Zero;
}
// points1, points2,
void computeRot(vector<double>& template_vextex, vector<double>& vertex,
    vector<vector<double> >& template_nbor_vertices, vector<vector<double > >& nbor_vertices,
    vector<unsigned int>& neighbors, vector<double>& weights,
    vector<double>& output_rot, bool deform)
{
    int num_neighbors = neighbors.size();
    MatrixXd Xt(3, num_neighbors), X(3, num_neighbors);
    for(int i = 0; i < num_neighbors; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            Xt(j,i) = weights[i] * (
                template_vextex[j] - template_nbor_vertices[ neighbors[i] ][j]);

            X(j,i) = weights[i] * (
                vertex[j] - nbor_vertices[ neighbors[i] ][j]);
            
            if(deform)
            X(j,i) += Xt(j,i);
        }
    }

    Eigen::Matrix3d sigma = Xt * X.transpose();
    Eigen::JacobiSVD<Eigen::Matrix3d> svd(sigma, Eigen::ComputeFullU | Eigen::ComputeFullV);
    Eigen::Matrix3d Rot;

    if(svd.matrixU().determinant()*svd.matrixV().determinant() < 0.0) {
        Eigen::Vector3d S = Eigen::Vector3d::Ones(); S(2) = -1.0;
        Rot = svd.matrixV()*S.asDiagonal()*svd.matrixU().transpose();
    } else {
        Rot = svd.matrixV()*svd.matrixU().transpose();
    }

    // ceres::RotationMatrixToAngleAxis(&Rot(0, 0), &output_rot[0]);

    Eigen::AngleAxisd angleAxis(Rot);
    for(int i = 0; i < 3; ++i)
    output_rot[i] = angleAxis.axis()[i] * angleAxis.angle();

}
Exemple #5
0
bool SIMoutput::writeGlvS2 (const Vector& psol, int iStep, int& nBlock,
                            double time, int idBlock, int psolComps)
{
  if (psol.empty())
    return true; // No primary solution
  else if (!myVtf || !myProblem)
    return false;
  else if (myProblem->getNoSolutions() < 1)
    return true; // No patch-level primary solution

  size_t nf = myProblem->getNoFields(2);
  if (nf < 1) return true; // No secondary solution

  bool haveAsol = false;
  if (mySol)
  {
    if (this->getNoFields() == 1)
      haveAsol = mySol->hasScalarSol() > 1;
    else
      haveAsol = mySol->hasVectorSol() > 1;
  }

  bool doProject = (opt.discretization == ASM::Spline ||
                    opt.discretization == ASM::SplineC1) &&
    opt.project.find(SIMoptions::GLOBAL) != opt.project.end();

  size_t sMAX = nf;
  if (haveAsol) sMAX += nf;
  if (doProject) sMAX += nf;
  std::vector<IntVec> sID(sMAX);
  std::array<IntVec,2> vID;
  Matrix field, pdir;
  Vector lovec;

  size_t i, j, k;
  int geomID = myGeomID;
  for (i = 0; i < myModel.size(); i++)
  {
    if (myModel[i]->empty()) continue; // skip empty patches

    if (msgLevel > 1)
      IFEM::cout <<"Writing secondary solution for patch "<< i+1 << std::endl;

    // Direct evaluation of secondary solution variables

    LocalSystem::patch = i;
    myProblem->initResultPoints(time,true);
    myModel[i]->extractNodeVec(psol,myProblem->getSolution(),psolComps,0);
    this->extractPatchDependencies(myProblem,myModel,i);
    this->setPatchMaterial(i+1);
    if (!myModel[i]->evalSolution(field,*myProblem,opt.nViz))
      return false;

    myModel[i]->filterResults(field,myVtf->getBlock(++geomID));

    for (j = 1, k = 0; j <= field.rows() && k < sMAX; j++)
      if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID))
        return false;
      else
        sID[k++].push_back(nBlock);

    // Write principal directions, if any, as vector fields

    size_t nPoints = field.cols();
    for (j = 0; j < 2 && myProblem->getPrincipalDir(pdir,nPoints,j+1); j++)
    {
      myModel[i]->filterResults(pdir,myVtf->getBlock(geomID));
      if (!myVtf->writeVres(pdir,++nBlock,geomID,this->getNoSpaceDim()))
        return -2;
      else
        vID[j].push_back(nBlock);
    }

    if (doProject)
    {
      // Projection of secondary solution variables (tensorial splines only)

      myProblem->initResultPoints(time);
      if (!myModel[i]->evalSolution(field,*myProblem,opt.nViz,'D'))
        return false;

      myModel[i]->filterResults(field,myVtf->getBlock(geomID));

      for (j = 1; j <= field.rows() && k < sMAX; j++)
        if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID))
          return false;
        else
          sID[k++].push_back(nBlock);
    }

    if (haveAsol)
    {
      // Evaluate analytical solution variables

      if (msgLevel > 1)
        IFEM::cout <<"Writing exact solution for patch "<< i+1 << std::endl;

      const ElementBlock* grid = myVtf->getBlock(geomID);
      Vec3Vec::const_iterator cit = grid->begin_XYZ();
      field.fill(0.0);
      for (j = 1; cit != grid->end_XYZ() && haveAsol; j++, cit++)
      {
        Vec4 Xt(*cit,time);
        if (mySol->hasScalarSol() == 3 || mySol->hasVectorSol() == 3)
          haveAsol = myProblem->evalSol(lovec,*mySol->getStressSol(),Xt);
        else if (this->getNoFields() == 1)
          haveAsol = myProblem->evalSol(lovec,*mySol->getScalarSecSol(),Xt);
        else
          haveAsol = myProblem->evalSol(lovec,*mySol->getVectorSecSol(),Xt);
        if (haveAsol)
          field.fillColumn(j,lovec);
      }

      for (j = 1; j <= field.rows() && k < sMAX && haveAsol; j++)
        if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID))
          return false;
        else
          sID[k++].push_back(nBlock);
    }
  }

  // Write result block identifications

  std::string vname("Principal direction P1");
  for (i = 0; i < 2; i++, vname[vname.size()-1]++)
    if (!vID[i].empty())
      if (!myVtf->writeVblk(vID[i],vname.c_str(),idBlock+i,iStep))
        return false;

  const char* prefix = haveAsol ? "FE" : nullptr;
  for (i = j = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++)
    if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,prefix).c_str(),
                          idBlock++,iStep)) return false;

  if (doProject)
    for (i = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++)
      if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,"Projected").c_str(),
                            idBlock++,iStep)) return false;

  if (haveAsol)
    for (i = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++)
      if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,"Exact").c_str(),
                            idBlock++,iStep)) return false;

  return true;
}