Select Git revision
test_ASTNodeExpressionBuilder.cpp
MeshModule.cpp 3.67 KiB
#include <language/MeshModule.hpp>
#include <language/BuiltinFunctionEmbedder.hpp>
#include <language/FunctionTable.hpp>
#include <language/TypeDescriptor.hpp>
#include <mesh/Connectivity.hpp>
#include <mesh/GmshReader.hpp>
#include <mesh/Mesh.hpp>
#include <utils/Exceptions.hpp>
#include <output/VTKWriter.hpp>
template <>
inline ASTNodeDataType ast_node_data_type_from<std::shared_ptr<IMesh>> = {ASTNodeDataType::type_id_t, "mesh"};
template <>
inline ASTNodeDataType ast_node_data_type_from<FunctionId> = {ASTNodeDataType::function_t};
MeshModule::MeshModule()
{
this->_addTypeDescriptor(
std::make_shared<TypeDescriptor>(ast_node_data_type_from<std::shared_ptr<IMesh>>.typeName()));
this->_addBuiltinFunction("readGmsh", std::make_shared<BuiltinFunctionEmbedder<std::shared_ptr<IMesh>, std::string>>(
std::function<std::shared_ptr<IMesh>(std::string)>{
[](std::string file_name) -> std::shared_ptr<IMesh> {
GmshReader gmsh_reader(file_name);
return gmsh_reader.mesh();
}}
));
this
->_addBuiltinFunction("transform",
std::make_shared<
BuiltinFunctionEmbedder<std::shared_ptr<IMesh>, std::shared_ptr<IMesh>, FunctionId>>(
std::function<std::shared_ptr<IMesh>(std::shared_ptr<IMesh>, FunctionId)>{
[](std::shared_ptr<IMesh> p_mesh, FunctionId function_id) -> std::shared_ptr<IMesh> {
switch (p_mesh->dimension()) {
case 1: {
throw NotImplementedError("not implemented in 1d");
break;
}
case 2: {
throw NotImplementedError("not implemented in 2d");
break;
}
case 3: {
std::cout << "Using function " << function_id.m_function_id << '\n';
using MeshType = Mesh<Connectivity3D>;
const MeshType& given_mesh = dynamic_cast<const MeshType&>(*p_mesh);
NodeValue<const TinyVector<3>> given_xr = given_mesh.xr();
NodeValue<TinyVector<3>> xr(given_mesh.connectivity());
parallel_for(
given_mesh.numberOfNodes(), PUGS_LAMBDA(const NodeId& r) {
const TinyVector<3> shift{0, 0.05, 0.05};
const auto x = given_xr[r] - shift;
const double c = std::cos(0.01 * x[0]);
const double s = std::sin(0.01 * x[0]);
const TinyVector<3> transformed{x[0], x[1] * c + x[2] * s, -x[1] * s + x[2] * c};
xr[r] = transformed + shift;
});
return std::make_shared<MeshType>(given_mesh.shared_connectivity(), xr);
}
default: {
return nullptr;
}
}
}}
));
}