-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from streeve/heat_transfer
Add heat transfer
- Loading branch information
Showing
15 changed files
with
609 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"num_cells" : {"value": [49, 49, 49]}, | ||
"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}"}, | ||
"thermal_conductivity" : {"value": 387, "unit": "W/(m.K)"}, | ||
"specific_heat_capacity" : {"value": 385, "unit": "J/(kg.K)"}, | ||
"reference_temperature" : {"value": 100.0, "unit": "oC"}, | ||
"horizon" : {"value": 0.00615, "unit": "m"}, | ||
"final_time" : {"value": 8, "unit": "s"}, | ||
"timestep" : {"value": 0.02, "unit": "s", "note": "This timestep is too large for mechanics to be stable. Use thermal_deformation_heat_transfer.json instead if coupled thermomechanics is desired."}, | ||
"thermal_subcycle_steps" : {"value": 1}, | ||
"output_frequency" : {"value": 10}, | ||
"output_reference" : {"value": true} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
{ | ||
"num_cells" : {"value": [100, 30, 3]}, | ||
"system_size" : {"value": [1.0, 0.3, 0.03], "unit": "m"}, | ||
"density" : {"value": 3980, "unit": "kg/m^3"}, | ||
"elastic_modulus" : {"value": 370e+9, "unit": "Pa"}, | ||
"thermal_coefficient" : {"value": 7.5E-6, "unit": "oC^{-1}"}, | ||
"reference_temperature" : {"value": 20.0, "unit": "oC"}, | ||
"horizon" : {"value": 0.03, "unit": "m"}, | ||
"final_time" : {"value": 0.01, "unit": "s"}, | ||
"timestep" : {"value": 7.5E-7, "unit": "s"}, | ||
"output_frequency" : {"value": 100}, | ||
"output_reference" : {"value": true} | ||
"num_cells" : {"value": [101, 31, 3]}, | ||
"system_size" : {"value": [1.0, 0.3, 0.03], "unit": "m"}, | ||
"density" : {"value": 3980, "unit": "kg/m^3"}, | ||
"elastic_modulus" : {"value": 370e+9, "unit": "Pa"}, | ||
"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": 20.0, "unit": "oC"}, | ||
"horizon" : {"value": 0.03, "unit": "m"}, | ||
"final_time" : {"value": 0.01, "unit": "s"}, | ||
"timestep" : {"value": 7.5E-7, "unit": "s"}, | ||
"thermal_subcycle_steps": {"value": 100}, | ||
"output_frequency" : {"value": 100}, | ||
"output_reference" : {"value": true} | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/thermomechanics/inputs/thermal_deformation_heat_transfer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"num_cells" : {"value": [49, 49, 49]}, | ||
"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}"}, | ||
"thermal_conductivity" : {"value": 387, "unit": "W/(m.K)"}, | ||
"specific_heat_capacity" : {"value": 385, "unit": "J/(kg.K)"}, | ||
"reference_temperature" : {"value": 100.0, "unit": "oC"}, | ||
"horizon" : {"value": 0.00615, "unit": "m"}, | ||
"final_time" : {"value": 8, "unit": "s"}, | ||
"timestep" : {"value": 4.2e-07, "unit": "s"}, | ||
"thermal_subcycle_steps" : {"value": 5e+4}, | ||
"output_frequency" : {"value": 10}, | ||
"output_reference" : {"value": true} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
examples/thermomechanics/thermal_deformation_heat_transfer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/**************************************************************************** | ||
* 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 pseudo-1d cube. | ||
void thermalDeformationHeatTransferExample( 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 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 = | ||
std::make_shared<CabanaPD::Particles<memory_space, model_type, | ||
typename thermal_type::base_type>>( | ||
exec_space(), low_corner, high_corner, num_cells, halo_width ); | ||
|
||
// ==================================================== | ||
// 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::Elastic{}, *particles, delta, K, kappa, cp, | ||
alpha, temp0 ); | ||
|
||
// ==================================================== | ||
// Create solver | ||
// ==================================================== | ||
auto cabana_pd = CabanaPD::createSolverElastic<memory_space>( | ||
inputs, particles, force_model ); | ||
|
||
// ==================================================== | ||
// Boundary condition | ||
// ==================================================== | ||
// Temperature profile imposed on top and bottom surfaces | ||
double dy = particles->dx[1]; | ||
using plane_type = CabanaPD::RegionBoundary<CabanaPD::RectangularPrism>; | ||
|
||
// Top surface | ||
plane_type plane1( low_corner[0], high_corner[0], high_corner[1] - dy, | ||
high_corner[1] + dy, low_corner[2], high_corner[2] ); | ||
|
||
// Bottom surface | ||
plane_type plane2( low_corner[0], high_corner[0], low_corner[1] - dy, | ||
low_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 = { plane1, plane2 }; | ||
auto bc = CabanaPD::createBoundaryCondition( | ||
temp_bc, exec_space{}, *particles, planes, false, 1.0 ); | ||
|
||
// ==================================================== | ||
// Simulation run | ||
// ==================================================== | ||
cabana_pd->init( bc ); | ||
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 ); | ||
|
||
thermalDeformationHeatTransferExample( argv[1] ); | ||
|
||
Kokkos::finalize(); | ||
MPI_Finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.