Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ex13: add mesh.refined(1) and everything is broken #799

Closed
gatling-nrl opened this issue Nov 18, 2021 · 4 comments · Fixed by #792
Closed

ex13: add mesh.refined(1) and everything is broken #799

gatling-nrl opened this issue Nov 18, 2021 · 4 comments · Fixed by #792

Comments

@gatling-nrl
Copy link
Contributor

Add mesh = mesh.refined(1) before line 40

mesh = mesh.translated(mesh.p[0] * np.stack([np.cos(mesh.p[1]),
np.sin(mesh.p[1])]) - mesh.p)
elements = ElementTriP2()
basis = Basis(mesh, elements)

and you get

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_21440/3992918866.py in <module>
     32 
     33 u = basis.zeros()
---> 34 u[basis.get_dofs("positive")] = 1.
     35 u = solve(*condense(A, x=u, D=basis.get_dofs({"positive", "ground"})))
     36 

c:\users\username\local\scikit-fem\skfem\assembly\basis\abstract_basis.py in get_dofs(self, facets, elements, skip)
    243                                               skip_dofnames=skip)
    244 
--> 245         facets = self._get_dofs_normalize_facets(facets)
    246         return self.dofs.get_facet_dofs(facets,
    247                                         skip_dofnames=skip)

c:\users\username\local\scikit-fem\skfem\assembly\basis\abstract_basis.py in _get_dofs_normalize_facets(self, facets)
    261             return self.mesh.facets_satisfying(facets)
    262         elif isinstance(facets, str):
--> 263             return self.mesh.boundaries[facets]
    264         raise NotImplementedError
    265 

TypeError: 'NoneType' object is not subscriptable
@gdmcbain
Copy link
Contributor

Ouch! #104?

@kinnala
Copy link
Owner

kinnala commented Nov 18, 2021

This is already fixed in #792, just waiting for it to be merged.

Edit: However, it is not fixed for all Mesh types.

We used to have a warning if boundaries and subdomains are invalidated by a refine but I have forgotten to include it in the large Mesh refactor in 3.0.0. I'll try adding it again.

Also some kind of proper error message would be nice if the boundary name does not exist when calling get_dofs.

@kinnala
Copy link
Owner

kinnala commented Nov 18, 2021

Let me add that currently subdomains are always invalidated by a refine.

@kinnala
Copy link
Owner

kinnala commented Nov 18, 2021

I did some changes in #792 and now it looks like this if refined does not preserve the names:

In [1]: from skfem import *                                                   

In [2]: m = MeshTet().refined()                                               
Named boundaries invalidated by a call to Mesh.refined()

In [3]: basis = Basis(m, ElementTetP1())                                      

In [4]: basis.get_dofs("left")                                                
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-9d9e979f36a3> in <module>
----> 1 basis.get_dofs("left")

~/src/scikit-fem/skfem/assembly/basis/abstract_basis.py in get_dofs(self, facets, elements, skip)
    243                                               skip_dofnames=skip)
    244 
--> 245         facets = self._get_dofs_normalize_facets(facets)
    246         return self.dofs.get_facet_dofs(facets,
    247                                         skip_dofnames=skip)

~/src/scikit-fem/skfem/assembly/basis/abstract_basis.py in _get_dofs_normalize_facets(self, facets)
    265                 return self.mesh.boundaries[facets]
    266             else:
--> 267                 raise ValueError("Boundary '{}' not found.".format(facets))
    268         raise NotImplementedError
    269 

ValueError: Boundary 'left' not found.

The ultimate goal, of course, is to have these preserved for all Mesh types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants