Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f5e136
dfMatrixDataBase
maorz1998 Aug 1, 2023
a59a190
add unittest of fvm::div(phi, U)
STwangyingrui Aug 2, 2023
1b25756
simplify unittest
STwangyingrui Aug 3, 2023
cbd7b49
add initial version of GPU new UEqn
STwangyingrui Aug 3, 2023
be72eb0
small fix of fvm_div_boundary
STwangyingrui Aug 4, 2023
7be1190
modify fvm_div_scalar to fvm_div_vector
STwangyingrui Aug 4, 2023
196f22a
implement fvm::ddt(rho, U) and add unittest for it
STwangyingrui Aug 4, 2023
4606238
implement fvm::laplacian(gamma, U) and add unittest for it; fix sever…
STwangyingrui Aug 7, 2023
cc7223d
implement fvc::ddt(rho, K) and add unittest for it; fix several old b…
STwangyingrui Aug 7, 2023
15e30b4
workaround to fix a bug of floating-point numerical error for fvc_ddt
STwangyingrui Aug 7, 2023
a8c68c6
fix occasional errors of fvm fvm::ddt and fvc::ddt: caused by re-usin…
STwangyingrui Aug 7, 2023
2453037
workaround way two (use volatile) to avoid floating-point numerical e…
STwangyingrui Aug 7, 2023
ae31072
workaround way three (use nvcc option -fmad=false) to avoid floating-…
STwangyingrui Aug 7, 2023
b16100f
use template to simplify unittest
STwangyingrui Aug 7, 2023
8b3805f
modify getTypeInfo to support tensor type
STwangyingrui Aug 7, 2023
776aa69
first commit for debugging
maorz1998 Aug 9, 2023
4ee65cc
fvc op & CPU op
maorz1998 Aug 11, 2023
7e29a10
add the comparison with the original method
maorz1998 Aug 12, 2023
db5a689
run pass basic ueqn_gpu
STwangyingrui Aug 15, 2023
04d5512
fvc/fvm ops support sign
STwangyingrui Aug 15, 2023
cbb74cd
use cuda graph in ueqn
STwangyingrui Aug 15, 2023
50eee68
fix bugs in turbulence term
maorz1998 Aug 16, 2023
f691478
primiry opt & add time monitor
maorz1998 Aug 17, 2023
7a7accf
add solve part, fix some bugs
maorz1998 Aug 21, 2023
d684488
modify app
maorz1998 Aug 21, 2023
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
646 changes: 646 additions & 0 deletions GPUTest/GPUTestBase.H

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions GPUTest/GPUTestRefBase.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

// unittest of fvc::grad(U)
void test_fvc_grad_vector_orig(dfMatrixDataBase& dfDataBase, Foam::fvMesh& mesh, volVectorField& U, initType type,
dfMatrixDataBaseOrig* dfDataBaseOrig)
{
if (type == initType::randomInit) {
U.oldTime();
randomInitField<volVectorField>(U);
}

// run CPU
// volTensorField fvc_ouput_tensor = fvc::grad(U);
volTensorField fvc_ouput_tensor = gaussGradSchemeGrad(U);

// prepare for run GPU
// prepare U on GPU
uploadRegisteredField<volVectorField>(dfDataBase, U, "u");

double *d_fvc_ouput_tensor = nullptr, *d_fvc_ouput_boundary_tensor = nullptr, *d_fvc_ouput_boundary_tensor_init = nullptr;
checkCudaErrors(cudaMalloc((void**)&d_fvc_ouput_tensor, dfDataBase.cell_value_tsr_bytes));
checkCudaErrors(cudaMalloc((void**)&d_fvc_ouput_boundary_tensor, dfDataBase.boundary_surface_value_tsr_bytes));
checkCudaErrors(cudaMalloc((void**)&d_fvc_ouput_boundary_tensor_init, dfDataBase.boundary_surface_value_tsr_bytes));
checkCudaErrors(cudaMemset(d_fvc_ouput_tensor, 0, dfDataBase.cell_value_tsr_bytes));
checkCudaErrors(cudaMemset(d_fvc_ouput_boundary_tensor, 0, dfDataBase.boundary_surface_value_tsr_bytes));
checkCudaErrors(cudaMemset(d_fvc_ouput_boundary_tensor_init, 0, dfDataBase.boundary_surface_value_tsr_bytes));

fvc_grad_vector_orig(dfDataBase.stream, dfDataBaseOrig, dfDataBase, d_fvc_ouput_tensor, d_fvc_ouput_boundary_tensor_init, d_fvc_ouput_boundary_tensor);

// compare result
bool printFlag = false;
std::vector<double> h_fvc_ouput_tensor(dfDataBase.num_cells * 9);
checkCudaErrors(cudaMemcpy(h_fvc_ouput_tensor.data(), d_fvc_ouput_tensor, dfDataBase.cell_value_tsr_bytes, cudaMemcpyDeviceToHost));
checkVectorEqual(dfDataBase.num_cells * 9, &fvc_ouput_tensor[0][0], h_fvc_ouput_tensor.data(), 1e-14, printFlag);
}

void test_fvc_grad_scalar_orig(dfMatrixDataBase& dfDataBase, Foam::fvMesh& mesh, volScalarField& p, initType type,
dfMatrixDataBaseOrig* dfDataBaseOrig)
{
if (type == initType::randomInit) {
p.oldTime();
randomInitField<volScalarField>(p);
}

// run CPU
// volVectorField fvc_ouput_vector = fvc::grad(p);
volVectorField fvc_ouput_vector = gaussGradSchemeGrad(p);

// prepare for run GPU
// prepare p on GPU
uploadRegisteredField<volScalarField>(dfDataBase, p, "p");

double *d_fvc_ouput_vector = nullptr;
checkCudaErrors(cudaMalloc((void**)&d_fvc_ouput_vector, dfDataBase.cell_value_vec_bytes));
checkCudaErrors(cudaMemset(d_fvc_ouput_vector, 0, dfDataBase.cell_value_vec_bytes));

fvc_grad_scalar_orig(dfDataBase.stream, dfDataBaseOrig, dfDataBase, d_fvc_ouput_vector);

// compare result
bool printFlag = false;
std::vector<double> h_fvc_ouput_vector(dfDataBase.num_cells * 3);
checkCudaErrors(cudaMemcpy(h_fvc_ouput_vector.data(), d_fvc_ouput_vector, dfDataBase.cell_value_vec_bytes, cudaMemcpyDeviceToHost));
checkVectorEqual(dfDataBase.num_cells * 3, &fvc_ouput_vector[0][0], h_fvc_ouput_vector.data(), 1e-14, printFlag);
}
4 changes: 4 additions & 0 deletions GPUTest/Make/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unittest.C

EXE = $(DF_APPBIN)/unitTest

50 changes: 50 additions & 0 deletions GPUTest/Make/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-include $(GENERAL_RULES)/mplibType

EXE_INC = -std=c++14 \
-g \
-fopenmp \
-Wno-unused-variable \
-Wno-unused-but-set-variable \
-Wno-old-style-cast \
$(PFLAGS) $(PINC) \
$(if $(LIBTORCH_ROOT),-DUSE_LIBTORCH,) \
$(if $(PYTHON_INC_DIR),-DUSE_PYTORCH,) \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/finiteVolume/cfdTools \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude \
-I$(LIB_SRC)/Pstream/mpi \
-I$(DF_SRC)/dfCanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(DF_SRC)/dfCombustionModels/lnInclude \
-I$(CANTERA_ROOT)/include \
-I$(DF_ROOT)/src_gpu \
-I$(DF_ROOT)/src_gpu_orig \
-I$(DF_ROOT)/GPUTestRef/lnInclude \
-I/usr/local/cuda-11.6/include \
-I$(AMGX_DIR)/include

EXE_LIBS = \
-lcompressibleTransportModels \
-lturbulenceModels \
-lfiniteVolume \
-lmeshTools \
-lsampling \
-L$(DF_LIBBIN) \
-ldfFluidThermophysicalModels \
-ldfCompressibleTurbulenceModels \
-ldfCanteraMixture \
-ldfChemistryModel \
-ldfCombustionModels \
-ldfGenMatrix \
$(CANTERA_ROOT)/lib/libcantera.so \
/usr/local/cuda-11.6/lib64/libcudart.so \
$(AMGX_DIR)/build/libamgxsh.so \
$(DF_ROOT)/src_gpu/build/libdfMatrix.so \
$(DF_ROOT)/src_gpu_orig/build/libdfMatrixOrig.so

12 changes: 12 additions & 0 deletions GPUTest/correctPhi.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CorrectPhi
(
U,
phi,
p,
rho,
psi,
dimensionedScalar("rAUf", dimTime, 1),
divrhoU(),
pimple,
true
);
176 changes: 176 additions & 0 deletions GPUTest/createFields.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#include "createRDeltaT.H"

Info<< "Reading thermophysical properties\n" << endl;

// fluidThermo* pThermo = new hePsiThermo<psiThermo, CanteraMixture>(mesh, word::null);
fluidThermo* pThermo = new heRhoThermo<rhoThermo, CanteraMixture>(mesh, word::null);
fluidThermo& thermo = *pThermo;
// thermo.validate(args.executable(), "ha");

const volScalarField& psi = thermo.psi();
volScalarField& p = thermo.p();
volScalarField& T = thermo.T();
volScalarField rho
(
IOobject
(
"rho",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
thermo.rho()
);


Info<< "Reading field U\n" << endl;
volVectorField U
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

#include "compressibleCreatePhi.H"

pressureControl pressureControl(p, rho, pimple.dict(), false);

mesh.setFluxRequired(p.name());

Info<< "Creating turbulence model\n" << endl;
autoPtr<compressible::turbulenceModel> turbulence
(
compressible::turbulenceModel::New
(
rho,
U,
phi,
thermo
)
);

Info<< "Creating field dpdt\n" << endl;
volScalarField dpdt
(
IOobject
(
"dpdt",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("dpdt",p.dimensions()/dimTime, 0)
);


Info<< "Creating reaction model\n" << endl;
autoPtr<CombustionModel<basicThermo>> combustion
(
CombustionModel<basicThermo>::New(thermo, turbulence())
);
Info<< "end Creating reaction model\n" << endl;


const word combModelName(mesh.objectRegistry::lookupObject<IOdictionary>("combustionProperties").lookup("combustionModel"));
Info << "Combustion Model Name is confirmed as "<< combModelName << endl;

const word turbName(mesh.objectRegistry::lookupObject<IOdictionary>("turbulenceProperties").lookup("simulationType"));

dfChemistryModel<basicThermo>* chemistry = combustion->chemistry();
PtrList<volScalarField>& Y = chemistry->Y();
const word inertSpecie(chemistry->lookup("inertSpecie"));
const label inertIndex(chemistry->species()[inertSpecie]);
chemistry->setEnergyName("ha");
chemistry->updateEnergy();


chemistry->correctThermo();
Info<< "At initial time, min/max(T) = " << min(T).value() << ", " << max(T).value() << endl;

//for dpdt

Info<< "Creating field kinetic energy K\n" << endl;
volScalarField K("K", 0.5*magSqr(U));

multivariateSurfaceInterpolationScheme<scalar>::fieldTable fields;

if(combModelName!="flareFGM")
{
forAll(Y, i)
{
fields.add(Y[i]);
}
fields.add(thermo.he());
}


const scalar Sct = chemistry->lookupOrDefault("Sct", 1.);
volScalarField diffAlphaD
(
IOobject
(
"diffAlphaD",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar(dimEnergy/dimTime/dimVolume, 0)
);
volVectorField hDiffCorrFlux
(
IOobject
(
"hDiffCorrFlux",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedVector(dimensionSet(1,0,-3,0,0,0,0), Zero)
);
volVectorField sumYDiffError
(
IOobject
(
"sumYDiffError",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedVector("sumYDiffError", dimDynamicViscosity/dimLength, Zero)
);

IOdictionary CanteraTorchProperties
(
IOobject
(
"CanteraTorchProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
const Switch splitting = CanteraTorchProperties.lookupOrDefault("splittingStrategy", false);
#ifdef USE_PYTORCH
const Switch log_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("log", false);
const Switch torch_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("torch", false);
#endif
#ifdef USE_LIBTORCH
const Switch log_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("log", false);
const Switch torch_ = CanteraTorchProperties.subDict("TorchSettings").lookupOrDefault("torch", false);
#endif
Loading