-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSource.cpp
More file actions
77 lines (58 loc) · 2.4 KB
/
Copy pathSource.cpp
File metadata and controls
77 lines (58 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by Raffaele Montella on 07/12/20.
//
#include "Source.hpp"
#include <random>
Source::Source(string id, double k, double j, double i, double start, double end, int particlesPerHour, int mode):
id(id),k(k),j(j),i(i),start(start),end(end),particlesPerHour(particlesPerHour),mode(mode) {
logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("WaComM"));
}
Source::~Source() = default;
void Source::emit(const std::shared_ptr<Config>& config, std::shared_ptr<Particles> particles, double currentOceanTime) {
// Create a random number generator
std::default_random_engine generator;
// Create a distribution probability with mean=0 and stddev=0.25
std::normal_distribution<double> distribution(0.0,0.25);
// Check if the source is active
if (mode>0) {
unsigned long id=0;
if (particles->size()>0) {
id = particles->at(particles->size() - 1).Id() + 1;
}
// Check if the particle have to be released
if ((mode == 1) && (start<0 || start <= currentOceanTime) && (end<0 || end >= currentOceanTime) ) {
// Release the particles
for (int idx = 0; idx < particlesPerHour; idx++) {
double kk = k;
double jj = j;
double ii = i;
if (config->RandomSources()) {
kk = k + distribution(generator);
jj = j + distribution(generator);
ii = i + distribution(generator);
}
particles->push_back(Particle(id, kk, jj, ii, currentOceanTime));
id++;
}
}
}
}
Source::Source() {
logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("WaComM"));
}
void Source::Id(string value) { id = value; }
void Source::K(double value) { k = value; }
void Source::J(double value) { j = value; }
void Source::I(double value) { i = value; }
void Source::Start(double value) { start = value; }
void Source::End(double value) { end = value; }
void Source::ParticlesPerHour(int value) { particlesPerHour = value; }
void Source::Mode(int value) { mode = value; }
string Source::Id() { return id; }
double Source::K() { return k; }
double Source::J() { return j; }
double Source::I() { return i; }
double Source::Start() { return start; }
double Source::End() { return end; }
int Source::ParticlesPerHour() { return particlesPerHour; }
int Source::Mode() { return mode; }