mesh-adaptation / animate

Anisotropic mesh adaptation toolkit for Firedrake
MIT License
6 stars 0 forks source link

Bubble shear on the fly adapt demo #145

Closed ddundo closed 2 weeks ago

ddundo commented 1 month ago

Closes #55. Closes #144.

ddundo commented 1 month ago

Still a few small things to sort out before ready for full review.

@stephankramer further to our discussion, could you please check that the run_simulation function looks good? No need to take a look at anything else :) I'd just like to have a solid problem and solver setup that I would then use in generating training data - where I would vary initial condition and velocity field. I'd keep everything else the same. So before doing that I'd like to make sure this looks good.

ddundo commented 3 weeks ago

Hey @jwallwork23, could you please review when you have a bit of time?

I had to comment out the rank check in RiemannianMetric as otherwise RiemannianMetric.sub() raises the following error:

Traceback (most recent call last):
  File "/home/ubuntu/software/firedrake-may24/src/animate/demos/bubble_shear.py", line 424, in <module>
    mesh = adapt_metric_advection(mesh, t0, t1, c)
  File "/home/ubuntu/software/firedrake-may24/src/animate/demos/bubble_shear.py", line 393, in adapt_metric_advection
    m_.assign(metric_.sub(2 * i + j))
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/home/ubuntu/software/firedrake-may24/src/firedrake/firedrake/function.py", line 349, in sub
    return self._components[i]
  File "/home/ubuntu/software/firedrake-may24/src/PyOP2/pyop2/utils.py", line 62, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/home/ubuntu/software/firedrake-may24/src/firedrake/firedrake/function.py", line 333, in _components
    return tuple(type(self)(self.function_space().sub(i), self.topological.sub(i))
  File "/home/ubuntu/software/firedrake-may24/src/firedrake/firedrake/function.py", line 333, in <genexpr>
    return tuple(type(self)(self.function_space().sub(i), self.topological.sub(i))
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/home/ubuntu/software/firedrake-may24/src/animate/animate/metric.py", line 89, in __init__
    raise ValueError(
ValueError: Riemannian metric should be matrix-valued, not rank-1 tensor-valued.

Do you see a nice workaround please? If it's not obvious, I'll keep digging :) other than that it should be good I think

jwallwork23 commented 3 weeks ago

Could you not just try interpolating metric_[i,j] rather than assigning a sub-component? It's not as efficient as assignment but generating a sub-component of a metric would take a bit of work by the looks of it.

jwallwork23 commented 3 weeks ago

Alternatively, just have a solver that acts on the full metric rather than a solver for each of it's components?

ddundo commented 2 weeks ago

Thanks a lot for the detailed review @jwallwork23! I'm sorry for doing such a terrible job at self-reviewing :) hopefully all is good now!

ddundo commented 2 weeks ago

Thanks again @jwallwork23! Addressed the final comments so will merge now.

(Cancelled the workflow since it's just text updates)