Beispiel #1
0
def Draw(scene, *args, **kwargs):
    if _headless:
        scene.initGL()
        scene.update()
        return scene
    else:
        import ngsolve
        ngsolve.Draw(scene, *args, **kwargs)
        ngsolve.Redraw(blocking=True)
Beispiel #2
0
 def _solveStep(self):
     # reset the boundary condition after every refinement
     self._gfu.Set(self._g, definedon=self._mesh.Boundaries(".*"))
     # draw the solution if the gui is open
     if self.show_gui:
         ngs.Draw(self._gfu)
     # assamble the bilinear form
     self._a.Assemble()
     # assamble the linear functional
     self._f.Assemble()
     # solve the boundary value problem iteratively
     # if the solution does not converge, this is the first place to look
     ngs.solvers.BVP(bf=self._a, lf=self._f, gf=self._gfu, pre=self._c)
     if self.show_gui:
         ngs.Redraw(blocking=True)
Beispiel #3
0
              names=["mesh"], filename=meshfilename,
              subdivision=0).Do()
    VTKOutput(ma=mesh, coefs=[mu, mu],
              names=["pressure"], filename=solfilename,
              subdivision=p).Do()


def mark_for_refinement():

    # extract estimator component from solution:
    eh = [euz.components[i] for i in range(sep[0])]
    elerr = ngs.Integrate(vec(eh)*vec(eh) + waveA(eh,cwave)*waveA(eh,cwave),
                          mesh, ngs.VOL, element_wise=True)
    maxerr = max(abs(elerr.NumPy()))

    # mark elements
    for el in mesh.Elements():
        mesh.SetRefinementFlag(el, bool(abs(elerr[el.nr]) > markprm * maxerr))
    globalerr = sqrt(abs(sum(elerr)))
    print("Adaptive step %d: Estimated error=%g, Ndofs=%d"
          % (itcount, globalerr, X.ndof))


while X.ndof < 40000 and globalerr > 1.e-4:

    itcount += 1
    mesh.Refine()
    solve_on_current_mesh()
    ngs.Redraw(blocking=True)
    mark_for_refinement()
Beispiel #4
0
 def Redraw(self, blocking=False):
     ngsolve.Redraw(blocking=blocking)
Beispiel #5
0
                a.Apply(gfu.vec, xx)
                # print('damping:', damping)
                # print('curr:', ngs.Norm(curr))
                # print('xx:', ngs.Norm(xx))
                # print('w:', ngs.Norm(w))
                w2.data = mass.mat * curr
                mid.data = timestep/2 * (w + b) - w2 + b2
                # print('mid:', ngs.Norm(mid))

                a.AssembleLinearization(curr)
                mat.AsVector().data = timestep/2 * a.mat.AsVector() - mass.mat.AsVector()
                inv = mat.Inverse(V.FreeDofs())
                du.data = inv * mid
                # print('du:', ngs.Norm(du))
                curr.data -= damping * du
                # print('curr:', ngs.Norm(curr))

                a.Apply(curr, w)
                w2.data = mass.mat * curr
                new_mid.data = timestep/2 * (w + b) - w2 + b2
                # print('new_mid', ngs.Norm(new_mid))
                # if ngs.Norm(new_mid) < newton_safety_rho * ngs.Norm(mid):
                if ngs.Norm(new_mid) < ngs.Norm(mid):
                    break
                elif damping == newton_damping_sequence[-1]:
                    print("Damped Newton doesn't converge")
                    sys.exit()

        gfu.vec.data = curr.data
        ngs.Redraw()
    a.Assemble()
    L.Assemble()

    # solve EM problem
    res = L.vec.CreateVector()
    res.data = L.vec - a.mat * psi.vec
    psi.vec.data += a.mat.Inverse(V.FreeDofs()) * res

    # Update current time
    t += dt

    # assemble temperature problem
    L_1.Assemble()
    a_1.Assemble()

    # solve temperature problem
    res = L_1.vec.CreateVector()
    res.data = L_1.vec - a_1.mat * T_n1.vec
    T_n1.vec.data += a_1.mat.Inverse(VT.FreeDofs()) * res
    # Update previous solution
    T_n.Set(T_n1)

    # evaluate temperature at point of interest
    datafile.write("%f\t%f\n" % (t, T_n(mesh(0.5, 0.75))))
    ng.Redraw()

datafile.close()
hflux = -k_iso * ng.grad(T_n1)  # heat flux
# attemp to plot white arrows, does not work
ng.Draw(hflux, mesh, "flux")
Beispiel #7
0
    ngsolve.Draw(mesh, name="mesh")
    ngsolve.Draw(gfbf, mesh, name="bf")

dobft = False
if dobft:
    while True:
        bf_nr = int(0)
        if ngsolve.mpi_world.rank == 0:
            bf_nr = int(input('nr ?'))
            print('got nr', bf_nr)
        bf_nr = ngsolve.mpi_world.Sum(bf_nr)
        if ngsolve.mpi_world.rank == 1:
            gfbf.vec[:] = 0
            gfbf.vec[bf_nr] = 1
        ngsolve.mpi_world.Barrier()
        ngsolve.Redraw()

ngsolve.ngsglobals.msg_level = 5
print('V ndof', V.ndof)
pc_opts["ngs_amg_rots"] = rots
pc_opts["ngs_amg_reg_mats"] = False
pc_opts["ngs_amg_reg_rmats"] = False
pc_opts["ngs_amg_max_coarse_size"] = 3
pc_opts["ngs_amg_max_levels"] = 2
pc_opts["ngs_amg_first_aaf"] = 0.4
if noinv == True:
    pc_opts["ngs_amg_clev"] = "none"
pc_opts["ngs_amg_cinv_type"] = "masterinverse"
pc_opts["ngs_amg_sp_omega"] = 1.0
pc_opts["ngs_amg_log_level"] = "extra"
pc_opts["ngs_amg_enable_redist"] = True