Neko  0.8.1
A portable framework for high-order spectral element flow simulations
stl_file.f90
Go to the documentation of this file.
1 ! Copyright (c) 2022, The Neko Authors
2 ! All rights reserved.
3 !
4 ! Redistribution and use in source and binary forms, with or without
5 ! modification, are permitted provided that the following conditions
6 ! are met:
7 !
8 ! * Redistributions of source code must retain the above copyright
9 ! notice, this list of conditions and the following disclaimer.
10 !
11 ! * Redistributions in binary form must reproduce the above
12 ! copyright notice, this list of conditions and the following
13 ! disclaimer in the documentation and/or other materials provided
14 ! with the distribution.
15 !
16 ! * Neither the name of the authors nor the names of its
17 ! contributors may be used to endorse or promote products derived
18 ! from this software without specific prior written permission.
19 !
20 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 ! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 ! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 ! POSSIBILITY OF SUCH DAMAGE.
32 !
34 module stl_file
35  use num_types
36  use generic_file
37  use tri_mesh
38  use logger
39  use point
40  use neko_mpi_types
41  use mpi_f08
42  use utils, only: neko_error
43  use comm
44  use stl
45  implicit none
46  private
47 
49  type, public, extends(generic_file_t) :: stl_file_t
50  contains
51  procedure :: read => stl_file_read
52  procedure :: write => stl_file_write
53  end type stl_file_t
54 
55 contains
56 
57  subroutine stl_file_write(this, data, t)
58  class(stl_file_t), intent(inout) :: this
59  class(*), target, intent(in) :: data
60  real(kind=rp), intent(in), optional :: t
61  call neko_log%error('Not implemented')
62  end subroutine stl_file_write
63 
64  subroutine stl_file_read(this, data)
65  class(stl_file_t) :: this
66  class(*), target, intent(inout) :: data
67  type(tri_mesh_t), pointer :: tri_msh => null()
68  type(mpi_status) :: status
69  type(mpi_file) :: fh
70  type(point_t) :: p(3)
71  type(stl_hdr_t) :: stl_hdr
72  type(stl_triangle_t), allocatable :: stl_tri(:)
73  integer :: i, p_idx, ierr
74 
75  call this%check_exists()
76 
77  select type(data)
78  type is(tri_mesh_t)
79  tri_msh => data
80  class default
81  call neko_log%error('Invalid data')
82  end select
83 
84  call mpi_file_open(neko_comm, trim(this%fname), &
85  mpi_mode_rdonly, mpi_info_null, fh, ierr)
86  call mpi_file_read_all(fh, stl_hdr, 1, mpi_stl_header, status, ierr)
87 
88  if (stl_hdr%hdr(1:6) .eq. 'solid') then
89  call neko_log%error('Invalid STL file (ASCII)')
90  end if
91 
92  call tri_msh%init(stl_hdr%ntri)
93  allocate(stl_tri(stl_hdr%ntri))
94 
95  call mpi_file_read_all(fh, stl_tri, stl_hdr%ntri, &
96  mpi_stl_triangle, status, ierr)
97 
98  p_idx = 0
99  do i = 1, stl_hdr%ntri
100  p_idx = p_idx + 1
101  p(1) = point_t(dble(stl_tri(i)%v1), p_idx)
102  p_idx = p_idx + 1
103  p(2) = point_t(dble(stl_tri(i)%v2), p_idx)
104  p_idx = p_idx + 1
105  p(3) = point_t(dble(stl_tri(i)%v3), p_idx)
106  call tri_msh%add_element(p(1), p(2), p(3))
107  end do
108 
109  deallocate(stl_tri)
110 
111  call mpi_file_close(fh, ierr)
112 
113  end subroutine stl_file_read
114 
115 end module stl_file
Definition: comm.F90:1
type(mpi_comm) neko_comm
MPI communicator.
Definition: comm.F90:16
Logging routines.
Definition: log.f90:34
type(log_t), public neko_log
Global log stream.
Definition: log.f90:61
MPI derived types.
Definition: mpi_types.f90:34
type(mpi_datatype), public mpi_stl_header
MPI Derived type for a STL header.
Definition: mpi_types.f90:57
type(mpi_datatype), public mpi_stl_triangle
MPI derived type for a STL triangle.
Definition: mpi_types.f90:58
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Implements a point.
Definition: point.f90:35
Stereolithography (STL) file.
Definition: stl_file.f90:34
subroutine stl_file_write(this, data, t)
Definition: stl_file.f90:58
subroutine stl_file_read(this, data)
Definition: stl_file.f90:65
Stereolithography format.
Definition: stl.f90:2
Defines a triangular surface mesh.
Definition: tri_mesh.f90:35
Utilities.
Definition: utils.f90:35
A generic file handler.
A point in with coordinates .
Definition: point.f90:43
Defines a STL hdr.
Definition: stl.f90:8
Defines a STL triangle.
Definition: stl.f90:14
Interface for STL files.
Definition: stl_file.f90:49