Skip to content

Commit

Permalink
Merge pull request #10 from smaslan/master
Browse files Browse the repository at this point in the history
Modification for windows compiling and few minor fixes
  • Loading branch information
reos-rcrozier committed Jun 14, 2023
2 parents abaa0c0 + cfbcfe7 commit 10d11cf
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cfemm/fsolver/fsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ bool FSolver::runSolver(bool verbose)
{
WarnMessage("Harmonic planar incremental permeability problems are work in progress. RESULTS WON'T BE VALID!\n");
}
if (!Harmonic2D(L))
if (!Harmonic2D(L,verbose))
{
WarnMessage("Couldn't solve the problem\n");
return false;
Expand All @@ -1319,7 +1319,7 @@ bool FSolver::runSolver(bool verbose)
WarnMessage("Cannot handle harmonic axisymmetric incremental problems.\n");
return false;
}
if (!HarmonicAxisymmetric(L))
if (!HarmonicAxisymmetric(L,verbose))
{
WarnMessage("Couldn't solve the problem\n");
return false;
Expand Down
4 changes: 2 additions & 2 deletions cfemm/fsolver/fsolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class FSolver : public FEASolver<
* \endinternal
*/
int WriteStatic2D(CBigLinProb &L);
int Harmonic2D(CBigComplexLinProb &L);
int Harmonic2D(CBigComplexLinProb &L,bool verbose=false);
int WriteHarmonic2D(CBigComplexLinProb &L);
int StaticAxisymmetric(CBigLinProb &L);
int HarmonicAxisymmetric(CBigComplexLinProb &L);
int HarmonicAxisymmetric(CBigComplexLinProb &L,bool verbose=false);
void GetFillFactor(int lbl);
double ElmArea(int i);

Expand Down
7 changes: 4 additions & 3 deletions cfemm/fsolver/harmonic2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

double Power(double x, int y);

int FSolver::Harmonic2D(CBigComplexLinProb &L)
int FSolver::Harmonic2D(CBigComplexLinProb &L,bool verbose)
{
int i,j,k,ww,s;
CComplex Mx[3][3],My[3][3],Mxy[3][3];
Expand Down Expand Up @@ -219,7 +219,8 @@ int FSolver::Harmonic2D(CBigComplexLinProb &L)

// TheView->SetDlgItemText(IDC_FRAME1,"Matrix Construction");
// TheView->m_prog1.SetPos(0);
printf("Matrix Construction\n");
if(verbose)
printf("Matrix Construction\n");

if(Iter>0) L.Wipe();

Expand Down Expand Up @@ -822,7 +823,7 @@ int FSolver::Harmonic2D(CBigComplexLinProb &L)
L.Precision=std::min(1.e-4,0.001*res);
if (L.Precision<Precision) L.Precision=Precision;
}
if (L.PBCGSolveMod(Iter)==false) return false;
if (L.PBCGSolveMod(Iter,verbose)==false) return false;


if (LinearFlag==false)
Expand Down
10 changes: 6 additions & 4 deletions cfemm/fsolver/harmonicaxi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// #define NEWTON

int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L)
int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L,bool verbose)
{
int i,j,k,s,flag,ww,Iter=0;
int pctr;
Expand Down Expand Up @@ -208,7 +208,8 @@ int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L)

// TheView->SetDlgItemText(IDC_FRAME1,"Matrix Construction");
// TheView->m_prog1.SetPos(0);
printf("Matrix Construction\n");
if(verbose)
printf("Matrix Construction\n");
pctr=0;

if (Iter>0) L.Wipe();
Expand Down Expand Up @@ -747,7 +748,7 @@ int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L)
if (L.Precision<Precision) L.Precision=Precision;
}

if (L.PBCGSolveMod(Iter)==0) return 0;
if (L.PBCGSolveMod(Iter,verbose)==0) return 0;

if (LinearFlag==false)
{
Expand Down Expand Up @@ -782,7 +783,8 @@ int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L)
else sprintf(outstr,"Successive Approx(%i) Relax=%.4g\n",Iter,Relax);
//#endif
// TheView->SetDlgItemText(IDC_FRAME2,outstr);
printf("%s\n", outstr);
if(verbose)
printf("%s\n", outstr);
j=(int) (100.*log10(res)/(log10(Precision)+2.));
if (j>100) j=100;
// TheView->m_prog2.SetPos(j);
Expand Down
5 changes: 3 additions & 2 deletions cfemm/libfemm/cspars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ int CBigComplexLinProb::KludgeSolve(int flag)
// Calls PCGSQStart to do a small number of iterations,
// moving the starting point for PBCG away from the
// pathological starting points that can sometimes crop up.
int CBigComplexLinProb::PBCGSolveMod(int flag)
int CBigComplexLinProb::PBCGSolveMod(int flag,bool verbose)
{
// if this is a N-R iteration, call the appropriate solver
if (bNewton)
Expand All @@ -1070,7 +1070,8 @@ int CBigComplexLinProb::PBCGSolveMod(int flag)
if(flag==false)
{
// TheView->SetDlgItemText(IDC_FRAME1,"Initializing Solver");
printf("Initializing Solver");
if(verbose)
printf("Initializing Solver");
if (PCGSQStart()==0) return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion cfemm/libfemm/cspars.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CBigComplexLinProb

// flag==false initializes solution to zero
// flag==true starts from solution of previous call
int PBCGSolveMod(int flag); // Precondition Biconjugate Gradient
int PBCGSolveMod(int flag,bool verbose=false); // Precondition Biconjugate Gradient
int PCGSQStart();
int PBCGSolve(int flag);
int BiCGSTAB(int flag);
Expand Down
4 changes: 3 additions & 1 deletion mfemm/+mfemmdeps/ipdm.m
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,9 @@
p_i = lower(pv_pairs{2*i-1});
v_i = pv_pairs{2*i};

ind = strmatch(p_i,lpropnames,'exact');
% ###fix: deprecated strmatch() replaced
%ind = strmatch(p_i,lpropnames,'exact');
ind = find(strcmp(p_i,lpropnames),1);
if isempty(ind)
ind = find(strncmp(p_i,lpropnames,length(p_i)));
if isempty(ind)
Expand Down
4 changes: 3 additions & 1 deletion mfemm/+mfemmdeps/parse_pv_pairs.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
p_i = lower(pv_pairs{2*i-1});
v_i = pv_pairs{2*i};

ind = strmatch(p_i,lpropnames,'exact');
% ###fix: deprecated strmatch() replaced
%ind = strmatch(p_i,lpropnames,'exact');
ind = find(strcmp(p_i,lpropnames),1);
if isempty(ind)
ind = find(strncmp(p_i,lpropnames,length(p_i)));
if isempty(ind)
Expand Down
24 changes: 22 additions & 2 deletions mfemm/+mmake/make.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ function make(target,mmakefilename,varargin)
else
wd = '';
end

% try
% Read the makefile
[state.implicitRules, state.vars] = implicit_mmakefile(options);
state = read_mmakefile(state, mmakefilename, options.FcnMakeFileArgs);

if isempty(target)
target = state.rules(1).target{1};
end
Expand Down Expand Up @@ -174,7 +175,8 @@ function make(target,mmakefilename,varargin)
ismscompiler = false;
end
end
vars.PWD = pwd;
% ###fix: replace backslash for Windows
vars.PWD = pathsep_to_unix(pwd);

vars.MEXFLAGS = '-O'; % Mirror MATLAB's default, but be explicit about it

Expand Down Expand Up @@ -382,6 +384,7 @@ function make(target,mmakefilename,varargin)
end

function state = read_mmakefile(state,path,fcnfileargs)

if regexp(path,'\.m$','once')
state = read_functional_mmakefile(state,path,fcnfileargs);
else
Expand All @@ -391,6 +394,7 @@ function make(target,mmakefilename,varargin)

% Parse a MATLAB-function style MMakefile.
function state = read_functional_mmakefile(state,path,fcnfileargs)

% We have an m-file function
[~,fcn] = fileparts(path);
assert(strcmp(path,which(fcn)),'Function that is called (%s) and filename (%s) do not match',which(fcn),path);
Expand All @@ -402,6 +406,12 @@ function make(target,mmakefilename,varargin)
error(['MJB:mmake:' EX.identifier],'Error reading MMakefile (%s):%s',path,EX.message);
end

% ###fix: replace backslash for Windows
for k = 1:numel(state.rules)
state.rules(k).target = pathsep_to_unix(state.rules(k).target);
state.rules(k).deps = pathsep_to_unix(state.rules(k).deps);
end

% Iterate through the defined variables, add them to state and expand them
fn = fieldnames(vars)';
for fcell = fn
Expand Down Expand Up @@ -688,6 +698,7 @@ function make(target,mmakefilename,varargin)
out(loc).commands = expand_auto_vars(ruleset(i).commands, out(loc));
end
end

end

% Check if the path is absolute
Expand Down Expand Up @@ -892,3 +903,12 @@ function make(target,mmakefilename,varargin)
end

end

function [paths] = pathsep_to_unix(paths)
% Replace Windows file seps by unix style
% note: only for GNU Octave for now, because not tested in Matlab...

if ispc() && isoctave && ~isempty(paths)
paths = strrep(paths,'\','/');
end
end
4 changes: 3 additions & 1 deletion mfemm/+mmake/parse_pv_pairs.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
p_i = lower(pv_pairs{2*i-1});
v_i = pv_pairs{2*i};

ind = strmatch(p_i,lpropnames,'exact');
% ###fix: deprecated strmatch() replaced
%ind = strmatch(p_i,lpropnames,'exact');
ind = find(strcmp(p_i,lpropnames),1);
if isempty(ind)
ind = find(strncmp(p_i,lpropnames,length(p_i)));
if isempty(ind)
Expand Down
5 changes: 4 additions & 1 deletion mfemm/fsolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
error('The following required files were missing\n%sPerhaps you need to rerun fmesher?', missingfilestr);
end

mexfsolver(filename, double(verbose), double(deletemeshfiles));
err = mexfsolver(filename, double(verbose), double(deletemeshfiles));
if err
error(sprintf('mexfsolver() failed with error code %d!',err));
end

ansfile = [filename, '.ans'];

Expand Down
9 changes: 7 additions & 2 deletions mfemm/loadfemmsolution.m
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@

s = fgetl(fid);

% fixed: moved here to be set before MeshedSideLength default load!
arcsegprops.MaxSegDegrees = C{4};

switch ftype.(FemmProblem.ProbInfo.Domain)

Expand All @@ -914,7 +916,7 @@
if C{8} > 0
arcsegprops.MeshedSideLength = C{8};
else
arcsegprops.MeshedSideLength = arcsegprops.MaxSegDegrees;
arcsegprops.MeshedSideLength = arcsegprops.MaxSegDegrees; % ###note: same as MeshedSideLength by default...
end
end

Expand All @@ -925,7 +927,7 @@
arcsegprops.InConductor = C{8};
end

arcsegprops.MaxSegDegrees = C{4};


arcsegprops.BoundaryMarker = C{5};

Expand Down Expand Up @@ -1025,6 +1027,9 @@
% % convert from a side length to area constraint
% FemmProblem.BlockLabels(i).MaxArea = pi * FemmProblem.BlockLabels(i).MaxArea * FemmProblem.BlockLabels(i).MaxArea / 4;
end

% ###fix: this one is expected in addblocklabel_mfemm(), but not set anywhere when problem loaded from file (only set when problem generated from scratch)!
FemmProblem.BlockLabels(i).IsMagnet = ~isnan(FemmProblem.BlockLabels(i).MagDir);

case ftype.heatflow

Expand Down
8 changes: 6 additions & 2 deletions mfemm/mfemm_setup.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
|| ~(exist('fpproc_interface_mex', 'file') == 3) ...
|| options.ForceMexRecompile

fprintf('Compiling mex functions for mfemm.\n');
if options.Verbose
fprintf('Compiling mex functions for mfemm.\n');
end

CC = onCleanup(@() cd(pwd));
cd (thisfilepath);
Expand Down Expand Up @@ -191,7 +193,9 @@

else

fprintf('Not compiling mex functions as they already exist.\n');
if options.Verbose
fprintf('Not compiling mex functions as they already exist.\n');
end

end

Expand Down
9 changes: 4 additions & 5 deletions mfemm/preproc/addgroup_mfemm.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ function checkforexisting (FemmProblem, groupno)
% tests if group numbers are already present in the FemmProblem

% check the group number is unique in the groups
if isfield (FemmProblem, 'Groups')
for fname = fieldnames (FemmProblem.Groups)

if FemmProblem.Groups.(fname) == groupno
if isfield (FemmProblem, 'Groups')
for fname = fieldnames (FemmProblem.Groups)
if FemmProblem.Groups.(fname{1}) == groupno
error ( 'MFEMM::badgroupno', ...
'Group number %f already exists in the list of groups, for group with name %s', ...
groupno, fname );
groupno, fname{1} );
end

end
Expand Down

0 comments on commit 10d11cf

Please sign in to comment.