@@ -64,8 +64,8 @@ function soft_dependencies(d::DependencyGraph{Dict{Symbol,HardDependencyNode}},
6464 soft_dep_vars. value,
6565 process_, # process name
6666 " " ,
67- inputs_ (soft_dep_vars. value),
68- outputs_ (soft_dep_vars. value),
67+ # inputs_(soft_dep_vars.value),
68+ # outputs_(soft_dep_vars.value),
6969 AbstractTrees. children (soft_dep_vars), # hard dependencies
7070 nothing ,
7171 nothing ,
@@ -323,156 +323,32 @@ function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dic
323323 end
324324
325325 if haskey (timestep_mapped_outs, proc)
326- CreateTimeStepMapping (i, reverse_multiscale_mapping, organ , proc)
326+ create_timestep_mapping (i, timestep_mapped_outs , proc)
327327 end
328328
329329 end
330330 end
331331
332332 dep_graph = DependencyGraph (independant_process_root, soft_dep_graphs_roots. not_found)
333333
334- # TODO move these into the loop to directly act on the ndoe, use the provided timestep mappings
335- # Don't provide parents, and then change the run! function to apply from the node to itself
336- # traverse_dependency_graph!(x -> set_non_default_timestep_in_node(x, orchestrator), dependency_graph, visit_hard_dep=false)
337- # traverse_dependency_graph!(x -> add_timestep_data_to_node(x, orchestrator), dep_graph, visit_hard_dep=false)
338-
339-
340334 return dep_graph
341335end
342336
343- # # set the timestep for everyone first, else we might not use the correct timestep when looking at the parents later
344- function set_non_default_timestep_in_node (soft_dependency_node, orchestrator:: Orchestrator2 )
345- for mtsm in orchestrator. non_default_timestep_mapping
346- if mtsm. scale == soft_dependency_node. scale && (mtsm. model) == typeof (model_ (soft_dependency_node. value))
347- soft_dependency_node. timestep = mtsm. timestep
348- end
349- end
350- end
351-
352- function add_timestep_data_to_node (soft_dependency_node, orchestrator:: Orchestrator2 )
353-
354- # now we can create the mapping
355- for mtsm in orchestrator. non_default_timestep_mapping
356- if mtsm. scale == soft_dependency_node. scale && (mtsm. model) == typeof (model_ (soft_dependency_node. value))
357- for (var_from, var_to) in mtsm. var_to_var
358- if ! isnothing (soft_dependency_node. parent)
359- parent = nothing
360- variable_mapping = nothing
361- for parent_node in soft_dependency_node. parent
362- if typeof (parent_node. value) == var_from. model && parent_node. scale == var_from. scale
363- parent = parent_node
364- variable_mapping = create_timestep_mapping (soft_dependency_node, parent, var_to, var_from)
365- break
366- end
367- end
368- if isnothing (parent)
369- # error
370- end
371- if isnothing (parent. timestep_mapping_data)
372- parent. timestep_mapping_data = Vector {TimestepMapping} ()
373- end
374- push! (parent. timestep_mapping_data, variable_mapping)
375- else
376- # Error
377- end
378- end
379- end
380- end
381- end
382-
383- # Create the structure to attach to the softdependencynode, (not to be confused with the user-declared timestep-mapping structure)
384- function create_timestep_mapping (node:: SoftDependencyNode , parent:: SoftDependencyNode , var_to:: Var_to , var_from:: Var_from )
385-
386- @assert parent. timestep != 0 " Error : node timestep internally set to 0"
387-
388- timestep_ratio = node. timestep / parent. timestep
389-
390- # Keeping things simple for now, only integers allowed
391- @assert timestep_ratio == trunc (timestep_ratio) " Error : non-integer timestep ratio"
392-
393- # TODO ensure type compatibility between var_to and var_from
394- # Simplification probably possible by doing the check earlier
395-
396- # TODO test previoustimestep
397- var_type = DataType
398-
399- for (symbol, var_dump) in node. inputs
400- for var in var_dump
401- if isa (var, MappedVar)
402- # check the source variable, because the sink one might be a vector...?
403- # TODO multinode mapping
404- if isa (var. source_organ, MultiNodeMapping)
405- if var. source_variable[1 ] == var_from. name
406- # This should be a fixed size array, ideally
407- var_type = eltype (eltype (mapped_default (var)))
408- break
409- end
410- else
411- if var. source_variable == var_from. name
412- # This should be a fixed size array, ideally
413- var_type = eltype (mapped_default (var))
414- break
415- end
416- end
417- else
418- if var. symbol == var_from. name
419- @assert " untested"
420- var_type = eltype (mapped_default (var))
421- break
422- end
423- end
424- end
425- end
426-
427- # TODO : type shouldn't be Any but Vector{var_type}
428- return TimestepMapping (var_from. name, var_to. name, node, var_from. mapping_function, mapping_data_template, Dict {MultiScaleTreeGraph.NodeMTG, Any} ())
429- end
430-
431-
432- function CreateTimeStepMapping (soft_dependency_node, reverse_multiscale_mapping, scale, proc)
433-
434- for mapping_entry in reverse_multiscale_mapping[scale]
435- if isa (mapping_entry, MultiScaleModel)
436- if process (mapping_entry. model) == proc
437- for timestep_mapped_var_data in mapping_entry. timestep_mapped_variables
438- timestep_ratio = timestep_mapped_var_data. timestep_to / soft_dependency_node. timestep
439- if timestep_ratio > 1 # todo assert it's an int or a rational ?
440- @assert timestep_ratio == trunc (timestep_ratio) " Error : non-integer timestep ratio"
337+ function create_timestep_mapping (soft_dependency_node, timestep_mapped_outs, proc)
441338
442- tmvd = timestep_mapped_var_data
339+ for (proc_mapped, mapping_entries) in timestep_mapped_outs
443340
444- var_type = DataType
341+ if proc_mapped == proc
342+ for (var_to, (timestep_mapped_var_data, default_value)) in mapping_entries
343+ timestep_ratio = timestep_mapped_var_data. timestep_to / soft_dependency_node. timestep
344+ if timestep_ratio > 1 # todo assert it's an int or a rational ?
345+ @assert timestep_ratio == trunc (timestep_ratio) " Error : non-integer timestep ratio"
445346
446- for (symbol, var_dump) in soft_dependency_node. outputs
447- for var in var_dump
448- if isa (var, MappedVar)
449- # check the source variable, because the sink one might be a vector...?
450- # TODO multinode mapping
451- if isa (var. source_organ, MultiNodeMapping)
452- if var. source_variable[1 ] == tmvd. name_from
453- # This should be a fixed size array, ideally
454- var_type = eltype (eltype (mapped_default (var)))
455- break
456- end
457- else
458- if var. source_variable == tmvd. name_from
459- # This should be a fixed size array, ideally
460- var_type = eltype (mapped_default (var))
461- break
462- end
463- end
464- else
465- if var. symbol == tmvd. name_from
466- @assert " untested"
467- var_type = eltype (mapped_default (var))
468- break
469- end
470- end
471- end
472- end
347+ tmvd = timestep_mapped_var_data
348+ var_type = typeof (default_value)
473349
474- mapping_data_template = Vector {var_type} (undef, convert (Int64, timestep_ratio))
475- tsm = TimestepMapping (tmvd. name_from, tmvd. name_to, soft_dependency_node , tmvd. aggregation_function, mapping_data_template, Dict {MultiScaleTreeGraph.NodeMTG,Any} ())
350+ mapping_data_template = Vector {var_type} (undef, convert (Int64, timestep_ratio))
351+ tsm = TimestepMapping (tmvd. name_from, tmvd. name_to, timestep_mapped_var_data . timestep_to , tmvd. aggregation_function, mapping_data_template, Dict {MultiScaleTreeGraph.NodeMTG,Any} ())
476352
477353 if isnothing (soft_dependency_node. timestep_mapping_data)
478354 soft_dependency_node. timestep_mapping_data = Vector {TimestepMapping} ()
@@ -483,10 +359,9 @@ function CreateTimeStepMapping(soft_dependency_node, reverse_multiscale_mapping,
483359 end
484360 end
485361end
486- end
487362
488363
489- """
364+ """
490365 drop_process(proc_vars, process)
491366
492367Return a new `NamedTuple` with the process `process` removed from the `NamedTuple` `proc_vars`.
@@ -674,6 +549,13 @@ function search_inputs_in_multiscale_output(process, organ, inputs, soft_dep_gra
674549 return inputs_as_output_of_other_scale
675550end
676551
552+ function extract_mapped_outputs (timestep_mapped_outputs)
553+ extracted = Pair[]
554+ for pair in timestep_mapped_outputs
555+ push! (extracted, Pair (first (last (pair)). name_to, last (last (pair))))
556+ end
557+ return extracted
558+ end
677559
678560function add_input_as_output! (inputs_as_output_of_other_scale, soft_dep_graphs, organ_source, variable, value)
679561
@@ -684,7 +566,7 @@ function add_input_as_output!(inputs_as_output_of_other_scale, soft_dep_graphs,
684566 vars_all_outputs = vars_output
685567
686568 if haskey (timestep_mapped_outputs, proc_output)
687- vars_all_outputs = (; vars_output... , flatten_vars (timestep_mapped_outputs)... )
569+ vars_all_outputs = (; vars_output... , extract_mapped_outputs (timestep_mapped_outputs[proc_output] )... )
688570 end
689571
690572 # If the variable is found in the outputs of the process at the other scale:
0 commit comments