Uint MergedParallelDistribution::end_idx_in_part(const Uint part) const
{
  Uint end_idx = 0;
  boost_foreach (Handle< ParallelDistribution > hash, m_subhash)
    end_idx += hash->end_idx_in_part(part);
  return end_idx;
}
Uint MergedParallelDistribution::part_size() const
{
  Uint psize = 0;
  boost_foreach (Handle< ParallelDistribution > hash, m_subhash)
    psize += hash->part_size();
  return psize;
}
Ejemplo n.º 3
0
Uint CMixedHash::end_idx_in_part(const Uint part) const
{
  Uint end_idx = 0;
  boost_foreach (CHash::ConstPtr hash, m_subhash)
    end_idx += hash->end_idx_in_part(part);
  return end_idx;
}
Ejemplo n.º 4
0
Uint CMixedHash::part_size() const
{
  Uint psize = 0;
  boost_foreach (CHash::ConstPtr hash, m_subhash)
    psize += hash->part_size();
  return psize;
}
Ejemplo n.º 5
0
Uint CMixedHash::start_idx_in_part(const Uint part) const
{
  Uint start_idx = 0;
  boost_foreach (CHash::ConstPtr hash, m_subhash)
    start_idx += hash->start_idx_in_part(part);
  return start_idx ;
}
Ejemplo n.º 6
0
bool IterativeSolver::stop_condition()
{
  bool finish = false;
  boost_foreach(CCriterion& stop_criterion, find_components<CCriterion>(*this))
      finish |= stop_criterion();
  return finish;
}
Ejemplo n.º 7
0
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Updates all the actual recipients with 'success'. This is done after the
   // message delivery has been accepted by the remote server.
   //---------------------------------------------------------------------------()
   void
   SMTPClientConnection::_UpdateSuccessfulRecipients()
   {
      boost_foreach(shared_ptr<MessageRecipient> actualRecipient, _actualRecipients)
         actualRecipient->SetDeliveryResult(MessageRecipient::ResultOK);

   }
