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

Automate State Initialization #228

Merged
merged 13 commits into from
Sep 10, 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
109 changes: 109 additions & 0 deletions single-node-refactor/input-sgtm-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# num_dims: 3

dynamic_options:
time_final: 1.0
dt_min: 1.e-8
dt_max: 1.e-2
dt_start: 1.e-5
cycle_stop: 1


# mesh_options:
# source: file
# file_path: /var/tmp/repos/Fierro/fork/Fierro/testing/meshes/mesh_Sedov_8.geo

mesh_options:
source: generate
num_dims: 3
type: box
origin: [0.0, 0.0, 0.0]
length: [10.0, 10.0, 10.0]
num_elems: [10, 10, 10]


output_options:
timer_output_level: thorough
output_file_format: vtk
graphics_time_step: 1.0
# graphics_iteration_step: 10

solver_options:
- solver:
method: SGTM3D
# solver_vars:
# - blah
# - blah
# - blah

# boundary_conditions:
# # Tag X plane
# - boundary_condition:
# solver: SGH3D
# geometry: x_plane
# direction: x_dir
# value: 0.0
# type: reflected_velocity


# # Tag Y plane
# - boundary_condition:
# solver: SGH3D
# geometry: y_plane
# direction: y_dir
# value: 0.0
# type: reflected_velocity

# # Tag z plane
# - boundary_condition:
# solver: SGH3D
# geometry: z_plane
# direction: z_dir
# value: 0.0
# type: reflected_velocity



materials:
- material:
id: 0
eos_model_type: decoupled
eos_model: gamma_law_gas
# strength_model: none
q1: 1.0
q2: 1.333
q1ex: 1.0
q2ex: 1.333
eos_global_vars:
- 1.666666666666667
- 1.0E-14
- 1.0

regions:
- fill_volume:
type: global
material_id: 0
den: 1.0
sie: 1.e-10
velocity: cartesian
u: 0.0
v: 0.0
w: 0.0



# energy source initial conditions
# - fill_volume:
# type: sphere
# origin: [0.0, 0.0, 0.0]
# radius1: 0.0
# radius2: 0.1
# material_id: 0
# den: 1.0
# # ie: 0.25833839995946534
# sie: 61.67375002 # 963.652344
# velocity: cartesian
# u: 0.0
# v: 0.0
# w: 0.0


6 changes: 5 additions & 1 deletion single-node-refactor/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ add_subdirectory(Solvers/SGH_solver_3D)
include_directories(Solvers/SGH_solver_rz/include)
add_subdirectory(Solvers/SGH_solver_rz)

add_executable(Fierro main.cpp driver.cpp solver.cpp ${COMMON_Files} ${YAML_SRC_Files} ${SGH_3D_SRC_Files} ${SGH_RZ_SRC_Files})
# Add SGTM Solver
include_directories(Solvers/SGTM_solver_3D/include)
add_subdirectory(Solvers/SGTM_solver_3D)

add_executable(Fierro main.cpp driver.cpp solver.cpp ${COMMON_Files} ${YAML_SRC_Files} ${SGH_3D_SRC_Files} ${SGH_RZ_SRC_Files} ${SGTM_3D_SRC_Files})
target_link_libraries(Fierro PRIVATE matar Kokkos::kokkos)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/src/momentum.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/properties.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_execute.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/time_integration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_initialize.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_setup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sgh_solver_3D.h
PARENT_SCOPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,66 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define SGH3D_SOLVER_H

#include "solver.h"
#include "state.h"

// Forward declare structs
struct SimulationParameters_t;
struct Material_t;
struct Mesh_t;
struct BoundaryCondition_t;
struct State_t;
// struct State_t;
struct RegionFill_t;
struct RegionFill_host_t;
struct corners_in_mat_t;
// struct corners_in_mat_t;

using namespace mtr; // matar namespace


namespace SGH3D_State
{
// Node state to be initialized for the SGH solver
static const std::vector<node_state> required_node_state =
{
node_state::coords,
node_state::velocity,
node_state::mass,
node_state::temp // Note, remove this, unused WIP
};

// Gauss point state to be initialized for the SGH solver
static const std::vector<gauss_pt_state> required_gauss_pt_state =
{
gauss_pt_state::volume,
gauss_pt_state::divergence_velocity
};

// Material point state to be initialized for the SGH solver
static const std::vector<material_pt_state> required_material_pt_state =
{
material_pt_state::density,
material_pt_state::pressure,
material_pt_state::stress,
material_pt_state::sound_speed,
material_pt_state::mass,
material_pt_state::volume_fraction,
material_pt_state::specific_internal_energy,
material_pt_state::eroded_flag
};

// Material corner state to be initialized for the SGH solver
static const std::vector<material_corner_state> required_material_corner_state =
{
material_corner_state::force
};

// Corner state to be initialized for the SGH solver
static const std::vector<corner_state> required_corner_state =
{
corner_state::force,
corner_state::mass
};
}

/////////////////////////////////////////////////////////////////////////////
///
/// \class SGH3D
Expand All @@ -75,10 +122,7 @@ class SGH3D : public Solver
Material_t& Materials,
Mesh_t& mesh,
BoundaryCondition_t& Boundary,
State_t& State) const override
{
// stuff goes here
}
State_t& State) const override;

/////////////////////////////////////////////////////////////////////////////
///
Expand Down
18 changes: 16 additions & 2 deletions single-node-refactor/src/Solvers/SGH_solver_3D/src/sgh_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,18 @@ void SGH3D::execute(SimulationParameters_t& SimulationParamaters,

// Write initial state at t=0
printf("Writing outputs to file at %f \n", graphics_time);
mesh_writer.write_mesh(mesh, State, SimulationParamaters, time_value, graphics_times);
mesh_writer.write_mesh(
mesh,
State,
SimulationParamaters,
time_value,
graphics_times,
SGH3D_State::required_node_state,
SGH3D_State::required_gauss_pt_state,
SGH3D_State::required_material_pt_state);



graphics_time = time_value + graphics_dt_ival;

// loop over the max number of time integration cycles
Expand Down Expand Up @@ -360,7 +371,10 @@ void SGH3D::execute(SimulationParameters_t& SimulationParamaters,
State,
SimulationParamaters,
time_value,
graphics_times);
graphics_times,
SGH3D_State::required_node_state,
SGH3D_State::required_gauss_pt_state,
SGH3D_State::required_material_pt_state);

graphics_time = time_value + graphics_dt_ival;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**********************************************************************************************
© 2020. Triad National Security, LLC. All rights reserved.
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
Department of Energy/National Nuclear Security Administration. All rights in the program are
reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear
Security Administration. The Government is granted for itself and others acting on its behalf a
nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare
derivative works, distribute copies to the public, perform publicly and display publicly, and
to permit others to do so.
This program is open source under the BSD-3 License.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************************************/

#include "sgh_solver_3D.h"
#include "state.h"
#include "mesh.h"
#include "simulation_parameters.h"

void SGH3D::initialize(SimulationParameters_t& SimulationParamaters,
Material_t& Materials,
Mesh_t& mesh,
BoundaryCondition_t& Boundary,
State_t& State) const
{
int num_nodes = mesh.num_nodes;
int num_gauss_pts = mesh.num_elems;
int num_corners = mesh.num_corners;
int rk_num_bins = SimulationParamaters.dynamic_options.rk_num_stages;
int num_dim = mesh.num_dims;

State.node.initialize(rk_num_bins, num_nodes, num_dim, SGH3D_State::required_node_state);
State.GaussPoints.initialize(rk_num_bins, num_gauss_pts, num_dim, SGH3D_State::required_gauss_pt_state);
State.corner.initialize(num_corners, num_dim, SGH3D_State::required_corner_state);

// NOTE: Material points and material corners are initialize in sgh_setup after calculating the material->mesh maps

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "boundary_conditions.h"
#include "state.h"
#include "simulation_parameters.h"
#include "geometry_new.h"

/////////////////////////////////////////////////////////////////////////////
///
Expand Down Expand Up @@ -265,6 +266,9 @@ void SGH3D::setup(SimulationParameters_t& SimulationParamaters,

const size_t rk_num_bins = SimulationParamaters.dynamic_options.rk_num_bins;

// Calculate element volume
geometry::get_vol(State.GaussPoints.vol, State.node.coords, mesh);

// create temporary state fields
// Painting routine requires only 1 material per GaussPoint
DCArrayKokkos<double> GaussPoint_den(num_elems);
Expand Down Expand Up @@ -345,8 +349,8 @@ void SGH3D::setup(SimulationParameters_t& SimulationParamaters,
size_t num_corners_for_mat = num_elems_for_mat * mesh.num_nodes_in_elem;

State.MaterialToMeshMaps(mat_id).initialize(num_elems_for_mat);
State.MaterialPoints(mat_id).initialize(rk_num_bins, num_points_for_mat, 3); // aways 3D, even for 2D-RZ calcs
State.MaterialCorners(mat_id).initialize(num_corners_for_mat, mesh.num_dims);
State.MaterialPoints(mat_id).initialize(rk_num_bins, num_points_for_mat, mesh.num_dims, SGH3D_State::required_material_pt_state);
State.MaterialCorners(mat_id).initialize(num_corners_for_mat, mesh.num_dims, SGH3D_State::required_material_corner_state);
// zones are not used
} // end for mat_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/src/properties_rz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_execute_rz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/time_integration_rz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_setup_rz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sgh_initialize_rz.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sgh_solver_rz.h
PARENT_SCOPE
)
Loading
Loading