dofs in subdomain #764
gatling-nrl
started this conversation in
Show and tell
Replies: 2 comments 32 replies
-
How about ex26? scikit-fem/docs/examples/ex26.py Line 34 in 7500d1c |
Beta Was this translation helpful? Give feedback.
5 replies
-
This little bit of syntactic sugar made the app code much more readable class MyBasis(skfem.Basis):
def get_dofs(self, *args, **kwargs):
if 'subdomain' in kwargs:
mesh = self.mesh
subdomain = mesh.subdomains[kwargs['subdomain']]
return np.unique(self.element_dofs[:, subdomain])
elif 'facets_satisfying' in kwargs:
facets = self.mesh.facets_satisfying(kwargs['facets_satisfying'])
return super().get_dofs(facets).flatten()
else:
return super().get_dofs(*args, **kwargs).flatten() as in basis = MyBasis(skfem.io.from_meshio(mesh), skfem.ElementTriP1())
b_dofs = np.hstack([
basis.get_dofs(facets_satisfying=lambda x: np.isclose(x[0], 0)), # left
basis.get_dofs(facets_satisfying=lambda x: np.isclose(x[0], 1)), # right
basis.get_dofs(facets_satisfying=lambda x: np.isclose(x[1], 0)), # bottom
basis.get_dofs(subdomain='grounded_electrode'),
basis.get_dofs(subdomain='source_electrode'),
]) |
Beta Was this translation helpful? Give feedback.
27 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my application (solving Laplace's equation for electric potential) I have some embedded electrodes. Some of them act as boundary conditions and some act as probes. Each electrode occupies its own subdomain in the mesh. I want to get the dofs in these subdomains to set the boundary conditions, or in the case of the probes, compute the average potential.
I've got a working solution, I just think it's ugly and maybe not that fast. Ideas for improvement? Even though facets use midpoints and so I used midpoints here too, I don't trust
==
with floats. Hence thenp.linalg.norm
is acting like a broadcastableisclose
.Beta Was this translation helpful? Give feedback.
All reactions