1 | #ifndef __GEOWORLD_MINERALDATABASE_TYPES_H__
|
---|
2 | #define __GEOWORLD_MINERALDATABASE_TYPES_H__
|
---|
3 |
|
---|
4 | #include <bitset>
|
---|
5 | #include <string>
|
---|
6 | #include <vector>
|
---|
7 | #include <list>
|
---|
8 | #include <set>
|
---|
9 |
|
---|
10 | #include <mars_ptr.h>
|
---|
11 | #include <mars_platform.h>
|
---|
12 |
|
---|
13 | #include "chemelem.h"
|
---|
14 |
|
---|
15 | namespace geoworld
|
---|
16 | {
|
---|
17 | enum PointScale
|
---|
18 | {
|
---|
19 | PtSc_NA = 0,
|
---|
20 | PtSc_VeryLow = 1,
|
---|
21 | PtSc_Low = 2,
|
---|
22 | PtSc_Moderate = 3,
|
---|
23 | PtSc_High = 4,
|
---|
24 | PtSc_VeryHigh = 5,
|
---|
25 |
|
---|
26 | CountPtSc = 6
|
---|
27 | };
|
---|
28 | static_assert( CountPtSc == 6, "CountPtSc does not match safety catch, did you forget to update something?" );
|
---|
29 |
|
---|
30 | enum Silica
|
---|
31 | {
|
---|
32 | Silica_NA = 0,
|
---|
33 | Silica_Felsic = 5,
|
---|
34 | Silica_InterFelsic = 4,
|
---|
35 | Silica_Intermediate = 3,
|
---|
36 | Silica_Mafic = 2,
|
---|
37 | Silica_UltraMafic = 1,
|
---|
38 |
|
---|
39 | CountSilica = 6
|
---|
40 | };
|
---|
41 | static_assert( CountSilica == 6, "CountSilica does not match safety catch, did you forget to update something?" );
|
---|
42 |
|
---|
43 | enum Origin
|
---|
44 | {
|
---|
45 | Origin_NA,
|
---|
46 | Origin_Volcanic,
|
---|
47 | Origin_Subvolcanic,
|
---|
48 | Origin_Plutonic,
|
---|
49 | Origin_Meteoritic
|
---|
50 | };
|
---|
51 |
|
---|
52 | enum Sediment
|
---|
53 | {
|
---|
54 | Sediment_NA = 0,
|
---|
55 | Sediment_Evaporite = 1,
|
---|
56 | Sediment_Clay = 2,
|
---|
57 | Sediment_SiltyClay = 3,
|
---|
58 | Sediment_Silt = 4,
|
---|
59 | Sediment_SandySilt = 5,
|
---|
60 | Sediment_Sand = 6,
|
---|
61 | Sediment_Gravel = 7,
|
---|
62 |
|
---|
63 | Sediment_COUNT = 8
|
---|
64 | };
|
---|
65 | static_assert( Sediment_COUNT == 8, "Sediment_COUNT does not match safety catch, did you forget to update something?" );
|
---|
66 |
|
---|
67 | enum DepositDistribution
|
---|
68 | {
|
---|
69 | Dist_NA = 0,
|
---|
70 | Dist_Cluster = 1,
|
---|
71 | Dist_Vein = 2,
|
---|
72 | Dist_Sill = 3,
|
---|
73 | Dist_Dike = 4,
|
---|
74 | Dist_Layer = 5,
|
---|
75 | Dist_Laccolith = 6,
|
---|
76 |
|
---|
77 | CountDist = 7
|
---|
78 | };
|
---|
79 | typedef std::bitset< CountDist > DepositDistributionFlags;
|
---|
80 | static_assert( CountDist == 7, "CountDist does not match safety catch, did you forget to update something?" ); // Safety-catch, ensure that CountDist always accurately reflects DepositDistribution flags
|
---|
81 |
|
---|
82 | class MineralDef;
|
---|
83 | typedef mars::WeakReference< MineralDef > MineralPtr;
|
---|
84 |
|
---|
85 | class MineralFormula : private ChemicalFormulaParser::IQuantityCallback
|
---|
86 | {
|
---|
87 | public:
|
---|
88 | class ElementQuantity
|
---|
89 | {
|
---|
90 | public:
|
---|
91 | const AtomicNumber number;
|
---|
92 | const float amount;
|
---|
93 |
|
---|
94 | inline ElementQuantity (AtomicNumber number, const float amount)
|
---|
95 | : number (number), amount (amount) {}
|
---|
96 | inline ElementQuantity (const ElementQuantity & copy)
|
---|
97 | : number(copy.number), amount(copy.amount) {}
|
---|
98 | };
|
---|
99 |
|
---|
100 | private:
|
---|
101 | std::list <ElementQuantity> _chemicals;
|
---|
102 |
|
---|
103 | inline void setChemicalQuantity (const AtomicNumber atom, const float amt)
|
---|
104 | { _chemicals.push_back (ElementQuantity(atom, amt)); }
|
---|
105 |
|
---|
106 | public:
|
---|
107 | MineralFormula (const std::string & formula)
|
---|
108 | {
|
---|
109 | ChemicalFormulaParser fpars(formula);
|
---|
110 | fpars.quantities (this);
|
---|
111 | }
|
---|
112 | MineralFormula (const MineralFormula & copy)
|
---|
113 | : _chemicals (copy._chemicals) {}
|
---|
114 |
|
---|
115 | inline MineralFormula & operator = (const MineralFormula & copy)
|
---|
116 | {
|
---|
117 | _chemicals.clear();
|
---|
118 | _chemicals.insert(_chemicals.begin(), copy._chemicals.cbegin(), copy._chemicals.cend());
|
---|
119 | return *this;
|
---|
120 | }
|
---|
121 | };
|
---|
122 |
|
---|
123 | class MineralClass
|
---|
124 | {
|
---|
125 | public:
|
---|
126 | class Disposition
|
---|
127 | {
|
---|
128 | public:
|
---|
129 | typedef std::bitset <Sediment_COUNT> SedimentSet;
|
---|
130 |
|
---|
131 | Origin origin;
|
---|
132 | PointScale temperature, pressure, weathered;
|
---|
133 | union {
|
---|
134 | Silica base;
|
---|
135 | PointScale numeric;
|
---|
136 | } silica;
|
---|
137 |
|
---|
138 | SedimentSet sediment;
|
---|
139 |
|
---|
140 | inline Disposition ()
|
---|
141 | : origin(Origin_NA), temperature(PtSc_NA), pressure(PtSc_NA), weathered(PtSc_NA)
|
---|
142 | {
|
---|
143 | silica.base = Silica_NA;
|
---|
144 | }
|
---|
145 | };
|
---|
146 |
|
---|
147 | enum Type
|
---|
148 | {
|
---|
149 | Type_NA = 0,
|
---|
150 | Type_Sedimentary = 1,
|
---|
151 | Type_Igneous = 2
|
---|
152 | };
|
---|
153 |
|
---|
154 | typedef std::list <Disposition> DispositionList;
|
---|
155 |
|
---|
156 | std::string name;
|
---|
157 | DispositionList dispositions;
|
---|
158 | Type type;
|
---|
159 |
|
---|
160 | inline MineralClass ()
|
---|
161 | : type(Type_NA) {}
|
---|
162 |
|
---|
163 | // Used by WeakReference< T >
|
---|
164 | inline bool operator == (const MineralClass & other) const
|
---|
165 | { return name == other.name; }
|
---|
166 | // Used by WeakReference< T >
|
---|
167 | inline bool operator == (const std::string & sName) const
|
---|
168 | { return name == sName; }
|
---|
169 | // Used by WeakReference< T >
|
---|
170 | inline operator const std::string & () const
|
---|
171 | { return name; }
|
---|
172 | };
|
---|
173 | typedef mars::WeakReference< MineralClass > MinClassPtr;
|
---|
174 | typedef std::list< MinClassPtr > MinClassReferenceList;
|
---|
175 |
|
---|
176 | class MineralDeposit
|
---|
177 | {
|
---|
178 | public:
|
---|
179 | MineralPtr mineral;
|
---|
180 | DepositDistribution distribution;
|
---|
181 |
|
---|
182 | MineralDeposit ()
|
---|
183 | : distribution(Dist_NA) {}
|
---|
184 |
|
---|
185 | MineralDeposit (const MineralPtr & pMin, const DepositDistribution enddDistribution)
|
---|
186 | : mineral(pMin), distribution(enddDistribution) {}
|
---|
187 |
|
---|
188 | inline operator bool () const { return !mineral.isNull(); }
|
---|
189 | inline bool operator ! () const { return mineral.isNull(); }
|
---|
190 |
|
---|
191 | inline bool operator == (const MineralDeposit & other) const
|
---|
192 | { return mineral == other.mineral && distribution == other.distribution; }
|
---|
193 | };
|
---|
194 |
|
---|
195 | class MineralReference
|
---|
196 | {
|
---|
197 | public:
|
---|
198 | MineralPtr mineral;
|
---|
199 | DepositDistributionFlags distributions;
|
---|
200 |
|
---|
201 | inline operator bool () const { return !mineral.isNull(); }
|
---|
202 | inline bool operator ! () const { return mineral.isNull(); }
|
---|
203 | inline bool operator & (const MineralDeposit & deposit) const
|
---|
204 | { return *this && deposit && mineral == deposit.mineral && distributions[deposit.distribution]; }
|
---|
205 |
|
---|
206 | inline bool operator == (const MineralReference & other) const
|
---|
207 | {
|
---|
208 | return mineral == other.mineral && distributions == other.distributions;
|
---|
209 | }
|
---|
210 | inline bool operator < (const MineralReference & other) const
|
---|
211 | {
|
---|
212 | return mineral < other.mineral || (mineral == other.mineral && distributions.to_ulong() < other.distributions.to_ulong());
|
---|
213 | }
|
---|
214 | };
|
---|
215 |
|
---|
216 | typedef std::list< MineralReference > MineralReferenceList;
|
---|
217 | typedef std::list< MineralDeposit > MineralDepositList;
|
---|
218 |
|
---|
219 | class PetrogenyDef
|
---|
220 | {
|
---|
221 | private:
|
---|
222 | static bool intersection (const MineralReferenceList & lstSubject, const MineralDepositList & lstObject);
|
---|
223 | static bool intersection (const MinClassReferenceList & lstSubject, const MinClassPtr & pMinClassObject);
|
---|
224 |
|
---|
225 | public:
|
---|
226 | DepositDistributionFlags distributions;
|
---|
227 | PointScale abundance, size;
|
---|
228 | MineralReferenceList associations, protolith;
|
---|
229 | MineralReference host;
|
---|
230 | MinClassReferenceList environments;
|
---|
231 |
|
---|
232 | inline PetrogenyDef ()
|
---|
233 | : abundance (PtSc_Moderate), size(PtSc_Moderate) {}
|
---|
234 |
|
---|
235 | inline bool satisfies (const MineralDepositList & lstNeighborhood, const MineralDepositList & lstPrecursors, const MineralDeposit & oMinDeposit, const MinClassPtr & pEnvironment) const
|
---|
236 | {
|
---|
237 | return
|
---|
238 | (associations.empty() || intersection(associations, lstNeighborhood)) &&
|
---|
239 | (protolith.empty() || intersection(protolith, lstPrecursors)) &&
|
---|
240 | (!host || host & oMinDeposit) &&
|
---|
241 | (environments.empty() || intersection(environments, pEnvironment));
|
---|
242 | }
|
---|
243 | };
|
---|
244 |
|
---|
245 | class MineralGroupDef
|
---|
246 | {
|
---|
247 | public:
|
---|
248 | typedef std::list< MineralPtr > MineralList;
|
---|
249 |
|
---|
250 | std::string name;
|
---|
251 | MineralList members;
|
---|
252 | };
|
---|
253 |
|
---|
254 | // TODO: Link world sphere packs to MineralDef instances, right now this is done by a mineral name string
|
---|
255 | class MineralDef
|
---|
256 | {
|
---|
257 | public:
|
---|
258 | typedef std::list <PetrogenyDef> GenesisList;
|
---|
259 |
|
---|
260 | class YieldMin
|
---|
261 | {
|
---|
262 | private:
|
---|
263 | MineralFormula _mineral;
|
---|
264 | float _percentage;
|
---|
265 | float _flux;
|
---|
266 |
|
---|
267 | public:
|
---|
268 | const MineralFormula & mineral;
|
---|
269 | const float & percentage;
|
---|
270 | const float & flux;
|
---|
271 |
|
---|
272 | inline YieldMin (const MineralFormula & mineral, float percentage, float flux)
|
---|
273 | : _mineral(mineral), _percentage(percentage), _flux(flux),
|
---|
274 | mineral(_mineral), percentage(_percentage), flux(_flux)
|
---|
275 | {}
|
---|
276 | inline YieldMin (const MineralFormula & mineral)
|
---|
277 | : _mineral(mineral), _percentage(1.0), _flux(0.0),
|
---|
278 | mineral(_mineral), percentage(_percentage), flux(_flux) {}
|
---|
279 | inline YieldMin (const YieldMin & copy)
|
---|
280 | : _mineral(copy._mineral), _percentage(copy._percentage), _flux(copy._flux),
|
---|
281 | mineral(_mineral), percentage(_percentage), flux(_flux) {}
|
---|
282 |
|
---|
283 | inline YieldMin & operator = (const YieldMin & copy)
|
---|
284 | {
|
---|
285 | this->_mineral = copy._mineral;
|
---|
286 | this->_percentage = copy._percentage;
|
---|
287 | this->_flux = copy._flux;
|
---|
288 | return *this;
|
---|
289 | }
|
---|
290 | };
|
---|
291 | class YieldSet
|
---|
292 | {
|
---|
293 | private:
|
---|
294 | std::vector <YieldMin> _yields;
|
---|
295 |
|
---|
296 | public:
|
---|
297 | inline void add(const YieldMin & y) { _yields.push_back(y); }
|
---|
298 | };
|
---|
299 |
|
---|
300 | float
|
---|
301 | melting_point,
|
---|
302 | boiling_point,
|
---|
303 | density;
|
---|
304 | PhasePoint triple_point, critical_point, sublimation_point;
|
---|
305 | std::vector <YieldSet> yields;
|
---|
306 | std::string
|
---|
307 | name;
|
---|
308 |
|
---|
309 | MinClassPtr clazz;
|
---|
310 |
|
---|
311 | GenesisList genesis;
|
---|
312 |
|
---|
313 | // Pass in a number of factors and see if all of them satisfy at least one set of petrogeny conditions
|
---|
314 | template< typename L >
|
---|
315 | void intersectGeneses (L & lstGeneses, const MineralDepositList & lstNeighborhood, const MineralDepositList & lstPrecursors, const MineralDeposit & oMinDeposit, const MinClassPtr & pEnvironment, PetrogenyDef = **L().begin()) const
|
---|
316 | {
|
---|
317 | for (GenesisList::const_iterator i = genesis.begin(); i != genesis.end(); ++i)
|
---|
318 | if (i->satisfies(lstNeighborhood, lstPrecursors, oMinDeposit, pEnvironment))
|
---|
319 | lstGeneses.push_back(i);
|
---|
320 | }
|
---|
321 |
|
---|
322 | // Used by WeakReference< T >
|
---|
323 | inline bool operator == (const MineralDef & other) const
|
---|
324 | { return name == other.name; }
|
---|
325 | // Used by WeakReference< T >
|
---|
326 | inline bool operator == (const std::string & sName) const
|
---|
327 | { return name == sName; }
|
---|
328 | // Used by WeakReference< T >
|
---|
329 | inline operator const std::string & () const
|
---|
330 | { return name; }
|
---|
331 | };
|
---|
332 |
|
---|
333 | class IMineralsDatabase
|
---|
334 | {
|
---|
335 | public:
|
---|
336 | virtual mars::ptr< MineralDef > addMineral (const mars::ptr< MineralDef > & ptr) = 0;
|
---|
337 | virtual mars::ptr< MineralClass > addClass (const mars::ptr< MineralClass > & ptr) = 0;
|
---|
338 | virtual mars::ptr< MineralGroupDef > addGroup (const mars::ptr< MineralGroupDef > & ptr) = 0;
|
---|
339 | };
|
---|
340 |
|
---|
341 | class IMineralsDBReader
|
---|
342 | {
|
---|
343 | public:
|
---|
344 | virtual bool load (IMineralsDatabase * pMinDB) = 0;
|
---|
345 | };
|
---|
346 | }
|
---|
347 |
|
---|
348 | #endif
|
---|