Skip to content

Commit fa19de9

Browse files
Merge pull request #64 from ManuelLerchner/51-sheet-3-task-4-simulation-of-a-falling-drop-wall
51 sheet 3 task 4 simulation of a falling drop wall
2 parents 1f3df26 + acf23b7 commit fa19de9

15 files changed

+201
-30
lines changed

input/body_collision.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<video_length>30</video_length>
99
<delta_t>0.00005</delta_t>
1010
<end_time>20.0</end_time>
11+
<third_dimension>true</third_dimension>
1112
<particle_container>
1213
<linkedcells_container>
1314
<domain_size>
@@ -18,7 +19,7 @@
1819
<cutoff_radius>10</cutoff_radius>
1920
<boundary_conditions>
2021
<left>
21-
<outflow />
22+
<reflective />
2223
</left>
2324
<right>
2425
<reflective />
@@ -30,7 +31,7 @@
3031
<reflective />
3132
</top>
3233
<back>
33-
<outflow />
34+
<reflective />
3435
</back>
3536
<front>
3637
<reflective />
@@ -57,8 +58,8 @@
5758
<mass>1</mass>
5859
<velocity>
5960
<x>10.0</x>
60-
<y>10.0</y>
61-
<z>10.0</z>
61+
<y>0.0</y>
62+
<z>0.0</z>
6263
</velocity>
6364
<type>0</type>
6465
</cuboid_spawner>

input/body_collision_assignment3.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<video_length>30</video_length>
99
<delta_t>0.0005</delta_t>
1010
<end_time>20.0</end_time>
11+
<third_dimension>false</third_dimension>
1112
<particle_container>
1213
<linkedcells_container>
1314
<domain_size>

input/falling_drop_assignment3.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0"?>
2+
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="simulation_schema.xsd">
4+
5+
<settings>
6+
<fps>24</fps>
7+
<video_length>30</video_length>
8+
<delta_t>0.00005</delta_t>
9+
<end_time>10.0</end_time>
10+
<third_dimension>false</third_dimension>
11+
<particle_container>
12+
<linkedcells_container>
13+
<domain_size>
14+
<x>120</x>
15+
<y>50</y>
16+
<z>1</z>
17+
</domain_size>
18+
<cutoff_radius>3.0</cutoff_radius>
19+
<boundary_conditions>
20+
<left>
21+
<reflective />
22+
</left>
23+
<right>
24+
<reflective />
25+
</right>
26+
<bottom>
27+
<reflective />
28+
</bottom>
29+
<top>
30+
<reflective />
31+
</top>
32+
<back>
33+
<reflective />
34+
</back>
35+
<front>
36+
<reflective />
37+
</front>
38+
</boundary_conditions>
39+
</linkedcells_container>
40+
</particle_container>
41+
</settings>
42+
43+
<particles>
44+
<sphere_spawner>
45+
<center>
46+
<x>60.0</x>
47+
<y>25.0</y>
48+
<z>0.5</z>
49+
</center>
50+
<radius>15</radius>
51+
<grid_spacing>1.1225</grid_spacing>
52+
<temperature>0.1</temperature>
53+
<mass>1.0</mass>
54+
<velocity>
55+
<x>0.0</x>
56+
<y>-10.0</y>
57+
<z>0.0</z>
58+
</velocity>
59+
<type>0</type>
60+
</sphere_spawner>
61+
62+
</particles>
63+
64+
</configuration>

src/io/input/xml/XMLFileReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ SimulationParams XMLFileReader::readFile(const std::string& filepath, std::uniqu
2929

3030
// Spawn particles specified in the XML file
3131
for (auto xsd_cuboid : particles.cuboid_spawner()) {
32-
auto spawner = XSDTypeAdapter::convertToCuboidSpawner(xsd_cuboid);
32+
auto spawner = XSDTypeAdapter::convertToCuboidSpawner(xsd_cuboid, settings.third_dimension());
3333
particle_container->reserve(particle_container->size() + spawner.getEstimatedNumberOfParticles());
3434
spawner.spawnParticles(particle_container);
3535
}
3636

3737
for (auto xsd_sphere : particles.sphere_spawner()) {
38-
auto spawner = XSDTypeAdapter::convertToSphereSpawner(xsd_sphere);
38+
auto spawner = XSDTypeAdapter::convertToSphereSpawner(xsd_sphere, settings.third_dimension());
3939
particle_container->reserve(particle_container->size() + spawner.getEstimatedNumberOfParticles());
4040
spawner.spawnParticles(particle_container);
4141
}
4242

4343
for (auto xsd_particle : particles.single_particle()) {
44-
auto particle = XSDTypeAdapter::convertToParticle(xsd_particle);
44+
auto particle = XSDTypeAdapter::convertToParticle(xsd_particle, settings.third_dimension());
4545
particle_container->addParticle(particle);
4646
}
4747

src/io/input/xml/parser/XSDTypeAdapter.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "utils/ArrayUtils.h"
77
#include "utils/MaxwellBoltzmannDistribution.h"
88

9-
CuboidSpawner XSDTypeAdapter::convertToCuboidSpawner(const particles::cuboid_spawner_type& cuboid) {
9+
CuboidSpawner XSDTypeAdapter::convertToCuboidSpawner(const particles::cuboid_spawner_type& cuboid, bool third_dimension) {
1010
auto lower_left_front_corner = convertToVector(cuboid.lower_left_front_corner());
1111
auto grid_dimensions = convertToVector(cuboid.grid_dim());
1212
auto initial_velocity = convertToVector(cuboid.velocity());
@@ -21,6 +21,11 @@ CuboidSpawner XSDTypeAdapter::convertToCuboidSpawner(const particles::cuboid_spa
2121
exit(-1);
2222
}
2323

24+
if (!third_dimension && grid_dimensions[2] > 1) {
25+
Logger::logger->error("Cuboid grid dimensions must be 1 in z direction if third dimension is disabled");
26+
exit(-1);
27+
}
28+
2429
if (grid_spacing <= 0) {
2530
Logger::logger->error("Cuboid grid spacing must be positive");
2631
exit(-1);
@@ -36,11 +41,11 @@ CuboidSpawner XSDTypeAdapter::convertToCuboidSpawner(const particles::cuboid_spa
3641
exit(-1);
3742
}
3843

39-
return CuboidSpawner{lower_left_front_corner, grid_dimensions, grid_spacing, mass,
40-
initial_velocity, static_cast<int>(type), temperature};
44+
return CuboidSpawner{lower_left_front_corner, grid_dimensions, grid_spacing, mass,
45+
initial_velocity, static_cast<int>(type), third_dimension, temperature};
4146
}
4247

43-
SphereSpawner XSDTypeAdapter::convertToSphereSpawner(const particles::sphere_spawner_type& sphere) {
48+
SphereSpawner XSDTypeAdapter::convertToSphereSpawner(const particles::sphere_spawner_type& sphere, bool third_dimension) {
4449
auto center = convertToVector(sphere.center());
4550
auto initial_velocity = convertToVector(sphere.velocity());
4651

@@ -70,12 +75,14 @@ SphereSpawner XSDTypeAdapter::convertToSphereSpawner(const particles::sphere_spa
7075
exit(-1);
7176
}
7277

73-
return SphereSpawner{center, static_cast<int>(radius), grid_spacing, mass, initial_velocity, static_cast<int>(type), temperature};
78+
return SphereSpawner{center, static_cast<int>(radius), grid_spacing, mass,
79+
initial_velocity, static_cast<int>(type), third_dimension, temperature};
7480
}
7581

76-
Particle XSDTypeAdapter::convertToParticle(const particles::single_particle_type& particle) {
82+
Particle XSDTypeAdapter::convertToParticle(const particles::single_particle_type& particle, bool third_dimension) {
7783
auto position = convertToVector(particle.position());
78-
auto initial_velocity = convertToVector(particle.velocity()) + maxwellBoltzmannDistributedVelocity(particle.temperature(), 2);
84+
auto initial_velocity =
85+
convertToVector(particle.velocity()) + maxwellBoltzmannDistributedVelocity(particle.temperature(), third_dimension ? 3 : 2);
7986

8087
auto mass = particle.mass();
8188
auto type = particle.type();

src/io/input/xml/parser/XSDTypeAdapter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,28 @@ class XSDTypeAdapter {
1717
* @brief Converts a cuboid from the XSD format to the internal format
1818
*
1919
* @param cuboid Cuboid in the XSD format
20+
* @param third_dimension Whether the third dimension is enabled
2021
* @return CuboidSpawner parsed from the given cuboid in the XSD format
2122
*/
22-
static CuboidSpawner convertToCuboidSpawner(const particles::cuboid_spawner_type& cuboid);
23+
static CuboidSpawner convertToCuboidSpawner(const particles::cuboid_spawner_type& cuboid, bool third_dimension);
2324

2425
/**
2526
* @brief Converts a sphere from the XSD format to the internal format
2627
*
2728
* @param sphere Sphere in the XSD format
29+
* @param third_dimension Whether the third dimension is enabled
2830
* @return SphereSpawner parsed from the given sphere in the XSD format
2931
*/
30-
static SphereSpawner convertToSphereSpawner(const particles::sphere_spawner_type& sphere);
32+
static SphereSpawner convertToSphereSpawner(const particles::sphere_spawner_type& sphere, bool third_dimension);
3133

3234
/**
3335
* @brief Converts a particle from the XSD format to the internal format
3436
*
3537
* @param particle Particle in the XSD format
38+
* @param third_dimension Whether the third dimension is enabled
3639
* @return Particle parsed from the given particle in the XSD format
3740
*/
38-
static Particle convertToParticle(const particles::single_particle_type& particle);
41+
static Particle convertToParticle(const particles::single_particle_type& particle, bool third_dimension);
3942

4043
/**
4144
* @brief Converts a container type from the XSD format to the internal format

src/io/input/xml/parser/simulation_schema.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ settings::end_time_type& settings::end_time() { return this->end_time_.get(); }
418418

419419
void settings::end_time(const end_time_type& x) { this->end_time_.set(x); }
420420

421+
const settings::third_dimension_type& settings::third_dimension() const { return this->third_dimension_.get(); }
422+
423+
settings::third_dimension_type& settings::third_dimension() { return this->third_dimension_.get(); }
424+
425+
void settings::third_dimension(const third_dimension_type& x) { this->third_dimension_.set(x); }
426+
421427
const settings::particle_container_type& settings::particle_container() const { return this->particle_container_.get(); }
422428

423429
settings::particle_container_type& settings::particle_container() { return this->particle_container_.get(); }
@@ -1647,21 +1653,23 @@ configuration::~configuration() {}
16471653
//
16481654

16491655
settings::settings(const fps_type& fps, const video_length_type& video_length, const delta_t_type& delta_t, const end_time_type& end_time,
1650-
const particle_container_type& particle_container)
1656+
const third_dimension_type& third_dimension, const particle_container_type& particle_container)
16511657
: ::xml_schema::type(),
16521658
fps_(fps, this),
16531659
video_length_(video_length, this),
16541660
delta_t_(delta_t, this),
16551661
end_time_(end_time, this),
1662+
third_dimension_(third_dimension, this),
16561663
particle_container_(particle_container, this) {}
16571664

16581665
settings::settings(const fps_type& fps, const video_length_type& video_length, const delta_t_type& delta_t, const end_time_type& end_time,
1659-
::std::unique_ptr<particle_container_type> particle_container)
1666+
const third_dimension_type& third_dimension, ::std::unique_ptr<particle_container_type> particle_container)
16601667
: ::xml_schema::type(),
16611668
fps_(fps, this),
16621669
video_length_(video_length, this),
16631670
delta_t_(delta_t, this),
16641671
end_time_(end_time, this),
1672+
third_dimension_(third_dimension, this),
16651673
particle_container_(std::move(particle_container), this) {}
16661674

16671675
settings::settings(const settings& x, ::xml_schema::flags f, ::xml_schema::container* c)
@@ -1670,6 +1678,7 @@ settings::settings(const settings& x, ::xml_schema::flags f, ::xml_schema::conta
16701678
video_length_(x.video_length_, f, this),
16711679
delta_t_(x.delta_t_, f, this),
16721680
end_time_(x.end_time_, f, this),
1681+
third_dimension_(x.third_dimension_, f, this),
16731682
particle_container_(x.particle_container_, f, this) {}
16741683

16751684
settings::settings(const ::xercesc::DOMElement& e, ::xml_schema::flags f, ::xml_schema::container* c)
@@ -1678,6 +1687,7 @@ settings::settings(const ::xercesc::DOMElement& e, ::xml_schema::flags f, ::xml_
16781687
video_length_(this),
16791688
delta_t_(this),
16801689
end_time_(this),
1690+
third_dimension_(this),
16811691
particle_container_(this) {
16821692
if ((f & ::xml_schema::flags::base) == 0) {
16831693
::xsd::cxx::xml::dom::parser<char> p(e, true, false, false);
@@ -1726,6 +1736,15 @@ void settings::parse(::xsd::cxx::xml::dom::parser<char>& p, ::xml_schema::flags
17261736
}
17271737
}
17281738

1739+
// third_dimension
1740+
//
1741+
if (n.name() == "third_dimension" && n.namespace_().empty()) {
1742+
if (!third_dimension_.present()) {
1743+
this->third_dimension_.set(third_dimension_traits::create(i, f, this));
1744+
continue;
1745+
}
1746+
}
1747+
17291748
// particle_container
17301749
//
17311750
if (n.name() == "particle_container" && n.namespace_().empty()) {
@@ -1756,6 +1775,10 @@ void settings::parse(::xsd::cxx::xml::dom::parser<char>& p, ::xml_schema::flags
17561775
throw ::xsd::cxx::tree::expected_element<char>("end_time", "");
17571776
}
17581777

1778+
if (!third_dimension_.present()) {
1779+
throw ::xsd::cxx::tree::expected_element<char>("third_dimension", "");
1780+
}
1781+
17591782
if (!particle_container_.present()) {
17601783
throw ::xsd::cxx::tree::expected_element<char>("particle_container", "");
17611784
}
@@ -1770,6 +1793,7 @@ settings& settings::operator=(const settings& x) {
17701793
this->video_length_ = x.video_length_;
17711794
this->delta_t_ = x.delta_t_;
17721795
this->end_time_ = x.end_time_;
1796+
this->third_dimension_ = x.third_dimension_;
17731797
this->particle_container_ = x.particle_container_;
17741798
}
17751799

@@ -2492,6 +2516,14 @@ void operator<<(::xercesc::DOMElement& e, const settings& i) {
24922516
s << ::xml_schema::as_double(i.end_time());
24932517
}
24942518

2519+
// third_dimension
2520+
//
2521+
{
2522+
::xercesc::DOMElement& s(::xsd::cxx::xml::dom::create_element("third_dimension", e));
2523+
2524+
s << i.third_dimension();
2525+
}
2526+
24952527
// particle_container
24962528
//
24972529
{

0 commit comments

Comments
 (0)