|
Neko 1.99.11
A portable framework for high-order spectral element flow simulations
|
The user file is a fortran file where the user can implement their own functions to extend the capabilities of the default Neko executable. The user file can be used for setting advanced initial/boundary conditions, source terms, I/O operations, and interactions with the Neko framework.
This section will provide a written explanation of the user file, its structure, and how to compile and run it. For a more hands-on approach, see the examples section, which contains several user file examples that demonstrate various aspects of programming with Neko.
The user file is a regular Fortran .f90 file that needs to be compiled with makeneko, located in the bin folder of your neko installation. To compile a user file user.f90, run:
If everything goes well, you should observe the following output:
Compiling your user file with makeneko will create a neko executable, which you will need to execute with your case file as an argument. For example, if your case file is called user.case:
Or in parallel using MPI:
The current high-level structure of the user file is shown below.
The user file implements the user module. This modules contains a subroutine named user_setup, which we use to interface the internal procedures defined in src/common/user_intf.f90 with the subroutines that you will implement in your user file. Each user subroutine should be implemented under the contains statement, below user_setup.
The following user functions, if defined in the user file, will always be executed, regardless of what is set in the case file:
Three subroutines startup, initialize and finalize may be used to initialize/finalize any user defined variables, external objects, or processes. The startup routine is called immediately after the case file is read in, meaning that no important objects are initialized yet (e.g. the mesh, fluid, etc.). The initialize and finalize are respectively executed right before/after the simulation time loop.
In most cases, one can use initialize routine and not the startup. The latter is only necessary when you want to either manipulate the case file programmatically before it is used in the simulation, or define some variables that will be used in the constructors of some of the types. An example of the latter is defining some material property constants that can be used in the user material_properties routine, which is run by the constructor of the casefluid object.
In the example above, the subroutines startup, initialize and finalize contain the actual implementations. They must also be associated to the internal procedures inside, inside user_setup:
The subroutine compute is executed at the end of every time step. It can be used for computing and/or outputting your own variables/quantities at every time step.
In the example above, the subroutine user_check contains the actual implementation, as a homage to the Nek5000 routine, which served a similar purpose. As usual, the routine needs to be registered by adding:
to our user_setup. The preprocess routine can be implemented similarly.
The material_properties routine allows for more complex computations and setting of various material properties, such as rho, mu for the fluid and cp, lambda for the scalar. The example below is taken from the rayleigh_benard_cylinder example.
And of course not forgetting to register our function in user_setup by adding the following line:
Note the usage of the scheme_name argument. This is used in several user routines, to provide the information about what solver (scheme) called the routine. In this example, we make use of it to distinguish the fluid and scalar solvers. The default scheme names are fluid and scalar, but can be controlled by the name entry in the JSON configuration of the solver. Here, the name for the scalar was set to temperature.
This user function allows for the modification of the mesh at runtime, by acting on the element nodes of the mesh specified in the case file. This function is only called once before the simulation time loop. The example below is taken from the tgv example.
The registering of the above function in user_setup should then be done as follows:
Wall-model sampling values can be set separately for each wall node by using "value": "user" in the boundary condition's sampling object. The callback is called once during wall-sampler setup, before sampling locations are constructed. Set a boundary-condition name in the case file to distinguish multiple user-sampled wall boundaries.
For distance sampling, register wall_sampling_distance in user_setup:
The callback receives linear wall-node indices in msk(:) and must fill distances(n_samples, n_nodes) with positive values. Geometry can be obtained through neko_user_access when needed:
For GLL sampling, register wall_sampling_gll instead. Its interface is the same except that the output is integer :: indices(:,:); every entry must be a positive GLL index. n_samples is the first dimension in both callbacks, so a user routine remains source-compatible when a wall model later supports more than one sample per wall node. Current wall models require n_samples: 1.
As explained in the case file page, certain components of the simulation can be set to be user defined. These components and their associated user functions are:
| Description | User function | JSON Object in the case file |
|---|---|---|
| Initial conditions | initial_conditions | case.fluid.initial_condition or case.scalar.initial_condition |
| Source terms | source_term | case.fluid.source_terms or case.scalar.source_terms |
| Dirichlet boundary conditions | dirichlet_conditions | case.fluid.boundary_conditions or case.scalar.boundary_conditions |
| Neumann boundary conditions | neumann_conditions | case.scalar.boundary_conditions |
| Wall-model sampling | wall_sampling_gll or wall_sampling_distance | case.fluid.boundary_conditions[].sampling |
Enabling user defined initial conditions for the fluid and/or scalar is done by setting the initial_condition.type to "user" in the relevant sections of the case file, case.fluid and/or case.scalar.
See the relevant sections on the fluid and scalar initial conditions in the case file page for more details.
The associated user function for initial conditions must then be added to the user file. An example for the fluid taken from the advecting cone example, is shown below.
Not again the usage of scheme_name to distinguish between the fluid and the scalar. Depending on the scheme, the contents of the field list fields changes, and we extract individual fields via field pointers accordingly. The incompressible fluid solver always generates solution fields, u, v and w. For the scalar, the name of the field coincides with scheme_name. For single scalar cases, this defaults to s. For multiple scalar cases, the field name is set to the scalar name specified in the JSON configuration (e.g., "s1", "s2", etc.).
We should also add of the following lines in user_setup, as usual.
Enabling user defined source terms for the fluid and/or scalar is done by adding JSON Objects to the case.fluid.source_terms and/or case.scalar.source_terms lists.
See the relevant sections on the fluid and scalar source terms in the [case file page](Case File) for more details.
The associated user functions for the fluid and/or scalar source terms can then be added to the user file. An example for the fluid, taken from the scalar_mms example, is shown below.
As usual, we point the user routine to our implementation in user_setup.
This user function can be used to specify Dirichlet boundary values for velocity components u,v,w, the pressure p, and/or the scalar(s). This type of boundary condition allows for time-dependent velocity profiles or non-uniform pressure profiles to e.g. impose an outlet pressure computed from another simulation.
The user routine is called by the user_velocity and user_pressure boundary conditions for the fluid, and the user boundary condtition for the scalar. Once the appropriate boundaries have been identified, the user function dirichlet_conditions should be used to compute and apply the desired values to our velocity/pressure/scalar field(s).
The structure of the interface is very similar to e.g. the initial conditions. One gets a list of solution fields, the contents of which depends on what scheme owns the boundary condition. For user_velocity, it will be a list of 3 fields with names u, v, w; For user_pressure, a list with a single field p; For the scalar, also a single field with the same name as the solution field for the scalar (s by default).
It is crucial to understand that all three boundary condition will call the same routine! So, if one has, for example, both user_velocity for the fluid and user for the scalar, it is necessary to have an if statement in the user routine to distinguish between the two cases. The convenient way to do that is to check the size of the passed field list and the names of the fields inside. For example, if there is one field and it is called s, one executes the code setting the boundary values for the scalar s.
Note that the fields that one manipulates in the user routine are not the actual velocity fields, etc. Instead, the code does a masked copy from the dummy fields manipulated in the user routine to the actual fields of unknowns, with the mask corresponding to the boundary faces. So, even if you somehow manipulate the fields elsewhere in the domain inside the user routine, that will not affect the solution.
In the following example, we indicate in case.fluid.boundary_conditions that we would like to apply a velocity profile on the boundary number 1 (in this case, the inlet boundary). On boundary number 2 (the outlet boundary), we change the pressure. In case.scalar.boundary_conditions, we indicate the same for the scalar on boundaries 1 and 2 (inlet and outlet).
The header of the user function is given in the code snippet below.
The arguments and their purpose are as follows:
Links to the documentation to learn more about what the types mentioned above contain and how to use them: src/field/field.f90, src/bc/bc.f90.
The user function should be registered in user_setup with the following line:
A very simple example illustrating the above is shown below, which is taken from the cyl_boundary_layer example
This example is applying constant dirichlet values at the selected boundaries for the velocity components and presure. The scalar is applied a function s(y,z) = sin(y)*sin(z) to demonstrate the usage of boundary masks.
Note that we are only applying our boundary values at the first timestep, which is done simply with the line if (time%tstep .ne. 1) return. This is a trick that can be used for time-independent boundary profiles that require some kind of time consuming operation like interpolation or reading from a file, which would add overhead if executed at every time step.
This user function can be used to specify Neumann boundary values for the scalar(s). This type of boundary condition allows for time-dependent scalar flux over the surface.
The user routine is called by the user boundary condition for the scalar. Once the appropriate boundaries have been identified, the user function neumann_conditions should be used to compute and apply the desired values to our scalar field(s).
The structure of the interface is very similar to e.g. the initial conditions. One gets a list of solution fields, the contents of which depends on which scalar owns the boundary condition. A single field with the same name as the solution field for the scalar (s by default).
It is crucial to understand that all boundary conditions will call the same routine! So, if one has, for example, both user for two scalars, it is necessary to have an if statement in the user routine to distinguish between the two cases. The convenient way to do that is to check the names of the fields inside. For example, if there is one field and it is called s0, one executes the code setting the boundary values for the scalar s0.
Note that the fields that one manipulates in the user routine are not the actual scalar fields. Instead, the code does a masked copy from the dummy fields manipulated in the user routine to the actual fields of unknowns, with the mask corresponding to the boundary faces. So, even if you somehow manipulate the fields elsewhere in the domain inside the user routine, that will not affect the solution. For the Neumann boundary conditions, in particular, the field that one manipulates is actually the flux on the boundaries, which means all internal points should be dummy.
In the following example, we indicate in case.scalar.boundary_conditions, the flux to be sin(t) and -sin(t) for the scalar on boundaries 1 and 2.
The header of the user function is given in the code snippet below.
The arguments and their purpose are as follows:
Links to the documentation to learn more about what the types mentioned above contain and how to use them: src/field/field.f90, src/bc/bc.f90.
The user function should be registered in user_setup with the following line:
A very simple example illustrating the above is shown below.
When using the Arbitrary Lagrangian-Eulerian (ALE) framework for simulating moving meshes and boundaries, Neko allows users to explicitly define custom mesh velocities, base shapes, and rigid body kinematics.
These functions must be registered inside your user_setup subroutine in exactly the same way as the standard functions described above:
The interface ale_rigid_kinematics allows you to implement a custom time-dependent rigid body motion amplitude for a particular body. The Double_ocyl_cylinder example shows the usage of this interface.
Example (Superimpose):
subroutine user_rigid_kinematics(body_id, time, vel_trans, vel_ang)integer, intent(in) :: body_idtype(time_state_t), intent(in) :: timereal(kind=rp), intent(inout) :: vel_trans(3)real(kind=rp), intent(inout) :: vel_ang(3)real(kind=rp) :: t</blockquote>t = time%tselect case (body_id)case (1) ! First registered body in ALE section in case file.! Amplitude for x motionvel_trans(1) = vel_trans(1) + your_custom_translational_motion! Amplitude for rotation around zvel_ang(3) = vel_ang(3) + your_custom_rotational_motionend selectend subroutine user_rigid_kinematics@icode> **example** (override):fortran subroutine user_rigid_kinematics(body_id, time, vel_trans, vel_ang) integer, intent(in) :: body_id type(time_state_t), intent(in) :: time real(kind=rp), intent(inout) :: vel_trans(3) real(kind=rp), intent(inout) :: vel_ang(3) real(kind=rp) :: t
t = timet
select case (body_id) case (1) ! First registered body in ALE section in case file.
! Amplitude for x motion vel_trans(1) = Your_custom_Translational_Motion
! Amplitude for rotation around z vel_ang(3) = Your_custom_Rotational_Motion
end select end subroutine user_rigid_kinematics
Any motion defined based on `vel_trans` will be applied as an amplitude of translational velocity, whereas any motion defined by `vel_ang` will be the amplitude of angular velocity for that body. In the second example above (override), any motion set in the case file will be completely overridden by the custom motions.@attention `body_id` is defined based on the order in which the bodies are registered in the `"ale.bodies"` array in the case file.@note The `ale_rigid_kinematics` interface does not require the `base_shape` fields (see [here](#case-file_fluid-ale-solver) to read more about `base_shape` in Neko). The code will automatically apply the correct base shape fields to the motion based on the `body_id`.### Mesh Velocity {#user-file_ale-mesh-velocity}The interface `ale_mesh_velocity` allows you to implement a custom subroutine to directly manipulate the mesh velocity fields (`wm_x`, `wm_y`, `wm_z`). This is the only way to create custom surface deformation, e.g., time-dependent surface indentation.The following example illustrates how to apply a time-dependent surface indentation for a channel flow.fortran module user use neko implicit none
contains subroutine user_setup(user) type(user_t), intent(inout) :: user
! Register ALE mesh velocity userale_mesh_velocity => user_indentation_motion
end subroutine user_setup
subroutine user_indentation_motion(wm_x, wm_y, wm_z, coef, & x_ref, y_ref, z_ref, base_shapes, time) type(coef_t), intent(in) :: coef type(field_t), intent(inout) :: wm_x, wm_y, wm_z type(field_t), intent(in) :: x_ref, y_ref, z_ref type(field_t), intent(in) :: base_shapes(:) type(time_state_t), intent(in) :: time
integer :: i, n real(kind=rp) :: t, x_dist, half_width real(kind=rp) :: omega_ind real(kind=rp) :: h_t, arg, u_tanh, uy real(kind=rp) :: phi_top, phi_bot
! freq real(kind=rp) :: indent_freq = 0.05_rp ! The middle point of the indentation on x-axis real(kind=rp) :: indent_center = 20.0_rp ! The total width of the indentation real(kind=rp) :: indent_width = 4.0_rp ! Amplitude of the indentation real(kind=rp) :: indent_height = 0.25_rp ! Sharpness of the edge ! Higher = square box, Lower = smooth hill real(kind=rp) :: sharpness = 4.0_rp
t = timet n = coefdofsize()
! omega omega_ind = indent_freq * 2.0_rp * pi
h_t = indent_height * omega_ind * cos(omega_ind * t)
half_width = 0.5_rp * indent_width
! Copy mesh velocity from device to host if (NEKO_BCKND_DEVICE .eq. 1) then call device_memcpy(wm_yx, wm_yx_d, n, DEVICE_TO_HOST, .true.) end if
do i = 1, n
! Calculate Distance based on INITIAL mesh coordinates ! When running on device, x_ref, y_ref, z_ref are copied to host memory during init. ! So no need to copy them here. x_dist = abs(x_refx(i,1,1,1) - indent_center)
! If distance > half_width, arg becomes positive and tanh goes to 1 -> u_tanh goes to 0 arg = sharpness * (x_dist - half_width) u_tanh = 0.5_rp * (1.0_rp - tanh(arg))
uy = h_t * u_tanh
! When running on device, base_shapes are copied to host memory during init. ! So no need to copy them here. ! phi for bottom surface. body_ID = 1, since it's the first body registered in ale.bodies phi_bot = base_shapes(1)x(i,1,1,1)
! phi for top surface. body_ID = 2 phi_top = base_shapes(2)x(i,1,1,1)
wm_yx(i,1,1,1) = wm_yx(i,1,1,1) - ((0.5_rp*uy) * phi_top) + (uy * phi_bot)
end do
! Copy mesh velocity from host to device if (NEKO_BCKND_DEVICE .eq. 1) then call device_memcpy(wm_yx, wm_yx_d, n, HOST_TO_DEVICE, .true.) end if
end subroutine user_indentation_motion end module user
@warning This user subroutine is called at the very end of the mesh velocity calculation. This means that any modification to the mesh velocity in this subroutine will affect all motions applied earlier. `wm_y%%x(i,1,1,1) = wm_y%%x(i,1,1,1) + Your_Custom_Mesh_velocity` will superimpose on **all** previously set mesh motions, whereas `wm_y%%x(i,1,1,1) = Your_Custom_Mesh_velocity` will completely override any motion set earlier.@attention Even though it is logically possible to apply rigid body motion to an object using a custom `ale_mesh_velocity` subroutine, it **should not** be used for this purpose. Doing so bypasses several internal steps, causing computations regarding the pivot (see [this section](#case-file_fluid-ale-pivot)) and consequently rigid body calculations to be wrong. Always use the `ale_rigid_kinematics` interface for rigid body motion.@note Since `user_indentation_motion` subroutine directly manipulates the global mesh velocity fields, the computed mesh velocity should be multiplied by the corresponding `base_shape` for that body (see the example above).### Custom Base Shapes {#user-file_ale-base-shapes}The interface `ale_base_shapes` allows you to implement a user subroutine to define your own custom base shape fields for ALE mesh movements.> **Example:**fortran subroutine user_base_shapes(base_shapes) type(field_t), intent(inout) :: base_shapes(:) integer :: n
n = base_shapes(1)size()
if (NEKO_BCKND_DEVICE .eq. 1) then ! Fix the motion of the first ALE body (body_id = 1) call device_cfill(base_shapes(1)x_d, 0.0_rp, n) ! Apply the motion of the second ALE body (body_id = 2) to the entire domain call device_cfill(base_shapes(2)x_d, 1.0_rp, n) else ! Fix the motion of the first ALE body (body_id = 1) call cfill(base_shapes(1)x, 0.0_rp, n) ! Apply the motion of the second ALE body (body_id = 2) to the entire domain call cfill(base_shapes(2)x, 1.0_rp, n) end if
end subroutine user_base_shapes
The example above will suppress the mesh deformation associated with the first ALE body and apply the rigid body motion of ALE body 2 to the entire domain (including the inlet, outlet, and any other boundaries).@note If this user subroutine is utilized, it is the user's responsibility to verify that the total base shape field (\f$ \phi_{total} \f$) remains strictly bounded between 0.0 and 1.0.## Additional remarks and tips### Running on GPUs {#user-file_tips_running-on-gpus}When running on GPUs, special care must be taken when using certain userfunctions. The short explanation is that the device (GPU) has its own memory andcannot directly access the memory on the host (CPU). This means that data andmore specifically arrays must be copied manually from the host to the device(see device::device_memcpy).@attention In some cases, data transfer via `device_memcpy` is avoidable. Nekohas some device math functions implemented that operate directly on devicearrays. If you can decompose whatever operations you are performing in a userfunction into a set of instructions from the `math` module (e.g. `cadd`,`cfill`, `sub2`, ...), you may use the corresponding `device_math` functions to[offload work to the GPU](@ref accelerators_offload-work).Additionally, when you operate on `field_t` objects (which is very common), youcan use routines in the `field_math` module, that will automatically run on theright backend. This is highly recommended and avoids `if` statements.An example where manual transfer to the GPU was necessary has already beengiven for the source term. It is reiterated below.fortran subroutine source_term(scheme_name, rhs, time) character(len=*), intent(in) :: scheme_name type(field_list_t), intent(inout) :: rhs type(time_state_t), intent(in) :: time
real(kind=rp) :: x type(field_t), pointer :: f integer :: i
if (scheme_name .eq. 'fluid') return
f => rhsitems(1)ptr do i = 1, fsize() x = fdofx(i,1,1,1)
! 0.01 is the viscosity fx(i,1,1,1) = cos(x) - 0.01 * sin(x) - 1.0_rp end do
if (NEKO_BCKND_DEVICE .eq. 1) then call device_memcpy(fx, fx_d, fsize(), & HOST_TO_DEVICE, sync=.false.) end if
end subroutine source_term
Note that `f%%x` is the field's data on the CPU. Therefore, to populate thecorrespoding array on GPU, we need to call to `device_memcpy`.Looking at the detailof the `device_memcpy` call, we note the following:- Device arrays are refered to by appending the suffix `_d` to the host arrayvariable name (e.g. `f%%x` and `f%%x_d`). This is the standard in Neko.- We specify the direction of the data movement with the flag `HOST_TO_DEVICE`.Other flags can also be used to move data from device to host(`DEVICE_TO_HOST`) or device to device (`DEVICE_TO_DEVICE`). See the[accelerators page](@ref accelerators_data-transfer) for more details on this.- The `sync` argument is a non-optional argument which dictates wether or not toperform the data transfer synchronously.@attention Use asynchronous data transfers at your own risk! If you are unsure,use `sync = .true.` as a starting point.Finally, observe that we use the flag `NEKO_BCKND_DEVICE` to check if we areindeed running on GPUs. In that case, `NEKO_BCKND_DEVICE` would be equal to 1.### Running in multiple program multiple data (MPMD) mode {#user-file_tips_mpmd}Neko can run along other programs concurrently and communicate data between themthrough the `COMM_WORLD` communicator. This works to process data `in-situ` andfor other use-cases such as overset meshes.At the moment the important variable to set when executing in this mode is the`NEKO_COMM_ID` env variable. This can be done in line when executing neko but itis a good idea to have a helper script. It is also a good idea to redirectthe log file with `NEKO_LOG_FILE`. An example `run_inner.sh` would look like this:bash #!/usr/bin/env bash
export NEKO_LOG_FILE=innerlog.$SLURM_JOBID export NEKO_COMM_ID=0
./neko_inner cylinder_inner.case
Setting another helper to run another neko executable with `NEKO_COMM_ID` equal to `1`,and called `run_outer.sh` would allow to run both programs with:bash mpirun -np 4 ./run_inner.sh : -np 4 ./run_outer.sh
Note that the operator `:` is the one that indicates that both processesshare the same global communicator **this is not the same as running with &**.The latter generally runs two independent sessions that do not necessarily talkto each other. Check your MPI implementation's way of handling MPMD.If the other program is not neko, then you just need to make sureto split the global communicator with a color that is not the same as the idthat you gave to neko.On supercomputers, if `slurm` is used, generally the jobs need to be launchedwith the `--multi-prog` flag accompanied by a `mpmd.conf` file that indicateswhich rank runs which program. An example for running on a GPU cluster, whereGPUs must be selected looks like this:bash export MPICH_GPU_SUPPORT_ENABLED=1 CPU_BIND="map_cpu:49,57,17,25,1,9,33,41"
cat > select_gpu << 'EOF' #!/bin/bash export ROCR_VISIBLE_DEVICES=$SLURM_LOCALID exec "$@" EOF chmod +x ./select_gpu
cat > mpmd.conf << 'EOF' 0-7 ./select_gpu ./run_inner.sh 8-15 ./select_gpu ./run_outer.sh EOF
srun –unbuffered –cpu-bind=${CPU_BIND} –multi-prog mpmd.conf
rm -f ./select_gpu ./mpmd.conf
Note that here, `mpmd.conf` is generated internally. See that we are runningwith `16` ranks and ranks `0-7` run the inner job while the rest run the outer one.#### Custom GPU kernels {#user-file_tips_running-on-gpus-custom-kernels}When running on GPUs it is possible to call an own custom kernel. Thiscould be more performant for more complex source terms or boundaryconditions.Assume we have a custom kernel called `mydevice_kernel` in a CUDA filecalled `mykernel.cu`, to set the initial velicity field. To call thecustom kernel, the user file must define a C interface to the routine(inside the `.cu` file) that launches the kernelfortran interface subroutine mydevice_kernel(u_d, v_d, w_d, n) & bind(c, name = 'mydevice_kernel') use, intrinsic :: iso_c_binding, only: c_int, c_ptr type(c_ptr), value :: u_d, v_d, w_d integer(c_int) :: n end subroutine mydevice_kernel end interface
Furthermore, the CUDA/HIP file must allow for C linkage, hence theroutine `mydevice_kernel` must be inside an `extern "C"` block.cpp extern "C" { void mydevice_kernel(void <em>u, void *v, void *w, int *n) { / Launch the device kernel here */ } }
The user defined routine for initial conditions calls the kernel inthe following way.fortran
!> Set the advecting velocity field. subroutine set_velocity(u, v, w, p, params) type(field_t), intent(inout) :: u type(field_t), intent(inout) :: v type(field_t), intent(inout) :: w type(field_t), intent(inout) :: p type(json_file), intent(inout) :: params
if (NEKO_BCKND_DEVICE .eq. 1) then call mydevice_kernel(ux_d, vx_d, wx_d, udofsize()) endif
end subroutine set_velocity
Finally, compile using `makeneko` and provide both the `user.f90` and`mykernel.cu` file.bash makeneko user.f90 mykernel.cu
- Note
- makeneko does currently only support custom kernels written in CUDA or HIP.
Neko uses the concept of registry as a practical way to retrieve fields and point zones anywhere in the user file.
The registry neko_registry is often used in user functions where certain fields are not directly accessible as arguments. One can retrieve any field in the registry by its name with neko_registry%get_field(name). Default fields that are added to the registry are u,v,w,p and s if running with the scalar enabled. For a practical example of usage, see the rayleigh benard example
Other fields may be added to the registry by various simulation components. For example:
The point zone registry, neko_point_zone_registry, can be used to retrieve pointers to point_zone_t objects defined in the case file. See using point zones for detailed instructions.
Neko proives a special variable called neko_user_access that can be used in the user file to access the internal state of the entire case and the underlying solvers.
In particular the case object (case_t) is reached via neko_user_access%case. There-in the fluid and scalars components refer to the asscociated schemes. You are encouraged to look a bit at case.f90 to see the overall structure.
A very common use case is to get access to various SEM-related objects, as well as the mesh object.