Ejemplo n.º 1
0
int test_mesh3d_loader(char *file_name)
{
	_F_
	Mesh mesh;
	Mesh3DReader mloader;
	if (mloader.load(file_name, &mesh)) {
		mesh.dump();
		return ERROR_SUCCESS;
	}
	else {
		printf("failed\n");
		return ERROR_FAILURE;
	}
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{

	// Load the mesh. 
	Mesh mesh;
	Mesh3DReader mloader;
	mloader.load("lshape_hex.mesh3d", &mesh);

	// rough surface handler
	roughSurface r1 ;
	r1.setFilneName(std::string("1.surf")) ;
	r1.loadSurface() ;
	r1.findMinMax();

	columnList myCols ;
	bool further =true ;
	for(int iter=0 ; iter < 16 && further == true ; iter++)
	{
		std::cout << "Performing Refinement Level: " << iter << std::endl ;
		further = false ;
		for ( Word_t idx = mesh.elements.first(), _max = mesh.elements.count(); idx <= _max && idx != INVALID_IDX; idx = mesh.elements.next(idx) )
		if ( mesh.elements[idx]->used) if (mesh.elements[idx]->active)
		{
			std::vector<Word_t> vtcs(mesh.elements[idx]->get_num_vertices()) ;
			//Word_t vtcs[mesh.elements[idx]->get_num_vertices()] ;
			mesh.elements[idx]->get_vertices(&vtcs[0]) ;
			//mesh.vertices[vtcs[0]]->dump() ;
			double minX=+std::numeric_limits<double>::max() ;
			double maxX=-std::numeric_limits<double>::max() ; 
			double minY=+std::numeric_limits<double>::max() ;
			double maxY=-std::numeric_limits<double>::max() ; 
			double minZ=+std::numeric_limits<double>::max() ;
			double maxZ=-std::numeric_limits<double>::max() ; 

			for( int i=0 ; i<vtcs.size() ; i++)
			{
				double x = mesh.vertices[vtcs[i]]->x ;
				double y = mesh.vertices[vtcs[i]]->y ;
				if(minX > x) minX = x ;
				if(maxX < x) maxX = x ;      
				if(minY > y) minY = y ;
				if(maxY < y) maxY = y ;
			}

			double sX = 0.05e-6;
			double sY = 0.05e-6;
			double deltaX = (maxX-minX) ;
			double deltaY = (maxY-minY) ;
			int nX = (int)floor(deltaX/sX) ;
			int nY = (int)floor(deltaY/sY) ;
			for( int u=0 ; u<=nX ; u++) for( int u=0 ; u<nY ; u++)
			{
				double x = minX + u*sX ;
				double y = minY + u*sY ;
				double z = r1.interpolate(x, y) ;
				if(minZ > z) minZ = z ;
				if(maxZ < z) maxZ = z ;
			}
			myCols[corner(minX,minY)].elements.insert(idx) ;
			myCols[corner(minX,minY)].lo = minZ ;
			myCols[corner(minX,minY)].hi = maxZ ;

			double deltaZ = std::abs(maxZ - minZ) ;
			if( deltaZ > 2.e-6)
			{
				//std::cout << "\n Iter., element, A.R., deltaZ: " << iter << " " << idx << " " << 2.*3.e-6/deltaX << " " << deltaZ ;
				if(mesh.can_refine_element(idx, H3D_H3D_REFT_HEX_XY)) mesh.refine_element(idx, H3D_H3D_REFT_HEX_XY) ;
				further = true ;
			}
			//mesh.elements[idx]->dump() ;
		}  
	}


	//for ( Word_t idx = mesh.vertices.first(), _max = mesh.vertices.count(); idx <= _max && idx != INVALID_IDX; idx = mesh.vertices.next(idx) )
		//if( std::abs(mesh.vertices[idx]->z - 0.) < 1e-32 ) mesh.vertices[idx]->z = r1.interpolate(mesh.vertices[idx]->x,mesh.vertices[idx]->y) ;	

	for ( Word_t idx = mesh.elements.first(), _max = mesh.elements.count(); idx <= _max && idx != INVALID_IDX; idx = mesh.elements.next(idx) )
		if ( mesh.elements[idx]->used) if (mesh.elements[idx]->active)
		{
			std::vector<Word_t> vtcs(mesh.elements[idx]->get_num_vertices()) ;
			mesh.elements[idx]->get_vertices(&vtcs[0]) ;
			double minZ=+std::numeric_limits<double>::max() ;
			double maxZ=-std::numeric_limits<double>::max() ;
			double deltaZ=-std::numeric_limits<double>::max() ;

			for(std::vector<Word_t>::iterator i=vtcs.begin() ; i!=vtcs.end() ; i++)
			{
				double z = mesh.vertices[*i]->z ;
				if(minZ > z) minZ = z ;
				if(maxZ < z) maxZ = z ;
				deltaZ = std::abs(maxZ - minZ) ;
			}
			//std::cout << std::endl ;
			if(deltaZ > 6e-6)
			{
				if( mesh.can_refine_element(idx, H3D_REFT_HEX_Z) ) mesh.refine_element(idx, H3D_REFT_HEX_Z) ;
				//else if( mesh.can_refine_element(idx, H3D_H3D_H3D_REFT_HEX_XYZ) ) mesh.refine_element(idx, H3D_H3D_H3D_REFT_HEX_XYZ) ;
			}
		}

//mesh.refine_element(172, H3D_REFT_HEX_Z);
//mesh.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);
//mesh.refine_all_elements(H3D_REFT_HEX_Z);
//mesh.refine_element(4,H3D_H3D_H3D_REFT_HEX_XYZ);
 

	out_mesh(&mesh, "mesh");
	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **args) {
	int res = ERR_SUCCESS;

#ifdef WITH_PETSC
	PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL);
#endif
	set_verbose(false);

	TRACE_START("trace.txt");
	DEBUG_OUTPUT_ON;
	SET_VERBOSE_LEVEL(0);

	if (argc < 5) error("Not enough parameters");

	sscanf(args[2], "%d", &m);
	sscanf(args[3], "%d", &n);
	sscanf(args[4], "%d", &o);

	printf("* Loading mesh '%s'\n", args[1]);
	Mesh mesh;
	Mesh3DReader mloader;
	if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]);

	H1ShapesetLobattoHex shapeset;
	printf("* Setting the space up\n");
	H1Space space(&mesh, &shapeset);
	space.set_bc_types(bc_types);

	int mx = maxn(4, m, n, o, 4);
	order3_t order(mx, mx, mx);
