<commit_before>/// @file frac_comp_ient.cpp
/// @brief Implementation of finding fractions/completions intersections with mesh
/// @author uentity
/// @version 
/// @date 06.10.2011
/// @copyright This source code is released under the terms of
///            the BSD License. See LICENSE for more details.

#include "frac_comp_ident.h"
#include "bcsr_matrix_iface.h"
#include "wpi_algo.h"
#include "wpi_strategy_3d.h"
#include "export_python_wrapper.h"
#include "py_list_converter.h"

#include <boost/format.hpp>
#include <iosfwd>
#include <iostream>

namespace blue_sky { namespace fci {
// impl details
using namespace std;
using namespace wpi;

typedef algo< strategy_3d > wpi_algo;

// hidden details
namespace {

/*-----------------------------------------------------------------
 * search different tables
 *----------------------------------------------------------------*/
struct fract_traits  {
	static boost::format select_unique_well_branch() {
		return boost::format("SELECT DISTINCT well_name, branch_name FROM fractures WHERE d=%f");
	}

	static boost::format select_segment() {
		return boost::format(
			"SELECT md, half_length1 + half_length_2 FROM fractures WHERE d=%f and well_name='%s' and branch_name='%s'"
		);
	}
};

struct compl_traits {
	static boost::format select_unique_well_branch() {
		return boost::format("SELECT DISTINCT well_name, branch_name FROM completions WHERE d=%f");
	}

	static boost::format select_segment() {
		return boost::format(
			"SELECT md, length FROM completions WHERE d=%f and well_name='%s' and branch_name='%s'"
		);
	}
};

// simple dump
void dump(std::ostream& os, const compdat& cd) {
	os << setw(15) << cd.well_name << ' ' << setw(15) << cd.branch_name << ' ';
	for(int i = 0; i < 4; ++i)
		os << setw(4) << cd.cell_pos[i];
	os << setw(2) << cd.dir;
	os << setw(10) << std::fixed << std::setprecision(3) << cd.kh_mult << std::endl;
}

void dump(std::ostream& os, const cd_storage& cfs) {
	for(cd_storage::const_iterator pc = cfs.begin(), end = cfs.end(); pc != end; ++pc)
		dump(os, *pc);
}

}  // oef hidden namespace

/*-----------------------------------------------------------------
 * compdat
 *----------------------------------------------------------------*/
compdat::compdat(const string& well_name_, const string& branch_name_, const pos_i& cell_pos_, const pos_i& mesh_size)
	: well_name(well_name_), branch_name(branch_name_), dir(' '), kh_mult(0)
{
	copy(&cell_pos_[0], &cell_pos_[strategy_3d::D], &cell_pos[0]);
	cell_pos[3] = cell_pos[2];
	cell_id_ = wpi_algo::encode_cell_id(cell_pos_, mesh_size);
}

compdat::compdat(const string& well_name_, const string& branch_name_, ulong cell_id, const pos_i& mesh_size)
	: well_name(well_name_), branch_name(branch_name_), dir(' '), kh_mult(0), cell_id_(cell_id)
{
	pos_i cell_pos_;
	wpi_algo::decode_cell_id(cell_id, cell_pos_, mesh_size);
	copy(&cell_pos_[0], &cell_pos_[strategy_3d::D], &cell_pos[0]);
	cell_pos[3] = cell_pos[2];
}

compdat::compdat(ulong cell_id)
	: dir(' '), kh_mult(0), cell_id_(cell_id)
{}

/*-----------------------------------------------------------------
 * compdat_builder::impl
 *----------------------------------------------------------------*/
class compdat_builder::impl {
public:
	//typedef algo< strategy_3d > wpi_algo;
	typedef typename wpi_algo::trimesh trimesh;
	typedef typename wpi_algo::well_path well_path;
	typedef typename wpi_algo::well_hit_cell whc;
	typedef typename wpi_algo::intersect_path xpath;
	typedef typename wpi_algo::hit_idx_t hit_idx_t;
	typedef typename wpi_algo::xbuilder xbuilder;
	//typedef intersect_builder2< strategy_3d > xbuilder;

	typedef typename strategy_3d::vertex_pos_i vertex_pos_i;
	typedef typename strategy_3d::vertex_pos vertex_pos;
	typedef typename mesh_tools< strategy_3d>::mesh_part mesh_part;

	typedef typename sql_well::sp_traj_t sp_traj_t;
	typedef typename sql_well::sp_table_t sp_table_t;

	typedef multimap< string, string > wb_storage;
	typedef typename xpath::iterator x_iterator;

	impl(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn) {
		init(nx, ny, coord, zcorn);
	}

	impl(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn,
		smart_ptr< sql_well > src_well)
	{
		init(nx, ny, coord, zcorn);
		init(src_well);
	}

	void init(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn) {
		// build trimesh for given coord+zcorn
		tops_ = wpi_algo::coord_zcorn2trimesh(nx, ny, coord, zcorn, m_, m_size_, true);<commit_msg>FCI: don't auto-free COORD & ZCORN arrays in compdat_builder<commit_after>/// @file frac_comp_ient.cpp
/// @brief Implementation of finding fractions/completions intersections with mesh
/// @author uentity
/// @version 
/// @date 06.10.2011
/// @copyright This source code is released under the terms of
///            the BSD License. See LICENSE for more details.

#include "frac_comp_ident.h"
#include "bcsr_matrix_iface.h"
#include "wpi_algo.h"
#include "wpi_strategy_3d.h"
#include "export_python_wrapper.h"
#include "py_list_converter.h"

#include <boost/format.hpp>
#include <iosfwd>
#include <iostream>

namespace blue_sky { namespace fci {
// impl details
using namespace std;
using namespace wpi;

typedef algo< strategy_3d > wpi_algo;

// hidden details
namespace {

/*-----------------------------------------------------------------
 * search different tables
 *----------------------------------------------------------------*/
struct fract_traits  {
	static boost::format select_unique_well_branch() {
		return boost::format("SELECT DISTINCT well_name, branch_name FROM fractures WHERE d=%f");
	}

	static boost::format select_segment() {
		return boost::format(
			"SELECT md, half_length1 + half_length_2 FROM fractures WHERE d=%f and well_name='%s' and branch_name='%s'"
		);
	}
};

struct compl_traits {
	static boost::format select_unique_well_branch() {
		return boost::format("SELECT DISTINCT well_name, branch_name FROM completions WHERE d=%f");
	}

	static boost::format select_segment() {
		return boost::format(
			"SELECT md, length FROM completions WHERE d=%f and well_name='%s' and branch_name='%s'"
		);
	}
};

// simple dump
void dump(std::ostream& os, const compdat& cd) {
	os << setw(15) << cd.well_name << ' ' << setw(15) << cd.branch_name << ' ';
	for(int i = 0; i < 4; ++i)
		os << setw(4) << cd.cell_pos[i];
	os << setw(2) << cd.dir;
	os << setw(10) << std::fixed << std::setprecision(3) << cd.kh_mult << std::endl;
}

void dump(std::ostream& os, const cd_storage& cfs) {
	for(cd_storage::const_iterator pc = cfs.begin(), end = cfs.end(); pc != end; ++pc)
		dump(os, *pc);
}

}  // oef hidden namespace

/*-----------------------------------------------------------------
 * compdat
 *----------------------------------------------------------------*/
compdat::compdat(const string& well_name_, const string& branch_name_, const pos_i& cell_pos_, const pos_i& mesh_size)
	: well_name(well_name_), branch_name(branch_name_), dir(' '), kh_mult(0)
{
	copy(&cell_pos_[0], &cell_pos_[strategy_3d::D], &cell_pos[0]);
	cell_pos[3] = cell_pos[2];
	cell_id_ = wpi_algo::encode_cell_id(cell_pos_, mesh_size);
}

compdat::compdat(const string& well_name_, const string& branch_name_, ulong cell_id, const pos_i& mesh_size)
	: well_name(well_name_), branch_name(branch_name_), dir(' '), kh_mult(0), cell_id_(cell_id)
{
	pos_i cell_pos_;
	wpi_algo::decode_cell_id(cell_id, cell_pos_, mesh_size);
	copy(&cell_pos_[0], &cell_pos_[strategy_3d::D], &cell_pos[0]);
	cell_pos[3] = cell_pos[2];
}

compdat::compdat(ulong cell_id)
	: dir(' '), kh_mult(0), cell_id_(cell_id)
{}

/*-----------------------------------------------------------------
 * compdat_builder::impl
 *----------------------------------------------------------------*/
class compdat_builder::impl {
public:
	//typedef algo< strategy_3d > wpi_algo;
	typedef typename wpi_algo::trimesh trimesh;
	typedef typename wpi_algo::well_path well_path;
	typedef typename wpi_algo::well_hit_cell whc;
	typedef typename wpi_algo::intersect_path xpath;
	typedef typename wpi_algo::hit_idx_t hit_idx_t;
	typedef typename wpi_algo::xbuilder xbuilder;
	//typedef intersect_builder2< strategy_3d > xbuilder;

	typedef typename strategy_3d::vertex_pos_i vertex_pos_i;
	typedef typename strategy_3d::vertex_pos vertex_pos;
	typedef typename mesh_tools< strategy_3d>::mesh_part mesh_part;

	typedef typename sql_well::sp_traj_t sp_traj_t;
	typedef typename sql_well::sp_table_t sp_table_t;

	typedef multimap< string, string > wb_storage;
	typedef typename xpath::iterator x_iterator;

	impl(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn) {
		init(nx, ny, coord, zcorn);
	}

	impl(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn,
		smart_ptr< sql_well > src_well)
	{
		init(nx, ny, coord, zcorn);
		init(src_well);
	}

	void init(t_ulong nx, t_ulong ny, spv_float coord, spv_float zcorn) {
		// build trimesh for given coord+zcorn
		tops_ = wpi_algo::coord_zcorn2trimesh(nx, ny, coord, zcorn, m_, m_size_);
{'fraction_non_alphanumeric': 0.20966118752096613, 'fraction_numerical': 0.009616459800961647, 'mean_word_length': 3.3735941320293397, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3288951', 'n_tokens_mistral': 3278, 'n_tokens_neox': 3067, 'n_words': 719}