示例#1
0
def interpolateDesignVec(orig_filter, orig_vec, new_filter, new_vec):
    """
    This function interpolates a design vector from the original design space defined
    on an OctForest or QuadForest and interpolates it to a new OctForest or QuadForest.

    This function is used after a mesh adaptation step to get the new design space.

    Args:
        orig_filter (OctForest or QuadForest): Original filter Oct or QuadForest object
        orig_vec (PVec): Design variables on the original mesh in a ParOpt.PVec
        new_filter (OctForest or QuadForest): New filter Oct or QuadForest object
        new_vec (PVec): Design variables on the new mesh in a ParOpt.PVec (set on ouput)
    """

    # Convert the PVec class to TACSBVec
    orig_x = TMR.convertPVecToVec(orig_vec)
    if orig_x is None:
        raise ValueError(
            'Original vector must be generated by TMR.TopoProblem')
    new_x = TMR.convertPVecToVec(new_vec)
    if new_x is None:
        raise ValueError('New vector must be generated by TMR.TopoProblem')

    if orig_x.getVarsPerNode() != new_x.getVarsPerNode():
        raise ValueError('Number of variables per node must be consistent')

    orig_varmap = orig_x.getVarMap()
    new_varmap = new_x.getVarMap()
    vars_per_node = orig_x.getVarsPerNode()

    # Create the interpolation class
    interp = TACS.VecInterp(orig_varmap, new_varmap, vars_per_node)
    new_filter.createInterpolation(orig_filter, interp)
    interp.initialize()

    # Perform the interpolation
    interp.mult(orig_x, new_x)

    return
示例#2
0
        # Set parameters
        opt.setMaxMajorIterations(args.max_opt_iters)
        opt.setHessianResetFreq(args.hessian_reset)
        problem.setIterationCounter(args.max_opt_iters * ite)
        opt.setAbsOptimalityTol(args.opt_abs_tol)
        opt.setBarrierFraction(args.opt_barrier_frac)
        opt.setBarrierPower(args.opt_barrier_power)
        opt.setOutputFrequency(args.output_freq)
        opt.setOutputFile(
            os.path.join(args.prefix, 'paropt_output%d.out' % (ite)))

        # If the old filter exists, we're on the second iteration
        if old_filtr:
            # Create the interpolation
            interp = TACS.VecInterp(old_varmap, varmap)
            filtr.createInterpolation(old_filtr, interp)
            interp.initialize()

            # Get the optimization variables for the new optimizer
            x, z, zw, zl, zu = opt.getOptimizedPoint()

            # Do not try to estimate the new multipliers
            opt.setInitStartingPoint(0)

            # Set the values of the new mass constraint multipliers
            z[0] = old_z

            # Do the interpolation
            old_vec = problem.convertPVecToVec(old_dvs)
            x_vec = problem.convertPVecToVec(x)
示例#3
0
        # Set parameters for ParOpt in the subproblem
        opt.setMaxMajorIterations(500)
        opt.setAbsOptimalityTol(1e-6)

        # Don't update the quasi-Newton method
        opt.setQuasiNewton(qn)
        opt.setUseQuasiNewtonUpdates(0)

        # Set the design variable bounds
        filename = os.path.join(args.prefix, 'paropt%d.out' % (ite))
        opt.setOutputFile(filename)
        # If the old filter exists, we're on the second iteration
        if old_filtr:
            # Create the interpolation
            interp = TACS.VecInterp(old_varmap, varmap)
            filtr.createInterpolation(old_filtr, interp)
            interp.initialize()

            # Get the optimization variables for the new optimizer
            x, z, zw, zl, zu = opt.getOptimizedPoint()

            # Do the interpolation
            old_vec = problem.convertPVecToVec(old_x)
            x_vec = problem.convertPVecToVec(x)
            interp.mult(old_vec, x_vec)

            # Set the new design variables
            problem.setInitDesignVars(x)

        # Initialize the problem
示例#4
0
for i in range(len(octants)):
    if i % 7 == 0:
        refine[i] = 2
    elif i % 5 == 0:
        refine[i] = -1

# Make the coarse tree finer than the fine tree for testing purposes
coarse = fine.duplicate()
coarse.refine(refine)
coarse.balance(0)
coarse.repartition()
coarse.setMeshOrder(2, TMR.GAUSS_LOBATTO_POINTS)
coarse.createNodes()

coarse_range = coarse.getNodeRange()
nc = coarse_range[comm.rank + 1] - coarse_range[comm.rank]
coarse_map = TACS.VarMap(comm, nc)

fine_range = fine.getNodeRange()
nf = fine_range[comm.rank + 1] - fine_range[comm.rank]
fine_map = TACS.VarMap(comm, nf)

# Create the two interpolations fine -> coarse and coarse -> fine
interp = TACS.VecInterp(coarse_map, fine_map, 1)
fine.createInterpolation(coarse, interp)
interp.initialize()

interp2 = TACS.VecInterp(fine_map, coarse_map, 1)
coarse.createInterpolation(fine, interp2)
interp2.initialize()