Skip to content

Commit

Permalink
add basic laplacian code #68
Browse files Browse the repository at this point in the history
  • Loading branch information
prudhomm committed Oct 24, 2022
1 parent d6151cb commit 2fc98f6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 42 deletions.
22 changes: 8 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
cmake_minimum_required(VERSION 3.21.0)
project(myproject VERSION 1.0.0)
set(EXTRA_VERSION "")
set(PROJECT_SHORTNAME "p")
set(PROJECT_SHORTNAME "myproject")

include(GNUInstallDirs)

Expand All @@ -33,18 +33,12 @@ if (POLICY CMP0077)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
endif()

if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} )
if ( USE_FEELPP_TOOLBOXES )
find_package(Feel++ COMPONENTS Toolboxes PATHS ${FEELPP_DIR}/share/feelpp/feel/cmake/modules $ENV{FEELPP_DIR}/share/feelpp/feel/cmake/modules /usr/share/feelpp/feel/cmake/modules /usr/local/share/feelpp/feel/cmake/modules )
else()
find_package(Feel++ PATHS ${FEELPP_DIR}/share/feelpp/feel/cmake/modules $ENV{FEELPP_DIR}/share/feelpp/feel/cmake/modules /usr/share/feelpp/feel/cmake/modules /usr/local/share/feelpp/feel/cmake/modules )
endif( USE_FEELPP_TOOLBOXES )

if(NOT FEELPP_FOUND)
message(FATAL_ERROR "Feel++ was not found on your system. Make sure to install it and specify the FEELPP_DIR to reference the installation directory.")
endif()
else()
include_directories(${CMAKE_SOURCE_DIR}/toolboxes ${CMAKE_BINARY_DIR}/toolboxes)
find_package(Feel++ COMPONENTS Toolboxes PATHS ${FEELPP_DIR}/share/feelpp/feel/cmake/modules $ENV{FEELPP_DIR}/share/feelpp/feel/cmake/modules /usr/share/feelpp/feel/cmake/modules /usr/local/share/feelpp/feel/cmake/modules )
if(NOT FEELPP_FOUND)
message(FATAL_ERROR "Feel++ was not found on your system. Make sure to install it and specify the FEELPP_DIR to reference the installation directory.")
endif()
if ( NOT FEELPP_TOOLBOXES_FOUND )
message(WARNING "Feel++ Toolboxes SDK is not found on your system. The toolbox application is now disabled.")
endif()

