【问题标题】:Where are saved files in Google Colab located?Google Colab 中保存的文件位于何处?
【发布时间】:2020-03-16 06:54:56
【问题描述】:

我正在尝试访问保存热方程解的 VTK 文件,但我不知道它在 Colab 中的保存位置。

from fenics import *
import time
T = 2.0            # final time
num_steps = 50     # number of time steps
dt = T / num_steps # time step size
# Create mesh and define function space
nx = ny = 30
mesh = RectangleMesh(Point(-2, -2), Point(2, 2), nx, ny)
V = FunctionSpace(mesh, 'P', 1)
# Define boundary condition
def boundary(x, on_boundary):
    return on_boundary
bc = DirichletBC(V, Constant(0), boundary)
# Define initial value
u_0 = Expression('exp(-a*pow(x[0], 2) - a*pow(x[1], 2))',
                 degree=2, a=5)
u_n = interpolate(u_0, V)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
F = u*v*dx + dt*dot(grad(u), grad(v))*dx - (u_n + dt*f)*v*dx
a, L = lhs(F), rhs(F)
# Create VTK file for saving solution
vtkfile = File('heat_gaussian/solution.pvd')
# Time-stepping
u = Function(V)
t=0
for n in range(num_steps):
    # Update current time
    t += dt
    # Compute solution
    solve(a == L, u, bc)
    # Save to file and plot solution
    vtkfile << (u, t)
    plot(u)
    # Update previous solution
    u_n.assign(u)
# Hold plot
#interactive()

我试过了;

from google.colab import files
plt.savefig("vtkfile")
files.download("vtkfile")

from google.colab import files files.upload()
from google.colab import drive drive.mount('vtkfile')

但仍然出现错误。在 notebook 中创建的文件存储在哪里?

【问题讨论】:

    标签: python google-colaboratory vtk pde fenics


    【解决方案1】:

    在colab界面的左侧,有一个“文件”选项卡。您可以在那里找到您保存的所有文件。

    【讨论】:

    • 正是我的眼睛未能捕捉到的内容:D 谢谢!
    【解决方案2】:

    如果您安装了 GDrive,则文件应存储在名为 Colab Notebooks

    的文件夹中

    您还可以使用以下命令之一检查当前文件夹。

    %cd
    

    !pwd 
    

    【讨论】:

    • %cd 和 !pwd 都将 /root 作为输出。我找到了这些文件,但如何下载它们?
    【解决方案3】:

    作为@jules-cui 回答的补充,在 Colab 界面的左侧,您会看到一些图标。 单击文件夹图标,它将打开运行时中的所有文件。您可以单击右侧任何文件的扩展菜单,然后单击下载。

    【讨论】:

      【解决方案4】:

      为了补充之前的答案,如果您想将代码保存为 .py 文件,然后下载:%%writefile your_file.py

      例如:

      %%writefile test.py

      print('Hello World!')

      如果你想看看它是否有效:!python test.py

      输出:Hello World!

      要下载文件,请转到临时文件夹(左侧),在那里找到它。

      【讨论】:

        猜你喜欢
        • 2019-10-31
        • 1970-01-01
        • 2021-02-24
        • 2018-09-27
        • 2018-07-19
        • 2020-09-10
        • 1970-01-01
        • 1970-01-01
        • 2020-10-16
        相关资源
        最近更新 更多