Skip to content
Snippets Groups Projects
Select Git revision
  • 49e3c023ef9103a7b3620b653fd929d501c73ba6
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

MeshModule.cpp

Blame
  • 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;
                                    }
                                    }
                                  }}
    
                                ));
    }