I am quite new to both abaqus and fortran programming. I am working on a project where I am tying phase field to fracture propagation where the void phase is taken into the kinematics of the crack propagation. I will not go too much into detail!
I have attached 3 codes/messages with my question here:
a) umat_sdvini3.f (my user subroutine file that has both sdvini and umat in it)
b) Job-User-mod-9.inp (the .inp input file that I created with the help of Abaqus CAE)
c) Job-User-15.msg (the file that contains the error message!)
When I am telling Abaqus to run the job with the user subroutine, the job gets aborted for some reason! In the previous job runs (11 to 14), when in the subroutine file, the if/else statement for the state variable was commented out, everything ran fine!
With the second if/else statement uncommented in the attached fortran file, there is an error and the job is getting aborted!
The fortran 77 code for my user subroutine: (it is the second if/else statement command block not running properly! I thought I could access the values of the solution dependent state variables via coords(1) which is the x-coordinates!
subroutine sdvini(statev,coords,nstatv,ncrds,noel,npt,layer,kspt)
include 'aba_param.inc'
dimension statev(nstatv), coords(ncrds)
statev(1)=5.d0
return
end
subroutine umat(stress,statev,ddsdde,sse,spd,scd,
1 rpl,ddsddt,drplde,drpldt,
2 stran,dstran,time,dtime,temp,dtemp,predef,dpred,cmname,
3 ndi,nshr,ntens,nstatv,props,nprops,coords,drot,pnewdt,
4 celent,dfgrd0,dfgrd1,noel,npt,layer,kspt,kstep,kinc)
include 'aba_param.inc'
character*80 cmname
dimension stress(ntens),statev(nstatv)
dimension ddsdde(ntens,ntens),ddsddt(ntens),drplde(ntens)
dimension stran(ntens),dstran(ntens),time(2),predef(1),dpred(1)
dimension props(nprops),coords(3),drot(3,3),dfgrd0(3,3),dfgrd1(3,3)
C real E, xnu, bulk, shear
integer i, j
ddsdde = 0.d0
E = props(1)
xnu = props(2)
statev(1)=5.d0
shear = E/2.d0/(1.d0+xnu)
bulk = E/3.d0/(1.d0-2.d0*xnu)
real f_i=1.0e-10
real w_bar=0.25d0
real walpha=2.d0
a_1 = (-2)*(1.d0-f_i)/0.25d0
a_2 = (1.d0-f_i)/(0.25**2)
C omega = statev(1)
if(ndi.eq.2 .and. nshr.eq.1) then
ddsdde(1,1) = bulk + (10.d0/9.d0)*shear
ddsdde(1,2) = bulk - (8.d0/9.d0)*shear
ddsdde(2,1) = bulk - (8.d0/9.d0)*shear
ddsdde(2,2) = bulk + (10.d0/9.d0)*shear
ddsdde(3,3) = 2.d0*shear
ddsdde = ddsdde*statev(1)
end if
do i=1,ntens
do j=1,ntens
stress(i) = stress(i) + ddsdde(i,j)*dstran(j)
end do
end do
if(coords(1).le.0 .and. coords(2).eq.0) then
statev(1) = (w_bar*(1-tanh(w_alpha*coords(1))))
statev(1)=1.d0+a_1*(statev(1))+a_2*(statev(1)**2)
elseif(coords(1).gt.0 .and. coords(2).eq.0) then
statev(1) = (w_bar*(1+tanh(w_alpha*coords(1))))
statev(1)=1.d0+a_1*(statev(1))+a_2*(statev(1)**2)
else
statev(1)=0.d0
end if
statev(1)=state(1) + kinc
write(6,*) ddsdde
return
end
This is the .inp file of the Abaqus (Standard):
*Heading
** Job name: Job-User-9 Model name: Model-1
** Generated by: Abaqus/CAE 6.14-2
*Preprint, echo=NO, model=NO, history=NO, contact=NO
**
** PARTS
**
*Part, name=Plate
*Node
1, 0., 100.
2, 0., 99.5
3, 0., 99.
4, 0., 98.5
5, 0., 98.
6, 0., 97.5
7, 0., 97.
8, 0., 96.5
9, 0., 96.
10, 0., 95.5
11, 0., 95.
12, 0., 94.5
13, 0., 94.
14, 0., 93.5
15, 0., 93.
16, 0., 92.5
17, 0., 92.
18, 0., 91.5
19, 0., 91.
20, 0., 90.5
21, 0., 90.
22, 0., 89.5
23, 0., 89.
24, 0., 88.5
25, 0., 88.
26, 0., 87.5
27, 0., 87.
28, 0., 86.5
29, 0., 86.
30, 0., 85.5
31, 0., 85.
32, 0., 84.5
33, 0., 84.
34, 0., 83.5
35, 0., 83.
36, 0., 82.5
37, 0., 82.
38, 0., 81.5
39, 0., 81.
40, 0., 80.5
41, 0., 80.
42, 0., 79.5
43, 0., 79.
44, 0., 78.5
45, 0., 78.
46, 0., 77.5
47, 0., 77.
48, 0., 76.5
49, 0., 76.
50, 0., 75.5
...
...
...
*Element, type=CPS4R
1, 1, 2, 203, 202
2, 2, 3, 204, 203
3, 3, 4, 205, 204
4, 4, 5, 206, 205
5, 5, 6, 207, 206
6, 6, 7, 208, 207
7, 7, 8, 209, 208
8, 8, 9, 210, 209
9, 9, 10, 211, 210
10, 10, 11, 212, 211
11, 11, 12, 213, 212
12, 12, 13, 214, 213
13, 13, 14, 215, 214
14, 14, 15, 216, 215
15, 15, 16, 217, 216
16, 16, 17, 218, 217
17, 17, 18, 219, 218
18, 18, 19, 220, 219
19, 19, 20, 221, 220
20, 20, 21, 222, 221
21, 21, 22, 223, 222
22, 22, 23, 224, 223
23, 23, 24, 225, 224
24, 24, 25, 226, 225
25, 25, 26, 227, 226
26, 26, 27, 228, 227
27, 27, 28, 229, 228
28, 28, 29, 230, 229
29, 29, 30, 231, 230
30, 30, 31, 232, 231
31, 31, 32, 233, 232
32, 32, 33, 234, 233
33, 33, 34, 235, 234
34, 34, 35, 236, 235
35, 35, 36, 237, 236
36, 36, 37, 238, 237
37, 37, 38, 239, 238
38, 38, 39, 240, 239
39, 39, 40, 241, 240
40, 40, 41, 242, 241
41, 41, 42, 243, 242
42, 42, 43, 244, 243
43, 43, 44, 245, 244
44, 44, 45, 246, 245
45, 45, 46, 247, 246
46, 46, 47, 248, 247
47, 47, 48, 249, 248
48, 48, 49, 250, 249
49, 49, 50, 251, 250
50, 50, 51, 252, 251
...
...
...
*Nset, nset=Set-1, generate
1, 40401, 1
*Elset, elset=Set-1, generate
1, 40000, 1
** Section: Section-1
*Solid Section, elset=Set-1, controls=EC-1, material=Material-1
1.,
*Hourglass Stiffness
100., , 0., 0.
*End Part
**
**
** ASSEMBLY
**
*Assembly, name=Assembly
**
*Instance, name=Plate-1, part=Plate
*End Instance
**
*Nset, nset=Left_edge, instance=Plate-1, generate
1, 201, 1
*Elset, elset=Left_edge, instance=Plate-1, generate
1, 200, 1
*Nset, nset=bottom-edge, instance=Plate-1, generate
2211, 40401, 201
*Elset, elset=bottom-edge, instance=Plate-1, generate
2200, 40000, 200
*Elset, elset=_Surf-1_S3, internal, instance=Plate-1, generate
39801, 40000, 1
*Elset, elset=_Surf-1_S4, internal, instance=Plate-1, generate
1, 39801, 200
*Surface, type=ELEMENT, name=Surf-1
_Surf-1_S3, S3
_Surf-1_S4, S4
*End Assembly
**
** ELEMENT CONTROLS
**
*Section Controls, name=EC-1, hourglass=STIFFNESS
1., 1., 1.
**
** MATERIALS
**
*Material, name=Material-1
*Depvar
1,
*User Material, constants=2
1e+06, 0.3
**
*INITIAL CONDITIONS, TYPE=SOLUTION,USER
** BOUNDARY CONDITIONS
**
** Name: BC-1 Type: Displacement/Rotation
*Boundary
Left_edge, 1, 1
** Name: BC-2 Type: Displacement/Rotation
*Boundary
bottom-edge, 2, 2
** ----------------------------------------------------------------
**
** STEP: Step-1
**
*Step, name=Step-1, nlgeom=NO
*Static
1., 1., 1e-05, 1.
**
** LOADS
**
** Name: Load-1 Type: Pressure
*Dsload
Surf-1, P, -100.
**
** OUTPUT REQUESTS
**
*Restart, write, frequency=0
**
** FIELD OUTPUT: F-Output-1
**
*Output, field
*Node Output
CF, COORD, RF, U
*Element Output, directions=YES
E, S, SDV
**
** FIELD OUTPUT: F-Output-2-bottomEdge
**
*Node Output, nset=bottom-edge
COORD, U
*Element Output, elset=bottom-edge, directions=YES
S, SDV
**
** HISTORY OUTPUT: H-Output-1
**
*Output, history, variable=PRESELECT
*End Step
The .msg file is below: (I do not understand the error well!!! at all!!!)
Abaqus JOB Job-User-15
Abaqus 6.14-2
Abaqus License Manager checked out the following licenses:
Abaqus/Standard checked out 5 tokens from Flexnet server lm.rcc.psu.edu.
<255 out of 300 licenses remain available>.
Begin Compiling Abaqus/Standard User Subroutines
Thu 13 Jul 2017 02:38:34 PM EDT
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on
Intel(R) 64, Version 15.0.0.090 Build 20140723
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
Intel(R) Fortran 15.0-1684
End Compiling Abaqus/Standard User Subroutines
Begin Linking Abaqus/Standard User Subroutines
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on
Intel(R) 64, Version 15.0.0.090 Build 20140723
Copyright (C) 1985-2014 Intel Corporation. All rights reserved.
ifort: command line remark #10148: option '-i-dynamic' not supported
GNU ld version 2.20.51.0.2-5.36.el6 20100205
End Linking Abaqus/Standard User Subroutines
Thu 13 Jul 2017 02:38:35 PM EDT
Begin Analysis Input File Processor
Thu 13 Jul 2017 02:38:35 PM EDT
Run pre
Thu 13 Jul 2017 02:38:39 PM EDT
End Analysis Input File Processor
Begin Abaqus/Standard Analysis
Thu 13 Jul 2017 02:38:39 PM EDT
Run standard
/gpfs/apps/x86_64-rhel6/abaqus/6.14-2/6.14-2/code/bin/standard: symbol
lookup error: /tmp/mfg5310_Job-User-15_1727/libstandardU.so: undefined
symbol: state_
Thu 13 Jul 2017 02:38:43 PM EDT
Abaqus Error: Abaqus/Standard Analysis exited with an error - Please see the
message file for possible error messages if the file exists.
Abaqus/Analysis exited with errors
Could any of you please help me with what it could be? Please!
Thank you,
Mousumi
As indicated by the error message, you have a typo at the undefined variable state.
statev(1)=state(1) + kinc
!! Should be:
statev(1)=statev(1) + kinc
It's possible the compiler didn't catch that error during compilation prior to runtime since you are using implicit typing (that is, not explicitly defining the variable types before using them). Perhaps you can verify that yourself.
Related
I'm analyzing an obfuscated OpenGL application. I want to generate a .obj file that describes the multi-polygon model which is displayed in the application.
So I froze the app and dig out the values set in VBO and IBO. But the values set in IBO was far more mysterious than what I've expected. The value was
0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 5, 8, 3, 3, 9, 9, 10, 11, 12, 12, 10, 13, 14, 14, 10, 15, 16, 16, 17, 17, 7, 8, 8, 18, 18, 19, 20, 21, 21, 22, 22, 23, 24, 25, 25, 26, 26, 27, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 36, 37, 38, 38, 36, 39, 34, 34, 40, 40, 40, 41, 42, 43, 44, 44, 45, 45, 46, 47, 48, 49, 49, 50, 50, 51, 52, 52, 53, 53, 54, 55, 55, 56, 56, 57, 58, 58, 59, 59, 60, 61, 62, 62, 63, 63, 63, 64, 65, 66, 67, 64, 68, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 77, 78, 79, 80, 81, 82, 82, 80, 83, 83, 84, 84, 85, 86, 87, 88, 88, 89, 89, 90, 91, 91, 92, 92, 92, 93, 94, 95, 96, 96, 97, 97, 97, 98, 99, 100, 101, 102, 102, 100, 103, 103, 104, 104, 105, 106, 107, 107, 108, 108, 108, 109, 110, 111, 112, 112, 100, 100, 101, 113, 114, 114, ... (length=10495)
As you can see indices like 40, 63, 92 and 108 are tripled, so setting neither GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP nor GL_POLYGON to glDrawElements won't work correctly.
Are there some kind of advanced techniques to use triple sequenced indices in IBO? What does it mean? For what reason is it used for?
Repeated indices like that are indicative of aggressive optimization of triangle strips. A repeated index creates degenerate triangles: triangles with zero area. Since they have no visible area, they are not rendered. They exist so that you can jump from one triangle strip to the next without having to issue another draw command.
So a double-index is often used to stitch two strips together. The two triangles it generates will not be rendered.
However, because of the way strips work with the winding order, the facing for the triangles can work out incorrectly. That is, if you stitched two strips together with a double-index, the second strip would start out with the reverse winding order than it desires.
That's where triple indices come in. The third index fixes the winding order for the triangles in the destination strip. The three extra triangles it generates will not be rendered.
The more modern way to handle multiple strips in the same draw call is to use primitive restart indices. But the index list as it currently stands is adequate for use with GL_TRIANGLE_STRIP.
You can read this strip list and process it into a series of separate triangles (as appropriate for GL_TRIANGLES) easily enough. Simply look at each sequence of 3 vertices, and output that to your triangle buffer, so long as it is not a degenerate triangle. And you'll have to reverse the order of two of the indices for every odd-numbered triangle. The code would look something like this:
const int num_faces = indices.size() - 2;
faces.reserve(num_faces);
for(auto i = 0; i < num_faces; ++i)
{
Face f(indices[i], indices[i + 1], indices[i + 2]);
//Don't add any degenerate faces.
if(!(f[0] == f[1] || f[0] == f[2] || f[1] == f[2]))
{
if(i % 2 == 1) //Every odd-numbered face.
std::swap(f[1], f[2]);
faces.push_back(f);
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have taken this Fortran program from a book which basically runs a goodness to fit test for certain data and gives output. Code and its actual result/output are given as under:
real*4 x(50),xc(50,20),omega(50)
integer ir(50)
real*8 xx
c This code tests goodness of fit.
n=47
c The method of Bak, Nielsen, and Madsen is used.
data (x(i), i=1,47)/ 18, 22, 26, 16, 19, 21, 18, 22,
* 25, 31, 30, 34, 31, 25, 21, 24, 21, 28, 24, 26, 32,
* 33, 36, 39, 32, 33, 42, 44, 43, 48, 50, 56, 57, 59,
* 51, 49, 49, 57, 69, 72, 75, 76, 78, 73, 73, 75, 86/
do 999 icase=1,2
c Parameter icase =1 or 2 denotes SDE model 1 or 2.
xx=102038.
m=8
h=1.0
do 10 j=1,m+1
10 omega(j)=0.0
kk=4
akk=kk
h=h/akk
do 202 i=2,n
xs=x(i-1)
xe=x(i)
do 202 j=1,m
xk=xs
do 252 k=1,kk
call functs(icase,xk,f,g)
call random(xx,rand1,rand2)
252 xk=xk+h*f+sqrt(h)*g*rand1
xc(i,j)=xk
202 continue
do 402 i=2,n
irr=1
do 302 j=1,m
xe=x(i)
xcalc=xc(i,j)
if(xe.gt.xcalc) irr=irr+1
302 continue
402 ir(i)=irr
do 502 i=2,n
irr=ir(i)
omega(irr)=omega(irr)+1.0
502 continue
chi2=0.0
an=n
am=m
hlp=(an-1.0)/(am+1.0)
do 602 j=1,m+1
602 chi2=chi2+(omega(j)-hlp)**2/hlp
write(6,100) icase,chi2
100 format(5x,i7,5x,f9.2)
999 continue
stop
end
subroutine functs(icase,x,f,g)
th1=3510.0
th2=13500.0
f=th1/(x*x)
g=th2/(x*x)
if(icase.eq.1) goto 17
th1=.0361
th2=.6090
f=th1*x
g=sqrt(th2*x)
17 continue
return
end
subroutine random(xx,rand1,rand2)
real*8 xx,a,b,d,rng(2)
a=16807.
ib=2147483647
b=ib
do 55 i=1,2
id=a*xx/b
d=id
xx=a*xx-d*b
55 rng(i)=xx/b
pi=3.141592654
u1=rng(1)
u2=rng(2)
hlp=sqrt(-2.0*alog(u1))
rand1=hlp*cos(pi*2.0*u2)
rand2=hlp*sin(pi*2.0*u2)
return
end
Output of this program is:
1 18.57
2 4.09
However, even after using many online Fortran compilers i am not getting these results. It is giving errors like non standard type declaration etc.
I need help to get the same output as mentioned above.
The code is a written using the (old) Fortran 77 style with the addition of some common extensions. Since it uses the so called fixed-form the columns used by the source code are crucial to have a correct code. In particular for the case:
comments are defined by c character at the first column
continuation lines are defined by * at the sixth column
labels must use the first 5 columns
regular code must use 7-72 column range
Properly indenting your code allows to have it running on both GNU gfortran (tested using v.4.8.2) and Intel ifort (tested using version 15.0.2). To inform the compiler that you want to adopt the fixed-form for most compilers you have just to use .f extension for the source file. Otherwise you have suitable compilers options. For gfortran, compile specifying -ffixed-form. to The (minimally) indented code is provided below.
real*4 x(50),xc(50,20),omega(50)
integer ir(50)
real*8 xx
c This code tests goodness of fit.
n=47
c The method of Bak, Nielsen, and Madsen is used.
data (x(i), i=1,47)/ 18, 22, 26, 16, 19, 21, 18, 22,
* 25, 31, 30, 34, 31, 25, 21, 24, 21, 28, 24, 26, 32,
* 33, 36, 39, 32, 33, 42, 44, 43, 48, 50, 56, 57, 59,
* 51, 49, 49, 57, 69, 72, 75, 76, 78, 73, 73, 75, 86/
do 999 icase=1,2
c Parameter icase =1 or 2 denotes SDE model 1 or 2.
xx=102038.
m=8
h=1.0
do 10 j=1,m+1
10 omega(j)=0.0
kk=4
akk=kk
h=h/akk
do 202 i=2,n
xs=x(i-1)
xe=x(i)
do 202 j=1,m
xk=xs
do 252 k=1,kk
call functs(icase,xk,f,g)
call random(xx,rand1,rand2)
252 xk=xk+h*f+sqrt(h)*g*rand1
xc(i,j)=xk
202 continue
do 402 i=2,n
irr=1
do 302 j=1,m
xe=x(i)
xcalc=xc(i,j)
if(xe.gt.xcalc) irr=irr+1
302 continue
402 ir(i)=irr
do 502 i=2,n
irr=ir(i)
omega(irr)=omega(irr)+1.0
502 continue
chi2=0.0
an=n
am=m
hlp=(an-1.0)/(am+1.0)
do 602 j=1,m+1
602 chi2=chi2+(omega(j)-hlp)**2/hlp
write(6,100) icase,chi2
100 format(5x,i7,5x,f9.2)
999 continue
stop
end
subroutine functs(icase,x,f,g)
th1=3510.0
th2=13500.0
f=th1/(x*x)
g=th2/(x*x)
if(icase.eq.1) goto 17
th1=.0361
th2=.6090
f=th1*x
g=sqrt(th2*x)
17 continue
return
end
subroutine random(xx,rand1,rand2)
real*8 xx,a,b,d,rng(2)
a=16807.
ib=2147483647
b=ib
do 55 i=1,2
id=a*xx/b
d=id
xx=a*xx-d*b
55 rng(i)=xx/b
pi=3.141592654
u1=rng(1)
u2=rng(2)
hlp=sqrt(-2.0*alog(u1))
rand1=hlp*cos(pi*2.0*u2)
rand2=hlp*sin(pi*2.0*u2)
return
end
If you want to compile using an online resource be sure you properly copy-paste the code (with the right indentation) and use the option for the fixed form. For example using https://www.tutorialspoint.com/compile_fortran_online.php in the shell below compile typing: gfortran -ffixed-form *.f95 -o main.
Since Fortran 77 style is quite old now, if you are starting a new code I personally suggest to move to free-form source code and to use more recent Fortran features. A possible rewrite of the code using a modern style is given below:
module my_kinds
integer, parameter :: sp = selected_real_kind(9)
integer, parameter :: dp = selected_real_kind(18)
end module my_kinds
program test_from_book
use my_kinds
real(sp) :: x(50),xc(50,20),omega(50)
integer :: ir(50)
real(dp) :: xx
! This code tests goodness of fit.
n=47
! The method of Bak, Nielsen, and Madsen is used.
x = [ 18, 22, 26, 16, 19, 21, 18, 22, &
25, 31, 30, 34, 31, 25, 21, 24, 21, 28, 24, 26, 32, &
33, 36, 39, 32, 33, 42, 44, 43, 48, 50, 56, 57, 59, &
51, 49, 49, 57, 69, 72, 75, 76, 78, 73, 73, 75, 86, &
0 , 0, 0]
loop_999: do icase=1,2
! Parameter icase =1 or 2 denotes SDE model 1 or 2.
xx=102038.
m=8
h=1.0
do j=1,m+1
omega(j)=0.0
enddo
kk=4
akk=kk
h=h/akk
loop_202: do i=2,n
xs=x(i-1)
xe=x(i)
do j=1,m
xk=xs
do k=1,kk
call functs(icase,xk,f,g)
call random(xx,rand1,rand2)
xk=xk+h*f+sqrt(h)*g*rand1
enddo
xc(i,j)=xk
enddo
enddo loop_202
loop_402: do i=2,n
irr=1
do j=1,m
xe=x(i)
xcalc=xc(i,j)
if(xe.gt.xcalc) irr=irr+1
enddo
ir(i)=irr
enddo loop_402
do i=2,n
irr=ir(i)
omega(irr)=omega(irr)+1.0
enddo
chi2=0.0
an=n
am=m
hlp=(an-1.0)/(am+1.0)
do j=1,m+1
chi2=chi2+(omega(j)-hlp)**2/hlp
enddo
write(6,100) icase,chi2
100 format(5x,i7,5x,f9.2)
enddo loop_999
stop
end
subroutine functs(icase,x,f,g)
th1=3510.0
th2=13500.0
f=th1/(x*x)
g=th2/(x*x)
if(icase.ne.1) then
th1=.0361
th2=.6090
f=th1*x
g=sqrt(th2*x)
endif
end
subroutine random(xx,rand1,rand2)
use my_kinds
real(dp) :: xx,a,b,d,rng(2)
a=16807.
ib=2147483647
b=ib
do i=1,2
id=a*xx/b
d=id
xx=a*xx-d*b
rng(i)=xx/b
enddo
pi=3.141592654
u1=rng(1)
u2=rng(2)
hlp=sqrt(-2.0*alog(u1))
rand1=hlp*cos(pi*2.0*u2)
rand2=hlp*sin(pi*2.0*u2)
end
I am new using Eigen library and I am having problems transform/reshape a vector in a matrix.
I am trying to get an specific row of a matrix and convert it as a matrix, but each time that I do that the result is not what I am expecting.
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> m(8, 9);
m << 11, 12, 13, 14, 15, 16, 17, 18, 19,
21, 22, 23, 24, 25, 26, 27, 28, 29,
31, 32, 33, 34, 35, 36, 37, 38, 39,
41, 42, 43, 44, 45, 46, 47, 48, 49,
51, 52, 53, 54, 55, 56, 57, 58, 59,
61, 62, 63, 64, 65, 66, 67, 68, 69,
71, 72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88, 89;
std::cout << m << std::endl << std::endl;
Matrix<double,1,Dynamic,RowMajor> B = m.row(0);
std::cout << B << std::endl << std::endl;
Map<Matrix3d,RowMajor> A(B.data(),3,3);
std::cout << A << std::endl << std::endl;
Result
11 14 17
12 15 18
13 16 19
I want:
11 12 13
14 15 16
17 18 19
You dont need to select a row first and then map. Just map directly from m and assign the transpose of map to a matrix A as follows
Matrix3d A = Map<Matrix3d>(m.data()).transpose();
If you don't like transposing then forcing the map to use RowMajor for the destination type works too
Matrix3d A = Map<Matrix<double, 3, 3, RowMajor>>(m.data());
Although, at this small size it doesn't matter. Cheers
You need to get the transpose of the result matrix. I think eigen library is converting a vector to a matrix by picking every n'th element to form a row in a n*n sized vector.
I am trying to assign values to the Arrival, BurstTime, and IOTime arrays. It worked fine when I didn't have Arrival[9]. However trying to pass multiple ints into the variable doesn't work. I get -86638*** numbers. I have been trying to find an answer for days, No luck.
This is my struct.
struct ReadyQueue
{
//static const int MAX_NUMBER = 10;
int ArrivalTime[10];
int BurstTime[10];
int IOTime[10];
std::string Name;
};
and my variables
P[0].ArrivalTime[10] = 0, 98, 221, 327, 423, 530, 628, 719, 788 ;
P[1].ArrivalTime[8] = 17, 116, 208, 320, 437, 554, 665, 754 ; // P2
P[2].ArrivalTime[7] = 27, 125, 238, 364, 468, 579, 680; // P3
P[3].ArrivalTime[8] = 45, 155, 276, 392, 515, 642, 739, 820 ; // P4
P[4].ArrivalTime[10] = 62, 186, 343, 489, 603, 715, 807, 887, 952, 997; // P5
P[5].ArrivalTime[7] = 67, 174, 262, 348, 446, 566, 654; // P6
P[6].ArrivalTime[9] = 77, 148, 216, 302, 359, 461, 546, 622, 697; // P7
P[7].ArrivalTime[8] = 83, 196, 306, 409, 499, 608, 702, 773 ; // P8
P[8].ArrivalTime[9] = 92, 192, 296, 386, 492, 599, 692, 734, 803; // P9
P[0].BurstTime[8] = 17 , 18, 17, 16, 14, 16, 14, 15, 15;
P[0].IOTime[8] = 24, 73, 31, 27, 33, 43, 64, 19 ;
P[1].BurstTime[8] = 10, 9, 8, 7, 9, 12, 15, 19 ;
P[1].IOTime[7] = 31, 35, 42, 43, 47, 43, 51 ;
P[2].IOTime[6] = 51, 53, 61, 31, 43, 31 ;
P[2].BurstTime[7] = 18, 23, 24, 22, 21, 20, 12 ;
P[3].BurstTime[8] = 17, 19, 20, 17, 15, 12, 15, 14 ;
P[3].IOTime[7] = 42, 55, 54, 52, 67, 72, 66 ;
P[4].BurstTime[10] = 5, 6, 5, 3, 5, 4, 3, 4, 3, 5 ;
P[4].IOTime[9] = 61, 82, 71, 61, 62, 51, 77, 61, 42 ;
P[5].BurstTime[7] = 10, 12, 14, 11, 15, 13, 11 ;
P[5].IOTime[6] = 35, 41, 33, 32, 41, 29 ;
P[6].BurstTime[7] = 6, 7, 5, 4, 5, 7, 8, 6, 5 ;
P[6].IOTime[8] = 18, 21, 19, 16, 29, 21, 22, 24 ;
P[7].BurstTime[8] = 9, 12, 14, 14, 16, 14, 13, 15 ;
P[7].IOTime[7] = 52, 42, 31, 21, 43, 31, 32 ;
P[8].BurstTime[9] = 6, 4, 6, 6, 7, 4, 5, 5, 4 ;
P[8].BurstTime[8] = 35, 41, 33, 32, 41, 29, 16, 22 ;
Thank you very much
I want to clarify what those assignments do, because I see some wrong answers.
Let's see it with an example:
P[0].ArrivalTime[10] = 0, 98, 221, 327, 423, 530, 628, 719, 788 ;
First, that statement is assigning 0 in the eleventh element of the ArrivalTime array and I don't think you wanted to do this due to ArrivalTime[9] is the last element.
Second, the comma operator evaluates the first operand, discard the result, and then evaluates the second operand and returns his value. In the example you could think this evaluation returns 788, but assign operator have more precedence than comma, so, the statement will evaluate like this:
((P[0].ArrivalTime[10] = 0), 98, 221, 327, 423, 530, 628, 719, 788 ;
Change this:
struct ReadyQueue
{
//static const int MAX_NUMBER = 10;
int ArrivalTime[10];
int BurstTime[10];
int IOTime[10];
std::string Name;
};
to this:
struct Item
{
int ArrivalTime;
int BurstTime;
int IOTime;
};
struct Ready_queue
{
string name;
queue<Item> items;
};
where queue is std::queue.
If that doesn't suit your higher level purpose, then something similar that does suit that (unexplained) purpose.
The main point is an inversion of the logical structure, putting related data together.
Do note that e.g. x = 6, 4, 6, 6, 7, 4, 5, 5, 4 ; is parsed as (x = 6), 4, 6, 6, 7, 4, 5, 5, 4 ; and thus is equivalent to just = 6;. The longwinded expression after the assignment is using the comma operator, which evaluates the expressions in ordinary reading order, producing the value of the last one. Due to the parsing also that final value is discarded.
Please note that my answer contained a mistake which I corrected it: equal operator has a higher priority than the comma operator (it might still contain traces of it)
This is not how you assign an array to a variable.
what you are doing is simply:
assign 788 0 to p[0].ArrivalTime[10] //the 11th element of p[0] which is outside the reserved space for the array
because the comma operator what it does is that it evaluates every one from left to right and return the last value: example:
int i=0,j;
j=i++,(i+=5),i; //j=0 and i=6 //because it is in fact (j=i++),(i+=5),i;
j=(i++,(i+=5),i); //j=6 and i=6
what you are trying to do is assign p[0].arrivalTime to an array of 10. You should do it this way:
P[0].ArrivalTime[0] = 0 ;
P[0].ArrivalTime[1] = 98 ;
...
P[0].ArrivalTime[9] = 788 ;
I don't know any method that assign an array to an array variable after declaration
You cannot do assignments to arrays like this in c/c++. You can use a similar syntax with {} for initializing arrays, but it won't work for what you want to do here. You could use memcpy to copy the arrays into the memory locations in the struct.
memcpy( p[0].ArrivalTime,
(const int[9]) {0, 98, 221, 327, 423, 530, 628, 719, 788},
sizeof(int [9])
);
Note that the comma is an operator which evaluates a list of expressions and returns the value of the last expression. This means that
P[0].ArrivalTime[10] = 0, 98, 221, 327, 423, 530, 628, 719, 788 ;
assigns 0 to the value at index 10 of the array named ArrivalTime and ignores the rest of the list.
I have a question which can be divided into two subquestions.
I have created a table the code of which is given below.
Problem 1.
xstep = 1;
xmaximum = 6;
numberofxnodes = 6;
numberofynodes = 3;
numberofzlayers = 3;
maximumgridnodes = numberofxnodes*numberofynodes
mnodes = numberofxnodes*numberofynodes*numberofzlayers;
orginaltable =
Table[{i,
node2 = i + xstep, node3 = node2 + xmaximum,
node4 = node3 - xstep,node5 = i + maximumgridnodes,
node6 = node5 + xstep,node7 = node6 + xmaximum,
node8 = node7 - xstep},
{i, 1, mnodes}]
If I run this I will get my original table. Basically I want to remove the sixth element and multiples of the sixth element from my original table. I am able to do this by using this code below.
modifiedtable = Drop[orginaltable, {6, mnodes, 6}]
Now I get the modified table where every sixth element and multiples of sixth element of my original table is removed. This solves my Problem 1.
Now my Problem 2:
** MAJOR EDITED VERSION**:(ALL THE CODES GIVEN ABOVE IS CORRECT)
Thanks a lot for the answers, but I wanted something else and I made a mistake
while explaining it initially so I'm making another try.
Below is my modified table: I want the elements in between
"/** and **/" deleted and remaining there.
{{1, 2, 8, 7, 19, 20, 26, 25}, {2, 3, 9, 8, 20, 21, 27, 26}, {3, 4,10, 9, 21, 22, 28, 27}, {4, 5, 11, 10, 22, 23, 29, 28}, {5, 6, 12, 11, 23, 24, 30, 29}, {7, 8, 14, 13, 25, 26, 32, 31}, {8, 9, 15, 14, 26, 27, 33, 32}, {9, 10, 16, 15, 27, 28, 34, 33}, {10, 11, 17, 16, 28, 29, 35, 34}, {11, 12, 18, 17, 29, 30, 36, 35}, /**{13, 14, 20, 19, 31, 32, 38, 37}, {14, 15, 21, 20, 32, 33, 39, 38}, {15, 16, 22, 21, 33, 34, 40, 39}, {16, 17, 23, 22, 34, 35, 41, 40}, {17, 18, 24, 23, 35, 36, 42, 41},**/ {19, 20, 26, 25, 37, 38, 44, 43}, {20, 21, 27, 26, 38, 39, 45, 44}, {21, 22, 28, 27, 39, 40, 46, 45}, {22, 23, 29, 28, 40, 41, 47, 46}, {23, 24, 30, 29, 41, 42, 48, 47}, {25, 26, 32, 31,43, 44, 50, 49}, {26, 27, 33, 32, 44, 45, 51, 50}, {27, 28, 34, 33, 45, 46, 52, 51}, {28, 29, 35, 34, 46, 47, 53, 52}, {29, 30, 36, 35, 47, 48, 54, 53}, /**{31, 32, 38, 37, 49, 50, 56, 55}, {32, 33, 39, 38,50, 51, 57, 56}, {33, 34, 40, 39, 51, 52, 58, 57}, {34, 35, 41, 40, 52, 53, 59, 58}, {35, 36, 42, 41, 53, 54, 60, 59},**/ {37, 38, 44, 43,55, 56, 62, 61}, {38, 39, 45, 44, 56, 57, 63, 62}, {39, 40, 46, 45, 57, 58, 64, 63}, {40, 41, 47, 46, 58, 59, 65, 64}, {41, 42, 48, 47,59, 60, 66, 65}, {43, 44, 50, 49, 61, 62, 68, 67}, {44, 45, 51, 50, 62, 63, 69, 68}, {45, 46, 52, 51, 63, 64, 70, 69}, {46, 47, 53, 52, 64, 65, 71, 70}, {47, 48, 54, 53, 65, 66, 72, 71}, /**{49, 50, 56, 55, 67, 68, 74, 73}, {50, 51, 57, 56, 68, 69, 75, 74},{51,52, 58, 57, 69, 70, 76, 75}, {52, 53, 59, 58, 70, 71, 77, 76}, {53, 54, 60, 59, 71, 72, 78, 77}}**/
Now, if you observe, I wanted the first ten elements
(1st to 10th element of modifiedtable) to be there in my final table
( DoubleModifiedTable ). the the next five (11th to 15th elements of modifiedtable) deleted.
Then the next ten elements ( 16th to 25th elements of modifiedtable)
to be present in my final table ( DoubleModifiedTable )
then the next five deleted (26th to 30th elements of modifiedtable) and so on for the whole table.
Let say we solve this problem and we name the final table DoubleModifiedTable.
I am basically interested in getting the DoubleModifiedTable. I decided to subdivide the problem as it easy to explain.
I want this to happen automatically through the table since as this is just an example table but in reality I have huge table. If I can understand how I can solve this problem for this table, then I can solve it for my large table too.
Perhaps simpler:
DoubleModifiedTable =
Module[{copy = modifiedtable},
copy[[Flatten[# + Range[5] & /# Range[10, Length[copy], 10]]]] = Sequence[];
copy]
EDIT
Even simpler:
DoubleModifiedTable =
Delete[modifiedtable,
Transpose[{Flatten[# + Range[5] & /# Range[10, Length[modifiedtable], 10]]}]]
EDIT 2
Per OP's request: one only has to change a single number (10 to 15) in any of my solutions to get the answer to a modified problem:
DoubleModifiedTable =
Delete[modifiedtable,
Transpose[{Flatten[# + Range[5] & /# Range[10, Length[modifiedtable], 15]]}]]
Another way is to do something like
DoubleModifiedTable = With[{n = 10, m = 5},
Flatten[{{modifiedtable[[;; m]]},
Partition[modifiedtable, n - m, n, {n - m + 1, 1}, {}]}, 2]]
Edit
The edited version of Problem 2 is actually slightly simpler to solve than the original version. You could for example do something like
DoubleModifiedTable =
With[{n = 10, m = 5}, Flatten[Partition[modifiedtable, n, n + m, 1, {}], 1]]
Edit 2
What my second version does is to split the original list modifiedtable into sublists using Partition and then to flatten these sublists to form the final list. If you look at the Documentation for Partition you can see that I'm using the 6th form of Partition which means that the length of the sublists is n and the offset (the distance be is n+m. The gap between the sublists is therefore n+m-n==m.
The next argument, 1, is actually equivalent to {1,1} which tells Mathematica that the first element of modifiedtable should appear at position 1 in the first sublist and the last element of modifiedtable should appear on or after position 1 of the last sublist.
The last argument, {} is to indicate that no padding should be used for sublists with length <=n.
In summary, if you want to delete the first 10 elements and keep the next 5 you want sublists of length n=5 with gap m=10. Since you want the first sublist to start with the (m+1)-th element of modifiedtable, you could replace the fourth argument in Partition with something of the form {k,1} for some value of k but it's probably easier to just drop the first m elements of modifiedtable beforehand, i.e.
DoubleModifiedTable =
With[{n = 5, m = 10},
Flatten[Partition[Drop[modifiedtable, m], n, n + m, 1, {}], 1]]
DoubleModifiedTable=
modifiedtable[[
Complement[
Range[Length[modifiedtable]],
Flatten#Table[10 i + j, {i, Floor[Length[modifiedtable]/10]}, {j, 5}]
]
]]
or, slightly shorter
DoubleModifiedTable=
#[[
Complement[
Range[Length[#]],
Flatten#Table[10 i + j, {i, Floor[Length[#]/10]}, {j, 5}]
]
]] & # modifiedtable