Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83489198
dlma_iterator.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
Tue, Sep 17, 10:24
Size
4 KB
Mime Type
text/x-c++
Expires
Thu, Sep 19, 10:24 (2 d)
Engine
blob
Format
Raw Data
Handle
20843934
Attached To
rDLMA Diffusion limited mixed aggregation
dlma_iterator.cpp
View Options
#include <dlma_iterator.hh>
namespace
simulation
{
template
<
typename
type
>
std
::
vector
<
std
::
string
>
dlma_iterator
<
type
>::
split_string_by_delimiter
(
const
std
::
string
&
s
,
char
delimiter
)
{
std
::
vector
<
std
::
string
>
tokens
;
std
::
string
token
;
std
::
istringstream
tokenStream
(
s
);
while
(
std
::
getline
(
tokenStream
,
token
,
delimiter
))
{
tokens
.
push_back
(
token
);
}
return
tokens
;
}
template
<
typename
type
>
dlma_iterator
<
type
>::
dlma_iterator
(
char
*
filename
)
{
std
::
ifstream
parser
(
filename
,
std
::
ifstream
::
in
);
if
(
parser
.
fail
()){
std
::
cout
<<
"either file does not exist or does not have permissions"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
std
::
string
bind_name
;
bool
bind_flag
=
false
;
std
::
string
agg_condition_name
;
bool
agg_condition_flag
=
false
;
std
::
string
check_agg_name
;
bool
check_agg_flag
=
false
;
std
::
string
movement_name
;
bool
movement_flag
=
false
;
std
::
string
save_config_name
;
bool
save_config_flag
=
false
;
int
rng_seed
;
bool
rng_seed_flag
=
false
;
int
lattice
;
bool
lattice_flag
=
false
;
int
count
=
0
;
std
::
string
str
;
std
::
vector
<
std
::
string
>
results
;
while
(
getline
(
parser
,
str
)){
results
=
split_string_by_delimiter
(
str
,
'='
);
if
(
results
[
0
]
==
"bind"
){
bind_name
=
results
[
1
];
bind_flag
=
true
;
}
if
(
results
[
0
]
==
"aggregation_condition"
){
agg_condition_name
=
results
[
1
];
agg_condition_flag
=
true
;
}
if
(
results
[
0
]
==
"aggregation_type"
){
check_agg_name
=
results
[
1
];
check_agg_flag
=
true
;
}
if
(
results
[
0
]
==
"movement"
){
movement_name
=
results
[
1
];
movement_flag
=
true
;
}
if
(
results
[
0
]
==
"system"
){
save_config_name
=
results
[
1
];
save_config_flag
=
true
;
}
if
(
results
[
0
]
==
"rng_seed"
){
rng_seed
=
stoi
(
results
[
1
]);
rng_seed
++
;
rng_seed_flag
=
true
;
}
if
(
results
[
0
]
==
"lattice"
){
lattice
=
stoi
(
results
[
1
]);
lattice_flag
=
true
;
}
}
parser
.
close
();
if
(
bind_flag
==
false
){
std
::
cout
<<
"please provide bind"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
agg_condition_flag
==
false
){
std
::
cout
<<
"please provide aggregation condition"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
check_agg_flag
==
false
){
std
::
cout
<<
"please provide aggregation type"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
movement_flag
==
false
){
std
::
cout
<<
"please provide movement"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
save_config_flag
==
false
){
std
::
cout
<<
"please provide system type"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
if
(
rng_seed_flag
==
false
){
rng_seed
=
1
;
}
if
(
lattice_flag
==
false
){
std
::
cout
<<
"please provide lattice type"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
sys_state
=
factory
->
create_new_system
(
save_config_name
,
lattice
,
filename
);
binding_obj
=
factory
->
create_bind_system
(
bind_name
,
sys_state
);
agg_condition
=
factory
->
create_aggregation_condition
(
agg_condition_name
,
sys_state
);
aggregation_check_obj
=
factory
->
create_check_aggregation
(
check_agg_name
,
lattice
,
sys_state
,
binding_obj
,
agg_condition
);
movement_test
=
factory
->
create_movement
(
movement_name
,
sys_state
->
get_dim
(),
rng_seed
,
lattice
);
save_obj
=
factory
->
create_save_config
(
save_config_name
,
sys_state
,
sys_state
->
get_box
());
for
(
int
i
=
0
;
i
<
sys_state
->
get_latest_cluster_id_without_increment
();
i
++
){
temp_c
=
sys_state
->
get_aggregate
(
i
);
if
(
temp_c
){
aggregation_check_obj
->
check_for_aggregation
(
temp_c
);
}
}
}
template
<
typename
type
>
void
dlma_iterator
<
type
>::
iteration_step
()
{
temp
=
(
int
)(
movement_test
->
get_rand
()
*
sys_state
->
total_aggregates
());
temp_c
=
sys_state
->
get_constituent
(
temp
);
sys_state
->
move_aggregate
(
temp
,
movement_test
->
delta_x
());
aggregation_check_obj
->
check_for_aggregation
(
temp_c
);
}
template
<
typename
type
>
void
dlma_iterator
<
type
>::
run_system
()
{
while
(
sys_state
->
total_aggregates
()
!=
1
){
//std::cout<<"aggregates="<<sys_state->total_aggregates()<<std::endl;
iteration_step
();
}
}
template
<
typename
type
>
void
dlma_iterator
<
type
>::
save_config_file
()
{
save_obj
->
save_configuration
();
}
template
<
typename
type
>
void
dlma_iterator
<
type
>::
save_config_file
(
char
*
filename
)
{
save_obj
->
save_configuration
(
filename
);
}
template
class
dlma_iterator
<
int
>
;
template
class
dlma_iterator
<
double
>
;
}
Event Timeline
Log In to Comment