Exemplo n.º 1
0
if extract_figures_to_files:
    for fmt in FIGURE_OUTPUTS:
        plt.savefig("tikz/{}_{}_perturbed.{}".format(ROOT, name, fmt),
                    bbox_inches='tight',
                    dpi=dpi)

plt.figure('transformed')
drawCoefficient_origin(NFine, a_trans, transformed=True, lim=lim)
if extract_figures_to_files:
    for fmt in FIGURE_OUTPUTS:
        plt.savefig("tikz/{}_{}_transformed.{}".format(ROOT, name, fmt),
                    bbox_inches='tight',
                    dpi=dpi)

plt.figure('Right hand side')
draw_f(NFine + 1, f_ref)
if extract_figures_to_files:
    for fmt in FIGURE_OUTPUTS:
        plt.savefig("tikz/{}_{}_rhs.{}".format(ROOT, name, fmt),
                    bbox_inches='tight',
                    dpi=dpi)

plt.figure('Right hand side trans')
draw_f(NFine + 1, f_trans)
if extract_figures_to_files:
    for fmt in FIGURE_OUTPUTS:
        plt.savefig("tikz/{}_{}_rhs_trans.{}".format(ROOT, name, fmt),
                    bbox_inches='tight',
                    dpi=dpi)
'''
Plot solutions
Exemplo n.º 2
0
# ATTENTION : In this case TRANS means PERTURBED
aFine_trans = CoefClass.SpecificVanish(Number = numbers, Original=False).flatten()

'''
Plot diffusion coefficient and right hand side
'''

plt.figure("Coefficient")
drawCoefficient_origin(NFine, aFine_ref)

plt.figure("Perturbed coefficient")
drawCoefficient_origin(NFine, aFine_trans)

plt.figure('Right hand side')
draw_f(NFine+1, f_ref)

plt.show()

'''
Compute FEM
'''

uFineFull_trans, AFine_trans, _ = femsolver.solveFine(world, aFine_trans, f_ref, None, boundaryConditions)


'''
Set the coefficient that we want to approximate and the tolerance
'''

a_Fine_to_be_approximated = aFine_trans
boundaryConditions = np.array([[0, 0], [0, 0]])
world = World(NWorldCoarse, NCoarseElement, boundaryConditions)

f = np.zeros(NpFine)  #* 0.0001
f_reshaped = f.reshape(NFine + 1)
# f_ref_reshaped[int(0*fine/8):int(2*fine/8),int(0*fine/8):int(2*fine/8)] = 1
# f_ref_reshaped[int(6*fine/8):int(8*fine/8),int(6*fine/8):int(8*fine/8)] = 1
f_reshaped[int(4 * fine / 8):int(5 * fine / 8),
           int(4 * fine / 8):int(5 * fine / 8)] = 10
f = f_reshaped.reshape(NpFine)

plt.figure("Coefficient")
drawCoefficient_origin(NFine, aFine)

plt.figure('Right hand side')
draw_f(NFine + 1, f)

plt.show()

uSol, AFine, _ = femsolver.solveFine(world, aFine, f, None, boundaryConditions)

kList = [4]
NList = [32]
logH = {N: np.abs(np.log(np.sqrt(2 * (1. / N**2)))) for N in NList}
for N in NList:
    print('___________________________________________________')
    for k in kList:
        print(
            '   k = {}    H = 1/{}    logH = {:3f}   => k = {} should be sufficient'
            .format(k, N, logH[N], int(logH[N] + 0.99)),
            end='',