enable_testing()
Expand Down Expand Up @@ -95,7 +89,7 @@ set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "science")
set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}${EXTRA_VERSION}")
set(CPACK_DEBIAN_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
#set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/debian/postinst")
# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/debian/postinst")

include(CPack)

1 change: 1 addition & 0 deletions src/.tests.laplacian
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
laplacian-1 --config-file ${CMAKE_CURRENT_SOURCE_DIR}/cases/laplacian/fin/fin1/fin2d.cfg
1 change: 0 additions & 1 deletion src/.tests.myapp

This file was deleted.

1 change: 1 addition & 0 deletions src/.tests.toolbox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toolbox-1 --config-file ${CMAKE_CURRENT_SOURCE_DIR}/cases/electric/2d.cfg
1 change: 0 additions & 1 deletion src/.tests.update-toolbox

This file was deleted.

9 changes: 5 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
feelpp_add_application(myapp SRCS main.cpp TESTS INSTALL)

feelpp_add_application(update-toolbox SRCS update-toolbox.cpp LINK_LIBRARIES Feelpp::feelpp_toolbox_electric_lib TESTS)
feelpp_add_testcase(cases)
feelpp_add_application(laplacian SRCS laplacian.cpp TESTS INSTALL )

if ( FEELPP_TOOLBOXES_FOUND )
feelpp_add_application(toolbox SRCS toolbox.cpp LINK_LIBRARIES Feelpp::feelpp_toolbox_electric_lib TESTS)
feelpp_add_testcase(cases)
endif()
75 changes: 53 additions & 22 deletions src/main.cpp → src/laplacian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,42 @@
#include <feel/feelfilters/loadmesh.hpp>
#include <feel/feelvf/form.hpp>
#include <feel/feelvf/vf.hpp>
#include <feel/feelvf/bdf.hpp>
#include <feel/feelts/bdf.hpp>

namespace Feel
{
inline const int FEELPP_DIM=2;
inline const int FEELPP_ORDER=1;

static inline const bool do_print = true;
static inline const bool dont_print = false;

/**
* @brief compute the summary of a container
*
* @tparam Container type of the container
* @param c container
* @param print boolean, true print the summary, false otherwise
* @return nl::json json object containing the summary
*/
template<typename Container>
nl::json summary( Container const& c, bool print = do_print )
{
using namespace Feel;
using namespace Feel::vf;
nl::json j;
j["size"] = c.size();
j["min"] = c.min();
j["max"] = c.max();
j["mean"] = mean( _range = elements( c.mesh() ), _expr = idv( c ) );

if (print)
{
if (Environment::isMasterRank())
std::cout << j.dump(2) << std::endl;
}
return j;
}
inline Feel::po::options_description
makeOptions()
{
Expand Down Expand Up @@ -62,9 +94,9 @@ int runLaplacian( nl::json const& specs )
if ( boption("steady") )
M_bdf->setSteady();

for ( auto [key, material] : specs["/Models/laplacian/materials"_json_pointer].items() )
for ( auto [key, material] : specs["/Models/laplacian/Materials"_json_pointer].items() )
{
LOG( INFO ) << fmt::format( "material {}", material );
LOG( INFO ) << fmt::format( "Material {} found", material );
std::string mat = fmt::format( "/Materials/{}/k", material.get<std::string>() );
auto k = specs[nl::json::json_pointer( mat )].get<std::string>();

Expand All @@ -75,7 +107,7 @@ int runLaplacian( nl::json const& specs )
// BC Neumann
if ( specs["/BoundaryConditions/laplacian"_json_pointer].contains( "flux" ) )
{
for ( auto& [bc, value] : specs["/BoundaryConditions/heat/flux"_json_pointer].items() )
for ( auto& [bc, value] : specs["/BoundaryConditions/laplacian/flux"_json_pointer].items() )
{
LOG( INFO ) << fmt::format( "flux {}: {}", bc, value.dump() );
auto flux = value["expr"].get<std::string>();
Expand All @@ -86,11 +118,11 @@ int runLaplacian( nl::json const& specs )
}

// BC Robin
if ( specs["/BoundaryConditions/laplacian"_json_pointer].contains( "convective_heat_flux" ) )
if ( specs["/BoundaryConditions/laplacian"_json_pointer].contains( "convective_laplacian_flux" ) )
{
for ( auto& [bc, value] : specs["/BoundaryConditions/heat/convective_heat_flux"_json_pointer].items() )
for ( auto& [bc, value] : specs["/BoundaryConditions/laplacian/convective_laplacian_flux"_json_pointer].items() )
{
LOG( INFO ) << fmt::format( "convective_heat_flux {}: {}", bc, value.dump() );
LOG( INFO ) << fmt::format( "convective_laplacian_flux {}: {}", bc, value.dump() );
auto h = value["h"].get<std::string>();
auto Text = value["Text"].get<std::string>();

Expand All @@ -111,13 +143,16 @@ int runLaplacian( nl::json const& specs )
<< "The final time is " << M_bdf->timeFinal() << "\n"
<< "BDF order : " << M_bdf->timeOrder() << "\n" << std::endl;

// Solve
// exporter mesh and fields for visualisation in paraview
auto e = exporter(_mesh = mesh);

// time loop
for ( M_bdf->start(); M_bdf->isFinished()==false; M_bdf->next(u) )
{
at = a;
lt = l;

for ( auto [key, material] : specs["/Models/laplacian/materials"_json_pointer].items() )
for ( auto [key, material] : specs["/Models/laplacian/Materials"_json_pointer].items() )
{
std::string matRho = fmt::format( "/Materials/{}/rho", material.get<std::string>() );
std::string matCp = fmt::format( "/Materials/{}/Cp", material.get<std::string>() );
Expand All @@ -129,22 +164,18 @@ int runLaplacian( nl::json const& specs )
}

at.solve( _rhs = lt, _solution = u );
}
// compute summary
summary(u);

// compute outputs
auto m = mean( _range = elements( mesh ), _expr = idv( u ) );
if ( Environment::isMasterRank() )
{
std::cout << fmt::format( "- mean value: {}", m ) << std::endl;
std::cout << fmt::format( "- min value: {}", u.min() ) << std::endl;
std::cout << fmt::format( "- max value: {}", u.max() ) << std::endl;
std::cout << fmt::format( "- max deviation: {}", u.max() - u.min() ) << std::endl;
e->step(M_bdf->time())->addRegions();
e->step(M_bdf->time())->add("u", u);
e->step(M_bdf->time())->save();
}


// Export
auto e = exporter( _mesh = mesh );
e->addRegions();
e->add( "T", v );
e->save();



return 0;
}
Expand Down
File renamed without changes.

0 comments on commit 2fc98f6

Please sign in to comment.