bool ase_newer_than(const ase_string& f1, const ase_string& f2) { ase_utf16_string wf1(f1); ase_utf16_string wf2(f2); WIN32_FIND_DATAW fd1, fd2; auto_dir d1(FindFirstFileW(wf1.data(), &fd1)); if (d1.get() == INVALID_HANDLE_VALUE) { return false; } auto_dir d2(FindFirstFileW(wf2.data(), &fd2)); if (d2.get() == INVALID_HANDLE_VALUE) { return false; } return (CompareFileTime(&fd1.ftLastWriteTime, &fd2.ftLastWriteTime) > 0); }
int NNIEdgeTest(edge *e, tree *T, double **A, double *weight) { int a,b,c,d; edge *f; double *lambda; double D_LR, D_LU, D_LD, D_RD, D_RU, D_DU; double w1,w2,w0; if ((leaf(e->tail)) || (leaf(e->head))) return(NONE); lambda = (double *)malloc(3*sizeof(double)); a = e->tail->parentEdge->topsize; f = siblingEdge(e); b = f->bottomsize; c = e->head->leftEdge->bottomsize; d = e->head->rightEdge->bottomsize; lambda[0] = ((double) b*c + a*d)/((a + b)*(c+d)); lambda[1] = ((double) b*c + a*d)/((a + c)*(b+d)); lambda[2] = ((double) c*d + a*b)/((a + d)*(b+c)); D_LR = A[e->head->leftEdge->head->index][e->head->rightEdge->head->index]; D_LU = A[e->head->leftEdge->head->index][e->tail->index]; D_LD = A[e->head->leftEdge->head->index][f->head->index]; D_RU = A[e->head->rightEdge->head->index][e->tail->index]; D_RD = A[e->head->rightEdge->head->index][f->head->index]; D_DU = A[e->tail->index][f->head->index]; w0 = wf2(lambda[0],D_RU,D_LD,D_LU,D_RD,D_DU,D_LR); w1 = wf2(lambda[1],D_RU,D_LD,D_DU,D_LR,D_LU,D_RD); w2 = wf2(lambda[2],D_DU,D_LR,D_LU,D_RD,D_RU,D_LD); free(lambda); if (w0 <= w1) { if (w0 <= w2) /*w0 <= w1,w2*/ { *weight = 0.0; return(NONE); } else /*w2 < w0 <= w1 */ { *weight = w2 - w0; /* if (verbose) { printf("Swap across %s. ",e->label); printf("Weight dropping by %lf.\n",w0 - w2); printf("New weight should be %lf.\n",T->weight + w2 - w0); }*/ return(RIGHT); } } else if (w2 <= w1) /*w2 <= w1 < w0*/ { *weight = w2 - w0; /* if (verbose) { printf("Swap across %s. ",e->label); printf("Weight dropping by %lf.\n",w0 - w2); printf("New weight should be %lf.\n",T->weight + w2 - w0); }*/ return(RIGHT); } else /*w1 < w2, w0*/ { *weight = w1 - w0; /* if (verbose) { printf("Swap across %s. ",e->label); printf("Weight dropping by %lf.\n",w0 - w1); printf("New weight should be %lf.\n",T->weight + w1 - w0); }*/ return(LEFT); } }
int main(int argc, char **argv) { // Time measurement. TimePeriod cpu_time; cpu_time.tick(); // Load the mesh. Mesh mesh; MeshReaderH2D mloader; mloader.load("square.mesh", &mesh); // Perform initial mesh refinemets. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Set exact solution. CustomExactSolution exact(&mesh); // Initialize boundary conditions DefaultEssentialBCNonConst<double> bc_essential("Bdy", &exact); EssentialBCs<double> bcs(&bc_essential); // Initialize the weak formulation. CustomWeakFormPoisson wf1; // Create an H1 space with default shapeset. H1Space<double> space(&mesh, &bcs, P_INIT); int ndof = Space<double>::get_num_dofs(&space); info("ndof: %d", ndof); info("---- Assembling by DiscreteProblem, solving by %s:", MatrixSolverNames[matrix_solver].c_str()); // Initialize the linear discrete problem. DiscreteProblem<double> dp1(&wf1, &space); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix<double>* matrix = create_matrix<double>(matrix_solver); Vector<double>* rhs = create_vector<double>(matrix_solver); LinearSolver<double>* solver = create_linear_solver<double>(matrix_solver, matrix, rhs); #ifdef HAVE_AZTECOO if (matrix_solver == SOLVER_AZTECOO) { (dynamic_cast<AztecOOSolver<double>*>(solver))->set_solver(iterative_method); (dynamic_cast<AztecOOSolver<double>*>(solver))->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } #endif // Begin time measurement of assembly. cpu_time.tick(HERMES_SKIP); // Initial coefficient vector for the Newton's method. double* coeff_vec = new double[ndof]; memset(coeff_vec, 0, ndof*sizeof(double)); // Initialize the Newton solver. Hermes::Hermes2D::NewtonSolver<double> newton(&dp1, matrix_solver); // Perform Newton's iteration and translate the resulting coefficient vector into a Solution. Hermes::Hermes2D::Solution<double> sln1; try { newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) { e.printMsg(); error("Newton's iteration failed."); } Hermes::Hermes2D::Solution<double>::vector_to_solution(newton.get_sln_vector(), &space, &sln1); // CPU time measurement. double time = cpu_time.tick().last(); // Calculate errors. double rel_err_1 = Global<double>::calc_rel_error(&sln1, &exact, HERMES_H1_NORM) * 100; info("CPU time: %g s.", time); info("Exact H1 error: %g%%.", rel_err_1); delete(matrix); delete(rhs); delete(solver); // View the solution and mesh. ScalarView sview("Solution", new WinGeom(0, 0, 440, 350)); sview.show(&sln1); //OrderView oview("Polynomial orders", new WinGeom(450, 0, 400, 350)); //oview.show(&space); // TRILINOS PART: info("---- Assembling by DiscreteProblem, solving by NOX:"); // Initialize the weak formulation for Trilinos. CustomWeakFormPoisson wf2(TRILINOS_JFNK); // Initialize DiscreteProblem. DiscreteProblem<double> dp2(&wf2, &space); // Time measurement. cpu_time.tick(HERMES_SKIP); // Set initial vector for NOX. // NOTE: Using zero vector was causing convergence problems. info("Projecting to obtain initial vector for the Newton's method."); ZeroSolution init_sln(&mesh); // Initialize the NOX solver with the vector "coeff_vec". info("Initializing NOX."); NewtonSolverNOX<double> nox_solver(&dp2); nox_solver.set_output_flags(message_type); nox_solver.set_ls_type(iterative_method); nox_solver.set_ls_tolerance(ls_tolerance); nox_solver.set_conv_iters(max_iters); if (flag_absresid) nox_solver.set_conv_abs_resid(abs_resid); if (flag_relresid) nox_solver.set_conv_rel_resid(rel_resid); // Choose preconditioning. MlPrecond<double> pc("sa"); if (PRECOND) { if (TRILINOS_JFNK) nox_solver.set_precond(pc); else nox_solver.set_precond(preconditioner); } // Assemble and solve using NOX. Solution<double> sln2; OGProjection<double>::project_global(&space, &init_sln, coeff_vec); try { nox_solver.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) { e.printMsg(); error("NOX failed."); } Solution<double>::vector_to_solution(nox_solver.get_sln_vector(), &space, &sln2); info("Number of nonlin iterations: %d (norm of residual: %g)", nox_solver.get_num_iters(), nox_solver.get_residual()); info("Total number of iterations in linsolver: %d (achieved tolerance in the last step: %g)", nox_solver.get_num_lin_iters(), nox_solver.get_achieved_tol()); // CPU time needed by NOX. time = cpu_time.tick().last(); // Show the NOX solution. ScalarView view2("Solution<double> 2", new WinGeom(450, 0, 460, 350)); view2.show(&sln2); //view2.show(&exact); // Calculate errors. double rel_err_2 = Global<double>::calc_rel_error(&sln2, &exact, HERMES_H1_NORM) * 100; info("CPU time: %g s.", time); info("Exact H1 error: %g%%.", rel_err_2); // Wait for all views to be closed. View::wait(); return 0; }