How do I get adapted solution/mesh from AdaptiveNonlinearVariationalSolver?


208
views
0
6 months ago by
I've implemented a nonlinear problem using AdaptiveNonlinearVariationSolver.  It seems to be working great!  However, I seem to only be getting the solution on the original mesh when I got to save the result.

The `solve' code: 

  const double tol = 1.0e-5;
  solver->solve(tol);
  solver->summary();​

gives the result:

  Level  |  functional_value  error_estimate  tolerance  num_cells  num_dofs
  --------------------------------------------------------------------------
  0      |          0.372476     -0.00542166      1e-05        100       400
  1      |          0.365322     -0.00241628      1e-05        101       404
  2      |          0.361227    -0.000776095      1e-05        102       408
  3      |          0.360395    -0.000149968      1e-05        103       412
  4      |          0.360213     5.41196e-05      1e-05        104       416
  5      |          0.361027     7.38952e-05      1e-05        106       424
  6      |          0.361897     4.12015e-05      1e-05        108       432
  7      |          0.362406     3.35135e-05      1e-05        111       444
  8      |          0.363026     1.70329e-05      1e-05        115       460
  9      |          0.363427     1.24012e-05      1e-05        120       480
  10     |          0.363799      1.0119e-05      1e-05        127       508
  11     |          0.364113     6.99198e-06      1e-05        136       544
​

However, when I do something like

  auto h = std::make_shared<dfn::Function>(std::make_shared<dfn::Function>(soln->operator[](1))->leaf_node());

  std::cout << " NUM H CELLS: " << h->function_space()->mesh()->num_cells() << std::endl;​
 
It prints that the number of cells is 100, which is the original mesh.  Here 'soln' holds the solution to the nonlinear problem, which has two variables 'h' and 'u'.  When I plot the solution it looks like it is on the original mesh as well.  Does anyone know what I'm missing?
Community: FEniCS Project
Perhaps a related and even more relative question: why do the two dolfin::Functions that are returned by lead_node and root_node have the same value in the domain?
written 6 months ago by Andrew Davis  

1 Answer


0
6 months ago by
Changing the code to

  auto h = std::make_shared<dfn::Function>(soln->leaf_node() [1]);

  dfn::File file("solution.pvd");
  file << *h;
​
Outputs the correct solution to to the *.pvd file!  However, when I try to evaluate the function at specific points---for example

  const Eigen::VectorXd x = Eigen::VectorXd::LinSpaced(N, 0.0, 1.0);
  Eigen::VectorXd solution(N);
  for( unsigned int i=0; i<N; ++i ) {
    dfn::Array<double> xa(1);
    xa[0] = x(i);
    
    dfn::Array<double> sol(1);
    h->eval(sol, xa);

    solution(i) = sol[0];
  }
​

The eval still seems to be calling the course function.  Does anyone know why?
Nevermind, I made a stupid mistake reading the data!  It is working great now!
written 6 months ago by Andrew Davis  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »