--- /dev/null
+New: Added random_value<T>() and random_point<dim>() in tests.h, to simplify and unify our way to generate random numbers and points.
+<br>
+(Luca Heltai, 2017/11/21)
LinearAlgebra::distributed::Vector<double> init_vector;
mf_data->initialize_dof_vector(init_vector);
for (auto it = init_vector.begin(); it != init_vector.end(); ++it)
- *it = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ *it = random_value<double>();
constraints.set_zero(init_vector);
eigensolver.set_initial_vector(init_vector);
LinearAlgebra::distributed::Vector<double> init_vector;
mf_data->initialize_dof_vector(init_vector);
for (auto it = init_vector.begin(); it != init_vector.end(); ++it)
- *it = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ *it = random_value<double>();
constraints.set_zero(init_vector);
eigensolver.set_initial_vector(init_vector);
// as in symmetric_tensor_10
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<dim; ++j)
- t[i][j] = 1. * Testing::rand() / RAND_MAX;
+ t[i][j] = random_value<double>();
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<dim; ++j)
Point<dim> p;
for (unsigned int d=0; d<dim; ++d)
p[d] = coordinates[d][0] +
- (1. * Testing::rand() / RAND_MAX) * (coordinates[d].back() -
- coordinates[d][0]);
+ (random_value<double>()) * (coordinates[d].back() -
+ coordinates[d][0]);
double exact_value = 1;
for (unsigned int d=0; d<dim; ++d)
Point<dim> p;
for (unsigned int d=0; d<dim; ++d)
p[d] = coordinates[d][0] +
- (1. * Testing::rand() / RAND_MAX) * (coordinates[d].back() -
- coordinates[d][0]);
+ (random_value<double>()) * (coordinates[d].back() -
+ coordinates[d][0]);
double exact_value = 1;
for (unsigned int d=0; d<dim; ++d)
double rand_2 ()
{
- return 1.*Testing::rand()/RAND_MAX*4-2.;
+ return random_value<double>()*4-2.;
}
for (unsigned int i=0; i<p.size(); ++i)
{
Polynomial<double> q = p[i];
- double x = (double)Testing::rand()/RAND_MAX;
- double factor = 5.*(double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
+ double factor = 5.*random_value<double>();
q.scale (factor);
double value1 = p[i].value (factor * x);
double value2 = q .value (x);
for (unsigned int i=0; i<p.size(); ++i)
{
Polynomial<double> q = p[i];
- double x = (double)Testing::rand()/RAND_MAX;
- double a = 10.*(-1.+2.*(double)Testing::rand()/RAND_MAX);
+ double x = random_value<double>();
+ double a = 10.*(-1.+2.*random_value<double>());
q.shift (a);
double value1 = p[i].value (x+a);
double value2 = q .value (x);
for (unsigned int i=0; i<p.size(); ++i)
{
Polynomial<double> q = p[i];
- double x = (double)Testing::rand()/RAND_MAX;
- double a = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
+ double a = random_value<double>();
q *= a;
double value1 = p[i].value (x) * a;
double value2 = q .value (x);
{
Polynomial<double> q = p[i];
q *= p[j];
- double x = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
double value1 = p[i].value (x) * p[j].value(x);
double value2 = q .value (x);
if (std::fabs(value1-value2) > std::max(1e-13,1e-13*std::fabs(value1)))
for (unsigned int i=0; i<p.size(); ++i)
{
Polynomial<double> q = p[i];
- double x = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
q += zero;
double value1 = p[i].value (x);
double value2 = q .value (x);
Polynomial<double> q = p[i];
q += zero;
q *= p[j];
- double x = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
double value1 = p[i].value (x) * p[j].value(x);
double value2 = q .value (x);
if (std::fabs(value1-value2) > std::max(1e-9,1e-9*std::fabs(value1)))
deallog << "Representation of one at random points";
for (unsigned int j=0; j<12; ++j)
{
- double x = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
double value = 0;
for (unsigned int i=0; i<p.size(); ++i)
{
Monomial<double> zero (0,0);
for (unsigned int j=0; j<p.size(); ++j)
{
- double x = (double)Testing::rand()/RAND_MAX;
+ double x = random_value<double>();
p[j].value (x, values);
Polynomial<double> q = p[j];
q += zero;
for (unsigned int j=0; j<3; ++j)
for (unsigned int k=0; k<3; ++k)
for (unsigned int l=0; l<3; ++l)
- A[i][j][k][l] = 1.*Testing::rand()/RAND_MAX;
+ A[i][j][k][l] = random_value<double>();
break;
default:
std::vector<Point<dim> > points(size);
for (auto &p : points)
- for (unsigned int i=0; i<dim; ++i)
- p[i] = Testing::rand()/double(RAND_MAX);
+ p = random_point<dim>();
auto buffer = Utilities::pack(points);
auto a_pair = std::make_pair(1, 3.14);
for (auto &p : points)
- for (unsigned int i=0; i<dim; ++i)
- p[i] = Testing::rand()/double(RAND_MAX);
+ p = random_point<dim>();
auto a_tuple = std::make_tuple(a_pair, points);
void initialize(Evaluation &eval)
{
eval.is_cartesian = true;
- eval.cartesian_weight = static_cast<double>(rand())/RAND_MAX;
+ eval.cartesian_weight = random_value<double>();
for (unsigned int i=0; i<4; ++i)
eval.cartesian_weight = std::max(eval.cartesian_weight, eval.cartesian_weight * eval.cartesian_weight);
eval.general_weight[0] = 0.2313342 * eval.cartesian_weight;
- eval.jac_weight[0] = static_cast<double>(rand())/RAND_MAX;
+ eval.jac_weight[0] = random_value<double>();
}
initialize(current);
initialize(old);
VectorizedArray<double> weight;
- weight = static_cast<double>(rand())/RAND_MAX;
+ weight = random_value<double>();
VectorizedArray<double> vec;
for (unsigned int v=0; v<VectorizedArray<double>::n_array_elements; ++v)
- vec[v] = static_cast<double>(rand())/RAND_MAX;
+ vec[v] = random_value<double>();
current.values[0] = vec;
old.values[0] = vec * 1.112 - std::max(2.*vec - 1., VectorizedArray<double>());
// the iterator and compare it with the exact value
Vector<double> src(m.n()), dst(m.m()), dst_ref(m.m());
for (unsigned int i=0; i<src.size(); ++i)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
for (unsigned int i=0; i<m.m(); ++i)
{
double sum = 0;
// the entries in extract_row_copy and compare it with the exact value
Vector<double> src(m.n()), dst(m.m()), dst_ref(m.m());
for (unsigned int i=0; i<src.size(); ++i)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
std::vector<types::global_dof_index> indices(sp.max_entries_per_row());
std::vector<double> values(sp.max_entries_per_row());
for (unsigned int i=0; i<m.m(); ++i)
for (unsigned int d = 0; d < dim; ++d)
{
for (unsigned int c = 0; c < p_order; ++c)
- coeff[c] = (double) Testing::rand() / (double) RAND_MAX;
+ coeff[c] = random_value<double>();
base.push_back (Polynomials::Polynomial<double> (coeff));
}
}
Vector<double> estimated_error_per_cell (n_cells);
for (unsigned int i = 0; i < n_cells; ++i)
- estimated_error_per_cell(i) = (double) Testing::rand() / (double) RAND_MAX;
+ estimated_error_per_cell(i) = random_value<double>();
GridRefinement::refine_and_coarsen_fixed_number (triangulation,
estimated_error_per_cell,
// generate some random points bounded by [0., 0.2)^2 in R^2 space
// any point in this domain should be inside one of the cells
- Point<2> p( static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX),
- static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX)/8. );
+ Point<2> p( random_value<double>(),
+ random_value<double>()/8. );
try
{
// points inside a radius of 0.9)
for (int i=0; i<1000; i++)
{
- double r = sqrt((0.9*Testing::rand()/RAND_MAX));
+ double r = sqrt(random_value<double>(.9));
double phi = 2*3.14*(1.0*Testing::rand()/RAND_MAX);
double x = r*cos(phi);
double y = r*sin(phi);
// values between 0 and 1.
Vector<double> solution(dof_handler.n_dofs ());
for (unsigned int i = 0; i < dof_handler.n_dofs (); ++i)
- solution(i) = (double) Testing::rand() / (double) RAND_MAX;
+ solution(i) = random_value<double>();
// Now check if the function is
// continuous in normal direction
const unsigned int) const
{
const double base = std::pow(p(0), 1./3.);
- const double random = 2.*Testing::rand()/RAND_MAX-1;
+ const double random = random_value<double>(-1., 1.);
return std::max (base+.1*random, 0.);
}
const unsigned int) const
{
const double base = std::pow(p(0), 1./3.);
- const double random = 2.*Testing::rand()/RAND_MAX-1;
+ const double random = random_value<double>(-1., 1.);
return std::max (base+.1*random, 0.);
}
std::vector<double> dof_values (fe.dofs_per_cell);
for (unsigned int i=0; i<dof_values.size(); ++i)
- dof_values[i] = 1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ dof_values[i] = 1. + 2.*random_value<double>();
const std::vector<Point<dim> > &generalized_support_points = fe.get_generalized_support_points();
std::vector<Vector<double> > real_values (generalized_support_points.size(), Vector<double>(dim));
Vector<double> tmp1(dofs_per_cell), tmp2(dofs_per_cell);
for (unsigned int i=0; i<dofs_per_cell; ++i)
- tmp1(i) = 1.*Testing::rand()/RAND_MAX;
+ tmp1(i) = random_value<double>();
deallog << "solving degree = " << degree << std::endl;
check_solver_within_range(
Vector<double> tmp1(dofs_per_cell), tmp2(dofs_per_cell);
for (unsigned int i=0; i<dofs_per_cell; ++i)
- tmp1(i) = 1.*Testing::rand()/RAND_MAX;
+ tmp1(i) = random_value<double>();
deallog << "solving degree = " << degree << std::endl;
check_solver_within_range(
std::vector<Point<dim>> points;
for (size_t i=0; i<n_points; ++i)
- {
- Point<dim> p;
- for (unsigned int d=0; d<dim; ++d)
- p[d] = double(Testing::rand())/RAND_MAX; //Normalizing the value
- points.push_back(p);
- }
+ points.push_back(random_point<dim>());
std::vector<typename DoFHandler<dim>::active_cell_iterator> cells;
std::vector<std::vector<Point<dim> > > qpoints;
Vector<double> tmp1(dofs_per_cell), tmp2(dofs_per_cell);
for (unsigned int i=0; i<dofs_per_cell; ++i)
- tmp1(i) = 1.*Testing::rand()/RAND_MAX;
+ tmp1(i) = random_value<double>();
cg.solve (mass_matrix, tmp2, tmp1, PreconditionIdentity());
deallog << "Degree=" << degree
Vector<double> tmp1(dofs_per_cell), tmp2(dofs_per_cell);
for (unsigned int i=0; i<dofs_per_cell; ++i)
- tmp1(i) = 1.*Testing::rand()/RAND_MAX;
+ tmp1(i) = random_value<double>();
cg.solve (mass_matrix, tmp2, tmp1, PreconditionIdentity());
deallog << "Degree=" << degree
// Fill solution vector with random values between 0 and 1.
for (unsigned int i = 0; i < dof_handler->n_dofs (); ++i)
- solution(i) = (double) Testing::rand() / (double) RAND_MAX;
+ solution(i) = random_value<double>();
// Now check if the function is continuous in normal
// direction.
for (unsigned int i=0; i<n; ++i)
{
for (unsigned int j=0; j<n; ++j)
- A(i,j) = Testing::rand()/(1.0*RAND_MAX);
+ A(i,j) = random_value<double>();
for (unsigned int j=0; j<m; ++j)
{
- B(i,j) = Bt(j,i) = Testing::rand()/(1.0*RAND_MAX);
- D(j,i) = Dt(i,j) = Testing::rand()/(1.0*RAND_MAX);
+ B(i,j) = Bt(j,i) = random_value<double>();
+ D(j,i) = Dt(i,j) = random_value<double>();
}
}
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<m; ++j)
- C(i,j) = Testing::rand()/(1.0*RAND_MAX);
+ C(i,j) = random_value<double>();
// Compare first Schur complement
// with mmult.
FullMatrix<Number> A(2, 76), B(76, 3), C(2, 3), D(3, 2), E(2, 3);
for (unsigned int i=0; i<A.m(); ++i)
for (unsigned int j=0; j<A.n(); ++j)
- A(i,j) = (double)Testing::rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
for (unsigned int i=0; i<B.m(); ++i)
for (unsigned int j=0; j<B.n(); ++j)
- B(i,j) = (double)Testing::rand()/RAND_MAX;
+ B(i,j) = random_value<double>();
A.mmult(C, B); // C = A * B
B.TmTmult(D, A); // D = B^T * A^T
FullMatrix<Number> A(2, 76), B(3, 76), C(2, 3), D(2, 3);
for (unsigned int i=0; i<A.m(); ++i)
for (unsigned int j=0; j<A.n(); ++j)
- A(i,j) = (double)Testing::rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
for (unsigned int i=0; i<B.m(); ++i)
for (unsigned int j=0; j<B.n(); ++j)
- B(i,j) = (double)Testing::rand()/RAND_MAX;
+ B(i,j) = random_value<double>();
A.mTmult(C, B); // C = A * B^T
FullMatrix<Number> A(76, 2), B(76, 3), C(2, 3), D(2, 3);
for (unsigned int i=0; i<A.m(); ++i)
for (unsigned int j=0; j<A.n(); ++j)
- A(i,j) = (double)Testing::rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
for (unsigned int i=0; i<B.m(); ++i)
for (unsigned int j=0; j<B.n(); ++j)
- B(i,j) = (double)Testing::rand()/RAND_MAX;
+ B(i,j) = random_value<double>();
A.Tmmult(C, B); // C = A^T * B
std::vector<Point<dim>> points;
for (size_t i=0; i<n_points; ++i)
- {
- Point<dim> p;
- for (unsigned int d=0; d<dim; ++d)
- p[d] = double(Testing::rand())/RAND_MAX; //Normalizing the value
- points.push_back(p);
- }
+ points.push_back(random_point<dim>());
// Initializing the cache
GridTools::Cache<dim,dim> cache(tria);
deallog << "Points in study: " << n_points << std::endl;
for (size_t i=0; i<n_points; ++i)
- {
- //We need points in the square [0,1]x[0,1]: this is achieved normalizing with RAND_MAX
- //RAND_MAX for the used algorithm is 2147483647
- Point<spacedim> p;
- for (unsigned int d=0; d<spacedim; ++d)
- p[d] = double(Testing::rand())/RAND_MAX; //Normalizing the value
- points.push_back(p);
- }
+ points.push_back(random_point<spacedim>());
auto v_to_c = GridTools::vertex_to_cell_map (tria);
auto v_to_c_d = GridTools::vertex_to_cell_centers_directions (tria, v_to_c);
deallog << "Points in study: " << n_points << std::endl;
for (size_t i=0; i<n_points; ++i)
- {
- //We need points in the square [0,1]x[0,1]: this is achieved normalizing with RAND_MAX
- //RAND_MAX for the used algorithm is 2147483647
- Point<spacedim> p;
- for (unsigned int d=0; d<spacedim; ++d)
- p[d] = double(Testing::rand())/RAND_MAX; //Normalizing the value
- points.push_back(p);
- }
+ points.push_back(random_point<spacedim>());
auto &mapping = StaticMappingQ1<dim,spacedim>::mapping;
{
for (; cell != endc; ++cell)
{
- cell->set_active_fe_index ((int)(4.0 * (double) Testing::rand() / (double) RAND_MAX));
+ cell->set_active_fe_index ((int)(4.0 * random_value<double>()));
}
}
else
if (counter % 42 == 0)
local_mat(i,j) = 0;
else
- local_mat (i,j) = (double)Testing::rand() / RAND_MAX;
+ local_mat (i,j) = random_value<double>();
cell->get_dof_indices (local_dof_indices);
constraints.distribute_local_to_global (local_mat, local_dof_indices,
sparse);
if (counter % 42 == 0)
local_mat(i,j) = 0;
else
- local_mat (i,j) = (double)Testing::rand() / RAND_MAX;
+ local_mat (i,j) = random_value<double>();
cell->get_dof_indices (local_dof_indices);
constraints.distribute_local_to_global (local_mat, local_dof_indices,
sparse);
FullMatrix<number> matrix(n, n);
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<n; ++j)
- matrix(i,j) = -0.1 + 0.2 * Testing::rand()/RAND_MAX;
+ matrix(i,j) = random_value<double>(-.1, .1);
// put diagonal entries of different strengths. these are very challenging
// for GMRES and will usually take a lot of iterations until the Krylov
FullMatrix<number> matrix(n, n);
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<n; ++j)
- matrix(i,j) = -0.1 + 0.2 * Testing::rand()/RAND_MAX;
+ matrix(i,j) = random_value<double>(-.1, .1);
// put diagonal entries of different strengths. these are very challenging
// for GMRES and will usually take a lot of iterations until the Krylov
const unsigned int size = Testing::rand() % 100000;
LinearAlgebra::Vector<number> vec (size);
for (unsigned int i=0; i<size; ++i)
- vec(i) = static_cast<number>(Testing::rand())/static_cast<number>(RAND_MAX);
+ vec(i) = random_value<number>();
const typename LinearAlgebra::ReadWriteVector<number>::real_type norm = vec.l2_norm();
for (unsigned int i=0; i<30; ++i)
AssertThrow (vec.l2_norm() == norm, ExcInternalError());
Vector<double> in (size), out(size);
for (unsigned int i=0; i<size; ++i)
- in(i) = (double)Testing::rand()/RAND_MAX;
+ in(i) = random_value<double>();
PreconditionChebyshev<FullMatrixModified,Vector<double> > prec;
PreconditionChebyshev<FullMatrixModified,Vector<double> >::AdditionalData
Vector<double> in (size), out(size);
for (unsigned int i=0; i<size; ++i)
- in(i) = (double)Testing::rand()/RAND_MAX;
+ in(i) = random_value<double>();
PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual> prec;
PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual>::AdditionalData
for (unsigned int i=0; i<3; ++i)
{
for (unsigned int j=0; j<dim; ++j)
- v(j) = 1. * Testing::rand()/RAND_MAX;
+ v(j) = random_value<double>();
A.vmult (tmp1, v);
cheby_data.preconditioner->vmult (tmp2, tmp1);
Vector<double> in (size), out(size), ref(size), zero(size);
for (unsigned int i=0; i<size; ++i)
- in(i) = (double)Testing::rand()/RAND_MAX;
+ in(i) = random_value<double>();
PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual> prec;
PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual>::AdditionalData
for (unsigned int i=0; i<3; ++i)
{
for (unsigned int j=0; j<dim; ++j)
- v(j) = 1. * Testing::rand()/RAND_MAX;
+ v(j) = random_value<double>();
AA.vmult (tmp1, v);
cheby_data.preconditioner->vmult (tmp2, tmp1);
for (unsigned int i=0; i<3; ++i)
{
for (unsigned int j=0; j<dim; ++j)
- v(j) = 1. * Testing::rand()/RAND_MAX;
+ v(j) = random_value<double>();
A.vmult (tmp1, v);
ilu.vmult (tmp2, tmp1);
for (unsigned int i=0; i<3; ++i)
{
for (unsigned int j=0; j<dim; ++j)
- v(j) = 1. * Testing::rand()/RAND_MAX;
+ v(j) = random_value<double>();
A.Tvmult (tmp1, v);
ilu.Tvmult (tmp2, tmp1);
for (unsigned int i=0; i<3; ++i)
{
for (unsigned int j=0; j<dim; ++j)
- v(j) = 1. * Testing::rand()/RAND_MAX;
+ v(j) = random_value<double>();
A.vmult (tmp1, v);
mic.vmult (tmp2, tmp1);
PETScWrappers::MPI::Vector y(MPI_COMM_WORLD, dim, dim);
PETScWrappers::MPI::Vector x(MPI_COMM_WORLD, dim, dim);
for (unsigned int j=0; j<v0.size(); ++j)
- v0[j] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ v0[j] = random_value<double>();
v0.compress(VectorOperation::insert);
GrowingVectorMemory<PETScWrappers::MPI::Vector> vector_memory;
LinearAlgebra::distributed::Vector<double> init_vector;
mf_data->initialize_dof_vector(init_vector);
for (auto it = init_vector.begin(); it != init_vector.end(); ++it)
- *it = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ *it = random_value<double>();
constraints.set_zero(init_vector);
LinearAlgebra::distributed::Vector<double> init_vector;
mf_data->initialize_dof_vector(init_vector);
for (auto it = init_vector.begin(); it != init_vector.end(); ++it)
- *it = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ *it = random_value<double>();
constraints.set_zero(init_vector);
eigensolver.set_initial_vector(init_vector);
n_in++;
else
n_out++;
- x(i) = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ x(i) = random_value<double>();
}
deallog << " Modes inside/outside: " << n_in << " " << n_out << std::endl;
const unsigned int size = Testing::rand() % 100000;
Vector<number> vec (size);
for (unsigned int i=0; i<size; ++i)
- vec(i) = static_cast<number>(Testing::rand())/static_cast<number>(RAND_MAX);
+ vec(i) = random_value<number>();
const typename Vector<number>::real_type norm = vec.l2_norm();
for (unsigned int i=0; i<30; ++i)
AssertThrow (vec.l2_norm() == norm, ExcInternalError());
Vector<number> larger1 (size+8), larger2(size+8), in1(size), in2(size);
for (unsigned int i=0; i<size; ++i)
{
- in1(i) = static_cast<number>(Testing::rand())/static_cast<number>(RAND_MAX);
- in2(i) = static_cast<number>(Testing::rand())/static_cast<number>(RAND_MAX);
+ in1(i) = random_value<number>();
+ in2(i) = random_value<number>();
}
const number inner_product = in1 * in2;
Utilities::System::posix_memalign ((void **)&val, 64, sizeof(Number)*size);
for (unsigned int i = 0; i < size; ++i)
- val[i] = (double)rand()/RAND_MAX;
+ val[i] = random_value<double>();
internal::VectorOperations::MeanValue<Number> mean(val);
for (unsigned int i = 0; i < size; ++i)
for (unsigned int j = i; j < size; ++j)
{
- const double val = (double)Testing::rand()/RAND_MAX;
+ const double val = random_value<double>();
Assert (val >= 0. && val <= 1.,
ExcInternalError());
if (i==j)
{
for (unsigned int i = 0; i < A.m(); ++i)
for (unsigned int j = 0; j < A.n(); ++j)
- A(i,j) = (double)Testing::rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
}
LAPACKFullMatrix<double> AL(m, k), BL(k, n), CL(m, n);
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<k; ++j)
- A(i,j) = AL(i,j) = (double)rand()/RAND_MAX;
+ A(i,j) = AL(i,j) = random_value<double>();
for (unsigned int i=0; i<k; ++i)
for (unsigned int j=0; j<n; ++j)
- B(i,j) = BL(i,j) = (double)rand()/RAND_MAX;
+ B(i,j) = BL(i,j) = random_value<double>();
A.mmult(C, B);
AL.mmult(CL, BL);
LAPACKFullMatrix<double> AL(k,m), BL(k, n), CL(m, n);
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<k; ++j)
- A(j,i) = AL(j,i) = (double)rand()/RAND_MAX;
+ A(j,i) = AL(j,i) = random_value<double>();
for (unsigned int i=0; i<k; ++i)
for (unsigned int j=0; j<n; ++j)
- B(i,j) = BL(i,j) = (double)rand()/RAND_MAX;
+ B(i,j) = BL(i,j) = random_value<double>();
A.Tmmult(C, B);
AL.Tmmult(CL, BL);
LAPACKFullMatrix<double> AL(m, k), BL(n, k), CL(m, n);
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<k; ++j)
- A(i,j) = AL(i,j) = (double)rand()/RAND_MAX;
+ A(i,j) = AL(i,j) = random_value<double>();
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<k; ++j)
- B(i,j) = BL(i,j) = (double)rand()/RAND_MAX;
+ B(i,j) = BL(i,j) = random_value<double>();
A.mTmult(C, B);
AL.mTmult(CL, BL);
LAPACKFullMatrix<double> AL(k, m), BL(n, k), CL(m, n);
for (unsigned int i=0; i<k; ++i)
for (unsigned int j=0; j<m; ++j)
- A(i,j) = AL(i,j) = (double)rand()/RAND_MAX;
+ A(i,j) = AL(i,j) = random_value<double>();
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<k; ++j)
- B(i,j) = BL(i,j) = (double)rand()/RAND_MAX;
+ B(i,j) = BL(i,j) = random_value<double>();
A.TmTmult(C, B);
AL.TmTmult(CL, BL);
LAPACKFullMatrix<double> A(n,n);
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<n; ++j)
- A(i,j) = (double)rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
A.compute_lu_factorization();
LAPACKFullMatrix<double> rhs_orig(n, 3);
for (unsigned int i=0; i<3; ++i)
for (unsigned int j=0; j<n; ++j)
- rhs_orig(j,i) = 2.32 * rand() / RAND_MAX - 0.9923;
+ rhs_orig(j,i) =random_value<double>(-0.9923,1.3277);
for (unsigned int transpose=0; transpose < 2; ++transpose)
{
LAPACKFullMatrix<double> A(m,n);
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<n; ++j)
- A(i,j) = (double)rand()/RAND_MAX;
+ A(i,j) = random_value<double>();
LAPACKFullMatrix<double> A_check(A);
matrix_free->initialize_dof_vector(dst4);
for (unsigned int i = 0; i < src.local_size(); ++i)
- src.local_element(i) = (NumberType)Testing::rand()/RAND_MAX;
+ src.local_element(i) = random_value<NumberType>();
MatrixFreeOperators::MassOperator<dim,fe_degree, n_q_points, 1, LinearAlgebra::distributed::Vector<NumberType>> mf_mass;
MatrixFreeOperators::LaplaceOperator<dim,fe_degree, n_q_points, 1, LinearAlgebra::distributed::Vector<NumberType>> mf_laplace;
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in_dist(i) = entry;
}
for (unsigned int j=0; j<system_rhs.block(0).size(); ++j)
if (constraints_u.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(0)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(1).size(); ++j)
if (constraints_p.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(1)(j) = val;
}
for (unsigned int i=0; i<(M+1)/2; ++i)
for (unsigned int j=0; j<N; ++j)
{
- shape[i*N+j] = -1. + 2. * (double)Testing::rand()/RAND_MAX;
+ shape[i*N+j] = -1. + 2. * random_value<double>();
if (type == 1)
shape[(M-1-i)*N+N-1-j] = -shape[i*N+j];
else
double x[N], x_ref[N], y[M], y_ref[M];
for (unsigned int i=0; i<N; ++i)
- x[i] = (double)Testing::rand()/RAND_MAX;
+ x[i] = random_value<double>();
// compute reference
for (unsigned int i=0; i<M; ++i)
for (unsigned int i=0; i<M; ++i)
- y[i] = (double)Testing::rand()/RAND_MAX;
+ y[i] = random_value<double>();
// compute reference
for (unsigned int i=0; i<N; ++i)
for (unsigned int i=0; i<(M+1)/2; ++i)
for (unsigned int j=0; j<N; ++j)
{
- shape[i][j] = -1. + 2. * (double)Testing::rand()/RAND_MAX;
+ shape[i][j] = -1. + 2. * random_value<double>();
if (type == 1)
shape[M-1-i][N-1-j] = -shape[i][j];
else
double x[N], x_ref[N], y[M], y_ref[M];
for (unsigned int i=0; i<N; ++i)
- x[i] = (double)Testing::rand()/RAND_MAX;
+ x[i] = random_value<double>();
// compute reference
for (unsigned int i=0; i<M; ++i)
for (unsigned int i=0; i<M; ++i)
- y[i] = (double)Testing::rand()/RAND_MAX;
+ y[i] = random_value<double>();
// compute reference
for (unsigned int i=0; i<N; ++i)
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
constraints.distribute(solution);
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
{
if (constraints[no]->is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
src[no](i) = entry;
}
{
if (constraints[no]->is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
src[no](i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
constraints.distribute(solution);
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
constraints.distribute(solution);
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
constraints.distribute(solution);
// create vector with random entries
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution_dist(i) = entry;
}
// create vector with random entries
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution_dist(i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
// and their gradients
for (unsigned int q=0; q<n_q_points; ++q)
{
- values[q][j] = Testing::rand()/(double)RAND_MAX;
+ values[q][j] = random_value<double>();
for (unsigned int d=0; d<dim; ++d)
- gradients[q*dim+d][j] = -1. + 2. * (Testing::rand()/(double)RAND_MAX);
+ gradients[q*dim+d][j] = -1. + 2. * (random_value<double>());
}
fe_val.reinit (data.get_cell_iterator(cell,j));
data.get_cell_iterator(cell,j)->get_dof_indices(dof_indices);
// and their gradients
for (unsigned int q=0; q<n_q_points0; ++q)
{
- values0[q][j] = Testing::rand()/(double)RAND_MAX;
+ values0[q][j] = random_value<double>();
for (unsigned int d=0; d<dim; ++d)
- gradients0[q*dim+d][j] = -1. + 2. * (Testing::rand()/(double)RAND_MAX);
+ gradients0[q*dim+d][j] = -1. + 2. * (random_value<double>());
}
fe_val0.reinit (data.get_cell_iterator(cell,j,0));
data.get_cell_iterator(cell,j,0)->get_dof_indices(dof_indices0);
for (unsigned int q=0; q<n_q_points1; ++q)
{
- values1[q][j] = Testing::rand()/(double)RAND_MAX;
+ values1[q][j] = random_value<double>();
for (unsigned int d=0; d<dim; ++d)
- gradients1[q*dim+d][j] = -1. + 2. * (Testing::rand()/(double)RAND_MAX);
+ gradients1[q*dim+d][j] = -1. + 2. * (random_value<double>());
}
for (unsigned int i=0; i<dofs_per_cell1; ++i)
{
// and their gradients
for (unsigned int q=0; q<n_q_points0; ++q)
{
- values0[q][j] = Testing::rand()/(double)RAND_MAX;
+ values0[q][j] = random_value<double>();
for (unsigned int d=0; d<dim; ++d)
- gradients0[q*dim+d][j] = -1. + 2. * (Testing::rand()/(double)RAND_MAX);
+ gradients0[q*dim+d][j] = -1. + 2. * (random_value<double>());
}
fe_val0.reinit (data.get_cell_iterator(cell,j,0));
data.get_cell_iterator(cell,j,0)->get_dof_indices(dof_indices0);
for (unsigned int q=0; q<n_q_points1; ++q)
{
- values1[q][j] = Testing::rand()/(double)RAND_MAX;
+ values1[q][j] = random_value<double>();
for (unsigned int d=0; d<dim; ++d)
- gradients1[q*dim+d][j] = -1. + 2. * (Testing::rand()/(double)RAND_MAX);
+ gradients1[q*dim+d][j] = -1. + 2. * (random_value<double>());
}
for (unsigned int i=0; i<dofs_per_cell1; ++i)
{
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
}
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
}
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
}
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (out, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (out, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (out, in);
mf_data_0->initialize_dof_vector (in);
for (unsigned int i=0; i<in.local_size(); ++i)
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
mf_c0.initialize_dof_vector(out);
mf_c0.initialize_dof_vector(ref);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (out, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (ref, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in[0].local_element(i) = (double)Testing::rand()/RAND_MAX;
- in[1].local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in[0].local_element(i) = random_value<double>();
+ in[1].local_element(i) = random_value<double>();
}
mf.vmult (out, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.block(0).local_element(i) = (double)Testing::rand()/RAND_MAX;
- in.block(1).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.block(0).local_element(i) = random_value<double>();
+ in.block(1).local_element(i) = random_value<double>();
}
mf.vmult (out, in);
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
in_dist(i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
in_dist(i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
in_dist(i) = entry;
}
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.local_element(i) = random_value<double>();
}
mf.vmult (out, in);
{
if (constraints.is_constrained(dof.locally_owned_dofs().index_within_set(i)))
continue;
- in.block(0).local_element(i) = (double)Testing::rand()/RAND_MAX;
- in.block(1).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.block(0).local_element(i) = random_value<double>();
+ in.block(1).local_element(i) = random_value<double>();
}
mf.vmult (out, in);
{
if (constraints.is_constrained(dof.locally_owned_dofs().index_within_set(i)))
continue;
- in.block(0).local_element(i) = (double)Testing::rand()/RAND_MAX;
- in.block(1).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in.block(0).local_element(i) = random_value<double>();
+ in.block(1).local_element(i) = random_value<double>();
}
mf.vmult (out, in);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in[0].local_element(i) = (double)Testing::rand()/RAND_MAX;
- in[1].local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in[0].local_element(i) = random_value<double>();
+ in[1].local_element(i) = random_value<double>();
}
std::vector<LinearAlgebra::distributed::Vector<number> *> in_ptr(2), out_ptr(2);
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- in[0].local_element(i) = (double)Testing::rand()/RAND_MAX;
- in[1].local_element(i) = (double)Testing::rand()/RAND_MAX;
- in[2].local_element(i) = (double)Testing::rand()/RAND_MAX;
+ in[0].local_element(i) = random_value<double>();
+ in[1].local_element(i) = random_value<double>();
+ in[2].local_element(i) = random_value<double>();
}
std::vector<LinearAlgebra::distributed::Vector<number> *> in_ptr(3), out_ptr(3);
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in(i) = entry;
in_dist(i) = entry;
}
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<system_rhs.block(i).size(); ++j)
{
- const double val = -1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1. + 2.*random_value<double>();
system_rhs.block(i)(j) = val;
}
constraints.condense(system_rhs);
for (unsigned int i=0; i<dim; ++i)
for (unsigned int j=0; j<system_rhs.block(i).size(); ++j)
{
- const double val = -1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1. + 2.*random_value<double>();
system_rhs.block(i)(j) = val;
}
constraints.condense(system_rhs);
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
if (constraints.is_constrained(i) == false)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
}
// now perform matrix-vector product and check
{
if (constraints.is_constrained(i))
continue;
- in(i) = (double)Testing::rand()/RAND_MAX;
+ in(i) = random_value<double>();
}
mf.vmult (out, in);
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
if (constraints.is_constrained(i) == false)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
}
// now perform matrix-vector product and check
for (unsigned int i=0; i<dof.n_dofs(level); ++i)
{
if (mg_constraints[level].is_constrained(i) == false)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
}
// now perform matrix-vector product and check
for (unsigned int i=0; i<dim+1; ++i)
for (unsigned int j=0; j<system_rhs.block(i).size(); ++j)
{
- const double val = -1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1. + 2.*random_value<double>();
system_rhs.block(i)(j) = val;
vec1[i](j) = val;
}
for (unsigned int j=0; j<system_rhs.block(0).size(); ++j)
if (constraints_u.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(0)(j) = val;
mf_system_rhs.block(0)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(1).size(); ++j)
if (constraints_p.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(1)(j) = val;
mf_system_rhs.block(1)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(0).size(); ++j)
if (constraints_u.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(0)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(1).size(); ++j)
if (constraints_p.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(1)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(0).size(); ++j)
if (constraints_u.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(0)(j) = val;
}
for (unsigned int j=0; j<system_rhs.block(1).size(); ++j)
if (constraints_p.is_constrained(j) == false)
{
- const double val = -1 + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1 + 2.*random_value<double>();
system_rhs.block(1)(j) = val;
}
for (unsigned int i=0; i<dim+1; ++i)
for (unsigned int j=0; j<system_rhs.block(i).size(); ++j)
{
- const double val = -1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1. + 2.*random_value<double>();
system_rhs.block(i)(j) = val;
vec1[i](j) = val;
}
for (unsigned int i=0; i<dim+1; ++i)
for (unsigned int j=0; j<system_rhs.block(i).size(); ++j)
{
- const double val = -1. + 2.*(double)Testing::rand()/double(RAND_MAX);
+ const double val = -1. + 2.*random_value<double>();
system_rhs.block(i)(j) = val;
vec1[i](j) = val;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
in_dist(i) = entry;
}
for (unsigned int i=0; i<dof.n_dofs(); ++i)
{
if (constraints.is_constrained(i) == false)
- src(i) = (double)Testing::rand()/RAND_MAX;
+ src(i) = random_value<double>();
}
// now perform 30 matrix-vector products in
{
if (constraints.is_constrained(i))
continue;
- const double entry = Testing::rand()/(double)RAND_MAX;
+ const double entry = random_value<double>();
solution(i) = entry;
}
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- right.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ right.block(b).local_element(i) = random_value<double>();
}
mf.vmult (left.block(b), right.block(b));
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- left2.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ left2.block(b).local_element(i) = random_value<double>();
}
}
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- right.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ right.block(b).local_element(i) = random_value<double>();
}
mf.vmult (left.block(b), right.block(b));
owned_set.nth_index_in_set (i);
if (constraints.is_constrained(glob_index))
continue;
- left2.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ left2.block(b).local_element(i) = random_value<double>();
}
}
for (unsigned int i=0; i<col_partitioning.n_elements(); ++i)
{
const unsigned int global_index = col_partitioning.nth_index_in_set(i);
- dx(global_index) = (double)Testing::rand()/RAND_MAX;
+ dx(global_index) = random_value<double>();
x(global_index) = dx(global_index);
}
dy = 1.;
for (unsigned int i=0; i<row_partitioning.n_elements(); ++i)
{
const unsigned int global_index = row_partitioning.nth_index_in_set(i);
- dy(global_index) = (double)Testing::rand()/RAND_MAX;
+ dy(global_index) = random_value<double>();
y(global_index) = dy(global_index);
}
dx = 1.;
for (unsigned int i=0; i<col_partitioning.n_elements(); ++i)
{
const unsigned int global_index = col_partitioning.nth_index_in_set(i);
- dx(global_index) = (double)Testing::rand()/RAND_MAX;
+ dx(global_index) = random_value<double>();
x(global_index) = dx(global_index);
}
dy = 1.;
// set values:
for (unsigned int b = 0; b < nb; ++b)
for (unsigned int i=0; i<lbv[l].block(b).local_size(); ++i)
- lbv[l].block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ lbv[l].block(b).local_element(i) = random_value<double>();
lbv[l].compress(VectorOperation::insert);
}
MGLevelObject<LinearAlgebra::distributed::BlockVector<Number>> lbv2(0, tr.n_global_levels()-1);
for (unsigned int b=0; b < nb; ++b)
for (unsigned int i = 0; i < bv.block(b).local_size(); ++i)
- bv.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ bv.block(b).local_element(i) = random_value<double>();
transfer.copy_to_mg(mgdof, lbv2, bv);
// Also check that the block vector has its (global) size set on each level:
// set values:
for (unsigned int b = 0; b < nb; ++b)
for (unsigned int i=0; i<lbv[l].block(b).local_size(); ++i)
- lbv[l].block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ lbv[l].block(b).local_element(i) = random_value<double>();
lbv[l].compress(VectorOperation::insert);
}
MGLevelObject<LinearAlgebra::distributed::BlockVector<Number>> lbv2(0, tr.n_global_levels()-1);
for (unsigned int b=0; b < nb; ++b)
for (unsigned int i = 0; i < bv.block(b).local_size(); ++i)
- bv.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ bv.block(b).local_element(i) = random_value<double>();
transfer.copy_to_mg(mgdof_ptr, lbv2, bv);
// Also check that the block vector has its (global) size set on each level:
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v3.block(b).reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.block(b).local_size(); ++i)
- v1.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.block(b).local_element(i) = random_value<double>();
transfer_ref.prolongate(level, v2.block(b), v1.block(b));
}
v3.block(b).reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.block(b).local_size(); ++i)
- v1.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.block(b).local_element(i) = random_value<double>();
transfer_ref.restrict_and_add(level, v2.block(b), v1.block(b));
}
v3.block(b).reinit(mgdof_ptr[b]->locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.block(b).local_size(); ++i)
- v1.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.block(b).local_element(i) = random_value<double>();
transfer_ref[b].prolongate(level, v2.block(b), v1.block(b));
}
v3.block(b).reinit(mgdof_ptr[b]->locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.block(b).local_size(); ++i)
- v1.block(b).local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.block(b).local_element(i) = random_value<double>();
transfer_ref[b].restrict_and_add(level, v2.block(b), v1.block(b));
}
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.prolongate(level, v2, v1);
transfer_ref.prolongate(level, v3, v1_cpy);
v2.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
v3.reinit(mgdof.locally_owned_mg_dofs(level-1), MPI_COMM_WORLD);
for (unsigned int i=0; i<v1.local_size(); ++i)
- v1.local_element(i) = (double)Testing::rand()/RAND_MAX;
+ v1.local_element(i) = random_value<double>();
v1_cpy = v1;
transfer.restrict_and_add(level, v2, v1);
transfer_ref.restrict_and_add(level, v3, v1_cpy);
// to avoid dependency on SLEPc random numbers:
for (unsigned int i = 0; i < u.size(); i++)
for (unsigned int j=0; j<u[i].size(); ++j)
- u[i][j] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ u[i][j] = random_value<double>();
for (auto &vector : u)
vector.compress(VectorOperation::insert);
// to avoid dependency on random numbers:
for (unsigned int i = 0; i < u.size(); i++)
for (unsigned int j=0; j<u[i].size(); ++j)
- u[i][j] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ u[i][j] = random_value<double>();
for (auto &vector : u)
vector.compress(VectorOperation::insert);
{
eigenfunctions[i].reinit (locally_owned_dofs, mpi_communicator);//without ghost dofs
for (unsigned int j=0; j<locally_owned_dofs.n_elements(); ++j)
- eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = random_value<double>();
eigenfunctions[i].compress(dealii::VectorOperation::insert);
}
{
eigenfunctions[i].reinit (locally_owned_dofs, mpi_communicator);//without ghost dofs
for (unsigned int j=0; j<locally_owned_dofs.n_elements(); ++j)
- eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = random_value<double>();
eigenfunctions[i].compress(dealii::VectorOperation::insert);
}
{
eigenfunctions[i].reinit (locally_owned_dofs, mpi_communicator);//without ghost dofs
for (unsigned int j=0; j<locally_owned_dofs.n_elements(); ++j)
- eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX);
+ eigenfunctions[i][locally_owned_dofs.nth_index_in_set(j)] = random_value<double>();
eigenfunctions[i].compress(dealii::VectorOperation::insert);
}
#include <deal.II/base/utilities.h>
#include <deal.II/base/thread_management.h>
#include <deal.II/base/multithread_info.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/patterns.h>
#include <cmath>
#include <cstdlib>
#include <fstream>
+// Get a uniformly distributed random value between min and max
+template<typename T=double>
+T random_value(const T &min, const T &max)
+{
+ return min+(max-min)*(Testing::rand()/static_cast<T>(RAND_MAX));
+}
+
+
+
+// Same as above, but allows one to leave 0 as a default minimum value,
+// and specify only the maximum
+template<typename T=double>
+T random_value(const T &max=1)
+{
+ return random_value<T>(static_cast<T>(0), max);
+}
+
+
+
+// Construct a uniformly distributed random point, with each coordinate
+// between min and max
+template<int dim>
+inline Point<dim> random_point(const double &min=0.0,
+ const double &max=1.0)
+{
+ Assert(max >= min, ExcMessage("Make sure max>=min"));
+ Point<dim> p;
+ for (unsigned int i=0; i<dim; ++i)
+ p[i] = random_value(min, max);
+ return p;
+}
+
+
+
// given the name of a file, copy it to deallog
// and then delete it
void cat_file(const char *filename)