static void parseVELFPVELOCFile(const QString&datFileName, Mesh* mesh) {
    // these files are optional, so if not present, reading is skipped
    int nnodes = mesh->nodes().size();
    QFileInfo fi(datFileName);
    QVector<float> maxVel(nnodes);

    {
        QString nodesFileName(fi.dir().filePath("VELFP.OUT"));
        QFile nodesFile(nodesFileName);
        if (!nodesFile.open(QIODevice::ReadOnly | QIODevice::Text)) return;
        QTextStream nodesStream(&nodesFile);
        int node_inx = 0;

        // VELFP.OUT - COORDINATES (NODE NUM, X, Y, MAX VEL) - Maximum floodplain flow velocity;
        while (!nodesStream.atEnd())
        {
            if (node_inx == nnodes) throw LoadStatus::Err_IncompatibleMesh;

            QString line = nodesStream.readLine();
            QStringList lineParts = line.split(" ", QString::SkipEmptyParts);
            if (lineParts.size() != 4) {
                throw LoadStatus::Err_UnknownFormat;
            }

            float val = getFloat(lineParts[3]);
            maxVel[node_inx] = val;

            node_inx++;
        }
    }

    {
        QString nodesFileName(fi.dir().filePath("VELOC.OUT"));
        QFile nodesFile(nodesFileName);
        if (!nodesFile.open(QIODevice::ReadOnly | QIODevice::Text)) return;
        QTextStream nodesStream(&nodesFile);
        int node_inx = 0;

        // VELOC.OUT - COORDINATES (NODE NUM, X, Y, MAX VEL)  - Maximum channel flow velocity
        while (!nodesStream.atEnd())
        {
            if (node_inx == nnodes) throw LoadStatus::Err_IncompatibleMesh;

            QString line = nodesStream.readLine();
            QStringList lineParts = line.split(" ", QString::SkipEmptyParts);
            if (lineParts.size() != 4) {
                throw LoadStatus::Err_UnknownFormat;
            }

            float val = getFloat(lineParts[3]);
            if (!is_nodata(val)) { // overwrite value from VELFP if it is not 0
                maxVel[node_inx] = val;
            }

            node_inx++;
        }
    }

    addStaticDataset(maxVel, "Velocity/Maximums", DataSet::Scalar, datFileName, mesh);
}
Ejemplo n.º 2
0
// Will be called from subclasses, as is virtual function
//----------------------------------------------------------------------------------------------------------------------  
void Muscle::toXml(ci::XmlTree& muscle)
{
  // XMLTree muscle provided by subclass   //ci::XmlTree muscle("Muscle", "");
  muscle.setAttribute("Name", getName());
  muscle.setAttribute("IsFlexor", isFlexor());
  muscle.setAttribute("IsMono", isMonoArticulate());
    
  ci::XmlTree attach("Attachment",""); 
  attach.setAttribute("Origin", getOrigin()); 
  attach.setAttribute("Insertion", getInsertion());   
  muscle.push_back(attach);
  
  double Fmax = getForceMax();
  ci::XmlTree maxForce("MaxIsoForce", toString(Fmax));
  muscle.push_back(maxForce);
  
  double Vmax = getVelocityMax();
  ci::XmlTree maxVel("MaxVelocity", toString(Vmax));
  muscle.push_back(maxVel);  
  
  ci::XmlTree length("Length",""); 
  length.setAttribute("Optimal", getOptimalLength()); 
  length.setAttribute("Min", m_lengthMin); 
  length.setAttribute("Max", m_lengthMax); 
  muscle.push_back(length);
  
  ci::XmlTree hillParams("HillParameters",""); 
  hillParams.setAttribute("Shortening", m_hillSh); 
  hillParams.setAttribute("Lengthening", m_hillLn); 
  hillParams.setAttribute("Asymptote", m_hillMax); 
  hillParams.setAttribute("Slope", m_hillSlope); 
  muscle.push_back(hillParams);
}
Ejemplo n.º 3
0
void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName )
{
  // these files are optional, so if not present, reading is skipped
  size_t nVertices = mMesh->verticesCount();
  std::vector<double> maxVel( nVertices );

  {
    std::string velocityFile( fileNameFromDir( datFileName, "VELFP.OUT" ) );
    if ( !MDAL::fileExists( velocityFile ) )
    {
      return; //optional file
    }

    std::ifstream velocityStream( velocityFile, std::ifstream::in );
    std::string line;

    size_t vertex_idx = 0;

    // VELFP.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL) - Maximum floodplain flow velocity;
    while ( std::getline( velocityStream, line ) )
    {
      if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh;

      line = MDAL::rtrim( line );
      std::vector<std::string> lineParts = MDAL::split( line, ' ' );
      if ( lineParts.size() != 4 )
      {
        throw MDAL_Status::Err_UnknownFormat;
      }

      double val = getDouble( lineParts[3] );
      maxVel[vertex_idx] = val;

      vertex_idx++;
    }
  }

  {
    std::string velocityFile( fileNameFromDir( datFileName, "VELOC.OUT" ) );
    if ( !MDAL::fileExists( velocityFile ) )
    {
      return; //optional file
    }

    std::ifstream velocityStream( velocityFile, std::ifstream::in );
    std::string line;

    size_t vertex_idx = 0;

    // VELOC.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL)  - Maximum channel flow velocity
    while ( std::getline( velocityStream, line ) )
    {
      if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh;

      line = MDAL::rtrim( line );
      std::vector<std::string> lineParts = MDAL::split( line, ' ' );
      if ( lineParts.size() != 4 )
      {
        throw MDAL_Status::Err_UnknownFormat;
      }

      double val = getDouble( lineParts[3] );
      if ( !is_nodata( val ) ) // overwrite value from VELFP if it is not 0
      {
        maxVel[vertex_idx] = val;
      }

      vertex_idx++;
    }
  }

  addStaticDataset( true, maxVel, "Velocity/Maximums", datFileName );
}