Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for partial derivatives #13

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4342fb8
Adding of the math_tools/ folder and renaming od utils/math_tools.hpp…
gdgirard Dec 12, 2024
9e3387e
Modification of the title comment.
gdgirard Dec 12, 2024
cf02192
Rename file Lnorm_tools.hpp -> l_norm_tools.hpp
EmilyBourne Dec 12, 2024
faef937
Merge branch 'main' into gdgirard_10-partial-derivatives-of-a-2d-field
EmilyBourne Dec 12, 2024
0727d78
Remove dead link
EmilyBourne Dec 12, 2024
8a5c51b
Rename tests/utils/test_math_tools.cpp into tests/math_tools/test_lno…
gdgirard Dec 12, 2024
8b5b68b
Add missing README.md.
gdgirard Dec 12, 2024
9be6573
[GEOM TOKAMAXI] Add partial_derivatives.hpp.
gdgirard Dec 12, 2024
648f9c5
Add computation of max error for test_partial_derivatives.
gdgirard Dec 13, 2024
78ca751
The SplineBuilder must be batched
EmilyBourne Dec 13, 2024
ae00a5d
Add missing return
EmilyBourne Dec 13, 2024
53e1472
Correct the test on partial derivatives.
gdgirard Dec 13, 2024
0dfaf0a
Merge branch 'main' into gdgirard_10-partial-derivatives-of-a-2d-field_2
gdgirard Dec 13, 2024
599f139
Fix markdown problems.
gdgirard Dec 13, 2024
ca24c18
Generalisation of partial derivatives to more than 2D.
gdgirard Dec 13, 2024
f5efa98
Add static assert.
gdgirard Dec 13, 2024
aa8dd43
Update src/math_tools/README.md
gdgirard Dec 13, 2024
a7b9d22
Apply suggestions from code review
gdgirard Dec 13, 2024
68e23ee
Delete unuseful comment
gdgirard Dec 13, 2024
509e7b5
Add missing comments in class PartialDerivative.
gdgirard Dec 13, 2024
90e55ea
Correct the indentation.
gdgirard Dec 13, 2024
92c5a3c
Correct comments.
gdgirard Dec 13, 2024
698786e
Add missing compilation flags
EmilyBourne Dec 13, 2024
d3b8a9d
Allow MPI to run as root (this is fine inside a docker)
EmilyBourne Dec 13, 2024
212cbfb
Merge branch 'main' into gdgirard_10-partial-derivatives-of-a-2d-field_2
EmilyBourne Dec 13, 2024
975e67e
Fix indentation
EmilyBourne Dec 13, 2024
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
2 changes: 1 addition & 1 deletion simulations/geometryRTheta/diocotron/diocotron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "euler.hpp"
#include "geometry.hpp"
#include "input.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "output.hpp"
#include "paraconfpp.hpp"
#include "params.yaml.hpp"
Expand Down
2 changes: 1 addition & 1 deletion simulations/geometryRTheta/vortex_merger/vortex_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "euler.hpp"
#include "geometry.hpp"
#include "input.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "paraconfpp.hpp"
#include "params.yaml.hpp"
#include "pdi_out.yml.hpp"
Expand Down
2 changes: 1 addition & 1 deletion simulations/geometryXY/guiding_center/guiding_center.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "geometry.hpp"
#include "initialization_Kelvin_Helmholtz.hpp"
#include "input.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "output.hpp"
#include "paraconfpp.hpp"
#include "params.yaml.hpp"
Expand Down
17 changes: 9 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# SPDX-License-Identifier: MIT

add_subdirectory(advection)
add_subdirectory(collisions)
add_subdirectory(data_types)
add_subdirectory(utils)
add_subdirectory(speciesinfo)
add_subdirectory(io)
add_subdirectory(paraconfpp)
add_subdirectory(quadrature)
add_subdirectory(geometryXVx)
add_subdirectory(geometryXY)
add_subdirectory(geometryRTheta)
add_subdirectory(geometryXYVxVy)
add_subdirectory(geometryVparMu)
add_subdirectory(interpolation)
add_subdirectory(mapping)
add_subdirectory(multipatch)
add_subdirectory(advection)
add_subdirectory(timestepper)
add_subdirectory(collisions)
add_subdirectory(math_tools)
add_subdirectory(mpi_parallelisation)
add_subdirectory(multipatch)
add_subdirectory(paraconfpp)
add_subdirectory(pde_solvers)
add_subdirectory(quadrature)
add_subdirectory(speciesinfo)
add_subdirectory(timestepper)
add_subdirectory(utils)
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The `src/` folder contains all the code necessary to build a gyrokinetic semi-La
- [interpolation](./interpolation/README.md) - Code describing interpolation methods.
- [io](./io/README.md) - Code describing tools for inputting and outputting data in a simulation.
- [mapping](./mapping/README.md) - Code describing tools for handling different coordinate systems.
- [math\_tools](./math_tools/README.md) - Code describing math tools functions.
- [multipatch](./multipatch/README.md) - Code describing multipatch geometry.
<!-- - [paraconfpp](./paraconfpp/README.md) - Paraconf utility functions. -->
- [mpi\_parallelisation](./mpi_parallelisation/README.md) - Code describing the MPI parallelisation.
Expand Down
1 change: 1 addition & 0 deletions src/geometryRTheta/advection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_link_libraries(advection_rp
gslx::geometry_RTheta
gslx::interpolation_2D_rp
gslx::mapping
gslx::math_tools
gslx::utils
)
add_library(gslx::advection_rp ALIAS advection_rp)
2 changes: 1 addition & 1 deletion src/geometryRTheta/advection/advection_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "directional_tag.hpp"
#include "geometry.hpp"
#include "geometry_pseudo_cartesian.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "vector_field.hpp"
#include "vector_field_mem.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ddc_alias_inline_functions.hpp"
#include "ddc_aliases.hpp"
#include "geometry.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "poisson_like_rhs_function.hpp"
#include "polarpoissonlikesolver.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/geometryRTheta/time_solver/bsl_predcorr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "geometry.hpp"
#include "ifoot_finder.hpp"
#include "itimesolver.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "poisson_like_rhs_function.hpp"
#include "polarpoissonlikesolver.hpp"
#include "rk2.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/geometryXY/time_integration/predcorr_RK2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "ddc_aliases.hpp"
#include "directional_tag.hpp"
#include "geometry.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "paraconfpp.hpp"
#include "rk2.hpp"
#include "vector_field.hpp"
Expand Down
16 changes: 16 additions & 0 deletions src/math_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: MIT

add_library("math_tools" INTERFACE)

target_include_directories("math_tools"
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}"
)

target_link_libraries("math_tools"
INTERFACE
DDC::DDC
gslx::data_types
)

add_library("gslx::math_tools" ALIAS "math_tools")

9 changes: 9 additions & 0 deletions src/math_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Utility Functions

This folder contains mathematical classes and functions.

## Utility tools

gdgirard marked this conversation as resolved.
Show resolved Hide resolved
The l\_norm\_tools.hpp file contains functions computing the infinity norm. For now, it computes the infinity norm of
- a double: $`\Vert x \Vert_{\infty} = x`$;
- a coordinate: $`\Vert x \Vert_{\infty} = \max_{i} (|x_i|)`$.
4 changes: 2 additions & 2 deletions src/utils/math_tools.hpp → src/math_tools/l_norm_tools.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
/**
* @file math_tools.hpp
* File Describing useful mathematical functions.
* @file l_norm_tools.hpp
* File Describing useful mathematical functions to compute Lnorms
*/

#pragma once
Expand Down
73 changes: 73 additions & 0 deletions src/math_tools/partial_derivatives.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

// SPDX-License-Identifier: MIT
/**
* @file partial_derivatives.hpp
* File containing functions to compute the partial derivatives
*/

#pragma once

#include <ddc/ddc.hpp>

#include "ddc_alias_inline_functions.hpp"
#include "ddc_aliases.hpp"


/**
* @brief Compute the partial derivative of a
*
* For a given field @f$F(X1,X2)@f$ , compute
* @f$\partial_{Xi} F(X1,X2)@f$ with i=1 or 2.
*
* @param[in] Xi
* The given coordinate for the partial derivative.
*
* @return @f$\partial_{Xi} F(X1,X2)@f$
*/

template <
class GridXi,
class GridX1,
class GridX2,
class FieldX1Builder,
class FieldX1Evaluator>
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
class PartialDerivative
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
{
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
private:
using IdxRangeX1X2 = IdxRange<GridX1, GridX2>;
using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type;
using DFieldX1X2 = DField<IdxRangeX1X2>;
using DConstFieldX1X2 = DConstField<IdxRangeX1X2>;

// Type for spline representation of the field
using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type;
using FieldX1SplineMem = DFieldMem<IdxRangeBSFieldX1>;
using FieldX1SplineCoeffs = DField<IdxRangeBSFieldX1>;

FieldX1Builder const& m_fieldx1_builder;
FieldX1Evaluator const& m_fieldx1_evaluator;

public:
explicit PartialDerivative(
FieldX1Builder const& fieldx1_builder,
FieldX1Evaluator const& fieldx1_evaluator)
: m_fieldx1_builder(fieldx1_builder)
, m_fieldx1_evaluator(fieldx1_evaluator)
{
}

~PartialDerivative() = default;

DFieldX1X2 operator()(DFieldX1X2 dfield_dx1_x1x2, DConstFieldX1X2 field_x1x2)
{
// Build spline representation of the field ....................................
FieldX1SplineMem fieldx1_coefs_alloc(
m_fieldx1_builder.batched_spline_domain());
FieldX1SplineCoeffs fieldx1_coefs = get_field(fieldx1_coefs_alloc);

m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2));
m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, get_const_field(fieldx1_coefs));

return dfield_dx1_x1x2;
}
};
2 changes: 0 additions & 2 deletions src/multipatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ The `multipatch` folder contains all the code describing methods and classes whi

- [data\_types](./data_types/README.md) - Defines classes to handle objects on a multipatch domain more conveniently.

- [interface\_derivatives](./interface_derivatives/README.md) - Ongoing work only available on GitLab.

- [spline](./spline/README.md) - Defines structures and methods to deal with different splines on every patches.

- [utils](./utils/README.md) - Defines utility functions to operate over multiple patches.
2 changes: 1 addition & 1 deletion src/multipatch/utils/multipatch_math_tools.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
#pragma once
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "multipatch_field.hpp"

/**
Expand Down
3 changes: 1 addition & 2 deletions src/timestepper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@



add_library(timestepper INTERFACE)
target_include_directories(timestepper
INTERFACE
Expand All @@ -9,6 +7,7 @@ target_include_directories(timestepper
target_link_libraries(timestepper INTERFACE
DDC::core
gslx::data_types
gslx::math_tools
gslx::multipatch_data_types
gslx::multipatch_utils
gslx::utils
Expand Down
2 changes: 1 addition & 1 deletion src/timestepper/crank_nicolson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "ddc_aliases.hpp"
#include "ddc_helper.hpp"
#include "itimestepper.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "multipatch_math_tools.hpp"
#include "vector_field_common.hpp"

Expand Down
6 changes: 0 additions & 6 deletions src/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,3 @@ This folder contains classes and functions which facilitate the writing of the r
The class ddcHelper exists to provide functionalities which are currently missing from DDC.

The class NDTag exists to provide a way to group directional tags together. This is notably useful in order to create a vector field.

## Utility tools

The utils\_tools.hpp file contains functions computing the infinity norm. For now, it computes the infinity norm of
- a double: $`\Vert x \Vert_{\infty} = x`$;
- a coordinate: $`\Vert x \Vert_{\infty} = \max_{i} (|x_i|)`$.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_subdirectory(geometryRTheta)
add_subdirectory(geometryVparMu)
add_subdirectory(multipatch)
add_subdirectory(mpi_parallelisation)
add_subdirectory(math_tools)
add_subdirectory(pde_solvers)
add_subdirectory(quadrature)
add_subdirectory(timestepper)
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ It is broken up into the following sub-folders:
- geometryVparMu - Tests in the vpar-mu geometry.
- geometryXVx - Tests in the x-vx geometry.
- geometryXYVxVy - Tests in the x,y-vx,vy geometry.
- math\_tools - Test for mathematical functions.
- MPI parallelism - Tests for the templated MPI operators.
- [multipatch](./multipatch/README.md) - Tests for the classes that work over multipatch geometries.
- PDE solvers - Tests for the templated Partial Differential Equation solvers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "bsl_advection_rp.hpp"
#include "directional_tag.hpp"
#include "geometry.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "paraconfpp.hpp"
#include "params.yaml.hpp"
#include "quadrature.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "crank_nicolson.hpp"
#include "euler.hpp"
#include "geometry.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "mesh_builder.hpp"
#include "quadrature.hpp"
#include "rk3.hpp"
Expand Down
1 change: 1 addition & 0 deletions tests/geometryRTheta/quadrature/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_link_libraries(Li_norms_spline_quadrature_tests
sll::SLL
gslx::geometry_RTheta
gslx::quadrature
gslx::math_tools
gslx::utils

)
Expand Down
2 changes: 1 addition & 1 deletion tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <gtest/gtest.h>

#include "geometry.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"
#include "mesh_builder.hpp"
#include "quadrature.hpp"
#include "spline_quadrature.hpp"
Expand Down
21 changes: 21 additions & 0 deletions tests/math_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: MIT


include(GoogleTest)

add_executable(unit_tests_math_tools
test_lnorm_tools.cpp
test_partial_derivatives.cpp
../main.cpp
)
target_link_libraries(unit_tests_math_tools
PUBLIC
DDC::pdi
GTest::gtest
GTest::gmock
paraconf::paraconf
gslx::math_tools
gslx::utils
)
gdgirard marked this conversation as resolved.
Show resolved Hide resolved

gtest_discover_tests(unit_tests_math_tools DISCOVERY_MODE PRE_TEST)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "ddc_alias_inline_functions.hpp"
#include "ddc_aliases.hpp"
#include "ddc_helper.hpp"
#include "math_tools.hpp"
#include "l_norm_tools.hpp"

namespace {

Expand Down
Loading
Loading