Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local-Global Solver API #144

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Local-Global Solver API #144

wants to merge 26 commits into from

Conversation

termi-official
Copy link
Owner

No description provided.

@termi-official termi-official marked this pull request as draft September 4, 2024 17:50
@termi-official
Copy link
Owner Author

termi-official commented Jan 8, 2025

Found some snippets. Probably part of this PR.

# Ferrite-specific
struct MaterialCache{M, DH, CV, FV}
    material::M
    dh::DH
    cv::CV
    fv::FV
end

# Standard assembly loop for global problem
function stress!(du, u, q, cache::MaterialCache, t)
    K = allocate_matrix(cache.dh)
    f = zeros(ndofs(cache.dh))
    # Allocate the element stiffness matrix
    n_basefuncs = getnbasefunctions(cache.cv)
    ke = zeros(n_basefuncs, n_basefuncs)
    fe = zeros(n_basefuncs)
    # Create an assembler
    assembler = start_assemble(K, f)
    # Loop over all cells
    for cell in CellIterator(cache.dh)
        # Update the shape function gradients based on the cell coordinates
        reinit!(cache.cv, cell)
        # Reset the element stiffness matrix
        fill!(ke, 0.0)
        fill!(fe, 0.0)
        # Compute element contribution
        assemble_cell!(ke, fe, u, q, cell, cache.cv, material)
        # Assemble ke into K
        assemble!(assembler, celldofs(cell), ke, fe)
    end
    for face in FacetIterator(cache.dh, getfacetset(cache.dh.grid,"right"))
        # Update the facetvalues to the correct facet number
        reinit!(cache.fv, face)
        # Reset the temporary array for the next facet
        fill!(fe, 0.0)
        # Access the cell's coordinates
        cell_coordinates = getcoordinates(face)
        for qp in 1:getnquadpoints(cache.fv)
            # Calculate the global coordinate of the quadrature point.
            x = spatial_coordinate(cache.fv, qp, cell_coordinates)
            tₚ = cache.material.traction(x, t)
            # Get the integration weight for the current quadrature point.= getdetJdV(cache.fv, qp)
            for i in 1:getnbasefunctions(cache.fv)
                Nᵢ = shape_value(cache.fv, qp, i)
                fe[i] += tₚ * Nᵢ *end
        end
        # Add the local contributions to the correct indices in the global external force vector
        assemble!(f, celldofs(face), fe)
    end
    du .= K*u .- f
end

function stress_Ju!(K, u, q, cache::MaterialCache, t)
    # Allocate the element stiffness matrix
    n_basefuncs = getnbasefunctions(cache.cv)
    ke = zeros(n_basefuncs, n_basefuncs)
    # Create an assembler
    assembler = start_assemble(K; fillzero=false)
    # Loop over all cells
    for cell in CellIterator(dh)
        # Update the shape function gradients based on the cell coordinates
        reinit!(cache.cv, cell)
        # Reset the element stiffness matrix
        fill!(ke, 0.0)
        # Compute element contribution
        assemble_cell_Ju!(ke, u, q, cell, cache.cv, cache.material)
        # Assemble ke into K
        assemble!(assembler, celldofs(cell), ke)
    end
end

function stress_Jq!(K, u, q, cache::MaterialCache, t)
    # Allocate the element stiffness matrix
    n_basefuncs = getnbasefunctions(cache.cv)
    ke = zeros(n_basefuncs, n_basefuncs)
    # Create an assembler
    assembler = start_assemble(K)
    # Loop over all cells
    for cell in CellIterator(dh)
        # Update the shape function gradients based on the cell coordinates
        reinit!(cache.cv, cell)
        # Reset the element stiffness matrix
        fill!(ke, 0.0)
        # Compute element contribution
        assemble_cell_Jq!(ke, u, q, cell, cache.cv, cache.material)
        # Assemble ke into K
        assemble!(assembler, celldofs(cell), ke)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant