underworldcode / underworld3

https://underworldcode.github.io/underworld3/
18 stars 10 forks source link

Error in Darcy solver #228

Open Sruthy-s-24 opened 1 month ago

Sruthy-s-24 commented 1 month ago

Describe the bug

I discussed this issue with Louis and reporting it as he requested. While using the Darcy solve if this line: darcy_solver.constitutive_model.Parameters.s = sympy.Matrix([0, 0]).T, is not there, I am getting this error message.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[15], line 1
----> 1 darcy_solver.solve()

File [~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py:337](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py#line=336), in SNES_Darcy.solve(self, zero_init_guess, timestep, verbose, _force_setup)
    324 """
    325 Generates solution to constructed system.
    326 
   (...)
    333     value used to evaluate inertial contribution
    334 """
    336 if (not self.is_setup) or _force_setup:
--> 337     self._setup_pointwise_functions(verbose)
    338     self._setup_discretisation(verbose)
    339     self._setup_solver(verbose)

File src[/underworld3/cython/petsc_generic_snes_solvers.pyx:717](http://localhost:8888/underworld3/cython/petsc_generic_snes_solvers.pyx#line=716), in underworld3.cython.generic_solvers.SNES_Scalar._setup_pointwise_functions()

File [~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py:277](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py#line=276), in SNES_Darcy.darcy_problem_description(self)
    274 self._f0 = self.F0.value
    276 # f1 residual term (integration by parts [/](http://localhost:8888/) gradients)
--> 277 self._f1 = self.F1.value
    279 # Flow calculation
    280 self._v_projector.uw_function = -self.F1.value

File [~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py:261](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py#line=260), in SNES_Darcy.F1(self)
    256 @property
    257 def F1(self):
    259     F1_val = uw.function.expression(
    260         r"\mathbf{F}_1\left( \mathbf{u} \right)",
--> 261         sympy.simplify(self.darcy_flux),
    262         "Darcy pointwise flux term: F_1(u)",
    263     )
    265     # backward compatibility
    266     self._f1 = F1_val.value

File [~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py:304](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/systems/solvers.py#line=303), in SNES_Darcy.darcy_flux(self)
    302 @property
    303 def darcy_flux(self):
--> 304     flux = self.constitutive_model.flux.T
    305     return flux

File [~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/constitutive_models.py:1584](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3_folder/src/underworld3/constitutive_models.py#line=1583), in DarcyFlowModel.flux(self)
   1577 @property
   1578 def flux(self):
   1579     """Computes the effect of the constitutive tensor on the gradients of the unknowns.
   1580     (always uses the `c` form of the tensor). In general cases, the history of the gradients
   1581     may be required to evaluate the flux.
   1582     """
-> 1584     ddu = self.grad_u - self.Parameters.s
   1586     return self._q(ddu)

File [~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/core/decorators.py:106](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/core/decorators.py#line=105), in call_highest_priority.<locals>.priority_decorator.<locals>.binary_op_wrapper(self, other)
    104         if f is not None:
    105             return f(self)
--> 106 return func(self, other)

File [~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/matrices/common.py:2937](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/matrices/common.py#line=2936), in MatrixArithmetic.__sub__(self, a)
   2935 @call_highest_priority('__rsub__')
   2936 def __sub__(self, a):
-> 2937     return self + (-a)

File [~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/core/decorators.py:106](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/core/decorators.py#line=105), in call_highest_priority.<locals>.priority_decorator.<locals>.binary_op_wrapper(self, other)
    104         if f is not None:
    105             return f(self)
--> 106 return func(self, other)

File [~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/matrices/common.py:2656](http://localhost:8888/lab/tree/~/Documents/codes/uw3-local-installation/uw3-env/lib/python3.11/site-packages/sympy-1.12-py3.11.egg/sympy/matrices/common.py#line=2655), in MatrixArithmetic.__add__(self, other)
   2653 if getattr(other, 'is_MatrixLike', False):
   2654     return MatrixArithmetic._eval_add(self, other)
-> 2656 raise TypeError('cannot add %s and %s' % (type(self), type(other)))

TypeError: cannot add <class 'sympy.matrices.dense.MutableDenseMatrix'> and <class 'sympy.core.mul.Mul'>
lmoresi commented 4 weeks ago

@julesghub - update on whether this is fixed for @Sruthy-s-24, please ?

bknight1 commented 4 weeks ago

Looks to have been updated in the latest dev branch: https://github.com/underworldcode/underworld3/blob/3ef67b9871a50d240993334d5dd1beef0f2127bb/src/underworld3/constitutive_models.py#L1509C1-L1513C14