Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5473017
Draft of populating mesh connectivity by reading in file.
rchen20 Dec 10, 2025
d97757a
New data file format.
rchen20 Dec 10, 2025
41885c1
Remove inclusion of data hpp.
rchen20 Dec 10, 2025
22c50e9
Use formulas for hyperplanes per angle, interior faces, boundary face…
rchen20 Dec 19, 2025
b2436a6
Reading mesh connectivity from the file.
rchen20 Dec 31, 2025
e71154a
Cleaner data format, and add problem size to the data file.
rchen20 Dec 31, 2025
60c9047
Typos, fixes, relative path to data file.
rchen20 Jan 5, 2026
500ace8
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 5, 2026
188107c
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 6, 2026
9b6d8d7
Add mesh input file option to commandline.
rchen20 Jan 14, 2026
85918d5
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 14, 2026
5ac46d5
Remove debug prints.
rchen20 Jan 16, 2026
6839b05
Require --femsweep-mesh-file to be specified in order to run the FEMS…
rchen20 Jan 16, 2026
59d5291
Fix variable scope for loops, and convert while into for.
rchen20 Jan 16, 2026
2e5a100
Remove string cast.
rchen20 Jan 16, 2026
7e145cb
Helper function to read arrays from mesh file.
rchen20 Jan 16, 2026
dd434ee
Use stol instead of stoi.
rchen20 Jan 16, 2026
e95c474
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 16, 2026
c88fc53
File name is a member of femsweep.
rchen20 Jan 16, 2026
0a3a53a
Use sharedinteriorfaces instead of constant.
rchen20 Jan 16, 2026
062fec8
Lambda helper for reading one mesh parameter.
rchen20 Jan 21, 2026
0d4c8bc
Remove old mesh.
rchen20 Jan 21, 2026
8e36b91
New mesh file.
rchen20 Jan 21, 2026
e5327ec
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 21, 2026
c6724e0
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 22, 2026
286f1a3
Trigger CI.
rchen20 Jan 22, 2026
0f203ef
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 23, 2026
d620d95
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 23, 2026
24094d6
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Jan 27, 2026
c1df678
Merge branch 'develop' into task/chen59/femsweepmeshfile
rchen20 Feb 3, 2026
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
203 changes: 183 additions & 20 deletions src/apps/FEMSWEEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

#include "FEMSWEEP.hpp"
#include "FEMSWEEP_DATA.hpp"

#include "RAJA/RAJA.hpp"

#include "common/DataUtils.hpp"

#include <fstream>
#include <string>
#include <algorithm>
#include <cmath>

Expand All @@ -26,12 +27,88 @@ namespace apps
FEMSWEEP::FEMSWEEP(const RunParams& params)
: KernelBase(rajaperf::Apps_FEMSWEEP, params)
{
m_nx = 15;
m_ny = 15;
m_nz = 15;
m_mesh_file = params.getFemsweepMeshFile();

// Read problem size from file.
std::ifstream dataFile(m_mesh_file);

if ( !dataFile.is_open() )
{
std::cout << "Could not open " << m_mesh_file << " in constructor." << std::endl;
}

std::string line;
while ( std::getline(dataFile, line) )
{

if ( line == std::string("m_nx") )
{
// Read next line for value.
if ( std::getline(dataFile, line) )
{
m_nx = std::stol(line);
}
else
{
std::cout << "Unable to initialize m_nx properly in constructor. Please check the " << m_mesh_file << " file." << std::endl;
}
}

else if ( line == std::string("m_ny") )
{
// Read next line for value.
if ( std::getline(dataFile, line) )
{
m_ny = std::stol(line);
}
else
{
std::cout << "Unable to initialize m_ny properly in constructor. Please check the " << m_mesh_file << " file." << std::endl;
}
}

else if ( line == std::string("m_nz") )
{
// Read next line for value.
if ( std::getline(dataFile, line) )
{
m_nz = std::stol(line);
}
else
{
std::cout << "Unable to initialize m_nz properly in constructor. Please check the " << m_mesh_file << " file." << std::endl;
}
}

else if ( line == std::string("m_na") )
{
// Read next line for value.
if ( std::getline(dataFile, line) )
{
m_na = std::stol(line);
}
else
{
std::cout << "Unable to initialize m_na properly in constructor. Please check the " << m_mesh_file << " file." << std::endl;
}
}

else if ( line == std::string("m_ng") )
{
// Read next line for value.
if ( std::getline(dataFile, line) )
{
m_ng = std::stol(line);
}
else
{
std::cout << "Unable to initialize m_ng properly in constructor. Please check the " << m_mesh_file << " file." << std::endl;
}
}

}

m_ne = m_nx * m_ny * m_nz;
m_na = 72;
m_ng = 128;

setDefaultProblemSize(ND * m_ne * m_ng * m_na);
setDefaultReps(1);
Expand All @@ -53,10 +130,15 @@ FEMSWEEP::FEMSWEEP(const RunParams& params)

void FEMSWEEP::setSize(Index_type RAJAPERF_UNUSED_ARG(target_size), Index_type target_reps)
{
m_sharedinteriorfaces = (m_nx - 1) * m_ny * m_nz +
m_nx * (m_ny - 1) * m_nz +
m_nx * m_ny * (m_nz - 1);
m_boundaryfaces = 2 * m_nx * m_ny + 2 * m_ny * m_nz + 2 * m_nx * m_nz;
m_hplanes = m_nx + m_ny + m_nz - 2;

m_Blen = ND * m_ne * m_na;
m_Alen = ND * ND * m_ne * m_na;
// 9450 is a property of the mesh. Will need to derive this when mesh generator is available.
m_Flen = FDS * FDS * 2 * 9450 * m_na;
m_Flen = FDS * FDS * 2 * m_sharedinteriorfaces * m_na;
m_Sglen = m_ne * m_ng;
m_M0len = ND * ND * m_ne;
m_Xlen = ND * m_ne * m_ng * m_na;
Expand Down Expand Up @@ -88,6 +170,40 @@ FEMSWEEP::~FEMSWEEP()
{
}

template < typename T >
void FEMSWEEP::readIndexArray(VariantID vid, std::ifstream & file, T*& arr, Index_type expectedsize, std::string arrname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be a free function, probably in an unnamed namespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move it if some other kernel is going to use it, but I think the femsweep is the only one that requires something like this at the moment so I'll keep it the way it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just mean that it doesn't use any of the kernel's state, it could be a free function. Its not a big deal, but its probably best practice if that's true to make it a free function.

{
std::string line;

// Read next line for array size.
if ( std::getline(file, line) )
{
long sizetemp = std::stol(line);
// Check size for sanity.
if ( sizetemp != expectedsize )
{
std::cout << "Size of " << arrname << " in " << m_mesh_file << " does not match." << std::endl;
}
auto temp_arr = allocDataForInit(arr, sizetemp, vid);
// Read rest of entries for array.
for ( int lcount = 0; lcount < sizetemp; ++lcount )
{
if ( std::getline(file, line) )
{
arr[lcount] = std::stol(line);
}
else
{
std::cout << "Invalid entry in " << m_mesh_file << " for " << arrname << "." << std::endl;
}
}
}
else
{
std::cout << "Invalid size entry in " << m_mesh_file << " for " << arrname << "." << std::endl;
}
}

void FEMSWEEP::setUp(VariantID vid, size_t RAJAPERF_UNUSED_ARG(tune_idx))
{
allocAndInitDataRandValue (m_Bdat , m_Blen , vid);
Expand All @@ -97,18 +213,65 @@ void FEMSWEEP::setUp(VariantID vid, size_t RAJAPERF_UNUSED_ARG(tune_idx))
allocAndInitDataRandValue (m_M0dat , m_M0len , vid);
allocAndInitDataRandValue (m_Xdat , m_Xlen , vid);

// Some of the constants are properties of the mesh.
// Will need to derive these when mesh generator is available.
allocAndCopyHostData(m_nhpaa_r, g_nhpaa_r, m_na , vid);
allocAndCopyHostData(m_ohpaa_r, g_ohpaa_r, m_na , vid);
allocAndCopyHostData(m_phpaa_r, g_phpaa_r, m_na * 43 , vid);
allocAndCopyHostData(m_order_r, g_order_r, m_na * m_ne, vid);

allocAndCopyHostData(m_AngleElem2FaceType, g_AngleElem2FaceType, NLF * m_ne * m_na , vid);
allocAndCopyHostData(m_elem_to_faces , g_elem_to_faces , NLF * m_ne , vid);
allocAndCopyHostData(m_F_g2l , g_F_g2l , 10800 , vid);
allocAndCopyHostData(m_idx1 , g_idx1 , 37800 , vid);
allocAndCopyHostData(m_idx2 , g_idx2 , 37800 , vid);
// Read mesh connectivity data from file.
std::ifstream dataFile(m_mesh_file);

if ( !dataFile.is_open() )
{
std::cout << "Could not open " << m_mesh_file << " in setUp." << std::endl;
}

std::string line;
while ( std::getline(dataFile, line) )
{

if ( line == "m_nhpaa_r" )
{
readIndexArray(vid, dataFile, m_nhpaa_r, m_na, "m_nhpaa_r");
}

else if ( line == std::string("m_ohpaa_r") )
{
readIndexArray(vid, dataFile, m_ohpaa_r, m_na, "m_ohpaa_r");
}

else if ( line == std::string("m_phpaa_r") )
{
readIndexArray(vid, dataFile, m_phpaa_r, m_na * m_hplanes, "m_phpaa_r");
}

else if ( line == std::string("m_order_r") )
{
readIndexArray(vid, dataFile, m_order_r, m_na * m_ne, "m_order_r");
}

else if ( line == std::string("m_AngleElem2FaceType") )
{
readIndexArray(vid, dataFile, m_AngleElem2FaceType, NLF * m_na * m_ne, "m_AngleElem2FaceType");
}

else if ( line == std::string("m_elem_to_faces") )
{
readIndexArray(vid, dataFile, m_elem_to_faces, NLF * m_ne, "m_elem_to_faces");
}

else if ( line == std::string("m_F_g2l") )
{
readIndexArray(vid, dataFile, m_F_g2l, m_sharedinteriorfaces + m_boundaryfaces, "m_F_g2l");
}

else if ( line == std::string("m_idx1") )
{
readIndexArray(vid, dataFile, m_idx1, m_sharedinteriorfaces * 4, "m_idx1");
}

else if ( line == std::string("m_idx2") )
{
readIndexArray(vid, dataFile, m_idx2, m_sharedinteriorfaces * 4, "m_idx2");
}

}

}

void FEMSWEEP::updateChecksum(VariantID vid, size_t RAJAPERF_UNUSED_ARG(tune_idx))
Expand Down
40 changes: 19 additions & 21 deletions src/apps/FEMSWEEP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ class FEMSWEEP : public KernelBase
template < size_t block_size >
void runHipVariantImpl(VariantID vid);

template < typename T >
void readIndexArray(VariantID vid, std::ifstream & file, T*& arr, Index_type expectedsize, std::string arrname);

private:
#if defined(RAJA_ENABLE_HIP)
static const size_t default_gpu_block_size = 64;
Expand All @@ -308,31 +311,26 @@ class FEMSWEEP : public KernelBase
using gpu_block_sizes_type = integer::make_gpu_block_size_list_type<default_gpu_block_size,
integer::MultipleOf<32>>;

std::string m_mesh_file; // Path to file name of femsweep mesh.

Index_type m_nx;
Index_type m_ny;
Index_type m_nz;
Index_type m_ne;
Index_type m_na;
Index_type m_ng;

Index_type m_sharedinteriorfaces;
Index_type m_boundaryfaces;
Index_type m_hplanes;

Real_ptr m_Bdat;
Real_ptr m_Adat;
Real_ptr m_Fdat;
Real_ptr m_Sgdat;
Real_ptr m_M0dat;
Real_ptr m_Xdat;

Index_ptr m_nhpaa_r;
Index_ptr m_ohpaa_r;
Index_ptr m_phpaa_r;
Index_ptr m_order_r;

Index_ptr m_AngleElem2FaceType;
Index_ptr m_elem_to_faces ;
Index_ptr m_F_g2l ;
Index_ptr m_idx1 ;
Index_ptr m_idx2 ;

Index_type m_Blen;
Index_type m_Alen;
Index_type m_Flen;
Expand All @@ -352,16 +350,16 @@ class FEMSWEEP : public KernelBase
Index_type m_idx2len;

// Mesh data
static Index_type g_nhpaa_r[72];
static Index_type g_ohpaa_r[72];
static Index_type g_phpaa_r[3096];
static Index_type g_order_r[243000];

static Index_type g_AngleElem2FaceType[1458000];
static Index_type g_elem_to_faces[20250] ;
static Index_type g_F_g2l[10800] ;
static Index_type g_idx1[37800] ;
static Index_type g_idx2[37800] ;
Index_ptr m_nhpaa_r;
Index_ptr m_ohpaa_r;
Index_ptr m_phpaa_r;
Index_ptr m_order_r;

Index_ptr m_AngleElem2FaceType;
Index_ptr m_elem_to_faces ;
Index_ptr m_F_g2l ;
Index_ptr m_idx1 ;
Index_ptr m_idx2 ;
};

} // end namespace apps
Expand Down
Loading