示例#1
0
def plot_1D_concentrations(t, cT, c1):
    # Cell concentrations are last in the cT / c1 vectors
    xc = simulation.compute_cell_centers()[:, 0]
    xn = simulation.vertices()[:, 0]
    import ComPASS.utils.mpl_backends as mpl_backends

    plt = mpl_backends.import_pyplot(False)
    if plt:
        plt.clf()
        plt.subplot(211)
        plt.plot(xc, cT[-nbCells:])
        plt.xticks(np.arange(0, Lx + 0.01, step=5))
        plt.title(f"t={t:.2f}")
        plt.ylabel("Total conc")
        plt.subplot(212)
        plt.plot(xc, c1[-nbCells:])
        plt.xticks(np.arange(0, Lx + 0.01, step=5))
        plt.xlabel("x in meters")
        plt.ylabel("C1 conc")
        plt.draw()
        plt.pause(0.1)

        plt.savefig(ComPASS.to_output_directory(f"conc_{t:.2f}.png"),
                    format="png")
示例#2
0
simulation.standard_loop(
    final_time=final_time,
    output_period=final_time / 10,
    initial_timestep=final_time / 100,
    output_callbacks=(collect_node_temperature, ),
)

if ComPASS.mpi.communicator().size == 1:
    assert ComPASS.mpi.is_on_master_proc
    x = simulation.compute_cell_centers()[:, 0]
    with open(ComPASS.to_output_directory("cell_temperatures.csv"), "w") as f:
        s = ";".join(["%f" % (xi) for xi in x])
        print('"time (years)\\x";' + s, file=f)
        for tT in cell_temperatures:
            t, T = tT
            T = K2degC(T)
            print("%f;" % (t / year) + ";".join(["%f" % (Ti) for Ti in T]),
                  file=f)
    import ComPASS.utils.mpl_backends as mpl_backends

    plt = mpl_backends.import_pyplot(False)
    if plt:
        plt.clf()
        for tT in cell_temperatures:
            t, T = tT
            T = K2degC(T)
            plt.plot(x, T)
        plt.xlabel("x in meters")
        plt.ylabel("temperature in Celsius degrees")
        plt.savefig(ComPASS.to_output_directory("cell_temperatures"))
示例#3
0
import ComPASS.utils.mpl_backends as mplb

plt = mplb.import_pyplot()

try:
    execfile
except NameError:

    def execfile(file, globals=globals(), locals=locals()):
        fh = open(file, "r")
        try:
            exec(fh.read() + "\n", globals, locals)
        finally:
            fh.close()


import petsc4py, sys

petsc4py.init(sys.argv)

from petsc4py import PETSc

try:
    range = xrange
except:
    pass

from petsc4py import PETSc

# grid size and spacing
m, n = 4, 4