コード例 #1
0
void ImportSTL:: doImport
(
    const std::string& name,
    mesh::Mesh&        mesh )
{
    preciceTrace1("doImport()", name);
    assertion1(mesh.getDimensions() == 3, mesh.getDimensions());
    // TODO
}
コード例 #2
0
ファイル: fvmpor_DAE_impl.cpp プロジェクト: jackd/FVMPor
 double Physics::compute_mass(const mesh::Mesh& m, const_iterator u) {
     double total_mass = 0.;
     const double* source = reinterpret_cast<const double*>(&u[0]);
     vdPackI(m.nodes(), &source[0], 2, &h_vec[0]);
     process_volumes_psk( m );
     for(int i=0; i<m.local_nodes(); i++)
         //total_mass += m.volume(i).vol()*u[i].M;
         total_mass += m.volume(i).vol()*theta_vec[i]*rho_vec[i];
     return total_mass;
 }
コード例 #3
0
ファイル: fvmpor_DAE_impl.cpp プロジェクト: jackd/FVMPor
    double Physics::mass_flux_per_time(const mesh::Mesh& m){
        double flux_per_time = 0.;
        for( int i=m.interior_cvfaces(); i<m.cvfaces(); i++ )
        {
            const mesh::CVFace& cvf = m.cvface(i);
            int boundary_tag = cvf.boundary();
            const BoundaryCondition& BC = boundary_condition_h( boundary_tag );
            double t=0.;
            if( BC.type()==3 )
                flux_per_time -= BC.value(t) * m.cvface(i).area();
        }

        return flux_per_time*constants().rho_0();
    }
コード例 #4
0
void DriftRatchet:: createBodyWall
(
   mesh::Mesh&              mesh,
   mesh::PropertyContainer* propertyContainer,
   mesh::Vertex*            cutVertices[],
   mesh::Edge*              cutEdges[] )
{
   int sectionCount = getCutsAlongXAxis ( _discretizationWidth );
   double currentXInImage = 0.0;
   double currentXInPreImage = 0.0;
   double xStepInImage = _length / (double)sectionCount;
   double xStepInPreImage = (_pores * getCharacteristicLength(_maxRadius)) / (double)sectionCount;
   int dimensions = mesh.getDimensions();
   utils::DynVector currentCenter ( dimensions, 0.0 );
   currentXInImage    += xStepInImage;
   currentXInPreImage += xStepInPreImage;
   for ( int i=0; i < sectionCount; i++ ) {
      currentCenter(0) = currentXInImage;
      double radius = getRadius ( currentXInPreImage );
      createBodyWallSection ( mesh, propertyContainer, cutVertices, cutEdges,
                              currentCenter, radius );
      currentXInImage    += xStepInImage;
      currentXInPreImage += xStepInPreImage;
   }
}
コード例 #5
0
void DriftRatchet:: createRightWall
(
  mesh::Mesh&              mesh,
  mesh::PropertyContainer* propertyContainer,
  mesh::Vertex*            cutVertices[],
  mesh::Edge*              cutEdges[]  )
{
  int dimensions = mesh.getDimensions();
  if ( dimensions == 2 ){
    utils::Vector2D center ( 0.0 );
    center(0) += _length;
    mesh::Vertex& centerVertex = mesh.createVertex ( center );
    if ( propertyContainer != NULL ) {
      centerVertex.addParent ( *propertyContainer );
    }
    mesh::Edge& e0 = mesh.createEdge ( centerVertex, *cutVertices[0] );
    mesh::Edge& e1 = mesh.createEdge ( *cutVertices[1], centerVertex );
    if ( propertyContainer != NULL ) {
      e0.addParent ( *propertyContainer );
      e1.addParent ( *propertyContainer );
    }
  }
  else {
    assertion1 ( dimensions == 3, dimensions );
    utils::Vector3D center ( 0.0 );
    center(0) += _length;
    mesh::Vertex& centerVertex = mesh.createVertex ( center );
    if ( propertyContainer != NULL ) {
      centerVertex.addParent ( *propertyContainer );
    }
    int vertexCount = getNumberOfVerticesPerCut ( _discretizationWidth );

    // Create edges and triangles
    mesh::Edge& firstCenterEdge = mesh.createEdge ( centerVertex, *cutVertices[0] );
    if ( propertyContainer != NULL ) {
      firstCenterEdge.addParent ( *propertyContainer );
    }
    mesh::Edge* oldCenterEdge = & firstCenterEdge;
    mesh::Edge* newCenterEdge = NULL;
    for ( int i=0; i < vertexCount - 1; i++ ) {
      newCenterEdge = & mesh.createEdge ( centerVertex, *cutVertices[i+1] );
      mesh::Triangle& t = mesh.createTriangle (
          *cutEdges[i], *oldCenterEdge, *newCenterEdge );
      if ( propertyContainer != NULL ) {
        newCenterEdge->addParent ( *propertyContainer );
        t.addParent ( *propertyContainer );
      }
      oldCenterEdge = newCenterEdge;
    }
    mesh::Triangle& t = mesh.createTriangle ( *cutEdges[vertexCount-1],
                                              *oldCenterEdge, firstCenterEdge );
    if ( propertyContainer != NULL ) {
      t.addParent ( *propertyContainer );
    }
  }
}
コード例 #6
0
void ImportGeometry:: allocateDataValues
(
  mesh::Mesh& mesh )
{
  // Data values are already allocated during import when a checkpoint is read
  // and should not be overwritten by reallocating them.
  if ( not _importCheckpoint ){
    mesh.allocateDataValues();
  }
}
コード例 #7
0
ファイル: mrmesh.cpp プロジェクト: MarcRamos/mrtrix3
void run ()
{

  Mesh::Mesh mesh;

  if (get_options ("blocky").size()) {

    auto input = Image<bool>::open (argument[0]);
    Mesh::vox2mesh (input, mesh);

  } else {

    auto input = Image<float>::open (argument[0]);
    float threshold = get_option_value ("threshold", Filter::estimate_optimal_threshold (input));
    Mesh::vox2mesh_mc (input, threshold, mesh);

  }

  mesh.save (argument[1]);

}
コード例 #8
0
ファイル: mesh2pve.cpp プロジェクト: szho42/mrtrix3
void run ()
{

  // Read in the mesh data
  Mesh::Mesh mesh (argument[0]);

  // If the .vtk files come from FIRST, they are defined in a native FSL space, and
  //   therefore the source image must be known in order to transform to real space
  Options opt = get_options ("first");
  if (opt.size()) {
    Image::Header H_first (opt[0][0]);
    mesh.transform_first_to_realspace (H_first);
  }

  // Get the template image
  Image::Header template_image (argument[1]);

  // Create the output image
  mesh.output_pve_image (template_image, argument[2]);

}
コード例 #9
0
void DriftRatchet:: specializedCreate
(
  mesh::Mesh& seed )
{
   using namespace mesh;
   std::string nameSubID ( seed.getName() + "-side-" );
   PropertyContainer* leftWall = NULL;
   PropertyContainer* rightWall = NULL;
   if ( seed.getNameIDPairs().count(nameSubID + "0") ) {
      leftWall = & seed.getPropertyContainer ( nameSubID + "0" );
   }
   if ( seed.getNameIDPairs().count(nameSubID + "1") ) {
      rightWall = & seed.getPropertyContainer ( nameSubID + "1" );
   }
   int count = getNumberOfVerticesPerCut ( _discretizationWidth );
   mesh::Vertex** cutVertices = new mesh::Vertex* [count];
   count = getOffset().size() == 3 ? count : 0; // Only used in 3D
   mesh::Edge ** cutEdges = new mesh::Edge * [count];
   createLeftWall ( seed, leftWall, cutVertices, cutEdges );
   createBodyWall ( seed, NULL, cutVertices, cutEdges );
   createRightWall ( seed, rightWall, cutVertices, cutEdges );
   delete[] cutVertices;
   delete[] cutEdges;
}
コード例 #10
0
ファイル: fvmpor_DAE_impl.cpp プロジェクト: jackd/FVMPor
    void Physics::preprocess_evaluation(double t, const mesh::Mesh& m,
                                        const_iterator u, const_iterator udash)
    {
        ++num_calls;

        for (int i = 0; i < m.nodes(); ++i) {
            assert(u[i].h == u[i].h &&
                   u[i].h !=  std::numeric_limits<double>::infinity() &&
                   u[i].h != -std::numeric_limits<double>::infinity()
            );
            assert(u[i].M == u[i].M &&
                   u[i].M !=  std::numeric_limits<double>::infinity() &&
                   u[i].M != -std::numeric_limits<double>::infinity()
            );
        }

        // Copy h from solution vector to h_vec and c_vec
        const double* source = reinterpret_cast<const double*>(&u[0]);
        vdPackI(m.nodes(), &source[0], 2, &h_vec[0]);

        // h and gradient at CV faces
        shape_matrix.matvec( h_vec, h_faces );
        shape_gradient_matrixX.matvec( h_vec, grad_h_faces_.x() );
        shape_gradient_matrixY.matvec( h_vec, grad_h_faces_.y() );
        if (dimension == 3)
            shape_gradient_matrixZ.matvec( h_vec, grad_h_faces_.z() );

        // determine the p-s-k values
        process_volumes_psk( m );
        // density at faces using shape functions
        process_faces_shape( m );
        // Compute psk values at faces using upwinding/limiting
        process_faces_lim( m );
        // compute fluxes
        process_fluxes( t, m );
    }
コード例 #11
0
void CommunicateMesh:: receiveMesh
(
  mesh::Mesh& mesh,
  int         rankSender )
{
  preciceTrace2 ( "receiveMesh()", mesh.getName(), rankSender );
  using tarch::la::raw;
  int dim = mesh.getDimensions();
  std::map<int, mesh::Vertex*> vertexMap;
  int vertexCount;
  _communication->startReceivePackage ( rankSender );
  _communication->receive ( vertexCount, rankSender);
  utils::DynVector coords(dim);
  for ( int i=0; i < vertexCount; i++ ){
    _communication->receive ( raw(coords), dim, rankSender );
    mesh::Vertex& v = mesh.createVertex ( coords );
    assertion1 ( v.getID() >= 0, v.getID() );
    vertexMap[v.getID()] = &v;
  }
  std::map<int,mesh::Edge*> edgeMap; // only used in 3D
  int edgeCount;
  _communication->receive ( edgeCount, rankSender );
  for ( int i=0; i < edgeCount; i++ ){
    int vertexIndex1 = -1;
    int vertexIndex2 = -1;
    _communication->receive ( vertexIndex1, rankSender );
    _communication->receive ( vertexIndex2, rankSender );

    assertion ( vertexMap.find(vertexIndex1) != vertexMap.end() );
    assertion ( vertexMap.find(vertexIndex2) != vertexMap.end() );
    assertion1 ( vertexIndex1 != vertexIndex2, vertexIndex1 );

    if ( dim == 2 ){
      mesh.createEdge ( *vertexMap[vertexIndex1], *vertexMap[vertexIndex2] );
    }
    else {
      assertion1 ( dim == 3, dim );
      mesh::Edge & e = mesh.createEdge (
          *vertexMap[vertexIndex1], *vertexMap[vertexIndex2] );
      assertion1 ( e.getID() >= 0, e.getID() );
      edgeMap[e.getID()] = &e;
    }
  }
  if ( dim == 3 ){
    int triangleCount = 0;
    assertion ( (edgeMap.size() > 0) || (triangleCount == 0) );
    _communication->receive ( triangleCount, rankSender );
    for ( int i=0; i < triangleCount; i++ ) {
      int index1 = -1;
      int index2 = -1;
      int index3 = -1;
      _communication->receive ( index1, rankSender );
      _communication->receive ( index2, rankSender );
      _communication->receive ( index3, rankSender );

      assertion ( edgeMap.find(index1) != edgeMap.end() );
      assertion ( edgeMap.find(index2) != edgeMap.end() );
      assertion ( edgeMap.find(index3) != edgeMap.end() );
      assertion ( index1 != index2 );
      assertion ( index2 != index3 );
      assertion ( index3 != index1 );

      mesh.createTriangle ( *edgeMap[index1], *edgeMap[index2], *edgeMap[index3] );
    }
  }
  _communication->finishReceivePackage ();
}
コード例 #12
0
void DriftRatchet:: createBodyWallSection
(
   mesh::Mesh&              mesh,
   mesh::PropertyContainer* propertyContainer,
   mesh::Vertex*            cutVertices[],
   mesh::Edge*              cutEdges[],
   const utils::DynVector&  center,
   double                   radius )
{
  int dimensions = mesh.getDimensions();
  if ( dimensions == 2 ){
    utils::Vector2D upperPoint ( center[0], center[1] + radius );
    utils::Vector2D lowerPoint ( center[0], center[1] - radius );
    mesh::Vertex& upperVertex = mesh.createVertex ( upperPoint );
    mesh::Vertex& lowerVertex = mesh.createVertex ( lowerPoint );
    mesh::Edge& e0 = mesh.createEdge ( upperVertex, *cutVertices[0] );
    mesh::Edge& e1 = mesh.createEdge ( *cutVertices[1], lowerVertex );
    cutVertices[0] = & upperVertex;
    cutVertices[1] = & lowerVertex;
    if ( propertyContainer != NULL ) {
      e0.addParent ( *propertyContainer );
      e1.addParent ( *propertyContainer );
      cutVertices[0]->addParent ( *propertyContainer );
      cutVertices[1]->addParent ( *propertyContainer );
    }
  }
  else {
    assertion1 ( dimensions == 3, dimensions );
    double currentAngle = 0.0;
    int vertexCount = getNumberOfVerticesPerCut ( _discretizationWidth );
    double angle = 2.0 * tarch::la::PI / static_cast<double>(vertexCount);

    // Create vertices
    mesh::Vertex ** newCutVertices = new mesh::Vertex * [vertexCount];
    for ( int i=0; i < vertexCount; i++ ) {
      utils::Vector3D currentCenter ( center );
      double y = std::cos(currentAngle) * radius;
      currentCenter(1) += y;
      double z = std::sin(currentAngle) * radius;
      currentCenter(2) += z;
      currentAngle += angle;
      newCutVertices[i] = & mesh.createVertex ( currentCenter );
      if ( propertyContainer != NULL ) {
        newCutVertices[i]->addParent ( *propertyContainer );
      }
    }

    // Create edges and triangles
    mesh::Edge** newCutEdges = new mesh::Edge * [vertexCount];
    mesh::Edge* initialEdge = & mesh.createEdge ( *cutVertices[0],
                                                  *newCutVertices[0] );
    if ( propertyContainer != NULL ) {
      initialEdge->addParent ( *propertyContainer );
    }
    mesh::Edge* firstEdge = initialEdge;
    mesh::Edge* crossingEdge = NULL;
    mesh::Edge* secondEdge = NULL;
    for ( int i=0; i < vertexCount - 1; i++ ) {
      crossingEdge = & mesh.createEdge ( *cutVertices[i],
                                         *newCutVertices[i+1] );
      newCutEdges[i] = & mesh.createEdge ( *newCutVertices[i],
                                           *newCutVertices[i+1] );
      secondEdge = & mesh.createEdge ( *cutVertices[i+1],
                                       *newCutVertices[i+1] );
      mesh::Triangle& t0 = mesh.createTriangle ( *firstEdge, *newCutEdges[i], *crossingEdge );
      mesh::Triangle& t1 = mesh.createTriangle ( *crossingEdge, *secondEdge, *cutEdges[i] );
      if ( propertyContainer != NULL ) {
        t0.addParent ( *propertyContainer );
        t1.addParent ( *propertyContainer );
        crossingEdge->addParent ( *propertyContainer );
        secondEdge->addParent ( *propertyContainer );
      }
      firstEdge = secondEdge;
    }
    crossingEdge = & mesh.createEdge ( *cutVertices[vertexCount - 1],
                                       *newCutVertices[0] );
    newCutEdges[vertexCount - 1] =
      & mesh.createEdge ( *newCutVertices[vertexCount - 1], *newCutVertices[0] );
    secondEdge = initialEdge;
    mesh::Triangle & t0 =
      mesh.createTriangle ( *firstEdge, *newCutEdges[vertexCount -1], *crossingEdge );
    mesh::Triangle & t1 =
      mesh.createTriangle ( *crossingEdge, *secondEdge, *cutEdges[vertexCount - 1] );
    if ( propertyContainer != NULL ) {
      crossingEdge->addParent ( *propertyContainer );
      newCutEdges[vertexCount - 1]->addParent ( *propertyContainer );
      t0.addParent ( *propertyContainer );
      t1.addParent ( *propertyContainer );
    }

    // Transfer cutting vertices and edges
    for ( int i=0; i < vertexCount; i++ ) {
      cutVertices[i] = newCutVertices[i];
      cutEdges[i] = newCutEdges[i];
    }
    delete[] newCutVertices;
    delete[] newCutEdges;
  }
}
コード例 #13
0
void DriftRatchet:: createLeftWall
(
  mesh::Mesh&              mesh,
  mesh::PropertyContainer* propertyContainer,
  mesh::Vertex*            cutVertices[],
  mesh::Edge*              cutEdges[]  )
{
  int dimensions = mesh.getDimensions();
  if ( dimensions == 2 ){
    using utils::Vector2D;
    double radius = getRadius ( 0.0 );
    Vector2D center ( 0.0 );
    mesh::Vertex& centerVertex = mesh.createVertex ( center );
    if ( propertyContainer != NULL ) {
       centerVertex.addParent ( *propertyContainer );
    }
    Vector2D upperPoint ( center(0), center(1) + radius );
    cutVertices[0] = & mesh.createVertex ( upperPoint );
    Vector2D lowerPoint ( center(0), center(1) - radius);
    cutVertices[1] = & mesh.createVertex ( lowerPoint );
    mesh::Edge& e0 = mesh.createEdge ( *cutVertices[0], centerVertex);
    mesh::Edge& e1 = mesh.createEdge ( centerVertex, *cutVertices[1] );
    if ( propertyContainer != NULL ) {
      e0.addParent ( *propertyContainer );
      e1.addParent ( *propertyContainer );
    }
  }
  else {
    assertion1 ( dimensions == 3, dimensions );
    using utils::Vector3D;
    double currentAngle = 0.0;
    int vertexCount = getNumberOfVerticesPerCut ( _discretizationWidth );
    double angle = 2.0 * tarch::la::PI / static_cast<double>(vertexCount);
    double radius = getRadius ( 0.0 );
    Vector3D center(0.0);
    mesh::Vertex& centerVertex = mesh.createVertex ( center );
    if ( propertyContainer != NULL ) {
       centerVertex.addParent ( *propertyContainer );
    }

    // Create vertices
    for ( int i=0; i < vertexCount; i++ ) {
      Vector3D currentPoint ( center );
      double y = std::cos(currentAngle) * radius;
      currentPoint(1) += y;
      double z = std::sin(currentAngle) * radius;
      currentPoint(2) += z;
      currentAngle += angle;
      cutVertices[i] = & mesh.createVertex ( currentPoint );
      if ( propertyContainer != NULL ) {
        cutVertices[i]->addParent ( *propertyContainer );
      }
    }

    // Create edges and triangles
    mesh::Edge & firstCenterEdge = mesh.createEdge ( centerVertex,
                                                     *cutVertices[0] );
    mesh::Edge * oldCenterEdge = & firstCenterEdge;
    mesh::Edge * newCenterEdge = NULL;
    for ( int i=0; i < vertexCount - 1; i++ ) {
      newCenterEdge = & mesh.createEdge ( centerVertex, *cutVertices[i+1] );
      cutEdges[i] = & mesh.createEdge ( *cutVertices[i], *cutVertices[i+1] );
      mesh::Triangle & t = mesh.createTriangle ( *oldCenterEdge, *cutEdges[i], *newCenterEdge );
      if ( propertyContainer != NULL ) {
        cutEdges[i]->addParent ( *propertyContainer );
        oldCenterEdge->addParent ( *propertyContainer );
        t.addParent ( *propertyContainer );
      }
      oldCenterEdge = newCenterEdge;
    }
    cutEdges[vertexCount-1] = & mesh.createEdge ( *cutVertices[vertexCount-1],
                                                  *cutVertices[0] );
    mesh::Triangle & t = mesh.createTriangle (
      *oldCenterEdge, *cutEdges[vertexCount-1], firstCenterEdge );
    if ( propertyContainer != NULL ) {
      cutEdges[vertexCount-1]->addParent ( *propertyContainer );
      t.addParent ( *propertyContainer );
    }
  }
}
コード例 #14
0
ファイル: fvmpor_DAE_impl.cpp プロジェクト: jackd/FVMPor
    void Physics::initialise(double& t, const mesh::Mesh& m,
                             iterator u, iterator udash, iterator temp,
                             Callback compute_residual)
    {
        // allocate storage
        initialise_vectors( m );

        // Set initial values
        set_initial_conditions(t, m);
        for( int i=0; i<m.local_nodes(); i++ ){
            u[i].h = h_vec[i];
            udash[i].M = 0;
        }

        // set M and C according to pressure and concentration 
        process_volumes_psk( m ); // find theta for each volume
        for( int i=0; i<m.local_nodes(); i++ ){
            u[i].M = rho_vec[i]*theta_vec[i];
            //std::cout << u[i].M << " " << rho_vec[i] << " " << theta_vec[i] << std::endl;
        }

        // Compute residual
        compute_residual(temp, true);

        // determine the derivative coefficients
        process_derivative_coefficients( m );

        // Set initial derivatives
        for( int f=0; f<m.interior_cvfaces(); f++ ){
            int front_id = m.cvface(f).front().id();
            double vol = m.volume(front_id).vol();
            if (front_id < m.local_nodes()){
                udash[front_id].M += M_flux_faces[f]/vol;
            }
            int back_id = m.cvface(f).back().id();
            vol = m.volume(back_id).vol();
            if (back_id < m.local_nodes()){
                udash[back_id].M -= M_flux_faces[f]/vol;
            }
        }
        for( int f=m.interior_cvfaces(); f<m.cvfaces(); f++){
            int back_id = m.cvface(f).back().id();
            double vol = m.volume(back_id).vol();
            if (back_id < m.local_nodes()){
                udash[back_id].M -= M_flux_faces[f]/vol;
            }
        }
        /*
        for(int i=0; i<m.local_nodes(); i++){
            if(fabs(udash[i].M)>1e-10)
                //std::cout << i << " " << u[i].h << " " << u[i].M << " " << udash[i].h  << " " << udash[i].M << std::endl;  
        }
        */
    }