Ejemplo n.º 8
0
void CMixedHash::config_nb_parts ()
{
  option("nb_parts").put_value(m_nb_parts);
  if (m_subhash.size())
  {
    boost_foreach(CHash::Ptr hash, m_subhash)
      hash->configure_option("nb_parts", m_nb_parts);
  }
}
void MergedParallelDistribution::config_nb_parts ()
{
  m_nb_parts = options().value<Uint>("nb_parts");
  if (m_subhash.size())
  {
    boost_foreach(Handle< ParallelDistribution > hash, m_subhash)
      hash->options().set("nb_parts", m_nb_parts);
  }
}
Ejemplo n.º 10
0
void CUnifiedData::reset()
{
  m_start_idx.clear();
  boost_foreach(Component& data_link, m_data_links->children())
    m_data_links->remove_component(data_link);
  m_data_vector.resize(0);
  m_data_indices->resize(1);
  m_data_indices->array()[0]=0;
  m_size=0;
}
Ejemplo n.º 11
0
CAction& SFDSolver::create_bc(const std::string& name, const std::vector<CRegion::Ptr>& regions, const std::string& bc_builder_name)
{
  std::vector<URI> regions_uri; regions_uri.reserve(regions.size());
  boost_foreach(CRegion::Ptr region, regions)
    regions_uri.push_back(region->uri());

  CAction::Ptr for_all_faces = m_apply_bcs->create_component_ptr<CForAllFaces>(name);
  for_all_faces->configure_option("regions",regions_uri);
  CAction& bc = for_all_faces->create_action(bc_builder_name,bc_builder_name);
  auto_config_fields(bc);
  return bc;
}
Ejemplo n.º 12
0
void OutputIterationInfo::execute()
{
  if (m_residual.expired())     throw SetupError(FromHere(), "Residual field was not set");
  if (m_time.expired())         throw SetupError(FromHere(), "Time component was not set");

  // compute norm
  Real rhs_L2=0;
  boost_foreach(CTable<Real>::ConstRow rhs , m_residual.lock()->data().array())
    rhs_L2 += rhs[0]*rhs[0];
  rhs_L2 = sqrt(rhs_L2) / m_residual.lock()->data().size();

  // output convergence info
  CFinfo << "Iter [" << std::setw(4) << time().iter() << "]";
  CFinfo << "      Time [" << std::setprecision(4) << std::setiosflags(std::ios_base::scientific) << std::setw(10) << time().time() << "]";
  CFinfo << "      Time Step [" << std::setprecision(4) << std::setiosflags(std::ios_base::scientific) << std::setw(10) << time().dt() << "]";
  CFinfo << "      L2(rhs) [" << std::setprecision(4) << std::setiosflags(std::ios_base::scientific) << std::setw(10) << rhs_L2 << "]";
  CFinfo << CFendl;
}
Ejemplo n.º 13
0
void RDSolver::config_mesh()
{
  if( is_null(m_mesh) ) return;

  Mesh& mesh = *(m_mesh);

  physics::PhysModel& pm = physics(); // physcial model must have already been configured

  if( pm.ndim() != mesh.dimension() )
    throw SetupError( FromHere(), "Dimensionality mismatch. Loaded mesh ndim " + to_str(mesh.dimension()) + " and physical model dimension " + to_str(pm.ndim()) );

  // setup the fields

  prepare_mesh().configure_option_recursively( RDM::Tags::mesh(), m_mesh ); // trigger config_mesh()

  prepare_mesh().execute();

  // configure all other subcomponents with the mesh

  boost_foreach( Component& comp, find_components(*this) )
    comp.configure_option_recursively( RDM::Tags::mesh(), m_mesh );
}
Ejemplo n.º 14
0
void RDSolver::config_physics()
{
  try
  {
    PhysModel& pm = physics();

    std::string user_vars = options().option(  RDM::Tags::update_vars() ).value<std::string>();
    if( user_vars.empty() )
      return;

    Handle< Variables > upv(find_component_ptr_with_tag(pm, RDM::Tags::update_vars()));

    if( is_not_null(upv) ) // if exits insure is the good one
    {
      if( upv->type() != user_vars )
      {
        pm.remove_component(upv->name() );
        upv.reset();
      }
    }

    if( is_null(upv) )
      pm.create_variables( user_vars, RDM::Tags::update_vars() );

    boost_foreach( Component& comp, find_components(*this) )
      comp.configure_option_recursively( RDM::Tags::physical_model(), pm.handle<PhysModel>() );

    // load the library which has the correct RDM physics

    std::string modeltype = pm.model_type();
    boost::to_lower( modeltype );
    OSystem::instance().lib_loader()->load_library( "coolfluid_rdm_" + modeltype );
  }
  catch(SetupError&)
  {
    // Do nothing if physmodel is not configured
  }
}
Ejemplo n.º 15
0
void Octtree::find_cell_ranks( const boost::multi_array<Real,2>& coordinates, std::vector<Uint>& ranks )
{
  ranks.resize(coordinates.size());

  Handle< Elements > element_component;
  Uint element_idx;
  std::deque<Uint> missing_cells;

  RealVector dummy(m_dim);

  for(Uint i=0; i<coordinates.size(); ++i)
  {
    for (Uint d=0; d<m_dim; ++d)
      dummy[d] = coordinates[i][d];
    if( find_element(dummy,element_component,element_idx) )
    {
      ranks[i] = Comm::instance().rank();
    }
    else
    {
      ranks[i] = math::Consts::uint_max();
      missing_cells.push_back(i);
    }
  }

  std::vector<Real> send_coords(m_dim*missing_cells.size());
  std::vector<Real> recv_coords;

  Uint c(0);
  boost_foreach(const Uint i, missing_cells)
  {
    for(Uint d=0; d<m_dim; ++d)
      send_coords[c++]=coordinates[i][d];
  }

  for (Uint root=0; root<PE::Comm::instance().size(); ++root)
  {

    recv_coords.resize(0);
    PE::Comm::instance().broadcast(send_coords,recv_coords,root,m_dim);

    // size is only because it doesn't get resized for this rank
    std::vector<Uint> send_found(missing_cells.size(),math::Consts::uint_max());

    if (root!=Comm::instance().rank())
    {
      std::vector<RealVector> recv_coordinates(recv_coords.size()/m_dim) ;
      boost_foreach(RealVector& realvec, recv_coordinates)
          realvec.resize(m_dim);

      c=0;
      for (Uint i=0; i<recv_coordinates.size(); ++i)
      {
        for(Uint d=0; d<m_dim; ++d)
          recv_coordinates[i][d]=recv_coords[c++];
      }

      send_found.resize(recv_coordinates.size());
      for (Uint i=0; i<recv_coordinates.size(); ++i)
      {
        if( find_element(recv_coordinates[i],element_component,element_idx) )
        {
          send_found[i] = Comm::instance().rank();
        }
        else
          send_found[i] = math::Consts::uint_max();
      }
    }

    std::vector<Uint> recv_found(missing_cells.size()*Comm::instance().size());
    PE::Comm::instance().gather(send_found,recv_found,root);

    if( root==Comm::instance().rank())
    {
      const Uint stride = missing_cells.size();
      for (Uint i=0; i<missing_cells.size(); ++i)
      {
        for(Uint p=0; p<Comm::instance().size(); ++p)
        {
          ranks[missing_cells[i]] = std::min(recv_found[i+p*stride] , ranks[missing_cells[i]]);
        }
      }
    }
  }
}
Ejemplo n.º 16
0
void CMeshWriter::set_fields(const std::vector<CField::Ptr>& fields)
{
  m_fields.resize(0);
  boost_foreach( CField::Ptr field, fields )
    m_fields.push_back(field);
}
Ejemplo n.º 17
0
void SetupMultipleSolutions::execute()
{
  RDM::RDSolver& mysolver = solver().as_type< RDM::RDSolver >();

  /* nb_levels == rkorder */

  const Uint nb_levels = option("nb_levels").value<Uint>();

  CMesh&  mesh = *m_mesh.lock();
  CGroup& fields = mysolver.fields();

  // get the geometry field group

  Geometry& geometry = mesh.geometry();

  const std::string solution_space = mysolver.option("solution_space").value<std::string>();

  // check that the geometry belongs to the same space as selected by the user

  FieldGroup::Ptr solution_group;

  if( solution_space == geometry.space() )
    solution_group = geometry.as_ptr<FieldGroup>();
  else
  {
    // check if solution space already exists
    solution_group = find_component_ptr_with_name<FieldGroup>( mesh, RDM::Tags::solution() );
    if ( is_null(solution_group) )
    {
      boost_foreach(CEntities& elements, mesh.topology().elements_range())
          elements.create_space( RDM::Tags::solution(), "CF.Mesh.SF.SF"+elements.element_type().shape_name() + solution_space );
      solution_group = mesh.create_field_group( RDM::Tags::solution(), FieldGroup::Basis::POINT_BASED).as_ptr<FieldGroup>();
    }
    else // not null so check that space is what user wants
    {
      if( solution_space != solution_group->space() )
        throw NotImplemented( FromHere(), "Changing solution space not supported" );
    }
  }

  // construct vector of variables

  const Uint nbdofs = physical_model().neqs();

  std::string vars;
  for(Uint i = 0; i < nbdofs; ++i)
  {
   vars += "u" + to_str(i) + "[1]";
   if( i != nbdofs-1 ) vars += ",";
  }

  // configure 1st solution

  Field::Ptr solution = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::solution() );
  if ( is_null( solution ) )
  {
    solution = solution_group->create_field( RDM::Tags::solution(), vars ).as_ptr<Field>();

    solution->add_tag(Tags::solution());
  }

  // create the other solutions based on the first solution field

  std::vector< Field::Ptr > rk_steps;

  rk_steps.push_back(solution);

  for(Uint step = 1; step < nb_levels; ++step)
  {
    Field::Ptr solution_k = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::solution() + to_str(step));
    if ( is_null( solution_k ) )
    {
      std::string name = std::string(Tags::solution()) + to_str(step);
      solution_k = solution_group->create_field( name, solution->descriptor().description() ).as_ptr<Field>();
      solution_k->descriptor().prefix_variable_names("rk" + to_str(step) + "_");
      solution_k->add_tag("rksteps");
    }

    cf_assert( solution_k );
    rk_steps.push_back(solution_k);
  }

  /// @todo here we should check if space() order is correct,
  ///       if not the change space() by enriching or other appropriate action

  // configure residual

  Field::Ptr residual = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::residual());
  if ( is_null( residual ) )
  {
    residual = solution_group->create_field(Tags::residual(), solution->descriptor().description() ).as_ptr<Field>();
    residual->descriptor().prefix_variable_names("rhs_");
    residual->add_tag(Tags::residual());
  }


  // configure wave_speed

  Field::Ptr wave_speed = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::wave_speed());
  if ( is_null( wave_speed ) )
  {
    wave_speed = solution_group->create_field(Tags::wave_speed(), "ws[1]" ).as_ptr<Field>();
    wave_speed->add_tag(Tags::wave_speed());
  }


  // create links

  if( ! fields.get_child_ptr( solution->name() ) )
    fields.create_component<CLink>( solution->name() ).link_to(solution).add_tag(RDM::Tags::solution());
  if( ! fields.get_child_ptr( RDM::Tags::residual() ) )
    fields.create_component<CLink>( RDM::Tags::residual() ).link_to(residual).add_tag(RDM::Tags::residual());
  if( ! fields.get_child_ptr( RDM::Tags::wave_speed() ) )
    fields.create_component<CLink>( RDM::Tags::wave_speed() ).link_to(wave_speed).add_tag(RDM::Tags::wave_speed());

  for( Uint step = 1; step < rk_steps.size(); ++step)
  {
    if( ! fields.get_child_ptr( rk_steps[step]->name() ) )
      fields.create_component<CLink>( rk_steps[step]->name() ).link_to(solution).add_tag("rksteps");
  }


  // parallelize the solution if not yet done

  CommPattern& pattern = solution->parallelize();

  std::vector<URI> parallel_fields;
  parallel_fields.push_back( solution->uri() );

  for(Uint step = 1; step < nb_levels; ++step)
  {
    rk_steps[step]->parallelize_with( pattern );
    parallel_fields.push_back( rk_steps[step]->uri() );
  }

  mysolver.actions().get_child("Synchronize").configure_option("Fields", parallel_fields);

//  std::cout << "solution " << solution->uri().string() << std::endl;
//  std::cout << "residual " << residual->uri().string() << std::endl;
//  std::cout << "wave_speed " << wave_speed->uri().string() << std::endl;

}