コード例 #1
0
def test_add_field():
    pp = PostProcessor()

    pp.add_field(SolutionField("foo"))
    assert "foo" in pp._fields.keys()

    pp += SolutionField("bar")
    assert set(["foo", "bar"]) == set(pp._fields.keys())

    pp += [SolutionField("a"), SolutionField("b")]
    assert set(["foo", "bar", "a", "b"]) == set(pp._fields.keys())

    pp.add_fields([
        MetaField("foo"),
        MetaField2("foo", "bar"),
    ])

    assert set(["foo", "bar", "a", "b", "MetaField_foo",
                "MetaField2_foo_bar"]) == set(pp._fields.keys())
コード例 #2
0
def test_update_all():
    pressure = SolutionField("MockPressure")  #MockPressure()
    velocity = SolutionField("MockVelocity")  #MockVelocity()
    Du = MockVelocityGradient()
    epsilon = MockStrain(dict(start_timestep=3))
    sigma = MockStress(dict(start_time=0.5, end_time=0.8))

    # Add fields to postprocessor
    pp = PostProcessor()
    pp.add_fields([pressure, velocity, Du, epsilon, sigma])

    N = 11
    T = [(i, float(i) / (N - 1)) for i in xrange(N)]

    for timestep, t in T:
        pp.update_all(
            {
                "MockPressure": lambda: "p" + str(timestep),
                "MockVelocity": lambda: "u" + str(timestep)
            }, t, timestep)

        assert Du.touched == timestep + 1

        assert pp._cache[0]["MockPressure"] == "p%d" % timestep
        assert pp._cache[0]["MockVelocity"] == "u%d" % timestep
        assert pp._cache[0]["MockVelocityGradient"] == "grad(u%d)" % timestep

        if timestep >= 3:
            assert pp._cache[0][
                "MockStrain"] == "epsilon(grad(u%d))" % timestep
        else:
            assert "MockStrain" not in pp._cache[0]

        if 0.5 <= t <= 0.8:
            assert pp._cache[0][
                "MockStress"] == "sigma(epsilon(grad(u%d)), p%d)" % (timestep,
                                                                     timestep)
        else:
            assert "MockStress" not in pp._cache[0]
コード例 #3
0
ファイル: KinematicViscosity.py プロジェクト: fmoabreu/fluxo
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "KinematicViscosity", params, label)
コード例 #4
0
ファイル: FluidDensity.py プロジェクト: fmoabreu/fluxo
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "FluidDensity", params, label)
コード例 #5
0
ファイル: FluidDensity.py プロジェクト: fmoabreu/fluxo
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "FluidDensity", params, label)
コード例 #6
0
ファイル: Pressure.py プロジェクト: fmoabreu/fluxo
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "Pressure", params, label)
コード例 #7
0
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "Pressure", params, label)
コード例 #8
0
ファイル: Velocity.py プロジェクト: fmoabreu/fluxo
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "Velocity", params, label)
コード例 #9
0
 def __init__(self, params=None, label=None):
     SolutionField.__init__(self, "Velocity", params, label)
コード例 #10
0
ファイル: monodomain.py プロジェクト: daveb-dev/xalbrain
def run_splitting_solver(domain, dt, T):

    # Create cardiac model  problem description
    cell_model = Tentusscher_panfilov_2006_epi_cell()
    heart = setup_model(cell_model, domain)

    # Customize and create monodomain solver
    ps = SplittingSolver.default_parameters()
    ps["pde_solver"] = "monodomain"
    ps["apply_stimulus_current_to_pde"] = True

    # 2nd order splitting scheme
    ps["theta"] = 0.5

    # Use explicit first-order Rush-Larsen scheme for the ODEs
    ps["ode_solver_choice"] = "CardiacODESolver"
    ps["CardiacODESolver"]["scheme"] = "RL1"

    # Crank-Nicolson discretization for PDEs in time:
    ps["MonodomainSolver"]["theta"] = 0.5
    ps["MonodomainSolver"]["linear_solver_type"] = "iterative"
    ps["MonodomainSolver"]["algorithm"] = "cg"
    ps["MonodomainSolver"]["preconditioner"] = "petsc_amg"

    # Create solver
    solver = SplittingSolver(heart, params=ps)

    # Extract the solution fields and set the initial conditions
    (vs_, vs, vur) = solver.solution_fields()
    vs_.assign(cell_model.initial_conditions())
    solutions = solver.solve((0, T), dt)


    postprocessor = PostProcessor(dict(casedir="test", clean_casedir=True))
    postprocessor.store_mesh(heart.domain())

    field_params = dict(
        save=True,
        save_as=["hdf5", "xdmf"],
        plot=False,
        start_timestep=-1,
        stride_timestep=1
    )

    postprocessor.add_field(SolutionField("v", field_params))
    theta = ps["theta"]

    # Solve
    total = Timer("XXX Total cbcbeat solver time")
    for i, (timestep, (vs_, vs, vur)) in enumerate(solutions):

        t0, t1 = timestep
        current_t = t0 + theta*(t1 - t0)    
        postprocessor.update_all({"v": lambda: vur}, current_t, i)
        print("Solving on %s" % str(timestep))

        # Print memory usage (just for the fun of it)
        print(memory_usage())

    total.stop()

    # Plot result (as sanity check)
    #plot(vs[0], interactive=True)

    # Stop timer and list timings
    if MPI.rank(mpi_comm_world()) == 0:
        list_timings(TimingClear_keep, [TimingType_wall])