Changeset 26715
- Timestamp:
- 12/08/21 04:48:57 (3 years ago)
- Location:
- issm/trunk-jpl/src/jl/md
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/jl/md/classes.jl
r26703 r26715 135 135 return model( Mesh2dTriangle(), Geometry(), Mask(), Materials(), Initialization(),Stressbalance(), Constants(), [], BuddFriction()) 136 136 end#}}} 137 function model(matmd::Dict) #{{{ 138 139 #initialize output 140 md = model() 141 142 #Loop over all possible fields 143 for name1 in fieldnames(model) 144 if haskey(matmd, String(name1)) 145 mdfield = getfield(md,name1) 146 matfield = matmd[String(name1)] 147 for name2 in fieldnames(typeof(mdfield)) 148 if haskey(matfield, String(name2)) 149 println("recovering md.",name1,".",name2) 150 value_matlab = matfield[String(name2)] 151 value_julia = getfield(mdfield, name2) 152 153 if typeof(value_matlab)==typeof(value_julia) 154 #setfield!(mdfield, name2, convert(typeof(getfield(mdfield, name2)), matfield[String(name2)])) 155 setfield!(mdfield, name2, value_matlab) 156 157 elseif typeof(value_matlab)==Float64 && typeof(value_julia)==Int64 158 setfield!(mdfield, name2, Int64(value_matlab)) 159 160 elseif typeof(value_matlab)==Matrix{Float64} && typeof(value_julia)==Vector{Float64} 161 if(size(value_matlab,2)!=1) error("only one column expected") end 162 setfield!(mdfield, name2, value_matlab[:,1]) 163 164 elseif typeof(value_matlab)==Matrix{Float64} && typeof(value_julia)==Matrix{Int64} 165 matrix = Matrix{Int64}(undef,size(value_matlab)) 166 for i in 1:length(value_matlab) matrix[i] = Int64(value_matlab[i]) end 167 setfield!(mdfield, name2, matrix) 168 169 elseif typeof(value_matlab)==Matrix{Float64} && typeof(value_julia)==Vector{Bool} 170 if(size(value_matlab,2)!=1) error("only one column expected") end 171 vector = Vector{Bool}(undef,size(value_matlab,1)) 172 for i in 1:length(vector) vector[i] = Bool(value_matlab[i]) end 173 setfield!(mdfield, name2, vector) 174 175 else 176 error("Don't know how to convert ",typeof(value_matlab)," to ",typeof(value_julia)) 177 end 178 end 179 end 180 #setfield!(md, name1, mdfield) 181 end 182 end 183 184 return md 185 end#}}} 137 186 function Base.show(io::IO, md::model)# {{{ 138 187 -
issm/trunk-jpl/src/jl/md/utils.jl
r26712 r26715 153 153 return dataout 154 154 end #}}} 155 function InterpFromMeshToMesh2d2(index_data::Array,x_data::Vector,y_data::Vector,data::Vector,xout::Vector,yout::Vector) #{{{ 156 157 #prepare input arrays 158 nods = Cint(length(x_data)) 159 nels = Cint(size(index_data,1)) 160 nods_interp = Cint(length(xout)) 161 Cindex=Array{Cint,1}(undef,length(index_data)) 162 for i in 1:size(index_data,1) 163 for j in 1:3 164 Cindex[(i-1)*3+j] = Int32(index_data[i,j]) 165 end 166 end 167 Cx = Array{Cdouble,1}(undef,nods) 168 Cy = Array{Cdouble,1}(undef,nods) 169 Cdata = Array{Cdouble,1}(undef,nods) 170 for i in 1:nods 171 Cx[i] = x_data[i] 172 Cy[i] = y_data[i] 173 Cdata[i] = data[i] 174 end 175 Cxout = Array{Cdouble,1}(undef,nods_interp) 176 Cyout = Array{Cdouble,1}(undef,nods_interp) 177 Cdataout = Array{Cdouble,1}(undef,nods_interp) 178 for i in 1:nods_interp 179 Cxout[i] = xout[i] 180 Cyout[i] = yout[i] 181 end 182 183 #This is not working.... 184 #rc=ccall( (:InterpFromMeshToMesh2dx,"../bamg/libBamg.so"), 185 # Cint, (Ptr{Cdouble},Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint), 186 # Ref(Cdataout), Ref(Cindex), Ref(Cx), Ref(Cy), nods, nels, 187 # Ref(Cdata), nods, 1, Ref(Cxout), Ref(Cyout), nods_interp) 188 #rc=ccall( (:InterpFromMeshToMesh2dx,"../bamg/libBamg.so"), 189 # Cint, (Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint), 190 # Ref(Cindex), Ref(Cx), Ref(Cy), nods, nels) 191 # 192 # 193 dataout = Vector{Float64}(undef,nods_interp) 194 rc=ccall( (:InterpFromMeshToMesh2dx3,"/Users/mmorligh/Desktop/issmuci/trunk-jpl/src/jl/bamg/libBamg.dylib"), 195 Cint, (Ptr{Cdouble}, Cint), 196 dataout, nods_interp) 197 198 #Process output 199 for i in 1:nods_interp 200 dataout[i] = Cdataout[i] 201 end 202 203 return dataout 204 end #}}} 155 205 function solve(md::model,solution::String) #{{{ 156 206
Note:
See TracChangeset
for help on using the changeset viewer.