text:
// SketchUp Ruby API Debugger. Copyright 2013 Trimble Navigation Ltd.
// Authors:
// - Bugra Barin
//

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

#include "./DebuggerSettings.h"

using namespace SketchUp::RubyDebugger;

namespace SketchUp {
namespace RubyDebugger {
namespace Settings {

static std::string GetFilePath() {
  static std::string file_path;
  if (file_path.empty()) {
#ifdef WIN32
    // Loading from ProgramData because loading from user folder may cause
    // issues with unicode user names. We might deal with that later.
    char path[MAX_PATH];
    path[0] = '\0';
    BOOL ok = SHGetSpecialFolderPathA(NULL, path, CSIDL_COMMON_APPDATA, FALSE);
    file_path = std::string(path) + "\\SketchUp\\RubyDebugger.settings";
#endif
  }
  return file_path;
}

using boost::property_tree::ptree;

static void Save(const BreakPoint& bp, ptree& pt) {
  pt.put("file", bp.file);
  pt.put("line", bp.line);
  pt.put("index", bp.index);
  pt.put("enabled", bp.enabled);
  pt.put("condition", bp.condition);
}

static void Load(const ptree& pt, BreakPoint& bp) {
  bp.file = pt.get<std::string>("file");
  bp.line = pt.get<size_t>("line");
  bp.index = pt.get<size_t>("index");
  bp.enabled = pt.get<bool>("enabled");
  bp.condition = pt.get<std::string>("condition");
}

void SaveBreakPoints(const BreakPointsMap& resolved_bps,
                     const std::vector<BreakPoint>& unresolved_pbs) {
  try {
    ptree pt_all;

    // Resolved breakpoints
    ptree pt_res;
    for (auto it = resolved_bps.cbegin(), ite = resolved_bps.cend(); it != ite;
         ++it) {
      for (auto it2 = it->second.cbegin(), it2e = it->second.cend();
           it2 != it2e; ++it2) {
        const BreakPoint& bp = it2->second;
        ptree pt;
        Save(bp, pt);
        pt_res.push_back(ptree::value_type("breakpoint", pt));
      }
    }
    pt_all.push_back(ptree::value_type("resolved_breakpoints", pt_res));

    // Unresolved breakpoints
    ptree pt_unres;
    for (auto it = unresolved_pbs.cbegin(), ite = unresolved_pbs.cend();
         it != ite; ++it) {
      const BreakPoint& bp = *it;
      ptree pt;
      Save(bp, pt);
      pt_unres.push_back(ptree::value_type("breakpoint", pt));
    }
    pt_all.push_back(ptree::value_type("unresolved_breakpoints", pt_unres));

    std::string file_path = GetFilePath();
    write_xml(file_path, pt_all);
  } catch (const std::exception&) {
  }
}

void LoadBreakPoints(BreakPointsMap& resolved_bps,
                     std::vector<BreakPoint>& unresolved_pbs,
                     size_t& last_breakpoint_index) {
  ptree pt;
  resolved_bps.clear();
  unresolved_pbs.clear();

  // Load the XML file into the property tree.
  std::string file_path = GetFilePath();
  try {
    read_xml(file_path, pt);

    // Resolved breakpoints
    auto it = pt.find("resolved_breakpoints");
    if (it != pt.not_found()) {
      for (auto it2 = it->second.begin(), it2e = it->second.end(); it2 != it2e;
           ++it2) {
        const ptree& pt_bp = it2->second;
        BreakPoint bp;
        Load(pt_bp, bp);
        auto& map = resolved_bps[bp.line];
        map[bp.file] = bp;
        last_breakpoint_index = std::max(last_breakpoint_index, bp.index);
      }
    }

    // Unresolved breakpoints
    it = pt.find("unresolved_breakpoints");
    if (it != pt.not_found()) {
      for (auto it2 = it->second.begin(), it2e = it->second.end(); it2 != it2e;
           ++it2) {
        const ptree& pt_bp = it2->second;
        BreakPoint bp;
        Load(pt_bp, bp);
        unresolved_pbs.push_back(bp);
        last_breakpoint_index = std::max(last_breakpoint_index, bp.index);
      }
    }
  } catch (const std::exception&) {
  }
}

} // end namespace Settings
} // end namespace RubyDebugger
} // end namespace SketchUp

max_stars_repo_name: megatripcol/sketchup-ruby-debugger

max_issues_repo_name: thomthom/sketchup-ruby-debugger

max_forks_repo_name: thomthom/sketchup-ruby-debugger


text:
#include <iostream>
#include <queue>
#include <thread>
#include <assert.h>
#include "createcluster.h"
#include "cpp-hiredis-cluster/include/hirediscommand.h"
#include <boost/functional/hash.hpp>

using namespace RedisCluster;
using std::string;
using std::cout;
using std::cerr;
using std::endl;
using namespace std;

int hashCode(char *str)
{
    boost::hash<std::string> string_hash;

    return string_hash(str);
}

void processClusterCommand(const char *address, int port, char *table, char *data)
{
    Cluster<redisContext>::ptr_t cluster_p;
    redisReply * reply;
    int value = 0;
    string command;
    cluster_p = HiredisCommand<>::createCluster( address, port );
    cout << "Bus error 0" << endl;
    while (value < 20) {
      command = "FOO";
      command = command + to_string(value);

      reply = static_cast<redisReply*>( HiredisCommand<>::Command( cluster_p, "FOO", "hset %s %i %s", table, hashCode(data), data));
      if( reply->type == REDIS_REPLY_STATUS  || reply->type == REDIS_REPLY_ERROR )
      {
          cout << " Reply to SET FOO BAR " << endl;
          cout << reply->str << endl;
      }
      value = value + 1;
      freeReplyObject( reply );
    }
    delete cluster_p;
}

int main(){
  int port = 8001;
  clusterSpec s1 = {
    8000,
    2000,
    6,
    1,
    "127.0.0.1"
  };
  startCluster(s1);
  cout << "Worked till here!!!" <<endl;
  createCluster(s1);
  try
  {
    while (port < 8005) {
      /* code */
      processClusterCommand("127.0.0.1", port, "hsh", "sup data");
      port = port + 1;
    }
  } catch ( const RedisCluster::ClusterException &e )
  {
      cout << "Cluster exception: " << e.what() << endl;
  }
  return 0;
}

ext: cpp

max_stars_repo_name: AALEKH/credis

max_issues_repo_name: AALEKH/credis

max_forks_repo_name: AALEKH/credis


text:
//
// OpenTissue, A toolbox for physical based simulation and animation.
// Copyright (C) 2007 Department of Computer Science, University of Copenhagen
//
#include <OpenTissue/configuration.h>

#include <OpenTissue/core/math/big/big_types.h>
#include <OpenTissue/core/math/math_basic_types.h>
#include <OpenTissue/kinematics/skeleton/skeleton_types.h>
#include <OpenTissue/kinematics/inverse/inverse.h>

#define BOOST_AUTO_TEST_MAIN
#include <OpenTissue/utility/utility_push_boost_filter.h>
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <boost/test/test_tools.hpp>
#include <OpenTissue/utility/utility_pop_boost_filter.h>

typedef OpenTissue::math::default_math_types		  			                 math_types;
typedef math_types::value_traits                                         value_traits;
typedef math_types::real_type                                            real_type;
typedef OpenTissue::skeleton::DefaultBoneTraits<math_types>              base_bone_traits;
typedef OpenTissue::kinematics::inverse::BoneTraits<base_bone_traits>    bone_traits;
typedef OpenTissue::skeleton::Types<math_types, bone_traits>             skeleton_types;
typedef skeleton_types::skeleton_type                                    skeleton_type;
typedef skeleton_types::bone_type                                        bone_type;
typedef ublas::vector<real_type>                                         vector_type;
typedef OpenTissue::kinematics::inverse::Chain< skeleton_type >          chain_type;

BOOST_AUTO_TEST_SUITE(opentissue_kinematics_inverse_compute_weighted_diff);

