Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mgoullie
sp4_exercises
Commits
5f3e56fc
Commit
5f3e56fc
authored
Nov 04, 2020
by
Emil Gallyamov
Browse files
Week7 solution + week8 exercise
parent
f17d735f
Changes
47
Expand all
Hide whitespace changes
Inline
Side-by-side
exercises/week7/paraview/sources-solution/solar-system.pvsm
0 → 100644
View file @
5f3e56fc
This diff is collapsed.
Click to expand it.
exercises/week8/particles/.gitignore
0 → 100644
View file @
5f3e56fc
step-*.csv
\ No newline at end of file
exercises/week8/particles/particle.classes
0 → 100644
View file @
5f3e56fc
class Real(double)
class UInt(unsigned int)
class Vector
public Vector(UInt dim);
public ~Vector();
public Real & operator[](UInt i);
private Real * values;
private UInt dim;
class Particle
public Particle();
public ~Particle();
public Real & getMass();
public Vector & getPosition();
public Vector & getVelocity();
public Vector & getForce();
protected Real mass;
protected Vector position;
protected Vector velocity;
protected Vector force;
class PingPongBall(Particle)
public PingPongBall();
public ~PingPongBall();
public Real & getRadius();
public Real & getContactDissipation();
private Real radius;
private Real contact_dissipation;
class Planet(Particle)
public Planet();
public ~Planet();
public std::string & getName();
private std::string name;
class Compute
public Compute();
public ~Compute();
public pure virtual void compute(System & system);
class ComputeInteraction(Compute)
public ComputeInteraction();
public ~ComputeInteraction();
public pure virtual void compute(System & system);
class ComputeContact(ComputeInteraction)
public ComputeContact();
public ~ComputeContact();
public void compute(System & system);
class ComputeGravity(ComputeInteraction)
public ComputeGravity();
public ~ComputeGravity();
public void compute(System & system);
class CsvReader(Compute)
public CsvReader(const std::string & filename);
public ~CsvReader();
public void read(System & system);
public void compute(System & system);
protected std::string filename;
class CsvWriter(Compute)
public CsvWriter(const std::string & filename);
public ~CsvWriter();
public void write(System& system);
public void compute(System & system);
protected std::string filename;
class ComputeVerletIntegration(Compute)
public ComputeVerletIntegration(Real dt);
public ~ComputeVerletIntegration();
public void compute(System& system);
public void addInteraction(std::shared_ptr<ComputeInteraction> interaction);
public setDeltaT(Real dt);
private Real dt;
private InteractionList interactions;
class System
public System()
public ~System()
public UInt getListSize();
public Particle & getParticle(UInt i);
public addParticle(Particle& new_particle);
public removeParticle(UInt particle);
private ListParticles list_particles;
class SystemEvolution
public SystemEvolution(System & system);
public evolve();
protected std::vector<Compute *> computes;
protected System & system;
class ListParticles(std::vector<Particle*>)
\ No newline at end of file
exercises/week8/particles/starting_point/CMakeLists.txt
0 → 100644
View file @
5f3e56fc
cmake_minimum_required
(
VERSION 2.6
)
project
(
Particles
)
set
(
CMAKE_CXX_STANDARD 14
)
add_executable
(
particles
main.cc
vector.cc
compute_boundary.cc
compute_verlet_integration.cc
particle.cc
planet.cc
compute_gravity.cc
csv_reader.cc
particles_factory_interface.cc
planets_factory.cc
compute_contact.cc
compute_kinetic_energy.cc
csv_writer.cc
system.cc
compute_energy.cc
compute_potential_energy.cc
ping_pong_ball.cc
system_evolution.cc
ping_pong_balls_factory.cc
compute_interaction.cc
)
exercises/week8/particles/starting_point/compute.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE__HH__
#define __COMPUTE__HH__
/* -------------------------------------------------------------------------- */
#include "system.hh"
/* -------------------------------------------------------------------------- */
//! Base class for all compute
class
Compute
{
public:
//! Virtual destructor needed because we have subclasses
virtual
~
Compute
()
=
default
;
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public:
//! Compute is pure virtual
virtual
void
compute
(
System
&
system
)
=
0
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE__HH__
exercises/week8/particles/starting_point/compute_boundary.cc
0 → 100644
View file @
5f3e56fc
#include "compute_boundary.hh"
/* -------------------------------------------------------------------------- */
ComputeBoundary
::
ComputeBoundary
(
const
Vector
&
xmin
,
const
Vector
&
xmax
)
:
xmin
(
xmin
),
xmax
(
xmax
)
{
Vector
d
=
xmax
-
xmin
;
for
(
UInt
i
=
0
;
i
<
Vector
::
dim
;
++
i
)
if
(
d
[
i
]
<
0
)
{
std
::
cout
<<
"XMax and XMin do not form a domain range"
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
/* -------------------------------------------------------------------------- */
void
ComputeBoundary
::
compute
(
System
&
system
)
{
}
/* -------------------------------------------------------------------------- */
exercises/week8/particles/starting_point/compute_boundary.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_BOUNDARY__HH__
#define __COMPUTE_BOUNDARY__HH__
/* -------------------------------------------------------------------------- */
#include "compute.hh"
/* -------------------------------------------------------------------------- */
//! Compute interaction with simulation box
class
ComputeBoundary
:
public
Compute
{
// Constructors/Destructors
public:
ComputeBoundary
(
const
Vector
&
xmin
,
const
Vector
&
xmax
);
// Methods
public:
void
compute
(
System
&
system
)
override
;
// Members
protected:
Vector
xmin
,
xmax
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_BOUNDARY__HH__
exercises/week8/particles/starting_point/compute_contact.cc
0 → 100644
View file @
5f3e56fc
#include "compute_contact.hh"
#include "ping_pong_ball.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
void
ComputeContact
::
setPenalty
(
Real
penalty
)
{
}
/* -------------------------------------------------------------------------- */
void
ComputeContact
::
compute
(
System
&
system
)
{
}
exercises/week8/particles/starting_point/compute_contact.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_CONTACT__HH__
#define __COMPUTE_CONTACT__HH__
/* -------------------------------------------------------------------------- */
#include "compute_interaction.hh"
//! Compute contact interaction between ping-pong balls
class
ComputeContact
:
public
ComputeInteraction
{
// Virtual implementation
public:
//! Penalty contact implementation
void
compute
(
System
&
system
)
override
;
// Accessors
public:
//! Set penalty
void
setPenalty
(
Real
penalty
);
// Members
protected:
Real
penalty
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_CONTACT__HH__
exercises/week8/particles/starting_point/compute_energy.cc
0 → 100644
View file @
5f3e56fc
#include "compute_energy.hh"
/* -------------------------------------------------------------------------- */
exercises/week8/particles/starting_point/compute_energy.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_ENERGY__HH__
#define __COMPUTE_ENERGY__HH__
/* -------------------------------------------------------------------------- */
#include "compute.hh"
//! Base class for energy computation
class
ComputeEnergy
:
public
Compute
{
// Methods
public:
Real
getValue
()
{
return
value
;
}
protected:
Real
value
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_ENERGY__HH__
exercises/week8/particles/starting_point/compute_gravity.cc
0 → 100644
View file @
5f3e56fc
#include "compute_gravity.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
void
ComputeGravity
::
compute
(
System
&
system
)
{
}
exercises/week8/particles/starting_point/compute_gravity.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_GRAVITY__HH__
#define __COMPUTE_GRAVITY__HH__
/* -------------------------------------------------------------------------- */
#include "compute_interaction.hh"
//! Compute Newton gravity interaction
class
ComputeGravity
:
public
ComputeInteraction
{
// Virtual implementation
public:
//! Newton gravity implementation
void
compute
(
System
&
system
)
override
;
// Accessors
public:
//! set the gravitational constant
void
setG
(
Real
G
);
// Members
private:
//! newton constant
Real
G
=
1.
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_GRAVITY__HH__
exercises/week8/particles/starting_point/compute_interaction.cc
0 → 100644
View file @
5f3e56fc
#include "compute_interaction.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
exercises/week8/particles/starting_point/compute_interaction.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_INTERACTION__HH__
#define __COMPUTE_INTERACTION__HH__
/* -------------------------------------------------------------------------- */
#include "compute.hh"
//! Base class for interaction computation
class
ComputeInteraction
:
public
Compute
{
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_INTERACTION__HH__
exercises/week8/particles/starting_point/compute_kinetic_energy.cc
0 → 100644
View file @
5f3e56fc
#include "compute_kinetic_energy.hh"
/* -------------------------------------------------------------------------- */
void
ComputeKineticEnergy
::
compute
(
System
&
system
)
{}
/* -------------------------------------------------------------------------- */
exercises/week8/particles/starting_point/compute_kinetic_energy.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_KINETIC_ENERGY__HH__
#define __COMPUTE_KINETIC_ENERGY__HH__
/* -------------------------------------------------------------------------- */
#include "compute_energy.hh"
//! Compute kinetic energy of system
class
ComputeKineticEnergy
:
public
ComputeEnergy
{
public:
void
compute
(
System
&
system
)
override
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_KINETIC_ENERGY__HH__
exercises/week8/particles/starting_point/compute_potential_energy.cc
0 → 100644
View file @
5f3e56fc
#include "compute_potential_energy.hh"
/* -------------------------------------------------------------------------- */
ComputePotentialEnergy
::
ComputePotentialEnergy
(
ComputeInteraction
&
cForces
)
:
cForces
(
cForces
)
{}
/* -------------------------------------------------------------------------- */
void
ComputePotentialEnergy
::
compute
(
System
&
system
)
{}
exercises/week8/particles/starting_point/compute_potential_energy.hh
0 → 100644
View file @
5f3e56fc
#ifndef __COMPUTE_POTENTIAL_ENERGY__HH__
#define __COMPUTE_POTENTIAL_ENERGY__HH__
/* -------------------------------------------------------------------------- */
#include "compute_energy.hh"
#include "compute_interaction.hh"
/* -------------------------------------------------------------------------- */
//! Compute potential energy of system
class
ComputePotentialEnergy
:
public
ComputeEnergy
{
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
ComputePotentialEnergy
(
ComputeInteraction
&
cForces
);
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public:
void
compute
(
System
&
system
)
override
;
/* ------------------------------------------------------------------------ */
/* Members */
/* ------------------------------------------------------------------------ */
protected:
ComputeInteraction
&
cForces
;
};
/* -------------------------------------------------------------------------- */
#endif //__COMPUTE_POTENTIAL_ENERGY__HH__
exercises/week8/particles/starting_point/compute_verlet_integration.cc
0 → 100644
View file @
5f3e56fc
#include "compute_verlet_integration.hh"
ComputeVerletIntegration
::
ComputeVerletIntegration
(
Real
dt
)
:
dt
(
dt
)
{}
/* -------------------------------------------------------------------------- */
void
ComputeVerletIntegration
::
setDeltaT
(
Real
dt
)
{
}
/* -------------------------------------------------------------------------- */
void
ComputeVerletIntegration
::
compute
(
System
&
system
)
{
}
/* -------------------------------------------------------------------------- */
void
ComputeVerletIntegration
::
addInteraction
(
std
::
shared_ptr
<
ComputeInteraction
>
interaction
)
{
}
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment