Skip to content
Snippets Groups Projects
Select Git revision
  • e786a7b321bcaab6d5dfb5a6d391123b31437771
  • develop default protected
  • origin/stage/bouguettaia
  • feature/kinetic-schemes
  • feature/reconstruction
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/variational-hydro
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • feature/escobar-smoother
  • feature/hypoelasticity-clean
  • 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

test_ASTNodeArraySubscriptExpressionBuilder.cpp

Blame
    • Stéphane Del Pino's avatar
      e786a7b3
      Change ASTNodeDataType construction and handling of type descriptors · e786a7b3
      Stéphane Del Pino authored
      From the ast point of view this gives cleaner data type description.
      Nodes used to describe type names are now explicitly described as
      type names. Previously,
      
      - the data type could be marked as the described type. Now it is
      referred as the `typename` of the type. For instance the `R^2`
      type descriptor node was given `R^2` as a data type. Now it is given
      the `typename(R^2)`: it is a typename which refers to `R^2`.
      - In some other cases, it could have been just `typename` which forced
      to re-parse entries (which is never good).
      
      Also `affectations` types is fixed: it is now given the `void` type
      instead of the type of the affected data.
      
      Functions input and output spaces types should now be correctly
      defined: some more tests are however required.
      
      The case of compound types is however not that clear since the data
      type of the type `R*R*R^2` is just defined as `typename(list)`. This
      may be improved (in order to help checking of function definition/use.
      
      An initialization issue related to tuples of R^1 was fixed on the way
      and some error messages improved.
      
      This is related to issue #21
      e786a7b3
      History
      Change ASTNodeDataType construction and handling of type descriptors
      Stéphane Del Pino authored
      From the ast point of view this gives cleaner data type description.
      Nodes used to describe type names are now explicitly described as
      type names. Previously,
      
      - the data type could be marked as the described type. Now it is
      referred as the `typename` of the type. For instance the `R^2`
      type descriptor node was given `R^2` as a data type. Now it is given
      the `typename(R^2)`: it is a typename which refers to `R^2`.
      - In some other cases, it could have been just `typename` which forced
      to re-parse entries (which is never good).
      
      Also `affectations` types is fixed: it is now given the `void` type
      instead of the type of the affected data.
      
      Functions input and output spaces types should now be correctly
      defined: some more tests are however required.
      
      The case of compound types is however not that clear since the data
      type of the type `R*R*R^2` is just defined as `typename(list)`. This
      may be improved (in order to help checking of function definition/use.
      
      An initialization issue related to tuples of R^1 was fixed on the way
      and some error messages improved.
      
      This is related to issue #21
    DiscreteFunctionUtils.cpp 4.08 KiB
    #include <scheme/DiscreteFunctionUtils.hpp>
    
    #include <mesh/Connectivity.hpp>
    #include <mesh/IMesh.hpp>
    #include <mesh/Mesh.hpp>
    #include <scheme/DiscreteFunctionP0.hpp>
    #include <scheme/DiscreteFunctionVariant.hpp>
    #include <utils/Stringify.hpp>
    
    std::shared_ptr<const IMesh>
    getCommonMesh(const std::vector<std::shared_ptr<const DiscreteFunctionVariant>>& discrete_function_variant_list)
    {
      std::shared_ptr<const IMesh> i_mesh;
      bool is_same_mesh = true;
      for (const auto& discrete_function_variant : discrete_function_variant_list) {
        std::visit(
          [&](auto&& discrete_function) {
            if (not i_mesh.use_count()) {
              i_mesh = discrete_function.mesh();
            } else {
              if (i_mesh != discrete_function.mesh()) {
                is_same_mesh = false;
              }
            }
          },
          discrete_function_variant->discreteFunction());
      }
      if (not is_same_mesh) {
        i_mesh.reset();
      }
      return i_mesh;
    }
    
    bool
    hasSameMesh(const std::vector<std::shared_ptr<const DiscreteFunctionVariant>>& discrete_function_variant_list)
    {
      std::shared_ptr<const IMesh> i_mesh;
      bool is_same_mesh = true;
      for (const auto& discrete_function_variant : discrete_function_variant_list) {
        std::visit(
          [&](auto&& discrete_function) {
            if (not i_mesh.use_count()) {
              i_mesh = discrete_function.mesh();
            } else {
              if (i_mesh != discrete_function.mesh()) {
                is_same_mesh = false;
              }
            }
          },
          discrete_function_variant->discreteFunction());
      }
    
      return is_same_mesh;
    }
    
    template <size_t Dimension, typename DataType>
    std::shared_ptr<const IDiscreteFunction>
    shallowCopy(const std::shared_ptr<const Mesh<Connectivity<Dimension>>>& mesh,
                const std::shared_ptr<const DiscreteFunctionP0<Dimension, DataType>>& discrete_function)
    {
      Assert(mesh->shared_connectivity() ==
               dynamic_cast<const Mesh<Connectivity<Dimension>>&>(*discrete_function->mesh()).shared_connectivity(),
             "connectivities should be the same");
    
      return std::make_shared<DiscreteFunctionP0<Dimension, DataType>>(mesh, discrete_function->cellValues());
    }
    
    template <typename MeshType, typename DiscreteFunctionT>
    std::shared_ptr<const DiscreteFunctionVariant>
    shallowCopy(const std::shared_ptr<const MeshType>& mesh, const DiscreteFunctionT& f)
    {
      const std::shared_ptr function_mesh = std::dynamic_pointer_cast<const MeshType>(f.mesh());
    
      if (mesh->shared_connectivity() != function_mesh->shared_connectivity()) {
        throw NormalError("cannot shallow copy when connectivity changes");
      }
    
      if constexpr (std::is_same_v<MeshType, typename DiscreteFunctionT::MeshType>) {
        if constexpr (is_discrete_function_P0_v<DiscreteFunctionT>) {
          return std::make_shared<DiscreteFunctionVariant>(DiscreteFunctionT(mesh, f.cellValues()));
        } else if constexpr (is_discrete_function_P0_vector_v<DiscreteFunctionT>) {
          return std::make_shared<DiscreteFunctionVariant>(DiscreteFunctionT(mesh, f.cellArrays()));
        } else {
          throw UnexpectedError("invalid discrete function type");
        }
      } else {
        throw UnexpectedError("invalid mesh types");
      }
    }
    
    std::shared_ptr<const DiscreteFunctionVariant>
    shallowCopy(const std::shared_ptr<const IMesh>& mesh,
                const std::shared_ptr<const DiscreteFunctionVariant>& discrete_function_variant)
    {
      return std::visit(
        [&](auto&& f) {
          if (mesh == f.mesh()) {
            return discrete_function_variant;
          } else if (mesh->dimension() != f.mesh()->dimension()) {
            throw NormalError("incompatible mesh dimensions");
          }
    
          switch (mesh->dimension()) {
          case 1: {
            return shallowCopy(std::dynamic_pointer_cast<const Mesh<Connectivity<1>>>(mesh), f);
          }
          case 2: {
            return shallowCopy(std::dynamic_pointer_cast<const Mesh<Connectivity<2>>>(mesh), f);
          }
          case 3: {
            return shallowCopy(std::dynamic_pointer_cast<const Mesh<Connectivity<3>>>(mesh), f);
          }
            // LCOV_EXCL_START
          default: {
            throw UnexpectedError("invalid mesh dimension");
          }
            // LCOV_EXCL_STOP
          }
        },
        discrete_function_variant->discreteFunction());
    }