Create hollow cylinder mesh in OpenFoam (journal bearing simulation) - mesh

I need to do the journal bearing simulation on OpenFOAM and I have tried several days even setting up the mesh by myself, however, what I get is the full cylinder, instead of the attached picture. Also appreciate if you can help with how I should specify my movingWall.
Below is my code for the boundaryMesh
convertToMeters 0.01;
vertices
(
(0.115 0.029 0) //vertex 0
(-0.065 0.029 0) //vertex 1
(-0.065 -0.029 0) //vertex 2
(0.115 -0.029 0) //vertex 3
(0.186 0.059 0) //vertex 4
(-0.186 0.059 0) //vertex 5
(-0.186 -0.059 0) //vertex 6
(0.186 -0.059 0) //vertex 7
(0.115 0.029 -5) //vertex 8
(-0.065 0.029 -5) //vertex 9
(-0.065 -0.029 -5) //vertex 10
(0.115 -0.029 -5) //vertex 11
(0.186 0.059 -5) //vertex 12
(-0.186 0.059 -5) //vertex 13
(-0.186 -0.059 -5) //vertex 14
(0.186 -0.059 -5) //vertex 15
);
blocks
(
hex (0 1 2 3 8 9 10 11) (5 5 3) simpleGrading (1 1 1) //block 1
hex (0 4 5 1 8 12 13 9) (5 5 3) simpleGrading (1 1 1) //block 2
hex (1 5 6 2 9 13 14 10) (5 5 3) simpleGrading (1 1 1) //block 3
hex (2 6 7 3 10 14 15 11) (5 5 3) simpleGrading (1 1 1) //block 4
hex (7 4 0 3 15 12 8 11) (5 5 3) simpleGrading (1 1 1) //block 5
);
edges
(
arc 4 5 (0 0.196 0) //edge 1
arc 5 6 (-0.196 0 0) //edge 2
arc 6 7 (0 -0.196 0) //edge 3
arc 7 4 (0.196 0 0) //edge 4
arc 0 1 (0 0.096 0) //edge 5
arc 1 2 (-0.071 0 0) //edge 6
arc 2 3 (0 -0.096 0) //edge 7
arc 3 0 (0.121 0 0) //edge 8
arc 12 13 (0 0.196 -5) //edge 9
arc 13 14 (-0.196 0 -5) //edge 10
arc 14 15 (0 -0.196 -5) //edge 11
arc 15 12 (0.196 0 -5) //edge 12
arc 8 9 (0 0.096 -5) //edge 13
arc 9 10 (-0.071 0 -5) //edge 14
arc 10 11 (0 -0.096 -5) //edge 15
arc 11 8 (0.121 0 -5) //edge 16
);
boundary
(
movingWall
{
type wall;
faces
(
(0 1 2 3)
(8 9 10 11)
);
}
fixedWalls
{
type patch;
faces
(
(0 4 5 1)
(1 5 6 2)
(2 6 7 3)
(3 7 4 0)
(8 9 13 12)
(9 10 14 13)
(10 11 15 14)
(11 8 12 15)
);
}
frontAndBack
{
type empty;
faces
(
(12 13 5 4)
(13 14 6 5)
(14 15 7 6)
(15 12 4 7)
);
}
);
mergePatchPairs();

Related

Why does this piecewise linear mixed model not produce equal estimates at the knot

I am wondering if someone could help me interpret my piecewise lmm results. Why does ggpredict() produce different estimates for the knot at 10 weeks (end of tx; see ‘0’ in graph at end)? I've structured the data like so:
bpiDat <- bpiDat %>%
mutate(baseToEndTx = ifelse(week <= 10, week, 1)) %>%
mutate(endOfTxToFu = case_when(
week <= 10 ~ 0,
week == 18 ~ 8,
week == 26 ~ 16,
week == 34 ~ 24
)) %>%
select(id, treatment, baseHamd, week, baseToEndTx, endOfTxToFu,
painInterferenceMean, painSeverityMean, bpiTotal) %>%
mutate(baseHamd = scale(baseHamd, scale=F))
Which looks like this:
id treatment baseHamd week baseToEndTx endOfTxToFu painSeverityMean
1 1 4.92529343 0 0 0 6.75
1 1 4.92529343 2 2 0 7.25
1 1 4.92529343 4 4 0 8.00
1 1 4.92529343 6 6 0 NA
1 1 4.92529343 8 8 0 8.25
1 1 4.92529343 10 10 0 8.00
1 1 4.92529343 18 1 8 8.25
1 1 4.92529343 26 1 16 8.25
1 4.92529343 34 1 24 8.00
The best fitting model:
model8 <- lme(painSeverityMean ~ baseHamd + baseToEndTx*treatment + endOfTxToFu + I(endOfTxToFu^2)*treatment,
data = bpiDat,
method = "REML",
na.action = "na.exclude",
random = ~baseToEndTx | id)
This is how I’m visualizing:
test1 <- ggpredict(model8, c("baseToEndTx", "treatment"), ci.lvl = NA) %>%
mutate(x = x - 10) %>%
mutate(phase = "duringTx")
test2 <- ggpredict(model8, c("endOfTxToFu", "treatment"), ci.lvl = NA) %>%
mutate(phase = "followUp")
t <- rbind(test1, test2)
t <- t %>%
pivot_wider(names_from = "phase",
values_from = "predicted")
ggplot(t) +
geom_smooth(aes(x,duringTx,col=group),method="lm",se=FALSE) +
geom_smooth(aes(x,followUp,col=group),method="lm",se=FALSE) +
geom_point(aes(x,duringTx,col=group)) +
geom_point(aes(x,followUp,col=group)) +
ylim(2,6)
Which produces this:


generate date feature column using pandas

I have a timeseries data frame that has columns like these:
Date temp_data holiday day
01.01.2000 10000 0 1
02.01.2000 0 1 2
03.01.2000 2000 0 3
..
..
..
26.01.2000 200 0 26
27.01.2000 0 1 27
28.01.2000 500 0 28
29.01.2000 0 1 29
30.01.2000 200 0 30
31.01.2000 0 1 31
01.02.2000 0 1 1
02.02.2000 2500 0 2
Here, holiday = 0 when there is data present - indicates a working day
holiday = 1 when there is no data present - indicated a non-working day
I am trying to extract three new columns from this data -second_last_working_day_of_month and third_last_working_day_of_month and the fourth_last_wday
the output data frame should look like this
Date temp_data holiday day secondlast_wd thirdlast_wd fouthlast_wd
01.01.2000 10000 0 1 1 0 0
02.01.2000 0 1 2 0 0 0
03.01.2000 2000 0 3 0 0 0
..
..
25.01.2000 345 0 25 0 0 1
26.01.2000 200 0 26 0 1 0
27.01.2000 0 1 27 0 0 0
28.01.2000 500 0 28 1 0 0
29.01.2000 0 1 29 0 0 0
30.01.2000 200 0 30 0 0 0
31.01.2000 0 1 31 0 0 0
01.02.2000 0 1 1 0 0 0
02.02.2000 2500 0 2 0 0 0
Can anyone help me with this?
Example
data = [['26.01.2000', 200, 0, 26], ['27.01.2000', 0, 1, 27], ['28.01.2000', 500, 0, 28],
['29.01.2000', 0, 1, 29], ['30.01.2000', 200, 0, 30], ['31.01.2000', 0, 1, 31],
['26.02.2000', 200, 0, 26], ['27.02.2000', 0, 0, 27], ['28.02.2000', 500, 0, 28],['29.02.2000', 0, 1, 29]]
df = pd.DataFrame(data, columns=['Date', 'temp_data', 'holiday', 'day'])
df
Date temp_data holiday day
0 26.01.2000 200 0 26
1 27.01.2000 0 1 27
2 28.01.2000 500 0 28
3 29.01.2000 0 1 29
4 30.01.2000 200 0 30
5 31.01.2000 0 1 31
6 26.02.2000 200 0 26
7 27.02.2000 0 0 27
8 28.02.2000 500 0 28
9 29.02.2000 0 1 29
Code
for example make secondlast_wd column (n=2)
n = 2
s = pd.to_datetime(df['Date'])
result = df['holiday'].eq(0) & df.iloc[::-1, 2].eq(0).groupby(s.dt.month).cumsum().eq(n)
result
0 False
1 False
2 True
3 False
4 False
5 False
6 False
7 True
8 False
9 False
Name: holiday, dtype: bool
make result to secondlast_wd column
df.assign(secondlast_wd=result.astype('int'))
output:
Date temp_data holiday day secondlast_wd
0 26.01.2000 200 0 26 0
1 27.01.2000 0 1 27 0
2 28.01.2000 500 0 28 1
3 29.01.2000 0 1 29 0
4 30.01.2000 200 0 30 0
5 31.01.2000 0 1 31 0
6 26.02.2000 200 0 26 0
7 27.02.2000 0 0 27 1
8 28.02.2000 500 0 28 0
9 29.02.2000 0 1 29 0
you can change n and can get third, forth and so on..
Update for comment
chk workday(reverse index)
df.iloc[::-1, 2].eq(0) # 2 means location of 'holyday'. can use df.loc[::-1,"holiday"]
9 False
8 True
7 True
6 True
5 False
4 True
3 False
2 True
1 False
0 True
Name: holiday, dtype: bool
reverse cumsum by group(month). then when workday is +1 above value and when holyday is still same value with above.(of course in reverse index)
df.iloc[::-1, 2].eq(0).groupby(s.dt.month).cumsum()
9 0
8 1
7 2
6 3
5 0
4 1
3 1
2 2
1 2
0 3
Name: holiday, dtype: int64
find holiday == 0 and result == 2, that is secondlast_wd
df['holiday'].eq(0) & df.iloc[::-1, 2].eq(0).groupby(s.dt.month).cumsum().eq(2)
0 False
1 False
2 True
3 False
4 False
5 False
6 False
7 True
8 False
9 False
Name: holiday, dtype: bool
This operation returns index as it was.(not reverse)
Other Way
A more understandable code would be:
s = pd.to_datetime(df['Date'])
idx1 = df[df['holiday'].eq(0)].groupby(s.dt.month, as_index=False).nth(-2).index
df.loc[idx1, 'lastsecondary_wd'] = 1
df['lastsecondary_wd'] = df['lastsecondary_wd'].fillna(0).astype('int')
same result

