Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91000606
module.hpp
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, Nov 6, 19:41
Size
4 KB
Mime Type
text/x-c++
Expires
Fri, Nov 8, 19:41 (2 d)
Engine
blob
Format
Raw Data
Handle
22177399
Attached To
rSPECMICP SpecMiCP / ReactMiCP
module.hpp
View Options
/*-------------------------------------------------------
- Module : database
- File : module
- 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.
---------------------------------------------------------*/
#ifndef SPECMICP_DATAABASE_MODULE_HPP
#define SPECMICP_DATAABASE_MODULE_HPP
//! \file module.hpp base class for a database module
#include "data_container.hpp"
namespace
specmicp
{
namespace
database
{
//! \brief Base class for a database module
class
DatabaseModule
{
public
:
//! Create a blank database
DatabaseModule
()
{
reset_database
();
}
//! Use the database thedata
DatabaseModule
(
RawDatabasePtr
thedata
)
:
data
(
thedata
)
{}
//! \brief set the database
void
set_database
(
RawDatabasePtr
thedata
)
{
data
=
thedata
;}
//! \brief (Re)set the database - create a blank database
void
reset_database
()
{
data
=
std
::
make_shared
<
DataContainer
>
();}
//! \brief Return true if the database is canonical
bool
is_database_canonical
()
{
return
data
->
is_canonical
;}
//! \brief Return the id of species "label" in list_labels
//!
//! return no_species if the species cannot be found in the database
static
index_t
label_to_id
(
const
std
::
string
&
label
,
const
std
::
vector
<
std
::
string
>&
list_labels
)
{
auto
search
=
std
::
find
(
list_labels
.
begin
(),
list_labels
.
end
(),
label
);
if
(
search
==
list_labels
.
end
())
return
no_species
;
else
return
(
search
-
list_labels
.
begin
());
}
//! \brief Return the id of species "label" in list_labels
//!
//! Throw std::invalid_argument if the species cannot be found in the list
static
index_t
safe_label_to_id
(
const
std
::
string
&
label
,
const
std
::
vector
<
std
::
string
>&
list_labels
)
{
auto
search
=
std
::
find
(
list_labels
.
begin
(),
list_labels
.
end
(),
label
);
if
(
search
==
list_labels
.
end
())
throw
std
::
invalid_argument
(
"Unknown species : '"
+
label
+
"'."
);
else
return
(
search
-
list_labels
.
begin
());
}
//! \brief Return the id of the mineral "label"
//!
//! Return no_species if label is not a mineral (at equilibrium)
index_t
mineral_label_to_id
(
const
std
::
string
&
label
)
{
return
label_to_id
(
label
,
data
->
labels_minerals
);
}
//! \brief Return the id of the mineral "label"
//!
//! Return no_species if label is not a mineral (at equilibrium)
index_t
mineral_kinetic_label_to_id
(
const
std
::
string
&
label
)
{
return
label_to_id
(
label
,
data
->
labels_minerals_kinetic
);
}
//! \brief Return the id of the component "label"
//!
//! Return no_species if "label" is not a component
index_t
component_label_to_id
(
const
std
::
string
&
label
)
{
return
label_to_id
(
label
,
data
->
labels_basis
);
}
//! \brief Return the id of the secondary aqueous species "label"
//!
//! Return no_species if "label" is not an aqueous species.
//! A component (of the basis) is not considered as a secondary aqueous species.
index_t
aqueous_label_to_id
(
const
std
::
string
&
label
)
{
return
label_to_id
(
label
,
data
->
labels_aqueous
);
}
//! \brief Return the id of the gas "label"
//!
//! Return no_species if "label" is not a gas
index_t
gas_label_to_id
(
const
std
::
string
&
label
)
{
return
label_to_id
(
label
,
data
->
labels_gas
);
}
protected
:
RawDatabasePtr
data
;
//! The database
};
}
// end namespace database
}
// end namespace specmicp
#endif
// SPECMICP_DATAABASE_MODULE_HPP
Event Timeline
Log In to Comment