当前位置: 首页>>代码示例>>C++>>正文


C++ Space::get_n_active_elem方法代码示例

本文整理汇总了C++中Space::get_n_active_elem方法的典型用法代码示例。如果您正苦于以下问题:C++ Space::get_n_active_elem方法的具体用法?C++ Space::get_n_active_elem怎么用?C++ Space::get_n_active_elem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Space的用法示例。


在下文中一共展示了Space::get_n_active_elem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
            it++;
        }

        // Starting with second adaptivity step, obtain new coarse
        // mesh solution via projecting the fine mesh solution.
        if(as > 1)
        {
            info("Projecting the fine mesh solution onto the coarse mesh.");
            // Project the fine mesh solution (defined on space_ref) onto the coarse mesh (defined on space).
            OGProjection::project_global(space, ref_space, matrix_solver);
        }

        // Calculate element errors and total error estimate.
        info("Calculating error estimate.");
        double err_est_array[MAX_ELEM_NUM];
        double err_est_rel = calc_err_est(NORM, space, ref_space, err_est_array) * 100;

        // Report results.
        info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%",
             Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel);

        // Time measurement.
        cpu_time.tick();

        // If exact solution available, also calculate exact error.
        if (EXACT_SOL_PROVIDED)
        {
            // Calculate element errors wrt. exact solution.
            double err_exact_rel = calc_err_exact(NORM, space, exact_sol, NEQ, A, B) * 100;

            // Info for user.
            info("Relative error (exact) = %g %%", err_exact_rel);

            // Add entry to DOF and CPU convergence graphs.
            graph_dof_exact.add_values(Space::get_num_dofs(space), err_exact_rel);
            graph_cpu_exact.add_values(cpu_time.accumulated(), err_exact_rel);
            if (as == 2)
                if (err_exact_rel > 1e-10) success_test = 0;
        }

        // Add entry to DOF and CPU convergence graphs.
        graph_dof_est.add_values(Space::get_num_dofs(space), err_est_rel);
        graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel);

        // Decide whether the relative error is sufficiently small.
        if(err_est_rel < TOL_ERR_REL) done = true;

        // Extra code for this test.
        if (as == 30)
        {
            if (err_est_rel > 1e-10) success_test = 0;
            if (space->get_n_active_elem() != 2) success_test = 0;
            Element *e = space->first_active_element();
            if (e->p != 2) success_test = 0;
            e = space->last_active_element();
            if (e->p != 2) success_test = 0;
            break;
        }

        // Returns updated coarse and fine meshes, with the last
        // coarse and fine mesh solutions on them, respectively.
        // The coefficient vectors and numbers of degrees of freedom
        // on both meshes are also updated.
        adapt(NORM, ADAPT_TYPE, THRESHOLD, err_est_array, space, ref_space);

        as++;

        // Plot meshes, results, and errors.
        adapt_plotting(space, ref_space, NORM, EXACT_SOL_PROVIDED, exact_sol);

        // Cleanup.
        delete solver;
        delete matrix;
        delete rhs;
        delete ref_space;
        delete dp;
        delete [] coeff_vec;

    }
    while (done == false);

    info("Total running time: %g s", cpu_time.accumulated());

    // Save convergence graphs.
    graph_dof_est.save("conv_dof_est.dat");
    graph_cpu_est.save("conv_cpu_est.dat");
    graph_dof_exact.save("conv_dof_exact.dat");
    graph_cpu_exact.save("conv_cpu_exact.dat");

    if (success_test)
    {
        info("Success!");
        return ERROR_SUCCESS;
    }
    else
    {
        info("Failure!");
        return ERROR_FAILURE;
    }
}
开发者ID:FranzGrenvicht,项目名称:hermes,代码行数:101,代码来源:main.cpp

示例2: main


//.........这里部分代码省略.........
      if(res_l2_norm < NEWTON_TOL_COARSE && it > 1) break;

      // Multiply the residual vector with -1 since the matrix 
      // equation reads J(Y^n) \deltaY^{n+1} = -F(Y^n).
      for(int i=0; i<ndof_coarse; i++) rhs_coarse->set(i, -rhs_coarse->get(i));
 
      // Solve the linear system.
      if(!solver_coarse->solve())
      error ("Matrix solver failed.\n");

      // Add \deltaY^{n+1} to Y^n.
      for (int i = 0; i < ndof_coarse; i++) coeff_vec_coarse[i] += solver_coarse->get_solution()[i];

      // If the maximum number of iteration has been reached, then quit.
      if (it >= NEWTON_MAX_ITER) error ("Newton method did not converge.");
      
      // Copy coefficients from vector y to elements.
      set_coeff_vector(coeff_vec_coarse, space);
      
      it++;
    }
    
    // Cleanup.
    delete matrix_coarse;
    delete rhs_coarse;
    delete solver_coarse;
    delete [] coeff_vec_coarse;
    delete dp_coarse;

    // For every element perform its fast trial refinement (FTR),
    // calculate the norm of the difference between the FTR
    // solution and the coarse space solution, and store the
    // error in the elem_errors[] array.
    int n_elem = space->get_n_active_elem();
    for (int i=0; i < n_elem; i++) 
    {

      info("=== Starting FTR of Elem [%d].", i);

      // Replicate coarse space including solution.
      Space *space_ref_local = space->replicate();

      // Perform FTR of element 'i'
      space_ref_local->reference_refinement(i, 1);
      info("Elem [%d]: fine space created (%d DOF).", 
             i, space_ref_local->assign_dofs());

      // Initialize the FE problem. 
      bool is_linear = false;
      DiscreteProblem* dp = new DiscreteProblem(&wf, space_ref_local, is_linear);

      // Set up the solver, matrix, and rhs according to the solver selection.
      SparseMatrix* matrix = create_matrix(matrix_solver);
      Vector* rhs = create_vector(matrix_solver);
      Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);

      // Newton's loop on the FTR space.
      // Fill vector coeff_vec using dof and coeffs arrays in elements.
      double *coeff_vec = new double[Space::get_num_dofs(space_ref_local)];
      get_coeff_vector(space_ref_local, coeff_vec);
      memset(coeff_vec, 0, Space::get_num_dofs(space_ref_local)*sizeof(double));

      int it = 1;
      while (1) 
      {
        // Obtain the number of degrees of freedom.
开发者ID:alieed,项目名称:hermes,代码行数:67,代码来源:main.cpp


注:本文中的Space::get_n_active_elem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。