Beispiel #1
0
/*
 * desc_array - dump info
 */
static void desc_array( unsigned_8 *ptr, bool is386 )
/***************************************************/
{
    addr32_ptr  *p32;
    addr48_ptr  *p48;

    Wdputs( "          scalar type 1 = " );
    scalar_type( ptr[0] );
    Wdputs( "  scalar type 2 = " );
    scalar_type( ptr[1] );
    ptr += 2;
    Wdputslc( "\n          addr = " );
    if( is386 ) {
        p48 = (addr48_ptr *)ptr;
        ptr += sizeof(addr48_ptr);
        Puthex( p48->segment, 4 );
        Wdputc( ':' );
        Puthex( p48->offset, 8 );
    } else {
        p32 = (addr32_ptr *)ptr;
        ptr += sizeof(addr32_ptr);
        Puthex( p32->segment, 4 );
        Wdputc( ':' );
        Puthex( p32->offset, 4 );
    }
    base_type_index( ptr );

} /* desc_array */
template<typename scalar_type> finite_hyperbox<scalar_type> finite_bounding_box(
		const support_function_provider& s) {
	scalar_type xp, xn;
	math::vdom_vector<scalar_type> v;
	bool is_empty = false;
	bool is_bounded = true;

	typename finite_hyperbox<scalar_type>::point_type c_point(s.get_dim());
	typename finite_hyperbox<scalar_type>::point_type g_point(s.get_dim());

	/* Positive and negative direction */
	variable_id_set vars = s.get_variable_ids();
	positional_vdomain dom(vars);
	for (unsigned int j = 0; j < dom.size(); ++j) {
		math::vdom_vector<scalar_type> ln(dom);
		math::vdom_vector<scalar_type> lp(dom);
		ln[j] = -scalar_type(1);
		lp[j] = scalar_type(1);
		s.compute_support(ln, xn, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << ln << std::endl;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		s.compute_support(lp, xp, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << lp;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		//std::cout << l << ":" << x << " at " << v << ", empty:" << is_empty << ", bounded:" << is_bounded << std::endl;
		if (is_empty) {
			// return an empty box
			return finite_hyperbox<scalar_type>::empty_box(dom);
		} else {
			if (is_bounded) {
				c_point[j] = (xp - xn) / scalar_type(2);
				g_point[j] = xp - c_point[j];
			} else {
				throw std::runtime_error(
						"finite_bounding_box not allowed with unbounded set");
			};
		}
	}
	return finite_hyperbox<scalar_type> (c_point, g_point, dom);
}
template<typename scalar_type> finite_hyperbox<scalar_type> finite_bounding_box(
		const support_function_provider& s,
		const math::affine_map<scalar_type>& t) {
	scalar_type xp, xn;
	math::vdom_vector<scalar_type> v;
	bool is_empty = false;
	bool is_bounded = true;

	positional_vdomain dom = t.domain();
	positional_vdomain codom = t.codomain();

	typename finite_hyperbox<scalar_type>::point_type c_point(codom.size());
	typename finite_hyperbox<scalar_type>::point_type g_point(codom.size());

	/* Positive and negative direction */
	for (unsigned int j = 0; j < codom.size(); ++j) {
		math::vdom_vector<scalar_type> lp(dom, t.get_A().vector_from_row(j));
		math::vdom_vector<scalar_type> ln(-lp);
		s.compute_support(ln, xn, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << ln << std::endl;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		s.compute_support(lp, xp, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << lp;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		xp += t.get_b()[j];
		xn -= t.get_b()[j];
		//std::cout << l << ":" << x << " at " << v << ", empty:" << is_empty << ", bounded:" << is_bounded << std::endl;
		if (is_empty) {
			// return an empty box
			return finite_hyperbox<scalar_type>::empty_box(codom);
		} else {
			if (is_bounded) {
				c_point[j] = (xp - xn) / scalar_type(2);
				g_point[j] = xp - c_point[j];
			} else {
				throw std::runtime_error(
						"finite_bounding_box not allowed with unbounded set");
			};
		}
	}
	return finite_hyperbox<scalar_type> (c_point, g_point, codom);
}
template<typename scalar_type> finite_hyperbox<scalar_type> finite_symmetric_bounding_box(
		const support_function_provider& s,
		const math::affine_map<scalar_type>& t) {
	scalar_type xp, xn;
	math::vdom_vector<scalar_type> v;
	bool is_empty = false;
	bool is_bounded = true;

	/* Positive and negative direction */
	positional_vdomain dom = t.domain();
	positional_vdomain codom = t.codomain();

	typename finite_hyperbox<scalar_type>::point_type c_point(codom.size(),
			scalar_type(0));
	typename finite_hyperbox<scalar_type>::point_type g_point(codom.size());

	for (unsigned int j = 0; j < codom.size(); ++j) {
		math::vdom_vector<scalar_type> lp(dom, t.get_A().vector_from_row(j));
		math::vdom_vector<scalar_type> ln(-lp);
		s.compute_support(ln, xn, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << ln << std::endl;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_symmetric_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		s.compute_support(lp, xp, v, is_empty, is_bounded);
		if (!is_bounded) {
			std::stringstream ss;
			ss << "unbounded in direction " << lp;
			ss << "in set: " << s << std::endl;
			throw std::runtime_error(
					"finite_symmetric_bounding_box not allowed with unbounded set:\n"
							+ ss.str());
		};
		xp += t.get_b()[j];
		xn -= t.get_b()[j];
		//std::cout << ln << ":" << xn << "..." << lp << ":" << xp << " at " << v << ", empty:" << is_empty << ", bounded:" << is_bounded << std::endl;
		if (is_empty) {
			// return an empty box
			return finite_hyperbox<scalar_type>::empty_box(codom);
		} else {
			// Use absolute value so that the generator is not negative
			// (which bef def it shouldn't be)
			if (xn > xp)
				g_point[j] = abs(xn);
			else
				g_point[j] = abs(xp);
		}
	}
	return finite_hyperbox<scalar_type> (c_point, g_point, codom);
}
inline
const spacetime_plif::delta_parameters& spacetime_plif::get_delta_params(
		const duration& delta) {
	if (min_infeasible_delta>=scalar_type(0) && delta>=min_infeasible_delta) {
		throw math::invalid_number_exception("throwing because of numerical issues, this should be caught");
	}

	if (my_delta_params_it == my_delta_params_cache.end() || !is_MEQ(
			my_delta_params_it->first, delta)) {
		my_delta_params_it = my_delta_params_cache.find(delta);
		if (my_delta_params_it == my_delta_params_cache.end()) {
			// not in the cache yet, so compute and add them
			try {
				delta_parameters params = compute_delta_params(delta);
//				std::cout << std::endl
//						<< "inserting delta=" << delta << " into cache" << std::endl;
				my_delta_params_it = my_delta_params_cache.insert_missing(delta,
						params);
//				std::cout << std::endl
//						<< "inserting done" << std::endl;

				min_delta = std::max(scalar_type(0),
						std::min(min_delta, delta));
				IFLOGGER(DEBUG5) {
					LOGGER(DEBUG5, "get_delta_params",
							"computed flowpipe parameters for delta="+to_string(delta));
				}
			} catch (math::invalid_number_exception& e) {
				if (min_infeasible_delta < scalar_type(0)) {
					min_infeasible_delta = delta;
				} else {
					min_infeasible_delta = std::min(min_infeasible_delta,
							delta);
				}
//				std::cout << std::endl
//						<< "throwing because of numerical issues" << std::endl;
				throw e;
			}

		}
	}
Beispiel #6
0
int main()
{
	using scalar_type = double;

	constexpr double
		grid_length_x = 4 * M_PI,
		grid_length_y = 1 * M_PI,
		grid_length_z = 2 * M_PI;

	constexpr size_t
		grid_size_x = 32,
		grid_size_y = 32,
		grid_size_z = 32;

	const auto rhs
		= get_rhs<scalar_type>(
			grid_length_x,
			grid_length_y,
			grid_length_z,
			grid_size_x,
			grid_size_y,
			grid_size_z
		);

	auto solution
		= pamhd::poisson::solve_bicgstab(
			grid_size_x,
			grid_size_y,
			grid_size_z,
			grid_length_x / grid_size_x,
			grid_length_y / grid_size_y,
			grid_length_z / grid_size_z,
			rhs
		);

	solution = normalize_solution(
			grid_length_x,
			grid_length_y,
			grid_length_z,
			grid_size_x,
			grid_size_y,
			grid_size_z,
			solution
	);

	const auto analytic
		= get_analytic_solution(
			grid_length_x,
			grid_length_y,
			grid_length_z,
			grid_size_x,
			grid_size_y,
			grid_size_z
		);

	const double
		diff_l1_norm = get_diff_lp_norm(solution, analytic, scalar_type(1)),
		diff_l2_norm = get_diff_lp_norm(solution, analytic, scalar_type(2)),
		diff_linf_norm = get_diff_lp_norm(solution, analytic, scalar_type(0));

	if (diff_l1_norm > 30) {
		std::cerr <<  __FILE__ << "(" << __LINE__ << "): "
			<< "L1 norm too large: " << diff_l1_norm
			<< std::endl;
		abort();
	}
	if (diff_l2_norm > 0.3) {
		std::cerr <<  __FILE__ << "(" << __LINE__ << "): "
			<< "L2 norm too large: " << diff_l2_norm
			<< std::endl;
		abort();
	}
	if (diff_linf_norm > 0.01) {
		std::cerr <<  __FILE__ << "(" << __LINE__ << "): "
			<< "Infinite L norm too large: " << diff_linf_norm
			<< std::endl;
		abort();
	}

	return EXIT_SUCCESS;
}
Beispiel #7
0
/*
 * Dump_types - dump all typing information
 */
void Dmp_type( int cnt, unsigned_32 *offs )
/*****************************************/
{
    int         i;
    addr32_ptr  *p32;
    addr48_ptr  *p48;
    unsigned_8  *ptr;
    unsigned_16 index;
    unsigned_16 curr_index;
    unsigned_32 coff;
    char        name[256];
    unsigned_8  buff[256];

    for( i = 0; i < cnt; i++ ) {
        coff = 0;
        Wdputs( "      Data " );
        Putdec( i );
        Wdputs( ":  offset " );
        Puthex( offs[i], 8 );
        Wdputslc( "\n" );
        curr_index = 0;
        for( ;; ) {
            Wlseek( coff + Curr_sectoff + offs[i] );
            Wread( buff, sizeof( buff ) );
            Wdputs( "        " );
            Puthex( coff, 4 );
            Wdputs( ": " );
            ptr = buff+2;
            switch( buff[1] ) {
            case SCALAR:
                StartType( "SCALAR", ++curr_index );
                ptr = buff+3;
                Get_local_name( name, ptr, buff );
                Wdputs( "          \"" );
                Wdputs( name );
                Wdputs( "\"  scalar type = " );
                scalar_type( buff[2] );
                Wdputslc( "\n" );
                break;
            case SCOPE:
                StartType( "SCOPE", ++curr_index);
                Get_local_name( name, ptr, buff );
                Wdputs( "          \"" );
                Wdputs( name );
                Wdputslc( "\"\n" );
                break;
            case NAME:
                StartType( "NAME", ++curr_index);
                ptr = Get_type_index( ptr, &index );
                ptr = Get_type_index( ptr, &index );
                Get_local_name( name, ptr, buff );
                Wdputs( "          \"" );
                Wdputs( name );
                Wdputs( "\"  type idx = " );
                Putdec( index );
                Wdputs( "  scope idx = " );
                ptr = Get_type_index( buff+2, &index );
                Putdec( index );
                Wdputslc( "\n" );
                break;
            case CUE_TABLE:
                Wdputs( "cue table offset=" );
                Puthex( *(unsigned_32 *)ptr, 8 );
                Wdputslc( "\n" );
                break;
            case TYPE_EOF:
                return;
            case BYTE_INDEX:
                StartType( "BYTE_INDEX ARRAY", ++curr_index);
                array_index( ptr, 1 );
                break;
            case WORD_INDEX:
                StartType( "WORD_INDEX ARRAY", ++curr_index);
                array_index( ptr, 2 );
                break;
            case LONG_INDEX:
                StartType( "LONG_INDEX ARRAY", ++curr_index);
                array_index( ptr, 4 );
                break;
            case TYPE_INDEX:
                StartType( "TYPE_INDEX ARRAY", ++curr_index);
                Wdputs( "          index type = " );
                ptr = Get_type_index( ptr, &index );
                Putdec( index );
                base_type_index( ptr );
                break;
            case DESC_INDEX:
                StartType( "DESC_INDEX ARRAY", ++curr_index);
                desc_array( ptr, false );
                break;
            case DESC_INDEX_386:
                StartType( "DESC_INDEX ARRAY", ++curr_index);
                desc_array( ptr, true );
                break;
            case BYTE_RANGE:
                StartType( "BYTE_RANGE", ++curr_index);
                range( ptr, 1 );
                break;
            case WORD_RANGE:
                StartType( "WORD_RANGE", ++curr_index);
                range( ptr, 2 );
                break;
            case LONG_RANGE:
                StartType( "LONG_RANGE", ++curr_index);
                range( ptr, 4 );
                break;
            case PTR_NEAR:
                StartType( "NEAR PTR", ++curr_index);
                Wdputs( "       " );
                near_ptr( buff );
                break;
            case PTR_FAR:
                StartType( "FAR PTR", ++curr_index);
                Wdputs( "       " );
                base_type_index( ptr );
                break;
            case PTR_HUGE:
                StartType( "HUGE PTR", ++curr_index);
                Wdputs( "       " );
                base_type_index( ptr );
                break;
            case PTR_NEAR_DEREF:
                StartType( "NEAR_DEREF PTR", ++curr_index);
                Wdputs( "       " );
                near_ptr( buff );
                break;
            case PTR_FAR_DEREF:
                StartType( "FAR_DEREF PTR", ++curr_index);
                Wdputs( "       " );
                base_type_index( ptr );
                break;
            case PTR_HUGE_DEREF:
                StartType( "HUGE_DEREF PTR", ++curr_index);
                Wdputs( "       " );
                base_type_index( ptr );
                break;
            case PTR_NEAR386:
                StartType( "NEAR386 PTR", ++curr_index);
                Wdputs( "       " );
                near_ptr( buff );
                break;
            case PTR_FAR386:
                StartType( "FAR386 PTR", ++curr_index);
                Wdputs( "       " );
                base_type_index( ptr );
                break;
            case PTR_NEAR386_DEREF:
                StartType( "NEAR386_DEREF PTR", ++curr_index);
                Wdputs( "       " );
                near_ptr( buff );
                break;
            case PTR_FAR386_DEREF:
                StartType( "FAR386_DEREF PTR", ++curr_index);
                Wdputs( "\n       " );
                base_type_index( ptr );
                break;
            case CLIST:
                StartType( "ENUM_LIST", ++curr_index);
                Wdputs( "          number of consts = " );
                Puthex( *ptr, 4 );
                Wdputs( "   scalar type = " );
                scalar_type( buff[4] );
                Wdputslc( "\n" );
                break;
            case CONST_BYTE:
                Wdputslc( "CONST_BYTE\n" );
                enum_const( buff, 1 );
                break;
            case CONST_WORD:
                Wdputslc( "CONST_WORD\n" );
                enum_const( buff, 2 );
                break;
            case CONST_LONG:
                Wdputslc( "CONST_LONG\n" );
                enum_const( buff, 4 );
                break;
            case FLIST:
                StartType( "FIELD_LIST", ++curr_index);
                Wdputs( "          number of fields = " );
                Puthex( *ptr, 4 );
                if( buff[0] > 4 ) {
                    Wdputs( "   size = " );
                    ptr += 2;
                    Puthex( *ptr, 8 );
                }
                Wdputslc( "\n" );
                break;
            case FIELD_BYTE:
                Wdputslc( "FIELD_BYTE\n" );
                bit_field_struct( buff, 1, false );
                break;
            case FIELD_WORD:
                Wdputslc( "FIELD_WORD\n" );
                bit_field_struct( buff, 2, false );
                break;
            case FIELD_LONG:
                Wdputslc( "FIELD_LONG\n" );
                bit_field_struct( buff, 4, false );
                break;
            case BIT_BYTE:
                Wdputslc( "BIT_BYTE\n" );
                bit_field_struct( buff, 1, true );
                break;
            case BIT_WORD:
                Wdputslc( "BIT_WORD\n" );
                bit_field_struct( buff, 2, true );
                break;
            case BIT_LONG:
                Wdputslc( "BIT_LONG\n" );
                bit_field_struct( buff, 4, true );
                break;
            case FIELD_CLASS:
                Wdputslc( "FIELD_CLASS\n" );
                bit_field_class( buff, false );
                break;
            case BIT_CLASS:
                Wdputslc( "BIT_CLASS\n" );
                bit_field_class( buff, true );
                break;
            case INHERIT_CLASS:
                Wdputslc( "INHERIT_CLASS\n" );
                Wdputs( "          adjust locator = " );
                ptr = Dump_location_expression( ptr, "            " );
                Wdputs( "          ancestor type = " );
                Get_type_index( ptr, &index );
                Putdec( index );
                Wdputslc( "\n" );
                break;
            case PNEAR:
                StartType( "NEAR PROC", ++curr_index);
                near_far_proc( buff );
                break;
            case PFAR:
                StartType( "FAR PROC", ++curr_index);
                near_far_proc( buff );
                break;
            case PNEAR386:
                StartType( "NEAR386 PROC", ++curr_index);
                near_far_proc( buff );
                break;
            case PFAR386:
                StartType( "FAR386 PROC", ++curr_index);
                near_far_proc( buff );
                break;
            case EXT_PARMS:
                Wdputslc( "EXT_PARMS\n" );
                param_type_index( (unsigned_8)buff[0]-2, ptr );
                break;
            case CHAR_BYTE:
                StartType( "CHAR_BYTE", ++curr_index);
                Wdputs( "        length = " );
                Puthex( *ptr, 2 );
                Wdputslc( "\n" );
                break;
            case CHAR_WORD:
                StartType( "CHAR_WORD", ++curr_index);
                Wdputs( "        length = " );
                Puthex( *ptr, 4 );
                Wdputslc( "\n" );
                break;
            case CHAR_LONG:
                StartType( "CHAR_LONG", ++curr_index);
                Wdputs( "        length = " );
                Puthex( *ptr, 8 );
                Wdputslc( "\n" );
                break;
            case CHAR_IND:
                StartType( "CHAR_IND", ++curr_index);
                Wdputs( "       scalar type = " );
                scalar_type( buff[2] );
                p32 = (addr32_ptr *)ptr;
                Puthex( p32->segment, 4 );
                Wdputc( ':' );
                Puthex( p32->offset, 4 );
                Wdputslc( "\n" );
                break;
            case CHAR_IND_386:
                StartType( "CHAR_IND_386", ++curr_index);
                Wdputs( "       scalar type = " );
                scalar_type( buff[2] );
                p48 = (addr48_ptr *)ptr;
                Puthex( p48->segment, 4 );
                Wdputc( ':' );
                Puthex( p48->offset, 8 );
                Wdputslc( "\n" );
                break;
            case CHAR_LOCATION:
                StartType( "CHAR_LOC", ++curr_index);
                Wdputs( "       scalar type = " );
                scalar_type( buff[2] );
                Wdputs( "          size locator = " );
                ptr = Dump_location_expression( ptr + 1, "            " );
                Wdputslc( "\n" );
                break;
            }
            coff += buff[0];
            if( coff >= (offs[i+1] - offs[i]) ) {
                break;
            }
        }
    }

} /* Dmp_type */