Skip to content
Snippets Groups Projects
Commit ade345a8 authored by Rafael Ravedutti's avatar Rafael Ravedutti
Browse files

Allow to set frequency of VTK outputs

parent 5d53e076
No related branches found
No related tags found
1 merge request!1Implement DEM and many other features
...@@ -162,7 +162,7 @@ psim.read_particle_data( ...@@ -162,7 +162,7 @@ psim.read_particle_data(
pairs.halfspace()) pairs.halfspace())
psim.build_neighbor_lists(linkedCellWidth + skin) psim.build_neighbor_lists(linkedCellWidth + skin)
psim.vtk_output(f"output/dem_{target}") psim.vtk_output(f"output/dem_{target}", frequency=visSpacing)
psim.compute(linear_spring_dashpot, linkedCellWidth + skin, symbols={'dt': dt_SI}) psim.compute(linear_spring_dashpot, linkedCellWidth + skin, symbols={'dt': dt_SI})
psim.compute(euler, symbols={'dt': dt_SI}) psim.compute(euler, symbols={'dt': dt_SI})
psim.compute(gravity, symbols={'densityParticle_SI': densityParticle_SI, psim.compute(gravity, symbols={'densityParticle_SI': densityParticle_SI,
......
...@@ -8,13 +8,17 @@ ...@@ -8,13 +8,17 @@
namespace pairs { namespace pairs {
void vtk_write_data(PairsSimulation *ps, const char *filename, int start, int end, int timestep) { void vtk_write_data(PairsSimulation *ps, const char *filename, int start, int end, int timestep, int frequency) {
std::string output_filename(filename); std::string output_filename(filename);
auto masses = ps->getAsFloatProperty(ps->getPropertyByName("mass")); auto masses = ps->getAsFloatProperty(ps->getPropertyByName("mass"));
auto positions = ps->getAsVectorProperty(ps->getPropertyByName("position")); auto positions = ps->getAsVectorProperty(ps->getPropertyByName("position"));
const int n = end - start; const int n = end - start;
std::ostringstream filename_oss; std::ostringstream filename_oss;
if(frequency != 0 && timestep % frequency != 0) {
return;
}
filename_oss << filename << "_"; filename_oss << filename << "_";
if(ps->getDomainPartitioner()->getWorldSize() > 1) { if(ps->getDomainPartitioner()->getWorldSize() > 1) {
filename_oss << "r" << ps->getDomainPartitioner()->getRank() << "_"; filename_oss << "r" << ps->getDomainPartitioner()->getRank() << "_";
......
...@@ -69,6 +69,7 @@ class Simulation: ...@@ -69,6 +69,7 @@ class Simulation:
self.expr_id = 0 self.expr_id = 0
self.iter_id = 0 self.iter_id = 0
self.vtk_file = None self.vtk_file = None
self.vtk_frequency = 0
self._target = None self._target = None
self._dom_part = DimensionRanges(self) self._dom_part = DimensionRanges(self)
...@@ -247,8 +248,9 @@ class Simulation: ...@@ -247,8 +248,9 @@ class Simulation:
else: else:
self.nested_count += 1 self.nested_count += 1
def vtk_output(self, filename): def vtk_output(self, filename, frequency=0):
self.vtk_file = filename self.vtk_file = filename
self.vtk_frequency = frequency
def target(self, target): def target(self, target):
self._target = target self._target = target
...@@ -283,13 +285,13 @@ class Simulation: ...@@ -283,13 +285,13 @@ class Simulation:
timestep = Timestep(self, self.ntimesteps, timestep_procedures) timestep = Timestep(self, self.ntimesteps, timestep_procedures)
self.enter(timestep.block) self.enter(timestep.block)
timestep.add(VTKWrite(self, self.vtk_file, timestep.timestep() + 1)) timestep.add(VTKWrite(self, self.vtk_file, timestep.timestep() + 1, self.vtk_frequency))
self.leave() self.leave()
body = Block.from_list(self, [ body = Block.from_list(self, [
self.setups, self.setups,
BuildCellListsStencil(self, self.cell_lists), BuildCellListsStencil(self, self.cell_lists),
VTKWrite(self, self.vtk_file, 0), VTKWrite(self, self.vtk_file, 0, self.vtk_frequency),
timestep.as_block() timestep.as_block()
]) ])
......
...@@ -6,15 +6,16 @@ from pairs.sim.lowerable import Lowerable ...@@ -6,15 +6,16 @@ from pairs.sim.lowerable import Lowerable
class VTKWrite(Lowerable): class VTKWrite(Lowerable):
def __init__(self, sim, filename, timestep): def __init__(self, sim, filename, timestep, frequency):
super().__init__(sim) super().__init__(sim)
self.filename = filename self.filename = filename
self.timestep = Lit.cvt(sim, timestep) self.timestep = Lit.cvt(sim, timestep)
self.frequency = frequency
@pairs_inline @pairs_inline
def lower(self): def lower(self):
nlocal = self.sim.nlocal nlocal = self.sim.nlocal
nghost = self.sim.nghost nghost = self.sim.nghost
nall = nlocal + nghost nall = nlocal + nghost
Call_Void(self.sim, "pairs::vtk_write_data", [self.filename + "_local", 0, nlocal, self.timestep]) Call_Void(self.sim, "pairs::vtk_write_data", [self.filename + "_local", 0, nlocal, self.timestep, self.frequency])
Call_Void(self.sim, "pairs::vtk_write_data", [self.filename + "_ghost", nlocal, nall, self.timestep]) Call_Void(self.sim, "pairs::vtk_write_data", [self.filename + "_ghost", nlocal, nall, self.timestep, self.frequency])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment