Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NP_TMcode
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Mulas
NP_TMcode
Commits
ed31ec86
Commit
ed31ec86
authored
3 months ago
by
Giovanni La Mura
Browse files
Options
Downloads
Patches
Plain Diff
Implement geometry configuration from script
parent
551d68e7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scripts/model_maker.py
+121
-32
121 additions, 32 deletions
src/scripts/model_maker.py
with
121 additions
and
32 deletions
src/scripts/model_maker.py
+
121
−
32
View file @
ed31ec86
...
@@ -36,8 +36,9 @@ def main():
...
@@ -36,8 +36,9 @@ def main():
print_help
()
print_help
()
else
:
else
:
sconf
,
gconf
=
load_model
(
argv
[
1
])
sconf
,
gconf
=
load_model
(
argv
[
1
])
if
sconf
is
not
None
:
if
(
sconf
is
not
None
)
and
(
gconf
is
not
None
)
:
result
=
write_legacy_sconf
(
sconf
)
result
=
write_legacy_sconf
(
sconf
)
if
(
result
==
0
):
result
+=
write_legacy_gconf
(
gconf
)
else
:
else
:
print
(
"
ERROR: could not create configuration.
"
)
print
(
"
ERROR: could not create configuration.
"
)
result
=
1
result
=
1
...
@@ -52,7 +53,8 @@ def interpolate_constants(sconf):
...
@@ -52,7 +53,8 @@ def interpolate_constants(sconf):
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_name
=
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
]
dielec_path
=
PurePath
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
file_name
=
str
(
dielec_path
)
dielec_file
=
open
(
file_name
,
'
r
'
)
dielec_file
=
open
(
file_name
,
'
r
'
)
wavelengths
=
[]
wavelengths
=
[]
rpart
=
[]
rpart
=
[]
...
@@ -142,6 +144,7 @@ def load_model(model_file):
...
@@ -142,6 +144,7 @@ def load_model(model_file):
sconf
[
'
xi_end
'
]
=
float
(
model
[
'
radiation_settings
'
][
'
scale_end
'
])
sconf
[
'
xi_end
'
]
=
float
(
model
[
'
radiation_settings
'
][
'
scale_end
'
])
sconf
[
'
xi_step
'
]
=
float
(
model
[
'
radiation_settings
'
][
'
scale_step
'
])
sconf
[
'
xi_step
'
]
=
float
(
model
[
'
radiation_settings
'
][
'
scale_step
'
])
sconf
[
'
configurations
'
]
=
int
(
model
[
'
particle_settings
'
][
'
n_types
'
])
sconf
[
'
configurations
'
]
=
int
(
model
[
'
particle_settings
'
][
'
n_types
'
])
sconf
[
'
dielec_path
'
]
=
model
[
'
material_settings
'
][
'
dielec_path
'
]
sconf
[
'
dielec_file
'
]
=
model
[
'
material_settings
'
][
'
dielec_file
'
]
sconf
[
'
dielec_file
'
]
=
model
[
'
material_settings
'
][
'
dielec_file
'
]
num_dielec
=
len
(
model
[
'
particle_settings
'
][
'
dielec_id
'
])
num_dielec
=
len
(
model
[
'
particle_settings
'
][
'
dielec_id
'
])
if
(
len
(
model
[
'
particle_settings
'
][
'
n_layers
'
])
!=
sconf
[
'
configurations
'
]):
if
(
len
(
model
[
'
particle_settings
'
][
'
n_layers
'
])
!=
sconf
[
'
configurations
'
]):
...
@@ -221,6 +224,44 @@ def load_model(model_file):
...
@@ -221,6 +224,44 @@ def load_model(model_file):
else
:
else
:
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
sconf
[
'
rcf
'
][
i
][
j
]
=
float
(
model
[
'
particle_settings
'
][
'
rad_frac
'
][
i
][
j
])
sconf
[
'
rcf
'
][
i
][
j
]
=
float
(
model
[
'
particle_settings
'
][
'
rad_frac
'
][
i
][
j
])
# Create the gconf dict
str_polar
=
model
[
'
radiation_settings
'
][
'
polarization
'
]
if
(
str_polar
not
in
[
"
LINEAR
"
,
"
CIRCULAR
"
]):
print
(
"
ERROR: %s is not a recognized polarization state.
"
%
str_polar
)
return
(
None
,
None
)
gconf
=
{
'
out_file
'
:
PurePath
(
model
[
'
input_settings
'
][
'
input_folder
'
],
model
[
'
input_settings
'
][
'
geometry_file
'
]
)
}
gconf
[
'
nsph
'
]
=
sconf
[
'
nsph
'
]
gconf
[
'
application
'
]
=
model
[
'
particle_settings
'
][
'
application
'
]
gconf
[
'
li
'
]
=
int
(
model
[
'
geometry_settings
'
][
'
li
'
])
gconf
[
'
le
'
]
=
int
(
gconf
[
'
li
'
]
if
gconf
[
'
application
'
]
==
"
SPHERE
"
else
model
[
'
geometry_settings
'
][
'
le
'
]
)
gconf
[
'
inpol
'
]
=
0
if
str_polar
==
"
LINEAR
"
else
1
gconf
[
'
npnt
'
]
=
int
(
model
[
'
geometry_settings
'
][
'
npnt
'
])
gconf
[
'
npntts
'
]
=
int
(
model
[
'
geometry_settings
'
][
'
npntts
'
])
gconf
[
'
iavm
'
]
=
int
(
model
[
'
geometry_settings
'
][
'
iavm
'
])
gconf
[
'
isam
'
]
=
int
(
model
[
'
geometry_settings
'
][
'
isam
'
])
gconf
[
'
th
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_start
'
])
gconf
[
'
thstp
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_step
'
])
gconf
[
'
thlst
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_end
'
])
gconf
[
'
ph
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_start
'
])
gconf
[
'
phstp
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_step
'
])
gconf
[
'
phlst
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_end
'
])
gconf
[
'
ths
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_start
'
])
gconf
[
'
thsstp
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_step
'
])
gconf
[
'
thslst
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_th_end
'
])
gconf
[
'
phs
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_start
'
])
gconf
[
'
phsstp
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_step
'
])
gconf
[
'
phslst
'
]
=
float
(
model
[
'
geometry_settings
'
][
'
in_ph_end
'
])
gconf
[
'
vec_sph_x
'
]
=
[
0.0
for
i
in
range
(
gconf
[
'
nsph
'
])]
gconf
[
'
vec_sph_y
'
]
=
[
0.0
for
i
in
range
(
gconf
[
'
nsph
'
])]
gconf
[
'
vec_sph_z
'
]
=
[
0.0
for
i
in
range
(
gconf
[
'
nsph
'
])]
gconf
[
'
jwtm
'
]
=
int
(
model
[
'
output_settings
'
][
'
jwtm
'
])
else
:
# model is None
else
:
# model is None
print
(
"
ERROR: could not parse
"
+
model_file
+
"
!
"
)
print
(
"
ERROR: could not parse
"
+
model_file
+
"
!
"
)
return
(
sconf
,
gconf
)
return
(
sconf
,
gconf
)
...
@@ -241,7 +282,8 @@ def match_grid(sconf):
...
@@ -241,7 +282,8 @@ def match_grid(sconf):
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_name
=
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
]
dielec_path
=
PurePath
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
file_name
=
str
(
dielec_path
)
dielec_file
=
open
(
file_name
,
'
r
'
)
dielec_file
=
open
(
file_name
,
'
r
'
)
wavelengths
=
[]
wavelengths
=
[]
rpart
=
[]
rpart
=
[]
...
@@ -302,8 +344,11 @@ def match_grid(sconf):
...
@@ -302,8 +344,11 @@ def match_grid(sconf):
## \brief Print a command-line help summary.
## \brief Print a command-line help summary.
def
print_help
():
def
print_help
():
print
(
"
"
)
print
(
"
###############################################
"
)
print
(
"
*** MODEL_MAKER ***
"
)
print
(
"
# #
"
)
print
(
"
# NPtm_code MODEL_MAKER #
"
)
print
(
"
# #
"
)
print
(
"
###############################################
"
)
print
(
"
"
)
print
(
"
"
)
print
(
"
Create input files for FORTRAN and C++ code.
"
)
print
(
"
Create input files for FORTRAN and C++ code.
"
)
print
(
"
"
)
print
(
"
"
)
...
@@ -315,18 +360,65 @@ def print_help():
...
@@ -315,18 +360,65 @@ def print_help():
print
(
"
--help Print this help and exit.
"
)
print
(
"
--help Print this help and exit.
"
)
print
(
"
"
)
print
(
"
"
)
def
write_legacy_sconf
(
sconf
):
## \brief Write the geometry configuration dictionary to legacy format.
#
# \param conf: `dict` Geometry configuration dictionary.
# \return result: `int` An exit code (0 if successful).
def
write_legacy_gconf
(
conf
):
result
=
0
out_file
=
str
(
conf
[
'
out_file
'
])
nsph
=
conf
[
'
nsph
'
]
str_line
=
"
INIT
"
# Write legacy output
output
=
open
(
out_file
,
'
w
'
)
if
(
conf
[
'
application
'
]
==
"
SPHERE
"
):
str_line
=
"
{0:4d} {1:4d} {2:4d} {3:4d} {4:4d} {5:4d}
\n
"
.
format
(
nsph
,
conf
[
'
li
'
],
conf
[
'
inpol
'
],
conf
[
'
npnt
'
],
conf
[
'
npntts
'
],
conf
[
'
isam
'
]
)
output
.
write
(
str_line
)
else
:
mxndm
=
2
*
nsph
*
conf
[
'
li
'
]
*
(
conf
[
'
li
'
]
+
2
)
str_line
=
"
{0:4d} {1:4d} {2:4d} {3:4d} {4:4d} {5:4d} {6:4d} {7:4d}
\n
"
.
format
(
nsph
,
conf
[
'
li
'
],
conf
[
'
le
'
],
mxndm
,
conf
[
'
inpol
'
],
conf
[
'
npnt
'
],
conf
[
'
npntts
'
],
conf
[
'
iavm
'
],
conf
[
'
isam
'
]
)
output
.
write
(
str_line
)
for
si
in
range
(
nsph
):
str_line
=
"
{0:15.8E} {1:15.8E} {2:15.8E}
\n
"
.
format
(
conf
[
'
vec_sph_x
'
][
si
],
conf
[
'
vec_sph_y
'
][
si
],
conf
[
'
vec_sph_z
'
][
si
]
)
output
.
write
(
str_line
)
str_line
=
"
{0:7.2E} {1:7.2E} {2:7.2E} {3:7.2E} {4:7.2E} {5:7.2E}
\n
"
.
format
(
conf
[
'
th
'
],
conf
[
'
thstp
'
],
conf
[
'
thlst
'
],
conf
[
'
ph
'
],
conf
[
'
phstp
'
],
conf
[
'
phlst
'
]
)
output
.
write
(
str_line
)
str_line
=
"
{0:7.2E} {1:7.2E} {2:7.2E} {3:7.2E} {4:7.2E} {5:7.2E}
\n
"
.
format
(
conf
[
'
ths
'
],
conf
[
'
thsstp
'
],
conf
[
'
thslst
'
],
conf
[
'
phs
'
],
conf
[
'
phsstp
'
],
conf
[
'
phslst
'
]
)
output
.
write
(
str_line
)
str_line
=
"
{0:d}
\n
0
\n
"
.
format
(
conf
[
'
jwtm
'
])
output
.
write
(
str_line
)
output
.
close
()
return
result
## \brief Write the scatterer configuration dictionary to legacy format.
#
# \param conf: `dict` Scatterer configuration dictionary.
# \return result: `int` An exit code (0 if successful).
def
write_legacy_sconf
(
conf
):
result
=
0
result
=
0
out_file
=
str
(
s
conf
[
'
out_file
'
])
out_file
=
str
(
conf
[
'
out_file
'
])
nsph
=
s
conf
[
'
nsph
'
]
nsph
=
conf
[
'
nsph
'
]
ies
=
s
conf
[
'
ies
'
]
ies
=
conf
[
'
ies
'
]
exdc
=
s
conf
[
'
exdc
'
]
exdc
=
conf
[
'
exdc
'
]
wp
=
s
conf
[
'
wp
'
]
wp
=
conf
[
'
wp
'
]
xip
=
s
conf
[
'
xip
'
]
xip
=
conf
[
'
xip
'
]
idfc
=
s
conf
[
'
idfc
'
]
idfc
=
conf
[
'
idfc
'
]
instpc
=
s
conf
[
'
instpc
'
]
instpc
=
conf
[
'
instpc
'
]
xi_flag
=
3
xi_flag
=
3
nxi
=
s
conf
[
'
nxi
'
]
nxi
=
conf
[
'
nxi
'
]
# Write legacy output
# Write legacy output
output
=
open
(
out_file
,
'
w
'
)
output
=
open
(
out_file
,
'
w
'
)
str_line
=
"
{0:3d}{1:3d}
\n
"
.
format
(
nsph
,
ies
)
str_line
=
"
{0:3d}{1:3d}
\n
"
.
format
(
nsph
,
ies
)
...
@@ -337,14 +429,14 @@ def write_legacy_sconf(sconf):
...
@@ -337,14 +429,14 @@ def write_legacy_sconf(sconf):
output
.
write
(
str_line
)
output
.
write
(
str_line
)
if
(
instpc
==
0
):
if
(
instpc
==
0
):
for
ixi
in
range
(
nxi
):
for
ixi
in
range
(
nxi
):
str_line
=
"
{0:.3E}
\n
"
.
format
(
s
conf
[
'
vec_xi
'
][
ixi
])
str_line
=
"
{0:.3E}
\n
"
.
format
(
conf
[
'
vec_xi
'
][
ixi
])
output
.
write
(
str_line
)
output
.
write
(
str_line
)
else
:
else
:
str_line
=
"
{0:.3E} {1:.3E}
\n
"
.
format
(
s
conf
[
'
xi_start
'
],
s
conf
[
'
xi_step
'
])
str_line
=
"
{0:.3E} {1:.3E}
\n
"
.
format
(
conf
[
'
xi_start
'
],
conf
[
'
xi_step
'
])
output
.
write
(
str_line
)
output
.
write
(
str_line
)
sphere_count
=
0
sphere_count
=
0
for
si
in
range
(
nsph
):
for
si
in
range
(
nsph
):
str_line
=
"
{0:5d}
"
.
format
(
s
conf
[
'
vec_types
'
][
si
])
str_line
=
"
{0:5d}
"
.
format
(
conf
[
'
vec_types
'
][
si
])
output
.
write
(
str_line
)
output
.
write
(
str_line
)
sphere_count
+=
1
sphere_count
+=
1
if
(
sphere_count
==
16
):
if
(
sphere_count
==
16
):
...
@@ -352,20 +444,20 @@ def write_legacy_sconf(sconf):
...
@@ -352,20 +444,20 @@ def write_legacy_sconf(sconf):
sphere_count
=
0
sphere_count
=
0
if
(
sphere_count
!=
0
):
if
(
sphere_count
!=
0
):
output
.
write
(
"
\n
"
)
output
.
write
(
"
\n
"
)
for
ci
in
range
(
s
conf
[
'
configurations
'
]):
for
ci
in
range
(
conf
[
'
configurations
'
]):
str_line
=
"
{0:3d} {1:15.7E}
\n
"
.
format
(
s
conf
[
'
nshl
'
][
ci
],
s
conf
[
'
ros
'
][
ci
])
str_line
=
"
{0:3d} {1:15.7E}
\n
"
.
format
(
conf
[
'
nshl
'
][
ci
],
conf
[
'
ros
'
][
ci
])
output
.
write
(
str_line
)
output
.
write
(
str_line
)
for
cj
in
range
(
s
conf
[
'
nshl
'
][
ci
]):
for
cj
in
range
(
conf
[
'
nshl
'
][
ci
]):
str_line
=
"
{0:.7E}
\n
"
.
format
(
s
conf
[
'
rcf
'
][
ci
][
cj
])
str_line
=
"
{0:.7E}
\n
"
.
format
(
conf
[
'
rcf
'
][
ci
][
cj
])
output
.
write
(
str_line
)
output
.
write
(
str_line
)
if
(
s
conf
[
'
idfc
'
]
==
0
):
if
(
conf
[
'
idfc
'
]
==
0
):
# Write all wavelength dependent constants for each layer in each configuration
# Write all wavelength dependent constants for each layer in each configuration
for
xi
in
range
(
s
conf
[
'
configurations
'
]):
for
xi
in
range
(
conf
[
'
configurations
'
]):
for
xj
in
range
(
s
conf
[
'
nshl
'
][
xi
]):
for
xj
in
range
(
conf
[
'
nshl
'
][
xi
]):
for
xk
in
range
(
s
conf
[
'
nxi
'
]):
for
xk
in
range
(
conf
[
'
nxi
'
]):
for
xii
in
range
(
s
conf
[
'
configurations
'
]):
for
xii
in
range
(
conf
[
'
configurations
'
]):
rdc0
=
s
conf
[
'
rdc0
'
][
xj
][
xii
][
xk
]
rdc0
=
conf
[
'
rdc0
'
][
xj
][
xii
][
xk
]
idc0
=
s
conf
[
'
idc0
'
][
xj
][
xii
][
xk
]
idc0
=
conf
[
'
idc0
'
][
xj
][
xii
][
xk
]
if
(
rdc0
!=
0.0
and
idc0
!=
0.0
):
if
(
rdc0
!=
0.0
and
idc0
!=
0.0
):
str_line
=
"
({0:11.5E},{1:11.5E})
\n
"
.
format
(
rdc0
,
idc0
)
str_line
=
"
({0:11.5E},{1:11.5E})
\n
"
.
format
(
rdc0
,
idc0
)
output
.
write
(
str_line
)
output
.
write
(
str_line
)
...
@@ -373,9 +465,6 @@ def write_legacy_sconf(sconf):
...
@@ -373,9 +465,6 @@ def write_legacy_sconf(sconf):
output
.
close
()
output
.
close
()
return
result
return
result
def
write_gconf
(
model
,
out_file
):
return
## \brief Exit code (0 for success)
## \brief Exit code (0 for success)
exit_code
=
main
()
exit_code
=
main
()
exit
(
exit_code
)
exit
(
exit_code
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment