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

Export data with TXTExport into single file #628

Merged
merged 26 commits into from
Nov 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5bd4f3d
Update exports.py
KulaginVladimir Nov 1, 2023
d4e8efd
Update txt_export.py
KulaginVladimir Nov 1, 2023
f1872ed
Update test_misc.py
KulaginVladimir Nov 2, 2023
1b22cc7
Update test_misc.py
KulaginVladimir Nov 2, 2023
1f74be4
Update test_txt_export.py
KulaginVladimir Nov 2, 2023
e15fa36
Update txt_export.py
KulaginVladimir Nov 2, 2023
8734036
Update test_misc.py
KulaginVladimir Nov 2, 2023
6815933
Update test_txt_export.py
KulaginVladimir Nov 2, 2023
e8c56ac
added TODO
RemDelaporteMathurin Nov 2, 2023
5501226
refactoring
RemDelaporteMathurin Nov 2, 2023
c5e5e78
fixed header
RemDelaporteMathurin Nov 2, 2023
4268f23
fixed tests
RemDelaporteMathurin Nov 2, 2023
4d750c7
Update festim/exports/txt_export.py
KulaginVladimir Nov 2, 2023
5d9adc6
Update txt_export.py
KulaginVladimir Nov 2, 2023
742a051
Merge remote-tracking branch 'kulaginvladimir/main' into txt_export_r…
RemDelaporteMathurin Nov 2, 2023
fa2f947
Merge pull request #1 from RemDelaporteMathurin/txt_export_refac
KulaginVladimir Nov 2, 2023
8f6f8f4
Update test_misc.py
KulaginVladimir Nov 2, 2023
f5242a6
Update txt_export.py
KulaginVladimir Nov 3, 2023
06120d1
Update test_misc.py
KulaginVladimir Nov 3, 2023
a1784dd
Update test_txt_export.py
KulaginVladimir Nov 3, 2023
01c8a01
Update txt_export.py
KulaginVladimir Nov 3, 2023
4edcc68
Update test_txt_export.py
KulaginVladimir Nov 3, 2023
1ae33cf
Update test_misc.py
KulaginVladimir Nov 3, 2023
24c7607
Update test/system/test_misc.py
KulaginVladimir Nov 3, 2023
748e383
Update festim/exports/txt_export.py
KulaginVladimir Nov 3, 2023
f26e219
Black formatted
KulaginVladimir Nov 3, 2023
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
Prev Previous commit
Next Next commit
Update txt_export.py
Black format
KulaginVladimir authored Nov 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e15fa362e7ab3a2786e3a89fa82fcbea49249c23
32 changes: 25 additions & 7 deletions festim/exports/txt_export.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ def is_it_time_to_export(self, current_time):
for time in self.times:
if np.isclose(time, current_time):
return True

return False

def when_is_next_time(self, current_time):
@@ -60,10 +59,10 @@ def write(self, current_time, nb_iteration, steady):
if self.is_it_time_to_export(current_time):
if steady:
filename = "{}/{}_steady.txt".format(self.folder, self.label)
header = 'x,t=steady'
header = "x,t=steady"
else:
filename = "{}/{}_transient.txt".format(self.folder, self.label)
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
header = 'x,t={}s'.format(current_time)
header = "x,t={}s".format(current_time)
x = f.interpolate(f.Expression("x[0]", degree=1), V_DG1)
# if the directory doesn't exist
# create it
@@ -72,16 +71,35 @@ def write(self, current_time, nb_iteration, steady):
os.makedirs(dirname, exist_ok=True)
# if steady or it is the first time to export
# write data
# else append new column to the existing file
# else append new column to the existing file
if steady or self.is_it_first_time_to_export(current_time, nb_iteration):
np.savetxt(filename, np.transpose([x.vector()[:], solution.vector()[:]]), header = header, delimiter = ',', comments='')
np.savetxt(
filename,
np.transpose([x.vector()[:], solution.vector()[:]]),
header=header,
delimiter=",",
comments="",
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
)
else:
# Update the header
old_file = open(filename)
header = old_file.readline().split('\n')[0] + ',t={}s'.format(current_time)
header = old_file.readline().split("\n")[0] + ",t={}s".format(
current_time
)
old_file.close()
# Append new column
np.savetxt(filename, np.column_stack([np.loadtxt(filename, delimiter = ',', skiprows = 1), np.transpose(solution.vector()[:])]), header=header, delimiter = ',', comments='')
np.savetxt(
filename,
np.column_stack(
[
np.loadtxt(filename, delimiter=",", skiprows=1),
np.transpose(solution.vector()[:]),
]
),
header=header,
delimiter=",",
comments="",
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
)


class TXTExports: