Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Merged since v2.5.0, not yet released.
required `parametersProperties` keys before writing. ([#179])
- A User Guide page on driving a simulation from NumPy arrays, with no
landscape file and no GIS. ([#189])
- `-DFOREFIRE_ENABLE_NETCDF=OFF` builds the engine without NetCDF or HDF5,
the first step towards a WebAssembly build and a slim wheel. Commands that
read or write NetCDF files report that the build has no NetCDF support.
The default stays on. ([#171])

### Fixed

Expand Down Expand Up @@ -248,3 +252,4 @@ repository stays easy to return to.
[#192]: https://github.com/forefireAPI/forefire/pull/192
[#203]: https://github.com/forefireAPI/forefire/pull/203
[#205]: https://github.com/forefireAPI/forefire/issues/205
[#171]: https://github.com/forefireAPI/forefire/issues/171
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ else()
endif()

option(FOREFIRE_ENABLE_MPI "Enable MPI coupling when MPI is available" ${_ff_default_mpi})
option(FOREFIRE_ENABLE_NETCDF "Build the NetCDF-backed I/O paths" ON)
option(FOREFIRE_NATIVE_ARCH "Optimise for the build machine's CPU (-march=native)" ${_ff_default_native})
option(FOREFIRE_BUILD_PYTHON "Build the pyforefire Python extension module" ${_ff_default_python})
option(FOREFIRE_STATIC_CORE "Build the ForeFire core as a static library" ${_ff_default_static})
Expand Down Expand Up @@ -137,7 +138,12 @@ endif()
# detection logic below lives in exactly one place.
add_library(forefire_netcdf INTERFACE)

if(DEFINED ENV{SRC_MESONH} AND DEFINED ENV{XYZ} AND DEFINED ENV{FF_STATIC})
if(NOT FOREFIRE_ENABLE_NETCDF)
# FF_NO_NETCDF compiles out every NetCDF-backed path; each entry point keeps
# a stub that reports the missing support (see DataBroker.h).
message(STATUS "NetCDF support disabled (FOREFIRE_ENABLE_NETCDF=OFF)")
target_compile_definitions(forefire_netcdf INTERFACE FF_NO_NETCDF)
elseif(DEFINED ENV{SRC_MESONH} AND DEFINED ENV{XYZ} AND DEFINED ENV{FF_STATIC})
message(STATUS "MESONH and XYZ environment variables are set. FF_STATIC too, static NetCDF.")
set(MESONH $ENV{SRC_MESONH})
set(XYZ $ENV{XYZ})
Expand Down
29 changes: 29 additions & 0 deletions src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace libforefire
{

size_t n = argCount(arg);
#ifndef FF_NO_NETCDF
// The two-argument form reads the domain extent out of a MesoNH PGD
// file, so it exists only where NetCDF does.
if (n == 2)
{

Expand Down Expand Up @@ -176,6 +179,7 @@ namespace libforefire

}
}
#endif /* FF_NO_NETCDF */
if (n >= 3)
{
FFPoint SW = getPoint("sw", arg);
Expand Down Expand Up @@ -2502,6 +2506,18 @@ namespace libforefire
return normal;
}

#ifdef FF_NO_NETCDF

// saveData writes a landscape file, which is NetCDF end to end; there is no
// partial behaviour to keep when NetCDF is compiled out.
int Command::saveData(const std::string &arg, size_t &numTabs)
{
std::cout << "saveData: this build has no NetCDF support" << std::endl;
return error;
}

#else

int Command::saveData(const std::string &arg, size_t &numTabs)
{
// Check for an argument
Expand Down Expand Up @@ -2836,6 +2852,8 @@ namespace libforefire
}
}

#endif /* FF_NO_NETCDF */

int Command::loadData(const string &arg, size_t &numTabs)
{

Expand Down Expand Up @@ -2865,6 +2883,11 @@ namespace libforefire
if (args.size() == 2)
{

#ifdef FF_NO_NETCDF
cout << "loadData: reading a domain from " << path
<< " needs NetCDF, which this build has no support for" << endl;
return error;
#else
simParam->setParameter("NetCDFfile", args[0]);
try
{
Expand Down Expand Up @@ -2950,6 +2973,7 @@ namespace libforefire
}

ExecuteCommand(com);
#endif /* FF_NO_NETCDF */
}
if (args.size() == 1)
{
Expand Down Expand Up @@ -3710,6 +3734,10 @@ namespace libforefire

void Command::writeNetCDF(const char *filename, const string &varName, const std::vector<std::vector<double>> &matrix, const vector<double> &latitudes, const vector<double> &longitudes)
{
#ifdef FF_NO_NETCDF
std::cerr << "writeNetCDF: this build has no NetCDF support, "
<< filename << " not written" << std::endl;
#else
try
{
// Create (or replace) the NetCDF file using NetCDF-4 mode.
Expand Down Expand Up @@ -3753,6 +3781,7 @@ namespace libforefire
{
std::cerr << "Error writing NetCDF file: " << e.what() << std::endl;
}
#endif /* FF_NO_NETCDF */
}
void Command::writeASCII(const char *filename, const std::vector<std::vector<double>> &matrix, double SWX, double SWY, double NEX, double NEY)
{
Expand Down
15 changes: 15 additions & 0 deletions src/DataBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,19 @@ namespace libforefire
}
}

#ifdef FF_NO_NETCDF

void DataBroker::loadFromNCFile(std::string filename)
{
// The empty-filename early return matches the NetCDF path: the command
// layer calls this with no file on every session setup.
if (filename.empty()) return;
cout << "loadFromNCFile: this build has no NetCDF support, ignoring "
<< filename << endl;
}

#else

void DataBroker::loadFromNCFile(std::string filename)
{
if(filename.empty())
Expand Down Expand Up @@ -1682,4 +1695,6 @@ namespace libforefire
return data;
}

#endif /* FF_NO_NETCDF */

}
8 changes: 8 additions & 0 deletions src/DataBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
#include "FFArrays.h"
#include "ParallelData.h"
#include "SimulationParameters.h"
// FF_NO_NETCDF drops every NetCDF-backed code path. The umbrella header is
// included in exactly this one place, and the `using namespace` below drags it
// into every translation unit that reaches DataBroker.h, so the guard here is
// what makes a NetCDF-free build (Emscripten, slim wheels) possible at all.
#ifndef FF_NO_NETCDF
#include <netcdf>
using namespace netCDF;
using namespace netCDF::exceptions;
#endif

using namespace std;

Expand Down Expand Up @@ -205,6 +211,7 @@ class DataBroker {
bool isRelevantData(FFPoint&, FFPoint&);


#ifndef FF_NO_NETCDF
/*! \brief loading a NCXYZTDataLayer from an NcFile */
XYZTDataLayer<double>* constructXYZTLayer(NcVar&, FFPoint&, FFPoint&,double , double , int );
/*! \brief loading a FuelDataLayer from an NcFile */
Expand All @@ -216,6 +223,7 @@ class DataBroker {
/*! \transpose data from fortran netcdf*/
double* readAndTransposeFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t& ,bool , int );
int* readAndTransposeIntFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t&, bool , int );
#endif

public:

Expand Down
16 changes: 16 additions & 0 deletions src/FireDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3460,6 +3460,20 @@



#ifdef FF_NO_NETCDF

void FireDomain::loadArrivalTimeNC(string fname){
cout << "loadArrivalTimeNC: this build has no NetCDF support, ignoring "
<< fname << endl;
}

void FireDomain::saveArrivalTimeNC(){
cout << "saveArrivalTimeNC: this build has no NetCDF support, "
"nothing written" << endl;
}

#else

void FireDomain::loadArrivalTimeNC(string fname){
if (getDomainID()!=0) return;

Expand Down Expand Up @@ -3598,6 +3612,8 @@
}


#endif /* FF_NO_NETCDF */

void FireDomain::visualizeBurningMatrixAroundNode(FireNode* fn){
if( !striclyWithinDomain(fn) ) return;
/* Position of the firenode in the burning matrix */
Expand Down
Loading