a list as a sublist of a list from group into list

I have a dataframe, which has 2 columns,
a b
0 1 2
1 1 1
2 1 1
3 1 2
4 1 1
5 2 0
6 2 1
7 2 1
8 2 2
9 2 2
10 2 1
11 2 1
12 2 2
Is there a direct way to make a third column as below
a b c
0 1 2 0
1 1 1 1
2 1 1 0
3 1 2 1
4 1 1 0
5 2 0 0
6 2 1 1
7 2 1 0
8 2 2 1
9 2 2 0
10 2 1 0
11 2 1 0
12 2 2 0
in which target [1, 2] is a sublist of df.groupby('a').b.apply(list), find the 2 rows that firstly fit the target in every group.
df.groupby('a').b.apply(list) gives
1 [2, 1, 1, 2, 1]
2 [0, 1, 1, 2, 2, 1, 1, 2]
[1,2] is a sublist of [2, 1, 1, 2, 1] and [0, 1, 1, 2, 2, 1, 1, 2]
so far, I have a function
def is_sub_with_gap(sub, lst):
'''
check if sub is a sublist of lst
'''
ln, j = len(sub), 0
ans = []
for i, ele in enumerate(lst):
if ele == sub[j]:
j += 1
ans.append(i)
if j == ln:
return True, ans
return False, []
test on the function
In [55]: is_sub_with_gap([1,2], [2, 1, 1, 2, 1])
Out[55]: (True, [1, 3])
You can change output by select index values of groups in custom function, flatten it by Series.explode and then test index values by Index.isin:
L = [1, 2]
def is_sub_with_gap(sub, lst):
'''
check of sub is a sublist of lst
'''
ln, j = len(sub), 0
ans = []
for i, ele in enumerate(lst):
if ele == sub[j]:
j += 1
ans.append(i)
if j == ln:
return lst.index[ans]
return []
idx = df.groupby('a').b.apply(lambda x: is_sub_with_gap(L, x)).explode()
df['c'] = df.index.isin(idx).view('i1')
print (df)
a b c
0 1 2 0
1 1 1 1
2 1 1 0
3 1 2 1
4 1 1 0
5 2 0 0
6 2 1 1
7 2 1 0
8 2 2 1
9 2 2 0
10 2 1 0
11 2 1 0
12 2 2 0

Display commend in ampl

I have a 2 dimension variable in ampl and I want to display it. I want to change the order of the indices but I do not know how to do that! I put my code , data and out put I described what kind of out put I want to have.
Here is my code:
param n;
param t;
param w;
param p;
set Var, default{1..n};
set Ind, default{1..t};
set mode, default{1..w};
var E{mode, Ind};
var B{mode,Var};
var C{mode,Ind};
param X{mode,Var,Ind};
var H{Ind};
minimize obj: sum{m in mode,i in Ind}E[m,i];
s.t. a1{m in mode, i in Ind}: sum{j in Var} X[m,j,i]*B[m,j] -C[m,i] <=E[m,i];
solve;
display C;
data;
param w:=4;
param n:=9;
param t:=2;
param X:=
[*,*,1]: 1 2 3 4 5 6 7 8 9 :=
1 69 59 100 70 35 1 1 0 0
2 34 31 372 71 35 1 0 1 0
3 35 25 417 70 35 1 0 0 1
4 0 10 180 30 35 1 0 0 0
[*,*,2]: 1 2 3 4 5 6 7 8 9 :=
1 64 58 68 68 30 2 1 0 0
2 44 31 354 84 30 2 0 1 0
3 53 25 399 85 30 2 0 0 1
4 0 11 255 50 30 2 0 0 0
The output of this code using glpksol is like tis:
C[1,1].val = -1.11111111111111
C[1,2].val = -1.11111111111111
C[2,1].val = -0.858585858585859
C[2,2].val = -1.11111111111111
C[3,1].val = -0.915032679738562
C[3,2].val = -1.11111111111111
C[4,1].val = 0.141414141414141
C[4,2].val = 0.2003367003367
but I want the result to be like this:
C[1,1].val = -1.11111111111111
C[2,1].val = -0.858585858585859
C[3,1].val = -0.915032679738562
C[4,1].val = 0.141414141414141
C[1,2].val = -1.11111111111111
C[2,2].val = -1.11111111111111
C[3,2].val = -1.11111111111111
C[4,2].val = 0.2003367003367
any idea?
You can use for loops and printf commands in your .run file:
for {i in Ind}
for {m in mode}
printf "C[%d,%d] = %.4f\n", m, i, C[m,i];
or even:
printf {i in Ind, m in mode} "C[%d,%d] = %.4f\n", m, i, C[m,i];
I don't get the same numerical results as you, but anyway the output works:
C[1,1] = 0.0000
C[2,1] = 0.0000
C[3,1] = 0.0000
C[4,1] = 0.0000
C[1,2] = 0.0000
C[2,2] = 0.0000
C[3,2] = 0.0000
C[4,2] = 0.0000

Find out range for every field in a column

