Skip to content

Commit

Permalink
Update test cases that generate particle output
Browse files Browse the repository at this point in the history
  • Loading branch information
hlokavarapu committed May 14, 2017
1 parent f4fe3a1 commit 8d734e1
Show file tree
Hide file tree
Showing 103 changed files with 1,130 additions and 320 deletions.
18 changes: 18 additions & 0 deletions include/aspect/particle/output/ascii.h
Expand Up @@ -101,6 +101,24 @@ namespace aspect
void
load (std::istringstream &is);

/**
* Returns a constructed filename.
*/
const std::string
get_file_name();

/**
* Get the absolute path where the specified particle output will be generated.
*/
const std::string
get_particle_output_location();

/**
* Get the current file index.
*/
const std::string
get_file_index();

private:
/**
* Internal index of file output number.
Expand Down
18 changes: 18 additions & 0 deletions include/aspect/particle/output/hdf5.h
Expand Up @@ -104,6 +104,24 @@ namespace aspect
void
load (std::istringstream &is);

/**
* Returns a constructed filename.
*/
const std::string
get_file_name();

/**
* Get the absolute path where the specified particle output will be generated.
*/
const std::string
get_particle_output_location();

/**
* Get the current file index.
*/
const std::string
get_file_index();

private:
/**
* Internal index of file output number.
Expand Down
32 changes: 31 additions & 1 deletion include/aspect/particle/output/interface.h
Expand Up @@ -85,6 +85,27 @@ namespace aspect
const Property::ParticlePropertyInformation &property_information,
const double current_time) = 0;

/**
* Returns the particle file name taking into account the file index as well as the mpi proccess.
*/
virtual
const std::string
get_file_name();

/**
* Get the absolute path where the specified particle output will be generated.
*/
virtual
const std::string
get_particle_output_location();

/**
* Get the current file index.
*/
virtual
const std::string
get_file_index();

/**
* Read or write the data of this object for serialization
*/
Expand Down Expand Up @@ -163,7 +184,7 @@ namespace aspect
*/
template <int dim>
Interface<dim> *
create_particle_output (ParameterHandler &prm);
create_particle_output (const std::string &name);

/**
* Declare the runtime parameters of the registered particle outputs.
Expand All @@ -174,13 +195,22 @@ namespace aspect
void
declare_parameters (ParameterHandler &prm);

/**
* Return a list of names of all implemented output format models,
* separated by '|' so that it can be used in an object of type
* Patterns::Selection.
*/
template <int dim>
std::string get_names ();

/**
* Given a class name, a name, and a description for the parameter file
* for a particle output, register it with the functions that
* can declare their parameters and create these objects.
*
* @ingroup ParticleOutputs
*/

#define ASPECT_REGISTER_PARTICLE_OUTPUT(classname, name, description) \
template class classname<2>; \
template class classname<3>; \
Expand Down
18 changes: 18 additions & 0 deletions include/aspect/particle/output/vtu.h
Expand Up @@ -100,6 +100,24 @@ namespace aspect
void
load (std::istringstream &is);

/**
* Returns a constructed filename.
*/
const std::string
get_file_name();

/**
* Get the absolute path where the specified particle output will be generated.
*/
const std::string
get_particle_output_location();

/**
* Get the current file index.
*/
const std::string
get_file_index();

private:
/**
* Internal index of file output number.
Expand Down
2 changes: 1 addition & 1 deletion include/aspect/particle/world.h
Expand Up @@ -287,7 +287,7 @@ namespace aspect
/**
* Pointer to an output object
*/
std_cxx11::unique_ptr<Output::Interface<dim> > output;
std::vector<std_cxx11::shared_ptr<Output::Interface<dim> > > output;

/**
* Set of particles currently in the local domain, organized by
Expand Down
40 changes: 29 additions & 11 deletions source/particle/output/ascii.cc
Expand Up @@ -48,16 +48,8 @@ namespace aspect
const Property::ParticlePropertyInformation &property_information,
const double /*time*/)
{
const std::string output_file_prefix =
this->get_output_directory()
+ "particles/"
+ "particle-"
+ Utilities::int_to_string (file_index, 5);
const std::string full_filename =
output_file_prefix
+ "."
+ Utilities::int_to_string(Utilities::MPI::this_mpi_process(this->get_mpi_communicator()), 4)
+ ".txt";
const std::string full_filename = get_particle_output_location()
+ get_file_name();

std::ofstream output (full_filename.c_str());

Expand Down Expand Up @@ -108,7 +100,7 @@ namespace aspect

file_index++;

return output_file_prefix;
return "txt";
}

template <int dim>
Expand All @@ -135,6 +127,32 @@ namespace aspect
aspect::iarchive ia (is);
ia >> (*this);
}

template <int dim>
const std::string
ASCIIOutput<dim>::get_file_name ()
{
return "particles-"
+ get_file_index()
+ "."
+ Utilities::int_to_string(Utilities::MPI::this_mpi_process(this->get_mpi_communicator()), 4)
+ ".txt";
}

template <int dim>
const std::string
ASCIIOutput<dim>::get_particle_output_location ()
{
return this->get_output_directory()
+ "particles/";
}

template <int dim>
const std::string
ASCIIOutput<dim>::get_file_index ()
{
return Utilities::int_to_string(file_index, 5);
}
}
}
}
Expand Down
40 changes: 29 additions & 11 deletions source/particle/output/hdf5.cc
Expand Up @@ -78,12 +78,8 @@ namespace aspect
{
#ifdef DEAL_II_WITH_HDF5
// Create the filename
const std::string output_file_prefix = "particles-" + Utilities::int_to_string (file_index, 5);
const std::string output_path_prefix =
this->get_output_directory()
+ "particles/"
+ output_file_prefix;
const std::string h5_filename = output_path_prefix+".h5";
const std::string h5_filename = get_particle_output_location()
+ get_file_name();

// Create the hdf5 output size information
types::particle_index n_local_particles = particles.size();
Expand Down Expand Up @@ -258,10 +254,8 @@ namespace aspect
// Record and output XDMF info on root process
if (Utilities::MPI::this_mpi_process(this->get_mpi_communicator()) == 0)
{
const std::string local_h5_filename =
"particles/"
+ output_file_prefix
+ ".h5";
const std::string local_h5_filename = "particles/"
+ get_file_name();
XDMFEntry entry(local_h5_filename, current_time, n_global_particles, 0, 3);
DataOut<dim> data_out;
const std::string xdmf_filename = (this->get_output_directory() + "particles.xdmf");
Expand All @@ -288,7 +282,7 @@ namespace aspect

file_index++;

return output_path_prefix;
return "h5";
#else
(void) property_information;
(void) particles;
Expand Down Expand Up @@ -323,6 +317,30 @@ namespace aspect
aspect::iarchive ia (is);
ia >> (*this);
}

template <int dim>
const std::string
HDF5Output<dim>::get_file_name ()
{
return "particles-"
+ get_file_index()
+ ".h5";
}

template <int dim>
const std::string
HDF5Output<dim>::get_particle_output_location()
{
return this->get_output_directory()
+ "particles/";
}

template <int dim>
const std::string
HDF5Output<dim>::get_file_index()
{
return Utilities::int_to_string (file_index, 5);
}
}
}
}
Expand Down
61 changes: 41 additions & 20 deletions source/particle/output/interface.cc
Expand Up @@ -18,6 +18,8 @@
<http://www.gnu.org/licenses/>.
*/



#include <aspect/particle/output/interface.h>


Expand Down Expand Up @@ -61,6 +63,29 @@ namespace aspect
Interface<dim>::load (std::istringstream &)
{}

template <int dim>
const std::string
Interface<dim>::get_file_name()
{
// To prevent warning statement during compilation
return "";
}

template <int dim>
const std::string
Interface<dim>::get_particle_output_location()
{
// To prevent warning statement during compilation
return "";
}

template <int dim>
const std::string
Interface<dim>::get_file_index()
{
// To prevent warning statement during compilation
return "";
}

// -------------------------------- Deal with registering models and automating
// -------------------------------- their setup and selection at run time
Expand Down Expand Up @@ -92,27 +117,22 @@ namespace aspect

template <int dim>
Interface<dim> *
create_particle_output (ParameterHandler &prm)
create_particle_output (const std::string &name)
{
std::string name;
prm.enter_subsection ("Postprocess");
{
prm.enter_subsection ("Particles");
{
name = prm.get ("Data output format");
}
prm.leave_subsection ();
}
prm.leave_subsection ();

if (name != "none")
return std_cxx1x::get<dim>(registered_plugins).create_plugin (name,
"Particle::Output name");
else
return NULL;
}
Interface<dim> *output
= std_cxx1x::get<dim>(registered_plugins).create_plugin (name,
"Particle::Output name");

return output;
}

template <int dim>
std::string
get_names()
{
return std_cxx11::get<dim>(registered_plugins).get_pattern_of_names ();
}

template <int dim>
void
Expand All @@ -127,11 +147,12 @@ namespace aspect
= std_cxx1x::get<dim>(registered_plugins).get_pattern_of_names ();

prm.declare_entry ("Data output format", "vtu",
Patterns::Selection (pattern_of_names + "|none"),
Patterns::List (Patterns::Selection(pattern_of_names + "|none")),
"File format to output raw particle data in. "
"Multiple formats can be specified sperated by a comma (,)"
"If you select 'none' no output will be "
"written."
"Select one of the following models:\n\n"
"Select one or multiple of the following models:\n\n"
+
std_cxx1x::get<dim>(registered_plugins).get_description_string());
}
Expand Down Expand Up @@ -181,7 +202,7 @@ namespace aspect
\
template \
Interface<dim> * \
create_particle_output<dim> (ParameterHandler &prm);
create_particle_output<dim> (const std::string &name);

ASPECT_INSTANTIATE(INSTANTIATE)
}
Expand Down

0 comments on commit 8d734e1

Please sign in to comment.