BOOST_AUTO_TEST_CASE(test_cases)
{
  using std::fabs;

  real_type const too_tiny = boost::numeric_cast<real_type>(10e-15);

  // Create some skeleton to test with
  skeleton_type skeleton;
  bone_type * b[4];
  b[0] = skeleton.create_bone();
  b[1] = skeleton.create_bone(b[0]);
  b[2] = skeleton.create_bone(b[1]);
  b[3] = skeleton.create_bone(b[0]);

  // Now we try to set up some testing data
  //
  // Skeleton hierarchy looks like this
  //
  //            |  hinge
  //            b0
  //    slider /  \   ball
  //          b1   b3
  //    ball  |
  //          b2
  //
  b[0]->type() = bone_traits::hinge_type;
  b[1]->type() = bone_traits::slider_type;
  b[2]->type() = bone_traits::ball_type;
  b[3]->type() = bone_traits::ball_type;

  b[0]->u() = math_types::vector3_type( value_traits::zero(), value_traits::zero(), value_traits::one() );
  b[0]->relative().T().clear();
  OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[0]),  0u, value_traits::pi() );
  b[0]->box_limits().min_limit(0) = -value_traits::pi();
  b[0]->box_limits().max_limit(0) =  value_traits::pi();

  b[1]->u() = math_types::vector3_type( value_traits::one(), value_traits::zero(), value_traits::zero() );
  b[1]->relative().Q().identity();
  OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[1]),  0u, value_traits::one() );
  b[1]->box_limits().min_limit(0) = -value_traits::two();
  b[1]->box_limits().max_limit(0) =  value_traits::two();

  b[2]->relative().T().clear();
  for(size_t j=0u;j<3u;++j)
  {
    OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[2]),  j, value_traits::pi_half() );
    b[2]->box_limits().min_limit(j) = -value_traits::pi_quarter();
    b[2]->box_limits().max_limit(j) =  value_traits::pi_quarter();
  }
  b[2]->relative().T().clear();
  for(size_t j=0u;j<3u;++j)
  {
    OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[3]),  j, value_traits::zero() );
    b[3]->box_limits().min_limit(j) = -value_traits::pi_half();
    b[3]->box_limits().max_limit(j) =  value_traits::pi_half();
  }

  // we assume that get/set joint parameters work and use these for initializing data.
  vector_type theta;
  OpenTissue::kinematics::inverse::get_joint_parameters( skeleton, theta );
  OpenTissue::kinematics::inverse::set_joint_parameters( skeleton, theta );

  // Create some chains
  std::vector<chain_type> chains;
  chains.resize( 2 );
  chains[0].init( b[0], b[2] );
  chains[1].init( b[0], b[3] );

  // Set some positional goal placements
  chains[0].p_global() =  math_types::vector3_type( - value_traits::two(), value_traits::zero(), value_traits::zero() );
  chains[1].p_global() =  math_types::vector3_type(   value_traits::one(), value_traits::zero(), value_traits::zero() );
  chains[0].p_local().clear();
  chains[1].p_local().clear();
  chains[0].only_position() = true;
  chains[1].only_position() = true;

  // Compute the difference vector
  vector_type delta;
  OpenTissue::kinematics::inverse::compute_weighted_difference( chains.begin(), chains.end(), delta );

  // Test if we received the expected values
  BOOST_CHECK( delta.size() == 6u );
  BOOST_CHECK( fabs(-value_traits::one() - delta(0)) < too_tiny );
  BOOST_CHECK( fabs(delta(1)) < too_tiny );
  BOOST_CHECK( fabs(delta(2)) < too_tiny );
  BOOST_CHECK( fabs(value_traits::one()-delta(3)) < too_tiny );
  BOOST_CHECK( fabs(delta(4)) < too_tiny );
  BOOST_CHECK( fabs(delta(5)) < too_tiny );

  //--- Next we will test a rotation part of goal placement ------
  chains[1].only_position() = false;
  chains[1].x_global() =  math_types::vector3_type(   value_traits::zero(), value_traits::zero(), value_traits::one() );
  chains[1].y_global() =  math_types::vector3_type(   value_traits::zero(), value_traits::one(), value_traits::zero() );
  chains[1].x_local()  =  math_types::vector3_type(   value_traits::one(),  value_traits::zero(), value_traits::zero() );
  chains[1].y_local()  =  math_types::vector3_type(   value_traits::zero(), value_traits::one(), value_traits::zero()  );

  // Set up some controlled relative transformation
  OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[3]),  0u, value_traits::zero() );
  OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[3]),  1u, value_traits::pi_half() );
  OpenTissue::kinematics::inverse::ACCESSOR::unsynch_set_theta( *(b[3]),  2u, value_traits::pi() );

  // We use get/set- joint paramters to make sure everything is initialized
  OpenTissue::kinematics::inverse::get_joint_parameters( skeleton, theta );
  OpenTissue::kinematics::inverse::set_joint_parameters( skeleton, theta );

  // Compute difference vector
  OpenTissue::kinematics::inverse::compute_weighted_difference( chains.begin(), chains.end(), delta );

  // Test if we have the expected values
  BOOST_CHECK( delta.size() == 12u );
  BOOST_CHECK( fabs(-value_traits::one() - delta(0)) < too_tiny );
  BOOST_CHECK( fabs(delta(1)) < too_tiny );
  BOOST_CHECK( fabs(delta(2)) < too_tiny );
  BOOST_CHECK( fabs(value_traits::one()-delta(3)) < too_tiny );
  BOOST_CHECK( fabs(delta(4)) < too_tiny );
  BOOST_CHECK( fabs(delta(5)) < too_tiny );
  BOOST_CHECK( fabs(delta(6)) < too_tiny );
  BOOST_CHECK( fabs(delta(7)) < too_tiny );
  BOOST_CHECK( fabs(delta(8)) < too_tiny );
  BOOST_CHECK( fabs(delta(9)) < too_tiny );
  BOOST_CHECK( fabs(delta(10)) < too_tiny );
  BOOST_CHECK( fabs(delta(11)) < too_tiny );

}

BOOST_AUTO_TEST_SUITE_END();

max_stars_repo_name: ricortiz/OpenTissue

max_issues_repo_name: ricortiz/OpenTissue

max_forks_repo_name: ricortiz/OpenTissue


text:
// Copyright Oleg Maximenko 2015.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://github.com/svgpp/svgpp for library home page.

#pragma once

#include <boost/array.hpp>
#include <svgpp/definitions.hpp>

namespace svgpp { namespace detail
{

template<class Number>
struct transform_events_interface
{
  virtual void transform_matrix(const boost::array<Number, 6> & matrix) = 0;
  virtual void transform_translate(Number tx, Number ty) = 0;
  virtual void transform_translate(Number tx) = 0;
  virtual void transform_scale(Number sx, Number sy) = 0;
  virtual void transform_scale(Number scale) = 0;
  virtual void transform_rotate(Number angle) = 0;
  virtual void transform_rotate(Number angle, Number cx, Number cy) = 0;
  virtual void transform_skew_x(Number angle) = 0;
  virtual void transform_skew_y(Number angle) = 0;
};

template<class Iterator, class Number>
bool parse_transform(Iterator & it, Iterator end, transform_events_interface<Number> & context);

}}

ext: hpp

max_stars_repo_name: RichardCory/svgpp


text:
/*
 * Copyright 2021 IFPEN-CEA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <map>
#include <mpi.h>

#include <boost/lexical_cast.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/cmdline.hpp>
#include <boost/program_options/variables_map.hpp>

#include <arccore/message_passing_mpi/StandaloneMpiMessagePassingMng.h>
#include <arccore/trace/ITraceMng.h>
#include <arccore/base/StringBuilder.h>

#include <alien/distribution/MatrixDistribution.h>
#include <alien/distribution/VectorDistribution.h>
#include <alien/index_manager/IIndexManager.h>
#include <alien/index_manager/IndexManager.h>
#include <alien/index_manager/functional/DefaultAbstractFamily.h>

#include <alien/ref/AlienRefSemantic.h>

#include <alien/kernels/simple_csr/algebra/SimpleCSRLinearAlgebra.h>
#include <alien/kernels/simple_csr/algebra/SimpleCSRInternalLinearAlgebra.h>

#ifdef ALIEN_USE_SYCL
#include <alien/kernels/sycl/SYCLPrecomp.h>
#include <alien/kernels/sycl/data/SYCLBEllPackMatrix.h>
#include <alien/kernels/sycl/data/SYCLVector.h>
#include <alien/kernels/sycl/algebra/SYCLLinearAlgebra.h>
#include <alien/kernels/sycl/algebra/SYCLInternalLinearAlgebra.h>

#include "alien/kernels/sycl/data/SYCLEnv.h"
#include "alien/kernels/sycl/data/SYCLEnvInternal.h"
#include <alien/kernels/sycl/algebra/SYCLKernelInternal.h>
#endif

#include <alien/expression/krylov/AlienKrylov.h>

#include <alien/utils/StdTimer.h>

namespace Environment
{
void initialize(int argc, char** argv)
{
  MPI_Init(&argc, &argv);
}

void finalize()
{
  MPI_Finalize();
}

Arccore::MessagePassing::IMessagePassingMng*
parallelMng()
{
  return Arccore::MessagePassing::Mpi::StandaloneMpiMessagePassingMng::create(
  MPI_COMM_WORLD);
}

Arccore::ITraceMng*
traceMng()
{
  return Arccore::arccoreCreateDefaultTraceMng();
}
} // namespace Environment

// Define index type for local ids
typedef Arccore::Integer LID;
// Define index type for global (unique) ids
typedef Arccore::Int64 UID;

int main(int argc, char** argv)
{

  // clang-format off
  using namespace boost::program_options ;
  options_description desc;
  desc.add_options()
      ("help",                                                            "produce help")
      ("nx",                  value<int>()->default_value(10),            "nx")
      ("ny",                  value<int>()->default_value(10),            "ny")
      ("solver",              value<std::string>()->default_value("bicgs"),"solver [cg,bicgs]")
      ("precond",             value<std::string>()->default_value("diag"),"preconditioner [diag,cheb,neumann,ilu0,filu0]")
      ("output-level",        value<int>()->default_value(0),             "output level")
      ("asynch",              value<int>()->default_value(0),             "Asynch mode synch : 0 or asynch 1")
      ("dot-algo",            value<int>()->default_value(0),             "dot algo choice")
      ("max-iter",            value<int>()->default_value(1000),          "max iterations")
      ("tol",                 value<double>()->default_value(1.e-6),      "tolerance")
      ("poly-factor",         value<double>()->default_value(0.5),        "polynome factor")
      ("poly-factor-max-iter",value<int>()->default_value(10),            "polynome factor max iterations")
      ("poly-order",          value<int>()->default_value(3),             "polynome order")
      ("filu-factor-niter",   value<int>()->default_value(0),             "nb ILU Factorization iter")
      ("filu-solver-niter",   value<int>()->default_value(3),             "nb ILU resolution iter")
      ("filu-tol",            value<double>()->default_value(3),          "nb ILU tolerance")
      ("kernel",              value<std::string>()->default_value("simplecsr"), "Kernel type [simplecsr sycl]")
      ("test",                value<std::string>()->default_value("solver"),    "test [solver,mult,all]");
  // clang-format on

  variables_map vm;
  store(parse_command_line(argc, argv, desc), vm);
  notify(vm);

  if (vm.count("help")) {
    std::cout << desc << "\n";
    return 1;
  }

  /*
   * Example : LAPLACIAN PROBLEM on a 2D square mesh of size NX x NY
   * Unknowns on nodes (i,j)
   * Use a 5-Points stencil
   *
   *
   *           (I,J+1)
   *              |
   * (I-1,J) -- (I,J) -- (I+1,J)
   *              |
   *           (I,J-1)
   *
   * TUTORIAL : LINEAR SYSTEM mat.X=rhs DEFINITION
   * =========================================
   */
  int Nx = vm["nx"].as<int>();
  int Ny = vm["ny"].as<int>();
  // int space_size = Nx * Ny;

  // INITIALIZE PARALLEL ENVIRONMENT
  Environment::initialize(argc, argv);

  auto parallel_mng = Environment::parallelMng();
  auto trace_mng = Environment::traceMng();

  auto comm_size = Environment::parallelMng()->commSize();
  auto comm_rank = Environment::parallelMng()->commRank();

  Arccore::StringBuilder filename("krylov.log");
  Arccore::ReferenceCounter<Arccore::ITraceStream> ofile;
  if (comm_size > 1) {
    filename += comm_rank;
    ofile = Arccore::ITraceStream::createFileStream(filename.toString());
    trace_mng->setRedirectStream(ofile.get());
  }
  trace_mng->finishInitialize();

  Alien::setTraceMng(trace_mng);
  Alien::setVerbosityLevel(Alien::Verbosity::Debug);

  trace_mng->info() << "INFO START KRYLOV TEST";
  trace_mng->info() << "NB PROC = " << comm_size;
  trace_mng->info() << "RANK    = " << comm_rank;
  trace_mng->flush();

  /*
     * MESH PARTITION ALONG Y AXIS
     *
     */
  int local_ny = Ny / comm_size;
  int r = Ny % comm_size;

  std::vector<int> y_offset(comm_size + 1);
  y_offset[0] = 0;
  for (int ip = 0; ip < r; ++ip)
    y_offset[ip + 1] = y_offset[ip] + local_ny + 1;

  for (int ip = r; ip < comm_size; ++ip)
    y_offset[ip + 1] = y_offset[ip] + local_ny;

  // Define a lambda function to compute node uids from the 2D (i,j) coordinates
  // (i,j) -> uid = node_uid(i,j)
  auto node_uid = [&](int i, int j) { return j * Nx + i; };

  /*
     * DEFINITION of Unknowns Unique Ids and  Local Ids
     */
  Alien::UniqueArray<UID> uid;
  Alien::UniqueArray<Arccore::Integer> owners;
  Alien::UniqueArray<LID> lid;
  std::map<UID, LID> uid2lid;
  int first_j = y_offset[comm_rank];
  int last_j = y_offset[comm_rank + 1];

  int index = 0;
  for (int j = first_j; j < last_j; ++j) {
    for (int i = 0; i < Nx; ++i) {
      int n_uid = node_uid(i, j);
      uid.add(n_uid);
      owners.add(comm_rank);
      lid.add(index);
      uid2lid[n_uid] = index;
      ++index;
    }
  }

  int nb_ghost = 0;
  if (comm_size > 1) {
    if (comm_rank > 0) {
      for (int i = 0; i < Nx; ++i) {
        int n_uid = node_uid(i, first_j - 1);
        uid.add(n_uid);
        owners.add(comm_rank - 1);
        lid.add(index);
        uid2lid[n_uid] = index;
        ++index;
        ++nb_ghost;
      }
    }
    if (comm_rank < comm_size - 1) {
      for (int i = 0; i < Nx; ++i) {
        int n_uid = node_uid(i, last_j);
        uid.add(n_uid);
        owners.add(comm_rank + 1);
        lid.add(index);
        uid2lid[n_uid] = index;
        ++index;
        ++nb_ghost;
      }
    }
  }

  /*
     * DEFINITION of an abstract family of unknowns
     */
  Alien::DefaultAbstractFamily family(uid, owners, parallel_mng);

  Alien::IndexManager index_manager(parallel_mng);

  /*
     * Creation of a set of indexes
     */
  auto indexSetU = index_manager.buildScalarIndexSet("U", family, 0);

  // Combine all index set and create Linear system index system
  index_manager.prepare();

  auto global_size = index_manager.globalSize();
  auto local_size = index_manager.localSize();

  trace_mng->info() << "GLOBAL SIZE : " << global_size;
  trace_mng->info() << "LOCAL SIZE  : " << local_size;
  trace_mng->info() << "GHOST SIZE  : " << nb_ghost;
  trace_mng->flush();

  /*
   * DEFINITION of
   * - Alien Space,
   * - matrix and vector distributions
   * to manage the distribution of indexes between all MPI processes
   */

  auto space = Alien::Space(global_size, "MySpace");

  auto matrix_dist =
  Alien::MatrixDistribution(global_size, global_size, local_size, parallel_mng);
  auto vector_dist = Alien::VectorDistribution(global_size, local_size, parallel_mng);

  trace_mng->info() << "MATRIX DISTRIBUTION INFO";
  trace_mng->info() << "GLOBAL ROW SIZE : " << matrix_dist.globalRowSize();
  trace_mng->info() << "LOCAL ROW SIZE  : " << matrix_dist.localRowSize();
  trace_mng->info() << "GLOBAL COL SIZE : " << matrix_dist.globalColSize();
  trace_mng->info() << "LOCAL COL SIZE  : " << matrix_dist.localColSize();

  trace_mng->info() << "VECTOR DISTRIBUTION INFO";
  trace_mng->info() << "GLOBAL SIZE : " << vector_dist.globalSize();
  trace_mng->info() << "LOCAL SIZE  : " << vector_dist.localSize();
  trace_mng->flush();

  auto allUIndex = index_manager.getIndexes(indexSetU);

  double off_diag = 0.5;
  /*
   *  Assemble matrix.
   */
  auto A = Alien::Matrix(matrix_dist);

  /* Two passes */

  // PROFILE DEFINITION
  {
    Alien::MatrixProfiler profiler(A);

    for (int j = first_j; j < last_j; ++j) {
      // BOUCLE SUIVANT AXE X
      for (int i = 0; i < Nx; ++i) {
        auto n_uid = node_uid(i, j);
        auto n_lid = uid2lid[n_uid];
        auto irow = allUIndex[n_lid];

        // DEFINE DIAGONAL
        profiler.addMatrixEntry(irow, irow);

        // OFF DIAG
        // lower
        if (j > 0) {
          auto off_uid = node_uid(i, j - 1);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1)
            profiler.addMatrixEntry(irow, jcol);
        }
        // left
        if (i > 0) {
          auto off_uid = node_uid(i - 1, j);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1)
            profiler.addMatrixEntry(irow, jcol);
        }
        // right
        if (i < Nx - 1) {
          auto off_uid = node_uid(i + 1, j);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1)
            profiler.addMatrixEntry(irow, jcol);
        }
        // upper
        if (j < Ny - 1) {
          auto off_uid = node_uid(i, j + 1);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1)
            profiler.addMatrixEntry(irow, jcol);
        }
      }
    }
  }

  // SECOND STEP : MATRIX FILLING STEP
  {
    Alien::ProfiledMatrixBuilder builder(A, Alien::ProfiledMatrixOptions::eResetValues);
    // Loop on Y-axis
    for (int j = first_j; j < last_j; ++j) {
      // Loop on X-axis
      for (int i = 0; i < Nx; ++i) {
        auto n_uid = node_uid(i, j);
        auto n_lid = uid2lid[n_uid];
        auto irow = allUIndex[n_lid];

        double diag = 0.;
        // OFF DIAG
        // lower
        if (j > 0) {
          auto off_uid = node_uid(i, j - 1);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1) {
            builder(irow, jcol) = -off_diag;
            diag += off_diag;
          }
        }
        // left
        if (i > 0) {
          auto off_uid = node_uid(i - 1, j);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1) {
            builder(irow, jcol) = -off_diag;
            diag += off_diag;
          }
        }
        // right
        if (i < Nx - 1) {
          auto off_uid = node_uid(i + 1, j);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1) {
            builder(irow, jcol) = -off_diag;
            diag += off_diag;
          }
        }
        if (i == Nx - 1) {
          // Dirichlet Boundary Condition on XMAX
          diag += off_diag;
        }

        // upper
        if (j < Ny - 1) {
          auto off_uid = node_uid(i, j + 1);
          auto off_lid = uid2lid[off_uid];
          auto jcol = allUIndex[off_lid];
          if (jcol != -1) {
            builder(irow, jcol) = -off_diag;
            diag += off_diag;
          }
        }
        // DIAGONAL
        builder(irow, irow) = diag;
      }
    }
  }

  /*
   * Build rhs vector
   */
  auto b = Alien::Vector(vector_dist);
  auto x = Alien::Vector(vector_dist);

  {
    Alien::VectorWriter writer_b(b);
    Alien::VectorWriter writer_x(x);

    // Loop on Y-axis
    for (int j = first_j; j < last_j; ++j) {
      // Loop on X-axis
      for (int i = 0; i < Nx; ++i) {
        auto n_uid = node_uid(i, j);
        auto n_lid = uid2lid[n_uid];
        auto irow = allUIndex[n_lid];

        //writer[irow] = 1. / (1. + i + j);
        //writer[irow] = 1. ;
        writer_b[irow] = 0.;
        writer_x[irow] = 0.;
        if (i == Nx - 1) {
          writer_b[irow] += off_diag;
        }
      }
    }
  }

  // clang-format off
  typedef Alien::StdTimer   TimerType ;
  typedef TimerType::Sentry SentryType ;
  // clang-format on

  TimerType timer;
  std::string kernel = vm["kernel"].as<std::string>();

  if (vm["test"].as<std::string>().compare("all") == 0 || vm["test"].as<std::string>().compare("mult") == 0) {

    auto x0 = Alien::Vector(vector_dist);
    auto y = Alien::Vector(vector_dist);
    {
      Alien::VectorWriter writer_x0(x0);
      writer_x0 = 1.;
    }

    // clang-format off
    auto run = [&](auto& alg)
              {
                typedef typename
                    boost::remove_reference<decltype(alg)>::type AlgebraType ;
                typedef typename AlgebraType::BackEndType        BackEndType ;
                typedef Alien::Iteration<AlgebraType>            StopCriteriaType ;

                auto const& true_A = A.impl()->get<BackEndType>() ;
                auto const& true_x0 = x0.impl()->get<BackEndType>() ;
                auto&       true_y = y.impl()->get<BackEndType>(true) ;

                alg.mult(true_A,true_x0,true_y) ;
              } ;
    // clang-format on

    if (kernel.compare("simplecsr") == 0) {
      Alien::SimpleCSRInternalLinearAlgebra alg;
      SentryType sentry(timer, "CSR-SPMV");
      run(alg);
    }
    if (kernel.compare("sycl") == 0) {
#ifdef ALIEN_USE_SYCL
      Alien::SYCLInternalLinearAlgebra alg;
      SentryType sentry(timer, "SYCL-SPMV");
      run(alg);
#else
      trace_mng->info() << "SYCL BackEnd not available";
#endif
    }
  }

  if (vm["test"].as<std::string>().compare("all") == 0 || vm["test"].as<std::string>().compare("solver") == 0) {
    // clang-format off
    int         max_iteration = vm["max-iter"].as<int>();
    double      tol           = vm["tol"].as<double>();
    std::string solver        = vm["solver"].as<std::string>();
    std::string precond       = vm["precond"].as<std::string>();
    int         output_level  = vm["output-level"].as<int>();
    int         asynch        = vm["asynch"].as<int>();
    // clang-format on

    // clang-format off
    auto run = [&](auto& alg)
              {
                typedef typename
                    boost::remove_reference<decltype(alg)>::type AlgebraType ;
                typedef typename AlgebraType::BackEndType        BackEndType ;
                typedef Alien::Iteration<AlgebraType>            StopCriteriaType ;

                auto const& true_A = A.impl()->get<BackEndType>() ;
                auto const& true_b = b.impl()->get<BackEndType>() ;
                auto&       true_x = x.impl()->get<BackEndType>(true) ;

                StopCriteriaType stop_criteria{alg,true_b,tol,max_iteration,output_level>0?trace_mng:nullptr} ;

                if(solver.compare("cg")==0)
                {
                  typedef Alien::CG<AlgebraType> SolverType ;

                  SolverType solver{alg,trace_mng} ;
                  solver.setOutputLevel(output_level) ;

                  if(precond.compare("diag")==0)
                    {
                      trace_mng->info()<<"DIAG PRECONDITIONER";
                      trace_mng->flush() ;
                      typedef Alien::DiagPreconditioner<AlgebraType> PrecondType ;
                      PrecondType      precond{alg,true_A} ;
                      precond.init() ;
                      SentryType sentry(timer,"CG-Diag") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("cheb")==0)
                    {
                      trace_mng->info()<<"CHEBYSHEV PRECONDITIONER";
                      double polynom_factor          = vm["poly-factor"].as<double>() ;
                      int    polynom_order           = vm["poly-order"].as<int>() ;
                      int    polynom_factor_max_iter = vm["poly-factor-max-iter"].as<int>() ;

                      typedef Alien::ChebyshevPreconditioner<AlgebraType> PrecondType ;
                      PrecondType      precond{alg,true_A,polynom_factor,polynom_order,polynom_factor_max_iter,trace_mng} ;
                      precond.setOutputLevel(output_level) ;
                      precond.init() ;

                      SentryType sentry(timer,"CG-ChebyshevPoly") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("neumann")==0)
                    {
                      trace_mng->info()<<"NEUMANN PRECONDITIONER";
                      double polynom_factor          = vm["poly-factor"].as<double>() ;
                      int    polynom_order           = vm["poly-order"].as<int>() ;
                      int    polynom_factor_max_iter = vm["poly-factor-max-iter"].as<int>() ;

                      typedef Alien::NeumannPolyPreconditioner<AlgebraType> PrecondType ;
                      PrecondType precond{alg,true_A,polynom_factor,polynom_order,polynom_factor_max_iter,trace_mng} ;
                      precond.init() ;

                      SentryType sentry(timer,"CG-NeumanPoly") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                }

                if(solver.compare("bicgs")==0)
                {
                  typedef Alien::BiCGStab<AlgebraType> SolverType ;
                  SolverType solver{alg,trace_mng} ;
                  solver.setOutputLevel(output_level) ;
                  if(precond.compare("diag")==0)
                    {
                      trace_mng->info()<<"DIAG PRECONDITIONER";
                      trace_mng->flush() ;
                      typedef Alien::DiagPreconditioner<AlgebraType> PrecondType ;
                      PrecondType      precond{alg,true_A} ;
                      precond.init() ;
                      SentryType sentry(timer,"BiCGS-Diag") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("cheb")==0)
                    {
                      trace_mng->info()<<"CHEBYSHEV PRECONDITIONER";
                      double polynom_factor          = vm["poly-factor"].as<double>() ;
                      int    polynom_order           = vm["poly-order"].as<int>() ;
                      int    polynom_factor_max_iter = vm["poly-factor-max-iter"].as<int>() ;

                      typedef Alien::ChebyshevPreconditioner<AlgebraType> PrecondType ;
                      PrecondType      precond{alg,true_A,polynom_factor,polynom_order,polynom_factor_max_iter,trace_mng} ;
                      precond.setOutputLevel(output_level) ;
                      precond.init() ;

                      SentryType sentry(timer,"BiCGS-ChebyshevPoly") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("neumann")==0)
                    {
                      trace_mng->info()<<"NEUMANN PRECONDITIONER";
                      double polynom_factor          = vm["poly-factor"].as<double>() ;
                      int    polynom_order           = vm["poly-order"].as<int>() ;
                      int    polynom_factor_max_iter = vm["poly-factor-max-iter"].as<int>() ;

                      typedef Alien::NeumannPolyPreconditioner<AlgebraType> PrecondType ;
                      PrecondType precond{alg,true_A,polynom_factor,polynom_order,polynom_factor_max_iter,trace_mng} ;
                      precond.init() ;

                      SentryType sentry(timer,"BiCGS-NeumanPoly") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("ilu0")==0)
                    {
                      trace_mng->info()<<"ILU0 PRECONDITIONER";
                      typedef Alien::ILU0Preconditioner<AlgebraType> PrecondType ;
                      PrecondType precond{alg,true_A,trace_mng} ;
                      precond.init() ;

                      SentryType sentry(timer,"BiCGS-ILU0") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                  if(precond.compare("filu0")==0)
                    {
                      trace_mng->info()<<"FILU0 PRECONDITIONER";
                      typedef Alien::FILU0Preconditioner<AlgebraType> PrecondType ;
                      PrecondType precond{alg,true_A,trace_mng} ;
                      precond.setParameter("nb-factor-iter",vm["filu-factor-niter"].as<int>()) ;
                      precond.setParameter("nb-solver-iter",vm["filu-solver-niter"].as<int>()) ;
                      precond.setParameter("tol",           vm["filu-tol"].as<double>()) ;
                      precond.init() ;

                      SentryType sentry(timer,"BiCGS-FILU0") ;
                      if(asynch==0)
                        solver.solve(precond,stop_criteria,true_A,true_b,true_x) ;
                      else
                        solver.solve2(precond,stop_criteria,true_A,true_b,true_x) ;
                    }
                }

                if(stop_criteria.getStatus())
                {
                  trace_mng->info()<<"Solver has converged";
                  trace_mng->info()<<"Nb iterations  : "<<stop_criteria();
                  trace_mng->info()<<"Criteria value : "<<stop_criteria.getValue();
                }
                else
                {
                  trace_mng->info()<<"Solver convergence failed";
                }
              } ;
    // clang-format on

    if (kernel.compare("simplecsr") == 0) {
      Alien::SimpleCSRInternalLinearAlgebra alg;
      run(alg);
    }
    if (kernel.compare("sycl") == 0) {
#ifdef ALIEN_USE_SYCL
      Alien::SYCLInternalLinearAlgebra alg;
      alg.setDotAlgo(vm["dot-algo"].as<int>());
      run(alg);
#else
      trace_mng->info() << "SYCL BackEnd not available";
#endif
    }
  }

  timer.printInfo(trace_mng->info().file(), "KRYLOV-BENCH");

  Environment::finalize();

  return 0;
}


text:
#include "asm_mode.h"

#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/tokenizer.hpp>

#include <crete/proc_reader.h>
#include <fstream>

using namespace std;
using namespace boost;
namespace fs = filesystem;
namespace po = program_options;

namespace crete
{

ASMMode::ASMMode(std::istream& is, std::ostream& os) :
    is_(is),
    os_(os),
    ops_descr_(make_options())
{
}

void ASMMode::start()
{
    display_welcome();
    run_shell();
}

void ASMMode::display_welcome()
{
    std::cout << "ASM mode initiated" << "\n"
            << "\t--help for the list of options" << "\n"
            << "\t--quit to exit" << endl;
}

void ASMMode::run_shell()
{
    auto next_cmd = string{};

    do
    {
        std::cout << ">> ";
        getline(is_, next_cmd);

    }while(process_options(next_cmd));
}

boost::program_options::options_description ASMMode::make_options()
{
    po::options_description desc("Options");

    desc.add_options()
        ("abs-addr,a", po::value<string>(), "get absolute address (hex (0xN) or dec)")
        ("batch,b", po::value<fs::path>(), "batch mode of hex mode")
        ("dec-addr,d", po::value<string>(), "get absolute address (dec)")
        ("hex-addr,h", po::value<string>(), "get absolute address (hex)")
        ("quit,q", "exit shell")
        ("help", "displays help message")
        ("proc-maps,p", po::value<fs::path>(), "set proc-maps file")
        ;

    return desc;
}

bool ASMMode::process_options(const std::string& opts)
{
    auto args = tokenize_options(opts);
    boost::program_options::variables_map var_map;
    try
    {
        po::store(po::command_line_parser(args).options(ops_descr_).run(), var_map);
        po::notify(var_map);
    }
    catch(std::exception& e) // Failed to parse.
    {
        cerr << e.what() << endl;
        return true;
    }

    if(var_map.size() == 0)
    {
        cout << "Unknown command or missing arguments" << endl;
        cout << "Use '--help' for more details" << endl;

        return true;
    }
    if(var_map.count("abs-addr"))
    {
        auto addr = var_map["abs-addr"].as<string>();
        uint64_t res = 0;

        if(addr.at(0) == '0' && addr.at(1) == 'x')
        {
            res = parse_hex(addr);
        }
        else
        {
            res = parse_dec(addr);
        }

        process_address(res);

        return true;
    }
    if(var_map.count("hex-addr"))
    {
        auto addr = var_map["hex-addr"].as<string>();

        process_address(parse_hex(addr));

        return true;
    }
    if(var_map.count("dec-addr"))
    {
        auto addr = var_map["dec-addr"].as<string>();

        process_address(parse_dec(addr));

        return true;
    }
    if(var_map.count("exit"))
    {
        return false;
    }
    if(var_map.count("help"))
    {
        cout << ops_descr_ << endl;

        return true;
    }
    if(var_map.count("proc-maps"))
    {
        auto path = var_map["proc-maps"].as<fs::path>();
        if(!fs::exists(path))
        {
            cerr << "invalid path: " << path << endl;
            return true;
        }

        parse_proc_maps(path);

        return true;
    }
    if(var_map.count("batch"))
    {
        auto path = var_map["batch"].as<fs::path>();
        if(!fs::exists(path))
        {
            cerr << "invalid path: " << path << endl;
            return true;
        }

        std::ifstream in_f(path.string(), std::ifstream::in);

        std::string addr;
        while(std::getline(in_f, addr)) {
            if(!addr.empty()){
//                fprintf(stderr, "addr = 0x%s\n", addr.c_str());
                process_address(parse_hex(addr));
            }
        }

        return true;
    }

    return false;
}

std::vector<string> ASMMode::tokenize_options(const string& opts)
{
    escaped_list_separator<char> separator("\\", "= ", "\"\'");

    tokenizer<escaped_list_separator<char>> tokens(opts, separator);

    vector<string> args;
    copy_if(tokens.begin(),
            tokens.end(),
            back_inserter(args),
            [](const string& s) { return !s.empty(); });

    return args;
}

void ASMMode::parse_proc_maps(const filesystem::path& path)
{
    addr_ranges_.clear();

    ProcReader reader{path};

    auto maps = reader.find_all();

    for(const auto& m : maps)
    {
        auto range = AddressRange{};

        range.low_ = m.address().first;
        range.high_ = m.address().second;
        range.path_ = m.path();

        addr_ranges_.push_back(range);
    }
}

bool ASMMode::have_proc_map() const
{
    return !addr_ranges_.empty();
}

void ASMMode::process_address(uint64_t addr) const
{
    if(have_proc_map())
    {
        auto it = find_if(addr_ranges_.begin(), addr_ranges_.end(), [&addr](const AddressRange& range) {
           if(range.high_ >= addr &&
              range.low_ <= addr) return true;
           return false;
        });

        if(it != addr_ranges_.end())
        {
            auto& r = *it;

            if(it->path_.stem() != "harness") // Don't offset the binary.
            {
                auto offset = addr - r.low_;

                os_ << "0x"
                    << hex << offset << dec
                    << " : "
                    << r.path_.stem()
                    << endl;

                return;
            }
            else
            {
                os_ << "0x"
                    << hex << addr << dec
                    << " : "
                    << "harness"
                    << endl;

                return;
            }
        }
        else
        {
            os_ << "Warning: address not in any proc-maps ranges\n";
        }
    }
    else
    {
        os_ << "proc_map does not exist!\n";
    }

    os_ << "0x"
        << hex << addr << dec
        << endl;
}

uint64_t ASMMode::parse_hex(const string& s) const
{
    uint64_t res = 0;

    stringstream ss;
    if(s.at(0) == '0' && s.at(1) == 'x')
    {
        ss << hex << s.substr(2, s.size() - 2);
        ss >> hex >> res;
    }
    else // Still hex, but no 0x-prefix.
    {
        ss << hex << s;
        ss >> hex >> res;
    }

    return res;
}

uint64_t ASMMode::parse_dec(const string& s) const
{
    uint64_t res = 0;

    if(s.at(0) == '0' && s.at(1) == 'x')
        cerr << "Warning: 0x-prefix given, but decimal expected.\n";

    stringstream ss;
    ss << dec << s;
    ss >> dec >> res;

    return res;
}

bool operator==(const AddressRange& lhs, const AddressRange& rhs)
{
    if(lhs.path_ == rhs.path_)
    {
        assert(lhs.low_ == rhs.low_ && lhs.high_ == rhs.high_);
        return true;
    }
    return false;
}

bool operator==(const AddressRange& lhs, const filesystem::path& rhs)
{
    return lhs.path_ == rhs;
}

bool operator==(const filesystem::path& lhs, const AddressRange& rhs)
{
    return rhs == lhs;
}

bool operator==(const AddressRange& lhs, const uint64_t& rhs)
{
    return lhs.low_ <= rhs && lhs.high_ >= rhs;
}

bool operator==(const uint64_t& lhs, const AddressRange& rhs)
{
    return rhs == lhs;
}

} // namespace crete


text:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include "RayTrace.h"
#include "RayTrace_IceModels.h"

struct underline{
	static char esc;
	const std::string& str;
	underline(const std::string& s):str(s){}
	friend std::ostream& operator<<(std::ostream& os, const underline& u);
};

char underline::esc=0x1B;

std::ostream& operator<<(std::ostream& os, const underline& u){
	return(os << underline::esc << "[4m" << u.str << underline::esc << "[0m");
}

template<typename positionType>
class pathPrinter{
public:
	pathPrinter(){}
	void operator()(const positionType& p, RayTrace::RKStepType stepType){
		std::cout << p.x << ' ' << p.z << '\n';
	}
};

int main(int argc, char* argv[]){
	double ns,nd,nc;
	double src_x, src_y, src_z, trg_x, trg_y, trg_z;
	Vector src,trg;
	bool showLabels=true;
	bool dumpPaths=false;
	bool surface_reflect;
	bool bedrock_reflect;
	double requiredAccuracy;
	double frequency;
	double polarization;
	boost::shared_ptr<RayTrace::indexOfRefractionModel> refractionModel;
	std::string refractionName;
	boost::shared_ptr<RayTrace::attenuationModel> attenuationModel;
	std::string attenuationName;

	boost::program_options::options_description desc("Allowed options");
	desc.add_options()
		("help,h","print usage information")
		("src_x",boost::program_options::value<double>(&src_x),"source x coordinate")
		("src_y",boost::program_options::value<double>(&src_y),"source y coordinate")
		("src_z",boost::program_options::value<double>(&src_z),"source z coordinate")
		("trg_x",boost::program_options::value<double>(&trg_x),"target x coordinate")
		("trg_y",boost::program_options::value<double>(&trg_y),"target y coordinate")
		("trg_z",boost::program_options::value<double>(&trg_z),"target z coordinate")
		("quiet,q","quiet, hide column labels")
		("show_paths,p","show paths; print out x and z coordinates of points visited along each path. Suppresses ordinary output")
		("n_s",boost::program_options::value<double>(&ns)->default_value(1.35),"surface index of refraction")
		("n_d",boost::program_options::value<double>(&nd)->default_value(1.78),"deep index of refraction")
		("n_c",boost::program_options::value<double>(&nc)->default_value(.0132),"index of refraction transition coefficient")
		("reflect_surface",boost::program_options::value<bool>(&surface_reflect)->default_value(true),"whether to search for surface\nreflected solutions")
		("reflect_bedrock",boost::program_options::value<bool>(&bedrock_reflect)->default_value(false),"whether to search for bedrock\nreflected solutions")
		("accuracy",boost::program_options::value<double>(&requiredAccuracy)->default_value(0.1),"the maximum acceptable vertical miss distance in meters")
		("frequency",boost::program_options::value<double>(&frequency)->default_value(300),"the frequency of the signal, in MHz")
		("polarization",boost::program_options::value<double>(&polarization)->default_value(RayTrace::pi/2),"the angle of the signal polarization, relative to the plane of propagation, in radians")
		("index_of_refraction",boost::program_options::value<std::string>(&refractionName)->default_value("exponential"),
		 "the index of refraction function of the ice, recognized values are 'exponential', 'inverse_exponential', 'quadratic', 'todor_linear', 'todor_chi', and 'todor_LL'")
		("attenuation",boost::program_options::value<std::string>(&attenuationName)->default_value("besson"),"the attenuation function of the ice, recognized values are 'negligible' and 'besson'")
	;
	boost::program_options::positional_options_description p;
	p.add("src_x", 1);
	p.add("src_y", 1);
	p.add("src_z", 1);
	p.add("trg_x", 1);
	p.add("trg_y", 1);
	p.add("trg_z", 1);

	boost::program_options::variables_map vm;
	try{
		boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
		boost::program_options::notify(vm);
	}catch(std::exception& except){
		std::cerr << "Caught an exception during argument parsing: " << except.what() << std::endl;
		return(1);
	}catch(...){
		std::cerr << "An unknown exception was caught during argument parsing" << std::endl;
		return(1);
	}

	if (vm.count ("help") || argc < 2) {
		std::cout << "Usage: ray_solver [OPTION]... " << underline("src.x") << ' ' << underline("src.y") << ' ' << underline("src.z") << ' '
		<< underline("trg.x") << ' ' << underline("trg.y") << ' ' << underline("trg.z") << std::endl;
		std::cout << desc << std::endl;
		std::cout << "Angles are measured in radians from the downward vertical" << std::endl;
		std::cout << "The reported attenuation includes the effects of the ice attenuation model and reflections." << std::endl;
		std::cout << "The (electric field) amplitude value reported combines the attenuation with the divergence of rays." << std::endl;
		return(0);
	}
	if(vm.count("quiet"))
	   showLabels=false;
	if(vm.count("show_paths")){
		dumpPaths=true;
		showLabels=false;
	}
	if(refractionName=="exponential")
		refractionModel=boost::shared_ptr<exponentialRefractiveIndex>(new exponentialRefractiveIndex(ns,nd,nc));
		//refractionModel=boost::make_shared<exponentialRefractiveIndex>(ns,nd,nc);
	else if(refractionName=="inverse_exponential")
		refractionModel=boost::shared_ptr<inverseExponentialRefractiveIndex>(new inverseExponentialRefractiveIndex(ns,nd,nc));
		//refractionModel=boost::make_shared<inverseExponentialRefractiveIndex>(ns,nd,nc);
	else if(refractionName=="quadratic")
		refractionModel=boost::shared_ptr<quadraticRefractiveIndex>(new quadraticRefractiveIndex(ns,nd,nc));
		//refractionModel=boost::make_shared<quadraticRefractiveIndex>(ns,nd,nc);
	else if(refractionName=="todor_linear")
		refractionModel=boost::shared_ptr<todorLinearRefractiveIndex>(new todorLinearRefractiveIndex(ns,nd));
		//refractionModel=boost::make_shared<todorLinearRefractiveIndex>(ns,nd);
	else if(refractionName=="todor_chi")
		refractionModel=boost::shared_ptr<todorChiRefractiveIndex>(new todorChiRefractiveIndex(ns,nd));
		//refractionModel=boost::make_shared<todorChiRefractiveIndex>(ns,nd);
	else if(refractionName=="todor_LL")
		refractionModel=boost::shared_ptr<todorLLRefractiveIndex>(new todorLLRefractiveIndex(ns,nd));
		//refractionModel=boost::make_shared<todorLLRefractiveIndex>(ns,nd);
	else{
		std::cerr << "Unrecognized refraction model name '" << refractionName << "'" << std::endl;
		return(1);
	}
	if(attenuationName=="besson")
		attenuationModel=boost::shared_ptr<basicAttenuationModel>(new basicAttenuationModel);
		//attenuationModel=boost::make_shared<basicAttenuationModel>();
	else if(attenuationName=="negligible")
		attenuationModel=boost::shared_ptr<negligibleAttenuationModel>(new negligibleAttenuationModel);
		//attenuationModel=boost::make_shared<negligibleAttenuationModel>();
	else{
		std::cerr << "Unrecognized attenuation model name '" << attenuationName << "'" << std::endl;
		return(1);
	}

	unsigned short refl = RayTrace::NoReflection;
	if(surface_reflect)
		refl|=RayTrace::SurfaceReflection;
	if(bedrock_reflect)
		refl|=RayTrace::BedrockReflection;

	src.SetX(src_x);
	src.SetY(src_y);
	src.SetZ(src_z);
	trg.SetX(trg_x);
	trg.SetY(trg_y);
	trg.SetZ(trg_z);

	std::vector<RayTrace::TraceRecord> paths;

	RayTrace::TraceFinder tf(refractionModel,attenuationModel);

	paths=tf.findPaths(src,trg,frequency/1.0e3,polarization,refl,requiredAccuracy);
	if(showLabels){
		if(!paths.empty()){
			std::cout << std::fixed
			<< "path length (m) "
			<< "path time (ns) "
			<< "launch angle "
			<< "recipt angle "
			<< "reflect angle "
			<< "miss dist. "
			<< "attenuation "
			<< "amplitude"
			<< std::endl;
		}
		else
			std::cout << "No solutions" << std::endl;
	}
	if(!dumpPaths){
		for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
			double signal = tf.signalStrength(*it,src,trg,refl);
			std::cout << std::left << std::fixed
			<< std::setprecision(2) << std::setw(15) << it->pathLen << ' '
			<< std::setprecision(2) << std::setw(14) << 1e9*it->pathTime << ' '
			<< std::setprecision(4) << std::setw(12) << it->launchAngle << ' '
			<< std::setprecision(4) << std::setw(12) << it->receiptAngle << ' '
			<< std::setprecision(3) << std::setw(13) << it->reflectionAngle << ' '
			<< std::setprecision(2) << std::setw(10) << it->miss << ' '
			<< std::scientific << std::setprecision(4) << std::setw(11) << it->attenuation << ' '
			//amplitude calculation, ignoring frequency response at both ends, angular response of receiver
			<< std::setw(10) << (it->attenuation*signal)
			<< std::endl;
		}
	}
	else{ //do write out path data
		pathPrinter<RayTrace::minimalRayPosition> print;
		for(std::vector<RayTrace::TraceRecord>::const_iterator it=paths.begin(); it!=paths.end(); ++it){
			tf.doTrace<RayTrace::minimalRayPosition>(src_z, it->launchAngle, RayTrace::rayTargetRecord(trg_z,sqrt((trg_x-src_x)*(trg_x-src_x)+(trg_y-src_y)*(trg_y-src_y))), refl, 0.0, 0.0, &print);
			std::cout << "\n\n";
		}
	}
	return(0);
}

