Neko  0.9.0
A portable framework for high-order spectral element flow simulations
field_writer.f90
Go to the documentation of this file.
1 ! Copyright (c) 2024, 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 !
33 !
35 
37  use num_types, only : rp, dp, sp
38  use json_module, only : json_file
41  use field, only : field_t
42  use operators, only : curl
43  use case, only : case_t
46  implicit none
47  private
48 
50  type, public, extends(simulation_component_t) :: field_writer_t
52  type(fld_file_output_t), private :: output
53 
54  contains
56  procedure, pass(this) :: init => field_writer_init_from_json
58  procedure, pass(this) :: init_from_attributes => &
61  procedure, pass(this) :: free => field_writer_free
63  procedure, pass(this) :: compute_ => field_writer_compute
64  end type field_writer_t
65 
66 contains
67 
71  subroutine field_writer_init_from_json(this, json, case)
72  class(field_writer_t), intent(inout) :: this
73  type(json_file), intent(inout) :: json
74  class(case_t), intent(inout), target :: case
75  character(len=:), allocatable :: filename
76  character(len=:), allocatable :: precision
77  character(len=20), allocatable :: fields(:)
78 
79  call this%init_base(json, case)
80  call json_get(json, "fields", fields)
81 
82  if (json%valid_path("output_filename")) then
83  call json_get(json, "output_filename", filename)
84  if (json%valid_path("output_precision")) then
85  call json_get(json, "output_precision", precision)
86  if (precision == "double") then
87  call field_writer_init_from_attributes(this, fields, filename, dp)
88  else
89  call field_writer_init_from_attributes(this, fields, filename, sp)
90  end if
91  else
92  call field_writer_init_from_attributes(this, fields, filename)
93  end if
94  else
95  call field_writer_init_from_attributes(this, fields)
96  end if
97  end subroutine field_writer_init_from_json
98 
105  subroutine field_writer_init_from_attributes(this, fields, filename, precision)
106  class(field_writer_t), intent(inout) :: this
107  character(len=20), allocatable, intent(in) :: fields(:)
108  character(len=*), intent(in), optional :: filename
109  integer, intent(in), optional :: precision
110  character(len=20) :: fieldi
111  integer :: i
112 
113  ! Regsiter fields if they don't exist.
114  do i=1, size(fields)
115  fieldi = trim(fields(i))
116  call neko_field_registry%add_field(this%case%fluid%dm_Xh, fieldi,&
117  ignore_existing=.true.)
118  end do
119 
120  if (present(filename)) then
121  if (present(precision)) then
122  call this%output%init(precision, filename, size(fields))
123  else
124  call this%output%init(sp, filename, size(fields))
125  end if
126  do i=1, size(fields)
127  fieldi = trim(fields(i))
128  call this%output%fields%assign(i, neko_field_registry%get_field(fieldi))
129  end do
130 
131  call this%case%output_controller%add(this%output, &
132  this%output_controller%control_value, &
133  this%output_controller%control_mode)
134  else
135  do i=1, size(fields)
136  fieldi = trim(fields(i))
137  call this%case%f_out%fluid%append(neko_field_registry%get_field(fieldi))
138  end do
139  end if
140 
141  end subroutine field_writer_init_from_attributes
142 
144  subroutine field_writer_free(this)
145  class(field_writer_t), intent(inout) :: this
146  call this%free_base()
147  end subroutine field_writer_free
148 
152  subroutine field_writer_compute(this, t, tstep)
153  class(field_writer_t), intent(inout) :: this
154  real(kind=rp), intent(in) :: t
155  integer, intent(in) :: tstep
156 
157  end subroutine field_writer_compute
158 
159 end module field_writer
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Definition: json_utils.f90:54
Retrieves a parameter by name or throws an error.
Definition: json_utils.f90:45
Defines a simulation case.
Definition: case.f90:34
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
Implements the field_writer_t type.
subroutine field_writer_free(this)
Destructor.
subroutine field_writer_init_from_attributes(this, fields, filename, precision)
Actual constructor.
subroutine field_writer_init_from_json(this, json, case)
Constructor from json.
subroutine field_writer_compute(this, t, tstep)
Here to comply with the interface, does nothing.
Defines a field.
Definition: field.f90:34
Implements fld_file_output_t.
Utilities for retrieving parameters from the case files.
Definition: json_utils.f90:34
integer, parameter, public dp
Definition: num_types.f90:9
integer, parameter, public sp
Definition: num_types.f90:8
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Operators.
Definition: operators.f90:34
subroutine, public curl(w1, w2, w3, u1, u2, u3, work1, work2, coef)
Definition: operators.f90:362
Defines an output.
Definition: output.f90:34
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
A simulation component that writes a 3d field to a file.
A simple output saving a list of fields to a .fld file.
Base abstract class for simulation components.