# Double exports in TXTExport

**URL:** <https://festim.discourse.group/t/double-exports-in-txtexport/58>\
**Category:** User Support\
**Created:** [July 12, 2024, 10:57pm UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58 "2024-07-12T22:57:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jairrs](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/jairrs/32/48_2.png) [@jairrs](https://festim.discourse.group/u/jairrs)\
**Post date:** [July 12, 2024, 10:57pm UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/1 "2024-07-12T22:57:04Z")

</div>

Running this code

```python
import festim as F
import numpy as np
import sympy as sp
from matplotlib import pyplot as plt

C_0 = 1 # atom m^-3
D = 1 # 1 m^2 s^-1
profile_time = 25 # s
exact_solution = C_0 * (1 - sp.erf(F.x / sp.sqrt(4*D*F.t)))

model = F.Simulation()

### Mesh Settings ###
vertices = np.concatenate([
    np.linspace(0, 1, 100),
    np.linspace(1, 20, 200),
])

model.mesh = F.MeshFromVertices(vertices)

model.boundary_conditions = [
    F.DirichletBC(surfaces=[1], value=C_0, field="solute")
]

model.materials = [F.Material(id=1, D_0=D, E_D=0)]

model.T = F.Temperature(500) # ignored in this problem

model.dt = F.Stepsize(
    initial_value=0.01,
    stepsize_change_ratio=1.1,
    milestones=[profile_time]
)

model.settings = F.Settings(
    absolute_tolerance=1e-10,
    relative_tolerance=1e-10,
    final_time=30
)

test_point_x = 0.45
derived_quantities = F.DerivedQuantities(
    [F.PointValue("solute", x=test_point_x)]
)
model.exports = [
    derived_quantities, 
    F.TXTExport(
        field="solute", 
        filename="./tmap_1b_concentration.txt",
        times=[profile_time]
    ),
]

model.initialise()
model.run()

```

gets me a .txt where every x except for 0 and 20 (the endpoints) appears twice with slightly different values, always 3 rows apart.

Example:  
 ![image](https://global.discourse-cdn.com/free1/uploads/festim/original/1X/4d14964dc0f18244ab74b5587fff960dca9043fc.png)

Why could this be?

---

<div class="post-metadata">

**Author:** ![jhdark](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/jhdark/32/13_2.png) [@jhdark](https://festim.discourse.group/u/jhdark)\
**Post date:** [July 13, 2024, 7:31am UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/2 "2024-07-13T07:31:35Z")

</div>

Hey @jairrs

I think this is happening because there’s no node in the mesh at the point x=0.45, just need to increase the number of divisions by a further one and you should have a node at that location:

```auto
vertices = np.concatenate([
    np.linspace(0, 1, 101),
    np.linspace(1, 20, 200),
])

```

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [July 13, 2024, 8:39am UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/3 "2024-07-13T08:39:57Z")

</div>

I don’t think the issue is related to x=0.45 but rather to the TXT export duplicating some lines. Maybe @VVKulagin has some hints?

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [July 13, 2024, 8:42am UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/4 "2024-07-13T08:42:05Z")

</div>

Actually I think this is due to a DG projection in TXTExport. I don’t think there is anything we can do about this.

If we want to get rid of that we could at least make sure that values are sorted by x

We could also expose the finite element to the users in the export

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [July 13, 2024, 9:49am UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/5 "2024-07-13T09:49:01Z")

</div>

> [@remidm](#):
>
> Actually I think this is due to a DG projection in TXTExport.

It’s indeed related to the DG projection.

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [July 13, 2024, 12:35pm UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/6 "2024-07-13T12:35:22Z")

</div>

@jairrs this is the explanation of what is going on:

Since we sometimes have discontinuous mobile concentration profiles (when we have dissimilar materials) then we need to project the field on a discontinuous functionspace to capture the discontinuities. This is done by using DG (Discontinuous Galerkin) elements.

A single DG element has the same number of degrees of freedom than a CG element but for CG, the dofs are shared on the edged (see below).

![image](https://global.discourse-cdn.com/free1/uploads/festim/original/1X/2e63978aac2a2f81a3e73e9612b4ad7904b88aaa.png)

This is why you see duplicated x coordinates with slightly different concentration values.

Several things you can do to get around this:

- sort the values according to x (this could potentially be done in FESTIM…)
- remove duplicated nodes with numpy unique `np.unique` or something similar.

---

<div class="post-metadata">

**Author:** ![jairrs](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/jairrs/32/48_2.png) [@jairrs](https://festim.discourse.group/u/jairrs)\
**Post date:** [July 13, 2024, 6:16pm UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/7 "2024-07-13T18:16:52Z")

</div>

I believe FESTIM should handle this. I don’t see any benefit to letting the user choose which concentration they want to use, and having both is confusing.

---

<div class="post-metadata">

**Author:** ![remidm](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/remidm/32/4_2.png) [@remidm](https://festim.discourse.group/u/remidm)\
**Post date:** [July 15, 2024, 6:10am UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/8 "2024-07-15T06:10:17Z")

</div>

Yes, these were just workarounds while we implement a proper fix.

First up these duplicates should be very similar to like the 10th digit! So just picking one or the other should not change the results whatsoever.

The thing is you do need to have both since when you have an interface, you want to know which is the concentration on both sides of the interface.

I guess the internal FESTIM process should be:

1. if there is only one material (or no conservation of chemical potential) then project to CG instead of DG
2. If there are interfaces, since `TXTExport` is only used in 1D, project to DG but only keep the duplicates where there are interfaces (based on the materials `border` argument)

---

<div class="post-metadata">

**Author:** ![VVKulagin](https://yyz2.discourse-cdn.com/free1/user_avatar/festim.discourse.group/vvkulagin/32/51_2.png) [@VVKulagin](https://festim.discourse.group/u/VVKulagin)\
**Post date:** [December 21, 2024, 3:23pm UTC](https://festim.discourse.group/t/double-exports-in-txtexport/58/9 "2024-12-21T15:23:51Z")

</div>

This issue should be resolved in the next 1.4 release. See [this PR](https://github.com/festim-dev/FESTIM/pull/883) for the details on the updated behavior of `TXTExport`.
