Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121798193
bm_adim_system.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jul 13, 23:55
Size
4 KB
Mime Type
text/x-c
Expires
Tue, Jul 15, 23:55 (2 d)
Engine
blob
Format
Raw Data
Handle
27392940
Attached To
rSPECMICP SpecMiCP / ReactMiCP
bm_adim_system.cpp
View Options
#include <benchmark/benchmark.h>
#include "specmicp/adimensional/adimensional_system.hpp"
#include "database/database.hpp"
#include "database.hpp"
#include "physics/laws.hpp"
#include <iostream>
using
namespace
specmicp
;
static
specmicp
::
RawDatabasePtr
get_simple_database
()
{
specmicp
::
database
::
Database
thedatabase
(
TEST_CEMDATA_PATH
);
std
::
map
<
std
::
string
,
std
::
string
>
swapping
({
{
"H[+]"
,
"HO[-]"
},
});
thedatabase
.
swap_components
(
swapping
);
std
::
vector
<
std
::
string
>
to_keep
=
{
"HO[-]"
,
"Ca[2+]"
};
thedatabase
.
keep_only_components
(
to_keep
);
thedatabase
.
remove_half_cell_reactions
(
std
::
vector
<
std
::
string
>
({
"H2O"
,
"HO[-]"
}));
return
thedatabase
.
get_database
();
}
static
AdimensionalSystemConstraints
get_simple_constraints
(
RawDatabasePtr
raw_data
)
{
Vector
total_concentration
=
Vector
::
Zero
(
raw_data
->
nb_component
());
total_concentration
(
raw_data
->
get_id_component
(
"H2O"
))
=
55.5
;
total_concentration
(
raw_data
->
get_id_component
(
"HO[-]"
))
=
2e-3
;
total_concentration
(
raw_data
->
get_id_component
(
"Ca[2+]"
))
=
1e-3
;
return
AdimensionalSystemConstraints
(
total_concentration
);
}
static
void
bm_simple_init
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
while
(
state
.
KeepRunning
())
{
AdimensionalSystem
system
(
raw_data
,
constraints
);
}
}
BENCHMARK
(
bm_simple_init
);
static
void
bm_simple_secondary_variables
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
AdimensionalSystem
system
(
raw_data
,
constraints
);
Vector
x
(
4
);
x
<<
0.1
,
-
3
,
-
3
,
0.0
;
while
(
state
.
KeepRunning
())
{
system
.
set_secondary_variables
(
x
);
}
}
BENCHMARK
(
bm_simple_secondary_variables
);
static
void
bm_simple_secondary_concentration
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
AdimensionalSystem
system
(
raw_data
,
constraints
);
Vector
x
(
4
);
x
<<
0.1
,
-
3
,
-
3
,
0.0
;
while
(
state
.
KeepRunning
())
{
system
.
set_secondary_concentration
(
x
);
}
}
BENCHMARK
(
bm_simple_secondary_concentration
);
static
void
bm_simple_log_gamma
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
AdimensionalSystem
system
(
raw_data
,
constraints
);
Vector
x
(
4
);
x
<<
0.1
,
-
3
,
-
3
,
0.0
;
system
.
set_secondary_concentration
(
x
);
while
(
state
.
KeepRunning
())
{
system
.
compute_log_gamma
(
x
);
}
}
BENCHMARK
(
bm_simple_log_gamma
);
static
void
bm_debye_huckel
(
benchmark
::
State
&
state
)
{
scalar_t
sqrtI
=
0.1
;
scalar_t
zi
=
2
;
scalar_t
ao
=
3.0
;
while
(
state
.
KeepRunning
())
{
scalar_t
a
=
laws
::
debye_huckel
(
sqrtI
,
zi
,
ao
);
benchmark
::
DoNotOptimize
(
a
);
}
}
BENCHMARK
(
bm_debye_huckel
);
static
void
bm_extended_debye_huckel
(
benchmark
::
State
&
state
)
{
scalar_t
I
=
0.01
;
scalar_t
sqrtI
=
0.1
;
scalar_t
zi
=
2
;
scalar_t
ao
=
3.0
;
scalar_t
bdot
=
0.1
;
while
(
state
.
KeepRunning
())
{
scalar_t
a
=
laws
::
extended_debye_huckel
(
I
,
sqrtI
,
zi
,
ao
,
bdot
);
benchmark
::
DoNotOptimize
(
a
);
}
}
BENCHMARK
(
bm_extended_debye_huckel
);
static
void
bm_simple_residual_water
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
AdimensionalSystem
system
(
raw_data
,
constraints
);
Vector
x
(
4
);
x
<<
0.1
,
-
3
,
-
3
,
0.0
;
system
.
set_secondary_variables
(
x
);
while
(
state
.
KeepRunning
())
{
system
.
residual_water_conservation
(
x
);
}
}
BENCHMARK
(
bm_simple_residual_water
);
static
void
bm_simple_residual_ca
(
benchmark
::
State
&
state
)
{
RawDatabasePtr
raw_data
=
get_simple_database
();
AdimensionalSystemConstraints
constraints
=
get_simple_constraints
(
raw_data
);
AdimensionalSystem
system
(
raw_data
,
constraints
);
Vector
x
(
4
);
x
<<
0.1
,
-
3
,
-
3
,
0.0
;
system
.
set_secondary_variables
(
x
);
while
(
state
.
KeepRunning
())
{
system
.
residual_component
(
x
,
2
);
}
}
BENCHMARK
(
bm_simple_residual_ca
);
BENCHMARK_MAIN
()
Event Timeline
Log In to Comment