コード例 #1
0
ファイル: test_L2tracking.py プロジェクト: mfkiwl/fireshape
def run_L2tracking_optimization(write_output=False):
    """ Test template for fsz.LevelsetFunctional."""

    # tool for developing new tests, allows storing shape iterates
    if write_output:
        out = fd.File("domain.pvd")

        def cb(*args):
            out.write(Q.mesh_m.coordinates)

        cb()
    else:
        cb = None

    # setup problem
    mesh = fd.UnitSquareMesh(30, 30)
    Q = fs.FeControlSpace(mesh)
    inner = fs.ElasticityInnerProduct(Q)
    q = fs.ControlVector(Q, inner)

    # setup PDE constraint
    mesh_m = Q.mesh_m
    e = PoissonSolver(mesh_m)

    # create PDEconstrained objective functional
    J_ = L2trackingObjective(e, Q, cb=cb)
    J = fs.ReducedObjective(J_, e)

    # ROL parameters
    params_dict = {
        'General': {
            'Secant': {
                'Type': 'Limited-Memory BFGS',
                'Maximum Storage': 10
            }
        },
        'Step': {
            'Type': 'Line Search',
            'Line Search': {
                'Descent Method': {
                    'Type': 'Quasi-Newton Step'
                }
            },
        },
        'Status Test': {
            'Gradient Tolerance': 1e-4,
            'Step Tolerance': 1e-5,
            'Iteration Limit': 15
        }
    }

    # assemble and solve ROL optimization problem
    params = ROL.ParameterList(params_dict, "Parameters")
    problem = ROL.OptimizationProblem(J, q)
    solver = ROL.OptimizationSolver(problem, params)
    solver.solve()

    # verify that the norm of the gradient at optimum is small enough
    state = solver.getAlgorithmState()
    assert (state.gnorm < 1e-4)
コード例 #2
0
# import sys; sys.exit()

directory = f"./output/stokes/base_{base_inner}_cr_{use_cr}/"
if not os.path.exists(directory):
    os.makedirs(directory, exist_ok=True)
out = fd.File(directory + "u.pvd")

vol = fsz.LevelsetFunctional(fd.Constant(1.0), Q)
baryx = fsz.LevelsetFunctional(x, Q)
baryy = fsz.LevelsetFunctional(y, Q)
econ = fs.EqualityConstraint([vol, baryx, baryy])
emul = ROL.StdVector(3)
econ_val = ROL.StdVector(3)

Je = fsz.EnergyObjective(e, Q, cb=None)
Jr = fs.ReducedObjective(Je, e)
# J = 2e-4 * Jr
J = 1e-2 * Jr
q = fs.ControlVector(Q, inner)

params_dict = {
    "General": {
        "Secant": {
            "Type": "Limited-Memory BFGS",
            "Maximum Storage": 5
        }
    },
    "Step": {
        "Type": "Augmented Lagrangian",
        "Line Search": {
            "Descent Method": {
コード例 #3
0
e = NavierStokesSolver(Q.mesh_m, viscosity)

# save state variable evolution in file u2.pvd or u3.pvd
if mesh.topological_dimension() == 2:  # in 2D
    out = fd.File("solution/u2D.pvd")
elif mesh.topological_dimension() == 3:  # in 3D
    out = fd.File("solution/u3D.pvd")


def cb():
    return out.write(e.solution.split()[0])


# create PDEconstrained objective functional
J_ = PipeObjective(e, Q, cb=cb)
J = fs.ReducedObjective(J_, e)

# add regularization to improve mesh quality
Jq = fsz.MoYoSpectralConstraint(10, fd.Constant(0.5), Q)
J = J + Jq

# Set up volume constraint
vol = fsz.VolumeFunctional(Q)
initial_vol = vol.value(q, None)
econ = fs.EqualityConstraint([vol], target_value=[initial_vol])
emul = ROL.StdVector(1)

# ROL parameters
params_dict = {
    'General': {'Print Verbosity': 0,  # set to 1 to understand output
                'Secant': {'Type': 'Limited-Memory BFGS',
コード例 #4
0
e = fsz.StokesSolver(mesh_m,
                     inflow_bids=[1, 2],
                     inflow_expr=inflow_expr,
                     noslip_bids=[4])
e.solve()
out = fd.File("u.pvd")


def cb(*args):
    out.write(e.solution.split()[0])


cb()

Je = fsz.EnergyObjective(e, Q, cb=cb)
Jr = 1e-2 * fs.ReducedObjective(Je, e)
Js = fsz.MoYoSpectralConstraint(10., fd.Constant(0.7), Q)
Jd = 1e-3 * fsz.DeformationRegularization(
    Q, l2_reg=1e-2, sym_grad_reg=1e0, skew_grad_reg=1e-2)
J = Jr + Jd + Js
q = fs.ControlVector(Q, inner)
g = q.clone()

vol = fsz.LevelsetFunctional(fd.Constant(1.0), Q)
baryx = fsz.LevelsetFunctional(x, Q)
baryy = fsz.LevelsetFunctional(y, Q)
econ = fs.EqualityConstraint([vol, baryx, baryy])
emul = ROL.StdVector(3)

params_dict = {
    'General': {