Skip to content

Commit c776f81

Browse files
authored
Merge pull request #5 from BerkeleyLab/prep-0.1.0-release
Documentation & expanded compiler support
2 parents 521a9f1 + 8deb3cf commit c776f81

3 files changed

Lines changed: 84 additions & 28 deletions

File tree

README.md

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,102 @@ ___________ .__
1010
Formal: Fortran mimetic abstraction language
1111
============================================
1212

13-
_Towards a formally verifiable, tensor-calculus langauge embedded in Fortran 2028._
13+
_Towards an embedded domain-specific language (DSL) for tensor calculus and formal verification._
1414

15-
## Examples
15+
Introduction
16+
------------
17+
Formal supports research on mimetic software abstractions for tensor calculus by providing
18+
19+
- Derived types that mimic tensor fields and
20+
- Differential and integral operators for writing tensor expressions.
21+
22+
Formal's types and operators implement the discrete calculus of [Castillo & Corbino (2020)]:
23+
mimetic discretizations satisfying discrete versions of tensor calculus theorems.
24+
25+
Like the underlying numerical methods, Formal's software abstractios mimic their tensor calculus counterparts.
26+
For example, given scalar and vector fields $f$ and $\vec{v}$ defined over a unit volume $V = [0,1]^3$ bounded
27+
by a surface area $A$, the program [`example/extended-gauss-divergence.F90`] demonstrates satisfaction of the
28+
extended Gauss divergence theorem:
29+
30+
$$ \iiint_V (\vec{v} \cdot \nabla f) dV + \iiint_V (f \nabla \cdot \vec{v}) dV = \iint_A f \vec{v} \cdot d\vec{A} $$
31+
32+
Running the program as follows
33+
```fortran
34+
fpm run --example extended-gauss-divergence --compiler flang-new --flag -O3
35+
```
36+
produces output that includes actual program syntax:
37+
```fortran
38+
f = (x**2)/2 ! <-- scalar function
39+
v = x ! <-- vector function
40+
.SSS. (v .dot. .grad. f) * dV = .3333333330205934
41+
.SSS. ( f * .div. v) * dV = .16666666739857125
42+
-.SS. (f .x. (v .dot. dA)) = -.5000000004191649
43+
----------------------------------------------------
44+
sum = -.2220446049250313E-15 (residual)
45+
```
46+
where the small residual of approximately $-.222 \times 10^{-15}$ evidences a highly accurate approximation.
47+
48+
**Future work:** Formal lays a foundation for defining a DSL embedded in Fortran via template requirements,
49+
a feature of the forthcoming standard known informally as Fortran 202Y.
50+
51+
Examples
52+
--------
1653
See this repository's [example](./example) subdirectory for demonstrations of how
17-
to use Formal. For usage information for each example, execute something like:
54+
to use Formal. For usage information for each example, execute something like
1855
```bash
1956
fpm run --example <base-name> -- --help
2057
```
21-
where `base-name` is the portion of an example file name preceding the `.F90` or
22-
`.f90` extension. To save typing in a terminal window, set the `example`
23-
directory as your present working directory before issuing the above `fpm run`
24-
command. Then use tab completion to enter enter the base name and delete the
25-
file extension before pressing `return`.
26-
27-
## Prerequisites
58+
replacing `<base-name>` with the portion of an example file name preceding the `.F90` or
59+
`.f90` extension. To save typing in a terminal window, set the `example` directory as
60+
your present working directory before typing `fpm run` above. Then use tab completion to
61+
enter a file name and delete the file extension before pressing `return` or `enter`.
2862

63+
Prerequisite
64+
------------
2965
Building and testing Formal requires the Fortran Package Manager ([`fpm`]),
3066
which can be obtained via a package manager (e.g., `brew install fpm` on macOS)
3167
or by compiling the single-file concatenation of the `fpm` source that is
3268
included among the release assets. For the `fpm` 0.12.0 release, for example,
3369
compiling [fpm-0.12.0.F90] and placing the resulting executable file in your
3470
`PATH` suffices.
3571

36-
## Building and testing
72+
Building and testing
73+
--------------------
74+
Vendor | Compiler | Version(s) Tested | Build/Test Command
75+
--------|-------------|-------------------|-------------------
76+
GCC | `gfortran` | 14-15 | fpm test --compiler gfortran --profile release
77+
GCC | `gfortran` | 13 | fpm test --compiler gfortran --profile release --flag "-ffree-line-length-none"
78+
Intel | `ifx` | 2025.1.2 | FOR_COARRAY_NUM_IMAGES=1 fpm test --compiler ifx --flag "-fpp -O3 -coarray" --profile release
79+
LLVM | `flang-new` | 20-21 | fpm test --compiler flang-new --flag "-O3"
80+
LLVM | `flang-new` | 19 | fpm test --compiler flang-new --flag "-O3 -mmlir -allow-assumed-rank"
81+
NAG | `nagfor` | 7.2 Build 7242 | fpm test --compiler nagfor --flag "-O3 -fpp"
3782

38-
| Vendor | Compiler | Version(s) | Build/Test Command |
39-
|--------|-------------|------------|-------------------------------------------------------|
40-
| GCC | `gfortran` | 14-15 | fpm test --compiler gfortran --profile release |
41-
| GCC | `gfortran` | 13 | fpm test --compiler gfortran --profile release --flag "-ffree-line-length-none"|
42-
| Intel | `ifx` | 2025.1.2 | FOR_COARRAY_NUM_IMAGES=1 fpm test --compiler ifx --flag "-fpp -O3 -coarray" --profile release |
43-
| LLVM | `flang-new` | 20-21 | fpm test --compiler flang-new --flag "-O3" |
44-
| LLVM | `flang-new` | 19 | fpm test --compiler flang-new --flag "-O3 -mmlir -allow-assumed-rank" |
45-
| NAG | `nagfor` | 7.2 | fpm test --compiler nagfor --flag "-O3 -fpp" |
83+
With `fpm` versions _after_ 0.12.0, `flang-new` can be shortened to `flang` in the above `fpm` commands.
4684

47-
**Known Issues**
48-
1. With `fpm` versions _after_ 0.12.0, `flang-new` can be shortened to `flang`.
49-
2. With NAG 7.2, Build 7235 or later is recommended, but earlier builds might work.
50-
51-
## Documentation
85+
Documentation
86+
-------------
5287
The [`doc/uml/class-diagram.md`] file contains a Mermaid script that generates a
5388
Unified Modeling Language (UML) class diagram depicting many Formal derived
5489
types and their interrelationships. GitHub's web servers render the diagram
5590
graphically when viewed in a web browser.
5691

92+
Support and Licensing
93+
---------------------
94+
Please see [LICENSE.txt] for the copyright and license under which Formal is distributed.
95+
To report any difficulty with building, testing, or using Formal, please submit an [issue].
96+
To contribute code, please submit a [pull request] from a fork of Formal.
97+
98+
Funding Acknowledgment
99+
----------------------
100+
Formal is a software artifact of research funded by the Competitive Portfolios for Advanced
101+
Scientific Computing Research Program of the U.S. Department of Energy, Office of Science,
102+
Office of Advanced Scientific Computing Research under contract DE-AC02-05CH11231.
103+
57104
[`fpm`]: https://github.com/fortran-lang/fpm
58105
[fpm-0.12.0.F90]: https://github.com/fortran-lang/fpm/releases/download/v0.12.0/fpm-0.12.0.F90
59106
[`doc/uml/class-diagram.md`]: ./doc/uml/class-diagram.md
107+
[Castillo & Corbino (2020)]: https://doi.org/10.1016/j.cam.2019.06.042
108+
[`example/extended-gauss-divergence.F90`]: ./example/extended-gauss-divergence.F90
109+
[issue]: https://github.com/berkeleylab/formal/issues
110+
[pull request]: https://github.com/berkeleylab/formal/pulls
111+
[LICENSE.txt]: ./LICENSE.txt

example/extended-gauss-divergence.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ program extended_gauss_divergence
8888

8989
if (flags%grad_ .or. all_terms) then
9090
SSS_v_dot_grad_f_dV = .SSS. (v .dot. .grad. f) * dV
91-
print '(a,g0)', ".SSS. (v .dot. .grad. f) * dV = ", SSS_v_dot_grad_f_dV
91+
print '(a,g0)', ".SSS. (v .dot. .grad. f) * dV = ", SSS_v_dot_grad_f_dV
9292
end if
9393

9494
if (flags%div_ .or. all_terms) then
9595
SSS_f_div_v_dV = .SSS. (f * .div. v) * dV
96-
print '(a,g0)', ".SSS. ( f * .div. v) * dV = ", SSS_f_div_v_dV
96+
print '(a,g0)', ".SSS. ( f * .div. v) * dV = ", SSS_f_div_v_dV
9797
end if
9898

9999
end associate differential_volume
100100

101101
differential_area: &
102102
associate(dA => v%dA())
103103
if (flags%vf_ .or. all_terms) then
104-
SS_f_v_dot_dA = .SS. (f .x. (v .dot. dA))
105-
print '(a,g0)', " -.SS. (f .x. (v .dot. dA)) = ", -SS_f_v_dot_dA
104+
SS_f_v_dot_dA = .SS. (f .x. (v .dot. dA))
105+
print '(a,g0)', " -.SS. (f .x. (v .dot. dA)) = ", -SS_f_v_dot_dA
106106
end if
107107

108108
if (all_terms) then

src/formal/vector_1D_s.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ pure module function construct_1D_vector_from_function(initializer, order, cells
6969

7070
integer center
7171

72+
#ifdef NAGFOR
73+
associate(D => self%divergence_operator_1D_)
74+
#else
7275
associate(D => (self%divergence_operator_1D_))
76+
#endif
7377
associate(Dv => D .x. self%values_)
7478
divergence_1D%tensor_1D_t = tensor_1D_t(Dv(2:size(Dv)-1), self%x_min_, self%x_max_, self%cells_, self%order_)
7579
associate( &

0 commit comments

Comments
 (0)