本文整理汇总了Python中dolfin.Function.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Function.copy方法的具体用法?Python Function.copy怎么用?Python Function.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin.Function
的用法示例。
在下文中一共展示了Function.copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_precomputed_bessel_functions
# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import copy [as 别名]
def load_precomputed_bessel_functions(self, PS):
""" loads precomputed Bessel functions (modes of analytic solution) """
f = HDF5File(mpi_comm_world(), 'precomputed/precomputed_' + self.precomputed_filename + '.hdf5', 'r')
temp = toc()
fce = Function(PS)
f.read(fce, "parab")
self.bessel_parabolic = fce.copy(deepcopy=True)
for i in range(8):
f.read(fce, "real%d" % i)
self.bessel_real.append(fce.copy(deepcopy=True))
f.read(fce, "imag%d" % i)
self.bessel_complex.append(fce.copy(deepcopy=True))
print("Loaded partial solution functions. Time: %f" % (toc() - temp))
示例2: VTKToDOLFIN
# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import copy [as 别名]
class VTKToDOLFIN(object):
"""
A wrapper around vtk to simplify handling of VTK files
generated from DOLFIN.
The class handles reading of data into DOLFIN objects for further processing
"""
def __init__(self, filename, mesh=None, deepcopy=False):
"""
Initialize a the reader with a pvd or a vtu filename
"""
if not os.path.isfile(filename):
raise IOError("File '%s' does not excist"%filename)
filetype = filename.split(".")[-1]
self._name = ".".join(filename.split(".")[0:-1])
if filetype not in ["pvd", "vtu"]:
raise TypeError("Expected a 'pvd' or a 'vtu' file")
# Get dirname
dirname = os.path.dirname(filename)
# Check mesh argument
if mesh is not None and not isinstance(mesh, Mesh):
raise TypeError, "Expected a 'Mesh' for the mesh arguments"
# Store deepcopy argument
self._deepcopy = deepcopy
# Store mesh
self._mesh = mesh
# Initialize the filename cache
self._filenames = []
if filetype == "vtu":
self._filenames.append(filename)
self._times = np.array([])
else:
# Parse pvd file
tree = ElementTree(file=filename)
times = []
for item in tree.iter():
if item.tag == "DataSet":
self._filenames.append(os.path.join(\
dirname,item.attrib["file"]))
times.append(float(item.attrib["timestep"]))
times = np.array(times, dtype='d')
# If there are no time data stored in the file use an empty array
if np.all(np.diff(times)==1):
times = np.array([])
# Store time data
self._times = times
# Construct file reader
self.reader = vtk.vtkXMLUnstructuredGridReader()
# Read in data from file
self._update_vtk_data()
# Init dolfin structures (Function, FunctionSpace)
self._init_dolfin_data()
def _update_vtk_data(self, index=0):
"Set a new data file"
# Update file name
print "Reading '%s'"%self._filenames[index]
self.reader.SetFileName(self._filenames[index])
# Read data
self.reader.Update()
# Set data type (scalar or vector)
# FIXME: Include Tensors when that is supported by DOLFIN
self.scalar = self.reader.GetOutput().GetPointData().GetScalars() is not None
print "Scalar data set" if self.scalar else "Vector data set"
def _init_dolfin_data(self):
"Update DOLFIN function from vtk data"
if self.reader.GetNumberOfPointArrays() != 1:
raise ValueError("Expected the vtk file to include one data "\
"set per vertex.")
# Initilize FunctionSpace and Function if not initialized
if self.scalar:
self._V = FunctionSpace(self.mesh(), "CG", 1)
else:
self._V = VectorFunctionSpace(self.mesh(), "CG", 1)
self._u = Function(self._V)
def _update_dolfin_data(self):
"Update dolfin data from present VTK file"
# Get VTK point data
#.........这里部分代码省略.........