コード例 #1
0
'''
Domain mapping perturbation
'''
number_of_channels = len(CoefClass.ShapeRemember)

bending_perturbation = perturbations.MultipleMovingStripes(world, number_of_channels, space, thick, plot_mapping = True)
aFine_pert, f_pert = bending_perturbation.computePerturbation(aFine_with_defects, f_ref)
aFine_trans, f_trans = bending_perturbation.computeTransformation(aFine_with_defects, f_ref)


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

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

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

plt.figure('transformed')
drawCoefficient_origin(NFine, aFine_trans)

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


plt.show()

'''
Check whether domain mapping method works sufficiently good
コード例 #2
0
'''
plot data
'''

plt.figure("Coefficient")
if ROOT == "ex2_noisy":
    lim = [np.max(a_trans), np.min(a_trans)]  # for ex2
elif ROOT == "ex3_noisy":
    lim = [np.max(a_trans), np.min(a_ref)]  # for ex3
elif ROOT == "ex2":
    lim = [np.max(a_trans), np.min(a_trans)]  # for ex2
elif ROOT == "ex3":
    lim = [np.max(a_trans), np.min(a_ref)]  # for ex3
else:
    lim = None
drawCoefficient_origin(NFine, a_ref, lim=lim)
if extract_figures_to_files:
    for fmt in FIGURE_OUTPUTS:
        plt.savefig("tikz/{}_{}_original.{}".format(ROOT, name, fmt),
                    bbox_inches='tight',
                    dpi=dpi)

plt.figure("Perturbed coefficient")
drawCoefficient_origin(NFine, a_pert, lim=lim)
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')
コード例 #3
0
Construct diffusion coefficient
'''

space = 3 * factor
thick = 6 * factor

bg = 0.1  #background
val = 1  #values

soilinput = np.array([[8, 6, 3], [8, 3, 6], [10, 3, 4]])
soilMatrix = buildcoef2d.soil_converter(soilinput, NFine, BoundarySpace=space)
print(soilMatrix)

CoefClass = buildcoef2d.Coefficient2d(NFine,
                                      bg=bg,
                                      val=val,
                                      length=thick,
                                      thick=thick,
                                      space=space,
                                      probfactor=1,
                                      right=1,
                                      equidistant=True,
                                      BoundarySpace=True,
                                      soilMatrix=soilMatrix)

aFine = CoefClass.BuildCoefficient().flatten()

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

plt.show()
# Set reference coefficient
aCoarse_ref_shaped = CoefClass.BuildCoefficient()
aCoarse_ref = aCoarse_ref_shaped.flatten()
aFine_ref = func.evaluateDQ0(NCoeff, aCoarse_ref, xtFine_ref)

# Compute perturbed coefficient
# Coefficient and right hand side naming:
# ._pert    is a function defined on the uniform grid in the perturbed domain
# ._ref     is a function defined on the uniform grid in the reference domain
# ._trans   is a function defined on the uniform grid on the reference domain,
#           after transformation from the perturbed domain
aFine_pert = func.evaluateDQ0(NFine, aFine_ref, xtFine_ref)
aBack_ref = func.evaluateDQ0(NFine, aFine_pert, xtFine_pert)

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

plt.figure("a_perturbed")
drawCoefficient_origin(NFine, aFine_pert)

plt.figure("a_back")
drawCoefficient_origin(NFine, aBack_ref)

# aFine_trans is the transformed perturbed reference coefficient
aFine_trans = np.einsum('tji, t, tkj, t -> tik', psi.Jinv(xtFine), aFine_ref, psi.Jinv(xtFine), psi.detJ(xtFine))

f_pert = np.ones(np.prod(NFine+1))
f_ref = func.evaluateCQ1(NFine, f_pert, xpFine_pert)
f_trans = np.einsum('t, t -> t', f_ref, psi.detJ(xpFine))

#d3sol(NFine,f, 'right hand side NT')