Commit 3a9c05ef authored by GILLES Sebastien's avatar GILLES Sebastien

#1465 Add a test to help implement the writing down of a Lua file from...

#1465 Add a test to help implement the writing down of a Lua file from InputData with non-default values inside.
parent 56573426
......@@ -2,3 +2,4 @@ include(${CMAKE_CURRENT_LIST_DIR}/CommandLineOptions/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/InputData/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/InputParameter/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/InitialCondition/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/WriteLuaFile/CMakeLists.txt)
add_executable(MoReFEMTestMoReFEMDataWriteLuaFile
${CMAKE_CURRENT_LIST_DIR}/test.cpp
)
target_link_libraries(MoReFEMTestMoReFEMDataWriteLuaFile
${MOREFEM_TEST_TOOLS})
add_test(WriteLuaFile
MoReFEMTestMoReFEMDataWriteLuaFile
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR})
set_tests_properties(WriteLuaFile PROPERTIES TIMEOUT 10)
/*!
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Sun, 18 Nov 2018 22:29:38 +0100
// Copyright (c) Inria. All rights reserved.
//
*/
#ifndef MOREFEM_x_TEST_x_CORE_x_MO_RE_F_E_M_DATA_x_WRITE_LUA_FILE_x_INPUT_DATA_HPP_
# define MOREFEM_x_TEST_x_CORE_x_MO_RE_F_E_M_DATA_x_WRITE_LUA_FILE_x_INPUT_DATA_HPP_
# include "Core/MoReFEMData/MoReFEMData.hpp"
# include "Core/InputData/Instances/Reaction/ReactionCoefficient.hpp"
# include "Core/InputData/Instances/Geometry/Mesh.hpp"
# include "Core/InputData/Instances/Parameter/Source/VectorialTransientSource.hpp"
namespace MoReFEM
{
namespace TestNS::WriteLuaFileNS
{
//! \copydoc doxygen_hide_input_data_tuple
using InputDataTuple = std::tuple
<
InputDataNS::TimeManager,
InputDataNS::Result,
InputDataNS::ReactionNS::ReactionCoefficient,
InputDataNS::Mesh<5>,
InputDataNS::VectorialTransientSource<4>
>;
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = InputData<InputDataTuple>;
//! \copydoc doxygen_hide_morefem_data_type
using morefem_data_type = MoReFEMData<InputData>;
} // namespace TestNS::WriteLuaFileNS
} // namespace MoReFEM
#endif // MOREFEM_x_TEST_x_CORE_x_MO_RE_F_E_M_DATA_x_WRITE_LUA_FILE_x_INPUT_DATA_HPP_
-- Comment lines are introduced by "--".
-- In a section (i.e. within braces), all entries must be separated by a comma.
transient = {
-- Time at the beginning of the code (in seconds).
-- Expected format: VALUE
-- Constraint: v >= 0.
init_time = 0.,
-- Time step between two iterations, in seconds.
-- Expected format: VALUE
-- Constraint: v > 0.
timeStep = 0.1,
-- Maximum time, if set to zero run a static case.
-- Expected format: VALUE
-- Constraint: v >= 0.
timeMax = 10.
} -- transient
Result = {
-- Directory in which all the results will be written. This path may use the environment variable
-- MOREFEM_RESULT_DIR, which is either provided in user's environment or automatically set to
-- '/Volumes/Data/${USER}/MoReFEM/Results' in MoReFEM initialization step. You may also use
-- ${MOREFEM_START_TIME} in the value which will be replaced by a time under format
-- YYYY_MM_DD_HH_MM_SS.Please do not read the value directly from this Lua file: whenever you need the path
-- to the result directory, use instead MoReFEMData::GetResultDirectory().
-- Expected format: "VALUE"
output_directory = "${MOREFEM_TEST_OUTPUT_DIR}/WriteLuaFile",
-- Enables to skip some printing in the console. Can be used to WriteSolution every n time.
-- Expected format: VALUE
-- Constraint: v > 0
display_value = 1,
-- Defines the solutions output format. Set to false for ascii or true for binary.
-- Expected format: 'true' or 'false' (without the quote)
binary_output = false
} -- Result
Mesh5 = {
-- Path of the mesh file to use.
-- Expected format: "VALUE"
mesh = "${MOREFEM_ROOT}/Data/Mesh/Bar.mesh",
-- Format of the input mesh.
-- Expected format: "VALUE"
-- Constraint: value_in(v, {'Ensight', 'Medit'})
format = "Medit",
-- Highest dimension of the input mesh. This dimension might be lower than the one effectively read in the
-- mesh file; in which case Coords will be reduced provided all the dropped values are 0. If not, an
-- exception is thrown.
-- Expected format: VALUE
-- Constraint: v <= 3 and v > 0
dimension = 3,
-- Space unit of the mesh.
-- Expected format: VALUE
space_unit = 1.
} -- Mesh5
-- Value of R.
-- Expected format: VALUE
ReactionCoefficient = 1.
TransientSource4 = {
nature = { "lua_function", "constant", "constant"},
value = {
[[
function (x, y, z)
return 100. * math.exp(-((x - 0.5)^2 + (y - 0.5)^2)/(0.1^2));
end
]],
0., 0. }
} -- TransientSource4
/*!
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Wed, 25 Jul 2018 18:29:56 +0200
// Copyright (c) Inria. All rights reserved.
//
*/
#include <cstdlib>
#include <tuple>
#include "Utilities/Containers/Print.hpp"
#define BOOST_TEST_MODULE core_write_lua_file
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "Utilities/Filesystem/File.hpp"
#include "Utilities/Filesystem/Folder.hpp"
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "Core/TimeManager/TimeManagerInstance.hpp"
#include "ThirdParty/IncludeWithoutWarning/Seldon/Seldon.hpp"
#include "ThirdParty/IncludeWithoutWarning/Mpi/Mpi.hpp"
#include "Test/Tools/InitializeTestMoReFEMData.hpp"
#include "Test/Core/MoReFEMData/WriteLuaFile/InputData.hpp"
#include "Test/Tools/Fixture/Environment.hpp"
using namespace MoReFEM;
PRAGMA_DIAGNOSTIC(push)
# ifdef __clang__
PRAGMA_DIAGNOSTIC(ignored "-Wdisabled-macro-expansion")
# endif // __clang__
BOOST_FIXTURE_TEST_CASE(check_value, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
const std::string output_directory = environment.SubstituteValues("${MOREFEM_TEST_OUTPUT_DIR}/TestWriteLuaFile/");
if (FilesystemNS::Folder::DoExist(output_directory))
FilesystemNS::Folder::Remove(output_directory, __FILE__, __LINE__);
FilesystemNS::Folder::Create(output_directory, __FILE__, __LINE__);
auto generated_lua = environment.SubstituteValues(output_directory + "generated_lua_file.lua");
if (FilesystemNS::File::DoExist(generated_lua))
FilesystemNS::File::Remove(generated_lua, __FILE__, __LINE__);
using input_data_type = TestNS::WriteLuaFileNS::InputData;
BOOST_CHECK_THROW(TestNS::InitializeTestMoReFEMData<input_data_type> init(std::move(generated_lua)),
std::exception);
auto full_fledged_lua_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Core/MoReFEMData/WriteLuaFile/demo.lua");
TestNS::InitializeTestMoReFEMData<input_data_type> init(std::move(full_fledged_lua_file));
auto generated_by_direct_call_lua_file = output_directory + "/generated_by_direct_call_lua_file.lua";
Utilities::InputDataNS::CreateDefaultInputFile<input_data_type::Tuple>(generated_by_direct_call_lua_file);
BOOST_CHECK(FilesystemNS::File::AreEquals(generated_lua, generated_by_direct_call_lua_file, __FILE__, __LINE__));
}
PRAGMA_DIAGNOSTIC(pop)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment