Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions example/extended-gauss-divergence.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,13 @@ program extended_gauss_divergence
!! where `.SSS.` and `.SS.` are the 1D equivalents of a volume integral over the whole
!! domain and a surface integral over a domain boundary of unit area, respectively.

! PURPOSE: Import derived types (*_t) and abstract interfaces (*_i) from modules (*_m) that
! export the public entities provided by the Formal mimetic abstraction library and
! the Julienne correctness-checking framework. Also import scalar and vector functions
! from a user-defined module: integrand_operands_m.
! KEYWORDS: derived type, use association, abstract interface
! CONTEXT: demonstration of satisfaction of an extended form of the Gauss Divergence Theorem

use julienne_m, only : command_line_t
use formal_m, only : scalar_1D_t, scalar_1D_initializer_i, vector_1D_t, vector_1D_initializer_i
use integrand_operands_m, only : scalar, vector
! END CODE CHUNK

implicit none
! PURPOSE: Define procedure pointers for 1D scalar- and vector-field initialization functions
! KEYWORDS: initial condition, 1D, scalar, vector
! CONTEXT: pass as the first argument in a scalar_1D_t or vector_1D_t constructor function invocation
procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer => scalar
procedure(vector_1D_initializer_i), pointer :: vector_1D_initializer => vector
! END CODE CHUNK

type numerical_arguments_t
!! Define default initializations that can be overridden with the command-line arguments
Expand Down
48 changes: 0 additions & 48 deletions example/vibe-coding/rag-target.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
! that need not be in the code that we desire for the retreival augmented generation (RAG)
! process to generate.

! PURPOSE: User-defined module functions for use in initializing scalar and vector fields on
! a one-dimensional (1D) staggered grid. Scalar functions will be sampled at cell
! centers and domian boundaries (domain interval end points in 1D). Vector functions
! will be sampled at cell faces (subinterval end points).
! KEYWORDS: module function, scalar, vector
! CONTEXT:
module rag_integrand_operands_m
implicit none
contains
Expand All @@ -95,75 +89,33 @@ pure function vector(x) result(v)
end function

end module
! END CODE CHUNK

program rag_target

! PURPOSE: Import derived types (*_t) and abstract interfaces (*_i) from modules (*_m) that
! export the public entities provided by the Formal mimetic abstraction library and
! the Julienne correctness-checking framework. Also import scalar and vector functions
! from a user-defined module: rag_integrand_operands_m.
! KEYWORDS: derived type, use association, abstract interface
! CONTEXT: demonstration of satisfaction of an extended form of the Gauss Divergence Theorem

use formal_m, only : scalar_1D_t, scalar_1D_initializer_i, vector_1D_t, vector_1D_initializer_i
use rag_integrand_operands_m, only : scalar, vector
! END CODE CHUNK

implicit none
! PURPOSE: Define procedure pointers for 1D scalar- and vector-field initialization functions
! KEYWORDS: initial condition, 1D, scalar, vector
! CONTEXT: pass as the first argument in a scalar_1D_t or vector_1D_t constructor function invocation
procedure(scalar_1D_initializer_i), pointer :: scalar_1D_initializer => scalar
procedure(vector_1D_initializer_i), pointer :: vector_1D_initializer => vector
! END CODE CHUNK

double precision SSS_v_dot_grad_f_dV, SSS_f_div_v_dV, SS_f_v_dot_dA

! PURPOSE: Construct 1D scalar- and vector-field objects with a specified order of accuracy,
! number of grid cells, and domain boundaries
! KEYWORDS: scalar field, vector field, one-dimensional (1D)
! CONTEXT: construct fields for use as operands in vector-calculus expressions
integrand_factors: &
associate( &
f => scalar_1D_t(scalar_1D_initializer, order=4, cells=200, x_min=0D0, x_max=1D0) &
,v => vector_1D_t(vector_1D_initializer, order=4, cells=200, x_min=0D0, x_max=1D0) &
)
! END CODE CHUNK
differential_volume: &
associate(dV => f%dV())

! PURPOSE: Evaluate a volume integral over the problem domain with an integrand formed
! from the dot product of a vector field v with the gradient of a scalar f
! KEYWORDS: volume integral, dot product, gradient
! CONTEXT: Use to verfiy the extended Gauss divergence theorem.
SSS_v_dot_grad_f_dV = .SSS. (v .dot. .grad. f) * dV
! END CODE CHUNK

! PURPOSE: Evaluate a volume integral over the problem domain with an integrand formed
! from the product of a scalar field f with the divergence of a vector field v
! KEYWORDS: volume integral, divergence
! CONTEXT: Use to verfiy the extended Gauss divergence theorem.
SSS_f_div_v_dV = .SSS. (f * .div. v) * dV
! END CODE CHUNK

end associate differential_volume

differential_area: &
associate(dA => v%dA())
! PURPOSE: Evaluate a boundary surface integral representing the flux of a vector field formed
! from the product of a scalar field f and a vector field v
! KEYWORDS: surface integral, flux
! CONTEXT: Use to verfiy the extended Gauss divergence theorem.
SS_f_v_dot_dA = .SS. (f .x. (v .dot. dA))
! END CODE CHUNK

! PURPOSE: Verify satisfaction of the Extended Gauss Divergence Theorem by computing a residual
! formed from the two volume integrals and one surface integral in the theorem.
! KEYWORDS: Extended Gauss Divergence Theorem, residual
! CONTEXT: A small resudual verifies the satisfaction of the Extended Guass Divergence Theorem
print '(26x,a,g0,a)',"sum = ", SSS_v_dot_grad_f_dV + SSS_f_div_v_dV - SS_f_v_dot_dA, " (residual)"
! END CODE CHUNK
end associate differential_area
end associate integrand_factors

Expand Down
90 changes: 65 additions & 25 deletions src/formal/divergence_1D_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

#ifdef __GFORTRAN__

! PURPOSE: Computes the cell-center x-coordinates for a uniform 1D grid given the domain bounds
! and number of cells, returning an array of cell-center locations offset by half a cell
! width from x_min.
! KEYWORDS: grid, cell-center, uniform-mesh, 1D, structured-grid, staggered-grid, utility, gfortran
! CONTEXT: This helper function is only compiled under gfortran and provides cell-center coordinate
! computation needed by the divergence_1D submodule. It constructs a uniform grid with cell
! width dx = (x_max - x_min)/cells and places each cell center at x_min + dx/2 + (cell-1)*dx
! using an implied do loop. Other compilers may provide this functionality through a different
! code path or type-bound procedure. This function is used by divergence_1D_grid to return
! the grid coordinates associated with a divergence_1D_t object.
pure function cell_center_locations(x_min, x_max, cells) result(x)
double precision, intent(in) :: x_min, x_max
integer, intent(in) :: cells
Expand All @@ -24,14 +34,24 @@ pure function cell_center_locations(x_min, x_max, cells) result(x)
x = x_min + dx/2. + [((cell-1)*dx, cell = 1, cells)]
end associate
end function
! END CODE CHUNK

#endif

! PURPOSE: Definition of procedure to compute the product of a scalar and a divergence
! KEYWORDS: scalar multiplication
! CONTEXT: Invoke this function via the binary infix operator "*" with scalar and divergence left- and
! right-hand operands, respectively

! PURPOSE: Computes the element-wise product of a scalar_1D field's interior values with a
! divergence_1D field's cell-centered values, producing a new scalar_x_divergence_1D_t
! object that carries both the multiplied values and the divergence quadrature weights.
! KEYWORDS: scalar-multiplication, divergence, operator-overloading, premultiply, scalar_1D,
! divergence_1D, structured-grid, staggered-grid, quadrature-weights, interior-values
! CONTEXT: This procedure implements the left-multiplication of a scalar_1D_t by a divergence_1D_t
! in the formal library's operator overloading framework. The scalar field has two extra
! boundary values compared to the divergence field's cell-centered values, so the scalar's
! interior slice (index 2 through size-1) is multiplied element-wise with the divergence
! values. The result inherits the scalar field's grid metadata and the divergence field's
! quadrature weights, with a compiler-conditional call to either weights() or
! divergence_1D_weights() to handle gfortran naming differences. Assertions verify that
! the scalar field has exactly two more values than the divergence field and that the
! resulting weights array has the expected size.
module procedure premultiply_scalar_1D
call_julienne_assert(size(scalar_1D%values_) .equalsExpected. size(divergence_1D%values_) + 2)
scalar_x_divergence_1D%tensor_1D_t = &
Expand All @@ -45,41 +65,60 @@ pure function cell_center_locations(x_min, x_max, cells) result(x)
end procedure
! END CODE CHUNK

! PURPOSE: Definition of procedure to compute the product of a divergence and a scalar
! KEYWORDS: scalar multiplication
! CONTEXT: Invoke this function via the binary infix operator "*" with divergence and scalar left- and
! right-hand operands, respectively

! PURPOSE: Delegates right-multiplication of a divergence_1D field by a scalar_1D field to the
! premultiply_scalar_1D procedure, ensuring commutativity of scalar-divergence
! multiplication.
! KEYWORDS: scalar-multiplication, divergence, operator-overloading, postmultiply, commutativity,
! scalar_1D, divergence_1D, delegation
! CONTEXT: This procedure implements the right-multiplication form (divergence * scalar) by
! delegating to premultiply_scalar_1D (scalar * divergence) in the formal library's
! operator overloading framework. Since scalar-divergence multiplication is commutative,
! this thin wrapper avoids duplicating the multiplication logic and ensures both operator
! orderings produce identical results.
module procedure postmultiply_scalar_1D
scalar_x_divergence_1D = premultiply_scalar_1D(scalar_1D, divergence_1D)
end procedure
! END CODE CHUNK

! PURPOSE: Definition of procedure to provide the cell-centered values of divergences.
! KEYWORDS: staggered grid, divergence
! CONTEXT: Invoke this function via the "values" generic binding to produce discrete divergence values.

! PURPOSE: Returns the cell-centered divergence values stored in a divergence_1D_t object.
! KEYWORDS: divergence, accessor, cell-centered-values, divergence_1D, getter
! CONTEXT: This procedure is a simple accessor that exposes the internally stored cell-centered
! divergence values from a divergence_1D_t object. It is used by test functions and other
! operators in the formal library to retrieve computed divergence data for comparison
! against analytical expectations or for use in compound operator expressions.
module procedure divergence_1D_values
cell_centered_values = self%values_
end procedure
! END CODE CHUNK

! PURPOSE: Definition of procedure to provide staggered-grid locations at which divergence values are stored: cell centers.
! KEYWORDS: cell centers, staggered grid, divergence
! CONTEXT: Invoke this function via the "grid" generic binding to produce discrete gradient-vector locations for
! initialization-function sampling, printing, or plotting.

! PURPOSE: Returns the cell-center x-coordinates of the 1D grid associated with a divergence_1D_t
! object by delegating to the cell_center_locations helper function.
! KEYWORDS: grid, cell-center, accessor, divergence_1D, structured-grid, staggered-grid, getter
! CONTEXT: This procedure provides access to the grid coordinates associated with a divergence_1D_t
! object in the formal library. It delegates to the cell_center_locations function, passing
! the stored domain bounds and cell count. Test functions use this accessor to retrieve
! grid coordinates for constructing spatially-varying expected values when verifying
! divergence operator results.
module procedure divergence_1D_grid
cell_centers = cell_center_locations(self%x_min_, self%x_max_, self%cells_)
end procedure
! END CODE CHUNK

! PURPOSE: Definition of procedure to compute the quadrature weights for use in the mimetic inner products of a scalar
! and the divergence of a vector.
! KEYWORDS: quadrature, numerical integration, coefficients, weights
! CONTEXT: Invoke this function via the "weights" generic binding to produce the quadrature weights
! associated with mimetic approximations to divergences.

! PURPOSE: Computes the mimetic quadrature weights for a divergence_1D_t object, returning an
! array of m+2 weights where m is the number of cells, with boundary skin weights that
! ensure discrete conservation properties and interior weights of 1.0.
! KEYWORDS: quadrature-weights, mimetic, divergence, boundary-weights, Corbino-Castillo,
! structured-grid, staggered-grid, 2nd-order, 4th-order, conservation, summation-by-parts
! CONTEXT: This procedure computes the quadrature weights used for discrete integration involving
! divergence fields in the formal library's mimetic finite-difference framework. The
! weights follow the formulation of Corbino & Castillo (2020) Eqs. 14-15 and 19, where
! boundary "skin" weights deviate from unity to maintain discrete conservation and
! summation-by-parts properties. For 2nd-order discretizations the skin is empty (all
! weights are 1.0), while for 4th-order discretizations an 8-element skin array provides
! the boundary corrections. The skin is mirrored symmetrically at both domain boundaries.
! Assertions verify that the grid has sufficient cells to accommodate the skin depth on
! both sides and that the resulting weights array has the expected size of cells+2.
! Unsupported orders trigger an error stop.
module procedure divergence_1D_weights
integer c

Expand All @@ -102,4 +141,5 @@ pure function cell_center_locations(x_min, x_max, cells) result(x)
call_julienne_assert(size(weights) .equalsExpected. self%cells_+2)
end procedure
! END CODE CHUNK

end submodule divergence_1D_s
Loading