### Jutul.jl: State and Parameter Setup Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Utility functions for initializing the state and parameters required for a Jutul simulation. These functions streamline the process of preparing the necessary data structures for the simulator. ```julia using Jutul # Assume 'model' is defined # state = setup_state(model) # parameters = setup_parameters(model) # state, parameters = setup_state_and_parameters(model) # forces = setup_forces(model) ``` -------------------------------- ### Jutul.jl: Model Setup Interfaces Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Defines the core structures for setting up simulation models in Jutul.jl. This includes `SimulationModel` and `MultiModel` for different simulation scenarios. These are fundamental for defining the problem to be solved. ```julia using Jutul # Example usage (conceptual) # model = SimulationModel(...) # multi_model = MultiModel(...) ``` -------------------------------- ### Example: Cartesian meshes Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Demonstrates the creation and plotting of 2D and 3D Cartesian meshes, including conversion to unstructured meshes and visualization of cell data. ```APIDOC ## Example: Cartesian meshes For example, we can make a small 2D mesh with given physical dimensions and convert it: ```@example cart_mesh using Jutul nx = 10 ny = 5 g2d_cart = CartesianMesh((nx, ny), (100.0, 50.0)) ``` ```@example cart_mesh g2d = UnstructuredMesh(g2d_cart) ``` We can then plot it, colorizing each cell by its enumeration: ```@example cart_mesh using CairoMakie fig, ax, plt = plot_cell_data(g2d, 1:number_of_cells(g2d)) plot_mesh_edges!(ax, g2d) fig ``` If we want to drill down a bit further, we can make a plot: We can make a 3D mesh in the same manner: ```@example cart_mesh nz = 3 g3d = UnstructuredMesh(CartesianMesh((nx, ny, nz), (100.0, 50.0, 30.0))) ``` And plot it the same way: ```@example cart_mesh using CairoMakie nc = number_of_cells(g3d) fig, ax, plt = plot_cell_data(g3d, 1:nc) plot_mesh_edges!(ax, g3d) fig ``` We can also plot only a subset of cells: ```@example cart_mesh using CairoMakie fig, ax, plt = plot_cell_data(g3d, 1:nc, cells = 1:2:nc) fig ``` ``` -------------------------------- ### Jutul.jl Generic Optimization and Parameter Handling Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Provides documentation for Jutul.jl's generic optimization interface, which supports differentiation with respect to any parameter used in a simulation setup function via AbstractDifferentiation.jl. Includes functions for managing optimization parameters. ```julia ```@docs DictParameters ``` ``` ```julia ```@docs free_optimization_parameter! freeze_optimization_parameter! set_optimization_parameter! ``` ``` ```julia ```@docs optimize parameters_gradient ``` ``` -------------------------------- ### Example: Mesh manipulation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Illustrates how to create new meshes by transforming existing ones. This includes extracting cells within a specific region (e.g., a circle) and extruding a 2D mesh into a 3D mesh with tweaked node points. ```APIDOC ## Example: Mesh manipulation We can quickly build new meshes by applying transformations to an already existing mesh. Let us create a Cartesian mesh and extract the cells that lie within a circle: ```@example extrude_submesh using Jutul, CairoMakie g = UnstructuredMesh(CartesianMesh((10, 10), (1.0, 1.0))) geo = tpfv_geometry(g) keep = Int[] for c in 1:number_of_cells(g) x, y = geo.cell_centroids[:, c] if (x - 0.5)^2 + (y - 0.5)^2 < 0.25 push!(keep, c) end end subg = extract_submesh(g, keep) fig, ax, plt = plot_mesh(subg) plot_mesh_edges!(ax, g, color = :red) fig ``` We can turn this into a 3D mesh by extruding it, and then tweak the nodes: ```@example extrude_submesh g3d = Jutul.extrude_mesh(subg, 20) for node in eachindex(subg.node_points) g3d.node_points[node] += 0.01*rand(3) end fig, ax, plt = plot_mesh(g3d) fig ``` ``` -------------------------------- ### Visualize Jutul Simulation Results with GLMakie in Julia Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/index.md Provides an example of visualizing simulation results from Jutul.jl using the GLMakie plotting library for interactive plots. This code snippet shows how to activate the GLMakie backend and plot cell data. It requires the GLMakie package. ```julia using GLMakie GLMakie.activate!() # Assuming g and state0 are defined from the previous snippet fig, ax = plot_cell_data(g, state0[:T]) fig ``` -------------------------------- ### Example: Cell intersection Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Demonstrates how to use `find_enclosing_cells` to identify cells intersected by a given trajectory in both 3D and 2D meshes, with optional visualization. ```APIDOC ## Example: Cell intersection ```@example using CairoMakie, Jutul # 3D mesh G = CartesianMesh((4, 4, 5), (100.0, 100.0, 100.0)) trajectory = [ 50.0 25.0 1; 55 35.0 25; 65.0 40.0 50.0; 70.0 70.0 90.0 ] cells = Jutul.find_enclosing_cells(G, trajectory) # Optional plotting, requires Makie: fig, ax, plt = Jutul.plot_mesh_edges(G) plot_mesh!(ax, G, cells = cells, alpha = 0.5, transparency = true) lines!(ax, trajectory, linewidth = 10) fig ``` 2D version: ```@example using CairoMakie, Jutul # 2D mesh G = CartesianMesh((50, 50), (1.0, 2.0)) trajectory = [ 0.1 0.1; 0.2 0.4; 0.3 1.2 ] fig, ax, plt = Jutul.plot_mesh_edges(G) cells = Jutul.find_enclosing_cells(G, trajectory) # Plotting, needs Makie fig, ax, plt = Jutul.plot_mesh_edges(G) plot_mesh!(ax, G, cells = cells, alpha = 0.5, transparency = true) lines!(ax, trajectory[:, 1], trajectory[:, 2], linewidth = 3) fig ``` ``` -------------------------------- ### Plotting Functions Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Plotting mesh data requires a loaded Makie backend (e.g., GLMakie or CairoMakie). The documentation examples use CairoMakie for compatibility without OpenGL, but GLMakie is recommended for faster, interactive plots. ```APIDOC ## Plotting functions Plotting requires that a Makie backend is loaded (typically GLMakie or CairoMakie). The documentation uses `CairoMakie` to work on machines without OpenGL enabled, but if you want fast and interactive plots, `GLMakie` should be preferred. ### Non-mutating ```@docs plot_mesh plot_cell_data plot_mesh_edges plot_interactive ``` ### Mutating ```@docs plot_mesh! plot_cell_data! plot_mesh_edges! ``` ``` -------------------------------- ### Set up Jutul Simulation Loop in Julia Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/index.md Demonstrates setting up a simulation loop for a 2D heat equation using Jutul.jl. It involves creating a grid, defining the system, setting initial conditions, and running the simulation with specified time steps. Dependencies include the Jutul package. ```julia using Jutul sys = SimpleHeatSystem() # Create a 100x100 grid nx = ny = 100 L = 100.0 H = 100.0 g = CartesianMesh((nx, ny), (L, H)) # Create a data domain with geometry information D = DataDomain(g) # Set up a model with the grid and system model = SimulationModel(D, sys) # Initial condition is random values nc = number_of_cells(g) T0 = zeros(nc) x = D[:cell_centroids][1, :] y = D[:cell_centroids][2, :] # Create initial peak of heat to diffuse out. for i in 1:nc if (x[i] > 0.25*L) & (x[i] < 0.75*L) & (y[i] > 0.25*H) & (y[i] < 0.75*H) T0[i] = 100.0 end end state0 = setup_state(model, Dict(:T=>T0)) sim = Simulator(model, state0 = state0) dt = fill(1.0, 100) states, = simulate(sim, dt, info_level = 1); ``` -------------------------------- ### Jutul.jl: Simulator Interfaces Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Core functions for executing simulations with Jutul.jl. This includes `simulate` and `simulate!` for running entire simulations and `Jutul.solve_timestep!` for advancing the simulation one time step. ```julia using Jutul # Assume 'model', 'initial_state', 'parameters', 'dt', 't_end' are defined # Jutul.simulate(model, forces, t_end, dt, state0=initial_state, par_model=parameters) # Jutul.solve_timestep!(state, model, dt, forces, parameters) ``` -------------------------------- ### Jutul Various Utilities Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents various utility functions within Jutul.jl, including convergence criteria definition, partitioning, and load-balanced endpoint management for distributed simulations. ```julia convergence_criterion Jutul.partition Jutul.load_balanced_endpoint ``` -------------------------------- ### Jutul.jl: Simulator Configuration Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Provides tools for configuring the behavior of the Jutul simulator. This includes defining the `Simulator` object, setting up configurations with `simulator_config` and `JutulConfig`, and modifying options with `add_option!`. ```julia using Jutul # Assume 'model' is defined # config = simulator_config(model) # JutulConfig.add_option!(config, :linear_solver, LUSolver()) ``` -------------------------------- ### Visualize Jutul Simulation Results with CairoMakie in Julia Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/index.md Shows how to visualize simulation results from Jutul.jl using the CairoMakie plotting library. This code snippet demonstrates plotting initial and final states of the 2D heat equation simulation. It requires Julia 1.9+ and the CairoMakie package. ```julia using CairoMakie # Assuming g and state0 are defined from the previous snippet fig, ax = plot_cell_data(g, state0[:T]) fig ``` -------------------------------- ### Jutul.jl: Systems and Domains Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Defines fundamental components for describing the physical system and its spatial discretization. Includes `JutulSystem`, `JutulContext`, `JutulDomain`, `DataDomain`, `DiscretizedDomain`, and `Jutul.JutulDiscretization`. ```julia using Jutul # Conceptual usage: # ctx = Jutul.DefaultContext() # domain = DiscretizedDomain(...) # system = JutulSystem(...) ``` -------------------------------- ### Jutul.jl Numerical Parameter Optimization Interface Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Documents Jutul.jl's numerical parameter optimization interface, designed for differentiating with respect to numerical parameters within the model. This interface includes functions for setting up optimization and solving sensitivities. ```julia ```@docs solve_adjoint_sensitivities solve_adjoint_sensitivities! Jutul.solve_numerical_sensitivities setup_parameter_optimization ``` ``` -------------------------------- ### Interactive Jutul Simulation Visualization in Julia Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/index.md Demonstrates interactive plotting of Jutul.jl simulation results over time. This function allows stepping through each time-step of the simulation, which is particularly useful with interactive backends like GLMakie. Requires Jutul and a plotting backend like GLMakie. ```julia # Assuming g, state0, and states are defined from previous snippets plot_interactive(g, [state0; states]) ``` -------------------------------- ### Jutul.jl: Execution Contexts Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Defines the execution contexts for running simulations, specifying how computations are performed, especially concerning parallelism. Includes `DefaultContext` and `ParallelCSRContext`. ```julia using Jutul # Conceptual usage when setting up a model or simulator: # ctx = Jutul.DefaultContext() # parallel_ctx = Jutul.ParallelCSRContext() ``` -------------------------------- ### Numerical Parameter Optimization Interface Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md This interface focuses on differentiating with respect to numerical parameters within the model. It provides functions for solving adjoint and numerical sensitivities and setting up parameter optimization. ```APIDOC ## Numerical Parameter Optimization Interface This interface specifically targets differentiating with respect to numerical parameters within the model, offering efficient computation of sensitivities. ### Functions * **`solve_adjoint_sensitivities(model, state, parameters, objective)`**: Solves for adjoint sensitivities for a given model, state, parameters, and objective. * **`solve_adjoint_sensitivities!(adj_sens, model, state, parameters, objective)`**: Solves for adjoint sensitivities and stores them in the provided `adj_sens` array. * **`solve_numerical_sensitivities(model, state, parameters, objective)`**: Solves for numerical sensitivities (e.g., using finite differences). * **`setup_parameter_optimization(model, objective, parameters)`**: Sets up the necessary components for parameter optimization based on the model, objective, and parameters. ``` -------------------------------- ### Generic Optimization Interface Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md The generic optimization interface in Jutul.jl handles gradients with respect to any parameter used in a function that sets up a complete simulation case from a `AbstractDict`. It leverages AbstractDifferentiation.jl, with the default backend being `ForwardDiff`. ```APIDOC ## Generic Optimization Interface This interface is highly general and supports gradient computation with respect to any parameter used in a setup function that takes an `AbstractDict` to define a simulation case. It relies on [AbstractDifferentiation.jl](https://github.com/JuliaDiff/AbstractDifferentiation.jl). ### Backend The default backend is `ForwardDiff`. To ensure compatibility, initialize arrays and other types appropriately for the AD type (e.g., avoid `zeros` without a type). ### Parameters * **`DictParameters`**: Represents parameters stored in a dictionary-like structure. * **`free_optimization_parameter!(params, key)`**: Frees an optimization parameter, allowing it to be modified during optimization. * **`freeze_optimization_parameter!(params, key)`**: Freezes an optimization parameter, preventing it from being modified. * **`set_optimization_parameter!(params, key, value)`**: Sets the value of an optimization parameter. ### Optimization Functions * **`optimize(objective, setup_case, parameters, options)`**: Performs the optimization process. * **`parameters_gradient(objective, setup_case, parameters)`**: Computes the gradient of the objective function with respect to the parameters. ``` -------------------------------- ### Jutul Matrix Layout Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents the different matrix layout strategies supported by Jutul.jl for sparse matrix representations. Options include entity-major, equation-major, and block-major layouts. ```julia Jutul.JutulMatrixLayout Jutul.EntityMajorLayout Jutul.EquationMajorLayout Jutul.BlockMajorLayout ``` -------------------------------- ### Jutul.jl: Linear Solvers Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Abstract base types and concrete implementations for linear solvers used within Jutul.jl. Includes generic Krylov subspace methods (`GenericKrylov`) and direct solvers like `LUSolver`. ```julia using Jutul # Example usage with a simulator config: # config = simulator_config(model) # JutulConfig.add_option!(config, :linear_solver, GenericKrylov(:cg)) # JutulConfig.add_option!(config, :linear_solver, LUSolver()) ``` -------------------------------- ### Jutul Equations API Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Provides API documentation for Jutul equation handling. Functions allow querying the total number of equations and the number of equations per entity. ```julia Jutul.number_of_equations Jutul.number_of_equations_per_entity ``` -------------------------------- ### Jutul.jl: Preconditioners Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Various preconditioner implementations for use with iterative linear solvers in Jutul.jl. These are crucial for improving the convergence speed of the solvers. ```julia using Jutul # Example usage with a simulator config: # config = simulator_config(model) # JutulConfig.add_option!(config, :preconditioner, AMGPreconditioner()) # JutulConfig.add_option!(config, :preconditioner, ILUZeroPreconditioner()) ``` -------------------------------- ### Jutul.jl Global Objective Function Interfaces Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Documents the interfaces for global objective functions in Jutul.jl, which are defined over the entire simulation time. These functions typically take the solution across all time steps, forces, and initial conditions as input. ```julia ```@docs Jutul.AbstractGlobalObjective ``` ``` ```julia ```@docs Jutul.WrappedGlobalObjective ``` ``` -------------------------------- ### Jutul Entities API Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Provides API documentation for Jutul entity manipulation. Functions include querying the number of partials and entities per type. ```julia number_of_partials_per_entity number_of_entities ``` -------------------------------- ### Jutul.jl Local/Sum Objective Function Interfaces Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Details the interfaces for local or sum objective functions in Jutul.jl, where the objective is evaluated as a sum over individual time steps. This allows for objectives that vary within the simulation's time domain. ```julia ```@docs Jutul.AbstractSumObjective ``` ``` ```julia ```@docs Jutul.WrappedSumObjective ``` ``` -------------------------------- ### Jutul.jl Objective Function Interfaces Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Defines the core interfaces for objective functions in Jutul.jl, supporting both global and local (sum over time steps) evaluations. Implementations can be provided as direct functions or as subtypes of abstract objective types. ```julia ```@docs Jutul.AbstractJutulObjective ``` ``` ```julia ```@docs Jutul.optimization_step_info ``` ``` -------------------------------- ### Jutul.jl: Model API Getters Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Provides functions to retrieve different types of variables and parameters from a Jutul simulation model. These getters are essential for inspecting and understanding the model's components before and during a simulation. ```julia using Jutul # Assume 'model' is a defined Jutul model # secondary_vars = Jutul.get_secondary_variables(model) # primary_vars = Jutul.get_primary_variables(model) # parameters = Jutul.get_parameters(model) # all_vars = Jutul.get_variables(model) ``` -------------------------------- ### Mesh Generation: Gmsh Support Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Provides functionality to generate meshes from Gmsh files, enabling the use of complex geometries defined in Gmsh for simulations. ```APIDOC ## Mesh generation ### Gmsh support ```@docs Jutul.mesh_from_gmsh ``` ``` -------------------------------- ### Create and Plot Spiral Mesh Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Generates a spiral mesh with specified angular sections, rotations, and radial spacing, then visualizes the cells. Requires Jutul and CairoMakie. Input: number of angular sections, number of rotations, radial spacing. Output: A plot of the spiral mesh cells. ```julia using Jutul, CairoMakie import Jutul.RadialMeshes: spiral_mesh n_angular_sections = 10 nrotations = 4 spacing = [0.0, 0.5, 1.0] rmesh = spiral_mesh(n_angular_sections, nrotations, spacing = spacing) num_cells = number_of_cells(rmesh) fig, ax, plt = plot_cell_data(rmesh, 1:number_of_cells(rmesh)) fig ``` -------------------------------- ### Jutul Variables API Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Provides API documentation for Jutul variable manipulation. Functions include querying degrees of freedom, values per entity, scale, increment limits, and associated entities. ```julia degrees_of_freedom_per_entity values_per_entity maximum_value minimum_value variable_scale absolute_increment_limit relative_increment_limit associated_entity ``` -------------------------------- ### Create and Plot 2D Cartesian Mesh and Convert to Unstructured Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Demonstrates creating a 2D Cartesian mesh with specified dimensions and resolution, converting it to an unstructured mesh, and then plotting the cell data and mesh edges. Requires the CairoMakie plotting library. ```Julia using Jutul nx = 10 ny = 5 g2d_cart = CartesianMesh((nx, ny), (100.0, 50.0)) ``` ```Julia g2d = UnstructuredMesh(g2d_cart) ``` ```Julia using CairoMakie fig, ax, plt = plot_cell_data(g2d, 1:number_of_cells(g2d)) plot_mesh_edges!(ax, g2d) fig ``` -------------------------------- ### Jutul Equation Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents the base type for equations within the Jutul framework. This serves as a foundation for defining various physical or mathematical equations. ```julia JutulEquation ``` -------------------------------- ### Jutul Automatic Differentiation Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents the automatic differentiation (AD) capabilities within Jutul.jl. This includes functions for value extraction, conversion, local AD, cache management, array allocation, and entity-specific AD retrieval. ```julia Jutul.value Jutul.as_value Jutul.local_ad Jutul.JutulAutoDiffCache Jutul.CompactAutoDiffCache Jutul.allocate_array_ad Jutul.get_ad_entity_scalar Jutul.get_entries ``` -------------------------------- ### Create and Plot 3D Cartesian Mesh and Subset of Cells Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Shows how to create a 3D Cartesian mesh, convert it to an unstructured mesh, and plot its cell data and edges. It also demonstrates plotting only a subset of the cells. Requires the CairoMakie plotting library. ```Julia using Jutul nx = 10 ny = 5 nz = 3 g3d = UnstructuredMesh(CartesianMesh((nx, ny, nz), (100.0, 50.0, 30.0))) ``` ```Julia using CairoMakie nc = number_of_cells(g3d) fig, ax, plt = plot_cell_data(g3d, 1:nc) plot_mesh_edges!(ax, g3d) fig ``` ```Julia using CairoMakie fig, ax, plt = plot_cell_data(g3d, 1:nc, cells = 1:2:nc) fig ``` -------------------------------- ### Create and Plot Radial Mesh Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Generates a radial mesh with specified angular divisions and radial layers, then visualizes its edges. Requires Jutul and CairoMakie libraries. The mesh can be centered or not. Input: number of angular sections, radial layer boundaries. Output: A plot of the mesh edges. ```julia using Jutul, CairoMakie import Jutul.RadialMeshes: radial_mesh import Jutul: plot_mesh_edges nangle = 10 radii = [0.2, 0.5, 1.0] m = radial_mesh(nangle, radii; centerpoint = true) plot_mesh_edges(m) ``` -------------------------------- ### Objective Functions in Jutul.jl Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/optimization.md Jutul.jl supports two main types of objective functions: those evaluated globally over all time-steps and those evaluated locally (typically as a sum over all time-steps). Users can implement these by passing a function directly or by creating a subtype that is a Julia callable struct. ```APIDOC ## Objective Functions Jutul.jl supports two main types of objective functions: * **Global Objectives**: Defined over the entire simulation time. The objective function takes the solution for all time-steps, forces, time-step information, initial state, and input data. * **Local/Sum Objectives**: Evaluated locally, typically as a sum over all time-steps. ### Interface Both types of objectives require implementing a specific interface. This can be done by: 1. **Passing a function directly**: Jutul infers the objective type from the number of arguments. 2. **Creating an explicit subtype**: Make a subtype that is a Julia callable struct. Objective functions receive `step_info` (a `Dict`), which contains information about the current simulation step. ``` -------------------------------- ### Jutul.jl: Model API Setters Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Allows modification of the simulation model's state and parameters. These setters are crucial for initializing or updating the model's conditions prior to or during a simulation run. ```julia using Jutul # Assume 'model' and 'state' are defined # Jutul.set_secondary_variables!(state, model, values) # Jutul.set_primary_variables!(state, model, values) # Jutul.set_parameters!(model, values) ``` -------------------------------- ### Jutul Variable Updating Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents utilities for updating variables within the Jutul framework, specifically focusing on secondary variable calculations and dependency retrieval. ```julia @jutul_secondary Jutul.get_dependencies ``` -------------------------------- ### Mesh API Functions Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Provides essential functions for querying and manipulating mesh properties, including counting cells, faces, and boundary faces, as well as extruding meshes and extracting submeshes. ```APIDOC ## Mesh API functions ### Queries ```@docs number_of_cells number_of_faces number_of_boundary_faces ``` ### Manipulation ```@docs Jutul.extrude_mesh Jutul.extract_submesh ``` ``` -------------------------------- ### Plot Spiral Mesh Tags Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Generates tags for a spiral mesh based on radial spacing and visualizes data associated with these tags. This helps in analyzing properties distributed across the spiral structure. Requires Jutul and CairoMakie. Input: Spiral mesh object, radial spacing. Output: Multiple plots, each showing cell data for a specific tag. ```julia import Jutul.RadialMeshes: spiral_mesh_tags tags = spiral_mesh_tags(rmesh, spacing) fig = Figure(size = (400, 1800)) for (figno, pp) in enumerate(pairs(tags)) k, val = pp ax = Axis(fig[figno, 1], title = "Spiral tag $k") plot_cell_data!(ax, rmesh, val) end fig ``` -------------------------------- ### Jutul.jl: Model Information Getters Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/usage.md Functions to obtain scalar information about the size and dimensionality of the simulation model. These are useful for resource allocation and understanding the scale of the problem. ```julia using Jutul # Assume 'model' is a defined Jutul model # num_dof = Jutul.number_of_degrees_of_freedom(model) # num_values = Jutul.number_of_values(model) ``` -------------------------------- ### Extract Submesh within a Circle and Extrude to 3D Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Illustrates creating a 2D Cartesian mesh, extracting cells within a circular region to form a submesh, and then extruding this submesh into a 3D mesh. Node points of the 3D mesh are slightly perturbed. Requires Jutul and CairoMakie. ```Julia using Jutul, CairoMakie g = UnstructuredMesh(CartesianMesh((10, 10), (1.0, 1.0))) geo = tpfv_geometry(g) keep = Int[] for c in 1:number_of_cells(g) x, y = geo.cell_centroids[:, c] if (x - 0.5)^2 + (y - 0.5)^2 < 0.25 push!(keep, c) end end subg = extract_submesh(g, keep) fig, ax, plt = plot_mesh(subg) plot_mesh_edges!(ax, g, color = :red) fig ``` ```Julia g3d = Jutul.extrude_mesh(subg, 20) for node in eachindex(subg.node_points) g3d.node_points[node] += 0.01*rand(3) end fig, ax, plt = plot_mesh(g3d) fig ``` -------------------------------- ### Geometry Functions Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Provides functions related to mesh geometry, including `TwoPointFiniteVolumeGeometry`, `tpfv_geometry` for retrieving geometry information, `find_enclosing_cells` to locate cells intersected by a trajectory, and `cells_inside_bounding_box`. ```APIDOC ### Geometry ```@docs TwoPointFiniteVolumeGeometry Jutul.tpfv_geometry Jutul.find_enclosing_cells Jutul.cells_inside_bounding_box ``` ``` -------------------------------- ### Index Radial Mesh Cells Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Demonstrates how to index cells in a radial mesh using a Cartesian-like indexing scheme. This allows treating radial meshes similarly to Cartesian ones for data access. Input: A radial mesh object. Output: A vector of cell indices (i, j, k) for each cell. ```julia IJ = map(i -> cell_ijk(m, i), 1:number_of_cells(m)) ``` -------------------------------- ### Plot Radial Mesh Faces and Normals Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Generates a radial mesh without a centerpoint and visualizes its faces, boundary faces, and oriented normals. This function uses standard Makie plotting calls and requires Jutul and CairoMakie. Input: Radial mesh object, cell data. Output: A detailed plot of the mesh structure including normals. ```julia using Jutul, CairoMakie import Jutul.RadialMeshes: radial_mesh using LinearAlgebra m = radial_mesh(nangle, radii; centerpoint = false) ncells = number_of_cells(m) fig, ax, plt = plot_cell_data(m, 1:ncells, alpha = 0.25) scatter!(ax, m.node_points) for face in 1:number_of_faces(m) n1, n2 = m.faces.faces_to_nodes[face] pt1 = m.node_points[n1] pt2 = m.node_points[n2] lines!(ax, [pt1, pt2], color = :red) end for bface in 1:number_of_boundary_faces(m) n1, n2 = m.boundary_faces.faces_to_nodes[bface] pt1 = m.node_points[n1] pt2 = m.node_points[n2] lines!(ax, [pt1, pt2], color = :blue) end fig ``` -------------------------------- ### Jutul Entity Types Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents the various entity types recognized by the Jutul framework, including Cells, Faces, and Nodes. These represent the spatial discretization of the simulation domain. ```julia JutulEntity Cells Faces Nodes ``` -------------------------------- ### Jutul Variable Types Documentation Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/internals.md Documents the different types of variables used within the Jutul framework, such as JutulVariables, ScalarVariable, and VectorVariables. These are fundamental for representing and managing simulation data. ```julia JutulVariables ScalarVariable VectorVariables ``` -------------------------------- ### Plot Cell Data on Radial Mesh Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Visualizes data associated with cells on a radial mesh. This function maps cell data to their geometric locations for plotting. Requires Jutul and CairoMakie. Input: Radial mesh object, cell data. Output: A plot of cell data. ```julia fig, ax, plt = plot_cell_data(m, map(first, IJ)) ``` ```julia fig, ax, plt = plot_cell_data(m, map(ijk -> ijk[2], IJ)) ``` -------------------------------- ### Plot Oriented Normals on Radial Mesh Cell Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Zooms in on a single cell of a radial mesh and plots its oriented normals (interior and boundary). This visualization is crucial for understanding flux calculations in discretized domains. Requires Jutul, CairoMakie, and LinearAlgebra. Input: Radial mesh object, cell number. Output: A plot showing cell faces, normals, and boundary normals. ```julia using Jutul, CairoMakie using LinearAlgebra geo = tpfv_geometry(m) cellno = 1 fig, ax, plt = plot_mesh(m, cells = cellno) for face in m.faces.cells_to_faces[cellno] n1, n2 = m.faces.faces_to_nodes[face] pt1 = m.node_points[n1] pt2 = m.node_points[n2] lines!(ax, [pt1, pt2], color = :red) midpt = (pt1 + pt2) / 2 if m.faces.neighbors[face][1] == cellno sgn = 1 else sgn = -1 end lines!(ax, [midpt, midpt + sgn*norm(pt2 - pt1, 2)*geo.normals[:, face]], color = :orange) end for bface in m.boundary_faces.cells_to_faces[cellno] n1, n2 = m.boundary_faces.faces_to_nodes[bface] pt1 = m.node_points[n1] pt2 = m.node_points[n2] lines!(ax, [pt1, pt2], color = :blue) midpt = (pt1 + pt2) / 2 lines!(ax, [midpt, midpt + norm(pt2 - pt1, 2)*geo.boundary_normals[:, bface]], color = :green) end scatter!(ax, m.node_points) fig ``` -------------------------------- ### Find Enclosing Cells for a 3D Trajectory in a Cartesian Mesh Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Demonstrates finding the cells within a 3D Cartesian mesh that are intersected by a given trajectory. Requires Jutul and CairoMakie for plotting. The trajectory is defined as a matrix of coordinates. ```Julia using CairoMakie, Jutul # 3D mesh G = CartesianMesh((4, 4, 5), (100.0, 100.0, 100.0)) trajectory = [ 50.0 25.0 1; 55 35.0 25; 65.0 40.0 50.0; 70.0 70.0 90.0 ] cells = Jutul.find_enclosing_cells(G, trajectory) # Optional plotting, requires Makie: fig, ax, plt = Jutul.plot_mesh_edges(G) plot_mesh!(ax, G, cells = cells, alpha = 0.5, transparency = true) lines!(ax, trajectory, linewidth = 10) fig ``` -------------------------------- ### Find Enclosing Cells for a 2D Trajectory in a Cartesian Mesh Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Shows how to find the cells intersected by a trajectory within a 2D Cartesian mesh. Requires Jutul and CairoMakie for plotting. The trajectory is provided as a 2D matrix. ```Julia using CairoMakie, Jutul # 2D mesh G = CartesianMesh((50, 50), (1.0, 2.0)) trajectory = [ 0.1 0.1; 0.2 0.4; 0.3 1.2 ] fig, ax, plt = Jutul.plot_mesh_edges(G) cells = Jutul.find_enclosing_cells(G, trajectory) # Plotting, needs Makie fig, ax, plt = Jutul.plot_mesh_edges(G) plot_mesh!(ax, G, cells = cells, alpha = 0.5, transparency = true) lines!(ax, trajectory[:, 1], trajectory[:, 2], linewidth = 3) fig ``` -------------------------------- ### Mesh Types Source: https://github.com/sintefmath/jutul.jl/blob/main/docs/src/mesh.md Jutul.jl supports two primary internal mesh types: Cartesian meshes and unstructured meshes. Unstructured meshes are general polyhedral mesh formats, and Cartesian meshes can be readily converted into this format. Coarsened meshes can be generated from a fine-scale mesh and a partition vector. ```APIDOC ## Mesh Types Jutul has two main internal mesh types: Cartesian meshes and unstructured meshes. The unstructured format is a general polyhedral mesh format, and a Cartesian mesh can easily be converted to an unstructured mesh. Coarsened meshes can be created by a fine scale mesh and a partition vector. ```@docs JutulMesh CartesianMesh UnstructuredMesh CoarseMesh MRSTWrapMesh ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.