Skip to content

Commit 6f6357b

Browse files
authored
Migrate to header-only yaml (#143)
* Add FKYAML * Port configreader * Remove yaml-cpp dependency * Remove yaml-cpp from CI * Revert Makefile change
1 parent 59252a9 commit 6f6357b

File tree

8 files changed

+14720
-42
lines changed

8 files changed

+14720
-42
lines changed

.github/workflows/request-deb-package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
apt update
5555
apt -y upgrade
5656
apt -y install git build-essential lsb-release cmake libeigen3-dev libxml2-dev libboost-all-dev python3-dev python3-numpy petsc-dev sed
57-
apt -y install libarpack2-dev libspooles-dev libyaml-cpp-dev
57+
apt -y install libarpack2-dev libspooles-dev
5858
- name: Install preCICE
5959
uses: precice/setup-precice-action@main
6060
with:

.github/workflows/ubuntu_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
ref: ${{ github.ref }}
4141
- name: install dependencies
42-
run: sudo apt install libarpack2-dev libspooles-dev libyaml-cpp-dev -y
42+
run: sudo apt install libarpack2-dev libspooles-dev -y
4343
- name: Download CalculiX
4444
run: wget http://www.dhondt.de/ccx_2.20.src.tar.bz2
4545
- name: Unpack Calculix

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repos:
55
hooks:
66
- id: clang-format
77
files: "^adapter"
8+
exclude: "^adapter/fkYAML.hpp"
89
# Official repo for default hooks
910
- repo: https://github.com/pre-commit/pre-commit-hooks
1011
rev: 'v4.3.0'

Makefile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CCX_VERSION = 2.20
66
CCX = $(HOME)/CalculiX/ccx_$(CCX_VERSION)/src
77

8-
### Change these if you built SPOOLES, ARPACK, or yaml-cpp from source ###
8+
### Change these if you built SPOOLES, or ARPACK from source ###
99
# SPOOLES include flags (e.g. -I$(HOME)/SPOOLES.2.2 )
1010
SPOOLES_INCLUDE = -I/usr/include/spooles/
1111
# SPOOLES library flags (e.g. $(HOME)/SPOOLES.2.2/spooles.a)
@@ -15,11 +15,6 @@ SPOOLES_LIBS = -lspooles
1515
ARPACK_INCLUDE =
1616
# ARPACK library flags (e.g. $(HOME)/ARPACK/libarpack_INTEL.a)
1717
ARPACK_LIBS = -larpack -llapack -lblas
18-
#
19-
# yaml-cpp include flags (e.g. -I$(HOME)/yaml-cpp/include)
20-
YAML_INCLUDE = -I/usr/include/
21-
# yaml-cpp library flags (e.g. -L$(HOME)/yaml-cpp/build -lyaml-cpp)
22-
YAML_LIBS = -lyaml-cpp
2318

2419
# Get the CFLAGS and LIBS from pkg-config (preCICE version >= 1.4.0).
2520
# If pkg-config cannot find the libprecice.pc meta-file, you may need to set the
@@ -37,22 +32,20 @@ INCLUDES = \
3732
-I$(CCX) \
3833
$(SPOOLES_INCLUDE) \
3934
$(PKGCONF_CFLAGS) \
40-
$(ARPACK_INCLUDE) \
41-
$(YAML_INCLUDE)
35+
$(ARPACK_INCLUDE)
4236

4337
LIBS = \
4438
$(SPOOLES_LIBS) \
4539
$(PKGCONF_LIBS) \
4640
-lstdc++ \
47-
$(YAML_LIBS) \
4841
$(ARPACK_LIBS) \
4942
-lpthread -lm -lc
5043

5144
# Compilers and flags
5245
#CFLAGS = -g -Wall -std=c++11 -O0 -fopenmp $(INCLUDES) -DARCH="Linux" -DSPOOLES -DARPACK -DMATRIXSTORAGE
5346
#FFLAGS = -g -Wall -O0 -fopenmp $(INCLUDES)
5447

55-
CFLAGS = -Wall -O3 -fopenmp $(INCLUDES) -DARCH="Linux" -DSPOOLES -DARPACK -DMATRIXSTORAGE -DUSE_MT
48+
CFLAGS = -Wall -O3 -fopenmp $(INCLUDES) -DARCH="Linux" -DSPOOLES -DARPACK -DMATRIXSTORAGE -DUSE_MT -Wno-implicit-function-declaration
5649

5750
# OS-specific options
5851
UNAME_S := $(shell uname -s)
@@ -62,7 +55,7 @@ else
6255
CC = mpicc
6356
endif
6457

65-
FFLAGS = -Wall -O3 -fopenmp $(INCLUDES) ${ADDITIONAL_FFLAGS}
58+
FFLAGS = -Wall -O3 -fopenmp $(INCLUDES) ${ADDITIONAL_FFLAGS} -Wno-implicit-function-declaration
6659
# Note for GCC 10 or newer: add -fallow-argument-mismatch in the above flags
6760
FC = mpifort
6861
# FC = mpif90

Makefile_i8_PaStiX

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Path to original CalculiX source (e.g. $(HOME)/ccx_2.20/src )
55
CCX = $(HOME)/CalculiX/ccx_2.20/src
66

7-
### Change these if you built SPOOLES, ARPACK, or yaml-cpp from source ###
7+
### Change these if you built SPOOLES, or ARPACK from source ###
88
# SPOOLES include flags (e.g. -I$(HOME)/SPOOLES.2.2 )
99
SPOOLES_INCLUDE = -I/usr/include/spooles/
1010
# SPOOLES library flags (e.g. $(HOME)/SPOOLES.2.2/spooles.a)
@@ -15,11 +15,6 @@ ARPACK_INCLUDE =
1515
# ARPACK library flags (e.g. $(HOME)/ARPACK/libarpack_INTEL.a)
1616
ARPACK_LIBS = $(HOME)/ARPACK/libarpack_INTEL.a
1717
#ARPACK_LIBS = -larpack -llapack -lblas
18-
#
19-
# yaml-cpp include flags (e.g. -I$(HOME)/yaml-cpp/include)
20-
YAML_INCLUDE = -I/usr/include/
21-
# yaml-cpp library flags (e.g. -L$(HOME)/yaml-cpp/build -lyaml-cpp)
22-
YAML_LIBS = -lyaml-cpp
2318

2419
# Get the CFLAGS and LIBS from pkg-config (preCICE version >= 1.4.0).
2520
# If pkg-config cannot find the libprecice.pc meta-file, you may need to set the
@@ -49,14 +44,12 @@ INCLUDES = \
4944
$(SPOOLES_INCLUDE) \
5045
$(PKGCONF_CFLAGS) \
5146
$(ARPACK_INCLUDE) \
52-
$(YAML_INCLUDE) \
5347
$(PASTIX_INCLUDE)
5448

5549
LIBS = \
5650
$(SPOOLES_LIBS) \
5751
$(PKGCONF_LIBS) \
5852
-lstdc++ \
59-
$(YAML_LIBS) \
6053
$(ARPACK_LIBS) \
6154
-lpthread -lm -lc \
6255
$(PASTIX_LIBS) \
@@ -102,7 +95,7 @@ $(OBJDIR)/%.o : %.f
10295
$(OBJDIR)/%.o : adapter/%.c
10396
$(CC) $(CFLAGS) -c $< -o $@
10497
$(OBJDIR)/%.o : adapter/%.cpp
105-
g++ -std=c++11 $(YAML_INCLUDE) -c $< -o $@ $(LIBS)
98+
g++ -std=c++11 -c $< -o $@ $(LIBS)
10699
#$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ $(LIBS)
107100

108101
# Source files in the $(CCX) folder

adapter/ConfigReader.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
#include <cassert>
1313
#include <cstdlib>
1414
#include <cstring>
15-
#include <iostream>
15+
#include <fstream>
1616
#include <iterator>
1717
#include "ConfigReader.h"
18-
#include "yaml-cpp/yaml.h"
18+
#include "fkYAML.hpp"
19+
20+
fkyaml::node load_yaml(char const *configFilename)
21+
{
22+
std::ifstream ifs(configFilename);
23+
return fkyaml::node::deserialize(ifs);
24+
}
1925

2026
void ConfigReader_Read(char const *configFilename, char const *participantName, AdapterConfig *adapterConfig)
2127
{
22-
YAML::Node config = YAML::LoadFile(configFilename);
28+
auto config = load_yaml(configFilename);
2329

24-
adapterConfig->preciceConfigFilename = strdup(config["precice-config-file"].as<std::string>().c_str());
30+
adapterConfig->preciceConfigFilename = strdup(config["precice-config-file"].get_value<std::string>().c_str());
2531

2632
int numInterfaces = config["participants"][participantName]["interfaces"].size();
2733
adapterConfig->numInterfaces = numInterfaces;
@@ -33,61 +39,61 @@ void ConfigReader_Read(char const *configFilename, char const *participantName,
3339
new (currentInterfacePointer) InterfaceConfig();
3440
InterfaceConfig &interface = *currentInterfacePointer;
3541

36-
if (config["participants"][participantName]["interfaces"][i]["nodes-mesh"]) {
37-
interface.nodesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["nodes-mesh"].as<std::string>().c_str());
42+
if (config["participants"][participantName]["interfaces"][i].contains("nodes-mesh")) {
43+
interface.nodesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["nodes-mesh"].get_value<std::string>().c_str());
3844
interface.map = 0;
39-
} else if (config["participants"][participantName]["interfaces"][i]["nodes-mesh-with-connectivity"]) {
40-
interface.nodesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["nodes-mesh-with-connectivity"].as<std::string>().c_str());
45+
} else if (config["participants"][participantName]["interfaces"][i].contains("nodes-mesh-with-connectivity")) {
46+
interface.nodesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["nodes-mesh-with-connectivity"].get_value<std::string>().c_str());
4147
interface.map = 1;
4248
} else {
4349
interface.nodesMeshName = NULL;
4450
}
4551

46-
if (config["participants"][participantName]["interfaces"][i]["faces-mesh"]) {
47-
interface.facesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["faces-mesh"].as<std::string>().c_str());
52+
if (config["participants"][participantName]["interfaces"][i].contains("faces-mesh")) {
53+
interface.facesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["faces-mesh"].get_value<std::string>().c_str());
4854
} else {
4955
interface.facesMeshName = NULL;
5056
}
5157

52-
if (config["participants"][participantName]["interfaces"][i]["mesh"]) {
53-
interface.facesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["mesh"].as<std::string>().c_str());
58+
if (config["participants"][participantName]["interfaces"][i].contains("mesh")) {
59+
interface.facesMeshName = strdup(config["participants"][participantName]["interfaces"][i]["mesh"].get_value<std::string>().c_str());
5460
}
5561

56-
std::string patchName = config["participants"][participantName]["interfaces"][i]["patch"].as<std::string>();
62+
std::string patchName = config["participants"][participantName]["interfaces"][i]["patch"].get_value<std::string>();
5763
std::transform(patchName.begin(), patchName.end(), patchName.begin(), toupper);
5864
interface.patchName = strdup(patchName.c_str());
5965

6066
interface.numWriteData = config["participants"][participantName]["interfaces"][i]["write-data"].size();
6167
interface.numReadData = config["participants"][participantName]["interfaces"][i]["read-data"].size();
6268

63-
if (config["participants"][participantName]["interfaces"][i]["write-data"]) {
69+
if (config["participants"][participantName]["interfaces"][i].contains("write-data")) {
6470
if (interface.numWriteData == 0) {
6571
// write-data is a string
6672
interface.numWriteData = 1;
6773
interface.writeDataNames = (char **) malloc(sizeof(char *) * interface.numWriteData);
68-
interface.writeDataNames[0] = strdup(config["participants"][participantName]["interfaces"][i]["write-data"].as<std::string>().c_str());
74+
interface.writeDataNames[0] = strdup(config["participants"][participantName]["interfaces"][i]["write-data"].get_value<std::string>().c_str());
6975
} else {
7076
// write-data is an array
7177
interface.writeDataNames = (char **) malloc(sizeof(char *) * interface.numWriteData);
7278

7379
for (int j = 0; j < interface.numWriteData; j++) {
74-
interface.writeDataNames[j] = strdup(config["participants"][participantName]["interfaces"][i]["write-data"][j].as<std::string>().c_str());
80+
interface.writeDataNames[j] = strdup(config["participants"][participantName]["interfaces"][i]["write-data"][j].get_value<std::string>().c_str());
7581
}
7682
}
7783
}
7884

79-
if (config["participants"][participantName]["interfaces"][i]["read-data"]) {
85+
if (config["participants"][participantName]["interfaces"][i].contains("read-data")) {
8086
if (interface.numReadData == 0) {
8187
// read-data is a string
8288
interface.numReadData = 1;
8389
interface.readDataNames = (char **) malloc(sizeof(char *) * interface.numReadData);
84-
interface.readDataNames[0] = strdup(config["participants"][participantName]["interfaces"][i]["read-data"].as<std::string>().c_str());
90+
interface.readDataNames[0] = strdup(config["participants"][participantName]["interfaces"][i]["read-data"].get_value<std::string>().c_str());
8591
} else {
8692
// read-data is an array
8793
interface.readDataNames = (char **) malloc(sizeof(char *) * interface.numReadData);
8894

8995
for (int j = 0; j < interface.numReadData; j++) {
90-
interface.readDataNames[j] = strdup(config["participants"][participantName]["interfaces"][i]["read-data"][j].as<std::string>().c_str());
96+
interface.readDataNames[j] = strdup(config["participants"][participantName]["interfaces"][i]["read-data"][j].get_value<std::string>().c_str());
9197
}
9298
}
9399
}

0 commit comments

Comments
 (0)