Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ LIST(APPEND PROCESS_SRCS
stellarator_variables.f90
stellarator.f90
stellarator_configuration.f90
input.f90
)

PREPROCESS()
Expand Down
29 changes: 29 additions & 0 deletions process/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class ProcessException(Exception):
"""A base Exception to derive other PROCESS exceptions from"""

def __init__(self, *args, **kwargs):
super().__init__(*args)
self._diagnostics = kwargs

def __str__(self):
exception_message = super().__str__()
diagnostics_message = "\n".join(
[f"\t{d}: {repr(v)}" for d, v in self._diagnostics.items()]
)

if diagnostics_message:
return f"{exception_message}\n{diagnostics_message}"

return exception_message


class ProcessValidationError(ProcessException):
"""Exception raised when validating PROCESS input.

E.g. initial values, constraint/variable combinations, switch combinations"""

pass


class ProcessValueError(ProcessException, ValueError):
pass
1,092 changes: 1,092 additions & 0 deletions process/init.py

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions process/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from process.current_drive import CurrentDrive
from process.impurity_radiation import initialise_imprad
from process.caller import write_output_files
import process.init as init

import process

Expand Down Expand Up @@ -298,8 +299,8 @@ def run(self):
config = RunProcessConfig(self.config_file)
config.setup()

fortran.init_module.init_all_module_vars()
fortran.init_module.init()
init.init_all_module_vars()
init.init_process()

