derived-types

Fortran function to overload multiplication between derived types with allocatable components

╄→尐↘猪︶ㄣ 提交于 2020-01-05 03:46:07
问题 Foreword In order to store banded matrices whose full counterparts can have both rows and columns indexed from indices other than 1 , I defined a derived data type as TYPE CDS REAL, DIMENSION(:,:), ALLOCATABLE :: matrix INTEGER, DIMENSION(2) :: lb, ub INTEGER :: ld, ud END TYPE CDS where CDS stands for compressed diagonal storage. Given the declaration TYPE(CDS) :: A , The rank-2 component matrix is supposed to contain, as columns, the diagonals of the actual full matrix (like here, except

Array of derived type: select entry

蓝咒 提交于 2020-01-02 08:50:01
问题 Currently in my code I have a 2D array integer, allocatable :: elements(:,:) and define some constants integer, parameter :: TYP = 1 integer, parameter :: WIDTH = 2 integer, parameter :: HEIGHT = 3 ! ... integer, parameter :: NUM_ENTRIES = 10 and allocate something like allocate(elements(NUM_ENTRIES,10000)) so I can access elements like write(*,*) elements(WIDTH,100) ! gives the width of the 100th element Now I would like to have not only integer but a mixture of types for every element. So I

Array of derived type: select entry

守給你的承諾、 提交于 2020-01-02 08:49:52
问题 Currently in my code I have a 2D array integer, allocatable :: elements(:,:) and define some constants integer, parameter :: TYP = 1 integer, parameter :: WIDTH = 2 integer, parameter :: HEIGHT = 3 ! ... integer, parameter :: NUM_ENTRIES = 10 and allocate something like allocate(elements(NUM_ENTRIES,10000)) so I can access elements like write(*,*) elements(WIDTH,100) ! gives the width of the 100th element Now I would like to have not only integer but a mixture of types for every element. So I

Error in Derived type declaration: Variable at (1) in this context must be constant

孤人 提交于 2019-12-31 02:58:12
问题 I have a derived type declared in a module like this: MODULE dmotifs TYPE :: PRM INTEGER, PRIVATE :: nsp=4,nrx=8,maxprx=4 REAL, PRIVATE :: cref=1e-6,tref=1 REAL, DIMENSION(nrx,maxprx) :: k REAL :: input END TYPE PRM CONTAINS SUBROUTINE unreg(y,param,r,s) TYPE(PRM), INTENT(IN) :: param REAL, DIMENSION(param%nsp), INTENT(IN) :: y INTEGER, DIMENSION(param%nsp,param%nrx), INTENT(OUT) :: s=0 REAL, DIMENSION(param%nrx,1), INTENT(OUT) :: r=0 REAL :: mOut, mCtrl, pOut, pCtrl mOut=y(ind_mOut) mCtrl=y

Fortran90 derived types with mpi, alignment issue?

人盡茶涼 提交于 2019-12-24 12:07:47
问题 I got problem with the following basic code: program foo use mpi implicit none type bartype real(8) :: x integer :: i end type bartype integer :: mpi_bar_type integer :: & count=2, & blocklengths(2)=(/1,1/), & types(2)=(/mpi_double_precision, & mpi_integer/) integer(kind=mpi_address_kind) :: displs(2) type(bartype) :: bar, bararray(4) integer :: rank, ierr, i, test(4), addr0 call mpi_init(ierr) call mpi_comm_rank(mpi_comm_world, rank, ierr) call mpi_get_address(bar, addr0) call mpi_get

Fortran derived types

会有一股神秘感。 提交于 2019-12-23 22:19:49
问题 I was wondering if it is somehow possible to define a derived type in Fortran which automatically returns the right type, without calling the type specifically e.g. var%real ? Here's an example to explain what I mean: module DervType implicit none type, public :: mytype real(8) :: r integer :: i logical :: l end type end module DervType program TestType use DervType implicit none type(mytype) :: test test = 1. !! <-- I don't want to use test%r here end program TestType Would this be possible

Constructor of derived types

会有一股神秘感。 提交于 2019-12-23 10:19:25
问题 I am trying to write a constructor for a derived type of an abstract one to solve this other question, but it seems that it's not working, or better, it isn't called at all. The aim is to have a runtime polymorphism setting the correct number of legs of an animal. These are the two modules: animal module animal_module implicit none type, abstract :: animal private integer, public :: nlegs = -1 contains procedure :: legs end type animal contains function legs(this) result(n) class(animal),

Fortran derived types containing derived types to be accessible from C

故事扮演 提交于 2019-12-23 01:19:19
问题 As an extension to this post, I have derived types which have as members derived types themselves. Example below: module simple use iso_c_binding TYPE SIMPLEF INTEGER :: A INTEGER, POINTER :: B, C(:) END TYPE SIMPLEF TYPE COMPLEXF INTEGER :: X TYPE (SIMPLEF) :: Y END TYPE COMPLEXF end module simple The aim is, as in the post above, to have similar derived types in C and to be able to pass values back and forth to Fortran. The solution can be seen here. However here it's not just a derived

What is the difference between darray and subarray in mpi?

蹲街弑〆低调 提交于 2019-12-22 10:55:04
问题 I have a parallel I/O project for parallel programming class, and I have to implement derived datatypes. I didn't clearly understand the difference between darray and subarray. Can darray be derived from dynamically allocated arrays or not? And what is the main difference? 回答1: Subarray lets you describe a single block/slice of a larger multidimensional array. If every MPI task has a single slice/block of a large global array, (or if you are communicating chunks of local arrays between tasks)

How to override method with derived return type in C#?

和自甴很熟 提交于 2019-12-20 06:28:12
问题 I want to override a virtual method with a derived class type. What's the current best way to do this? So far I've found two approaches: Use an abstract base class for each derived type; bridge with protected methods. Use a protected implementation with a public accessor. Base case (no solution implemented, Clone always returns base type A1 ): public class A1 { public int X1 { get; set; } public A1(int x1) { this.X1 = x1; } public virtual A1 Clone() { return new A1(X1); } } public class A2 :