Ejemplo n.º 1
0
RS_Vector RS_Arc::getNearestMiddle(const RS_Vector& coord,
                                   double* dist,
                                   int middlePoints
                                   )const {
#ifndef EMU_C99
    using std::isnormal;
#endif

    RS_DEBUG->print("RS_Arc::getNearestMiddle(): begin\n");
        double amin=getAngle1();
        double amax=getAngle2();
        //std::cout<<"RS_Arc::getNearestMiddle(): middlePoints="<<middlePoints<<std::endl;
        if( !(/*std::*/isnormal(amin) || /*std::*/isnormal(amax))){
                //whole circle, no middle point
                if(dist != NULL) {
                        *dist=RS_MAXDOUBLE;
                }
                return RS_Vector(false);
        }
        if(isReversed()) {
                std::swap(amin,amax);
        }
        double da=fmod(amax-amin+2.*M_PI, 2.*M_PI);
        if ( da < RS_TOLERANCE ) {
                da= 2.*M_PI; // whole circle
        }
        RS_Vector vp(getNearestPointOnEntity(coord,true,dist));
        double angle=getCenter().angleTo(vp);
        int counts=middlePoints+1;
        int i( static_cast<int>(fmod(angle-amin+2.*M_PI,2.*M_PI)/da*counts+0.5));
        if(!i) i++; // remove end points
        if(i==counts) i--;
        angle=amin + da*(double(i)/double(counts));
        vp.setPolar(getRadius(), angle);
        vp.move(getCenter());

	if (dist) {
        *dist = vp.distanceTo(coord);
    }
    RS_DEBUG->print("RS_Arc::getNearestMiddle(): end\n");
    return vp;
}
Ejemplo n.º 2
0
	void set(const rapidjson::Value& object) {
		using std::isnormal;

		if (not object.HasMember("save-mhd-n")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a save-mhd-n key."
			);
		}
		save_mhd_n = object["save-mhd-n"].GetDouble();

		if (not object.HasMember("time-start")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a time-start key."
			);
		}
		time_start = object["time-start"].GetDouble();

		if (not object.HasMember("time-length")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a time-length key."
			);
		}
		time_length = object["time-length"].GetDouble();

		if (not object.HasMember("time-step-factor")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a time-step-factor key."
			);
		}
		time_step_factor = object["time-step-factor"].GetDouble();

		if (not object.HasMember("remove-div-B-n")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a remove-div-B-n key."
			);
		}
		remove_div_B_n = object["remove-div-B-n"].GetDouble();

		if (not object.HasMember("poisson-norm-stop")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a poisson-norm-stop key."
			);
		}
		poisson_norm_stop = object["poisson-norm-stop"].GetDouble();

		if (not object.HasMember("poisson-norm-increase-max")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a poisson-norm-increase-max key."
			);
		}
		poisson_norm_increase_max = object["poisson-norm-increase-max"].GetDouble();

		if (not object.HasMember("adiabatic-index")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a adiabatic-index key."
			);
		}
		adiabatic_index = object["adiabatic-index"].GetDouble();
		if (not isnormal(adiabatic_index) or adiabatic_index < 0) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "Invalid adiabatic index: " + std::to_string(adiabatic_index)
				+ ", should be > 0"
			);
		}

		if (not object.HasMember("vacuum-permeability")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a vacuum-permeability key."
			);
		}
		vacuum_permeability = object["vacuum-permeability"].GetDouble();
		if (not isnormal(vacuum_permeability) or vacuum_permeability < 0) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "Invalid vacuum permeability: " + std::to_string(vacuum_permeability)
				+ ", should be > 0"
			);
		}

		if (not object.HasMember("proton-mass")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a proton-mass key."
			);
		}
		proton_mass = object["proton-mass"].GetDouble();
		if (not isnormal(proton_mass) or proton_mass < 0) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "Invalid proton_mass: " + std::to_string(proton_mass)
				+ ", should be > 0"
			);
		}

		if (not object.HasMember("solver-mhd")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a solver-mhd key."
			);
		}
		solver = object["solver-mhd"].GetString();
		if (
			solver != "rusanov"
			and solver != "hll-athena"
			and solver != "hlld-athena"
			and solver != "roe-athena"
		) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "Invalid mhd solver: " + solver
				+ ", should be one of rusanov, hll-athena, hlld-athena, roe-athena."
			);
		}

		if (object.HasMember("output-directory")) {
			output_directory = object["output-directory"].GetString();
		}

		if (not object.HasMember("load-balancer")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a load-balancer key."
			);
		}
		lb_name = object["load-balancer"].GetString();

		if (not object.HasMember("minimum-pressure")) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON data doesn't have a minimum-pressure key."
			);
		}
		const auto& min_pressure_json = object["minimum-pressure"];
		if (not min_pressure_json.IsNumber()) {
			throw std::invalid_argument(
				std::string(__FILE__ "(") + std::to_string(__LINE__) + "): "
				+ "JSON item minimum-pressure is not a number."
			);
		}
		min_pressure = min_pressure_json.GetDouble();
	}
Ejemplo n.º 3
0
/**
 * is the Ellipse an Arc
 * @return false, if both angle1/angle2 are zero
 *
 *Author: Dongxu Li
 */
bool RS_Ellipse::isArc() const{
#ifndef EMU_C99
    using std::isnormal;
#endif
    return /*std::*/isnormal(getAngle1()) || /*std::*/isnormal(getAngle2());
}
Ejemplo n.º 4
0
> std::tuple<MHD, double> get_flux_rusanov(
	MHD& state_neg,
	MHD& state_pos,
	const Vector& bg_face_magnetic_field,
	const double& area,
	const double& dt,
	const double& adiabatic_index,
	const double& vacuum_permeability
) {
	using std::isnormal;
	using std::isfinite;
	using std::to_string;

	const Mass_Density Mas{};
	const Momentum_Density Mom{};
	const Total_Energy_Density Nrj{};
	const Magnetic_Field Mag{};

	if (not isnormal(state_neg[Mas]) or state_neg[Mas] < 0) {
		throw std::domain_error(
			"Invalid mass density in state_neg: "
			+ to_string(state_neg[Mas])
		);
	}
	if (not isnormal(state_pos[Mas]) or state_pos[Mas] < 0) {
		throw std::domain_error(
			"Invalid mass density in state_pos: "
			+ to_string(state_pos[Mas])
		);
	}

	const auto
		fast_magnetosonic_neg
			= get_fast_magnetosonic_speed(
				state_neg[Mas],
				state_neg[Mom],
				state_neg[Nrj],
				state_neg[Mag],
				bg_face_magnetic_field,
				adiabatic_index,
				vacuum_permeability
			),

		fast_magnetosonic_pos
			= get_fast_magnetosonic_speed(
				state_pos[Mas],
				state_pos[Mom],
				state_pos[Nrj],
				state_pos[Mag],
				bg_face_magnetic_field,
				adiabatic_index,
				vacuum_permeability
			),

		max_fast_ms = std::max(fast_magnetosonic_neg, fast_magnetosonic_pos),
		max_signal = std::max(
			std::abs(state_neg[Mom][0] / state_neg[Mas]) + max_fast_ms,
			std::abs(state_pos[Mom][0] / state_pos[Mas]) + max_fast_ms
		);

	const auto Mas_getter
		= [](MHD& state) -> typename Mass_Density::data_type& {
			return state[Mass_Density()];
		};
	const auto Mom_getter
		= [](MHD& state) -> typename Momentum_Density::data_type& {
			return state[Momentum_Density()];
		};
	const auto Nrj_getter
		= [](MHD& state) -> typename Total_Energy_Density::data_type& {
			return state[Total_Energy_Density()];
		};
	const auto Mag_getter
		= [](MHD& state) -> typename Magnetic_Field::data_type& {
			return state[Magnetic_Field()];
		};

	MHD
		flux_neg
			= get_flux(
				state_neg,
				bg_face_magnetic_field,
				adiabatic_index,
				vacuum_permeability,
				Mas_getter, Mom_getter, Nrj_getter, Mag_getter
			),
		flux_pos
			= get_flux(
				state_pos,
				bg_face_magnetic_field,
				adiabatic_index,
				vacuum_permeability,
				Mas_getter, Mom_getter, Nrj_getter, Mag_getter
			);

	MHD flux
		= (flux_neg + flux_pos) / 2
		- (state_pos - state_neg) * (max_signal / 2);

	flux *= area * dt;

	return std::make_tuple(flux, max_signal);
}