FileManager
-
class FileManager
Public Functions
-
inline FileManager(LinearElasticity *physics)
Constructor. Saves pointer to provided LinearElasticity object.
- Parameters:
physics – pointer to the LinearElasticity object that will be used by the hyperoptimization algorithm.
-
PetscErrorCode initializeHDF5(PetscScalar volfrac, PetscScalar timestep, PetscScalar temperature, PetscInt numberElementsX, PetscInt numberElementsY, PetscInt numberElementsZ, PetscScalar penalty, PetscScalar filterRadius, PetscInt numberSteps, PetscInt saveFrequency, PetscInt NoseHooverChainOrder, std::string filePath, bool randomStartingValues, std::string initialConditionsFile, DomainCoordinates domain, std::vector<BoundaryCondition> boundaryConditions)
Creates an HDF5 file for iteration with the provided parameters. This must be called before starting the iteration loop.
- Parameters:
volfrac – volume fraction setting
timestep – timestep setting
temperature – system temperature setting
numberElementsX – cells in the x direction
numberElementsY – cells in the y direction
numberElementsZ – cells in the z direction
penalty – optimization penalty power setting
filterRadius – minimum filter radius setting
numberSteps – number of iterations to save
saveFrequency – number of iterations for each sample
NoseHooverChainOrder – number of particles in the Nose Hoover chain
filePath – path to save the HDF5 output file to
randomStartingValues – indicates if the positions were set uniformly or not
initialConditionsFile – path to pre-set initial conditions if provided
domain – domain coordinates of the problem
boundaryConditions – groups of boundary conditions for the problem
- Returns:
0 or PetscError.
-
PetscErrorCode saveIteration(PetscInt iteration, Vec positions)
Saves an iteration of the optimized positions.
- Parameters:
iteration – step to save
positions – grid of scalar position values at the given iteration
- Returns:
0 or PetscError.
-
PetscErrorCode saveFinalState(bool saveHamiltionan, HypOptParameters finalState, std::vector<PetscScalar> hamiltonians, std::vector<PetscScalar> compliance, std::vector<PetscScalar> temperatures, std::vector<PetscScalar> LagrangeMultipliers, std::vector<PetscScalar> iterationTimes, std::vector<PetscScalar> timesteps, std::vector<PetscScalar> energyErrors, std::vector<PetscScalar> volFracs, std::vector<PetscInt> solverIterationsSensitivity, std::vector<PetscInt> solverIterationsHamiltonian)
Saves the final state of the system for restarting functionality. Additionally saves metadata from each iteration.
- Parameters:
saveHamiltionan – option to save the Hamiltonian and Compliance metadata.
finalState – final state of the system, including all particle and NH particle positions and velocities.
hamiltonians – Hamiltonian at each iteration (if saveHamiltionan option is false this can be NULL).
compliance – compliance at each iteration (if saveHamiltionan option is false this can be NULL).
temperatures – system temperature at each iteration.
LagrangeMultipliers – Lagrangian Multipliers at each iteration.
iterationTimes – time to solve each iteration.
timesteps – timestep at each iteration. Useful for variable timestep runs.
energyErrors – energy error at each iteration.
volFracs – volume fraction at each iteration.
solverIterationsSensitivity – number of iterations the FEA solver for the sensitivity calculation.
solverIterationsHamiltonian – number of iterations the FEA solver for the Hamiltonian calculation.
- Returns:
0 or PetscError.
-
std::string getSaveFilePath()
Save file path accessor.
- Returns:
the path to the HDF5 save file.
-
std::string getDataGroup()
Data group accessor.
- Returns:
the the name of the data group.
Public Static Functions
-
static bool doesFileExist(std::string filePath)
Helper function to determine if a file exists.
Uses the std::ifstream::open function and checks if the fail opened succesfully. This method is imperfect if the file fails to open for another reason, but should work for most cases without getting too complicated.
- Parameters:
filePath – the path to check.
- Returns:
true if the file exists, false otherwise.
-
static PetscErrorCode getFinalStateVectors(std::string filePath, HypOptParameters finalState, Vec finalStateField)
Helper function to get the final state from a given restart file.
- Parameters:
filePath – the restart file to parse.
finalState – [out] structure to fill with with the state parameters (particle positions and velocities)
finalStateField – [out] final state field vector to pass to the Linear Elasticity class.
- Returns:
0 for success, PetscError otherwise.
-
template<typename T>
static PetscErrorCode HDF5SaveStdVector(PetscViewer HDF5saveFile, std::vector<T> vector, const char *vectorName) Helper function which converts a std::vector object into a Petsc vector before saving it to the provided HDF5 viewer.
Currently only needed for PetscScalar objects, though this could easily be overloaded or templated for more support if needed.
- Parameters:
HDF5saveFile – Petsc Viewer set up to the desired file and data group.
vector – scalar std::vector object to save.
vectorName – name under which to save the vector in the HDF5 file.
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode HDF5GetSavedVec(std::string filePath, std::string location, Vec vector)
Helper function to retrieve a vector from a given HDF5 file.
- Todo:
this function should probably be overloaded to pass a pre-preppared PetscViewer for efficiency (although this is far from the slowest part of the code).
- Parameters:
filePath – the file from which to acquire the desired vector.
location – HDF5 group where the vector is saved
vector – [out] the vector to populate
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode getHDF5Settings(std::string filePath, PetscInt *noseHooverChainOrder, PetscScalar *volumeFraction, PetscScalar *timestep, PetscScalar *targetTemperature, PetscScalar *penalty, PetscScalar *minimumFilterRadius, std::vector<uint32_t> *gridDimensions, DomainCoordinates *domain, std::vector<BoundaryCondition> *boundaryConditions)
Helper function to retrieve the simulation settings froma given restart file.
- Parameters:
filePath – the restart file to parse.
noseHooverChainOrder – [out] setting to populate
volumeFraction – [out] setting to populate
timestep – [out] setting to populate
targetTemperature – [out] setting to populate
penalty – [out] setting to populate
minimumFilterRadius – [out] setting to populate
gridDimensions – [out] setting to populate
domain – [out] setting to populate
boundaryConditions – [out] setting to populate
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode saveInitialConditions(Vec positions, Vec velocities, std::string filePath)
Saves provided initial conditions to an hdf5 file at the path provided.
- Parameters:
positions – initial positions
velocities – initial velocities
filePath – path to hdf5 file to create/append
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode loadInitialConditions(Vec positions, Vec velocities, std::string filePath)
Loads initial conditions from an hdf5 file at the path provided.
- Parameters:
positions – [out] initial positions
velocities – [out] initial velocities
filePath – [out] path to hdf5 file to create/append
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode saveBoundaryConditions(PetscViewer saveFileHDF5, std::vector<BoundaryCondition> boundaryConditions)
Saves provided boundary conditions to an hdf5 file at the path provided.
- Parameters:
saveFileHDF5 – viewer already initialized to hdf5 file to save
boundaryConditions – settings to save
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode getBoundaryConditions(PetscViewer saveFileHDF5, std::vector<BoundaryCondition> *boundaryConditions)
Gets boundary conditions from the provided viewer.
- Parameters:
saveFileHDF5 – viewer already initialized to hdf5 file to save
boundaryConditions – [out] settings to populate
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode saveDomainInformation(PetscViewer saveFileHDF5, DomainCoordinates domain)
Saves provided domain coordinates to an hdf5 file at the path provided.
- Parameters:
saveFileHDF5 – viewer already initialized to hdf5 file to save
domain – settings to save
- Returns:
0 on success, PetscError otherwise.
-
static PetscErrorCode getDomainInformation(PetscViewer saveFileHDF5, DomainCoordinates *domain)
Gets domain coordinates from the provided viewer.
- Parameters:
saveFileHDF5 – viewer already initialized to hdf5 file to save
domain – [out] settings to populate
- Returns:
0 on success, PetscError otherwise.
Private Functions
-
std::string autoAppendFilePath(std::string fileName, std::string fileExtension)
Private helper function which finds a unique file name in the given path.
If the given file alreaqdy exists, “ (1)” is appended to the name. If it still does exists, “ (1)” is incremented until a file name is found which does not exist.
- Todo:
this could probably be simplified to not require sepparating file path and extension.
- Parameters:
fileName – the file name to append (with no file extension).
fileExtension – the file extension to be used.
Private Static Attributes
-
static const std::string stateGroup
-
static const std::string dataGroup
-
static const std::string settingsGroup
-
static const std::string volfracName
-
static const std::string timestepName
-
static const std::string tempName
-
static const std::string xDimName
-
static const std::string yDimName
-
static const std::string zDimName
-
static const std::string penaltyName
-
static const std::string minRadiusName
-
static const std::string numStepName
-
static const std::string saveFreqName
-
static const std::string chainOrdName
-
static const std::string hamiltonianName
-
static const std::string complainceName
-
static const std::string temperatureName
-
static const std::string lagrangianMultipliarName
-
static const std::string iterationComputeTimeName
-
static const std::string timestepsName
-
static const std::string energyErrorsName
-
static const std::string finalPositionName
-
static const std::string finalVelocityName
-
static const std::string finalEvenNHPositionName
-
static const std::string finalEvenNHVelocityName
-
static const std::string finalOddNHPositionName
-
static const std::string finalOddNHVelocityName
-
static const std::string finalStateFieldName
-
static const std::string initialPositionName
-
static const std::string initialVelocityName
-
inline FileManager(LinearElasticity *physics)