Exemplo n.º 1
0
	T *get_chunk_value_at(unsigned int x, unsigned int z, const std::string &name) {
		unsigned int pos = z * region_file::REGION_SIZE + x;

		// check if x, z coord are out-of-bounds
		if(pos >= region_file::CHUNK_COUNT) {
			unsigned int coord[] = {x, z};
			std::vector<unsigned int> coord_vec(coord, coord + 2);
			throw region_file_exc(region_file_exc::OUT_OF_BOUNDS, coord_vec);
		}

		// cache tag data if cache-miss occurs
		if(fill[pos]
		        && data[pos].empty()) {
			region_file file(path);
			file.get_chunk_tag(x, z, data[pos]);
		}
		return dynamic_cast<T *>(data[pos].get_tag_by_name(name));
	}
void build_rigid_body_vectors(libMesh::ImplicitSystem&  input_system, MatNullSpace& nullsp_sys)
{
	// --- Set up some temporary variables to simplify code

	// System matrix pointer (only used to get the proper vector dimensions)
	libMesh::PetscMatrix<libMesh::Number> * mat_sys = libMesh::cast_ptr<libMesh::PetscMatrix<libMesh::Number>* >(input_system.matrix);

	/// Mesh address
	const libMesh::MeshBase& mesh_sys = input_system.get_mesh();

	// System number
	unsigned int sys_number = input_system.number();

	// --- Set the coordinates vector structure as the same of rigidity matrix
	Vec coord_vec_PETSC;
	PetscInt local_N;
	MatGetLocalSize(mat_sys->mat(),NULL,&local_N);
	VecCreate(mesh_sys.comm().get(),&coord_vec_PETSC);
	VecSetSizes(coord_vec_PETSC,local_N,mat_sys->n());
	VecSetBlockSize(coord_vec_PETSC,mesh_sys.mesh_dimension());
	VecSetFromOptions(coord_vec_PETSC);

	libMesh::PetscVector<libMesh::Number> coord_vec(coord_vec_PETSC,mesh_sys.comm());

	// --- Fill the coordinates vector
	auto node_it = mesh_sys.local_nodes_begin();
	auto node_it_end = mesh_sys.local_nodes_end();

	unsigned int dof_number = 0;

	for( ; node_it != node_it_end; ++node_it)
	{
		const libMesh::Node* node = *node_it;

		for(unsigned int var=0; var<node->n_dofs(sys_number); var++)
		{
			dof_number = node->dof_number(sys_number,var,0);
			coord_vec.set(dof_number,node->operator ()(var));
		}
	}

	MatNullSpaceCreateRigidBody(coord_vec.vec(),&nullsp_sys);
	VecDestroy(&coord_vec_PETSC);
};