KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
Classes | List of all members
Kratos::FileNameDataCollector Class Reference

#include <file_name_data_collector.h>

Collaboration diagram for Kratos::FileNameDataCollector:

Classes

class  FileNameData
 

Public Member Functions

Type Definitions
 KRATOS_CLASS_POINTER_DEFINITION (FileNameDataCollector)
 Pointer definition of FileNameDataCollector. More...
 
Life Cycle
 FileNameDataCollector (const ModelPart &rModelPart, const std::string &rFileNamePattern, const std::unordered_map< std::string, std::string > &rFlagFormatMap)
 Construct a new File Name Information Collector object. More...
 
Public member operations
std::string GetFileName () const
 Get the File Name string. More...
 
std::string GetPath () const
 Get the Path. More...
 
std::vector< std::string > GetSortedFileNamesList (const std::vector< std::string > &rFlagsSortingOrder) const
 Gets sorted list of files. More...
 
bool RetrieveFileNameData (FileNameData &rFileNameData, const std::string &rFileNameWithoutPath) const
 Get filename data. More...
 
std::vector< FileNameDataGetFileNameDataList () const
 Retrieves list of file name data objects. More...
 

Static Public Member Functions

Public static operations
static void SortListOfFileNameData (std::vector< FileNameData > &rFileNameDataList, const std::vector< std::string > &rFlagsSortingOrder)
 Sorts given list of file name data vector. More...
 
static std::pair< bool, std::string > ExtractFileNamePattern (const std::string &rFileName, const std::vector< std::string > &rFlagsList)
 Extracts file name pattern from a given file name. More...
 

Constructor & Destructor Documentation

◆ FileNameDataCollector()

Kratos::FileNameDataCollector::FileNameDataCollector ( const ModelPart rModelPart,
const std::string &  rFileNamePattern,
const std::unordered_map< std::string, std::string > &  rFlagFormatMap 
)

Construct a new File Name Information Collector object.

Construct an object which will handle given filename pattern. This rFileNamePattern can incldue folders, subfolders. It must include the file name. Followings are the list of flags supported.

Accepted flags are: "<rank>" : ranks of the model part "<step>" : STEP value in model parts's process info "<time>" : TIME value in model part's process info "<model_part_name>" : name of the model part "<model_part_full_name>": full name of the model part.

Flags "<rank>", "<step>" and "<time>" is only allowed be in the file name only. (Those flags are not allowed to be present in file path)

Example rFileNamePattern:

  1. "test_cases/<model_part_name>/<model_part_full_name>-<time>.h5"
  2. "test/test_1_<rank>_<time>.h5"

rFileNamePattern should always have a seperation character/string in between two flags. This seperation character/string can not start with a digit.

rFlagFormatMap holds format for each flag. If no format is specified, then value for that flag will be written without any formatting. Example map: { "<time>": "0.4f", "<step>": "%4d" }

Example formats:

  1. "0.4f"
  2. "%0.4f"
  3. "0.3e"
Parameters
rModelPartModel part on which this file name data collection is based on
rFileNamePatternFile name pattern (can have file name with or without file path)
rFlagFormatMapMap of formats (key : flag, value: format [both as strings])

Member Function Documentation

◆ ExtractFileNamePattern()

std::pair< bool, std::string > Kratos::FileNameDataCollector::ExtractFileNamePattern ( const std::string &  rFileName,
const std::vector< std::string > &  rFlagsList 
)
static

Extracts file name pattern from a given file name.

This method returns the file name pattern matching given order of flags from left to right. If all the given flags are found, this returns true, otherwise false.

Example patterns: Check test_file_name_data_collector.py::test_ExtractFileNamePattern

Parameters
rFileNameFilename with or without file path
rFlagsListList of flags exists in the file name
Returns
std::pair<bool, std::string> bool: true if all flags are found, false otherwise; string: found pattern

◆ GetFileName()

std::string Kratos::FileNameDataCollector::GetFileName ( ) const

Get the File Name string.

This method returns the file name string according to file name pattern and time step format provided in the constructor.

Returns
std::string

◆ GetFileNameDataList()

std::vector< FileNameDataCollector::FileNameData > Kratos::FileNameDataCollector::GetFileNameDataList ( ) const

Retrieves list of file name data objects.

This iterates through the constructor given file name pattern path files, and returns file name data vector containing file name data for matching file names.

Returns
std::vector<FileNameData>

◆ GetPath()

std::string Kratos::FileNameDataCollector::GetPath ( ) const

Get the Path.

This method returns path obtained from the constructor specified pattern

Returns
std::string Path from the pattern

◆ GetSortedFileNamesList()

std::vector< std::string > Kratos::FileNameDataCollector::GetSortedFileNamesList ( const std::vector< std::string > &  rFlagsSortingOrder) const

Gets sorted list of files.

This method returns list of file names matching the pattern given in the constructor The list of file names are sorted in the flags order given in rFlagsSortingOrder.

Accepted flags are: "<rank>" : ranks of the model part "<step>" : STEP value in model parts's process info "<time>" : TIME value in model part's process info

Parameters
rFlagsSortingOrderSorting order list of strings
Returns
std::vector<std::string> List of sorted file names

◆ KRATOS_CLASS_POINTER_DEFINITION()

Kratos::FileNameDataCollector::KRATOS_CLASS_POINTER_DEFINITION ( FileNameDataCollector  )

Pointer definition of FileNameDataCollector.

◆ RetrieveFileNameData()

bool Kratos::FileNameDataCollector::RetrieveFileNameData ( FileNameData rFileNameData,
const std::string &  rFileNameWithoutPath 
) const

Get filename data.

This will return FileNameData object containing rank, step, time if they are available in the given file name pattern. rFileNameWithoutPath should be only filename without the path.

If the corrensponding rFileNameWithoutPath does not math the pattern given in the constructor then this returns false; otherwise true.

If retrieval is successfully, FileNameData::mFileName will be filled with full file name including the path (specified by the constructor pattern). It will not check for existence of the file in the same path.

Parameters
rFileNameDataData retrieved from rFileNameWithoutPath
rFileNameWithoutPathFile name without file path
Returns
true rFileNameWithoutPath matches the given pattern
false rFileNameWithoutPath does not match the given pattern

◆ SortListOfFileNameData()

void Kratos::FileNameDataCollector::SortListOfFileNameData ( std::vector< FileNameData > &  rFileNameDataList,
const std::vector< std::string > &  rFlagsSortingOrder 
)
static

Sorts given list of file name data vector.

This method sorts given list of file name data vector according to sorting flags order given in rFlagsSortingOrder.

Accepted flags are: "<rank>" : ranks of the model part "<step>" : STEP value in model parts's process info "<time>" : TIME value in model part's process info

Parameters
rFileNameDataList
rFlagsSortingOrder

The documentation for this class was generated from the following files: