简体   繁体   English

这种写/读解决方案的方式是否安全?

[英]Is that way of writing/reading a solution safe?

I need to store a solution of expensive FEM calculation to use it in further analysis. 我需要存储昂贵的FEM计算解决方案,以便在进一步分析中使用它。 Browsing through tutorials I have so far discovered, that I may store my results like this: 浏览我到目前为止发现的教程,我可以像这样存储我的结果:

from fenics import *

mesh = Mesh('mesh/UnitSquare8x8.xml')

V = FunctionSpace(mesh, 'P', 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)

def boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u_D, boundary)

A = assemble(a)
b = assemble(L)
bc.apply(A, b)

u = Function(V)    
solver = KrylovSolver("cg", "ilu")
solver.solve(A, u.vector(), b)

File('solution.xml') << u.vector()

and later load them like this: 然后像这样加载它们:

from fenics import *

mesh = Mesh('mesh/UnitSquare8x8.xml')
V = FunctionSpace(mesh, 'P', 1)
u = Function(V)

File('solution.xml') >> u.vector()

Unfortunately I hardly know what exactly I am doing here. 不幸的是,我几乎不知道我到底在做什么。 Is that a proper way of storing and loading calculated results? 这是存储和加载计算结果的正确方法吗? Is order of elements in u.vector() (for the same mesh file) fixed within/between different FEniCS versions, or it is just an implementation detail which may change any time? u.vector()的元素顺序(对于相同的网格文件)是在不同的FEniCS版本内/之间修复的,还是只是一个可能随时改变的实现细节? If it is unsafe, then what is the proper way of doing so? 如果它不安全,那么这样做的正确方法是什么?

I have found another (possibly even more dangerous) solution. 我找到了另一种(可能更危险的)解决方案。 I may use VALUES = u.vector().get_local() and u.vector().set_local(VALUES) methods, as VALUES is a numpy array which I may easily store and load. 我可以使用VALUES = u.vector().get_local()u.vector().set_local(VALUES)方法,因为VALUES是一个我可以轻松存储和加载的numpy数组。

No, according to answer to Is the order of Vector elements preserved between runs? 不,根据回答是否在运行之间保留了Vector元素的顺序? the order of Vector elements is not guarranted to be preserved. Vector元素的顺序不保证是保留的。

It is recommended to use XDMFFile.write_checkpoint() and XDMFFile.read_checkpoint() methods instead. 建议使用XDMFFile.write_checkpoint()XDMFFile.read_checkpoint()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Django应用程序写入/读取机密文件的解决方案有多安全? - How safe is a solution of writing/reading secret file from within Django app? 套接字线程读写1字节安全吗? - is socket thread safe in writing or reading a 1byte? 我从不同线程读取/写入pandas数据帧是否安全? - Is my reading/writing in pandas dataframe from differents threads is safe? 有读取,写入和保存excel文件的更快方法吗? - Is there a faster way on reading, writing and saving excel files? 对于问卷类型的网站,可以使写入文件/从文件读取安全吗? - Is it possible to make writing to files/reading from files safe for a questionnaire type website? 有更好的方法来处理以文本模式编写csv和以二进制模式读取的方法吗? - Is there a better way to handle writing csv in text mode and reading in binary mode? 弹性写入队列解决方案? - Elastic writing queue solution? Python测试 - 这是一种编写测试的安全方法,以避免在每个测试函数中重复长字典 - Python Testing - Is this a safe way of writing my tests to avoid repeating long dictionaries in each test function 使字符串安全进行CSV编写? - Make a string safe for CSV writing? 编写安全的,强制执行的Python类 - Writing safe, enforced Python classes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM