Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate input parsing from input data #325

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Substrate/GrainOrientationRGB_IPF-Z.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9998,4 +9998,4 @@
0.988490809,0.123951873,0.763509062
0.930786718,0.79562441,0.665536534
0.772707546,0.494342328,0.950627754
0.992421119,0.082218904,0.82634183
0.992421119,0.082218904,0.82634183
2 changes: 1 addition & 1 deletion src/CAcelldata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "CAconfig.hpp"
#include "CAgrid.hpp"
#include "CAinputs.hpp"
#include "CAinputdata.hpp"
#include "CAparsefiles.hpp"
#include "CAtypes.hpp"
#include "mpi.h"
Expand Down
2 changes: 1 addition & 1 deletion src/CAgrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef EXACA_GRID_HPP
#define EXACA_GRID_HPP

#include "CAinputs.hpp"
#include "CAinputdata.hpp"
#include "CAparsefiles.hpp"

#include "mpi.h"
Expand Down
160 changes: 160 additions & 0 deletions src/CAinputdata.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright 2021-2023 Lawrence Livermore National Security, LLC and other ExaCA Project Developers.
// See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#ifndef EXACA_INPUTDATA_HPP
#define EXACA_INPUTDATA_HPP

#include "CAinfo.hpp"
#include "CAtimers.hpp"

#include "mpi.h"

#include <nlohmann/json.hpp>

#include <fstream>
#include <iostream>
#include <string>
#include <vector>

// Error if this is not a valid simulation type.
inline void validSimulationType(std::string simulation_type) {
if (simulation_type != "Directional" && simulation_type != "Spot" && simulation_type != "SingleGrain" &&
simulation_type != "FromFile" && simulation_type != "FromFinch")
throw std::runtime_error("Error: unknown problem type \"" + simulation_type + "\".");
}

// Structs to organize data within inputs struct
struct DomainInputs {
double deltax = 0.0, deltat = 0.0;
// number of CA cells in each direction only initialized here for problem types C, Spot, and SingleGrain
int nx = 0, ny = 0, nz = 0;
// multilayer problems only
int number_of_layers = 1, layer_height = 0;
// problem type Spot only
int spot_radius = 0;
};

struct NucleationInputs {
// unused for single grain problem type, zero by default
double n_max = 0.0;
double dtn = 0.0;
double dtsigma = 0.0;
};

struct InterfacialResponseInputs {
float freezing_range;
float A;
float B;
float C;
float D = 0.0;
enum IRFtypes {
cubic = 0,
quadratic = 1,
power = 2,
};
int function = cubic;
};

struct TemperatureInputs {
// Used for problem type R (by default, all temperature files read during init)
bool layerwise_temp_read = false;
int temp_files_in_series = 0;
std::vector<std::string> temp_paths;
// Use for problem types other than R (no temperature files to read) - default to no initial undercooling at
// solidification front
double G = 0, R = 0;
double init_undercooling = 0.0;
};

struct SubstrateInputs {
// problem type C only
std::string surface_init_mode = "";
// Only used for mode (i)
double fract_surface_sites_active = 0.0;
// Only used for mode (ii)
double surface_site_density = 0.0;
// Only used for mode (iii)
std::vector<int> grain_locations_x, grain_locations_y, grain_ids;
bool fill_bottom_surface = false;
// problem type SingleGrain only
int single_grain_orientation = 0;
// problem types Spot and R only
bool use_substrate_file = false;
bool baseplate_through_powder = false;
std::string substrate_filename = "";
double substrate_grain_spacing = 0.0;
// defaults to all sites in powder layer initialized with a new grain
double powder_active_fraction = 1.0;
// Top of baseplate assumed at Z = 0 if not otherwise given
double baseplate_top_z = 0.0;
// Initial size of octahedra during initialization of an active cell
float init_oct_size = 0.01;
};

struct PrintInputs {
// Base name of CA output
std::string base_filename = "";
// Path to CA output
std::string path_to_output = "";
// Names of output fields that can be printed to files during or at the end of a simulation
std::vector<std::string> fieldnames_key = {"GrainID",
"LayerID",
"GrainMisorientation",
"UndercoolingCurrent",
"UndercoolingSolidificationStart",
"MeltTimeStep",
"CritTimeStep",
"UndercoolingChange",
"CellType",
"DiagonalLength",
"SolidificationEventCounter",
"NumberOfSolidificationEvents"};
// Fields to be printed during a given layer
bool intralayer = false;
int intralayer_increment = 1;
bool intralayer_idle_frames = false;
bool intralayer_grain_id = false;
bool intralayer_layer_id = false;
bool intralayer_grain_misorientation = false;
bool intralayer_undercooling_current = false;
bool intralayer_undercooling_solidification_start = false;
bool intralayer_melt_time_step = false;
bool intralayer_crit_time_step = false;
bool intralayer_undercooling_change = false;
bool intralayer_cell_type = false;
bool intralayer_diagonal_length = false;
bool intralayer_solidification_event_counter = false;
bool intralayer_number_of_solidification_events = false;
// Fields to be printed at end of a layer
bool interlayer_full = false;
bool interlayer_current = false;
bool interlayer_grain_id = false;
bool interlayer_layer_id = false;
bool interlayer_grain_misorientation = false;
bool interlayer_undercooling_solidification_start = false;
bool interlayer_undercooling_current = false;
bool interlayer_melt_time_step = false;
bool interlayer_crit_time_step = false;
bool interlayer_undercooling_change = false;
bool interlayer_cell_type = false;
bool interlayer_diagonal_length = false;
bool interlayer_solidification_event_counter = false;
bool interlayer_number_of_solidification_events = false;
// True if intralayer_undercooling_solidification_start or interlayer_undercooling_solidification_start is true
bool store_solidification_start = false;
bool print_front_undercooling = false;
// List of layers following which the interlayer fields should be printed (will always include final layer of
// simulation)
std::vector<int> print_layer_number;

// Should binary be used for printing vtk data?
bool print_binary = false;

// Should the default RVE data for ExaConstit be printed? If so, with what size?
bool print_default_rve = false;
int rve_size = 0;
};

#endif
176 changes: 17 additions & 159 deletions src/CAinputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#ifndef EXACA_INPUTS_HPP
#define EXACA_INPUTS_HPP

#include "CAgrid.hpp"
#include "CAinfo.hpp"
#include "CAparsefiles.hpp"
#include "CAinputdata.hpp"
#include "CAtimers.hpp"

#include "mpi.h"
Expand All @@ -21,145 +22,6 @@
#include <string>
#include <vector>

// Structs to organize data within inputs struct
struct DomainInputs {
double deltax = 0.0, deltat = 0.0;
// number of CA cells in each direction only initialized here for problem types C, Spot, and SingleGrain
int nx = 0, ny = 0, nz = 0;
// multilayer problems only
int number_of_layers = 1, layer_height = 0;
// problem type Spot only
int spot_radius = 0;
};

struct NucleationInputs {
// unused for single grain problem type, zero by default
double n_max = 0.0;
double dtn = 0.0;
double dtsigma = 0.0;
};

struct InterfacialResponseInputs {
float freezing_range;
float A;
float B;
float C;
float D = 0.0;
enum IRFtypes {
cubic = 0,
quadratic = 1,
power = 2,
};
int function = cubic;
};

struct TemperatureInputs {
// Used for problem type R (by default, all temperature files read during init)
bool layerwise_temp_read = false;
int temp_files_in_series = 0;
std::vector<std::string> temp_paths;
// Use for problem types other than R (no temperature files to read) - default to no initial undercooling at
// solidification front
double G = 0, R = 0;
double init_undercooling = 0.0;
};

struct SubstrateInputs {
// problem type C only
std::string surface_init_mode = "";
// Only used for mode (i)
double fract_surface_sites_active = 0.0;
// Only used for mode (ii)
double surface_site_density = 0.0;
// Only used for mode (iii)
std::vector<int> grain_locations_x, grain_locations_y, grain_ids;
bool fill_bottom_surface = false;
// problem type SingleGrain only
int single_grain_orientation = 0;
// problem types Spot and R only
bool use_substrate_file = false;
bool baseplate_through_powder = false;
std::string substrate_filename = "";
double substrate_grain_spacing = 0.0;
// defaults to all sites in powder layer initialized with a new grain
double powder_active_fraction = 1.0;
// Top of baseplate assumed at Z = 0 if not otherwise given
double baseplate_top_z = 0.0;
// Initial size of octahedra during initialization of an active cell
float init_oct_size = 0.01;
};

struct PrintInputs {
// Base name of CA output
std::string base_filename = "";
// Path to CA output
std::string path_to_output = "";
// Names of output fields that can be printed to files during or at the end of a simulation
std::vector<std::string> fieldnames_key = {"GrainID",
"LayerID",
"GrainMisorientation",
"UndercoolingCurrent",
"UndercoolingSolidificationStart",
"MeltTimeStep",
"CritTimeStep",
"UndercoolingChange",
"CellType",
"DiagonalLength",
"SolidificationEventCounter",
"NumberOfSolidificationEvents"};
// Fields to be printed during a given layer
bool intralayer = false;
int intralayer_increment = 1;
bool intralayer_idle_frames = false;
bool intralayer_grain_id = false;
bool intralayer_layer_id = false;
bool intralayer_grain_misorientation = false;
bool intralayer_undercooling_current = false;
bool intralayer_undercooling_solidification_start = false;
bool intralayer_melt_time_step = false;
bool intralayer_crit_time_step = false;
bool intralayer_undercooling_change = false;
bool intralayer_cell_type = false;
bool intralayer_diagonal_length = false;
bool intralayer_solidification_event_counter = false;
bool intralayer_number_of_solidification_events = false;
// Fields to be printed at end of a layer
bool interlayer_full = false;
bool interlayer_current = false;
bool interlayer_grain_id = false;
bool interlayer_layer_id = false;
bool interlayer_grain_misorientation = false;
bool interlayer_undercooling_solidification_start = false;
bool interlayer_undercooling_current = false;
bool interlayer_melt_time_step = false;
bool interlayer_crit_time_step = false;
bool interlayer_undercooling_change = false;
bool interlayer_cell_type = false;
bool interlayer_diagonal_length = false;
bool interlayer_solidification_event_counter = false;
bool interlayer_number_of_solidification_events = false;
// True if intralayer_undercooling_solidification_start or interlayer_undercooling_solidification_start is true
bool store_solidification_start = false;
bool print_front_undercooling = false;
// List of layers following which the interlayer fields should be printed (will always include final layer of
// simulation)
std::vector<int> print_layer_number;

// Should binary be used for printing vtk data?
bool print_binary = false;

// Should the default RVE data for ExaConstit be printed? If so, with what size?
bool print_default_rve = false;
int rve_size = 0;
};

// Error if this is not a valid simulation type.
inline void validSimulationType(std::string simulation_type) {
if (simulation_type != "Directional" && simulation_type != "Spot" && simulation_type != "SingleGrain" &&
simulation_type != "FromFile" && simulation_type != "FromFinch")
throw std::runtime_error("Error: unknown problem type \"" + simulation_type + "\".");
}

struct Inputs {

std::string simulation_type = "", material_filename = "", grain_orientation_file = "";
Expand Down Expand Up @@ -671,17 +533,13 @@ struct Inputs {

// Print a log file for this ExaCA run in json file format, containing information about the run parameters used
// from the input file as well as the decomposition scheme
// Note: Passing external values for inputs like deltax that will later be stored in the grid class, with the grid
// class passed to this function
void printExaCALog(const int id, const int np, const int ny_local, const int y_offset, const double deltax,
const int number_of_layers, const int layer_height, const int nx, const int ny, const int nz,
Timers timers, const int cycle, const double x_min, const double x_max, const double y_min,
const double y_max, const double z_min, const double z_max, const float vol_fraction_nucleated) {
void printExaCALog(const int id, const int np, const int cycle, const Grid grid, Timers timers,
const float vol_fraction_nucleated) {

int *ny_local_allranks = new int[np];
int *y_offset_allranks = new int[np];
MPI_Gather(&ny_local, 1, MPI_INT, ny_local_allranks, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(&y_offset, 1, MPI_INT, y_offset_allranks, 1, MPI_INT, 0, MPI_COMM_WORLD);
std::vector<int> ny_local_allranks(np);
std::vector<int> y_offset_allranks(np);
MPI_Gather(&grid.ny_local, 1, MPI_INT, ny_local_allranks.data(), 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(&grid.y_offset, 1, MPI_INT, y_offset_allranks.data(), 1, MPI_INT, 0, MPI_COMM_WORLD);

if (id == 0) {
std::string FName = print.path_to_output + print.base_filename + ".json";
Expand All @@ -697,18 +555,18 @@ struct Inputs {
exaca_log << " \"SimulationType\": \"" << simulation_type << "\"," << std::endl;
exaca_log << " \"GrainOrientationFile\": \"" << grain_orientation_file << "\"," << std::endl;
exaca_log << " \"Domain\": {" << std::endl;
exaca_log << " \"Nx\": " << nx << "," << std::endl;
exaca_log << " \"Ny\": " << ny << "," << std::endl;
exaca_log << " \"Nz\": " << nz << "," << std::endl;
exaca_log << " \"CellSize\": " << deltax << "," << std::endl;
exaca_log << " \"Nx\": " << grid.nx << "," << std::endl;
exaca_log << " \"Ny\": " << grid.ny << "," << std::endl;
exaca_log << " \"Nz\": " << grid.nz << "," << std::endl;
exaca_log << " \"CellSize\": " << grid.deltax << "," << std::endl;
exaca_log << " \"TimeStep\": " << domain.deltat << "," << std::endl;
exaca_log << " \"XBounds\": [" << x_min << "," << x_max << "]," << std::endl;
exaca_log << " \"YBounds\": [" << y_min << "," << y_max << "]," << std::endl;
exaca_log << " \"ZBounds\": [" << z_min << "," << z_max << "]";
exaca_log << " \"XBounds\": [" << grid.x_min << "," << grid.x_max << "]," << std::endl;
exaca_log << " \"YBounds\": [" << grid.y_min << "," << grid.y_max << "]," << std::endl;
exaca_log << " \"ZBounds\": [" << grid.z_min << "," << grid.z_max << "]";
if (simulation_type == "FromFile") {
exaca_log << "," << std::endl;
exaca_log << " \"NumberOfLayers\": " << number_of_layers << "," << std::endl;
exaca_log << " \"LayerOffset\": " << layer_height;
exaca_log << " \"NumberOfLayers\": " << grid.number_of_layers << "," << std::endl;
exaca_log << " \"LayerOffset\": " << grid.layer_height;
}
else if (simulation_type == "Spot") {
exaca_log << "," << std::endl;
Expand Down
Loading
Loading