Exemplo n.º 1
0
    lambda_n = np.zeros(nbc)
    md.add_initialized_fem_data('lambda_n', mflambda_partial, lambda_n)
    md.add_initialized_data('r', [r])
    OBS = mfd.eval(obstacle)  # np.array([mfd.eval(obstacle)])
    md.add_initialized_fem_data('obstacle', mfd, OBS)
    md.add_penalized_contact_with_rigid_obstacle_brick \
      (mim_friction, 'u', 'obstacle', 'r', GAMMAC, 2, 'lambda_n')

    for ii in range(100):
        print('iteration %d' % (ii + 1))
        md.solve('max_res', 1E-9, 'max_iter', niter)
        U = md.get('variable', 'u')
        lambda_n_old = lambda_n
        sol = gf.linsolve_superlu(
            M,
            gf.asm_integral_contact_Uzawa_projection(GAMMAC, mim_friction, mfu,
                                                     U, mflambda_partial,
                                                     lambda_n, mfd, OBS, r))
        lambda_n = sol[0].transpose()
        md.set_variable('lambda_n', lambda_n)
        difff = max(abs(lambda_n - lambda_n_old))[0] / max(abs(lambda_n))[0]
        print('diff : %g' % difff)
        if difff < penalty_parameter:
            break

    solved = True

elif version >= 10 and version <= 13:  # The integral version with friction, Newton

    mflambda.set_qdim(d)
    ldof = mflambda.dof_on_region(GAMMAC)
Exemplo n.º 2
0
def linsolve(M, B):  # Call Superlu to solve a sparse linear system
    return (((gf.linsolve_superlu(M, B))[0]).T)[0]
#####################################################################################################
# Assembly of the linear system for potential and solve.
try:
    mdmag.assembly(option='build_matrix')
    mdmag.assembly(option='build_rhs')
except:
    print("Something went wrong when building magnitic filed matrix")
finally:
    print("vector potential started at",
          time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()),
          'total dof number',
          mdmag.rhs().size)
    tm = time.time()
    #mdmag.solve()
    bb = gf.linsolve_superlu(mdmag.tangent_matrix(), mdmag.rhs())[0][:, 0]
    mdmag.set_variable('b', bb[:B_RHS.size])
    mdmag.set_variable('p', bb[B_RHS.size:])
    tm = time.time() - tm
    print("vector potential elapsed time %s " % datetime.timedelta(seconds=tm))
    print("vector potential L2_norm",
          gf.compute_L2_norm(mfb, mdmag.variable('b'), mim))
# Assembly of the linear system for potential and solve. END
#####################################################################################################
mfb.export_to_vtk('vector_potential3d.vtk', 'ascii',
                  mdmag.variable('b'))  # esport magnetic potential

####################################################################
# done vector potential part
####################################################################