//	order3_t order(1, 1, 1);
//	order3_t order(m, n, o);
	printf("  - Setting uniform order to (%d, %d, %d)\n", mx, mx, mx);
	space.set_uniform_order(order);

	int ndofs = space.assign_dofs();
	printf("  - Number of DOFs: %d\n", ndofs);

	printf("* Calculating a solution\n");

#if defined WITH_UMFPACK
	UMFPackMatrix mat;
	UMFPackVector rhs;
	UMFPackLinearSolver solver(&mat, &rhs);
#elif defined WITH_PARDISO
	PardisoMatrix mat;
	PardisoVector rhs;
	PardisoLinearSolver solver(&mat, &rhs);
#elif defined WITH_PETSC
	PetscMatrix mat;
	PetscVector rhs;
	PetscLinearSolver solver(&mat, &rhs);
#elif defined WITH_MUMPS
	MumpsMatrix mat;
	MumpsVector rhs;
	MumpsSolver solver(&mat, &rhs);
#endif

	WeakForm wf;
	wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM);
	wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>);
	wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<ord_t, ord_t>);

	LinearProblem lp(&wf, &space);

	// assemble stiffness matrix
	printf("  - assembling...\n"); fflush(stdout);
	Timer assemble_timer;
	assemble_timer.start();
	lp.assemble(&mat, &rhs);
	assemble_timer.stop();
	printf("%s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds());

	// solve the stiffness matrix
	printf("  - solving... "); fflush(stdout);
	Timer solve_timer;
	solve_timer.start();
	bool solved = solver.solve();
	solve_timer.stop();
	printf("%s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds());

//	mat.dump(stdout, "a");
//	rhs.dump(stdout, "b");

	if (solved) {
		Solution sln(&mesh);
		sln.set_coeff_vector(&space, solver.get_solution());

//		printf("* Solution:\n");
//		double *s = solver.get_solution();
//		for (int i = 1; i <= ndofs; i++) {
//			printf(" x[% 3d] = % lf\n", i, s[i]);
//		}

		ExactSolution ex_sln(&mesh, exact_solution);
		// norm
		double h1_sln_norm = h1_norm(&sln);
		double h1_err_norm = h1_error(&sln, &ex_sln);
		printf(" - H1 solution norm:   % le\n", h1_sln_norm);
		printf(" - H1 error norm:      % le\n", h1_err_norm);

		double l2_sln_norm = l2_norm(&sln);
		double l2_err_norm = l2_error(&sln, &ex_sln);
		printf(" - L2 solution norm:   % le\n", l2_sln_norm);
		printf(" - L2 error norm:      % le\n", l2_err_norm);

		if (h1_err_norm > EPS || l2_err_norm > EPS) {
			// calculated solution is not enough precise
			res = ERR_FAILURE;
		}

#if 0 //def OUTPUT_DIR
		printf("* Output\n");
		// output
		const char *of_name = OUTPUT_DIR "/solution.pos";
		FILE *ofile = fopen(of_name, "w");
		if (ofile != NULL) {
			ExactSolution ex_sln(&mesh, exact_solution);
			DiffFilter eh(&sln, &ex_sln);
//			DiffFilter eh_dx(&mesh, &sln, &ex_sln, FN_DX, FN_DX);
//			DiffFilter eh_dy(&mesh, &sln, &ex_sln, FN_DY, FN_DY);
//			DiffFilter eh_dz(&mesh, &sln, &ex_sln, FN_DZ, FN_DZ);

			GmshOutputEngine output(ofile);
			output.out(&sln, "Uh");
//			output.out(&sln, "Uh dx", FN_DX_0);
//			output.out(&sln, "Uh dy", FN_DY_0);
//			output.out(&sln, "Uh dz", FN_DZ_0);
			output.out(&eh, "Eh");
//			output.out(&eh_dx, "Eh dx");
//			output.out(&eh_dy, "Eh dy");
//			output.out(&eh_dz, "Eh dz");
			output.out(&ex_sln, "U");
//			output.out(&ex_sln, "U dx", FN_DX_0);
//			output.out(&ex_sln, "U dy", FN_DY_0);
//			output.out(&ex_sln, "U dz", FN_DZ_0);

			fclose(ofile);
		}
		else {
			warning("Can not open '%s' for writing.", of_name);
		}
#endif
	}
	else
		res = ERR_FAILURE;

#ifdef WITH_PETSC
	mat.free();
	rhs.free();
	PetscFinalize();
#endif

	TRACE_END;

	return res;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
	int res = ERR_SUCCESS;

#ifdef WITH_PETSC
	PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL);
#endif
	set_verbose(false);

	if (argc < 5) error("Not enough parameters.");

	H1ShapesetLobattoHex shapeset;

	printf("* Loading mesh '%s'\n", argv[1]);
	Mesh mesh;
	Mesh3DReader mloader;
	if (!mloader.load(argv[1], &mesh)) error("Loading mesh file '%s'\n", argv[1]);

	printf("* Setting the space up\n");
	H1Space space(&mesh, &shapeset);
	space.set_bc_types(bc_types);
	space.set_essential_bc_values(essential_bc_values);

	int o[3] = { 0, 0, 0 };
	sscanf(argv[2], "%d", o + 0);
	sscanf(argv[3], "%d", o + 1);
	sscanf(argv[4], "%d", o + 2);
	order3_t order(o[0], o[1], o[2]);
	printf("  - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z);
	space.set_uniform_order(order);

	WeakForm wf;
	wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM, ANY);
	wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>, ANY);

	LinearProblem lp(&wf);
	lp.set_space(&space);

	bool done = false;
	int iter = 0;
	do {
		Timer assemble_timer("Assembling stiffness matrix");
		Timer solve_timer("Solving stiffness matrix");

		printf("\n=== Iter #%d ================================================================\n", iter);

		printf("\nSolution\n");

#if defined WITH_UMFPACK
		UMFPackMatrix mat;
		UMFPackVector rhs;
		UMFPackLinearSolver solver(&mat, &rhs);
#elif defined WITH_PARDISO
		PardisoMatrix mat;
		PardisoVector rhs;
		PardisoLinearSolver solver(&mat, &rhs);
#elif defined WITH_PETSC
		PetscMatrix mat;
		PetscVector rhs;
		PetscLinearSolver solver(&mat, &rhs);
#elif defined WITH_MUMPS
		MumpsMatrix mat;
		MumpsVector rhs;
		MumpsSolver solver(&mat, &rhs);
#endif

		int ndofs = space.assign_dofs();
		printf("  - Number of DOFs: %d\n", ndofs);

		// assemble stiffness matrix
		printf("  - Assembling... "); fflush(stdout);
		assemble_timer.reset();
		assemble_timer.start();
		lp.assemble(&mat, &rhs);
		assemble_timer.stop();
		printf("done in %s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds());

		// solve the stiffness matrix
		printf("  - Solving... "); fflush(stdout);
		solve_timer.reset();
		solve_timer.start();
		bool solved = solver.solve();
		solve_timer.stop();
		if (solved)
			printf("done in %s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds());
		else {
			res = ERR_FAILURE;
			printf("failed\n");
			break;
		}

		printf("Reference solution\n");

#if defined WITH_UMFPACK
		UMFPackLinearSolver rsolver(&mat, &rhs);
#elif defined WITH_PARDISO
		PardisoLinearSolver rsolver(&mat, &rhs);
#elif defined WITH_PETSC
		PetscLinearSolver rsolver(&mat, &rhs);
#elif defined WITH_MUMPS
		MumpsSolver rsolver(&mat, &rhs);
#endif

		Mesh rmesh;
		rmesh.copy(mesh);
		rmesh.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);

		Space *rspace = space.dup(&rmesh);
		rspace->copy_orders(space, 1);

		LinearProblem rlp(&wf);
		rlp.set_space(rspace);

		int rndofs = rspace->assign_dofs();
		printf("  - Number of DOFs: %d\n", rndofs);

		printf("  - Assembling... "); fflush(stdout);
		assemble_timer.reset();
		assemble_timer.start();
		rlp.assemble(&mat, &rhs);
		assemble_timer.stop();
		printf("done in %s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds());

		printf("  - Solving... "); fflush(stdout);
		solve_timer.reset();
		solve_timer.start();
		bool rsolved = rsolver.solve();
		solve_timer.stop();
		if (rsolved)
			printf("done in %s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds());
		else {
			res = ERR_FAILURE;
			printf("failed\n");
			break;
		}

		Solution sln(&mesh);
		sln.set_coeff_vector(&space, solver.get_solution());

		Solution rsln(&rmesh);
		rsln.set_coeff_vector(rspace, rsolver.get_solution());

		printf("Adaptivity:\n");
		H1Adapt hp(&space);
		double tol = hp.calc_error(&sln, &rsln) * 100;
		printf("  - tolerance: "); fflush(stdout);
		printf("% lf\n", tol);
		if (tol < TOLERANCE) {
			printf("\nDone\n");
			ExactSolution ex_sln(&mesh, exact_solution);
			// norm
			double h1_sln_norm = h1_norm(&sln);
			double h1_err_norm = h1_error(&sln, &ex_sln);
			printf("  - H1 solution norm:   % le\n", h1_sln_norm);
			printf("  - H1 error norm:      % le\n", h1_err_norm);

			double l2_sln_norm = l2_norm(&sln);
			double l2_err_norm = l2_error(&sln, &ex_sln);
			printf("  - L2 solution norm:   % le\n", l2_sln_norm);
			printf("  - L2 error norm:      % le\n", l2_err_norm);

			if (h1_err_norm > EPS || l2_err_norm > EPS) {
				// calculated solution is not enough precise
				res = ERR_FAILURE;
			}

			break;
		}

		Timer t("");
		printf("  - adapting... "); fflush(stdout);
		t.start();
		hp.adapt(THRESHOLD);
		t.stop();
		printf("done in %lf secs (refined %d element(s))\n", t.get_seconds(), hp.get_num_refined_elements());

		iter++;
	} while (!done);


#ifdef WITH_PETSC
	PetscFinalize();
#endif

	return res;
}
Ejemplo n.º 5
0
/***********************************************************************************
 * main program                                                                    *
 ***********************************************************************************/
int main(int argc, char **argv) {
#ifdef WITH_PETSC
  PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL);
  PetscPushErrorHandler(PetscIgnoreErrorHandler, PETSC_NULL);                   // Disable PETSc error handler.
#endif

  // Load the initial mesh. 
  Mesh mesh;
  Mesh3DReader mloader;
  mloader.load("l-beam.mesh3d", &mesh);

  // Initial uniform mesh refinements. 
  printf("Performing %d initial mesh refinements.\n", INIT_REF_NUM);
  for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);
  Word_t (nelem) = mesh.get_num_elements();
  printf("New number of elements is %d.\n", (int) nelem);

  // Initialize the shapeset and the cache. 
  H1ShapesetLobattoHex shapeset;

#if defined WITH_UMFPACK
  UMFPackMatrix mat;
  UMFPackVector rhs;
  UMFPackLinearSolver solver(&mat, &rhs);
#elif defined WITH_PARDISO
  PardisoMatrix mat;
  PardisoVector rhs;
  PardisoLinearSolver solver(&mat, &rhs);
#elif defined WITH_PETSC
  PetscMatrix mat;
  PetscVector rhs;
  PetscLinearSolver solver(&mat, &rhs);
#elif defined WITH_MUMPS
  MumpsMatrix mat;
  MumpsVector rhs;
  MumpsSolver solver(&mat, &rhs);
#endif

  // Create H1 spaces x-displacement component. 
  H1Space xdisp(&mesh, &shapeset);
  xdisp.set_bc_types(bc_types_x);
  xdisp.set_uniform_order(order3_t(P_INIT, P_INIT, P_INIT));

  // Create H1 spaces y-displacement component. 
  H1Space ydisp(&mesh, &shapeset);
  ydisp.set_bc_types(bc_types_y);
  ydisp.set_uniform_order(order3_t(P_INIT, P_INIT, P_INIT));

  // Create H1 spaces z-displacement component. 
  H1Space zdisp(&mesh, &shapeset);
  zdisp.set_bc_types(bc_types_z);
  zdisp.set_uniform_order(order3_t(P_INIT, P_INIT, P_INIT));

  // Assign DOF. 
  int ndofs = 0;
  ndofs += xdisp.assign_dofs(ndofs);
  ndofs += ydisp.assign_dofs(ndofs);
  ndofs += zdisp.assign_dofs(ndofs);
  printf("  - Number of DOFs: %d\n", ndofs);

  // Initialized the Weak formulation.
  WeakForm wf(3);
  wf.add_matrix_form(0, 0, bilinear_form_0_0<double, scalar>, bilinear_form_0_0<ord_t, ord_t>, SYM);
  wf.add_matrix_form(0, 1, bilinear_form_0_1<double, scalar>, bilinear_form_0_1<ord_t, ord_t>, SYM);
  wf.add_matrix_form(0, 2, bilinear_form_0_2<double, scalar>, bilinear_form_0_2<ord_t, ord_t>, SYM);
  wf.add_vector_form_surf(0, surf_linear_form_0<double, scalar>, surf_linear_form_0<ord_t, ord_t>);

  wf.add_matrix_form(1, 1, bilinear_form_1_1<double, scalar>, bilinear_form_1_1<ord_t, ord_t>, SYM);
  wf.add_matrix_form(1, 2, bilinear_form_1_2<double, scalar>, bilinear_form_1_2<ord_t, ord_t>, SYM);
  wf.add_vector_form_surf(1, surf_linear_form_1<double, scalar>, surf_linear_form_1<ord_t, ord_t>);

  wf.add_matrix_form(2, 2, bilinear_form_2_2<double, scalar>, bilinear_form_2_2<ord_t, ord_t>, SYM);
  wf.add_vector_form_surf(2, surf_linear_form_2<double, scalar>, surf_linear_form_2<ord_t, ord_t>, 5);

  // Initialize the mesh problem.
  LinearProblem lp(&wf);
  lp.set_spaces(Tuple<Space *>(&xdisp, &ydisp, &zdisp));

  // Assemble stiffness matrix
  printf("  - Assembling... "); fflush(stdout);
  Timer tmr_assemble;
  tmr_assemble.start();
  bool assembled = lp.assemble(&mat, &rhs);
  tmr_assemble.stop();
  if (assembled)
    printf("done in %s (%lf secs)\n", tmr_assemble.get_human_time(), tmr_assemble.get_seconds());
  else
    error("failed!");

  // Solve the stiffness matrix.
  printf("  - Solving... "); fflush(stdout);
  Timer tmr_solve;
  tmr_solve.start();
  bool solved = solver.solve();
  tmr_solve.stop();
  if (solved)
    printf("done in %s (%lf secs)\n", tmr_solve.get_human_time(), tmr_solve.get_seconds());
  else {
    printf("failed\n");
  }

  // Construct a solution. 
  double *s = solver.get_solution();
  Solution xsln(&mesh), ysln(&mesh), zsln(&mesh);
  xsln.set_fe_solution(&xdisp, s);
  ysln.set_fe_solution(&ydisp, s);
  zsln.set_fe_solution(&zdisp, s);

  // Output the solutions. 
  printf("  - Output... "); fflush(stdout);
  out_fn(&xsln, &ysln, &zsln, "disp");
  printf("done\n");

#ifdef WITH_PETSC
  mat.free();
  rhs.free();
  PetscFinalize();
#endif

  return 1;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	_F_
	int ret = ERROR_SUCCESS;

	if (argc < 3) {
		fprintf(stderr, "ERROR: not enough parameters\n");
		return ERR_FAILURE;
	}

	if (strcmp(argv[1], "h1") != 0 && strcmp(argv[1], "h1-ipol")) {
		fprintf(stderr, "ERROR: unknown type of the projection\n");
		return ERR_FAILURE;
	}

#ifdef WITH_PETSC
	PetscInitialize(NULL, NULL, (char *) PETSC_NULL, PETSC_NULL);
#endif
	set_verbose(false);

	H1ShapesetLobattoHex shapeset;

	Mesh mesh;
	Mesh3DReader mloader;
	if (!mloader.load(argv[2], &mesh)) {
		fprintf(stderr, "ERROR: loading mesh file '%s'\n", argv[2]);
		return ERR_FAILURE;
	}

#if defined WITH_UMFPACK
	UMFPackMatrix mat;
	UMFPackVector rhs;
	UMFPackLinearSolver solver(&mat, &rhs);
#elif defined WITH_PARDISO
	PardisoMatrix mat;
	PardisoVector rhs;
	PardisoLinearSolver solver(&mat, &rhs);
#elif defined WITH_PETSC
	PetscMatrix mat;
	PetscVector rhs;
	PetscLinearSolver solver(&mat, &rhs);
#elif defined WITH_MUMPS
	MumpsMatrix mat;
	MumpsVector rhs;
	MumpsSolver solver(&mat, &rhs);
#endif

	Word_t ne = mesh.elements.count();
	// make the mesh for the ref. solution
	mesh.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);

	H1Space space(&mesh, &shapeset);
	space.set_bc_types(bc_types);
	space.set_essential_bc_values(essential_bc_values);

#if defined X2_Y2_Z2
	order3_t o(2, 2, 2);
#elif defined X3_Y3_Z3
	order3_t o(3, 3, 3);
#elif defined XN_YM_ZO
	order3_t o(2, 3, 4);
#endif
	space.set_uniform_order(o);

	WeakForm wf;
	wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM, ANY);
	wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>, ANY);

	LinearProblem lp(&wf, &space);

	space.assign_dofs();

	// assemble the stiffness matrix
	lp.assemble(&mat, &rhs);

	// solve the stiffness matrix
	solver.solve();

	Solution sln(&mesh);
	sln.set_coeff_vector(&space, solver.get_solution());

	for (Word_t idx = mesh.elements.first(); idx <= ne; idx = mesh.elements.next(idx)) {
		Element *e = mesh.elements[idx];

		order3_t order(4, 4, 4);
		double error;

		Projection *proj;
		if (strcmp(argv[1], "h1") == 0) proj = new H1Projection(&sln, e, &shapeset);
		else if (strcmp(argv[1], "h1-ipol") == 0) proj = new H1ProjectionIpol(&sln, e, &shapeset);
		else return ERR_FAILURE;

		//
		error = 0.0;
		error += proj->get_error(H3D_REFT_HEX_NONE, -1, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_REFT_HEX_X, 20, order);
		error += proj->get_error(H3D_REFT_HEX_X, 21, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_REFT_HEX_Y, 22, order);
		error += proj->get_error(H3D_REFT_HEX_Y, 23, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_REFT_HEX_Z, 24, order);
		error += proj->get_error(H3D_REFT_HEX_Z, 25, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_H3D_REFT_HEX_XY,  8, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XY,  9, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XY, 10, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XY, 11, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_H3D_REFT_HEX_XZ, 12, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XZ, 13, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XZ, 14, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_XZ, 15, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		error += proj->get_error(H3D_H3D_REFT_HEX_YZ, 16, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_YZ, 17, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_YZ, 18, order);
		error += proj->get_error(H3D_H3D_REFT_HEX_YZ, 19, order);
		error = sqrt(error);
		CHECK_ERROR;

		//
		error = 0.0;
		for (int j = 0; j < 8; j++)
			error += proj->get_error(H3D_H3D_H3D_REFT_HEX_XYZ, j, order);
		error = sqrt(error);
		CHECK_ERROR;

		delete proj;
	}

#ifdef WITH_PETSC
	PetscFinalize();
#endif

	return ret;
}