Example #1
0
            # Compute the strain energy error estimate
            err_est, error = TMR.strainEnergyError(forest, assembler,
                                                   forest_refined,
                                                   assembler_refined)
        else:
            # Compute the adjoint
            assembler.evalSVSens(func, res)

            # Compute the adjoint solution
            adjoint = assembler.createVec()
            gmres.solve(res, adjoint)
            adjoint.scale(-1.0)

            # Compute the adjoint and use adjoint-based refinement
            err_est, func_corr, error = \
                     TMR.adjointError(forest, assembler,
                                      forest_refined, assembler_refined, adjoint)

        # Print the error estimate
        if comm.rank == 0:
            print('estimate = ', err_est)

        # Compute the refinement from the error estimate
        nbins = 30
        low = -15
        high = 0
        bounds = 10**np.linspace(low, high, nbins + 1)
        bins = np.zeros(nbins + 2, dtype=np.int)

        # Compute the bins
        for i in range(len(error)):
            if error[i] < bounds[0]:
Example #2
0
    # Compute the adjoint correction on the fine mesh
    adjoint_corr = adjoint_refined.dot(res_refined)

    # Compute the diff between the interpolated and reconstructed
    # solutions
    adjoint_interp = assembler_refined.createVec()
    TMR.computeInterpSolution(forest_refined, assembler_refined, forest,
                              assembler, adjoint_refined, adjoint)
    TMR.computeInterpSolution(forest, assembler, forest_refined,
                              assembler_refined, adjoint, adjoint_interp)
    adjoint_refined.axpy(-1.0, adjoint_interp)

    # Estimate the element-wise errors
    err_est, __, error = TMR.adjointError(forest, assembler, forest_refined,
                                          assembler_refined, ans_interp,
                                          adjoint_refined)

    # Compute the refined function value
    fval_corr = fval_refined + adjoint_corr

    # # Set the refined adjoint
    # flag = (TACS.ToFH5.NODES |
    #         TACS.ToFH5.DISPLACEMENTS |
    #         TACS.ToFH5.STRAINS |
    #         TACS.ToFH5.EXTRAS)

    # assembler.setVariables(adjoint)
    # f5 = TACS.ToFH5(assembler, TACS.PY_PLANE_STRESS, flag)
    # f5.writeToFile('results/adjoint_solution%02d.f5'%(step))