Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73378288
adimensional_system_solver.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
Sat, Jul 20, 23:33
Size
6 KB
Mime Type
text/x-c
Expires
Mon, Jul 22, 23:33 (2 d)
Engine
blob
Format
Raw Data
Handle
19194343
Attached To
rSPECMICP SpecMiCP / ReactMiCP
adimensional_system_solver.cpp
View Options
#include "catch.hpp"
#include <iostream>
#include "utils/log.hpp"
#include "specmicp/adimensional/adimensional_system.hpp"
#include "micpsolver/micpsolver.hpp"
#include "specmicp/adimensional/adimensional_system_solver.hpp"
#include "specmicp/problem_solver/formulation.hpp"
#include "specmicp/problem_solver/dissolver.hpp"
#include "specmicp/adimensional/adimensional_system_solution_extractor.hpp"
#include "specmicp/adimensional/adimensional_system_solution_saver.hpp"
#include "database/database.hpp"
specmicp
::
RawDatabasePtr
get_test_simple_database
()
{
specmicp
::
database
::
Database
thedatabase
(
"../data/cemdata_specmicp.js"
);
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
);
return
thedatabase
.
get_database
();
}
using
namespace
specmicp
;
TEST_CASE
(
"Solving adimensional system"
,
"[specmicp, MiCP, program, adimensional, solver]"
)
{
specmicp
::
logger
::
ErrFile
::
stream
()
=
&
std
::
cerr
;
specmicp
::
stdlog
::
ReportLevel
()
=
specmicp
::
logger
::
Error
;
specmicp
::
RawDatabasePtr
thedatabase
=
get_test_simple_database
();
auto
id_h2o
=
database
::
DataContainer
::
water_index
();
auto
id_oh
=
thedatabase
->
get_id_component
(
"HO[-]"
);
auto
id_ca
=
thedatabase
->
get_id_component
(
"Ca[2+]"
);
auto
id_ch
=
thedatabase
->
get_id_mineral
(
"Portlandite"
);
SECTION
(
"Solving simple case"
)
{
Vector
total_concentration
=
Vector
::
Zero
(
thedatabase
->
nb_component
());
total_concentration
(
id_h2o
)
=
3.0e4
;
total_concentration
(
id_oh
)
=
2.0e4
;
total_concentration
(
id_ca
)
=
1.0e4
;
specmicp
::
AdimensionalSystemConstraints
constraints
(
total_concentration
);
specmicp
::
micpsolver
::
MiCPSolverOptions
options
;
options
.
maxstep
=
100
;
options
.
maxiter_maxstep
=
100
;
options
.
disable_crashing
();
options
.
disable_scaling
();
options
.
disable_descent_direction
();
std
::
shared_ptr
<
specmicp
::
AdimensionalSystem
>
system
=
std
::
make_shared
<
specmicp
::
AdimensionalSystem
>
(
thedatabase
,
constraints
);
specmicp
::
micpsolver
::
MiCPSolver
<
specmicp
::
AdimensionalSystem
>
solver
(
system
);
solver
.
set_options
(
options
);
Vector
x
=
Vector
::
Zero
(
system
->
total_variables
());
x
(
system
->
ideq_w
())
=
0.8
;
x
(
system
->
ideq_paq
(
id_oh
))
=
-
2.0
;
x
(
system
->
ideq_paq
(
id_ca
))
=
-
2.3
;
system
->
compute_log_gamma
(
x
);
system
->
set_secondary_concentration
(
x
);
solver
.
solve
(
x
);
CHECK
(
x
(
system
->
ideq_w
())
==
Approx
(
0.542049
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_paq
(
id_oh
))
==
Approx
(
-
1.48059
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_paq
(
id_ca
))
==
Approx
(
-
1.8538
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_min
(
id_ch
))
==
Approx
(
0.32966
).
epsilon
(
1e-4
));
}
SECTION
(
"Solving simple case - volum in cm^3"
)
{
Vector
total_concentration
=
Vector
::
Zero
(
thedatabase
->
nb_component
());
total_concentration
(
id_h2o
)
=
0.03
;
total_concentration
(
id_oh
)
=
0.02
;
total_concentration
(
id_ca
)
=
0.01
;
specmicp
::
AdimensionalSystemConstraints
constraints
(
total_concentration
);
specmicp
::
micpsolver
::
MiCPSolverOptions
options
;
options
.
maxstep
=
10
;
options
.
maxiter_maxstep
=
100
;
options
.
disable_crashing
();
options
.
enable_scaling
();
options
.
disable_descent_direction
();
std
::
shared_ptr
<
specmicp
::
AdimensionalSystem
>
system
=
std
::
make_shared
<
specmicp
::
AdimensionalSystem
>
(
thedatabase
,
constraints
);
units
::
UnitsSet
unit_set
;
unit_set
.
length
=
units
::
LengthUnit
::
centimeter
;
system
->
set_units
(
unit_set
);
specmicp
::
micpsolver
::
MiCPSolver
<
specmicp
::
AdimensionalSystem
>
solver
(
system
);
solver
.
set_options
(
options
);
Vector
x
=
Vector
::
Zero
(
system
->
total_variables
());
x
(
system
->
ideq_w
())
=
0.8
;
x
(
system
->
ideq_paq
(
id_oh
))
=
-
2.0
;
x
(
system
->
ideq_paq
(
id_ca
))
=
-
2.3
;
system
->
compute_log_gamma
(
x
);
system
->
set_secondary_concentration
(
x
);
solver
.
solve
(
x
);
CHECK
(
x
(
system
->
ideq_w
())
==
Approx
(
0.542049
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_paq
(
id_oh
))
==
Approx
(
-
1.48059
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_paq
(
id_ca
))
==
Approx
(
-
1.8538
).
epsilon
(
1e-4
));
CHECK
(
x
(
system
->
ideq_min
(
id_ch
))
==
Approx
(
0.32966
).
epsilon
(
1e-4
));
}
SECTION
(
"Automatic solver"
)
{
Vector
total_concentration
=
Vector
::
Zero
(
thedatabase
->
nb_component
());
total_concentration
(
id_h2o
)
=
0.03
;
total_concentration
(
id_oh
)
=
0.02
;
total_concentration
(
id_ca
)
=
0.01
;
specmicp
::
Vector
x
;
specmicp
::
AdimensionalSystemConstraints
constraints
(
total_concentration
);
specmicp
::
AdimensionalSystemSolver
solver
(
thedatabase
,
constraints
);
solver
.
initialise_variables
(
x
,
0.8
,
-
2.0
);
//x(solver.dof_surface()) = -HUGE_VAL;
solver
.
get_options
().
units_set
.
length
=
specmicp
::
units
::
LengthUnit
::
centimeter
;
solver
.
get_options
().
solver_options
.
maxstep
=
10.0
;
solver
.
get_options
().
solver_options
.
maxiter_maxstep
=
100
;
solver
.
get_options
().
solver_options
.
use_crashing
=
false
;
solver
.
get_options
().
solver_options
.
use_scaling
=
true
;
solver
.
get_options
().
solver_options
.
disable_descent_direction
();
solver
.
get_options
().
solver_options
.
factor_gradient_search_direction
=
100
;
solver
.
solve
(
x
);
AdimensionalSystemSolution
solution
=
solver
.
get_raw_solution
(
x
);
AdimensionalSystemSolutionExtractor
extr
(
solution
,
thedatabase
,
solver
.
get_options
().
units_set
);
CHECK
(
extr
.
volume_fraction_water
()
==
Approx
(
0.542049
).
epsilon
(
1e-4
));
CHECK
(
extr
.
log_molality_component
(
id_oh
)
==
Approx
(
-
1.48059
).
epsilon
(
1e-4
));
CHECK
(
extr
.
log_molality_component
(
id_ca
)
==
Approx
(
-
1.8538
).
epsilon
(
1e-4
));
//CHECK(extr.free_surface_concentration() == -HUGE_VAL);
CHECK
(
extr
.
volume_fraction_mineral
(
id_ch
)
==
Approx
(
0.32966
).
epsilon
(
1e-4
));
AdimensionalSystemSolutionSaver
saver
(
thedatabase
);
saver
.
save_solution
(
"test_solution.js"
,
solution
);
AdimensionalSystemSolution
solution2
=
saver
.
parse_solution
(
"test_solution.js"
);
REQUIRE
(
solution
.
main_variables
(
0
)
==
Approx
(
solution2
.
main_variables
(
0
)));
REQUIRE
(
solution
.
main_variables
(
id_oh
)
==
Approx
(
solution2
.
main_variables
(
id_oh
)));
REQUIRE
(
solution
.
main_variables
(
id_ca
)
==
Approx
(
solution2
.
main_variables
(
id_ca
)));
REQUIRE
(
extr
.
volume_fraction_mineral
(
id_ch
)
==
Approx
(
solution2
.
main_variables
(
extr
.
dof_mineral
(
id_ch
))));
REQUIRE
(
solution
.
log_gamma
.
norm
()
==
Approx
(
solution2
.
log_gamma
.
norm
()));
}
}
Event Timeline
Log In to Comment