From 563d566a3f699af85a8fe558ebf7c724d4fd4756 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 14 Apr 2022 01:06:47 +0200 Subject: [PATCH] made two loops faster the most annoying one is still slow. --- src/YAML_types.f90 | 2 +- src/material.f90 | 50 ++++++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/YAML_types.f90 b/src/YAML_types.f90 index b32651905..857b24bd0 100644 --- a/src/YAML_types.f90 +++ b/src/YAML_types.f90 @@ -145,7 +145,7 @@ module YAML_types end type tDict - type :: tItem + type, public :: tItem character(len=:), allocatable :: key class(tNode), pointer :: node => NULL() class(tItem), pointer :: next => NULL() diff --git a/src/material.f90 b/src/material.f90 index 3ff280b0d..4d6bc361d 100644 --- a/src/material.f90 +++ b/src/material.f90 @@ -91,6 +91,7 @@ subroutine parse() homogenizations, & homogenization + class(tItem), pointer :: item integer, dimension(:), allocatable :: & counterPhase, & counterHomogenization @@ -102,6 +103,7 @@ subroutine parse() co, ce, & ma + materials => config_material%get('material') phases => config_material%get('phase') homogenizations => config_material%get('homogenization') @@ -169,17 +171,23 @@ subroutine parse() allocate(material_O_0(materials%length)) allocate(material_F_i_0(materials%length)) - do ma = 1, materials%length - material => materials%get(ma) - constituents => material%get('constituents') - allocate(material_O_0(ma)%data(constituents%length)) - allocate(material_F_i_0(ma)%data(1:3,1:3,constituents%length)) - do co = 1, constituents%length - constituent => constituents%get(co) - call material_O_0(ma)%data(co)%fromQuaternion(constituent%get_as1dFloat('O',requiredSize=4)) - material_F_i_0(ma)%data(1:3,1:3,co) = constituent%get_as2dFloat('F_i',defaultVal=math_I3,requiredShape=[3,3]) - enddo - enddo + ! manual iteration for performance + select type(materials) + class is(tList) + item => materials%first + do ma = 1, materials%length + material => item%node + constituents => material%get('constituents') + allocate(material_O_0(ma)%data(constituents%length)) + allocate(material_F_i_0(ma)%data(1:3,1:3,constituents%length)) + do co = 1, constituents%length + constituent => constituents%get(co) + call material_O_0(ma)%data(co)%fromQuaternion(constituent%get_as1dFloat('O',requiredSize=4)) + material_F_i_0(ma)%data(1:3,1:3,co) = constituent%get_as2dFloat('F_i',defaultVal=math_I3,requiredShape=[3,3]) + end do + item => item%next + end do + end select end subroutine parse @@ -195,17 +203,25 @@ subroutine sanityCheck(materials,homogenizations) class(tNode), pointer :: material, & homogenization, & constituents + class(tItem), pointer :: item integer :: m + if (maxval(discretization_materialAt) > materials%length) & call IO_error(155,ext_msg='More materials requested than found in material.yaml') - do m = 1, materials%length - material => materials%get(m) - constituents => material%get('constituents') - homogenization => homogenizations%get(material%get_asString('homogenization')) - if (constituents%length /= homogenization%get_asInt('N_constituents')) call IO_error(148) - end do + ! manual iteration for performance + select type(materials) + class is(tList) + item => materials%first + do m = 1, materials%length + material => materials%get(m) + constituents => material%get('constituents') + homogenization => homogenizations%get(material%get_asString('homogenization')) + if (constituents%length /= homogenization%get_asInt('N_constituents')) call IO_error(148) + item => item%next + end do + end select end subroutine sanityCheck