neqns, itervars = get_neqns_itervars()
lbs, ubs = get_variable_range(itervars, config.factor)
Expand Down Expand Up @@ -399,7 +400,7 @@ def init_module_vars():
This "resets" all module variables to their initialised values, so each
new run doesn't have any side-effects from previous runs.
"""
fortran.init_module.init_all_module_vars()
init.init_all_module_vars()

def set_filenames(self):
"""Validate the input filename and create other filenames from it."""
Expand Down Expand Up @@ -455,7 +456,7 @@ def initialise():
"""Run the init module to call all initialisation routines."""
initialise_imprad()
# Reads in input file
fortran.init_module.init()
init.init_process()

# Order optimisation parameters (arbitrary order in input file)
# Ensures consistency and makes output comparisons more straightforward
Expand Down
3 changes: 2 additions & 1 deletion scripts/vardes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import jinja2

from process.init import init_all_module_vars
from process import fortran


Expand Down Expand Up @@ -81,7 +82,7 @@ def get_input_output_variables(variables: List[FortranVariable]):
except AttributeError:
continue

fortran.init_module.init_all_module_vars()
init_all_module_vars()

for var in variables:
current_values_entry = f"{var.module}.{var.name}"
Expand Down
160 changes: 16 additions & 144 deletions source/fortran/init_module.f90
Original file line number Diff line number Diff line change
@@ -1,170 +1,43 @@
#ifndef INSTALLDIR
#error INSTALLDIR not defined!
#endif

module init_module

#ifndef dp
use, intrinsic :: iso_fortran_env, only: dp=>real64
#endif

implicit none

contains

subroutine init_all_module_vars
!! Initialise all module variables
!! This is vital to ensure a 'clean' state of Process before a new run starts,
!! otherwise components of the previous run's state can persist into the new
!! run. This matters ever since Process is used as a shared library, rather
!! than a 'run-once' executable.
use numerics, only: init_numerics
use process_input, only: init_input
use buildings_variables, only: init_buildings_variables
use cost_variables, only: init_cost_variables
use divertor_variables, only: init_divertor_variables
use error_handling, only: init_error_handling
subroutine init_fortran_modules
!! Temporary routine to call initialisation routines for Fortran modules
!! that are not wrapped by f2py and thus cannot be called from Python.

use fson_library, only: init_fson_library
use fwbs_variables, only: init_fwbs_variables
use global_variables, only: init_global_variables
use ccfe_hcpb_module, only: init_ccfe_hcpb_module
use heat_transport_variables, only: init_heat_transport_variables
use ife_variables, only: init_ife_variables
use impurity_radiation_module, only: init_impurity_radiation_module
use pfcoil_module, only: init_pfcoil_module
use physics_module, only: init_physics_module
use physics_variables, only: init_physics_variables
use scan_module, only: init_scan_module
use sctfcoil_module, only: init_sctfcoil_module
use stellarator_module, only: init_stellarator_module
use stellarator_variables, only: init_stellarator_variables
use tfcoil_variables, only: init_tfcoil_variables
use times_variables, only: init_times_variables
use constants, only: init_constants
use current_drive_variables, only: init_current_drive_variables
use primary_pumping_variables, only: init_primary_pumping_variables
use pfcoil_variables, only: init_pfcoil_variables
use structure_variables, only: init_structure_variables
use vacuum_variables, only: init_vacuum_variables
use pf_power_variables, only: init_pf_power_variables
use build_variables, only: init_build_variables
use constraint_variables, only: init_constraint_variables
use pulse_variables, only: init_pulse_variables
use rebco_variables, only: init_rebco_variables
use reinke_variables, only: init_reinke_variables
use define_iteration_variables, only: init_define_iteration_variables
use reinke_module, only: init_reinke_module
use water_usage_variables, only: init_watuse_variables
use CS_fatigue_variables, only: init_CS_fatigue_variables
use blanket_library, only: init_blanket_library
use dcll_module, only: init_dcll_module

call init_numerics
call init_input
call init_buildings_variables
call init_cost_variables
call init_divertor_variables
call init_error_handling
call init_fson_library
call init_fwbs_variables
call init_global_variables
call init_ccfe_hcpb_module
call init_heat_transport_variables
call init_ife_variables
call init_impurity_radiation_module
call init_pfcoil_module
call init_physics_module
call init_physics_variables
call init_scan_module
call init_sctfcoil_module
call init_stellarator_module
call init_stellarator_variables
call init_tfcoil_variables
call init_times_variables
call init_constants
call init_current_drive_variables
call init_primary_pumping_variables
call init_pfcoil_variables
call init_structure_variables
call init_vacuum_variables
call init_pf_power_variables
call init_build_variables
call init_constraint_variables
call init_pulse_variables
call init_rebco_variables
call init_reinke_variables
call init_define_iteration_variables
call init_reinke_module
call init_watuse_variables
call init_CS_fatigue_variables
call init_blanket_library
call init_dcll_module
end subroutine init_all_module_vars

subroutine init

!! Routine that calls the initialisation routines
!! author: P J Knight, CCFE, Culham Science Centre
!! None
!! This routine calls the main initialisation routines that set
!! the default values for the global variables, reads in data from
!! the input file, and checks the run parameters for consistency.

use global_variables, only: verbose, fileprefix, output_prefix
use main_module, only: run_summary
use constants, only: opt_file, vfile, nout, nplot, mfile, sig_file
use error_handling, only: initialise_error_list
use numerics, only: ixc , lablxc, nvar
use process_input, only: nin, input
use stellarator_module, only: stinit
implicit none

! Arguments

! Local variables
integer :: i

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call init_fson_library

! Initialise error handling
end subroutine init_fortran_modules

call initialise_error_list
subroutine open_files
use global_variables, only: verbose, fileprefix, output_prefix
use constants, only: nout, mfile
use process_input, only: nin

! Initialise the program variables
call initial
implicit none

! Open the input/output external files
if (trim(fileprefix) == "") then
open(unit=nin,file="IN.DAT",status='old')
else
open(unit=nin,file=trim(fileprefix),status='old')
end if
! open(unit=nin,file=trim(fileprefix)//'IN.DAT',status='old')

open(unit=nout ,file=trim(output_prefix)//'OUT.DAT' ,status='unknown')
open(unit=mfile ,file=trim(output_prefix)//'MFILE.DAT' ,status='unknown')

! Input any desired new initial values
call input

! Initialise stellarator parameters if necessary
! This overrides some of the bounds of the tokamak parameters
call stinit

! Check input data for errors/ambiguities
call check

! Write to the output file certain relevant details about this run
call run_summary

! Open verbose diagnostics file
if (verbose == 1) then
open(unit=vfile,file=trim(output_prefix)//'VFILE.DAT',status='unknown')
write(vfile,'(a80)') 'nviter = number of VMCON iterations.'
write(vfile,'(a80)') '(1-mod(ifail,7))=1 indicates that there has '// &
'been an escape from a failed line search.'
write(vfile,'(a80)') 'odd/even is a convenient plotting bit.'
write(vfile,'(100a13)') 'nviter','escape', 'odd/even', 'te','coe','rmajor', &
'fusion_power','bt','t_burn','sqsumsq', (lablxc(ixc(i)),i=1,nvar)
end if

end subroutine init
end subroutine open_files

subroutine open_idempotence_files
! Open new output file and mfile to write output to
Expand Down Expand Up @@ -223,5 +96,4 @@ subroutine finish
close(unit = opt_file)
if (verbose == 1) close(unit = vfile)
end subroutine finish

end module init_module
Loading