Commit 1d51241
authored
Add 1D divergence and laplacian operators (#247)
* refac: rename face_centered_vals -> cell_centered
* fix(gfortran): work around gfortran issues
This commit
1. Synchronizes a conditionally compiled
gfortran workaround to match the updated alternative block.
2. Updates the unit test to work around a gfortran issue with
`associate`.
* test(gradient): add 2nd line differentiation case
* fix(matvec): use size() to set loop limits
This commit fixes issues with the matrix-vector multiplication
function "matvec" to ensure infers the loop limits and array
section bounds from the dimensions of the arrays accessed by the
loop or array section.
* refac(test): mv code, rename function
* fix(grid): rm extra multiplicative factor of dx
* test(grad): add passing test differentiataing line
* refac(cell_centers_ex): domain(:) -> x_{min,max}
* feat(cell_centers_ex): add cells_ component
* refac(cell_centers_extended): rm grid_ component
* test(gradient): unit test of d(parabola)/dx passes
* refac(initializers): rm abstract initializer type
* fix(cell_centers_extended_s): rm dead code
* refac(gradient_t): mv to separate module/submodule
* refac(cell_centers_extended_t): rename scalar_1D_t
* refac(gradient_{t,m,s}):rename gradient_1D_{t,m,s}
* refac(gradient_operator):name gradient_operator_1D
* refac(mimetic_matrix}: append "_1D"
* fix(scalar_1D_s): import operators
* fix(mimetic_matrix_s): count upper/lower rows
* refac(mimetic_matrix_s): simpler loop bound
* fix(4th-order): flip some coefficient signs
* feat(mimetic_matrix_1D): add file_t constructor
This commit adds the ability to convert a mimetic matrix to a
Julienne file_t object so that the matrix elements can be printed
with code like the following
type(mimetic_matrix_t) mimetic_matrix
! define matrix here
associate(file => mimetic_matrix%to_file_t())
call file%write_lines()
end associate
* fix(mimetic_matrix_t): reshape upper block (A)
Now all tests pass for computing 1D gradients of 0th, 1st, &
2nd-order polynomials, each with mimetic discretizations of
2nd- and 4th-order accuracy.
* refac(vector): rename matrix-vector RHS scalar_1D
* doc(gradient_operator_1D): clarify statement label
* test(order): 2nd-/4th-order accuracy tests pass
This commit adds tests of the ratio of the log of the maximum
absolute error for gradients of a sinusoidal function. The tests
verify that 2nd- and 4th-order mimetic discretizations converge
to the expected gradient values at a rate proportional to dx raised
to the 2nd and 4th powers of the error within a tolerance of 5%.
* build(gfortran): work around concurrent type-spec
* build(gfortran-14): add locality specifier macro
To work around gfortran-14 not supporting `do concurrent` locality
specifiers, this commit removes specifiers conditionally via a new
macro: HAVE_LOCALITY_SPECIFIER_SUPPORT defined in
include/mole-language-support.F90.
* build(gfortran): use GCC ver to define local spec
* test(CI): build/test gradient-operator branch
* test(CI): reduce test matrix
* refac(fortran):combine scalar_1D/vector_1D modules
This commit combines scalar_1D_m and vector_1D_m into one new
tensors_1D_m module.
* refac(tensors_1D_t): build class hierarchy
This commit establishes the following class hierarchy:
vector_1D_t <|-- gradient_1D_t
scalar_1D_t <|-- divergence_1D_t
where <|-- denotes type extension with the parent type on the left
and the child type on the right.
* refactor(grid_s): gather grid funcs in new submod
* refactor: rename procedures to facilitate disambig
* refactor(M): lift matrix block to module for reuse
* chore: blank-space edits
* feat(vector_1D_t): type-bound .div. operator
* test(julienne): update dependency version to 3.3.0
This update facilitates reducing test-file complexity by
simplifying the workaround for a missing feature in gfortran
versions older than 14.3.
* chore(grad test): rm unused operator
* test(divergence): 1st passing unit test
* refactor(grid_s): distrib funcs to scalar/vector
* WIP: print diagnostics in divergence test
* fix(divergence_matrix_1D): delete rows of zeros
* refactor(divergence_{,operator_}1D_s}): combine
* refactor(gradient_{,operator_}1D_s}): combine
* refactor(tensor_1D_t): define scalar/vector parent
This commit reduces code duplication by
1. Defining an abstract parent tensor_1D_t type that non-abstract
scalar_1D_t and vector_1D_t now extend and
2. Moving common components from the child types to the parent.
Diagrammatically,
```mermaid
classDiagram
tensor_t <|-- scalar_1D_t
tensor_t <|-- vector_1D_t
class tensor_1D_t {
<<abstract>>
double precision : x_min_
double precision : x_max_
double precision : values_
integer : cells_
}
class scalar_1D_t {
gradient_1D_operator_t : gradient_1D_operator
grad() gradient_1D_t
}
class vector_1D_t {
divergence_1D_operator_t : divergence_1D_operator
div() divergence_1D_t
}
```
where x_min_, x_max_, and cells_ are scalar components and values_
is an allocaatable array component, and grad() and div() support
defined operations .grad. and .div., respectively, implementing
mimetic discrete approximations to the differential calculus
operators: gradient and divergence.
* refactor(tensor): mk nonabstract, construct parent
This commit
1. Makes tensor_1D_t non-abstract,
2. Defines a tensor_1D_t user-defined constructor, and
3. Refactors the scalar_1D_t constructor to construct its
tensor_1D_t parent component by assigning a whole object created
by the tensor_1D_t constructor.
TODO: find flang bug preventing similar refactoring of vector_1D_t
* fix(.div.): 2nd/4th-order divergences
Newly passing unit tests:
A 1D mimetic divergence operator
passes on computing 2nd-order .div.(.grad. s) for 1D scalar s with quadratic magnitude within 0.1000000000000E-11.
passes on computing 4th-order .div.(.grad. s) for 1D scalar s with quadratic magnitude within 0.1000000000000E-11.
2 of 2 tests passed. 0 tests were skipped.
* test(divergence): replace decl/def with associate
* refactor(scalar,vector): uniform nomenclature
For the scalar_1D_t and vector_1D_t derived types, this commit
1. Defines 1 public generic binding per type-bound procedure (TBP),
2. Makes all TBPs private, and
3. Applies uniform nomenclature as follows:
a. scalar_1_D_t
i. generic bindings: .grad., grid, values
ii. TBPs: grad, scalar_1D_grid, scalar_1D_values
a. vector_1_D_t
i. generic bindings: .div., grid, values
ii. TBPs: div, vector_1D_grid, vector_1D_values
* test(.div.):order of accuracy for 2nd-order method
* test(.div.):order of accuracy for 4th-order method
TODO: Fix 2 test failures exposed by the convergence tests,
wherein the diagnostics indicate that
(1) The order of accuracy is 1 for both 2nd- and 4th-order
divergences and
(2) The calculated values are shifted by one grid location,
which probably explains the order of accuracy of 1.
For example, with this commit, executing
fpm test --compiler flang-new --flag "-DASSERTIONS -O3"
yields the following excerpted output:
A 1D mimetic divergence operator
passes on computing 2nd-order .div.(.grad. s) for 1D scalar s with quadratic magnitude within 0.1000000000000E-13.
passes on computing 4th-order .div.(.grad. s) for 1D scalar s with quadratic magnitude within 0.1000000000000E-13.
FAILS on computing convergence rate of 2 for 2nd-order .div. for 1D vector with sinusoidal magnitude within 0.1000000000000E-13.
diagnostics:
expected 2.000000000000 within a tolerance of 0.5000000000000E-01; actual value is 0.9999973302351 (2nd-order .div. [sin(x) + cos(x)] order of accuracy)
FAILS on computing convergence rate of 4 for 4th-order .div. for 1D vector with sinusoidal magnitude within 0.1000000000000E-13.
diagnostics:
expected 1.000000000000 within a tolerance of 0.1000000000000E-01; actual value is 0.9680963154955
expected 0.9680958012876 within a tolerance of 0.1000000000000E-01; actual value is 0.9014535854427
expected 0.9014536512846 within a tolerance of 0.1000000000000E-01; actual value is 0.8312538148404
expected 0.8312538755549 within a tolerance of 0.1000000000000E-01; actual value is 0.7577734651947
* chore: blank-space edits, new associate, renamings
* fix(.div.): locate scalars only at cell centers
* chore(grad op test): blank-space edits
* test(grad):uniformly tighter convergence criterion
* chore: more blank-space ed, associate, renam/reorg
* chore(divergence test):rm type not used explicitly
* refactor: rm unnecessary gradient_1D_t child type
* refactor: rm unneeded divbergence_1D_t child type
* feat(.laplacian.): add & test for scalar operands
This commit adds
1. A .laplacian. generic binding for scalar_1D_t operands and
2. Unit tests for the new .laplacian. operator.
Thes L-infinity norm of the resulting error indicates that
computing the Laplacian by composing divergence and gradient
operators of a given order of accuracy produces a Laplacian
operator with an order of accuracy that is one polynomial
degree below the accuracy of the divergence and gradient
operators:
For a scalar s,
* 2nd-order .div. (.grad. s) yields a 1st-order .laplacian. s
* 4th-order .div. (.grad. s) yields a 3rd-order .laplacian. s
* test(laplacian): conditionally write gnuplot file
* fix(laplacian): adjust tolerance, test domain
* refactor(tensor): mk separate scalar,vector module
This commit increases modularity by moving scalar_1D_t and
vector_1D_t related functions out of tensors_1D_m and into a new
scalar_vector_1D_m.
* refactor(tensor): separate mimetic_matrix module
This commit further increases modularity by moving
mimetic_matrix_1D_t, gradient_operator_1D_t,
divergence_operator_1D_t, and related functions to a new
mimetic_matrix_1D_m module.
* refactor(tensors_1D_m): rename module
* refactor(mimetic_matrix): mk operators child types
This commit refactors gradient_operator_1D_t and
divergence_operator_1D_t so that they extend mimetic_matrix_1D_t.
* refactor(matvec): improve type safety
Whereas the `matvec` matrix-vector multiply function previously
accepted a polymorphic class(mimetic_matrix_t) dummy argument,
this commit ensures that
1. Only a gradient_operator_1D_t child of a mimetic_matrix_1D_t
can can be applied in the context wherein a gradient is being
calculated and
2. Only a divergence_operator_1D_t child of a mimetic_matrix_1D_t
can can be applied in the context wherein a divergence is being
calculated.
* refactor: renamings, rm unused vars, add comments
* refactor: recombine tensor, scalar, vector modules
* refactor(matvec): mk type-bound
* refactor(mimetic ops): associate & blank-space eds
* chore: work around gfortran bugs
* feat(example): compute Laplacian = div grad
* fix(scalar): constructor samples at cell centers
* fix(divergence,laplacian): def separate types
This commit disambiguates two quantities that behave mathematically
like scalars in some circumstances but are treated differently in
the discrete calculus of mimetic discretizations:
* divergence_1D_t: stored at cell centers & support no operators
* laplacian_1D_t: which extends divergence_1D_t because
In both cases, when the operand is a mathematical scalar, the
results is a scalar. However, in mimetic discretizations, the
results differ from a scalar quantity in that there are no boundary
values with the agove two types.
With these changes, the following operators map from the listed
operand type to the listed result type:
* .div.: scalar_1D_t operand, divergence_1D_t result and
* .laplacian.: scalar_1D_t, laplacian_1D_t result,
where for an object `s` of type scalar_1D_t,
.laplacian. s = .div. (.grad. s)
* fix(example): correct column headings
* test(laplacian): use {laplacian,divergence}_1D_t
* fix(example): gfortran `associate` bugs workaround
* test: work around gfortran bugs
* chore(gfortran): less duplication, skip 2 fails
This commit
1. Reduces the amount of code duplication related to working around
gfortran issues with `associate` statements -- at the cost
increasing the number of preprocessor macros.
2. Skips two known test failures (2nd- and 4th-order Laplacian
operator convergence rate tests) and adds a new macro
TEST_LAPLACIAN_CONVERGENCE that can be used to run the otherwise
skipped tests.
* refactor(example): redistrib macros, reform output
* feat(assembly): divergence, gradient matrices
This commit adds
1. generic `assemble` bindings to gradient_operator_t and
divergence_operator_t that produce the complete operator
matrix as a 2D array, including zero values.
2. example `print-assembled-1D-operators` demonstrating the
use of `assemble` to print the assembled matrices.
For a gradient operator matrix, G, for example, the `assemble`
computs the matrix product GI = G, where is the idenity matrix.
This approach
a. works around the fact that the MOLE Fortran data structures
store only the non-zero submatrix blocks.
b. supports the verification of both the non-zero values (which
were already available via `to_file_t` type-bound functions)
and the mimetic-matrix multiplication functions.
* fix(divergence): store zero rows
* test(laplacian): convergence rate checks pass
This commit reintroduces the execution of the Laplacian operator
convergence-rate tests with all tests passing.
* fix(example): div-grad example works for LLVM/GCC
* fix(div): adjust constraint, unit vector dimension
* fix(div): keep all of D
* feat(print-assembled): add usage output
* feat(example): add command-line flags
Usage:
fpm run \
--example print-assembled-1D-operators \
--compiler flang-new \
--flag "-O3" \
-- [--help|-h] | [--grad] [--div] [--order <integer>]
where square brackets indicate optional arguments and angular
brackets indicate user input values.
* refactor(A,A'): rm top/bottom rows of zeros
* fix(divergence): rm top/bottom after mat-vec prod
* fix(laplacian test): fix array dimensions
* test(div): assert divegerence operator mat-vec len
* test(laplacian): sep boundary/internal convergence
This commit
1. Adjusts the Laplacian convergence rate tests to check
for the nominal convergence rate at internal grid points and
a rate one order lower near boundaries,
2. Combines the Laplacian convergence checks int one function
that can be called for mimetic schmes of any order, and
4. Refactors the 2nd- and 4th-order mimetic Laplacian convergence
tests so that each calls the new unified function.
* test(divergence): blank-space edit
* fix(div,grad): work around nag compiler issue
* feat(vector,divergence): component constructors
* chore({gradient,scalar}_1D): rm unused files
* doc(UML): Fortran class diagram
* doc(UML): add operators
* fix gfortran builds
* test(CI): loosen 2 tolerances|run ifx single-image
* build(gfortran-{13,14} on ubuntu): workaround
This commit is an attempt to work around the issue demonstrate at
https://github.com/rouson/mole/actions/runs/19996603010/job/57345130923
* build(gfortran-{13,14} on ubuntu): workaround
This commit is an attempt to work around an issue demonstrated at
https://github.com/rouson/mole/actions/runs/19996724722/job/57345438334
* build(gfortran-{13,14} on ubuntu): workaround
This commit attempts to work around the issue demonstrated at
https://github.com/rouson/mole/actions/runs/19996775690/job/573455685891 parent f109f4c commit 1d51241
23 files changed
Lines changed: 1782 additions & 466 deletions
File tree
- .github/workflows
- doc
- example
- src/fortran
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments