Skip to content

Commit

Permalink
Added example of heat transfer in a pre-notched cube
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloseleson authored and streeve committed Jan 27, 2025
1 parent 4e15b57 commit 615d313
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 4 deletions.
8 changes: 7 additions & 1 deletion examples/thermomechanics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ target_link_libraries(ThermalCrack LINK_PUBLIC CabanaPD)
add_executable(ThermalDeformationHeatTransfer thermal_deformation_heat_transfer.cpp)
target_link_libraries(ThermalDeformationHeatTransfer LINK_PUBLIC CabanaPD)

install(TARGETS ThermalDeformation ThermalCrack ThermalDeformationHeatTransfer DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(ThermalCrackHeatTransfer thermal_crack_heat_transfer.cpp)
target_link_libraries(ThermalCrackHeatTransfer LINK_PUBLIC CabanaPD)

add_executable(ThermalDeformationHeatTransferPrenotched thermal_deformation_heat_transfer_prenotched.cpp)
target_link_libraries(ThermalDeformationHeatTransferPrenotched LINK_PUBLIC CabanaPD)

install(TARGETS ThermalDeformation ThermalCrack ThermalDeformationHeatTransfer ThermalCrackHeatTransfer ThermalDeformationHeatTransferPrenotched DESTINATION ${CMAKE_INSTALL_BINDIR})
3 changes: 2 additions & 1 deletion examples/thermomechanics/inputs/heat_transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"system_size" : {"value": [0.1, 0.1, 0.1], "unit": "m"},
"density" : {"value": 8915, "unit": "kg/m^3"},
"elastic_modulus" : {"value": 115e+9, "unit": "Pa"},
"thermal_expansion_coeff" : {"value": 17e-6, "unit": "oC^{-1}"},
"fracture_energy" : {"value": 1.3913e+04, "unit": "J/m^2"},
"thermal_expansion_coeff" : {"value": 0.0, "unit": "oC^{-1}"},
"thermal_conductivity" : {"value": 387, "unit": "W/(m.K)"},
"specific_heat_capacity" : {"value": 385, "unit": "J/(kg.K)"},
"reference_temperature" : {"value": 100.0, "unit": "oC"},
Expand Down
6 changes: 4 additions & 2 deletions examples/thermomechanics/inputs/thermal_crack.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"elastic_modulus" : {"value": 370e+9, "unit": "Pa"},
"fracture_energy" : {"value": 24.32, "unit": "J/m^2"},
"thermal_expansion_coeff" : {"value": 7.5E-6, "unit": "oC^{-1}"},
"thermal_conductivity" : {"value": 31, "unit": "W/(m.K)"},
"specific_heat_capacity" : {"value": 880, "unit": "J/(kg.K)"},
"reference_temperature" : {"value": 300.0, "unit": "oC"},
"background_temperature" : {"value": 20.0, "unit": "oC"},
"surface_temperature_ramp_time" : {"value": 0.001, "unit": "s"},
"horizon" : {"value": 3.0e-4, "unit": "m"},
"final_time" : {"value": 7.5e-4, "unit": "s"},
"timestep" : {"value": 7.5E-9, "unit": "s"},
"thermal_subcycle_steps" : {"value": 100},
"output_frequency" : {"value": 200},
"thermal_subcycle_steps" : {"value": 8e+4},
"output_frequency" : {"value": 500},
"output_reference" : {"value": true}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/****************************************************************************
* Copyright (c) 2022 by Oak Ridge National Laboratory *
* All rights reserved. *
* *
* This file is part of CabanaPD. CabanaPD is distributed under a *
* BSD 3-clause license. For the licensing terms see the LICENSE file in *
* the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#include <fstream>
#include <iostream>

#include "mpi.h"

#include <Kokkos_Core.hpp>

#include <CabanaPD.hpp>

// Simulate heat transfer in a pre-notched pseudo-1d cube.
void thermalDeformationHeatTransferPrenotchedExample(
const std::string filename )
{
// ====================================================
// Use default Kokkos spaces
// ====================================================
using exec_space = Kokkos::DefaultExecutionSpace;
using memory_space = typename exec_space::memory_space;

// ====================================================
// Read inputs
// ====================================================
CabanaPD::Inputs inputs( filename );

// ====================================================
// Material and problem parameters
// ====================================================
// Material parameters
double rho0 = inputs["density"];
double E = inputs["elastic_modulus"];
double nu = 0.25;
double K = E / ( 3 * ( 1 - 2 * nu ) );
double G0 = inputs["fracture_energy"];
double delta = inputs["horizon"];
double alpha = inputs["thermal_expansion_coeff"];
double kappa = inputs["thermal_conductivity"];
double cp = inputs["specific_heat_capacity"];

// Problem parameters
double temp0 = inputs["reference_temperature"];

// ====================================================
// Discretization
// ====================================================
// FIXME: set halo width based on delta
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
int m = std::floor( delta /
( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1; // Just to be safe.

// ====================================================
// Force model type
// ====================================================
using model_type = CabanaPD::PMB;
using thermal_type = CabanaPD::DynamicTemperature;

// ====================================================
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles =
CabanaPD::createParticles<memory_space, model_type, thermal_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
// Pre-notches
// ====================================================
// Number of pre-notches
constexpr int Npn = 2;

double height = inputs["system_size"][0];
double width = inputs["system_size"][1];
double thickness = inputs["system_size"][2];
double dy = particles->dx[1];

// Initialize pre-notch arrays
Kokkos::Array<Kokkos::Array<double, 3>, Npn> notch_positions;
Kokkos::Array<Kokkos::Array<double, 3>, Npn> notch_v1;
Kokkos::Array<Kokkos::Array<double, 3>, Npn> notch_v2;

// We intentionally translate the pre-notches vertically by 0.5 * dy
// to prevent particles from sitting exactly on the pre-notches.

// Pre-notch 1
Kokkos::Array<double, 3> p01 = { low_corner[0] + 0.25 * height,
low_corner[1] + 0.25 * height + 0.5 * dy,
low_corner[2] };
notch_positions[0] = p01;
Kokkos::Array<double, 3> v11 = { 0.5 * height, 0.5 * width, 0 };
notch_v1[0] = v11;
Kokkos::Array<double, 3> v2 = { 0, 0, thickness };
notch_v2[0] = v2;

// Pre-notch 2
Kokkos::Array<double, 3> p02 = { low_corner[0] + 0.25 * height,
high_corner[1] - 0.25 * height + 0.5 * dy,
low_corner[2] };
notch_positions[1] = p02;
Kokkos::Array<double, 3> v12 = { 0.5 * height, -0.5 * width, 0 };
notch_v1[1] = v12;
notch_v2[1] = v2;

CabanaPD::Prenotch<Npn> prenotch( notch_v1, notch_v2, notch_positions );

// ====================================================
// Custom particle initialization
// ====================================================
auto rho = particles->sliceDensity();
auto temp = particles->sliceTemperature();
auto init_functor = KOKKOS_LAMBDA( const int pid )
{
// Density
rho( pid ) = rho0;
// Temperature
temp( pid ) = temp0;
};
particles->updateParticles( exec_space{}, init_functor );

// ====================================================
// Force model
// ====================================================
auto force_model = CabanaPD::createForceModel(
model_type{}, CabanaPD::Fracture{}, *particles, delta, K, G0, kappa, cp,
alpha, temp0 );

// ====================================================
// Create solver
// ====================================================
auto cabana_pd =
CabanaPD::createSolver<memory_space>( inputs, particles, force_model );

// ====================================================
// Boundary condition
// ====================================================
// Temperature profile imposed on top surface
using plane_type = CabanaPD::RegionBoundary<CabanaPD::RectangularPrism>;

// Top surface
plane_type plane( low_corner[0], high_corner[0], high_corner[1] - dy,
high_corner[1] + dy, low_corner[2], high_corner[2] );

// This is purposely delayed until after solver init so that ghosted
// particles are correctly taken into account for lambda capture here.
temp = particles->sliceTemperature();
auto temp_bc = KOKKOS_LAMBDA( const int pid, const double )
{
temp( pid ) = 0.0;
};

std::vector<plane_type> planes = { plane };
auto bc = CabanaPD::createBoundaryCondition(
temp_bc, exec_space{}, *particles, planes, false, 1.0 );

// ====================================================
// Simulation run
// ====================================================
cabana_pd->init( bc, prenotch );
cabana_pd->run( bc );

// ====================================================
// Outputs
// ====================================================
// Output temperature along the y-axis
int profile_dim = 1;
auto value = KOKKOS_LAMBDA( const int pid ) { return temp( pid ); };
std::string file_name = "temperature_yaxis_profile.txt";
createOutputProfile( MPI_COMM_WORLD, num_cells[1], profile_dim, file_name,
*particles, value );
}

// Initialize MPI+Kokkos.
int main( int argc, char* argv[] )
{
MPI_Init( &argc, &argv );
Kokkos::initialize( argc, argv );

thermalDeformationHeatTransferPrenotchedExample( argv[1] );

Kokkos::finalize();
MPI_Finalize();
}

0 comments on commit 615d313

Please sign in to comment.