Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91961624
mineral_selector.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, Nov 16, 04:14
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 04:14 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22354912
Attached To
rSPECMICP SpecMiCP / ReactMiCP
mineral_selector.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : mineral_selector.cpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget, Princeton University
---------------------------------------------------------*/
#include "mineral_selector.hpp"
namespace specmicp {
namespace database {
void MineralSelector::keep_only(const std::vector<int>& minerals_to_keep)
{
// First we compute the new sizes
const int nb_to_keep = minerals_to_keep.size();
const int nb_to_remove = data->nb_mineral - nb_to_keep;
const int nb_new_min_kin = data->nb_mineral_kinetic + nb_to_remove;
// Then we assure that there is place for moving data
data->logk_mineral_kinetic.conservativeResize(nb_new_min_kin);
data->labels_minerals_kinetic.reserve(nb_new_min_kin);
data->nu_mineral_kinetic.conservativeResize(nb_new_min_kin, Eigen::NoChange);
data->_molar_volume_mineral_kinetic.conservativeResize(nb_new_min_kin);
// Then we move data
int new_id = 0;
int new_id_kin = data->nb_mineral_kinetic;
for (int id=0; id<data->nb_mineral; ++id)
{
auto search = std::find(minerals_to_keep.begin(), minerals_to_keep.end(), id);
if (search == minerals_to_keep.end() )
{
data->logk_mineral_kinetic(new_id_kin) = data->logk_mineral(id);
data->labels_minerals_kinetic.push_back(data->labels_minerals[id]);
data->nu_mineral_kinetic.row(new_id_kin) = data->nu_mineral.row(id);
data->_molar_volume_mineral_kinetic(new_id_kin) = data->_molar_volume_mineral(id);
++new_id_kin;
}
else
{
data->logk_mineral(new_id) = data->logk_mineral(id);
data->labels_minerals[new_id] = data->labels_minerals[id];
data->nu_mineral.row(new_id) = data->nu_mineral.row(id);
data->_molar_volume_mineral(new_id) = data->_molar_volume_mineral(id);
++new_id;
}
}
assert(new_id == nb_to_keep); // simple test to assure that everything is ok
assert(new_id_kin == nb_new_min_kin);
// Finally we shrink the containers for the mineral at equilibrium
data->logk_mineral.conservativeResize(nb_to_keep);
data->nu_mineral.conservativeResize(nb_to_keep, Eigen::NoChange);
data->labels_minerals.resize(nb_to_keep);
data->_molar_volume_mineral.conservativeResize(nb_to_keep);
data->nb_mineral = nb_to_keep;
data->nb_mineral_kinetic = nb_new_min_kin;
}
void MineralSelector::keep_only(const std::vector<std::string>& minerals_to_keep)
{
std::vector<int> ids(minerals_to_keep.size());
for (unsigned int min=0; min<minerals_to_keep.size(); ++min)
{
int id = mineral_label_to_id(minerals_to_keep[min]);
if (id == no_species)
{
throw std::invalid_argument("Unknown species : '"+minerals_to_keep[min]+"'.");
}
ids[min] = id;
}
keep_only(ids);
}
} // end namespace database
} // end namespace specmicp
Event Timeline
Log In to Comment