File Formatting Bug in the task4 Workshop File

I’m running version 1.1.1 of FESTIM, and it seems like some minor file formatting issues are still persisting in the code (see here for the first issue). I discovered this on trying to run the task4 workshop notebook (found here). When trying to plot the results of the simulation, only the concentartion t = 80,000s is plotted, which is the end of the simulation. (It’s colored green below because of the messed up legend assigment.)

This can be compared to the preview seen on the Github repo:

image

I checked the mobile.txt file and it only had one column of data in it for t = 80,000s, despite 3 different timestamps being specified in the TXTExports() method:

folder = "task4"

derived_quantities_with_barrier = F.DerivedQuantities()
derived_quantities_with_barrier.derived_quantities = [F.HydrogenFlux(surface=2)]

txt_exports = F.TXTExports(
    fields=['solute'],
    labels=['mobile'],
    times=[100, 17000, 8e5],
    folder=folder
    )

model_barrier.exports = [derived_quantities_with_barrier] + txt_exports.exports

It seems that the bug stems from mobile.txt being overwritten every time the TXTExports() method is specified to write data to the file.

Thanks in advance to whoever can help, hopefully it’s an easy fix!

Thanks @ee-nn for reporting this.

The workshop hasn’t been updated yet for FESTIM>1.0 and so a few things don’t work anymore. This is something we need to do!

This is not a bug, it’s a change in behaviour.
Before 1.0, the TXTExport class used to modify the stepsize in order to pass through the correct times (eg. if the current time is 10, the current stepsize is 5, and the next export time is 11, then the stepsize is cutback to 1).

Instead, we introduced milestones in 1.0. Milestones can be defined in Settings in order to make sure the simulation hits these times.

Consider doing the following:

txt_exports = F.TXTExports(
    fields=['solute'],
    labels=['mobile'],
    times=[100, 17000, 8e5],
    folder=folder
    )

model_barrier.dt = F.Stepsize(
    initial_value=5,
    stepsize_change_ratio=1.1,
    milestones=txt_exports.times
)

The produced mobile.txt file is then corect:

x,t=100.0s,t=17000.0s,t=800000.0s
2.040816326530612004e-08,1.801426784891369688e+14,1.809394334257680312e+14,1.822464499449328125e+14
0.000000000000000000e+00,1.838152232121175000e+14,1.838152232121175312e+14,1.838152232121175312e+14
4.081632653061224008e-08,1.764701337983499688e+14,1.780636436413083438e+14,1.806776766777480625e+14
2.040816326530612004e-08,1.801426784891368750e+14,1.809394334257678750e+14,1.822464499449327188e+14

@VVKulagin maybe we could do something about this: at the initialisation phase, we could check if the times of the TXTExport are in the Settings.milestones, and if not, add them (with a message to the user).

I see. Thanks for the clarification and pointers! Great to know there’s a simple fix :slight_smile:

1 Like