Ejemplo n.º 1
0
void BGMBase::export_tensor_as_vectors(
  const std::string &filename, const TensorStorageType &_whatToPrint) const
{
  FILE *f = Fopen(filename.c_str(), "w");
  if(!f) {
    Msg::Error("Could not open file '%s'", filename.c_str());
    return;
  }

  fprintf(f, "View \"Background Mesh\"{\n");

  TensorStorageType::const_iterator it = _whatToPrint.begin();
  const char *s = "VP";

  for(; it != _whatToPrint.end(); it++) { // for all vertices
    GPoint p = get_GPoint_from_MVertex(it->first);
    for(int i = 0; i < 3; i++) {
      fprintf(f, "%s(%g,%g,%g){%g,%g,%g};\n", s, p.x(), p.y(), p.z(),
              (it->second)(0, i), (it->second)(1, i), (it->second)(2, i));
      fprintf(f, "%s(%g,%g,%g){%g,%g,%g};\n", s, p.x(), p.y(), p.z(),
              -(it->second)(0, i), -(it->second)(1, i), -(it->second)(2, i));
    }
  }
  fprintf(f, "};\n");
  fclose(f);
}
Ejemplo n.º 2
0
void frameFieldBackgroundMesh2D::exportCrossField(const std::string &filename)
{
    FILE *f = Fopen(filename.c_str(), "w");
    if(!f) {
        Msg::Error("Could not open file '%s'", filename.c_str());
        return;
    }
    fprintf(f,"View \"Cross Field\"{\n");
    std::vector<double> deltas(2);
    deltas[0] = 0.;
    deltas[1] = M_PI;

    for (std::vector<MVertex*>::iterator it = beginvertices(); it!=endvertices(); it++) {
        MVertex *v = *it;
        double angle_current = angle(v);
        GPoint p = get_GPoint_from_MVertex(v);
        for (int i=0; i<2; i++) {
            Pair<SVector3, SVector3> dirs = compute_crossfield_directions(v->x(),v->y(),angle_current+deltas[i]);
            fprintf(f,"VP(%g,%g,%g) {%g,%g,%g};\n",p.x(),p.y(),p.z(),dirs.first()[0], dirs.first()[1], dirs.first()[2]);
            fprintf(f,"VP(%g,%g,%g) {%g,%g,%g};\n",p.x(),p.y(),p.z(),dirs.second()[0], dirs.second()[1], dirs.second()[2]);
        }
    }
    fprintf(f,"};\n");
    fclose(f);
}
Ejemplo n.º 3
0
void BGMBase::export_vector(const std::string &filename,
                            const VectorStorageType &_whatToPrint) const
{
  FILE *f = Fopen(filename.c_str(), "w");
  if(!f) {
    Msg::Error("Could not open file '%s'", filename.c_str());
    return;
  }

  fprintf(f, "View \"Background Mesh\"{\n");

  const MElement *elem;
  int nvertex;
  int type;

  for(unsigned int i = 0; i < getNumMeshElements(); i++) {
    elem = getElement(i);
    nvertex = elem->getNumVertices();
    type = elem->getType();
    const char *s = 0;
    switch(type) {
    case TYPE_PNT: s = "VP"; break;
    case TYPE_LIN: s = "VL"; break;
    case TYPE_TRI: s = "VT"; break;
    case TYPE_QUA: s = "VQ"; break;
    case TYPE_TET: s = "VS"; break;
    case TYPE_HEX: s = "VH"; break;
    case TYPE_PRI: s = "VI"; break;
    case TYPE_PYR: s = "VY"; break;
    default: throw;
    }

    fprintf(f, "%s(", s);
    const MVertex *v;
    std::vector<double> values(nvertex * 3);
    for(int iv = 0; iv < nvertex; iv++) {
      v = elem->getVertex(iv);
      std::vector<double> temp = get_nodal_value(v, _whatToPrint);
      for(int j = 0; j < 3; j++) values[iv * 3 + j] = temp[j];
      GPoint p = get_GPoint_from_MVertex(v);
      fprintf(f, "%g,%g,%g", p.x(), p.y(), p.z());
      if(iv != nvertex - 1)
        fprintf(f, ",");
      else
        fprintf(f, "){");
    }
    for(int iv = 0; iv < nvertex; iv++) {
      for(int j = 0; j < 3; j++) {
        fprintf(f, "%g", values[iv * 3 + j]);
        if(!((iv == nvertex - 1) && (j == 2)))
          fprintf(f, ",");
        else
          fprintf(f, "};\n");
      }
    }
  }
  fprintf(f, "};\n");
  fclose(f);
}
Ejemplo n.º 4
0
void BGMBase::export_scalar(const std::string &filename,
                            const DoubleStorageType &_whatToPrint) const
{
  FILE *f = Fopen(filename.c_str(), "w");
  if(!f) {
    Msg::Error("Could not open file '%s'", filename.c_str());
    return;
  }

  fprintf(f, "View \"Background Mesh\"{\n");

  const MElement *elem;
  int nvertex;
  int type;

  for(unsigned int i = 0; i < getNumMeshElements(); i++) {
    elem = getElement(i);
    nvertex = elem->getNumVertices();
    type = elem->getType();
    const char *s = 0;
    switch(type) {
    case TYPE_PNT: s = "SP"; break;
    case TYPE_LIN: s = "SL"; break;
    case TYPE_TRI: s = "ST"; break;
    case TYPE_QUA: s = "SQ"; break;
    case TYPE_TET: s = "SS"; break;
    case TYPE_HEX: s = "SH"; break;
    case TYPE_PRI: s = "SI"; break;
    case TYPE_PYR: s = "SY"; break;
    default: throw;
    }

    fprintf(f, "%s(", s);
    const MVertex *v;
    std::vector<double> values(nvertex);
    for(int iv = 0; iv < nvertex; iv++) {
      v = elem->getVertex(iv);
      values[iv] = get_nodal_value(v, _whatToPrint);
      // GPoint p = gf->point(SPoint2(v->x(),v->y()));
      GPoint p = get_GPoint_from_MVertex(v);
      fprintf(f, "%g,%g,%g", p.x(), p.y(), p.z());
      if(iv != nvertex - 1)
        fprintf(f, ",");
      else
        fprintf(f, "){");
    }
    for(int iv = 0; iv < nvertex; iv++) {
      fprintf(f, "%g", values[iv]);
      if(iv != nvertex - 1)
        fprintf(f, ",");
      else
        fprintf(f, "};\n");
    }
  }
  fprintf(f, "};\n");
  fclose(f);
}