Ejemplo n.º 1
0
def test_std_vector_run():

    params_dict = {
        'General': {
            'Secant': {
                'Type': 'Limited-Memory BFGS',
                'Maximum Storage': 5
            }
        },
        'Step': {
            'Type': 'Line Search',
            'Line Search': {
                'Descent Method': {
                    'Type': 'Quasi-Newton Method'
                }
            }
        },
        'Status Test': {
            'Gradient Tolerance': 1e-15,
            'Relative Gradient Tolerance': 1e-10,
            'Step Tolerance': 1e-16,
            'Relative Step Tolerance': 1e-10,
            'Iteration Limit': 10
        }
    }
    params = ROL.ParameterList(params_dict, "Parameters")
    algo = ROL.Algorithm("Line Search", params)
    x = ROL.StdVector(2)
    x[0] = -1.0
    x[1] = 2.0

    algo.run(x, obj)
    # Check answer to 8 decimal places
    assert round(x[0] - 1.0, 8) == 0.0
    assert round(x[1], 8) == 0.0
Ejemplo n.º 2
0
inner_product = L2Inner()

obj = Objective(inner_product)

u = Function(V, name="velocity").assign(vp)
opt = FeVector(u.vector(), inner_product)

# Add control bounds to the problem (uses more RAM)
xlo = Function(V)
xlo.interpolate(Constant(1.0))
x_lo = FeVector(xlo.vector(), inner_product)

xup = Function(V)
xup.interpolate(Constant(5.0))
x_up = FeVector(xup.vector(), inner_product)

bnd = ROL.Bounds(x_lo, x_up, 1.0)

algo = ROL.Algorithm("Line Search", params)

algo.run(opt, obj, bnd)

if comm.ensemble_comm.rank == 0:
    File("res.pvd", comm=comm.comm).write(vp)


if COMM_WORLD.rank == 0:
    func.close()
    mem.close()
Ejemplo n.º 3
0
                V0)
d = LA(d.vector(), dot_product)
x.checkVector(d, g)

jd = Function(V0)
jd = LA(jd.vector(), dot_product)

lower = interpolate(Constant(0.0), V0)
lower = LA(lower.vector(), dot_product)
upper = interpolate(Constant(1.0), V0)
upper = LA(upper.vector(), dot_product)

# Instantiate Objective class for poisson problem
obj = ObjR(dot_product)
obj.checkGradient(x, d, 7, 1)
volConstr = VolConstraint(dot_product)
volConstr.checkApplyJacobian(x, d, jd, 6, 1)
volConstr.checkAdjointConsistencyJacobian(v, d, x)

with open('input.xml', 'r') as myfile:
    parametersXML = myfile.read().replace('\n', '')
set_log_level(30)

params = ROL.ParameterList(parametersXML)
bound_constraint = ROL.BoundConstraint(lower, upper, 1.0)

alg2 = ROL.Algorithm("Augmented Lagrangian", params)
penaltyParam = 1
augLag = ROL.AugmentedLagrangian(obj, volConstr, l, penaltyParam, x, c, params)
alg2.run(x, l, augLag, volConstr, bound_constraint)