I have a column that looks like this:
A 1
B 3
C 5
D 4
E 7
F 1
G 1
H 3
For every filed in column#2, I want to calculate the range (max-min) of 3 field radius up and down.
A range(1 3 5 4)
B range(1 3 5 4 7)
C range(1 3 5 4 7 1)
D range(1 3 5 4 7 1 1)
E range( 3 5 4 7 1 1 3)
F range( 5 4 7 1 1 3)
G range( 4 7 1 1 3)
H range( 7 1 1 3)
How can do this in awk?
I could do the same in perl using:
my $set_size = #values;
for ( my $i = 0 ; $i < $set_size ; $i++ ) {
my $min = $i - 4;
if ( $min < 0 ) { $min = 0; }
my $max = $i + 4;
if ( $max > ( $set_size - 1 ) ) { $max = $set_size - 1; }
my $min_val = $values[$min];
my $max_val = $values[$min];
for ( my $j = $min ; $j <= $max ; $j++ ) {
if ( $values[$j] <= $min_val ) { $min_val = $values[$j]; }
if ( $values[$j] >= $max_val ) { $max_val = $values[$j]; }
}
my $range = $max_val - $min_val;
printf "$points[$i] %.15f\n", $range;
}
idk exactly what I want to calculate the range (max-min) of 3 field radius up and down. means but to get the output you posted from the input you posted would be:
$ cat tst.awk
{
keys[NR] = $1
values[NR] = $2
}
END {
range = 3
for (i=1; i<=NR; i++) {
min = ( (i - range) >= 1 ? i - range : 1 )
max = ( (i + range) <= NR ? i + range : NR )
printf "%s range(", keys[i]
for (j=min; j<=max; j++) {
printf "%s%s", values[j], (j<max ? " " : ")\n")
}
}
}
$
$ awk -f tst.awk file
A range(1 3 5 4)
B range(1 3 5 4 7)
C range(1 3 5 4 7 1)
D range(1 3 5 4 7 1 1)
E range(3 5 4 7 1 1 3)
F range(5 4 7 1 1 3)
G range(4 7 1 1 3)
H range(7 1 1 3)
Your sample perl doesn't print out your sample output, it seems to do something different... so here's how I'd do it in perl:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw/say/;
use List::Util qw/min max/;
my (#col1, #col2);
while (<>) {
chomp;
my ($v1, $v2) = split;
push #col1, $v1;
push #col2, $v2;
}
my #prefix;
for my $i (0 .. $#col1) {
my #range = #col2[max($i - 3, 0) .. min($i + 3, $#col2)];
push #prefix, ' ' if $i > 3;
unshift #range, #prefix;
say "$col1[$i] range(#range)"
}
running it:
$ perl range.pl input.txt
A range(1 3 5 4)
B range(1 3 5 4 7)
C range(1 3 5 4 7 1)
D range(1 3 5 4 7 1 1)
E range( 3 5 4 7 1 1 3)
F range( 5 4 7 1 1 3)
G range( 4 7 1 1 3)
H range( 7 1 1 3)
The formatting will break if any of the numbers are greater than 9, though.
Since you tagged tcl:
#!/usr/bin/env tclsh
lassign $argv file size
set fh [open $file r]
# assume exactly 2 space-separated words per line
set data [dict create {*}[split [read -nonewline $fh]]]
close $fh
set len [dict size $data]
set values [dict values $data]
set i 0
dict for {key _} $data {
set first [expr {max($i - $size, 0)}]
set last [expr {min($i + $size, $len)}]
puts [format "%s range(%s%s)" \
$key \
[string repeat " " $first] \
[lrange $values $first $last] \
]
incr i
}
outputs
A range(1 3 5 4)
B range(1 3 5 4 7)
C range(1 3 5 4 7 1)
D range(1 3 5 4 7 1 1)
E range( 3 5 4 7 1 1 3)
F range( 5 4 7 1 1 3)
G range( 4 7 1 1 3)
H range( 7 1 1 3)
TXR at the shell prompt:
bash$ txr -c '#(collect)
#label #num
#(end)
#(bind rng #[window-map 3 nil (opip list (remq nil) (mapcar toint)) num])
#(output)
# (repeat)
#label range(#rng) -> #(find-min rng)..#(find-max rng)
# (end)
#(end)'
A 1
B 3
C 5
D 4
E 7
F 1
G 1
H 3
[Ctrl-D][Enter]
A range(1 3 5 4) -> 1..5
B range(1 3 5 4 7) -> 1..7
C range(1 3 5 4 7 1) -> 1..7
D range(1 3 5 4 7 1 1) -> 1..7
E range(3 5 4 7 1 1 3) -> 1..7
F range(5 4 7 1 1 3) -> 1..7
G range(4 7 1 1 3) -> 1..7
H range(7 1 1 3) -> 1..7