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

InitialConditionFromXDMF class #845

Open
RemDelaporteMathurin opened this issue Jul 31, 2024 · 0 comments
Open

InitialConditionFromXDMF class #845

RemDelaporteMathurin opened this issue Jul 31, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@RemDelaporteMathurin
Copy link
Collaborator

Currently we have the InitialCondition class that can be used for initialising fields with mathematical expressions or XDMF files.

From an mathematical expression:

my_ic = F.InitialCondition(value=F.x**2 + F.y**2, field=0)

From a XDMFfile:

my_ic = F.InitialCondition(
    value="ic_file.xdmf",
    label="mobile",
    time_step=-1,
    field=0
)

We then look check if value is a string and if it ends by .xdmf and initialise fields accordingly:

def get_comp(self, V, value, label=None, time_step=None):
if type(value) == str and value.endswith(".xdmf"):
comp = Function(V)
with XDMFFile(value) as f:
f.read_checkpoint(comp, label, time_step)

if self.transient and self.initial_condition:
if isinstance(self.initial_condition.value, str):
if self.initial_condition.value.endswith(".xdmf"):
with f.XDMFFile(self.initial_condition.value) as file:
file.read_checkpoint(
self.T_n,
self.initial_condition.label,
self.initial_condition.time_step,
)

Proposition

We could have a new class InitialConditionFromXDMF and remove the arguments label, time_step from InitialCondition.

This would make things less confusing and would make the implementation more straightforward, we now just have to check for the type of the initial condition object:

if isintance(initial_condition, F.InitialConditon):
    # do something
elif isinstance(initial_condition, F.InitialConditionFromXDMF):
    # do something else
@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Jul 31, 2024
@RemDelaporteMathurin RemDelaporteMathurin added this to the UKAEA workshop milestone Jul 31, 2024
@RemDelaporteMathurin RemDelaporteMathurin removed this from the UKAEA workshop milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant