Skip to content

Commit

Permalink
(conan-io#8375) Feature/add ofeli
Browse files Browse the repository at this point in the history
* add ofeli library

* follow pep8

* follow conan hooks

* set compiler to c++11

* add c++ 11 standard to test_package

* set supported compiler

* check os for setting compiler

* remove stdc++11 from conanfiles

* check min cppstd and add debug or release build type choose

* test with config_options

* remote stdc++11 cppstd_flag and update license

* check libstdc++ ABI support
  • Loading branch information
Kr4is authored and miklelappo committed Feb 9, 2022
1 parent a7ae4ac commit d82e472
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/ofeli/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/ofeli/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"4.1.2":
url: "https://github.com/rtouzani/ofeli/releases/download/ofeli-4.1.2/ofeli-4.1.2.tar.gz"
sha256: "672723856be984b6ea423976c4d13748e327f04e6571694cd662bcda1ed1f8d4"
75 changes: 75 additions & 0 deletions recipes/ofeli/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment
import os
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.40.0"


class OfeliConan(ConanFile):
name = "ofeli"
description = "An Object Finite Element Library"
topics = ("ofeli", "finite element", "finite element library",
"finite element analysis", "finite element solver")
license = "LGPL-3.0-or-later"
homepage = "http://ofeli.org/index.html"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _doc_folder(self):
return os.path.join(
self._source_subfolder,
"doc"
)

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration(
"Ofeli is just supported for Linux")
if self.settings.compiler != "gcc":
raise ConanInvalidConfiguration(
"Ofeli is just supported for GCC")
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
if self.settings.compiler.libcxx != "libstdc++11":
raise ConanInvalidConfiguration(
"Ofeli supports only libstdc++'s new ABI")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
strip_root=True, destination=self._source_subfolder)

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self)
self._autotools.configure(args=["--enable-%s" % ("release"
if self.settings.build_type == "Release"
else "debug")])
return self._autotools

def build(self):
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("*.h", dst="include",
src=os.path.join(self._source_subfolder, "include"))
self.copy("*libofeli.a", dst="lib",
src=os.path.join(self._source_subfolder, "src"))
self.copy("*.md", dst="res",
src=os.path.join(self._source_subfolder, "material"))
self.copy("COPYING", dst="licenses", src=self._doc_folder)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "Ofeli"
self.cpp_info.names["cmake_find_package_multi"] = "Ofeli"
self.cpp_info.libs = ["ofeli"]
self.env_info.OFELI_PATH_MATERIAL.append(
os.path.join(self.package_folder, "res"))
11 changes: 11 additions & 0 deletions recipes/ofeli/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.4)
project(test_package LANGUAGES CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::ofeli)
17 changes: 17 additions & 0 deletions recipes/ofeli/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
76 changes: 76 additions & 0 deletions recipes/ofeli/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*==============================================================================
O F E L I
Object Finite Element Library
==============================================================================
Copyright (C) 1998 - 2015 Rachid Touzani
This file is part of OFELI.
OFELI is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OFELI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with OFELI. If not, see <http://www.gnu.org/licenses/>.
==============================================================================
An example of a Finite Element Code using OFELI
Solution of a 1-D Elliptic problem using P1 Finite elements
==============================================================================*/

#include "OFELI.h"
using namespace OFELI;

int main(int argc, char *argv[])
{
double L=1;
int N=10;

/// Read and output mesh data
banner();
if (argc>1)
N = atoi(argv[1]);
Mesh ms(L,N);
int NbN = N+1;

// Declare problem data (matrix, rhs, boundary conditions, body forces)
TrMatrix<double> A(NbN);
Vect<double> b(ms);
b.set("16*pi*pi*sin(4*pi*x)");

// Build matrix and R.H.S.
double h = L/double(N);
b *= h;
for (int i=2; i<NbN; i++) {
A(i,i ) = 2./h;
A(i,i+1) = -1./h;
A(i,i-1) = -1./h;
}

// Impose boundary conditions
A(1,1) = 1.; A(1,2) = 0.; b(1) = 0;
A(NbN,NbN) = 1.; A(NbN-1,NbN) = 0.; b(NbN) = 0;

// Solve the linear system of equations
A.solve(b);

// Output solution and error
cout << "\nSolution:\n" << b;
Vect<double> sol(ms);
sol.set("sin(4*pi*x)");
cout << "Error = " << (b-sol).getNormMax() << endl;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/ofeli/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.1.2":
folder: all

0 comments on commit d82e472

Please sign in to comment.