max_stars_repo_name: shrishabh/phasedArray

max_issues_repo_name: shrishabh/phasedArrayOptimized

max_forks_repo_name: shrishabh/phasedArrayOptimized


text:
//
// Copyright (c) 2016-2019 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/sml.hpp>
#include <map>
#include <string>
#include <type_traits>

namespace sml = boost::sml;

struct e1 {};
struct e2 {};
struct e3 {};

const auto idle = sml::state<class idle>;
const auto s1 = sml::state<class s1>;
const auto is_handled = sml::state<class is_handled>;
const auto errors = sml::state<class errors>;

test unexpected_event_empty = [] {
  struct c {
    auto operator()() const {
      using namespace sml;
      // clang-format off
      return make_transition_table(
        *idle + unexpected_event<e1> = X
      );
      // clang-format on
    }
  };

  sml::sm<c> sm;
  sm.process_event(e1{});
  expect(sm.is(sml::X));
};

test unexpected_specific_initial_state = [] {
  struct c {
    auto operator()() const {
      using namespace sml;
      // clang-format off
      return make_transition_table(
         (*idle) + event<e1> / []{},
           idle  + unexpected_event<e2> = X
      );
      // clang-format on
    }
  };

  sml::sm<c> sm;
  using namespace sml;
  sm.process_event(e1{});
  expect(sm.is(idle));
  sm.process_event(e2{});
  expect(sm.is(X));
};

test unexpected_specific_event = [] {
  struct c {
    auto operator()() const {
      using namespace sml;
      // clang-format off
      return make_transition_table(
        (*idle)      + event<e1> = is_handled,
          is_handled + unexpected_event<e1> = X
      );
      // clang-format on
    }
  };

  sml::sm<c> sm;
  using namespace sml;
  sm.process_event(e1{});
  expect(sm.is(is_handled));
  sm.process_event(e1{});
  expect(sm.is(X));
};

test unexpected_specific_event_with_data = [] {
  struct event_data {
    int i;
  };
  struct c {
    auto operator()() const {
      using namespace sml;
      // clang-format off
      return make_transition_table(
         *(idle)      + event<e1> = is_handled,
           is_handled + unexpected_event<event_data>
              / [](const event_data& e) { expect(42 == e.i); } = X
      );
      // clang-format on
    }
  };

  sml::sm<c> sm;
  using namespace sml;
  sm.process_event(e1{});
  expect(sm.is(is_handled));
  sm.process_event(event_data{42});
  expect(sm.is(X));
};

template <class TCalls, class T>
struct handle_unexpected_events {
  template <class TEvent>
  void operator()(const TEvent&, int& i) {
    expect(std::is_same<TEvent, T>::value);
    expect(42 == i);
    ++ue_calls[TCalls::unexpected_event_any];
  }
  std::map<TCalls, int>& ue_calls;
};

test unexpected_any_event = [] {
  enum class calls { unexpected_event_e1, unexpected_event_e2, unexpected_event_any };
  struct c {
    auto operator()() {
      using namespace sml;
      // clang-format off
      return make_transition_table(
        (*idle)      + event<e1> = is_handled,
          is_handled + unexpected_event<e1> / [this] { ++ue_calls[calls::unexpected_event_e1]; },
          is_handled + unexpected_event<e2> / [this](int& i) { i = 42; ++ue_calls[calls::unexpected_event_e2]; },
          is_handled + unexpected_event<_>  / handle_unexpected_events<calls, e3>{ue_calls} = X
      );
      // clang-format on
    }

    std::map<calls, int> ue_calls;
  };

  int i = 0;
  sml::sm<c> sm{i};
  c& c_ = sm;
  using namespace sml;
  sm.process_event(e1{});
  expect(sm.is(is_handled));

  sm.process_event(e1{});
  expect(1 == c_.ue_calls[calls::unexpected_event_e1]);
  expect(0 == c_.ue_calls[calls::unexpected_event_e2]);
  expect(0 == c_.ue_calls[calls::unexpected_event_any]);
  expect(sm.is(is_handled));

  sm.process_event(e1{});
  expect(2 == c_.ue_calls[calls::unexpected_event_e1]);
  expect(0 == c_.ue_calls[calls::unexpected_event_e2]);
  expect(0 == c_.ue_calls[calls::unexpected_event_any]);
  expect(sm.is(is_handled));

  sm.process_event(e2{});
  expect(2 == c_.ue_calls[calls::unexpected_event_e1]);
  expect(1 == c_.ue_calls[calls::unexpected_event_e2]);
  expect(0 == c_.ue_calls[calls::unexpected_event_any]);
  expect(sm.is(is_handled));

  sm.process_event(e1{});
  expect(3 == c_.ue_calls[calls::unexpected_event_e1]);
  expect(1 == c_.ue_calls[calls::unexpected_event_e2]);
  expect(0 == c_.ue_calls[calls::unexpected_event_any]);
  expect(sm.is(is_handled));

  sm.process_event(e3{});
  expect(3 == c_.ue_calls[calls::unexpected_event_e1]);
  expect(1 == c_.ue_calls[calls::unexpected_event_e2]);
  expect(1 == c_.ue_calls[calls::unexpected_event_any]);
  expect(sm.is(X));
};

test unexpected_event_orthogonal_region = [] {
  struct c {
    auto operator()() const {
      using namespace sml;
      // clang-format off
      return make_transition_table(
        *(idle)   + event<e1> = s1,
        *(errors) + unexpected_event<e2> = X
      );
      // clang-format on
    }
  };

  sml::sm<c> sm;
  using namespace sml;

  sm.process_event(e1{});
  expect(sm.is(s1, errors));

  sm.process_event(e1{});
  expect(sm.is(s1, errors));

  sm.process_event(e2{});
  expect(sm.is(s1, X));
};

max_stars_repo_name: GuiCodron/sml

max_issues_repo_name: GuiCodron/sml

max_forks_repo_name: GuiCodron/sml


text:
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.

// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <geometry_test_common.hpp>

#include <boost/geometry/core/access.hpp>

#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/algorithms/make.hpp>

#include <boost/geometry/geometries/adapted/c_array.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>

#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/geometries/box.hpp>

BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

template <typename G>
void test_get_set()
{
    typedef typename bg::coordinate_type<G>::type coordinate_type;

    G g;
    bg::set<0>(g, coordinate_type(1));
    bg::set<1>(g, coordinate_type(2));

    coordinate_type x = bg::get<0>(g);
    coordinate_type y = bg::get<1>(g);

    BOOST_CHECK_CLOSE(double(x), 1.0, 0.0001);
    BOOST_CHECK_CLOSE(double(y), 2.0, 0.0001);
}

template <typename G>
void test_indexed_get_set(G& g)
{
    bg::set<0, 0>(g, 1);
    bg::set<0, 1>(g, 2);
    bg::set<1, 0>(g, 3);
    bg::set<1, 1>(g, 4);

    typedef typename bg::coordinate_type<G>::type coordinate_type;
    coordinate_type x1 = bg::get<0, 0>(g);
    coordinate_type y1 = bg::get<0, 1>(g);
    coordinate_type x2 = bg::get<1, 0>(g);
    coordinate_type y2 = bg::get<1, 1>(g);

    BOOST_CHECK_CLOSE(double(x1), 1.0, 0.0001);
    BOOST_CHECK_CLOSE(double(y1), 2.0, 0.0001);
    BOOST_CHECK_CLOSE(double(x2), 3.0, 0.0001);
    BOOST_CHECK_CLOSE(double(y2), 4.0, 0.0001);
}

template <typename G, typename T>
void test_indexed_get(G const& g, T a, T b, T c, T d)
{
    T x1 = bg::get<0, 0>(g);
    T y1 = bg::get<0, 1>(g);
    T x2 = bg::get<1, 0>(g);
    T y2 = bg::get<1, 1>(g);

    BOOST_CHECK_CLOSE(double(x1), double(a), 0.0001);
    BOOST_CHECK_CLOSE(double(y1), double(b), 0.0001);
    BOOST_CHECK_CLOSE(double(x2), double(c), 0.0001);
    BOOST_CHECK_CLOSE(double(y2), double(d), 0.0001);
}

template <typename P>
void test_all()
{
    typedef typename bg::coordinate_type<P>::type coordinate_type;

    // POINT, setting coordinate
    test_get_set<P>();

    // BOX, setting left/right/top/bottom
    bg::model::box<P> b;
    test_indexed_get_set(b);

    // SEGMENT (in GGL not having default constructor; however that is not a requirement)
    P p1 = bg::make_zero<P>();
    P p2 = bg::make_zero<P>();
    bg::model::referring_segment<P> s(p1, p2);
    test_indexed_get_set(s);

    // CONST SEGMENT
    bg::set<0>(p1, 1); // we don't use assign because dim in {2,3}
    bg::set<1>(p1, 2);
    bg::set<0>(p2, 3);
    bg::set<1>(p2, 4);
    bg::model::referring_segment<P const> cs(p1, p2);
    test_indexed_get(cs,
        coordinate_type(1), coordinate_type(2),
        coordinate_type(3), coordinate_type(4));
}

int test_main(int, char* [])
{
    test_get_set<int[2]>();
    test_get_set<float[2]>();
    test_get_set<double[2]>();
    test_get_set<double[3]>();

    test_get_set<boost::tuple<double, double> >();

    test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
    test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
    test_all<bg::model::point<double, 2, bg::cs::cartesian> >();

    return 0;
}