コード例 #1
0
 def save_eigenvectors(self,n,file_name="output/modes.pvd",save_imaginary=False):
     eigenvalues = [] 
     eigenvectors = [] 
     file = File(self.comm,file_name)
     for i in range(n):
         eig, u_r, u_im = self.get_eigenpair(i)
         u_r.rename("mode real","mode real")
         file.write(u_r,i)
         if save_imaginary:
             u_im.rename("mode imaginary","mode imaginary")
             file.write(u_im,i)            
     return file_name
コード例 #2
0
ファイル: ParameterManager.py プロジェクト: dykesk/WindSE
    def Save(self, func, filename, subfolder="",val=0,file=None,filetype="default"):
        """
        This function is used to save the various dolfin.Functions created
        by windse. It should only be accessed internally.

        Args:
            func (dolfin.Function): The Function to be saved
            filename (str): the name of the function

        :Keyword Arguments:
            * **subfolder** (*str*): where to save the files within the output folder
            * **n** (*float*): used for saving a series of output. Use n=0 for the first save.

        """
        self.fprint("Saving: {0}".format(filename))

        ### Name the function in the meta data, This should probably be done at creation
        func.rename(filename,filename)

        if filetype == "default":
            filetype = self.save_file_type

        if file is None:
            ### Make sure the folder exists
            if not os.path.exists(self.folder+subfolder): os.makedirs(self.folder+subfolder)

            if filetype == "pvd":
                file_string = self.folder+subfolder+filename+".pvd"
                out = File(file_string)
                out << (func,val)
            elif filetype == "xdmf":
                file_string = self.folder+subfolder+filename+".xdmf"
                out = XDMFFile(file_string)
                out.write(func,val)

            return out

        else:
            if filetype == "pvd" or isinstance(func,type(Mesh)):
                file << (func,val)
            elif filetype == "xdmf":
                file.write(func,val)
コード例 #3
0
    V = FunctionSpace(mesh, 'CG', 3)
    x = interpolate(Expression('x[0]', degree=1), V)
    y = interpolate(Expression('x[1]', degree=1), V)

    basis = []
    for i in range(deg):
        for j in range(deg):
            basis.append(Eval((x**i) * (y**j)))

    ip = lambda u, v: u.vector().inner(v.vector())
    #ip = lambda u, v: assemble(inner(u, v)*dx)
    #ip = lambda u, v: assemble(inner(u, v)*dx + inner(grad(u), grad(v))*dx)

    # NOTE: skipping 1 bacause Eval of it is not a Function
    energy, pod_basis = pod(basis[1:], ip=ip)

    out = File('pod_test.pvd')
    for i, f in enumerate(pod_basis):
        f.rename('f', '0')
        out << (f, float(i))

    with XDMFFile(mesh.mpi_comm(), 'pod_test.xdmf') as out:
        for i, f in enumerate(pod_basis):
            f.rename('f', '0')
            out.write(f, float(i))

    for fi in pod_basis:
        for fj in pod_basis:
            print ip(fi, fj)
        print