2973 def initialise(self, parent):
2975 Create the declarations and assignments required for the
2976 basis-functions required by an invoke. These are added as children
2977 of the supplied parent node in the AST.
2979 :param parent: the node in the f2pygen AST that will be the
2980 parent of all of the declarations and assignments.
2981 :type parent: :py:class:`psyclone.f2pygen.SubroutineGen`
2983 :raises InternalError: if an invalid entry is encountered in the \
2984 self._basis_fns list.
2987 api_config = Config.get().api_conf(
"dynamo0.3")
2988 const = LFRicConstants()
2989 basis_declarations = []
2993 if self._qr_vars
or self._eval_targets:
2995 UseGen(parent, name=const.
2996 FUNCTION_SPACE_TYPE_MAP[
"function_space"][
"module"],
2997 only=
True, funcnames=[
"BASIS",
"DIFF_BASIS"]))
3000 parent.add(CommentGen(parent,
""))
3001 parent.add(CommentGen(parent,
" Look-up quadrature variables"))
3002 parent.add(CommentGen(parent,
""))
3005 for shp
in self._qr_vars:
3006 quad_map = const.QUADRATURE_TYPE_MAP[shp]
3007 parent.add(UseGen(parent,
3008 name=quad_map[
"module"],
3010 funcnames=[quad_map[
"type"],
3011 quad_map[
"proxy_type"]]))
3012 self._initialise_xyz_qr(parent)
3013 self._initialise_xyoz_qr(parent)
3014 self._initialise_xoyoz_qr(parent)
3015 self._initialise_face_or_edge_qr(parent,
"face")
3016 self._initialise_face_or_edge_qr(parent,
"edge")
3018 if self._eval_targets:
3019 parent.add(CommentGen(parent,
""))
3020 parent.add(CommentGen(parent,
3021 " Initialise evaluator-related quantities "
3022 "for the target function spaces"))
3023 parent.add(CommentGen(parent,
""))
3025 for (fspace, arg)
in self._eval_targets.values():
3028 nodes_name =
"nodes_" + fspace.mangled_name
3029 parent.add(AssignGen(
3030 parent, lhs=nodes_name,
3031 rhs=
"%".join([arg.proxy_name_indexed, arg.ref_name(fspace),
3034 my_kind = api_config.default_kind[
"real"]
3035 parent.add(DeclGen(parent, datatype=
"real",
3038 entity_decls=[nodes_name+
"(:,:) => null()"]))
3039 const_mod = const.UTILITIES_MOD_MAP[
"constants"][
"module"]
3040 const_mod_uses = self._invoke.invokes.psy. \
3041 infrastructure_modules[const_mod]
3045 const_mod_uses.add(my_kind)
3048 parent.add(CommentGen(parent,
""))
3049 parent.add(CommentGen(parent,
" Allocate basis/diff-basis arrays"))
3050 parent.add(CommentGen(parent,
""))
3053 for basis_fn
in self._basis_fns:
3055 if basis_fn[
'type'] ==
"basis":
3056 first_dim = self.basis_first_dim_name(basis_fn[
"fspace"])
3057 dim_space =
"get_dim_space()"
3058 elif basis_fn[
'type'] ==
"diff-basis":
3059 first_dim = self.diff_basis_first_dim_name(
3061 dim_space =
"get_dim_space_diff()"
3063 raise InternalError(
3064 f
"Unrecognised type of basis function: "
3065 f
"'{basis_fn['''type''']}'. Should be either 'basis' or "
3068 if first_dim
not in var_dim_list:
3069 var_dim_list.append(first_dim)
3071 [basis_fn[
"arg"].proxy_name_indexed,
3072 basis_fn[
"arg"].ref_name(basis_fn[
"fspace"]),
3074 parent.add(AssignGen(parent, lhs=first_dim, rhs=rhs))
3076 var_dims, basis_arrays = self._basis_fn_declns()
3080 parent.add(DeclGen(parent, datatype=
"integer",
3081 kind=api_config.default_kind[
"integer"],
3082 entity_decls=var_dims))
3084 basis_declarations = []
3085 for basis
in basis_arrays:
3088 basis+
"("+
", ".join(basis_arrays[basis])+
")"))
3089 basis_declarations.append(
3090 basis+
"("+
",".join([
":"]*len(basis_arrays[basis]))+
")")
3093 if basis_declarations:
3094 my_kind = api_config.default_kind[
"real"]
3095 parent.add(DeclGen(parent, datatype=
"real", kind=my_kind,
3097 entity_decls=basis_declarations))
3103 self._compute_basis_fns(parent)