Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78584842
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
Wed, Aug 21, 19:20
Size
4 KB
Mime Type
text/x-c
Expires
Fri, Aug 23, 19:20 (2 d)
Engine
blob
Format
Raw Data
Handle
20067602
Attached To
rSPECMICP SpecMiCP / ReactMiCP
mineral_selector.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : mineral_selector.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 "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