Preview:
/ Function to refine the mesh at a given level of refinement
void refine_mesh(int level) {
    // Loop over all cells in the mesh
    for (int i = 0; i < num_cells; i++) {
        // Check if the cell needs to be refined
        if (cell_needs_refinement(i, level)) {
            // Split the cell into subcells
            split_cell(i);
        }
    }
}

// Function to check if a cell needs to be refined
bool cell_needs_refinement(int cell_index, int level) {
    // Implement the criteria for deciding if a cell needs to be refined here
    // For example, you could check if the error estimate for the cell exceeds a certain threshold
    // or if the cell is near a region of interest (e.g. near a boundary or singularity)
}

// Function to split a cell into subcells
void split_cell(int cell_index) {
    // Create the subcells and update the data structures that store the mesh
    // For example, you could create 4 new subcells by dividing the cell into quadrants
    // and then update the arrays that store the vertices and connectivity of the mesh
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter