Exemplo n.º 1
0
double rk_adjust_stepsize(int order, double h, double eps_abs, double eps_rel, const VectorMatrix &y, const VectorMatrix &y_error)
{
	double norm = 0.0;

	if (isCudaEnabled()) {
#ifdef HAVE_CUDA
		assert(0 && "Not implemented for cuda: rk_adjust_stepsize!");
#endif
	} else {
		norm = rk_scaled_error_norm_cpu(h, eps_abs, eps_rel, y, y_error);
	}

	// from error norm, adjust stepsize.
	const double S = 0.9; // this is called step_headroom in OOMMF

	if (norm > 1.1) {
		// decrease step, no more than factor of 5, but a fraction S more
		// than scaling suggests (for better accuracy)
		double r = S / std::pow(norm, 1.0/order); // r = S * pow(1/norm, 1/order), 1 is the desired scaled error (norm=1 maximizes step size h within the desired error bounds)
		if (r < 0.2) r = 0.2;
		return h*r;

	} else if (norm < 0.5) {
		// increase step, but no more than by a factor of 5 
		double r = S / std::pow(norm, 1.0/(order+1.0));
		if (r > 5.0) r = 5.0; // increase no more than factor of 5
		if (r < 1.0) r = 1.0; // don't allow any decrease caused by S<1 
		return h*r;
	} else {
		// no change 
		return h;
	}
}
Exemplo n.º 2
0
void rk_combine_result(
	double h, ButcherTableau &tab,
	const VectorMatrix &k0, const VectorMatrix &k1, const VectorMatrix &k2,
	const VectorMatrix &k3, const VectorMatrix &k4, const VectorMatrix &k5,
	VectorMatrix &y, VectorMatrix &y_error)
{
	const int s = y.size();
	if (   s != y_error.size()
	    || s != k1.size()
	    || s != k2.size()
	    || s != k3.size()
	    || s != k4.size()
	    || s != k5.size()) throw std::runtime_error("rk_combine_result: Input matrix size mismatch.");
	if (!tab.num_steps == 6) throw std::runtime_error("Need num_steps == 6 in rk_combine_result");

	if (isCudaEnabled()) {
#ifdef HAVE_CUDA
		rk_combine_result_cuda(h, tab, k0, k1, k2, k3, k4, k5, y, y_error, isCuda64Enabled());
#else
		assert(0);
#endif
	} else {
		rk_combine_result_cpu(h, tab, k0, k1, k2, k3, k4, k5, y, y_error);
	}
}
Exemplo n.º 3
0
double exchange(
	int dim_x, int dim_y, int dim_z,
	double delta_x, double delta_y, double delta_z,
	bool periodic_x, bool periodic_y, bool periodic_z,
	const Matrix &Ms,
	const Matrix &A,
	const VectorMatrix &M,
	VectorMatrix &H)
{
	const bool use_cuda = isCudaEnabled();

	double res = 0;
	if (use_cuda) {
#ifdef HAVE_CUDA
		CUTIC("exchange");
		res = exchange_cuda(dim_x, dim_y, dim_z, delta_x, delta_y, delta_z, periodic_x, periodic_y, periodic_z, Ms, A, M, H, isCuda64Enabled());
		CUTOC("exchange");
#else
		assert(0);
#endif
	} else {
		TIC("exchange");
		res = exchange_cpu(dim_x, dim_y, dim_z, delta_x, delta_y, delta_z, periodic_x, periodic_y, periodic_z, Ms, A, M, H);
		TOC("exchange");
	}

	return res;
}
Exemplo n.º 4
0
double cubic_anisotropy(
	const VectorMatrix &axis1,
	const VectorMatrix &axis2,
	const       Matrix &k,
	const       Matrix &Ms,
	const VectorMatrix &M,
	VectorMatrix &H)
{
	const bool use_cuda = isCudaEnabled();

	double energy_sum = 0.0;

	if (use_cuda) {
#ifdef HAVE_CUDA
		CUTIC("cubic_anisotropy");
		energy_sum = cubic_anisotropy_cuda(axis1, axis2, k, Ms, M, H, isCuda64Enabled());
		CUTOC("cubic_anisotropy");
#else
		assert(0);
#endif
	} else {
		TIC("cubic_anisotropy");
		energy_sum = cubic_anisotropy_cpu(axis1, axis2, k, Ms, M, H);
		TOC("cubic_anisotropy");
	}

	return energy_sum;
}
Exemplo n.º 5
0
void minimize(
	const Matrix &f, const double h,
	const VectorMatrix &M,
	const VectorMatrix &H,
	VectorMatrix &M2)
{
	const bool use_cuda = isCudaEnabled();

	if (use_cuda) {
#ifdef HAVE_CUDA
		CUTIC("minimize");
#ifdef HAVE_CUDA_64
		if (isCuda64Enabled())
			minimize_cu64(f, h, M, H, M2);
		else
#endif
			minimize_cu32(f, h, M, H, M2);
		CUTOC("minimize");
#else
		assert(0);
#endif
	} else {
		TIC("minimize");
		minimize_cpu(f, h, M, H, M2);
		TOC("minimize");
	}
}
Exemplo n.º 6
0
void gradient(double delta_x, double delta_y, double delta_z, const Matrix &pot, VectorMatrix &field)
{
	const bool use_cuda = isCudaEnabled();

	if (use_cuda) {
#ifdef HAVE_CUDA
		Matrix::const_cu32_accessor pot_acc(pot);
		gradient_cuda(delta_x, delta_y, delta_z, pot_acc.ptr(), field);
#else
		assert(0);
#endif
	} else {
		Matrix::ro_accessor pot_acc(pot);
		gradient_cpu(delta_x, delta_y, delta_z, pot_acc.ptr(), field);
	}
}
Exemplo n.º 7
0
void rk_prepare_step(
	int step, double h, ButcherTableau &tab,
	const VectorMatrix &k0, const VectorMatrix &k1, const VectorMatrix &k2,
	const VectorMatrix &k3, const VectorMatrix &k4, const VectorMatrix &k5,
	const VectorMatrix &y,
	VectorMatrix &ytmp)
{
	if (isCudaEnabled()) {
#ifdef HAVE_CUDA
		rk_prepare_step_cuda(step, h, tab, k0, k1, k2, k3, k4, k5, y, ytmp, isCuda64Enabled());
#else
		assert(0);
#endif
	} else {
		rk_prepare_step_cpu(step, h, tab, k0, k1, k2, k3, k4, k5, y, ytmp);
	}
}