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

Discussion for redesign #159

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,888 changes: 263 additions & 4,625 deletions conda-lock.yml

Large diffs are not rendered by default.

25 changes: 2 additions & 23 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,8 @@ channels:
dependencies:
- python>=3.10
# runtime
- fenics-dolfinx=0.6.0
- mpi4py=3.1.4
- scipy
- pint
- matplotlib
- python-gmsh=4.11.1
- meshio=5.3.4
- jsonschema
# tests
- pytest
- coverage
- toml
# docs
- sphinx
- sphinx-gallery
- myst-parser
- sphinx_rtd_theme
# environment
- conda-ecosystem-user-package-isolation
# formatting
- black
- isort
- pip
- pydantic
- numpy
- pip:
- -e .

36 changes: 36 additions & 0 deletions src/fenicsxconcrete/bcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from pydantic import ConfigDict, RootModel
from pydantic.dataclasses import dataclass
from pydantic.types import conlist
from typing import Callable, NewType
import numpy as np

Marker = NewType('Marker', int)

@dataclass(config=dict(arbitrary_types_allowed=True))
class DirichletBCDefinition:
"""
Definition of a time- and position-dependent Dirichlet boundary condition.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the Dirichlet boundary condition be defined in time? Just passing a np.ndarray or a function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would need to be a function $f(x,t)\mapsto y,\quad x\in\partial\Omega$, so in python a Callable[[np.ndarray, float],np.ndarray] . For simplicity, a numpy array would be interpreted as a constant BC at every point in time

Note that functions cannot be serialized to JSON!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the eval function, you could define a string and then convert that to a python function. The string can be stored in json

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that. To me, it screams security risk but then again, so would be importing any code you haven't written yourself

"""
marker: Marker | list[float] | Callable[[np.ndarray], np.ndarray]
value: conlist(float, min_length=1, max_length=3) | Callable[[np.ndarray, float], np.ndarray]
subspace: int | None
variable: str

@dataclass(config=dict(arbitrary_types_allowed=True))
class NeumannBCDefinition:
"""
Definition of a time- and position-dependent Neumann boundary condition.
"""
marker: Marker
value: conlist(float, min_length=1, max_length=3) | Callable[[np.ndarray, float], np.ndarray]

@dataclass(config=dict(arbitrary_types_allowed=True))
class BodyForceDefinition:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body force is very much mechanics driven, for the heat equation,this would be different (volumetric heat flux). I guess this would also just be a function of x and t and returns the corresponding term.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure what to do here. What would be the general term for body force? So any integral

$$ \int_\Omega \mathbf b \rho \mathrm d x $$

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source term?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how we should generalize this. As far as I see it, the body-force definition is constant because gravity is constant. But how is it with heat flux? From this doc https://www.simscale.com/docs/simulation-setup/boundary-conditions/volume-heat-flux/ I get that it could vary with time and position

Copy link
Member

@joergfunger joergfunger Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't that be the same as the functional representation of boundary conditions being a function of space and time? So there could certainly be constant or linear functions as standard (both relevant for body forces or linearly increasing boundary conditions) and then have the functional representation as additional option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but my question is more related to what should be allowed. In an ideal world, the data structure would ensure that only valid values (like constant gravity) are allowed, but I guess that should then be the responsibility of the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess it will be very hard to be able to define problems and test the validity beforehand (just from the syntax). And for Dirichlet BC I see now way around that, otherwise we are very limited, so then it makes no difference it that is added here again. But we could define two functions, one for BodyForce = constant and SpaceTimeDependentBodyForce(x,t).

value: conlist(float, min_length=1, max_length=3)

@dataclass(config=dict(arbitrary_types_allowed=True))
class InitialConditionDefinition:
value: list[float]
variable: str
2 changes: 0 additions & 2 deletions src/fenicsxconcrete/boundary_conditions/__init__.py

This file was deleted.

217 changes: 0 additions & 217 deletions src/fenicsxconcrete/boundary_conditions/bcs.py

This file was deleted.

Loading