Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92562724
database.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
Thu, Nov 21, 12:20
Size
4 KB
Mime Type
text/x-c
Expires
Sat, Nov 23, 12:20 (1 d, 11 h)
Engine
blob
Format
Raw Data
Handle
22440714
Attached To
rSPECMICP SpecMiCP / ReactMiCP
database.cpp
View Options
/*-------------------------------------------------------
- Module : database
- File : database.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 "database.hpp"
#include <iostream>
#include "selector.hpp"
#include "canonicalizer.hpp"
#include "switch_basis.hpp"
#include "mineral_selector.hpp"
#include "reader.hpp"
namespace specmicp {
namespace database {
void Database::make_canonical()
{
canonicalize_database(data);
}
void Database::change_basis(std::vector<index_t>& new_basis)
{
BasisSwitcher(data).change_basis(new_basis);
}
// this is a proxy to a DatabaseSelector
void Database::remove_components(const std::vector<index_t>& id_components_to_remove)
{
DatabaseSelector selector(data);
selector.remove_component(id_components_to_remove);
}
// this is a proxy to a DatabaseSelector
void Database::keep_only_components(const std::vector<index_t>& id_components_to_keep)
{
DatabaseSelector selector(data);
selector.keep_only_component(id_components_to_keep);
}
void Database::minerals_keep_only(const std::vector<std::string>& minerals_to_keep)
{
MineralSelector(data).keep_only(minerals_to_keep);
}
void Database::swap_components(std::map<std::string, std::string>& swap_to_make)
{
std::vector<index_t> id_swap;
id_swap.reserve(data->nb_component);
for (index_t i: data->range_component())
{
id_swap.push_back(i);
}
for (auto it=swap_to_make.begin(); it!=swap_to_make.end(); ++it)
{
if (it->first == "H2O") {
throw std::invalid_argument("Basis switch : water cannot be swapped from basis");
}
const index_t idc = safe_label_to_id(it->first, data->labels_basis);
const index_t idaq = data->nb_component + label_to_id(it->second, data->labels_aqueous);
id_swap[idc] = idaq;
}
change_basis(id_swap);
}
void Database::parse_database(std::string filepath)
{
DataReader reader(filepath);
reader.parse();
set_database(reader.get_database());
}
void Database::keep_only_components(const std::vector<std::string>& labels_components_to_keep)
{
std::vector<index_t> id_components_to_keep;
id_components_to_keep.reserve(labels_components_to_keep.size());
for (auto it=labels_components_to_keep.begin(); it!=labels_components_to_keep.end(); ++it)
{
id_components_to_keep.push_back(safe_label_to_id(*it, data->labels_basis));
}
keep_only_components(id_components_to_keep);
}
void Database::remove_gas_phases()
{
DatabaseSelector(data).remove_all_gas();
}
} // end namespace database
} // end namespace specmicp
Event Timeline
Log In to Comment