Skip to content

Commit

Permalink
examples: boris: going multi-particle #5
Browse files Browse the repository at this point in the history
a few adjustments to logging of particles

next: rewriting particles ...  -_-
  • Loading branch information
torbjoernk committed Nov 19, 2014
1 parent 496a0b9 commit a5988c0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/boris/boris_sdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace pfasst
auto initial_particles = sweeper->get_particles(0);
distribute_particles_around_center(initial_center, initial_particles);

sweeper->set_initial_energy();
LOG(INFO) << OUT::green
<< "Initial Particles";
for (auto p : sweeper->get_particles(0)) {
Expand All @@ -60,6 +59,7 @@ namespace pfasst
}
LOG(INFO) << OUT::green
<< "\tcenter:" << *(get_center_of_mass(sweeper->get_particles(0)));
sweeper->set_initial_energy();
sdc.run();

return sweeper->get_errors();
Expand Down
37 changes: 35 additions & 2 deletions examples/boris/particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace std;
#include <Eigen/Dense>

#include <pfasst/globals.hpp>
#include <pfasst/logging.hpp>
#include <pfasst/interfaces.hpp>
#include <pfasst/encap/encapsulation.hpp>

Expand Down Expand Up @@ -71,7 +72,8 @@ namespace pfasst
typename time = time_precision
>
class ParticleComponentEncapsulation
: public Encapsulation<time>
: public Encapsulation<time>
, public el::Loggable
{
public:
//! @{
Expand Down Expand Up @@ -118,6 +120,13 @@ namespace pfasst
throw NotImplementedYet("operator[] for ParticleComponent");
}
//! @}

//! @{
virtual void log(el::base::type::ostream_t& os) const
{
os << fixed << setprecision(5);
}
//! @}
};


Expand Down Expand Up @@ -183,7 +192,8 @@ namespace pfasst
template <typename, typename> class AccelerationT = AccelerationEncapsulation
>
class ParticleEncapsulation
: public Encapsulation<time>
: public Encapsulation<time>
, public el::Loggable
{
public:
//! @{
Expand Down Expand Up @@ -307,7 +317,30 @@ namespace pfasst
acceleration_type& accel() { return this->m_accel; }
const acceleration_type& accel() const { return this->m_accel; }
//! @}

//! @{
virtual void log(el::base::type::ostream_t& os) const
{
os << fixed << setprecision(5);
os << "Particle(";
this->pos().log(os);
os << ", ";
this->vel().log(os);
os << ", ";
this->accel().log(os);
os << ")";
os.unsetf(ios_base::floatfield);
}
//! @}
};

template<typename scalar, typename time>
ostream& operator<<(ostream& out, const shared_ptr<ParticleEncapsulation<scalar, time>>& p)
{
out << "<" << p.get() << ">";
p->log(out);
return out;
}
} // ::pfasst::examples::boris
} // ::pfasst::examples
} // ::pfasst
Expand Down
69 changes: 44 additions & 25 deletions examples/boris/particle_3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,22 @@ namespace pfasst
return *this;
}
//! @}
};

//! @{
virtual void log(el::base::type::ostream_t& os) const override
{
ParticleComponentEncapsulation<scalar, time>::log(os);
os << "Position([" << this->x << ", " << this->y << ", " << this->z << "])";
os.unsetf(ios_base::floatfield);
}
//! @}
};

template<typename scalar, typename time>
ostream& operator<<(ostream& out, const Position3DEncapsulation<scalar, time>& pos)
ostream& operator<<(ostream& out, const shared_ptr<Position3DEncapsulation<scalar, time>>& pos)
{
out << pos.as_matrix();
out << "<" << pos.get() << ">";
pos->log(out);
return out;
}

Expand Down Expand Up @@ -684,13 +693,22 @@ namespace pfasst
this->w /= value;
return *this;
}
};

//! @{
virtual void log(el::base::type::ostream_t& os) const
{
ParticleComponentEncapsulation<scalar, time>::log(os);
os << "Velocity([" << this->u << ", " << this->v << ", " << this->w << "])";
os.unsetf(ios_base::floatfield);
}
//! @}
};

template<typename scalar, typename time>
ostream& operator<<(ostream& out, const Velocity3DEncapsulation<scalar, time>& vel)
ostream& operator<<(ostream& out, const shared_ptr<Velocity3DEncapsulation<scalar, time>>& vel)
{
out << vel.as_matrix();
out << "<" << vel.get() << ">";
vel->log(out);
return out;
}

Expand Down Expand Up @@ -1010,12 +1028,22 @@ namespace pfasst
this->c -= second.c;
return *this;
}

//! @{
virtual void log(el::base::type::ostream_t& os) const
{
ParticleComponentEncapsulation<scalar, time>::log(os);
os << "Acceleration([" << this->a << ", " << this->b << ", " << this->c << "])";
os.unsetf(ios_base::floatfield);
}
//! @}
};

template<typename scalar, typename time>
ostream& operator<<(ostream& out, const Acceleration3DEncapsulation<scalar, time>& accel)
ostream& operator<<(ostream& out, const shared_ptr<Acceleration3DEncapsulation<scalar, time>>& accel)
{
out << accel.as_matrix();
out << "<" << accel.get() << ">";
accel->log(out);
return out;
}

Expand All @@ -1029,8 +1057,7 @@ namespace pfasst
time,
Position3DEncapsulation,
Velocity3DEncapsulation,
Acceleration3DEncapsulation>,
public el::Loggable
Acceleration3DEncapsulation>
{
private:
typedef ParticleEncapsulation<scalar,
Expand Down Expand Up @@ -1122,10 +1149,6 @@ namespace pfasst
mat.block(0, 6, 1, 3) = this->m_accel.as_matrix();
return mat;
}

virtual void log(el::base::type::ostream_t& os) const override {
os << "pos: [" << this->pos().as_matrix() << "]\tvel: [" << this->vel().as_matrix() << "]\taccel: [" << this->accel().as_matrix() << "]";
}
//! @}

//! @{
Expand All @@ -1141,17 +1164,13 @@ namespace pfasst
//! @}
};



// template<
// typename scalar,
// typename time = time_precision
// >
// ostream& operator<<(ostream& out, const Particle3DEncapsulation<time, scalar>& particle)
// {
// out << "pos: " << particle.pos().as_matrix() << "\tvel: " << particle.vel().as_matrix() << "\taccel: " << particle.accel().as_matrix();
// return out;
// }
template<typename scalar, typename time>
ostream& operator<<(ostream& out, const shared_ptr<Particle3DEncapsulation<scalar, time>>& p)
{
out << "<" << p.get() << ">";
p->log(out);
return out;
}


// XXX: not sure whether this factory is actually useful
Expand Down

0 comments on commit a5988c0

Please sign in to comment.