Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73453951
carboalu.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 21, 09:50
Size
8 KB
Mime Type
text/x-c++
Expires
Tue, Jul 23, 09:50 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19204323
Attached To
rSPECMICP SpecMiCP / ReactMiCP
carboalu.cpp
View Options
/*-------------------------------------------------------
- Module : tests/
- File : carboalu.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#include <iostream>
#include <chrono>
#include "utils/log.hpp"
#include "specmicp/reaction_path.hpp"
double
mult
=
1.0
;
double
m_c3s
=
mult
*
0.6
;
double
m_c2s
=
mult
*
0.2
;
double
m_c3a
=
mult
*
0.10
;
double
m_gypsum
=
mult
*
0.10
;
double
wc
=
0.8
;
class
Timer
{
public
:
Timer
()
:
beg_
(
clock_
::
now
())
{}
void
reset
()
{
beg_
=
clock_
::
now
();
}
double
elapsed
()
const
{
return
std
::
chrono
::
duration_cast
<
second_
>
(
clock_
::
now
()
-
beg_
).
count
();
}
private
:
typedef
std
::
chrono
::
high_resolution_clock
clock_
;
typedef
std
::
chrono
::
duration
<
double
,
std
::
ratio
<
1
>
>
second_
;
std
::
chrono
::
time_point
<
clock_
>
beg_
;
};
struct
Params
{
specmicp
::
micpsolver
::
NCPfunction
ncpfunction
;
double
penalizationfactor
;
bool
scaling
;
};
const
Params
CCKParam
=
{
specmicp
::
micpsolver
::
NCPfunction
::
penalizedFB
,
0.8
,
false
};
const
Params
FBParam
=
{
specmicp
::
micpsolver
::
NCPfunction
::
penalizedFB
,
1.0
,
false
};
const
Params
minParam
=
{
specmicp
::
micpsolver
::
NCPfunction
::
min
,
1.0
,
true
};
void
solve_carboalu
(
double
delta
,
Params
param
,
bool
output
=
true
,
bool
coldstart
=
false
)
{
specmicp
::
database
::
Database
database
(
"../data/cemdata_specmicp.js"
);
std
::
shared_ptr
<
specmicp
::
database
::
DataContainer
>
data
=
database
.
get_database
();
std
::
map
<
std
::
string
,
std
::
string
>
swapping
({
{
"H[+]"
,
"HO[-]"
},
{
"Al[3+]"
,
"Al(OH)4[-]"
},
{
"Si(OH)4"
,
"SiO(OH)3[-]"
}
});
database
.
swap_components
(
swapping
);
std
::
shared_ptr
<
specmicp
::
ReactionPathModel
>
model
=
std
::
make_shared
<
specmicp
::
ReactionPathModel
>
();
double
delta_h2co3
=
delta
;
double
delta_sio2
=
0.00
;
double
m_water
=
wc
*
1e-3
*
(
m_c3s
*
(
3
*
56.08
+
60.08
)
+
m_c2s
*
(
2
*
56.06
+
60.08
)
+
m_c3a
*
(
3
*
56.08
+
101.96
)
+
m_gypsum
*
(
56.08
+
80.06
+
2
*
18.02
));
//std::cout << m_water << std::endl;
model
->
amount_aqueous
=
{
{
"H2O"
,
specmicp
::
reaction_amount_t
(
m_water
/
data
->
molar_mass_basis_si
(
0
),
delta_h2co3
+
delta_sio2
)},
{
"HCO3[-]"
,
specmicp
::
reaction_amount_t
(
0
,
delta_h2co3
)},
{
"HO[-]"
,
specmicp
::
reaction_amount_t
(
0
,
-
delta_h2co3
-
delta_sio2
)},
{
"SiO(OH)3[-]"
,
specmicp
::
reaction_amount_t
(
0
,
delta_sio2
)},
};
model
->
amount_minerals
=
{
{
"C3S"
,
specmicp
::
reaction_amount_t
(
m_c3s
,
0
)},
{
"C2S"
,
specmicp
::
reaction_amount_t
(
m_c2s
,
0
)},
{
"C3A"
,
specmicp
::
reaction_amount_t
(
m_c3a
,
0
)},
{
"Gypsum"
,
specmicp
::
reaction_amount_t
(
m_gypsum
,
0
)}
};
model
->
database_path
=
"../data/cemdata_specmicp.js"
;
model
->
minerals_to_keep
=
{
"Portlandite"
,
"CSH,jennite"
,
"CSH,tobermorite"
,
"SiO2,am"
,
"Calcite"
,
"Al(OH)3,am"
,
"Monosulfoaluminate"
,
"Tricarboaluminate"
,
"Monocarboaluminate"
,
"Hemicarboaluminate"
,
"Straetlingite"
,
"Gypsum"
,
"Ettringite"
,
"Thaumasite"
};
Eigen
::
VectorXd
x
;
specmicp
::
ReactionPathDriver
driver
(
model
,
data
,
x
);
Eigen
::
VectorXd
totaq
(
data
->
nb_component
);
double
totiter
=
0
;
double
totfact
=
0
;
driver
.
get_options
().
solver_options
.
penalization_factor
=
param
.
penalizationfactor
;
driver
.
get_options
().
ncp_function
=
param
.
ncpfunction
;
driver
.
get_options
().
solver_options
.
use_scaling
=
param
.
scaling
;
driver
.
get_options
().
solver_options
.
max_factorization_step
=
4
;
driver
.
get_options
().
solver_options
.
factor_gradient_search_direction
=
200
;
driver
.
get_options
().
solver_options
.
max_iter
=
50
;
driver
.
get_options
().
solver_options
.
maxstep
=
100
;
driver
.
get_options
().
solver_options
.
factor_descent_condition
=
1e-6
;
driver
.
get_options
().
allow_restart
=
true
;
driver
.
get_options
().
system_options
.
charge_keeper
=
database
.
component_label_to_id
(
"HO[-]"
);
if
(
output
)
{
std
::
cout
<<
"Reaction_path return_code nb_iter nb_fact pH"
;
for
(
auto
it
=
data
->
labels_basis
.
begin
();
it
!=
data
->
labels_basis
.
end
();
++
it
)
{
std
::
cout
<<
" "
<<
*
it
;
}
for
(
auto
it
=
data
->
labels_minerals
.
begin
();
it
!=
data
->
labels_minerals
.
end
();
++
it
)
{
std
::
cout
<<
" "
<<
*
it
;
}
std
::
cout
<<
std
::
endl
;
}
const
int
nb_step
=
1
+
2.5
/
delta
;
for
(
int
i
=
0
;
i
<
nb_step
;
++
i
)
{
specmicp
::
micpsolver
::
MiCPPerformance
perf
=
driver
.
one_step
(
x
,
coldstart
);
specmicp
::
EquilibriumState
solution
=
driver
.
get_current_solution
();
solution
.
total_aqueous_concentrations
(
totaq
);
if
(
output
)
{
std
::
cout
<<
i
*
(
delta_sio2
+
delta_h2co3
)
<<
" "
<<
(
int
)
perf
.
return_code
<<
" "
<<
perf
.
nb_iterations
<<
" "
<<
perf
.
nb_factorization
<<
" "
<<
solution
.
pH
()
<<
" "
<<
solution
.
mass_water
()
<<
" "
<<
totaq
.
block
(
1
,
0
,
data
->
nb_component
-
1
,
1
).
transpose
();
for
(
int
m
=
0
;
m
<
data
->
nb_mineral
;
++
m
)
std
::
cout
<<
" "
<<
solution
.
moles_mineral
(
m
);
std
::
cout
<<
std
::
endl
;
}
totiter
+=
perf
.
nb_iterations
;
totfact
+=
perf
.
nb_factorization
;
//data->stability_mineral(database.mineral_label_to_id("SiO2,am")) = specmicp::database::MineralStabilityClass::cannot_dissolve;
}
if
(
output
)
{
std
::
cout
<<
"Average iterations : "
<<
totiter
/
nb_step
<<
std
::
endl
;
std
::
cout
<<
"Average factorization : "
<<
totfact
/
nb_step
<<
std
::
endl
;
}
}
int
main
()
{
specmicp
::
stdlog
::
ReportLevel
()
=
specmicp
::
logger
::
Warning
;
specmicp
::
logger
::
ErrFile
::
stream
()
=
&
std
::
cerr
;
int
nbloop
=
7500
;
double
delta
=
0.01
;
Timer
tmr
;
solve_carboalu
(
delta
,
CCKParam
,
true
);
//for (int i=0; i<nbloop; ++i) {solve_carboalu(delta, CCKParam, false);}
//std::cout << "CCK runtime: " << tmr.elapsed()/nbloop << std::endl;
//solve_carboalu(delta, CCKParam, true, true);
//tmr.reset();
//for (int i=0; i<nbloop; ++i) {solve_carboalu(delta, CCKParam, false, true);}
//std::cout << "CCK coldstart runtime: " << tmr.elapsed()/nbloop << std::endl;
//solve_carboalu(delta, FBParam, true);
//tmr.reset();
//for (int i=0; i<nbloop; ++i) {solve_carboalu(delta, FBParam, false);}
//std::cout << "FB runtime: " << tmr.elapsed()/nbloop << std::endl;
//solve_carboalu(delta, minParam, true);
//tmr.reset();
//for (int i=0; i<nbloop; ++i) {solve_carboalu(delta, minParam, false);}
//std::cout << "min runtime: " << tmr.elapsed()/nbloop << std::endl;
//solve_carboalu(delta, minParam, true, true);
}
Event Timeline
Log In to Comment